Commit add0ea33 authored by strobe@google.com's avatar strobe@google.com

Fix sourceAbort() for BMFF streams.

MP4StreamParser::Flush() (called eventually by sourceAbort()) did not reset the
parser state, and so would only work if the call happened to come when the
parser was already in a particular state (which happened to always be true for
the browser test harness it was originally tested with).

Additionally, the format-specific buffer conversion methods did not cause
an error to be propagated to the caller on failure, resulting in unexpected
success for the added test.

BUG=
TEST=MP4StreamParserTest.TestFlush


Review URL: https://chromiumcodereview.appspot.com/10843044

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149730 0039d316-1c4b-4281-b951-d872f2087c98
parent 27d1b57d
......@@ -58,14 +58,20 @@ void MP4StreamParser::Init(const InitCB& init_cb,
end_of_segment_cb_ = end_of_segment_cb;
}
void MP4StreamParser::Flush() {
DCHECK_NE(state_, kWaitingForInit);
void MP4StreamParser::Reset() {
queue_.Reset();
moov_.reset();
runs_.reset();
moof_head_ = 0;
mdat_tail_ = 0;
}
void MP4StreamParser::Flush() {
DCHECK_NE(state_, kWaitingForInit);
Reset();
ChangeState(kParsingBoxes);
}
bool MP4StreamParser::Parse(const uint8* buf, int size) {
DCHECK_NE(state_, kWaitingForInit);
......@@ -97,9 +103,7 @@ bool MP4StreamParser::Parse(const uint8* buf, int size) {
if (err) {
DLOG(ERROR) << "Error while parsing MP4";
queue_.Reset();
moov_.reset();
runs_.reset();
Reset();
ChangeState(kError);
return false;
}
......@@ -378,8 +382,12 @@ bool MP4StreamParser::EnqueueSample(BufferQueue* audio_buffers,
std::vector<SubsampleEntry> subsamples;
if (decrypt_config.get())
subsamples = decrypt_config->subsamples();
RCHECK(PrepareAVCBuffer(runs_->video_description().avcc,
&frame_buf, &subsamples));
if (!PrepareAVCBuffer(runs_->video_description().avcc,
&frame_buf, &subsamples)) {
DLOG(ERROR) << "Failed to prepare AVC sample for decode";
*err = true;
return false;
}
if (!subsamples.empty()) {
decrypt_config.reset(new DecryptConfig(
decrypt_config->key_id(),
......@@ -392,7 +400,11 @@ bool MP4StreamParser::EnqueueSample(BufferQueue* audio_buffers,
if (audio) {
const AAC& aac = runs_->audio_description().esds.aac;
RCHECK(aac.ConvertEsdsToADTS(&frame_buf));
if (!aac.ConvertEsdsToADTS(&frame_buf)) {
DLOG(ERROR) << "Failed to convert ESDS to ADTS";
*err = true;
return false;
}
}
scoped_refptr<StreamParserBuffer> stream_buf =
......
......@@ -70,6 +70,8 @@ class MEDIA_EXPORT MP4StreamParser : public StreamParser {
bool SendAndFlushSamples(BufferQueue* audio_buffers,
BufferQueue* video_buffers);
void Reset();
State state_;
InitCB init_cb_;
NewConfigCB config_cb_;
......
......@@ -137,6 +137,19 @@ TEST_F(MP4StreamParserTest, TestMultiFragmentAppend) {
ParseMP4File("bear.1280x720_dash.mp4", 768432);
}
TEST_F(MP4StreamParserTest, TestFlush) {
// Flush while reading sample data, then start a new stream.
InitializeParser();
scoped_refptr<DecoderBuffer> buffer =
ReadTestDataFile("bear.1280x720_dash.mp4");
EXPECT_TRUE(AppendDataInPieces(buffer->GetData(), 65536, 512));
parser_->Flush();
EXPECT_TRUE(AppendDataInPieces(buffer->GetData(),
buffer->GetDataSize(),
512));
}
TEST_F(MP4StreamParserTest, TestReinitialization) {
InitializeParser();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment