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

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

Issue 2737653002: Buffer 2 seconds of data in the ffmpeg demuxer. (Closed)
Patch Set: UnmarkEndOfStream -> UnmarkEndOfStreamAndClearError Created 3 years, 9 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 | « no previous file | media/filters/ffmpeg_demuxer_unittest.cc » ('j') | 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 244 }
245 245
246 MEDIA_LOG(INFO, media_log) << "FFmpegDemuxer: created video stream, config " 246 MEDIA_LOG(INFO, media_log) << "FFmpegDemuxer: created video stream, config "
247 << video_config->AsHumanReadableString(); 247 << video_config->AsHumanReadableString();
248 } 248 }
249 249
250 return base::WrapUnique(new FFmpegDemuxerStream( 250 return base::WrapUnique(new FFmpegDemuxerStream(
251 demuxer, stream, std::move(audio_config), std::move(video_config))); 251 demuxer, stream, std::move(audio_config), std::move(video_config)));
252 } 252 }
253 253
254 static void UnmarkEndOfStream(AVFormatContext* format_context) { 254 static void UnmarkEndOfStreamAndClearError(AVFormatContext* format_context) {
255 format_context->pb->eof_reached = 0; 255 format_context->pb->eof_reached = 0;
256 format_context->pb->error = 0;
256 } 257 }
257 258
258 // 259 //
259 // FFmpegDemuxerStream 260 // FFmpegDemuxerStream
260 // 261 //
261 FFmpegDemuxerStream::FFmpegDemuxerStream( 262 FFmpegDemuxerStream::FFmpegDemuxerStream(
262 FFmpegDemuxer* demuxer, 263 FFmpegDemuxer* demuxer,
263 AVStream* stream, 264 AVStream* stream,
264 std::unique_ptr<AudioDecoderConfig> audio_config, 265 std::unique_ptr<AudioDecoderConfig> audio_config,
265 std::unique_ptr<VideoDecoderConfig> video_config) 266 std::unique_ptr<VideoDecoderConfig> video_config)
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 } 774 }
774 } 775 }
775 776
776 // Have capacity? Ask for more! 777 // Have capacity? Ask for more!
777 if (HasAvailableCapacity() && !end_of_stream_) { 778 if (HasAvailableCapacity() && !end_of_stream_) {
778 demuxer_->NotifyCapacityAvailable(); 779 demuxer_->NotifyCapacityAvailable();
779 } 780 }
780 } 781 }
781 782
782 bool FFmpegDemuxerStream::HasAvailableCapacity() { 783 bool FFmpegDemuxerStream::HasAvailableCapacity() {
783 // TODO(scherkus): Remove this return and reenable time-based capacity 784 // Try to have two second's worth of encoded data per stream.
784 // after our data sources support canceling/concurrent reads, see 785 const base::TimeDelta kCapacity = base::TimeDelta::FromSeconds(2);
785 // http://crbug.com/165762 for details.
786 #if 1
787 return !read_cb_.is_null();
788 #else
789 // Try to have one second's worth of encoded data per stream.
790 const base::TimeDelta kCapacity = base::TimeDelta::FromSeconds(1);
791 return buffer_queue_.IsEmpty() || buffer_queue_.Duration() < kCapacity; 786 return buffer_queue_.IsEmpty() || buffer_queue_.Duration() < kCapacity;
792 #endif
793 } 787 }
794 788
795 size_t FFmpegDemuxerStream::MemoryUsage() const { 789 size_t FFmpegDemuxerStream::MemoryUsage() const {
796 return buffer_queue_.data_size(); 790 return buffer_queue_.data_size();
797 } 791 }
798 792
799 TextKind FFmpegDemuxerStream::GetTextKind() const { 793 TextKind FFmpegDemuxerStream::GetTextKind() const {
800 DCHECK_EQ(type_, DemuxerStream::TEXT); 794 DCHECK_EQ(type_, DemuxerStream::TEXT);
801 795
802 if (stream_->disposition & AV_DISPOSITION_CAPTIONS) 796 if (stream_->disposition & AV_DISPOSITION_CAPTIONS)
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 stream->Abort(); 922 stream->Abort();
929 } 923 }
930 924
931 // It's important to invalidate read/seek completion callbacks to avoid any 925 // It's important to invalidate read/seek completion callbacks to avoid any
932 // errors that occur because of the data source abort. 926 // errors that occur because of the data source abort.
933 weak_factory_.InvalidateWeakPtrs(); 927 weak_factory_.InvalidateWeakPtrs();
934 data_source_->Abort(); 928 data_source_->Abort();
935 929
936 // Aborting the read may cause EOF to be marked, undo this. 930 // Aborting the read may cause EOF to be marked, undo this.
937 blocking_task_runner_->PostTask( 931 blocking_task_runner_->PostTask(
938 FROM_HERE, base::Bind(&UnmarkEndOfStream, glue_->format_context())); 932 FROM_HERE,
933 base::Bind(&UnmarkEndOfStreamAndClearError, glue_->format_context()));
939 pending_read_ = false; 934 pending_read_ = false;
940 935
941 // TODO(dalecurtis): We probably should report PIPELINE_ERROR_ABORT here 936 // TODO(dalecurtis): We probably should report PIPELINE_ERROR_ABORT here
942 // instead to avoid any preroll work that may be started upon return, but 937 // instead to avoid any preroll work that may be started upon return, but
943 // currently the PipelineImpl does not know how to handle this. 938 // currently the PipelineImpl does not know how to handle this.
944 if (!pending_seek_cb_.is_null()) 939 if (!pending_seek_cb_.is_null())
945 base::ResetAndReturn(&pending_seek_cb_).Run(PIPELINE_OK); 940 base::ResetAndReturn(&pending_seek_cb_).Run(PIPELINE_OK);
946 } 941 }
947 942
948 void FFmpegDemuxer::Stop() { 943 void FFmpegDemuxer::Stop() {
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
1839 1834
1840 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { 1835 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) {
1841 DCHECK(task_runner_->BelongsToCurrentThread()); 1836 DCHECK(task_runner_->BelongsToCurrentThread());
1842 for (const auto& stream : streams_) { 1837 for (const auto& stream : streams_) {
1843 if (stream) 1838 if (stream)
1844 stream->SetLiveness(liveness); 1839 stream->SetLiveness(liveness);
1845 } 1840 }
1846 } 1841 }
1847 1842
1848 } // namespace media 1843 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/filters/ffmpeg_demuxer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698