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/metrics/sparse_histogram.h" | 9 #include "base/metrics/sparse_histogram.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 int numRead = AVIOReadOperation( | 168 int numRead = AVIOReadOperation( |
169 avio_context_.get()->opaque, buffer.get()->data(), buffer.get()->size()); | 169 avio_context_.get()->opaque, buffer.get()->data(), buffer.get()->size()); |
170 AVIOSeekOperation(avio_context_.get()->opaque, pos, SEEK_SET); | 170 AVIOSeekOperation(avio_context_.get()->opaque, pos, SEEK_SET); |
171 if (numRead > 0) { | 171 if (numRead > 0) { |
172 // < 0 means Read failed | 172 // < 0 means Read failed |
173 container_names::MediaContainerName container = | 173 container_names::MediaContainerName container = |
174 container_names::DetermineContainer(buffer.get()->data(), numRead); | 174 container_names::DetermineContainer(buffer.get()->data(), numRead); |
175 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedContainer", container); | 175 UMA_HISTOGRAM_SPARSE_SLOWLY("Media.DetectedContainer", container); |
176 } | 176 } |
177 | 177 |
178 // Use TOC when available to quickly seek MP3 file. | |
179 // TODO(dalecurtis): Remove this upon rolling ffmpeg. Commit c43bd08... will | |
180 // make setting AVFMT_FLAG_FAST_SEEK (which we already do) default usetoc = 1. | |
181 AVDictionary* options = nullptr; | |
182 av_dict_set(&options, "usetoc", "1", 0); | |
183 | |
184 // By passing nullptr for the filename (second parameter) we are telling | 178 // By passing nullptr for the filename (second parameter) we are telling |
185 // FFmpeg to use the AVIO context we setup from the AVFormatContext structure. | 179 // FFmpeg to use the AVIO context we setup from the AVFormatContext structure. |
186 bool success = | 180 return avformat_open_input(&format_context_, nullptr, nullptr, nullptr) == 0; |
187 avformat_open_input(&format_context_, nullptr, nullptr, &options) == 0; | |
188 | |
189 if (options) | |
190 av_dict_free(&options); | |
191 | |
192 return success; | |
193 } | 181 } |
194 | 182 |
195 FFmpegGlue::~FFmpegGlue() { | 183 FFmpegGlue::~FFmpegGlue() { |
196 // In the event of avformat_open_input() failure, FFmpeg may sometimes free | 184 // In the event of avformat_open_input() failure, FFmpeg may sometimes free |
197 // our AVFormatContext behind the scenes, but leave the buffer alive. It will | 185 // our AVFormatContext behind the scenes, but leave the buffer alive. It will |
198 // helpfully set |format_context_| to nullptr in this case. | 186 // helpfully set |format_context_| to nullptr in this case. |
199 if (!format_context_) { | 187 if (!format_context_) { |
200 av_free(avio_context_->buffer); | 188 av_free(avio_context_->buffer); |
201 return; | 189 return; |
202 } | 190 } |
(...skipping 24 matching lines...) Expand all Loading... |
227 avcodec_close(stream->codec); | 215 avcodec_close(stream->codec); |
228 } | 216 } |
229 } | 217 } |
230 } | 218 } |
231 | 219 |
232 avformat_close_input(&format_context_); | 220 avformat_close_input(&format_context_); |
233 av_free(avio_context_->buffer); | 221 av_free(avio_context_->buffer); |
234 } | 222 } |
235 | 223 |
236 } // namespace media | 224 } // namespace media |
OLD | NEW |