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

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

Issue 2549263002: FFmpegDemuxer should fall back to disabled streams for seeking (Closed)
Patch Set: Revise/refactor stream selection logic Created 4 years 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
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 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 } 1516 }
1517 } 1517 }
1518 params.SetBoolean("found_audio_stream", (audio_track_count > 0)); 1518 params.SetBoolean("found_audio_stream", (audio_track_count > 0));
1519 params.SetBoolean("found_video_stream", (video_track_count > 0)); 1519 params.SetBoolean("found_video_stream", (video_track_count > 0));
1520 SetTimeProperty(metadata_event.get(), "max_duration", max_duration); 1520 SetTimeProperty(metadata_event.get(), "max_duration", max_duration);
1521 SetTimeProperty(metadata_event.get(), "start_time", start_time_); 1521 SetTimeProperty(metadata_event.get(), "start_time", start_time_);
1522 metadata_event->params.SetInteger("bitrate", bitrate_); 1522 metadata_event->params.SetInteger("bitrate", bitrate_);
1523 media_log_->AddEvent(std::move(metadata_event)); 1523 media_log_->AddEvent(std::move(metadata_event));
1524 } 1524 }
1525 1525
1526 FFmpegDemuxerStream* FFmpegDemuxer::FindStreamWithLowestStartPts(bool enabled) {
1527 FFmpegDemuxerStream* lowest_start_time_stream = nullptr;
1528 for (const auto& stream : streams_) {
1529 if (!stream || stream->start_time() == kNoTimestamp)
1530 continue;
1531 if (stream->enabled() != enabled)
1532 continue;
1533 if (!lowest_start_time_stream ||
1534 stream->start_time() < lowest_start_time_stream->start_time()) {
1535 lowest_start_time_stream = stream.get();
1536 }
1537 }
1538 return lowest_start_time_stream;
1539 }
1540
1526 FFmpegDemuxerStream* FFmpegDemuxer::FindPreferredStreamForSeeking( 1541 FFmpegDemuxerStream* FFmpegDemuxer::FindPreferredStreamForSeeking(
1527 base::TimeDelta seek_time) { 1542 base::TimeDelta seek_time) {
1528 // If we have a selected/enabled video stream and its start time is lower 1543 // If we have a selected/enabled video stream and its start time is lower
1529 // than the |seek_time| or unknown, then always prefer it for seeking. 1544 // than the |seek_time| or unknown, then always prefer it for seeking.
1530 FFmpegDemuxerStream* video_stream = nullptr; 1545 FFmpegDemuxerStream* video_stream = nullptr;
1531 for (const auto& stream : streams_) { 1546 for (const auto& stream : streams_) {
1532 if (stream && stream->type() == DemuxerStream::VIDEO && stream->enabled()) { 1547 if (stream && stream->type() == DemuxerStream::VIDEO && stream->enabled()) {
1533 video_stream = stream.get(); 1548 video_stream = stream.get();
1534 if (video_stream->start_time() == kNoTimestamp || 1549 if (video_stream->start_time() == kNoTimestamp ||
1535 video_stream->start_time() <= seek_time) { 1550 video_stream->start_time() <= seek_time) {
1536 return video_stream; 1551 return video_stream;
1537 } 1552 }
1538 break; 1553 break;
1539 } 1554 }
1540 } 1555 }
1541 1556
1542 // If video stream is not present or |seek_time| is lower than the video start 1557 // If video stream is not present or |seek_time| is lower than the video start
1543 // time, then try to find an enabled stream with the lowest start time. 1558 // time, then try to find an enabled stream with the lowest start time.
1544 FFmpegDemuxerStream* lowest_start_time_stream = nullptr; 1559 FFmpegDemuxerStream* lowest_start_time_enabled_stream =
1545 for (const auto& stream : streams_) { 1560 FindStreamWithLowestStartPts(true);
1546 if (!stream || !stream->enabled() || stream->start_time() == kNoTimestamp) 1561 if (lowest_start_time_enabled_stream &&
1547 continue; 1562 lowest_start_time_enabled_stream->start_time() <= seek_time) {
1548 if (!lowest_start_time_stream || 1563 return lowest_start_time_enabled_stream;
1549 stream->start_time() < lowest_start_time_stream->start_time()) {
1550 lowest_start_time_stream = stream.get();
1551 }
1552 }
1553 // If we found a stream with start time lower than |seek_time|, then use it.
1554 if (lowest_start_time_stream &&
1555 lowest_start_time_stream->start_time() <= seek_time) {
1556 return lowest_start_time_stream;
1557 } 1564 }
1558 1565
1559 // If we couldn't find any streams with the start time lower than |seek_time| 1566 // Fall back to any enabled stream, even if it's start time is unknown.
servolk 2016/12/06 18:14:17 TBH I'm not 100% sure about this. Should we prefer
DaleCurtis 2016/12/06 20:18:03 We shouldn't have any streams with a start time of
servolk 2016/12/06 22:05:29 Are you sure about this? Looking at comment https:
DaleCurtis 2016/12/06 22:17:09 We never correct the start time if this is true, s
servolk 2016/12/06 23:00:41 Ok, so in other words this means that it's the rig
DaleCurtis 2016/12/06 23:29:05 I think we can set the start_time to zero when it'
servolk 2016/12/06 23:43:34 You are right, looks like FFmpegDemuxerStream::sta
1560 // then use either video (if one exists) or any audio stream. 1567 for (const auto& stream : streams_) {
1561 return video_stream ? video_stream : static_cast<FFmpegDemuxerStream*>( 1568 if (stream && stream->enabled())
1562 GetStream(DemuxerStream::AUDIO)); 1569 return stream.get();
1570 }
1571
1572 // If there's no enabled streams to consider from, try a disabled stream with
1573 // the lowest known start time.
1574 FFmpegDemuxerStream* lowest_start_time_disabled_stream =
1575 FindStreamWithLowestStartPts(false);
1576 if (lowest_start_time_disabled_stream &&
1577 lowest_start_time_disabled_stream->start_time() <= seek_time) {
1578 return lowest_start_time_disabled_stream;
1579 }
1580
1581 // Otherwise fall back to any other stream.
1582 for (const auto& stream : streams_) {
1583 if (stream)
1584 return stream.get();
1585 }
1586
1587 NOTREACHED();
1588 return nullptr;
1563 } 1589 }
1564 1590
1565 void FFmpegDemuxer::OnSeekFrameDone(int result) { 1591 void FFmpegDemuxer::OnSeekFrameDone(int result) {
1566 DCHECK(task_runner_->BelongsToCurrentThread()); 1592 DCHECK(task_runner_->BelongsToCurrentThread());
1567 CHECK(!pending_seek_cb_.is_null()); 1593 CHECK(!pending_seek_cb_.is_null());
1568 1594
1569 if (!blocking_thread_.IsRunning()) { 1595 if (!blocking_thread_.IsRunning()) {
1570 MEDIA_LOG(ERROR, media_log_) << GetDisplayName() << ": bad state"; 1596 MEDIA_LOG(ERROR, media_log_) << GetDisplayName() << ": bad state";
1571 base::ResetAndReturn(&pending_seek_cb_).Run(PIPELINE_ERROR_ABORT); 1597 base::ResetAndReturn(&pending_seek_cb_).Run(PIPELINE_ERROR_ABORT);
1572 return; 1598 return;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1783 1809
1784 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { 1810 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) {
1785 DCHECK(task_runner_->BelongsToCurrentThread()); 1811 DCHECK(task_runner_->BelongsToCurrentThread());
1786 for (const auto& stream : streams_) { 1812 for (const auto& stream : streams_) {
1787 if (stream) 1813 if (stream)
1788 stream->SetLiveness(liveness); 1814 stream->SetLiveness(liveness);
1789 } 1815 }
1790 } 1816 }
1791 1817
1792 } // namespace media 1818 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698