1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
|
/*
* Copyright 2022 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MEDIA_BASE_MEDIA_CHANNEL_IMPL_H_
#define MEDIA_BASE_MEDIA_CHANNEL_IMPL_H_
#include <stddef.h>
#include <stdint.h>
#include <functional>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/audio_options.h"
#include "api/call/audio_sink.h"
#include "api/call/transport.h"
#include "api/crypto/frame_decryptor_interface.h"
#include "api/crypto/frame_encryptor_interface.h"
#include "api/frame_transformer_interface.h"
#include "api/media_types.h"
#include "api/rtc_error.h"
#include "api/rtp_parameters.h"
#include "api/rtp_sender_interface.h"
#include "api/scoped_refptr.h"
#include "api/sequence_checker.h"
#include "api/task_queue/pending_task_safety_flag.h"
#include "api/task_queue/task_queue_base.h"
#include "api/transport/rtp/rtp_source.h"
#include "api/video/recordable_encoded_frame.h"
#include "api/video/video_frame.h"
#include "api/video/video_sink_interface.h"
#include "api/video/video_source_interface.h"
#include "api/video_codecs/video_encoder_factory.h"
#include "media/base/codec.h"
#include "media/base/media_channel.h"
#include "media/base/stream_params.h"
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
#include "rtc_base/async_packet_socket.h"
#include "rtc_base/checks.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/dscp.h"
#include "rtc_base/logging.h"
#include "rtc_base/network/sent_packet.h"
#include "rtc_base/network_route.h"
#include "rtc_base/socket.h"
#include "rtc_base/thread_annotations.h"
// This file contains the base classes for classes that implement
// the MediaChannel interfaces.
// These implementation classes used to be the exposed interface names,
// but this is in the process of being changed.
// TODO(bugs.webrtc.org/13931): Consider removing these classes.
// The target
namespace cricket {
class VoiceMediaChannel;
class VideoMediaChannel;
class MediaChannel : public MediaSendChannelInterface,
public MediaReceiveChannelInterface {
public:
explicit MediaChannel(webrtc::TaskQueueBase* network_thread,
bool enable_dscp = false);
virtual ~MediaChannel();
// Downcasting to the subclasses.
virtual VideoMediaChannel* AsVideoChannel() {
RTC_CHECK_NOTREACHED();
return nullptr;
}
virtual VoiceMediaChannel* AsVoiceChannel() {
RTC_CHECK_NOTREACHED();
return nullptr;
}
// Must declare the methods inherited from the base interface template,
// even when abstract, to tell the compiler that all instances of the name
// referred to by subclasses of this share the same implementation.
cricket::MediaType media_type() const override = 0;
void OnPacketReceived(const webrtc::RtpPacketReceived& packet) override = 0;
void OnPacketSent(const rtc::SentPacket& sent_packet) override = 0;
void OnReadyToSend(bool ready) override = 0;
void OnNetworkRouteChanged(absl::string_view transport_name,
const rtc::NetworkRoute& network_route) override =
0;
// Sets the abstract interface class for sending RTP/RTCP data.
virtual void SetInterface(MediaChannelNetworkInterface* iface);
// Returns the absolute sendtime extension id value from media channel.
virtual int GetRtpSendTimeExtnId() const;
// Base method to send packet using MediaChannelNetworkInterface.
bool SendPacket(rtc::CopyOnWriteBuffer* packet,
const rtc::PacketOptions& options);
bool SendRtcp(rtc::CopyOnWriteBuffer* packet,
const rtc::PacketOptions& options);
int SetOption(MediaChannelNetworkInterface::SocketType type,
rtc::Socket::Option opt,
int option);
// Corresponds to the SDP attribute extmap-allow-mixed, see RFC8285.
// Set to true if it's allowed to mix one- and two-byte RTP header extensions
// in the same stream. The setter and getter must only be called from
// worker_thread.
void SetExtmapAllowMixed(bool extmap_allow_mixed) override;
bool ExtmapAllowMixed() const override;
// Returns `true` if a non-null MediaChannelNetworkInterface pointer is held.
// Must be called on the network thread.
bool HasNetworkInterface() const;
void SetFrameEncryptor(uint32_t ssrc,
rtc::scoped_refptr<webrtc::FrameEncryptorInterface>
frame_encryptor) override;
void SetFrameDecryptor(uint32_t ssrc,
rtc::scoped_refptr<webrtc::FrameDecryptorInterface>
frame_decryptor) override;
void SetEncoderToPacketizerFrameTransformer(
uint32_t ssrc,
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)
override;
void SetDepacketizerToDecoderFrameTransformer(
uint32_t ssrc,
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)
override;
protected:
int SetOptionLocked(MediaChannelNetworkInterface::SocketType type,
rtc::Socket::Option opt,
int option) RTC_RUN_ON(network_thread_);
bool DscpEnabled() const;
// This is the DSCP value used for both RTP and RTCP channels if DSCP is
// enabled. It can be changed at any time via `SetPreferredDscp`.
rtc::DiffServCodePoint PreferredDscp() const;
void SetPreferredDscp(rtc::DiffServCodePoint new_dscp);
rtc::scoped_refptr<webrtc::PendingTaskSafetyFlag> network_safety();
// Utility implementation for derived classes (video/voice) that applies
// the packet options and passes the data onwards to `SendPacket`.
void SendRtp(const uint8_t* data,
size_t len,
const webrtc::PacketOptions& options);
void SendRtcp(const uint8_t* data, size_t len);
private:
// Apply the preferred DSCP setting to the underlying network interface RTP
// and RTCP channels. If DSCP is disabled, then apply the default DSCP value.
void UpdateDscp() RTC_RUN_ON(network_thread_);
bool DoSendPacket(rtc::CopyOnWriteBuffer* packet,
bool rtcp,
const rtc::PacketOptions& options);
const bool enable_dscp_;
const rtc::scoped_refptr<webrtc::PendingTaskSafetyFlag> network_safety_
RTC_PT_GUARDED_BY(network_thread_);
webrtc::TaskQueueBase* const network_thread_;
MediaChannelNetworkInterface* network_interface_
RTC_GUARDED_BY(network_thread_) = nullptr;
rtc::DiffServCodePoint preferred_dscp_ RTC_GUARDED_BY(network_thread_) =
rtc::DSCP_DEFAULT;
bool extmap_allow_mixed_ = false;
};
// Base class for implementation classes
class VideoMediaChannel : public MediaChannel,
public VideoMediaSendChannelInterface,
public VideoMediaReceiveChannelInterface {
public:
explicit VideoMediaChannel(webrtc::TaskQueueBase* network_thread,
bool enable_dscp = false)
: MediaChannel(network_thread, enable_dscp) {}
~VideoMediaChannel() override {}
// Downcasting to the implemented interfaces.
VideoMediaSendChannelInterface* AsVideoSendChannel() override { return this; }
VoiceMediaSendChannelInterface* AsVoiceSendChannel() override {
RTC_CHECK_NOTREACHED();
return nullptr;
}
VideoMediaReceiveChannelInterface* AsVideoReceiveChannel() override {
return this;
}
cricket::MediaType media_type() const override;
// Downcasting to the subclasses.
VideoMediaChannel* AsVideoChannel() override { return this; }
void SetExtmapAllowMixed(bool mixed) override {
MediaChannel::SetExtmapAllowMixed(mixed);
}
bool ExtmapAllowMixed() const override {
return MediaChannel::ExtmapAllowMixed();
}
// This fills the "bitrate parts" (rtx, video bitrate) of the
// BandwidthEstimationInfo, since that part that isn't possible to get
// through webrtc::Call::GetStats, as they are statistics of the send
// streams.
// TODO(holmer): We should change this so that either BWE graphs doesn't
// need access to bitrates of the streams, or change the (RTC)StatsCollector
// so that it's getting the send stream stats separately by calling
// GetStats(), and merges with BandwidthEstimationInfo by itself.
void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) override = 0;
// Gets quality stats for the channel.
virtual bool GetSendStats(VideoMediaSendInfo* info) = 0;
virtual bool GetReceiveStats(VideoMediaReceiveInfo* info) = 0;
// Enable network condition based codec switching.
void SetVideoCodecSwitchingEnabled(bool enabled) override;
private:
// Functions not implemented on this interface
bool GetStats(VideoMediaSendInfo* info) override {
RTC_CHECK_NOTREACHED();
return false;
}
bool GetStats(VideoMediaReceiveInfo* info) override {
RTC_CHECK_NOTREACHED();
return false;
}
};
// Base class for implementation classes
class VoiceMediaChannel : public MediaChannel,
public VoiceMediaSendChannelInterface,
public VoiceMediaReceiveChannelInterface {
public:
MediaType media_type() const override;
VoiceMediaChannel(webrtc::TaskQueueBase* network_thread,
bool enable_dscp = false)
: MediaChannel(network_thread, enable_dscp) {}
~VoiceMediaChannel() override {}
// Downcasting to the implemented interfaces.
VoiceMediaSendChannelInterface* AsVoiceSendChannel() override { return this; }
VoiceMediaReceiveChannelInterface* AsVoiceReceiveChannel() override {
return this;
}
VoiceMediaChannel* AsVoiceChannel() override { return this; }
VideoMediaSendChannelInterface* AsVideoSendChannel() override {
RTC_CHECK_NOTREACHED();
return nullptr;
}
void SetExtmapAllowMixed(bool mixed) override {
MediaChannel::SetExtmapAllowMixed(mixed);
}
bool ExtmapAllowMixed() const override {
return MediaChannel::ExtmapAllowMixed();
}
// Gets quality stats for the channel.
virtual bool GetSendStats(VoiceMediaSendInfo* info) = 0;
virtual bool GetReceiveStats(VoiceMediaReceiveInfo* info,
bool get_and_clear_legacy_stats) = 0;
private:
// Functions not implemented on this interface
bool GetStats(VoiceMediaSendInfo* info) override {
RTC_CHECK_NOTREACHED();
return false;
}
bool GetStats(VoiceMediaReceiveInfo* info,
bool get_and_clear_legacy_stats) override {
RTC_CHECK_NOTREACHED();
return false;
}
};
// The externally exposed objects that support the Send and Receive interfaces.
// These dispatch their functions to the underlying MediaChannel objects.
class VoiceMediaSendChannel : public VoiceMediaSendChannelInterface {
public:
explicit VoiceMediaSendChannel(VoiceMediaChannel* impl) : impl_(impl) {}
virtual ~VoiceMediaSendChannel() {}
VoiceMediaSendChannelInterface* AsVoiceSendChannel() override { return this; }
VideoMediaSendChannelInterface* AsVideoSendChannel() override {
RTC_CHECK_NOTREACHED();
return nullptr;
}
// Implementation of MediaBaseChannelInterface
cricket::MediaType media_type() const override { return MEDIA_TYPE_AUDIO; }
void OnPacketReceived(const webrtc::RtpPacketReceived& packet) override {
impl()->OnPacketReceived(packet);
}
void OnPacketSent(const rtc::SentPacket& sent_packet) override {
impl()->OnPacketSent(sent_packet);
}
void OnReadyToSend(bool ready) override { impl()->OnReadyToSend(ready); }
void OnNetworkRouteChanged(absl::string_view transport_name,
const rtc::NetworkRoute& network_route) override {
impl()->OnNetworkRouteChanged(transport_name, network_route);
}
void SetExtmapAllowMixed(bool extmap_allow_mixed) override {
impl()->SetExtmapAllowMixed(extmap_allow_mixed);
}
bool ExtmapAllowMixed() const override { return impl()->ExtmapAllowMixed(); }
// Implementation of MediaSendChannelInterface
bool AddSendStream(const StreamParams& sp) override {
return impl()->AddSendStream(sp);
}
bool RemoveSendStream(uint32_t ssrc) override {
return impl()->RemoveSendStream(ssrc);
}
void SetFrameEncryptor(uint32_t ssrc,
rtc::scoped_refptr<webrtc::FrameEncryptorInterface>
frame_encryptor) override {
impl()->SetFrameEncryptor(ssrc, frame_encryptor);
}
webrtc::RTCError SetRtpSendParameters(
uint32_t ssrc,
const webrtc::RtpParameters& parameters,
webrtc::SetParametersCallback callback = nullptr) override {
return impl()->SetRtpSendParameters(ssrc, parameters, std::move(callback));
}
void SetEncoderToPacketizerFrameTransformer(
uint32_t ssrc,
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)
override {
return impl()->SetEncoderToPacketizerFrameTransformer(ssrc,
frame_transformer);
}
void SetEncoderSelector(uint32_t ssrc,
webrtc::VideoEncoderFactory::EncoderSelectorInterface*
encoder_selector) override {
impl()->SetEncoderSelector(ssrc, encoder_selector);
}
webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override {
return impl()->GetRtpSendParameters(ssrc);
}
// Implementation of VoiceMediaSendChannel
bool SetSendParameters(const AudioSendParameters& params) override {
return impl()->SetSendParameters(params);
}
void SetSend(bool send) override { return impl()->SetSend(send); }
bool SetAudioSend(uint32_t ssrc,
bool enable,
const AudioOptions* options,
AudioSource* source) override {
return impl()->SetAudioSend(ssrc, enable, options, source);
}
bool CanInsertDtmf() override { return impl()->CanInsertDtmf(); }
bool InsertDtmf(uint32_t ssrc, int event, int duration) override {
return impl()->InsertDtmf(ssrc, event, duration);
}
bool GetStats(VoiceMediaSendInfo* info) override {
return impl_->GetSendStats(info);
}
private:
VoiceMediaSendChannelInterface* impl() { return impl_; }
const VoiceMediaSendChannelInterface* impl() const { return impl_; }
VoiceMediaChannel* impl_;
};
class VoiceMediaReceiveChannel : public VoiceMediaReceiveChannelInterface {
public:
explicit VoiceMediaReceiveChannel(VoiceMediaChannel* impl) : impl_(impl) {}
virtual ~VoiceMediaReceiveChannel() {}
// Implementation of MediaBaseChannelInterface
cricket::MediaType media_type() const override { return MEDIA_TYPE_AUDIO; }
void OnPacketReceived(const webrtc::RtpPacketReceived& packet) override {
impl()->OnPacketReceived(packet);
}
void OnPacketSent(const rtc::SentPacket& sent_packet) override {
impl()->OnPacketSent(sent_packet);
}
void OnReadyToSend(bool ready) override { impl()->OnReadyToSend(ready); }
void OnNetworkRouteChanged(absl::string_view transport_name,
const rtc::NetworkRoute& network_route) override {
impl()->OnNetworkRouteChanged(transport_name, network_route);
}
void SetExtmapAllowMixed(bool extmap_allow_mixed) override {
impl()->SetExtmapAllowMixed(extmap_allow_mixed);
}
bool ExtmapAllowMixed() const override { return impl()->ExtmapAllowMixed(); }
// Implementation of Delayable
bool SetBaseMinimumPlayoutDelayMs(uint32_t ssrc, int delay_ms) override {
return impl()->SetBaseMinimumPlayoutDelayMs(ssrc, delay_ms);
}
absl::optional<int> GetBaseMinimumPlayoutDelayMs(
uint32_t ssrc) const override {
return impl()->GetBaseMinimumPlayoutDelayMs(ssrc);
}
// Implementation of MediaReceiveChannelInterface
bool AddRecvStream(const StreamParams& sp) override {
return impl()->AddRecvStream(sp);
}
bool RemoveRecvStream(uint32_t ssrc) override {
return impl()->RemoveRecvStream(ssrc);
}
void ResetUnsignaledRecvStream() override {
return impl()->ResetUnsignaledRecvStream();
}
absl::optional<uint32_t> GetUnsignaledSsrc() const override {
return impl()->GetUnsignaledSsrc();
}
void OnDemuxerCriteriaUpdatePending() override {
impl()->OnDemuxerCriteriaUpdatePending();
}
void OnDemuxerCriteriaUpdateComplete() override {
impl()->OnDemuxerCriteriaUpdateComplete();
}
void SetFrameDecryptor(uint32_t ssrc,
rtc::scoped_refptr<webrtc::FrameDecryptorInterface>
frame_decryptor) override {
impl()->SetFrameDecryptor(ssrc, frame_decryptor);
}
void SetDepacketizerToDecoderFrameTransformer(
uint32_t ssrc,
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)
override {
impl()->SetDepacketizerToDecoderFrameTransformer(ssrc, frame_transformer);
}
// Implementation of VoiceMediaReceiveChannelInterface
bool SetRecvParameters(const AudioRecvParameters& params) override {
return impl()->SetRecvParameters(params);
}
webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const override {
return impl()->GetRtpReceiveParameters(ssrc);
}
std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const override {
return impl()->GetSources(ssrc);
}
webrtc::RtpParameters GetDefaultRtpReceiveParameters() const override {
return impl()->GetDefaultRtpReceiveParameters();
}
void SetPlayout(bool playout) override { return impl()->SetPlayout(playout); }
bool SetOutputVolume(uint32_t ssrc, double volume) override {
return impl()->SetOutputVolume(ssrc, volume);
}
bool SetDefaultOutputVolume(double volume) override {
return impl()->SetDefaultOutputVolume(volume);
}
void SetRawAudioSink(
uint32_t ssrc,
std::unique_ptr<webrtc::AudioSinkInterface> sink) override {
return impl()->SetRawAudioSink(ssrc, std::move(sink));
}
void SetDefaultRawAudioSink(
std::unique_ptr<webrtc::AudioSinkInterface> sink) override {
return impl()->SetDefaultRawAudioSink(std::move(sink));
}
bool GetStats(VoiceMediaReceiveInfo* info, bool reset_legacy) override {
return impl_->GetReceiveStats(info, reset_legacy);
}
private:
VoiceMediaReceiveChannelInterface* impl() { return impl_; }
const VoiceMediaReceiveChannelInterface* impl() const { return impl_; }
VoiceMediaChannel* impl_;
};
class VideoMediaSendChannel : public VideoMediaSendChannelInterface {
public:
explicit VideoMediaSendChannel(VideoMediaChannel* impl) : impl_(impl) {}
VideoMediaSendChannelInterface* AsVideoSendChannel() override { return this; }
VoiceMediaSendChannelInterface* AsVoiceSendChannel() override {
RTC_CHECK_NOTREACHED();
return nullptr;
}
// Implementation of MediaBaseChannelInterface
cricket::MediaType media_type() const override { return MEDIA_TYPE_VIDEO; }
void OnPacketReceived(const webrtc::RtpPacketReceived& packet) override {
impl()->OnPacketReceived(packet);
}
void OnPacketSent(const rtc::SentPacket& sent_packet) override {
impl()->OnPacketSent(sent_packet);
}
void OnReadyToSend(bool ready) override { impl()->OnReadyToSend(ready); }
void OnNetworkRouteChanged(absl::string_view transport_name,
const rtc::NetworkRoute& network_route) override {
impl()->OnNetworkRouteChanged(transport_name, network_route);
}
void SetExtmapAllowMixed(bool extmap_allow_mixed) override {
impl()->SetExtmapAllowMixed(extmap_allow_mixed);
}
bool ExtmapAllowMixed() const override { return impl()->ExtmapAllowMixed(); }
// Implementation of MediaSendChannelInterface
bool AddSendStream(const StreamParams& sp) override {
return impl()->AddSendStream(sp);
}
bool RemoveSendStream(uint32_t ssrc) override {
return impl()->RemoveSendStream(ssrc);
}
void SetFrameEncryptor(uint32_t ssrc,
rtc::scoped_refptr<webrtc::FrameEncryptorInterface>
frame_encryptor) override {
impl()->SetFrameEncryptor(ssrc, frame_encryptor);
}
webrtc::RTCError SetRtpSendParameters(
uint32_t ssrc,
const webrtc::RtpParameters& parameters,
webrtc::SetParametersCallback callback = nullptr) override {
return impl()->SetRtpSendParameters(ssrc, parameters, std::move(callback));
}
void SetEncoderToPacketizerFrameTransformer(
uint32_t ssrc,
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)
override {
return impl()->SetEncoderToPacketizerFrameTransformer(ssrc,
frame_transformer);
}
void SetEncoderSelector(uint32_t ssrc,
webrtc::VideoEncoderFactory::EncoderSelectorInterface*
encoder_selector) override {
impl()->SetEncoderSelector(ssrc, encoder_selector);
}
webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override {
return impl()->GetRtpSendParameters(ssrc);
}
// Implementation of VideoMediaSendChannelInterface
bool SetSendParameters(const VideoSendParameters& params) override {
return impl()->SetSendParameters(params);
}
bool GetSendCodec(VideoCodec* send_codec) override {
return impl()->GetSendCodec(send_codec);
}
bool SetSend(bool send) override { return impl()->SetSend(send); }
bool SetVideoSend(
uint32_t ssrc,
const VideoOptions* options,
rtc::VideoSourceInterface<webrtc::VideoFrame>* source) override {
return impl()->SetVideoSend(ssrc, options, source);
}
void GenerateSendKeyFrame(uint32_t ssrc,
const std::vector<std::string>& rids) override {
return impl()->GenerateSendKeyFrame(ssrc, rids);
}
void SetVideoCodecSwitchingEnabled(bool enabled) override {
return impl()->SetVideoCodecSwitchingEnabled(enabled);
}
bool GetStats(VideoMediaSendInfo* info) override {
return impl_->GetSendStats(info);
}
void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) override {
return impl_->FillBitrateInfo(bwe_info);
}
private:
VideoMediaSendChannelInterface* impl() { return impl_; }
const VideoMediaSendChannelInterface* impl() const { return impl_; }
VideoMediaChannel* const impl_;
};
class VideoMediaReceiveChannel : public VideoMediaReceiveChannelInterface {
public:
explicit VideoMediaReceiveChannel(VideoMediaChannel* impl) : impl_(impl) {}
// Implementation of MediaBaseChannelInterface
cricket::MediaType media_type() const override { return MEDIA_TYPE_VIDEO; }
void OnPacketReceived(const webrtc::RtpPacketReceived& packet) override {
impl()->OnPacketReceived(packet);
}
void OnPacketSent(const rtc::SentPacket& sent_packet) override {
impl()->OnPacketSent(sent_packet);
}
void OnReadyToSend(bool ready) override { impl()->OnReadyToSend(ready); }
void OnNetworkRouteChanged(absl::string_view transport_name,
const rtc::NetworkRoute& network_route) override {
impl()->OnNetworkRouteChanged(transport_name, network_route);
}
void SetExtmapAllowMixed(bool extmap_allow_mixed) override {
impl()->SetExtmapAllowMixed(extmap_allow_mixed);
}
bool ExtmapAllowMixed() const override { return impl()->ExtmapAllowMixed(); }
// Implementation of Delayable
bool SetBaseMinimumPlayoutDelayMs(uint32_t ssrc, int delay_ms) override {
return impl()->SetBaseMinimumPlayoutDelayMs(ssrc, delay_ms);
}
absl::optional<int> GetBaseMinimumPlayoutDelayMs(
uint32_t ssrc) const override {
return impl()->GetBaseMinimumPlayoutDelayMs(ssrc);
}
// Implementation of MediaReceiveChannelInterface
VideoMediaReceiveChannelInterface* AsVideoReceiveChannel() override {
return this;
}
bool AddRecvStream(const StreamParams& sp) override {
return impl()->AddRecvStream(sp);
}
bool RemoveRecvStream(uint32_t ssrc) override {
return impl()->RemoveRecvStream(ssrc);
}
void ResetUnsignaledRecvStream() override {
return impl()->ResetUnsignaledRecvStream();
}
absl::optional<uint32_t> GetUnsignaledSsrc() const override {
return impl()->GetUnsignaledSsrc();
}
void OnDemuxerCriteriaUpdatePending() override {
impl()->OnDemuxerCriteriaUpdatePending();
}
void OnDemuxerCriteriaUpdateComplete() override {
impl()->OnDemuxerCriteriaUpdateComplete();
}
void SetFrameDecryptor(uint32_t ssrc,
rtc::scoped_refptr<webrtc::FrameDecryptorInterface>
frame_decryptor) override {
impl()->SetFrameDecryptor(ssrc, frame_decryptor);
}
void SetDepacketizerToDecoderFrameTransformer(
uint32_t ssrc,
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)
override {
impl()->SetDepacketizerToDecoderFrameTransformer(ssrc, frame_transformer);
}
// Implementation on videoMediaReceiveChannelInterface
bool SetRecvParameters(const VideoRecvParameters& params) override {
return impl()->SetRecvParameters(params);
}
webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const override {
return impl()->GetRtpReceiveParameters(ssrc);
}
webrtc::RtpParameters GetDefaultRtpReceiveParameters() const override {
return impl()->GetDefaultRtpReceiveParameters();
}
bool SetSink(uint32_t ssrc,
rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override {
return impl()->SetSink(ssrc, sink);
}
void SetDefaultSink(
rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override {
return impl()->SetDefaultSink(sink);
}
void RequestRecvKeyFrame(uint32_t ssrc) override {
return impl()->RequestRecvKeyFrame(ssrc);
}
std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const override {
return impl()->GetSources(ssrc);
}
// Set recordable encoded frame callback for `ssrc`
void SetRecordableEncodedFrameCallback(
uint32_t ssrc,
std::function<void(const webrtc::RecordableEncodedFrame&)> callback)
override {
return impl()->SetRecordableEncodedFrameCallback(ssrc, std::move(callback));
}
// Clear recordable encoded frame callback for `ssrc`
void ClearRecordableEncodedFrameCallback(uint32_t ssrc) override {
impl()->ClearRecordableEncodedFrameCallback(ssrc);
}
bool GetStats(VideoMediaReceiveInfo* info) override {
return impl_->GetReceiveStats(info);
}
private:
VideoMediaReceiveChannelInterface* impl() { return impl_; }
const VideoMediaReceiveChannelInterface* impl() const { return impl_; }
VideoMediaChannel* const impl_;
};
} // namespace cricket
#endif // MEDIA_BASE_MEDIA_CHANNEL_IMPL_H_
|