NetEq: Change member variables for current RTP types to rtc::Optionals
With this change, the value 0xFF is no longer used to flag that the RTP
type is unknown. Instead, an empty value for the rtc::Optional is used.
Review-Url: https://codereview.webrtc.org/2290153002
Cr-Commit-Position: refs/heads/master@{#13989}
diff --git a/webrtc/modules/audio_coding/neteq/mock/mock_packet_buffer.h b/webrtc/modules/audio_coding/neteq/mock/mock_packet_buffer.h
index 6bb9590..ef6c97e 100644
--- a/webrtc/modules/audio_coding/neteq/mock/mock_packet_buffer.h
+++ b/webrtc/modules/audio_coding/neteq/mock/mock_packet_buffer.h
@@ -32,8 +32,8 @@
MOCK_METHOD4(InsertPacketList,
int(PacketList* packet_list,
const DecoderDatabase& decoder_database,
- uint8_t* current_rtp_payload_type,
- uint8_t* current_cng_rtp_payload_type));
+ rtc::Optional<uint8_t>* current_rtp_payload_type,
+ rtc::Optional<uint8_t>* current_cng_rtp_payload_type));
MOCK_CONST_METHOD1(NextTimestamp,
int(uint32_t* next_timestamp));
MOCK_CONST_METHOD2(NextHigherTimestamp,
diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl.cc b/webrtc/modules/audio_coding/neteq/neteq_impl.cc
index 78e3112..8c36dd9 100644
--- a/webrtc/modules/audio_coding/neteq/neteq_impl.cc
+++ b/webrtc/modules/audio_coding/neteq/neteq_impl.cc
@@ -95,8 +95,6 @@
new_codec_(false),
timestamp_(0),
reset_decoder_(false),
- current_rtp_payload_type_(0xFF), // Invalid RTP payload type.
- current_cng_rtp_payload_type_(0xFF), // Invalid RTP payload type.
ssrc_(0),
first_packet_(true),
error_code_(0),
@@ -537,10 +535,10 @@
<< static_cast<int>(rtp_header.header.payloadType);
return kSyncPacketNotAccepted;
}
- if (first_packet_ ||
- rtp_header.header.payloadType != current_rtp_payload_type_ ||
+ if (first_packet_ || !current_rtp_payload_type_ ||
+ rtp_header.header.payloadType != *current_rtp_payload_type_ ||
rtp_header.header.ssrc != ssrc_) {
- // Even if |current_rtp_payload_type_| is 0xFF, sync-packet isn't
+ // Even if |current_rtp_payload_type_| is empty, sync-packet isn't
// accepted.
LOG_F(LS_ERROR)
<< "Changing codec, SSRC or first packet with sync-packet.";
@@ -743,10 +741,11 @@
new_codec_ = true;
}
- RTC_DCHECK(current_rtp_payload_type_ == 0xFF ||
- decoder_database_->GetDecoderInfo(current_rtp_payload_type_))
- << "Payload type " << static_cast<int>(current_rtp_payload_type_)
- << " is unknown where it shouldn't be";
+ if (current_rtp_payload_type_) {
+ RTC_DCHECK(decoder_database_->GetDecoderInfo(*current_rtp_payload_type_))
+ << "Payload type " << static_cast<int>(*current_rtp_payload_type_)
+ << " is unknown where it shouldn't be";
+ }
if (update_sample_rate_and_channels && !packet_buffer_->Empty()) {
// We do not use |current_rtp_payload_type_| to |set payload_type|, but
diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl.h b/webrtc/modules/audio_coding/neteq/neteq_impl.h
index 91770c5..f2f6419 100644
--- a/webrtc/modules/audio_coding/neteq/neteq_impl.h
+++ b/webrtc/modules/audio_coding/neteq/neteq_impl.h
@@ -16,6 +16,7 @@
#include "webrtc/base/constructormagic.h"
#include "webrtc/base/criticalsection.h"
+#include "webrtc/base/optional.h"
#include "webrtc/base/thread_annotations.h"
#include "webrtc/modules/audio_coding/neteq/audio_multi_vector.h"
#include "webrtc/modules/audio_coding/neteq/defines.h"
@@ -397,8 +398,8 @@
bool new_codec_ GUARDED_BY(crit_sect_);
uint32_t timestamp_ GUARDED_BY(crit_sect_);
bool reset_decoder_ GUARDED_BY(crit_sect_);
- uint8_t current_rtp_payload_type_ GUARDED_BY(crit_sect_);
- uint8_t current_cng_rtp_payload_type_ GUARDED_BY(crit_sect_);
+ rtc::Optional<uint8_t> current_rtp_payload_type_ GUARDED_BY(crit_sect_);
+ rtc::Optional<uint8_t> current_cng_rtp_payload_type_ GUARDED_BY(crit_sect_);
uint32_t ssrc_ GUARDED_BY(crit_sect_);
bool first_packet_ GUARDED_BY(crit_sect_);
int error_code_ GUARDED_BY(crit_sect_); // Store last error code.
diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc b/webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc
index f6caca3..c74342b 100644
--- a/webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc
+++ b/webrtc/modules/audio_coding/neteq/neteq_impl_unittest.cc
@@ -287,8 +287,9 @@
.Times(1);
EXPECT_CALL(*mock_packet_buffer_, InsertPacketList(_, _, _, _))
.Times(2)
- .WillRepeatedly(DoAll(SetArgPointee<2>(kPayloadType),
- WithArg<0>(Invoke(DeletePacketsAndReturnOk))));
+ .WillRepeatedly(
+ DoAll(SetArgPointee<2>(rtc::Optional<uint8_t>(kPayloadType)),
+ WithArg<0>(Invoke(DeletePacketsAndReturnOk))));
// SetArgPointee<2>(kPayloadType) means that the third argument (zero-based
// index) is a pointer, and the variable pointed to is set to kPayloadType.
// Also invoke the function DeletePacketsAndReturnOk to properly delete all
diff --git a/webrtc/modules/audio_coding/neteq/packet_buffer.cc b/webrtc/modules/audio_coding/neteq/packet_buffer.cc
index f1b898e..61cc957 100644
--- a/webrtc/modules/audio_coding/neteq/packet_buffer.cc
+++ b/webrtc/modules/audio_coding/neteq/packet_buffer.cc
@@ -108,31 +108,34 @@
return return_val;
}
-int PacketBuffer::InsertPacketList(PacketList* packet_list,
- const DecoderDatabase& decoder_database,
- uint8_t* current_rtp_payload_type,
- uint8_t* current_cng_rtp_payload_type) {
+int PacketBuffer::InsertPacketList(
+ PacketList* packet_list,
+ const DecoderDatabase& decoder_database,
+ rtc::Optional<uint8_t>* current_rtp_payload_type,
+ rtc::Optional<uint8_t>* current_cng_rtp_payload_type) {
bool flushed = false;
while (!packet_list->empty()) {
Packet* packet = packet_list->front();
if (decoder_database.IsComfortNoise(packet->header.payloadType)) {
- if (*current_cng_rtp_payload_type != 0xFF &&
- *current_cng_rtp_payload_type != packet->header.payloadType) {
+ if (*current_cng_rtp_payload_type &&
+ **current_cng_rtp_payload_type != packet->header.payloadType) {
// New CNG payload type implies new codec type.
- *current_rtp_payload_type = 0xFF;
+ *current_rtp_payload_type = rtc::Optional<uint8_t>();
Flush();
flushed = true;
}
- *current_cng_rtp_payload_type = packet->header.payloadType;
+ *current_cng_rtp_payload_type =
+ rtc::Optional<uint8_t>(packet->header.payloadType);
} else if (!decoder_database.IsDtmf(packet->header.payloadType)) {
// This must be speech.
- if (*current_rtp_payload_type != 0xFF &&
- *current_rtp_payload_type != packet->header.payloadType) {
- *current_cng_rtp_payload_type = 0xFF;
+ if (*current_rtp_payload_type &&
+ **current_rtp_payload_type != packet->header.payloadType) {
+ *current_cng_rtp_payload_type = rtc::Optional<uint8_t>();
Flush();
flushed = true;
}
- *current_rtp_payload_type = packet->header.payloadType;
+ *current_rtp_payload_type =
+ rtc::Optional<uint8_t>(packet->header.payloadType);
}
int return_val = InsertPacket(packet);
packet_list->pop_front();
diff --git a/webrtc/modules/audio_coding/neteq/packet_buffer.h b/webrtc/modules/audio_coding/neteq/packet_buffer.h
index 6867b4c..be2eceb 100644
--- a/webrtc/modules/audio_coding/neteq/packet_buffer.h
+++ b/webrtc/modules/audio_coding/neteq/packet_buffer.h
@@ -12,6 +12,7 @@
#define WEBRTC_MODULES_AUDIO_CODING_NETEQ_PACKET_BUFFER_H_
#include "webrtc/base/constructormagic.h"
+#include "webrtc/base/optional.h"
#include "webrtc/modules/audio_coding/neteq/packet.h"
#include "webrtc/typedefs.h"
@@ -59,10 +60,11 @@
// The last three parameters are included for legacy compatibility.
// TODO(hlundin): Redesign to not use current_*_payload_type and
// decoder_database.
- virtual int InsertPacketList(PacketList* packet_list,
- const DecoderDatabase& decoder_database,
- uint8_t* current_rtp_payload_type,
- uint8_t* current_cng_rtp_payload_type);
+ virtual int InsertPacketList(
+ PacketList* packet_list,
+ const DecoderDatabase& decoder_database,
+ rtc::Optional<uint8_t>* current_rtp_payload_type,
+ rtc::Optional<uint8_t>* current_cng_rtp_payload_type);
// Gets the timestamp for the first packet in the buffer and writes it to the
// output variable |next_timestamp|.
diff --git a/webrtc/modules/audio_coding/neteq/packet_buffer_unittest.cc b/webrtc/modules/audio_coding/neteq/packet_buffer_unittest.cc
index 73dbd62..f1d2ad0 100644
--- a/webrtc/modules/audio_coding/neteq/packet_buffer_unittest.cc
+++ b/webrtc/modules/audio_coding/neteq/packet_buffer_unittest.cc
@@ -174,16 +174,17 @@
}
MockDecoderDatabase decoder_database;
- uint8_t current_pt = 0xFF;
- uint8_t current_cng_pt = 0xFF;
+ rtc::Optional<uint8_t> current_pt;
+ rtc::Optional<uint8_t> current_cng_pt;
EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list,
decoder_database,
¤t_pt,
¤t_cng_pt));
EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list.
EXPECT_EQ(10u, buffer.NumPacketsInBuffer());
- EXPECT_EQ(0, current_pt); // Current payload type changed to 0.
- EXPECT_EQ(0xFF, current_cng_pt); // CNG payload type not changed.
+ EXPECT_EQ(rtc::Optional<uint8_t>(0),
+ current_pt); // Current payload type changed to 0.
+ EXPECT_FALSE(current_cng_pt); // CNG payload type not changed.
buffer.Flush(); // Clean up.
@@ -212,16 +213,17 @@
MockDecoderDatabase decoder_database;
- uint8_t current_pt = 0xFF;
- uint8_t current_cng_pt = 0xFF;
+ rtc::Optional<uint8_t> current_pt;
+ rtc::Optional<uint8_t> current_cng_pt;
EXPECT_EQ(PacketBuffer::kFlushed, buffer.InsertPacketList(&list,
decoder_database,
¤t_pt,
¤t_cng_pt));
EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list.
EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); // Only the last packet.
- EXPECT_EQ(1, current_pt); // Current payload type changed to 0.
- EXPECT_EQ(0xFF, current_cng_pt); // CNG payload type not changed.
+ EXPECT_EQ(rtc::Optional<uint8_t>(1),
+ current_pt); // Current payload type changed to 1.
+ EXPECT_FALSE(current_cng_pt); // CNG payload type not changed.
buffer.Flush(); // Clean up.
@@ -341,8 +343,8 @@
}
MockDecoderDatabase decoder_database;
- uint8_t current_pt = 0xFF;
- uint8_t current_cng_pt = 0xFF;
+ rtc::Optional<uint8_t> current_pt;
+ rtc::Optional<uint8_t> current_cng_pt;
EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list,
decoder_database,
@@ -412,8 +414,8 @@
list.push_back(packet);
list.push_back(gen.NextPacket(payload_len)); // Valid packet.
MockDecoderDatabase decoder_database;
- uint8_t current_pt = 0xFF;
- uint8_t current_cng_pt = 0xFF;
+ rtc::Optional<uint8_t> current_pt;
+ rtc::Optional<uint8_t> current_cng_pt;
EXPECT_EQ(PacketBuffer::kInvalidPacket,
buffer->InsertPacketList(&list,
decoder_database,