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

Side by Side Diff: media/filters/opus_audio_decoder.cc

Issue 257563007: Don't double correct for discarded codec delay frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style cleanup. Fix rendundant Initialize(). Created 6 years, 8 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
« no previous file with comments | « media/filters/audio_file_reader.cc ('k') | media/filters/opus_audio_decoder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "media/filters/opus_audio_decoder.h" 5 #include "media/filters/opus_audio_decoder.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/sys_byteorder.h" 10 #include "base/sys_byteorder.h"
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 DCHECK(task_runner_->BelongsToCurrentThread()); 282 DCHECK(task_runner_->BelongsToCurrentThread());
283 283
284 opus_multistream_decoder_ctl(opus_decoder_, OPUS_RESET_STATE); 284 opus_multistream_decoder_ctl(opus_decoder_, OPUS_RESET_STATE);
285 ResetTimestampState(); 285 ResetTimestampState();
286 task_runner_->PostTask(FROM_HERE, closure); 286 task_runner_->PostTask(FROM_HERE, closure);
287 } 287 }
288 288
289 void OpusAudioDecoder::Stop() { 289 void OpusAudioDecoder::Stop() {
290 DCHECK(task_runner_->BelongsToCurrentThread()); 290 DCHECK(task_runner_->BelongsToCurrentThread());
291 291
292 if (!opus_decoder_)
293 return;
294
292 opus_multistream_decoder_ctl(opus_decoder_, OPUS_RESET_STATE); 295 opus_multistream_decoder_ctl(opus_decoder_, OPUS_RESET_STATE);
293 ResetTimestampState(); 296 ResetTimestampState();
294 CloseDecoder(); 297 CloseDecoder();
295 } 298 }
296 299
297 OpusAudioDecoder::~OpusAudioDecoder() {} 300 OpusAudioDecoder::~OpusAudioDecoder() {}
298 301
299 void OpusAudioDecoder::DecodeBuffer( 302 void OpusAudioDecoder::DecodeBuffer(
300 const scoped_refptr<DecoderBuffer>& input, 303 const scoped_refptr<DecoderBuffer>& input,
301 const DecodeCB& decode_cb) { 304 const DecodeCB& decode_cb) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 return false; 394 return false;
392 395
393 if (config_.codec_delay() <= 0) { 396 if (config_.codec_delay() <= 0) {
394 DLOG(ERROR) << "Invalid file. Incorrect value for codec delay: " 397 DLOG(ERROR) << "Invalid file. Incorrect value for codec delay: "
395 << config_.codec_delay(); 398 << config_.codec_delay();
396 return false; 399 return false;
397 } 400 }
398 401
399 if (config_.codec_delay() != opus_extra_data.skip_samples) { 402 if (config_.codec_delay() != opus_extra_data.skip_samples) {
400 DLOG(ERROR) << "Invalid file. Codec Delay in container does not match the " 403 DLOG(ERROR) << "Invalid file. Codec Delay in container does not match the "
401 << "value in Opus Extra Data."; 404 << "value in Opus Extra Data. " << config_.codec_delay()
405 << " vs " << opus_extra_data.skip_samples;
402 return false; 406 return false;
403 } 407 }
404 408
405 uint8 channel_mapping[kMaxVorbisChannels] = {0}; 409 uint8 channel_mapping[kMaxVorbisChannels] = {0};
406 memcpy(&channel_mapping, 410 memcpy(&channel_mapping,
407 kDefaultOpusChannelLayout, 411 kDefaultOpusChannelLayout,
408 kMaxChannelsWithDefaultLayout); 412 kMaxChannelsWithDefaultLayout);
409 413
410 if (channel_count > kMaxChannelsWithDefaultLayout) { 414 if (channel_count > kMaxChannelsWithDefaultLayout) {
411 RemapOpusChannelLayout(opus_extra_data.stream_map, 415 RemapOpusChannelLayout(opus_extra_data.stream_map,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 << " timestamp: " << input->timestamp().InMicroseconds() 488 << " timestamp: " << input->timestamp().InMicroseconds()
485 << " us, duration: " << input->duration().InMicroseconds() 489 << " us, duration: " << input->duration().InMicroseconds()
486 << " us, packet size: " << input->data_size() << " bytes with" 490 << " us, packet size: " << input->data_size() << " bytes with"
487 << " status: " << opus_strerror(frames_decoded); 491 << " status: " << opus_strerror(frames_decoded);
488 return false; 492 return false;
489 } 493 }
490 494
491 if (output_timestamp_helper_->base_timestamp() == kNoTimestamp() && 495 if (output_timestamp_helper_->base_timestamp() == kNoTimestamp() &&
492 !input->end_of_stream()) { 496 !input->end_of_stream()) {
493 DCHECK(input->timestamp() != kNoTimestamp()); 497 DCHECK(input->timestamp() != kNoTimestamp());
494 // Adjust the timestamp helper so the base timestamp is corrected for frames
495 // dropped due to codec delay.
496 output_timestamp_helper_->SetBaseTimestamp(input->timestamp()); 498 output_timestamp_helper_->SetBaseTimestamp(input->timestamp());
497 output_timestamp_helper_->SetBaseTimestamp(
498 input->timestamp() -
499 output_timestamp_helper_->GetFrameDuration(config_.codec_delay()));
500 } 499 }
501 500
502 // Trim off any extraneous allocation. 501 // Trim off any extraneous allocation.
503 DCHECK_LE(frames_decoded, output_buffer->get()->frame_count()); 502 DCHECK_LE(frames_decoded, output_buffer->get()->frame_count());
504 const int trim_frames = output_buffer->get()->frame_count() - frames_decoded; 503 const int trim_frames = output_buffer->get()->frame_count() - frames_decoded;
505 if (trim_frames > 0) 504 if (trim_frames > 0)
506 output_buffer->get()->TrimEnd(trim_frames); 505 output_buffer->get()->TrimEnd(trim_frames);
507 506
508 // Handle frame discard and trimming. 507 // Handle frame discard and trimming.
509 int frames_to_output = frames_decoded; 508 int frames_to_output = frames_decoded;
(...skipping 28 matching lines...) Expand all
538 537
539 // Assign timestamp and duration to the buffer. 538 // Assign timestamp and duration to the buffer.
540 output_buffer->get()->set_timestamp(output_timestamp_helper_->GetTimestamp()); 539 output_buffer->get()->set_timestamp(output_timestamp_helper_->GetTimestamp());
541 output_buffer->get()->set_duration( 540 output_buffer->get()->set_duration(
542 output_timestamp_helper_->GetFrameDuration(frames_to_output)); 541 output_timestamp_helper_->GetFrameDuration(frames_to_output));
543 output_timestamp_helper_->AddFrames(frames_to_output); 542 output_timestamp_helper_->AddFrames(frames_to_output);
544 return true; 543 return true;
545 } 544 }
546 545
547 } // namespace media 546 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/audio_file_reader.cc ('k') | media/filters/opus_audio_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698