OLD | NEW |
---|---|
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 "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" |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 const AVRational& time_base, int64 timestamp) { | 269 const AVRational& time_base, int64 timestamp) { |
270 if (timestamp == static_cast<int64>(AV_NOPTS_VALUE)) | 270 if (timestamp == static_cast<int64>(AV_NOPTS_VALUE)) |
271 return kNoTimestamp(); | 271 return kNoTimestamp(); |
272 | 272 |
273 return ConvertFromTimeBase(time_base, timestamp); | 273 return ConvertFromTimeBase(time_base, timestamp); |
274 } | 274 } |
275 | 275 |
276 // | 276 // |
277 // FFmpegDemuxer | 277 // FFmpegDemuxer |
278 // | 278 // |
279 FFmpegDemuxer::FFmpegDemuxer(MessageLoop* message_loop, bool local_source) | 279 FFmpegDemuxer::FFmpegDemuxer( |
280 MessageLoop* message_loop, | |
281 const scoped_refptr<DataSource>& data_source, | |
282 bool local_source) | |
280 : message_loop_(message_loop), | 283 : message_loop_(message_loop), |
281 local_source_(local_source), | 284 local_source_(local_source), |
282 format_context_(NULL), | 285 format_context_(NULL), |
286 data_source_(data_source), | |
283 read_event_(false, false), | 287 read_event_(false, false), |
284 read_has_failed_(false), | 288 read_has_failed_(false), |
285 last_read_bytes_(0), | 289 last_read_bytes_(0), |
286 read_position_(0), | 290 read_position_(0), |
287 max_duration_(base::TimeDelta::FromMicroseconds(-1)), | 291 max_duration_(base::TimeDelta::FromMicroseconds(-1)), |
288 deferred_status_(PIPELINE_OK), | 292 deferred_status_(PIPELINE_OK), |
289 first_seek_hack_(true), | 293 first_seek_hack_(true), |
290 start_time_(kNoTimestamp()), | 294 start_time_(kNoTimestamp()), |
291 audio_disabled_(false) { | 295 audio_disabled_(false) { |
292 DCHECK(message_loop_); | 296 DCHECK(message_loop_); |
297 DCHECK(data_source_); | |
293 } | 298 } |
294 | 299 |
295 FFmpegDemuxer::~FFmpegDemuxer() { | 300 FFmpegDemuxer::~FFmpegDemuxer() { |
296 // In this destructor, we clean up resources held by FFmpeg. It is ugly to | 301 // In this destructor, we clean up resources held by FFmpeg. It is ugly to |
297 // close the codec contexts here because the corresponding codecs are opened | 302 // close the codec contexts here because the corresponding codecs are opened |
298 // in the decoder filters. By reaching this point, all filters should have | 303 // in the decoder filters. By reaching this point, all filters should have |
299 // stopped, so this is the only safe place to do the global clean up. | 304 // stopped, so this is the only safe place to do the global clean up. |
300 // TODO(hclam): close the codecs in the corresponding decoders. | 305 // TODO(hclam): close the codecs in the corresponding decoders. |
301 if (!format_context_) | 306 if (!format_context_) |
302 return; | 307 return; |
(...skipping 26 matching lines...) Expand all Loading... | |
329 data_source_->SetPlaybackRate(playback_rate); | 334 data_source_->SetPlaybackRate(playback_rate); |
330 } | 335 } |
331 | 336 |
332 void FFmpegDemuxer::OnAudioRendererDisabled() { | 337 void FFmpegDemuxer::OnAudioRendererDisabled() { |
333 message_loop_->PostTask(FROM_HERE, base::Bind( | 338 message_loop_->PostTask(FROM_HERE, base::Bind( |
334 &FFmpegDemuxer::DisableAudioStreamTask, this)); | 339 &FFmpegDemuxer::DisableAudioStreamTask, this)); |
335 } | 340 } |
336 | 341 |
337 void FFmpegDemuxer::set_host(DemuxerHost* demuxer_host) { | 342 void FFmpegDemuxer::set_host(DemuxerHost* demuxer_host) { |
338 Demuxer::set_host(demuxer_host); | 343 Demuxer::set_host(demuxer_host); |
339 if (data_source_) | 344 data_source_->set_host(demuxer_host); |
340 data_source_->set_host(demuxer_host); | 345 |
341 if (max_duration_.InMicroseconds() >= 0) | 346 if (max_duration_.InMicroseconds() >= 0) |
acolwell GONE FROM CHROMIUM
2012/03/27 20:11:35
I think all the deferred calls below shouldn't be
scherkus (not reviewing)
2012/03/27 20:44:09
woah!
ended up cleaning this code up a bit more b
| |
342 host()->SetDuration(max_duration_); | 347 host()->SetDuration(max_duration_); |
343 if (read_position_ > 0) | 348 if (read_position_ > 0) |
344 host()->SetCurrentReadPosition(read_position_); | 349 host()->SetCurrentReadPosition(read_position_); |
345 if (deferred_status_ != PIPELINE_OK) | 350 if (deferred_status_ != PIPELINE_OK) |
346 host()->OnDemuxerError(deferred_status_); | 351 host()->OnDemuxerError(deferred_status_); |
347 } | 352 } |
348 | 353 |
349 void FFmpegDemuxer::Initialize(DataSource* data_source, | 354 void FFmpegDemuxer::Initialize(const PipelineStatusCB& status_cb) { |
350 const PipelineStatusCB& status_cb) { | 355 message_loop_->PostTask(FROM_HERE, base::Bind( |
351 message_loop_->PostTask( | 356 &FFmpegDemuxer::InitializeTask, this, status_cb)); |
352 FROM_HERE, | |
353 base::Bind(&FFmpegDemuxer::InitializeTask, this, | |
354 make_scoped_refptr(data_source), status_cb)); | |
355 } | 357 } |
356 | 358 |
357 scoped_refptr<DemuxerStream> FFmpegDemuxer::GetStream( | 359 scoped_refptr<DemuxerStream> FFmpegDemuxer::GetStream( |
358 DemuxerStream::Type type) { | 360 DemuxerStream::Type type) { |
359 StreamVector::iterator iter; | 361 StreamVector::iterator iter; |
360 for (iter = streams_.begin(); iter != streams_.end(); ++iter) { | 362 for (iter = streams_.begin(); iter != streams_.end(); ++iter) { |
361 if (*iter && (*iter)->type() == type) { | 363 if (*iter && (*iter)->type() == type) { |
362 return *iter; | 364 return *iter; |
363 } | 365 } |
364 } | 366 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 bool FFmpegDemuxer::IsStreaming() { | 438 bool FFmpegDemuxer::IsStreaming() { |
437 DCHECK(data_source_); | 439 DCHECK(data_source_); |
438 | 440 |
439 return data_source_->IsStreaming(); | 441 return data_source_->IsStreaming(); |
440 } | 442 } |
441 | 443 |
442 MessageLoop* FFmpegDemuxer::message_loop() { | 444 MessageLoop* FFmpegDemuxer::message_loop() { |
443 return message_loop_; | 445 return message_loop_; |
444 } | 446 } |
445 | 447 |
446 void FFmpegDemuxer::InitializeTask(DataSource* data_source, | 448 void FFmpegDemuxer::InitializeTask(const PipelineStatusCB& status_cb) { |
447 const PipelineStatusCB& status_cb) { | |
448 DCHECK_EQ(MessageLoop::current(), message_loop_); | 449 DCHECK_EQ(MessageLoop::current(), message_loop_); |
449 | 450 |
450 data_source_ = data_source; | |
451 if (host()) | |
452 data_source_->set_host(host()); | |
453 | |
454 // Add ourself to Protocol list and get our unique key. | 451 // Add ourself to Protocol list and get our unique key. |
455 std::string key = FFmpegGlue::GetInstance()->AddProtocol(this); | 452 std::string key = FFmpegGlue::GetInstance()->AddProtocol(this); |
456 | 453 |
457 // Open FFmpeg AVFormatContext. | 454 // Open FFmpeg AVFormatContext. |
458 DCHECK(!format_context_); | 455 DCHECK(!format_context_); |
459 AVFormatContext* context = NULL; | 456 AVFormatContext* context = NULL; |
460 int result = avformat_open_input(&context, key.c_str(), NULL, NULL); | 457 int result = avformat_open_input(&context, key.c_str(), NULL, NULL); |
461 | 458 |
462 // Remove ourself from protocol list. | 459 // Remove ourself from protocol list. |
463 FFmpegGlue::GetInstance()->RemoveProtocol(this); | 460 FFmpegGlue::GetInstance()->RemoveProtocol(this); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
732 read_event_.Wait(); | 729 read_event_.Wait(); |
733 return last_read_bytes_; | 730 return last_read_bytes_; |
734 } | 731 } |
735 | 732 |
736 void FFmpegDemuxer::SignalReadCompleted(int size) { | 733 void FFmpegDemuxer::SignalReadCompleted(int size) { |
737 last_read_bytes_ = size; | 734 last_read_bytes_ = size; |
738 read_event_.Signal(); | 735 read_event_.Signal(); |
739 } | 736 } |
740 | 737 |
741 } // namespace media | 738 } // namespace media |
OLD | NEW |