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

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

Issue 8936014: Removing DataSource from Filter hierarchy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved preload into a separate file. Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "media/base/data_buffer.h" 13 #include "media/base/data_buffer.h"
14 #include "media/base/filter_host.h"
15 #include "media/base/limits.h" 14 #include "media/base/limits.h"
16 #include "media/base/media_switches.h" 15 #include "media/base/media_switches.h"
17 #include "media/ffmpeg/ffmpeg_common.h" 16 #include "media/ffmpeg/ffmpeg_common.h"
18 #include "media/filters/bitstream_converter.h" 17 #include "media/filters/bitstream_converter.h"
19 #include "media/filters/ffmpeg_demuxer.h" 18 #include "media/filters/ffmpeg_demuxer.h"
20 #include "media/filters/ffmpeg_glue.h" 19 #include "media/filters/ffmpeg_glue.h"
21 #include "media/filters/ffmpeg_h264_bitstream_converter.h" 20 #include "media/filters/ffmpeg_h264_bitstream_converter.h"
22 21
23 namespace media { 22 namespace media {
24 23
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 311
313 void FFmpegDemuxer::Stop(const base::Closure& callback) { 312 void FFmpegDemuxer::Stop(const base::Closure& callback) {
314 // Post a task to notify the streams to stop as well. 313 // Post a task to notify the streams to stop as well.
315 message_loop_->PostTask(FROM_HERE, 314 message_loop_->PostTask(FROM_HERE,
316 base::Bind(&FFmpegDemuxer::StopTask, this, callback)); 315 base::Bind(&FFmpegDemuxer::StopTask, this, callback));
317 316
318 // Then wakes up the thread from reading. 317 // Then wakes up the thread from reading.
319 SignalReadCompleted(DataSource::kReadError); 318 SignalReadCompleted(DataSource::kReadError);
320 } 319 }
321 320
322 void FFmpegDemuxer::Seek(base::TimeDelta time, const FilterStatusCB& cb) { 321 void FFmpegDemuxer::Seek(base::TimeDelta time, const PipelineStatusCB& cb) {
323 message_loop_->PostTask(FROM_HERE, 322 message_loop_->PostTask(FROM_HERE,
324 base::Bind(&FFmpegDemuxer::SeekTask, this, time, cb)); 323 base::Bind(&FFmpegDemuxer::SeekTask, this, time, cb));
325 } 324 }
326 325
327 void FFmpegDemuxer::SetPlaybackRate(float playback_rate) { 326 void FFmpegDemuxer::SetPlaybackRate(float playback_rate) {
328 DCHECK(data_source_.get()); 327 DCHECK(data_source_.get());
329 data_source_->SetPlaybackRate(playback_rate); 328 data_source_->SetPlaybackRate(playback_rate);
330 } 329 }
331 330
332 void FFmpegDemuxer::SetPreload(Preload preload) { 331 void FFmpegDemuxer::SetPreload(Preload preload) {
333 DCHECK(data_source_.get()); 332 DCHECK(data_source_.get());
334 data_source_->SetPreload(preload); 333 data_source_->SetPreload(preload);
335 } 334 }
336 335
337 void FFmpegDemuxer::OnAudioRendererDisabled() { 336 void FFmpegDemuxer::OnAudioRendererDisabled() {
338 message_loop_->PostTask(FROM_HERE, base::Bind( 337 message_loop_->PostTask(FROM_HERE, base::Bind(
339 &FFmpegDemuxer::DisableAudioStreamTask, this)); 338 &FFmpegDemuxer::DisableAudioStreamTask, this));
340 } 339 }
341 340
342 void FFmpegDemuxer::set_host(FilterHost* filter_host) { 341 void FFmpegDemuxer::set_host(DemuxerHost* demuxer_host) {
343 Demuxer::set_host(filter_host); 342 Demuxer::set_host(demuxer_host);
344 if (data_source_) 343 if (data_source_)
345 data_source_->set_host(filter_host); 344 data_source_->set_host(demuxer_host);
346 if (max_duration_.InMicroseconds() >= 0) 345 if (max_duration_.InMicroseconds() >= 0)
347 host()->SetDuration(max_duration_); 346 host()->SetDuration(max_duration_);
348 if (read_position_ > 0) 347 if (read_position_ > 0)
349 host()->SetCurrentReadPosition(read_position_); 348 host()->SetCurrentReadPosition(read_position_);
350 if (deferred_status_ != PIPELINE_OK) 349 if (deferred_status_ != PIPELINE_OK)
351 host()->SetError(deferred_status_); 350 host()->OnDemuxerError(deferred_status_);
352 } 351 }
353 352
354 void FFmpegDemuxer::Initialize(DataSource* data_source, 353 void FFmpegDemuxer::Initialize(DataSource* data_source,
355 const PipelineStatusCB& callback) { 354 const PipelineStatusCB& callback) {
356 message_loop_->PostTask( 355 message_loop_->PostTask(
357 FROM_HERE, 356 FROM_HERE,
358 base::Bind(&FFmpegDemuxer::InitializeTask, this, 357 base::Bind(&FFmpegDemuxer::InitializeTask, this,
359 make_scoped_refptr(data_source), 358 make_scoped_refptr(data_source),
360 callback)); 359 callback));
361 } 360 }
(...skipping 26 matching lines...) Expand all
388 // Asynchronous read from data source. 387 // Asynchronous read from data source.
389 data_source_->Read(read_position_, size, data, 388 data_source_->Read(read_position_, size, data,
390 base::Bind(&FFmpegDemuxer::OnReadCompleted, this)); 389 base::Bind(&FFmpegDemuxer::OnReadCompleted, this));
391 390
392 // TODO(hclam): The method is called on the demuxer thread and this method 391 // TODO(hclam): The method is called on the demuxer thread and this method
393 // call will block the thread. We need to implemented an additional thread to 392 // call will block the thread. We need to implemented an additional thread to
394 // let FFmpeg demuxer methods to run on. 393 // let FFmpeg demuxer methods to run on.
395 size_t last_read_bytes = WaitForRead(); 394 size_t last_read_bytes = WaitForRead();
396 if (last_read_bytes == DataSource::kReadError) { 395 if (last_read_bytes == DataSource::kReadError) {
397 if (host()) 396 if (host())
398 host()->SetError(PIPELINE_ERROR_READ); 397 host()->OnDemuxerError(PIPELINE_ERROR_READ);
399 else 398 else
400 deferred_status_ = PIPELINE_ERROR_READ; 399 deferred_status_ = PIPELINE_ERROR_READ;
401 400
402 // Returns with a negative number to signal an error to FFmpeg. 401 // Returns with a negative number to signal an error to FFmpeg.
403 read_has_failed_ = true; 402 read_has_failed_ = true;
404 return AVERROR(EIO); 403 return AVERROR(EIO);
405 } 404 }
406 read_position_ += last_read_bytes; 405 read_position_ += last_read_bytes;
407 406
408 if (host()) 407 if (host())
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 } 573 }
575 574
576 bool FFmpegDemuxer::IsLocalSource() { 575 bool FFmpegDemuxer::IsLocalSource() {
577 return local_source_; 576 return local_source_;
578 } 577 }
579 578
580 bool FFmpegDemuxer::IsSeekable() { 579 bool FFmpegDemuxer::IsSeekable() {
581 return !IsStreaming(); 580 return !IsStreaming();
582 } 581 }
583 582
584 void FFmpegDemuxer::SeekTask(base::TimeDelta time, const FilterStatusCB& cb) { 583 void FFmpegDemuxer::SeekTask(base::TimeDelta time, const PipelineStatusCB& cb) {
585 DCHECK_EQ(MessageLoop::current(), message_loop_); 584 DCHECK_EQ(MessageLoop::current(), message_loop_);
586 585
587 // TODO(scherkus): remove this by separating Seek() from Flush() from 586 // TODO(scherkus): remove this by separating Seek() from Flush() from
588 // Preroll() states (i.e., the implicit Seek(0) should really be a Preroll()). 587 // Preroll() states (i.e., the implicit Seek(0) should really be a Preroll()).
589 if (first_seek_hack_) { 588 if (first_seek_hack_) {
590 first_seek_hack_ = false; 589 first_seek_hack_ = false;
591 590
592 if (time == start_time_) { 591 if (time == start_time_) {
593 cb.Run(PIPELINE_OK); 592 cb.Run(PIPELINE_OK);
594 return; 593 return;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 read_event_.Wait(); 732 read_event_.Wait();
734 return last_read_bytes_; 733 return last_read_bytes_;
735 } 734 }
736 735
737 void FFmpegDemuxer::SignalReadCompleted(size_t size) { 736 void FFmpegDemuxer::SignalReadCompleted(size_t size) {
738 last_read_bytes_ = size; 737 last_read_bytes_ = size;
739 read_event_.Signal(); 738 read_event_.Signal();
740 } 739 }
741 740
742 } // namespace media 741 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698