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

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

Issue 1515433002: Replace uses of raw uint32's with a type-checked RtpTimeTicks data type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
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"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "media/base/audio_bus.h" 13 #include "media/base/audio_bus.h"
14 #include "media/base/media.h" 14 #include "media/base/media.h"
15 #include "media/cast/cast_config.h" 15 #include "media/cast/cast_config.h"
16 #include "media/cast/cast_environment.h" 16 #include "media/cast/cast_environment.h"
17 #include "media/cast/common/rtp_time.h"
17 #include "media/cast/sender/audio_encoder.h" 18 #include "media/cast/sender/audio_encoder.h"
18 #include "media/cast/test/fake_single_thread_task_runner.h" 19 #include "media/cast/test/fake_single_thread_task_runner.h"
19 #include "media/cast/test/utility/audio_utility.h" 20 #include "media/cast/test/utility/audio_utility.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 namespace media { 23 namespace media {
23 namespace cast { 24 namespace cast {
24 25
25 static const int kNumChannels = 2; 26 static const int kNumChannels = 2;
26 27
27 namespace { 28 namespace {
28 29
29 class TestEncodedAudioFrameReceiver { 30 class TestEncodedAudioFrameReceiver {
30 public: 31 public:
31 TestEncodedAudioFrameReceiver() : frames_received_(0), rtp_lower_bound_(0) {} 32 TestEncodedAudioFrameReceiver() : frames_received_(0) {}
32 virtual ~TestEncodedAudioFrameReceiver() {} 33 virtual ~TestEncodedAudioFrameReceiver() {}
33 34
34 int frames_received() const { return frames_received_; } 35 int frames_received() const { return frames_received_; }
35 36
36 void SetCaptureTimeBounds(const base::TimeTicks& lower_bound, 37 void SetCaptureTimeBounds(const base::TimeTicks& lower_bound,
37 const base::TimeTicks& upper_bound) { 38 const base::TimeTicks& upper_bound) {
38 lower_bound_ = lower_bound; 39 lower_bound_ = lower_bound;
39 upper_bound_ = upper_bound; 40 upper_bound_ = upper_bound;
40 } 41 }
41 42
42 void SetSamplesPerFrame(int samples_per_frame) { 43 void SetSamplesPerFrame(int samples_per_frame) {
43 samples_per_frame_ = samples_per_frame; 44 samples_per_frame_ = samples_per_frame;
44 } 45 }
45 46
46 void FrameEncoded(scoped_ptr<SenderEncodedFrame> encoded_frame, 47 void FrameEncoded(scoped_ptr<SenderEncodedFrame> encoded_frame,
47 int samples_skipped) { 48 int samples_skipped) {
48 EXPECT_EQ(encoded_frame->dependency, EncodedFrame::KEY); 49 EXPECT_EQ(encoded_frame->dependency, EncodedFrame::KEY);
49 EXPECT_EQ(static_cast<uint8>(frames_received_ & 0xff), 50 EXPECT_EQ(static_cast<uint8>(frames_received_ & 0xff),
50 encoded_frame->frame_id); 51 encoded_frame->frame_id);
51 EXPECT_EQ(encoded_frame->frame_id, encoded_frame->referenced_frame_id); 52 EXPECT_EQ(encoded_frame->frame_id, encoded_frame->referenced_frame_id);
52 // RTP timestamps should be monotonically increasing and integer multiples 53 // RTP timestamps should be monotonically increasing and integer multiples
53 // of the fixed frame size. 54 // of the fixed frame size.
54 EXPECT_LE(rtp_lower_bound_, encoded_frame->rtp_timestamp); 55 EXPECT_LE(rtp_lower_bound_, encoded_frame->rtp_timestamp);
55 rtp_lower_bound_ = encoded_frame->rtp_timestamp; 56 rtp_lower_bound_ = encoded_frame->rtp_timestamp;
56 EXPECT_EQ(0u, encoded_frame->rtp_timestamp % samples_per_frame_); 57 EXPECT_EQ(RtpTimeDelta(), (encoded_frame->rtp_timestamp - RtpTimeTicks()) %
58 RtpTimeDelta::FromTicks(samples_per_frame_));
57 EXPECT_TRUE(!encoded_frame->data.empty()); 59 EXPECT_TRUE(!encoded_frame->data.empty());
58 60
59 EXPECT_LE(lower_bound_, encoded_frame->reference_time); 61 EXPECT_LE(lower_bound_, encoded_frame->reference_time);
60 lower_bound_ = encoded_frame->reference_time; 62 lower_bound_ = encoded_frame->reference_time;
61 EXPECT_GT(upper_bound_, encoded_frame->reference_time); 63 EXPECT_GT(upper_bound_, encoded_frame->reference_time);
62 64
63 EXPECT_LE(0.0, encoded_frame->deadline_utilization); 65 EXPECT_LE(0.0, encoded_frame->deadline_utilization);
64 EXPECT_EQ(-1.0, encoded_frame->lossy_utilization); 66 EXPECT_EQ(-1.0, encoded_frame->lossy_utilization);
65 67
66 ++frames_received_; 68 ++frames_received_;
67 } 69 }
68 70
69 private: 71 private:
70 int frames_received_; 72 int frames_received_;
71 uint32 rtp_lower_bound_; 73 RtpTimeTicks rtp_lower_bound_;
72 int samples_per_frame_; 74 int samples_per_frame_;
73 base::TimeTicks lower_bound_; 75 base::TimeTicks lower_bound_;
74 base::TimeTicks upper_bound_; 76 base::TimeTicks upper_bound_;
75 77
76 DISALLOW_COPY_AND_ASSIGN(TestEncodedAudioFrameReceiver); 78 DISALLOW_COPY_AND_ASSIGN(TestEncodedAudioFrameReceiver);
77 }; 79 };
78 80
79 struct TestScenario { 81 struct TestScenario {
80 const int64* durations_in_ms; 82 const int64* durations_in_ms;
81 size_t num_durations; 83 size_t num_durations;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 TestScenario(kManyCalls_Mixed2, arraysize(kManyCalls_Mixed2)), 246 TestScenario(kManyCalls_Mixed2, arraysize(kManyCalls_Mixed2)),
245 TestScenario(kManyCalls_Mixed3, arraysize(kManyCalls_Mixed3)), 247 TestScenario(kManyCalls_Mixed3, arraysize(kManyCalls_Mixed3)),
246 TestScenario(kManyCalls_Mixed4, arraysize(kManyCalls_Mixed4)), 248 TestScenario(kManyCalls_Mixed4, arraysize(kManyCalls_Mixed4)),
247 TestScenario(kManyCalls_Mixed5, arraysize(kManyCalls_Mixed5)), 249 TestScenario(kManyCalls_Mixed5, arraysize(kManyCalls_Mixed5)),
248 TestScenario(kOneBigUnderrun, arraysize(kOneBigUnderrun)), 250 TestScenario(kOneBigUnderrun, arraysize(kOneBigUnderrun)),
249 TestScenario(kTwoBigUnderruns, arraysize(kTwoBigUnderruns)), 251 TestScenario(kTwoBigUnderruns, arraysize(kTwoBigUnderruns)),
250 TestScenario(kMixedUnderruns, arraysize(kMixedUnderruns)))); 252 TestScenario(kMixedUnderruns, arraysize(kMixedUnderruns))));
251 253
252 } // namespace cast 254 } // namespace cast
253 } // namespace media 255 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698