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