Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 AudioCodingModuleImpl::~AudioCodingModuleImpl() = default; | 465 AudioCodingModuleImpl::~AudioCodingModuleImpl() = default; |
| 466 | 466 |
| 467 int32_t AudioCodingModuleImpl::Encode(const InputData& input_data) { | 467 int32_t AudioCodingModuleImpl::Encode(const InputData& input_data) { |
| 468 AudioEncoder::EncodedInfo encoded_info; | 468 AudioEncoder::EncodedInfo encoded_info; |
| 469 uint8_t previous_pltype; | 469 uint8_t previous_pltype; |
| 470 | 470 |
| 471 // Check if there is an encoder before. | 471 // Check if there is an encoder before. |
| 472 if (!HaveValidEncoder("Process")) | 472 if (!HaveValidEncoder("Process")) |
| 473 return -1; | 473 return -1; |
| 474 | 474 |
| 475 if(!first_frame_) { | |
| 476 RTC_DCHECK_GT(input_data.input_timestamp, last_timestamp_) | |
| 477 << "Time should not move backwards"; | |
| 478 } | |
| 479 | |
| 475 // Scale the timestamp to the codec's RTP timestamp rate. | 480 // Scale the timestamp to the codec's RTP timestamp rate. |
| 476 uint32_t rtp_timestamp = | 481 uint32_t rtp_timestamp = |
| 477 first_frame_ ? input_data.input_timestamp | 482 first_frame_ ? input_data.input_timestamp |
|
ossu
2016/07/06 08:38:56
Here is where the output timestamp gets adjusted i
| |
| 478 : last_rtp_timestamp_ + | 483 : last_rtp_timestamp_ + |
| 479 rtc::CheckedDivExact( | 484 rtc::CheckedDivExact( |
| 480 input_data.input_timestamp - last_timestamp_, | 485 input_data.input_timestamp - last_timestamp_, |
| 481 static_cast<uint32_t>(rtc::CheckedDivExact( | 486 static_cast<uint32_t>(rtc::CheckedDivExact( |
| 482 encoder_stack_->SampleRateHz(), | 487 encoder_stack_->SampleRateHz(), |
| 483 encoder_stack_->RtpTimestampRateHz()))); | 488 encoder_stack_->RtpTimestampRateHz()))); |
| 484 last_timestamp_ = input_data.input_timestamp; | 489 last_timestamp_ = input_data.input_timestamp; |
| 485 last_rtp_timestamp_ = rtp_timestamp; | 490 last_rtp_timestamp_ = rtp_timestamp; |
| 486 first_frame_ = false; | 491 first_frame_ = false; |
| 487 | 492 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 745 // TODO(henrik.lundin): This condition should probably be | 750 // TODO(henrik.lundin): This condition should probably be |
| 746 // in_frame.num_channels_ > encoder_stack_->NumChannels() | 751 // in_frame.num_channels_ > encoder_stack_->NumChannels() |
| 747 const bool down_mix = | 752 const bool down_mix = |
| 748 in_frame.num_channels_ == 2 && encoder_stack_->NumChannels() == 1; | 753 in_frame.num_channels_ == 2 && encoder_stack_->NumChannels() == 1; |
| 749 | 754 |
| 750 if (!first_10ms_data_) { | 755 if (!first_10ms_data_) { |
| 751 expected_in_ts_ = in_frame.timestamp_; | 756 expected_in_ts_ = in_frame.timestamp_; |
| 752 expected_codec_ts_ = in_frame.timestamp_; | 757 expected_codec_ts_ = in_frame.timestamp_; |
| 753 first_10ms_data_ = true; | 758 first_10ms_data_ = true; |
| 754 } else if (in_frame.timestamp_ != expected_in_ts_) { | 759 } else if (in_frame.timestamp_ != expected_in_ts_) { |
| 755 // TODO(turajs): Do we need a warning here. | 760 LOG(LS_WARNING) << "Unexpected input timestamp: " << in_frame.timestamp_ |
|
ossu
2016/07/05 16:39:04
Probably.
| |
| 761 << ", expected: " << expected_in_ts_; | |
|
tlegrand-webrtc
2016/07/06 08:25:44
Will we only end up here once in the case the code
ossu
2016/07/06 08:38:56
This shouldn't happen when the codec changes. In f
| |
| 756 expected_codec_ts_ += | 762 expected_codec_ts_ += |
| 757 (in_frame.timestamp_ - expected_in_ts_) * | 763 (in_frame.timestamp_ - expected_in_ts_) * |
| 758 static_cast<uint32_t>( | 764 static_cast<uint32_t>( |
| 759 static_cast<double>(encoder_stack_->SampleRateHz()) / | 765 static_cast<double>(encoder_stack_->SampleRateHz()) / |
| 760 static_cast<double>(in_frame.sample_rate_hz_)); | 766 static_cast<double>(in_frame.sample_rate_hz_)); |
| 761 expected_in_ts_ = in_frame.timestamp_; | 767 expected_in_ts_ = in_frame.timestamp_; |
| 762 } | 768 } |
| 763 | 769 |
| 764 | 770 |
| 765 if (!down_mix && !resample) { | 771 if (!down_mix && !resample) { |
| 766 // No pre-processing is required. | 772 // No pre-processing is required. |
| 773 if (expected_in_ts_ == expected_codec_ts_) { | |
| 774 // If we've never resampled, we can use the input frame as-is | |
| 775 *ptr_out = &in_frame; | |
| 776 } else { | |
| 777 // Otherwise we'll need to alter the timestamp. Since in_frame is const, | |
| 778 // we'll have to make a copy of it. | |
| 779 preprocess_frame_.CopyFrom(in_frame); | |
| 780 preprocess_frame_.timestamp_ = expected_codec_ts_; | |
| 781 *ptr_out = &preprocess_frame_; | |
| 782 } | |
| 783 | |
| 767 expected_in_ts_ += static_cast<uint32_t>(in_frame.samples_per_channel_); | 784 expected_in_ts_ += static_cast<uint32_t>(in_frame.samples_per_channel_); |
| 768 expected_codec_ts_ += static_cast<uint32_t>(in_frame.samples_per_channel_); | 785 expected_codec_ts_ += static_cast<uint32_t>(in_frame.samples_per_channel_); |
| 769 *ptr_out = &in_frame; | |
| 770 return 0; | 786 return 0; |
| 771 } | 787 } |
| 772 | 788 |
| 773 *ptr_out = &preprocess_frame_; | 789 *ptr_out = &preprocess_frame_; |
| 774 preprocess_frame_.num_channels_ = in_frame.num_channels_; | 790 preprocess_frame_.num_channels_ = in_frame.num_channels_; |
| 775 int16_t audio[WEBRTC_10MS_PCM_AUDIO]; | 791 int16_t audio[WEBRTC_10MS_PCM_AUDIO]; |
| 776 const int16_t* src_ptr_audio = in_frame.data_; | 792 const int16_t* src_ptr_audio = in_frame.data_; |
| 777 int16_t* dest_ptr_audio = preprocess_frame_.data_; | 793 int16_t* dest_ptr_audio = preprocess_frame_.data_; |
| 778 if (down_mix) { | 794 if (down_mix) { |
| 779 // If a resampling is required the output of a down-mix is written into a | 795 // If a resampling is required the output of a down-mix is written into a |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1317 // Checks the validity of the parameters of the given codec | 1333 // Checks the validity of the parameters of the given codec |
| 1318 bool AudioCodingModule::IsCodecValid(const CodecInst& codec) { | 1334 bool AudioCodingModule::IsCodecValid(const CodecInst& codec) { |
| 1319 bool valid = acm2::RentACodec::IsCodecValid(codec); | 1335 bool valid = acm2::RentACodec::IsCodecValid(codec); |
| 1320 if (!valid) | 1336 if (!valid) |
| 1321 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, -1, | 1337 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, -1, |
| 1322 "Invalid codec setting"); | 1338 "Invalid codec setting"); |
| 1323 return valid; | 1339 return valid; |
| 1324 } | 1340 } |
| 1325 | 1341 |
| 1326 } // namespace webrtc | 1342 } // namespace webrtc |
| OLD | NEW |