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

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

Issue 9010001: Fix ChunkDemuxer seeks that occur during a partially parsed cluster. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: _ Created 9 years 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/webm/webm_cluster_parser.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "media/base/audio_decoder_config.h" 6 #include "media/base/audio_decoder_config.h"
7 #include "media/base/mock_callback.h" 7 #include "media/base/mock_callback.h"
8 #include "media/base/mock_demuxer_host.h" 8 #include "media/base/mock_demuxer_host.h"
9 #include "media/base/test_data_util.h" 9 #include "media/base/test_data_util.h"
10 #include "media/filters/chunk_demuxer.h" 10 #include "media/filters/chunk_demuxer.h"
11 #include "media/filters/chunk_demuxer_client.h" 11 #include "media/filters/chunk_demuxer_client.h"
12 #include "media/webm/cluster_builder.h" 12 #include "media/webm/cluster_builder.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 using ::testing::AnyNumber; 15 using ::testing::AnyNumber;
16 using ::testing::InSequence; 16 using ::testing::InSequence;
17 using ::testing::Return; 17 using ::testing::Return;
18 using ::testing::SetArgumentPointee; 18 using ::testing::SetArgumentPointee;
19 using ::testing::NiceMock;
20 using ::testing::_; 19 using ::testing::_;
21 20
22 namespace media { 21 namespace media {
23 22
24 static const uint8 kTracksHeader[] = { 23 static const uint8 kTracksHeader[] = {
25 0x16, 0x54, 0xAE, 0x6B, // Tracks ID 24 0x16, 0x54, 0xAE, 0x6B, // Tracks ID
26 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // tracks(size = 0) 25 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // tracks(size = 0)
27 }; 26 };
28 27
29 static const int kTracksHeaderSize = sizeof(kTracksHeader); 28 static const int kTracksHeaderSize = sizeof(kTracksHeader);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 uint8 data[] = { 0x00 }; 184 uint8 data[] = { 0x00 };
186 cb->AddSimpleBlock(track_num, timecode, 0, data, sizeof(data)); 185 cb->AddSimpleBlock(track_num, timecode, 0, data, sizeof(data));
187 } 186 }
188 187
189 void AddSimpleBlock(ClusterBuilder* cb, int track_num, int64 timecode, 188 void AddSimpleBlock(ClusterBuilder* cb, int track_num, int64 timecode,
190 int size) { 189 int size) {
191 scoped_array<uint8> data(new uint8[size]); 190 scoped_array<uint8> data(new uint8[size]);
192 cb->AddSimpleBlock(track_num, timecode, 0, data.get(), size); 191 cb->AddSimpleBlock(track_num, timecode, 0, data.get(), size);
193 } 192 }
194 193
194 MOCK_METHOD1(OnRead, void(int64 timestamp_in_ms));
195
196 void ReadDone(const scoped_refptr<Buffer>& buffer) {
197 int64 ts = buffer->GetTimestamp().InMilliseconds();
198 EXPECT_FALSE(buffer->IsEndOfStream());
199 OnRead(ts);
200 }
201
202 void ExpectRead(DemuxerStream* stream, int64 timestamp_in_ms) {
203 EXPECT_CALL(*this, OnRead(timestamp_in_ms));
scherkus (not reviewing) 2011/12/20 18:26:17 alternatively I *think* you can declare a gmock ma
acolwell GONE FROM CHROMIUM 2011/12/20 19:11:53 Nice! Done.
204 stream->Read(base::Bind(&ChunkDemuxerTest::ReadDone,
205 base::Unretained(this)));
206 }
207
195 MOCK_METHOD1(Checkpoint, void(int id)); 208 MOCK_METHOD1(Checkpoint, void(int id));
196 209
197 MockDemuxerHost mock_demuxer_host_; 210 MockDemuxerHost mock_demuxer_host_;
198 211
199 scoped_ptr<MockChunkDemuxerClient> client_; 212 scoped_ptr<MockChunkDemuxerClient> client_;
200 scoped_refptr<ChunkDemuxer> demuxer_; 213 scoped_refptr<ChunkDemuxer> demuxer_;
201 214
202 private: 215 private:
203 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest); 216 DISALLOW_COPY_AND_ASSIGN(ChunkDemuxerTest);
204 }; 217 };
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 AddSimpleBlock(&cb, kVideoTrackNum, 0); 283 AddSimpleBlock(&cb, kVideoTrackNum, 0);
271 scoped_ptr<Cluster> cluster(cb.Finish()); 284 scoped_ptr<Cluster> cluster(cb.Finish());
272 285
273 Checkpoint(1); 286 Checkpoint(1);
274 287
275 AppendData(cluster->data(), cluster->size()); 288 AppendData(cluster->data(), cluster->size());
276 289
277 Checkpoint(2); 290 Checkpoint(2);
278 } 291 }
279 292
293 // Test the case where a Seek() is requested while the parser
294 // is in the middle of cluster. This is to verify that the parser
295 // resets itself on seek and is in the right state when data from
296 // the new seek point arrives.
297 TEST_F(ChunkDemuxerTest, TestSeekWhileParsingCluster) {
298 InitDemuxer(true, true);
299
300 scoped_refptr<DemuxerStream> audio =
301 demuxer_->GetStream(DemuxerStream::AUDIO);
302 scoped_refptr<DemuxerStream> video =
303 demuxer_->GetStream(DemuxerStream::VIDEO);
304
305 InSequence s;
306
307 ClusterBuilder cb;
308 cb.SetClusterTimecode(0);
309 AddSimpleBlock(&cb, kAudioTrackNum, 1);
310 AddSimpleBlock(&cb, kVideoTrackNum, 2);
311 AddSimpleBlock(&cb, kAudioTrackNum, 10);
312 AddSimpleBlock(&cb, kVideoTrackNum, 20);
313 scoped_ptr<Cluster> clusterA(cb.Finish());
scherkus (not reviewing) 2011/12/20 18:26:17 clusterA -> cluster_a
acolwell GONE FROM CHROMIUM 2011/12/20 19:11:53 Done & fixed all other instances in this file.
314
315 cb.SetClusterTimecode(5000);
316 AddSimpleBlock(&cb, kAudioTrackNum, 5000);
317 AddSimpleBlock(&cb, kVideoTrackNum, 5005);
318 AddSimpleBlock(&cb, kAudioTrackNum, 5007);
319 AddSimpleBlock(&cb, kVideoTrackNum, 5035);
320 scoped_ptr<Cluster> clusterB(cb.Finish());
scherkus (not reviewing) 2011/12/20 18:26:17 ditto
acolwell GONE FROM CHROMIUM 2011/12/20 19:11:53 Done.
321
322 // Append all but the last byte so that everything but
323 // the last block can be parsed.
324 AppendData(clusterA->data(), clusterA->size() - 1);
325
326 ExpectRead(audio, 1);
327 ExpectRead(video, 2);
328 ExpectRead(audio, 10);
329
330 demuxer_->FlushData();
331 demuxer_->Seek(base::TimeDelta::FromSeconds(5),
332 NewExpectedStatusCB(PIPELINE_OK));
333
334
335 // Append the new cluster and verify that only the blocks
336 // in the new cluster are returned.
337 AppendData(clusterB->data(), clusterB->size());
338 ExpectRead(audio, 5000);
339 ExpectRead(video, 5005);
340 ExpectRead(audio, 5007);
341 ExpectRead(video, 5035);
342 }
343
280 // Test the case where AppendData() is called before Init(). 344 // Test the case where AppendData() is called before Init().
281 TEST_F(ChunkDemuxerTest, TestAppendDataBeforeInit) { 345 TEST_F(ChunkDemuxerTest, TestAppendDataBeforeInit) {
282 scoped_array<uint8> info_tracks; 346 scoped_array<uint8> info_tracks;
283 int info_tracks_size = 0; 347 int info_tracks_size = 0;
284 CreateInfoTracks(true, true, &info_tracks, &info_tracks_size); 348 CreateInfoTracks(true, true, &info_tracks, &info_tracks_size);
285 349
286 EXPECT_FALSE(demuxer_->AppendData(info_tracks.get(), info_tracks_size)); 350 EXPECT_FALSE(demuxer_->AppendData(info_tracks.get(), info_tracks_size));
287 } 351 }
288 352
289 static void OnReadDone(const base::TimeDelta& expected_time, 353 static void OnReadDone(const base::TimeDelta& expected_time,
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 base::TimeDelta::FromMilliseconds( 836 base::TimeDelta::FromMilliseconds(
773 buffer_timestamps[i].video_time), 837 buffer_timestamps[i].video_time),
774 &video_read_done)); 838 &video_read_done));
775 839
776 EXPECT_TRUE(audio_read_done); 840 EXPECT_TRUE(audio_read_done);
777 EXPECT_TRUE(video_read_done); 841 EXPECT_TRUE(video_read_done);
778 } 842 }
779 } 843 }
780 844
781 } // namespace media 845 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/chunk_demuxer.cc ('k') | media/webm/webm_cluster_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698