| #include "api/video_codecs/video_encoder_factory.h" |
| 6 | #include "api/video_codecs/video_decoder_factory.h" |
| 7 | #include "api/media_stream_interface.h" |
| 8 | #include "rtc_base/network_monitor_factory.h" |
| 9 | #include "modules/audio_device/include/audio_device.h" |
| 10 | #include "rtc_base/ref_counted_object.h" |
| 11 | #include <string> |
| 12 |
| 13 | struct AVFrame; |
| 14 | struct AVCodecContext; |
| 15 |
| 16 | namespace tgcalls { |
| 17 |
| 18 | enum class VideoState; |
| 19 |
| 20 | class VideoCapturerInterface; |
| 21 | class PlatformContext; |
| 22 |
| 23 | struct PlatformCaptureInfo { |
| 24 | bool shouldBeAdaptedToReceiverAspectRate = false; |
| 25 | int rotation = 0; |
| 26 | }; |
| 27 |
| 28 | class WrappedAudioDeviceModule : public webrtc::AudioDeviceModule { |
| 29 | public: |
| 30 | virtual void Stop() = 0; |
| 31 | }; |
| 32 |
| 33 | class DefaultWrappedAudioDeviceModule : public WrappedAudioDeviceModule { |
| 34 | public: |
| 35 | DefaultWrappedAudioDeviceModule(rtc::scoped_refptr<webrtc::AudioDeviceModule> impl) : |
| 36 | _impl(impl) { |
| 37 | } |
| 38 |
| 39 | virtual ~DefaultWrappedAudioDeviceModule() { |
| 40 | } |
| 41 |
| 42 | virtual void Stop() override { |
| 43 | } |
| 44 |
| 45 | virtual int32_t ActiveAudioLayer(AudioLayer *audioLayer) const override { |
| 46 | return _impl->ActiveAudioLayer(audioLayer); |
| 47 | } |
| 48 |
| 49 | virtual int32_t RegisterAudioCallback(webrtc::AudioTransport *audioCallback) override { |
| 50 | return _impl->RegisterAudioCallback(audioCallback); |
| 51 | } |
| 52 |
| 53 | virtual int32_t Init() override { |
| 54 | return _impl->Init(); |
| 55 | } |
| 56 |
| 57 | virtual int32_t Terminate() override { |
| 58 | return _impl->Terminate(); |
| 59 | } |
| 60 |
| 61 | virtual bool Initialized() const override { |
| 62 | return _impl->Initialized(); |
| 63 | } |
| 64 |
| 65 | virtual int16_t PlayoutDevices() override { |
| 66 | return _impl->PlayoutDevices(); |
| 67 | } |
| 68 |
| 69 | virtual int16_t RecordingDevices() override { |
| 70 | return _impl->RecordingDevices(); |
| 71 | } |
| 72 |
| 73 | virtual int32_t PlayoutDeviceName(uint16_t index, char name[webrtc::kAdmMaxDeviceNameSize], char guid[webrtc::kAdmMaxGuidSize]) override { |
| 74 | return _impl->PlayoutDeviceName(index, name, guid); |
| 75 | } |
| 76 |
| 77 | virtual int32_t RecordingDeviceName(uint16_t index, char name[webrtc::kAdmMaxDeviceNameSize], char guid[webrtc::kAdmMaxGuidSize]) override { |
| 78 | return _impl->RecordingDeviceName(index, name, guid); |
| 79 | } |
| 80 |
| 81 | virtual int32_t SetPlayoutDevice(uint16_t index) override { |
| 82 | return _impl->SetPlayoutDevice(index); |
| 83 | } |
| 84 |
| 85 | virtual int32_t SetPlayoutDevice(WindowsDeviceType device) override { |
| 86 | return _impl->SetPlayoutDevice(device); |
| 87 | } |
| 88 |
| 89 | virtual int32_t SetRecordingDevice(uint16_t index) override { |
| 90 | return _impl->SetRecordingDevice(index); |
| 91 | } |
| 92 |
| 93 | virtual int32_t SetRecordingDevice(WindowsDeviceType device) override { |
| 94 | return _impl->SetRecordingDevice(device); |
| 95 | } |
| 96 |
| 97 | virtual int32_t PlayoutIsAvailable(bool *available) override { |
| 98 | return _impl->PlayoutIsAvailable(available); |
| 99 | } |
| 100 |
| 101 | virtual int32_t InitPlayout() override { |
| 102 | return _impl->InitPlayout(); |
| 103 | } |
| 104 |
| 105 | virtual bool PlayoutIsInitialized() const override { |
| 106 | return _impl->PlayoutIsInitialized(); |
| 107 | } |
| 108 |
| 109 | virtual int32_t RecordingIsAvailable(bool *available) override { |
| 110 | return _impl->RecordingIsAvailable(available); |
| 111 | } |
| 112 |
| 113 | virtual int32_t InitRecording() override { |
| 114 | return _impl->InitRecording(); |
| 115 | } |
| 116 |
| 117 | virtual bool RecordingIsInitialized() const override { |
| 118 | return _impl->RecordingIsInitialized(); |
| 119 | } |
| 120 |
| 121 | virtual int32_t StartPlayout() override { |
| 122 | return _impl->StartPlayout(); |
| 123 | } |
| 124 |
| 125 | virtual int32_t StopPlayout() override { |
| 126 | return _impl->StopPlayout(); |
| 127 | } |
| 128 |
| 129 | virtual bool Playing() const override { |
| 130 | return _impl->Playing(); |
| 131 | } |
| 132 |
| 133 | virtual int32_t StartRecording() override { |
| 134 | return _impl->StartRecording(); |
| 135 | } |
| 136 |
| 137 | virtual int32_t StopRecording() override { |
| 138 | return _impl->StopRecording(); |
| 139 | } |
| 140 |
| 141 | virtual bool Recording() const override { |
| 142 | return _impl->Recording(); |
| 143 | } |
| 144 |
| 145 | virtual int32_t InitSpeaker() override { |
| 146 | return _impl->InitSpeaker(); |
| 147 | } |
| 148 |
| 149 | virtual bool SpeakerIsInitialized() const override { |
| 150 | return _impl->SpeakerIsInitialized(); |
| 151 | } |
| 152 |
| 153 | virtual int32_t InitMicrophone() override { |
| 154 | return _impl->InitMicrophone(); |
| 155 | } |
| 156 |
| 157 | virtual bool MicrophoneIsInitialized() const override { |
| 158 | return _impl->MicrophoneIsInitialized(); |
| 159 | } |
| 160 |
| 161 | virtual int32_t SpeakerVolumeIsAvailable(bool *available) override { |
| 162 | return _impl->SpeakerVolumeIsAvailable(available); |
| 163 | } |
| 164 |
| 165 | virtual int32_t SetSpeakerVolume(uint32_t volume) override { |
| 166 | return _impl->SetSpeakerVolume(volume); |
| 167 | } |
| 168 |
| 169 | virtual int32_t SpeakerVolume(uint32_t* volume) const override { |
| 170 | return _impl->SpeakerVolume(volume); |
| 171 | } |
| 172 |
| 173 | virtual int32_t MaxSpeakerVolume(uint32_t *maxVolume) const override { |
| 174 | return _impl->MaxSpeakerVolume(maxVolume); |
| 175 | } |
| 176 |
| 177 | virtual int32_t MinSpeakerVolume(uint32_t *minVolume) const override { |
| 178 | return _impl->MinSpeakerVolume(minVolume); |
| 179 | } |
| 180 |
| 181 | virtual int32_t MicrophoneVolumeIsAvailable(bool *available) override { |
| 182 | return _impl->MicrophoneVolumeIsAvailable(available); |
| 183 | } |
| 184 |
| 185 | virtual int32_t SetMicrophoneVolume(uint32_t volume) override { |
| 186 | return _impl->SetMicrophoneVolume(volume); |
| 187 | } |
| 188 |
| 189 | virtual int32_t MicrophoneVolume(uint32_t *volume) const override { |
| 190 | return _impl->MicrophoneVolume(volume); |
| 191 | } |
| 192 |
| 193 | virtual int32_t MaxMicrophoneVolume(uint32_t *maxVolume) const override { |
| 194 | return _impl->MaxMicrophoneVolume(maxVolume); |
| 195 | } |
| 196 |
| 197 | virtual int32_t MinMicrophoneVolume(uint32_t *minVolume) const override { |
| 198 | return _impl->MinMicrophoneVolume(minVolume); |
| 199 | } |
| 200 |
| 201 | virtual int32_t SpeakerMuteIsAvailable(bool *available) override { |
| 202 | return _impl->SpeakerMuteIsAvailable(available); |
| 203 | } |
| 204 |
| 205 | virtual int32_t SetSpeakerMute(bool enable) override { |
| 206 | return _impl->SetSpeakerMute(enable); |
| 207 | } |
| 208 |
| 209 | virtual int32_t SpeakerMute(bool *enabled) const override { |
| 210 | return _impl->SpeakerMute(enabled); |
| 211 | } |
| 212 |
| 213 | virtual int32_t MicrophoneMuteIsAvailable(bool *available) override { |
| 214 | return _impl->MicrophoneMuteIsAvailable(available); |
| 215 | } |
| 216 |
| 217 | virtual int32_t SetMicrophoneMute(bool enable) override { |
| 218 | return _impl->SetMicrophoneMute(enable); |
| 219 | } |
| 220 |
| 221 | virtual int32_t MicrophoneMute(bool *enabled) const override { |
| 222 | return _impl->MicrophoneMute(enabled); |
| 223 | } |
| 224 |
| 225 | virtual int32_t StereoPlayoutIsAvailable(bool *available) const override { |
| 226 | return _impl->StereoPlayoutIsAvailable(available); |
| 227 | } |
| 228 |
| 229 | virtual int32_t SetStereoPlayout(bool enable) override { |
| 230 | return _impl->SetStereoPlayout(enable); |
| 231 | } |
| 232 |
| 233 | virtual int32_t StereoPlayout(bool *enabled) const override { |
| 234 | return _impl->StereoPlayout(enabled); |
| 235 | } |
| 236 |
| 237 | virtual int32_t StereoRecordingIsAvailable(bool *available) const override { |
| 238 | return _impl->StereoRecordingIsAvailable(available); |
| 239 | } |
| 240 |
| 241 | virtual int32_t SetStereoRecording(bool enable) override { |
| 242 | return _impl->SetStereoRecording(enable); |
| 243 | } |
| 244 |
| 245 | virtual int32_t StereoRecording(bool *enabled) const override { |
| 246 | return _impl->StereoRecording(enabled); |
| 247 | } |
| 248 |
| 249 | virtual int32_t PlayoutDelay(uint16_t* delayMS) const override { |
| 250 | return _impl->PlayoutDelay(delayMS); |
| 251 | } |
| 252 |
| 253 | virtual bool BuiltInAECIsAvailable() const override { |
| 254 | return _impl->BuiltInAECIsAvailable(); |
| 255 | } |
| 256 |
| 257 | virtual bool BuiltInAGCIsAvailable() const override { |
| 258 | return _impl->BuiltInAGCIsAvailable(); |
| 259 | } |
| 260 |
| 261 | virtual bool BuiltInNSIsAvailable() const override { |
| 262 | return _impl->BuiltInNSIsAvailable(); |
| 263 | } |
| 264 |
| 265 | virtual int32_t EnableBuiltInAEC(bool enable) override { |
| 266 | return _impl->EnableBuiltInAEC(enable); |
| 267 | } |
| 268 |
| 269 | virtual int32_t EnableBuiltInAGC(bool enable) override { |
| 270 | return _impl->EnableBuiltInAGC(enable); |
| 271 | } |
| 272 |
| 273 | virtual int32_t EnableBuiltInNS(bool enable) override { |
| 274 | return _impl->EnableBuiltInNS(enable); |
| 275 | } |
| 276 |
| 277 | virtual int32_t GetPlayoutUnderrunCount() const override { |
| 278 | return _impl->GetPlayoutUnderrunCount(); |
| 279 | } |
| 280 |
| 281 | #if defined(WEBRTC_IOS) |
| 282 | virtual int GetPlayoutAudioParameters(webrtc::AudioParameters *params) const override { |
| 283 | return _impl->GetPlayoutAudioParameters(params); |
| 284 | } |
| 285 | virtual int GetRecordAudioParameters(webrtc::AudioParameters *params) const override { |
| 286 | return _impl->GetRecordAudioParameters(params); |
| 287 | } |
| 288 | #endif // WEBRTC_IOS |
| 289 |
| 290 | rtc::scoped_refptr<webrtc::AudioDeviceModule> WrappedInstance() { |
| 291 | return _impl; |
| 292 | } |
| 293 |
| 294 | private: |
| 295 | rtc::scoped_refptr<webrtc::AudioDeviceModule> _impl; |
| 296 | }; |
| 297 |
| 298 | class PlatformVideoFrame { |
| 299 | public: |
| 300 | PlatformVideoFrame() { |
| 301 | } |
| 302 |
| 303 | virtual ~PlatformVideoFrame() = default; |
| 304 | }; |
| 305 |
| 306 | class PlatformInterface { |
| 307 | public: |
| 308 | static PlatformInterface *SharedInstance(); |
| 309 | virtual ~PlatformInterface() = default; |
| 310 |
| 311 | virtual void configurePlatformAudio(int numChannels = 1) { |
| 312 | } |
| 313 |
| 314 | virtual std::unique_ptr<rtc::NetworkMonitorFactory> createNetworkMonitorFactory() { |
| 315 | return nullptr; |
| 316 | } |
| 317 |
| 318 | virtual std::unique_ptr<webrtc::VideoEncoderFactory> makeVideoEncoderFactory(std::shared_ptr<PlatformContext> platformContext, bool preferHardwareEncoding = false, bool isScreencast = false) = 0; |
| 319 | virtual std::unique_ptr<webrtc::VideoDecoderFactory> makeVideoDecoderFactory(std::shared_ptr<PlatformContext> platformContext) = 0; |
| 320 | virtual bool supportsEncoding(const std::string &codecName, std::shared_ptr<PlatformContext> platformContext) = 0; |
| 321 | virtual rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> makeVideoSource(rtc::Thread *signalingThread, rtc::Thread *workerThread, bool screencapture) = 0; |
| 322 | virtual void adaptVideoSource(rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> videoSource, int width, int height, int fps) = 0; |
| 323 | virtual std::unique_ptr<VideoCapturerInterface> makeVideoCapturer(rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source, std::string deviceId, std::function<void(VideoState)> stateUpdated, std::function<void(PlatformCaptureInfo)> captureInfoUpdated, std::shared_ptr<PlatformContext> platformContext, std::pair<int, int> &outResolution) = 0; |
| 324 | virtual rtc::scoped_refptr<WrappedAudioDeviceModule> wrapAudioDeviceModule(rtc::scoped_refptr<webrtc::AudioDeviceModule> module) { |
| 325 | return rtc::make_ref_counted<DefaultWrappedAudioDeviceModule>(module); |
| 326 | } |
| 327 | virtual void setupVideoDecoding(AVCodecContext *codecContext) { |
| 328 | } |
| 329 | virtual rtc::scoped_refptr<webrtc::VideoFrameBuffer> createPlatformFrameFromData(AVFrame const *frame) { |
| 330 | return nullptr; |
| 331 | } |
| 332 |
| 333 | public: |
| 334 | bool preferX264 = false; |
| 335 | }; |
| 336 |
| 337 | std::unique_ptr<PlatformInterface> CreatePlatformInterface(); |
| 338 |
| 339 | inline PlatformInterface *PlatformInterface::SharedInstance() { |
| 340 | static const auto result = CreatePlatformInterface(); |
| 341 | return result.get(); |
| 342 | } |
| 343 |
| 344 | } // namespace tgcalls |
| 345 |
| 346 | #endif |
| 347 |