Chromium Code Reviews| Index: media/ffmpeg/ffmpeg_common.cc |
| diff --git a/media/ffmpeg/ffmpeg_common.cc b/media/ffmpeg/ffmpeg_common.cc |
| index 7af9635b6bcfd4c3e22aa69a87ade04de6745fb1..d095b807f73f4977c95a023b508f266cc0390ef2 100644 |
| --- a/media/ffmpeg/ffmpeg_common.cc |
| +++ b/media/ffmpeg/ffmpeg_common.cc |
| @@ -206,4 +206,29 @@ int GetSurfaceWidth(AVStream* stream) { |
| return width & ~1; |
| } |
| +void DestroyAVFormatContext(AVFormatContext* format_context) { |
| + if (!format_context) |
|
scherkus (not reviewing)
2011/06/22 17:31:09
we expect to receive NULL?
acolwell GONE FROM CHROMIUM
2011/06/23 16:51:28
No. I just copied a little too much from FFmpegDem
|
| + return; |
| + |
| + // Iterate each stream and destroy each one of them. |
| + int streams = format_context->nb_streams; |
| + for (int i = 0; i < streams; ++i) { |
| + AVStream* stream = format_context->streams[i]; |
| + |
| + // The conditions for calling avcodec_close(): |
| + // 1. AVStream is alive. |
| + // 2. AVCodecContext in AVStream is alive. |
| + // 3. AVCodec in AVCodecContext is alive. |
| + // Notice that closing a codec context without prior avcodec_open() will |
| + // result in a crash in FFmpeg. |
| + if (stream && stream->codec && stream->codec->codec) { |
| + stream->discard = AVDISCARD_ALL; |
| + avcodec_close(stream->codec); |
| + } |
| + } |
| + |
| + // Then finally cleanup the format context. |
| + av_close_input_file(format_context); |
| +} |
| + |
| } // namespace media |