diff options
author | acolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-26 00:11:55 +0000 |
---|---|---|
committer | acolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-26 00:11:55 +0000 |
commit | 500c8ab770fa3f9b0581b489704b92c0fcc0de08 (patch) | |
tree | 8b58cf1355158220c3719df5f6e162fd6620b9d6 /media | |
parent | 86c6f57bb2b13eead781e93202ca2c9c73b0da04 (diff) | |
download | chromium_src-500c8ab770fa3f9b0581b489704b92c0fcc0de08.zip chromium_src-500c8ab770fa3f9b0581b489704b92c0fcc0de08.tar.gz chromium_src-500c8ab770fa3f9b0581b489704b92c0fcc0de08.tar.bz2 |
Replace StreamParserHost interface with callbacks.
BUG=122909
TEST=Existing ChunkDemuxer tests cover this change.
Review URL: http://codereview.chromium.org/10134066
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134020 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/base/stream_parser.cc | 4 | ||||
-rw-r--r-- | media/base/stream_parser.h | 54 | ||||
-rw-r--r-- | media/filters/chunk_demuxer.cc | 8 | ||||
-rw-r--r-- | media/filters/chunk_demuxer.h | 12 | ||||
-rw-r--r-- | media/webm/webm_stream_parser.cc | 29 | ||||
-rw-r--r-- | media/webm/webm_stream_parser.h | 8 |
6 files changed, 57 insertions, 58 deletions
diff --git a/media/base/stream_parser.cc b/media/base/stream_parser.cc index 255cc6f..1240919 100644 --- a/media/base/stream_parser.cc +++ b/media/base/stream_parser.cc @@ -6,10 +6,6 @@ namespace media { -StreamParserHost::StreamParserHost() {} - -StreamParserHost::~StreamParserHost() {} - StreamParser::StreamParser() {} StreamParser::~StreamParser() {} diff --git a/media/base/stream_parser.h b/media/base/stream_parser.h index daeee4b..2d71573 100644 --- a/media/base/stream_parser.h +++ b/media/base/stream_parser.h @@ -18,37 +18,11 @@ class AudioDecoderConfig; class Buffer; class VideoDecoderConfig; -// Provides callback methods for StreamParser to report information -// about the media stream. -class MEDIA_EXPORT StreamParserHost { - public: - typedef std::deque<scoped_refptr<Buffer> > BufferQueue; - - StreamParserHost(); - virtual ~StreamParserHost(); - - // New audio and/or video decoder configurations were encountered. All audio - // and video buffers after this call will be associated with these - // configurations. - // Returns true if the new configurations are accepted. - // Returns false if the new configurations are not supported and indicates - // that a parsing error should be signalled. - virtual bool OnNewConfigs(const AudioDecoderConfig& audio_config, - const VideoDecoderConfig& video_config) = 0; - - // New audio buffers have been received. - virtual bool OnAudioBuffers(const BufferQueue& buffers) = 0; - - // New video buffers have been received. - virtual bool OnVideoBuffers(const BufferQueue& buffers) = 0; - - private: - DISALLOW_COPY_AND_ASSIGN(StreamParserHost); -}; - // Abstract interface for parsing media byte streams. class MEDIA_EXPORT StreamParser { public: + typedef std::deque<scoped_refptr<Buffer> > BufferQueue; + StreamParser(); virtual ~StreamParser(); @@ -60,11 +34,33 @@ class MEDIA_EXPORT StreamParser { // value if the first parameter is true. typedef base::Callback<void(bool, base::TimeDelta)> InitCB; + // Indicates when new stream configurations have been parsed. + // First parameter - The new audio configuration. If the config is not valid + // then it means that there isn't an audio stream. + // Second parameter - The new video configuration. If the config is not valid + // then it means that there isn't an audio stream. + // Return value - True if the new configurations are accepted. + // False if the new configurations are not supported + // and indicates that a parsing error should be signalled. + typedef base::Callback<bool(const AudioDecoderConfig&, + const VideoDecoderConfig&)> NewConfigCB; + + // New stream buffers have been parsed. + // First parameter - A queue of newly parsed buffers. + // Return value - True indicates that the buffers are accepted. + // False if something was wrong with the buffers and a parsing + // error should be signalled. + typedef base::Callback<bool(const BufferQueue&)> NewBuffersCB; + + // Initialize the parser with necessary callbacks. Must be called before any // data is passed to Parse(). |init_cb| will be called once enough data has // been parsed to determine the initial stream configurations, presentation // start time, and duration. - virtual void Init(const InitCB& init_cb, StreamParserHost* host) = 0; + virtual void Init(const InitCB& init_cb, + const NewConfigCB& config_cb, + const NewBuffersCB& audio_cb, + const NewBuffersCB& video_cb) = 0; // Called when a seek occurs. This flushes the current parser state // and puts the parser in a state where it can receive data for the new seek diff --git a/media/filters/chunk_demuxer.cc b/media/filters/chunk_demuxer.cc index 8b82449..9c1a6cb 100644 --- a/media/filters/chunk_demuxer.cc +++ b/media/filters/chunk_demuxer.cc @@ -361,7 +361,9 @@ void ChunkDemuxer::Initialize(DemuxerHost* host, stream_parser_->Init( base::Bind(&ChunkDemuxer::OnStreamParserInitDone, this), - this); + base::Bind(&ChunkDemuxer::OnNewConfigs, base::Unretained(this)), + base::Bind(&ChunkDemuxer::OnAudioBuffers, base::Unretained(this)), + base::Bind(&ChunkDemuxer::OnVideoBuffers, base::Unretained(this))); } client_->DemuxerOpened(this); @@ -708,7 +710,7 @@ bool ChunkDemuxer::OnNewConfigs(const AudioDecoderConfig& audio_config, return true; } -bool ChunkDemuxer::OnAudioBuffers(const BufferQueue& buffers) { +bool ChunkDemuxer::OnAudioBuffers(const StreamParser::BufferQueue& buffers) { if (!audio_.get()) return false; @@ -721,7 +723,7 @@ bool ChunkDemuxer::OnAudioBuffers(const BufferQueue& buffers) { return true; } -bool ChunkDemuxer::OnVideoBuffers(const BufferQueue& buffers) { +bool ChunkDemuxer::OnVideoBuffers(const StreamParser::BufferQueue& buffers) { if (!video_.get()) return false; diff --git a/media/filters/chunk_demuxer.h b/media/filters/chunk_demuxer.h index 7c4ae36..0a14d48 100644 --- a/media/filters/chunk_demuxer.h +++ b/media/filters/chunk_demuxer.h @@ -21,7 +21,7 @@ class FFmpegURLProtocol; // Demuxer implementation that allows chunks of media data to be passed // from JavaScript to the media stack. -class MEDIA_EXPORT ChunkDemuxer : public Demuxer, public StreamParserHost { +class MEDIA_EXPORT ChunkDemuxer : public Demuxer { public: enum Status { kOk, // ID added w/o error. @@ -86,11 +86,11 @@ class MEDIA_EXPORT ChunkDemuxer : public Demuxer, public StreamParserHost { void OnStreamParserInitDone(bool success, base::TimeDelta duration); - // StreamParserHost implementation. - virtual bool OnNewConfigs(const AudioDecoderConfig& audio_config, - const VideoDecoderConfig& video_config) OVERRIDE; - virtual bool OnAudioBuffers(const BufferQueue& buffer) OVERRIDE; - virtual bool OnVideoBuffers(const BufferQueue& buffer) OVERRIDE; + // StreamParser callbacks. + bool OnNewConfigs(const AudioDecoderConfig& audio_config, + const VideoDecoderConfig& video_config); + bool OnAudioBuffers(const StreamParser::BufferQueue& buffer); + bool OnVideoBuffers(const StreamParser::BufferQueue& buffer); base::Lock lock_; State state_; diff --git a/media/webm/webm_stream_parser.cc b/media/webm/webm_stream_parser.cc index c0b01fc..94e3256 100644 --- a/media/webm/webm_stream_parser.cc +++ b/media/webm/webm_stream_parser.cc @@ -181,22 +181,26 @@ bool FFmpegConfigHelper::SetupStreamConfigs() { } WebMStreamParser::WebMStreamParser() - : state_(kWaitingForInit), - host_(NULL) { + : state_(kWaitingForInit) { } WebMStreamParser::~WebMStreamParser() {} -void WebMStreamParser::Init(const InitCB& init_cb, StreamParserHost* host) { +void WebMStreamParser::Init(const InitCB& init_cb, + const NewConfigCB& config_cb, + const NewBuffersCB& audio_cb, + const NewBuffersCB& video_cb) { DCHECK_EQ(state_, kWaitingForInit); DCHECK(init_cb_.is_null()); - DCHECK(!host_); DCHECK(!init_cb.is_null()); - DCHECK(host); + DCHECK(!config_cb.is_null()); + DCHECK(!audio_cb.is_null() || !video_cb.is_null()); ChangeState(kParsingHeaders); init_cb_ = init_cb; - host_ = host; + config_cb_ = config_cb; + audio_cb_ = audio_cb; + video_cb_ = video_cb; } void WebMStreamParser::Flush() { @@ -328,8 +332,7 @@ int WebMStreamParser::ParseInfoAndTracks(const uint8* data, int size) { if (!config_helper.Parse(data, bytes_parsed)) return -1; - host_->OnNewConfigs(config_helper.audio_config(), - config_helper.video_config()); + config_cb_.Run(config_helper.audio_config(),config_helper.video_config()); cluster_parser_.reset(new WebMClusterParser( info_parser.timecode_scale(), @@ -372,15 +375,13 @@ int WebMStreamParser::ParseCluster(const uint8* data, int size) { if (bytes_parsed <= 0) return bytes_parsed; - const StreamParserHost::BufferQueue& audio_buffers = - cluster_parser_->audio_buffers(); - const StreamParserHost::BufferQueue& video_buffers = - cluster_parser_->video_buffers(); + const BufferQueue& audio_buffers = cluster_parser_->audio_buffers(); + const BufferQueue& video_buffers = cluster_parser_->video_buffers(); - if (!audio_buffers.empty() && !host_->OnAudioBuffers(audio_buffers)) + if (!audio_buffers.empty() && !audio_cb_.Run(audio_buffers)) return -1; - if (!video_buffers.empty() && !host_->OnVideoBuffers(video_buffers)) + if (!video_buffers.empty() && !video_cb_.Run(video_buffers)) return -1; return bytes_parsed; diff --git a/media/webm/webm_stream_parser.h b/media/webm/webm_stream_parser.h index 699b469..0311297 100644 --- a/media/webm/webm_stream_parser.h +++ b/media/webm/webm_stream_parser.h @@ -22,7 +22,9 @@ class WebMStreamParser : public StreamParser { virtual ~WebMStreamParser(); // StreamParser implementation. - virtual void Init(const InitCB& init_cb, StreamParserHost* host) OVERRIDE; + virtual void Init(const InitCB& init_cb, const NewConfigCB& config_cb, + const NewBuffersCB& audio_cb, + const NewBuffersCB& video_cb) OVERRIDE; virtual void Flush() OVERRIDE; virtual bool Parse(const uint8* buf, int size) OVERRIDE; @@ -57,7 +59,9 @@ class WebMStreamParser : public StreamParser { State state_; InitCB init_cb_; - StreamParserHost* host_; + NewConfigCB config_cb_; + NewBuffersCB audio_cb_; + NewBuffersCB video_cb_; scoped_ptr<WebMClusterParser> cluster_parser_; ByteQueue byte_queue_; |