Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: media/cast/sender/audio_encoder_unittest.cc

Issue 1905763002: Convert //media/cast from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/cast/sender/audio_encoder.cc ('k') | media/cast/sender/audio_sender.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/cast/sender/audio_encoder.h"
6
5 #include <stddef.h> 7 #include <stddef.h>
6 #include <stdint.h> 8 #include <stdint.h>
7 9
10 #include <memory>
8 #include <sstream> 11 #include <sstream>
9 #include <string> 12 #include <string>
10 13
11 #include "base/bind.h" 14 #include "base/bind.h"
12 #include "base/bind_helpers.h" 15 #include "base/bind_helpers.h"
13 #include "base/macros.h" 16 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "build/build_config.h" 17 #include "build/build_config.h"
16 #include "media/base/audio_bus.h" 18 #include "media/base/audio_bus.h"
17 #include "media/base/fake_single_thread_task_runner.h" 19 #include "media/base/fake_single_thread_task_runner.h"
18 #include "media/base/media.h" 20 #include "media/base/media.h"
19 #include "media/cast/cast_config.h" 21 #include "media/cast/cast_config.h"
20 #include "media/cast/cast_environment.h" 22 #include "media/cast/cast_environment.h"
21 #include "media/cast/common/rtp_time.h" 23 #include "media/cast/common/rtp_time.h"
22 #include "media/cast/sender/audio_encoder.h"
23 #include "media/cast/test/utility/audio_utility.h" 24 #include "media/cast/test/utility/audio_utility.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 26
26 namespace media { 27 namespace media {
27 namespace cast { 28 namespace cast {
28 29
29 static const int kNumChannels = 2; 30 static const int kNumChannels = 2;
30 31
31 namespace { 32 namespace {
32 33
33 class TestEncodedAudioFrameReceiver { 34 class TestEncodedAudioFrameReceiver {
34 public: 35 public:
35 TestEncodedAudioFrameReceiver() : frames_received_(0) {} 36 TestEncodedAudioFrameReceiver() : frames_received_(0) {}
36 virtual ~TestEncodedAudioFrameReceiver() {} 37 virtual ~TestEncodedAudioFrameReceiver() {}
37 38
38 int frames_received() const { return frames_received_; } 39 int frames_received() const { return frames_received_; }
39 40
40 void SetCaptureTimeBounds(const base::TimeTicks& lower_bound, 41 void SetCaptureTimeBounds(const base::TimeTicks& lower_bound,
41 const base::TimeTicks& upper_bound) { 42 const base::TimeTicks& upper_bound) {
42 lower_bound_ = lower_bound; 43 lower_bound_ = lower_bound;
43 upper_bound_ = upper_bound; 44 upper_bound_ = upper_bound;
44 } 45 }
45 46
46 void SetSamplesPerFrame(int samples_per_frame) { 47 void SetSamplesPerFrame(int samples_per_frame) {
47 samples_per_frame_ = samples_per_frame; 48 samples_per_frame_ = samples_per_frame;
48 } 49 }
49 50
50 void FrameEncoded(scoped_ptr<SenderEncodedFrame> encoded_frame, 51 void FrameEncoded(std::unique_ptr<SenderEncodedFrame> encoded_frame,
51 int samples_skipped) { 52 int samples_skipped) {
52 EXPECT_EQ(encoded_frame->dependency, EncodedFrame::KEY); 53 EXPECT_EQ(encoded_frame->dependency, EncodedFrame::KEY);
53 EXPECT_EQ(static_cast<uint8_t>(frames_received_ & 0xff), 54 EXPECT_EQ(static_cast<uint8_t>(frames_received_ & 0xff),
54 encoded_frame->frame_id); 55 encoded_frame->frame_id);
55 EXPECT_EQ(encoded_frame->frame_id, encoded_frame->referenced_frame_id); 56 EXPECT_EQ(encoded_frame->frame_id, encoded_frame->referenced_frame_id);
56 // RTP timestamps should be monotonically increasing and integer multiples 57 // RTP timestamps should be monotonically increasing and integer multiples
57 // of the fixed frame size. 58 // of the fixed frame size.
58 EXPECT_LE(rtp_lower_bound_, encoded_frame->rtp_timestamp); 59 EXPECT_LE(rtp_lower_bound_, encoded_frame->rtp_timestamp);
59 rtp_lower_bound_ = encoded_frame->rtp_timestamp; 60 rtp_lower_bound_ = encoded_frame->rtp_timestamp;
60 EXPECT_EQ(RtpTimeDelta(), (encoded_frame->rtp_timestamp - RtpTimeTicks()) % 61 EXPECT_EQ(RtpTimeDelta(), (encoded_frame->rtp_timestamp - RtpTimeTicks()) %
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 public: 106 public:
106 AudioEncoderTest() { 107 AudioEncoderTest() {
107 InitializeMediaLibrary(); 108 InitializeMediaLibrary();
108 testing_clock_ = new base::SimpleTestTickClock(); 109 testing_clock_ = new base::SimpleTestTickClock();
109 testing_clock_->Advance(base::TimeTicks::Now() - base::TimeTicks()); 110 testing_clock_->Advance(base::TimeTicks::Now() - base::TimeTicks());
110 } 111 }
111 112
112 void SetUp() final { 113 void SetUp() final {
113 task_runner_ = new FakeSingleThreadTaskRunner(testing_clock_); 114 task_runner_ = new FakeSingleThreadTaskRunner(testing_clock_);
114 cast_environment_ = 115 cast_environment_ =
115 new CastEnvironment(scoped_ptr<base::TickClock>(testing_clock_), 116 new CastEnvironment(std::unique_ptr<base::TickClock>(testing_clock_),
116 task_runner_, task_runner_, task_runner_); 117 task_runner_, task_runner_, task_runner_);
117 } 118 }
118 119
119 virtual ~AudioEncoderTest() {} 120 virtual ~AudioEncoderTest() {}
120 121
121 void RunTestForCodec(Codec codec) { 122 void RunTestForCodec(Codec codec) {
122 const TestScenario& scenario = GetParam(); 123 const TestScenario& scenario = GetParam();
123 SCOPED_TRACE(::testing::Message() << "Durations: " << scenario.ToString()); 124 SCOPED_TRACE(::testing::Message() << "Durations: " << scenario.ToString());
124 125
125 CreateObjectsForCodec(codec); 126 CreateObjectsForCodec(codec);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 kDefaultAudioEncoderBitrate, 166 kDefaultAudioEncoderBitrate,
166 codec, 167 codec,
167 base::Bind(&TestEncodedAudioFrameReceiver::FrameEncoded, 168 base::Bind(&TestEncodedAudioFrameReceiver::FrameEncoded,
168 base::Unretained(receiver_.get())))); 169 base::Unretained(receiver_.get()))));
169 170
170 receiver_->SetSamplesPerFrame(audio_encoder_->GetSamplesPerFrame()); 171 receiver_->SetSamplesPerFrame(audio_encoder_->GetSamplesPerFrame());
171 } 172 }
172 173
173 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment. 174 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment.
174 scoped_refptr<FakeSingleThreadTaskRunner> task_runner_; 175 scoped_refptr<FakeSingleThreadTaskRunner> task_runner_;
175 scoped_ptr<TestAudioBusFactory> audio_bus_factory_; 176 std::unique_ptr<TestAudioBusFactory> audio_bus_factory_;
176 scoped_ptr<TestEncodedAudioFrameReceiver> receiver_; 177 std::unique_ptr<TestEncodedAudioFrameReceiver> receiver_;
177 scoped_ptr<AudioEncoder> audio_encoder_; 178 std::unique_ptr<AudioEncoder> audio_encoder_;
178 scoped_refptr<CastEnvironment> cast_environment_; 179 scoped_refptr<CastEnvironment> cast_environment_;
179 180
180 DISALLOW_COPY_AND_ASSIGN(AudioEncoderTest); 181 DISALLOW_COPY_AND_ASSIGN(AudioEncoderTest);
181 }; 182 };
182 183
183 TEST_P(AudioEncoderTest, EncodeOpus) { 184 TEST_P(AudioEncoderTest, EncodeOpus) {
184 RunTestForCodec(CODEC_AUDIO_OPUS); 185 RunTestForCodec(CODEC_AUDIO_OPUS);
185 } 186 }
186 187
187 TEST_P(AudioEncoderTest, EncodePcm16) { 188 TEST_P(AudioEncoderTest, EncodePcm16) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 TestScenario(kManyCalls_Mixed2, arraysize(kManyCalls_Mixed2)), 248 TestScenario(kManyCalls_Mixed2, arraysize(kManyCalls_Mixed2)),
248 TestScenario(kManyCalls_Mixed3, arraysize(kManyCalls_Mixed3)), 249 TestScenario(kManyCalls_Mixed3, arraysize(kManyCalls_Mixed3)),
249 TestScenario(kManyCalls_Mixed4, arraysize(kManyCalls_Mixed4)), 250 TestScenario(kManyCalls_Mixed4, arraysize(kManyCalls_Mixed4)),
250 TestScenario(kManyCalls_Mixed5, arraysize(kManyCalls_Mixed5)), 251 TestScenario(kManyCalls_Mixed5, arraysize(kManyCalls_Mixed5)),
251 TestScenario(kOneBigUnderrun, arraysize(kOneBigUnderrun)), 252 TestScenario(kOneBigUnderrun, arraysize(kOneBigUnderrun)),
252 TestScenario(kTwoBigUnderruns, arraysize(kTwoBigUnderruns)), 253 TestScenario(kTwoBigUnderruns, arraysize(kTwoBigUnderruns)),
253 TestScenario(kMixedUnderruns, arraysize(kMixedUnderruns)))); 254 TestScenario(kMixedUnderruns, arraysize(kMixedUnderruns))));
254 255
255 } // namespace cast 256 } // namespace cast
256 } // namespace media 257 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/sender/audio_encoder.cc ('k') | media/cast/sender/audio_sender.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698