| 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 "media/ffmpeg/ffmpeg_common.h" | 5 #include "media/ffmpeg/ffmpeg_common.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace media { | 9 namespace media { |
| 10 | 10 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 203 |
| 204 // An even width makes things easier for YV12 and appears to be the behavior | 204 // An even width makes things easier for YV12 and appears to be the behavior |
| 205 // expected by WebKit layout tests. | 205 // expected by WebKit layout tests. |
| 206 return width & ~1; | 206 return width & ~1; |
| 207 } | 207 } |
| 208 | 208 |
| 209 void DestroyAVFormatContext(AVFormatContext* format_context) { | 209 void DestroyAVFormatContext(AVFormatContext* format_context) { |
| 210 DCHECK(format_context); | 210 DCHECK(format_context); |
| 211 | 211 |
| 212 // Iterate each stream and destroy each one of them. | 212 // Iterate each stream and destroy each one of them. |
| 213 int streams = format_context->nb_streams; | 213 if (format_context->streams) { |
| 214 for (int i = 0; i < streams; ++i) { | 214 int streams = format_context->nb_streams; |
| 215 AVStream* stream = format_context->streams[i]; | 215 for (int i = 0; i < streams; ++i) { |
| 216 AVStream* stream = format_context->streams[i]; |
| 216 | 217 |
| 217 // The conditions for calling avcodec_close(): | 218 // The conditions for calling avcodec_close(): |
| 218 // 1. AVStream is alive. | 219 // 1. AVStream is alive. |
| 219 // 2. AVCodecContext in AVStream is alive. | 220 // 2. AVCodecContext in AVStream is alive. |
| 220 // 3. AVCodec in AVCodecContext is alive. | 221 // 3. AVCodec in AVCodecContext is alive. |
| 221 // Notice that closing a codec context without prior avcodec_open() will | 222 // Notice that closing a codec context without prior avcodec_open() will |
| 222 // result in a crash in FFmpeg. | 223 // result in a crash in FFmpeg. |
| 223 if (stream && stream->codec && stream->codec->codec) { | 224 if (stream && stream->codec && stream->codec->codec) { |
| 224 stream->discard = AVDISCARD_ALL; | 225 stream->discard = AVDISCARD_ALL; |
| 225 avcodec_close(stream->codec); | 226 avcodec_close(stream->codec); |
| 227 } |
| 226 } | 228 } |
| 227 } | 229 } |
| 228 | 230 |
| 229 // Then finally cleanup the format context. | 231 // Then finally cleanup the format context. |
| 230 av_close_input_file(format_context); | 232 av_close_input_file(format_context); |
| 231 } | 233 } |
| 232 | 234 |
| 233 } // namespace media | 235 } // namespace media |
| OLD | NEW |