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

Side by Side Diff: webrtc/modules/audio_coding/neteq/tools/neteq_test.cc

Issue 2851383004: NetEqTest: Extend the callback structure (Closed)
Patch Set: Created 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 23 matching lines...) Expand all
34 void DefaultNetEqTestErrorCallback::OnGetAudioError(int error_code) { 34 void DefaultNetEqTestErrorCallback::OnGetAudioError(int error_code) {
35 std::cerr << "GetAudio returned error code " << error_code << std::endl; 35 std::cerr << "GetAudio returned error code " << error_code << std::endl;
36 FATAL(); 36 FATAL();
37 } 37 }
38 38
39 NetEqTest::NetEqTest(const NetEq::Config& config, 39 NetEqTest::NetEqTest(const NetEq::Config& config,
40 const DecoderMap& codecs, 40 const DecoderMap& codecs,
41 const ExtDecoderMap& ext_codecs, 41 const ExtDecoderMap& ext_codecs,
42 std::unique_ptr<NetEqInput> input, 42 std::unique_ptr<NetEqInput> input,
43 std::unique_ptr<AudioSink> output, 43 std::unique_ptr<AudioSink> output,
44 NetEqTestErrorCallback* error_callback) 44 Callbacks callbacks)
45 : neteq_(NetEq::Create(config, CreateBuiltinAudioDecoderFactory())), 45 : neteq_(NetEq::Create(config, CreateBuiltinAudioDecoderFactory())),
46 input_(std::move(input)), 46 input_(std::move(input)),
47 output_(std::move(output)), 47 output_(std::move(output)),
48 error_callback_(error_callback), 48 callbacks_(callbacks),
49 sample_rate_hz_(config.sample_rate_hz) { 49 sample_rate_hz_(config.sample_rate_hz) {
50 RTC_CHECK(!config.enable_muted_state) 50 RTC_CHECK(!config.enable_muted_state)
51 << "The code does not handle enable_muted_state"; 51 << "The code does not handle enable_muted_state";
52 RegisterDecoders(codecs); 52 RegisterDecoders(codecs);
53 RegisterExternalDecoders(ext_codecs); 53 RegisterExternalDecoders(ext_codecs);
54 } 54 }
55 55
56 int64_t NetEqTest::Run() { 56 int64_t NetEqTest::Run() {
57 const int64_t start_time_ms = *input_->NextEventTime(); 57 const int64_t start_time_ms = *input_->NextEventTime();
58 int64_t time_now_ms = start_time_ms; 58 int64_t time_now_ms = start_time_ms;
59 59
60 while (!input_->ended()) { 60 while (!input_->ended()) {
61 // Advance time to next event. 61 // Advance time to next event.
62 RTC_DCHECK(input_->NextEventTime()); 62 RTC_DCHECK(input_->NextEventTime());
63 time_now_ms = *input_->NextEventTime(); 63 time_now_ms = *input_->NextEventTime();
64 // Check if it is time to insert packet. 64 // Check if it is time to insert packet.
65 if (input_->NextPacketTime() && time_now_ms >= *input_->NextPacketTime()) { 65 if (input_->NextPacketTime() && time_now_ms >= *input_->NextPacketTime()) {
66 std::unique_ptr<NetEqInput::PacketData> packet_data = input_->PopPacket(); 66 std::unique_ptr<NetEqInput::PacketData> packet_data = input_->PopPacket();
67 RTC_CHECK(packet_data); 67 RTC_CHECK(packet_data);
68 int error = neteq_->InsertPacket( 68 int error = neteq_->InsertPacket(
69 packet_data->header, 69 packet_data->header,
70 rtc::ArrayView<const uint8_t>(packet_data->payload), 70 rtc::ArrayView<const uint8_t>(packet_data->payload),
71 static_cast<uint32_t>(packet_data->time_ms * sample_rate_hz_ / 1000)); 71 static_cast<uint32_t>(packet_data->time_ms * sample_rate_hz_ / 1000));
72 if (error != NetEq::kOK && error_callback_) { 72 if (error != NetEq::kOK && callbacks_.error_callback) {
AleBzk 2017/05/02 10:36:55 For sure, it's fine as it is now. Just wondering i
hlundin-webrtc 2017/05/04 12:50:07 I think we have a fair amount of the shorter form
73 error_callback_->OnInsertPacketError(neteq_->LastError(), *packet_data); 73 callbacks_.error_callback->OnInsertPacketError(neteq_->LastError(),
74 *packet_data);
75 }
76 if (callbacks_.post_insert_packet) {
77 callbacks_.post_insert_packet->AfterInsertPacket(*packet_data,
78 neteq_.get());
AleBzk 2017/05/02 10:36:55 I wonder if there was an error for which a packet
hlundin-webrtc 2017/05/04 12:50:07 There could be. But I think we can leave that up t
74 } 79 }
75 } 80 }
76 81
77 // Check if it is time to get output audio. 82 // Check if it is time to get output audio.
78 if (input_->NextOutputEventTime() && 83 if (input_->NextOutputEventTime() &&
79 time_now_ms >= *input_->NextOutputEventTime()) { 84 time_now_ms >= *input_->NextOutputEventTime()) {
85 if (callbacks_.get_audio_callback) {
86 callbacks_.get_audio_callback->BeforeGetAudio(neteq_.get());
87 }
80 AudioFrame out_frame; 88 AudioFrame out_frame;
81 bool muted; 89 bool muted;
82 int error = neteq_->GetAudio(&out_frame, &muted); 90 int error = neteq_->GetAudio(&out_frame, &muted);
83 RTC_CHECK(!muted) << "The code does not handle enable_muted_state"; 91 RTC_CHECK(!muted) << "The code does not handle enable_muted_state";
84 if (error != NetEq::kOK) { 92 if (error != NetEq::kOK) {
85 if (error_callback_) { 93 if (callbacks_.error_callback) {
86 error_callback_->OnGetAudioError(neteq_->LastError()); 94 callbacks_.error_callback->OnGetAudioError(neteq_->LastError());
87 } 95 }
88 } else { 96 } else {
89 sample_rate_hz_ = out_frame.sample_rate_hz_; 97 sample_rate_hz_ = out_frame.sample_rate_hz_;
90 } 98 }
99 if (callbacks_.get_audio_callback) {
100 callbacks_.get_audio_callback->AfterGetAudio(time_now_ms, out_frame,
101 muted, neteq_.get());
102 }
91 103
92 if (output_) { 104 if (output_) {
93 RTC_CHECK(output_->WriteArray( 105 RTC_CHECK(output_->WriteArray(
94 out_frame.data_, 106 out_frame.data_,
95 out_frame.samples_per_channel_ * out_frame.num_channels_)); 107 out_frame.samples_per_channel_ * out_frame.num_channels_));
96 } 108 }
97 109
98 input_->AdvanceOutputEvent(); 110 input_->AdvanceOutputEvent();
99 } 111 }
100 } 112 }
(...skipping 22 matching lines...) Expand all
123 neteq_->RegisterExternalDecoder(c.second.decoder, c.second.codec, 135 neteq_->RegisterExternalDecoder(c.second.decoder, c.second.codec,
124 c.second.codec_name, c.first), 136 c.second.codec_name, c.first),
125 NetEq::kOK) 137 NetEq::kOK)
126 << "Cannot register " << c.second.codec_name << " to payload type " 138 << "Cannot register " << c.second.codec_name << " to payload type "
127 << c.first; 139 << c.first;
128 } 140 }
129 } 141 }
130 142
131 } // namespace test 143 } // namespace test
132 } // namespace webrtc 144 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698