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

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

Issue 2020363003: Refactor neteq_rtpplay (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing win compilation and gyp dependencies Created 4 years, 6 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 | « webrtc/modules/audio_coding/neteq/tools/neteq_test.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/audio_coding/neteq/tools/neteq_test.h"
12
13 #include <iostream>
14
15 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h"
16
17 namespace webrtc {
18 namespace test {
19
20 void DefaultNetEqTestErrorCallback::OnInsertPacketError(
21 int error_code,
22 const NetEqInput::PacketData& packet) {
23 if (error_code == NetEq::kUnknownRtpPayloadType) {
24 std::cerr << "RTP Payload type "
25 << static_cast<int>(packet.header.header.payloadType)
26 << " is unknown." << std::endl;
27 } else {
28 std::cerr << "InsertPacket returned error code " << error_code << std::endl;
29 std::cerr << "Header data:" << std::endl;
30 std::cerr << " PT = " << static_cast<int>(packet.header.header.payloadType)
31 << std::endl;
32 std::cerr << " SN = " << packet.header.header.sequenceNumber << std::endl;
33 std::cerr << " TS = " << packet.header.header.timestamp << std::endl;
34 }
35 FATAL();
36 }
37
38 void DefaultNetEqTestErrorCallback::OnGetAudioError(int error_code) {
39 std::cerr << "GetAudio returned error code " << error_code << std::endl;
40 FATAL();
41 }
42
43 NetEqTest::NetEqTest(const NetEq::Config& config,
44 const DecoderMap& codecs,
45 const ExtDecoderMap& ext_codecs,
46 std::unique_ptr<NetEqInput> input,
47 std::unique_ptr<AudioSink> output,
48 NetEqTestErrorCallback* error_callback)
49 : neteq_(NetEq::Create(config, CreateBuiltinAudioDecoderFactory())),
50 input_(std::move(input)),
51 output_(std::move(output)),
52 error_callback_(error_callback),
53 sample_rate_hz_(config.sample_rate_hz) {
54 RTC_CHECK(!config.enable_muted_state)
55 << "The code does not handle enable_muted_state";
56 RegisterDecoders(codecs);
57 RegisterExternalDecoders(ext_codecs);
58 }
59
60 int64_t NetEqTest::Run() {
61 const int64_t start_time_ms = *input_->NextEventTime();
62 int64_t time_now_ms = start_time_ms;
63
64 while (!input_->ended()) {
65 // Advance time to next event.
66 RTC_DCHECK(input_->NextEventTime());
67 time_now_ms = *input_->NextEventTime();
68 // Check if it is time to insert packet.
69 if (input_->NextPacketTime() && time_now_ms >= *input_->NextPacketTime()) {
70 std::unique_ptr<NetEqInput::PacketData> packet_data = input_->PopPacket();
71 RTC_CHECK(packet_data);
72 int error = neteq_->InsertPacket(
73 packet_data->header,
74 rtc::ArrayView<const uint8_t>(packet_data->payload),
75 static_cast<uint32_t>(packet_data->time_ms * sample_rate_hz_ / 1000));
76 if (error != NetEq::kOK && error_callback_) {
77 error_callback_->OnInsertPacketError(neteq_->LastError(), *packet_data);
78 }
79 }
80
81 // Check if it is time to get output audio.
82 if (input_->NextOutputEventTime() &&
83 time_now_ms >= *input_->NextOutputEventTime()) {
84 AudioFrame out_frame;
85 bool muted;
86 int error = neteq_->GetAudio(&out_frame, &muted);
87 RTC_CHECK(!muted) << "The code does not handle enable_muted_state";
88 if (error != NetEq::kOK) {
89 if (error_callback_) {
90 error_callback_->OnGetAudioError(neteq_->LastError());
91 }
92 } else {
93 sample_rate_hz_ = out_frame.sample_rate_hz_;
94 }
95
96 if (output_) {
97 RTC_CHECK(output_->WriteArray(
98 out_frame.data_,
99 out_frame.samples_per_channel_ * out_frame.num_channels_));
100 }
101
102 input_->AdvanceOutputEvent();
103 }
104 }
105 return time_now_ms - start_time_ms;
106 }
107
108 NetEqNetworkStatistics NetEqTest::SimulationStats() {
109 NetEqNetworkStatistics stats;
110 RTC_CHECK_EQ(neteq_->NetworkStatistics(&stats), 0);
111 return stats;
112 }
113
114 void NetEqTest::RegisterDecoders(const DecoderMap& codecs) {
115 for (const auto& c : codecs) {
116 RTC_CHECK_EQ(
117 neteq_->RegisterPayloadType(c.second.first, c.second.second, c.first),
118 NetEq::kOK)
119 << "Cannot register " << c.second.second << " to payload type "
120 << c.first;
121 }
122 }
123
124 void NetEqTest::RegisterExternalDecoders(const ExtDecoderMap& codecs) {
125 for (const auto& c : codecs) {
126 RTC_CHECK_EQ(
127 neteq_->RegisterExternalDecoder(c.second.decoder, c.second.codec,
128 c.second.codec_name, c.first),
129 NetEq::kOK)
130 << "Cannot register " << c.second.codec_name << " to payload type "
131 << c.first;
132 }
133 }
134
135 } // namespace test
136 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/tools/neteq_test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698