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

Side by Side Diff: media/cast/audio_receiver/audio_decoder_unittest.cc

Issue 288103002: [Cast] EncodedAudioFrame+EncodedVideoFrame+reference_time --> EncodedFrame (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « media/cast/audio_receiver/audio_decoder.cc ('k') | media/cast/audio_receiver/audio_receiver.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/stl_util.h"
8 #include "base/synchronization/condition_variable.h" 7 #include "base/synchronization/condition_variable.h"
9 #include "base/synchronization/lock.h" 8 #include "base/synchronization/lock.h"
10 #include "base/sys_byteorder.h" 9 #include "base/sys_byteorder.h"
11 #include "base/time/time.h" 10 #include "base/time/time.h"
12 #include "media/cast/audio_receiver/audio_decoder.h" 11 #include "media/cast/audio_receiver/audio_decoder.h"
13 #include "media/cast/cast_config.h" 12 #include "media/cast/cast_config.h"
14 #include "media/cast/test/utility/audio_utility.h" 13 #include "media/cast/test/utility/audio_utility.h"
15 #include "media/cast/test/utility/standalone_cast_environment.h" 14 #include "media/cast/test/utility/standalone_cast_environment.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/opus/src/include/opus.h" 16 #include "third_party/opus/src/include/opus.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 GetParam().num_channels, 63 GetParam().num_channels,
65 OPUS_APPLICATION_AUDIO)); 64 OPUS_APPLICATION_AUDIO));
66 CHECK_EQ(OPUS_OK, 65 CHECK_EQ(OPUS_OK,
67 opus_encoder_ctl(opus_encoder, OPUS_SET_BITRATE(OPUS_AUTO))); 66 opus_encoder_ctl(opus_encoder, OPUS_SET_BITRATE(OPUS_AUTO)));
68 } 67 }
69 68
70 total_audio_feed_in_ = base::TimeDelta(); 69 total_audio_feed_in_ = base::TimeDelta();
71 total_audio_decoded_ = base::TimeDelta(); 70 total_audio_decoded_ = base::TimeDelta();
72 } 71 }
73 72
74 // Called from the unit test thread to create another EncodedAudioFrame and 73 // Called from the unit test thread to create another EncodedFrame and push it
75 // push it into the decoding pipeline. 74 // into the decoding pipeline.
76 void FeedMoreAudio(const base::TimeDelta& duration, 75 void FeedMoreAudio(const base::TimeDelta& duration,
77 int num_dropped_frames) { 76 int num_dropped_frames) {
78 // Prepare a simulated EncodedAudioFrame to feed into the AudioDecoder. 77 // Prepare a simulated EncodedFrame to feed into the AudioDecoder.
79 scoped_ptr<transport::EncodedAudioFrame> encoded_frame( 78 scoped_ptr<transport::EncodedFrame> encoded_frame(
80 new transport::EncodedAudioFrame()); 79 new transport::EncodedFrame());
81 encoded_frame->codec = GetParam().codec; 80 encoded_frame->dependency = transport::EncodedFrame::KEY;
82 encoded_frame->frame_id = last_frame_id_ + 1 + num_dropped_frames; 81 encoded_frame->frame_id = last_frame_id_ + 1 + num_dropped_frames;
82 encoded_frame->referenced_frame_id = encoded_frame->frame_id;
83 last_frame_id_ = encoded_frame->frame_id; 83 last_frame_id_ = encoded_frame->frame_id;
84 84
85 const scoped_ptr<AudioBus> audio_bus( 85 const scoped_ptr<AudioBus> audio_bus(
86 audio_bus_factory_->NextAudioBus(duration).Pass()); 86 audio_bus_factory_->NextAudioBus(duration).Pass());
87 87
88 // Encode |audio_bus| into |encoded_frame->data|. 88 // Encode |audio_bus| into |encoded_frame->data|.
89 const int num_elements = audio_bus->channels() * audio_bus->frames(); 89 const int num_elements = audio_bus->channels() * audio_bus->frames();
90 std::vector<int16> interleaved(num_elements); 90 std::vector<int16> interleaved(num_elements);
91 audio_bus->ToInterleaved( 91 audio_bus->ToInterleaved(
92 audio_bus->frames(), sizeof(int16), &interleaved.front()); 92 audio_bus->frames(), sizeof(int16), &interleaved.front());
93 if (GetParam().codec == transport::kPcm16) { 93 if (GetParam().codec == transport::kPcm16) {
94 encoded_frame->data.resize(num_elements * sizeof(int16)); 94 encoded_frame->data.resize(num_elements * sizeof(int16));
95 int16* const pcm_data = 95 int16* const pcm_data =
96 reinterpret_cast<int16*>(string_as_array(&encoded_frame->data)); 96 reinterpret_cast<int16*>(encoded_frame->mutable_bytes());
97 for (size_t i = 0; i < interleaved.size(); ++i) 97 for (size_t i = 0; i < interleaved.size(); ++i)
98 pcm_data[i] = static_cast<int16>(base::HostToNet16(interleaved[i])); 98 pcm_data[i] = static_cast<int16>(base::HostToNet16(interleaved[i]));
99 } else if (GetParam().codec == transport::kOpus) { 99 } else if (GetParam().codec == transport::kOpus) {
100 OpusEncoder* const opus_encoder = 100 OpusEncoder* const opus_encoder =
101 reinterpret_cast<OpusEncoder*>(opus_encoder_memory_.get()); 101 reinterpret_cast<OpusEncoder*>(opus_encoder_memory_.get());
102 const int kOpusEncodeBufferSize = 4000; 102 const int kOpusEncodeBufferSize = 4000;
103 encoded_frame->data.resize(kOpusEncodeBufferSize); 103 encoded_frame->data.resize(kOpusEncodeBufferSize);
104 const int payload_size = 104 const int payload_size =
105 opus_encode(opus_encoder, 105 opus_encode(opus_encoder,
106 &interleaved.front(), 106 &interleaved.front(),
107 audio_bus->frames(), 107 audio_bus->frames(),
108 reinterpret_cast<unsigned char*>( 108 encoded_frame->mutable_bytes(),
109 string_as_array(&encoded_frame->data)),
110 encoded_frame->data.size()); 109 encoded_frame->data.size());
111 CHECK_GT(payload_size, 1); 110 CHECK_GT(payload_size, 1);
112 encoded_frame->data.resize(payload_size); 111 encoded_frame->data.resize(payload_size);
113 } else { 112 } else {
114 ASSERT_TRUE(false); // Not reached. 113 ASSERT_TRUE(false); // Not reached.
115 } 114 }
116 115
117 { 116 {
118 base::AutoLock auto_lock(lock_); 117 base::AutoLock auto_lock(lock_);
119 total_audio_feed_in_ += duration; 118 total_audio_feed_in_ += duration;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 INSTANTIATE_TEST_CASE_P(AudioDecoderTestScenarios, 234 INSTANTIATE_TEST_CASE_P(AudioDecoderTestScenarios,
236 AudioDecoderTest, 235 AudioDecoderTest,
237 ::testing::Values( 236 ::testing::Values(
238 TestScenario(transport::kPcm16, 1, 8000), 237 TestScenario(transport::kPcm16, 1, 8000),
239 TestScenario(transport::kPcm16, 2, 48000), 238 TestScenario(transport::kPcm16, 2, 48000),
240 TestScenario(transport::kOpus, 1, 8000), 239 TestScenario(transport::kOpus, 1, 8000),
241 TestScenario(transport::kOpus, 2, 48000))); 240 TestScenario(transport::kOpus, 2, 48000)));
242 241
243 } // namespace cast 242 } // namespace cast
244 } // namespace media 243 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/audio_receiver/audio_decoder.cc ('k') | media/cast/audio_receiver/audio_receiver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698