Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/filters/ffmpeg_demuxer.h" | 5 #include "media/filters/ffmpeg_demuxer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 video_config_(video_config.release()), | 269 video_config_(video_config.release()), |
| 270 type_(UNKNOWN), | 270 type_(UNKNOWN), |
| 271 liveness_(LIVENESS_UNKNOWN), | 271 liveness_(LIVENESS_UNKNOWN), |
| 272 end_of_stream_(false), | 272 end_of_stream_(false), |
| 273 last_packet_timestamp_(kNoTimestamp), | 273 last_packet_timestamp_(kNoTimestamp), |
| 274 last_packet_duration_(kNoTimestamp), | 274 last_packet_duration_(kNoTimestamp), |
| 275 video_rotation_(VIDEO_ROTATION_0), | 275 video_rotation_(VIDEO_ROTATION_0), |
| 276 is_enabled_(true), | 276 is_enabled_(true), |
| 277 waiting_for_keyframe_(false), | 277 waiting_for_keyframe_(false), |
| 278 aborted_(false), | 278 aborted_(false), |
| 279 fixup_negative_timestamps_(false) { | 279 fixup_negative_timestamps_(false), |
| 280 warned_about_missing_timestamps_(false) { | |
| 280 DCHECK(demuxer_); | 281 DCHECK(demuxer_); |
| 281 | 282 |
| 282 bool is_encrypted = false; | 283 bool is_encrypted = false; |
| 283 int rotation = 0; | 284 int rotation = 0; |
| 284 AVDictionaryEntry* rotation_entry = NULL; | 285 AVDictionaryEntry* rotation_entry = NULL; |
| 285 | 286 |
| 286 // Determine our media format. | 287 // Determine our media format. |
| 287 switch (stream->codecpar->codec_type) { | 288 switch (stream->codecpar->codec_type) { |
| 288 case AVMEDIA_TYPE_AUDIO: | 289 case AVMEDIA_TYPE_AUDIO: |
| 289 DCHECK(audio_config_.get() && !video_config_.get()); | 290 DCHECK(audio_config_.get() && !video_config_.get()); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 // nearest millisecond. See enable_negative_timestamp_fixups(). | 521 // nearest millisecond. See enable_negative_timestamp_fixups(). |
| 521 DCHECK_LE(-std::ceil(FramesToTimeDelta( | 522 DCHECK_LE(-std::ceil(FramesToTimeDelta( |
| 522 audio_decoder_config().codec_delay(), | 523 audio_decoder_config().codec_delay(), |
| 523 audio_decoder_config().samples_per_second()) | 524 audio_decoder_config().samples_per_second()) |
| 524 .InMillisecondsF()), | 525 .InMillisecondsF()), |
| 525 stream_timestamp.InMillisecondsF()); | 526 stream_timestamp.InMillisecondsF()); |
| 526 } | 527 } |
| 527 } | 528 } |
| 528 } else { | 529 } else { |
| 529 // If this happens on the first packet, decoders will throw an error. | 530 // If this happens on the first packet, decoders will throw an error. |
| 530 buffer->set_timestamp(kNoTimestamp); | 531 // Just try zero. crbug.com/665305 . |
| 532 if (!warned_about_missing_timestamps_) { | |
| 533 LOG(WARNING) << "No timestamp provided for initial buffer"; | |
| 534 warned_about_missing_timestamps_ = true; | |
| 535 } | |
| 536 buffer->set_timestamp(base::TimeDelta()); | |
| 531 } | 537 } |
| 532 | 538 |
| 533 if (last_packet_timestamp_ != kNoTimestamp) { | 539 if (last_packet_timestamp_ != kNoTimestamp) { |
| 534 // FFmpeg doesn't support chained ogg correctly. Instead of guaranteeing | 540 // FFmpeg doesn't support chained ogg correctly. Instead of guaranteeing |
| 535 // continuity across links in the chain it uses the timestamp information | 541 // continuity across links in the chain it uses the timestamp information |
| 536 // from each link directly. Doing so can lead to timestamps which appear to | 542 // from each link directly. Doing so can lead to timestamps which appear to |
| 537 // go backwards in time. | 543 // go backwards in time. |
| 538 // | 544 // |
| 539 // If the new link starts with a negative timestamp or a timestamp less than | 545 // If the new link starts with a negative timestamp or a timestamp less than |
| 540 // the original (positive) |start_time|, we will get a negative timestamp | 546 // the original (positive) |start_time|, we will get a negative timestamp |
| 541 // here. It's also possible FFmpeg returns kNoTimestamp here if it's not | 547 // here. It's also possible FFmpeg returns kNoTimestamp here if it's not |
| 542 // able to work out a timestamp using the previous link and the next. | 548 // able to work out a timestamp using the previous link and the next. |
| 543 // | 549 // |
| 544 // Fixing chained ogg is non-trivial, so for now just reuse the last good | 550 // Fixing chained ogg is non-trivial, so for now just reuse the last good |
| 545 // timestamp. The decoder will rewrite the timestamps to be sample accurate | 551 // timestamp. The decoder will rewrite the timestamps to be sample accurate |
| 546 // later. See http://crbug.com/396864. | 552 // later. See http://crbug.com/396864. |
| 547 if (fixup_negative_timestamps_ && | 553 // |
| 548 (buffer->timestamp() == kNoTimestamp || | 554 // Whether we're fixing up timestamps or not, if we have no timestamp, then |
| 555 // use the last timestamp instead. This can happen if bad media causes | |
| 556 // ffmpeg to fail to provide a timestamp. crbug.com/665305 | |
| 557 if (buffer->timestamp() == kNoTimestamp || | |
| 558 (fixup_negative_timestamps_ && | |
| 549 buffer->timestamp() < last_packet_timestamp_)) { | 559 buffer->timestamp() < last_packet_timestamp_)) { |
| 560 if (!fixup_negative_timestamps_ && !warned_about_missing_timestamps_) { | |
|
liberato (no reviews please)
2016/12/12 22:24:48
"!fixup..." to prevent a warning when we wouldn't
| |
| 561 LOG(WARNING) << "No timestamp provided for buffer"; | |
| 562 warned_about_missing_timestamps_ = true; | |
| 563 } | |
| 550 buffer->set_timestamp(last_packet_timestamp_ + | 564 buffer->set_timestamp(last_packet_timestamp_ + |
| 551 (last_packet_duration_ != kNoTimestamp | 565 (last_packet_duration_ != kNoTimestamp |
| 552 ? last_packet_duration_ | 566 ? last_packet_duration_ |
| 553 : base::TimeDelta::FromMicroseconds(1))); | 567 : base::TimeDelta::FromMicroseconds(1))); |
| 554 } | 568 } |
| 555 | 569 |
| 556 // The demuxer should always output positive timestamps. | 570 // The demuxer should always output non-negative timestamps. If it output |
| 571 // no timestamp, then we should have already fixed that up. | |
| 572 DCHECK(buffer->timestamp() != kNoTimestamp); | |
| 557 DCHECK(buffer->timestamp() >= base::TimeDelta()); | 573 DCHECK(buffer->timestamp() >= base::TimeDelta()); |
| 558 DCHECK(buffer->timestamp() != kNoTimestamp); | |
| 559 | 574 |
| 560 if (last_packet_timestamp_ < buffer->timestamp()) { | 575 if (last_packet_timestamp_ < buffer->timestamp()) { |
| 561 buffered_ranges_.Add(last_packet_timestamp_, buffer->timestamp()); | 576 buffered_ranges_.Add(last_packet_timestamp_, buffer->timestamp()); |
| 562 demuxer_->NotifyBufferingChanged(); | 577 demuxer_->NotifyBufferingChanged(); |
| 563 } | 578 } |
| 564 } | 579 } |
| 565 | 580 |
| 566 if (packet.get()->flags & AV_PKT_FLAG_KEY) | 581 if (packet.get()->flags & AV_PKT_FLAG_KEY) |
| 567 buffer->set_is_key_frame(true); | 582 buffer->set_is_key_frame(true); |
| 568 | 583 |
| (...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1804 | 1819 |
| 1805 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { | 1820 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { |
| 1806 DCHECK(task_runner_->BelongsToCurrentThread()); | 1821 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 1807 for (const auto& stream : streams_) { | 1822 for (const auto& stream : streams_) { |
| 1808 if (stream) | 1823 if (stream) |
| 1809 stream->SetLiveness(liveness); | 1824 stream->SetLiveness(liveness); |
| 1810 } | 1825 } |
| 1811 } | 1826 } |
| 1812 | 1827 |
| 1813 } // namespace media | 1828 } // namespace media |
| OLD | NEW |