| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 106 |
| 107 last_block_timecode_ = -1; | 107 last_block_timecode_ = -1; |
| 108 cluster_timecode_ = -1; | 108 cluster_timecode_ = -1; |
| 109 } | 109 } |
| 110 | 110 |
| 111 return result; | 111 return result; |
| 112 } | 112 } |
| 113 | 113 |
| 114 const WebMClusterParser::BufferQueue& WebMClusterParser::GetAudioBuffers() { | 114 const WebMClusterParser::BufferQueue& WebMClusterParser::GetAudioBuffers() { |
| 115 if (cluster_ended_) | 115 if (cluster_ended_) |
| 116 audio_.ApplyDurationDefaultOrEstimateIfNeeded(); | 116 audio_.ApplyDurationEstimateIfNeeded(); |
| 117 return audio_.buffers(); | 117 return audio_.buffers(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 const WebMClusterParser::BufferQueue& WebMClusterParser::GetVideoBuffers() { | 120 const WebMClusterParser::BufferQueue& WebMClusterParser::GetVideoBuffers() { |
| 121 if (cluster_ended_) | 121 if (cluster_ended_) |
| 122 video_.ApplyDurationDefaultOrEstimateIfNeeded(); | 122 video_.ApplyDurationEstimateIfNeeded(); |
| 123 return video_.buffers(); | 123 return video_.buffers(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 const WebMClusterParser::TextBufferQueueMap& | 126 const WebMClusterParser::TextBufferQueueMap& |
| 127 WebMClusterParser::GetTextBuffers() { | 127 WebMClusterParser::GetTextBuffers() { |
| 128 // Translate our |text_track_map_| into |text_buffers_map_|, inserting rows in | 128 // Translate our |text_track_map_| into |text_buffers_map_|, inserting rows in |
| 129 // the output only for non-empty text buffer queues in |text_track_map_|. | 129 // the output only for non-empty text buffer queues in |text_track_map_|. |
| 130 text_buffers_map_.clear(); | 130 text_buffers_map_.clear(); |
| 131 for (TextTrackMap::const_iterator itr = text_track_map_.begin(); | 131 for (TextTrackMap::const_iterator itr = text_track_map_.begin(); |
| 132 itr != text_track_map_.end(); | 132 itr != text_track_map_.end(); |
| 133 ++itr) { | 133 ++itr) { |
| 134 // Per OnBlock(), all text buffers should already have valid durations, so | 134 // Per OnBlock(), all text buffers should already have valid durations, so |
| 135 // there is no need to call | 135 // there is no need to call |
| 136 // itr->second.ApplyDurationDefaultOrEstimateIfNeeded() here. | 136 // itr->second.ApplyDurationEstimateIfNeeded() here. |
| 137 const BufferQueue& text_buffers = itr->second.buffers(); | 137 const BufferQueue& text_buffers = itr->second.buffers(); |
| 138 if (!text_buffers.empty()) | 138 if (!text_buffers.empty()) |
| 139 text_buffers_map_.insert(std::make_pair(itr->first, text_buffers)); | 139 text_buffers_map_.insert(std::make_pair(itr->first, text_buffers)); |
| 140 } | 140 } |
| 141 | 141 |
| 142 return text_buffers_map_; | 142 return text_buffers_map_; |
| 143 } | 143 } |
| 144 | 144 |
| 145 WebMParserClient* WebMClusterParser::OnListStart(int id) { | 145 WebMParserClient* WebMClusterParser::OnListStart(int id) { |
| 146 if (id == kWebMIdCluster) { | 146 if (id == kWebMIdCluster) { |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 true, buffer_type, track_num); | 400 true, buffer_type, track_num); |
| 401 } | 401 } |
| 402 | 402 |
| 403 buffer->set_timestamp(timestamp); | 403 buffer->set_timestamp(timestamp); |
| 404 if (cluster_start_time_ == kNoTimestamp()) | 404 if (cluster_start_time_ == kNoTimestamp()) |
| 405 cluster_start_time_ = timestamp; | 405 cluster_start_time_ = timestamp; |
| 406 | 406 |
| 407 if (block_duration >= 0) { | 407 if (block_duration >= 0) { |
| 408 buffer->set_duration(base::TimeDelta::FromMicroseconds( | 408 buffer->set_duration(base::TimeDelta::FromMicroseconds( |
| 409 block_duration * timecode_multiplier_)); | 409 block_duration * timecode_multiplier_)); |
| 410 } else { |
| 411 DCHECK_NE(buffer_type, DemuxerStream::TEXT); |
| 412 buffer->set_duration(track->default_duration()); |
| 410 } | 413 } |
| 411 | 414 |
| 412 if (discard_padding != 0) { | 415 if (discard_padding != 0) { |
| 413 buffer->set_discard_padding(base::TimeDelta::FromMicroseconds( | 416 buffer->set_discard_padding(base::TimeDelta::FromMicroseconds( |
| 414 discard_padding / 1000)); | 417 discard_padding / 1000)); |
| 415 } | 418 } |
| 416 | 419 |
| 417 return track->AddBuffer(buffer); | 420 return track->AddBuffer(buffer); |
| 418 } | 421 } |
| 419 | 422 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 461 |
| 459 if (buffer->duration() == kNoTimestamp()) { | 462 if (buffer->duration() == kNoTimestamp()) { |
| 460 last_added_buffer_missing_duration_ = buffer; | 463 last_added_buffer_missing_duration_ = buffer; |
| 461 DVLOG(2) << "AddBuffer() : holding back buffer that is missing duration"; | 464 DVLOG(2) << "AddBuffer() : holding back buffer that is missing duration"; |
| 462 return true; | 465 return true; |
| 463 } | 466 } |
| 464 | 467 |
| 465 return QueueBuffer(buffer); | 468 return QueueBuffer(buffer); |
| 466 } | 469 } |
| 467 | 470 |
| 468 void WebMClusterParser::Track::ApplyDurationDefaultOrEstimateIfNeeded() { | 471 void WebMClusterParser::Track::ApplyDurationEstimateIfNeeded() { |
| 469 if (!last_added_buffer_missing_duration_) | 472 if (!last_added_buffer_missing_duration_) |
| 470 return; | 473 return; |
| 471 | 474 |
| 472 last_added_buffer_missing_duration_->set_duration( | 475 last_added_buffer_missing_duration_->set_duration(GetDurationEstimate()); |
| 473 GetDurationDefaultOrEstimate()); | |
| 474 | 476 |
| 475 DVLOG(2) << "ApplyDurationDefaultOrEstimateIfNeeded() : new dur : " | 477 DVLOG(2) << "ApplyDurationEstimateIfNeeded() : new dur : " |
| 476 << " ts " | 478 << " ts " |
| 477 << last_added_buffer_missing_duration_->timestamp().InSecondsF() | 479 << last_added_buffer_missing_duration_->timestamp().InSecondsF() |
| 478 << " dur " | 480 << " dur " |
| 479 << last_added_buffer_missing_duration_->duration().InSecondsF() | 481 << last_added_buffer_missing_duration_->duration().InSecondsF() |
| 480 << " kf " << last_added_buffer_missing_duration_->IsKeyframe() | 482 << " kf " << last_added_buffer_missing_duration_->IsKeyframe() |
| 481 << " size " << last_added_buffer_missing_duration_->data_size(); | 483 << " size " << last_added_buffer_missing_duration_->data_size(); |
| 482 | 484 |
| 483 // Don't use the applied duration as a future estimation (don't use | 485 // Don't use the applied duration as a future estimation (don't use |
| 484 // QueueBuffer() here.) | 486 // QueueBuffer() here.) |
| 485 buffers_.push_back(last_added_buffer_missing_duration_); | 487 buffers_.push_back(last_added_buffer_missing_duration_); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 << duration.InSecondsF(); | 531 << duration.InSecondsF(); |
| 530 return false; | 532 return false; |
| 531 } | 533 } |
| 532 | 534 |
| 533 estimated_next_frame_duration_ = std::max(duration, | 535 estimated_next_frame_duration_ = std::max(duration, |
| 534 estimated_next_frame_duration_); | 536 estimated_next_frame_duration_); |
| 535 buffers_.push_back(buffer); | 537 buffers_.push_back(buffer); |
| 536 return true; | 538 return true; |
| 537 } | 539 } |
| 538 | 540 |
| 539 base::TimeDelta WebMClusterParser::Track::GetDurationDefaultOrEstimate() { | 541 base::TimeDelta WebMClusterParser::Track::GetDurationEstimate() { |
| 540 base::TimeDelta duration = default_duration_; | 542 base::TimeDelta duration = estimated_next_frame_duration_; |
| 541 if (duration != kNoTimestamp()) { | 543 if (duration != kNoTimestamp()) { |
| 542 DVLOG(3) << __FUNCTION__ << " : using TrackEntry DefaultDuration"; | |
| 543 } else if (estimated_next_frame_duration_ != kNoTimestamp()) { | |
| 544 DVLOG(3) << __FUNCTION__ << " : using estimated duration"; | 544 DVLOG(3) << __FUNCTION__ << " : using estimated duration"; |
| 545 duration = estimated_next_frame_duration_; | |
| 546 } else { | 545 } else { |
| 547 DVLOG(3) << __FUNCTION__ << " : using hardcoded default duration"; | 546 DVLOG(3) << __FUNCTION__ << " : using hardcoded default duration"; |
| 548 if (is_video_) { | 547 if (is_video_) { |
| 549 duration = base::TimeDelta::FromMilliseconds( | 548 duration = base::TimeDelta::FromMilliseconds( |
| 550 kDefaultVideoBufferDurationInMs); | 549 kDefaultVideoBufferDurationInMs); |
| 551 } else { | 550 } else { |
| 552 duration = base::TimeDelta::FromMilliseconds( | 551 duration = base::TimeDelta::FromMilliseconds( |
| 553 kDefaultAudioBufferDurationInMs); | 552 kDefaultAudioBufferDurationInMs); |
| 554 } | 553 } |
| 555 } | 554 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 572 WebMClusterParser::FindTextTrack(int track_num) { | 571 WebMClusterParser::FindTextTrack(int track_num) { |
| 573 const TextTrackMap::iterator it = text_track_map_.find(track_num); | 572 const TextTrackMap::iterator it = text_track_map_.find(track_num); |
| 574 | 573 |
| 575 if (it == text_track_map_.end()) | 574 if (it == text_track_map_.end()) |
| 576 return NULL; | 575 return NULL; |
| 577 | 576 |
| 578 return &it->second; | 577 return &it->second; |
| 579 } | 578 } |
| 580 | 579 |
| 581 } // namespace media | 580 } // namespace media |
| OLD | NEW |