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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 else | 199 else |
200 aspect_ratio = 1.0; | 200 aspect_ratio = 1.0; |
201 | 201 |
202 int width = floor(stream->codec->coded_width * aspect_ratio + 0.5); | 202 int width = floor(stream->codec->coded_width * aspect_ratio + 0.5); |
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) { |
| 210 DCHECK(format_context); |
| 211 |
| 212 // Iterate each stream and destroy each one of them. |
| 213 int streams = format_context->nb_streams; |
| 214 for (int i = 0; i < streams; ++i) { |
| 215 AVStream* stream = format_context->streams[i]; |
| 216 |
| 217 // The conditions for calling avcodec_close(): |
| 218 // 1. AVStream is alive. |
| 219 // 2. AVCodecContext in AVStream is alive. |
| 220 // 3. AVCodec in AVCodecContext is alive. |
| 221 // Notice that closing a codec context without prior avcodec_open() will |
| 222 // result in a crash in FFmpeg. |
| 223 if (stream && stream->codec && stream->codec->codec) { |
| 224 stream->discard = AVDISCARD_ALL; |
| 225 avcodec_close(stream->codec); |
| 226 } |
| 227 } |
| 228 |
| 229 // Then finally cleanup the format context. |
| 230 av_close_input_file(format_context); |
| 231 } |
| 232 |
209 } // namespace media | 233 } // namespace media |
OLD | NEW |