diff options
author | Torne (Richard Coles) <torne@google.com> | 2014-11-12 00:42:03 +0000 |
---|---|---|
committer | Torne (Richard Coles) <torne@google.com> | 2014-11-12 00:42:03 +0000 |
commit | 361320edab39c39820a61c753b14555c603423a7 (patch) | |
tree | 32949f5ca19925bf1049834f417a80d9462d0b95 | |
parent | 01a30f2a2c6542ec84470d4262a80865ec01e297 (diff) | |
parent | 60ab669c4c545b328b5c8b0453eb2cdecf851651 (diff) | |
download | webrtc-361320edab39c39820a61c753b14555c603423a7.tar.gz |
Merge third_party/webrtc from https://chromium.googlesource.com/external/webrtc/trunk/webrtc.git at 60ab669c4c545b328b5c8b0453eb2cdecf851651
This commit was generated by merge_from_chromium.py.
Change-Id: I7efe0f9a490c88eb3ec522902a351f9662e8753e
35 files changed, 471 insertions, 375 deletions
diff --git a/base/helpers.cc b/base/helpers.cc index 8b14cdfd..84d1c93b 100644 --- a/base/helpers.cc +++ b/base/helpers.cc @@ -47,36 +47,17 @@ class RandomGenerator { }; #if defined(SSL_USE_OPENSSL) -// The OpenSSL RNG. Need to make sure it doesn't run out of entropy. +// The OpenSSL RNG. class SecureRandomGenerator : public RandomGenerator { public: - SecureRandomGenerator() : inited_(false) { - } - ~SecureRandomGenerator() { - } + SecureRandomGenerator() {} + ~SecureRandomGenerator() {} virtual bool Init(const void* seed, size_t len) { - // By default, seed from the system state. - if (!inited_) { - if (RAND_poll() <= 0) { - return false; - } - inited_ = true; - } - // Allow app data to be mixed in, if provided. - if (seed) { - RAND_seed(seed, len); - } return true; } virtual bool Generate(void* buf, size_t len) { - if (!inited_ && !Init(NULL, 0)) { - return false; - } return (RAND_bytes(reinterpret_cast<unsigned char*>(buf), len) > 0); } - - private: - bool inited_; }; #elif defined(SSL_USE_NSS_RNG) diff --git a/base/openssladapter.cc b/base/openssladapter.cc index 68a1fcb1..feb01d36 100644 --- a/base/openssladapter.cc +++ b/base/openssladapter.cc @@ -34,6 +34,7 @@ #include "webrtc/base/common.h" #include "webrtc/base/logging.h" #include "webrtc/base/openssl.h" +#include "webrtc/base/safe_conversions.h" #include "webrtc/base/sslroots.h" #include "webrtc/base/stringutils.h" @@ -141,7 +142,7 @@ static int socket_write(BIO* b, const char* in, int inl) { } static int socket_puts(BIO* b, const char* str) { - return socket_write(b, str, strlen(str)); + return socket_write(b, str, rtc::checked_cast<int>(strlen(str))); } static long socket_ctrl(BIO* b, int cmd, long num, void* ptr) { @@ -448,7 +449,7 @@ OpenSSLAdapter::Send(const void* pv, size_t cb) { ssl_write_needs_read_ = false; - int code = SSL_write(ssl_, pv, cb); + int code = SSL_write(ssl_, pv, checked_cast<int>(cb)); switch (SSL_get_error(ssl_, code)) { case SSL_ERROR_NONE: //LOG(LS_INFO) << " -- success"; @@ -503,7 +504,7 @@ OpenSSLAdapter::Recv(void* pv, size_t cb) { ssl_read_needs_write_ = false; - int code = SSL_read(ssl_, pv, cb); + int code = SSL_read(ssl_, pv, checked_cast<int>(cb)); switch (SSL_get_error(ssl_, code)) { case SSL_ERROR_NONE: //LOG(LS_INFO) << " -- success"; @@ -843,7 +844,8 @@ bool OpenSSLAdapter::ConfigureTrustedRootCertificates(SSL_CTX* ctx) { for (int i = 0; i < ARRAY_SIZE(kSSLCertCertificateList); i++) { const unsigned char* cert_buffer = kSSLCertCertificateList[i]; size_t cert_buffer_len = kSSLCertCertificateSizeList[i]; - X509* cert = d2i_X509(NULL, &cert_buffer, cert_buffer_len); + X509* cert = d2i_X509(NULL, &cert_buffer, + checked_cast<long>(cert_buffer_len)); if (cert) { int return_value = X509_STORE_add_cert(SSL_CTX_get_cert_store(ctx), cert); if (return_value == 0) { diff --git a/base/opensslstreamadapter.cc b/base/opensslstreamadapter.cc index 133eb72b..d790e4e8 100644 --- a/base/opensslstreamadapter.cc +++ b/base/opensslstreamadapter.cc @@ -26,6 +26,7 @@ #include "webrtc/base/common.h" #include "webrtc/base/logging.h" +#include "webrtc/base/safe_conversions.h" #include "webrtc/base/stream.h" #include "webrtc/base/openssl.h" #include "webrtc/base/openssladapter.h" @@ -114,7 +115,7 @@ static int stream_read(BIO* b, char* out, int outl) { int error; StreamResult result = stream->Read(out, outl, &read, &error); if (result == SR_SUCCESS) { - return read; + return checked_cast<int>(read); } else if (result == SR_EOS) { b->num = 1; } else if (result == SR_BLOCK) { @@ -132,7 +133,7 @@ static int stream_write(BIO* b, const char* in, int inl) { int error; StreamResult result = stream->Write(in, inl, &written, &error); if (result == SR_SUCCESS) { - return written; + return checked_cast<int>(written); } else if (result == SR_BLOCK) { BIO_set_retry_write(b); } @@ -140,7 +141,7 @@ static int stream_write(BIO* b, const char* in, int inl) { } static int stream_puts(BIO* b, const char* str) { - return stream_write(b, str, strlen(str)); + return stream_write(b, str, checked_cast<int>(strlen(str))); } static long stream_ctrl(BIO* b, int cmd, long num, void* ptr) { @@ -364,7 +365,7 @@ StreamResult OpenSSLStreamAdapter::Write(const void* data, size_t data_len, ssl_write_needs_read_ = false; - int code = SSL_write(ssl_, data, data_len); + int code = SSL_write(ssl_, data, checked_cast<int>(data_len)); int ssl_error = SSL_get_error(ssl_, code); switch (ssl_error) { case SSL_ERROR_NONE: @@ -425,7 +426,7 @@ StreamResult OpenSSLStreamAdapter::Read(void* data, size_t data_len, ssl_read_needs_write_ = false; - int code = SSL_read(ssl_, data, data_len); + int code = SSL_read(ssl_, data, checked_cast<int>(data_len)); int ssl_error = SSL_get_error(ssl_, code); switch (ssl_error) { case SSL_ERROR_NONE: diff --git a/base/safe_conversions_impl.h b/base/safe_conversions_impl.h index 2950f970..77b053a8 100644 --- a/base/safe_conversions_impl.h +++ b/base/safe_conversions_impl.h @@ -15,6 +15,8 @@ #include <limits> +#include "webrtc/base/compile_assert.h" + namespace rtc { namespace internal { @@ -39,13 +39,13 @@ std::string VideoStream::ToString() const { ss << ", max_bitrate_bps:" << max_bitrate_bps; ss << ", max_qp: " << max_qp; - ss << ", temporal_layer_thresholds_bps: {"; + ss << ", temporal_layer_thresholds_bps: ["; for (size_t i = 0; i < temporal_layer_thresholds_bps.size(); ++i) { ss << temporal_layer_thresholds_bps[i]; if (i != temporal_layer_thresholds_bps.size() - 1) - ss << "}, {"; + ss << ", "; } - ss << '}'; + ss << ']'; ss << '}'; return ss.str(); @@ -54,13 +54,13 @@ std::string VideoStream::ToString() const { std::string VideoEncoderConfig::ToString() const { std::stringstream ss; - ss << "{streams: {"; + ss << "{streams: ["; for (size_t i = 0; i < streams.size(); ++i) { ss << streams[i].ToString(); if (i != streams.size() - 1) - ss << "}, {"; + ss << ", "; } - ss << '}'; + ss << ']'; ss << ", content_type: "; switch (content_type) { case kRealtimeVideo: diff --git a/modules/audio_coding/main/acm2/acm_isac.cc b/modules/audio_coding/main/acm2/acm_isac.cc index bc20c961..8fa96e50 100644 --- a/modules/audio_coding/main/acm2/acm_isac.cc +++ b/modules/audio_coding/main/acm2/acm_isac.cc @@ -277,7 +277,6 @@ ACMISAC::ACMISAC(int16_t codec_id) return; } codec_inst_ptr_->inst = NULL; - state_ = codec_inst_ptr_; } ACMISAC::~ACMISAC() { diff --git a/modules/audio_coding/neteq/audio_decoder.cc b/modules/audio_coding/neteq/audio_decoder.cc index 04a74eef..d5a27628 100644 --- a/modules/audio_coding/neteq/audio_decoder.cc +++ b/modules/audio_coding/neteq/audio_decoder.cc @@ -12,6 +12,7 @@ #include <assert.h> +#include "webrtc/base/checks.h" #include "webrtc/modules/audio_coding/neteq/audio_decoder_impl.h" namespace webrtc { @@ -51,6 +52,11 @@ bool AudioDecoder::PacketHasFec(const uint8_t* encoded, return false; } +CNG_dec_inst* AudioDecoder::CngDecoderInstance() { + FATAL() << "Not a CNG decoder"; + return NULL; +} + bool AudioDecoder::CodecSupported(NetEqDecoder codec_type) { switch (codec_type) { case kDecoderPCMu: diff --git a/modules/audio_coding/neteq/audio_decoder_impl.cc b/modules/audio_coding/neteq/audio_decoder_impl.cc index 07b1b4be..eb078234 100644 --- a/modules/audio_coding/neteq/audio_decoder_impl.cc +++ b/modules/audio_coding/neteq/audio_decoder_impl.cc @@ -103,17 +103,17 @@ AudioDecoderPcm16BMultiCh::AudioDecoderPcm16BMultiCh(int num_channels) { // iLBC #ifdef WEBRTC_CODEC_ILBC AudioDecoderIlbc::AudioDecoderIlbc() { - WebRtcIlbcfix_DecoderCreate(reinterpret_cast<iLBC_decinst_t**>(&state_)); + WebRtcIlbcfix_DecoderCreate(&dec_state_); } AudioDecoderIlbc::~AudioDecoderIlbc() { - WebRtcIlbcfix_DecoderFree(static_cast<iLBC_decinst_t*>(state_)); + WebRtcIlbcfix_DecoderFree(dec_state_); } int AudioDecoderIlbc::Decode(const uint8_t* encoded, size_t encoded_len, int16_t* decoded, SpeechType* speech_type) { int16_t temp_type = 1; // Default is speech. - int16_t ret = WebRtcIlbcfix_Decode(static_cast<iLBC_decinst_t*>(state_), + int16_t ret = WebRtcIlbcfix_Decode(dec_state_, reinterpret_cast<const int16_t*>(encoded), static_cast<int16_t>(encoded_len), decoded, &temp_type); @@ -122,12 +122,11 @@ int AudioDecoderIlbc::Decode(const uint8_t* encoded, size_t encoded_len, } int AudioDecoderIlbc::DecodePlc(int num_frames, int16_t* decoded) { - return WebRtcIlbcfix_NetEqPlc(static_cast<iLBC_decinst_t*>(state_), - decoded, num_frames); + return WebRtcIlbcfix_NetEqPlc(dec_state_, decoded, num_frames); } int AudioDecoderIlbc::Init() { - return WebRtcIlbcfix_Decoderinit30Ms(static_cast<iLBC_decinst_t*>(state_)); + return WebRtcIlbcfix_Decoderinit30Ms(dec_state_); } #endif @@ -135,19 +134,18 @@ int AudioDecoderIlbc::Init() { #ifdef WEBRTC_CODEC_ISAC AudioDecoderIsac::AudioDecoderIsac(int decode_sample_rate_hz) { DCHECK(decode_sample_rate_hz == 16000 || decode_sample_rate_hz == 32000); - WebRtcIsac_Create(reinterpret_cast<ISACStruct**>(&state_)); - WebRtcIsac_SetDecSampRate(static_cast<ISACStruct*>(state_), - decode_sample_rate_hz); + WebRtcIsac_Create(&isac_state_); + WebRtcIsac_SetDecSampRate(isac_state_, decode_sample_rate_hz); } AudioDecoderIsac::~AudioDecoderIsac() { - WebRtcIsac_Free(static_cast<ISACStruct*>(state_)); + WebRtcIsac_Free(isac_state_); } int AudioDecoderIsac::Decode(const uint8_t* encoded, size_t encoded_len, int16_t* decoded, SpeechType* speech_type) { int16_t temp_type = 1; // Default is speech. - int16_t ret = WebRtcIsac_Decode(static_cast<ISACStruct*>(state_), + int16_t ret = WebRtcIsac_Decode(isac_state_, encoded, static_cast<int16_t>(encoded_len), decoded, &temp_type); @@ -159,7 +157,7 @@ int AudioDecoderIsac::DecodeRedundant(const uint8_t* encoded, size_t encoded_len, int16_t* decoded, SpeechType* speech_type) { int16_t temp_type = 1; // Default is speech. - int16_t ret = WebRtcIsac_DecodeRcu(static_cast<ISACStruct*>(state_), + int16_t ret = WebRtcIsac_DecodeRcu(isac_state_, encoded, static_cast<int16_t>(encoded_len), decoded, &temp_type); @@ -168,12 +166,11 @@ int AudioDecoderIsac::DecodeRedundant(const uint8_t* encoded, } int AudioDecoderIsac::DecodePlc(int num_frames, int16_t* decoded) { - return WebRtcIsac_DecodePlc(static_cast<ISACStruct*>(state_), - decoded, num_frames); + return WebRtcIsac_DecodePlc(isac_state_, decoded, num_frames); } int AudioDecoderIsac::Init() { - return WebRtcIsac_DecoderInit(static_cast<ISACStruct*>(state_)); + return WebRtcIsac_DecoderInit(isac_state_); } int AudioDecoderIsac::IncomingPacket(const uint8_t* payload, @@ -181,7 +178,7 @@ int AudioDecoderIsac::IncomingPacket(const uint8_t* payload, uint16_t rtp_sequence_number, uint32_t rtp_timestamp, uint32_t arrival_timestamp) { - return WebRtcIsac_UpdateBwEstimate(static_cast<ISACStruct*>(state_), + return WebRtcIsac_UpdateBwEstimate(isac_state_, payload, static_cast<int32_t>(payload_len), rtp_sequence_number, @@ -190,24 +187,24 @@ int AudioDecoderIsac::IncomingPacket(const uint8_t* payload, } int AudioDecoderIsac::ErrorCode() { - return WebRtcIsac_GetErrorCode(static_cast<ISACStruct*>(state_)); + return WebRtcIsac_GetErrorCode(isac_state_); } #endif // iSAC fix #ifdef WEBRTC_CODEC_ISACFX AudioDecoderIsacFix::AudioDecoderIsacFix() { - WebRtcIsacfix_Create(reinterpret_cast<ISACFIX_MainStruct**>(&state_)); + WebRtcIsacfix_Create(&isac_state_); } AudioDecoderIsacFix::~AudioDecoderIsacFix() { - WebRtcIsacfix_Free(static_cast<ISACFIX_MainStruct*>(state_)); + WebRtcIsacfix_Free(isac_state_); } int AudioDecoderIsacFix::Decode(const uint8_t* encoded, size_t encoded_len, int16_t* decoded, SpeechType* speech_type) { int16_t temp_type = 1; // Default is speech. - int16_t ret = WebRtcIsacfix_Decode(static_cast<ISACFIX_MainStruct*>(state_), + int16_t ret = WebRtcIsacfix_Decode(isac_state_, encoded, static_cast<int16_t>(encoded_len), decoded, &temp_type); @@ -216,7 +213,7 @@ int AudioDecoderIsacFix::Decode(const uint8_t* encoded, size_t encoded_len, } int AudioDecoderIsacFix::Init() { - return WebRtcIsacfix_DecoderInit(static_cast<ISACFIX_MainStruct*>(state_)); + return WebRtcIsacfix_DecoderInit(isac_state_); } int AudioDecoderIsacFix::IncomingPacket(const uint8_t* payload, @@ -225,32 +222,32 @@ int AudioDecoderIsacFix::IncomingPacket(const uint8_t* payload, uint32_t rtp_timestamp, uint32_t arrival_timestamp) { return WebRtcIsacfix_UpdateBwEstimate( - static_cast<ISACFIX_MainStruct*>(state_), + isac_state_, payload, static_cast<int32_t>(payload_len), rtp_sequence_number, rtp_timestamp, arrival_timestamp); } int AudioDecoderIsacFix::ErrorCode() { - return WebRtcIsacfix_GetErrorCode(static_cast<ISACFIX_MainStruct*>(state_)); + return WebRtcIsacfix_GetErrorCode(isac_state_); } #endif // G.722 #ifdef WEBRTC_CODEC_G722 AudioDecoderG722::AudioDecoderG722() { - WebRtcG722_CreateDecoder(reinterpret_cast<G722DecInst**>(&state_)); + WebRtcG722_CreateDecoder(&dec_state_); } AudioDecoderG722::~AudioDecoderG722() { - WebRtcG722_FreeDecoder(static_cast<G722DecInst*>(state_)); + WebRtcG722_FreeDecoder(dec_state_); } int AudioDecoderG722::Decode(const uint8_t* encoded, size_t encoded_len, int16_t* decoded, SpeechType* speech_type) { int16_t temp_type = 1; // Default is speech. int16_t ret = WebRtcG722_Decode( - static_cast<G722DecInst*>(state_), + dec_state_, const_cast<int16_t*>(reinterpret_cast<const int16_t*>(encoded)), static_cast<int16_t>(encoded_len), decoded, &temp_type); *speech_type = ConvertSpeechType(temp_type); @@ -258,7 +255,7 @@ int AudioDecoderG722::Decode(const uint8_t* encoded, size_t encoded_len, } int AudioDecoderG722::Init() { - return WebRtcG722_DecoderInit(static_cast<G722DecInst*>(state_)); + return WebRtcG722_DecoderInit(dec_state_); } int AudioDecoderG722::PacketDuration(const uint8_t* encoded, @@ -267,18 +264,15 @@ int AudioDecoderG722::PacketDuration(const uint8_t* encoded, return static_cast<int>(2 * encoded_len / channels_); } -AudioDecoderG722Stereo::AudioDecoderG722Stereo() - : AudioDecoderG722(), - state_left_(state_), // Base member |state_| is used for left channel. - state_right_(NULL) { +AudioDecoderG722Stereo::AudioDecoderG722Stereo() { channels_ = 2; - // |state_left_| already created by the base class AudioDecoderG722. - WebRtcG722_CreateDecoder(reinterpret_cast<G722DecInst**>(&state_right_)); + WebRtcG722_CreateDecoder(&dec_state_left_); + WebRtcG722_CreateDecoder(&dec_state_right_); } AudioDecoderG722Stereo::~AudioDecoderG722Stereo() { - // |state_left_| will be freed by the base class AudioDecoderG722. - WebRtcG722_FreeDecoder(static_cast<G722DecInst*>(state_right_)); + WebRtcG722_FreeDecoder(dec_state_left_); + WebRtcG722_FreeDecoder(dec_state_right_); } int AudioDecoderG722Stereo::Decode(const uint8_t* encoded, size_t encoded_len, @@ -289,13 +283,13 @@ int AudioDecoderG722Stereo::Decode(const uint8_t* encoded, size_t encoded_len, SplitStereoPacket(encoded, encoded_len, encoded_deinterleaved); // Decode left and right. int16_t ret = WebRtcG722_Decode( - static_cast<G722DecInst*>(state_left_), + dec_state_left_, reinterpret_cast<int16_t*>(encoded_deinterleaved), static_cast<int16_t>(encoded_len / 2), decoded, &temp_type); if (ret >= 0) { int decoded_len = ret; ret = WebRtcG722_Decode( - static_cast<G722DecInst*>(state_right_), + dec_state_right_, reinterpret_cast<int16_t*>(&encoded_deinterleaved[encoded_len / 2]), static_cast<int16_t>(encoded_len / 2), &decoded[decoded_len], &temp_type); if (ret == decoded_len) { @@ -317,11 +311,10 @@ int AudioDecoderG722Stereo::Decode(const uint8_t* encoded, size_t encoded_len, } int AudioDecoderG722Stereo::Init() { - int ret = WebRtcG722_DecoderInit(static_cast<G722DecInst*>(state_right_)); - if (ret != 0) { - return ret; - } - return AudioDecoderG722::Init(); + int r = WebRtcG722_DecoderInit(dec_state_left_); + if (r != 0) + return r; + return WebRtcG722_DecoderInit(dec_state_right_); } // Split the stereo packet and place left and right channel after each other @@ -401,18 +394,17 @@ int AudioDecoderCelt::DecodePlc(int num_frames, int16_t* decoded) { AudioDecoderOpus::AudioDecoderOpus(int num_channels) { DCHECK(num_channels == 1 || num_channels == 2); channels_ = num_channels; - WebRtcOpus_DecoderCreate(reinterpret_cast<OpusDecInst**>(&state_), - static_cast<int>(channels_)); + WebRtcOpus_DecoderCreate(&dec_state_, static_cast<int>(channels_)); } AudioDecoderOpus::~AudioDecoderOpus() { - WebRtcOpus_DecoderFree(static_cast<OpusDecInst*>(state_)); + WebRtcOpus_DecoderFree(dec_state_); } int AudioDecoderOpus::Decode(const uint8_t* encoded, size_t encoded_len, int16_t* decoded, SpeechType* speech_type) { int16_t temp_type = 1; // Default is speech. - int16_t ret = WebRtcOpus_DecodeNew(static_cast<OpusDecInst*>(state_), encoded, + int16_t ret = WebRtcOpus_DecodeNew(dec_state_, encoded, static_cast<int16_t>(encoded_len), decoded, &temp_type); if (ret > 0) @@ -425,7 +417,7 @@ int AudioDecoderOpus::DecodeRedundant(const uint8_t* encoded, size_t encoded_len, int16_t* decoded, SpeechType* speech_type) { int16_t temp_type = 1; // Default is speech. - int16_t ret = WebRtcOpus_DecodeFec(static_cast<OpusDecInst*>(state_), encoded, + int16_t ret = WebRtcOpus_DecodeFec(dec_state_, encoded, static_cast<int16_t>(encoded_len), decoded, &temp_type); if (ret > 0) @@ -435,12 +427,12 @@ int AudioDecoderOpus::DecodeRedundant(const uint8_t* encoded, } int AudioDecoderOpus::Init() { - return WebRtcOpus_DecoderInitNew(static_cast<OpusDecInst*>(state_)); + return WebRtcOpus_DecoderInitNew(dec_state_); } int AudioDecoderOpus::PacketDuration(const uint8_t* encoded, size_t encoded_len) { - return WebRtcOpus_DurationEst(static_cast<OpusDecInst*>(state_), + return WebRtcOpus_DurationEst(dec_state_, encoded, static_cast<int>(encoded_len)); } @@ -458,19 +450,15 @@ bool AudioDecoderOpus::PacketHasFec(const uint8_t* encoded, #endif AudioDecoderCng::AudioDecoderCng() { - WebRtcCng_CreateDec(reinterpret_cast<CNG_dec_inst**>(&state_)); - assert(state_); + CHECK_EQ(0, WebRtcCng_CreateDec(&dec_state_)); } AudioDecoderCng::~AudioDecoderCng() { - if (state_) { - WebRtcCng_FreeDec(static_cast<CNG_dec_inst*>(state_)); - } + WebRtcCng_FreeDec(dec_state_); } int AudioDecoderCng::Init() { - assert(state_); - return WebRtcCng_InitDec(static_cast<CNG_dec_inst*>(state_)); + return WebRtcCng_InitDec(dec_state_); } } // namespace webrtc diff --git a/modules/audio_coding/neteq/audio_decoder_impl.h b/modules/audio_coding/neteq/audio_decoder_impl.h index 214392e7..b30331f3 100644 --- a/modules/audio_coding/neteq/audio_decoder_impl.h +++ b/modules/audio_coding/neteq/audio_decoder_impl.h @@ -19,6 +19,22 @@ #include "webrtc/engine_configurations.h" #endif #include "webrtc/base/constructormagic.h" +#include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h" +#ifdef WEBRTC_CODEC_G722 +#include "webrtc/modules/audio_coding/codecs/g722/include/g722_interface.h" +#endif +#ifdef WEBRTC_CODEC_ILBC +#include "webrtc/modules/audio_coding/codecs/ilbc/interface/ilbc.h" +#endif +#ifdef WEBRTC_CODEC_ISACFX +#include "webrtc/modules/audio_coding/codecs/isac/fix/interface/isacfix.h" +#endif +#ifdef WEBRTC_CODEC_ISAC +#include "webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h" +#endif +#ifdef WEBRTC_CODEC_OPUS +#include "webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h" +#endif #include "webrtc/modules/audio_coding/neteq/interface/audio_decoder.h" #include "webrtc/typedefs.h" @@ -109,6 +125,7 @@ class AudioDecoderIlbc : public AudioDecoder { virtual int Init(); private: + iLBC_decinst_t* dec_state_; DISALLOW_COPY_AND_ASSIGN(AudioDecoderIlbc); }; #endif @@ -133,6 +150,7 @@ class AudioDecoderIsac : public AudioDecoder { virtual int ErrorCode(); private: + ISACStruct* isac_state_; DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsac); }; #endif @@ -153,6 +171,7 @@ class AudioDecoderIsacFix : public AudioDecoder { virtual int ErrorCode(); private: + ISACFIX_MainStruct* isac_state_; DISALLOW_COPY_AND_ASSIGN(AudioDecoderIsacFix); }; #endif @@ -169,10 +188,11 @@ class AudioDecoderG722 : public AudioDecoder { virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len); private: + G722DecInst* dec_state_; DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722); }; -class AudioDecoderG722Stereo : public AudioDecoderG722 { +class AudioDecoderG722Stereo : public AudioDecoder { public: AudioDecoderG722Stereo(); virtual ~AudioDecoderG722Stereo(); @@ -189,8 +209,8 @@ class AudioDecoderG722Stereo : public AudioDecoderG722 { void SplitStereoPacket(const uint8_t* encoded, size_t encoded_len, uint8_t* encoded_deinterleaved); - void* const state_left_; - void* state_right_; + G722DecInst* dec_state_left_; + G722DecInst* dec_state_right_; DISALLOW_COPY_AND_ASSIGN(AudioDecoderG722Stereo); }; @@ -229,6 +249,7 @@ class AudioDecoderOpus : public AudioDecoder { virtual bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const; private: + OpusDecInst* dec_state_; DISALLOW_COPY_AND_ASSIGN(AudioDecoderOpus); }; #endif @@ -252,7 +273,10 @@ class AudioDecoderCng : public AudioDecoder { uint32_t rtp_timestamp, uint32_t arrival_timestamp) { return -1; } + virtual CNG_dec_inst* CngDecoderInstance() OVERRIDE { return dec_state_; } + private: + CNG_dec_inst* dec_state_; DISALLOW_COPY_AND_ASSIGN(AudioDecoderCng); }; diff --git a/modules/audio_coding/neteq/comfort_noise.cc b/modules/audio_coding/neteq/comfort_noise.cc index 31bb40c9..e2be066e 100644 --- a/modules/audio_coding/neteq/comfort_noise.cc +++ b/modules/audio_coding/neteq/comfort_noise.cc @@ -36,7 +36,7 @@ int ComfortNoise::UpdateParameters(Packet* packet) { return kUnknownPayloadType; } decoder_database_->SetActiveCngDecoder(packet->header.payloadType); - CNG_dec_inst* cng_inst = static_cast<CNG_dec_inst*>(cng_decoder->state()); + CNG_dec_inst* cng_inst = cng_decoder->CngDecoderInstance(); int16_t ret = WebRtcCng_UpdateSid(cng_inst, packet->payload, packet->payload_length); @@ -72,7 +72,7 @@ int ComfortNoise::Generate(size_t requested_length, if (!cng_decoder) { return kUnknownPayloadType; } - CNG_dec_inst* cng_inst = static_cast<CNG_dec_inst*>(cng_decoder->state()); + CNG_dec_inst* cng_inst = cng_decoder->CngDecoderInstance(); // The expression &(*output)[0][0] is a pointer to the first element in // the first channel. if (WebRtcCng_Generate(cng_inst, &(*output)[0][0], diff --git a/modules/audio_coding/neteq/interface/audio_decoder.h b/modules/audio_coding/neteq/interface/audio_decoder.h index 16d78c9e..be85c4dd 100644 --- a/modules/audio_coding/neteq/interface/audio_decoder.h +++ b/modules/audio_coding/neteq/interface/audio_decoder.h @@ -14,6 +14,7 @@ #include <stdlib.h> // NULL #include "webrtc/base/constructormagic.h" +#include "webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h" #include "webrtc/typedefs.h" namespace webrtc { @@ -63,7 +64,7 @@ class AudioDecoder { // Used by PacketDuration below. Save the value -1 for errors. enum { kNotImplemented = -2 }; - AudioDecoder() : channels_(1), state_(NULL) {} + AudioDecoder() : channels_(1) {} virtual ~AudioDecoder() {} // Decodes |encode_len| bytes from |encoded| and writes the result in @@ -114,8 +115,9 @@ class AudioDecoder { // Returns true if the packet has FEC and false otherwise. virtual bool PacketHasFec(const uint8_t* encoded, size_t encoded_len) const; - // Returns the underlying decoder state. - void* state() { return state_; } + // If this is a CNG decoder, return the underlying CNG_dec_inst*. If this + // isn't a CNG decoder, don't call this method. + virtual CNG_dec_inst* CngDecoderInstance(); // Returns true if |codec_type| is supported. static bool CodecSupported(NetEqDecoder codec_type); @@ -134,7 +136,6 @@ class AudioDecoder { static SpeechType ConvertSpeechType(int16_t type); size_t channels_; - void* state_; private: DISALLOW_COPY_AND_ASSIGN(AudioDecoder); diff --git a/modules/audio_coding/neteq/normal.cc b/modules/audio_coding/neteq/normal.cc index 46d03fb8..ca2c1ee5 100644 --- a/modules/audio_coding/neteq/normal.cc +++ b/modules/audio_coding/neteq/normal.cc @@ -147,9 +147,9 @@ int Normal::Process(const int16_t* input, AudioDecoder* cng_decoder = decoder_database_->GetActiveCngDecoder(); if (cng_decoder) { - CNG_dec_inst* cng_inst = static_cast<CNG_dec_inst*>(cng_decoder->state()); // Generate long enough for 32kHz. - if (WebRtcCng_Generate(cng_inst, cng_output, kCngLength, 0) < 0) { + if (WebRtcCng_Generate(cng_decoder->CngDecoderInstance(), cng_output, + kCngLength, 0) < 0) { // Error returned; set return vector to all zeros. memset(cng_output, 0, sizeof(cng_output)); } diff --git a/modules/audio_device/android/opensles_input.cc b/modules/audio_device/android/opensles_input.cc index f22d8bf7..e68a6aa2 100644 --- a/modules/audio_device/android/opensles_input.cc +++ b/modules/audio_device/android/opensles_input.cc @@ -360,6 +360,24 @@ bool OpenSlesInput::CreateAudioRecorder() { req), false); + SLAndroidConfigurationItf recorder_config; + OPENSL_RETURN_ON_FAILURE( + (*sles_recorder_)->GetInterface(sles_recorder_, + SL_IID_ANDROIDCONFIGURATION, + &recorder_config), + false); + + // Set audio recorder configuration to + // SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION which ensures that we + // use the main microphone tuned for audio communications. + SLint32 stream_type = SL_ANDROID_RECORDING_PRESET_VOICE_COMMUNICATION; + OPENSL_RETURN_ON_FAILURE( + (*recorder_config)->SetConfiguration(recorder_config, + SL_ANDROID_KEY_RECORDING_PRESET, + &stream_type, + sizeof(SLint32)), + false); + // Realize the recorder in synchronous mode. OPENSL_RETURN_ON_FAILURE((*sles_recorder_)->Realize(sles_recorder_, SL_BOOLEAN_FALSE), diff --git a/modules/audio_device/android/opensles_output.cc b/modules/audio_device/android/opensles_output.cc index 377789b2..487e2840 100644 --- a/modules/audio_device/android/opensles_output.cc +++ b/modules/audio_device/android/opensles_output.cc @@ -407,6 +407,24 @@ bool OpenSlesOutput::CreateAudioPlayer() { &audio_source, &audio_sink, kNumInterfaces, ids, req), false); + + SLAndroidConfigurationItf player_config; + OPENSL_RETURN_ON_FAILURE( + (*sles_player_)->GetInterface(sles_player_, + SL_IID_ANDROIDCONFIGURATION, + &player_config), + false); + + // Set audio player configuration to SL_ANDROID_STREAM_VOICE which corresponds + // to android.media.AudioManager.STREAM_VOICE_CALL. + SLint32 stream_type = SL_ANDROID_STREAM_VOICE; + OPENSL_RETURN_ON_FAILURE( + (*player_config)->SetConfiguration(player_config, + SL_ANDROID_KEY_STREAM_TYPE, + &stream_type, + sizeof(SLint32)), + false); + // Realize the player in synchronous mode. OPENSL_RETURN_ON_FAILURE((*sles_player_)->Realize(sles_player_, SL_BOOLEAN_FALSE), diff --git a/modules/rtp_rtcp/source/rtp_format.h b/modules/rtp_rtcp/source/rtp_format.h index faef7a0b..18225f9b 100644 --- a/modules/rtp_rtcp/source/rtp_format.h +++ b/modules/rtp_rtcp/source/rtp_format.h @@ -53,12 +53,10 @@ class RtpPacketizer { class RtpDepacketizer { public: struct ParsedPayload { - explicit ParsedPayload(WebRtcRTPHeader* rtp_header) - : payload(NULL), payload_length(0), header(rtp_header) {} - const uint8_t* payload; size_t payload_length; - WebRtcRTPHeader* header; + FrameType frame_type; + RTPTypeHeader type; }; static RtpDepacketizer* Create(RtpVideoCodecTypes type); diff --git a/modules/rtp_rtcp/source/rtp_format_h264.cc b/modules/rtp_rtcp/source/rtp_format_h264.cc index b6af1ada..0d20b301 100644 --- a/modules/rtp_rtcp/source/rtp_format_h264.cc +++ b/modules/rtp_rtcp/source/rtp_format_h264.cc @@ -37,12 +37,15 @@ enum NalDefs { kFBit = 0x80, kNriMask = 0x60, kTypeMask = 0x1F }; // Bit masks for FU (A and B) headers. enum FuDefs { kSBit = 0x80, kEBit = 0x40, kRBit = 0x20 }; -void ParseSingleNalu(WebRtcRTPHeader* rtp_header, +void ParseSingleNalu(RtpDepacketizer::ParsedPayload* parsed_payload, const uint8_t* payload_data, size_t payload_data_length) { - rtp_header->type.Video.codec = kRtpVideoH264; - rtp_header->type.Video.isFirstPacket = true; - RTPVideoHeaderH264* h264_header = &rtp_header->type.Video.codecHeader.H264; + parsed_payload->type.Video.width = 0; + parsed_payload->type.Video.height = 0; + parsed_payload->type.Video.codec = kRtpVideoH264; + parsed_payload->type.Video.isFirstPacket = true; + RTPVideoHeaderH264* h264_header = + &parsed_payload->type.Video.codecHeader.H264; h264_header->single_nalu = true; h264_header->stap_a = false; @@ -56,15 +59,15 @@ void ParseSingleNalu(WebRtcRTPHeader* rtp_header, case kSps: case kPps: case kIdr: - rtp_header->frameType = kVideoFrameKey; + parsed_payload->frame_type = kVideoFrameKey; break; default: - rtp_header->frameType = kVideoFrameDelta; + parsed_payload->frame_type = kVideoFrameDelta; break; } } -void ParseFuaNalu(WebRtcRTPHeader* rtp_header, +void ParseFuaNalu(RtpDepacketizer::ParsedPayload* parsed_payload, const uint8_t* payload_data, size_t payload_data_length, size_t* offset) { @@ -82,13 +85,16 @@ void ParseFuaNalu(WebRtcRTPHeader* rtp_header, } if (original_nal_type == kIdr) { - rtp_header->frameType = kVideoFrameKey; + parsed_payload->frame_type = kVideoFrameKey; } else { - rtp_header->frameType = kVideoFrameDelta; + parsed_payload->frame_type = kVideoFrameDelta; } - rtp_header->type.Video.codec = kRtpVideoH264; - rtp_header->type.Video.isFirstPacket = first_fragment; - RTPVideoHeaderH264* h264_header = &rtp_header->type.Video.codecHeader.H264; + parsed_payload->type.Video.width = 0; + parsed_payload->type.Video.height = 0; + parsed_payload->type.Video.codec = kRtpVideoH264; + parsed_payload->type.Video.isFirstPacket = first_fragment; + RTPVideoHeaderH264* h264_header = + &parsed_payload->type.Video.codecHeader.H264; h264_header->single_nalu = false; h264_header->stap_a = false; } @@ -298,12 +304,11 @@ bool RtpDepacketizerH264::Parse(ParsedPayload* parsed_payload, size_t offset = 0; if (nal_type == kFuA) { // Fragmented NAL units (FU-A). - ParseFuaNalu( - parsed_payload->header, payload_data, payload_data_length, &offset); + ParseFuaNalu(parsed_payload, payload_data, payload_data_length, &offset); } else { // We handle STAP-A and single NALU's the same way here. The jitter buffer // will depacketize the STAP-A into NAL units later. - ParseSingleNalu(parsed_payload->header, payload_data, payload_data_length); + ParseSingleNalu(parsed_payload, payload_data, payload_data_length); } parsed_payload->payload = payload_data + offset; diff --git a/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc b/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc index fb29b5a6..eb690ea8 100644 --- a/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc +++ b/modules/rtp_rtcp/source/rtp_format_h264_unittest.cc @@ -399,17 +399,15 @@ class RtpDepacketizerH264Test : public ::testing::Test { TEST_F(RtpDepacketizerH264Test, TestSingleNalu) { uint8_t packet[2] = {0x05, 0xFF}; // F=0, NRI=0, Type=5. - - WebRtcRTPHeader expected_header; - memset(&expected_header, 0, sizeof(expected_header)); - RtpDepacketizer::ParsedPayload payload(&expected_header); + RtpDepacketizer::ParsedPayload payload; ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); ExpectPacket(&payload, packet, sizeof(packet)); - EXPECT_EQ(kVideoFrameKey, payload.header->frameType); - EXPECT_TRUE(payload.header->type.Video.isFirstPacket); - EXPECT_TRUE(payload.header->type.Video.codecHeader.H264.single_nalu); - EXPECT_FALSE(payload.header->type.Video.codecHeader.H264.stap_a); + EXPECT_EQ(kVideoFrameKey, payload.frame_type); + EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); + EXPECT_TRUE(payload.type.Video.isFirstPacket); + EXPECT_TRUE(payload.type.Video.codecHeader.H264.single_nalu); + EXPECT_FALSE(payload.type.Video.codecHeader.H264.stap_a); } TEST_F(RtpDepacketizerH264Test, TestStapAKey) { @@ -417,17 +415,15 @@ TEST_F(RtpDepacketizerH264Test, TestStapAKey) { // Length, nal header, payload. 0, 0x02, kIdr, 0xFF, 0, 0x03, kIdr, 0xFF, 0x00, 0, 0x04, kIdr, 0xFF, 0x00, 0x11}; - - WebRtcRTPHeader expected_header; - memset(&expected_header, 0, sizeof(expected_header)); - RtpDepacketizer::ParsedPayload payload(&expected_header); + RtpDepacketizer::ParsedPayload payload; ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); ExpectPacket(&payload, packet, sizeof(packet)); - EXPECT_EQ(kVideoFrameKey, payload.header->frameType); - EXPECT_TRUE(payload.header->type.Video.isFirstPacket); - EXPECT_TRUE(payload.header->type.Video.codecHeader.H264.single_nalu); - EXPECT_TRUE(payload.header->type.Video.codecHeader.H264.stap_a); + EXPECT_EQ(kVideoFrameKey, payload.frame_type); + EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); + EXPECT_TRUE(payload.type.Video.isFirstPacket); + EXPECT_TRUE(payload.type.Video.codecHeader.H264.single_nalu); + EXPECT_TRUE(payload.type.Video.codecHeader.H264.stap_a); } TEST_F(RtpDepacketizerH264Test, TestStapADelta) { @@ -435,17 +431,15 @@ TEST_F(RtpDepacketizerH264Test, TestStapADelta) { // Length, nal header, payload. 0, 0x02, kSlice, 0xFF, 0, 0x03, kSlice, 0xFF, 0x00, 0, 0x04, kSlice, 0xFF, 0x00, 0x11}; - - WebRtcRTPHeader expected_header; - memset(&expected_header, 0, sizeof(expected_header)); - RtpDepacketizer::ParsedPayload payload(&expected_header); + RtpDepacketizer::ParsedPayload payload; ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); ExpectPacket(&payload, packet, sizeof(packet)); - EXPECT_EQ(kVideoFrameDelta, payload.header->frameType); - EXPECT_TRUE(payload.header->type.Video.isFirstPacket); - EXPECT_TRUE(payload.header->type.Video.codecHeader.H264.single_nalu); - EXPECT_TRUE(payload.header->type.Video.codecHeader.H264.stap_a); + EXPECT_EQ(kVideoFrameDelta, payload.frame_type); + EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); + EXPECT_TRUE(payload.type.Video.isFirstPacket); + EXPECT_TRUE(payload.type.Video.codecHeader.H264.single_nalu); + EXPECT_TRUE(payload.type.Video.codecHeader.H264.stap_a); } TEST_F(RtpDepacketizerH264Test, TestFuA) { @@ -470,33 +464,36 @@ TEST_F(RtpDepacketizerH264Test, TestFuA) { }; const uint8_t kExpected3[1] = {0x03}; - WebRtcRTPHeader expected_header; - memset(&expected_header, 0, sizeof(expected_header)); - RtpDepacketizer::ParsedPayload payload(&expected_header); + RtpDepacketizer::ParsedPayload payload; // We expect that the first packet is one byte shorter since the FU-A header // has been replaced by the original nal header. ASSERT_TRUE(depacketizer_->Parse(&payload, packet1, sizeof(packet1))); ExpectPacket(&payload, kExpected1, sizeof(kExpected1)); - EXPECT_EQ(kVideoFrameKey, payload.header->frameType); - EXPECT_TRUE(payload.header->type.Video.isFirstPacket); - EXPECT_FALSE(payload.header->type.Video.codecHeader.H264.single_nalu); - EXPECT_FALSE(payload.header->type.Video.codecHeader.H264.stap_a); + EXPECT_EQ(kVideoFrameKey, payload.frame_type); + EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); + EXPECT_TRUE(payload.type.Video.isFirstPacket); + EXPECT_FALSE(payload.type.Video.codecHeader.H264.single_nalu); + EXPECT_FALSE(payload.type.Video.codecHeader.H264.stap_a); // Following packets will be 2 bytes shorter since they will only be appended // onto the first packet. + payload = RtpDepacketizer::ParsedPayload(); ASSERT_TRUE(depacketizer_->Parse(&payload, packet2, sizeof(packet2))); ExpectPacket(&payload, kExpected2, sizeof(kExpected2)); - EXPECT_EQ(kVideoFrameKey, payload.header->frameType); - EXPECT_FALSE(payload.header->type.Video.isFirstPacket); - EXPECT_FALSE(payload.header->type.Video.codecHeader.H264.single_nalu); - EXPECT_FALSE(payload.header->type.Video.codecHeader.H264.stap_a); + EXPECT_EQ(kVideoFrameKey, payload.frame_type); + EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); + EXPECT_FALSE(payload.type.Video.isFirstPacket); + EXPECT_FALSE(payload.type.Video.codecHeader.H264.single_nalu); + EXPECT_FALSE(payload.type.Video.codecHeader.H264.stap_a); + payload = RtpDepacketizer::ParsedPayload(); ASSERT_TRUE(depacketizer_->Parse(&payload, packet3, sizeof(packet3))); ExpectPacket(&payload, kExpected3, sizeof(kExpected3)); - EXPECT_EQ(kVideoFrameKey, payload.header->frameType); - EXPECT_FALSE(payload.header->type.Video.isFirstPacket); - EXPECT_FALSE(payload.header->type.Video.codecHeader.H264.single_nalu); - EXPECT_FALSE(payload.header->type.Video.codecHeader.H264.stap_a); + EXPECT_EQ(kVideoFrameKey, payload.frame_type); + EXPECT_EQ(kRtpVideoH264, payload.type.Video.codec); + EXPECT_FALSE(payload.type.Video.isFirstPacket); + EXPECT_FALSE(payload.type.Video.codecHeader.H264.single_nalu); + EXPECT_FALSE(payload.type.Video.codecHeader.H264.stap_a); } } // namespace webrtc diff --git a/modules/rtp_rtcp/source/rtp_format_video_generic.cc b/modules/rtp_rtcp/source/rtp_format_video_generic.cc index 4907846f..ab210ecb 100644 --- a/modules/rtp_rtcp/source/rtp_format_video_generic.cc +++ b/modules/rtp_rtcp/source/rtp_format_video_generic.cc @@ -90,17 +90,19 @@ bool RtpDepacketizerGeneric::Parse(ParsedPayload* parsed_payload, const uint8_t* payload_data, size_t payload_data_length) { assert(parsed_payload != NULL); - assert(parsed_payload->header != NULL); uint8_t generic_header = *payload_data++; --payload_data_length; - parsed_payload->header->frameType = + parsed_payload->frame_type = ((generic_header & RtpFormatVideoGeneric::kKeyFrameBit) != 0) ? kVideoFrameKey : kVideoFrameDelta; - parsed_payload->header->type.Video.isFirstPacket = + parsed_payload->type.Video.isFirstPacket = (generic_header & RtpFormatVideoGeneric::kFirstPacketBit) != 0; + parsed_payload->type.Video.codec = kRtpVideoGeneric; + parsed_payload->type.Video.width = 0; + parsed_payload->type.Video.height = 0; parsed_payload->payload = payload_data; parsed_payload->payload_length = payload_data_length; diff --git a/modules/rtp_rtcp/source/rtp_format_vp8.cc b/modules/rtp_rtcp/source/rtp_format_vp8.cc index 86bdd8bd..d74e04f8 100644 --- a/modules/rtp_rtcp/source/rtp_format_vp8.cc +++ b/modules/rtp_rtcp/source/rtp_format_vp8.cc @@ -121,11 +121,11 @@ int ParseVP8Extension(RTPVideoHeaderVP8* vp8, return parsed_bytes; } -int ParseVP8FrameSize(WebRtcRTPHeader* rtp_header, +int ParseVP8FrameSize(RtpDepacketizer::ParsedPayload* parsed_payload, const uint8_t* data, int data_length) { - assert(rtp_header != NULL); - if (rtp_header->frameType != kVideoFrameKey) { + assert(parsed_payload != NULL); + if (parsed_payload->frame_type != kVideoFrameKey) { // Included in payload header for I-frames. return 0; } @@ -134,8 +134,8 @@ int ParseVP8FrameSize(WebRtcRTPHeader* rtp_header, // in the beginning of the partition. return -1; } - rtp_header->type.Video.width = ((data[7] << 8) + data[6]) & 0x3FFF; - rtp_header->type.Video.height = ((data[9] << 8) + data[8]) & 0x3FFF; + parsed_payload->type.Video.width = ((data[7] << 8) + data[6]) & 0x3FFF; + parsed_payload->type.Video.height = ((data[9] << 8) + data[8]) & 0x3FFF; return 0; } } // namespace @@ -664,27 +664,27 @@ bool RtpDepacketizerVp8::Parse(ParsedPayload* parsed_payload, const uint8_t* payload_data, size_t payload_data_length) { assert(parsed_payload != NULL); - assert(parsed_payload->header != NULL); // Parse mandatory first byte of payload descriptor. bool extension = (*payload_data & 0x80) ? true : false; // X bit bool beginning_of_partition = (*payload_data & 0x10) ? true : false; // S bit int partition_id = (*payload_data & 0x0F); // PartID field - parsed_payload->header->type.Video.isFirstPacket = + parsed_payload->type.Video.width = 0; + parsed_payload->type.Video.height = 0; + parsed_payload->type.Video.isFirstPacket = beginning_of_partition && (partition_id == 0); - - parsed_payload->header->type.Video.codecHeader.VP8.nonReference = + parsed_payload->type.Video.codec = kRtpVideoVp8; + parsed_payload->type.Video.codecHeader.VP8.nonReference = (*payload_data & 0x20) ? true : false; // N bit - parsed_payload->header->type.Video.codecHeader.VP8.partitionId = partition_id; - parsed_payload->header->type.Video.codecHeader.VP8.beginningOfPartition = + parsed_payload->type.Video.codecHeader.VP8.partitionId = partition_id; + parsed_payload->type.Video.codecHeader.VP8.beginningOfPartition = beginning_of_partition; - parsed_payload->header->type.Video.codecHeader.VP8.pictureId = kNoPictureId; - parsed_payload->header->type.Video.codecHeader.VP8.tl0PicIdx = kNoTl0PicIdx; - parsed_payload->header->type.Video.codecHeader.VP8.temporalIdx = - kNoTemporalIdx; - parsed_payload->header->type.Video.codecHeader.VP8.layerSync = false; - parsed_payload->header->type.Video.codecHeader.VP8.keyIdx = kNoKeyIdx; + parsed_payload->type.Video.codecHeader.VP8.pictureId = kNoPictureId; + parsed_payload->type.Video.codecHeader.VP8.tl0PicIdx = kNoTl0PicIdx; + parsed_payload->type.Video.codecHeader.VP8.temporalIdx = kNoTemporalIdx; + parsed_payload->type.Video.codecHeader.VP8.layerSync = false; + parsed_payload->type.Video.codecHeader.VP8.keyIdx = kNoKeyIdx; if (partition_id > 8) { // Weak check for corrupt payload_data: PartID MUST NOT be larger than 8. @@ -697,7 +697,7 @@ bool RtpDepacketizerVp8::Parse(ParsedPayload* parsed_payload, if (extension) { const int parsed_bytes = - ParseVP8Extension(&parsed_payload->header->type.Video.codecHeader.VP8, + ParseVP8Extension(&parsed_payload->type.Video.codecHeader.VP8, payload_data, payload_data_length); if (parsed_bytes < 0) @@ -713,14 +713,14 @@ bool RtpDepacketizerVp8::Parse(ParsedPayload* parsed_payload, // Read P bit from payload header (only at beginning of first partition). if (payload_data_length > 0 && beginning_of_partition && partition_id == 0) { - parsed_payload->header->frameType = + parsed_payload->frame_type = (*payload_data & 0x01) ? kVideoFrameDelta : kVideoFrameKey; } else { - parsed_payload->header->frameType = kVideoFrameDelta; + parsed_payload->frame_type = kVideoFrameDelta; } - if (0 != ParseVP8FrameSize( - parsed_payload->header, payload_data, payload_data_length)) { + if (ParseVP8FrameSize(parsed_payload, payload_data, payload_data_length) != + 0) { return false; } diff --git a/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc b/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc index b13f8793..4382ac2c 100644 --- a/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc +++ b/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc @@ -56,24 +56,23 @@ namespace { // | padding | // : : // +-+-+-+-+-+-+-+-+ - -void VerifyBasicHeader(WebRtcRTPHeader* header, bool N, bool S, int part_id) { - ASSERT_TRUE(header != NULL); - EXPECT_EQ(N, header->type.Video.codecHeader.VP8.nonReference); - EXPECT_EQ(S, header->type.Video.codecHeader.VP8.beginningOfPartition); - EXPECT_EQ(part_id, header->type.Video.codecHeader.VP8.partitionId); +void VerifyBasicHeader(RTPTypeHeader* type, bool N, bool S, int part_id) { + ASSERT_TRUE(type != NULL); + EXPECT_EQ(N, type->Video.codecHeader.VP8.nonReference); + EXPECT_EQ(S, type->Video.codecHeader.VP8.beginningOfPartition); + EXPECT_EQ(part_id, type->Video.codecHeader.VP8.partitionId); } -void VerifyExtensions(WebRtcRTPHeader* header, +void VerifyExtensions(RTPTypeHeader* type, int16_t picture_id, /* I */ int16_t tl0_pic_idx, /* L */ uint8_t temporal_idx, /* T */ int key_idx /* K */) { - ASSERT_TRUE(header != NULL); - EXPECT_EQ(picture_id, header->type.Video.codecHeader.VP8.pictureId); - EXPECT_EQ(tl0_pic_idx, header->type.Video.codecHeader.VP8.tl0PicIdx); - EXPECT_EQ(temporal_idx, header->type.Video.codecHeader.VP8.temporalIdx); - EXPECT_EQ(key_idx, header->type.Video.codecHeader.VP8.keyIdx); + ASSERT_TRUE(type != NULL); + EXPECT_EQ(picture_id, type->Video.codecHeader.VP8.pictureId); + EXPECT_EQ(tl0_pic_idx, type->Video.codecHeader.VP8.tl0PicIdx); + EXPECT_EQ(temporal_idx, type->Video.codecHeader.VP8.temporalIdx); + EXPECT_EQ(key_idx, type->Video.codecHeader.VP8.keyIdx); } } // namespace @@ -405,18 +404,16 @@ TEST_F(RtpDepacketizerVp8Test, BasicHeader) { uint8_t packet[4] = {0}; packet[0] = 0x14; // Binary 0001 0100; S = 1, PartID = 4. packet[1] = 0x01; // P frame. - - WebRtcRTPHeader rtp_header; - memset(&rtp_header, 0, sizeof(rtp_header)); - RtpDepacketizer::ParsedPayload payload(&rtp_header); + RtpDepacketizer::ParsedPayload payload; ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); ExpectPacket( &payload, packet + kHeaderLength, sizeof(packet) - kHeaderLength); - EXPECT_EQ(kVideoFrameDelta, payload.header->frameType); - VerifyBasicHeader(payload.header, 0, 1, 4); + EXPECT_EQ(kVideoFrameDelta, payload.frame_type); + EXPECT_EQ(kRtpVideoVp8, payload.type.Video.codec); + VerifyBasicHeader(&payload.type, 0, 1, 4); VerifyExtensions( - payload.header, kNoPictureId, kNoTl0PicIdx, kNoTemporalIdx, kNoKeyIdx); + &payload.type, kNoPictureId, kNoTl0PicIdx, kNoTemporalIdx, kNoKeyIdx); } TEST_F(RtpDepacketizerVp8Test, PictureID) { @@ -427,29 +424,27 @@ TEST_F(RtpDepacketizerVp8Test, PictureID) { packet[0] = 0xA0; packet[1] = 0x80; packet[2] = kPictureId; - - WebRtcRTPHeader rtp_header; - memset(&rtp_header, 0, sizeof(rtp_header)); - RtpDepacketizer::ParsedPayload payload(&rtp_header); + RtpDepacketizer::ParsedPayload payload; ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); ExpectPacket( &payload, packet + kHeaderLength1, sizeof(packet) - kHeaderLength1); - EXPECT_EQ(kVideoFrameDelta, payload.header->frameType); - VerifyBasicHeader(payload.header, 1, 0, 0); + EXPECT_EQ(kVideoFrameDelta, payload.frame_type); + EXPECT_EQ(kRtpVideoVp8, payload.type.Video.codec); + VerifyBasicHeader(&payload.type, 1, 0, 0); VerifyExtensions( - payload.header, kPictureId, kNoTl0PicIdx, kNoTemporalIdx, kNoKeyIdx); + &payload.type, kPictureId, kNoTl0PicIdx, kNoTemporalIdx, kNoKeyIdx); // Re-use packet, but change to long PictureID. packet[2] = 0x80 | kPictureId; packet[3] = kPictureId; - memset(payload.header, 0, sizeof(rtp_header)); + payload = RtpDepacketizer::ParsedPayload(); ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); ExpectPacket( &payload, packet + kHeaderLength2, sizeof(packet) - kHeaderLength2); - VerifyBasicHeader(payload.header, 1, 0, 0); - VerifyExtensions(payload.header, + VerifyBasicHeader(&payload.type, 1, 0, 0); + VerifyExtensions(&payload.type, (kPictureId << 8) + kPictureId, kNoTl0PicIdx, kNoTemporalIdx, @@ -463,18 +458,16 @@ TEST_F(RtpDepacketizerVp8Test, Tl0PicIdx) { packet[0] = 0x90; packet[1] = 0x40; packet[2] = kTl0PicIdx; - - WebRtcRTPHeader rtp_header; - memset(&rtp_header, 0, sizeof(rtp_header)); - RtpDepacketizer::ParsedPayload payload(&rtp_header); + RtpDepacketizer::ParsedPayload payload; ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); ExpectPacket( &payload, packet + kHeaderLength, sizeof(packet) - kHeaderLength); - EXPECT_EQ(kVideoFrameKey, payload.header->frameType); - VerifyBasicHeader(payload.header, 0, 1, 0); + EXPECT_EQ(kVideoFrameKey, payload.frame_type); + EXPECT_EQ(kRtpVideoVp8, payload.type.Video.codec); + VerifyBasicHeader(&payload.type, 0, 1, 0); VerifyExtensions( - payload.header, kNoPictureId, kTl0PicIdx, kNoTemporalIdx, kNoKeyIdx); + &payload.type, kNoPictureId, kTl0PicIdx, kNoTemporalIdx, kNoKeyIdx); } TEST_F(RtpDepacketizerVp8Test, TIDAndLayerSync) { @@ -483,18 +476,16 @@ TEST_F(RtpDepacketizerVp8Test, TIDAndLayerSync) { packet[0] = 0x88; packet[1] = 0x20; packet[2] = 0x80; // TID(2) + LayerSync(false) - - WebRtcRTPHeader rtp_header; - memset(&rtp_header, 0, sizeof(rtp_header)); - RtpDepacketizer::ParsedPayload payload(&rtp_header); + RtpDepacketizer::ParsedPayload payload; ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); ExpectPacket( &payload, packet + kHeaderLength, sizeof(packet) - kHeaderLength); - EXPECT_EQ(kVideoFrameDelta, payload.header->frameType); - VerifyBasicHeader(payload.header, 0, 0, 8); - VerifyExtensions(payload.header, kNoPictureId, kNoTl0PicIdx, 2, kNoKeyIdx); - EXPECT_FALSE(payload.header->type.Video.codecHeader.VP8.layerSync); + EXPECT_EQ(kVideoFrameDelta, payload.frame_type); + EXPECT_EQ(kRtpVideoVp8, payload.type.Video.codec); + VerifyBasicHeader(&payload.type, 0, 0, 8); + VerifyExtensions(&payload.type, kNoPictureId, kNoTl0PicIdx, 2, kNoKeyIdx); + EXPECT_FALSE(payload.type.Video.codecHeader.VP8.layerSync); } TEST_F(RtpDepacketizerVp8Test, KeyIdx) { @@ -504,18 +495,16 @@ TEST_F(RtpDepacketizerVp8Test, KeyIdx) { packet[0] = 0x88; packet[1] = 0x10; // K = 1. packet[2] = kKeyIdx; - - WebRtcRTPHeader rtp_header; - memset(&rtp_header, 0, sizeof(rtp_header)); - RtpDepacketizer::ParsedPayload payload(&rtp_header); + RtpDepacketizer::ParsedPayload payload; ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); ExpectPacket( &payload, packet + kHeaderLength, sizeof(packet) - kHeaderLength); - EXPECT_EQ(kVideoFrameDelta, payload.header->frameType); - VerifyBasicHeader(payload.header, 0, 0, 8); + EXPECT_EQ(kVideoFrameDelta, payload.frame_type); + EXPECT_EQ(kRtpVideoVp8, payload.type.Video.codec); + VerifyBasicHeader(&payload.type, 0, 0, 8); VerifyExtensions( - payload.header, kNoPictureId, kNoTl0PicIdx, kNoTemporalIdx, kKeyIdx); + &payload.type, kNoPictureId, kNoTl0PicIdx, kNoTemporalIdx, kKeyIdx); } TEST_F(RtpDepacketizerVp8Test, MultipleExtensions) { @@ -527,17 +516,15 @@ TEST_F(RtpDepacketizerVp8Test, MultipleExtensions) { packet[3] = 17; // PictureID, low 8 bits. packet[4] = 42; // Tl0PicIdx. packet[5] = 0x40 | 0x20 | 0x11; // TID(1) + LayerSync(true) + KEYIDX(17). - - WebRtcRTPHeader rtp_header; - memset(&rtp_header, 0, sizeof(rtp_header)); - RtpDepacketizer::ParsedPayload payload(&rtp_header); + RtpDepacketizer::ParsedPayload payload; ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); ExpectPacket( &payload, packet + kHeaderLength, sizeof(packet) - kHeaderLength); - EXPECT_EQ(kVideoFrameDelta, payload.header->frameType); - VerifyBasicHeader(payload.header, 0, 0, 8); - VerifyExtensions(payload.header, (17 << 8) + 17, 42, 1, 17); + EXPECT_EQ(kVideoFrameDelta, payload.frame_type); + EXPECT_EQ(kRtpVideoVp8, payload.type.Video.codec); + VerifyBasicHeader(&payload.type, 0, 0, 8); + VerifyExtensions(&payload.type, (17 << 8) + 17, 42, 1, 17); } TEST_F(RtpDepacketizerVp8Test, TooShortHeader) { @@ -546,10 +533,7 @@ TEST_F(RtpDepacketizerVp8Test, TooShortHeader) { packet[1] = 0x80 | 0x40 | 0x20 | 0x10; // All extensions are enabled... packet[2] = 0x80 | 17; // ... but only 2 bytes PictureID is provided. packet[3] = 17; // PictureID, low 8 bits. - - WebRtcRTPHeader rtp_header; - memset(&rtp_header, 0, sizeof(rtp_header)); - RtpDepacketizer::ParsedPayload payload(&rtp_header); + RtpDepacketizer::ParsedPayload payload; EXPECT_FALSE(depacketizer_->Parse(&payload, packet, sizeof(packet))); } @@ -571,23 +555,20 @@ TEST_F(RtpDepacketizerVp8Test, TestWithPacketizer) { size_t send_bytes; ASSERT_TRUE(packetizer.NextPacket(packet, &send_bytes, &last)); ASSERT_TRUE(last); - - WebRtcRTPHeader rtp_header; - memset(&rtp_header, 0, sizeof(rtp_header)); - RtpDepacketizer::ParsedPayload payload(&rtp_header); + RtpDepacketizer::ParsedPayload payload; ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); ExpectPacket( &payload, packet + kHeaderLength, sizeof(packet) - kHeaderLength); - EXPECT_EQ(kVideoFrameKey, payload.header->frameType); - VerifyBasicHeader(payload.header, 1, 1, 0); - VerifyExtensions(payload.header, + EXPECT_EQ(kVideoFrameKey, payload.frame_type); + EXPECT_EQ(kRtpVideoVp8, payload.type.Video.codec); + VerifyBasicHeader(&payload.type, 1, 1, 0); + VerifyExtensions(&payload.type, input_header.pictureId, input_header.tl0PicIdx, input_header.temporalIdx, input_header.keyIdx); - EXPECT_EQ(payload.header->type.Video.codecHeader.VP8.layerSync, + EXPECT_EQ(payload.type.Video.codecHeader.VP8.layerSync, input_header.layerSync); } - } // namespace webrtc diff --git a/modules/rtp_rtcp/source/rtp_receiver_video.cc b/modules/rtp_rtcp/source/rtp_receiver_video.cc index dfbf35ae..6f6d6470 100644 --- a/modules/rtp_rtcp/source/rtp_receiver_video.cc +++ b/modules/rtp_rtcp/source/rtp_receiver_video.cc @@ -79,13 +79,15 @@ int32_t RTPReceiverVideo::ParseRtpPacket(WebRtcRTPHeader* rtp_header, } rtp_header->type.Video.isFirstPacket = is_first_packet; - RtpDepacketizer::ParsedPayload parsed_payload(rtp_header); + RtpDepacketizer::ParsedPayload parsed_payload; if (!depacketizer->Parse(&parsed_payload, payload, payload_data_length)) return -1; + rtp_header->frameType = parsed_payload.frame_type; + rtp_header->type = parsed_payload.type; return data_callback_->OnReceivedPayloadData(parsed_payload.payload, parsed_payload.payload_length, - parsed_payload.header) == 0 + rtp_header) == 0 ? 0 : -1; } diff --git a/p2p/base/basicpacketsocketfactory.cc b/p2p/base/basicpacketsocketfactory.cc index 06dfe76e..9b12e78d 100644 --- a/p2p/base/basicpacketsocketfactory.cc +++ b/p2p/base/basicpacketsocketfactory.cc @@ -44,7 +44,7 @@ BasicPacketSocketFactory::~BasicPacketSocketFactory() { } AsyncPacketSocket* BasicPacketSocketFactory::CreateUdpSocket( - const SocketAddress& address, int min_port, int max_port) { + const SocketAddress& address, uint16 min_port, uint16 max_port) { // UDP sockets are simple. rtc::AsyncSocket* socket = socket_factory()->CreateAsyncSocket( @@ -62,7 +62,8 @@ AsyncPacketSocket* BasicPacketSocketFactory::CreateUdpSocket( } AsyncPacketSocket* BasicPacketSocketFactory::CreateServerTcpSocket( - const SocketAddress& local_address, int min_port, int max_port, int opts) { + const SocketAddress& local_address, uint16 min_port, uint16 max_port, + int opts) { // Fail if TLS is required. if (opts & PacketSocketFactory::OPT_TLS) { @@ -177,7 +178,7 @@ AsyncResolverInterface* BasicPacketSocketFactory::CreateAsyncResolver() { int BasicPacketSocketFactory::BindSocket( AsyncSocket* socket, const SocketAddress& local_address, - int min_port, int max_port) { + uint16 min_port, uint16 max_port) { int ret = -1; if (min_port == 0 && max_port == 0) { // If there's no port range, let the OS pick a port for us. diff --git a/p2p/base/basicpacketsocketfactory.h b/p2p/base/basicpacketsocketfactory.h index fb3a5269..b23a6772 100644 --- a/p2p/base/basicpacketsocketfactory.h +++ b/p2p/base/basicpacketsocketfactory.h @@ -24,21 +24,28 @@ class BasicPacketSocketFactory : public PacketSocketFactory { BasicPacketSocketFactory(); explicit BasicPacketSocketFactory(Thread* thread); explicit BasicPacketSocketFactory(SocketFactory* socket_factory); - virtual ~BasicPacketSocketFactory(); - - virtual AsyncPacketSocket* CreateUdpSocket( - const SocketAddress& local_address, int min_port, int max_port); - virtual AsyncPacketSocket* CreateServerTcpSocket( - const SocketAddress& local_address, int min_port, int max_port, int opts); - virtual AsyncPacketSocket* CreateClientTcpSocket( - const SocketAddress& local_address, const SocketAddress& remote_address, - const ProxyInfo& proxy_info, const std::string& user_agent, int opts); - - virtual AsyncResolverInterface* CreateAsyncResolver(); + ~BasicPacketSocketFactory() override; + + AsyncPacketSocket* CreateUdpSocket(const SocketAddress& local_address, + uint16 min_port, + uint16 max_port) override; + AsyncPacketSocket* CreateServerTcpSocket(const SocketAddress& local_address, + uint16 min_port, + uint16 max_port, + int opts) override; + AsyncPacketSocket* CreateClientTcpSocket(const SocketAddress& local_address, + const SocketAddress& remote_address, + const ProxyInfo& proxy_info, + const std::string& user_agent, + int opts) override; + + AsyncResolverInterface* CreateAsyncResolver() override; private: - int BindSocket(AsyncSocket* socket, const SocketAddress& local_address, - int min_port, int max_port); + int BindSocket(AsyncSocket* socket, + const SocketAddress& local_address, + uint16 min_port, + uint16 max_port); SocketFactory* socket_factory(); diff --git a/p2p/base/packetsocketfactory.h b/p2p/base/packetsocketfactory.h index 1f45feca..d2d7b1b1 100644 --- a/p2p/base/packetsocketfactory.h +++ b/p2p/base/packetsocketfactory.h @@ -29,17 +29,23 @@ class PacketSocketFactory { PacketSocketFactory() { } virtual ~PacketSocketFactory() { } - virtual AsyncPacketSocket* CreateUdpSocket( - const SocketAddress& address, int min_port, int max_port) = 0; + virtual AsyncPacketSocket* CreateUdpSocket(const SocketAddress& address, + uint16 min_port, + uint16 max_port) = 0; virtual AsyncPacketSocket* CreateServerTcpSocket( - const SocketAddress& local_address, int min_port, int max_port, + const SocketAddress& local_address, + uint16 min_port, + uint16 max_port, int opts) = 0; // TODO: |proxy_info| and |user_agent| should be set // per-factory and not when socket is created. virtual AsyncPacketSocket* CreateClientTcpSocket( - const SocketAddress& local_address, const SocketAddress& remote_address, - const ProxyInfo& proxy_info, const std::string& user_agent, int opts) = 0; + const SocketAddress& local_address, + const SocketAddress& remote_address, + const ProxyInfo& proxy_info, + const std::string& user_agent, + int opts) = 0; virtual AsyncResolverInterface* CreateAsyncResolver() = 0; diff --git a/p2p/base/port.cc b/p2p/base/port.cc index f569d9f5..a8357ad6 100644 --- a/p2p/base/port.cc +++ b/p2p/base/port.cc @@ -152,9 +152,12 @@ static std::string ComputeFoundation( return rtc::ToString<uint32>(rtc::ComputeCrc32(ost.str())); } -Port::Port(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, const rtc::IPAddress& ip, - const std::string& username_fragment, const std::string& password) +Port::Port(rtc::Thread* thread, + rtc::PacketSocketFactory* factory, + rtc::Network* network, + const rtc::IPAddress& ip, + const std::string& username_fragment, + const std::string& password) : thread_(thread), factory_(factory), send_retransmit_count_attribute_(false), @@ -176,10 +179,14 @@ Port::Port(rtc::Thread* thread, rtc::PacketSocketFactory* factory, Construct(); } -Port::Port(rtc::Thread* thread, const std::string& type, +Port::Port(rtc::Thread* thread, + const std::string& type, rtc::PacketSocketFactory* factory, - rtc::Network* network, const rtc::IPAddress& ip, - int min_port, int max_port, const std::string& username_fragment, + rtc::Network* network, + const rtc::IPAddress& ip, + uint16 min_port, + uint16 max_port, + const std::string& username_fragment, const std::string& password) : thread_(thread), factory_(factory), diff --git a/p2p/base/port.h b/p2p/base/port.h index 48b85302..87072e67 100644 --- a/p2p/base/port.h +++ b/p2p/base/port.h @@ -107,13 +107,20 @@ typedef std::set<rtc::SocketAddress> ServerAddresses; class Port : public PortInterface, public rtc::MessageHandler, public sigslot::has_slots<> { public: - Port(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, const rtc::IPAddress& ip, - const std::string& username_fragment, const std::string& password); - Port(rtc::Thread* thread, const std::string& type, + Port(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, const rtc::IPAddress& ip, - int min_port, int max_port, const std::string& username_fragment, + rtc::Network* network, + const rtc::IPAddress& ip, + const std::string& username_fragment, + const std::string& password); + Port(rtc::Thread* thread, + const std::string& type, + rtc::PacketSocketFactory* factory, + rtc::Network* network, + const rtc::IPAddress& ip, + uint16 min_port, + uint16 max_port, + const std::string& username_fragment, const std::string& password); virtual ~Port(); @@ -256,8 +263,8 @@ class Port : public PortInterface, public rtc::MessageHandler, // Debugging description of this port virtual std::string ToString() const; rtc::IPAddress& ip() { return ip_; } - int min_port() { return min_port_; } - int max_port() { return max_port_; } + uint16 min_port() { return min_port_; } + uint16 max_port() { return max_port_; } // Timeout shortening function to speed up unit tests. void set_timeout_delay(int delay) { timeout_delay_ = delay; } @@ -354,8 +361,8 @@ class Port : public PortInterface, public rtc::MessageHandler, bool send_retransmit_count_attribute_; rtc::Network* network_; rtc::IPAddress ip_; - int min_port_; - int max_port_; + uint16 min_port_; + uint16 max_port_; std::string content_name_; int component_; uint32 generation_; diff --git a/p2p/base/port_unittest.cc b/p2p/base/port_unittest.cc index 8805709a..f09db284 100644 --- a/p2p/base/port_unittest.cc +++ b/p2p/base/port_unittest.cc @@ -100,12 +100,17 @@ static bool WriteStunMessage(const StunMessage* msg, ByteBuffer* buf) { // Stub port class for testing STUN generation and processing. class TestPort : public Port { public: - TestPort(rtc::Thread* thread, const std::string& type, - rtc::PacketSocketFactory* factory, rtc::Network* network, - const rtc::IPAddress& ip, int min_port, int max_port, - const std::string& username_fragment, const std::string& password) - : Port(thread, type, factory, network, ip, - min_port, max_port, username_fragment, password) { + TestPort(rtc::Thread* thread, + const std::string& type, + rtc::PacketSocketFactory* factory, + rtc::Network* network, + const rtc::IPAddress& ip, + uint16 min_port, + uint16 max_port, + const std::string& username_fragment, + const std::string& password) + : Port(thread, type, factory, network, ip, min_port, max_port, + username_fragment, password) { } ~TestPort() {} @@ -762,19 +767,21 @@ class FakePacketSocketFactory : public rtc::PacketSocketFactory { next_server_tcp_socket_(NULL), next_client_tcp_socket_(NULL) { } - virtual ~FakePacketSocketFactory() { } + ~FakePacketSocketFactory() override { } - virtual AsyncPacketSocket* CreateUdpSocket( - const SocketAddress& address, int min_port, int max_port) { + AsyncPacketSocket* CreateUdpSocket(const SocketAddress& address, + uint16 min_port, + uint16 max_port) override { EXPECT_TRUE(next_udp_socket_ != NULL); AsyncPacketSocket* result = next_udp_socket_; next_udp_socket_ = NULL; return result; } - virtual AsyncPacketSocket* CreateServerTcpSocket( - const SocketAddress& local_address, int min_port, int max_port, - int opts) { + AsyncPacketSocket* CreateServerTcpSocket(const SocketAddress& local_address, + uint16 min_port, + uint16 max_port, + int opts) override { EXPECT_TRUE(next_server_tcp_socket_ != NULL); AsyncPacketSocket* result = next_server_tcp_socket_; next_server_tcp_socket_ = NULL; @@ -783,10 +790,11 @@ class FakePacketSocketFactory : public rtc::PacketSocketFactory { // TODO: |proxy_info| and |user_agent| should be set // per-factory and not when socket is created. - virtual AsyncPacketSocket* CreateClientTcpSocket( - const SocketAddress& local_address, const SocketAddress& remote_address, - const rtc::ProxyInfo& proxy_info, - const std::string& user_agent, int opts) { + AsyncPacketSocket* CreateClientTcpSocket(const SocketAddress& local_address, + const SocketAddress& remote_address, + const rtc::ProxyInfo& proxy_info, + const std::string& user_agent, + int opts) override { EXPECT_TRUE(next_client_tcp_socket_ != NULL); AsyncPacketSocket* result = next_client_tcp_socket_; next_client_tcp_socket_ = NULL; diff --git a/p2p/base/relayport.cc b/p2p/base/relayport.cc index 4c40b3da..1a07f8fe 100644 --- a/p2p/base/relayport.cc +++ b/p2p/base/relayport.cc @@ -172,11 +172,14 @@ class AllocateRequest : public StunRequest { uint32 start_time_; }; -RelayPort::RelayPort( - rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, const rtc::IPAddress& ip, - int min_port, int max_port, const std::string& username, - const std::string& password) +RelayPort::RelayPort(rtc::Thread* thread, + rtc::PacketSocketFactory* factory, + rtc::Network* network, + const rtc::IPAddress& ip, + uint16 min_port, + uint16 max_port, + const std::string& username, + const std::string& password) : Port(thread, RELAY_PORT_TYPE, factory, network, ip, min_port, max_port, username, password), ready_(false), diff --git a/p2p/base/relayport.h b/p2p/base/relayport.h index 3d9538da..62971426 100644 --- a/p2p/base/relayport.h +++ b/p2p/base/relayport.h @@ -36,9 +36,13 @@ class RelayPort : public Port { // RelayPort doesn't yet do anything fancy in the ctor. static RelayPort* Create( - rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, const rtc::IPAddress& ip, - int min_port, int max_port, const std::string& username, + rtc::Thread* thread, + rtc::PacketSocketFactory* factory, + rtc::Network* network, + const rtc::IPAddress& ip, + uint16 min_port, + uint16 max_port, + const std::string& username, const std::string& password) { return new RelayPort(thread, factory, network, ip, min_port, max_port, username, password); @@ -66,9 +70,13 @@ class RelayPort : public Port { sigslot::signal1<const ProtocolAddress*> SignalSoftTimeout; protected: - RelayPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network*, const rtc::IPAddress& ip, - int min_port, int max_port, const std::string& username, + RelayPort(rtc::Thread* thread, + rtc::PacketSocketFactory* factory, + rtc::Network*, + const rtc::IPAddress& ip, + uint16 min_port, + uint16 max_port, + const std::string& username, const std::string& password); bool Init(); diff --git a/p2p/base/stunport.cc b/p2p/base/stunport.cc index ec6232a6..5ef9e9ea 100644 --- a/p2p/base/stunport.cc +++ b/p2p/base/stunport.cc @@ -162,7 +162,8 @@ UDPPort::UDPPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, rtc::Network* network, rtc::AsyncPacketSocket* socket, - const std::string& username, const std::string& password) + const std::string& username, + const std::string& password) : Port(thread, factory, network, socket->GetLocalAddress().ipaddr(), username, password), requests_(thread), @@ -175,8 +176,11 @@ UDPPort::UDPPort(rtc::Thread* thread, UDPPort::UDPPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, rtc::Network* network, - const rtc::IPAddress& ip, int min_port, int max_port, - const std::string& username, const std::string& password) + const rtc::IPAddress& ip, + uint16 min_port, + uint16 max_port, + const std::string& username, + const std::string& password) : Port(thread, LOCAL_PORT_TYPE, factory, network, ip, min_port, max_port, username, password), requests_(thread), diff --git a/p2p/base/stunport.h b/p2p/base/stunport.h index eda7bb90..9ca60462 100644 --- a/p2p/base/stunport.h +++ b/p2p/base/stunport.h @@ -34,8 +34,8 @@ class UDPPort : public Port { rtc::AsyncPacketSocket* socket, const std::string& username, const std::string& password) { - UDPPort* port = new UDPPort(thread, factory, network, socket, - username, password); + UDPPort* port = + new UDPPort(thread, factory, network, socket, username, password); if (!port->Init()) { delete port; port = NULL; @@ -47,12 +47,12 @@ class UDPPort : public Port { rtc::PacketSocketFactory* factory, rtc::Network* network, const rtc::IPAddress& ip, - int min_port, int max_port, + uint16 min_port, + uint16 max_port, const std::string& username, const std::string& password) { - UDPPort* port = new UDPPort(thread, factory, network, - ip, min_port, max_port, - username, password); + UDPPort* port = new UDPPort(thread, factory, network, ip, min_port, + max_port, username, password); if (!port->Init()) { delete port; port = NULL; @@ -98,14 +98,21 @@ class UDPPort : public Port { } protected: - UDPPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, const rtc::IPAddress& ip, - int min_port, int max_port, - const std::string& username, const std::string& password); - - UDPPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, rtc::AsyncPacketSocket* socket, - const std::string& username, const std::string& password); + UDPPort(rtc::Thread* thread, + rtc::PacketSocketFactory* factory, + rtc::Network* network, + const rtc::IPAddress& ip, + uint16 min_port, + uint16 max_port, + const std::string& username, + const std::string& password); + + UDPPort(rtc::Thread* thread, + rtc::PacketSocketFactory* factory, + rtc::Network* network, + rtc::AsyncPacketSocket* socket, + const std::string& username, + const std::string& password); bool Init(); @@ -194,18 +201,16 @@ class UDPPort : public Port { class StunPort : public UDPPort { public: - static StunPort* Create( - rtc::Thread* thread, - rtc::PacketSocketFactory* factory, - rtc::Network* network, - const rtc::IPAddress& ip, - int min_port, int max_port, - const std::string& username, - const std::string& password, - const ServerAddresses& servers) { - StunPort* port = new StunPort(thread, factory, network, - ip, min_port, max_port, - username, password, servers); + static StunPort* Create(rtc::Thread* thread, + rtc::PacketSocketFactory* factory, + rtc::Network* network, + const rtc::IPAddress& ip, + uint16 min_port, uint16 max_port, + const std::string& username, + const std::string& password, + const ServerAddresses& servers) { + StunPort* port = new StunPort(thread, factory, network, ip, min_port, + max_port, username, password, servers); if (!port->Init()) { delete port; port = NULL; @@ -220,10 +225,14 @@ class StunPort : public UDPPort { } protected: - StunPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, const rtc::IPAddress& ip, - int min_port, int max_port, - const std::string& username, const std::string& password, + StunPort(rtc::Thread* thread, + rtc::PacketSocketFactory* factory, + rtc::Network* network, + const rtc::IPAddress& ip, + uint16 min_port, + uint16 max_port, + const std::string& username, + const std::string& password, const ServerAddresses& servers) : UDPPort(thread, factory, network, ip, min_port, max_port, username, password) { diff --git a/p2p/base/tcpport.cc b/p2p/base/tcpport.cc index be3068be..b37f4d3f 100644 --- a/p2p/base/tcpport.cc +++ b/p2p/base/tcpport.cc @@ -18,9 +18,13 @@ namespace cricket { TCPPort::TCPPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, const rtc::IPAddress& ip, - int min_port, int max_port, const std::string& username, - const std::string& password, bool allow_listen) + rtc::Network* network, + const rtc::IPAddress& ip, + uint16 min_port, + uint16 max_port, + const std::string& username, + const std::string& password, + bool allow_listen) : Port(thread, LOCAL_PORT_TYPE, factory, network, ip, min_port, max_port, username, password), incoming_only_(false), diff --git a/p2p/base/tcpport.h b/p2p/base/tcpport.h index 43e49366..b3655a80 100644 --- a/p2p/base/tcpport.h +++ b/p2p/base/tcpport.h @@ -32,13 +32,13 @@ class TCPPort : public Port { rtc::PacketSocketFactory* factory, rtc::Network* network, const rtc::IPAddress& ip, - int min_port, int max_port, + uint16 min_port, + uint16 max_port, const std::string& username, const std::string& password, bool allow_listen) { - TCPPort* port = new TCPPort(thread, factory, network, - ip, min_port, max_port, - username, password, allow_listen); + TCPPort* port = new TCPPort(thread, factory, network, ip, min_port, + max_port, username, password, allow_listen); if (!port->Init()) { delete port; port = NULL; @@ -57,10 +57,15 @@ class TCPPort : public Port { virtual int GetError(); protected: - TCPPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, - rtc::Network* network, const rtc::IPAddress& ip, - int min_port, int max_port, const std::string& username, - const std::string& password, bool allow_listen); + TCPPort(rtc::Thread* thread, + rtc::PacketSocketFactory* factory, + rtc::Network* network, + const rtc::IPAddress& ip, + uint16 min_port, + uint16 max_port, + const std::string& username, + const std::string& password, + bool allow_listen); bool Init(); // Handles sending using the local TCP socket. diff --git a/p2p/base/turnport.cc b/p2p/base/turnport.cc index e7626fe0..fbdcfeb6 100644 --- a/p2p/base/turnport.cc +++ b/p2p/base/turnport.cc @@ -184,7 +184,8 @@ TurnPort::TurnPort(rtc::Thread* thread, rtc::PacketSocketFactory* factory, rtc::Network* network, const rtc::IPAddress& ip, - int min_port, int max_port, + uint16 min_port, + uint16 max_port, const std::string& username, const std::string& password, const ProtocolAddress& server_address, diff --git a/p2p/base/turnport.h b/p2p/base/turnport.h index 17fad176..4ed77a0c 100644 --- a/p2p/base/turnport.h +++ b/p2p/base/turnport.h @@ -42,16 +42,16 @@ class TurnPort : public Port { const ProtocolAddress& server_address, const RelayCredentials& credentials, int server_priority) { - return new TurnPort(thread, factory, network, socket, - username, password, server_address, - credentials, server_priority); + return new TurnPort(thread, factory, network, socket, username, password, + server_address, credentials, server_priority); } static TurnPort* Create(rtc::Thread* thread, rtc::PacketSocketFactory* factory, rtc::Network* network, const rtc::IPAddress& ip, - int min_port, int max_port, + uint16 min_port, + uint16 max_port, const std::string& username, // ice username. const std::string& password, // ice password. const ProtocolAddress& server_address, @@ -135,7 +135,8 @@ class TurnPort : public Port { rtc::PacketSocketFactory* factory, rtc::Network* network, const rtc::IPAddress& ip, - int min_port, int max_port, + uint16 min_port, + uint16 max_port, const std::string& username, const std::string& password, const ProtocolAddress& server_address, |