Chromium Code Reviews| 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" | 10 #include "media/base/stream_parser_buffer.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 start_dts(-1), | 50 start_dts(-1), |
| 51 sample_start_offset(-1), | 51 sample_start_offset(-1), |
| 52 is_audio(false), | 52 is_audio(false), |
| 53 aux_info_start_offset(-1), | 53 aux_info_start_offset(-1), |
| 54 aux_info_default_size(-1), | 54 aux_info_default_size(-1), |
| 55 aux_info_total_size(-1) { | 55 aux_info_total_size(-1) { |
| 56 } | 56 } |
| 57 TrackRunInfo::~TrackRunInfo() {} | 57 TrackRunInfo::~TrackRunInfo() {} |
| 58 | 58 |
| 59 TimeDelta TimeDeltaFromRational(int64 numer, int64 denom) { | 59 TimeDelta TimeDeltaFromRational(int64 numer, int64 denom) { |
| 60 DCHECK_LT((numer > 0 ? numer : -numer), | 60 // To avoid overflow, split the following calculation: |
|
DaleCurtis
2014/02/22 01:41:20
Why not TimeDelta::FromMicroseconds((static_cast<d
damienv1
2014/02/22 01:53:01
I was wondering if in some cases you can loose som
acolwell GONE FROM CHROMIUM
2014/02/22 02:00:35
The conversion to double can lose precision if |nu
| |
| 61 kint64max / base::Time::kMicrosecondsPerSecond); | 61 // (numer * base::Time::kMicrosecondsPerSecond) / denom |
| 62 return TimeDelta::FromMicroseconds( | 62 // into: |
| 63 base::Time::kMicrosecondsPerSecond * numer / denom); | 63 // (numer / denom) * base::Time::kMicrosecondsPerSecond + |
| 64 // ((numer % denom) * base::Time::kMicrosecondsPerSecond) / denom | |
| 65 int64 a = numer / denom; | |
| 66 DCHECK_LE((a > 0 ? a : -a), kint64max / base::Time::kMicrosecondsPerSecond); | |
| 67 int64 timea_in_us = a * base::Time::kMicrosecondsPerSecond; | |
| 68 | |
| 69 int64 b = numer % denom; | |
| 70 DCHECK_LE((b > 0 ? b : -b), kint64max / base::Time::kMicrosecondsPerSecond); | |
| 71 int64 timeb_in_us = (b * base::Time::kMicrosecondsPerSecond) / denom; | |
| 72 | |
| 73 DCHECK((timeb_in_us < 0) || (timea_in_us <= kint64max - timeb_in_us)); | |
| 74 DCHECK((timeb_in_us > 0) || (timea_in_us >= kint64min - timeb_in_us)); | |
| 75 return TimeDelta::FromMicroseconds(timea_in_us + timeb_in_us); | |
| 64 } | 76 } |
| 65 | 77 |
| 66 TrackRunIterator::TrackRunIterator(const Movie* moov, | 78 TrackRunIterator::TrackRunIterator(const Movie* moov, |
| 67 const LogCB& log_cb) | 79 const LogCB& log_cb) |
| 68 : moov_(moov), log_cb_(log_cb), sample_offset_(0) { | 80 : moov_(moov), log_cb_(log_cb), sample_offset_(0) { |
| 69 CHECK(moov); | 81 CHECK(moov); |
| 70 } | 82 } |
| 71 | 83 |
| 72 TrackRunIterator::~TrackRunIterator() {} | 84 TrackRunIterator::~TrackRunIterator() {} |
| 73 | 85 |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 const std::vector<uint8>& kid = track_encryption().default_kid; | 470 const std::vector<uint8>& kid = track_encryption().default_kid; |
| 459 return scoped_ptr<DecryptConfig>(new DecryptConfig( | 471 return scoped_ptr<DecryptConfig>(new DecryptConfig( |
| 460 std::string(reinterpret_cast<const char*>(&kid[0]), kid.size()), | 472 std::string(reinterpret_cast<const char*>(&kid[0]), kid.size()), |
| 461 std::string(reinterpret_cast<const char*>(cenc_info.iv), | 473 std::string(reinterpret_cast<const char*>(cenc_info.iv), |
| 462 arraysize(cenc_info.iv)), | 474 arraysize(cenc_info.iv)), |
| 463 cenc_info.subsamples)); | 475 cenc_info.subsamples)); |
| 464 } | 476 } |
| 465 | 477 |
| 466 } // namespace mp4 | 478 } // namespace mp4 |
| 467 } // namespace media | 479 } // namespace media |
| OLD | NEW |