diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-05 08:34:49 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-05 08:34:49 +0000 |
commit | c3c9af1cbf896627bc9dfcc224ee83c23b79b6be (patch) | |
tree | eb2170260e899732a17df200d79f3fe1e7c1fff2 /media | |
parent | bfe0d724ef301309eceb431767658f4cbe7b08c1 (diff) | |
download | chromium_src-c3c9af1cbf896627bc9dfcc224ee83c23b79b6be.zip chromium_src-c3c9af1cbf896627bc9dfcc224ee83c23b79b6be.tar.gz chromium_src-c3c9af1cbf896627bc9dfcc224ee83c23b79b6be.tar.bz2 |
Rename all FillThisBuffer and EmptyThisBuffer to something more meaningful
The FillThisBuffer and EmptyThisBuffer names are very confusing. Anyone
new working on the code probably won't understand the code at all. I'm changing
the names to something more meaningful, which state the actual action taken by
the methods. It is also easier to tell whether the method is for input pin or
for output pin by their names.
Review URL: http://codereview.chromium.org/3201013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58604 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
27 files changed, 223 insertions, 175 deletions
diff --git a/media/base/filters.h b/media/base/filters.h index 62fab2d..0fdf6cf 100644 --- a/media/base/filters.h +++ b/media/base/filters.h @@ -33,6 +33,7 @@ #include "base/time.h" #include "base/scoped_ptr.h" #include "media/base/media_format.h" +#include "media/base/video_frame.h" namespace media { @@ -40,7 +41,6 @@ class Buffer; class Decoder; class DemuxerStream; class FilterHost; -class VideoFrame; class WritableBuffer; // Identifies the type of filter implementation. Used in conjunction with some @@ -292,24 +292,28 @@ class VideoDecoder : public MediaFilter { // |set_fill_buffer_done_callback| install permanent callback from downstream // filter (i.e. Renderer). The callback is used to deliver video frames at // runtime to downstream filter - typedef Callback1<scoped_refptr<VideoFrame> >::Type FillBufferDoneCallback; - void set_fill_buffer_done_callback(FillBufferDoneCallback* callback) { - fill_buffer_done_callback_.reset(callback); - } - FillBufferDoneCallback* fill_buffer_done_callback() { - return fill_buffer_done_callback_.get(); + typedef Callback1<scoped_refptr<VideoFrame> >::Type ConsumeVideoFrameCallback; + void set_consume_video_frame_callback(ConsumeVideoFrameCallback* callback) { + consume_video_frame_callback_.reset(callback); } - // Render provides an output buffer for Decoder to write to. These buffers - // will be recycled to renderer by fill_buffer_done_callback_; + // Renderer provides an output buffer for Decoder to write to. These buffers + // will be recycled to renderer by |fill_buffer_done_callback_|. // We could also pass empty pointer here to let decoder provide buffers pool. - virtual void FillThisBuffer(scoped_refptr<VideoFrame> frame) = 0; + virtual void ProduceVideoFrame(scoped_refptr<VideoFrame> frame) = 0; // Indicate whether decoder provides its own output buffers virtual bool ProvidesBuffer() = 0; + protected: + // A video frame is ready to be consumed. This method invoke + // |consume_video_frame_callback_| internally. + void VideoFrameReady(scoped_refptr<VideoFrame> frame) { + consume_video_frame_callback_->Run(frame); + } + private: - scoped_ptr<FillBufferDoneCallback> fill_buffer_done_callback_; + scoped_ptr<ConsumeVideoFrameCallback> consume_video_frame_callback_; }; @@ -333,21 +337,22 @@ class AudioDecoder : public MediaFilter { // |set_fill_buffer_done_callback| install permanent callback from downstream // filter (i.e. Renderer). The callback is used to deliver buffers at // runtime to downstream filter. - typedef Callback1<scoped_refptr<Buffer> >::Type FillBufferDoneCallback; - void set_fill_buffer_done_callback(FillBufferDoneCallback* callback) { - fill_buffer_done_callback_.reset(callback); + typedef Callback1<scoped_refptr<Buffer> >::Type ConsumeAudioSamplesCallback; + void set_consume_audio_samples_callback( + ConsumeAudioSamplesCallback* callback) { + consume_audio_samples_callback_.reset(callback); } - FillBufferDoneCallback* fill_buffer_done_callback() { - return fill_buffer_done_callback_.get(); + ConsumeAudioSamplesCallback* consume_audio_samples_callback() { + return consume_audio_samples_callback_.get(); } - // Render provides an output buffer for Decoder to write to. These buffers + // Renderer provides an output buffer for Decoder to write to. These buffers // will be recycled to renderer by fill_buffer_done_callback_; // We could also pass empty pointer here to let decoder provide buffers pool. - virtual void FillThisBuffer(scoped_refptr<Buffer> buffer) = 0; + virtual void ProduceAudioSamples(scoped_refptr<Buffer> buffer) = 0; private: - scoped_ptr<FillBufferDoneCallback> fill_buffer_done_callback_; + scoped_ptr<ConsumeAudioSamplesCallback> consume_audio_samples_callback_; }; diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h index 6438916..fe5a58d 100644 --- a/media/base/mock_filters.h +++ b/media/base/mock_filters.h @@ -172,9 +172,14 @@ class MockVideoDecoder : public VideoDecoder { MOCK_METHOD2(Initialize, void(DemuxerStream* stream, FilterCallback* callback)); MOCK_METHOD0(media_format, const MediaFormat&()); - MOCK_METHOD1(FillThisBuffer, void(scoped_refptr<VideoFrame>)); + MOCK_METHOD1(ProduceVideoFrame, void(scoped_refptr<VideoFrame>)); MOCK_METHOD0(ProvidesBuffer, bool()); + // Make this method public so that tests can make use of it. + void VideoFrameReady(scoped_refptr<VideoFrame> frame) { + VideoDecoder::VideoFrameReady(frame); + } + protected: virtual ~MockVideoDecoder() {} @@ -196,11 +201,11 @@ class MockAudioDecoder : public AudioDecoder { MOCK_METHOD2(Initialize, void(DemuxerStream* stream, FilterCallback* callback)); MOCK_METHOD0(media_format, const MediaFormat&()); - MOCK_METHOD1(FillThisBuffer, void(scoped_refptr<Buffer>)); + MOCK_METHOD1(ProduceAudioSamples, void(scoped_refptr<Buffer>)); // change to public to allow unittest for access; - FillBufferDoneCallback* fill_buffer_done_callback() { - return AudioDecoder::fill_buffer_done_callback(); + ConsumeAudioSamplesCallback* consume_audio_samples_callback() { + return AudioDecoder::consume_audio_samples_callback(); } protected: @@ -224,7 +229,7 @@ class MockVideoRenderer : public VideoRenderer { MOCK_METHOD2(Initialize, void(VideoDecoder* decoder, FilterCallback* callback)); MOCK_METHOD0(HasEnded, bool()); - MOCK_METHOD1(FillThisBufferDone, void(scoped_refptr<VideoFrame> frame)); + MOCK_METHOD1(ConsumeVideoFrame, void(scoped_refptr<VideoFrame> frame)); protected: virtual ~MockVideoRenderer() {} diff --git a/media/filters/audio_renderer_base.cc b/media/filters/audio_renderer_base.cc index c0690e8..ca0ee87 100644 --- a/media/filters/audio_renderer_base.cc +++ b/media/filters/audio_renderer_base.cc @@ -86,8 +86,8 @@ void AudioRendererBase::Initialize(AudioDecoder* decoder, scoped_ptr<FilterCallback> c(callback); decoder_ = decoder; - decoder_->set_fill_buffer_done_callback( - NewCallback(this, &AudioRendererBase::OnFillBufferDone)); + decoder_->set_consume_audio_samples_callback( + NewCallback(this, &AudioRendererBase::ConsumeAudioSamples)); // Get the media properties to initialize our algorithms. int channels = 0; int sample_rate = 0; @@ -135,7 +135,7 @@ bool AudioRendererBase::HasEnded() { return recieved_end_of_stream_ && rendered_end_of_stream_; } -void AudioRendererBase::OnFillBufferDone(scoped_refptr<Buffer> buffer_in) { +void AudioRendererBase::ConsumeAudioSamples(scoped_refptr<Buffer> buffer_in) { AutoLock auto_lock(lock_); DCHECK(state_ == kPaused || state_ == kSeeking || state_ == kPlaying); DCHECK_GT(pending_reads_, 0u); @@ -247,7 +247,7 @@ void AudioRendererBase::ScheduleRead_Locked() { // provide buffer pools. In the future, we may want to implement real // buffer pool to recycle buffers. scoped_refptr<Buffer> buffer; - decoder_->FillThisBuffer(buffer); + decoder_->ProduceAudioSamples(buffer); } // static diff --git a/media/filters/audio_renderer_base.h b/media/filters/audio_renderer_base.h index fc9cac6..783a8ba 100644 --- a/media/filters/audio_renderer_base.h +++ b/media/filters/audio_renderer_base.h @@ -57,7 +57,7 @@ class AudioRendererBase : public AudioRenderer { // Called when a AudioDecoder completes decoding and decrements // |pending_reads_|. - virtual void OnFillBufferDone(scoped_refptr<Buffer> buffer_in); + virtual void ConsumeAudioSamples(scoped_refptr<Buffer> buffer_in); // Fills the given buffer with audio data by delegating to its |algorithm_|. // FillBuffer() also takes care of updating the clock. Returns the number of diff --git a/media/filters/audio_renderer_base_unittest.cc b/media/filters/audio_renderer_base_unittest.cc index 20d2912..3c25b77 100644 --- a/media/filters/audio_renderer_base_unittest.cc +++ b/media/filters/audio_renderer_base_unittest.cc @@ -54,7 +54,7 @@ class AudioRendererBaseTest : public ::testing::Test { renderer_->set_host(&host_); // Queue all reads from the decoder. - EXPECT_CALL(*decoder_, FillThisBuffer(_)) + EXPECT_CALL(*decoder_, ProduceAudioSamples(_)) .WillRepeatedly(Invoke(this, &AudioRendererBaseTest::EnqueueCallback)); // Sets the essential media format keys for this decoder. @@ -152,7 +152,7 @@ TEST_F(AudioRendererBaseTest, Initialize_Successful) { scoped_refptr<DataBuffer> buffer = new DataBuffer(1024); buffer->SetDataSize(1024); --pending_reads_; - decoder_->fill_buffer_done_callback()->Run(buffer); + decoder_->consume_audio_samples_callback()->Run(buffer); } } @@ -192,7 +192,7 @@ TEST_F(AudioRendererBaseTest, OneCompleteReadCycle) { while (pending_reads_) { scoped_refptr<DataBuffer> buffer = new DataBuffer(kDataSize); buffer->SetDataSize(kDataSize); - decoder_->fill_buffer_done_callback()->Run(buffer); + decoder_->consume_audio_samples_callback()->Run(buffer); --pending_reads_; bytes_buffered += kDataSize; } @@ -219,7 +219,7 @@ TEST_F(AudioRendererBaseTest, OneCompleteReadCycle) { // Fulfill the read with an end-of-stream packet. scoped_refptr<DataBuffer> last_buffer = new DataBuffer(0); - decoder_->fill_buffer_done_callback()->Run(last_buffer); + decoder_->consume_audio_samples_callback()->Run(last_buffer); --pending_reads_; // We shouldn't report ended until all data has been flushed out. diff --git a/media/filters/decoder_base.h b/media/filters/decoder_base.h index 9e806b3..60245ed 100644 --- a/media/filters/decoder_base.h +++ b/media/filters/decoder_base.h @@ -50,8 +50,10 @@ class DecoderBase : public Decoder { virtual const MediaFormat& media_format() { return media_format_; } - // Audio or video decoder. - virtual void FillThisBuffer(scoped_refptr<Output> output) { + // Audio decoder. + // Note that this class is only used by the audio decoder, this will + // eventually be merged into FFmpegAudioDecoder. + virtual void ProduceAudioSamples(scoped_refptr<Output> output) { this->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &DecoderBase::ReadTask, output)); } @@ -277,7 +279,11 @@ class DecoderBase : public Decoder { // Execute the callback! --pending_requests_; - Decoder::fill_buffer_done_callback()->Run(output); + + // TODO(hclam): We only inherit this class from FFmpegAudioDecoder so we + // are making this call. We should correct this by merging this class into + // FFmpegAudioDecoder. + Decoder::consume_audio_samples_callback()->Run(output); return true; } diff --git a/media/filters/decoder_base_unittest.cc b/media/filters/decoder_base_unittest.cc index 19ba820..ec80915 100644 --- a/media/filters/decoder_base_unittest.cc +++ b/media/filters/decoder_base_unittest.cc @@ -42,14 +42,15 @@ class MockBuffer : public media::Buffer { class MockDecoder : public media::MediaFilter { public: typedef Callback1<scoped_refptr<MockDecoderOutput> >::Type - FillBufferDoneCallback; - void set_fill_buffer_done_callback_(FillBufferDoneCallback* callback) { - fill_buffer_done_callback_.reset(callback); + ConsumeAudioSamplesCallback; + void set_consume_audio_samples_callback( + ConsumeAudioSamplesCallback* callback) { + consume_audio_samples_callback_.reset(callback); } - FillBufferDoneCallback* fill_buffer_done_callback() { - return fill_buffer_done_callback_.get(); + ConsumeAudioSamplesCallback* consume_audio_samples_callback() { + return consume_audio_samples_callback_.get(); } - scoped_ptr<FillBufferDoneCallback> fill_buffer_done_callback_; + scoped_ptr<ConsumeAudioSamplesCallback> consume_audio_samples_callback_; }; class MockDecoderCallback { @@ -117,7 +118,7 @@ TEST(DecoderBaseTest, FlowControl) { MessageLoop message_loop; scoped_refptr<MockDecoderImpl> decoder = new MockDecoderImpl(); MockDecoderCallback read_callback; - decoder->set_fill_buffer_done_callback_( + decoder->set_consume_audio_samples_callback( NewCallback(&read_callback, &MockDecoderCallback::OnReadComplete)); scoped_refptr<MockDemuxerStream> demuxer_stream = new MockDemuxerStream(); StrictMock<MockFilterCallback> callback; @@ -140,8 +141,8 @@ TEST(DecoderBaseTest, FlowControl) { .Times(2) .WillRepeatedly(SaveDecodeRequest(&decode_requests)); scoped_refptr<MockDecoderOutput> output; - decoder->FillThisBuffer(output); - decoder->FillThisBuffer(output); + decoder->ProduceAudioSamples(output); + decoder->ProduceAudioSamples(output); message_loop.RunAllPending(); // Fulfill the decode request. diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc index f43d90b..ca509f9 100644 --- a/media/filters/ffmpeg_video_decoder.cc +++ b/media/filters/ffmpeg_video_decoder.cc @@ -284,17 +284,16 @@ void FFmpegVideoDecoder::OnReadCompleteTask(scoped_refptr<Buffer> buffer) { } // Otherwise, attempt to decode a single frame. - decode_engine_->EmptyThisBuffer(buffer); + decode_engine_->ConsumeVideoSample(buffer); } -void FFmpegVideoDecoder::FillThisBuffer( +void FFmpegVideoDecoder::ProduceVideoFrame( scoped_refptr<VideoFrame> video_frame) { if (MessageLoop::current() != message_loop()) { message_loop()->PostTask( FROM_HERE, NewRunnableMethod(this, - &FFmpegVideoDecoder::FillThisBuffer, - video_frame)); + &FFmpegVideoDecoder::ProduceVideoFrame, video_frame)); return; } @@ -308,16 +307,16 @@ void FFmpegVideoDecoder::FillThisBuffer( // Signal VideoRenderer the end of the stream event. scoped_refptr<VideoFrame> empty_frame; VideoFrame::CreateEmptyFrame(&empty_frame); - fill_buffer_done_callback()->Run(empty_frame); + VideoFrameReady(empty_frame); // Fall through, because we still need to keep record of this frame. } // Notify decode engine the available of new frame. - decode_engine_->FillThisBuffer(video_frame); + decode_engine_->ProduceVideoFrame(video_frame); } -void FFmpegVideoDecoder::OnFillBufferCallback( +void FFmpegVideoDecoder::ConsumeVideoFrame( scoped_refptr<VideoFrame> video_frame) { DCHECK_EQ(MessageLoop::current(), message_loop()); DCHECK_NE(state_, kStopped); @@ -337,7 +336,7 @@ void FFmpegVideoDecoder::OnFillBufferCallback( video_frame->SetTimestamp(last_pts_.timestamp); video_frame->SetDuration(last_pts_.duration); - fill_buffer_done_callback()->Run(video_frame); + VideoFrameReady(video_frame); } else { // When in kFlushCodec, any errored decode, or a 0-lengthed frame, // is taken as a signal to stop decoding. @@ -347,12 +346,12 @@ void FFmpegVideoDecoder::OnFillBufferCallback( // Signal VideoRenderer the end of the stream event. scoped_refptr<VideoFrame> video_frame; VideoFrame::CreateEmptyFrame(&video_frame); - fill_buffer_done_callback()->Run(video_frame); + VideoFrameReady(video_frame); } } } -void FFmpegVideoDecoder::OnEmptyBufferCallback( +void FFmpegVideoDecoder::ProduceVideoSample( scoped_refptr<Buffer> buffer) { DCHECK_EQ(MessageLoop::current(), message_loop()); DCHECK_NE(state_, kStopped); @@ -424,9 +423,9 @@ void FFmpegVideoDecoder::FlushBuffers() { // Depends on who own the buffers, we either return it to the renderer // or return it to the decode engine. if (ProvidesBuffer()) - decode_engine_->FillThisBuffer(video_frame); + decode_engine_->ProduceVideoFrame(video_frame); else - fill_buffer_done_callback()->Run(video_frame); + VideoFrameReady(video_frame); } } diff --git a/media/filters/ffmpeg_video_decoder.h b/media/filters/ffmpeg_video_decoder.h index 8a9e5e5..d099892 100644 --- a/media/filters/ffmpeg_video_decoder.h +++ b/media/filters/ffmpeg_video_decoder.h @@ -42,7 +42,7 @@ class FFmpegVideoDecoder : public VideoDecoder, virtual void Initialize(DemuxerStream* demuxer_stream, FilterCallback* callback); virtual const MediaFormat& media_format() { return media_format_; } - virtual void FillThisBuffer(scoped_refptr<VideoFrame> video_frame); + virtual void ProduceVideoFrame(scoped_refptr<VideoFrame> video_frame); virtual bool ProvidesBuffer(); private: @@ -53,8 +53,8 @@ class FFmpegVideoDecoder : public VideoDecoder, virtual void OnSeekComplete(); virtual void OnError(); virtual void OnFormatChange(VideoStreamInfo stream_info); - virtual void OnEmptyBufferCallback(scoped_refptr<Buffer> buffer); - virtual void OnFillBufferCallback(scoped_refptr<VideoFrame> frame); + virtual void ProduceVideoSample(scoped_refptr<Buffer> buffer); + virtual void ConsumeVideoFrame(scoped_refptr<VideoFrame> frame); friend class FilterFactoryImpl1<FFmpegVideoDecoder, VideoDecodeEngine*>; friend class DecoderPrivateMock; diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc index b1bd481..381b277 100644 --- a/media/filters/ffmpeg_video_decoder_unittest.cc +++ b/media/filters/ffmpeg_video_decoder_unittest.cc @@ -47,13 +47,14 @@ class MockFFmpegDemuxerStream : public MockDemuxerStream, DISALLOW_COPY_AND_ASSIGN(MockFFmpegDemuxerStream); }; +// TODO(hclam): Share this in a separate file. class MockVideoDecodeEngine : public VideoDecodeEngine { public: MOCK_METHOD3(Initialize, void(MessageLoop* message_loop, VideoDecodeEngine::EventHandler* event_handler, const VideoCodecConfig& config)); - MOCK_METHOD1(EmptyThisBuffer, void(scoped_refptr<Buffer> buffer)); - MOCK_METHOD1(FillThisBuffer, void(scoped_refptr<VideoFrame> buffer)); + MOCK_METHOD1(ConsumeVideoSample, void(scoped_refptr<Buffer> buffer)); + MOCK_METHOD1(ProduceVideoFrame, void(scoped_refptr<VideoFrame> buffer)); MOCK_METHOD0(Uninitialize, void()); MOCK_METHOD0(Flush, void()); MOCK_METHOD0(Seek, void()); @@ -73,11 +74,11 @@ class DecoderPrivateMock : public FFmpegVideoDecoder { } // change access qualifier for test: used in actions. - void OnEmptyBufferCallback(scoped_refptr<Buffer> buffer) { - FFmpegVideoDecoder::OnEmptyBufferCallback(buffer); + void ProduceVideoSample(scoped_refptr<Buffer> buffer) { + FFmpegVideoDecoder::ProduceVideoSample(buffer); } - void OnFillBufferCallback(scoped_refptr<VideoFrame> frame) { - FFmpegVideoDecoder::OnFillBufferCallback(frame); + void ConsumeVideoFrame(scoped_refptr<VideoFrame> frame) { + FFmpegVideoDecoder::ConsumeVideoFrame(frame); } void OnReadComplete(Buffer* buffer) { FFmpegVideoDecoder::OnReadComplete(buffer); @@ -366,7 +367,7 @@ TEST_F(FFmpegVideoDecoderTest, FindPtsAndDuration) { } ACTION_P2(ReadFromDemux, decoder, buffer) { - decoder->OnEmptyBufferCallback(buffer); + decoder->ProduceVideoSample(buffer); } ACTION_P3(ReturnFromDemux, decoder, buffer, time_tuple) { @@ -379,14 +380,14 @@ ACTION_P3(ReturnFromDemux, decoder, buffer, time_tuple) { ACTION_P3(DecodeComplete, decoder, video_frame, time_tuple) { video_frame->SetTimestamp(time_tuple.timestamp); video_frame->SetDuration(time_tuple.duration); - decoder->OnFillBufferCallback(video_frame); + decoder->ConsumeVideoFrame(video_frame); } ACTION_P2(DecodeNotComplete, decoder, buffer) { scoped_refptr<VideoFrame> null_frame; if (buffer->IsEndOfStream()) // We had started flushing. - decoder->OnFillBufferCallback(null_frame); + decoder->ConsumeVideoFrame(null_frame); else - decoder->OnEmptyBufferCallback(buffer); + decoder->ProduceVideoSample(buffer); } ACTION_P(ConsumePTS, pts_heap) { @@ -406,8 +407,8 @@ TEST_F(FFmpegVideoDecoderTest, DoDecode_TestStateTransition) { // 5) All state transitions happen as expected. InitializeDecoderSuccessfully(); - decoder_->set_fill_buffer_done_callback( - NewCallback(renderer_.get(), &MockVideoRenderer::FillThisBufferDone)); + decoder_->set_consume_video_frame_callback( + NewCallback(renderer_.get(), &MockVideoRenderer::ConsumeVideoFrame)); // Setup initial state and check that it is sane. ASSERT_EQ(FFmpegVideoDecoder::kNormal, decoder_->state_); @@ -416,7 +417,7 @@ TEST_F(FFmpegVideoDecoderTest, DoDecode_TestStateTransition) { // Setup decoder to buffer one frame, decode one frame, fail one frame, // decode one more, and then fail the last one to end decoding. - EXPECT_CALL(*engine_, FillThisBuffer(_)) + EXPECT_CALL(*engine_, ProduceVideoFrame(_)) .Times(4) .WillRepeatedly(ReadFromDemux(decoder_.get(), buffer_)); EXPECT_CALL(*demuxer_.get(), Read(_)) @@ -430,20 +431,20 @@ TEST_F(FFmpegVideoDecoderTest, DoDecode_TestStateTransition) { end_of_stream_buffer_, kTestPts3)) .WillOnce(ReturnFromDemux(decoder_.get(), end_of_stream_buffer_, kTestPts3)); - EXPECT_CALL(*engine_, EmptyThisBuffer(_)) + EXPECT_CALL(*engine_, ConsumeVideoSample(_)) .WillOnce(DecodeNotComplete(decoder_.get(), buffer_)) .WillOnce(DecodeComplete(decoder_.get(), video_frame_, kTestPts1)) .WillOnce(DecodeNotComplete(decoder_.get(), buffer_)) .WillOnce(DecodeComplete(decoder_.get(), video_frame_, kTestPts2)) .WillOnce(DecodeComplete(decoder_.get(), video_frame_, kTestPts3)) .WillOnce(DecodeNotComplete(decoder_.get(), end_of_stream_buffer_)); - EXPECT_CALL(*renderer_.get(), FillThisBufferDone(_)) + EXPECT_CALL(*renderer_.get(), ConsumeVideoFrame(_)) .Times(4); // First request from renderer: at first round decode engine did not produce // any frame. Decoder will issue another read from demuxer. at second round // decode engine will get a valid frame. - decoder_->FillThisBuffer(video_frame_); + decoder_->ProduceVideoFrame(video_frame_); message_loop_.RunAllPending(); EXPECT_EQ(FFmpegVideoDecoder::kNormal, decoder_->state_); ASSERT_TRUE(kTestPts1.timestamp == decoder_->last_pts_.timestamp); @@ -453,7 +454,7 @@ TEST_F(FFmpegVideoDecoderTest, DoDecode_TestStateTransition) { // Second request from renderer: at first round decode engine did not produce // any frame. Decoder will issue another read from demuxer. at second round // decode engine will get a valid frame. - decoder_->FillThisBuffer(video_frame_); + decoder_->ProduceVideoFrame(video_frame_); message_loop_.RunAllPending(); EXPECT_EQ(FFmpegVideoDecoder::kFlushCodec, decoder_->state_); EXPECT_TRUE(kTestPts2.timestamp == decoder_->last_pts_.timestamp); @@ -463,7 +464,7 @@ TEST_F(FFmpegVideoDecoderTest, DoDecode_TestStateTransition) { // Third request from renderer: decode engine will return frame on the // first round. Input stream had reach EOS, therefore we had entered // kFlushCodec state after this call. - decoder_->FillThisBuffer(video_frame_); + decoder_->ProduceVideoFrame(video_frame_); message_loop_.RunAllPending(); EXPECT_EQ(FFmpegVideoDecoder::kFlushCodec, decoder_->state_); EXPECT_TRUE(kTestPts3.timestamp == decoder_->last_pts_.timestamp); @@ -472,7 +473,7 @@ TEST_F(FFmpegVideoDecoderTest, DoDecode_TestStateTransition) { // Fourth request from renderer: Both input/output reach EOF. therefore // we had reached the kDecodeFinished state after this call. - decoder_->FillThisBuffer(video_frame_); + decoder_->ProduceVideoFrame(video_frame_); message_loop_.RunAllPending(); EXPECT_EQ(FFmpegVideoDecoder::kDecodeFinished, decoder_->state_); EXPECT_TRUE(kTestPts3.timestamp == decoder_->last_pts_.timestamp); diff --git a/media/filters/omx_video_decoder.cc b/media/filters/omx_video_decoder.cc index c450b43..adb2c9c 100644 --- a/media/filters/omx_video_decoder.cc +++ b/media/filters/omx_video_decoder.cc @@ -215,27 +215,24 @@ void OmxVideoDecoder::OnFormatChange(VideoStreamInfo stream_info) { NOTIMPLEMENTED(); } -void OmxVideoDecoder::OnEmptyBufferCallback(scoped_refptr<Buffer> buffer) { +void OmxVideoDecoder::ProduceVideoSample(scoped_refptr<Buffer> buffer) { DCHECK_EQ(message_loop(), MessageLoop::current()); // Issue more demux. demuxer_stream_->Read(NewCallback(this, &OmxVideoDecoder::DemuxCompleteTask)); } -void OmxVideoDecoder::OnFillBufferCallback(scoped_refptr<VideoFrame> frame) { +void OmxVideoDecoder::ConsumeVideoFrame(scoped_refptr<VideoFrame> frame) { DCHECK_EQ(message_loop(), MessageLoop::current()); - - // Invoke the FillBufferDoneCallback with the frame. - DCHECK(fill_buffer_done_callback()); - fill_buffer_done_callback()->Run(frame); + VideoFrameReady(frame); } -void OmxVideoDecoder::FillThisBuffer(scoped_refptr<VideoFrame> frame) { +void OmxVideoDecoder::ProduceVideoFrame(scoped_refptr<VideoFrame> frame) { DCHECK(omx_engine_.get()); message_loop()->PostTask( FROM_HERE, NewRunnableMethod(omx_engine_.get(), - &VideoDecodeEngine::FillThisBuffer, frame)); + &VideoDecodeEngine::ProduceVideoFrame, frame)); } bool OmxVideoDecoder::ProvidesBuffer() { @@ -250,7 +247,7 @@ void OmxVideoDecoder::DemuxCompleteTask(Buffer* buffer) { message_loop()->PostTask( FROM_HERE, NewRunnableMethod(omx_engine_.get(), - &VideoDecodeEngine::EmptyThisBuffer, ref_buffer)); + &VideoDecodeEngine::ConsumeVideoSample, ref_buffer)); } } // namespace media diff --git a/media/filters/omx_video_decoder.h b/media/filters/omx_video_decoder.h index c82d930..2a4f63c 100644 --- a/media/filters/omx_video_decoder.h +++ b/media/filters/omx_video_decoder.h @@ -33,7 +33,7 @@ class OmxVideoDecoder : public VideoDecoder, virtual void Stop(FilterCallback* callback); virtual void Flush(FilterCallback* callback); virtual void Seek(base::TimeDelta time, FilterCallback* callback); - virtual void FillThisBuffer(scoped_refptr<VideoFrame> frame); + virtual void ProduceVideoFrame(scoped_refptr<VideoFrame> frame); virtual bool ProvidesBuffer(); virtual const MediaFormat& media_format() { return media_format_; } @@ -45,8 +45,8 @@ class OmxVideoDecoder : public VideoDecoder, virtual void OnSeekComplete(); virtual void OnError(); virtual void OnFormatChange(VideoStreamInfo stream_info); - virtual void OnEmptyBufferCallback(scoped_refptr<Buffer> buffer); - virtual void OnFillBufferCallback(scoped_refptr<VideoFrame> frame); + virtual void ProduceVideoSample(scoped_refptr<Buffer> buffer); + virtual void ConsumeVideoFrame(scoped_refptr<VideoFrame> frame); // TODO(hclam): This is very ugly that we keep reference instead of // scoped_refptr. diff --git a/media/filters/video_renderer_base.cc b/media/filters/video_renderer_base.cc index c9ede3a..950020c 100644 --- a/media/filters/video_renderer_base.cc +++ b/media/filters/video_renderer_base.cc @@ -163,8 +163,8 @@ void VideoRendererBase::Initialize(VideoDecoder* decoder, decoder_ = decoder; AutoCallbackRunner done_runner(callback); - decoder_->set_fill_buffer_done_callback( - NewCallback(this, &VideoRendererBase::OnFillBufferDone)); + decoder_->set_consume_video_frame_callback( + NewCallback(this, &VideoRendererBase::ConsumeVideoFrame)); // Notify the pipeline of the video dimensions. if (!ParseMediaFormat(decoder->media_format(), &surface_type_, @@ -355,7 +355,7 @@ void VideoRendererBase::PutCurrentFrame(scoped_refptr<VideoFrame> frame) { FlushBuffers(); } -void VideoRendererBase::OnFillBufferDone(scoped_refptr<VideoFrame> frame) { +void VideoRendererBase::ConsumeVideoFrame(scoped_refptr<VideoFrame> frame) { AutoLock auto_lock(lock_); // Decoder could reach seek state before our Seek() get called. @@ -434,7 +434,7 @@ void VideoRendererBase::ReadInput(scoped_refptr<VideoFrame> frame) { // We should never return empty frames or EOS frame. DCHECK(frame.get() && !frame->IsEndOfStream()); - decoder_->FillThisBuffer(frame); + decoder_->ProduceVideoFrame(frame); ++pending_reads_; } diff --git a/media/filters/video_renderer_base.h b/media/filters/video_renderer_base.h index b41c51e..f27955f7 100644 --- a/media/filters/video_renderer_base.h +++ b/media/filters/video_renderer_base.h @@ -112,7 +112,7 @@ class VideoRendererBase : public VideoRenderer, private: // Callback from video decoder to deliver decoded video frames and decrements // |pending_reads_|. - void OnFillBufferDone(scoped_refptr<VideoFrame> frame); + void ConsumeVideoFrame(scoped_refptr<VideoFrame> frame); // Helper method that schedules an asynchronous read from the decoder and // increments |pending_reads_|. diff --git a/media/filters/video_renderer_base_unittest.cc b/media/filters/video_renderer_base_unittest.cc index 486c85e..e27e445 100644 --- a/media/filters/video_renderer_base_unittest.cc +++ b/media/filters/video_renderer_base_unittest.cc @@ -53,7 +53,7 @@ class VideoRendererBaseTest : public ::testing::Test { renderer_->set_host(&host_); // Queue all reads from the decoder. - EXPECT_CALL(*decoder_, FillThisBuffer(_)) + EXPECT_CALL(*decoder_, ProduceVideoFrame(_)) .WillRepeatedly(Invoke(this, &VideoRendererBaseTest::EnqueueCallback)); // Sets the essential media format keys for this decoder. @@ -204,7 +204,7 @@ TEST_F(VideoRendererBaseTest, Initialize_Successful) { scoped_refptr<VideoFrame> frame; VideoFrame::CreateFrame(VideoFrame::RGB32, kWidth, kHeight, kZero, kZero, &frame); - decoder_->fill_buffer_done_callback()->Run(frame); + decoder_->VideoFrameReady(frame); } MockFilterCallback play_callback; diff --git a/media/mf/mft_h264_decoder.cc b/media/mf/mft_h264_decoder.cc index 66d9015..c63cae0 100644 --- a/media/mf/mft_h264_decoder.cc +++ b/media/mf/mft_h264_decoder.cc @@ -241,10 +241,10 @@ void MftH264Decoder::Seek() { event_handler_->OnSeekComplete(); } -void MftH264Decoder::EmptyThisBuffer(scoped_refptr<Buffer> buffer) { - LOG(INFO) << "MftH264Decoder::EmptyThisBuffer"; +void MftH264Decoder::ConsumeVideoSample(scoped_refptr<Buffer> buffer) { + LOG(INFO) << "MftH264Decoder::ConsumeVideoSample"; if (state_ == kUninitialized) { - LOG(ERROR) << "EmptyThisBuffer: invalid state"; + LOG(ERROR) << "ConsumeVideoSample: invalid state"; } ScopedComPtr<IMFSample> sample; if (!buffer->IsEndOfStream()) { @@ -277,14 +277,14 @@ void MftH264Decoder::EmptyThisBuffer(scoped_refptr<Buffer> buffer) { DoDecode(); } -void MftH264Decoder::FillThisBuffer(scoped_refptr<VideoFrame> frame) { - LOG(INFO) << "MftH264Decoder::FillThisBuffer"; +void MftH264Decoder::ProduceVideoFrame(scoped_refptr<VideoFrame> frame) { + LOG(INFO) << "MftH264Decoder::ProduceVideoFrame"; if (state_ == kUninitialized) { - LOG(ERROR) << "FillThisBuffer: invalid state"; + LOG(ERROR) << "ProduceVideoFrame: invalid state"; return; } scoped_refptr<Buffer> buffer; - event_handler_->OnEmptyBufferCallback(buffer); + event_handler_->ProduceVideoSample(buffer); } // private methods @@ -606,7 +606,7 @@ bool MftH264Decoder::DoDecode() { // No more output from the decoder. Notify EOS and stop playback. scoped_refptr<VideoFrame> frame; VideoFrame::CreateEmptyFrame(&frame); - event_handler_->OnFillBufferCallback(frame); + event_handler_->ConsumeVideoFrame(frame); state_ = MftH264Decoder::kStopped; return false; } @@ -735,7 +735,7 @@ bool MftH264Decoder::DoDecode() { CHECK(SUCCEEDED(output_buffer->Unlock())); } // TODO(jiesun): non-System memory case - event_handler_->OnFillBufferCallback(frame); + event_handler_->ConsumeVideoFrame(frame); return true; } diff --git a/media/mf/mft_h264_decoder.h b/media/mf/mft_h264_decoder.h index b84ab97..450cc2b 100644 --- a/media/mf/mft_h264_decoder.h +++ b/media/mf/mft_h264_decoder.h @@ -43,8 +43,8 @@ class MftH264Decoder : public media::VideoDecodeEngine { virtual void Uninitialize(); virtual void Flush(); virtual void Seek(); - virtual void EmptyThisBuffer(scoped_refptr<Buffer> buffer); - virtual void FillThisBuffer(scoped_refptr<VideoFrame> frame); + virtual void ConsumeVideoSample(scoped_refptr<Buffer> buffer); + virtual void ProduceVideoFrame(scoped_refptr<VideoFrame> frame); bool use_dxva() const { return use_dxva_; } State state() const { return state_; } diff --git a/media/mf/mft_h264_decoder_example.cc b/media/mf/mft_h264_decoder_example.cc index 4f5cd64..0a10e07 100644 --- a/media/mf/mft_h264_decoder_example.cc +++ b/media/mf/mft_h264_decoder_example.cc @@ -150,16 +150,16 @@ class MftH264DecoderHandler virtual void OnFormatChange(VideoStreamInfo stream_info) { info_.stream_info_ = stream_info; } - virtual void OnEmptyBufferCallback(scoped_refptr<Buffer> buffer) { + virtual void ProduceVideoSample(scoped_refptr<Buffer> buffer) { if (reader_ && decoder_) { scoped_refptr<DataBuffer> input; reader_->Read(&input); if (!input->IsEndOfStream()) frames_read_++; - decoder_->EmptyThisBuffer(input); + decoder_->ConsumeVideoSample(input); } } - virtual void OnFillBufferCallback(scoped_refptr<VideoFrame> frame) { + virtual void ConsumeVideoFrame(scoped_refptr<VideoFrame> frame) { if (frame.get()) { if (frame->format() != VideoFrame::EMPTY) { frames_decoded_++; @@ -174,7 +174,7 @@ class MftH264DecoderHandler } virtual void DecodeSingleFrame() { scoped_refptr<VideoFrame> frame; - decoder_->FillThisBuffer(frame); + decoder_->ProduceVideoFrame(frame); } virtual void Start() { while (decoder_->state() != MftH264Decoder::kStopped) @@ -197,7 +197,7 @@ class RenderToWindowHandler : public MftH264DecoderHandler { has_output_(false) { } virtual ~RenderToWindowHandler() {} - virtual void OnFillBufferCallback(scoped_refptr<VideoFrame> frame) { + virtual void ConsumeVideoFrame(scoped_refptr<VideoFrame> frame) { has_output_ = true; if (frame.get()) { if (frame->format() != VideoFrame::EMPTY) { @@ -251,7 +251,7 @@ class RenderToWindowHandler : public MftH264DecoderHandler { if (decoder_->state() != MftH264Decoder::kStopped) { while (decoder_->state() != MftH264Decoder::kStopped && !has_output_) { scoped_refptr<VideoFrame> frame; - decoder_->FillThisBuffer(frame); + decoder_->ProduceVideoFrame(frame); } if (decoder_->state() == MftH264Decoder::kStopped) loop_->QuitNow(); diff --git a/media/mf/test/mft_h264_decoder_unittest.cc b/media/mf/test/mft_h264_decoder_unittest.cc index e805127..80ea7b1 100644 --- a/media/mf/test/mft_h264_decoder_unittest.cc +++ b/media/mf/test/mft_h264_decoder_unittest.cc @@ -127,15 +127,15 @@ class SimpleMftH264DecoderHandler : public VideoDecodeEngine::EventHandler { format_change_count_++; info_.stream_info_ = stream_info; } - virtual void OnEmptyBufferCallback(scoped_refptr<Buffer> buffer) { + virtual void ProduceVideoSample(scoped_refptr<Buffer> buffer) { if (reader_.get() && decoder_) { empty_buffer_callback_count_++; scoped_refptr<DataBuffer> input; reader_->ReadCallback(&input); - decoder_->EmptyThisBuffer(input); + decoder_->ConsumeVideoSample(input); } } - virtual void OnFillBufferCallback(scoped_refptr<VideoFrame> frame) { + virtual void ConsumeVideoFrame(scoped_refptr<VideoFrame> frame) { fill_buffer_callback_count_++; current_frame_ = frame; } @@ -279,7 +279,7 @@ TEST_F(MftH264DecoderTest, DrainOnEmptyBuffer) { // Decoder should switch to drain mode because of this NULL buffer, and then // switch to kStopped when it says it needs more input during drain mode. - decoder->EmptyThisBuffer(buffer); + decoder->ConsumeVideoSample(buffer); EXPECT_EQ(MftH264Decoder::kStopped, decoder->state()); // Should have called back with one empty frame. @@ -308,7 +308,7 @@ TEST_F(MftH264DecoderTest, NoOutputOnGarbageInput) { handler.SetDecoder(decoder.get()); while (MftH264Decoder::kStopped != decoder->state()) { scoped_refptr<VideoFrame> frame; - decoder->FillThisBuffer(frame); + decoder->ProduceVideoFrame(frame); } // Output callback should only be invoked once - the empty frame to indicate @@ -356,7 +356,7 @@ TEST_F(MftH264DecoderTest, NoFlushAtStopped) { handler.SetDecoder(decoder.get()); while (MftH264Decoder::kStopped != decoder->state()) { scoped_refptr<VideoFrame> frame; - decoder->FillThisBuffer(frame); + decoder->ProduceVideoFrame(frame); } EXPECT_EQ(0, handler.flush_count_); int old_flush_count = handler.flush_count_; @@ -399,7 +399,7 @@ void DecodeValidVideo(const std::string& filename, int num_frames, bool dxva) { handler.SetDecoder(decoder.get()); while (MftH264Decoder::kStopped != decoder->state()) { scoped_refptr<VideoFrame> frame; - decoder->FillThisBuffer(frame); + decoder->ProduceVideoFrame(frame); } // We expect a format change when decoder receives enough data to determine diff --git a/media/omx/omx_codec_unittest.cc b/media/omx/omx_codec_unittest.cc index 0e4b258..47b1e97 100644 --- a/media/omx/omx_codec_unittest.cc +++ b/media/omx/omx_codec_unittest.cc @@ -351,8 +351,8 @@ class OmxCodecTest : public testing::Test { AVStream av_stream_; AVCodecContext av_codec_context_; - VideoDecodeEngine::EmptyThisBufferCallback* feed_done_cb_; - VideoDecodeEngine::FillThisBufferCallback* decode_done_cb_; + VideoDecodeEngine::ProduceVideoSampleCallback* feed_done_cb_; + VideoDecodeEngine::ConsumeVideoFrameCallback* decode_done_cb_; TaskMocker init_done_cb_task_; TaskMocker stop_task_; diff --git a/media/tools/omx_test/omx_test.cc b/media/tools/omx_test/omx_test.cc index f970c45..693c7be 100644 --- a/media/tools/omx_test/omx_test.cc +++ b/media/tools/omx_test/omx_test.cc @@ -120,7 +120,7 @@ class TestApp : public base::RefCountedThreadSafe<TestApp>, input_format.video_header.height); } - virtual void OnEmptyBufferCallback(scoped_refptr<Buffer> buffer) { + virtual void ProduceVideoSample(scoped_refptr<Buffer> buffer) { // We receive this callback when the decoder has consumed an input buffer. // In this case, delete the previous buffer and enqueue a new one. // There are some conditions we don't want to enqueue, for example when @@ -131,7 +131,7 @@ class TestApp : public base::RefCountedThreadSafe<TestApp>, FeedInputBuffer(); } - virtual void OnFillBufferCallback(scoped_refptr<VideoFrame> frame) { + virtual void ConsumeVideoFrame(scoped_refptr<VideoFrame> frame) { // This callback is received when the decoder has completed a decoding // task and given us some output data. The frame is owned by the decoder. if (stopped_ || error_) @@ -162,7 +162,7 @@ class TestApp : public base::RefCountedThreadSafe<TestApp>, uint8* data; int read; file_reader_->Read(&data, &read); - engine_->EmptyThisBuffer(new DataBuffer(data, read)); + engine_->ConsumeVideoSample(new DataBuffer(data, read)); } void Run() { diff --git a/media/video/ffmpeg_video_decode_engine.cc b/media/video/ffmpeg_video_decode_engine.cc index e1908b6..2d35fdc 100644 --- a/media/video/ffmpeg_video_decode_engine.cc +++ b/media/video/ffmpeg_video_decode_engine.cc @@ -151,7 +151,7 @@ static void CopyPlane(size_t plane, } } -void FFmpegVideoDecodeEngine::EmptyThisBuffer( +void FFmpegVideoDecodeEngine::ConsumeVideoSample( scoped_refptr<Buffer> buffer) { pending_input_buffers_--; if (flush_pending_) { @@ -162,7 +162,8 @@ void FFmpegVideoDecodeEngine::EmptyThisBuffer( } } -void FFmpegVideoDecodeEngine::FillThisBuffer(scoped_refptr<VideoFrame> frame) { +void FFmpegVideoDecodeEngine::ProduceVideoFrame( + scoped_refptr<VideoFrame> frame) { // We should never receive NULL frame or EOS frame. DCHECK(frame.get() && !frame->IsEndOfStream()); @@ -216,7 +217,7 @@ void FFmpegVideoDecodeEngine::DecodeFrame(scoped_refptr<Buffer> buffer) { << " , packet size: " << buffer->GetDataSize() << " bytes"; // TODO(jiesun): call event_handler_->OnError() instead. - event_handler_->OnFillBufferCallback(video_frame); + event_handler_->ConsumeVideoFrame(video_frame); return; } @@ -227,7 +228,7 @@ void FFmpegVideoDecodeEngine::DecodeFrame(scoped_refptr<Buffer> buffer) { // drained, we mark the flag. Otherwise we read from demuxer again. if (frame_decoded == 0) { if (buffer->IsEndOfStream()) { // We had started flushing. - event_handler_->OnFillBufferCallback(video_frame); + event_handler_->ConsumeVideoFrame(video_frame); output_eos_reached_ = true; } else { ReadInput(); @@ -242,7 +243,7 @@ void FFmpegVideoDecodeEngine::DecodeFrame(scoped_refptr<Buffer> buffer) { !av_frame_->data[VideoFrame::kUPlane] || !av_frame_->data[VideoFrame::kVPlane]) { // TODO(jiesun): call event_handler_->OnError() instead. - event_handler_->OnFillBufferCallback(video_frame); + event_handler_->ConsumeVideoFrame(video_frame); return; } @@ -290,7 +291,7 @@ void FFmpegVideoDecodeEngine::DecodeFrame(scoped_refptr<Buffer> buffer) { video_frame->SetDuration(duration); pending_output_buffers_--; - event_handler_->OnFillBufferCallback(video_frame); + event_handler_->ConsumeVideoFrame(video_frame); } void FFmpegVideoDecodeEngine::Uninitialize() { @@ -334,7 +335,7 @@ void FFmpegVideoDecodeEngine::Seek() { void FFmpegVideoDecodeEngine::ReadInput() { DCHECK_EQ(output_eos_reached_, false); pending_input_buffers_++; - event_handler_->OnEmptyBufferCallback(NULL); + event_handler_->ProduceVideoSample(NULL); } VideoFrame::Format FFmpegVideoDecodeEngine::GetSurfaceFormat() const { diff --git a/media/video/ffmpeg_video_decode_engine.h b/media/video/ffmpeg_video_decode_engine.h index 3e030db..bc1e033 100644 --- a/media/video/ffmpeg_video_decode_engine.h +++ b/media/video/ffmpeg_video_decode_engine.h @@ -29,8 +29,8 @@ class FFmpegVideoDecodeEngine : public VideoDecodeEngine { virtual void Initialize(MessageLoop* message_loop, VideoDecodeEngine::EventHandler* event_handler, const VideoCodecConfig& config); - virtual void EmptyThisBuffer(scoped_refptr<Buffer> buffer); - virtual void FillThisBuffer(scoped_refptr<VideoFrame> frame); + virtual void ConsumeVideoSample(scoped_refptr<Buffer> buffer); + virtual void ProduceVideoFrame(scoped_refptr<VideoFrame> frame); virtual void Uninitialize(); virtual void Flush(); virtual void Seek(); diff --git a/media/video/ffmpeg_video_decode_engine_unittest.cc b/media/video/ffmpeg_video_decode_engine_unittest.cc index b7856d8..704b251 100644 --- a/media/video/ffmpeg_video_decode_engine_unittest.cc +++ b/media/video/ffmpeg_video_decode_engine_unittest.cc @@ -96,9 +96,9 @@ class FFmpegVideoDecodeEngineTest : public testing::Test, } public: - MOCK_METHOD1(OnFillBufferCallback, + MOCK_METHOD1(ConsumeVideoFrame, void(scoped_refptr<VideoFrame> video_frame)); - MOCK_METHOD1(OnEmptyBufferCallback, + MOCK_METHOD1(ProduceVideoSample, void(scoped_refptr<Buffer> buffer)); MOCK_METHOD1(OnInitializeComplete, void(const VideoCodecInfo& info)); @@ -193,7 +193,7 @@ TEST_F(FFmpegVideoDecodeEngineTest, Initialize_OpenDecoderFails) { } ACTION_P2(DemuxComplete, engine, buffer) { - engine->EmptyThisBuffer(buffer); + engine->ConsumeVideoSample(buffer); } ACTION_P(DecodeComplete, decoder) { @@ -217,11 +217,11 @@ TEST_F(FFmpegVideoDecodeEngineTest, DecodeFrame_Normal) { .WillOnce(DoAll(SetArgumentPointee<2>(1), // Simulate 1 byte frame. Return(0))); - EXPECT_CALL(*this, OnEmptyBufferCallback(_)) + EXPECT_CALL(*this, ProduceVideoSample(_)) .WillOnce(DemuxComplete(test_engine_.get(), buffer_)); - EXPECT_CALL(*this, OnFillBufferCallback(_)) + EXPECT_CALL(*this, ConsumeVideoFrame(_)) .WillOnce(DecodeComplete(this)); - test_engine_->FillThisBuffer(video_frame_); + test_engine_->ProduceVideoFrame(video_frame_); // |video_frame_| timestamp is 0 because we set the timestamp based off // the buffer timestamp. @@ -243,12 +243,12 @@ TEST_F(FFmpegVideoDecodeEngineTest, DecodeFrame_0ByteFrame) { .WillOnce(DoAll(SetArgumentPointee<2>(1), // Simulate 1 byte frame. Return(0))); - EXPECT_CALL(*this, OnEmptyBufferCallback(_)) + EXPECT_CALL(*this, ProduceVideoSample(_)) .WillOnce(DemuxComplete(test_engine_.get(), buffer_)) .WillOnce(DemuxComplete(test_engine_.get(), buffer_)); - EXPECT_CALL(*this, OnFillBufferCallback(_)) + EXPECT_CALL(*this, ConsumeVideoFrame(_)) .WillOnce(DecodeComplete(this)); - test_engine_->FillThisBuffer(video_frame_); + test_engine_->ProduceVideoFrame(video_frame_); EXPECT_TRUE(video_frame_.get()); } @@ -262,11 +262,11 @@ TEST_F(FFmpegVideoDecodeEngineTest, DecodeFrame_DecodeError) { AVCodecDecodeVideo2(&codec_context_, &yuv_frame_, _, _)) .WillOnce(Return(-1)); - EXPECT_CALL(*this, OnEmptyBufferCallback(_)) + EXPECT_CALL(*this, ProduceVideoSample(_)) .WillOnce(DemuxComplete(test_engine_.get(), buffer_)); - EXPECT_CALL(*this, OnFillBufferCallback(_)) + EXPECT_CALL(*this, ConsumeVideoFrame(_)) .WillOnce(DecodeComplete(this)); - test_engine_->FillThisBuffer(video_frame_); + test_engine_->ProduceVideoFrame(video_frame_); EXPECT_FALSE(video_frame_.get()); } diff --git a/media/video/omx_video_decode_engine.cc b/media/video/omx_video_decode_engine.cc index c893d7d..3aa8101 100644 --- a/media/video/omx_video_decode_engine.cc +++ b/media/video/omx_video_decode_engine.cc @@ -119,7 +119,7 @@ void OmxVideoDecodeEngine::Initialize( } // This method handles only input buffer, without coupling with output -void OmxVideoDecodeEngine::EmptyThisBuffer(scoped_refptr<Buffer> buffer) { +void OmxVideoDecodeEngine::ConsumeVideoSample(scoped_refptr<Buffer> buffer) { DCHECK_EQ(message_loop_, MessageLoop::current()); DCHECK(!free_input_buffers_.empty()); DCHECK_GT(input_pending_request_, 0); @@ -304,7 +304,7 @@ void OmxVideoDecodeEngine::FinishEmptyBuffer(scoped_refptr<Buffer> buffer) { DCHECK_EQ(message_loop_, MessageLoop::current()); if (!input_queue_has_eos_) { - event_handler_->OnEmptyBufferCallback(buffer); + event_handler_->ProduceVideoSample(buffer); ++input_pending_request_; } } @@ -323,7 +323,7 @@ void OmxVideoDecodeEngine::FinishFillBuffer(OMX_BUFFERHEADERTYPE* buffer) { frame->SetTimestamp(base::TimeDelta::FromMicroseconds(buffer->nTimeStamp)); frame->SetDuration(frame->GetTimestamp() - last_pts_); last_pts_ = frame->GetTimestamp(); - event_handler_->OnFillBufferCallback(frame); + event_handler_->ConsumeVideoFrame(frame); output_pending_request_--; } @@ -597,7 +597,7 @@ void OmxVideoDecodeEngine::DoneSetStateExecuting(OMX_STATETYPE state) { // Function for receiving output buffers. Hookup for buffer recycling // and outside allocator. -void OmxVideoDecodeEngine::FillThisBuffer( +void OmxVideoDecodeEngine::ProduceVideoFrame( scoped_refptr<VideoFrame> video_frame) { DCHECK(video_frame.get() && !video_frame->IsEndOfStream()); output_pending_request_++; @@ -605,7 +605,7 @@ void OmxVideoDecodeEngine::FillThisBuffer( if (!CanAcceptOutput()) { if (uses_egl_image_) { // return it to owner. output_pending_request_--; - event_handler_->OnFillBufferCallback(video_frame); + event_handler_->ConsumeVideoFrame(video_frame); } return; } @@ -617,7 +617,7 @@ void OmxVideoDecodeEngine::FillThisBuffer( } else if (kClientFlushing == client_state_) { if (uses_egl_image_) { // return it to owner. output_pending_request_--; - event_handler_->OnFillBufferCallback(video_frame); + event_handler_->ConsumeVideoFrame(video_frame); } if (InputPortFlushed() && OutputPortFlushed()) ComponentFlushDone(); @@ -1220,7 +1220,7 @@ void OmxVideoDecodeEngine::FillBufferDoneTask(OMX_BUFFERHEADERTYPE* buffer) { if (uses_egl_image_) { scoped_refptr<VideoFrame> frame; frame = static_cast<VideoFrame*>(buffer->pAppPrivate); - event_handler_->OnFillBufferCallback(frame); + event_handler_->ConsumeVideoFrame(frame); output_pending_request_--; } return; @@ -1240,7 +1240,7 @@ void OmxVideoDecodeEngine::FillBufferDoneTask(OMX_BUFFERHEADERTYPE* buffer) { // Singal end of stream. scoped_refptr<VideoFrame> frame; VideoFrame::CreateEmptyFrame(&frame); - event_handler_->OnFillBufferCallback(frame); + event_handler_->ConsumeVideoFrame(frame); } if (client_state_ == kClientFlushing && diff --git a/media/video/omx_video_decode_engine.h b/media/video/omx_video_decode_engine.h index 9e8bcf3..8347eed 100644 --- a/media/video/omx_video_decode_engine.h +++ b/media/video/omx_video_decode_engine.h @@ -29,8 +29,8 @@ class OmxVideoDecodeEngine : public VideoDecodeEngine { virtual void Initialize(MessageLoop* message_loop, VideoDecodeEngine::EventHandler* event_handler, const VideoCodecConfig& config); - virtual void EmptyThisBuffer(scoped_refptr<Buffer> buffer); - virtual void FillThisBuffer(scoped_refptr<VideoFrame> frame); + virtual void ConsumeVideoSample(scoped_refptr<Buffer> buffer); + virtual void ProduceVideoFrame(scoped_refptr<VideoFrame> frame); virtual void Uninitialize(); virtual void Flush(); virtual void Seek(); diff --git a/media/video/video_decode_engine.h b/media/video/video_decode_engine.h index 9c84f11..df14522 100644 --- a/media/video/video_decode_engine.h +++ b/media/video/video_decode_engine.h @@ -79,8 +79,35 @@ class VideoDecodeEngine { virtual void OnSeekComplete() = 0; virtual void OnError() = 0; virtual void OnFormatChange(VideoStreamInfo stream_info) = 0; - virtual void OnEmptyBufferCallback(scoped_refptr<Buffer> buffer) = 0; - virtual void OnFillBufferCallback(scoped_refptr<VideoFrame> frame) = 0; + + // TODO(hclam): The following two methods shouldn't belong to this class + // because they are not video decode events but used to send decoded + // video frames and request video packets. + // + // Signal the user of VideoDecodeEngine to provide a video sample. + // + // In the normal running state, this method is called by the video decode + // engine to request video samples used for decoding. + // + // In the case when the video decode engine is flushing, this method is + // called to return video samples acquired by the video decode engine. + // + // |buffer| can be NULL in which case this method call is purely for + // requesting new video samples. If |buffer| is non-NULL, the buffer is + // returned to the owner at the sample time as a request for video sample + // is made. + virtual void ProduceVideoSample(scoped_refptr<Buffer> buffer) = 0; + + // Signal the user of VideoDecodeEngine that a video frame is ready to + // be consumed or a video frame is returned to the owner. + // + // In the normal running state, this method is called to signal that + // |frame| contains a decoded video frame and is ready to be used. + // + // In the case of flushing and video frame is provided externally, this + // method is called to return the video frame object to the owner. + // The content of the video frame may be invalid. + virtual void ConsumeVideoFrame(scoped_refptr<VideoFrame> frame) = 0; }; virtual ~VideoDecodeEngine() {} @@ -106,21 +133,27 @@ class VideoDecodeEngine { // issue read requests after Flush() us made. virtual void Seek() = 0; - // Buffer exchange method for input and output stream. - // These functions and callbacks could be used in two scenarios for both - // input and output streams: - // 1. Engine provide buffers. - // 2. Outside party provide buffers. - // The currently planned engine implementation: - // 1. provides the input buffer request inside engine through - // |EmptyThisBufferCallback|. The engine implementation has better knowledge - // of the decoder reordering delay and jittery removal requirements. Input - // buffers are returned into engine through |EmptyThisBuffer|. - // 2. Output buffers are provided from outside the engine, and feed into - // engine through |FillThisBuffer|. Output buffers are returned to outside - // by |FillThisBufferCallback|. - virtual void EmptyThisBuffer(scoped_refptr<Buffer> buffer) = 0; - virtual void FillThisBuffer(scoped_refptr<VideoFrame> frame) = 0; + // Provide a video sample to be used by the video decode engine. + // + // This method is called in response to ProvideVideoSample() called to the + // user. + virtual void ConsumeVideoSample(scoped_refptr<Buffer> buffer) = 0; + + // Signal the video decode engine to produce a video frame or return the + // video frame object to the video decode engine. + // + // In the normal running state, this method is called by the user of the + // video decode engine to request a decoded video frame. If |frame| is + // NULL the video decode engine should allocate a video frame object. + // Otherwise video decode engine should try to use the video frame object + // provided as output. + // + // In flushing state and video frames are allocated internally this method + // is called by the user to return the video frame object. + // + // In response to this method call, ConsumeVideoFrame() is called with a + // video frame object containing decoded video content. + virtual void ProduceVideoFrame(scoped_refptr<VideoFrame> frame) = 0; }; } // namespace media |