vp9_header_parser: make SetFrame private
and call it from ParseUncompressedHeader. this avoids attempts to parse a stale buffer should SetFrame fail. BUG=webm:1493 Change-Id: I441ae9d0db3f0a01d73902a8f5b06812e2e93422
This commit is contained in:
parent
6ab4f8fa97
commit
a5837e4dd0
@ -33,7 +33,10 @@ bool Vp9HeaderParser::SetFrame(const uint8_t* frame, size_t length) {
|
||||
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);
|
||||
if (frame_marker != kVp9FrameMarker) {
|
||||
fprintf(stderr, "Invalid VP9 frame_marker:%d\n", frame_marker);
|
||||
|
@ -51,12 +51,9 @@ class Vp9HeaderParser {
|
||||
column_tiles_(0),
|
||||
frame_parallel_mode_(0) {}
|
||||
|
||||
// Set the compressed VP9 frame. This must be called before
|
||||
// ParseUncompressedHeader.
|
||||
bool SetFrame(const uint8_t* frame, size_t length);
|
||||
|
||||
// Parse the VP9 uncompressed header.
|
||||
bool ParseUncompressedHeader();
|
||||
// Parse the VP9 uncompressed header. The return values of the remaining
|
||||
// functions are only valid on success.
|
||||
bool ParseUncompressedHeader(const uint8_t* frame, size_t length);
|
||||
|
||||
size_t frame_size() const { return frame_size_; }
|
||||
int profile() const { return profile_; }
|
||||
@ -73,6 +70,9 @@ class Vp9HeaderParser {
|
||||
int frame_parallel_mode() const { return frame_parallel_mode_; }
|
||||
|
||||
private:
|
||||
// Set the compressed VP9 frame.
|
||||
bool SetFrame(const uint8_t* frame, size_t length);
|
||||
|
||||
// Returns the next bit of the frame.
|
||||
int ReadBit();
|
||||
|
||||
|
@ -107,8 +107,8 @@ class Vp9HeaderParserTests : public ::testing::Test {
|
||||
data_len = static_cast<size_t>(frame.len);
|
||||
}
|
||||
ASSERT_FALSE(frame.Read(&reader_, data));
|
||||
parser_.SetFrame(data, data_len);
|
||||
ASSERT_EQ(parser_.ParseUncompressedHeader(), !invalid_bitstream);
|
||||
ASSERT_EQ(parser_.ParseUncompressedHeader(data, data_len),
|
||||
!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
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
@ -94,8 +94,7 @@ class Vp9LevelStatsTests : public ::testing::Test {
|
||||
data_len = static_cast<size_t>(frame.len);
|
||||
}
|
||||
ASSERT_FALSE(frame.Read(&reader_, &data[0]));
|
||||
parser_.SetFrame(&data[0], data_len);
|
||||
parser_.ParseUncompressedHeader();
|
||||
parser_.ParseUncompressedHeader(&data[0], data_len);
|
||||
stats_.AddFrame(parser_, time_ns);
|
||||
}
|
||||
}
|
||||
|
@ -715,8 +715,7 @@ void PrintVP9Info(const uint8_t* data, int size, FILE* o, int64_t time_ns,
|
||||
static_cast<uint32_t>(frame_length));
|
||||
return;
|
||||
}
|
||||
parser->SetFrame(data, frame_length);
|
||||
if (!parser->ParseUncompressedHeader())
|
||||
if (!parser->ParseUncompressedHeader(data, frame_length))
|
||||
return;
|
||||
level_stats->AddFrame(*parser, time_ns);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user