diff options
author | wolenetz@chromium.org <wolenetz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-24 01:22:23 +0000 |
---|---|---|
committer | wolenetz@chromium.org <wolenetz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-24 01:22:23 +0000 |
commit | c3a44a29ac1189ed84147cfef862251e32fe3d4e (patch) | |
tree | 612843229f18cb3e08477571f57e3c7093c9767c /media/formats | |
parent | 550d847ca5d051ba5cba0f95865bc4ce3362aa98 (diff) | |
download | chromium_src-c3a44a29ac1189ed84147cfef862251e32fe3d4e.zip chromium_src-c3a44a29ac1189ed84147cfef862251e32fe3d4e.tar.gz chromium_src-c3a44a29ac1189ed84147cfef862251e32fe3d4e.tar.bz2 |
SourceState: Coalesce OnNewBuffers() CB to include OnTextBuffers() behavior
Merges the new audio/video buffer callback (SourceState::OnNewBuffers)
with the new text buffer callback (SourceState::OnTextBuffers), so that
stream parsers use only OnNewBuffers for all buffer types. The only
known behavior change is to DCHECK if there are no audio, video,
or text buffers. This is a prerequisite CL for implementing MSE
coded frame processing algorithm compliance and handling SourceBuffer
append modes correctly.
R=xhwang@chromium.org
BUG=249422
TEST=All media_unittests pass on local linux with proprietary codecs enabled.
Review URL: https://codereview.chromium.org/143973009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@246762 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/formats')
-rw-r--r-- | media/formats/mp2t/mp2t_stream_parser.cc | 6 | ||||
-rw-r--r-- | media/formats/mp2t/mp2t_stream_parser.h | 2 | ||||
-rw-r--r-- | media/formats/mp2t/mp2t_stream_parser_unittest.cc | 10 | ||||
-rw-r--r-- | media/formats/mp3/mp3_stream_parser.cc | 5 | ||||
-rw-r--r-- | media/formats/mp3/mp3_stream_parser.h | 2 | ||||
-rw-r--r-- | media/formats/mp3/mp3_stream_parser_unittest.cc | 9 | ||||
-rw-r--r-- | media/formats/mp4/mp4_stream_parser.cc | 7 | ||||
-rw-r--r-- | media/formats/mp4/mp4_stream_parser.h | 2 | ||||
-rw-r--r-- | media/formats/mp4/mp4_stream_parser_unittest.cc | 11 | ||||
-rw-r--r-- | media/formats/webm/webm_cluster_parser.cc | 50 | ||||
-rw-r--r-- | media/formats/webm/webm_cluster_parser.h | 32 | ||||
-rw-r--r-- | media/formats/webm/webm_cluster_parser_unittest.cc | 32 | ||||
-rw-r--r-- | media/formats/webm/webm_stream_parser.cc | 22 | ||||
-rw-r--r-- | media/formats/webm/webm_stream_parser.h | 4 |
14 files changed, 87 insertions, 107 deletions
diff --git a/media/formats/mp2t/mp2t_stream_parser.cc b/media/formats/mp2t/mp2t_stream_parser.cc index 5cae16d..66bdf4f 100644 --- a/media/formats/mp2t/mp2t_stream_parser.cc +++ b/media/formats/mp2t/mp2t_stream_parser.cc @@ -168,7 +168,7 @@ void Mp2tStreamParser::Init( const InitCB& init_cb, const NewConfigCB& config_cb, const NewBuffersCB& new_buffers_cb, - const NewTextBuffersCB& /* text_cb */ , + bool /* ignore_text_tracks */ , const NeedKeyCB& need_key_cb, const NewMediaSegmentCB& new_segment_cb, const base::Closure& end_of_segment_cb, @@ -595,10 +595,12 @@ bool Mp2tStreamParser::EmitRemainingBuffers() { } // Add buffers. + TextBufferQueueMap empty_text_map; if (!queue_with_config.audio_queue.empty() || !queue_with_config.video_queue.empty()) { if (!new_buffers_cb_.Run(queue_with_config.audio_queue, - queue_with_config.video_queue)) { + queue_with_config.video_queue, + empty_text_map)) { return false; } } diff --git a/media/formats/mp2t/mp2t_stream_parser.h b/media/formats/mp2t/mp2t_stream_parser.h index 20a1353..85629dc 100644 --- a/media/formats/mp2t/mp2t_stream_parser.h +++ b/media/formats/mp2t/mp2t_stream_parser.h @@ -33,7 +33,7 @@ class MEDIA_EXPORT Mp2tStreamParser : public StreamParser { virtual void Init(const InitCB& init_cb, const NewConfigCB& config_cb, const NewBuffersCB& new_buffers_cb, - const NewTextBuffersCB& text_cb, + bool ignore_text_tracks, const NeedKeyCB& need_key_cb, const NewMediaSegmentCB& new_segment_cb, const base::Closure& end_of_segment_cb, diff --git a/media/formats/mp2t/mp2t_stream_parser_unittest.cc b/media/formats/mp2t/mp2t_stream_parser_unittest.cc index a88e40e..02370f2 100644 --- a/media/formats/mp2t/mp2t_stream_parser_unittest.cc +++ b/media/formats/mp2t/mp2t_stream_parser_unittest.cc @@ -83,12 +83,18 @@ class Mp2tStreamParserTest : public testing::Test { } bool OnNewBuffers(const StreamParser::BufferQueue& audio_buffers, - const StreamParser::BufferQueue& video_buffers) { + const StreamParser::BufferQueue& video_buffers, + const StreamParser::TextBufferQueueMap& text_map) { DumpBuffers("audio_buffers", audio_buffers); DumpBuffers("video_buffers", video_buffers); audio_frame_count_ += audio_buffers.size(); video_frame_count_ += video_buffers.size(); + // TODO(wolenetz/acolwell): Add text track support to more MSE parsers. See + // http://crbug.com/336926. + if (!text_map.empty()) + return false; + if (video_min_dts_ == kNoTimestamp() && !video_buffers.empty()) video_min_dts_ = video_buffers.front()->GetDecodeTimestamp(); if (!video_buffers.empty()) { @@ -126,7 +132,7 @@ class Mp2tStreamParserTest : public testing::Test { base::Unretained(this)), base::Bind(&Mp2tStreamParserTest::OnNewBuffers, base::Unretained(this)), - StreamParser::NewTextBuffersCB(), + true, base::Bind(&Mp2tStreamParserTest::OnKeyNeeded, base::Unretained(this)), base::Bind(&Mp2tStreamParserTest::OnNewSegment, diff --git a/media/formats/mp3/mp3_stream_parser.cc b/media/formats/mp3/mp3_stream_parser.cc index 3834f7a..832b9f9 100644 --- a/media/formats/mp3/mp3_stream_parser.cc +++ b/media/formats/mp3/mp3_stream_parser.cc @@ -117,7 +117,7 @@ MP3StreamParser::~MP3StreamParser() {} void MP3StreamParser::Init(const InitCB& init_cb, const NewConfigCB& config_cb, const NewBuffersCB& new_buffers_cb, - const NewTextBuffersCB& text_cb, + bool ignore_text_tracks, const NeedKeyCB& need_key_cb, const NewMediaSegmentCB& new_segment_cb, const base::Closure& end_of_segment_cb, @@ -598,7 +598,8 @@ bool MP3StreamParser::SendBuffers(BufferQueue* buffers, bool end_of_segment) { } BufferQueue empty_video_buffers; - if (!new_buffers_cb_.Run(*buffers, empty_video_buffers)) + TextBufferQueueMap empty_text_map; + if (!new_buffers_cb_.Run(*buffers, empty_video_buffers, empty_text_map)) return false; buffers->clear(); diff --git a/media/formats/mp3/mp3_stream_parser.h b/media/formats/mp3/mp3_stream_parser.h index 5d1778c..6b4b388 100644 --- a/media/formats/mp3/mp3_stream_parser.h +++ b/media/formats/mp3/mp3_stream_parser.h @@ -28,7 +28,7 @@ class MEDIA_EXPORT MP3StreamParser : public StreamParser { // StreamParser implementation. virtual void Init(const InitCB& init_cb, const NewConfigCB& config_cb, const NewBuffersCB& new_buffers_cb, - const NewTextBuffersCB& text_cb, + bool ignore_text_tracks, const NeedKeyCB& need_key_cb, const NewMediaSegmentCB& new_segment_cb, const base::Closure& end_of_segment_cb, diff --git a/media/formats/mp3/mp3_stream_parser_unittest.cc b/media/formats/mp3/mp3_stream_parser_unittest.cc index a279a1c..4ff7853 100644 --- a/media/formats/mp3/mp3_stream_parser_unittest.cc +++ b/media/formats/mp3/mp3_stream_parser_unittest.cc @@ -71,10 +71,15 @@ class MP3StreamParserTest : public testing::Test { } bool OnNewBuffers(const StreamParser::BufferQueue& audio_buffers, - const StreamParser::BufferQueue& video_buffers) { + const StreamParser::BufferQueue& video_buffers, + const StreamParser::TextBufferQueueMap& text_map) { EXPECT_FALSE(audio_buffers.empty()); EXPECT_TRUE(video_buffers.empty()); + // TODO(wolenetz/acolwell): Add text track support to more MSE parsers. See + // http://crbug.com/336926. + EXPECT_TRUE(text_map.empty()); + std::string buffers_str = BufferQueueToString(audio_buffers); DVLOG(1) << __FUNCTION__ << " : " << buffers_str; results_stream_ << buffers_str; @@ -101,7 +106,7 @@ class MP3StreamParserTest : public testing::Test { base::Bind(&MP3StreamParserTest::OnInitDone, base::Unretained(this)), base::Bind(&MP3StreamParserTest::OnNewConfig, base::Unretained(this)), base::Bind(&MP3StreamParserTest::OnNewBuffers, base::Unretained(this)), - StreamParser::NewTextBuffersCB(), + true, base::Bind(&MP3StreamParserTest::OnKeyNeeded, base::Unretained(this)), base::Bind(&MP3StreamParserTest::OnNewSegment, base::Unretained(this)), base::Bind(&MP3StreamParserTest::OnEndOfSegment, diff --git a/media/formats/mp4/mp4_stream_parser.cc b/media/formats/mp4/mp4_stream_parser.cc index a8038ea..be88d87 100644 --- a/media/formats/mp4/mp4_stream_parser.cc +++ b/media/formats/mp4/mp4_stream_parser.cc @@ -44,7 +44,7 @@ MP4StreamParser::~MP4StreamParser() {} void MP4StreamParser::Init(const InitCB& init_cb, const NewConfigCB& config_cb, const NewBuffersCB& new_buffers_cb, - const NewTextBuffersCB& /* text_cb */ , + bool /* ignore_text_tracks */ , const NeedKeyCB& need_key_cb, const NewMediaSegmentCB& new_segment_cb, const base::Closure& end_of_segment_cb, @@ -530,7 +530,10 @@ bool MP4StreamParser::SendAndFlushSamples(BufferQueue* audio_buffers, if (audio_buffers->empty() && video_buffers->empty()) return true; - bool success = new_buffers_cb_.Run(*audio_buffers, *video_buffers); + TextBufferQueueMap empty_text_map; + bool success = new_buffers_cb_.Run(*audio_buffers, + *video_buffers, + empty_text_map); audio_buffers->clear(); video_buffers->clear(); return success; diff --git a/media/formats/mp4/mp4_stream_parser.h b/media/formats/mp4/mp4_stream_parser.h index d229852..d7816ba 100644 --- a/media/formats/mp4/mp4_stream_parser.h +++ b/media/formats/mp4/mp4_stream_parser.h @@ -30,7 +30,7 @@ class MEDIA_EXPORT MP4StreamParser : public StreamParser { virtual void Init(const InitCB& init_cb, const NewConfigCB& config_cb, const NewBuffersCB& new_buffers_cb, - const NewTextBuffersCB& text_cb, + bool ignore_text_tracks, const NeedKeyCB& need_key_cb, const NewMediaSegmentCB& new_segment_cb, const base::Closure& end_of_segment_cb, diff --git a/media/formats/mp4/mp4_stream_parser_unittest.cc b/media/formats/mp4/mp4_stream_parser_unittest.cc index 0f9260a..f86a5b0 100644 --- a/media/formats/mp4/mp4_stream_parser_unittest.cc +++ b/media/formats/mp4/mp4_stream_parser_unittest.cc @@ -85,9 +85,16 @@ class MP4StreamParserTest : public testing::Test { } bool NewBuffersF(const StreamParser::BufferQueue& audio_buffers, - const StreamParser::BufferQueue& video_buffers) { + const StreamParser::BufferQueue& video_buffers, + const StreamParser::TextBufferQueueMap& text_map) { DumpBuffers("audio_buffers", audio_buffers); DumpBuffers("video_buffers", video_buffers); + + // TODO(wolenetz/acolwell): Add text track support to more MSE parsers. See + // http://crbug.com/336926. + if (!text_map.empty()) + return false; + return true; } @@ -111,7 +118,7 @@ class MP4StreamParserTest : public testing::Test { base::Bind(&MP4StreamParserTest::InitF, base::Unretained(this)), base::Bind(&MP4StreamParserTest::NewConfigF, base::Unretained(this)), base::Bind(&MP4StreamParserTest::NewBuffersF, base::Unretained(this)), - StreamParser::NewTextBuffersCB(), + true, base::Bind(&MP4StreamParserTest::KeyNeededF, base::Unretained(this)), base::Bind(&MP4StreamParserTest::NewSegmentF, base::Unretained(this)), base::Bind(&MP4StreamParserTest::EndOfSegmentF, diff --git a/media/formats/webm/webm_cluster_parser.cc b/media/formats/webm/webm_cluster_parser.cc index e662f83..67e6d82 100644 --- a/media/formats/webm/webm_cluster_parser.cc +++ b/media/formats/webm/webm_cluster_parser.cc @@ -17,38 +17,6 @@ namespace media { -WebMClusterParser::TextTrackIterator::TextTrackIterator( - const TextTrackMap& text_track_map) : - iterator_(text_track_map.begin()), - iterator_end_(text_track_map.end()) { -} - -WebMClusterParser::TextTrackIterator::TextTrackIterator( - const TextTrackIterator& rhs) : - iterator_(rhs.iterator_), - iterator_end_(rhs.iterator_end_) { -} - -WebMClusterParser::TextTrackIterator::~TextTrackIterator() { -} - -bool WebMClusterParser::TextTrackIterator::operator()( - int* track_num, - const BufferQueue** buffers) { - if (iterator_ == iterator_end_) { - *track_num = 0; - *buffers = NULL; - - return false; - } - - *track_num = iterator_->first; - *buffers = &iterator_->second.buffers(); - - ++iterator_; - return true; -} - WebMClusterParser::WebMClusterParser( int64 timecode_scale, int audio_track_num, int video_track_num, const WebMTracksParser::TextTracks& text_tracks, @@ -131,9 +99,20 @@ int WebMClusterParser::Parse(const uint8* buf, int size) { return result; } -WebMClusterParser::TextTrackIterator -WebMClusterParser::CreateTextTrackIterator() const { - return TextTrackIterator(text_track_map_); +const WebMClusterParser::TextBufferQueueMap& +WebMClusterParser::GetTextBuffers() { + // Translate our |text_track_map_| into |text_buffers_map_|, inserting rows in + // the output only for non-empty text buffer queues in |text_track_map_|. + text_buffers_map_.clear(); + for (TextTrackMap::const_iterator itr = text_track_map_.begin(); + itr != text_track_map_.end(); + ++itr) { + const BufferQueue& text_buffers = itr->second.buffers(); + if (!text_buffers.empty()) + text_buffers_map_.insert(std::make_pair(itr->first, text_buffers)); + } + + return text_buffers_map_; } WebMParserClient* WebMClusterParser::OnListStart(int id) { @@ -451,6 +430,7 @@ bool WebMClusterParser::Track::IsKeyframe(const uint8* data, int size) const { } void WebMClusterParser::ResetTextTracks() { + text_buffers_map_.clear(); for (TextTrackMap::iterator it = text_track_map_.begin(); it != text_track_map_.end(); ++it) { diff --git a/media/formats/webm/webm_cluster_parser.h b/media/formats/webm/webm_cluster_parser.h index db683f6..63cc507 100644 --- a/media/formats/webm/webm_cluster_parser.h +++ b/media/formats/webm/webm_cluster_parser.h @@ -53,24 +53,7 @@ class MEDIA_EXPORT WebMClusterParser : public WebMParserClient { public: typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; - - class MEDIA_EXPORT TextTrackIterator { - public: - explicit TextTrackIterator(const TextTrackMap& text_track_map); - TextTrackIterator(const TextTrackIterator& rhs); - ~TextTrackIterator(); - - // To visit each text track. If the iterator is exhausted, it returns - // as parameters the values 0 and NULL, and the function returns false. - // Otherwise, it returns the buffers for the associated track, and the - // function returns true. - bool operator()(int* track_num, const BufferQueue** buffers); - private: - TextTrackIterator& operator=(const TextTrackIterator&); - - TextTrackMap::const_iterator iterator_; - const TextTrackMap::const_iterator iterator_end_; - }; + typedef std::map<int, const BufferQueue> TextBufferQueueMap; WebMClusterParser(int64 timecode_scale, int audio_track_num, @@ -96,8 +79,11 @@ class MEDIA_EXPORT WebMClusterParser : public WebMParserClient { const BufferQueue& audio_buffers() const { return audio_.buffers(); } const BufferQueue& video_buffers() const { return video_.buffers(); } - // Returns an iterator object, allowing each text track to be visited. - TextTrackIterator CreateTextTrackIterator() const; + // Constructs and returns a subset of |text_track_map_| containing only + // tracks with non-empty buffer queues produced by the last Parse(). + // The returned map is cleared by Parse() or Reset() and updated by the next + // call to GetTextBuffers(). + const TextBufferQueueMap& GetTextBuffers(); // Returns true if the last Parse() call stopped at the end of a cluster. bool cluster_ended() const { return cluster_ended_; } @@ -149,6 +135,12 @@ class MEDIA_EXPORT WebMClusterParser : public WebMParserClient { Track audio_; Track video_; TextTrackMap text_track_map_; + + // Subset of |text_track_map_| maintained by GetTextBuffers(), and cleared by + // ResetTextTracks(). Callers of GetTextBuffers() get a const-ref to this + // member. + TextBufferQueueMap text_buffers_map_; + LogCB log_cb_; DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser); diff --git a/media/formats/webm/webm_cluster_parser_unittest.cc b/media/formats/webm/webm_cluster_parser_unittest.cc index a358cfe..e14a334 100644 --- a/media/formats/webm/webm_cluster_parser_unittest.cc +++ b/media/formats/webm/webm_cluster_parser_unittest.cc @@ -132,18 +132,13 @@ static bool VerifyBuffers(const WebMClusterParser::BufferQueue& audio_buffers, static bool VerifyBuffers(const scoped_ptr<WebMClusterParser>& parser, const BlockInfo* block_info, int block_count) { - typedef WebMClusterParser::TextTrackIterator TextTrackIterator; - TextTrackIterator text_it = parser->CreateTextTrackIterator(); - - int text_track_num; + const WebMClusterParser::TextBufferQueueMap& text_map = + parser->GetTextBuffers(); const WebMClusterParser::BufferQueue* text_buffers; - - while (text_it(&text_track_num, &text_buffers)) - break; - const WebMClusterParser::BufferQueue no_text_buffers; - - if (text_buffers == NULL) + if (!text_map.empty()) + text_buffers = &(text_map.rbegin()->second); + else text_buffers = &no_text_buffers; return VerifyBuffers(parser->audio_buffers(), @@ -476,18 +471,17 @@ TEST_F(WebMClusterParserTest, ParseMultipleTextTracks) { int result = parser_->Parse(cluster->data(), cluster->size()); EXPECT_EQ(cluster->size(), result); - WebMClusterParser::TextTrackIterator text_it = - parser_->CreateTextTrackIterator(); - - int text_track_num; - const WebMClusterParser::BufferQueue* text_buffers; - - while (text_it(&text_track_num, &text_buffers)) { + const WebMClusterParser::TextBufferQueueMap& text_map = + parser_->GetTextBuffers(); + for (WebMClusterParser::TextBufferQueueMap::const_iterator itr = + text_map.begin(); + itr != text_map.end(); + ++itr) { const WebMTracksParser::TextTracks::const_iterator find_result = - text_tracks.find(text_track_num); + text_tracks.find(itr->first); ASSERT_TRUE(find_result != text_tracks.end()); ASSERT_TRUE(VerifyTextBuffers(parser_, kInputBlockInfo, input_block_count, - text_track_num, *text_buffers)); + itr->first, itr->second)); } } diff --git a/media/formats/webm/webm_stream_parser.cc b/media/formats/webm/webm_stream_parser.cc index f39a8e3..fcb55de 100644 --- a/media/formats/webm/webm_stream_parser.cc +++ b/media/formats/webm/webm_stream_parser.cc @@ -28,7 +28,7 @@ WebMStreamParser::~WebMStreamParser() { void WebMStreamParser::Init(const InitCB& init_cb, const NewConfigCB& config_cb, const NewBuffersCB& new_buffers_cb, - const NewTextBuffersCB& text_cb, + bool ignore_text_tracks, const NeedKeyCB& need_key_cb, const NewMediaSegmentCB& new_segment_cb, const base::Closure& end_of_segment_cb, @@ -46,7 +46,7 @@ void WebMStreamParser::Init(const InitCB& init_cb, init_cb_ = init_cb; config_cb_ = config_cb; new_buffers_cb_ = new_buffers_cb; - text_cb_ = text_cb; + ignore_text_tracks_ = ignore_text_tracks; need_key_cb_ = need_key_cb; new_segment_cb_ = new_segment_cb; end_of_segment_cb_ = end_of_segment_cb; @@ -171,7 +171,7 @@ int WebMStreamParser::ParseInfoAndTracks(const uint8* data, int size) { cur_size -= result; bytes_parsed += result; - WebMTracksParser tracks_parser(log_cb_, text_cb_.is_null()); + WebMTracksParser tracks_parser(log_cb_, ignore_text_tracks_); result = tracks_parser.Parse(cur, cur_size); if (result <= 0) @@ -266,24 +266,14 @@ int WebMStreamParser::ParseCluster(const uint8* data, int size) { const BufferQueue& audio_buffers = cluster_parser_->audio_buffers(); const BufferQueue& video_buffers = cluster_parser_->video_buffers(); + const TextBufferQueueMap& text_map = cluster_parser_->GetTextBuffers(); bool cluster_ended = cluster_parser_->cluster_ended(); - if ((!audio_buffers.empty() || !video_buffers.empty()) && - !new_buffers_cb_.Run(audio_buffers, video_buffers)) { + if ((!audio_buffers.empty() || !video_buffers.empty() || !text_map.empty()) && + !new_buffers_cb_.Run(audio_buffers, video_buffers, text_map)) { return -1; } - WebMClusterParser::TextTrackIterator text_track_iter = - cluster_parser_->CreateTextTrackIterator(); - - int text_track_num; - const BufferQueue* text_buffers; - - while (text_track_iter(&text_track_num, &text_buffers)) { - if (!text_buffers->empty() && !text_cb_.Run(text_track_num, *text_buffers)) - return -1; - } - if (cluster_ended) { parsing_cluster_ = false; end_of_segment_cb_.Run(); diff --git a/media/formats/webm/webm_stream_parser.h b/media/formats/webm/webm_stream_parser.h index 5a4173f..822b801 100644 --- a/media/formats/webm/webm_stream_parser.h +++ b/media/formats/webm/webm_stream_parser.h @@ -25,7 +25,7 @@ class WebMStreamParser : public StreamParser { // StreamParser implementation. virtual void Init(const InitCB& init_cb, const NewConfigCB& config_cb, const NewBuffersCB& new_buffers_cb, - const NewTextBuffersCB& text_cb, + bool ignore_text_tracks, const NeedKeyCB& need_key_cb, const NewMediaSegmentCB& new_segment_cb, const base::Closure& end_of_segment_cb, @@ -69,7 +69,7 @@ class WebMStreamParser : public StreamParser { InitCB init_cb_; NewConfigCB config_cb_; NewBuffersCB new_buffers_cb_; - NewTextBuffersCB text_cb_; + bool ignore_text_tracks_; NeedKeyCB need_key_cb_; NewMediaSegmentCB new_segment_cb_; |