OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/callback.h" | 5 #include "base/callback.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 read_position_(0), | 228 read_position_(0), |
229 first_seek_hack_(true) { | 229 first_seek_hack_(true) { |
230 } | 230 } |
231 | 231 |
232 FFmpegDemuxer::~FFmpegDemuxer() { | 232 FFmpegDemuxer::~FFmpegDemuxer() { |
233 // In this destructor, we clean up resources held by FFmpeg. It is ugly to | 233 // In this destructor, we clean up resources held by FFmpeg. It is ugly to |
234 // close the codec contexts here because the corresponding codecs are opened | 234 // close the codec contexts here because the corresponding codecs are opened |
235 // in the decoder filters. By reaching this point, all filters should have | 235 // in the decoder filters. By reaching this point, all filters should have |
236 // stopped, so this is the only safe place to do the global clean up. | 236 // stopped, so this is the only safe place to do the global clean up. |
237 // TODO(hclam): close the codecs in the corresponding decoders. | 237 // TODO(hclam): close the codecs in the corresponding decoders. |
238 AutoLock auto_lock(FFmpegLock::get()->lock()); | |
239 if (!format_context_) | 238 if (!format_context_) |
240 return; | 239 return; |
241 | 240 |
242 // Iterate each stream and destroy each one of them. | 241 // Iterate each stream and destroy each one of them. |
243 int streams = format_context_->nb_streams; | 242 int streams = format_context_->nb_streams; |
244 for (int i = 0; i < streams; ++i) { | 243 for (int i = 0; i < streams; ++i) { |
245 AVStream* stream = format_context_->streams[i]; | 244 AVStream* stream = format_context_->streams[i]; |
246 | 245 |
247 // The conditions for calling avcodec_close(): | 246 // The conditions for calling avcodec_close(): |
248 // 1. AVStream is alive. | 247 // 1. AVStream is alive. |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 | 389 |
391 if (result < 0) { | 390 if (result < 0) { |
392 host()->SetError(DEMUXER_ERROR_COULD_NOT_OPEN); | 391 host()->SetError(DEMUXER_ERROR_COULD_NOT_OPEN); |
393 callback->Run(); | 392 callback->Run(); |
394 return; | 393 return; |
395 } | 394 } |
396 | 395 |
397 DCHECK(context); | 396 DCHECK(context); |
398 format_context_ = context; | 397 format_context_ = context; |
399 | 398 |
400 // Serialize calls to av_find_stream_info(). | 399 // Fully initialize AVFormatContext by parsing the stream a little. |
401 { | 400 result = av_find_stream_info(format_context_); |
402 AutoLock auto_lock(FFmpegLock::get()->lock()); | 401 if (result < 0) { |
403 | 402 host()->SetError(DEMUXER_ERROR_COULD_NOT_PARSE); |
404 // Fully initialize AVFormatContext by parsing the stream a little. | 403 callback->Run(); |
405 result = av_find_stream_info(format_context_); | 404 return; |
406 if (result < 0) { | |
407 host()->SetError(DEMUXER_ERROR_COULD_NOT_PARSE); | |
408 callback->Run(); | |
409 return; | |
410 } | |
411 } | 405 } |
412 | 406 |
413 // Create demuxer streams for all supported streams. | 407 // Create demuxer streams for all supported streams. |
414 base::TimeDelta max_duration; | 408 base::TimeDelta max_duration; |
415 for (size_t i = 0; i < format_context_->nb_streams; ++i) { | 409 for (size_t i = 0; i < format_context_->nb_streams; ++i) { |
416 AVCodecContext* codec_context = format_context_->streams[i]->codec; | 410 AVCodecContext* codec_context = format_context_->streams[i]->codec; |
417 CodecType codec_type = codec_context->codec_type; | 411 CodecType codec_type = codec_context->codec_type; |
418 if (codec_type == CODEC_TYPE_AUDIO || codec_type == CODEC_TYPE_VIDEO) { | 412 if (codec_type == CODEC_TYPE_AUDIO || codec_type == CODEC_TYPE_VIDEO) { |
419 AVStream* stream = format_context_->streams[i]; | 413 AVStream* stream = format_context_->streams[i]; |
420 FFmpegDemuxerStream* demuxer_stream | 414 FFmpegDemuxerStream* demuxer_stream |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 read_event_.Wait(); | 600 read_event_.Wait(); |
607 return last_read_bytes_; | 601 return last_read_bytes_; |
608 } | 602 } |
609 | 603 |
610 void FFmpegDemuxer::SignalReadCompleted(size_t size) { | 604 void FFmpegDemuxer::SignalReadCompleted(size_t size) { |
611 last_read_bytes_ = size; | 605 last_read_bytes_ = size; |
612 read_event_.Signal(); | 606 read_event_.Signal(); |
613 } | 607 } |
614 | 608 |
615 } // namespace media | 609 } // namespace media |
OLD | NEW |