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

Side by Side Diff: media/filters/chunk_demuxer_unittest.cc

Issue 14217008: Remove reference counting from media::DemuxerStream and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/filters/chunk_demuxer.cc ('k') | media/filters/decrypting_audio_decoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "media/base/audio_decoder_config.h" 9 #include "media/base/audio_decoder_config.h"
10 #include "media/base/decoder_buffer.h" 10 #include "media/base/decoder_buffer.h"
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 scoped_refptr<DecoderBuffer>* buffer_out, 657 scoped_refptr<DecoderBuffer>* buffer_out,
658 DemuxerStream::Status status, 658 DemuxerStream::Status status,
659 const scoped_refptr<DecoderBuffer>& buffer) { 659 const scoped_refptr<DecoderBuffer>& buffer) {
660 *status_out = status; 660 *status_out = status;
661 *buffer_out = buffer; 661 *buffer_out = buffer;
662 } 662 }
663 663
664 void ReadUntilNotOkOrEndOfStream(DemuxerStream::Type type, 664 void ReadUntilNotOkOrEndOfStream(DemuxerStream::Type type,
665 DemuxerStream::Status* status, 665 DemuxerStream::Status* status,
666 base::TimeDelta* last_timestamp) { 666 base::TimeDelta* last_timestamp) {
667 scoped_refptr<DemuxerStream> stream = demuxer_->GetStream(type); 667 DemuxerStream* stream = demuxer_->GetStream(type);
668 scoped_refptr<DecoderBuffer> buffer; 668 scoped_refptr<DecoderBuffer> buffer;
669 669
670 *last_timestamp = kNoTimestamp(); 670 *last_timestamp = kNoTimestamp();
671 do { 671 do {
672 stream->Read(base::Bind(&ChunkDemuxerTest::StoreStatusAndBuffer, 672 stream->Read(base::Bind(&ChunkDemuxerTest::StoreStatusAndBuffer,
673 base::Unretained(this), status, &buffer)); 673 base::Unretained(this), status, &buffer));
674 base::MessageLoop::current()->RunUntilIdle(); 674 base::MessageLoop::current()->RunUntilIdle();
675 if (*status == DemuxerStream::kOk && !buffer->IsEndOfStream()) 675 if (*status == DemuxerStream::kOk && !buffer->IsEndOfStream())
676 *last_timestamp = buffer->GetTimestamp(); 676 *last_timestamp = buffer->GetTimestamp();
677 } while (*status == DemuxerStream::kOk && !buffer->IsEndOfStream()); 677 } while (*status == DemuxerStream::kOk && !buffer->IsEndOfStream());
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 int need_key_count = (is_audio_encrypted ? 1 : 0) + 805 int need_key_count = (is_audio_encrypted ? 1 : 0) +
806 (is_video_encrypted ? 1 : 0); 806 (is_video_encrypted ? 1 : 0);
807 EXPECT_CALL(*this, NeedKeyMock(kWebMEncryptInitDataType, NotNull(), 807 EXPECT_CALL(*this, NeedKeyMock(kWebMEncryptInitDataType, NotNull(),
808 DecryptConfig::kDecryptionKeySize)) 808 DecryptConfig::kDecryptionKeySize))
809 .Times(Exactly(need_key_count)); 809 .Times(Exactly(need_key_count));
810 } 810 }
811 811
812 ASSERT_TRUE(InitDemuxerWithEncryptionInfo( 812 ASSERT_TRUE(InitDemuxerWithEncryptionInfo(
813 has_audio, has_video, is_audio_encrypted, is_video_encrypted)); 813 has_audio, has_video, is_audio_encrypted, is_video_encrypted));
814 814
815 scoped_refptr<DemuxerStream> audio_stream = 815 DemuxerStream* audio_stream = demuxer_->GetStream(DemuxerStream::AUDIO);
816 demuxer_->GetStream(DemuxerStream::AUDIO);
817 if (has_audio) { 816 if (has_audio) {
818 ASSERT_TRUE(audio_stream); 817 ASSERT_TRUE(audio_stream);
819 818
820 const AudioDecoderConfig& config = audio_stream->audio_decoder_config(); 819 const AudioDecoderConfig& config = audio_stream->audio_decoder_config();
821 EXPECT_EQ(kCodecVorbis, config.codec()); 820 EXPECT_EQ(kCodecVorbis, config.codec());
822 EXPECT_EQ(32, config.bits_per_channel()); 821 EXPECT_EQ(32, config.bits_per_channel());
823 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, config.channel_layout()); 822 EXPECT_EQ(CHANNEL_LAYOUT_STEREO, config.channel_layout());
824 EXPECT_EQ(44100, config.samples_per_second()); 823 EXPECT_EQ(44100, config.samples_per_second());
825 EXPECT_TRUE(config.extra_data()); 824 EXPECT_TRUE(config.extra_data());
826 EXPECT_GT(config.extra_data_size(), 0u); 825 EXPECT_GT(config.extra_data_size(), 0u);
827 EXPECT_EQ(kSampleFormatPlanarF32, config.sample_format()); 826 EXPECT_EQ(kSampleFormatPlanarF32, config.sample_format());
828 EXPECT_EQ(is_audio_encrypted, 827 EXPECT_EQ(is_audio_encrypted,
829 audio_stream->audio_decoder_config().is_encrypted()); 828 audio_stream->audio_decoder_config().is_encrypted());
830 } else { 829 } else {
831 EXPECT_FALSE(audio_stream); 830 EXPECT_FALSE(audio_stream);
832 } 831 }
833 832
834 scoped_refptr<DemuxerStream> video_stream = 833 DemuxerStream* video_stream = demuxer_->GetStream(DemuxerStream::VIDEO);
835 demuxer_->GetStream(DemuxerStream::VIDEO);
836 if (has_video) { 834 if (has_video) {
837 EXPECT_TRUE(video_stream); 835 EXPECT_TRUE(video_stream);
838 EXPECT_EQ(is_video_encrypted, 836 EXPECT_EQ(is_video_encrypted,
839 video_stream->video_decoder_config().is_encrypted()); 837 video_stream->video_decoder_config().is_encrypted());
840 } else { 838 } else {
841 EXPECT_FALSE(video_stream); 839 EXPECT_FALSE(video_stream);
842 } 840 }
843 841
844 ShutdownDemuxer(); 842 ShutdownDemuxer();
845 demuxer_.reset(); 843 demuxer_.reset();
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 : demuxer_(demuxer), 1126 : demuxer_(demuxer),
1129 audio_read_done_(false), 1127 audio_read_done_(false),
1130 video_read_done_(false) { 1128 video_read_done_(false) {
1131 } 1129 }
1132 1130
1133 // Request a read on the audio and video streams. 1131 // Request a read on the audio and video streams.
1134 void RequestReads() { 1132 void RequestReads() {
1135 EXPECT_FALSE(audio_read_done_); 1133 EXPECT_FALSE(audio_read_done_);
1136 EXPECT_FALSE(video_read_done_); 1134 EXPECT_FALSE(video_read_done_);
1137 1135
1138 scoped_refptr<DemuxerStream> audio = 1136 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO);
1139 demuxer_->GetStream(DemuxerStream::AUDIO); 1137 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO);
1140 scoped_refptr<DemuxerStream> video =
1141 demuxer_->GetStream(DemuxerStream::VIDEO);
1142 1138
1143 audio->Read(base::Bind(&OnEndOfStreamReadDone, &audio_read_done_)); 1139 audio->Read(base::Bind(&OnEndOfStreamReadDone, &audio_read_done_));
1144 video->Read(base::Bind(&OnEndOfStreamReadDone, &video_read_done_)); 1140 video->Read(base::Bind(&OnEndOfStreamReadDone, &video_read_done_));
1145 base::MessageLoop::current()->RunUntilIdle(); 1141 base::MessageLoop::current()->RunUntilIdle();
1146 } 1142 }
1147 1143
1148 // Check to see if |audio_read_done_| and |video_read_done_| variables 1144 // Check to see if |audio_read_done_| and |video_read_done_| variables
1149 // match |expected|. 1145 // match |expected|.
1150 void CheckIfReadDonesWereCalled(bool expected) { 1146 void CheckIfReadDonesWereCalled(bool expected) {
1151 EXPECT_EQ(expected, audio_read_done_); 1147 EXPECT_EQ(expected, audio_read_done_);
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
2126 } 2122 }
2127 2123
2128 TEST_F(ChunkDemuxerTest, TestConfigChange_Video) { 2124 TEST_F(ChunkDemuxerTest, TestConfigChange_Video) {
2129 InSequence s; 2125 InSequence s;
2130 2126
2131 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); 2127 ASSERT_TRUE(InitDemuxerWithConfigChangeData());
2132 2128
2133 DemuxerStream::Status status; 2129 DemuxerStream::Status status;
2134 base::TimeDelta last_timestamp; 2130 base::TimeDelta last_timestamp;
2135 2131
2136 scoped_refptr<DemuxerStream> video = 2132 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO);
2137 demuxer_->GetStream(DemuxerStream::VIDEO);
2138 2133
2139 // Fetch initial video config and verify it matches what we expect. 2134 // Fetch initial video config and verify it matches what we expect.
2140 const VideoDecoderConfig& video_config_1 = video->video_decoder_config(); 2135 const VideoDecoderConfig& video_config_1 = video->video_decoder_config();
2141 ASSERT_TRUE(video_config_1.IsValidConfig()); 2136 ASSERT_TRUE(video_config_1.IsValidConfig());
2142 EXPECT_EQ(video_config_1.natural_size().width(), 320); 2137 EXPECT_EQ(video_config_1.natural_size().width(), 320);
2143 EXPECT_EQ(video_config_1.natural_size().height(), 240); 2138 EXPECT_EQ(video_config_1.natural_size().height(), 240);
2144 2139
2145 ExpectRead(DemuxerStream::VIDEO, 0); 2140 ExpectRead(DemuxerStream::VIDEO, 0);
2146 2141
2147 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp); 2142 ReadUntilNotOkOrEndOfStream(DemuxerStream::VIDEO, &status, &last_timestamp);
(...skipping 26 matching lines...) Expand all
2174 } 2169 }
2175 2170
2176 TEST_F(ChunkDemuxerTest, TestConfigChange_Audio) { 2171 TEST_F(ChunkDemuxerTest, TestConfigChange_Audio) {
2177 InSequence s; 2172 InSequence s;
2178 2173
2179 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); 2174 ASSERT_TRUE(InitDemuxerWithConfigChangeData());
2180 2175
2181 DemuxerStream::Status status; 2176 DemuxerStream::Status status;
2182 base::TimeDelta last_timestamp; 2177 base::TimeDelta last_timestamp;
2183 2178
2184 scoped_refptr<DemuxerStream> audio = 2179 DemuxerStream* audio = demuxer_->GetStream(DemuxerStream::AUDIO);
2185 demuxer_->GetStream(DemuxerStream::AUDIO);
2186 2180
2187 // Fetch initial audio config and verify it matches what we expect. 2181 // Fetch initial audio config and verify it matches what we expect.
2188 const AudioDecoderConfig& audio_config_1 = audio->audio_decoder_config(); 2182 const AudioDecoderConfig& audio_config_1 = audio->audio_decoder_config();
2189 ASSERT_TRUE(audio_config_1.IsValidConfig()); 2183 ASSERT_TRUE(audio_config_1.IsValidConfig());
2190 EXPECT_EQ(audio_config_1.samples_per_second(), 44100); 2184 EXPECT_EQ(audio_config_1.samples_per_second(), 44100);
2191 EXPECT_EQ(audio_config_1.extra_data_size(), 3863u); 2185 EXPECT_EQ(audio_config_1.extra_data_size(), 3863u);
2192 2186
2193 ExpectRead(DemuxerStream::AUDIO, 0); 2187 ExpectRead(DemuxerStream::AUDIO, 0);
2194 2188
2195 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp); 2189 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp);
(...skipping 23 matching lines...) Expand all
2219 // config changes. 2213 // config changes.
2220 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp); 2214 ReadUntilNotOkOrEndOfStream(DemuxerStream::AUDIO, &status, &last_timestamp);
2221 ASSERT_EQ(status, DemuxerStream::kOk); 2215 ASSERT_EQ(status, DemuxerStream::kOk);
2222 } 2216 }
2223 2217
2224 TEST_F(ChunkDemuxerTest, TestConfigChange_Seek) { 2218 TEST_F(ChunkDemuxerTest, TestConfigChange_Seek) {
2225 InSequence s; 2219 InSequence s;
2226 2220
2227 ASSERT_TRUE(InitDemuxerWithConfigChangeData()); 2221 ASSERT_TRUE(InitDemuxerWithConfigChangeData());
2228 2222
2229 scoped_refptr<DemuxerStream> video = 2223 DemuxerStream* video = demuxer_->GetStream(DemuxerStream::VIDEO);
2230 demuxer_->GetStream(DemuxerStream::VIDEO);
2231 2224
2232 // Fetch initial video config and verify it matches what we expect. 2225 // Fetch initial video config and verify it matches what we expect.
2233 const VideoDecoderConfig& video_config_1 = video->video_decoder_config(); 2226 const VideoDecoderConfig& video_config_1 = video->video_decoder_config();
2234 ASSERT_TRUE(video_config_1.IsValidConfig()); 2227 ASSERT_TRUE(video_config_1.IsValidConfig());
2235 EXPECT_EQ(video_config_1.natural_size().width(), 320); 2228 EXPECT_EQ(video_config_1.natural_size().width(), 320);
2236 EXPECT_EQ(video_config_1.natural_size().height(), 240); 2229 EXPECT_EQ(video_config_1.natural_size().height(), 240);
2237 2230
2238 ExpectRead(DemuxerStream::VIDEO, 0); 2231 ExpectRead(DemuxerStream::VIDEO, 0);
2239 2232
2240 // Seek to a location with a different config. 2233 // Seek to a location with a different config.
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2444 // Test receiving a Shutdown() call before we get an Initialize() 2437 // Test receiving a Shutdown() call before we get an Initialize()
2445 // call. This can happen if video element gets destroyed before 2438 // call. This can happen if video element gets destroyed before
2446 // the pipeline has a chance to initialize the demuxer. 2439 // the pipeline has a chance to initialize the demuxer.
2447 TEST_F(ChunkDemuxerTest, TestShutdownBeforeInitialize) { 2440 TEST_F(ChunkDemuxerTest, TestShutdownBeforeInitialize) {
2448 demuxer_->Shutdown(); 2441 demuxer_->Shutdown();
2449 demuxer_->Initialize( 2442 demuxer_->Initialize(
2450 &host_, CreateInitDoneCB(DEMUXER_ERROR_COULD_NOT_OPEN)); 2443 &host_, CreateInitDoneCB(DEMUXER_ERROR_COULD_NOT_OPEN));
2451 message_loop_.RunUntilIdle(); 2444 message_loop_.RunUntilIdle();
2452 } 2445 }
2453 2446
2447 TEST_F(ChunkDemuxerTest, ReadAfterAudioDisabled) {
2448 ASSERT_TRUE(InitDemuxer(true, true));
2449 scoped_ptr<Cluster> cluster(kDefaultFirstCluster());
2450 AppendData(cluster->data(), cluster->size());
2451
2452 DemuxerStream* stream = demuxer_->GetStream(DemuxerStream::AUDIO);
2453 ASSERT_TRUE(stream);
2454
2455 // The stream should no longer be present.
2456 demuxer_->OnAudioRendererDisabled();
2457 ASSERT_FALSE(demuxer_->GetStream(DemuxerStream::AUDIO));
2458
2459 // Normally this would return an audio buffer at timestamp zero, but
2460 // all reads should return EOS buffers when disabled.
2461 bool audio_read_done = false;
2462 stream->Read(base::Bind(&OnReadDone_EOSExpected, &audio_read_done));
2463 message_loop_.RunUntilIdle();
2464
2465 EXPECT_TRUE(audio_read_done);
2466 }
2467
2454 } // namespace media 2468 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/chunk_demuxer.cc ('k') | media/filters/decrypting_audio_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698