OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/filters/ffmpeg_glue.h" | 5 #include "media/filters/ffmpeg_glue.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 191 } |
192 | 192 |
193 // If avformat_open_input() hasn't been called, we should simply free the | 193 // If avformat_open_input() hasn't been called, we should simply free the |
194 // AVFormatContext and buffer instead of using avformat_close_input(). | 194 // AVFormatContext and buffer instead of using avformat_close_input(). |
195 if (!open_called_) { | 195 if (!open_called_) { |
196 avformat_free_context(format_context_); | 196 avformat_free_context(format_context_); |
197 av_free(avio_context_->buffer); | 197 av_free(avio_context_->buffer); |
198 return; | 198 return; |
199 } | 199 } |
200 | 200 |
201 // If avformat_open_input() has been called with this context, we need to | |
202 // close out any codecs/streams before closing the context. | |
203 if (format_context_->streams) { | |
204 for (int i = format_context_->nb_streams - 1; i >= 0; --i) { | |
205 AVStream* stream = format_context_->streams[i]; | |
206 | |
207 // The conditions for calling avcodec_close(): | |
208 // 1. AVStream is alive. | |
209 // 2. AVCodecContext in AVStream is alive. | |
210 // 3. AVCodec in AVCodecContext is alive. | |
211 // | |
212 // Closing a codec context without prior avcodec_open2() will result in | |
213 // a crash in FFmpeg. | |
214 if (stream && stream->codec && stream->codec->codec) { | |
215 stream->discard = AVDISCARD_ALL; | |
216 avcodec_close(stream->codec); | |
217 } | |
218 } | |
219 } | |
220 | |
221 avformat_close_input(&format_context_); | 201 avformat_close_input(&format_context_); |
222 av_free(avio_context_->buffer); | 202 av_free(avio_context_->buffer); |
223 } | 203 } |
224 | 204 |
225 } // namespace media | 205 } // namespace media |
OLD | NEW |