Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: webkit/media/crypto/ppapi/ffmpeg_cdm_audio_decoder.cc

Issue 12224114: Guard against midstream audio configuration changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "webkit/media/crypto/ppapi/ffmpeg_cdm_audio_decoder.h" 5 #include "webkit/media/crypto/ppapi/ffmpeg_cdm_audio_decoder.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "media/base/audio_bus.h" 10 #include "media/base/audio_bus.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 80 }
81 } 81 }
82 82
83 FFmpegCdmAudioDecoder::FFmpegCdmAudioDecoder(cdm::Allocator* allocator) 83 FFmpegCdmAudioDecoder::FFmpegCdmAudioDecoder(cdm::Allocator* allocator)
84 : is_initialized_(false), 84 : is_initialized_(false),
85 allocator_(allocator), 85 allocator_(allocator),
86 codec_context_(NULL), 86 codec_context_(NULL),
87 av_frame_(NULL), 87 av_frame_(NULL),
88 bits_per_channel_(0), 88 bits_per_channel_(0),
89 samples_per_second_(0), 89 samples_per_second_(0),
90 channels_(0),
91 av_sample_format_(0),
90 bytes_per_frame_(0), 92 bytes_per_frame_(0),
91 last_input_timestamp_(media::kNoTimestamp()), 93 last_input_timestamp_(media::kNoTimestamp()),
92 output_bytes_to_drop_(0) { 94 output_bytes_to_drop_(0) {
93 } 95 }
94 96
95 FFmpegCdmAudioDecoder::~FFmpegCdmAudioDecoder() { 97 FFmpegCdmAudioDecoder::~FFmpegCdmAudioDecoder() {
96 ReleaseFFmpegResources(); 98 ReleaseFFmpegResources();
97 } 99 }
98 100
99 bool FFmpegCdmAudioDecoder::Initialize(const cdm::AudioDecoderConfig& config) { 101 bool FFmpegCdmAudioDecoder::Initialize(const cdm::AudioDecoderConfig& config) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // Success! 149 // Success!
148 av_frame_ = avcodec_alloc_frame(); 150 av_frame_ = avcodec_alloc_frame();
149 bits_per_channel_ = config.bits_per_channel; 151 bits_per_channel_ = config.bits_per_channel;
150 samples_per_second_ = config.samples_per_second; 152 samples_per_second_ = config.samples_per_second;
151 bytes_per_frame_ = codec_context_->channels * bits_per_channel_ / 8; 153 bytes_per_frame_ = codec_context_->channels * bits_per_channel_ / 8;
152 output_timestamp_helper_.reset(new media::AudioTimestampHelper( 154 output_timestamp_helper_.reset(new media::AudioTimestampHelper(
153 bytes_per_frame_, config.samples_per_second)); 155 bytes_per_frame_, config.samples_per_second));
154 serialized_audio_frames_.reserve(bytes_per_frame_ * samples_per_second_); 156 serialized_audio_frames_.reserve(bytes_per_frame_ * samples_per_second_);
155 is_initialized_ = true; 157 is_initialized_ = true;
156 158
159 // Store initial values to guard against mid-frame configuration changes.
scherkus (not reviewing) 2013/02/12 02:16:56 consistent terminology nit: s/mid-frame/mid-stream
DaleCurtis 2013/02/12 02:41:24 Done.
160 channels_ = codec_context_->channels;
161 av_sample_format_ = codec_context_->sample_fmt;
162
157 return true; 163 return true;
158 } 164 }
159 165
160 void FFmpegCdmAudioDecoder::Deinitialize() { 166 void FFmpegCdmAudioDecoder::Deinitialize() {
161 DVLOG(1) << "Deinitialize()"; 167 DVLOG(1) << "Deinitialize()";
162 ReleaseFFmpegResources(); 168 ReleaseFFmpegResources();
163 is_initialized_ = false; 169 is_initialized_ = false;
164 ResetTimestampState(); 170 ResetTimestampState();
165 } 171 }
166 172
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // If we have to drop samples it always means the timeline starts at 0. 268 // If we have to drop samples it always means the timeline starts at 0.
263 DCHECK_EQ(codec_context_->codec_id, CODEC_ID_VORBIS); 269 DCHECK_EQ(codec_context_->codec_id, CODEC_ID_VORBIS);
264 output_timestamp_helper_->SetBaseTimestamp(base::TimeDelta()); 270 output_timestamp_helper_->SetBaseTimestamp(base::TimeDelta());
265 } else { 271 } else {
266 output_timestamp_helper_->SetBaseTimestamp(timestamp); 272 output_timestamp_helper_->SetBaseTimestamp(timestamp);
267 } 273 }
268 } 274 }
269 275
270 int decoded_audio_size = 0; 276 int decoded_audio_size = 0;
271 if (frame_decoded) { 277 if (frame_decoded) {
272 int output_sample_rate = av_frame_->sample_rate; 278 if (av_frame_->sample_rate != samples_per_second_ ||
273 if (output_sample_rate != samples_per_second_) { 279 av_frame_->channels != channels_ ||
274 DLOG(ERROR) << "Output sample rate (" << output_sample_rate 280 av_frame_->format != av_sample_format_) {
275 << ") doesn't match expected rate " << samples_per_second_; 281 DLOG(ERROR) << "Unsupported mid-frame configuration change!"
scherkus (not reviewing) 2013/02/12 02:16:56 consistent terminology nit: s/mid-frame/mid-stream
DaleCurtis 2013/02/12 02:41:24 Done.
282 << " Sample Rate: " << av_frame_->sample_rate << " vs "
283 << samples_per_second_
284 << ", Channels: " << av_frame_->channels << " vs "
285 << channels_
286 << ", Sample Format: " << av_frame_->format << " vs "
287 << av_sample_format_;
276 return cdm::kDecodeError; 288 return cdm::kDecodeError;
277 } 289 }
278 290
279 decoded_audio_size = av_samples_get_buffer_size( 291 decoded_audio_size = av_samples_get_buffer_size(
280 NULL, codec_context_->channels, av_frame_->nb_samples, 292 NULL, codec_context_->channels, av_frame_->nb_samples,
281 codec_context_->sample_fmt, 1); 293 codec_context_->sample_fmt, 1);
282 // If we're decoding into float, adjust audio size. 294 // If we're decoding into float, adjust audio size.
283 if (converter_bus_ && bits_per_channel_ / 8 != sizeof(float)) { 295 if (converter_bus_ && bits_per_channel_ / 8 != sizeof(float)) {
284 DCHECK(codec_context_->sample_fmt == AV_SAMPLE_FMT_FLT || 296 DCHECK(codec_context_->sample_fmt == AV_SAMPLE_FMT_FLT ||
285 codec_context_->sample_fmt == AV_SAMPLE_FMT_FLTP); 297 codec_context_->sample_fmt == AV_SAMPLE_FMT_FLTP);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 } 401 }
390 } 402 }
391 403
392 void FFmpegCdmAudioDecoder::SerializeInt64(int64 value) { 404 void FFmpegCdmAudioDecoder::SerializeInt64(int64 value) {
393 int previous_size = serialized_audio_frames_.size(); 405 int previous_size = serialized_audio_frames_.size();
394 serialized_audio_frames_.resize(previous_size + sizeof(value)); 406 serialized_audio_frames_.resize(previous_size + sizeof(value));
395 memcpy(&serialized_audio_frames_[0] + previous_size, &value, sizeof(value)); 407 memcpy(&serialized_audio_frames_[0] + previous_size, &value, sizeof(value));
396 } 408 }
397 409
398 } // namespace webkit_media 410 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698