OLD | NEW |
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/callback.h" | 5 #include "base/callback.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 273 |
274 FFmpegDemuxer::~FFmpegDemuxer() { | 274 FFmpegDemuxer::~FFmpegDemuxer() { |
275 // In this destructor, we clean up resources held by FFmpeg. It is ugly to | 275 // In this destructor, we clean up resources held by FFmpeg. It is ugly to |
276 // close the codec contexts here because the corresponding codecs are opened | 276 // close the codec contexts here because the corresponding codecs are opened |
277 // in the decoder filters. By reaching this point, all filters should have | 277 // in the decoder filters. By reaching this point, all filters should have |
278 // stopped, so this is the only safe place to do the global clean up. | 278 // stopped, so this is the only safe place to do the global clean up. |
279 // TODO(hclam): close the codecs in the corresponding decoders. | 279 // TODO(hclam): close the codecs in the corresponding decoders. |
280 if (!format_context_) | 280 if (!format_context_) |
281 return; | 281 return; |
282 | 282 |
283 // Iterate each stream and destroy each one of them. | 283 DestroyAVFormatContext(format_context_); |
284 int streams = format_context_->nb_streams; | |
285 for (int i = 0; i < streams; ++i) { | |
286 AVStream* stream = format_context_->streams[i]; | |
287 | |
288 // The conditions for calling avcodec_close(): | |
289 // 1. AVStream is alive. | |
290 // 2. AVCodecContext in AVStream is alive. | |
291 // 3. AVCodec in AVCodecContext is alive. | |
292 // Notice that closing a codec context without prior avcodec_open() will | |
293 // result in a crash in FFmpeg. | |
294 if (stream && stream->codec && stream->codec->codec) { | |
295 stream->discard = AVDISCARD_ALL; | |
296 avcodec_close(stream->codec); | |
297 } | |
298 } | |
299 | |
300 // Then finally cleanup the format context. | |
301 av_close_input_file(format_context_); | |
302 format_context_ = NULL; | 284 format_context_ = NULL; |
303 } | 285 } |
304 | 286 |
305 void FFmpegDemuxer::PostDemuxTask() { | 287 void FFmpegDemuxer::PostDemuxTask() { |
306 message_loop_->PostTask(FROM_HERE, | 288 message_loop_->PostTask(FROM_HERE, |
307 NewRunnableMethod(this, &FFmpegDemuxer::DemuxTask)); | 289 NewRunnableMethod(this, &FFmpegDemuxer::DemuxTask)); |
308 } | 290 } |
309 | 291 |
310 void FFmpegDemuxer::Stop(FilterCallback* callback) { | 292 void FFmpegDemuxer::Stop(FilterCallback* callback) { |
311 // Post a task to notify the streams to stop as well. | 293 // Post a task to notify the streams to stop as well. |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 read_event_.Wait(); | 684 read_event_.Wait(); |
703 return last_read_bytes_; | 685 return last_read_bytes_; |
704 } | 686 } |
705 | 687 |
706 void FFmpegDemuxer::SignalReadCompleted(size_t size) { | 688 void FFmpegDemuxer::SignalReadCompleted(size_t size) { |
707 last_read_bytes_ = size; | 689 last_read_bytes_ = size; |
708 read_event_.Signal(); | 690 read_event_.Signal(); |
709 } | 691 } |
710 | 692 |
711 } // namespace media | 693 } // namespace media |
OLD | NEW |