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/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 buffer->set_duration(track->default_duration()); | |
|
wolenetz
2014/04/09 21:53:47
nit: DCHECK_NE(DemuxerStream::TEXT, buffer_type) t
Sergey Ulanov
2014/04/10 02:00:49
Done.
| |
| 410 } | 412 } |
| 411 | 413 |
| 412 if (discard_padding != 0) { | 414 if (discard_padding != 0) { |
| 413 buffer->set_discard_padding(base::TimeDelta::FromMicroseconds( | 415 buffer->set_discard_padding(base::TimeDelta::FromMicroseconds( |
| 414 discard_padding / 1000)); | 416 discard_padding / 1000)); |
| 415 } | 417 } |
| 416 | 418 |
| 417 return track->AddBuffer(buffer); | 419 return track->AddBuffer(buffer); |
| 418 } | 420 } |
| 419 | 421 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 | 460 |
| 459 if (buffer->duration() == kNoTimestamp()) { | 461 if (buffer->duration() == kNoTimestamp()) { |
| 460 last_added_buffer_missing_duration_ = buffer; | 462 last_added_buffer_missing_duration_ = buffer; |
| 461 DVLOG(2) << "AddBuffer() : holding back buffer that is missing duration"; | 463 DVLOG(2) << "AddBuffer() : holding back buffer that is missing duration"; |
| 462 return true; | 464 return true; |
| 463 } | 465 } |
| 464 | 466 |
| 465 return QueueBuffer(buffer); | 467 return QueueBuffer(buffer); |
| 466 } | 468 } |
| 467 | 469 |
| 468 void WebMClusterParser::Track::ApplyDurationDefaultOrEstimateIfNeeded() { | 470 void WebMClusterParser::Track::ApplyDurationEstimateIfNeeded() { |
| 469 if (!last_added_buffer_missing_duration_) | 471 if (!last_added_buffer_missing_duration_) |
| 470 return; | 472 return; |
| 471 | 473 |
| 472 last_added_buffer_missing_duration_->set_duration( | 474 last_added_buffer_missing_duration_->set_duration(GetDurationEstimate()); |
| 473 GetDurationDefaultOrEstimate()); | |
| 474 | 475 |
| 475 DVLOG(2) << "ApplyDurationDefaultOrEstimateIfNeeded() : new dur : " | 476 DVLOG(2) << "ApplyDurationEstimateIfNeeded() : new dur : " |
| 476 << " ts " | 477 << " ts " |
| 477 << last_added_buffer_missing_duration_->timestamp().InSecondsF() | 478 << last_added_buffer_missing_duration_->timestamp().InSecondsF() |
| 478 << " dur " | 479 << " dur " |
| 479 << last_added_buffer_missing_duration_->duration().InSecondsF() | 480 << last_added_buffer_missing_duration_->duration().InSecondsF() |
| 480 << " kf " << last_added_buffer_missing_duration_->IsKeyframe() | 481 << " kf " << last_added_buffer_missing_duration_->IsKeyframe() |
| 481 << " size " << last_added_buffer_missing_duration_->data_size(); | 482 << " size " << last_added_buffer_missing_duration_->data_size(); |
| 482 | 483 |
| 483 // Don't use the applied duration as a future estimation (don't use | 484 // Don't use the applied duration as a future estimation (don't use |
| 484 // QueueBuffer() here.) | 485 // QueueBuffer() here.) |
| 485 buffers_.push_back(last_added_buffer_missing_duration_); | 486 buffers_.push_back(last_added_buffer_missing_duration_); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 << duration.InSecondsF(); | 530 << duration.InSecondsF(); |
| 530 return false; | 531 return false; |
| 531 } | 532 } |
| 532 | 533 |
| 533 estimated_next_frame_duration_ = std::max(duration, | 534 estimated_next_frame_duration_ = std::max(duration, |
| 534 estimated_next_frame_duration_); | 535 estimated_next_frame_duration_); |
| 535 buffers_.push_back(buffer); | 536 buffers_.push_back(buffer); |
| 536 return true; | 537 return true; |
| 537 } | 538 } |
| 538 | 539 |
| 539 base::TimeDelta WebMClusterParser::Track::GetDurationDefaultOrEstimate() { | 540 base::TimeDelta WebMClusterParser::Track::GetDurationEstimate() { |
| 540 base::TimeDelta duration = default_duration_; | 541 base::TimeDelta duration = estimated_next_frame_duration_; |
| 541 if (duration != kNoTimestamp()) { | 542 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"; | 543 DVLOG(3) << __FUNCTION__ << " : using estimated duration"; |
| 545 duration = estimated_next_frame_duration_; | |
| 546 } else { | 544 } else { |
| 547 DVLOG(3) << __FUNCTION__ << " : using hardcoded default duration"; | 545 DVLOG(3) << __FUNCTION__ << " : using hardcoded default duration"; |
| 548 if (is_video_) { | 546 if (is_video_) { |
| 549 duration = base::TimeDelta::FromMilliseconds( | 547 duration = base::TimeDelta::FromMilliseconds( |
| 550 kDefaultVideoBufferDurationInMs); | 548 kDefaultVideoBufferDurationInMs); |
| 551 } else { | 549 } else { |
| 552 duration = base::TimeDelta::FromMilliseconds( | 550 duration = base::TimeDelta::FromMilliseconds( |
| 553 kDefaultAudioBufferDurationInMs); | 551 kDefaultAudioBufferDurationInMs); |
| 554 } | 552 } |
| 555 } | 553 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 572 WebMClusterParser::FindTextTrack(int track_num) { | 570 WebMClusterParser::FindTextTrack(int track_num) { |
| 573 const TextTrackMap::iterator it = text_track_map_.find(track_num); | 571 const TextTrackMap::iterator it = text_track_map_.find(track_num); |
| 574 | 572 |
| 575 if (it == text_track_map_.end()) | 573 if (it == text_track_map_.end()) |
| 576 return NULL; | 574 return NULL; |
| 577 | 575 |
| 578 return &it->second; | 576 return &it->second; |
| 579 } | 577 } |
| 580 | 578 |
| 581 } // namespace media | 579 } // namespace media |
| OLD | NEW |