Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: media/filters/ffmpeg_demuxer.cc

Issue 2808833005: Seek for video track changes on FFmpegDemuxer.
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/blink/webmediaplayer_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 507
508 // Only allow negative timestamps past if we know they'll be fixed up by the 508 // Only allow negative timestamps past if we know they'll be fixed up by the
509 // code paths below; otherwise they should be treated as a parse error. 509 // code paths below; otherwise they should be treated as a parse error.
510 if (!fixup_negative_timestamps_ && buffer->timestamp() < base::TimeDelta()) { 510 if (!fixup_negative_timestamps_ && buffer->timestamp() < base::TimeDelta()) {
511 MEDIA_LOG(DEBUG, media_log_) 511 MEDIA_LOG(DEBUG, media_log_)
512 << "FFmpegDemuxer: unfixable negative timestamp"; 512 << "FFmpegDemuxer: unfixable negative timestamp";
513 demuxer_->NotifyDemuxerError(DEMUXER_ERROR_COULD_NOT_PARSE); 513 demuxer_->NotifyDemuxerError(DEMUXER_ERROR_COULD_NOT_PARSE);
514 return; 514 return;
515 } 515 }
516 516
517 if (is_audio && last_packet_timestamp_ != kNoTimestamp &&
518 buffer->timestamp() < last_packet_timestamp_) {
519 LOG(ERROR) << "Dropping: " << buffer->timestamp();
520 return;
521 }
522
517 // If enabled, and no codec delay is present, mark audio packets with negative 523 // If enabled, and no codec delay is present, mark audio packets with negative
518 // timestamps for post-decode discard. If codec delay is present, discard is 524 // timestamps for post-decode discard. If codec delay is present, discard is
519 // handled by the decoder using that value. 525 // handled by the decoder using that value.
520 if (fixup_negative_timestamps_ && is_audio && 526 if (fixup_negative_timestamps_ && is_audio &&
521 stream_timestamp < base::TimeDelta() && 527 stream_timestamp < base::TimeDelta() &&
522 buffer->duration() != kNoTimestamp && 528 buffer->duration() != kNoTimestamp &&
523 !audio_decoder_config().codec_delay()) { 529 !audio_decoder_config().codec_delay()) {
524 DCHECK_EQ(buffer->discard_padding().first, base::TimeDelta()); 530 DCHECK_EQ(buffer->discard_padding().first, base::TimeDelta());
525 531
526 if (stream_timestamp + buffer->duration() < base::TimeDelta()) { 532 if (stream_timestamp + buffer->duration() < base::TimeDelta()) {
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 // First disable all streams that need to be disabled and then enable the 1696 // First disable all streams that need to be disabled and then enable the
1691 // stream that needs to be enabled (if any). 1697 // stream that needs to be enabled (if any).
1692 for (const auto& stream : streams_) { 1698 for (const auto& stream : streams_) {
1693 if (stream && stream->type() == DemuxerStream::VIDEO && 1699 if (stream && stream->type() == DemuxerStream::VIDEO &&
1694 stream.get() != selected_stream) { 1700 stream.get() != selected_stream) {
1695 DVLOG(1) << __func__ << ": disabling stream " << stream.get(); 1701 DVLOG(1) << __func__ << ": disabling stream " << stream.get();
1696 stream->set_enabled(false, curr_time); 1702 stream->set_enabled(false, curr_time);
1697 } 1703 }
1698 } 1704 }
1699 if (selected_stream) { 1705 if (selected_stream) {
1700 DVLOG(1) << __func__ << ": enabling stream " << selected_stream; 1706 LOG(ERROR) << __func__ << ": enabling stream " << selected_stream;
1701 selected_stream->set_enabled(true, curr_time); 1707 selected_stream->set_enabled(true, curr_time);
1708 selected_stream->FlushBuffers();
1709
1710 base::TimeDelta seek_time =
1711 start_time_ < base::TimeDelta()
1712 ? curr_time + start_time_
1713 : curr_time < start_time_ ? start_time_ : curr_time;
1714 blocking_task_runner_->PostTask(
1715 FROM_HERE,
1716 base::Bind(base::IgnoreResult(&av_seek_frame), glue_->format_context(),
1717 selected_stream->av_stream()->index,
1718 ConvertToTimeBase(selected_stream->av_stream()->time_base,
1719 seek_time),
1720 // Always seek to a timestamp <= to the desired timestamp.
1721 AVSEEK_FLAG_BACKWARD));
1702 } 1722 }
1703 } 1723 }
1704 1724
1705 void FFmpegDemuxer::ReadFrameIfNeeded() { 1725 void FFmpegDemuxer::ReadFrameIfNeeded() {
1706 DCHECK(task_runner_->BelongsToCurrentThread()); 1726 DCHECK(task_runner_->BelongsToCurrentThread());
1707 1727
1708 // Make sure we have work to do before reading. 1728 // Make sure we have work to do before reading.
1709 if (stopped_ || !StreamsHaveAvailableCapacity() || pending_read_ || 1729 if (stopped_ || !StreamsHaveAvailableCapacity() || pending_read_ ||
1710 !pending_seek_cb_.is_null()) { 1730 !pending_seek_cb_.is_null()) {
1711 return; 1731 return;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1852 1872
1853 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { 1873 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) {
1854 DCHECK(task_runner_->BelongsToCurrentThread()); 1874 DCHECK(task_runner_->BelongsToCurrentThread());
1855 for (const auto& stream : streams_) { 1875 for (const auto& stream : streams_) {
1856 if (stream) 1876 if (stream)
1857 stream->SetLiveness(liveness); 1877 stream->SetLiveness(liveness);
1858 } 1878 }
1859 } 1879 }
1860 1880
1861 } // namespace media 1881 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/webmediaplayer_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698