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()); |
238 if (!format_context_) | 239 if (!format_context_) |
239 return; | 240 return; |
240 | 241 |
241 // Iterate each stream and destroy each one of them. | 242 // Iterate each stream and destroy each one of them. |
242 int streams = format_context_->nb_streams; | 243 int streams = format_context_->nb_streams; |
243 for (int i = 0; i < streams; ++i) { | 244 for (int i = 0; i < streams; ++i) { |
244 AVStream* stream = format_context_->streams[i]; | 245 AVStream* stream = format_context_->streams[i]; |
245 | 246 |
246 // The conditions for calling avcodec_close(): | 247 // The conditions for calling avcodec_close(): |
247 // 1. AVStream is alive. | 248 // 1. AVStream is alive. |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 | 390 |
390 if (result < 0) { | 391 if (result < 0) { |
391 host()->SetError(DEMUXER_ERROR_COULD_NOT_OPEN); | 392 host()->SetError(DEMUXER_ERROR_COULD_NOT_OPEN); |
392 callback->Run(); | 393 callback->Run(); |
393 return; | 394 return; |
394 } | 395 } |
395 | 396 |
396 DCHECK(context); | 397 DCHECK(context); |
397 format_context_ = context; | 398 format_context_ = context; |
398 | 399 |
399 // Fully initialize AVFormatContext by parsing the stream a little. | 400 // Serialize calls to av_find_stream_info(). |
400 result = av_find_stream_info(format_context_); | 401 { |
401 if (result < 0) { | 402 AutoLock auto_lock(FFmpegLock::get()->lock()); |
402 host()->SetError(DEMUXER_ERROR_COULD_NOT_PARSE); | 403 |
403 callback->Run(); | 404 // Fully initialize AVFormatContext by parsing the stream a little. |
404 return; | 405 result = av_find_stream_info(format_context_); |
| 406 if (result < 0) { |
| 407 host()->SetError(DEMUXER_ERROR_COULD_NOT_PARSE); |
| 408 callback->Run(); |
| 409 return; |
| 410 } |
405 } | 411 } |
406 | 412 |
407 // Create demuxer streams for all supported streams. | 413 // Create demuxer streams for all supported streams. |
408 base::TimeDelta max_duration; | 414 base::TimeDelta max_duration; |
409 for (size_t i = 0; i < format_context_->nb_streams; ++i) { | 415 for (size_t i = 0; i < format_context_->nb_streams; ++i) { |
410 AVCodecContext* codec_context = format_context_->streams[i]->codec; | 416 AVCodecContext* codec_context = format_context_->streams[i]->codec; |
411 CodecType codec_type = codec_context->codec_type; | 417 CodecType codec_type = codec_context->codec_type; |
412 if (codec_type == CODEC_TYPE_AUDIO || codec_type == CODEC_TYPE_VIDEO) { | 418 if (codec_type == CODEC_TYPE_AUDIO || codec_type == CODEC_TYPE_VIDEO) { |
413 AVStream* stream = format_context_->streams[i]; | 419 AVStream* stream = format_context_->streams[i]; |
414 FFmpegDemuxerStream* demuxer_stream | 420 FFmpegDemuxerStream* demuxer_stream |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 read_event_.Wait(); | 606 read_event_.Wait(); |
601 return last_read_bytes_; | 607 return last_read_bytes_; |
602 } | 608 } |
603 | 609 |
604 void FFmpegDemuxer::SignalReadCompleted(size_t size) { | 610 void FFmpegDemuxer::SignalReadCompleted(size_t size) { |
605 last_read_bytes_ = size; | 611 last_read_bytes_ = size; |
606 read_event_.Signal(); | 612 read_event_.Signal(); |
607 } | 613 } |
608 | 614 |
609 } // namespace media | 615 } // namespace media |
OLD | NEW |