diff --git a/webrtc/modules/audio_coding/acm2/acm_receiver.cc b/webrtc/modules/audio_coding/acm2/acm_receiver.cc index 925e99c5d6..f8bacf8dc7 100644 --- a/webrtc/modules/audio_coding/acm2/acm_receiver.cc +++ b/webrtc/modules/audio_coding/acm2/acm_receiver.cc @@ -191,21 +191,6 @@ int AcmReceiver::GetAudio(int desired_freq_hz, AudioFrame* audio_frame) { audio_frame->num_channels_); call_stats_.DecodedByNetEq(audio_frame->speech_type_); - - // Computes the RTP timestamp of the first sample in |audio_frame| from - // |GetPlayoutTimestamp|, which is the timestamp of the last sample of - // |audio_frame|. - // TODO(henrik.lundin) Move setting of audio_frame->timestamp_ inside NetEq. - rtc::Optional playout_timestamp = GetPlayoutTimestamp(); - if (playout_timestamp) { - audio_frame->timestamp_ = - *playout_timestamp - - static_cast(audio_frame->samples_per_channel_); - } else { - // Remain 0 until we have a valid |playout_timestamp|. - audio_frame->timestamp_ = 0; - } - return 0; } diff --git a/webrtc/modules/audio_coding/acm2/acm_receiver_unittest_oldapi.cc b/webrtc/modules/audio_coding/acm2/acm_receiver_unittest_oldapi.cc index 969ff40bc2..c39a7cc797 100644 --- a/webrtc/modules/audio_coding/acm2/acm_receiver_unittest_oldapi.cc +++ b/webrtc/modules/audio_coding/acm2/acm_receiver_unittest_oldapi.cc @@ -326,6 +326,9 @@ class AcmReceiverTestFaxModeOldApi : public AcmReceiverTestOldApi { rtc::CheckedDivExact(5 * output_sample_rate_hz, 8000); AudioFrame frame; + EXPECT_EQ(0, receiver_->GetAudio(output_sample_rate_hz, &frame)); + // Expect timestamp = 0 before first packet is inserted. + EXPECT_EQ(0u, frame.timestamp_); for (int i = 0; i < 5; ++i) { InsertOnePacketOfSilence(codec.id); for (int k = 0; k < num_10ms_frames; ++k) { diff --git a/webrtc/modules/audio_coding/neteq/include/neteq.h b/webrtc/modules/audio_coding/neteq/include/neteq.h index 5b52424bee..89b0c54324 100644 --- a/webrtc/modules/audio_coding/neteq/include/neteq.h +++ b/webrtc/modules/audio_coding/neteq/include/neteq.h @@ -246,7 +246,7 @@ class NetEq { // Returns the RTP timestamp for the last sample delivered by GetAudio(). // The return value will be empty if no valid timestamp is available. - virtual rtc::Optional GetPlayoutTimestamp() = 0; + virtual rtc::Optional GetPlayoutTimestamp() const = 0; // Returns the sample rate in Hz of the audio produced in the last GetAudio // call. If GetAudio has not been called yet, the configured sample rate diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl.cc b/webrtc/modules/audio_coding/neteq/neteq_impl.cc index b4dfc9986d..40a031421e 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_impl.cc +++ b/webrtc/modules/audio_coding/neteq/neteq_impl.cc @@ -401,7 +401,7 @@ void NetEqImpl::DisableVad() { vad_->Disable(); } -rtc::Optional NetEqImpl::GetPlayoutTimestamp() { +rtc::Optional NetEqImpl::GetPlayoutTimestamp() const { rtc::CritScope lock(&crit_sect_); if (first_packet_) { // We don't have a valid RTP timestamp until we have decoded our first @@ -966,6 +966,15 @@ int NetEqImpl::GetAudioInternal(AudioFrame* audio_frame) { // Use dead reckoning to estimate the |playout_timestamp_|. playout_timestamp_ += static_cast(output_size_samples_); } + // Set the timestamp in the audio frame to zero before the first packet has + // been inserted. Otherwise, subtract the frame size in samples to get the + // timestamp of the first sample in the frame (playout_timestamp_ is the + // last + 1). + audio_frame->timestamp_ = + first_packet_ + ? 0 + : timestamp_scaler_->ToExternal(playout_timestamp_) - + static_cast(audio_frame->samples_per_channel_); if (decode_return_value) return decode_return_value; return return_value; diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl.h b/webrtc/modules/audio_coding/neteq/neteq_impl.h index 737efd46da..75055a7b47 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_impl.h +++ b/webrtc/modules/audio_coding/neteq/neteq_impl.h @@ -160,7 +160,7 @@ class NetEqImpl : public webrtc::NetEq { // Disables post-decode VAD. void DisableVad() override; - rtc::Optional GetPlayoutTimestamp() override; + rtc::Optional GetPlayoutTimestamp() const override; int last_output_sample_rate_hz() const override;