OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_audio_decoder.h" | 5 #include "media/filters/ffmpeg_audio_decoder.h" |
6 | 6 |
7 #include "media/base/callback.h" | 7 #include "media/base/callback.h" |
8 #include "media/base/data_buffer.h" | 8 #include "media/base/data_buffer.h" |
9 #include "media/base/limits.h" | 9 #include "media/base/limits.h" |
10 #include "media/ffmpeg/ffmpeg_common.h" | 10 #include "media/ffmpeg/ffmpeg_common.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 bps == 0 || | 54 bps == 0 || |
55 static_cast<size_t>(bps) > Limits::kMaxBPS || | 55 static_cast<size_t>(bps) > Limits::kMaxBPS || |
56 codec_context_->sample_rate == 0 || | 56 codec_context_->sample_rate == 0 || |
57 (static_cast<size_t>(codec_context_->sample_rate) > | 57 (static_cast<size_t>(codec_context_->sample_rate) > |
58 Limits::kMaxSampleRate)) { | 58 Limits::kMaxSampleRate)) { |
59 return; | 59 return; |
60 } | 60 } |
61 | 61 |
62 // Serialize calls to avcodec_open(). | 62 // Serialize calls to avcodec_open(). |
63 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); | 63 AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); |
64 { | 64 if (!codec || avcodec_open(codec_context_, codec) < 0) { |
65 AutoLock auto_lock(FFmpegLock::get()->lock()); | 65 return; |
66 if (!codec || avcodec_open(codec_context_, codec) < 0) { | |
67 return; | |
68 } | |
69 } | 66 } |
70 | 67 |
71 // When calling avcodec_find_decoder(), |codec_context_| might be altered by | 68 // When calling avcodec_find_decoder(), |codec_context_| might be altered by |
72 // the decoder to give more accurate values of the output format of the | 69 // the decoder to give more accurate values of the output format of the |
73 // decoder. So set the media format after a decoder is allocated. | 70 // decoder. So set the media format after a decoder is allocated. |
74 // TODO(hclam): Reuse the information provided by the demuxer for now, we may | 71 // TODO(hclam): Reuse the information provided by the demuxer for now, we may |
75 // need to wait until the first buffer is decoded to know the correct | 72 // need to wait until the first buffer is decoded to know the correct |
76 // information. | 73 // information. |
77 media_format_.SetAsInteger(MediaFormat::kChannels, codec_context_->channels); | 74 media_format_.SetAsInteger(MediaFormat::kChannels, codec_context_->channels); |
78 media_format_.SetAsInteger(MediaFormat::kSampleBits, | 75 media_format_.SetAsInteger(MediaFormat::kSampleBits, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) { | 189 base::TimeDelta FFmpegAudioDecoder::CalculateDuration(size_t size) { |
193 int64 denominator = codec_context_->channels * | 190 int64 denominator = codec_context_->channels * |
194 av_get_bits_per_sample_format(codec_context_->sample_fmt) / 8 * | 191 av_get_bits_per_sample_format(codec_context_->sample_fmt) / 8 * |
195 codec_context_->sample_rate; | 192 codec_context_->sample_rate; |
196 double microseconds = size / | 193 double microseconds = size / |
197 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond)); | 194 (denominator / static_cast<double>(base::Time::kMicrosecondsPerSecond)); |
198 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)); | 195 return base::TimeDelta::FromMicroseconds(static_cast<int64>(microseconds)); |
199 } | 196 } |
200 | 197 |
201 } // namespace | 198 } // namespace |
OLD | NEW |