OLD | NEW |
---|---|
(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 #ifndef WEBRTC_AUDIO_AUDIO_TRANSPORT_PROXY_H_ | |
12 #define WEBRTC_AUDIO_AUDIO_TRANSPORT_PROXY_H_ | |
13 | |
14 #include <algorithm> | |
15 | |
16 #include "webrtc/api/audio/audio_mixer.h" | |
17 #include "webrtc/base/logging.h" | |
18 #include "webrtc/modules/audio_device/include/audio_device_defines.h" | |
19 #include "webrtc/modules/audio_processing/include/audio_processing.h" | |
20 | |
21 namespace webrtc { | |
22 | |
23 class AudioTransportProxy : public AudioTransport { | |
24 public: | |
25 AudioTransportProxy(AudioTransport* voe_audio_transport, | |
26 AudioProcessing* apm, | |
27 AudioMixer* mixer) | |
28 : voe_audio_transport_(voe_audio_transport), apm_(apm), mixer_(mixer) { | |
29 RTC_DCHECK(mixer_); | |
30 } | |
31 | |
32 virtual ~AudioTransportProxy() {} | |
the sun
2016/10/27 10:06:46
override
| |
33 | |
34 int32_t RecordedDataIsAvailable(const void* audioSamples, | |
35 const size_t nSamples, | |
36 const size_t nBytesPerSample, | |
37 const size_t nChannels, | |
38 const uint32_t samplesPerSec, | |
39 const uint32_t totalDelayMS, | |
40 const int32_t clockDrift, | |
41 const uint32_t currentMicLevel, | |
42 const bool keyPressed, | |
43 uint32_t& newMicLevel) override { | |
44 // Pass call through to original audio transport instance. | |
45 if (voe_audio_transport_) { | |
46 return voe_audio_transport_->RecordedDataIsAvailable( | |
47 audioSamples, nSamples, nBytesPerSample, nChannels, samplesPerSec, | |
48 totalDelayMS, clockDrift, currentMicLevel, keyPressed, newMicLevel); | |
49 } else { | |
50 LOG(LS_ERROR) | |
51 << "AudioTransport proxy doesn't know where to send recorded data: " | |
52 "no Audio Transport provided."; | |
53 } | |
54 | |
55 return -1; | |
56 } | |
57 int32_t NeedMorePlayData(const size_t nSamples, | |
58 const size_t nBytesPerSample, | |
59 const size_t nChannels, | |
60 const uint32_t samplesPerSec, | |
61 void* audioSamples, | |
62 size_t& nSamplesOut, | |
63 int64_t* elapsed_time_ms, | |
64 int64_t* ntp_time_ms) override { | |
the sun
2016/10/27 10:06:46
RTC_DCHECK_EQ(2u, nBytesPerSample);
RTC_DCHECK(aud
| |
65 mixer_->Mix(static_cast<int>(samplesPerSec), static_cast<int>(nChannels), | |
66 &frame_for_mixing_); | |
67 *elapsed_time_ms = frame_for_mixing_.elapsed_time_ms_; | |
68 *ntp_time_ms = frame_for_mixing_.ntp_time_ms_; | |
69 | |
70 if (apm_) { | |
71 apm_->ProcessReverseStream(&frame_for_mixing_); | |
72 } else { | |
73 LOG(LS_ERROR) << "NeedMorePlayData called, but no APM provided."; | |
the sun
2016/10/27 10:06:46
In what context does this happen? Is the right way
| |
74 } | |
75 | |
76 // Deliver audio (PCM) samples to the ADM. | |
77 std::copy(frame_for_mixing_.data_, | |
78 frame_for_mixing_.data_ + nSamples * nChannels, | |
79 static_cast<int16_t*>(audioSamples)); | |
80 nSamplesOut = frame_for_mixing_.samples_per_channel_; | |
81 | |
82 return 0; | |
83 } | |
84 | |
85 void PushCaptureData(int voe_channel, | |
86 const void* audio_data, | |
87 int bits_per_sample, | |
88 int sample_rate, | |
89 size_t number_of_channels, | |
90 size_t number_of_frames) override { | |
the sun
2016/10/27 10:06:46
Add comment here why this path is unreachable.
| |
91 RTC_NOTREACHED(); | |
92 } | |
93 void PullRenderData(int bits_per_sample, | |
94 int sample_rate, | |
95 size_t number_of_channels, | |
96 size_t number_of_frames, | |
97 void* audio_data, | |
98 int64_t* elapsed_time_ms, | |
99 int64_t* ntp_time_ms) override { | |
100 mixer_->Mix(static_cast<int>(sample_rate), | |
101 static_cast<int>(number_of_channels), &frame_for_mixing_); | |
102 *elapsed_time_ms = frame_for_mixing_.elapsed_time_ms_; | |
103 *ntp_time_ms = frame_for_mixing_.ntp_time_ms_; | |
104 | |
105 // Deliver audio (PCM) samples to the ADM. | |
106 std::copy(frame_for_mixing_.data_, | |
107 frame_for_mixing_.data_ + number_of_frames * number_of_channels, | |
108 static_cast<int16_t*>(audio_data)); | |
109 } | |
110 | |
111 private: | |
112 AudioTransport* voe_audio_transport_; | |
113 AudioProcessing* apm_; | |
114 AudioMixer* mixer_; | |
115 AudioFrame frame_for_mixing_; | |
the sun
2016/10/27 10:06:46
DISALLOW_IMPLICIT...
| |
116 }; | |
117 } // namespace webrtc | |
118 | |
119 #endif // WEBRTC_AUDIO_AUDIO_TRANSPORT_PROXY_H_ | |
OLD | NEW |