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

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

Issue 683573002: ffmpeg reset bitstream converters on Seek (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 <string> 8 #include <string>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 end_of_stream_ = true; 378 end_of_stream_ = true;
379 SatisfyPendingRead(); 379 SatisfyPendingRead();
380 } 380 }
381 381
382 void FFmpegDemuxerStream::FlushBuffers() { 382 void FFmpegDemuxerStream::FlushBuffers() {
383 DCHECK(task_runner_->BelongsToCurrentThread()); 383 DCHECK(task_runner_->BelongsToCurrentThread());
384 DCHECK(read_cb_.is_null()) << "There should be no pending read"; 384 DCHECK(read_cb_.is_null()) << "There should be no pending read";
385 buffer_queue_.Clear(); 385 buffer_queue_.Clear();
386 end_of_stream_ = false; 386 end_of_stream_ = false;
387 last_packet_timestamp_ = kNoTimestamp(); 387 last_packet_timestamp_ = kNoTimestamp();
388 last_packet_duration_ = kNoTimestamp(); 388 last_packet_duration_ = kNoTimestamp();
xhwang 2014/10/30 03:36:20 ditto, call ResetBitstreamConverter() here?
389 } 389 }
390 390
391 void FFmpegDemuxerStream::Stop() { 391 void FFmpegDemuxerStream::Stop() {
392 DCHECK(task_runner_->BelongsToCurrentThread()); 392 DCHECK(task_runner_->BelongsToCurrentThread());
393 buffer_queue_.Clear(); 393 buffer_queue_.Clear();
394 if (!read_cb_.is_null()) { 394 if (!read_cb_.is_null()) {
395 base::ResetAndReturn(&read_cb_).Run( 395 base::ResetAndReturn(&read_cb_).Run(
396 DemuxerStream::kOk, DecoderBuffer::CreateEOSBuffer()); 396 DemuxerStream::kOk, DecoderBuffer::CreateEOSBuffer());
397 } 397 }
398 demuxer_ = NULL; 398 demuxer_ = NULL;
(...skipping 28 matching lines...) Expand all
427 DCHECK(task_runner_->BelongsToCurrentThread()); 427 DCHECK(task_runner_->BelongsToCurrentThread());
428 428
429 #if defined(USE_PROPRIETARY_CODECS) 429 #if defined(USE_PROPRIETARY_CODECS)
430 CHECK(bitstream_converter_.get()); 430 CHECK(bitstream_converter_.get());
431 bitstream_converter_enabled_ = true; 431 bitstream_converter_enabled_ = true;
432 #else 432 #else
433 NOTREACHED() << "Proprietary codecs not enabled."; 433 NOTREACHED() << "Proprietary codecs not enabled.";
434 #endif 434 #endif
435 } 435 }
436 436
437 void FFmpegDemuxerStream::ResetBitstreamConverter() {
438 // If a bitstream converter exists, reset it.
xhwang 2014/10/30 03:36:20 This comment doesn't belong here.
kjoswiak 2014/10/30 17:43:06 Done.
439 if (!bitstream_converter_enabled_)
xhwang 2014/10/30 03:36:20 bitstream_converter_enabled_ is inited in ctor, th
kjoswiak 2014/10/30 17:43:06 Done.
440 return;
441
442 #if defined(USE_PROPRIETARY_CODECS)
443 if (!bitstream_converter_)
444 return;
445
446 bitstream_converter_.reset(
447 new FFmpegH264ToAnnexBBitstreamConverter(stream_->codec));
kjoswiak 2014/10/29 20:24:27 Hmm, given https://code.google.com/p/chromium/issu
448 #endif // defined(USE_PROPRIETARY_CODECS)
449 }
450
437 bool FFmpegDemuxerStream::SupportsConfigChanges() { return false; } 451 bool FFmpegDemuxerStream::SupportsConfigChanges() { return false; }
438 452
439 AudioDecoderConfig FFmpegDemuxerStream::audio_decoder_config() { 453 AudioDecoderConfig FFmpegDemuxerStream::audio_decoder_config() {
440 DCHECK(task_runner_->BelongsToCurrentThread()); 454 DCHECK(task_runner_->BelongsToCurrentThread());
441 CHECK_EQ(type_, AUDIO); 455 CHECK_EQ(type_, AUDIO);
442 return audio_config_; 456 return audio_config_;
443 } 457 }
444 458
445 VideoDecoderConfig FFmpegDemuxerStream::video_decoder_config() { 459 VideoDecoderConfig FFmpegDemuxerStream::video_decoder_config() {
446 DCHECK(task_runner_->BelongsToCurrentThread()); 460 DCHECK(task_runner_->BelongsToCurrentThread());
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 600 }
587 601
588 void FFmpegDemuxer::Seek(base::TimeDelta time, const PipelineStatusCB& cb) { 602 void FFmpegDemuxer::Seek(base::TimeDelta time, const PipelineStatusCB& cb) {
589 DCHECK(task_runner_->BelongsToCurrentThread()); 603 DCHECK(task_runner_->BelongsToCurrentThread());
590 CHECK(!pending_seek_); 604 CHECK(!pending_seek_);
591 605
592 // TODO(scherkus): Inspect |pending_read_| and cancel IO via |blocking_url_|, 606 // TODO(scherkus): Inspect |pending_read_| and cancel IO via |blocking_url_|,
593 // otherwise we can end up waiting for a pre-seek read to complete even though 607 // otherwise we can end up waiting for a pre-seek read to complete even though
594 // we know we're going to drop it on the floor. 608 // we know we're going to drop it on the floor.
595 609
610 FFmpegDemuxerStream* video = GetFFmpegStream(DemuxerStream::VIDEO);
611 // H264 requires that we resend the header after flush.
612 // Reset its bitstream for converter to do so.
613 // This is related to chromium issue 140371 (http://crbug.com/140371).
614 if (video)
615 video->ResetBitstreamConverter();
xhwang 2014/10/30 03:36:20 Instead of doing this, can we handle Resetbitstrea
kjoswiak 2014/10/30 17:44:32 Done.
616
596 // FFmpeg requires seeks to be adjusted according to the lowest starting time. 617 // FFmpeg requires seeks to be adjusted according to the lowest starting time.
597 // Since EnqueuePacket() rebased negative timestamps by the start time, we 618 // Since EnqueuePacket() rebased negative timestamps by the start time, we
598 // must correct the shift here. 619 // must correct the shift here.
599 // 620 //
600 // Additionally, to workaround limitations in how we expose seekable ranges to 621 // Additionally, to workaround limitations in how we expose seekable ranges to
601 // Blink (http://crbug.com/137275), we also want to clamp seeks before the 622 // Blink (http://crbug.com/137275), we also want to clamp seeks before the
602 // start time to the start time. 623 // start time to the start time.
603 const base::TimeDelta seek_time = 624 const base::TimeDelta seek_time =
604 start_time_ < base::TimeDelta() ? time + start_time_ 625 start_time_ < base::TimeDelta() ? time + start_time_
605 : time < start_time_ ? start_time_ : time; 626 : time < start_time_ ? start_time_ : time;
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 } 1269 }
1249 for (size_t i = 0; i < buffered.size(); ++i) 1270 for (size_t i = 0; i < buffered.size(); ++i)
1250 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i)); 1271 host_->AddBufferedTimeRange(buffered.start(i), buffered.end(i));
1251 } 1272 }
1252 1273
1253 void FFmpegDemuxer::OnDataSourceError() { 1274 void FFmpegDemuxer::OnDataSourceError() {
1254 host_->OnDemuxerError(PIPELINE_ERROR_READ); 1275 host_->OnDemuxerError(PIPELINE_ERROR_READ);
1255 } 1276 }
1256 1277
1257 } // namespace media 1278 } // namespace media
OLDNEW
« media/filters/ffmpeg_demuxer.h ('K') | « media/filters/ffmpeg_demuxer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698