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/webm/webm_cluster_parser.h" | 5 #include "media/formats/webm/webm_cluster_parser.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/sys_byteorder.h" | 10 #include "base/sys_byteorder.h" |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 bool WebMClusterParser::Track::QueueBuffer( | 525 bool WebMClusterParser::Track::QueueBuffer( |
526 const scoped_refptr<StreamParserBuffer>& buffer) { | 526 const scoped_refptr<StreamParserBuffer>& buffer) { |
527 DCHECK(!last_added_buffer_missing_duration_); | 527 DCHECK(!last_added_buffer_missing_duration_); |
528 base::TimeDelta duration = buffer->duration(); | 528 base::TimeDelta duration = buffer->duration(); |
529 if (duration < base::TimeDelta() || duration == kNoTimestamp()) { | 529 if (duration < base::TimeDelta() || duration == kNoTimestamp()) { |
530 DVLOG(2) << "QueueBuffer() : Invalid buffer duration: " | 530 DVLOG(2) << "QueueBuffer() : Invalid buffer duration: " |
531 << duration.InSecondsF(); | 531 << duration.InSecondsF(); |
532 return false; | 532 return false; |
533 } | 533 } |
534 | 534 |
535 estimated_next_frame_duration_ = std::max(duration, | 535 // The estimated frame duration is the minimum non-zero duration since the |
536 estimated_next_frame_duration_); | 536 // last initialization segment. The minimum is used to ensure frame durations |
| 537 // aren't overestimated. |
| 538 if (duration > base::TimeDelta()) { |
| 539 if (estimated_next_frame_duration_ == kNoTimestamp()) { |
| 540 estimated_next_frame_duration_ = duration; |
| 541 } else { |
| 542 estimated_next_frame_duration_ = |
| 543 std::min(duration, estimated_next_frame_duration_); |
| 544 } |
| 545 } |
| 546 |
537 buffers_.push_back(buffer); | 547 buffers_.push_back(buffer); |
538 return true; | 548 return true; |
539 } | 549 } |
540 | 550 |
541 base::TimeDelta WebMClusterParser::Track::GetDurationEstimate() { | 551 base::TimeDelta WebMClusterParser::Track::GetDurationEstimate() { |
542 base::TimeDelta duration = estimated_next_frame_duration_; | 552 base::TimeDelta duration = estimated_next_frame_duration_; |
543 if (duration != kNoTimestamp()) { | 553 if (duration != kNoTimestamp()) { |
544 DVLOG(3) << __FUNCTION__ << " : using estimated duration"; | 554 DVLOG(3) << __FUNCTION__ << " : using estimated duration"; |
545 } else { | 555 } else { |
546 DVLOG(3) << __FUNCTION__ << " : using hardcoded default duration"; | 556 DVLOG(3) << __FUNCTION__ << " : using hardcoded default duration"; |
(...skipping 24 matching lines...) Expand all Loading... |
571 WebMClusterParser::FindTextTrack(int track_num) { | 581 WebMClusterParser::FindTextTrack(int track_num) { |
572 const TextTrackMap::iterator it = text_track_map_.find(track_num); | 582 const TextTrackMap::iterator it = text_track_map_.find(track_num); |
573 | 583 |
574 if (it == text_track_map_.end()) | 584 if (it == text_track_map_.end()) |
575 return NULL; | 585 return NULL; |
576 | 586 |
577 return &it->second; | 587 return &it->second; |
578 } | 588 } |
579 | 589 |
580 } // namespace media | 590 } // namespace media |
OLD | NEW |