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

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

Issue 251583003: Ensure DiscardPadding is parsed as a signed integer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase on top of test disable. Created 6 years, 7 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 | « no previous file | media/filters/pipeline_integration_test.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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 << " timestamp: " << input->timestamp().InMicroseconds() 484 << " timestamp: " << input->timestamp().InMicroseconds()
485 << " us, duration: " << input->duration().InMicroseconds() 485 << " us, duration: " << input->duration().InMicroseconds()
486 << " us, packet size: " << input->data_size() << " bytes with" 486 << " us, packet size: " << input->data_size() << " bytes with"
487 << " status: " << opus_strerror(frames_decoded); 487 << " status: " << opus_strerror(frames_decoded);
488 return false; 488 return false;
489 } 489 }
490 490
491 if (output_timestamp_helper_->base_timestamp() == kNoTimestamp() && 491 if (output_timestamp_helper_->base_timestamp() == kNoTimestamp() &&
492 !input->end_of_stream()) { 492 !input->end_of_stream()) {
493 DCHECK(input->timestamp() != kNoTimestamp()); 493 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()); 494 output_timestamp_helper_->SetBaseTimestamp(input->timestamp());
497 output_timestamp_helper_->SetBaseTimestamp(
498 input->timestamp() -
499 output_timestamp_helper_->GetFrameDuration(config_.codec_delay()));
500 } 495 }
501 496
502 // Trim off any extraneous allocation. 497 // Trim off any extraneous allocation.
503 DCHECK_LE(frames_decoded, output_buffer->get()->frame_count()); 498 DCHECK_LE(frames_decoded, output_buffer->get()->frame_count());
504 const int trim_frames = output_buffer->get()->frame_count() - frames_decoded; 499 const int trim_frames = output_buffer->get()->frame_count() - frames_decoded;
505 if (trim_frames > 0) 500 if (trim_frames > 0)
506 output_buffer->get()->TrimEnd(trim_frames); 501 output_buffer->get()->TrimEnd(trim_frames);
507 502
508 // Handle frame discard and trimming. 503 // Handle frame discard and trimming.
509 int frames_to_output = frames_decoded; 504 int frames_to_output = frames_decoded;
510 if (frames_decoded > frames_to_discard_) { 505 if (frames_decoded > frames_to_discard_) {
511 if (frames_to_discard_ > 0) { 506 if (frames_to_discard_ > 0) {
512 output_buffer->get()->TrimStart(frames_to_discard_); 507 output_buffer->get()->TrimStart(frames_to_discard_);
513 frames_to_output -= frames_to_discard_; 508 frames_to_output -= frames_to_discard_;
514 frames_to_discard_ = 0; 509 frames_to_discard_ = 0;
515 } 510 }
516 if (input->discard_padding().InMicroseconds() > 0) { 511 if (input->discard_padding().InMicroseconds() > 0) {
517 int discard_padding = TimeDeltaToAudioFrames( 512 int discard_padding = TimeDeltaToAudioFrames(
518 input->discard_padding(), config_.samples_per_second()); 513 input->discard_padding(), config_.samples_per_second());
519 if (discard_padding < 0 || discard_padding > frames_to_output) { 514 if (discard_padding < 0 || discard_padding > frames_to_output) {
520 DVLOG(1) << "Invalid file. Incorrect discard padding value."; 515 DVLOG(1) << "Invalid file. Incorrect discard padding value.";
521 return false; 516 return false;
522 } 517 }
523 output_buffer->get()->TrimEnd(discard_padding); 518 output_buffer->get()->TrimEnd(discard_padding);
524 frames_to_output -= discard_padding; 519 frames_to_output -= discard_padding;
520 } else {
521 DCHECK_EQ(input->discard_padding().InMicroseconds(), 0);
525 } 522 }
526 } else { 523 } else {
527 frames_to_discard_ -= frames_to_output; 524 frames_to_discard_ -= frames_to_output;
528 frames_to_output = 0; 525 frames_to_output = 0;
529 } 526 }
530 527
531 // Assign timestamp and duration to the buffer. 528 // Assign timestamp and duration to the buffer.
532 output_buffer->get()->set_timestamp(output_timestamp_helper_->GetTimestamp()); 529 output_buffer->get()->set_timestamp(output_timestamp_helper_->GetTimestamp());
533 output_buffer->get()->set_duration( 530 output_buffer->get()->set_duration(
534 output_timestamp_helper_->GetFrameDuration(frames_to_output)); 531 output_timestamp_helper_->GetFrameDuration(frames_to_output));
535 output_timestamp_helper_->AddFrames(frames_decoded); 532 output_timestamp_helper_->AddFrames(frames_decoded);
acolwell GONE FROM CHROMIUM 2014/04/25 00:06:05 Shouldn't this be frames_to_output?
DaleCurtis 2014/04/25 00:22:10 Whoops, yes.
536 533
537 // Discard the buffer to indicate we need more data. 534 // Discard the buffer to indicate we need more data.
538 if (!frames_to_output) 535 if (!frames_to_output)
539 *output_buffer = NULL; 536 *output_buffer = NULL;
acolwell GONE FROM CHROMIUM 2014/04/25 00:06:05 Move this above the output_buffer timestamps setup
DaleCurtis 2014/04/25 00:22:10 Done.
540 537
541 return true; 538 return true;
542 } 539 }
543 540
544 } // namespace media 541 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/filters/pipeline_integration_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698