OLD | NEW |
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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "media/mp4/box_definitions.h" | 8 #include "media/mp4/box_definitions.h" |
9 #include "media/mp4/rcheck.h" | 9 #include "media/mp4/rcheck.h" |
10 #include "media/mp4/track_run_iterator.h" | 10 #include "media/mp4/track_run_iterator.h" |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 iter_.reset(new TrackRunIterator(&moov_)); | 254 iter_.reset(new TrackRunIterator(&moov_)); |
255 MovieFragment moof = CreateFragment(); | 255 MovieFragment moof = CreateFragment(); |
256 moof.tracks[0].decode_time.decode_time = kAudioScale; | 256 moof.tracks[0].decode_time.decode_time = kAudioScale; |
257 ASSERT_TRUE(iter_->Init(moof)); | 257 ASSERT_TRUE(iter_->Init(moof)); |
258 EXPECT_EQ(TimeDeltaFromRational(moof.tracks[1].decode_time.decode_time, | 258 EXPECT_EQ(TimeDeltaFromRational(moof.tracks[1].decode_time.decode_time, |
259 kVideoScale), | 259 kVideoScale), |
260 iter_->GetMinDecodeTimestamp()); | 260 iter_->GetMinDecodeTimestamp()); |
261 } | 261 } |
262 | 262 |
263 TEST_F(TrackRunIteratorTest, ReorderingTest) { | 263 TEST_F(TrackRunIteratorTest, ReorderingTest) { |
| 264 // Test frame reordering and edit list support. The frames have the following |
| 265 // decode timestamps: |
| 266 // |
| 267 // 0ms 40ms 120ms 240ms |
| 268 // | 0 | 1 - | 2 - - | |
| 269 // |
| 270 // ...and these composition timestamps, after edit list adjustment: |
| 271 // |
| 272 // 0ms 40ms 160ms 240ms |
| 273 // | 0 | 2 - - | 1 - | |
| 274 |
| 275 // Create an edit list with one entry, with an initial start time of 80ms |
| 276 // (that is, 2 / kVideoTimescale) and a duration of zero (which is treated as |
| 277 // infinite according to 14496-12:2012). This will cause the first 80ms of the |
| 278 // media timeline - which will be empty, due to CTS biasing - to be discarded. |
264 iter_.reset(new TrackRunIterator(&moov_)); | 279 iter_.reset(new TrackRunIterator(&moov_)); |
| 280 EditListEntry entry; |
| 281 entry.segment_duration = 0; |
| 282 entry.media_time = 2; |
| 283 entry.media_rate_integer = 1; |
| 284 entry.media_rate_fraction = 0; |
| 285 moov_.tracks[1].edit.list.edits.push_back(entry); |
| 286 |
| 287 // Add CTS offsets. Without bias, the CTS offsets for the first three frames |
| 288 // would simply be [0, 3, -2]. Since CTS offsets should be non-negative for |
| 289 // maximum compatibility, these values are biased up to [2, 5, 0], and the |
| 290 // extra 80ms is removed via the edit list. |
265 MovieFragment moof = CreateFragment(); | 291 MovieFragment moof = CreateFragment(); |
266 std::vector<int32>& cts_offsets = | 292 std::vector<int32>& cts_offsets = |
267 moof.tracks[1].runs[0].sample_composition_time_offsets; | 293 moof.tracks[1].runs[0].sample_composition_time_offsets; |
268 cts_offsets.resize(10); | 294 cts_offsets.resize(10); |
269 cts_offsets[0] = 2; | 295 cts_offsets[0] = 2; |
270 cts_offsets[1] = -1; | 296 cts_offsets[1] = 5; |
| 297 cts_offsets[2] = 0; |
271 moof.tracks[1].decode_time.decode_time = 0; | 298 moof.tracks[1].decode_time.decode_time = 0; |
| 299 |
272 ASSERT_TRUE(iter_->Init(moof)); | 300 ASSERT_TRUE(iter_->Init(moof)); |
273 iter_->AdvanceRun(); | 301 iter_->AdvanceRun(); |
274 EXPECT_EQ(iter_->dts(), TimeDeltaFromRational(0, kVideoScale)); | 302 EXPECT_EQ(iter_->dts(), TimeDeltaFromRational(0, kVideoScale)); |
275 EXPECT_EQ(iter_->cts(), TimeDeltaFromRational(2, kVideoScale)); | 303 EXPECT_EQ(iter_->cts(), TimeDeltaFromRational(0, kVideoScale)); |
276 EXPECT_EQ(iter_->duration(), TimeDeltaFromRational(1, kVideoScale)); | 304 EXPECT_EQ(iter_->duration(), TimeDeltaFromRational(1, kVideoScale)); |
277 iter_->AdvanceSample(); | 305 iter_->AdvanceSample(); |
278 EXPECT_EQ(iter_->dts(), TimeDeltaFromRational(1, kVideoScale)); | 306 EXPECT_EQ(iter_->dts(), TimeDeltaFromRational(1, kVideoScale)); |
279 EXPECT_EQ(iter_->cts(), TimeDeltaFromRational(0, kVideoScale)); | 307 EXPECT_EQ(iter_->cts(), TimeDeltaFromRational(4, kVideoScale)); |
280 EXPECT_EQ(iter_->duration(), TimeDeltaFromRational(2, kVideoScale)); | 308 EXPECT_EQ(iter_->duration(), TimeDeltaFromRational(2, kVideoScale)); |
| 309 iter_->AdvanceSample(); |
| 310 EXPECT_EQ(iter_->dts(), TimeDeltaFromRational(3, kVideoScale)); |
| 311 EXPECT_EQ(iter_->cts(), TimeDeltaFromRational(1, kVideoScale)); |
| 312 EXPECT_EQ(iter_->duration(), TimeDeltaFromRational(3, kVideoScale)); |
281 } | 313 } |
282 | 314 |
283 TEST_F(TrackRunIteratorTest, IgnoreUnknownAuxInfoTest) { | 315 TEST_F(TrackRunIteratorTest, IgnoreUnknownAuxInfoTest) { |
284 iter_.reset(new TrackRunIterator(&moov_)); | 316 iter_.reset(new TrackRunIterator(&moov_)); |
285 MovieFragment moof = CreateFragment(); | 317 MovieFragment moof = CreateFragment(); |
286 moof.tracks[1].auxiliary_offset.offsets.push_back(50); | 318 moof.tracks[1].auxiliary_offset.offsets.push_back(50); |
287 moof.tracks[1].auxiliary_size.default_sample_info_size = 2; | 319 moof.tracks[1].auxiliary_size.default_sample_info_size = 2; |
288 moof.tracks[1].auxiliary_size.sample_count = 2; | 320 moof.tracks[1].auxiliary_size.sample_count = 2; |
289 moof.tracks[1].runs[0].sample_count = 2; | 321 moof.tracks[1].runs[0].sample_count = 2; |
290 ASSERT_TRUE(iter_->Init(moof)); | 322 ASSERT_TRUE(iter_->Init(moof)); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 EXPECT_EQ(iter_->track_id(), 1u); | 437 EXPECT_EQ(iter_->track_id(), 1u); |
406 EXPECT_EQ(iter_->aux_info_offset(), 201); | 438 EXPECT_EQ(iter_->aux_info_offset(), 201); |
407 EXPECT_EQ(iter_->sample_offset(), 10000); | 439 EXPECT_EQ(iter_->sample_offset(), 10000); |
408 EXPECT_EQ(iter_->GetMaxClearOffset(), 201); | 440 EXPECT_EQ(iter_->GetMaxClearOffset(), 201); |
409 EXPECT_TRUE(iter_->CacheAuxInfo(kAuxInfo, arraysize(kAuxInfo))); | 441 EXPECT_TRUE(iter_->CacheAuxInfo(kAuxInfo, arraysize(kAuxInfo))); |
410 EXPECT_EQ(iter_->GetMaxClearOffset(), 10000); | 442 EXPECT_EQ(iter_->GetMaxClearOffset(), 10000); |
411 } | 443 } |
412 | 444 |
413 } // namespace mp4 | 445 } // namespace mp4 |
414 } // namespace media | 446 } // namespace media |
OLD | NEW |