diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-01 22:07:28 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-01 22:07:28 +0000 |
commit | f32a8b30d6a18fa29e0a9ee5596eeae620a76599 (patch) | |
tree | 13d137d1bb6f9edf1ae92f872bc1266e850c3f46 /media | |
parent | e6244c185ebd639ceb81a052a4b2037313baf24d (diff) | |
download | chromium_src-f32a8b30d6a18fa29e0a9ee5596eeae620a76599.zip chromium_src-f32a8b30d6a18fa29e0a9ee5596eeae620a76599.tar.gz chromium_src-f32a8b30d6a18fa29e0a9ee5596eeae620a76599.tar.bz2 |
Change DemuxerStream::ReadCallback to use ref-counted buffers.
Previously callbackees had to remember to store the buffer in a scoped_refptr<>.
Review URL: http://codereview.chromium.org/8351045
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108178 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/base/demuxer_stream.h | 8 | ||||
-rw-r--r-- | media/base/mock_reader.h | 2 | ||||
-rw-r--r-- | media/filters/chunk_demuxer.cc | 5 | ||||
-rw-r--r-- | media/filters/chunk_demuxer_unittest.cc | 5 | ||||
-rw-r--r-- | media/filters/ffmpeg_audio_decoder.cc | 7 | ||||
-rw-r--r-- | media/filters/ffmpeg_audio_decoder.h | 2 | ||||
-rw-r--r-- | media/filters/ffmpeg_demuxer_unittest.cc | 2 | ||||
-rw-r--r-- | media/filters/ffmpeg_video_decoder.cc | 9 | ||||
-rw-r--r-- | media/filters/ffmpeg_video_decoder.h | 8 |
9 files changed, 22 insertions, 26 deletions
diff --git a/media/base/demuxer_stream.h b/media/base/demuxer_stream.h index 07dfe71..9ba4960 100644 --- a/media/base/demuxer_stream.h +++ b/media/base/demuxer_stream.h @@ -20,8 +20,6 @@ class VideoDecoderConfig; class MEDIA_EXPORT DemuxerStream : public base::RefCountedThreadSafe<DemuxerStream> { public: - typedef base::Callback<void(Buffer*)> ReadCallback; - enum Type { UNKNOWN, AUDIO, @@ -29,8 +27,10 @@ class MEDIA_EXPORT DemuxerStream NUM_TYPES, // Always keep this entry as the last one! }; - // Schedules a read. When the |read_callback| is called, the downstream - // object takes ownership of the buffer by AddRef()'ing the buffer. + // Request a buffer to returned via the provided callback. + // + // Buffers will be non-NULL yet may be end of stream buffers. + typedef base::Callback<void(scoped_refptr<Buffer>)> ReadCallback; virtual void Read(const ReadCallback& read_callback) = 0; // Returns the audio decoder configuration. It is an error to call this method diff --git a/media/base/mock_reader.h b/media/base/mock_reader.h index c8a5e8c..a6122a9 100644 --- a/media/base/mock_reader.h +++ b/media/base/mock_reader.h @@ -50,7 +50,7 @@ class MockReader bool expecting_call() { return expecting_call_; } private: - void OnReadComplete(BufferType* buffer) { + void OnReadComplete(const scoped_refptr<BufferType>& buffer) { DCHECK(!called_); DCHECK(expecting_call_); expecting_call_ = false; diff --git a/media/filters/chunk_demuxer.cc b/media/filters/chunk_demuxer.cc index 33da332..8762003 100644 --- a/media/filters/chunk_demuxer.cc +++ b/media/filters/chunk_demuxer.cc @@ -224,11 +224,10 @@ bool ChunkDemuxerStream::GetLastBufferTimestamp( // Helper function that makes sure |read_callback| runs on |message_loop|. static void RunOnMessageLoop(const DemuxerStream::ReadCallback& read_callback, MessageLoop* message_loop, - Buffer* buffer) { + const scoped_refptr<Buffer>& buffer) { if (MessageLoop::current() != message_loop) { message_loop->PostTask(FROM_HERE, base::Bind( - &RunOnMessageLoop, read_callback, message_loop, - scoped_refptr<Buffer>(buffer))); + &RunOnMessageLoop, read_callback, message_loop, buffer)); return; } diff --git a/media/filters/chunk_demuxer_unittest.cc b/media/filters/chunk_demuxer_unittest.cc index dd3dbd98..dc99422 100644 --- a/media/filters/chunk_demuxer_unittest.cc +++ b/media/filters/chunk_demuxer_unittest.cc @@ -279,7 +279,7 @@ TEST_F(ChunkDemuxerTest, TestAppendDataBeforeInit) { static void OnReadDone(const base::TimeDelta& expected_time, bool* called, - Buffer* buffer) { + const scoped_refptr<Buffer>& buffer) { EXPECT_EQ(expected_time, buffer->GetTimestamp()); *called = true; } @@ -538,7 +538,8 @@ class EndOfStreamHelper { } private: - static void OnEndOfStreamReadDone(bool* called, Buffer* buffer) { + static void OnEndOfStreamReadDone(bool* called, + const scoped_refptr<Buffer>& buffer) { EXPECT_TRUE(buffer->IsEndOfStream()); *called = true; } diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc index f2ac089..3a0ab34 100644 --- a/media/filters/ffmpeg_audio_decoder.cc +++ b/media/filters/ffmpeg_audio_decoder.cc @@ -250,13 +250,10 @@ void FFmpegAudioDecoder::ReadFromDemuxerStream() { demuxer_stream_->Read(base::Bind(&FFmpegAudioDecoder::DecodeBuffer, this)); } -void FFmpegAudioDecoder::DecodeBuffer(Buffer* buffer) { - // TODO(scherkus): change DemuxerStream::Read() to use scoped_refptr<> for - // callback. - scoped_refptr<Buffer> ref_buffer(buffer); +void FFmpegAudioDecoder::DecodeBuffer(const scoped_refptr<Buffer>& buffer) { message_loop_->PostTask( FROM_HERE, - base::Bind(&FFmpegAudioDecoder::DoDecodeBuffer, this, ref_buffer)); + base::Bind(&FFmpegAudioDecoder::DoDecodeBuffer, this, buffer)); } void FFmpegAudioDecoder::UpdateDurationAndTimestamp( diff --git a/media/filters/ffmpeg_audio_decoder.h b/media/filters/ffmpeg_audio_decoder.h index f961f40..3f33abf 100644 --- a/media/filters/ffmpeg_audio_decoder.h +++ b/media/filters/ffmpeg_audio_decoder.h @@ -43,7 +43,7 @@ class MEDIA_EXPORT FFmpegAudioDecoder : public AudioDecoder { // Reads from the demuxer stream with corresponding callback method. void ReadFromDemuxerStream(); - void DecodeBuffer(Buffer* buffer); + void DecodeBuffer(const scoped_refptr<Buffer>& buffer); // Updates the output buffer's duration and timestamp based on the input // buffer. Will fall back to an estimated timestamp if the input lacks a diff --git a/media/filters/ffmpeg_demuxer_unittest.cc b/media/filters/ffmpeg_demuxer_unittest.cc index 4af3060..b07b8ac 100644 --- a/media/filters/ffmpeg_demuxer_unittest.cc +++ b/media/filters/ffmpeg_demuxer_unittest.cc @@ -389,7 +389,7 @@ class MockReadCallback : public base::RefCountedThreadSafe<MockReadCallback> { } MOCK_METHOD0(OnDelete, void()); - MOCK_METHOD1(Run, void(Buffer* buffer)); + MOCK_METHOD1(Run, void(const scoped_refptr<Buffer>& buffer)); private: DISALLOW_COPY_AND_ASSIGN(MockReadCallback); diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc index deb0bf3..9be1247 100644 --- a/media/filters/ffmpeg_video_decoder.cc +++ b/media/filters/ffmpeg_video_decoder.cc @@ -175,13 +175,13 @@ void FFmpegVideoDecoder::OnError() { VideoFrameReady(NULL); } -void FFmpegVideoDecoder::OnReadComplete(Buffer* buffer_in) { - scoped_refptr<Buffer> buffer(buffer_in); +void FFmpegVideoDecoder::OnReadComplete(const scoped_refptr<Buffer>& buffer) { message_loop_->PostTask(FROM_HERE, base::Bind( &FFmpegVideoDecoder::OnReadCompleteTask, this, buffer)); } -void FFmpegVideoDecoder::OnReadCompleteTask(scoped_refptr<Buffer> buffer) { +void FFmpegVideoDecoder::OnReadCompleteTask( + const scoped_refptr<Buffer>& buffer) { DCHECK_EQ(MessageLoop::current(), message_loop_); DCHECK_NE(state_, kStopped); // because of Flush() before Stop(). @@ -293,8 +293,7 @@ void FFmpegVideoDecoder::ProduceVideoSample( DCHECK_EQ(MessageLoop::current(), message_loop_); DCHECK_NE(state_, kStopped); - demuxer_stream_->Read(base::Bind(&FFmpegVideoDecoder::OnReadComplete, - this)); + demuxer_stream_->Read(base::Bind(&FFmpegVideoDecoder::OnReadComplete, this)); } gfx::Size FFmpegVideoDecoder::natural_size() { diff --git a/media/filters/ffmpeg_video_decoder.h b/media/filters/ffmpeg_video_decoder.h index 5e1ba1a..ef47977 100644 --- a/media/filters/ffmpeg_video_decoder.h +++ b/media/filters/ffmpeg_video_decoder.h @@ -64,11 +64,11 @@ class MEDIA_EXPORT FFmpegVideoDecoder void OnFlushComplete(const base::Closure& callback); void OnSeekComplete(const base::Closure& callback); - void OnReadComplete(Buffer* buffer); - // TODO(jiesun): until demuxer pass scoped_refptr<Buffer>: we could not merge - // this with OnReadComplete - void OnReadCompleteTask(scoped_refptr<Buffer> buffer); + // TODO(scherkus): There are two of these to keep read completions + // asynchronous and media_unittests passing. Remove. + void OnReadComplete(const scoped_refptr<Buffer>& buffer); + void OnReadCompleteTask(const scoped_refptr<Buffer>& buffer); // Flush the output buffers that we had held in Paused state. void FlushBuffers(); |