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

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

Issue 605803004: [cast] Allow audio encoder implementations to specify the frame length. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move inline namespace back inside media::cast to better match original file. Created 6 years, 1 month 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.cc » ('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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <sstream> 7 #include <sstream>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 21 matching lines...) Expand all
32 virtual ~TestEncodedAudioFrameReceiver() {} 32 virtual ~TestEncodedAudioFrameReceiver() {}
33 33
34 int frames_received() const { return frames_received_; } 34 int frames_received() const { return frames_received_; }
35 35
36 void SetCaptureTimeBounds(const base::TimeTicks& lower_bound, 36 void SetCaptureTimeBounds(const base::TimeTicks& lower_bound,
37 const base::TimeTicks& upper_bound) { 37 const base::TimeTicks& upper_bound) {
38 lower_bound_ = lower_bound; 38 lower_bound_ = lower_bound;
39 upper_bound_ = upper_bound; 39 upper_bound_ = upper_bound;
40 } 40 }
41 41
42 void SetSamplesPerFrame(int samples_per_frame) {
43 samples_per_frame_ = samples_per_frame;
44 }
45
42 void FrameEncoded(scoped_ptr<EncodedFrame> encoded_frame, 46 void FrameEncoded(scoped_ptr<EncodedFrame> encoded_frame,
43 int samples_skipped) { 47 int samples_skipped) {
44 EXPECT_EQ(encoded_frame->dependency, EncodedFrame::KEY); 48 EXPECT_EQ(encoded_frame->dependency, EncodedFrame::KEY);
45 EXPECT_EQ(static_cast<uint8>(frames_received_ & 0xff), 49 EXPECT_EQ(static_cast<uint8>(frames_received_ & 0xff),
46 encoded_frame->frame_id); 50 encoded_frame->frame_id);
47 EXPECT_EQ(encoded_frame->frame_id, encoded_frame->referenced_frame_id); 51 EXPECT_EQ(encoded_frame->frame_id, encoded_frame->referenced_frame_id);
48 // RTP timestamps should be monotonically increasing and integer multiples 52 // RTP timestamps should be monotonically increasing and integer multiples
49 // of the fixed frame size. 53 // of the fixed frame size.
50 EXPECT_LE(rtp_lower_bound_, encoded_frame->rtp_timestamp); 54 EXPECT_LE(rtp_lower_bound_, encoded_frame->rtp_timestamp);
51 rtp_lower_bound_ = encoded_frame->rtp_timestamp; 55 rtp_lower_bound_ = encoded_frame->rtp_timestamp;
52 // Note: In audio_encoder.cc, 100 is the fixed audio frame rate. 56 EXPECT_EQ(0u, encoded_frame->rtp_timestamp % samples_per_frame_);
53 const int kSamplesPerFrame = kDefaultAudioSamplingRate / 100;
54 EXPECT_EQ(0u, encoded_frame->rtp_timestamp % kSamplesPerFrame);
55 EXPECT_TRUE(!encoded_frame->data.empty()); 57 EXPECT_TRUE(!encoded_frame->data.empty());
56 58
57 EXPECT_LE(lower_bound_, encoded_frame->reference_time); 59 EXPECT_LE(lower_bound_, encoded_frame->reference_time);
58 lower_bound_ = encoded_frame->reference_time; 60 lower_bound_ = encoded_frame->reference_time;
59 EXPECT_GT(upper_bound_, encoded_frame->reference_time); 61 EXPECT_GT(upper_bound_, encoded_frame->reference_time);
60 62
61 ++frames_received_; 63 ++frames_received_;
62 } 64 }
63 65
64 private: 66 private:
65 const Codec codec_; 67 const Codec codec_;
66 int frames_received_; 68 int frames_received_;
67 uint32 rtp_lower_bound_; 69 uint32 rtp_lower_bound_;
70 int samples_per_frame_;
68 base::TimeTicks lower_bound_; 71 base::TimeTicks lower_bound_;
69 base::TimeTicks upper_bound_; 72 base::TimeTicks upper_bound_;
70 73
71 DISALLOW_COPY_AND_ASSIGN(TestEncodedAudioFrameReceiver); 74 DISALLOW_COPY_AND_ASSIGN(TestEncodedAudioFrameReceiver);
72 }; 75 };
73 76
74 struct TestScenario { 77 struct TestScenario {
75 const int64* durations_in_ms; 78 const int64* durations_in_ms;
76 size_t num_durations; 79 size_t num_durations;
77 80
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 112 }
110 113
111 virtual ~AudioEncoderTest() {} 114 virtual ~AudioEncoderTest() {}
112 115
113 void RunTestForCodec(Codec codec) { 116 void RunTestForCodec(Codec codec) {
114 const TestScenario& scenario = GetParam(); 117 const TestScenario& scenario = GetParam();
115 SCOPED_TRACE(::testing::Message() << "Durations: " << scenario.ToString()); 118 SCOPED_TRACE(::testing::Message() << "Durations: " << scenario.ToString());
116 119
117 CreateObjectsForCodec(codec); 120 CreateObjectsForCodec(codec);
118 121
119 // Note: In audio_encoder.cc, 10 ms is the fixed frame duration. 122 const base::TimeDelta frame_duration = audio_encoder_->GetFrameDuration();
120 const base::TimeDelta frame_duration =
121 base::TimeDelta::FromMilliseconds(10);
122 123
123 for (size_t i = 0; i < scenario.num_durations; ++i) { 124 for (size_t i = 0; i < scenario.num_durations; ++i) {
124 const bool simulate_missing_data = scenario.durations_in_ms[i] < 0; 125 const bool simulate_missing_data = scenario.durations_in_ms[i] < 0;
125 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds( 126 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(
126 std::abs(scenario.durations_in_ms[i])); 127 std::abs(scenario.durations_in_ms[i]));
127 receiver_->SetCaptureTimeBounds( 128 receiver_->SetCaptureTimeBounds(
128 testing_clock_->NowTicks() - frame_duration, 129 testing_clock_->NowTicks() - frame_duration,
129 testing_clock_->NowTicks() + duration); 130 testing_clock_->NowTicks() + duration);
130 if (simulate_missing_data) { 131 if (simulate_missing_data) {
131 task_runner_->RunTasks(); 132 task_runner_->RunTasks();
(...skipping 21 matching lines...) Expand all
153 receiver_.reset(new TestEncodedAudioFrameReceiver(codec)); 154 receiver_.reset(new TestEncodedAudioFrameReceiver(codec));
154 155
155 audio_encoder_.reset(new AudioEncoder( 156 audio_encoder_.reset(new AudioEncoder(
156 cast_environment_, 157 cast_environment_,
157 kNumChannels, 158 kNumChannels,
158 kDefaultAudioSamplingRate, 159 kDefaultAudioSamplingRate,
159 kDefaultAudioEncoderBitrate, 160 kDefaultAudioEncoderBitrate,
160 codec, 161 codec,
161 base::Bind(&TestEncodedAudioFrameReceiver::FrameEncoded, 162 base::Bind(&TestEncodedAudioFrameReceiver::FrameEncoded,
162 base::Unretained(receiver_.get())))); 163 base::Unretained(receiver_.get()))));
164
165 receiver_->SetSamplesPerFrame(audio_encoder_->GetSamplesPerFrame());
163 } 166 }
164 167
165 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment. 168 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment.
166 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; 169 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
167 scoped_ptr<TestAudioBusFactory> audio_bus_factory_; 170 scoped_ptr<TestAudioBusFactory> audio_bus_factory_;
168 scoped_ptr<TestEncodedAudioFrameReceiver> receiver_; 171 scoped_ptr<TestEncodedAudioFrameReceiver> receiver_;
169 scoped_ptr<AudioEncoder> audio_encoder_; 172 scoped_ptr<AudioEncoder> audio_encoder_;
170 scoped_refptr<CastEnvironment> cast_environment_; 173 scoped_refptr<CastEnvironment> cast_environment_;
171 174
172 DISALLOW_COPY_AND_ASSIGN(AudioEncoderTest); 175 DISALLOW_COPY_AND_ASSIGN(AudioEncoderTest);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 TestScenario(kManyCalls_Mixed2, arraysize(kManyCalls_Mixed2)), 236 TestScenario(kManyCalls_Mixed2, arraysize(kManyCalls_Mixed2)),
234 TestScenario(kManyCalls_Mixed3, arraysize(kManyCalls_Mixed3)), 237 TestScenario(kManyCalls_Mixed3, arraysize(kManyCalls_Mixed3)),
235 TestScenario(kManyCalls_Mixed4, arraysize(kManyCalls_Mixed4)), 238 TestScenario(kManyCalls_Mixed4, arraysize(kManyCalls_Mixed4)),
236 TestScenario(kManyCalls_Mixed5, arraysize(kManyCalls_Mixed5)), 239 TestScenario(kManyCalls_Mixed5, arraysize(kManyCalls_Mixed5)),
237 TestScenario(kOneBigUnderrun, arraysize(kOneBigUnderrun)), 240 TestScenario(kOneBigUnderrun, arraysize(kOneBigUnderrun)),
238 TestScenario(kTwoBigUnderruns, arraysize(kTwoBigUnderruns)), 241 TestScenario(kTwoBigUnderruns, arraysize(kTwoBigUnderruns)),
239 TestScenario(kMixedUnderruns, arraysize(kMixedUnderruns)))); 242 TestScenario(kMixedUnderruns, arraysize(kMixedUnderruns))));
240 243
241 } // namespace cast 244 } // namespace cast
242 } // namespace media 245 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/sender/audio_encoder.cc ('k') | media/cast/sender/audio_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698