Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1670)

Unified Diff: media/filters/audio_renderer_impl_unittest.cc

Issue 297553002: Add callback in VideoDecoder and AudioDecoder to return decoded frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/filters/audio_decoder_selector_unittest.cc ('k') | media/filters/decoder_selector.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/audio_renderer_impl_unittest.cc
diff --git a/media/filters/audio_renderer_impl_unittest.cc b/media/filters/audio_renderer_impl_unittest.cc
index db18fe56c47192ba2d0844fb57c6a2469c6a3f31..b815176683067ae3b4f516c42416167882ef3141 100644
--- a/media/filters/audio_renderer_impl_unittest.cc
+++ b/media/filters/audio_renderer_impl_unittest.cc
@@ -29,6 +29,7 @@ using ::testing::_;
using ::testing::AnyNumber;
using ::testing::Invoke;
using ::testing::Return;
+using ::testing::SaveArg;
namespace media {
@@ -77,9 +78,10 @@ class AudioRendererImplTest : public ::testing::Test {
EXPECT_CALL(*decoder_, Reset(_))
.WillRepeatedly(Invoke(this, &AudioRendererImplTest::ResetDecoder));
- // Mock out demuxer reads
+ // Mock out demuxer reads.
EXPECT_CALL(demuxer_stream_, Read(_)).WillRepeatedly(
- RunCallback<0>(DemuxerStream::kOk, DecoderBuffer::CreateEOSBuffer()));
+ RunCallback<0>(DemuxerStream::kOk,
+ scoped_refptr<DecoderBuffer>(new DecoderBuffer(0))));
EXPECT_CALL(demuxer_stream_, SupportsConfigChanges())
.WillRepeatedly(Return(true));
AudioParameters out_params(AudioParameters::AUDIO_PCM_LOW_LATENCY,
@@ -112,8 +114,9 @@ class AudioRendererImplTest : public ::testing::Test {
}
void ExpectUnsupportedAudioDecoder() {
- EXPECT_CALL(*decoder_, Initialize(_, _))
- .WillOnce(RunCallback<1>(DECODER_ERROR_NOT_SUPPORTED));
+ EXPECT_CALL(*decoder_, Initialize(_, _, _))
+ .WillOnce(DoAll(SaveArg<2>(&output_cb_),
+ RunCallback<1>(DECODER_ERROR_NOT_SUPPORTED)));
}
MOCK_METHOD1(OnStatistics, void(const PipelineStatistics&));
@@ -141,8 +144,9 @@ class AudioRendererImplTest : public ::testing::Test {
}
void Initialize() {
- EXPECT_CALL(*decoder_, Initialize(_, _))
- .WillOnce(RunCallback<1>(PIPELINE_OK));
+ EXPECT_CALL(*decoder_, Initialize(_, _, _))
+ .WillOnce(DoAll(SaveArg<2>(&output_cb_),
+ RunCallback<1>(PIPELINE_OK)));
EXPECT_CALL(*decoder_, Stop());
InitializeWithStatus(PIPELINE_OK);
@@ -162,8 +166,9 @@ class AudioRendererImplTest : public ::testing::Test {
}
void InitializeAndStop() {
- EXPECT_CALL(*decoder_, Initialize(_, _))
- .WillOnce(RunCallback<1>(PIPELINE_OK));
+ EXPECT_CALL(*decoder_, Initialize(_, _, _))
+ .WillOnce(DoAll(SaveArg<2>(&output_cb_),
+ RunCallback<1>(PIPELINE_OK)));
EXPECT_CALL(*decoder_, Stop());
WaitableMessageLoopEvent event;
@@ -178,8 +183,9 @@ class AudioRendererImplTest : public ::testing::Test {
}
void InitializeAndStopDuringDecoderInit() {
- EXPECT_CALL(*decoder_, Initialize(_, _))
- .WillOnce(EnterPendingDecoderInitStateAction(this));
+ EXPECT_CALL(*decoder_, Initialize(_, _, _))
+ .WillOnce(DoAll(SaveArg<2>(&output_cb_),
+ EnterPendingDecoderInitStateAction(this)));
EXPECT_CALL(*decoder_, Stop());
WaitableMessageLoopEvent event;
@@ -223,9 +229,6 @@ class AudioRendererImplTest : public ::testing::Test {
WaitForPendingRead();
DeliverRemainingAudio();
event.RunAndWaitForStatus(PIPELINE_OK);
-
- // We should have no reads.
- EXPECT_TRUE(decode_cb_.is_null());
}
void StartRendering() {
@@ -286,12 +289,11 @@ class AudioRendererImplTest : public ::testing::Test {
DeliverBuffer(AudioDecoder::kOk, buffer);
}
- void AbortPendingRead() {
- DeliverBuffer(AudioDecoder::kAborted, NULL);
- }
-
void DeliverEndOfStream() {
- DeliverBuffer(AudioDecoder::kOk, AudioBuffer::CreateEOSBuffer());
+ // Repeatedly return EOS buffer
+ while (!decode_cb_.is_null()) {
+ DeliverBuffer(AudioDecoder::kOk, AudioBuffer::CreateEOSBuffer());
+ }
}
// Delivers frames until |renderer_|'s internal buffer is full and no longer
@@ -465,8 +467,12 @@ class AudioRendererImplTest : public ::testing::Test {
}
void ResetDecoder(const base::Closure& reset_cb) {
- CHECK(decode_cb_.is_null())
- << "Reset overlapping with reads is not permitted";
+ if (!decode_cb_.is_null()) {
+ // |reset_cb| will be called in DeliverBuffer(), after the decoder is
+ // flushed.
+ reset_cb_ = reset_cb;
+ return;
+ }
message_loop_.PostTask(FROM_HERE, reset_cb);
}
@@ -474,7 +480,14 @@ class AudioRendererImplTest : public ::testing::Test {
void DeliverBuffer(AudioDecoder::Status status,
const scoped_refptr<AudioBuffer>& buffer) {
CHECK(!decode_cb_.is_null());
- base::ResetAndReturn(&decode_cb_).Run(status, buffer);
+ if (buffer)
+ output_cb_.Run(buffer);
+ base::ResetAndReturn(&decode_cb_).Run(status);
+
+ if (!reset_cb_.is_null())
+ base::ResetAndReturn(&reset_cb_).Run();
+
+ message_loop_.RunUntilIdle();
}
MockDemuxerStream demuxer_stream_;
@@ -485,7 +498,9 @@ class AudioRendererImplTest : public ::testing::Test {
TimeTicks time_;
// Used for satisfying reads.
+ AudioDecoder::OutputCB output_cb_;
AudioDecoder::DecodeCB decode_cb_;
+ base::Closure reset_cb_;
scoped_ptr<AudioTimestampHelper> next_timestamp_;
WaitableMessageLoopEvent ended_event_;
@@ -594,7 +609,7 @@ TEST_F(AudioRendererImplTest, Underflow_CapacityResetsAfterFlush) {
EXPECT_GT(buffer_capacity(), initial_capacity);
// Verify that the buffer capacity is restored to the |initial_capacity|.
- AbortPendingRead();
+ DeliverEndOfStream();
Flush();
EXPECT_EQ(buffer_capacity(), initial_capacity);
}
@@ -614,7 +629,7 @@ TEST_F(AudioRendererImplTest, Underflow_FlushWhileUnderflowed) {
EXPECT_FALSE(ConsumeBufferedData(kDataSize, NULL));
// Verify that we can still Flush() before entering the rebuffering state.
- AbortPendingRead();
+ DeliverEndOfStream();
Flush();
}
@@ -758,52 +773,6 @@ TEST_F(AudioRendererImplTest, Underflow_PausePlay) {
EXPECT_EQ(FakeAudioRendererSink::kPlaying, sink_->state());
}
-TEST_F(AudioRendererImplTest, AbortPendingRead_Preroll) {
- Initialize();
-
- // Start prerolling and wait for a read.
- WaitableMessageLoopEvent event;
- renderer_->Preroll(TimeDelta(), event.GetPipelineStatusCB());
- WaitForPendingRead();
-
- // Simulate the decoder aborting the pending read.
- AbortPendingRead();
- event.RunAndWaitForStatus(PIPELINE_OK);
-
- Flush();
-
- // Preroll again to a different timestamp and verify it completed normally.
- Preroll(1000, PIPELINE_OK);
-}
-
-TEST_F(AudioRendererImplTest, AbortPendingRead_Flush) {
- Initialize();
-
- Preroll();
- StartRendering();
-
- // Partially drain internal buffer so we get a pending read.
- EXPECT_TRUE(ConsumeBufferedData(frames_buffered() / 2, NULL));
- WaitForPendingRead();
-
- StopRendering();
-
- EXPECT_TRUE(IsReadPending());
-
- // Start flushing.
- WaitableMessageLoopEvent flush_event;
- renderer_->Flush(flush_event.GetClosure());
-
- // Simulate the decoder aborting the pending read.
- AbortPendingRead();
- flush_event.RunAndWait();
-
- EXPECT_FALSE(IsReadPending());
-
- // Preroll again to a different timestamp and verify it completed normally.
- Preroll(1000, PIPELINE_OK);
-}
-
TEST_F(AudioRendererImplTest, PendingRead_Flush) {
Initialize();
@@ -925,6 +894,7 @@ TEST_F(AudioRendererImplTest, TimeUpdatesOnFirstBuffer) {
int frames_to_consume = frames_buffered() / 2;
EXPECT_TRUE(ConsumeBufferedData(frames_to_consume, NULL));
WaitForPendingRead();
+ base::RunLoop().RunUntilIdle();
// ConsumeBufferedData() uses an audio delay of zero, so ensure we received
// a time update that's equal to |kFramesToConsume| from above.
« no previous file with comments | « media/filters/audio_decoder_selector_unittest.cc ('k') | media/filters/decoder_selector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698