diff options
author | acolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-12 17:43:04 +0000 |
---|---|---|
committer | acolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-12 17:43:04 +0000 |
commit | 31bc2039ba95532aafee8f028673c2a53d76b24a (patch) | |
tree | b70c4e29d583cf1084675df8323f6375ef1c4f91 /media/webm/webm_cluster_parser.cc | |
parent | 8453535eedd7e7789fcc315436cead1a030312a4 (diff) | |
download | chromium_src-31bc2039ba95532aafee8f028673c2a53d76b24a.zip chromium_src-31bc2039ba95532aafee8f028673c2a53d76b24a.tar.gz chromium_src-31bc2039ba95532aafee8f028673c2a53d76b24a.tar.bz2 |
Adding support for incremental cluster parsing.
BUG=104160
TEST=Covered by ChunkDemuxer unittests.
Review URL: http://codereview.chromium.org/8775035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114030 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/webm/webm_cluster_parser.cc')
-rw-r--r-- | media/webm/webm_cluster_parser.cc | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/media/webm/webm_cluster_parser.cc b/media/webm/webm_cluster_parser.cc index 8eb045c..fd716b2 100644 --- a/media/webm/webm_cluster_parser.cc +++ b/media/webm/webm_cluster_parser.cc @@ -26,6 +26,7 @@ WebMClusterParser::WebMClusterParser(int64 timecode_scale, audio_default_duration_(audio_default_duration), video_track_num_(video_track_num), video_default_duration_(video_default_duration), + parser_(kWebMIdCluster), last_block_timecode_(-1), cluster_timecode_(-1) { } @@ -33,12 +34,25 @@ WebMClusterParser::WebMClusterParser(int64 timecode_scale, WebMClusterParser::~WebMClusterParser() {} int WebMClusterParser::Parse(const uint8* buf, int size) { - last_block_timecode_ = -1; - cluster_timecode_ = -1; audio_buffers_.clear(); video_buffers_.clear(); - return WebMParseListElement(buf, size, kWebMIdCluster, 1, this); + int result = parser_.Parse(buf, size, this); + + if (result <= 0) + return result; + + if (parser_.IsParsingComplete()) { + // Reset the parser if we're done parsing so that + // it is ready to accept another cluster on the next + // call. + parser_.Reset(); + + last_block_timecode_ = -1; + cluster_timecode_ = -1; + } + + return result; } bool WebMClusterParser::OnListStart(int id) { @@ -67,17 +81,17 @@ bool WebMClusterParser::OnUInt(int id, int64 val) { } bool WebMClusterParser::OnFloat(int id, double val) { - VLOG(1) << "Unexpected float element with ID " << std::hex << id; + DVLOG(1) << "Unexpected float element with ID " << std::hex << id; return false; } bool WebMClusterParser::OnBinary(int id, const uint8* data, int size) { - VLOG(1) << "Unexpected binary element with ID " << std::hex << id; + DVLOG(1) << "Unexpected binary element with ID " << std::hex << id; return false; } bool WebMClusterParser::OnString(int id, const std::string& str) { - VLOG(1) << "Unexpected string element with ID " << std::hex << id; + DVLOG(1) << "Unexpected string element with ID " << std::hex << id; return false; } @@ -85,17 +99,17 @@ bool WebMClusterParser::OnSimpleBlock(int track_num, int timecode, int flags, const uint8* data, int size) { if (cluster_timecode_ == -1) { - VLOG(1) << "Got SimpleBlock before cluster timecode."; + DVLOG(1) << "Got SimpleBlock before cluster timecode."; return false; } if (timecode < 0) { - VLOG(1) << "Got SimpleBlock with negative timecode offset " << timecode; + DVLOG(1) << "Got SimpleBlock with negative timecode offset " << timecode; return false; } if (last_block_timecode_ != -1 && timecode < last_block_timecode_) { - VLOG(1) << "Got SimpleBlock with a timecode before the previous block."; + DVLOG(1) << "Got SimpleBlock with a timecode before the previous block."; return false; } @@ -115,13 +129,13 @@ bool WebMClusterParser::OnSimpleBlock(int track_num, int timecode, buffer->SetDuration(video_default_duration_); queue = &video_buffers_; } else { - VLOG(1) << "Unexpected track number " << track_num; + DVLOG(1) << "Unexpected track number " << track_num; return false; } if (!queue->empty() && buffer->GetTimestamp() == queue->back()->GetTimestamp()) { - VLOG(1) << "Got SimpleBlock timecode is not strictly monotonically " + DVLOG(1) << "Got SimpleBlock timecode is not strictly monotonically " << "increasing for track " << track_num; return false; } |