OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "media/formats/mp4/track_run_iterator.h" | 5 #include "media/formats/mp4/track_run_iterator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "media/base/buffers.h" | 9 #include "media/base/buffers.h" |
10 #include "media/base/stream_parser_buffer.h" | |
11 #include "media/formats/mp4/rcheck.h" | 10 #include "media/formats/mp4/rcheck.h" |
12 #include "media/formats/mp4/sample_to_group_iterator.h" | 11 #include "media/formats/mp4/sample_to_group_iterator.h" |
13 | 12 |
14 namespace media { | 13 namespace media { |
15 namespace mp4 { | 14 namespace mp4 { |
16 | 15 |
17 struct SampleInfo { | 16 struct SampleInfo { |
18 int size; | 17 int size; |
19 int duration; | 18 int duration; |
20 int cts_offset; | 19 int cts_offset; |
(...skipping 29 matching lines...) Expand all Loading... |
50 timescale(-1), | 49 timescale(-1), |
51 start_dts(-1), | 50 start_dts(-1), |
52 sample_start_offset(-1), | 51 sample_start_offset(-1), |
53 is_audio(false), | 52 is_audio(false), |
54 aux_info_start_offset(-1), | 53 aux_info_start_offset(-1), |
55 aux_info_default_size(-1), | 54 aux_info_default_size(-1), |
56 aux_info_total_size(-1) { | 55 aux_info_total_size(-1) { |
57 } | 56 } |
58 TrackRunInfo::~TrackRunInfo() {} | 57 TrackRunInfo::~TrackRunInfo() {} |
59 | 58 |
60 TimeDelta TimeDeltaFromRational(int64 numer, int64 denom) { | 59 base::TimeDelta TimeDeltaFromRational(int64 numer, int64 denom) { |
61 // To avoid overflow, split the following calculation: | 60 // To avoid overflow, split the following calculation: |
62 // (numer * base::Time::kMicrosecondsPerSecond) / denom | 61 // (numer * base::Time::kMicrosecondsPerSecond) / denom |
63 // into: | 62 // into: |
64 // (numer / denom) * base::Time::kMicrosecondsPerSecond + | 63 // (numer / denom) * base::Time::kMicrosecondsPerSecond + |
65 // ((numer % denom) * base::Time::kMicrosecondsPerSecond) / denom | 64 // ((numer % denom) * base::Time::kMicrosecondsPerSecond) / denom |
66 int64 a = numer / denom; | 65 int64 a = numer / denom; |
67 DCHECK_LE((a > 0 ? a : -a), kint64max / base::Time::kMicrosecondsPerSecond); | 66 DCHECK_LE((a > 0 ? a : -a), kint64max / base::Time::kMicrosecondsPerSecond); |
68 int64 timea_in_us = a * base::Time::kMicrosecondsPerSecond; | 67 int64 timea_in_us = a * base::Time::kMicrosecondsPerSecond; |
69 | 68 |
70 int64 b = numer % denom; | 69 int64 b = numer % denom; |
71 DCHECK_LE((b > 0 ? b : -b), kint64max / base::Time::kMicrosecondsPerSecond); | 70 DCHECK_LE((b > 0 ? b : -b), kint64max / base::Time::kMicrosecondsPerSecond); |
72 int64 timeb_in_us = (b * base::Time::kMicrosecondsPerSecond) / denom; | 71 int64 timeb_in_us = (b * base::Time::kMicrosecondsPerSecond) / denom; |
73 | 72 |
74 DCHECK((timeb_in_us < 0) || (timea_in_us <= kint64max - timeb_in_us)); | 73 DCHECK((timeb_in_us < 0) || (timea_in_us <= kint64max - timeb_in_us)); |
75 DCHECK((timeb_in_us > 0) || (timea_in_us >= kint64min - timeb_in_us)); | 74 DCHECK((timeb_in_us > 0) || (timea_in_us >= kint64min - timeb_in_us)); |
76 return TimeDelta::FromMicroseconds(timea_in_us + timeb_in_us); | 75 return base::TimeDelta::FromMicroseconds(timea_in_us + timeb_in_us); |
| 76 } |
| 77 |
| 78 DecodeTimestamp DecodeTimestampFromRational(int64 numer, int64 denom) { |
| 79 return DecodeTimestamp::FromPresentationTime( |
| 80 TimeDeltaFromRational(numer, denom)); |
77 } | 81 } |
78 | 82 |
79 TrackRunIterator::TrackRunIterator(const Movie* moov, | 83 TrackRunIterator::TrackRunIterator(const Movie* moov, |
80 const LogCB& log_cb) | 84 const LogCB& log_cb) |
81 : moov_(moov), log_cb_(log_cb), sample_offset_(0) { | 85 : moov_(moov), log_cb_(log_cb), sample_offset_(0) { |
82 CHECK(moov); | 86 CHECK(moov); |
83 } | 87 } |
84 | 88 |
85 TrackRunIterator::~TrackRunIterator() {} | 89 TrackRunIterator::~TrackRunIterator() {} |
86 | 90 |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 int64 TrackRunIterator::sample_offset() const { | 466 int64 TrackRunIterator::sample_offset() const { |
463 DCHECK(IsSampleValid()); | 467 DCHECK(IsSampleValid()); |
464 return sample_offset_; | 468 return sample_offset_; |
465 } | 469 } |
466 | 470 |
467 int TrackRunIterator::sample_size() const { | 471 int TrackRunIterator::sample_size() const { |
468 DCHECK(IsSampleValid()); | 472 DCHECK(IsSampleValid()); |
469 return sample_itr_->size; | 473 return sample_itr_->size; |
470 } | 474 } |
471 | 475 |
472 TimeDelta TrackRunIterator::dts() const { | 476 DecodeTimestamp TrackRunIterator::dts() const { |
473 DCHECK(IsSampleValid()); | 477 DCHECK(IsSampleValid()); |
474 return TimeDeltaFromRational(sample_dts_, run_itr_->timescale); | 478 return DecodeTimestampFromRational(sample_dts_, run_itr_->timescale); |
475 } | 479 } |
476 | 480 |
477 TimeDelta TrackRunIterator::cts() const { | 481 base::TimeDelta TrackRunIterator::cts() const { |
478 DCHECK(IsSampleValid()); | 482 DCHECK(IsSampleValid()); |
479 return TimeDeltaFromRational(sample_dts_ + sample_itr_->cts_offset, | 483 return TimeDeltaFromRational(sample_dts_ + sample_itr_->cts_offset, |
480 run_itr_->timescale); | 484 run_itr_->timescale); |
481 } | 485 } |
482 | 486 |
483 TimeDelta TrackRunIterator::duration() const { | 487 base::TimeDelta TrackRunIterator::duration() const { |
484 DCHECK(IsSampleValid()); | 488 DCHECK(IsSampleValid()); |
485 return TimeDeltaFromRational(sample_itr_->duration, run_itr_->timescale); | 489 return TimeDeltaFromRational(sample_itr_->duration, run_itr_->timescale); |
486 } | 490 } |
487 | 491 |
488 bool TrackRunIterator::is_keyframe() const { | 492 bool TrackRunIterator::is_keyframe() const { |
489 DCHECK(IsSampleValid()); | 493 DCHECK(IsSampleValid()); |
490 return sample_itr_->is_keyframe; | 494 return sample_itr_->is_keyframe; |
491 } | 495 } |
492 | 496 |
493 bool TrackRunIterator::is_random_access_point() const { | 497 bool TrackRunIterator::is_random_access_point() const { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 } | 564 } |
561 | 565 |
562 uint8 TrackRunIterator::GetIvSize(size_t sample_index) const { | 566 uint8 TrackRunIterator::GetIvSize(size_t sample_index) const { |
563 uint32 index = GetGroupDescriptionIndex(sample_index); | 567 uint32 index = GetGroupDescriptionIndex(sample_index); |
564 return (index == 0) ? track_encryption().default_iv_size | 568 return (index == 0) ? track_encryption().default_iv_size |
565 : GetSampleEncryptionInfoEntry(index).iv_size; | 569 : GetSampleEncryptionInfoEntry(index).iv_size; |
566 } | 570 } |
567 | 571 |
568 } // namespace mp4 | 572 } // namespace mp4 |
569 } // namespace media | 573 } // namespace media |
OLD | NEW |