Move setting of AudioFrame::timestamp_ into NetEq

This was previously done in AcmReceiver, but belongs in NetEq where the
rest of the AudioFrame fields are populated.

BUG=webrtc:5669,webrtc:5607

Review URL: https://codereview.webrtc.org/1863993002

Cr-Commit-Position: refs/heads/master@{#12265}
This commit is contained in:
henrik.lundin 2016-04-06 08:38:56 -07:00 committed by Commit bot
parent d31b664a6c
commit 15c51e355f
5 changed files with 15 additions and 18 deletions

View File

@ -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<uint32_t> playout_timestamp = GetPlayoutTimestamp();
if (playout_timestamp) {
audio_frame->timestamp_ =
*playout_timestamp -
static_cast<uint32_t>(audio_frame->samples_per_channel_);
} else {
// Remain 0 until we have a valid |playout_timestamp|.
audio_frame->timestamp_ = 0;
}
return 0;
}

View File

@ -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) {

View File

@ -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<uint32_t> GetPlayoutTimestamp() = 0;
virtual rtc::Optional<uint32_t> 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

View File

@ -401,7 +401,7 @@ void NetEqImpl::DisableVad() {
vad_->Disable();
}
rtc::Optional<uint32_t> NetEqImpl::GetPlayoutTimestamp() {
rtc::Optional<uint32_t> 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<uint32_t>(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<uint32_t>(audio_frame->samples_per_channel_);
if (decode_return_value) return decode_return_value;
return return_value;

View File

@ -160,7 +160,7 @@ class NetEqImpl : public webrtc::NetEq {
// Disables post-decode VAD.
void DisableVad() override;
rtc::Optional<uint32_t> GetPlayoutTimestamp() override;
rtc::Optional<uint32_t> GetPlayoutTimestamp() const override;
int last_output_sample_rate_hz() const override;