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 6bb95901d8..ef6c97ed53 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 @@ class MockPacketBuffer : public PacketBuffer { 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* current_rtp_payload_type, + rtc::Optional* 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 78e3112184..8c36dd98ee 100644 --- a/webrtc/modules/audio_coding/neteq/neteq_impl.cc +++ b/webrtc/modules/audio_coding/neteq/neteq_impl.cc @@ -95,8 +95,6 @@ NetEqImpl::NetEqImpl(const NetEq::Config& config, 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 @@ int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header, << static_cast(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 @@ int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header, new_codec_ = true; } - RTC_DCHECK(current_rtp_payload_type_ == 0xFF || - decoder_database_->GetDecoderInfo(current_rtp_payload_type_)) - << "Payload type " << static_cast(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(*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 91770c5995..f2f6419eb1 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 @@ class NetEqImpl : public webrtc::NetEq { 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 current_rtp_payload_type_ GUARDED_BY(crit_sect_); + rtc::Optional 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 f6caca34f0..c74342bb84 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 @@ TEST_F(NetEqImplTest, InsertPacket) { .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(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 f1b898e34c..61cc9575d8 100644 --- a/webrtc/modules/audio_coding/neteq/packet_buffer.cc +++ b/webrtc/modules/audio_coding/neteq/packet_buffer.cc @@ -108,31 +108,34 @@ int PacketBuffer::InsertPacket(Packet* packet) { 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* current_rtp_payload_type, + rtc::Optional* 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(); Flush(); flushed = true; } - *current_cng_rtp_payload_type = packet->header.payloadType; + *current_cng_rtp_payload_type = + rtc::Optional(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(); Flush(); flushed = true; } - *current_rtp_payload_type = packet->header.payloadType; + *current_rtp_payload_type = + rtc::Optional(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 6867b4cb37..be2ecebaa3 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 @@ class PacketBuffer { // 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* current_rtp_payload_type, + rtc::Optional* 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 73dbd6203f..f1d2ad0046 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 @@ TEST(PacketBuffer, InsertPacketList) { } MockDecoderDatabase decoder_database; - uint8_t current_pt = 0xFF; - uint8_t current_cng_pt = 0xFF; + rtc::Optional current_pt; + rtc::Optional 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(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 @@ TEST(PacketBuffer, InsertPacketListChangePayloadType) { MockDecoderDatabase decoder_database; - uint8_t current_pt = 0xFF; - uint8_t current_cng_pt = 0xFF; + rtc::Optional current_pt; + rtc::Optional 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(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 @@ TEST(PacketBuffer, Reordering) { } MockDecoderDatabase decoder_database; - uint8_t current_pt = 0xFF; - uint8_t current_cng_pt = 0xFF; + rtc::Optional current_pt; + rtc::Optional current_cng_pt; EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list, decoder_database, @@ -412,8 +414,8 @@ TEST(PacketBuffer, Failures) { 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 current_pt; + rtc::Optional current_cng_pt; EXPECT_EQ(PacketBuffer::kInvalidPacket, buffer->InsertPacketList(&list, decoder_database,