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

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

Issue 10447035: Introducing DecoderBuffer and general Buffer cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Buffer Bonanza! Created 8 years, 7 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
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 "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/decoder_buffer.h"
7 #include "media/base/mock_callback.h" 8 #include "media/base/mock_callback.h"
8 #include "media/base/mock_demuxer_host.h" 9 #include "media/base/mock_demuxer_host.h"
9 #include "media/base/test_data_util.h" 10 #include "media/base/test_data_util.h"
10 #include "media/filters/chunk_demuxer.h" 11 #include "media/filters/chunk_demuxer.h"
11 #include "media/filters/chunk_demuxer_client.h" 12 #include "media/filters/chunk_demuxer_client.h"
12 #include "media/webm/cluster_builder.h" 13 #include "media/webm/cluster_builder.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 using ::testing::AnyNumber; 16 using ::testing::AnyNumber;
16 using ::testing::InSequence; 17 using ::testing::InSequence;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 63 }
63 } 64 }
64 65
65 MATCHER_P(HasTimestamp, timestamp_in_ms, "") { 66 MATCHER_P(HasTimestamp, timestamp_in_ms, "") {
66 return arg && !arg->IsEndOfStream() && 67 return arg && !arg->IsEndOfStream() &&
67 arg->GetTimestamp().InMilliseconds() == timestamp_in_ms; 68 arg->GetTimestamp().InMilliseconds() == timestamp_in_ms;
68 } 69 }
69 70
70 static void OnReadDone(const base::TimeDelta& expected_time, 71 static void OnReadDone(const base::TimeDelta& expected_time,
71 bool* called, 72 bool* called,
72 const scoped_refptr<Buffer>& buffer) { 73 const scoped_refptr<DecoderBuffer>& buffer) {
73 EXPECT_EQ(expected_time, buffer->GetTimestamp()); 74 EXPECT_EQ(expected_time, buffer->GetTimestamp());
74 *called = true; 75 *called = true;
75 } 76 }
76 77
77 class MockChunkDemuxerClient : public ChunkDemuxerClient { 78 class MockChunkDemuxerClient : public ChunkDemuxerClient {
78 public: 79 public:
79 MockChunkDemuxerClient() {} 80 MockChunkDemuxerClient() {}
80 virtual ~MockChunkDemuxerClient() {} 81 virtual ~MockChunkDemuxerClient() {}
81 82
82 MOCK_METHOD1(DemuxerOpened, void(ChunkDemuxer* demuxer)); 83 MOCK_METHOD1(DemuxerOpened, void(ChunkDemuxer* demuxer));
(...skipping 24 matching lines...) Expand all
107 demuxer_(new ChunkDemuxer(client_.get())) { 108 demuxer_(new ChunkDemuxer(client_.get())) {
108 } 109 }
109 110
110 virtual ~ChunkDemuxerTest() { 111 virtual ~ChunkDemuxerTest() {
111 ShutdownDemuxer(); 112 ShutdownDemuxer();
112 } 113 }
113 114
114 void CreateInfoTracks(bool has_audio, bool has_video, 115 void CreateInfoTracks(bool has_audio, bool has_video,
115 bool video_content_encoded, scoped_array<uint8>* buffer, 116 bool video_content_encoded, scoped_array<uint8>* buffer,
116 int* size) { 117 int* size) {
117 scoped_array<uint8> info; 118 scoped_refptr<DecoderBuffer> info;
scherkus (not reviewing) 2012/05/26 01:36:32 nice cleanup!
118 int info_size = 0; 119 scoped_refptr<DecoderBuffer> audio_track_entry;
119 scoped_array<uint8> audio_track_entry; 120 scoped_refptr<DecoderBuffer> video_track_entry;
120 int audio_track_entry_size = 0; 121 scoped_refptr<DecoderBuffer> video_content_encodings;
121 scoped_array<uint8> video_track_entry;
122 int video_track_entry_size = 0;
123 scoped_array<uint8> video_content_encodings;
124 int video_content_encodings_size = 0;
125 122
126 ReadTestDataFile("webm_info_element", &info, &info_size); 123 info = ReadTestDataFile("webm_info_element");
127 124
128 int tracks_element_size = 0; 125 int tracks_element_size = 0;
129 126
130 if (has_audio) { 127 if (has_audio) {
131 ReadTestDataFile("webm_vorbis_track_entry", &audio_track_entry, 128 audio_track_entry = ReadTestDataFile("webm_vorbis_track_entry");
132 &audio_track_entry_size); 129 tracks_element_size += audio_track_entry->GetDataSize();
133 tracks_element_size += audio_track_entry_size;
134 } 130 }
135 131
136 if (has_video) { 132 if (has_video) {
137 ReadTestDataFile("webm_vp8_track_entry", &video_track_entry, 133 video_track_entry = ReadTestDataFile("webm_vp8_track_entry");
138 &video_track_entry_size); 134 tracks_element_size += video_track_entry->GetDataSize();
139 tracks_element_size += video_track_entry_size;
140 if (video_content_encoded) { 135 if (video_content_encoded) {
141 ReadTestDataFile("webm_content_encodings", &video_content_encodings, 136 video_content_encodings = ReadTestDataFile("webm_content_encodings");
142 &video_content_encodings_size); 137 tracks_element_size += video_content_encodings->GetDataSize();
143 tracks_element_size += video_content_encodings_size;
144 } 138 }
145 } 139 }
146 140
147 *size = info_size + kTracksHeaderSize + tracks_element_size; 141 *size = info->GetDataSize() + kTracksHeaderSize + tracks_element_size;
148 142
149 buffer->reset(new uint8[*size]); 143 buffer->reset(new uint8[*size]);
150 144
151 uint8* buf = buffer->get(); 145 uint8* buf = buffer->get();
152 memcpy(buf, info.get(), info_size); 146 memcpy(buf, info->GetData(), info->GetDataSize());
153 buf += info_size; 147 buf += info->GetDataSize();
154 148
155 memcpy(buf, kTracksHeader, kTracksHeaderSize); 149 memcpy(buf, kTracksHeader, kTracksHeaderSize);
156 WriteInt64(buf + kTracksSizeOffset, tracks_element_size); 150 WriteInt64(buf + kTracksSizeOffset, tracks_element_size);
157 buf += kTracksHeaderSize; 151 buf += kTracksHeaderSize;
158 152
159 if (has_audio) { 153 if (has_audio) {
160 memcpy(buf, audio_track_entry.get(), audio_track_entry_size); 154 memcpy(buf, audio_track_entry->GetData(),
161 buf += audio_track_entry_size; 155 audio_track_entry->GetDataSize());
156 buf += audio_track_entry->GetDataSize();
162 } 157 }
163 158
164 if (has_video) { 159 if (has_video) {
165 memcpy(buf, video_track_entry.get(), video_track_entry_size); 160 memcpy(buf, video_track_entry->GetData(),
161 video_track_entry->GetDataSize());
166 if (video_content_encoded) { 162 if (video_content_encoded) {
167 memcpy(buf + video_track_entry_size, video_content_encodings.get(), 163 memcpy(buf + video_track_entry->GetDataSize(),
168 video_content_encodings_size); 164 video_content_encodings->GetData(),
169 video_track_entry_size += video_content_encodings_size; 165 video_content_encodings->GetDataSize());
170 WriteInt64(buf + kVideoTrackSizeOffset, 166 WriteInt64(buf + kVideoTrackSizeOffset, video_track_entry->GetDataSize()
171 video_track_entry_size - kVideoTrackEntryHeaderSize); 167 + video_content_encodings->GetDataSize()
scherkus (not reviewing) 2012/05/26 01:36:32 indenting here is funny maybe drop video_track_en
DaleCurtis 2012/05/29 21:17:01 Done.
168 - kVideoTrackEntryHeaderSize);
scherkus (not reviewing) 2012/05/26 01:36:32 also binary operators go @ the end of the previous
DaleCurtis 2012/05/29 21:17:01 Done.
169 buf += video_content_encodings->GetDataSize();
172 } 170 }
173 buf += video_track_entry_size; 171 buf += video_track_entry->GetDataSize();
174 } 172 }
175 } 173 }
176 174
177 ChunkDemuxer::Status AddId() { 175 ChunkDemuxer::Status AddId() {
178 std::vector<std::string> codecs(2); 176 std::vector<std::string> codecs(2);
179 codecs[0] = "vp8"; 177 codecs[0] = "vp8";
180 codecs[1] = "vorbis"; 178 codecs[1] = "vorbis";
181 return demuxer_->AddId(kSourceId, "video/webm", codecs); 179 return demuxer_->AddId(kSourceId, "video/webm", codecs);
182 } 180 }
183 181
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 ExpectRead(audio, audio_timecode); 325 ExpectRead(audio, audio_timecode);
328 audio_timecode += kAudioBlockDuration; 326 audio_timecode += kAudioBlockDuration;
329 continue; 327 continue;
330 } 328 }
331 329
332 ExpectRead(video, video_timecode); 330 ExpectRead(video, video_timecode);
333 video_timecode += kVideoBlockDuration; 331 video_timecode += kVideoBlockDuration;
334 } 332 }
335 } 333 }
336 334
337 MOCK_METHOD1(ReadDone, void(const scoped_refptr<Buffer>&)); 335 MOCK_METHOD1(ReadDone, void(const scoped_refptr<DecoderBuffer>&));
338 336
339 void ExpectRead(DemuxerStream* stream, int64 timestamp_in_ms) { 337 void ExpectRead(DemuxerStream* stream, int64 timestamp_in_ms) {
340 EXPECT_CALL(*this, ReadDone(HasTimestamp(timestamp_in_ms))); 338 EXPECT_CALL(*this, ReadDone(HasTimestamp(timestamp_in_ms)));
341 stream->Read(base::Bind(&ChunkDemuxerTest::ReadDone, 339 stream->Read(base::Bind(&ChunkDemuxerTest::ReadDone,
342 base::Unretained(this))); 340 base::Unretained(this)));
343 } 341 }
344 342
345 MOCK_METHOD1(Checkpoint, void(int id)); 343 MOCK_METHOD1(Checkpoint, void(int id));
346 344
347 struct BufferTimestamps { 345 struct BufferTimestamps {
348 int video_time_ms; 346 int video_time_ms;
349 int audio_time_ms; 347 int audio_time_ms;
350 }; 348 };
351 static const int kSkip = -1; 349 static const int kSkip = -1;
352 350
353 // Test parsing a WebM file. 351 // Test parsing a WebM file.
354 // |filename| - The name of the file in media/test/data to parse. 352 // |filename| - The name of the file in media/test/data to parse.
355 // |timestamps| - The expected timestamps on the parsed buffers. 353 // |timestamps| - The expected timestamps on the parsed buffers.
356 // a timestamp of kSkip indicates that a Read() call for that stream 354 // a timestamp of kSkip indicates that a Read() call for that stream
357 // shouldn't be made on that iteration of the loop. If both streams have 355 // shouldn't be made on that iteration of the loop. If both streams have
358 // a kSkip then the loop will terminate. 356 // a kSkip then the loop will terminate.
359 bool ParseWebMFile(const std::string& filename, 357 bool ParseWebMFile(const std::string& filename,
360 const BufferTimestamps* timestamps, 358 const BufferTimestamps* timestamps,
361 const base::TimeDelta& duration) { 359 const base::TimeDelta& duration) {
362 scoped_array<uint8> buffer;
363 int buffer_size = 0;
364
365 EXPECT_CALL(*client_, DemuxerOpened(_)); 360 EXPECT_CALL(*client_, DemuxerOpened(_));
366 demuxer_->Initialize( 361 demuxer_->Initialize(
367 &host_, CreateInitDoneCB(duration, PIPELINE_OK)); 362 &host_, CreateInitDoneCB(duration, PIPELINE_OK));
368 363
369 if (AddId() != ChunkDemuxer::kOk) 364 if (AddId() != ChunkDemuxer::kOk)
370 return false; 365 return false;
371 366
372 // Read a WebM file into memory and send the data to the demuxer. 367 // Read a WebM file into memory and send the data to the demuxer.
373 ReadTestDataFile(filename, &buffer, &buffer_size); 368 scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile(filename);
374 if (!AppendDataInPieces(buffer.get(), buffer_size, 512)) 369 if (!AppendDataInPieces(buffer->GetData(), buffer->GetDataSize(), 512))
375 return false; 370 return false;
376 371
377 scoped_refptr<DemuxerStream> audio = 372 scoped_refptr<DemuxerStream> audio =
378 demuxer_->GetStream(DemuxerStream::AUDIO); 373 demuxer_->GetStream(DemuxerStream::AUDIO);
379 scoped_refptr<DemuxerStream> video = 374 scoped_refptr<DemuxerStream> video =
380 demuxer_->GetStream(DemuxerStream::VIDEO); 375 demuxer_->GetStream(DemuxerStream::VIDEO);
381 376
382 // Verify that the timestamps on the first few packets match what we 377 // Verify that the timestamps on the first few packets match what we
383 // expect. 378 // expect.
384 for (size_t i = 0; 379 for (size_t i = 0;
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 } 758 }
764 759
765 // Check to see if |audio_read_done_| and |video_read_done_| variables 760 // Check to see if |audio_read_done_| and |video_read_done_| variables
766 // match |expected|. 761 // match |expected|.
767 void CheckIfReadDonesWereCalled(bool expected) { 762 void CheckIfReadDonesWereCalled(bool expected) {
768 EXPECT_EQ(expected, audio_read_done_); 763 EXPECT_EQ(expected, audio_read_done_);
769 EXPECT_EQ(expected, video_read_done_); 764 EXPECT_EQ(expected, video_read_done_);
770 } 765 }
771 766
772 private: 767 private:
773 static void OnEndOfStreamReadDone(bool* called, 768 static void OnEndOfStreamReadDone(
774 const scoped_refptr<Buffer>& buffer) { 769 bool* called, const scoped_refptr<DecoderBuffer>& buffer) {
775 EXPECT_TRUE(buffer->IsEndOfStream()); 770 EXPECT_TRUE(buffer->IsEndOfStream());
776 *called = true; 771 *called = true;
777 } 772 }
778 773
779 scoped_refptr<Demuxer> demuxer_; 774 scoped_refptr<Demuxer> demuxer_;
780 bool audio_read_done_; 775 bool audio_read_done_;
781 bool video_read_done_; 776 bool video_read_done_;
782 777
783 DISALLOW_COPY_AND_ASSIGN(EndOfStreamHelper); 778 DISALLOW_COPY_AND_ASSIGN(EndOfStreamHelper);
784 }; 779 };
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 1067
1073 std::vector<std::string> codecs(1); 1068 std::vector<std::string> codecs(1);
1074 codecs[0] = "vp8"; 1069 codecs[0] = "vp8";
1075 ASSERT_EQ(demuxer_->AddId(kSourceId, "video/webm", codecs), 1070 ASSERT_EQ(demuxer_->AddId(kSourceId, "video/webm", codecs),
1076 ChunkDemuxer::kOk); 1071 ChunkDemuxer::kOk);
1077 1072
1078 ASSERT_TRUE(AppendInfoTracks(true, true, false)); 1073 ASSERT_TRUE(AppendInfoTracks(true, true, false));
1079 } 1074 }
1080 1075
1081 } // namespace media 1076 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698