Change NetEq::GetPlayoutTimestamp to return an rtc::Optional<uint32_t>
This is in preparation for changes to when the playout timestamp is
valid.
BUG=webrtc:5669
Review URL: https://codereview.webrtc.org/1853183002
Cr-Commit-Position: refs/heads/master@{#12256}
diff --git a/webrtc/modules/audio_coding/acm2/acm_receiver.cc b/webrtc/modules/audio_coding/acm2/acm_receiver.cc
index 5649f07..925e99c 100644
--- a/webrtc/modules/audio_coding/acm2/acm_receiver.cc
+++ b/webrtc/modules/audio_coding/acm2/acm_receiver.cc
@@ -196,9 +196,10 @@
// |GetPlayoutTimestamp|, which is the timestamp of the last sample of
// |audio_frame|.
// TODO(henrik.lundin) Move setting of audio_frame->timestamp_ inside NetEq.
- uint32_t playout_timestamp = 0;
- if (GetPlayoutTimestamp(&playout_timestamp)) {
- audio_frame->timestamp_ = playout_timestamp -
+ 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|.
@@ -318,8 +319,8 @@
return 0;
}
-bool AcmReceiver::GetPlayoutTimestamp(uint32_t* timestamp) {
- return neteq_->GetPlayoutTimestamp(timestamp);
+rtc::Optional<uint32_t> AcmReceiver::GetPlayoutTimestamp() {
+ return neteq_->GetPlayoutTimestamp();
}
int AcmReceiver::LastAudioCodec(CodecInst* codec) const {
diff --git a/webrtc/modules/audio_coding/acm2/acm_receiver.h b/webrtc/modules/audio_coding/acm2/acm_receiver.h
index 77eb563..6fec1ff 100644
--- a/webrtc/modules/audio_coding/acm2/acm_receiver.h
+++ b/webrtc/modules/audio_coding/acm2/acm_receiver.h
@@ -195,11 +195,9 @@
//
int RemoveAllCodecs();
- //
- // Gets the RTP timestamp of the last sample delivered by GetAudio().
- // Returns true if the RTP timestamp is valid, otherwise false.
- //
- bool GetPlayoutTimestamp(uint32_t* timestamp);
+ // Returns the RTP timestamp for the last sample delivered by GetAudio().
+ // The return value will be empty if no valid timestamp is available.
+ rtc::Optional<uint32_t> GetPlayoutTimestamp();
//
// Get the audio codec associated with the last non-CNG/non-DTMF received
diff --git a/webrtc/modules/audio_coding/acm2/audio_coding_module_impl.cc b/webrtc/modules/audio_coding/acm2/audio_coding_module_impl.cc
index d30daaa..254c2f4 100644
--- a/webrtc/modules/audio_coding/acm2/audio_coding_module_impl.cc
+++ b/webrtc/modules/audio_coding/acm2/audio_coding_module_impl.cc
@@ -902,8 +902,16 @@
return encoder_stack_->SetDtx(false) ? 0 : -1;
}
-int AudioCodingModuleImpl::PlayoutTimestamp(uint32_t* timestamp) {
- return receiver_.GetPlayoutTimestamp(timestamp) ? 0 : -1;
+int32_t AudioCodingModuleImpl::PlayoutTimestamp(uint32_t* timestamp) {
+ rtc::Optional<uint32_t> ts = PlayoutTimestamp();
+ if (!ts)
+ return -1;
+ *timestamp = *ts;
+ return 0;
+}
+
+rtc::Optional<uint32_t> AudioCodingModuleImpl::PlayoutTimestamp() {
+ return receiver_.GetPlayoutTimestamp();
}
bool AudioCodingModuleImpl::HaveValidEncoder(const char* caller_name) const {
diff --git a/webrtc/modules/audio_coding/acm2/audio_coding_module_impl.h b/webrtc/modules/audio_coding/acm2/audio_coding_module_impl.h
index e463d29..63dfb81 100644
--- a/webrtc/modules/audio_coding/acm2/audio_coding_module_impl.h
+++ b/webrtc/modules/audio_coding/acm2/audio_coding_module_impl.h
@@ -157,8 +157,9 @@
// Smallest latency NetEq will maintain.
int LeastRequiredDelayMs() const override;
- // Get playout timestamp.
- int PlayoutTimestamp(uint32_t* timestamp) override;
+ RTC_DEPRECATED int32_t PlayoutTimestamp(uint32_t* timestamp) override;
+
+ rtc::Optional<uint32_t> PlayoutTimestamp() override;
// Get 10 milliseconds of raw audio data to play out, and
// automatic resample to the requested frequency if > 0.