diff options
author | Android Chromium Automerger <chromium-automerger@android> | 2014-04-30 19:34:58 +0000 |
---|---|---|
committer | Android Chromium Automerger <chromium-automerger@android> | 2014-04-30 19:34:58 +0000 |
commit | 3a802b959c8b320b70b62017c073e5959357e755 (patch) | |
tree | c87b2a584a40de1ff0e5eb17e94db253fd03c359 | |
parent | dfa35b4f2d7e584d2da14f2e0f1a05b43db7f86d (diff) | |
parent | cfed80f78803395dd066261afb5c5d99e5048d5d (diff) | |
download | webrtc-3a802b959c8b320b70b62017c073e5959357e755.tar.gz |
Merge third_party/webrtc from https://chromium.googlesource.com/external/webrtc/trunk/webrtc.git at cfed80f78803395dd066261afb5c5d99e5048d5d
This commit was generated by merge_from_chromium.py.
Change-Id: I94ed488723120a5df171c9e98791a9fde75b9dc8
127 files changed, 1204 insertions, 957 deletions
diff --git a/build/apk_tests.gyp b/build/apk_tests.gyp index f916cdf2..01859753 100644 --- a/build/apk_tests.gyp +++ b/build/apk_tests.gyp @@ -89,20 +89,6 @@ ], }, { - 'target_name': 'neteq_unittests_apk', - 'type': 'none', - 'variables': { - 'test_suite_name': 'neteq_unittests', - 'input_shlib_path': '<(SHARED_LIB_DIR)/<(SHARED_LIB_PREFIX)neteq_unittests<(SHARED_LIB_SUFFIX)', - }, - 'dependencies': [ - '<(webrtc_root)/modules/modules.gyp:neteq_unittests', - ], - 'includes': [ - '../../../build/apk_test.gypi', - ], - }, - { 'target_name': 'system_wrappers_unittests_apk', 'type': 'none', 'variables': { diff --git a/build/apk_tests_noop.gyp b/build/apk_tests_noop.gyp index e8d39d78..3523e79b 100644 --- a/build/apk_tests_noop.gyp +++ b/build/apk_tests_noop.gyp @@ -30,10 +30,6 @@ 'type': 'none', }, { - 'target_name': 'neteq_unittests_apk', - 'type': 'none', - }, - { 'target_name': 'system_wrappers_unittests_apk', 'type': 'none', }, diff --git a/build/download_vs_toolchain.py b/build/download_vs_toolchain.py new file mode 100644 index 00000000..2462bdce --- /dev/null +++ b/build/download_vs_toolchain.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# +# Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. +# +# Use of this source code is governed by a BSD-style license +# that can be found in the LICENSE file in the root of the source +# tree. An additional intellectual property rights grant can be found +# in the file PATENTS. All contributing project authors may +# be found in the AUTHORS file in the root of the source tree. + +# This script is used to run the vs_toolchain.py script to download the +# Visual Studio toolchain. It's just a temporary measure while waiting for the +# Chrome team to move find_depot_tools into src/build to get rid of these +# workarounds (similar one in gyp_webrtc). + +import os +import sys + + +script_dir = os.path.dirname(os.path.realpath(__file__)) +checkout_root = os.path.abspath(os.path.join(script_dir, os.pardir, os.pardir)) +sys.path.insert(0, os.path.join(checkout_root, 'build')) +sys.path.insert(0, os.path.join(checkout_root, 'tools', 'find_depot_tools')) + + +import vs_toolchain + + +if __name__ == '__main__': + sys.exit(vs_toolchain.main()) diff --git a/build/gyp_webrtc b/build/gyp_webrtc index 9ac4c141..4d5ae791 100755 --- a/build/gyp_webrtc +++ b/build/gyp_webrtc @@ -61,7 +61,9 @@ if __name__ == '__main__': if not os.environ.get('GYP_GENERATORS'): os.environ['GYP_GENERATORS'] = 'ninja' - vs2013_runtime_dll_dirs = vs_toolchain.DownloadVsToolchain() + vs2013_runtime_dll_dirs = None + if int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')): + vs2013_runtime_dll_dirs = vs_toolchain.SetEnvironmentAndGetRuntimeDllDirs() # Enforce gyp syntax checking. This adds about 20% execution time. args.append('--check') diff --git a/common_audio/resampler/push_sinc_resampler.cc b/common_audio/resampler/push_sinc_resampler.cc index 3469ff3f..02755590 100644 --- a/common_audio/resampler/push_sinc_resampler.cc +++ b/common_audio/resampler/push_sinc_resampler.cc @@ -10,6 +10,7 @@ #include "webrtc/common_audio/include/audio_util.h" +#include <assert.h> #include <string.h> #include "webrtc/common_audio/resampler/push_sinc_resampler.h" diff --git a/common_audio/resampler/sinc_resampler.cc b/common_audio/resampler/sinc_resampler.cc index 50299346..84f8125b 100644 --- a/common_audio/resampler/sinc_resampler.cc +++ b/common_audio/resampler/sinc_resampler.cc @@ -90,6 +90,7 @@ #include "webrtc/system_wrappers/interface/cpu_features_wrapper.h" #include "webrtc/typedefs.h" +#include <assert.h> #include <math.h> #include <string.h> diff --git a/common_audio/resampler/sinc_resampler_unittest.cc b/common_audio/resampler/sinc_resampler_unittest.cc index c085cfc2..97908625 100644 --- a/common_audio/resampler/sinc_resampler_unittest.cc +++ b/common_audio/resampler/sinc_resampler_unittest.cc @@ -62,7 +62,7 @@ TEST(SincResamplerTest, ChunkedResample) { static const int kChunks = 2; int max_chunk_size = resampler.ChunkSize() * kChunks; - scoped_array<float> resampled_destination(new float[max_chunk_size]); + scoped_ptr<float[]> resampled_destination(new float[max_chunk_size]); // Verify requesting ChunkSize() frames causes a single callback. EXPECT_CALL(mock_source, Run(_, _)) @@ -81,7 +81,7 @@ TEST(SincResamplerTest, Flush) { MockSource mock_source; SincResampler resampler(kSampleRateRatio, SincResampler::kDefaultRequestSize, &mock_source); - scoped_array<float> resampled_destination(new float[resampler.ChunkSize()]); + scoped_ptr<float[]> resampled_destination(new float[resampler.ChunkSize()]); // Fill the resampler with junk data. EXPECT_CALL(mock_source, Run(_, _)) @@ -266,7 +266,7 @@ TEST_P(SincResamplerTest, Resample) { // Force an update to the sample rate ratio to ensure dyanmic sample rate // changes are working correctly. - scoped_array<float> kernel(new float[SincResampler::kKernelStorageSize]); + scoped_ptr<float[]> kernel(new float[SincResampler::kKernelStorageSize]); memcpy(kernel.get(), resampler.get_kernel_for_testing(), SincResampler::kKernelStorageSize); resampler.SetRatio(M_PI); @@ -278,8 +278,8 @@ TEST_P(SincResamplerTest, Resample) { // TODO(dalecurtis): If we switch to AVX/SSE optimization, we'll need to // allocate these on 32-byte boundaries and ensure they're sized % 32 bytes. - scoped_array<float> resampled_destination(new float[output_samples]); - scoped_array<float> pure_destination(new float[output_samples]); + scoped_ptr<float[]> resampled_destination(new float[output_samples]); + scoped_ptr<float[]> pure_destination(new float[output_samples]); // Generate resampled signal. resampler.Resample(output_samples, resampled_destination.get()); diff --git a/common_audio/signal_processing/spl_init.c b/common_audio/signal_processing/spl_init.c index 454e13ba..762f9e42 100644 --- a/common_audio/signal_processing/spl_init.c +++ b/common_audio/signal_processing/spl_init.c @@ -65,8 +65,10 @@ static void InitPointersToNeon() { WebRtcSpl_MinValueW32 = WebRtcSpl_MinValueW32Neon; WebRtcSpl_CrossCorrelation = WebRtcSpl_CrossCorrelationNeon; WebRtcSpl_DownsampleFast = WebRtcSpl_DownsampleFastNeon; + /* TODO(henrik.lundin): re-enable NEON when the crash from bug 3243 is + understood. */ WebRtcSpl_ScaleAndAddVectorsWithRound = - WebRtcSpl_ScaleAndAddVectorsWithRoundNeon; + WebRtcSpl_ScaleAndAddVectorsWithRoundC; WebRtcSpl_CreateRealFFT = WebRtcSpl_CreateRealFFTNeon; WebRtcSpl_FreeRealFFT = WebRtcSpl_FreeRealFFTNeon; WebRtcSpl_RealForwardFFT = WebRtcSpl_RealForwardFFTNeon; diff --git a/common_types.h b/common_types.h index 68f2baa4..2d93102d 100644 --- a/common_types.h +++ b/common_types.h @@ -720,17 +720,17 @@ struct OverUseDetectorOptions { // This structure will have the information about when packet is actually // received by socket. struct PacketTime { - PacketTime() : timestamp(-1), max_error_us(-1) {} - PacketTime(int64_t timestamp, int64_t max_error_us) - : timestamp(timestamp), max_error_us(max_error_us) { + PacketTime() : timestamp(-1), not_before(-1) {} + PacketTime(int64_t timestamp, int64_t not_before) + : timestamp(timestamp), not_before(not_before) { } - int64_t timestamp; // Receive time after socket delivers the data. - int64_t max_error_us; // Earliest possible time the data could have arrived, - // indicating the potential error in the |timestamp| - // value,in case the system is busy. - // For example, the time of the last select() call. - // If unknown, this value will be set to zero. + int64_t timestamp; // Receive time after socket delivers the data. + int64_t not_before; // Earliest possible time the data could have arrived, + // indicating the potential error in the |timestamp| + // value,in case the system is busy. + // For example, the time of the last select() call. + // If unknown, this value will be set to zero. }; struct RTPHeaderExtension { diff --git a/common_video/interface/i420_video_frame.h b/common_video/interface/i420_video_frame.h index 4579484d..3f90a8e2 100644 --- a/common_video/interface/i420_video_frame.h +++ b/common_video/interface/i420_video_frame.h @@ -15,6 +15,8 @@ // // Storing and handling of YUV (I420) video frames. +#include <assert.h> + #include "webrtc/common_video/plane.h" #include "webrtc/system_wrappers/interface/scoped_refptr.h" #include "webrtc/typedefs.h" diff --git a/common_video/libyuv/libyuv_unittest.cc b/common_video/libyuv/libyuv_unittest.cc index 3df520ed..0abe7f3c 100644 --- a/common_video/libyuv/libyuv_unittest.cc +++ b/common_video/libyuv/libyuv_unittest.cc @@ -84,7 +84,7 @@ class TestLibYuv : public ::testing::Test { FILE* source_file_; I420VideoFrame orig_frame_; - scoped_array<uint8_t> orig_buffer_; + scoped_ptr<uint8_t[]> orig_buffer_; const int width_; const int height_; const int size_y_; @@ -147,7 +147,7 @@ TEST_F(TestLibYuv, ConvertTest) { (width_ + 1) / 2, (width_ + 1) / 2)); printf("\nConvert #%d I420 <-> I420 \n", j); - scoped_array<uint8_t> out_i420_buffer(new uint8_t[frame_length_]); + scoped_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, out_i420_buffer.get())); EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, @@ -162,7 +162,7 @@ TEST_F(TestLibYuv, ConvertTest) { j++; printf("\nConvert #%d I420 <-> RGB24\n", j); - scoped_array<uint8_t> res_rgb_buffer2(new uint8_t[width_ * height_ * 3]); + scoped_ptr<uint8_t[]> res_rgb_buffer2(new uint8_t[width_ * height_ * 3]); // Align the stride values for the output frame. int stride_y = 0; int stride_uv = 0; @@ -184,7 +184,7 @@ TEST_F(TestLibYuv, ConvertTest) { j++; printf("\nConvert #%d I420 <-> UYVY\n", j); - scoped_array<uint8_t> out_uyvy_buffer(new uint8_t[width_ * height_ * 2]); + scoped_ptr<uint8_t[]> out_uyvy_buffer(new uint8_t[width_ * height_ * 2]); EXPECT_EQ(0, ConvertFromI420(orig_frame_, kUYVY, 0, out_uyvy_buffer.get())); EXPECT_EQ(0, ConvertToI420(kUYVY, out_uyvy_buffer.get(), 0, 0, width_, height_, 0, kRotateNone, &res_i420_frame)); @@ -196,8 +196,8 @@ TEST_F(TestLibYuv, ConvertTest) { j++; printf("\nConvert #%d I420 <-> YV12\n", j); - scoped_array<uint8_t> outYV120Buffer(new uint8_t[frame_length_]); - scoped_array<uint8_t> res_i420_buffer(new uint8_t[frame_length_]); + scoped_ptr<uint8_t[]> outYV120Buffer(new uint8_t[frame_length_]); + scoped_ptr<uint8_t[]> res_i420_buffer(new uint8_t[frame_length_]); I420VideoFrame yv12_frame; EXPECT_EQ(0, ConvertFromI420(orig_frame_, kYV12, 0, outYV120Buffer.get())); yv12_frame.CreateFrame(size_y_, outYV120Buffer.get(), @@ -218,7 +218,7 @@ TEST_F(TestLibYuv, ConvertTest) { j++; printf("\nConvert #%d I420 <-> YUY2\n", j); - scoped_array<uint8_t> out_yuy2_buffer(new uint8_t[width_ * height_ * 2]); + scoped_ptr<uint8_t[]> out_yuy2_buffer(new uint8_t[width_ * height_ * 2]); EXPECT_EQ(0, ConvertFromI420(orig_frame_, kYUY2, 0, out_yuy2_buffer.get())); EXPECT_EQ(0, ConvertToI420(kYUY2, out_yuy2_buffer.get(), 0, 0, width_, @@ -231,7 +231,7 @@ TEST_F(TestLibYuv, ConvertTest) { psnr = I420PSNR(&orig_frame_, &res_i420_frame); EXPECT_EQ(48.0, psnr); printf("\nConvert #%d I420 <-> RGB565\n", j); - scoped_array<uint8_t> out_rgb565_buffer(new uint8_t[width_ * height_ * 2]); + scoped_ptr<uint8_t[]> out_rgb565_buffer(new uint8_t[width_ * height_ * 2]); EXPECT_EQ(0, ConvertFromI420(orig_frame_, kRGB565, 0, out_rgb565_buffer.get())); @@ -250,7 +250,7 @@ TEST_F(TestLibYuv, ConvertTest) { EXPECT_GT(ceil(psnr), 40); printf("\nConvert #%d I420 <-> ARGB8888\n", j); - scoped_array<uint8_t> out_argb8888_buffer(new uint8_t[width_ * height_ * 4]); + scoped_ptr<uint8_t[]> out_argb8888_buffer(new uint8_t[width_ * height_ * 4]); EXPECT_EQ(0, ConvertFromI420(orig_frame_, kARGB, 0, out_argb8888_buffer.get())); @@ -283,7 +283,7 @@ TEST_F(TestLibYuv, ConvertAlignedFrame) { Calc16ByteAlignedStride(width_, &stride_y, &stride_uv); EXPECT_EQ(0,res_i420_frame.CreateEmptyFrame(width_, height_, stride_y, stride_uv, stride_uv)); - scoped_array<uint8_t> out_i420_buffer(new uint8_t[frame_length_]); + scoped_ptr<uint8_t[]> out_i420_buffer(new uint8_t[frame_length_]); EXPECT_EQ(0, ConvertFromI420(orig_frame_, kI420, 0, out_i420_buffer.get())); EXPECT_EQ(0, ConvertToI420(kI420, out_i420_buffer.get(), 0, 0, diff --git a/common_video/libyuv/scaler_unittest.cc b/common_video/libyuv/scaler_unittest.cc index fee10df7..f186d82d 100644 --- a/common_video/libyuv/scaler_unittest.cc +++ b/common_video/libyuv/scaler_unittest.cc @@ -99,7 +99,7 @@ TEST_F(TestScaler, ScaleSendingBufferTooSmall) { kI420, kI420, kScalePoint)); I420VideoFrame test_frame2; - scoped_array<uint8_t> orig_buffer(new uint8_t[frame_length_]); + scoped_ptr<uint8_t[]> orig_buffer(new uint8_t[frame_length_]); EXPECT_GT(fread(orig_buffer.get(), 1, frame_length_, source_file_), 0U); test_frame_.CreateFrame(size_y_, orig_buffer.get(), size_uv_, orig_buffer.get() + size_y_, @@ -442,7 +442,7 @@ void TestScaler::ScaleSequence(ScaleMethod method, total_clock = 0; int frame_count = 0; int src_required_size = CalcBufferSize(kI420, src_width, src_height); - scoped_array<uint8_t> frame_buffer(new uint8_t[src_required_size]); + scoped_ptr<uint8_t[]> frame_buffer(new uint8_t[src_required_size]); int size_y = src_width * src_height; int size_uv = ((src_width + 1) / 2) * ((src_height + 1) / 2); diff --git a/examples/android/opensl_loopback/fake_audio_device_buffer.cc b/examples/android/opensl_loopback/fake_audio_device_buffer.cc index 81adc8ff..23b60eeb 100644 --- a/examples/android/opensl_loopback/fake_audio_device_buffer.cc +++ b/examples/android/opensl_loopback/fake_audio_device_buffer.cc @@ -22,7 +22,7 @@ FakeAudioDeviceBuffer::FakeAudioDeviceBuffer() next_available_buffer_(0), record_channels_(0), play_channels_(0) { - buf_.reset(new scoped_array<int8_t>[kNumBuffers]); + buf_.reset(new scoped_ptr<int8_t[]>[kNumBuffers]); for (int i = 0; i < kNumBuffers; ++i) { buf_[i].reset(new int8_t[buffer_size_bytes()]); } diff --git a/examples/android/opensl_loopback/fake_audio_device_buffer.h b/examples/android/opensl_loopback/fake_audio_device_buffer.h index b98ee1e8..1ef866cb 100644 --- a/examples/android/opensl_loopback/fake_audio_device_buffer.h +++ b/examples/android/opensl_loopback/fake_audio_device_buffer.h @@ -55,7 +55,7 @@ class FakeAudioDeviceBuffer : public AudioDeviceBuffer { AudioManagerJni audio_manager_; SingleRwFifo fifo_; - scoped_array<scoped_array<int8_t> > buf_; + scoped_ptr<scoped_ptr<int8_t[]>[]> buf_; int next_available_buffer_; uint8_t record_channels_; diff --git a/modules/audio_coding/codecs/isac/fix/source/transform_neon.S b/modules/audio_coding/codecs/isac/fix/source/transform_neon.S index 46682ac5..6713b286 100644 --- a/modules/audio_coding/codecs/isac/fix/source/transform_neon.S +++ b/modules/audio_coding/codecs/isac/fix/source/transform_neon.S @@ -42,7 +42,11 @@ DEFINE_FUNCTION WebRtcIsacfix_Time2SpecNeon add r5, sp, #(16 + FRAMESAMPLES * 2) @ tmpimQ16; adr r9, WebRtcIsacfix_kCosTab1 +#if defined(__APPLE__) + mov r6, #:lower16:(WebRtcIsacfix_kSinTab1 - WebRtcIsacfix_kCosTab1) +#else mov r6, #(WebRtcIsacfix_kSinTab1 - WebRtcIsacfix_kCosTab1) +#endif add r10, r9, r6 @ WebRtcIsacfix_kSinTab1 vmov.u32 q14, #0 @ Initialize the maximum values for tmpInIm. @@ -455,7 +459,12 @@ TransformAndFindMax: bgt TransformAndFindMax adr r10, WebRtcIsacfix_kSinTab1 +#if defined(__APPLE__) + mov r2, #:lower16:(WebRtcIsacfix_kSinTab1 - WebRtcIsacfix_kCosTab1) +#else mov r2, #(WebRtcIsacfix_kSinTab1 - WebRtcIsacfix_kCosTab1) +#endif + sub r11, r10, r2 @ WebRtcIsacfix_kCosTab1 @ Find the maximum value in the Neon registers diff --git a/modules/audio_coding/main/OWNERS b/modules/audio_coding/main/OWNERS index e1e6256c..83880d21 100644 --- a/modules/audio_coding/main/OWNERS +++ b/modules/audio_coding/main/OWNERS @@ -1,3 +1,4 @@ tina.legrand@webrtc.org turaj@webrtc.org jan.skoglund@webrtc.org +henrik.lundin@webrtc.org diff --git a/modules/audio_coding/main/acm2/acm_receiver.cc b/modules/audio_coding/main/acm2/acm_receiver.cc index a035259b..5e51ba89 100644 --- a/modules/audio_coding/main/acm2/acm_receiver.cc +++ b/modules/audio_coding/main/acm2/acm_receiver.cc @@ -117,23 +117,23 @@ bool IsCng(int codec_id) { } // namespace -AcmReceiver::AcmReceiver(Clock* clock) - : id_(0), - neteq_config_(), - neteq_(NetEq::Create(neteq_config_)), +AcmReceiver::AcmReceiver(const AudioCodingModule::Config& config) + : id_(config.id), + neteq_(NetEq::Create(config.neteq_config)), last_audio_decoder_(-1), // Invalid value. decode_lock_(RWLockWrapper::CreateRWLock()), neteq_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), vad_enabled_(true), previous_audio_activity_(AudioFrame::kVadPassive), - current_sample_rate_hz_(neteq_config_.sample_rate_hz), + current_sample_rate_hz_(config.neteq_config.sample_rate_hz), nack_(), nack_enabled_(false), - clock_(clock), + clock_(config.clock), av_sync_(false), initial_delay_manager_(), missing_packets_sync_stream_(), late_packets_sync_stream_() { + assert(clock_); for (int n = 0; n < ACMCodecDB::kMaxNumCodecs; ++n) { decoders_[n].registered = false; } @@ -765,13 +765,9 @@ bool AcmReceiver::GetSilence(int desired_sample_rate_hz, AudioFrame* frame) { // exceeds a threshold. int num_packets; int max_num_packets; - int buffer_size_byte; - int max_buffer_size_byte; const float kBufferingThresholdScale = 0.9f; - neteq_->PacketBufferStatistics(&num_packets, &max_num_packets, - &buffer_size_byte, &max_buffer_size_byte); - if (num_packets > max_num_packets * kBufferingThresholdScale || - buffer_size_byte > max_buffer_size_byte * kBufferingThresholdScale) { + neteq_->PacketBufferStatistics(&num_packets, &max_num_packets); + if (num_packets > max_num_packets * kBufferingThresholdScale) { initial_delay_manager_->DisableBuffering(); return false; } @@ -784,7 +780,6 @@ bool AcmReceiver::GetSilence(int desired_sample_rate_hz, AudioFrame* frame) { current_sample_rate_hz_ = ACMCodecDB::database_[last_audio_decoder_].plfreq; frame->num_channels_ = decoders_[last_audio_decoder_].channels; } else { - current_sample_rate_hz_ = neteq_config_.sample_rate_hz; frame->num_channels_ = 1; } diff --git a/modules/audio_coding/main/acm2/acm_receiver.h b/modules/audio_coding/main/acm2/acm_receiver.h index fe44de2d..7a238aec 100644 --- a/modules/audio_coding/main/acm2/acm_receiver.h +++ b/modules/audio_coding/main/acm2/acm_receiver.h @@ -27,7 +27,6 @@ namespace webrtc { -class Clock; struct CodecInst; class CriticalSectionWrapper; class RWLockWrapper; @@ -48,7 +47,7 @@ class AcmReceiver { }; // Constructor of the class - explicit AcmReceiver(Clock* clock); + explicit AcmReceiver(const AudioCodingModule::Config& config); // Destructor of the class. ~AcmReceiver(); @@ -339,7 +338,6 @@ class AcmReceiver { void InsertStreamOfSyncPackets(InitialDelayManager::SyncStream* sync_stream); int id_; - NetEq::Config neteq_config_; NetEq* neteq_; Decoder decoders_[ACMCodecDB::kMaxNumCodecs]; int last_audio_decoder_; diff --git a/modules/audio_coding/main/acm2/acm_receiver_unittest.cc b/modules/audio_coding/main/acm2/acm_receiver_unittest.cc index 81588605..c55eef95 100644 --- a/modules/audio_coding/main/acm2/acm_receiver_unittest.cc +++ b/modules/audio_coding/main/acm2/acm_receiver_unittest.cc @@ -43,12 +43,14 @@ class AcmReceiverTest : public AudioPacketizationCallback, public ::testing::Test { protected: AcmReceiverTest() - : receiver_(new AcmReceiver(Clock::GetRealTimeClock())), - acm_(new AudioCodingModuleImpl(0, Clock::GetRealTimeClock())), - timestamp_(0), + : timestamp_(0), packet_sent_(false), last_packet_send_timestamp_(timestamp_), - last_frame_type_(kFrameEmpty) {} + last_frame_type_(kFrameEmpty) { + AudioCodingModule::Config config; + acm_.reset(new AudioCodingModuleImpl(config)); + receiver_.reset(new AcmReceiver(config)); + } ~AcmReceiverTest() {} diff --git a/modules/audio_coding/main/acm2/acm_resampler.cc b/modules/audio_coding/main/acm2/acm_resampler.cc index 47379275..97d87b1b 100644 --- a/modules/audio_coding/main/acm2/acm_resampler.cc +++ b/modules/audio_coding/main/acm2/acm_resampler.cc @@ -10,6 +10,7 @@ #include "webrtc/modules/audio_coding/main/acm2/acm_resampler.h" +#include <assert.h> #include <string.h> #include "webrtc/common_audio/resampler/include/resampler.h" diff --git a/modules/audio_coding/main/acm2/audio_coding_module.cc b/modules/audio_coding/main/acm2/audio_coding_module.cc index 1fbeae2f..eca909cc 100644 --- a/modules/audio_coding/main/acm2/audio_coding_module.cc +++ b/modules/audio_coding/main/acm2/audio_coding_module.cc @@ -13,22 +13,21 @@ #include "webrtc/common_types.h" #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" #include "webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h" -#include "webrtc/modules/audio_coding/main/source/audio_coding_module_impl.h" #include "webrtc/system_wrappers/interface/clock.h" #include "webrtc/system_wrappers/interface/trace.h" namespace webrtc { -const char kLegacyAcmVersion[] = "acm1"; -const char kExperimentalAcmVersion[] = "acm2"; - // Create module AudioCodingModule* AudioCodingModule::Create(int id) { - return new acm2::AudioCodingModuleImpl(id, Clock::GetRealTimeClock()); + return Create(id, Clock::GetRealTimeClock()); } AudioCodingModule* AudioCodingModule::Create(int id, Clock* clock) { - return new acm2::AudioCodingModuleImpl(id, clock); + AudioCodingModule::Config config; + config.id = id; + config.clock = clock; + return new acm2::AudioCodingModuleImpl(config); } // Get number of supported codecs @@ -95,13 +94,4 @@ bool AudioCodingModule::IsCodecValid(const CodecInst& codec) { } } -AudioCodingModule* AudioCodingModuleFactory::Create(int id) const { - return new acm1::AudioCodingModuleImpl(static_cast<int32_t>(id), - Clock::GetRealTimeClock()); -} - -AudioCodingModule* NewAudioCodingModuleFactory::Create(int id) const { - return new acm2::AudioCodingModuleImpl(id, Clock::GetRealTimeClock()); -} - } // namespace webrtc diff --git a/modules/audio_coding/main/acm2/audio_coding_module.gypi b/modules/audio_coding/main/acm2/audio_coding_module.gypi index f51c3bf7..07fe7272 100644 --- a/modules/audio_coding/main/acm2/audio_coding_module.gypi +++ b/modules/audio_coding/main/acm2/audio_coding_module.gypi @@ -7,9 +7,29 @@ # be found in the AUTHORS file in the root of the source tree. { + 'variables': { + 'audio_coding_dependencies': [ + 'CNG', + 'G711', + 'G722', + 'iLBC', + 'iSAC', + 'iSACFix', + 'PCM16B', + '<(webrtc_root)/common_audio/common_audio.gyp:common_audio', + '<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers', + ], + 'audio_coding_defines': [], + 'conditions': [ + ['include_opus==1', { + 'audio_coding_dependencies': ['webrtc_opus',], + 'audio_coding_defines': ['WEBRTC_CODEC_OPUS',], + }], + ], + }, 'targets': [ { - 'target_name': 'acm2', + 'target_name': 'audio_coding_module', 'type': 'static_library', 'defines': [ '<@(audio_coding_defines)', @@ -93,4 +113,43 @@ ], }, ], + 'conditions': [ + ['include_tests==1', { + 'targets': [ + { + 'target_name': 'delay_test', + 'type': 'executable', + 'dependencies': [ + 'audio_coding_module', + '<(DEPTH)/testing/gtest.gyp:gtest', + '<(webrtc_root)/test/test.gyp:test_support', + '<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers', + '<(DEPTH)/third_party/gflags/gflags.gyp:gflags', + ], + 'sources': [ + '../test/delay_test.cc', + '../test/Channel.cc', + '../test/PCMFile.cc', + '../test/utility.cc', + ], + }, # delay_test + { + 'target_name': 'insert_packet_with_timing', + 'type': 'executable', + 'dependencies': [ + 'audio_coding_module', + '<(DEPTH)/testing/gtest.gyp:gtest', + '<(webrtc_root)/test/test.gyp:test_support', + '<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:system_wrappers', + '<(DEPTH)/third_party/gflags/gflags.gyp:gflags', + ], + 'sources': [ + '../test/insert_packet_with_timing.cc', + '../test/Channel.cc', + '../test/PCMFile.cc', + ], + }, # delay_test + ], + }], + ], } diff --git a/modules/audio_coding/main/acm2/audio_coding_module_impl.cc b/modules/audio_coding/main/acm2/audio_coding_module_impl.cc index 3d50ecc0..6133d236 100644 --- a/modules/audio_coding/main/acm2/audio_coding_module_impl.cc +++ b/modules/audio_coding/main/acm2/audio_coding_module_impl.cc @@ -114,9 +114,10 @@ static int TimestampLessThan(uint32_t t1, uint32_t t2) { } // namespace -AudioCodingModuleImpl::AudioCodingModuleImpl(int id, Clock* clock) +AudioCodingModuleImpl::AudioCodingModuleImpl( + const AudioCodingModule::Config& config) : packetization_callback_(NULL), - id_(id), + id_(config.id), expected_codec_ts_(0xD87F3F9F), expected_in_ts_(0xD87F3F9F), send_codec_inst_(), @@ -131,7 +132,7 @@ AudioCodingModuleImpl::AudioCodingModuleImpl(int id, Clock* clock) stereo_send_(false), current_send_codec_idx_(-1), send_codec_registered_(false), - receiver_(clock), + receiver_(config), acm_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), vad_callback_(NULL), is_first_red_(true), @@ -160,8 +161,6 @@ AudioCodingModuleImpl::AudioCodingModuleImpl(int id, Clock* clock) mirror_codec_idx_[i] = -1; } - receiver_.set_id(id_); - // Allocate memory for RED. red_buffer_ = new uint8_t[MAX_PAYLOAD_SIZE_BYTE]; @@ -202,7 +201,7 @@ AudioCodingModuleImpl::AudioCodingModuleImpl(int id, Clock* clock) WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, "Cannot initialize receiver"); } - WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, id, "Created"); + WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, id_, "Created"); } AudioCodingModuleImpl::~AudioCodingModuleImpl() { @@ -1979,10 +1978,6 @@ int AudioCodingModuleImpl::LeastRequiredDelayMs() const { return receiver_.LeastRequiredDelayMs(); } -const char* AudioCodingModuleImpl::Version() const { - return kExperimentalAcmVersion; -} - void AudioCodingModuleImpl::GetDecodingCallStatistics( AudioDecodingCallStats* call_stats) const { receiver_.GetDecodingCallStatistics(call_stats); diff --git a/modules/audio_coding/main/acm2/audio_coding_module_impl.h b/modules/audio_coding/main/acm2/audio_coding_module_impl.h index cdee3f9f..157fc01e 100644 --- a/modules/audio_coding/main/acm2/audio_coding_module_impl.h +++ b/modules/audio_coding/main/acm2/audio_coding_module_impl.h @@ -22,7 +22,6 @@ namespace webrtc { -class Clock; class CriticalSectionWrapper; class RWLockWrapper; @@ -33,11 +32,9 @@ class ACMGenericCodec; class AudioCodingModuleImpl : public AudioCodingModule { public: - AudioCodingModuleImpl(int id, Clock* clock); + explicit AudioCodingModuleImpl(const AudioCodingModule::Config& config); ~AudioCodingModuleImpl(); - virtual const char* Version() const; - // Change the unique identifier of this object. virtual int32_t ChangeUniqueId(const int32_t id); diff --git a/modules/audio_coding/main/acm2/nack_unittest.cc b/modules/audio_coding/main/acm2/nack_unittest.cc index 8011d885..5837c31a 100644 --- a/modules/audio_coding/main/acm2/nack_unittest.cc +++ b/modules/audio_coding/main/acm2/nack_unittest.cc @@ -398,7 +398,7 @@ TEST(NackTest, ChangeOfListSizeAppliedAndOldElementsRemoved) { // Packet lost more than NACK-list size limit. uint16_t num_lost_packets = kNackThreshold + kNackListSize + 5; - scoped_array<uint16_t> seq_num_lost(new uint16_t[num_lost_packets]); + scoped_ptr<uint16_t[]> seq_num_lost(new uint16_t[num_lost_packets]); for (int n = 0; n < num_lost_packets; ++n) { seq_num_lost[n] = ++seq_num; } diff --git a/modules/audio_coding/main/interface/audio_coding_module.h b/modules/audio_coding/main/interface/audio_coding_module.h index db45addd..9c7e5629 100644 --- a/modules/audio_coding/main/interface/audio_coding_module.h +++ b/modules/audio_coding/main/interface/audio_coding_module.h @@ -15,7 +15,9 @@ #include "webrtc/common_types.h" #include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedefs.h" +#include "webrtc/modules/audio_coding/neteq4/interface/neteq.h" #include "webrtc/modules/interface/module.h" +#include "webrtc/system_wrappers/interface/clock.h" #include "webrtc/typedefs.h" namespace webrtc { @@ -25,7 +27,6 @@ struct CodecInst; struct WebRtcRTPHeader; class AudioFrame; class RTPFragmentationHeader; -class Clock; #define WEBRTC_10MS_PCM_AUDIO 960 // 16 bits super wideband 48 kHz @@ -73,15 +74,22 @@ class ACMVQMonCallback { const uint16_t delayMS) = 0; // average delay in ms }; -// Version string for testing, to distinguish instances of ACM1 from ACM2. -extern const char kLegacyAcmVersion[]; -extern const char kExperimentalAcmVersion[]; - class AudioCodingModule: public Module { protected: AudioCodingModule() {} public: + struct Config { + Config() + : id(0), + neteq_config(), + clock(Clock::GetRealTimeClock()) {} + + int id; + NetEq::Config neteq_config; + Clock* clock; + }; + /////////////////////////////////////////////////////////////////////////// // Creation and destruction of a ACM. // @@ -178,11 +186,6 @@ class AudioCodingModule: public Module { // static bool IsCodecValid(const CodecInst& codec); - // Returns the version of ACM. This facilitates distinguishing instances of - // ACM1 from ACM2 while testing. This API will be removed when ACM1 is - // completely removed. - virtual const char* Version() const = 0; - /////////////////////////////////////////////////////////////////////////// // Sender // @@ -936,20 +939,6 @@ class AudioCodingModule: public Module { AudioDecodingCallStats* call_stats) const = 0; }; -struct AudioCodingModuleFactory { - AudioCodingModuleFactory() {} - virtual ~AudioCodingModuleFactory() {} - - virtual AudioCodingModule* Create(int id) const; -}; - -struct NewAudioCodingModuleFactory : AudioCodingModuleFactory { - NewAudioCodingModuleFactory() {} - virtual ~NewAudioCodingModuleFactory() {} - - virtual AudioCodingModule* Create(int id) const; -}; - } // namespace webrtc #endif // WEBRTC_MODULES_AUDIO_CODING_MAIN_INTERFACE_AUDIO_CODING_MODULE_H_ diff --git a/modules/audio_coding/main/source/audio_coding_module_impl.cc b/modules/audio_coding/main/source/audio_coding_module_impl.cc index b8060ce4..5bdbd011 100644 --- a/modules/audio_coding/main/source/audio_coding_module_impl.cc +++ b/modules/audio_coding/main/source/audio_coding_module_impl.cc @@ -2250,18 +2250,10 @@ int32_t AudioCodingModuleImpl::PlayoutData10Ms( int decoded_seq_num; uint32_t decoded_timestamp; bool update_nack = - neteq_.DecodedRtpInfo(&decoded_seq_num, &decoded_timestamp) && - nack_enabled_; // Update NACK only if it is enabled. - audio_frame->num_channels_ = audio_frame_.num_channels_; - audio_frame->vad_activity_ = audio_frame_.vad_activity_; - audio_frame->speech_type_ = audio_frame_.speech_type_; + neteq_.DecodedRtpInfo(&decoded_seq_num, &decoded_timestamp); - stereo_mode = (audio_frame_.num_channels_ > 1); - - // For stereo playout: // Master and Slave samples are interleaved starting with Master. - const uint16_t receive_freq = - static_cast<uint16_t>(audio_frame_.sample_rate_hz_); + uint16_t receive_freq; bool tone_detected = false; int16_t last_detected_tone; int16_t tone; @@ -2270,10 +2262,17 @@ int32_t AudioCodingModuleImpl::PlayoutData10Ms( { CriticalSectionScoped lock(acm_crit_sect_); + audio_frame->num_channels_ = audio_frame_.num_channels_; + audio_frame->vad_activity_ = audio_frame_.vad_activity_; + audio_frame->speech_type_ = audio_frame_.speech_type_; + + stereo_mode = (audio_frame_.num_channels_ > 1); + + receive_freq = static_cast<uint16_t>(audio_frame_.sample_rate_hz_); // Update call statistics. call_stats_.DecodedByNetEq(audio_frame->speech_type_); - if (update_nack) { + if (nack_enabled_ && update_nack) { assert(nack_.get()); nack_->UpdateLastDecodedPacket(decoded_seq_num, decoded_timestamp); } @@ -3029,10 +3028,6 @@ void AudioCodingModuleImpl::DisableNack() { nack_enabled_ = false; } -const char* AudioCodingModuleImpl::Version() const { - return kLegacyAcmVersion; -} - void AudioCodingModuleImpl::GetDecodingCallStatistics( AudioDecodingCallStats* call_stats) const { CriticalSectionScoped lock(acm_crit_sect_); diff --git a/modules/audio_coding/main/source/audio_coding_module_impl.h b/modules/audio_coding/main/source/audio_coding_module_impl.h index f0b22f11..b99e5aca 100644 --- a/modules/audio_coding/main/source/audio_coding_module_impl.h +++ b/modules/audio_coding/main/source/audio_coding_module_impl.h @@ -44,8 +44,6 @@ class AudioCodingModuleImpl : public AudioCodingModule { AudioCodingModuleImpl(const int32_t id, Clock* clock); ~AudioCodingModuleImpl(); - virtual const char* Version() const; - // Change the unique identifier of this object. virtual int32_t ChangeUniqueId(const int32_t id); diff --git a/modules/audio_coding/neteq4/background_noise.h b/modules/audio_coding/neteq4/background_noise.h index ac5446bf..141d71dc 100644 --- a/modules/audio_coding/neteq4/background_noise.h +++ b/modules/audio_coding/neteq4/background_noise.h @@ -126,7 +126,7 @@ class BackgroundNoise { int32_t residual_energy); size_t num_channels_; - scoped_array<ChannelParameters> channel_parameters_; + scoped_ptr<ChannelParameters[]> channel_parameters_; bool initialized_; NetEqBackgroundNoiseMode mode_; diff --git a/modules/audio_coding/neteq4/decision_logic_unittest.cc b/modules/audio_coding/neteq4/decision_logic_unittest.cc index d596c051..60a4b62a 100644 --- a/modules/audio_coding/neteq4/decision_logic_unittest.cc +++ b/modules/audio_coding/neteq4/decision_logic_unittest.cc @@ -24,7 +24,7 @@ TEST(DecisionLogic, CreateAndDestroy) { int fs_hz = 8000; int output_size_samples = fs_hz / 100; // Samples per 10 ms. DecoderDatabase decoder_database; - PacketBuffer packet_buffer(10, 1000); + PacketBuffer packet_buffer(10); DelayPeakDetector delay_peak_detector; DelayManager delay_manager(240, &delay_peak_detector); BufferLevelFilter buffer_level_filter; diff --git a/modules/audio_coding/neteq4/expand.h b/modules/audio_coding/neteq4/expand.h index aec1cd9b..6962aa04 100644 --- a/modules/audio_coding/neteq4/expand.h +++ b/modules/audio_coding/neteq4/expand.h @@ -167,7 +167,7 @@ class Expand { int lag_index_direction_; int current_lag_index_; bool stop_muting_; - scoped_array<ChannelParameters> channel_parameters_; + scoped_ptr<ChannelParameters[]> channel_parameters_; DISALLOW_COPY_AND_ASSIGN(Expand); }; diff --git a/modules/audio_coding/neteq4/interface/neteq.h b/modules/audio_coding/neteq4/interface/neteq.h index 8defe4f7..64a23e82 100644 --- a/modules/audio_coding/neteq4/interface/neteq.h +++ b/modules/audio_coding/neteq4/interface/neteq.h @@ -70,10 +70,15 @@ class NetEq { struct Config { Config() : sample_rate_hz(16000), - enable_audio_classifier(false) {} + enable_audio_classifier(false), + max_packets_in_buffer(50), + // |max_delay_ms| has the same effect as calling SetMaximumDelay(). + max_delay_ms(2000) {} int sample_rate_hz; // Initial vale. Will change with input data. bool enable_audio_classifier; + int max_packets_in_buffer; + int max_delay_ms; }; enum ReturnCodes { @@ -107,13 +112,9 @@ class NetEq { kFrameSplitError, kRedundancySplitError, kPacketBufferCorruption, - kOversizePacket, kSyncPacketNotAccepted }; - static const int kMaxNumPacketsInBuffer = 50; // TODO(hlundin): Remove. - static const int kMaxBytesInBuffer = 113280; // TODO(hlundin): Remove. - // Creates a new NetEq object, with parameters set in |config|. The |config| // object will only have to be valid for the duration of the call to this // method. @@ -179,7 +180,8 @@ class NetEq { // Sets a maximum delay in milliseconds for packet buffer. The latency will // not exceed the given value, even required delay (given the channel - // conditions) is higher. + // conditions) is higher. Calling this method has the same effect as setting + // the |max_delay_ms| value in the NetEq::Config struct. virtual bool SetMaximumDelay(int delay_ms) = 0; // The smallest latency required. This is computed bases on inter-arrival @@ -249,9 +251,7 @@ class NetEq { // Current usage of packet-buffer and it's limits. virtual void PacketBufferStatistics(int* current_num_packets, - int* max_num_packets, - int* current_memory_size_bytes, - int* max_memory_size_bytes) const = 0; + int* max_num_packets) const = 0; // Get sequence number and timestamp of the latest RTP. // This method is to facilitate NACK. diff --git a/modules/audio_coding/neteq4/mock/mock_packet_buffer.h b/modules/audio_coding/neteq4/mock/mock_packet_buffer.h index 37fa90de..b1d8ef90 100644 --- a/modules/audio_coding/neteq4/mock/mock_packet_buffer.h +++ b/modules/audio_coding/neteq4/mock/mock_packet_buffer.h @@ -19,8 +19,8 @@ namespace webrtc { class MockPacketBuffer : public PacketBuffer { public: - MockPacketBuffer(size_t max_number_of_packets, size_t max_payload_memory) - : PacketBuffer(max_number_of_packets, max_payload_memory) {} + MockPacketBuffer(size_t max_number_of_packets) + : PacketBuffer(max_number_of_packets) {} virtual ~MockPacketBuffer() { Die(); } MOCK_METHOD0(Die, void()); MOCK_METHOD0(Flush, diff --git a/modules/audio_coding/neteq4/neteq.cc b/modules/audio_coding/neteq4/neteq.cc index bfcd86a7..48dacea1 100644 --- a/modules/audio_coding/neteq4/neteq.cc +++ b/modules/audio_coding/neteq4/neteq.cc @@ -32,12 +32,12 @@ NetEq* NetEq::Create(const NetEq::Config& config) { BufferLevelFilter* buffer_level_filter = new BufferLevelFilter; DecoderDatabase* decoder_database = new DecoderDatabase; DelayPeakDetector* delay_peak_detector = new DelayPeakDetector; - DelayManager* delay_manager = new DelayManager(kMaxNumPacketsInBuffer, - delay_peak_detector); + DelayManager* delay_manager = + new DelayManager(config.max_packets_in_buffer, delay_peak_detector); + delay_manager->SetMaximumDelay(config.max_delay_ms); DtmfBuffer* dtmf_buffer = new DtmfBuffer(config.sample_rate_hz); DtmfToneGenerator* dtmf_tone_generator = new DtmfToneGenerator; - PacketBuffer* packet_buffer = new PacketBuffer(kMaxNumPacketsInBuffer, - kMaxBytesInBuffer); + PacketBuffer* packet_buffer = new PacketBuffer(config.max_packets_in_buffer); PayloadSplitter* payload_splitter = new PayloadSplitter; TimestampScaler* timestamp_scaler = new TimestampScaler(*decoder_database); AccelerateFactory* accelerate_factory = new AccelerateFactory; diff --git a/modules/audio_coding/neteq4/neteq_impl.cc b/modules/audio_coding/neteq4/neteq_impl.cc index dcf48ad4..38a54569 100644 --- a/modules/audio_coding/neteq4/neteq_impl.cc +++ b/modules/audio_coding/neteq4/neteq_impl.cc @@ -77,7 +77,6 @@ NetEqImpl::NetEqImpl(int fs, accelerate_factory_(accelerate_factory), preemptive_expand_factory_(preemptive_expand_factory), last_mode_(kModeNormal), - mute_factor_array_(NULL), decoded_buffer_length_(kMaxFrameSize), decoded_buffer_(new int16_t[decoded_buffer_length_]), playout_timestamp_(0), @@ -365,12 +364,9 @@ void NetEqImpl::FlushBuffers() { } void NetEqImpl::PacketBufferStatistics(int* current_num_packets, - int* max_num_packets, - int* current_memory_size_bytes, - int* max_memory_size_bytes) const { + int* max_num_packets) const { CriticalSectionScoped lock(crit_sect_.get()); - packet_buffer_->BufferStat(current_num_packets, max_num_packets, - current_memory_size_bytes, max_memory_size_bytes); + packet_buffer_->BufferStat(current_num_packets, max_num_packets); } int NetEqImpl::DecodedRtpInfo(int* sequence_number, uint32_t* timestamp) const { @@ -611,9 +607,6 @@ int NetEqImpl::InsertPacketInternal(const WebRtcRTPHeader& rtp_header, new_codec_ = true; update_sample_rate_and_channels = true; LOG_F(LS_WARNING) << "Packet buffer flushed"; - } else if (ret == PacketBuffer::kOversizePacket) { - LOG_F(LS_WARNING) << "Packet larger than packet buffer"; - return kOversizePacket; } else if (ret != PacketBuffer::kOK) { LOG_FERR1(LS_WARNING, InsertPacketList, packet_list.size()); PacketBuffer::DeleteAllPackets(&packet_list); diff --git a/modules/audio_coding/neteq4/neteq_impl.h b/modules/audio_coding/neteq4/neteq_impl.h index 09a0049f..5801d97c 100644 --- a/modules/audio_coding/neteq4/neteq_impl.h +++ b/modules/audio_coding/neteq4/neteq_impl.h @@ -186,9 +186,7 @@ class NetEqImpl : public webrtc::NetEq { virtual void FlushBuffers(); virtual void PacketBufferStatistics(int* current_num_packets, - int* max_num_packets, - int* current_memory_size_bytes, - int* max_memory_size_bytes) const; + int* max_num_packets) const; // Get sequence number and timestamp of the latest RTP. // This method is to facilitate NACK. @@ -371,9 +369,9 @@ class NetEqImpl : public webrtc::NetEq { int output_size_samples_ GUARDED_BY(crit_sect_); int decoder_frame_length_ GUARDED_BY(crit_sect_); Modes last_mode_ GUARDED_BY(crit_sect_); - scoped_array<int16_t> mute_factor_array_ GUARDED_BY(crit_sect_); + scoped_ptr<int16_t[]> mute_factor_array_ GUARDED_BY(crit_sect_); size_t decoded_buffer_length_ GUARDED_BY(crit_sect_); - scoped_array<int16_t> decoded_buffer_ GUARDED_BY(crit_sect_); + scoped_ptr<int16_t[]> decoded_buffer_ GUARDED_BY(crit_sect_); uint32_t playout_timestamp_ GUARDED_BY(crit_sect_); bool new_codec_ GUARDED_BY(crit_sect_); uint32_t timestamp_ GUARDED_BY(crit_sect_); diff --git a/modules/audio_coding/neteq4/neteq_impl_unittest.cc b/modules/audio_coding/neteq4/neteq_impl_unittest.cc index 15a1c8b8..aedd8d5a 100644 --- a/modules/audio_coding/neteq4/neteq_impl_unittest.cc +++ b/modules/audio_coding/neteq4/neteq_impl_unittest.cc @@ -102,13 +102,13 @@ class NetEqImplTest : public ::testing::Test { delay_peak_detector_ = new DelayPeakDetector; } if (use_mock_delay_manager_) { - mock_delay_manager_ = new MockDelayManager(NetEq::kMaxNumPacketsInBuffer, + mock_delay_manager_ = new MockDelayManager(config_.max_packets_in_buffer, delay_peak_detector_); EXPECT_CALL(*mock_delay_manager_, set_streaming_mode(false)).Times(1); delay_manager_ = mock_delay_manager_; } else { delay_manager_ = - new DelayManager(NetEq::kMaxNumPacketsInBuffer, delay_peak_detector_); + new DelayManager(config_.max_packets_in_buffer, delay_peak_detector_); } if (use_mock_dtmf_buffer_) { mock_dtmf_buffer_ = new MockDtmfBuffer(config_.sample_rate_hz); @@ -123,12 +123,10 @@ class NetEqImplTest : public ::testing::Test { dtmf_tone_generator_ = new DtmfToneGenerator; } if (use_mock_packet_buffer_) { - mock_packet_buffer_ = new MockPacketBuffer(NetEq::kMaxNumPacketsInBuffer, - NetEq::kMaxBytesInBuffer); + mock_packet_buffer_ = new MockPacketBuffer(config_.max_packets_in_buffer); packet_buffer_ = mock_packet_buffer_; } else { - packet_buffer_ = new PacketBuffer(NetEq::kMaxNumPacketsInBuffer, - NetEq::kMaxBytesInBuffer); + packet_buffer_ = new PacketBuffer(config_.max_packets_in_buffer); } if (use_mock_payload_splitter_) { mock_payload_splitter_ = new MockPayloadSplitter; @@ -381,7 +379,7 @@ TEST_F(NetEqImplTest, InsertPacketsUntilBufferIsFull) { neteq_->RegisterPayloadType(kDecoderPCM16B, kPayloadType)); // Insert packets. The buffer should not flush. - for (int i = 1; i <= NetEq::kMaxNumPacketsInBuffer; ++i) { + for (int i = 1; i <= config_.max_packets_in_buffer; ++i) { EXPECT_EQ(NetEq::kOK, neteq_->InsertPacket( rtp_header, payload, kPayloadLengthBytes, kReceiveTime)); diff --git a/modules/audio_coding/neteq4/neteq_unittest.cc b/modules/audio_coding/neteq4/neteq_unittest.cc index 90dc7171..93f2567d 100644 --- a/modules/audio_coding/neteq4/neteq_unittest.cc +++ b/modules/audio_coding/neteq4/neteq_unittest.cc @@ -945,18 +945,6 @@ TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(UnknownPayloadType)) { EXPECT_EQ(NetEq::kUnknownRtpPayloadType, neteq_->LastError()); } -TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(OversizePacket)) { - // Payload size is greater than packet buffer size - const int kPayloadBytes = NetEq::kMaxBytesInBuffer + 1; - uint8_t payload[kPayloadBytes] = {0}; - WebRtcRTPHeader rtp_info; - PopulateRtpInfo(0, 0, &rtp_info); - rtp_info.header.payloadType = 103; // iSAC, no packet splitting. - EXPECT_EQ(NetEq::kFail, - neteq_->InsertPacket(rtp_info, payload, kPayloadBytes, 0)); - EXPECT_EQ(NetEq::kOversizePacket, neteq_->LastError()); -} - TEST_F(NetEqDecodingTest, DISABLED_ON_ANDROID(DecoderError)) { const int kPayloadBytes = 100; uint8_t payload[kPayloadBytes] = {0}; diff --git a/modules/audio_coding/neteq4/packet_buffer.cc b/modules/audio_coding/neteq4/packet_buffer.cc index 0cc0854f..bcd0e7b4 100644 --- a/modules/audio_coding/neteq4/packet_buffer.cc +++ b/modules/audio_coding/neteq4/packet_buffer.cc @@ -36,14 +36,8 @@ class NewTimestampIsLarger { const Packet* new_packet_; }; -// Constructor. The arguments define the maximum number of slots and maximum -// payload memory (excluding RTP headers) that the buffer will accept. -PacketBuffer::PacketBuffer(size_t max_number_of_packets, - size_t max_memory_bytes) - : max_number_of_packets_(max_number_of_packets), - max_memory_bytes_(max_memory_bytes), - current_memory_bytes_(0) { -} +PacketBuffer::PacketBuffer(size_t max_number_of_packets) + : max_number_of_packets_(max_number_of_packets) {} // Destructor. All packets in the buffer will be destroyed. PacketBuffer::~PacketBuffer() { @@ -53,7 +47,6 @@ PacketBuffer::~PacketBuffer() { // Flush the buffer. All packets in the buffer will be destroyed. void PacketBuffer::Flush() { DeleteAllPackets(&buffer_); - current_memory_bytes_ = 0; } int PacketBuffer::InsertPacket(Packet* packet) { @@ -66,22 +59,10 @@ int PacketBuffer::InsertPacket(Packet* packet) { int return_val = kOK; - if ((buffer_.size() >= max_number_of_packets_) || - (current_memory_bytes_ + packet->payload_length - > static_cast<int>(max_memory_bytes_))) { + if (buffer_.size() >= max_number_of_packets_) { // Buffer is full. Flush it. Flush(); return_val = kFlushed; - if ((buffer_.size() >= max_number_of_packets_) || - (current_memory_bytes_ + packet->payload_length - > static_cast<int>(max_memory_bytes_))) { - // Buffer is still too small for the packet. Either the buffer limits are - // really small, or the packet is really large. Delete the packet and - // return an error. - delete [] packet->payload; - delete packet; - return kOversizePacket; - } } // Get an iterator pointing to the place in the buffer where the new packet @@ -91,7 +72,6 @@ int PacketBuffer::InsertPacket(Packet* packet) { buffer_.rbegin(), buffer_.rend(), NewTimestampIsLarger(packet)); buffer_.insert(rit.base(), packet); // Insert the packet at that position. - current_memory_bytes_ += packet->payload_length; return return_val; } @@ -183,8 +163,6 @@ Packet* PacketBuffer::GetNextPacket(int* discard_count) { // Assert that the packet sanity checks in InsertPacket method works. assert(packet && packet->payload); buffer_.pop_front(); - current_memory_bytes_ -= packet->payload_length; - assert(current_memory_bytes_ >= 0); // Assert bookkeeping is correct. // Discard other packets with the same timestamp. These are duplicates or // redundant payloads that should not be used. if (discard_count) { @@ -206,11 +184,9 @@ int PacketBuffer::DiscardNextPacket() { if (Empty()) { return kBufferEmpty; } - Packet* temp_packet = buffer_.front(); // Assert that the packet sanity checks in InsertPacket method works. - assert(temp_packet && temp_packet->payload); - current_memory_bytes_ -= temp_packet->payload_length; - assert(current_memory_bytes_ >= 0); // Assert bookkeeping is correct. + assert(buffer_.front()); + assert(buffer_.front()->payload); DeleteFirstPacket(&buffer_); return kOK; } @@ -280,14 +256,9 @@ void PacketBuffer::DeleteAllPackets(PacketList* packet_list) { } } -void PacketBuffer::BufferStat(int* num_packets, - int* max_num_packets, - int* current_memory_bytes, - int* max_memory_bytes) const { +void PacketBuffer::BufferStat(int* num_packets, int* max_num_packets) const { *num_packets = static_cast<int>(buffer_.size()); *max_num_packets = static_cast<int>(max_number_of_packets_); - *current_memory_bytes = current_memory_bytes_; - *max_memory_bytes = static_cast<int>(max_memory_bytes_); } } // namespace webrtc diff --git a/modules/audio_coding/neteq4/packet_buffer.h b/modules/audio_coding/neteq4/packet_buffer.h index e964c28f..3d22ad06 100644 --- a/modules/audio_coding/neteq4/packet_buffer.h +++ b/modules/audio_coding/neteq4/packet_buffer.h @@ -29,14 +29,12 @@ class PacketBuffer { kNotFound, kBufferEmpty, kInvalidPacket, - kInvalidPointer, - kOversizePacket + kInvalidPointer }; // Constructor creates a buffer which can hold a maximum of - // |max_number_of_packets| packets and |max_payload_memory| bytes of payload, - // excluding RTP headers. - PacketBuffer(size_t max_number_of_packets, size_t max_payload_memory); + // |max_number_of_packets| packets. + PacketBuffer(size_t max_number_of_packets); // Deletes all packets in the buffer before destroying the buffer. virtual ~PacketBuffer(); @@ -116,12 +114,7 @@ class PacketBuffer { // The default value for |inc| is 1. virtual void IncrementWaitingTimes(int inc = 1); - virtual void BufferStat(int* num_packets, - int* max_num_packets, - int* current_memory_bytes, - int* max_memory_bytes) const; - - virtual int current_memory_bytes() const { return current_memory_bytes_; } + virtual void BufferStat(int* num_packets, int* max_num_packets) const; // Static method that properly deletes the first packet, and its payload // array, in |packet_list|. Returns false if |packet_list| already was empty, @@ -134,8 +127,6 @@ class PacketBuffer { private: size_t max_number_of_packets_; - size_t max_memory_bytes_; - int current_memory_bytes_; PacketList buffer_; DISALLOW_COPY_AND_ASSIGN(PacketBuffer); }; diff --git a/modules/audio_coding/neteq4/packet_buffer_unittest.cc b/modules/audio_coding/neteq4/packet_buffer_unittest.cc index c8109dc6..387ca146 100644 --- a/modules/audio_coding/neteq4/packet_buffer_unittest.cc +++ b/modules/audio_coding/neteq4/packet_buffer_unittest.cc @@ -70,13 +70,13 @@ void PacketGenerator::SkipPacket() { // Start of test definitions. TEST(PacketBuffer, CreateAndDestroy) { - PacketBuffer* buffer = new PacketBuffer(10, 1000); // 10 packets, 1000 bytes. + PacketBuffer* buffer = new PacketBuffer(10); // 10 packets. EXPECT_TRUE(buffer->Empty()); delete buffer; } TEST(PacketBuffer, InsertPacket) { - PacketBuffer buffer(10, 1000); // 10 packets, 1000 bytes. + PacketBuffer buffer(10); // 10 packets. PacketGenerator gen(17u, 4711u, 0, 10); const int payload_len = 100; @@ -88,7 +88,6 @@ TEST(PacketBuffer, InsertPacket) { EXPECT_EQ(4711u, next_ts); EXPECT_FALSE(buffer.Empty()); EXPECT_EQ(1, buffer.NumPacketsInBuffer()); - EXPECT_EQ(payload_len, buffer.current_memory_bytes()); const RTPHeader* hdr = buffer.NextRtpHeader(); EXPECT_EQ(&(packet->header), hdr); // Compare pointer addresses. @@ -98,7 +97,7 @@ TEST(PacketBuffer, InsertPacket) { // Test to flush buffer. TEST(PacketBuffer, FlushBuffer) { - PacketBuffer buffer(10, 1000); // 10 packets, 1000 bytes. + PacketBuffer buffer(10); // 10 packets. PacketGenerator gen(0, 0, 0, 10); const int payload_len = 10; @@ -109,18 +108,16 @@ TEST(PacketBuffer, FlushBuffer) { } EXPECT_EQ(10, buffer.NumPacketsInBuffer()); EXPECT_FALSE(buffer.Empty()); - EXPECT_EQ(10 * payload_len, buffer.current_memory_bytes()); buffer.Flush(); // Buffer should delete the payloads itself. EXPECT_EQ(0, buffer.NumPacketsInBuffer()); EXPECT_TRUE(buffer.Empty()); - EXPECT_EQ(0, buffer.current_memory_bytes()); } // Test to fill the buffer over the limits, and verify that it flushes. TEST(PacketBuffer, OverfillBuffer) { - PacketBuffer buffer(10, 1000); // 10 packets, 1000 bytes. + PacketBuffer buffer(10); // 10 packets. PacketGenerator gen(0, 0, 0, 10); // Insert 10 small packets; should be ok. @@ -131,7 +128,6 @@ TEST(PacketBuffer, OverfillBuffer) { EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacket(packet)); } EXPECT_EQ(10, buffer.NumPacketsInBuffer()); - EXPECT_EQ(10 * payload_len, buffer.current_memory_bytes()); uint32_t next_ts; EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&next_ts)); EXPECT_EQ(0u, next_ts); // Expect first inserted packet to be first in line. @@ -140,30 +136,17 @@ TEST(PacketBuffer, OverfillBuffer) { Packet* packet = gen.NextPacket(payload_len); EXPECT_EQ(PacketBuffer::kFlushed, buffer.InsertPacket(packet)); EXPECT_EQ(1, buffer.NumPacketsInBuffer()); - EXPECT_EQ(payload_len, buffer.current_memory_bytes()); EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&next_ts)); // Expect last inserted packet to be first in line. EXPECT_EQ(packet->header.timestamp, next_ts); - // Insert 2 large packets; expect to flush when inserting the second one. - const int large_payload_len = 500; - packet = gen.NextPacket(large_payload_len); - EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacket(packet)); - EXPECT_EQ(2, buffer.NumPacketsInBuffer()); - EXPECT_EQ(payload_len + large_payload_len, buffer.current_memory_bytes()); - - packet = gen.NextPacket(large_payload_len); - EXPECT_EQ(PacketBuffer::kFlushed, buffer.InsertPacket(packet)); - EXPECT_EQ(1, buffer.NumPacketsInBuffer()); - EXPECT_EQ(large_payload_len, buffer.current_memory_bytes()); - - // Flush buffer to delete remaining packets. + // Flush buffer to delete all packets. buffer.Flush(); } // Test inserting a list of packets. TEST(PacketBuffer, InsertPacketList) { - PacketBuffer buffer(10, 1000); // 10 packets, 1000 bytes. + PacketBuffer buffer(10); // 10 packets. PacketGenerator gen(0, 0, 0, 10); PacketList list; const int payload_len = 10; @@ -187,7 +170,6 @@ TEST(PacketBuffer, InsertPacketList) { ¤t_cng_pt)); EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. EXPECT_EQ(10, buffer.NumPacketsInBuffer()); - EXPECT_EQ(10 * payload_len, buffer.current_memory_bytes()); EXPECT_EQ(0, current_pt); // Current payload type changed to 0. EXPECT_EQ(0xFF, current_cng_pt); // CNG payload type not changed. @@ -200,7 +182,7 @@ TEST(PacketBuffer, InsertPacketList) { // Expecting the buffer to flush. // TODO(hlundin): Remove this test when legacy operation is no longer needed. TEST(PacketBuffer, InsertPacketListChangePayloadType) { - PacketBuffer buffer(10, 1000); // 10 packets, 1000 bytes. + PacketBuffer buffer(10); // 10 packets. PacketGenerator gen(0, 0, 0, 10); PacketList list; const int payload_len = 10; @@ -229,7 +211,6 @@ TEST(PacketBuffer, InsertPacketListChangePayloadType) { ¤t_cng_pt)); EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. EXPECT_EQ(1, buffer.NumPacketsInBuffer()); // Only the last packet. - EXPECT_EQ(1 * payload_len, buffer.current_memory_bytes()); EXPECT_EQ(1, current_pt); // Current payload type changed to 0. EXPECT_EQ(0xFF, current_cng_pt); // CNG payload type not changed. @@ -252,7 +233,7 @@ TEST(PacketBuffer, InsertPacketListChangePayloadType) { // 8 0x0005 0x00000028 0x0000001E // 9 0x0006 0x00000032 0x00000028 TEST(PacketBuffer, ExtractOrderRedundancy) { - PacketBuffer buffer(100, 1000); // 100 packets, 1000 bytes. + PacketBuffer buffer(100); // 100 packets. const uint32_t ts_increment = 10; // Samples per packet. const uint16_t start_seq_no = 0xFFFF - 2; // Wraps after 3 packets. const uint32_t start_ts = 0xFFFFFFFF - @@ -321,7 +302,7 @@ TEST(PacketBuffer, ExtractOrderRedundancy) { } TEST(PacketBuffer, DiscardPackets) { - PacketBuffer buffer(100, 1000); // 100 packets, 1000 bytes. + PacketBuffer buffer(100); // 100 packets. const uint16_t start_seq_no = 17; const uint32_t start_ts = 4711; const uint32_t ts_increment = 10; @@ -335,7 +316,6 @@ TEST(PacketBuffer, DiscardPackets) { buffer.InsertPacket(packet); } EXPECT_EQ(10, buffer.NumPacketsInBuffer()); - EXPECT_EQ(10 * payload_len, buffer.current_memory_bytes()); // Discard them one by one and make sure that the right packets are at the // front of the buffer. @@ -351,7 +331,7 @@ TEST(PacketBuffer, DiscardPackets) { } TEST(PacketBuffer, Reordering) { - PacketBuffer buffer(100, 1000); // 100 packets, 1000 bytes. + PacketBuffer buffer(100); // 100 packets. const uint16_t start_seq_no = 17; const uint32_t start_ts = 4711; const uint32_t ts_increment = 10; @@ -384,7 +364,6 @@ TEST(PacketBuffer, Reordering) { ¤t_pt, ¤t_cng_pt)); EXPECT_EQ(10, buffer.NumPacketsInBuffer()); - EXPECT_EQ(10 * payload_len, buffer.current_memory_bytes()); // Extract them and make sure that come out in the right order. uint32_t current_ts = start_ts; @@ -408,18 +387,8 @@ TEST(PacketBuffer, Failures) { int payload_len = 100; PacketGenerator gen(start_seq_no, start_ts, 0, ts_increment); - PacketBuffer* buffer = new PacketBuffer(0, 1000); // 0 packets, 1000 bytes. - Packet* packet = gen.NextPacket(payload_len); - EXPECT_EQ(PacketBuffer::kOversizePacket, buffer->InsertPacket(packet)); - delete buffer; - - buffer = new PacketBuffer(100, 10); // 100 packets, 10 bytes. - packet = gen.NextPacket(payload_len); - EXPECT_EQ(PacketBuffer::kOversizePacket, buffer->InsertPacket(packet)); - delete buffer; - - buffer = new PacketBuffer(100, 10000); // 100 packets, 10000 bytes. - packet = NULL; + PacketBuffer* buffer = new PacketBuffer(100); // 100 packets. + Packet* packet = NULL; EXPECT_EQ(PacketBuffer::kInvalidPacket, buffer->InsertPacket(packet)); packet = gen.NextPacket(payload_len); delete [] packet->payload; @@ -448,7 +417,7 @@ TEST(PacketBuffer, Failures) { // Insert packet list of three packets, where the second packet has an invalid // payload. Expect first packet to be inserted, and the remaining two to be // discarded. - buffer = new PacketBuffer(100, 1000); // 100 packets, 1000 bytes. + buffer = new PacketBuffer(100); // 100 packets. PacketList list; list.push_back(gen.NextPacket(payload_len)); // Valid packet. packet = gen.NextPacket(payload_len); diff --git a/modules/audio_coding/neteq4/time_stretch.cc b/modules/audio_coding/neteq4/time_stretch.cc index 5b6b3ba9..5b246c11 100644 --- a/modules/audio_coding/neteq4/time_stretch.cc +++ b/modules/audio_coding/neteq4/time_stretch.cc @@ -29,7 +29,7 @@ TimeStretch::ReturnCodes TimeStretch::Process( int fs_mult_120 = fs_mult_ * 120; // Corresponds to 15 ms. const int16_t* signal; - scoped_array<int16_t> signal_array; + scoped_ptr<int16_t[]> signal_array; size_t signal_len; if (num_channels_ == 1) { signal = input; diff --git a/modules/audio_coding/neteq4/tools/audio_loop.h b/modules/audio_coding/neteq4/tools/audio_loop.h index 038ca370..0499a75c 100644 --- a/modules/audio_coding/neteq4/tools/audio_loop.h +++ b/modules/audio_coding/neteq4/tools/audio_loop.h @@ -27,8 +27,7 @@ class AudioLoop { AudioLoop() : next_index_(0), loop_length_samples_(0), - block_length_samples_(0), - audio_array_(NULL) { + block_length_samples_(0) { } virtual ~AudioLoop() {} @@ -50,7 +49,7 @@ class AudioLoop { size_t next_index_; size_t loop_length_samples_; size_t block_length_samples_; - scoped_array<int16_t> audio_array_; + scoped_ptr<int16_t[]> audio_array_; DISALLOW_COPY_AND_ASSIGN(AudioLoop); }; diff --git a/modules/audio_device/android/fine_audio_buffer.h b/modules/audio_device/android/fine_audio_buffer.h index 597b8aaa..e577b72f 100644 --- a/modules/audio_device/android/fine_audio_buffer.h +++ b/modules/audio_device/android/fine_audio_buffer.h @@ -56,7 +56,7 @@ class FineAudioBuffer { int bytes_per_10_ms_; // Storage for samples that are not yet asked for. - scoped_array<int8_t> cache_buffer_; + scoped_ptr<int8_t[]> cache_buffer_; int cached_buffer_start_; // Location of first unread sample. int cached_bytes_; // Number of bytes stored in cache. }; diff --git a/modules/audio_device/android/fine_audio_buffer_unittest.cc b/modules/audio_device/android/fine_audio_buffer_unittest.cc index 69ba741d..e1f03f8f 100644 --- a/modules/audio_device/android/fine_audio_buffer_unittest.cc +++ b/modules/audio_device/android/fine_audio_buffer_unittest.cc @@ -80,7 +80,7 @@ void RunFineBufferTest(int sample_rate, int frame_size_in_samples) { FineAudioBuffer fine_buffer(&audio_device_buffer, kFrameSizeBytes, sample_rate); - scoped_array<int8_t> out_buffer; + scoped_ptr<int8_t[]> out_buffer; out_buffer.reset( new int8_t[fine_buffer.RequiredBufferSizeBytes()]); for (int i = 0; i < kNumberOfFrames; ++i) { diff --git a/modules/audio_device/android/opensles_input.cc b/modules/audio_device/android/opensles_input.cc index 6b600c9f..f22d8bf7 100644 --- a/modules/audio_device/android/opensles_input.cc +++ b/modules/audio_device/android/opensles_input.cc @@ -289,7 +289,7 @@ void OpenSlesInput::AllocateBuffers() { fifo_.reset(new SingleRwFifo(num_fifo_buffers_needed_)); // Allocate the memory area to be used. - rec_buf_.reset(new scoped_array<int8_t>[TotalBuffersUsed()]); + rec_buf_.reset(new scoped_ptr<int8_t[]>[TotalBuffersUsed()]); for (int i = 0; i < TotalBuffersUsed(); ++i) { rec_buf_[i].reset(new int8_t[buffer_size_bytes()]); } diff --git a/modules/audio_device/android/opensles_input.h b/modules/audio_device/android/opensles_input.h index 48e4fd2d..d27d8243 100644 --- a/modules/audio_device/android/opensles_input.h +++ b/modules/audio_device/android/opensles_input.h @@ -205,7 +205,7 @@ class OpenSlesInput { // Audio buffers AudioDeviceBuffer* audio_buffer_; // Holds all allocated memory such that it is deallocated properly. - scoped_array<scoped_array<int8_t> > rec_buf_; + scoped_ptr<scoped_ptr<int8_t[]>[]> rec_buf_; // Index in |rec_buf_| pointing to the audio buffer that will be ready the // next time RecorderSimpleBufferQueueCallbackHandler is invoked. // Ready means buffer contains audio data from the device. diff --git a/modules/audio_device/android/opensles_output.cc b/modules/audio_device/android/opensles_output.cc index 6185b2ad..377789b2 100644 --- a/modules/audio_device/android/opensles_output.cc +++ b/modules/audio_device/android/opensles_output.cc @@ -340,7 +340,7 @@ void OpenSlesOutput::AllocateBuffers() { fifo_.reset(new SingleRwFifo(num_fifo_buffers_needed_)); // Allocate the memory area to be used. - play_buf_.reset(new scoped_array<int8_t>[TotalBuffersUsed()]); + play_buf_.reset(new scoped_ptr<int8_t[]>[TotalBuffersUsed()]); int required_buffer_size = fine_buffer_->RequiredBufferSizeBytes(); for (int i = 0; i < TotalBuffersUsed(); ++i) { play_buf_[i].reset(new int8_t[required_buffer_size]); diff --git a/modules/audio_device/android/opensles_output.h b/modules/audio_device/android/opensles_output.h index 464a7e41..aa9b5bf1 100644 --- a/modules/audio_device/android/opensles_output.h +++ b/modules/audio_device/android/opensles_output.h @@ -223,7 +223,7 @@ class OpenSlesOutput : public PlayoutDelayProvider { // Audio buffers AudioDeviceBuffer* audio_buffer_; scoped_ptr<FineAudioBuffer> fine_buffer_; - scoped_array<scoped_array<int8_t> > play_buf_; + scoped_ptr<scoped_ptr<int8_t[]>[]> play_buf_; // Index in |rec_buf_| pointing to the audio buffer that will be ready the // next time PlayerSimpleBufferQueueCallbackHandler is invoked. // Ready means buffer is ready to be played out to device. diff --git a/modules/audio_device/android/single_rw_fifo.h b/modules/audio_device/android/single_rw_fifo.h index a1fcfaab..092b1d5e 100644 --- a/modules/audio_device/android/single_rw_fifo.h +++ b/modules/audio_device/android/single_rw_fifo.h @@ -35,7 +35,7 @@ class SingleRwFifo { int capacity() const { return capacity_; } private: - scoped_array<int8_t*> queue_; + scoped_ptr<int8_t*[]> queue_; int capacity_; Atomic32 size_; diff --git a/modules/audio_device/android/single_rw_fifo_unittest.cc b/modules/audio_device/android/single_rw_fifo_unittest.cc index c722c275..9925baaa 100644 --- a/modules/audio_device/android/single_rw_fifo_unittest.cc +++ b/modules/audio_device/android/single_rw_fifo_unittest.cc @@ -90,7 +90,7 @@ class SingleRwFifoTest : public testing::Test { protected: SingleRwFifo fifo_; // Memory area for proper de-allocation. - scoped_array<int8_t> buffer_[kCapacity]; + scoped_ptr<int8_t[]> buffer_[kCapacity]; std::list<int8_t*> memory_queue_; int pushed_; diff --git a/modules/audio_processing/aec/aec_core.h b/modules/audio_processing/aec/aec_core.h index 9f302b79..327a5a91 100644 --- a/modules/audio_processing/aec/aec_core.h +++ b/modules/audio_processing/aec/aec_core.h @@ -22,17 +22,6 @@ #define PART_LEN1 (PART_LEN + 1) // Unique fft coefficients #define PART_LEN2 (PART_LEN * 2) // Length of partition * 2 -// Delay estimator constants, used for logging. -enum { - kMaxDelayBlocks = 60 -}; -enum { - kLookaheadBlocks = 15 -}; -enum { - kHistorySizeBlocks = kMaxDelayBlocks + kLookaheadBlocks -}; - typedef float complex_t[2]; // For performance reasons, some arrays of complex numbers are replaced by twice // as long arrays of float, all the real parts followed by all the imaginary diff --git a/modules/audio_processing/aec/aec_core_internal.h b/modules/audio_processing/aec/aec_core_internal.h index ba7cd347..1c560f91 100644 --- a/modules/audio_processing/aec/aec_core_internal.h +++ b/modules/audio_processing/aec/aec_core_internal.h @@ -26,6 +26,17 @@ enum { }; static const int kNormalNumPartitions = 12; +// Delay estimator constants, used for logging. +enum { + kMaxDelayBlocks = 60 +}; +enum { + kLookaheadBlocks = 15 +}; +enum { + kHistorySizeBlocks = kMaxDelayBlocks + kLookaheadBlocks +}; + // Extended filter adaptation parameters. // TODO(ajm): No narrowband tuning yet. static const float kExtendedMu = 0.4f; diff --git a/modules/audio_processing/aec/echo_cancellation.c b/modules/audio_processing/aec/echo_cancellation.c index d8b44301..c7f4a9ca 100644 --- a/modules/audio_processing/aec/echo_cancellation.c +++ b/modules/audio_processing/aec/echo_cancellation.c @@ -254,7 +254,7 @@ int32_t WebRtcAec_Init(void* aecInst, int32_t sampFreq, int32_t scSampFreq) { aecpc->checkBuffSize = 1; aecpc->firstVal = 0; - aecpc->startup_phase = 1; + aecpc->startup_phase = WebRtcAec_reported_delay_enabled(aecpc->aec); aecpc->bufSizeStart = 0; aecpc->checkBufSizeCtr = 0; aecpc->msInSndCardBuf = 0; diff --git a/modules/audio_processing/common.h b/modules/audio_processing/common.h index e4ac6ee0..42454df2 100644 --- a/modules/audio_processing/common.h +++ b/modules/audio_processing/common.h @@ -11,6 +11,7 @@ #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_COMMON_H_ #define WEBRTC_MODULES_AUDIO_PROCESSING_COMMON_H_ +#include <assert.h> #include <string.h> #include "webrtc/modules/audio_processing/include/audio_processing.h" diff --git a/modules/audio_processing/include/audio_processing.h b/modules/audio_processing/include/audio_processing.h index 6db1d12b..68b679d6 100644 --- a/modules/audio_processing/include/audio_processing.h +++ b/modules/audio_processing/include/audio_processing.h @@ -61,7 +61,12 @@ struct ExperimentalAgc { bool enabled; }; +#if defined(ANDROID) || defined(IOS) +// AECM only supports 8kHz & 16kHz. +static const int kAudioProcMaxNativeSampleRateHz = 16000; +#else static const int kAudioProcMaxNativeSampleRateHz = 32000; +#endif // The Audio Processing Module (APM) provides a collection of voice processing // components designed for real-time communications software. diff --git a/modules/audio_processing/lib_core_neon_offsets.gypi b/modules/audio_processing/lib_core_neon_offsets.gypi index a4d6b748..ce257a81 100644 --- a/modules/audio_processing/lib_core_neon_offsets.gypi +++ b/modules/audio_processing/lib_core_neon_offsets.gypi @@ -14,7 +14,7 @@ 'lib_intermediate_name': '', 'conditions' : [ ['android_webview_build==1', { - 'lib_intermediate_name' : '<(android_src)/$(call intermediates-dir-for, STATIC_LIBRARIES, lib_core_neon_offsets,,, $(GYP_VAR_PREFIX))/lib_core_neon_offsets.a', + 'lib_intermediate_name' : '$(realpath $(call intermediates-dir-for, STATIC_LIBRARIES, lib_core_neon_offsets,,, $(GYP_VAR_PREFIX)))/lib_core_neon_offsets.a', }], ], }, diff --git a/modules/audio_processing/test/process_test.cc b/modules/audio_processing/test/process_test.cc index 95984f54..01f9dcec 100644 --- a/modules/audio_processing/test/process_test.cc +++ b/modules/audio_processing/test/process_test.cc @@ -518,7 +518,7 @@ void void_main(int argc, char* argv[]) { const size_t path_size = apm->echo_control_mobile()->echo_path_size_bytes(); - scoped_array<char> echo_path(new char[path_size]); + scoped_ptr<char[]> echo_path(new char[path_size]); ASSERT_EQ(path_size, fread(echo_path.get(), sizeof(char), path_size, @@ -1004,7 +1004,7 @@ void void_main(int argc, char* argv[]) { if (aecm_echo_path_out_file != NULL) { const size_t path_size = apm->echo_control_mobile()->echo_path_size_bytes(); - scoped_array<char> echo_path(new char[path_size]); + scoped_ptr<char[]> echo_path(new char[path_size]); apm->echo_control_mobile()->GetEchoPath(echo_path.get(), path_size); ASSERT_EQ(path_size, fwrite(echo_path.get(), sizeof(char), diff --git a/modules/audio_processing/utility/ring_buffer_unittest.cc b/modules/audio_processing/utility/ring_buffer_unittest.cc index bd68f948..5dacf0b8 100644 --- a/modules/audio_processing/utility/ring_buffer_unittest.cc +++ b/modules/audio_processing/utility/ring_buffer_unittest.cc @@ -61,8 +61,8 @@ static void RandomStressTest(int** data_ptr) { srand(seed); for (int i = 0; i < kNumTests; i++) { const int buffer_size = std::max(rand() % kMaxBufferSize, 1); - scoped_array<int> write_data(new int[buffer_size]); - scoped_array<int> read_data(new int[buffer_size]); + scoped_ptr<int[]> write_data(new int[buffer_size]); + scoped_ptr<int[]> read_data(new int[buffer_size]); scoped_ring_buffer buffer(WebRtc_CreateBuffer(buffer_size, sizeof(int))); ASSERT_TRUE(buffer.get() != NULL); ASSERT_EQ(0, WebRtc_InitBuffer(buffer.get())); diff --git a/modules/desktop_capture/differ.h b/modules/desktop_capture/differ.h index 8edce80b..0b419d2d 100644 --- a/modules/desktop_capture/differ.h +++ b/modules/desktop_capture/differ.h @@ -76,7 +76,7 @@ class Differ { int bytes_per_row_; // Diff information for each block in the image. - scoped_array<DiffInfo> diff_info_; + scoped_ptr<DiffInfo[]> diff_info_; // Dimensions and total size of diff info array. int diff_info_width_; diff --git a/modules/desktop_capture/differ_unittest.cc b/modules/desktop_capture/differ_unittest.cc index 40fde4db..da1a2146 100644 --- a/modules/desktop_capture/differ_unittest.cc +++ b/modules/desktop_capture/differ_unittest.cc @@ -200,8 +200,8 @@ class DifferTest : public testing::Test { int buffer_size_; // Previous and current screen buffers. - scoped_array<uint8_t> prev_; - scoped_array<uint8_t> curr_; + scoped_ptr<uint8_t[]> prev_; + scoped_ptr<uint8_t[]> curr_; private: DISALLOW_COPY_AND_ASSIGN(DifferTest); diff --git a/modules/desktop_capture/mouse_cursor.cc b/modules/desktop_capture/mouse_cursor.cc index 07c89f04..22a9c0ee 100644 --- a/modules/desktop_capture/mouse_cursor.cc +++ b/modules/desktop_capture/mouse_cursor.cc @@ -10,6 +10,8 @@ #include "webrtc/modules/desktop_capture/mouse_cursor.h" +#include <assert.h> + #include "webrtc/modules/desktop_capture/desktop_frame.h" namespace webrtc { diff --git a/modules/desktop_capture/screen_capture_frame_queue.cc b/modules/desktop_capture/screen_capture_frame_queue.cc index b045f052..45a3507b 100644 --- a/modules/desktop_capture/screen_capture_frame_queue.cc +++ b/modules/desktop_capture/screen_capture_frame_queue.cc @@ -10,6 +10,7 @@ #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" +#include <assert.h> #include <algorithm> #include "webrtc/modules/desktop_capture/desktop_frame.h" diff --git a/modules/desktop_capture/screen_capturer_helper.cc b/modules/desktop_capture/screen_capturer_helper.cc index 75af043c..86761c17 100644 --- a/modules/desktop_capture/screen_capturer_helper.cc +++ b/modules/desktop_capture/screen_capturer_helper.cc @@ -10,6 +10,7 @@ #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" +#include <assert.h> #include <algorithm> #include "webrtc/system_wrappers/interface/logging.h" diff --git a/modules/desktop_capture/win/cursor.cc b/modules/desktop_capture/win/cursor.cc index 11bb2dbb..00055c44 100644 --- a/modules/desktop_capture/win/cursor.cc +++ b/modules/desktop_capture/win/cursor.cc @@ -137,7 +137,7 @@ MouseCursor* CreateMouseCursorFromHCursor(HDC dc, HCURSOR cursor) { int width = bitmap_info.bmWidth; int height = bitmap_info.bmHeight; - scoped_array<uint32_t> mask_data(new uint32_t[width * height]); + scoped_ptr<uint32_t[]> mask_data(new uint32_t[width * height]); // Get pixel data from |scoped_mask| converting it to 32bpp along the way. // GetDIBits() sets the alpha component of every pixel to 0. diff --git a/modules/desktop_capture/win/cursor_unittest.cc b/modules/desktop_capture/win/cursor_unittest.cc index 9d238748..b046ace3 100644 --- a/modules/desktop_capture/win/cursor_unittest.cc +++ b/modules/desktop_capture/win/cursor_unittest.cc @@ -62,7 +62,7 @@ bool ConvertToMouseShapeAndCompare(unsigned left, unsigned right) { // Get the pixels from |scoped_color|. int size = width * height; - scoped_array<uint32_t> data(new uint32_t[size]); + scoped_ptr<uint32_t[]> data(new uint32_t[size]); EXPECT_TRUE(GetBitmapBits(scoped_color, size * sizeof(uint32_t), data.get())); // Compare the 32bpp image in |mouse_shape| with the one loaded from |right|. diff --git a/modules/modules.gyp b/modules/modules.gyp index 8fd0714e..444c665f 100644 --- a/modules/modules.gyp +++ b/modules/modules.gyp @@ -16,8 +16,7 @@ 'audio_coding/codecs/isac/main/source/isac.gypi', 'audio_coding/codecs/isac/fix/source/isacfix.gypi', 'audio_coding/codecs/pcm16b/pcm16b.gypi', - 'audio_coding/main/source/audio_coding_module.gypi', - 'audio_coding/neteq/neteq.gypi', + 'audio_coding/main/acm2/audio_coding_module.gypi', 'audio_coding/neteq4/neteq.gypi', 'audio_conference_mixer/source/audio_conference_mixer.gypi', 'audio_device/audio_device.gypi', @@ -76,7 +75,6 @@ 'desktop_capture', 'iSACFix', 'media_file', - 'NetEq', 'NetEq4', 'NetEq4TestTools', 'neteq_unittest_tools', @@ -107,7 +105,6 @@ 'audio_coding/main/acm2/call_statistics_unittest.cc', 'audio_coding/main/acm2/initial_delay_manager_unittest.cc', 'audio_coding/main/acm2/nack_unittest.cc', - 'audio_coding/main/source/acm_neteq_unittest.cc', 'audio_coding/codecs/cng/cng_unittest.cc', 'audio_coding/codecs/isac/fix/source/filters_unittest.cc', 'audio_coding/codecs/isac/fix/source/filterbanks_unittest.cc', diff --git a/modules/remote_bitrate_estimator/bwe_simulations.cc b/modules/remote_bitrate_estimator/bwe_simulations.cc index e4c67b59..6b208e49 100644 --- a/modules/remote_bitrate_estimator/bwe_simulations.cc +++ b/modules/remote_bitrate_estimator/bwe_simulations.cc @@ -8,65 +8,63 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include "gtest/gtest.h" #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test.h" #include "webrtc/test/testsupport/fileutils.h" +using std::string; + namespace webrtc { namespace testing { namespace bwe { #if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE -std::vector<BweTestConfig::EstimatorConfig> SingleEstimatorConfig() { +BweTestConfig::EstimatorConfig CreateEstimatorConfig( + int flow_id, bool plot_delay, bool plot_estimate) { static const AbsoluteSendTimeRemoteBitrateEstimatorFactory factory = AbsoluteSendTimeRemoteBitrateEstimatorFactory(); - std::vector<BweTestConfig::EstimatorConfig> result; - result.push_back(BweTestConfig::EstimatorConfig("AST", &factory, kAimdControl, - false)); - return result; + return BweTestConfig::EstimatorConfig("AST", flow_id, &factory, kAimdControl, + plot_delay, plot_estimate); } -std::vector<const PacketSenderFactory*> AdaptiveVideoSenderFactories( - uint32_t count) { - static const AdaptiveVideoPacketSenderFactory factories[] = { - AdaptiveVideoPacketSenderFactory(30.00f, 150, 0x1234, 0.13f), - AdaptiveVideoPacketSenderFactory(30.00f, 300, 0x3456, 0.26f), - AdaptiveVideoPacketSenderFactory(15.00f, 600, 0x4567, 0.39f), - }; - - assert(count <= sizeof(factories) / sizeof(factories[0])); - - std::vector<const PacketSenderFactory*> result; - for (uint32_t i = 0; i < count; ++i) { - result.push_back(&factories[i]); - } +BweTestConfig MakeAdaptiveBweTestConfig() { + BweTestConfig result; + result.estimator_configs.push_back(CreateEstimatorConfig(0, true, true)); return result; } -BweTestConfig MakeAdaptiveBweTestConfig(uint32_t sender_count) { - BweTestConfig result = { - AdaptiveVideoSenderFactories(sender_count), SingleEstimatorConfig() - }; +BweTestConfig MakeMultiFlowBweTestConfig(int flow_count) { + BweTestConfig result; + for (int i = 0; i < flow_count; ++i) { + result.estimator_configs.push_back(CreateEstimatorConfig(i, false, true)); + } return result; } // This test fixture is used to instantiate tests running with adaptive video // senders. -class BweSimulation : public BweTest { +class BweSimulation : public BweTest, + public ::testing::TestWithParam<BweTestConfig> { public: BweSimulation() : BweTest() {} virtual ~BweSimulation() {} + virtual void SetUp() { + const BweTestConfig& config = GetParam(); + SetupTestFromConfig(config); + } + private: DISALLOW_COPY_AND_ASSIGN(BweSimulation); }; INSTANTIATE_TEST_CASE_P(VideoSendersTest, BweSimulation, - ::testing::Values(MakeAdaptiveBweTestConfig(1), - MakeAdaptiveBweTestConfig(3))); + ::testing::Values(MakeAdaptiveBweTestConfig())); TEST_P(BweSimulation, SprintUplinkTest) { VerboseLogging(true); + AdaptiveVideoSender sender(0, this, 30, 300, 0, 0); RateCounterFilter counter1(this, "sender_output"); TraceBasedDeliveryFilter filter(this, "link_capacity"); RateCounterFilter counter2(this, "receiver_input"); @@ -76,6 +74,7 @@ TEST_P(BweSimulation, SprintUplinkTest) { TEST_P(BweSimulation, Verizon4gDownlinkTest) { VerboseLogging(true); + AdaptiveVideoSender sender(0, this, 30, 300, 0, 0); RateCounterFilter counter1(this, "sender_output"); TraceBasedDeliveryFilter filter(this, "link_capacity"); RateCounterFilter counter2(this, "receiver_input"); @@ -85,6 +84,7 @@ TEST_P(BweSimulation, Verizon4gDownlinkTest) { TEST_P(BweSimulation, Choke1000kbps500kbps1000kbps) { VerboseLogging(true); + AdaptiveVideoSender sender(0, this, 30, 300, 0, 0); ChokeFilter filter(this); RateCounterFilter counter(this, "receiver_input"); filter.SetCapacity(1000); @@ -98,6 +98,7 @@ TEST_P(BweSimulation, Choke1000kbps500kbps1000kbps) { TEST_P(BweSimulation, Choke200kbps30kbps200kbps) { VerboseLogging(true); + AdaptiveVideoSender sender(0, this, 30, 300, 0, 0); ChokeFilter filter(this); RateCounterFilter counter(this, "receiver_input"); filter.SetCapacity(200); @@ -111,6 +112,7 @@ TEST_P(BweSimulation, Choke200kbps30kbps200kbps) { TEST_P(BweSimulation, GoogleWifiTrace3Mbps) { VerboseLogging(true); + AdaptiveVideoSender sender(0, this, 30, 300, 0, 0); RateCounterFilter counter1(this, "sender_output"); TraceBasedDeliveryFilter filter(this, "link_capacity"); filter.SetMaxDelay(500); @@ -118,6 +120,42 @@ TEST_P(BweSimulation, GoogleWifiTrace3Mbps) { ASSERT_TRUE(filter.Init(test::ResourcePath("google-wifi-3mbps", "rx"))); RunFor(300 * 1000); } + +class MultiFlowBweSimulation : public BweSimulation { + public: + MultiFlowBweSimulation() : BweSimulation() {} + virtual ~MultiFlowBweSimulation() {} + + private: + DISALLOW_COPY_AND_ASSIGN(MultiFlowBweSimulation); +}; + +INSTANTIATE_TEST_CASE_P(VideoSendersTest, MultiFlowBweSimulation, + ::testing::Values(MakeMultiFlowBweTestConfig(3))); + +TEST_P(MultiFlowBweSimulation, SelfFairnessTest) { + VerboseLogging(true); + const int kAllFlowIds[] = {0, 1, 2}; + const size_t kNumFlows = sizeof(kAllFlowIds) / sizeof(kAllFlowIds[0]); + scoped_ptr<AdaptiveVideoSender> senders[kNumFlows]; + for (size_t i = 0; i < kNumFlows; ++i) { + senders[i].reset(new AdaptiveVideoSender(kAllFlowIds[i], this, 30, 300, 0, + 0)); + } + // Second and third flow. + ChokeFilter choke(this, CreateFlowIds(&kAllFlowIds[1], 2)); + choke.SetCapacity(1500); + // First flow. + ChokeFilter choke2(this, CreateFlowIds(&kAllFlowIds[0], 1)); + choke2.SetCapacity(1000); + + scoped_ptr<RateCounterFilter> rate_counters[kNumFlows]; + for (size_t i = 0; i < kNumFlows; ++i) { + rate_counters[i].reset(new RateCounterFilter( + this, CreateFlowIds(&kAllFlowIds[i], 1), "receiver_input")); + } + RunFor(30 * 60 * 1000); +} #endif // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE } // namespace bwe } // namespace testing diff --git a/modules/remote_bitrate_estimator/rate_statistics.cc b/modules/remote_bitrate_estimator/rate_statistics.cc index 4a9b4488..48485ffb 100644 --- a/modules/remote_bitrate_estimator/rate_statistics.cc +++ b/modules/remote_bitrate_estimator/rate_statistics.cc @@ -10,6 +10,8 @@ #include "webrtc/modules/remote_bitrate_estimator/rate_statistics.h" +#include <assert.h> + namespace webrtc { RateStatistics::RateStatistics(uint32_t window_size_ms, float scale) diff --git a/modules/remote_bitrate_estimator/rate_statistics.h b/modules/remote_bitrate_estimator/rate_statistics.h index 42966905..f97371bd 100644 --- a/modules/remote_bitrate_estimator/rate_statistics.h +++ b/modules/remote_bitrate_estimator/rate_statistics.h @@ -34,7 +34,7 @@ class RateStatistics { // Counters are kept in buckets (circular buffer), with one bucket // per millisecond. const int num_buckets_; - scoped_array<uint32_t> buckets_; + scoped_ptr<uint32_t[]> buckets_; // Total count recorded in buckets. uint32_t accumulated_count_; diff --git a/modules/remote_bitrate_estimator/remote_bitrate_estimators_test.cc b/modules/remote_bitrate_estimator/remote_bitrate_estimators_test.cc index e4fb4fa9..67b60848 100644 --- a/modules/remote_bitrate_estimator/remote_bitrate_estimators_test.cc +++ b/modules/remote_bitrate_estimator/remote_bitrate_estimators_test.cc @@ -8,72 +8,95 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include <sstream> + #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test.h" #include "webrtc/test/testsupport/fileutils.h" +#include "webrtc/test/testsupport/perf_test.h" + +using std::string; namespace webrtc { namespace testing { namespace bwe { -std::vector<const PacketSenderFactory*> VideoSenderFactories(uint32_t count) { - static const VideoPacketSenderFactory factories[] = { - VideoPacketSenderFactory(30.00f, 150, 0x1234, 0.13f), - VideoPacketSenderFactory(15.00f, 500, 0x2345, 0.16f), - VideoPacketSenderFactory(30.00f, 1200, 0x3456, 0.26f), - VideoPacketSenderFactory(7.49f, 150, 0x4567, 0.05f), - VideoPacketSenderFactory(7.50f, 150, 0x5678, 0.15f), - VideoPacketSenderFactory(7.51f, 150, 0x6789, 0.25f), - VideoPacketSenderFactory(15.02f, 150, 0x7890, 0.27f), - VideoPacketSenderFactory(15.03f, 150, 0x8901, 0.38f), - VideoPacketSenderFactory(30.02f, 150, 0x9012, 0.39f), - VideoPacketSenderFactory(30.03f, 150, 0x0123, 0.52f) - }; - - assert(count <= sizeof(factories) / sizeof(factories[0])); - - std::vector<const PacketSenderFactory*> result; - for (uint32_t i = 0; i < count; ++i) { - result.push_back(&factories[i]); - } +enum Estimator { kAbsSendTime, kTransmissionOffset }; - return result; -} - -std::vector<BweTestConfig::EstimatorConfig> EstimatorConfigs() { +BweTestConfig::EstimatorConfig EstimatorConfigs(Estimator estimator, + int flow_id) { static const RemoteBitrateEstimatorFactory factories[] = { RemoteBitrateEstimatorFactory(), AbsoluteSendTimeRemoteBitrateEstimatorFactory() }; - - std::vector<BweTestConfig::EstimatorConfig> result; - result.push_back(BweTestConfig::EstimatorConfig("TOF", &factories[0])); - result.push_back(BweTestConfig::EstimatorConfig("AST", &factories[1])); - return result; + switch (estimator) { + case kTransmissionOffset: + return BweTestConfig::EstimatorConfig("TOF", flow_id, &factories[0], + kMimdControl, false, false); + case kAbsSendTime: + return BweTestConfig::EstimatorConfig("AST", flow_id, &factories[1], + kMimdControl, false, false); + } + assert(false); + return BweTestConfig::EstimatorConfig(); } -BweTestConfig MakeBweTestConfig(uint32_t sender_count) { - BweTestConfig result = { - VideoSenderFactories(sender_count), EstimatorConfigs() - }; +struct DefaultBweTestConfig { + BweTestConfig bwe_test_config; + size_t number_of_senders; +}; + +DefaultBweTestConfig MakeBweTestConfig(uint32_t sender_count, + Estimator estimator) { + DefaultBweTestConfig result; + result.bwe_test_config.estimator_configs.push_back( + EstimatorConfigs(estimator, 0)); + result.number_of_senders = sender_count; return result; } -INSTANTIATE_TEST_CASE_P(VideoSendersTest, BweTest, - ::testing::Values(MakeBweTestConfig(1), - MakeBweTestConfig(3))); +class DefaultBweTest : public BweTest, + public ::testing::TestWithParam<DefaultBweTestConfig> { + public: + DefaultBweTest() : packet_senders_() {} + virtual ~DefaultBweTest() {} + + virtual void SetUp() { + const DefaultBweTestConfig& config = GetParam(); + SetupTestFromConfig(config.bwe_test_config); + for (size_t i = 0; i < config.number_of_senders; ++i) { + packet_senders_.push_back(new VideoSender(0, this, 30, 300, 0, 0)); + } + } + + virtual void TearDown() { + while (!packet_senders_.empty()) { + delete packet_senders_.front(); + packet_senders_.pop_front(); + } + } + + protected: + std::list<PacketSender*> packet_senders_; +}; -TEST_P(BweTest, UnlimitedSpeed) { +INSTANTIATE_TEST_CASE_P(VideoSendersTest, DefaultBweTest, + ::testing::Values(MakeBweTestConfig(1, kAbsSendTime), + MakeBweTestConfig(3, kAbsSendTime), + MakeBweTestConfig(1, kTransmissionOffset), + MakeBweTestConfig(3, kTransmissionOffset))); + +TEST_P(DefaultBweTest, UnlimitedSpeed) { VerboseLogging(false); RunFor(10 * 60 * 1000); } -TEST_P(BweTest, DISABLED_SteadyLoss) { +TEST_P(DefaultBweTest, DISABLED_SteadyLoss) { LossFilter loss(this); loss.SetLoss(20.0); RunFor(10 * 60 * 1000); } -TEST_P(BweTest, IncreasingLoss1) { +TEST_P(DefaultBweTest, IncreasingLoss1) { LossFilter loss(this); for (int i = 0; i < 76; ++i) { loss.SetLoss(i); @@ -81,13 +104,13 @@ TEST_P(BweTest, IncreasingLoss1) { } } -TEST_P(BweTest, SteadyDelay) { +TEST_P(DefaultBweTest, SteadyDelay) { DelayFilter delay(this); delay.SetDelay(1000); RunFor(10 * 60 * 1000); } -TEST_P(BweTest, DISABLED_IncreasingDelay1) { +TEST_P(DefaultBweTest, DISABLED_IncreasingDelay1) { DelayFilter delay(this); RunFor(10 * 60 * 1000); for (int i = 0; i < 30 * 2; ++i) { @@ -97,7 +120,7 @@ TEST_P(BweTest, DISABLED_IncreasingDelay1) { RunFor(10 * 60 * 1000); } -TEST_P(BweTest, IncreasingDelay2) { +TEST_P(DefaultBweTest, IncreasingDelay2) { DelayFilter delay(this); RateCounterFilter counter(this); RunFor(1 * 60 * 1000); @@ -109,7 +132,7 @@ TEST_P(BweTest, IncreasingDelay2) { RunFor(10 * 60 * 1000); } -TEST_P(BweTest, JumpyDelay1) { +TEST_P(DefaultBweTest, JumpyDelay1) { DelayFilter delay(this); RunFor(10 * 60 * 1000); for (int i = 1; i < 200; ++i) { @@ -122,14 +145,14 @@ TEST_P(BweTest, JumpyDelay1) { RunFor(10 * 60 * 1000); } -TEST_P(BweTest, SteadyJitter) { +TEST_P(DefaultBweTest, SteadyJitter) { JitterFilter jitter(this); RateCounterFilter counter(this); jitter.SetJitter(20); RunFor(2 * 60 * 1000); } -TEST_P(BweTest, IncreasingJitter1) { +TEST_P(DefaultBweTest, IncreasingJitter1) { JitterFilter jitter(this); for (int i = 0; i < 2 * 60 * 2; ++i) { jitter.SetJitter(i); @@ -138,7 +161,7 @@ TEST_P(BweTest, IncreasingJitter1) { RunFor(10 * 60 * 1000); } -TEST_P(BweTest, IncreasingJitter2) { +TEST_P(DefaultBweTest, IncreasingJitter2) { JitterFilter jitter(this); RunFor(30 * 1000); for (int i = 1; i < 51; ++i) { @@ -149,13 +172,13 @@ TEST_P(BweTest, IncreasingJitter2) { RunFor(10 * 60 * 1000); } -TEST_P(BweTest, SteadyReorder) { +TEST_P(DefaultBweTest, SteadyReorder) { ReorderFilter reorder(this); reorder.SetReorder(20.0); RunFor(10 * 60 * 1000); } -TEST_P(BweTest, IncreasingReorder1) { +TEST_P(DefaultBweTest, IncreasingReorder1) { ReorderFilter reorder(this); for (int i = 0; i < 76; ++i) { reorder.SetReorder(i); @@ -163,13 +186,13 @@ TEST_P(BweTest, IncreasingReorder1) { } } -TEST_P(BweTest, DISABLED_SteadyChoke) { +TEST_P(DefaultBweTest, DISABLED_SteadyChoke) { ChokeFilter choke(this); choke.SetCapacity(140); RunFor(10 * 60 * 1000); } -TEST_P(BweTest, DISABLED_IncreasingChoke1) { +TEST_P(DefaultBweTest, DISABLED_IncreasingChoke1) { ChokeFilter choke(this); for (int i = 1200; i >= 100; i -= 100) { choke.SetCapacity(i); @@ -177,7 +200,7 @@ TEST_P(BweTest, DISABLED_IncreasingChoke1) { } } -TEST_P(BweTest, DISABLED_IncreasingChoke2) { +TEST_P(DefaultBweTest, DISABLED_IncreasingChoke2) { ChokeFilter choke(this); RunFor(60 * 1000); for (int i = 1200; i >= 100; i -= 20) { @@ -186,7 +209,7 @@ TEST_P(BweTest, DISABLED_IncreasingChoke2) { } } -TEST_P(BweTest, DISABLED_Multi1) { +TEST_P(DefaultBweTest, DISABLED_Multi1) { DelayFilter delay(this); ChokeFilter choke(this); RateCounterFilter counter(this); @@ -201,7 +224,7 @@ TEST_P(BweTest, DISABLED_Multi1) { RunFor(5 * 60 * 1000); } -TEST_P(BweTest, Multi2) { +TEST_P(DefaultBweTest, Multi2) { ChokeFilter choke(this); JitterFilter jitter(this); RateCounterFilter counter(this); @@ -209,6 +232,108 @@ TEST_P(BweTest, Multi2) { jitter.SetJitter(120); RunFor(5 * 60 * 1000); } + +// This test fixture is used to instantiate tests running with adaptive video +// senders. +class BweFeedbackTest : public BweTest, + public ::testing::TestWithParam<BweTestConfig> { + public: + BweFeedbackTest() : BweTest() {} + virtual ~BweFeedbackTest() {} + + virtual void SetUp() { + BweTestConfig config; + config.estimator_configs.push_back(EstimatorConfigs(kAbsSendTime, 0)); + SetupTestFromConfig(config); + } + + void PrintResults(double max_throughput_kbps, Stats<double> throughput_kbps, + Stats<double> delay_ms) { + double utilization = throughput_kbps.GetMean() / max_throughput_kbps; + webrtc::test::PrintResult("BwePerformance", + GetTestName(), + "Utilization", + utilization * 100.0, + "%", + false); + std::stringstream ss; + ss << throughput_kbps.GetStdDev() / throughput_kbps.GetMean(); + webrtc::test::PrintResult("BwePerformance", + GetTestName(), + "Utilization var coeff", + ss.str(), + "", + false); + webrtc::test::PrintResult("BwePerformance", + GetTestName(), + "Average delay", + delay_ms.AsString(), + "ms", + false); + } + + private: + DISALLOW_COPY_AND_ASSIGN(BweFeedbackTest); +}; + +TEST_F(BweFeedbackTest, Choke1000kbps500kbps1000kbps) { + AdaptiveVideoSender sender(0, this, 30, 300, 0, 0); + ChokeFilter filter(this); + RateCounterFilter counter(this, "receiver_input"); + const int kHighCapacityKbps = 1000; + const int kLowCapacityKbps = 500; + filter.SetCapacity(kHighCapacityKbps); + filter.SetMaxDelay(500); + RunFor(60 * 1000); + filter.SetCapacity(kLowCapacityKbps); + RunFor(60 * 1000); + filter.SetCapacity(kHighCapacityKbps); + RunFor(60 * 1000); + PrintResults((2 * kHighCapacityKbps + kLowCapacityKbps) / 3.0, + counter.GetBitrateStats(), filter.GetDelayStats()); +} + +TEST_F(BweFeedbackTest, Choke200kbps30kbps200kbps) { + AdaptiveVideoSender sender(0, this, 30, 300, 0, 0); + ChokeFilter filter(this); + RateCounterFilter counter(this, "receiver_input"); + const int kHighCapacityKbps = 200; + const int kLowCapacityKbps = 30; + filter.SetCapacity(kHighCapacityKbps); + filter.SetMaxDelay(500); + RunFor(60 * 1000); + filter.SetCapacity(kLowCapacityKbps); + RunFor(60 * 1000); + filter.SetCapacity(kHighCapacityKbps); + RunFor(60 * 1000); + + PrintResults((2 * kHighCapacityKbps + kLowCapacityKbps) / 3.0, + counter.GetBitrateStats(), filter.GetDelayStats()); +} + +TEST_F(BweFeedbackTest, Verizon4gDownlinkTest) { + AdaptiveVideoSender sender(0, this, 30, 300, 0, 0); + RateCounterFilter counter1(this, "sender_output"); + TraceBasedDeliveryFilter filter(this, "link_capacity"); + RateCounterFilter counter2(this, "receiver_input"); + ASSERT_TRUE(filter.Init(test::ResourcePath("verizon4g-downlink", "rx"))); + RunFor(22 * 60 * 1000); + PrintResults(filter.GetBitrateStats().GetMean(), counter2.GetBitrateStats(), + filter.GetDelayStats()); +} + +// webrtc:3277 +TEST_F(BweFeedbackTest, DISABLED_GoogleWifiTrace3Mbps) { + AdaptiveVideoSender sender(0, this, 30, 300, 0, 0); + RateCounterFilter counter1(this, "sender_output"); + TraceBasedDeliveryFilter filter(this, "link_capacity"); + filter.SetMaxDelay(500); + RateCounterFilter counter2(this, "receiver_input"); + ASSERT_TRUE(filter.Init(test::ResourcePath("google-wifi-3mbps", "rx"))); + RunFor(300 * 1000); + PrintResults(filter.GetBitrateStats().GetMean(), counter2.GetBitrateStats(), + filter.GetDelayStats()); +} } // namespace bwe } // namespace testing } // namespace webrtc diff --git a/modules/remote_bitrate_estimator/test/bwe_test.cc b/modules/remote_bitrate_estimator/test/bwe_test.cc index c5002910..90ce6a3e 100644 --- a/modules/remote_bitrate_estimator/test/bwe_test.cc +++ b/modules/remote_bitrate_estimator/test/bwe_test.cc @@ -23,44 +23,40 @@ namespace webrtc { namespace testing { namespace bwe { -namespace stl_helpers { -template<typename T> void DeleteElements(T* container) { - if (!container) return; - for (typename T::iterator it = container->begin(); it != container->end(); - ++it) { - delete *it; - } - container->clear(); -} -} // namespace stl_helpers - -class BweTest::TestedEstimator : public RemoteBitrateObserver { +class TestedEstimator : public RemoteBitrateObserver { public: static const uint32_t kRemoteBitrateEstimatorMinBitrateBps = 30000; + static const int kDelayPlotIntervalMs = 100; TestedEstimator(const string& test_name, const BweTestConfig::EstimatorConfig& config) : debug_name_(config.debug_name), + delay_log_prefix_(), + estimate_log_prefix_(), + last_delay_plot_ms_(0), + plot_delay_(config.plot_delay), + plot_estimate_(config.plot_estimate), clock_(0), stats_(), - relative_estimator_stats_(), latest_estimate_bps_(-1), estimator_(config.estimator_factory->Create( this, &clock_, config.control_type, kRemoteBitrateEstimatorMinBitrateBps)), - relative_estimator_(NULL), baseline_(BaseLineFileInterface::Create(test_name + "_" + debug_name_, config.update_baseline)) { assert(estimator_.get()); assert(baseline_.get()); + // Setup the prefix strings used when logging. + std::stringstream ss; + ss << "Delay_" << config.flow_id << "#2"; + delay_log_prefix_ = ss.str(); + ss.str(""); + ss << "Estimate_" << config.flow_id << "#1"; + estimate_log_prefix_ = ss.str(); // Default RTT in RemoteRateControl is 200 ms ; 50 ms is more realistic. estimator_->OnRttUpdate(50); } - void SetRelativeEstimator(TestedEstimator* relative_estimator) { - relative_estimator_ = relative_estimator; - } - void EatPacket(const Packet& packet) { BWE_TEST_LOGGING_CONTEXT(debug_name_); @@ -70,9 +66,15 @@ class BweTest::TestedEstimator : public RemoteBitrateObserver { // time once packet reaches the estimator. int64_t packet_time_ms = (packet.send_time_us() + 500) / 1000; BWE_TEST_LOGGING_TIME(packet_time_ms); - BWE_TEST_LOGGING_PLOT("Delay_#2", clock_.TimeInMilliseconds(), - packet_time_ms - - (packet.creation_time_us() + 500) / 1000); + if (plot_delay_) { + if (clock_.TimeInMilliseconds() - last_delay_plot_ms_ > + kDelayPlotIntervalMs) { + BWE_TEST_LOGGING_PLOT(delay_log_prefix_, clock_.TimeInMilliseconds(), + packet_time_ms - + (packet.creation_time_us() + 500) / 1000); + last_delay_plot_ms_ = clock_.TimeInMilliseconds(); + } + } int64_t step_ms = estimator_->TimeUntilNextProcess(); while ((clock_.TimeInMilliseconds() + step_ms) < packet_time_ms) { @@ -97,14 +99,9 @@ class BweTest::TestedEstimator : public RemoteBitrateObserver { double estimated_kbps = static_cast<double>(estimated_bps) / 1000.0; stats_.Push(estimated_kbps); - BWE_TEST_LOGGING_PLOT("Estimate_#1", clock_.TimeInMilliseconds(), - estimated_kbps); - uint32_t relative_estimate_bps = 0; - if (relative_estimator_ && - relative_estimator_->LatestEstimate(&relative_estimate_bps)) { - double relative_estimate_kbps = - static_cast<double>(relative_estimate_bps) / 1000.0; - relative_estimator_stats_.Push(estimated_kbps - relative_estimate_kbps); + if (plot_estimate_) { + BWE_TEST_LOGGING_PLOT(estimate_log_prefix_, clock_.TimeInMilliseconds(), + estimated_kbps); } return true; } @@ -115,10 +112,6 @@ class BweTest::TestedEstimator : public RemoteBitrateObserver { BWE_TEST_LOGGING_CONTEXT(debug_name_); BWE_TEST_LOGGING_CONTEXT("Mean"); stats_.Log("kbps"); - if (relative_estimator_) { - BWE_TEST_LOGGING_CONTEXT("Diff"); - relative_estimator_stats_.Log("kbps"); - } } void VerifyOrWriteBaseline() { @@ -144,145 +137,217 @@ class BweTest::TestedEstimator : public RemoteBitrateObserver { } string debug_name_; + string delay_log_prefix_; + string estimate_log_prefix_; + int64_t last_delay_plot_ms_; + bool plot_delay_; + bool plot_estimate_; SimulatedClock clock_; Stats<double> stats_; - Stats<double> relative_estimator_stats_; int64_t latest_estimate_bps_; scoped_ptr<RemoteBitrateEstimator> estimator_; - TestedEstimator* relative_estimator_; scoped_ptr<BaseLineFileInterface> baseline_; DISALLOW_IMPLICIT_CONSTRUCTORS(TestedEstimator); }; +class PacketProcessorRunner { + public: + explicit PacketProcessorRunner(PacketProcessor* processor) + : processor_(processor) {} + + bool HasProcessor(const PacketProcessor* processor) const { + return processor == processor_; + } + + void RunFor(int64_t time_ms, int64_t time_now_ms, Packets* in_out) { + Packets to_process; + FindPacketsToProcess(processor_->flow_ids(), in_out, &to_process); + processor_->RunFor(time_ms, &to_process); + QueuePackets(&to_process, time_now_ms * 1000); + if (!to_process.empty()) { + processor_->Plot((to_process.back().send_time_us() + 500) / 1000); + } + in_out->merge(to_process); + } + + private: + void FindPacketsToProcess(const FlowIds& flow_ids, Packets* in, + Packets* out) { + assert(out->empty()); + for (Packets::iterator it = in->begin(); it != in->end();) { + // TODO(holmer): Further optimize this by looking for consecutive flow ids + // in the packet list and only doing the binary search + splice once for a + // sequence. + if (std::binary_search(flow_ids.begin(), flow_ids.end(), it->flow_id())) { + Packets::iterator next = it; + ++next; + out->splice(out->end(), *in, it); + it = next; + } else { + ++it; + } + } + } + + void QueuePackets(Packets* batch, int64_t end_of_batch_time_us) { + queue_.merge(*batch); + if (queue_.empty()) { + return; + } + Packets to_transfer; + Packets::iterator it = queue_.begin(); + for (; it != queue_.end(); ++it) { + if (it->send_time_us() > end_of_batch_time_us) { + break; + } + } + to_transfer.splice(to_transfer.begin(), queue_, queue_.begin(), it); + batch->merge(to_transfer); + } + + PacketProcessor* processor_; + Packets queue_; +}; + BweTest::BweTest() : run_time_ms_(0), + time_now_ms_(-1), simulation_interval_ms_(-1), - previous_packets_(), - packet_senders_(), estimators_(), processors_() { } BweTest::~BweTest() { - stl_helpers::DeleteElements(&estimators_); - stl_helpers::DeleteElements(&packet_senders_); + BWE_TEST_LOGGING_GLOBAL_ENABLE(true); + for (EstimatorMap::iterator it = estimators_.begin(); it != estimators_.end(); + ++it) { + it->second->VerifyOrWriteBaseline(); + it->second->LogStats(); + } + BWE_TEST_LOGGING_GLOBAL_CONTEXT(""); + + for (EstimatorMap::iterator it = estimators_.begin(); + it != estimators_.end(); ++it) { + delete it->second; + } } -void BweTest::SetUp() { +void BweTest::SetupTestFromConfig(const BweTestConfig& config) { const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info(); string test_name = string(test_info->test_case_name()) + "_" + string(test_info->name()); BWE_TEST_LOGGING_GLOBAL_CONTEXT(test_name); - - const BweTestConfig& config = GetParam(); - - uint32_t total_capacity = 0; - for (vector<const PacketSenderFactory*>::const_iterator it = - config.sender_factories.begin(); it != config.sender_factories.end(); - ++it) { - PacketSender* sender = (*it)->Create(); - assert(sender); - total_capacity += sender->GetCapacityKbps(); - packet_senders_.push_back(sender); - processors_.push_back(sender); + for (vector<BweTestConfig::EstimatorConfig>::const_iterator it = + config.estimator_configs.begin(); it != config.estimator_configs.end(); + ++it) { + estimators_.insert(std::make_pair(it->flow_id, new TestedEstimator( + test_name, *it))); } - BWE_TEST_LOGGING_LOG1("RequiredLinkCapacity", "%d kbps", total_capacity) - - // Set simulation interval from first packet sender. - if (packet_senders_.size() > 0) { - simulation_interval_ms_ = packet_senders_[0]->GetFeedbackIntervalMs(); - } - - for (vector<BweTestConfig::EstimatorConfig>:: const_iterator it = - config.estimator_configs.begin(); it != config.estimator_configs.end(); - ++it) { - estimators_.push_back(new TestedEstimator(test_name, *it)); - } - if (estimators_.size() > 1) { - // Set all estimators as relative to the first one. - for (uint32_t i = 1; i < estimators_.size(); ++i) { - estimators_[i]->SetRelativeEstimator(estimators_[0]); - } - } - BWE_TEST_LOGGING_GLOBAL_ENABLE(false); } -void BweTest::TearDown() { - BWE_TEST_LOGGING_GLOBAL_ENABLE(true); - - for (vector<TestedEstimator*>::iterator eit = estimators_.begin(); - eit != estimators_.end(); ++eit) { - (*eit)->VerifyOrWriteBaseline(); - (*eit)->LogStats(); - } - - BWE_TEST_LOGGING_GLOBAL_CONTEXT(""); -} - -void BweTest::AddPacketProcessor( - PacketProcessor* processor) { +void BweTest::AddPacketProcessor(PacketProcessor* processor, bool is_sender) { assert(processor); - processors_.push_back(processor); + processors_.push_back(PacketProcessorRunner(processor)); + if (is_sender) { + senders_.push_back(static_cast<PacketSender*>(processor)); + } + const FlowIds& flow_ids = processor->flow_ids(); + for (size_t i = 0; i < flow_ids.size(); ++i) { + assert(estimators_.count(flow_ids[i]) == 1); + } } void BweTest::RemovePacketProcessor( PacketProcessor* processor) { - vector<PacketProcessor*>::iterator it = - std::find(processors_.begin(), processors_.end(), processor); - assert(it != processors_.end()); - processors_.erase(it); + for (vector<PacketProcessorRunner>::iterator it = processors_.begin(); + it != processors_.end(); ++it) { + if (it->HasProcessor(processor)) { + processors_.erase(it); + return; + } + } + assert(false); } void BweTest::VerboseLogging(bool enable) { BWE_TEST_LOGGING_GLOBAL_ENABLE(enable); } +void BweTest::GiveFeedbackToAffectedSenders(int flow_id, + TestedEstimator* estimator) { + std::list<PacketSender*> affected_senders; + for (std::vector<PacketSender*>::iterator psit = + senders_.begin(); psit != senders_.end(); ++psit) { + const FlowIds& flow_ids = (*psit)->flow_ids(); + if (std::binary_search(flow_ids.begin(), flow_ids.end(), flow_id)) { + affected_senders.push_back(*psit); + } + } + PacketSender::Feedback feedback = {0}; + if (estimator->CheckEstimate(&feedback) && !affected_senders.empty()) { + // Allocate the bitrate evenly between the senders. + feedback.estimated_bps /= affected_senders.size(); + for (std::list<PacketSender*>::iterator psit = affected_senders.begin(); + psit != affected_senders.end(); ++psit) { + (*psit)->GiveFeedback(feedback); + } + } +} + void BweTest::RunFor(int64_t time_ms) { - for (run_time_ms_ += time_ms; run_time_ms_ >= simulation_interval_ms_; - run_time_ms_ -= simulation_interval_ms_) { + // Set simulation interval from first packet sender. + // TODO(holmer): Support different feedback intervals for different flows. + if (!senders_.empty()) { + simulation_interval_ms_ = senders_[0]->GetFeedbackIntervalMs(); + } + assert(simulation_interval_ms_ > 0); + if (time_now_ms_ == -1) { + time_now_ms_ = simulation_interval_ms_; + } + for (run_time_ms_ += time_ms; + time_now_ms_ <= run_time_ms_ - simulation_interval_ms_; + time_now_ms_ += simulation_interval_ms_) { Packets packets; - for (vector<PacketProcessor*>::const_iterator it = + for (vector<PacketProcessorRunner>::iterator it = processors_.begin(); it != processors_.end(); ++it) { - (*it)->RunFor(simulation_interval_ms_, &packets); - if (!packets.empty()) { - (*it)->Plot((packets.back().send_time_us() + 500) / 1000); - } + it->RunFor(simulation_interval_ms_, time_now_ms_, &packets); } // Verify packets are in order between batches. - if (!packets.empty() && !previous_packets_.empty()) { - packets.splice(packets.begin(), previous_packets_, - --previous_packets_.end()); - ASSERT_TRUE(IsTimeSorted(packets)); - packets.erase(packets.begin()); + if (!packets.empty()) { + if (!previous_packets_.empty()) { + packets.splice(packets.begin(), previous_packets_, + --previous_packets_.end()); + ASSERT_TRUE(IsTimeSorted(packets)); + packets.erase(packets.begin()); + } + ASSERT_LE(packets.front().send_time_us(), time_now_ms_ * 1000); + ASSERT_LE(packets.back().send_time_us(), time_now_ms_ * 1000); } else { ASSERT_TRUE(IsTimeSorted(packets)); } - for (PacketsConstIt pit = packets.begin(); pit != packets.end(); ++pit) { - for (vector<TestedEstimator*>::iterator eit = estimators_.begin(); - eit != estimators_.end(); ++eit) { - (*eit)->EatPacket(*pit); - } + for (PacketsConstIt it = packets.begin(); it != packets.end(); ++it) { + EstimatorMap::iterator est_it = estimators_.find(it->flow_id()); + ASSERT_TRUE(est_it != estimators_.end()); + est_it->second->EatPacket(*it); } - previous_packets_.swap(packets); - - for (vector<TestedEstimator*>::iterator eit = estimators_.begin(); - eit != estimators_.end(); ++eit) { - PacketSender::Feedback feedback = {0}; - if ((*eit)->CheckEstimate(&feedback)) { - for (vector<PacketSender*>::iterator psit = packet_senders_.begin(); - psit != packet_senders_.end(); ++psit) { - (*psit)->GiveFeedback(feedback); - } - } + for (EstimatorMap::iterator est_it = estimators_.begin(); + est_it != estimators_.end(); ++est_it) { + GiveFeedbackToAffectedSenders(est_it->first, est_it->second); } } } + +string BweTest::GetTestName() const { + const ::testing::TestInfo* const test_info = + ::testing::UnitTest::GetInstance()->current_test_info(); + return string(test_info->name()); +} } // namespace bwe } // namespace testing } // namespace webrtc diff --git a/modules/remote_bitrate_estimator/test/bwe_test.h b/modules/remote_bitrate_estimator/test/bwe_test.h index cb708f42..ef351797 100644 --- a/modules/remote_bitrate_estimator/test/bwe_test.h +++ b/modules/remote_bitrate_estimator/test/bwe_test.h @@ -8,6 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include <map> #include <string> #include <vector> #include "gtest/gtest.h" @@ -26,60 +27,96 @@ struct BweTestConfig { struct EstimatorConfig { EstimatorConfig() : debug_name(), + flow_id(0), estimator_factory(NULL), control_type(kMimdControl), - update_baseline(false) { + update_baseline(false), + plot_delay(true), + plot_estimate(true) { } EstimatorConfig(std::string debug_name, - const RemoteBitrateEstimatorFactory* estimator_factory) + int flow_id, + const RemoteBitrateEstimatorFactory* estimator_factory, + bool plot_delay, + bool plot_estimate) : debug_name(debug_name), + flow_id(flow_id), estimator_factory(estimator_factory), control_type(kMimdControl), - update_baseline(false) { + update_baseline(false), + plot_delay(plot_delay), + plot_estimate(plot_estimate) { + } + EstimatorConfig(std::string debug_name, + int flow_id, + const RemoteBitrateEstimatorFactory* estimator_factory, + RateControlType control_type, + bool plot_delay, + bool plot_estimate) + : debug_name(debug_name), + flow_id(flow_id), + estimator_factory(estimator_factory), + control_type(control_type), + update_baseline(false), + plot_delay(plot_delay), + plot_estimate(plot_estimate) { } EstimatorConfig(std::string debug_name, + int flow_id, const RemoteBitrateEstimatorFactory* estimator_factory, RateControlType control_type, bool update_baseline) : debug_name(debug_name), + flow_id(flow_id), estimator_factory(estimator_factory), control_type(control_type), - update_baseline(update_baseline) { + update_baseline(update_baseline), + plot_delay(false), + plot_estimate(false) { } std::string debug_name; + int flow_id; const RemoteBitrateEstimatorFactory* estimator_factory; RateControlType control_type; bool update_baseline; + bool plot_delay; + bool plot_estimate; }; - std::vector<const PacketSenderFactory*> sender_factories; std::vector<EstimatorConfig> estimator_configs; }; -class BweTest : public ::testing::TestWithParam<BweTestConfig>, - public PacketProcessorListener { +class TestedEstimator; +class PacketProcessorRunner; + +class BweTest : public PacketProcessorListener { public: BweTest(); virtual ~BweTest(); - virtual void SetUp(); - virtual void TearDown(); - virtual void AddPacketProcessor(PacketProcessor* processor); + virtual void AddPacketProcessor(PacketProcessor* processor, bool is_sender); virtual void RemovePacketProcessor(PacketProcessor* processor); protected: + void SetupTestFromConfig(const BweTestConfig& config); void VerboseLogging(bool enable); void RunFor(int64_t time_ms); + std::string GetTestName() const; private: - class TestedEstimator; + typedef std::map<int, TestedEstimator*> EstimatorMap; + + void FindPacketsToProcess(const FlowIds& flow_ids, Packets* in, + Packets* out); + void GiveFeedbackToAffectedSenders(int flow_id, TestedEstimator* estimator); int64_t run_time_ms_; + int64_t time_now_ms_; int64_t simulation_interval_ms_; + EstimatorMap estimators_; Packets previous_packets_; - std::vector<PacketSender*> packet_senders_; - std::vector<TestedEstimator*> estimators_; - std::vector<PacketProcessor*> processors_; + std::vector<PacketSender*> senders_; + std::vector<PacketProcessorRunner> processors_; DISALLOW_COPY_AND_ASSIGN(BweTest); }; diff --git a/modules/remote_bitrate_estimator/test/bwe_test_framework.cc b/modules/remote_bitrate_estimator/test/bwe_test_framework.cc index 893b6fee..b3cd7db9 100644 --- a/modules/remote_bitrate_estimator/test/bwe_test_framework.cc +++ b/modules/remote_bitrate_estimator/test/bwe_test_framework.cc @@ -45,6 +45,11 @@ class DelayCapHelper { DISALLOW_COPY_AND_ASSIGN(DelayCapHelper); }; +const FlowIds CreateFlowIds(const int *flow_ids_array, size_t num_flow_ids) { + FlowIds flow_ids(&flow_ids_array[0], flow_ids_array + num_flow_ids); + return flow_ids; +} + class RateCounter { public: RateCounter() @@ -115,26 +120,29 @@ int Random::Gaussian(int mean, int standard_deviation) { } Packet::Packet() - : creation_time_us_(-1), + : flow_id_(0), + creation_time_us_(-1), send_time_us_(-1), payload_size_(0) { - memset(&header_, 0, sizeof(header_)); + memset(&header_, 0, sizeof(header_)); } -Packet::Packet(int64_t send_time_us, uint32_t payload_size, +Packet::Packet(int flow_id, int64_t send_time_us, uint32_t payload_size, const RTPHeader& header) - : creation_time_us_(send_time_us), - send_time_us_(send_time_us), - payload_size_(payload_size), - header_(header) { + : flow_id_(flow_id), + creation_time_us_(send_time_us), + send_time_us_(send_time_us), + payload_size_(payload_size), + header_(header) { } Packet::Packet(int64_t send_time_us, uint32_t sequence_number) - : creation_time_us_(send_time_us), + : flow_id_(0), + creation_time_us_(send_time_us), send_time_us_(send_time_us), payload_size_(0) { - memset(&header_, 0, sizeof(header_)); - header_.sequenceNumber = sequence_number; + memset(&header_, 0, sizeof(header_)); + header_.sequenceNumber = sequence_number; } bool Packet::operator<(const Packet& rhs) const { @@ -157,10 +165,20 @@ bool IsTimeSorted(const Packets& packets) { return true; } -PacketProcessor::PacketProcessor(PacketProcessorListener* listener) - : listener_(listener) { +PacketProcessor::PacketProcessor(PacketProcessorListener* listener, + bool is_sender) + : listener_(listener), flow_ids_(1, 0) { + if (listener_) { + listener_->AddPacketProcessor(this, is_sender); + } +} + +PacketProcessor::PacketProcessor(PacketProcessorListener* listener, + const FlowIds& flow_ids, + bool is_sender) + : listener_(listener), flow_ids_(flow_ids) { if (listener_) { - listener_->AddPacketProcessor(this); + listener_->AddPacketProcessor(this, is_sender); } } @@ -171,20 +189,36 @@ PacketProcessor::~PacketProcessor() { } RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener) - : PacketProcessor(listener), + : PacketProcessor(listener, false), rate_counter_(new RateCounter()), - pps_stats_(), + packets_per_second_stats_(), kbps_stats_(), name_("") {} RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener, const std::string& name) - : PacketProcessor(listener), + : PacketProcessor(listener, false), rate_counter_(new RateCounter()), - pps_stats_(), + packets_per_second_stats_(), kbps_stats_(), name_(name) {} +RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener, + const FlowIds& flow_ids, + const std::string& name) + : PacketProcessor(listener, flow_ids, false), + rate_counter_(new RateCounter()), + packets_per_second_stats_(), + kbps_stats_(), + name_(name) { + std::stringstream ss; + ss << name_ << "_"; + for (size_t i = 0; i < flow_ids.size(); ++i) { + ss << flow_ids[i] << ","; + } + name_ = ss.str(); +} + RateCounterFilter::~RateCounterFilter() { LogStats(); } @@ -199,7 +233,7 @@ uint32_t RateCounterFilter::bits_per_second() const { void RateCounterFilter::LogStats() { BWE_TEST_LOGGING_CONTEXT("RateCounterFilter"); - pps_stats_.Log("pps"); + packets_per_second_stats_.Log("pps"); kbps_stats_.Log("kbps"); } @@ -218,12 +252,12 @@ void RateCounterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { for (PacketsConstIt it = in_out->begin(); it != in_out->end(); ++it) { rate_counter_->UpdateRates(it->send_time_us(), it->payload_size()); } - pps_stats_.Push(rate_counter_->packets_per_second()); + packets_per_second_stats_.Push(rate_counter_->packets_per_second()); kbps_stats_.Push(rate_counter_->bits_per_second() / 1000.0); } LossFilter::LossFilter(PacketProcessorListener* listener) - : PacketProcessor(listener), + : PacketProcessor(listener, false), random_(0x12345678), loss_fraction_(0.0f) { } @@ -248,7 +282,7 @@ void LossFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { } DelayFilter::DelayFilter(PacketProcessorListener* listener) - : PacketProcessor(listener), + : PacketProcessor(listener, false), delay_us_(0), last_send_time_us_(0) { } @@ -270,7 +304,7 @@ void DelayFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { } JitterFilter::JitterFilter(PacketProcessorListener* listener) - : PacketProcessor(listener), + : PacketProcessor(listener, false), random_(0x89674523), stddev_jitter_us_(0), last_send_time_us_(0) { @@ -295,7 +329,7 @@ void JitterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { } ReorderFilter::ReorderFilter(PacketProcessorListener* listener) - : PacketProcessor(listener), + : PacketProcessor(listener, false), random_(0x27452389), reorder_fraction_(0.0f) { } @@ -327,7 +361,15 @@ void ReorderFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) { } ChokeFilter::ChokeFilter(PacketProcessorListener* listener) - : PacketProcessor(listener), + : PacketProcessor(listener, false), + kbps_(1200), + last_send_time_us_(0), + delay_cap_helper_(new DelayCapHelper()) { +} + +ChokeFilter::ChokeFilter(PacketProcessorListener* listener, + const FlowIds& flow_ids) + : PacketProcessor(listener, flow_ids, false), kbps_(1200), last_send_time_us_(0), delay_cap_helper_(new DelayCapHelper()) { @@ -369,26 +411,30 @@ Stats<double> ChokeFilter::GetDelayStats() const { TraceBasedDeliveryFilter::TraceBasedDeliveryFilter( PacketProcessorListener* listener) - : PacketProcessor(listener), + : PacketProcessor(listener, false), current_offset_us_(0), delivery_times_us_(), next_delivery_it_(), local_time_us_(-1), rate_counter_(new RateCounter), name_(""), - delay_cap_helper_(new DelayCapHelper()) {} + delay_cap_helper_(new DelayCapHelper()), + packets_per_second_stats_(), + kbps_stats_() {} TraceBasedDeliveryFilter::TraceBasedDeliveryFilter( PacketProcessorListener* listener, const std::string& name) - : PacketProcessor(listener), + : PacketProcessor(listener, false), current_offset_us_(0), delivery_times_us_(), next_delivery_it_(), local_time_us_(-1), rate_counter_(new RateCounter), name_(name), - delay_cap_helper_(new DelayCapHelper()) {} + delay_cap_helper_(new DelayCapHelper()), + packets_per_second_stats_(), + kbps_stats_() {} TraceBasedDeliveryFilter::~TraceBasedDeliveryFilter() { } @@ -449,6 +495,8 @@ void TraceBasedDeliveryFilter::RunFor(int64_t time_ms, Packets* in_out) { } ++it; } + packets_per_second_stats_.Push(rate_counter_->packets_per_second()); + kbps_stats_.Push(rate_counter_->bits_per_second() / 1000.0); } void TraceBasedDeliveryFilter::SetMaxDelay(int max_delay_ms) { @@ -459,6 +507,10 @@ Stats<double> TraceBasedDeliveryFilter::GetDelayStats() const { return delay_cap_helper_->delay_stats(); } +Stats<double> TraceBasedDeliveryFilter::GetBitrateStats() const { + return kbps_stats_; +} + void TraceBasedDeliveryFilter::ProceedToNextSlot() { if (*next_delivery_it_ <= local_time_us_) { ++next_delivery_it_; @@ -478,12 +530,18 @@ void TraceBasedDeliveryFilter::ProceedToNextSlot() { } PacketSender::PacketSender(PacketProcessorListener* listener) - : PacketProcessor(listener) { + : PacketProcessor(listener, true) {} + +PacketSender::PacketSender(PacketProcessorListener* listener, + const FlowIds& flow_ids) + : PacketProcessor(listener, flow_ids, true) { + } -VideoSender::VideoSender(PacketProcessorListener* listener, float fps, - uint32_t kbps, uint32_t ssrc, float first_frame_offset) - : PacketSender(listener), +VideoSender::VideoSender(int flow_id, PacketProcessorListener* listener, + float fps, uint32_t kbps, uint32_t ssrc, + float first_frame_offset) + : PacketSender(listener, FlowIds(1, flow_id)), kMaxPayloadSizeBytes(1200), kTimestampBase(0xff80ff00ul), frame_period_ms_(1000.0 / fps), @@ -506,7 +564,7 @@ uint32_t VideoSender::GetCapacityKbps() const { void VideoSender::RunFor(int64_t time_ms, Packets* in_out) { assert(in_out); now_ms_ += time_ms; - Packets newPackets; + Packets new_packets; while (now_ms_ >= next_frame_ms_) { prototype_header_.sequenceNumber++; prototype_header_.timestamp = kTimestampBase + @@ -524,21 +582,23 @@ void VideoSender::RunFor(int64_t time_ms, Packets* in_out) { uint32_t payload_size = frame_size_bytes_; while (payload_size > 0) { uint32_t size = std::min(kMaxPayloadSizeBytes, payload_size); - newPackets.push_back(Packet(send_time_us, size, prototype_header_)); + new_packets.push_back(Packet(flow_ids()[0], send_time_us, size, + prototype_header_)); payload_size -= size; } next_frame_ms_ += frame_period_ms_; } - in_out->merge(newPackets); + in_out->merge(new_packets); } -AdaptiveVideoSender::AdaptiveVideoSender(PacketProcessorListener* listener, +AdaptiveVideoSender::AdaptiveVideoSender(int flow_id, + PacketProcessorListener* listener, float fps, uint32_t kbps, uint32_t ssrc, float first_frame_offset) - : VideoSender(listener, fps, kbps, ssrc, first_frame_offset) {} + : VideoSender(flow_id, listener, fps, kbps, ssrc, first_frame_offset) {} void AdaptiveVideoSender::GiveFeedback(const PacketSender::Feedback& feedback) { bytes_per_second_ = feedback.estimated_bps / 8; diff --git a/modules/remote_bitrate_estimator/test/bwe_test_framework.h b/modules/remote_bitrate_estimator/test/bwe_test_framework.h index 5302ba3d..8af07f91 100644 --- a/modules/remote_bitrate_estimator/test/bwe_test_framework.h +++ b/modules/remote_bitrate_estimator/test/bwe_test_framework.h @@ -17,6 +17,7 @@ #include <algorithm> #include <list> #include <numeric> +#include <sstream> #include <string> #include <vector> @@ -31,6 +32,10 @@ namespace bwe { class DelayCapHelper; class RateCounter; + +typedef std::vector<int> FlowIds; +const FlowIds CreateFlowIds(const int *flow_ids_array, size_t num_flow_ids); + template<typename T> class Stats { public: Stats() @@ -84,6 +89,13 @@ template<typename T> class Stats { return max_; } + std::string AsString() { + std::stringstream ss; + ss << (GetMean() >= 0 ? GetMean() : -1) << ", " << + (GetStdDev() >= 0 ? GetStdDev() : -1); + return ss.str(); + } + void Log(const std::string& units) { BWE_TEST_LOGGING_LOG5("", "%f %s\t+/-%f\t[%f,%f]", GetMean(), units.c_str(), GetStdDev(), GetMin(), GetMax()); @@ -139,12 +151,13 @@ class Random { class Packet { public: Packet(); - Packet(int64_t send_time_us, uint32_t payload_size, + Packet(int flow_id, int64_t send_time_us, uint32_t payload_size, const RTPHeader& header); Packet(int64_t send_time_us, uint32_t sequence_number); bool operator<(const Packet& rhs) const; + int flow_id() const { return flow_id_; } int64_t creation_time_us() const { return creation_time_us_; } void set_send_time_us(int64_t send_time_us); int64_t send_time_us() const { return send_time_us_; } @@ -152,6 +165,7 @@ class Packet { const RTPHeader& header() const { return header_; } private: + int flow_id_; int64_t creation_time_us_; // Time when the packet was created. int64_t send_time_us_; // Time the packet left last processor touching it. uint32_t payload_size_; // Size of the (non-existent, simulated) payload. @@ -170,13 +184,16 @@ class PacketProcessorListener { public: virtual ~PacketProcessorListener() {} - virtual void AddPacketProcessor(PacketProcessor* processor) = 0; + virtual void AddPacketProcessor(PacketProcessor* processor, + bool is_sender) = 0; virtual void RemovePacketProcessor(PacketProcessor* processor) = 0; }; class PacketProcessor { public: - explicit PacketProcessor(PacketProcessorListener* listener); + PacketProcessor(PacketProcessorListener* listener, bool is_sender); + PacketProcessor(PacketProcessorListener* listener, const FlowIds& flow_ids, + bool is_sender); virtual ~PacketProcessor(); // Called after each simulation batch to allow the processor to plot any @@ -188,8 +205,11 @@ class PacketProcessor { // |send_time_us_|. The simulation time |time_ms| is optional to use. virtual void RunFor(int64_t time_ms, Packets* in_out) = 0; + const FlowIds& flow_ids() const { return flow_ids_; } + private: PacketProcessorListener* listener_; + FlowIds flow_ids_; DISALLOW_COPY_AND_ASSIGN(PacketProcessor); }; @@ -199,6 +219,9 @@ class RateCounterFilter : public PacketProcessor { explicit RateCounterFilter(PacketProcessorListener* listener); RateCounterFilter(PacketProcessorListener* listener, const std::string& name); + RateCounterFilter(PacketProcessorListener* listener, + const FlowIds& flow_ids, + const std::string& name); virtual ~RateCounterFilter(); uint32_t packets_per_second() const; @@ -211,7 +234,7 @@ class RateCounterFilter : public PacketProcessor { private: scoped_ptr<RateCounter> rate_counter_; - Stats<double> pps_stats_; + Stats<double> packets_per_second_stats_; Stats<double> kbps_stats_; std::string name_; @@ -283,6 +306,7 @@ class ReorderFilter : public PacketProcessor { class ChokeFilter : public PacketProcessor { public: explicit ChokeFilter(PacketProcessorListener* listener); + ChokeFilter(PacketProcessorListener* listener, const FlowIds& flow_ids); virtual ~ChokeFilter(); void SetCapacity(uint32_t kbps); @@ -315,6 +339,7 @@ class TraceBasedDeliveryFilter : public PacketProcessor { void SetMaxDelay(int max_delay_ms); Stats<double> GetDelayStats() const; + Stats<double> GetBitrateStats() const; private: void ProceedToNextSlot(); @@ -327,6 +352,8 @@ class TraceBasedDeliveryFilter : public PacketProcessor { scoped_ptr<RateCounter> rate_counter_; std::string name_; scoped_ptr<DelayCapHelper> delay_cap_helper_; + Stats<double> packets_per_second_stats_; + Stats<double> kbps_stats_; DISALLOW_COPY_AND_ASSIGN(TraceBasedDeliveryFilter); }; @@ -338,6 +365,7 @@ class PacketSender : public PacketProcessor { }; explicit PacketSender(PacketProcessorListener* listener); + PacketSender(PacketProcessorListener* listener, const FlowIds& flow_ids); virtual ~PacketSender() {} virtual uint32_t GetCapacityKbps() const { return 0; } @@ -347,23 +375,17 @@ class PacketSender : public PacketProcessor { // Note that changing the feedback interval affects the timing of when the // output of the estimators is sampled and therefore the baseline files may // have to be regenerated. - virtual int64_t GetFeedbackIntervalMs() const { return 1000; } + virtual int GetFeedbackIntervalMs() const { return 1000; } virtual void GiveFeedback(const Feedback& feedback) {} private: DISALLOW_COPY_AND_ASSIGN(PacketSender); }; -struct PacketSenderFactory { - PacketSenderFactory() {} - virtual ~PacketSenderFactory() {} - virtual PacketSender* Create() const = 0; -}; - class VideoSender : public PacketSender { public: - VideoSender(PacketProcessorListener* listener, float fps, uint32_t kbps, - uint32_t ssrc, float first_frame_offset); + VideoSender(int flow_id, PacketProcessorListener* listener, float fps, + uint32_t kbps, uint32_t ssrc, float first_frame_offset); virtual ~VideoSender() {} uint32_t max_payload_size_bytes() const { return kMaxPayloadSizeBytes; } @@ -390,48 +412,17 @@ class VideoSender : public PacketSender { class AdaptiveVideoSender : public VideoSender { public: - AdaptiveVideoSender(PacketProcessorListener* listener, float fps, - uint32_t kbps, uint32_t ssrc, float first_frame_offset); + AdaptiveVideoSender(int flow_id, PacketProcessorListener* listener, + float fps, uint32_t kbps, uint32_t ssrc, + float first_frame_offset); virtual ~AdaptiveVideoSender() {} - virtual int64_t GetFeedbackIntervalMs() const { return 100; } + virtual int GetFeedbackIntervalMs() const { return 100; } virtual void GiveFeedback(const Feedback& feedback); private: DISALLOW_IMPLICIT_CONSTRUCTORS(AdaptiveVideoSender); }; - -class VideoPacketSenderFactory : public PacketSenderFactory { - public: - VideoPacketSenderFactory(float fps, uint32_t kbps, uint32_t ssrc, - float frame_offset) - : fps_(fps), - kbps_(kbps), - ssrc_(ssrc), - frame_offset_(frame_offset) { - } - virtual ~VideoPacketSenderFactory() {} - virtual PacketSender* Create() const { - return new VideoSender(NULL, fps_, kbps_, ssrc_, frame_offset_); - } - protected: - float fps_; - uint32_t kbps_; - uint32_t ssrc_; - float frame_offset_; -}; - -class AdaptiveVideoPacketSenderFactory : public VideoPacketSenderFactory { - public: - AdaptiveVideoPacketSenderFactory(float fps, uint32_t kbps, uint32_t ssrc, - float frame_offset) - : VideoPacketSenderFactory(fps, kbps, ssrc, frame_offset) {} - virtual ~AdaptiveVideoPacketSenderFactory() {} - virtual PacketSender* Create() const { - return new AdaptiveVideoSender(NULL, fps_, kbps_, ssrc_, frame_offset_); - } -}; - } // namespace bwe } // namespace testing } // namespace webrtc diff --git a/modules/remote_bitrate_estimator/test/bwe_test_framework_unittest.cc b/modules/remote_bitrate_estimator/test/bwe_test_framework_unittest.cc index 56329b62..4ff35df4 100644 --- a/modules/remote_bitrate_estimator/test/bwe_test_framework_unittest.cc +++ b/modules/remote_bitrate_estimator/test/bwe_test_framework_unittest.cc @@ -184,7 +184,7 @@ class BweTestFramework_RateCounterFilterTest : public ::testing::Test { RTPHeader header; // "Send" a packet every 10 ms. for (int64_t i = 0; i < run_for_ms; i += 10, now_ms_ += 10) { - packets.push_back(Packet(now_ms_ * 1000, payload_bits / 8, header)); + packets.push_back(Packet(0, now_ms_ * 1000, payload_bits / 8, header)); } filter_.RunFor(run_for_ms, &packets); ASSERT_TRUE(IsTimeSorted(packets)); @@ -587,7 +587,7 @@ class BweTestFramework_ChokeFilterTest : public ::testing::Test { int64_t send_time_ms = now_ms_ + (i * run_for_ms) / packets_to_generate; header.sequenceNumber = sequence_number_++; // Payload is 1000 bits. - packets.push_back(Packet(send_time_ms * 1000, 125, header)); + packets.push_back(Packet(0, send_time_ms * 1000, 125, header)); send_times_us_.push_back(send_time_ms * 1000); } ASSERT_TRUE(IsTimeSorted(packets)); @@ -768,7 +768,7 @@ void TestVideoSender(VideoSender* sender, int64_t run_for_ms, TEST(BweTestFramework_VideoSenderTest, Fps1Kbps80_1s) { // 1 fps, 80 kbps - VideoSender sender(NULL, 1.0f, 80, 0x1234, 0); + VideoSender sender(0, NULL, 1.0f, 80, 0x1234, 0); EXPECT_EQ(10000u, sender.bytes_per_second()); // We're at 1 fps, so all packets should be generated on first call, giving 10 // packets of each 1000 bytes, total 10000 bytes. @@ -785,7 +785,7 @@ TEST(BweTestFramework_VideoSenderTest, Fps1Kbps80_1s) { TEST(BweTestFramework_VideoSenderTest, Fps1Kbps80_1s_Offset) { // 1 fps, 80 kbps, offset 0.5 of a frame period, ==0.5s in this case. - VideoSender sender(NULL, 1.0f, 80, 0x1234, 0.5f); + VideoSender sender(0, NULL, 1.0f, 80, 0x1234, 0.5f); EXPECT_EQ(10000u, sender.bytes_per_second()); // 499ms, no output. TestVideoSender(&sender, 499, 0, 0, 0); @@ -805,7 +805,7 @@ TEST(BweTestFramework_VideoSenderTest, Fps1Kbps80_1s_Offset) { TEST(BweTestFramework_VideoSenderTest, Fps50Kpbs80_11s) { // 50 fps, 80 kbps. - VideoSender sender(NULL, 50.0f, 80, 0x1234, 0); + VideoSender sender(0, NULL, 50.0f, 80, 0x1234, 0); EXPECT_EQ(10000u, sender.bytes_per_second()); // 9998ms, should see 500 frames, 200 byte payloads, total 100000 bytes. TestVideoSender(&sender, 9998, 500, 200, 100000); @@ -821,7 +821,7 @@ TEST(BweTestFramework_VideoSenderTest, Fps50Kpbs80_11s) { TEST(BweTestFramework_VideoSenderTest, Fps10Kpbs120_1s) { // 20 fps, 120 kbps. - VideoSender sender(NULL, 20.0f, 120, 0x1234, 0); + VideoSender sender(0, NULL, 20.0f, 120, 0x1234, 0); EXPECT_EQ(15000u, sender.bytes_per_second()); // 498ms, 10 frames with 750 byte payloads, total 7500 bytes. TestVideoSender(&sender, 498, 10, 750, 7500); @@ -837,7 +837,7 @@ TEST(BweTestFramework_VideoSenderTest, Fps10Kpbs120_1s) { TEST(BweTestFramework_VideoSenderTest, Fps30Kbps800_20s) { // 20 fps, 820 kbps. - VideoSender sender(NULL, 25.0f, 820, 0x1234, 0); + VideoSender sender(0, NULL, 25.0f, 820, 0x1234, 0); EXPECT_EQ(102500u, sender.bytes_per_second()); // 9998ms, 250 frames. 820 kbps = 102500 bytes/s, so total should be 1025000. // Each frame is 102500/25=4100 bytes, or 5 packets (4 @1000 bytes, 1 @100), @@ -858,7 +858,7 @@ TEST(BweTestFramework_VideoSenderTest, Fps30Kbps800_20s) { TEST(BweTestFramework_VideoSenderTest, TestAppendInOrder) { // 1 fps, 80 kbps, 250ms offset. - VideoSender sender1(NULL, 1.0f, 80, 0x1234, 0.25f); + VideoSender sender1(0, NULL, 1.0f, 80, 0x1234, 0.25f); EXPECT_EQ(10000u, sender1.bytes_per_second()); Packets packets; // Generate some packets, verify they are sorted. @@ -873,7 +873,7 @@ TEST(BweTestFramework_VideoSenderTest, TestAppendInOrder) { EXPECT_EQ(18u, packets.size()); // Another sender, 2 fps, 160 kpbs, 150ms offset - VideoSender sender2(NULL, 2.0f, 160, 0x2234, 0.30f); + VideoSender sender2(0, NULL, 2.0f, 160, 0x2234, 0.30f); EXPECT_EQ(20000u, sender2.bytes_per_second()); // Generate some packets, verify that they are merged with the packets already // on the list. @@ -887,7 +887,7 @@ TEST(BweTestFramework_VideoSenderTest, TestAppendInOrder) { } TEST(BweTestFramework_VideoSenderTest, FeedbackIneffective) { - VideoSender sender(NULL, 25.0f, 820, 0x1234, 0); + VideoSender sender(0, NULL, 25.0f, 820, 0x1234, 0); EXPECT_EQ(102500u, sender.bytes_per_second()); TestVideoSender(&sender, 9998, 1000, 500, 1025000); @@ -899,7 +899,7 @@ TEST(BweTestFramework_VideoSenderTest, FeedbackIneffective) { } TEST(BweTestFramework_AdaptiveVideoSenderTest, FeedbackChangesBitrate) { - AdaptiveVideoSender sender(NULL, 25.0f, 820, 0x1234, 0); + AdaptiveVideoSender sender(0, NULL, 25.0f, 820, 0x1234, 0); EXPECT_EQ(102500u, sender.bytes_per_second()); TestVideoSender(&sender, 9998, 1000, 500, 1025000); diff --git a/modules/rtp_rtcp/test/testFec/test_packet_masks_metrics.cc b/modules/rtp_rtcp/test/testFec/test_packet_masks_metrics.cc index cc1ee84e..2fb09683 100644 --- a/modules/rtp_rtcp/test/testFec/test_packet_masks_metrics.cc +++ b/modules/rtp_rtcp/test/testFec/test_packet_masks_metrics.cc @@ -198,7 +198,7 @@ class FecPacketMaskMetricsTest : public ::testing::Test { int RecoveredMediaPackets(int num_media_packets, int num_fec_packets, uint8_t* state) { - scoped_array<uint8_t> state_tmp( + scoped_ptr<uint8_t[]> state_tmp( new uint8_t[num_media_packets + num_fec_packets]); memcpy(state_tmp.get(), state, num_media_packets + num_fec_packets); int num_recovered_packets = 0; @@ -392,7 +392,7 @@ class FecPacketMaskMetricsTest : public ::testing::Test { // (which containes the code size parameters/protection length). void ComputeMetricsForCode(CodeType code_type, int code_index) { - scoped_array<double> prob_weight(new double[kNumLossModels]); + scoped_ptr<double[]> prob_weight(new double[kNumLossModels]); memset(prob_weight.get() , 0, sizeof(double) * kNumLossModels); MetricsFecCode metrics_code; SetMetricsZero(&metrics_code); @@ -400,7 +400,7 @@ class FecPacketMaskMetricsTest : public ::testing::Test { int num_media_packets = code_params_[code_index].num_media_packets; int num_fec_packets = code_params_[code_index].num_fec_packets; int tot_num_packets = num_media_packets + num_fec_packets; - scoped_array<uint8_t> state(new uint8_t[tot_num_packets]); + scoped_ptr<uint8_t[]> state(new uint8_t[tot_num_packets]); memset(state.get() , 0, tot_num_packets); int num_loss_configurations = static_cast<int>(pow(2.0f, tot_num_packets)); diff --git a/modules/utility/source/video_frames_queue.cc b/modules/utility/source/video_frames_queue.cc index fbcbd2c1..63afbe9b 100644 --- a/modules/utility/source/video_frames_queue.cc +++ b/modules/utility/source/video_frames_queue.cc @@ -80,8 +80,10 @@ I420VideoFrame* VideoFramesQueue::FrameToRecord() { // List is traversed beginning to end. If ptrRenderFrame is not // NULL it must be the first, and thus oldest, VideoFrame in the // queue. It can be recycled. - ReturnFrame(ptrRenderFrame); - iter = _incomingFrames.erase(iter); + if (ptrRenderFrame) { + ReturnFrame(ptrRenderFrame); + _incomingFrames.pop_front(); + } ptrRenderFrame = ptrOldestFrameInList; } else { // All VideoFrames following this one will be even newer. No match diff --git a/modules/video_capture/test/video_capture_unittest.cc b/modules/video_capture/test/video_capture_unittest.cc index db0c8187..4c2263d0 100644 --- a/modules/video_capture/test/video_capture_unittest.cc +++ b/modules/video_capture/test/video_capture_unittest.cc @@ -25,6 +25,7 @@ #include "webrtc/system_wrappers/interface/scoped_refptr.h" #include "webrtc/system_wrappers/interface/sleep.h" #include "webrtc/system_wrappers/interface/tick_util.h" +#include "webrtc/test/testsupport/gtest_disable.h" using webrtc::CriticalSectionWrapper; using webrtc::CriticalSectionScoped; @@ -473,7 +474,7 @@ TEST_F(VideoCaptureExternalTest, TestExternalCapture) { unsigned int length = webrtc::CalcBufferSize(webrtc::kI420, test_frame_.width(), test_frame_.height()); - webrtc::scoped_array<uint8_t> test_buffer(new uint8_t[length]); + webrtc::scoped_ptr<uint8_t[]> test_buffer(new uint8_t[length]); webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), length, capture_callback_.capability(), 0)); @@ -550,7 +551,8 @@ TEST_F(VideoCaptureExternalTest, DISABLED_TestExternalCaptureI420) { } // Test frame rate and no picture alarm. -TEST_F(VideoCaptureExternalTest , FrameRate) { +// Flaky on Win32, see webrtc:3270. +TEST_F(VideoCaptureExternalTest, DISABLED_ON_WIN(FrameRate)) { int64_t testTime = 3; TickTime startTime = TickTime::Now(); @@ -558,7 +560,7 @@ TEST_F(VideoCaptureExternalTest , FrameRate) { unsigned int length = webrtc::CalcBufferSize(webrtc::kI420, test_frame_.width(), test_frame_.height()); - webrtc::scoped_array<uint8_t> test_buffer(new uint8_t[length]); + webrtc::scoped_ptr<uint8_t[]> test_buffer(new uint8_t[length]); webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), length, capture_callback_.capability(), 0)); @@ -574,7 +576,7 @@ TEST_F(VideoCaptureExternalTest , FrameRate) { unsigned int length = webrtc::CalcBufferSize(webrtc::kI420, test_frame_.width(), test_frame_.height()); - webrtc::scoped_array<uint8_t> test_buffer(new uint8_t[length]); + webrtc::scoped_ptr<uint8_t[]> test_buffer(new uint8_t[length]); webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), length, capture_callback_.capability(), 0)); @@ -592,7 +594,7 @@ TEST_F(VideoCaptureExternalTest, Rotation) { unsigned int length = webrtc::CalcBufferSize(webrtc::kI420, test_frame_.width(), test_frame_.height()); - webrtc::scoped_array<uint8_t> test_buffer(new uint8_t[length]); + webrtc::scoped_ptr<uint8_t[]> test_buffer(new uint8_t[length]); webrtc::ExtractBuffer(test_frame_, length, test_buffer.get()); EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), length, capture_callback_.capability(), 0)); diff --git a/modules/video_coding/codecs/test/videoprocessor.cc b/modules/video_coding/codecs/test/videoprocessor.cc index 30ee6a8e..93738caf 100644 --- a/modules/video_coding/codecs/test/videoprocessor.cc +++ b/modules/video_coding/codecs/test/videoprocessor.cc @@ -331,7 +331,7 @@ void VideoProcessorImpl::FrameDecoded(const I420VideoFrame& image) { } // TODO(mikhal): Extracting the buffer for now - need to update test. int length = CalcBufferSize(kI420, up_image.width(), up_image.height()); - scoped_array<uint8_t> image_buffer(new uint8_t[length]); + scoped_ptr<uint8_t[]> image_buffer(new uint8_t[length]); length = ExtractBuffer(up_image, length, image_buffer.get()); // Update our copy of the last successful frame: memcpy(last_successful_frame_buffer_, image_buffer.get(), length); @@ -344,7 +344,7 @@ void VideoProcessorImpl::FrameDecoded(const I420VideoFrame& image) { // Update our copy of the last successful frame: // TODO(mikhal): Add as a member function, so won't be allocated per frame. int length = CalcBufferSize(kI420, image.width(), image.height()); - scoped_array<uint8_t> image_buffer(new uint8_t[length]); + scoped_ptr<uint8_t[]> image_buffer(new uint8_t[length]); length = ExtractBuffer(image, length, image_buffer.get()); assert(length > 0); memcpy(last_successful_frame_buffer_, image_buffer.get(), length); diff --git a/modules/video_coding/codecs/test_framework/unit_test.cc b/modules/video_coding/codecs/test_framework/unit_test.cc index 3b034e01..ec12a516 100644 --- a/modules/video_coding/codecs/test_framework/unit_test.cc +++ b/modules/video_coding/codecs/test_framework/unit_test.cc @@ -565,7 +565,7 @@ UnitTest::Perform() frameLength = WaitForDecodedFrame(); } unsigned int length = CalcBufferSize(kI420, width, height); - scoped_array<uint8_t> decoded_buffer(new uint8_t[length]); + scoped_ptr<uint8_t[]> decoded_buffer(new uint8_t[length]); ExtractBuffer(_decodedVideoBuffer, _lengthSourceFrame, decoded_buffer.get()); EXPECT_TRUE(CheckIfBitExact(decoded_buffer.get(), frameLength, _refDecFrame, @@ -645,7 +645,7 @@ UnitTest::Perform() // check that decoded frame matches with reference unsigned int length = CalcBufferSize(kI420, width, height); - scoped_array<uint8_t> decoded_buffer(new uint8_t[length]); + scoped_ptr<uint8_t[]> decoded_buffer(new uint8_t[length]); ExtractBuffer(_decodedVideoBuffer, length, decoded_buffer.get()); EXPECT_TRUE(CheckIfBitExact(decoded_buffer.get(), length, _refDecFrame, _lengthSourceFrame) == true); diff --git a/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc b/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc index ff99ed27..3cc8bc33 100644 --- a/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc +++ b/modules/video_coding/codecs/vp8/test/vp8_impl_unittest.cc @@ -181,7 +181,7 @@ class TestVp8Impl : public ::testing::Test { scoped_ptr<Vp8UnitTestEncodeCompleteCallback> encode_complete_callback_; scoped_ptr<Vp8UnitTestDecodeCompleteCallback> decode_complete_callback_; - scoped_array<uint8_t> source_buffer_; + scoped_ptr<uint8_t[]> source_buffer_; FILE* source_file_; I420VideoFrame input_frame_; scoped_ptr<VideoEncoder> encoder_; diff --git a/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc b/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc index 1bd3e1a6..ffa0bcc6 100644 --- a/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc +++ b/modules/video_coding/codecs/vp8/vp8_sequence_coder.cc @@ -142,7 +142,7 @@ int SequenceCoder(webrtc::test::CommandLineParser& parser) { EXPECT_EQ(0, decoder->InitDecode(&inst, 1)); webrtc::I420VideoFrame input_frame; unsigned int length = webrtc::CalcBufferSize(webrtc::kI420, width, height); - webrtc::scoped_array<uint8_t> frame_buffer(new uint8_t[length]); + webrtc::scoped_ptr<uint8_t[]> frame_buffer(new uint8_t[length]); int half_width = (width + 1) / 2; // Set and register callbacks. diff --git a/modules/video_coding/main/test/rtp_player.cc b/modules/video_coding/main/test/rtp_player.cc index e314a7c9..f02aebba 100644 --- a/modules/video_coding/main/test/rtp_player.cc +++ b/modules/video_coding/main/test/rtp_player.cc @@ -61,7 +61,7 @@ class RawRtpPacket { uint16_t seq_num() const { return seq_num_; } private: - scoped_array<uint8_t> data_; + scoped_ptr<uint8_t[]> data_; uint32_t length_; int64_t resend_time_ms_; uint32_t ssrc_; diff --git a/modules/video_processing/main/test/unit_test/brightness_detection_test.cc b/modules/video_processing/main/test/unit_test/brightness_detection_test.cc index d7ac7290..c53c1fb8 100644 --- a/modules/video_processing/main/test/unit_test/brightness_detection_test.cc +++ b/modules/video_processing/main/test/unit_test/brightness_detection_test.cc @@ -19,7 +19,7 @@ TEST_F(VideoProcessingModuleTest, BrightnessDetection) uint32_t frameNum = 0; int32_t brightnessWarning = 0; uint32_t warningCount = 0; - scoped_array<uint8_t> video_buffer(new uint8_t[frame_length_]); + scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); while (fread(video_buffer.get(), 1, frame_length_, source_file_) == frame_length_) { diff --git a/modules/video_processing/main/test/unit_test/color_enhancement_test.cc b/modules/video_processing/main/test/unit_test/color_enhancement_test.cc index fc560bef..c1cd4623 100644 --- a/modules/video_processing/main/test/unit_test/color_enhancement_test.cc +++ b/modules/video_processing/main/test/unit_test/color_enhancement_test.cc @@ -39,7 +39,7 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) ASSERT_TRUE(modFile != NULL) << "Could not open output file.\n"; uint32_t frameNum = 0; - scoped_array<uint8_t> video_buffer(new uint8_t[frame_length_]); + scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); while (fread(video_buffer.get(), 1, frame_length_, source_file_) == frame_length_) { @@ -86,7 +86,7 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) width_, half_width_, half_width_); // Compare frame-by-frame. - scoped_array<uint8_t> ref_buffer(new uint8_t[frame_length_]); + scoped_ptr<uint8_t[]> ref_buffer(new uint8_t[frame_length_]); while (fread(video_buffer.get(), 1, frame_length_, modFile) == frame_length_) { @@ -114,7 +114,7 @@ TEST_F(VideoProcessingModuleTest, ColorEnhancement) // Verify that all color pixels are enhanced, and no luminance values are // altered. - scoped_array<uint8_t> testFrame(new uint8_t[frame_length_]); + scoped_ptr<uint8_t[]> testFrame(new uint8_t[frame_length_]); // Use value 128 as probe value, since we know that this will be changed // in the enhancement. diff --git a/modules/video_processing/main/test/unit_test/content_metrics_test.cc b/modules/video_processing/main/test/unit_test/content_metrics_test.cc index 36a1ad76..c0d1ab43 100644 --- a/modules/video_processing/main/test/unit_test/content_metrics_test.cc +++ b/modules/video_processing/main/test/unit_test/content_metrics_test.cc @@ -23,7 +23,7 @@ TEST_F(VideoProcessingModuleTest, ContentAnalysis) { ca__c.Initialize(width_,height_); ca__sse.Initialize(width_,height_); - scoped_array<uint8_t> video_buffer(new uint8_t[frame_length_]); + scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); while (fread(video_buffer.get(), 1, frame_length_, source_file_) == frame_length_) { // Using ConvertToI420 to add stride to the image. diff --git a/modules/video_processing/main/test/unit_test/deflickering_test.cc b/modules/video_processing/main/test/unit_test/deflickering_test.cc index 0fa3f48b..1bf53fc8 100644 --- a/modules/video_processing/main/test/unit_test/deflickering_test.cc +++ b/modules/video_processing/main/test/unit_test/deflickering_test.cc @@ -43,7 +43,7 @@ TEST_F(VideoProcessingModuleTest, Deflickering) "Could not open output file: " << output_file << "\n"; printf("\nRun time [us / frame]:\n"); - scoped_array<uint8_t> video_buffer(new uint8_t[frame_length_]); + scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); for (uint32_t run_idx = 0; run_idx < NumRuns; run_idx++) { TickTime t0; diff --git a/modules/video_processing/main/test/unit_test/denoising_test.cc b/modules/video_processing/main/test/unit_test/denoising_test.cc index 3023a2d7..c00db6ab 100644 --- a/modules/video_processing/main/test/unit_test/denoising_test.cc +++ b/modules/video_processing/main/test/unit_test/denoising_test.cc @@ -49,7 +49,7 @@ TEST_F(VideoProcessingModuleTest, DISABLED_ON_ANDROID(Denoising)) int32_t modifiedPixels = 0; frameNum = 0; - scoped_array<uint8_t> video_buffer(new uint8_t[frame_length_]); + scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); while (fread(video_buffer.get(), 1, frame_length_, source_file_) == frame_length_) { diff --git a/modules/video_processing/main/test/unit_test/video_processing_unittest.cc b/modules/video_processing/main/test/unit_test/video_processing_unittest.cc index 6e549230..9d70e67a 100644 --- a/modules/video_processing/main/test/unit_test/video_processing_unittest.cc +++ b/modules/video_processing/main/test/unit_test/video_processing_unittest.cc @@ -89,7 +89,7 @@ TEST_F(VideoProcessingModuleTest, HandleNullBuffer) { TEST_F(VideoProcessingModuleTest, HandleBadStats) { VideoProcessingModule::FrameStats stats; - scoped_array<uint8_t> video_buffer(new uint8_t[frame_length_]); + scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, @@ -129,7 +129,7 @@ TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) { I420VideoFrame video_frame2; VideoProcessingModule::FrameStats stats; // Only testing non-static functions here. - scoped_array<uint8_t> video_buffer(new uint8_t[frame_length_]); + scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, @@ -172,7 +172,7 @@ TEST_F(VideoProcessingModuleTest, IdenticalResultsAfterReset) { TEST_F(VideoProcessingModuleTest, FrameStats) { VideoProcessingModule::FrameStats stats; - scoped_array<uint8_t> video_buffer(new uint8_t[frame_length_]); + scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); EXPECT_EQ(0, ConvertToI420(kI420, video_buffer.get(), 0, 0, @@ -242,7 +242,7 @@ TEST_F(VideoProcessingModuleTest, Resampler) { vpm_->EnableTemporalDecimation(false); // Reading test frame - scoped_array<uint8_t> video_buffer(new uint8_t[frame_length_]); + scoped_ptr<uint8_t[]> video_buffer(new uint8_t[frame_length_]); ASSERT_EQ(frame_length_, fread(video_buffer.get(), 1, frame_length_, source_file_)); // Using ConvertToI420 to add stride to the image. diff --git a/modules/video_render/video_render.gypi b/modules/video_render/video_render.gypi index a3c0f6d5..3cb61678 100644 --- a/modules/video_render/video_render.gypi +++ b/modules/video_render/video_render.gypi @@ -87,6 +87,12 @@ 'android/video_render_android_surface_view.cc', 'android/video_render_opengles20.cc', ], + }, { + 'all_dependent_settings': { + 'libraries': [ + '-lGLESv2', + ], + }, }], ['OS!="ios" or include_internal_video_render==0', { 'sources!': [ diff --git a/supplement.gypi b/supplement.gypi index 7898d4cb..2fad5745 100644 --- a/supplement.gypi +++ b/supplement.gypi @@ -1,5 +1,6 @@ { 'variables': { 'build_with_chromium': 0, + 'use_sanitizer_options': 0, } } diff --git a/system_wrappers/interface/scoped_ptr.h b/system_wrappers/interface/scoped_ptr.h index fb203638..8998f817 100644 --- a/system_wrappers/interface/scoped_ptr.h +++ b/system_wrappers/interface/scoped_ptr.h @@ -563,82 +563,4 @@ bool operator!=(T* p1, const webrtc::scoped_ptr<T, D>& p2) { return p1 != p2.get(); } -namespace webrtc { - -// DEPRECATED: Use scoped_ptr<T[]> instead. -// TODO(ajm): Remove scoped_array. -// -// scoped_array extends scoped_ptr to arrays. Deletion of the array pointed to -// is guaranteed, either on destruction of the scoped_array or via an explicit -// reset(). Use shared_array or std::vector if your needs are more complex. - -template<typename T> -class scoped_array { - private: - - T* ptr; - - scoped_array(scoped_array const &); - scoped_array & operator=(scoped_array const &); - - public: - - typedef T element_type; - - explicit scoped_array(T* p = NULL) : ptr(p) {} - - ~scoped_array() { - typedef char type_must_be_complete[sizeof(T)]; - delete[] ptr; - } - - void reset(T* p = NULL) { - typedef char type_must_be_complete[sizeof(T)]; - - if (ptr != p) { - T* arr = ptr; - ptr = p; - // Delete last, in case arr destructor indirectly results in ~scoped_array - delete [] arr; - } - } - - T& operator[](ptrdiff_t i) const { - assert(ptr != NULL); - assert(i >= 0); - return ptr[i]; - } - - T* get() const { - return ptr; - } - - void swap(scoped_array & b) { - T* tmp = b.ptr; - b.ptr = ptr; - ptr = tmp; - } - - T* release() { - T* tmp = ptr; - ptr = NULL; - return tmp; - } - - T** accept() { - if (ptr) { - delete [] ptr; - ptr = NULL; - } - return &ptr; - } -}; - -template<class T> inline -void swap(scoped_array<T>& a, scoped_array<T>& b) { - a.swap(b); -} - -} // namespace webrtc - #endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_SCOPED_PTR_H_ diff --git a/test/direct_transport.h b/test/direct_transport.h index 9dc9e1fc..c40a8c38 100644 --- a/test/direct_transport.h +++ b/test/direct_transport.h @@ -49,7 +49,7 @@ class DirectTransport : public newapi::Transport { scoped_ptr<CriticalSectionWrapper> lock_; scoped_ptr<EventWrapper> packet_event_; scoped_ptr<ThreadWrapper> thread_; - Clock* clock_; + Clock* const clock_; bool shutting_down_; diff --git a/test/fake_encoder.h b/test/fake_encoder.h index c0709c12..2a444a10 100644 --- a/test/fake_encoder.h +++ b/test/fake_encoder.h @@ -42,7 +42,7 @@ class FakeEncoder : public VideoEncoder { uint32_t framerate) OVERRIDE; private: - Clock* clock_; + Clock* const clock_; VideoCodec config_; EncodedImageCallback* callback_; int target_bitrate_kbps_; diff --git a/test/fake_network_pipe_unittest.cc b/test/fake_network_pipe_unittest.cc index 5076bc0a..6655fa16 100644 --- a/test/fake_network_pipe_unittest.cc +++ b/test/fake_network_pipe_unittest.cc @@ -47,7 +47,7 @@ class FakeNetworkPipeTest : public ::testing::Test { } void SendPackets(FakeNetworkPipe* pipe, int number_packets, int kPacketSize) { - scoped_array<uint8_t> packet(new uint8_t[kPacketSize]); + scoped_ptr<uint8_t[]> packet(new uint8_t[kPacketSize]); for (int i = 0; i < number_packets; ++i) { pipe->SendPacket(packet.get(), kPacketSize); } diff --git a/test/frame_generator_capturer.h b/test/frame_generator_capturer.h index 84b3c495..ee3f0e01 100644 --- a/test/frame_generator_capturer.h +++ b/test/frame_generator_capturer.h @@ -54,7 +54,7 @@ class FrameGeneratorCapturer : public VideoCapturer { void InsertFrame(); static bool Run(void* obj); - Clock* clock_; + Clock* const clock_; bool sending_; scoped_ptr<EventWrapper> tick_; diff --git a/test/rtp_rtcp_observer.h b/test/rtp_rtcp_observer.h index 00422cce..e4486534 100644 --- a/test/rtp_rtcp_observer.h +++ b/test/rtp_rtcp_observer.h @@ -53,15 +53,15 @@ class RtpRtcpObserver { protected: RtpRtcpObserver(unsigned int event_timeout_ms, const FakeNetworkPipe::Config& configuration) - : lock_(CriticalSectionWrapper::CreateCriticalSection()), + : crit_(CriticalSectionWrapper::CreateCriticalSection()), observation_complete_(EventWrapper::Create()), parser_(RtpHeaderParser::Create()), - send_transport_(lock_.get(), + send_transport_(crit_.get(), this, &RtpRtcpObserver::OnSendRtp, &RtpRtcpObserver::OnSendRtcp, configuration), - receive_transport_(lock_.get(), + receive_transport_(crit_.get(), this, &RtpRtcpObserver::OnReceiveRtp, &RtpRtcpObserver::OnReceiveRtcp, @@ -69,15 +69,15 @@ class RtpRtcpObserver { timeout_ms_(event_timeout_ms) {} explicit RtpRtcpObserver(unsigned int event_timeout_ms) - : lock_(CriticalSectionWrapper::CreateCriticalSection()), + : crit_(CriticalSectionWrapper::CreateCriticalSection()), observation_complete_(EventWrapper::Create()), parser_(RtpHeaderParser::Create()), - send_transport_(lock_.get(), + send_transport_(crit_.get(), this, &RtpRtcpObserver::OnSendRtp, &RtpRtcpObserver::OnSendRtcp, FakeNetworkPipe::Config()), - receive_transport_(lock_.get(), + receive_transport_(crit_.get(), this, &RtpRtcpObserver::OnReceiveRtp, &RtpRtcpObserver::OnReceiveRtcp, @@ -89,23 +89,26 @@ class RtpRtcpObserver { DROP_PACKET, }; - virtual Action OnSendRtp(const uint8_t* packet, size_t length) { + virtual Action OnSendRtp(const uint8_t* packet, size_t length) + EXCLUSIVE_LOCKS_REQUIRED(crit_) { return SEND_PACKET; } - virtual Action OnSendRtcp(const uint8_t* packet, size_t length) { + virtual Action OnSendRtcp(const uint8_t* packet, size_t length) + EXCLUSIVE_LOCKS_REQUIRED(crit_) { return SEND_PACKET; } - virtual Action OnReceiveRtp(const uint8_t* packet, size_t length) { + virtual Action OnReceiveRtp(const uint8_t* packet, size_t length) + EXCLUSIVE_LOCKS_REQUIRED(crit_) { return SEND_PACKET; } - virtual Action OnReceiveRtcp(const uint8_t* packet, size_t length) { + virtual Action OnReceiveRtcp(const uint8_t* packet, size_t length) + EXCLUSIVE_LOCKS_REQUIRED(crit_) { return SEND_PACKET; } - private: class PacketTransport : public test::DirectTransport { public: @@ -118,7 +121,7 @@ class RtpRtcpObserver { PacketTransportAction on_rtcp, const FakeNetworkPipe::Config& configuration) : test::DirectTransport(configuration), - lock_(lock), + crit_(lock), observer_(observer), on_rtp_(on_rtp), on_rtcp_(on_rtcp) {} @@ -128,7 +131,7 @@ class RtpRtcpObserver { EXPECT_FALSE(RtpHeaderParser::IsRtcp(packet, static_cast<int>(length))); Action action; { - CriticalSectionScoped crit_(lock_); + CriticalSectionScoped lock(crit_); action = (observer_->*on_rtp_)(packet, length); } switch (action) { @@ -145,7 +148,7 @@ class RtpRtcpObserver { EXPECT_TRUE(RtpHeaderParser::IsRtcp(packet, static_cast<int>(length))); Action action; { - CriticalSectionScoped crit_(lock_); + CriticalSectionScoped lock(crit_); action = (observer_->*on_rtcp_)(packet, length); } switch (action) { @@ -159,16 +162,16 @@ class RtpRtcpObserver { } // Pointer to shared lock instance protecting on_rtp_/on_rtcp_ calls. - CriticalSectionWrapper* lock_; + CriticalSectionWrapper* const crit_; - RtpRtcpObserver* observer_; - PacketTransportAction on_rtp_, on_rtcp_; + RtpRtcpObserver* const observer_; + const PacketTransportAction on_rtp_, on_rtcp_; }; protected: - scoped_ptr<CriticalSectionWrapper> lock_; - scoped_ptr<EventWrapper> observation_complete_; - scoped_ptr<RtpHeaderParser> parser_; + const scoped_ptr<CriticalSectionWrapper> crit_; + const scoped_ptr<EventWrapper> observation_complete_; + const scoped_ptr<RtpHeaderParser> parser_; private: PacketTransport send_transport_, receive_transport_; diff --git a/test/testsupport/fileutils.cc b/test/testsupport/fileutils.cc index 9d04ab02..a3e66201 100644 --- a/test/testsupport/fileutils.cc +++ b/test/testsupport/fileutils.cc @@ -10,8 +10,9 @@ #include "webrtc/test/testsupport/fileutils.h" -#ifdef WIN32 #include <assert.h> + +#ifdef WIN32 #include <direct.h> #include <tchar.h> #include <windows.h> diff --git a/test/testsupport/metrics/video_metrics.cc b/test/testsupport/metrics/video_metrics.cc index f537e039..1e19806b 100644 --- a/test/testsupport/metrics/video_metrics.cc +++ b/test/testsupport/metrics/video_metrics.cc @@ -111,8 +111,8 @@ int CalculateMetrics(VideoMetricsType video_metrics_type, const size_t frame_length = 3 * width * height >> 1; I420VideoFrame ref_frame; I420VideoFrame test_frame; - scoped_array<uint8_t> ref_buffer(new uint8_t[frame_length]); - scoped_array<uint8_t> test_buffer(new uint8_t[frame_length]); + scoped_ptr<uint8_t[]> ref_buffer(new uint8_t[frame_length]); + scoped_ptr<uint8_t[]> test_buffer(new uint8_t[frame_length]); // Set decoded image parameters. int half_width = (width + 1) / 2; diff --git a/tools/frame_editing/frame_editing_lib.cc b/tools/frame_editing/frame_editing_lib.cc index 6e252e87..93a548fe 100644 --- a/tools/frame_editing/frame_editing_lib.cc +++ b/tools/frame_editing/frame_editing_lib.cc @@ -38,7 +38,7 @@ int EditFrames(const string& in_path, int width, int height, // Frame size of I420. int frame_length = CalcBufferSize(kI420, width, height); - webrtc::scoped_array<uint8_t> temp_buffer(new uint8_t[frame_length]); + webrtc::scoped_ptr<uint8_t[]> temp_buffer(new uint8_t[frame_length]); FILE* out_fid = fopen(out_path.c_str(), "wb"); diff --git a/tools/frame_editing/frame_editing_unittest.cc b/tools/frame_editing/frame_editing_unittest.cc index 83302181..bdcc2f21 100644 --- a/tools/frame_editing/frame_editing_unittest.cc +++ b/tools/frame_editing/frame_editing_unittest.cc @@ -53,8 +53,8 @@ class FrameEditingTest : public ::testing::Test { } // Compares the frames in both streams to the end of one of the streams. void CompareToTheEnd(FILE* test_video_fid, FILE* ref_video_fid, - scoped_array<int>* ref_buffer, - scoped_array<int>* test_buffer) { + scoped_ptr<int[]>* ref_buffer, + scoped_ptr<int[]>* test_buffer) { while (!feof(test_video_fid) && !feof(ref_video_fid)) { num_bytes_read_ = fread(ref_buffer->get(), 1, kFrameSize, ref_video_fid); if (!feof(ref_video_fid)) { @@ -78,8 +78,8 @@ class FrameEditingTest : public ::testing::Test { FILE* original_fid_; FILE* edited_fid_; int num_bytes_read_; - scoped_array<int> original_buffer_; - scoped_array<int> edited_buffer_; + scoped_ptr<int[]> original_buffer_; + scoped_ptr<int[]> edited_buffer_; int num_frames_read_; }; diff --git a/video/bitrate_estimator_tests.cc b/video/bitrate_estimator_tests.cc index c28aea58..0cb30e3a 100644 --- a/video/bitrate_estimator_tests.cc +++ b/video/bitrate_estimator_tests.cc @@ -17,6 +17,7 @@ #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" #include "webrtc/system_wrappers/interface/event_wrapper.h" #include "webrtc/system_wrappers/interface/scoped_ptr.h" +#include "webrtc/system_wrappers/interface/thread_annotations.h" #include "webrtc/test/direct_transport.h" #include "webrtc/test/encoder_settings.h" #include "webrtc/test/fake_decoder.h" @@ -111,14 +112,14 @@ class BitrateEstimatorTest : public ::testing::Test { } void PushExpectedLogLine(const std::string& expected_log_line) { - CriticalSectionScoped cs(crit_sect_.get()); + CriticalSectionScoped lock(crit_sect_.get()); expected_log_lines_.push_back(expected_log_line); } virtual void Print(TraceLevel level, const char* message, int length) OVERRIDE { - CriticalSectionScoped cs(crit_sect_.get()); + CriticalSectionScoped lock(crit_sect_.get()); if (!(level & kTraceStateInfo)) { return; } @@ -147,9 +148,9 @@ class BitrateEstimatorTest : public ::testing::Test { private: typedef std::list<std::string> Strings; - scoped_ptr<CriticalSectionWrapper> crit_sect_; - Strings received_log_lines_; - Strings expected_log_lines_; + const scoped_ptr<CriticalSectionWrapper> crit_sect_; + Strings received_log_lines_ GUARDED_BY(crit_sect_); + Strings expected_log_lines_ GUARDED_BY(crit_sect_); scoped_ptr<EventWrapper> done_; }; diff --git a/video/call.cc b/video/call.cc index 595ec6ff..a3276540 100644 --- a/video/call.cc +++ b/video/call.cc @@ -21,6 +21,7 @@ #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" #include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" #include "webrtc/system_wrappers/interface/scoped_ptr.h" +#include "webrtc/system_wrappers/interface/thread_annotations.h" #include "webrtc/system_wrappers/interface/trace.h" #include "webrtc/video/video_receive_stream.h" #include "webrtc/video/video_send_stream.h" @@ -45,18 +46,18 @@ class CpuOveruseObserverProxy : public webrtc::CpuOveruseObserver { virtual ~CpuOveruseObserverProxy() {} virtual void OveruseDetected() OVERRIDE { - CriticalSectionScoped cs(crit_.get()); + CriticalSectionScoped lock(crit_.get()); overuse_callback_->OnOveruse(); } virtual void NormalUsage() OVERRIDE { - CriticalSectionScoped cs(crit_.get()); + CriticalSectionScoped lock(crit_.get()); overuse_callback_->OnNormalUse(); } private: - scoped_ptr<CriticalSectionWrapper> crit_; - OveruseCallback* overuse_callback_; + const scoped_ptr<CriticalSectionWrapper> crit_; + OveruseCallback* overuse_callback_ GUARDED_BY(crit_); }; class Call : public webrtc::Call, public PacketReceiver { @@ -95,10 +96,11 @@ class Call : public webrtc::Call, public PacketReceiver { Call::Config config_; - std::map<uint32_t, VideoReceiveStream*> receive_ssrcs_; + std::map<uint32_t, VideoReceiveStream*> receive_ssrcs_ + GUARDED_BY(receive_lock_); scoped_ptr<RWLockWrapper> receive_lock_; - std::map<uint32_t, VideoSendStream*> send_ssrcs_; + std::map<uint32_t, VideoSendStream*> send_ssrcs_ GUARDED_BY(send_lock_); scoped_ptr<RWLockWrapper> send_lock_; scoped_ptr<RtpHeaderParser> rtp_header_parser_; diff --git a/video/call_perf_tests.cc b/video/call_perf_tests.cc index 85d7e735..6b8ff96a 100644 --- a/video/call_perf_tests.cc +++ b/video/call_perf_tests.cc @@ -22,6 +22,7 @@ #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" #include "webrtc/system_wrappers/interface/scoped_ptr.h" +#include "webrtc/system_wrappers/interface/thread_annotations.h" #include "webrtc/test/direct_transport.h" #include "webrtc/test/encoder_settings.h" #include "webrtc/test/fake_audio_device.h" @@ -93,7 +94,7 @@ class SyncRtcpObserver : public test::RtpRtcpObserver { public: explicit SyncRtcpObserver(const FakeNetworkPipe::Config& config) : test::RtpRtcpObserver(kLongTimeoutMs, config), - critical_section_(CriticalSectionWrapper::CreateCriticalSection()) {} + crit_(CriticalSectionWrapper::CreateCriticalSection()) {} virtual Action OnSendRtcp(const uint8_t* packet, size_t length) OVERRIDE { RTCPUtility::RTCPParserV2 parser(packet, length, true); @@ -115,7 +116,7 @@ class SyncRtcpObserver : public test::RtpRtcpObserver { } int64_t RtpTimestampToNtp(uint32_t timestamp) const { - CriticalSectionScoped cs(critical_section_.get()); + CriticalSectionScoped lock(crit_.get()); int64_t timestamp_in_ms = -1; if (ntp_rtp_pairs_.size() == 2) { // TODO(stefan): We can't EXPECT_TRUE on this call due to a bug in the @@ -129,7 +130,7 @@ class SyncRtcpObserver : public test::RtpRtcpObserver { private: void StoreNtpRtpPair(synchronization::RtcpMeasurement ntp_rtp_pair) { - CriticalSectionScoped cs(critical_section_.get()); + CriticalSectionScoped lock(crit_.get()); for (synchronization::RtcpList::iterator it = ntp_rtp_pairs_.begin(); it != ntp_rtp_pairs_.end(); ++it) { @@ -147,8 +148,8 @@ class SyncRtcpObserver : public test::RtpRtcpObserver { ntp_rtp_pairs_.push_front(ntp_rtp_pair); } - scoped_ptr<CriticalSectionWrapper> critical_section_; - synchronization::RtcpList ntp_rtp_pairs_; + const scoped_ptr<CriticalSectionWrapper> crit_; + synchronization::RtcpList ntp_rtp_pairs_ GUARDED_BY(crit_); }; class VideoRtcpAndSyncObserver : public SyncRtcpObserver, public VideoRenderer { @@ -213,7 +214,7 @@ class VideoRtcpAndSyncObserver : public SyncRtcpObserver, public VideoRenderer { } private: - Clock* clock_; + Clock* const clock_; int voe_channel_; VoEVideoSync* voe_sync_; SyncRtcpObserver* audio_observer_; @@ -525,7 +526,8 @@ TEST_F(CallPerfTest, CaptureNtpTimeWithNetworkDelay) { TestCaptureNtpTime(net_config, kThresholdMs, kStartTimeMs, kRunTimeMs); } -TEST_F(CallPerfTest, CaptureNtpTimeWithNetworkJitter) { +// Flaky, webrtc:3271. +TEST_F(CallPerfTest, DISABLED_CaptureNtpTimeWithNetworkJitter) { FakeNetworkPipe::Config net_config; net_config.delay_standard_deviation_ms = 10; // TODO(wu): lower the threshold as the calculation/estimatation becomes more diff --git a/video/call_tests.cc b/video/call_tests.cc index 98f589ca..617b944f 100644 --- a/video/call_tests.cc +++ b/video/call_tests.cc @@ -435,7 +435,8 @@ TEST_F(CallTest, ReceivesAndRetransmitsNack) { DestroyStreams(); } -TEST_F(CallTest, CanReceiveFec) { +// TODO(pbos): Flaky, webrtc:3269 +TEST_F(CallTest, DISABLED_CanReceiveFec) { class FecRenderObserver : public test::RtpRtcpObserver, public VideoRenderer { public: FecRenderObserver() @@ -445,7 +446,8 @@ TEST_F(CallTest, CanReceiveFec) { protected_frame_timestamp_(0) {} private: - virtual Action OnSendRtp(const uint8_t* packet, size_t length) OVERRIDE { + virtual Action OnSendRtp(const uint8_t* packet, size_t length) OVERRIDE + EXCLUSIVE_LOCKS_REQUIRED(crit_) { RTPHeader header; EXPECT_TRUE(parser_->Parse(packet, static_cast<int>(length), &header)); @@ -486,7 +488,7 @@ TEST_F(CallTest, CanReceiveFec) { virtual void RenderFrame(const I420VideoFrame& video_frame, int time_to_render_ms) OVERRIDE { - CriticalSectionScoped crit_(lock_.get()); + CriticalSectionScoped lock(crit_.get()); // Rendering frame with timestamp associated with dropped packet -> FEC // protection worked. if (state_ == kProtectedPacketDropped && @@ -502,8 +504,8 @@ TEST_F(CallTest, CanReceiveFec) { kProtectedPacketDropped, } state_; - uint32_t protected_sequence_number_; - uint32_t protected_frame_timestamp_; + uint32_t protected_sequence_number_ GUARDED_BY(crit_); + uint32_t protected_frame_timestamp_ GUARDED_BY(crit_); } observer; CreateCalls(Call::Config(observer.SendTransport()), @@ -580,7 +582,7 @@ void CallTest::DecodesRetransmittedFrame(bool retransmit_over_rtx) { } virtual void FrameCallback(I420VideoFrame* frame) OVERRIDE { - CriticalSectionScoped crit_(lock_.get()); + CriticalSectionScoped lock(crit_.get()); if (frame->timestamp() == retransmitted_timestamp_) { EXPECT_TRUE(frame_retransmitted_); observation_complete_->Set(); @@ -784,7 +786,7 @@ class PliObserver : public test::RtpRtcpObserver, public VideoRenderer { virtual void RenderFrame(const I420VideoFrame& video_frame, int time_to_render_ms) OVERRIDE { - CriticalSectionScoped crit_(lock_.get()); + CriticalSectionScoped lock(crit_.get()); if (received_pli_ && video_frame.timestamp() > highest_dropped_timestamp_) { observation_complete_->Set(); } diff --git a/video/full_stack.cc b/video/full_stack.cc index a55270bc..51c0a8a7 100644 --- a/video/full_stack.cc +++ b/video/full_stack.cc @@ -24,6 +24,7 @@ #include "webrtc/system_wrappers/interface/event_wrapper.h" #include "webrtc/system_wrappers/interface/scoped_ptr.h" #include "webrtc/system_wrappers/interface/sleep.h" +#include "webrtc/system_wrappers/interface/thread_annotations.h" #include "webrtc/test/direct_transport.h" #include "webrtc/test/encoder_settings.h" #include "webrtc/test/fake_encoder.h" @@ -81,18 +82,18 @@ class VideoAnalyzer : public PacketReceiver, transport_(transport), receiver_(NULL), test_label_(test_label), + frames_left_(duration_frames), dropped_frames_(0), + last_render_time_(0), rtp_timestamp_delta_(0), + crit_(CriticalSectionWrapper::CreateCriticalSection()), first_send_frame_(NULL), - last_render_time_(0), avg_psnr_threshold_(avg_psnr_threshold), avg_ssim_threshold_(avg_ssim_threshold), - frames_left_(duration_frames), - crit_(CriticalSectionWrapper::CreateCriticalSection()), comparison_lock_(CriticalSectionWrapper::CreateCriticalSection()), comparison_thread_(ThreadWrapper::CreateThread(&FrameComparisonThread, this)), - trigger_(EventWrapper::Create()) { + done_(EventWrapper::Create()) { unsigned int id; EXPECT_TRUE(comparison_thread_->Start(id)); } @@ -117,7 +118,7 @@ class VideoAnalyzer : public PacketReceiver, RTPHeader header; parser->Parse(packet, static_cast<int>(length), &header); { - CriticalSectionScoped cs(crit_.get()); + CriticalSectionScoped lock(crit_.get()); recv_times_[header.timestamp - rtp_timestamp_delta_] = Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); } @@ -132,7 +133,7 @@ class VideoAnalyzer : public PacketReceiver, virtual void SwapFrame(I420VideoFrame* video_frame) OVERRIDE { I420VideoFrame* copy = NULL; { - CriticalSectionScoped cs(crit_.get()); + CriticalSectionScoped lock(crit_.get()); if (frame_pool_.size() > 0) { copy = frame_pool_.front(); frame_pool_.pop_front(); @@ -145,7 +146,7 @@ class VideoAnalyzer : public PacketReceiver, copy->set_timestamp(copy->render_time_ms() * 90); { - CriticalSectionScoped cs(crit_.get()); + CriticalSectionScoped lock(crit_.get()); if (first_send_frame_ == NULL && rtp_timestamp_delta_ == 0) first_send_frame_ = copy; @@ -161,7 +162,7 @@ class VideoAnalyzer : public PacketReceiver, parser->Parse(packet, static_cast<int>(length), &header); { - CriticalSectionScoped cs(crit_.get()); + CriticalSectionScoped lock(crit_.get()); if (rtp_timestamp_delta_ == 0) { rtp_timestamp_delta_ = header.timestamp - first_send_frame_->timestamp(); @@ -184,29 +185,27 @@ class VideoAnalyzer : public PacketReceiver, Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); uint32_t send_timestamp = video_frame.timestamp() - rtp_timestamp_delta_; - { - CriticalSectionScoped cs(crit_.get()); - while (frames_.front()->timestamp() < send_timestamp) { - AddFrameComparison( - frames_.front(), &last_rendered_frame_, true, render_time_ms); - frame_pool_.push_back(frames_.front()); - frames_.pop_front(); - } - - I420VideoFrame* reference_frame = frames_.front(); + CriticalSectionScoped lock(crit_.get()); + while (frames_.front()->timestamp() < send_timestamp) { + AddFrameComparison( + frames_.front(), &last_rendered_frame_, true, render_time_ms); + frame_pool_.push_back(frames_.front()); frames_.pop_front(); - assert(reference_frame != NULL); - EXPECT_EQ(reference_frame->timestamp(), send_timestamp); - assert(reference_frame->timestamp() == send_timestamp); - - AddFrameComparison(reference_frame, &video_frame, false, render_time_ms); - frame_pool_.push_back(reference_frame); } + I420VideoFrame* reference_frame = frames_.front(); + frames_.pop_front(); + assert(reference_frame != NULL); + EXPECT_EQ(reference_frame->timestamp(), send_timestamp); + assert(reference_frame->timestamp() == send_timestamp); + + AddFrameComparison(reference_frame, &video_frame, false, render_time_ms); + frame_pool_.push_back(reference_frame); + last_rendered_frame_.CopyFrame(video_frame); } - void Wait() { trigger_->Wait(120 * 1000); } + void Wait() { done_->Wait(120 * 1000); } VideoSendStreamInput* input_; Transport* transport_; @@ -250,7 +249,8 @@ class VideoAnalyzer : public PacketReceiver, void AddFrameComparison(const I420VideoFrame* reference, const I420VideoFrame* render, bool dropped, - int64_t render_time_ms) { + int64_t render_time_ms) + EXCLUSIVE_LOCKS_REQUIRED(crit_) { int64_t send_time_ms = send_times_[reference->timestamp()]; send_times_.erase(reference->timestamp()); int64_t recv_time_ms = recv_times_[reference->timestamp()]; @@ -313,7 +313,7 @@ class VideoAnalyzer : public PacketReceiver, PrintResult("time_between_rendered_frames", rendered_delta_, " ms"); EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_); EXPECT_GT(ssim_.Mean(), avg_ssim_threshold_); - trigger_->Set(); + done_->Set(); return false; } @@ -353,31 +353,32 @@ class VideoAnalyzer : public PacketReceiver, unit); } - const char* test_label_; + const char* const test_label_; test::Statistics sender_time_; test::Statistics receiver_time_; test::Statistics psnr_; test::Statistics ssim_; test::Statistics end_to_end_; test::Statistics rendered_delta_; - + int frames_left_; int dropped_frames_; - std::deque<I420VideoFrame*> frames_; - std::deque<I420VideoFrame*> frame_pool_; - I420VideoFrame last_rendered_frame_; - std::map<uint32_t, int64_t> send_times_; - std::map<uint32_t, int64_t> recv_times_; - uint32_t rtp_timestamp_delta_; - I420VideoFrame* first_send_frame_; int64_t last_render_time_; - double avg_psnr_threshold_; - double avg_ssim_threshold_; - int frames_left_; - scoped_ptr<CriticalSectionWrapper> crit_; - scoped_ptr<CriticalSectionWrapper> comparison_lock_; - scoped_ptr<ThreadWrapper> comparison_thread_; - std::deque<FrameComparison> comparisons_; - scoped_ptr<EventWrapper> trigger_; + uint32_t rtp_timestamp_delta_; + + const scoped_ptr<CriticalSectionWrapper> crit_; + std::deque<I420VideoFrame*> frames_ GUARDED_BY(crit_); + std::deque<I420VideoFrame*> frame_pool_ GUARDED_BY(crit_); + I420VideoFrame last_rendered_frame_ GUARDED_BY(crit_); + std::map<uint32_t, int64_t> send_times_ GUARDED_BY(crit_); + std::map<uint32_t, int64_t> recv_times_ GUARDED_BY(crit_); + I420VideoFrame* first_send_frame_ GUARDED_BY(crit_); + double avg_psnr_threshold_ GUARDED_BY(crit_); + double avg_ssim_threshold_ GUARDED_BY(crit_); + + const scoped_ptr<CriticalSectionWrapper> comparison_lock_; + const scoped_ptr<ThreadWrapper> comparison_thread_; + std::deque<FrameComparison> comparisons_ GUARDED_BY(comparison_lock_); + const scoped_ptr<EventWrapper> done_; }; TEST_P(FullStackTest, NoPacketLoss) { diff --git a/video/rampup_tests.cc b/video/rampup_tests.cc index a53fe62e..32a29982 100644 --- a/video/rampup_tests.cc +++ b/video/rampup_tests.cc @@ -48,14 +48,14 @@ class StreamObserver : public newapi::Transport, public RemoteBitrateObserver { StreamObserver(const SsrcMap& rtx_media_ssrcs, newapi::Transport* feedback_transport, Clock* clock) - : critical_section_(CriticalSectionWrapper::CreateCriticalSection()), + : clock_(clock), test_done_(EventWrapper::Create()), rtp_parser_(RtpHeaderParser::Create()), feedback_transport_(feedback_transport), receive_stats_(ReceiveStatistics::Create(clock)), payload_registry_( new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(false))), - clock_(clock), + crit_(CriticalSectionWrapper::CreateCriticalSection()), expected_bitrate_bps_(0), rtx_media_ssrcs_(rtx_media_ssrcs), total_sent_(0), @@ -85,12 +85,13 @@ class StreamObserver : public newapi::Transport, public RemoteBitrateObserver { } void set_expected_bitrate_bps(unsigned int expected_bitrate_bps) { + CriticalSectionScoped lock(crit_.get()); expected_bitrate_bps_ = expected_bitrate_bps; } virtual void OnReceiveBitrateChanged(const std::vector<unsigned int>& ssrcs, unsigned int bitrate) OVERRIDE { - CriticalSectionScoped lock(critical_section_.get()); + CriticalSectionScoped lock(crit_.get()); assert(expected_bitrate_bps_ > 0); if (bitrate >= expected_bitrate_bps_) { // Just trigger if there was any rtx padding packet. @@ -104,7 +105,7 @@ class StreamObserver : public newapi::Transport, public RemoteBitrateObserver { } virtual bool SendRtp(const uint8_t* packet, size_t length) OVERRIDE { - CriticalSectionScoped lock(critical_section_.get()); + CriticalSectionScoped lock(crit_.get()); RTPHeader header; EXPECT_TRUE(rtp_parser_->Parse(packet, static_cast<int>(length), &header)); receive_stats_->IncomingPacket(header, length, false); @@ -156,7 +157,7 @@ class StreamObserver : public newapi::Transport, public RemoteBitrateObserver { value, units, false); } - void TriggerTestDone() { + void TriggerTestDone() EXCLUSIVE_LOCKS_REQUIRED(crit_) { ReportResult("total-sent", total_sent_, "bytes"); ReportResult("padding-sent", padding_sent_, "bytes"); ReportResult("rtx-media-sent", rtx_media_sent_, "bytes"); @@ -166,23 +167,24 @@ class StreamObserver : public newapi::Transport, public RemoteBitrateObserver { test_done_->Set(); } - scoped_ptr<CriticalSectionWrapper> critical_section_; - scoped_ptr<EventWrapper> test_done_; - scoped_ptr<RtpHeaderParser> rtp_parser_; + Clock* const clock_; + const scoped_ptr<EventWrapper> test_done_; + const scoped_ptr<RtpHeaderParser> rtp_parser_; scoped_ptr<RtpRtcp> rtp_rtcp_; internal::TransportAdapter feedback_transport_; - scoped_ptr<ReceiveStatistics> receive_stats_; - scoped_ptr<RTPPayloadRegistry> payload_registry_; + const scoped_ptr<ReceiveStatistics> receive_stats_; + const scoped_ptr<RTPPayloadRegistry> payload_registry_; scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_; - Clock* clock_; - unsigned int expected_bitrate_bps_; - SsrcMap rtx_media_ssrcs_; - size_t total_sent_; - size_t padding_sent_; - size_t rtx_media_sent_; - int total_packets_sent_; - int padding_packets_sent_; - int rtx_media_packets_sent_; + + const scoped_ptr<CriticalSectionWrapper> crit_; + unsigned int expected_bitrate_bps_ GUARDED_BY(crit_); + SsrcMap rtx_media_ssrcs_ GUARDED_BY(crit_); + size_t total_sent_ GUARDED_BY(crit_); + size_t padding_sent_ GUARDED_BY(crit_); + size_t rtx_media_sent_ GUARDED_BY(crit_); + int total_packets_sent_ GUARDED_BY(crit_); + int padding_packets_sent_ GUARDED_BY(crit_); + int rtx_media_packets_sent_ GUARDED_BY(crit_); }; class LowRateStreamObserver : public test::DirectTransport, @@ -193,21 +195,21 @@ class LowRateStreamObserver : public test::DirectTransport, Clock* clock, size_t number_of_streams, bool rtx_used) - : critical_section_(CriticalSectionWrapper::CreateCriticalSection()), + : clock_(clock), + number_of_streams_(number_of_streams), + rtx_used_(rtx_used), test_done_(EventWrapper::Create()), rtp_parser_(RtpHeaderParser::Create()), feedback_transport_(feedback_transport), receive_stats_(ReceiveStatistics::Create(clock)), - clock_(clock), + crit_(CriticalSectionWrapper::CreateCriticalSection()), + send_stream_(NULL), test_state_(kFirstRampup), state_start_ms_(clock_->TimeInMilliseconds()), interval_start_ms_(state_start_ms_), last_remb_bps_(0), sent_bytes_(0), total_overuse_bytes_(0), - number_of_streams_(number_of_streams), - rtx_used_(rtx_used), - send_stream_(NULL), suspended_in_stats_(false) { RtpRtcp::Configuration config; config.receive_statistics = receive_stats_.get(); @@ -231,12 +233,13 @@ class LowRateStreamObserver : public test::DirectTransport, } virtual void SetSendStream(const VideoSendStream* send_stream) { + CriticalSectionScoped lock(crit_.get()); send_stream_ = send_stream; } virtual void OnReceiveBitrateChanged(const std::vector<unsigned int>& ssrcs, unsigned int bitrate) { - CriticalSectionScoped lock(critical_section_.get()); + CriticalSectionScoped lock(crit_.get()); rtp_rtcp_->SetREMBData( bitrate, static_cast<uint8_t>(ssrcs.size()), &ssrcs[0]); rtp_rtcp_->Process(); @@ -244,6 +247,7 @@ class LowRateStreamObserver : public test::DirectTransport, } virtual bool SendRtp(const uint8_t* data, size_t length) OVERRIDE { + CriticalSectionScoped lock(crit_.get()); sent_bytes_ += length; int64_t now_ms = clock_->TimeInMilliseconds(); if (now_ms > interval_start_ms_ + 1000) { // Let at least 1 second pass. @@ -265,7 +269,7 @@ class LowRateStreamObserver : public test::DirectTransport, } virtual bool DeliverPacket(const uint8_t* packet, size_t length) OVERRIDE { - CriticalSectionScoped lock(critical_section_.get()); + CriticalSectionScoped lock(crit_.get()); RTPHeader header; EXPECT_TRUE(rtp_parser_->Parse(packet, static_cast<int>(length), &header)); receive_stats_->IncomingPacket(header, length, false); @@ -300,8 +304,8 @@ class LowRateStreamObserver : public test::DirectTransport, // This method defines the state machine for the ramp up-down-up test. void EvolveTestState(unsigned int bitrate_bps) { int64_t now = clock_->TimeInMilliseconds(); + CriticalSectionScoped lock(crit_.get()); assert(send_stream_ != NULL); - CriticalSectionScoped lock(critical_section_.get()); switch (test_state_) { case kFirstRampup: { EXPECT_FALSE(suspended_in_stats_); @@ -374,25 +378,26 @@ class LowRateStreamObserver : public test::DirectTransport, static const unsigned int kExpectedLowBitrateBps = 20000; enum TestStates { kFirstRampup, kLowRate, kSecondRampup }; - scoped_ptr<CriticalSectionWrapper> critical_section_; - scoped_ptr<EventWrapper> test_done_; - scoped_ptr<RtpHeaderParser> rtp_parser_; + Clock* const clock_; + const size_t number_of_streams_; + const bool rtx_used_; + const scoped_ptr<EventWrapper> test_done_; + const scoped_ptr<RtpHeaderParser> rtp_parser_; scoped_ptr<RtpRtcp> rtp_rtcp_; internal::TransportAdapter feedback_transport_; - scoped_ptr<ReceiveStatistics> receive_stats_; + const scoped_ptr<ReceiveStatistics> receive_stats_; scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_; - Clock* clock_; - FakeNetworkPipe::Config forward_transport_config_; - TestStates test_state_; - int64_t state_start_ms_; - int64_t interval_start_ms_; - unsigned int last_remb_bps_; - size_t sent_bytes_; - size_t total_overuse_bytes_; - const size_t number_of_streams_; - const bool rtx_used_; - const VideoSendStream* send_stream_; - bool suspended_in_stats_ GUARDED_BY(critical_section_); + + scoped_ptr<CriticalSectionWrapper> crit_; + const VideoSendStream* send_stream_ GUARDED_BY(crit_); + FakeNetworkPipe::Config forward_transport_config_ GUARDED_BY(crit_); + TestStates test_state_ GUARDED_BY(crit_); + int64_t state_start_ms_ GUARDED_BY(crit_); + int64_t interval_start_ms_ GUARDED_BY(crit_); + unsigned int last_remb_bps_ GUARDED_BY(crit_); + size_t sent_bytes_ GUARDED_BY(crit_); + size_t total_overuse_bytes_ GUARDED_BY(crit_); + bool suspended_in_stats_ GUARDED_BY(crit_); }; } diff --git a/video/receive_statistics_proxy.cc b/video/receive_statistics_proxy.cc index f42e4d33..60042818 100644 --- a/video/receive_statistics_proxy.cc +++ b/video/receive_statistics_proxy.cc @@ -22,13 +22,13 @@ ReceiveStatisticsProxy::ReceiveStatisticsProxy(uint32_t ssrc, ViECodec* codec, int channel) : channel_(channel), - lock_(CriticalSectionWrapper::CreateCriticalSection()), clock_(clock), + codec_(codec), + rtp_rtcp_(rtp_rtcp), + crit_(CriticalSectionWrapper::CreateCriticalSection()), // 1000ms window, scale 1000 for ms to s. decode_fps_estimator_(1000, 1000), - renders_fps_estimator_(1000, 1000), - codec_(codec), - rtp_rtcp_(rtp_rtcp) { + renders_fps_estimator_(1000, 1000) { stats_.ssrc = ssrc; } @@ -37,7 +37,7 @@ ReceiveStatisticsProxy::~ReceiveStatisticsProxy() {} VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const { VideoReceiveStream::Stats stats; { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped lock(crit_.get()); stats = stats_; } stats.c_name = GetCName(); @@ -59,7 +59,7 @@ std::string ReceiveStatisticsProxy::GetCName() const { void ReceiveStatisticsProxy::IncomingRate(const int video_channel, const unsigned int framerate, const unsigned int bitrate) { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped lock(crit_.get()); stats_.network_frame_rate = framerate; stats_.bitrate_bps = bitrate; } @@ -67,7 +67,7 @@ void ReceiveStatisticsProxy::IncomingRate(const int video_channel, void ReceiveStatisticsProxy::StatisticsUpdated( const webrtc::RtcpStatistics& statistics, uint32_t ssrc) { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped lock(crit_.get()); stats_.rtcp_stats = statistics; } @@ -75,7 +75,7 @@ void ReceiveStatisticsProxy::StatisticsUpdated( void ReceiveStatisticsProxy::DataCountersUpdated( const webrtc::StreamDataCounters& counters, uint32_t ssrc) { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped lock(crit_.get()); stats_.rtp_stats = counters; } @@ -83,7 +83,7 @@ void ReceiveStatisticsProxy::DataCountersUpdated( void ReceiveStatisticsProxy::OnDecodedFrame() { uint64_t now = clock_->TimeInMilliseconds(); - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped lock(crit_.get()); decode_fps_estimator_.Update(1, now); stats_.decode_frame_rate = decode_fps_estimator_.Rate(now); } @@ -91,7 +91,7 @@ void ReceiveStatisticsProxy::OnDecodedFrame() { void ReceiveStatisticsProxy::OnRenderedFrame() { uint64_t now = clock_->TimeInMilliseconds(); - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped lock(crit_.get()); renders_fps_estimator_.Update(1, now); stats_.render_frame_rate = renders_fps_estimator_.Rate(now); } diff --git a/video/receive_statistics_proxy.h b/video/receive_statistics_proxy.h index bedebb3f..35e5cc3e 100644 --- a/video/receive_statistics_proxy.h +++ b/video/receive_statistics_proxy.h @@ -16,6 +16,7 @@ #include "webrtc/common_types.h" #include "webrtc/frame_callback.h" #include "webrtc/modules/remote_bitrate_estimator/rate_statistics.h" +#include "webrtc/system_wrappers/interface/thread_annotations.h" #include "webrtc/video_engine/include/vie_codec.h" #include "webrtc/video_engine/include/vie_rtp_rtcp.h" #include "webrtc/video_receive_stream.h" @@ -73,13 +74,14 @@ class ReceiveStatisticsProxy : public ViEDecoderObserver, std::string GetCName() const; const int channel_; - scoped_ptr<CriticalSectionWrapper> lock_; - Clock* clock_; - VideoReceiveStream::Stats stats_; - RateStatistics decode_fps_estimator_; - RateStatistics renders_fps_estimator_; - ViECodec* codec_; - ViERTP_RTCP* rtp_rtcp_; + Clock* const clock_; + ViECodec* const codec_; + ViERTP_RTCP* const rtp_rtcp_; + + scoped_ptr<CriticalSectionWrapper> crit_; + VideoReceiveStream::Stats stats_ GUARDED_BY(crit_); + RateStatistics decode_fps_estimator_ GUARDED_BY(crit_); + RateStatistics renders_fps_estimator_ GUARDED_BY(crit_); }; } // namespace internal diff --git a/video/send_statistics_proxy.cc b/video/send_statistics_proxy.cc index 1cd4e26a..c9bd05c1 100644 --- a/video/send_statistics_proxy.cc +++ b/video/send_statistics_proxy.cc @@ -20,33 +20,34 @@ SendStatisticsProxy::SendStatisticsProxy( const VideoSendStream::Config& config, SendStatisticsProxy::StatsProvider* stats_provider) : config_(config), - lock_(CriticalSectionWrapper::CreateCriticalSection()), - stats_provider_(stats_provider) {} + stats_provider_(stats_provider), + crit_(CriticalSectionWrapper::CreateCriticalSection()) { +} SendStatisticsProxy::~SendStatisticsProxy() {} void SendStatisticsProxy::OutgoingRate(const int video_channel, const unsigned int framerate, const unsigned int bitrate) { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped lock(crit_.get()); stats_.encode_frame_rate = framerate; } void SendStatisticsProxy::SuspendChange(int video_channel, bool is_suspended) { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped lock(crit_.get()); stats_.suspended = is_suspended; } void SendStatisticsProxy::CapturedFrameRate(const int capture_id, const unsigned char frame_rate) { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped lock(crit_.get()); stats_.input_frame_rate = frame_rate; } VideoSendStream::Stats SendStatisticsProxy::GetStats() const { VideoSendStream::Stats stats; { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped lock(crit_.get()); stats = stats_; } stats_provider_->GetSendSideDelay(&stats); @@ -68,7 +69,7 @@ StreamStats* SendStatisticsProxy::GetStatsEntry(uint32_t ssrc) { void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics, uint32_t ssrc) { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped lock(crit_.get()); StreamStats* stats = GetStatsEntry(ssrc); if (stats == NULL) return; @@ -79,7 +80,7 @@ void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics, void SendStatisticsProxy::DataCountersUpdated( const StreamDataCounters& counters, uint32_t ssrc) { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped lock(crit_.get()); StreamStats* stats = GetStatsEntry(ssrc); if (stats == NULL) return; @@ -89,7 +90,7 @@ void SendStatisticsProxy::DataCountersUpdated( void SendStatisticsProxy::Notify(const BitrateStatistics& bitrate, uint32_t ssrc) { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped lock(crit_.get()); StreamStats* stats = GetStatsEntry(ssrc); if (stats == NULL) return; @@ -100,7 +101,7 @@ void SendStatisticsProxy::Notify(const BitrateStatistics& bitrate, void SendStatisticsProxy::FrameCountUpdated(FrameType frame_type, uint32_t frame_count, const unsigned int ssrc) { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped lock(crit_.get()); StreamStats* stats = GetStatsEntry(ssrc); if (stats == NULL) return; diff --git a/video/send_statistics_proxy.h b/video/send_statistics_proxy.h index 2f45ff7f..a1ff14cd 100644 --- a/video/send_statistics_proxy.h +++ b/video/send_statistics_proxy.h @@ -81,12 +81,12 @@ class SendStatisticsProxy : public RtcpStatisticsCallback, const CaptureAlarm alarm) OVERRIDE {} private: - StreamStats* GetStatsEntry(uint32_t ssrc) EXCLUSIVE_LOCKS_REQUIRED(lock_); + StreamStats* GetStatsEntry(uint32_t ssrc) EXCLUSIVE_LOCKS_REQUIRED(crit_); const VideoSendStream::Config config_; - scoped_ptr<CriticalSectionWrapper> lock_; - VideoSendStream::Stats stats_ GUARDED_BY(lock_); StatsProvider* const stats_provider_; + scoped_ptr<CriticalSectionWrapper> crit_; + VideoSendStream::Stats stats_ GUARDED_BY(crit_); }; } // namespace webrtc diff --git a/video/video_receive_stream.h b/video/video_receive_stream.h index b4d13bce..4ff086a5 100644 --- a/video/video_receive_stream.h +++ b/video/video_receive_stream.h @@ -70,7 +70,7 @@ class VideoReceiveStream : public webrtc::VideoReceiveStream, TransportAdapter transport_adapter_; EncodedFrameCallbackAdapter encoded_frame_proxy_; VideoReceiveStream::Config config_; - Clock* clock_; + Clock* const clock_; ViEBase* video_engine_base_; ViECodec* codec_; diff --git a/video/video_send_stream.cc b/video/video_send_stream.cc index 2680b09d..e6e683a1 100644 --- a/video/video_send_stream.cc +++ b/video/video_send_stream.cc @@ -37,7 +37,8 @@ VideoSendStream::VideoSendStream(newapi::Transport* transport, codec_lock_(CriticalSectionWrapper::CreateCriticalSection()), config_(config), external_codec_(NULL), - channel_(-1) { + channel_(-1), + stats_proxy_(new SendStatisticsProxy(config, this)) { video_engine_base_ = ViEBase::GetInterface(video_engine); video_engine_base_->CreateChannel(channel_, base_channel); assert(channel_ != -1); @@ -142,8 +143,6 @@ VideoSendStream::VideoSendStream(newapi::Transport* transport, codec_->SuspendBelowMinBitrate(channel_); } - stats_proxy_.reset(new SendStatisticsProxy(config, this)); - rtp_rtcp_->RegisterSendChannelRtcpStatisticsCallback(channel_, stats_proxy_.get()); rtp_rtcp_->RegisterSendChannelRtpStatisticsCallback(channel_, diff --git a/video/video_send_stream.h b/video/video_send_stream.h index 8cfc2962..b8f5661f 100644 --- a/video/video_send_stream.h +++ b/video/video_send_stream.h @@ -87,7 +87,7 @@ class VideoSendStream : public webrtc::VideoSendStream, int channel_; int capture_id_; - scoped_ptr<SendStatisticsProxy> stats_proxy_; + const scoped_ptr<SendStatisticsProxy> stats_proxy_; }; } // namespace internal } // namespace webrtc diff --git a/video/video_send_stream_tests.cc b/video/video_send_stream_tests.cc index 2845bba7..13ac01cf 100644 --- a/video/video_send_stream_tests.cc +++ b/video/video_send_stream_tests.cc @@ -820,14 +820,14 @@ TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) { : RtpRtcpObserver(30 * 1000), // Timeout after 30 seconds. transport_adapter_(&transport_), clock_(Clock::GetRealTimeClock()), + send_stream_ptr_(send_stream_ptr), + crit_(CriticalSectionWrapper::CreateCriticalSection()), test_state_(kBeforeSuspend), rtp_count_(0), last_sequence_number_(0), suspended_frame_count_(0), low_remb_bps_(0), - high_remb_bps_(0), - crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), - send_stream_ptr_(send_stream_ptr) { + high_remb_bps_(0) { transport_adapter_.Enable(); } @@ -838,13 +838,13 @@ TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) { virtual Action OnSendRtcp(const uint8_t* packet, size_t length) OVERRIDE { // Receive statistics reporting having lost 0% of the packets. // This is needed for the send-side bitrate controller to work properly. - CriticalSectionScoped lock(crit_sect_.get()); + CriticalSectionScoped lock(crit_.get()); SendRtcpFeedback(0); // REMB is only sent if value is > 0. return SEND_PACKET; } virtual Action OnSendRtp(const uint8_t* packet, size_t length) OVERRIDE { - CriticalSectionScoped lock(crit_sect_.get()); + CriticalSectionScoped lock(crit_.get()); ++rtp_count_; RTPHeader header; EXPECT_TRUE(parser_->Parse(packet, static_cast<int>(length), &header)); @@ -880,7 +880,7 @@ TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) { // This method implements the I420FrameCallback. void FrameCallback(I420VideoFrame* video_frame) OVERRIDE { - CriticalSectionScoped lock(crit_sect_.get()); + CriticalSectionScoped lock(crit_.get()); if (test_state_ == kDuringSuspend && ++suspended_frame_count_ > kSuspendTimeFrames) { assert(*send_stream_ptr_); @@ -891,9 +891,15 @@ TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) { } } - void set_low_remb_bps(int value) { low_remb_bps_ = value; } + void set_low_remb_bps(int value) { + CriticalSectionScoped lock(crit_.get()); + low_remb_bps_ = value; + } - void set_high_remb_bps(int value) { high_remb_bps_ = value; } + void set_high_remb_bps(int value) { + CriticalSectionScoped lock(crit_.get()); + high_remb_bps_ = value; + } void Stop() { transport_.StopSending(); } @@ -905,7 +911,8 @@ TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) { kWaitingForStats }; - virtual void SendRtcpFeedback(int remb_value) { + virtual void SendRtcpFeedback(int remb_value) + EXCLUSIVE_LOCKS_REQUIRED(crit_) { FakeReceiveStatistics receive_stats( kSendSsrc, last_sequence_number_, rtp_count_, 0); RTCPSender rtcp_sender(0, false, clock_, &receive_stats); @@ -923,15 +930,16 @@ TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) { internal::TransportAdapter transport_adapter_; test::DirectTransport transport_; - Clock* clock_; - TestState test_state_; - int rtp_count_; - int last_sequence_number_; - int suspended_frame_count_; - int low_remb_bps_; - int high_remb_bps_; - scoped_ptr<CriticalSectionWrapper> crit_sect_; - VideoSendStream** send_stream_ptr_; + Clock* const clock_; + VideoSendStream** const send_stream_ptr_; + + const scoped_ptr<CriticalSectionWrapper> crit_; + TestState test_state_ GUARDED_BY(crit_); + int rtp_count_ GUARDED_BY(crit_); + int last_sequence_number_ GUARDED_BY(crit_); + int suspended_frame_count_ GUARDED_BY(crit_); + int low_remb_bps_ GUARDED_BY(crit_); + int high_remb_bps_ GUARDED_BY(crit_); } observer(&send_stream_); // Note that |send_stream_| is created in RunSendTest(), called below. This // is why a pointer to |send_stream_| must be provided here. @@ -961,26 +969,27 @@ TEST_F(VideoSendStreamTest, NoPaddingWhenVideoIsMuted) { PacketObserver() : RtpRtcpObserver(30 * 1000), // Timeout after 30 seconds. clock_(Clock::GetRealTimeClock()), - last_packet_time_ms_(-1), transport_adapter_(ReceiveTransport()), - capturer_(NULL), - crit_sect_(CriticalSectionWrapper::CreateCriticalSection()) { + crit_(CriticalSectionWrapper::CreateCriticalSection()), + last_packet_time_ms_(-1), + capturer_(NULL) { transport_adapter_.Enable(); } void SetCapturer(test::FrameGeneratorCapturer* capturer) { + CriticalSectionScoped lock(crit_.get()); capturer_ = capturer; } virtual Action OnSendRtp(const uint8_t* packet, size_t length) OVERRIDE { - CriticalSectionScoped lock(crit_sect_.get()); + CriticalSectionScoped lock(crit_.get()); last_packet_time_ms_ = clock_->TimeInMilliseconds(); capturer_->Stop(); return SEND_PACKET; } virtual Action OnSendRtcp(const uint8_t* packet, size_t length) OVERRIDE { - CriticalSectionScoped lock(crit_sect_.get()); + CriticalSectionScoped lock(crit_.get()); const int kVideoMutedThresholdMs = 10000; if (last_packet_time_ms_ > 0 && clock_->TimeInMilliseconds() - last_packet_time_ms_ > @@ -1002,11 +1011,11 @@ TEST_F(VideoSendStreamTest, NoPaddingWhenVideoIsMuted) { } private: - Clock* clock_; - int64_t last_packet_time_ms_; + Clock* const clock_; internal::TransportAdapter transport_adapter_; - test::FrameGeneratorCapturer* capturer_; - scoped_ptr<CriticalSectionWrapper> crit_sect_; + const scoped_ptr<CriticalSectionWrapper> crit_; + int64_t last_packet_time_ms_ GUARDED_BY(crit_); + test::FrameGeneratorCapturer* capturer_ GUARDED_BY(crit_); } observer; Call::Config call_config(observer.SendTransport()); diff --git a/video_engine/test/auto_test/automated/vie_extended_integration_test.cc b/video_engine/test/auto_test/automated/vie_extended_integration_test.cc index 01d92d1c..e43fc751 100644 --- a/video_engine/test/auto_test/automated/vie_extended_integration_test.cc +++ b/video_engine/test/auto_test/automated/vie_extended_integration_test.cc @@ -53,7 +53,7 @@ TEST_F(DISABLED_ON_MAC(ViEExtendedIntegrationTest), } TEST_F(DISABLED_ON_MAC(ViEExtendedIntegrationTest), - RunsRtpRtcpTestWithoutErrors) { + DISABLED_RunsRtpRtcpTestWithoutErrors) { tests_->ViERtpRtcpExtendedTest(); } diff --git a/video_engine/test/auto_test/automated/vie_standard_integration_test.cc b/video_engine/test/auto_test/automated/vie_standard_integration_test.cc index 51208bad..584f9e92 100644 --- a/video_engine/test/auto_test/automated/vie_standard_integration_test.cc +++ b/video_engine/test/auto_test/automated/vie_standard_integration_test.cc @@ -51,13 +51,8 @@ TEST_F(ViEStandardIntegrationTest, RunsRenderTestWithoutErrors) { tests_->ViERenderStandardTest(); } -// Fails on Mac, see https://code.google.com/p/webrtc/issues/detail?id=1790 -#if defined(WEBRTC_MAC) -#define MAYBE_RunsRtpRtcpTestWithoutErrors DISABLED_RunsRtpRtcpTestWithoutErrors -#else -#define MAYBE_RunsRtpRtcpTestWithoutErrors RunsRtpRtcpTestWithoutErrors -#endif -TEST_F(ViEStandardIntegrationTest, MAYBE_RunsRtpRtcpTestWithoutErrors) { +// Flaky, see webrtc:1790. +TEST_F(ViEStandardIntegrationTest, DISABLED_RunsRtpRtcpTestWithoutErrors) { tests_->ViERtpRtcpStandardTest(); } diff --git a/video_engine/test/auto_test/source/vie_autotest_codec.cc b/video_engine/test/auto_test/source/vie_autotest_codec.cc index d806b47b..93738c2a 100644 --- a/video_engine/test/auto_test/source/vie_autotest_codec.cc +++ b/video_engine/test/auto_test/source/vie_autotest_codec.cc @@ -510,6 +510,13 @@ void ViEAutoTest::ViECodecAPITest() { break; } } + const unsigned int kMinBitrate = 123; + video_codec.minBitrate = kMinBitrate; + video_codec.startBitrate = 50; + EXPECT_EQ(0, codec->SetSendCodec(video_channel, video_codec)); + EXPECT_EQ(0, codec->GetSendCodec(video_channel, video_codec)); + EXPECT_EQ(kMinBitrate, video_codec.startBitrate); + memset(&video_codec, 0, sizeof(video_codec)); EXPECT_EQ(0, codec->GetSendCodec(video_channel, video_codec)); EXPECT_EQ(webrtc::kVideoCodecVP8, video_codec.codecType); diff --git a/video_engine/test/libvietest/helpers/vie_to_file_renderer.cc b/video_engine/test/libvietest/helpers/vie_to_file_renderer.cc index 78649576..16c73f4e 100644 --- a/video_engine/test/libvietest/helpers/vie_to_file_renderer.cc +++ b/video_engine/test/libvietest/helpers/vie_to_file_renderer.cc @@ -30,7 +30,7 @@ struct Frame { memcpy(this->buffer.get(), buffer, buffer_size); } - webrtc::scoped_array<unsigned char> buffer; + webrtc::scoped_ptr<unsigned char[]> buffer; int buffer_size; uint32_t timestamp; int64_t render_time; diff --git a/video_engine/vie_capturer.cc b/video_engine/vie_capturer.cc index 94993ca4..65159a1d 100644 --- a/video_engine/vie_capturer.cc +++ b/video_engine/vie_capturer.cc @@ -535,7 +535,7 @@ void ViECapturer::DeliverI420Frame(I420VideoFrame* video_frame) { unsigned int length = CalcBufferSize(kI420, video_frame->width(), video_frame->height()); - scoped_array<uint8_t> video_buffer(new uint8_t[length]); + scoped_ptr<uint8_t[]> video_buffer(new uint8_t[length]); ExtractBuffer(*video_frame, length, video_buffer.get()); effect_filter_->Transform(length, video_buffer.get(), diff --git a/video_engine/vie_channel.cc b/video_engine/vie_channel.cc index 94210a37..d5e08787 100644 --- a/video_engine/vie_channel.cc +++ b/video_engine/vie_channel.cc @@ -1401,7 +1401,7 @@ int32_t ViEChannel::FrameToRender( unsigned int length = CalcBufferSize(kI420, video_frame.width(), video_frame.height()); - scoped_array<uint8_t> video_buffer(new uint8_t[length]); + scoped_ptr<uint8_t[]> video_buffer(new uint8_t[length]); ExtractBuffer(video_frame, length, video_buffer.get()); effect_filter_->Transform(length, video_buffer.get(), diff --git a/video_engine/vie_codec_impl.cc b/video_engine/vie_codec_impl.cc index 9ea3c9c0..3ba56de5 100644 --- a/video_engine/vie_codec_impl.cc +++ b/video_engine/vie_codec_impl.cc @@ -169,6 +169,9 @@ int ViECodecImpl::SetSendCodec(const int video_channel, LOG(LS_INFO) << "New max bitrate set " << video_codec_internal.maxBitrate; } + if (video_codec_internal.startBitrate < video_codec_internal.minBitrate) { + video_codec_internal.startBitrate = video_codec_internal.minBitrate; + } if (video_codec_internal.startBitrate > video_codec_internal.maxBitrate) { video_codec_internal.startBitrate = video_codec_internal.maxBitrate; } diff --git a/video_engine/vie_encoder.cc b/video_engine/vie_encoder.cc index e2b70eb6..957407da 100644 --- a/video_engine/vie_encoder.cc +++ b/video_engine/vie_encoder.cc @@ -503,7 +503,7 @@ void ViEEncoder::DeliverFrame(int id, unsigned int length = CalcBufferSize(kI420, video_frame->width(), video_frame->height()); - scoped_array<uint8_t> video_buffer(new uint8_t[length]); + scoped_ptr<uint8_t[]> video_buffer(new uint8_t[length]); ExtractBuffer(*video_frame, length, video_buffer.get()); effect_filter_->Transform(length, video_buffer.get(), diff --git a/voice_engine/channel.cc b/voice_engine/channel.cc index 5f6de0e3..b3c53f85 100644 --- a/voice_engine/channel.cc +++ b/voice_engine/channel.cc @@ -4279,7 +4279,7 @@ Channel::GetRtpRtcp(RtpRtcp** rtpRtcpModule, RtpReceiver** rtp_receiver) const int32_t Channel::MixOrReplaceAudioWithFile(int mixingFrequency) { - scoped_array<int16_t> fileBuffer(new int16_t[640]); + scoped_ptr<int16_t[]> fileBuffer(new int16_t[640]); int fileSamples(0); { @@ -4349,7 +4349,7 @@ Channel::MixAudioWithFile(AudioFrame& audioFrame, { assert(mixingFrequency <= 32000); - scoped_array<int16_t> fileBuffer(new int16_t[640]); + scoped_ptr<int16_t[]> fileBuffer(new int16_t[640]); int fileSamples(0); { diff --git a/voice_engine/include/mock/fake_voe_external_media.h b/voice_engine/include/mock/fake_voe_external_media.h index f45e1ba0..b327f3c5 100644 --- a/voice_engine/include/mock/fake_voe_external_media.h +++ b/voice_engine/include/mock/fake_voe_external_media.h @@ -53,7 +53,7 @@ class FakeVoEExternalMedia : public VoEExternalMedia { int samples_per_channel, int sample_rate_hz, int num_channels) { const int length = samples_per_channel * num_channels; - scoped_array<int16_t> data; + scoped_ptr<int16_t[]> data; if (!audio) { data.reset(new int16_t[length]); memset(data.get(), 0, length * sizeof(data[0])); diff --git a/voice_engine/transmit_mixer.cc b/voice_engine/transmit_mixer.cc index d2467cf9..cce2f946 100644 --- a/voice_engine/transmit_mixer.cc +++ b/voice_engine/transmit_mixer.cc @@ -1217,7 +1217,7 @@ int32_t TransmitMixer::RecordAudioToFile( int32_t TransmitMixer::MixOrReplaceAudioWithFile( int mixingFrequency) { - scoped_array<int16_t> fileBuffer(new int16_t[640]); + scoped_ptr<int16_t[]> fileBuffer(new int16_t[640]); int fileSamples(0); { |