| 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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 } | 491 } |
| 492 | 492 |
| 493 // Don't rebase timestamps for positive start times, the HTML Media Spec | 493 // Don't rebase timestamps for positive start times, the HTML Media Spec |
| 494 // details this in section "4.8.10.6 Offsets into the media resource." We | 494 // details this in section "4.8.10.6 Offsets into the media resource." We |
| 495 // will still need to rebase timestamps before seeking with FFmpeg though. | 495 // will still need to rebase timestamps before seeking with FFmpeg though. |
| 496 if (start_time > base::TimeDelta()) | 496 if (start_time > base::TimeDelta()) |
| 497 start_time = base::TimeDelta(); | 497 start_time = base::TimeDelta(); |
| 498 | 498 |
| 499 buffer->set_timestamp(stream_timestamp - start_time); | 499 buffer->set_timestamp(stream_timestamp - start_time); |
| 500 | 500 |
| 501 // Only allow negative timestamps past if we know they'll be fixed up by the |
| 502 // code paths below; otherwise they should be treated as a parse error. |
| 503 if (!fixup_negative_timestamps_ && buffer->timestamp() < base::TimeDelta()) { |
| 504 demuxer_->NotifyDemuxerError(DEMUXER_ERROR_COULD_NOT_PARSE); |
| 505 return; |
| 506 } |
| 507 |
| 501 // If enabled, and no codec delay is present, mark audio packets with | 508 // If enabled, and no codec delay is present, mark audio packets with |
| 502 // negative timestamps for post-decode discard. | 509 // negative timestamps for post-decode discard. |
| 503 if (fixup_negative_timestamps_ && is_audio && | 510 if (fixup_negative_timestamps_ && is_audio && |
| 504 stream_timestamp < base::TimeDelta() && | 511 stream_timestamp < base::TimeDelta() && |
| 505 buffer->duration() != kNoTimestamp) { | 512 buffer->duration() != kNoTimestamp) { |
| 506 if (!audio_decoder_config().codec_delay()) { | 513 if (!audio_decoder_config().codec_delay()) { |
| 507 DCHECK_EQ(buffer->discard_padding().first, base::TimeDelta()); | 514 DCHECK_EQ(buffer->discard_padding().first, base::TimeDelta()); |
| 508 | 515 |
| 509 if (stream_timestamp + buffer->duration() < base::TimeDelta()) { | 516 if (stream_timestamp + buffer->duration() < base::TimeDelta()) { |
| 510 DCHECK_EQ(buffer->discard_padding().second, base::TimeDelta()); | 517 DCHECK_EQ(buffer->discard_padding().second, base::TimeDelta()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 // later. See http://crbug.com/396864. | 552 // later. See http://crbug.com/396864. |
| 546 if (fixup_negative_timestamps_ && | 553 if (fixup_negative_timestamps_ && |
| 547 buffer->timestamp() < last_packet_timestamp_) { | 554 buffer->timestamp() < last_packet_timestamp_) { |
| 548 buffer->set_timestamp(last_packet_timestamp_ + | 555 buffer->set_timestamp(last_packet_timestamp_ + |
| 549 (last_packet_duration_ != kNoTimestamp | 556 (last_packet_duration_ != kNoTimestamp |
| 550 ? last_packet_duration_ | 557 ? last_packet_duration_ |
| 551 : base::TimeDelta::FromMicroseconds(1))); | 558 : base::TimeDelta::FromMicroseconds(1))); |
| 552 } | 559 } |
| 553 | 560 |
| 554 // The demuxer should always output positive timestamps. | 561 // The demuxer should always output positive timestamps. |
| 555 DCHECK(buffer->timestamp() >= base::TimeDelta()); | 562 DCHECK_GE(buffer->timestamp(), base::TimeDelta()); |
| 556 | 563 |
| 557 if (last_packet_timestamp_ < buffer->timestamp()) { | 564 if (last_packet_timestamp_ < buffer->timestamp()) { |
| 558 buffered_ranges_.Add(last_packet_timestamp_, buffer->timestamp()); | 565 buffered_ranges_.Add(last_packet_timestamp_, buffer->timestamp()); |
| 559 demuxer_->NotifyBufferingChanged(); | 566 demuxer_->NotifyBufferingChanged(); |
| 560 } | 567 } |
| 561 } | 568 } |
| 562 | 569 |
| 563 if (packet.get()->flags & AV_PKT_FLAG_KEY) | 570 if (packet.get()->flags & AV_PKT_FLAG_KEY) |
| 564 buffer->set_is_key_frame(true); | 571 buffer->set_is_key_frame(true); |
| 565 | 572 |
| (...skipping 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1830 | 1837 |
| 1831 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { | 1838 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { |
| 1832 DCHECK(task_runner_->BelongsToCurrentThread()); | 1839 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 1833 for (const auto& stream : streams_) { | 1840 for (const auto& stream : streams_) { |
| 1834 if (stream) | 1841 if (stream) |
| 1835 stream->SetLiveness(liveness); | 1842 stream->SetLiveness(liveness); |
| 1836 } | 1843 } |
| 1837 } | 1844 } |
| 1838 | 1845 |
| 1839 } // namespace media | 1846 } // namespace media |
| OLD | NEW |