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}
This commit is contained in:
henrik.lundin
2016-08-31 03:14:11 -07:00
committed by Commit bot
parent 9e4a3040ed
commit da8bbf6e3c
7 changed files with 51 additions and 43 deletions

View File

@ -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<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,

View File

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

View File

@ -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<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.

View File

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

View File

@ -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<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();

View File

@ -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<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|.

View File

@ -174,16 +174,17 @@ TEST(PacketBuffer, InsertPacketList) {
}
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,
&current_pt,
&current_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 @@ TEST(PacketBuffer, InsertPacketListChangePayloadType) {
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,
&current_pt,
&current_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 @@ TEST(PacketBuffer, Reordering) {
}
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 @@ 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<uint8_t> current_pt;
rtc::Optional<uint8_t> current_cng_pt;
EXPECT_EQ(PacketBuffer::kInvalidPacket,
buffer->InsertPacketList(&list,
decoder_database,