Merge "vp9_header_parser: make SetFrame private"

This commit is contained in:
James Zern 2018-02-02 19:46:59 +00:00 committed by Gerrit Code Review
commit faf76029b0
5 changed files with 22 additions and 13 deletions

View File

@ -33,7 +33,10 @@ bool Vp9HeaderParser::SetFrame(const uint8_t* frame, size_t length) {
return true; return true;
} }
bool Vp9HeaderParser::ParseUncompressedHeader() { bool Vp9HeaderParser::ParseUncompressedHeader(const uint8_t* frame,
size_t length) {
if (!SetFrame(frame, length))
return false;
const int frame_marker = VpxReadLiteral(2); const int frame_marker = VpxReadLiteral(2);
if (frame_marker != kVp9FrameMarker) { if (frame_marker != kVp9FrameMarker) {
fprintf(stderr, "Invalid VP9 frame_marker:%d\n", frame_marker); fprintf(stderr, "Invalid VP9 frame_marker:%d\n", frame_marker);

View File

@ -51,12 +51,9 @@ class Vp9HeaderParser {
column_tiles_(0), column_tiles_(0),
frame_parallel_mode_(0) {} frame_parallel_mode_(0) {}
// Set the compressed VP9 frame. This must be called before // Parse the VP9 uncompressed header. The return values of the remaining
// ParseUncompressedHeader. // functions are only valid on success.
bool SetFrame(const uint8_t* frame, size_t length); bool ParseUncompressedHeader(const uint8_t* frame, size_t length);
// Parse the VP9 uncompressed header.
bool ParseUncompressedHeader();
size_t frame_size() const { return frame_size_; } size_t frame_size() const { return frame_size_; }
int profile() const { return profile_; } int profile() const { return profile_; }
@ -73,6 +70,9 @@ class Vp9HeaderParser {
int frame_parallel_mode() const { return frame_parallel_mode_; } int frame_parallel_mode() const { return frame_parallel_mode_; }
private: private:
// Set the compressed VP9 frame.
bool SetFrame(const uint8_t* frame, size_t length);
// Returns the next bit of the frame. // Returns the next bit of the frame.
int ReadBit(); int ReadBit();

View File

@ -107,8 +107,8 @@ class Vp9HeaderParserTests : public ::testing::Test {
data_len = static_cast<size_t>(frame.len); data_len = static_cast<size_t>(frame.len);
} }
ASSERT_FALSE(frame.Read(&reader_, data)); ASSERT_FALSE(frame.Read(&reader_, data));
parser_.SetFrame(data, data_len); ASSERT_EQ(parser_.ParseUncompressedHeader(data, data_len),
ASSERT_EQ(parser_.ParseUncompressedHeader(), !invalid_bitstream); !invalid_bitstream);
} }
} }
@ -165,6 +165,14 @@ TEST_F(Vp9HeaderParserTests, Invalid) {
} }
} }
TEST_F(Vp9HeaderParserTests, API) {
vp9_parser::Vp9HeaderParser parser;
uint8_t data;
EXPECT_FALSE(parser.ParseUncompressedHeader(NULL, 0));
EXPECT_FALSE(parser.ParseUncompressedHeader(NULL, 10));
EXPECT_FALSE(parser.ParseUncompressedHeader(&data, 0));
}
} // namespace } // namespace
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {

View File

@ -94,8 +94,7 @@ class Vp9LevelStatsTests : public ::testing::Test {
data_len = static_cast<size_t>(frame.len); data_len = static_cast<size_t>(frame.len);
} }
ASSERT_FALSE(frame.Read(&reader_, &data[0])); ASSERT_FALSE(frame.Read(&reader_, &data[0]));
parser_.SetFrame(&data[0], data_len); parser_.ParseUncompressedHeader(&data[0], data_len);
parser_.ParseUncompressedHeader();
stats_.AddFrame(parser_, time_ns); stats_.AddFrame(parser_, time_ns);
} }
} }

View File

@ -715,8 +715,7 @@ void PrintVP9Info(const uint8_t* data, int size, FILE* o, int64_t time_ns,
static_cast<uint32_t>(frame_length)); static_cast<uint32_t>(frame_length));
return; return;
} }
parser->SetFrame(data, frame_length); if (!parser->ParseUncompressedHeader(data, frame_length))
if (!parser->ParseUncompressedHeader())
return; return;
level_stats->AddFrame(*parser, time_ns); level_stats->AddFrame(*parser, time_ns);