3
* Copyright 2004--2011, Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
13
* 3. The name of the author may not be used to endorse or promote products
14
* derived from this software without specific prior written permission.
16
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
#ifndef TALK_SESSION_PHONE_FAKEMEDIAENGINE_H_
29
#define TALK_SESSION_PHONE_FAKEMEDIAENGINE_H_
37
#include "talk/base/buffer.h"
38
#include "talk/p2p/base/sessiondescription.h"
39
#include "talk/session/phone/mediaengine.h"
40
#include "talk/session/phone/streamparams.h"
41
#include "talk/session/phone/rtputils.h"
45
class FakeMediaEngine;
46
class FakeVideoEngine;
47
class FakeVoiceEngine;
49
// A common helper class that handles sending and receiving RTP/RTCP packets.
51
class RtpHelper : public Base {
57
fail_set_send_codecs_(false),
58
fail_set_recv_codecs_(false),
61
const std::vector<RtpHeaderExtension>& recv_extensions() {
62
return recv_extensions_;
64
const std::vector<RtpHeaderExtension>& send_extensions() {
65
return send_extensions_;
67
bool sending() const { return sending_; }
68
bool playout() const { return playout_; }
69
const std::list<std::string>& rtp_packets() const { return rtp_packets_; }
70
const std::list<std::string>& rtcp_packets() const { return rtcp_packets_; }
71
int options() const { return options_; }
73
bool SendRtp(const void* data, int len) {
74
if (!sending_ || !Base::network_interface_) {
77
talk_base::Buffer packet(data, len, kMaxRtpPacketLen);
78
return Base::network_interface_->SendPacket(&packet);
80
bool SendRtcp(const void* data, int len) {
81
if (!Base::network_interface_) {
84
talk_base::Buffer packet(data, len, kMaxRtpPacketLen);
85
return Base::network_interface_->SendRtcp(&packet);
88
bool CheckRtp(const void* data, int len) {
89
bool success = !rtp_packets_.empty();
91
std::string packet = rtp_packets_.front();
92
rtp_packets_.pop_front();
93
success = (packet == std::string(static_cast<const char*>(data), len));
97
bool CheckRtcp(const void* data, int len) {
98
bool success = !rtcp_packets_.empty();
100
std::string packet = rtcp_packets_.front();
101
rtcp_packets_.pop_front();
102
success = (packet == std::string(static_cast<const char*>(data), len));
107
return rtp_packets_.empty();
110
return rtcp_packets_.empty();
112
virtual bool SetOptions(int options) {
116
virtual int GetOptions() const {
119
virtual bool SetRecvRtpHeaderExtensions(
120
const std::vector<RtpHeaderExtension>& extensions) {
121
recv_extensions_ = extensions;
124
virtual bool SetSendRtpHeaderExtensions(
125
const std::vector<RtpHeaderExtension>& extensions) {
126
send_extensions_ = extensions;
129
void set_fail_set_send_codecs(bool fail) {
130
fail_set_send_codecs_ = fail;
132
void set_fail_set_recv_codecs(bool fail) {
133
fail_set_recv_codecs_ = fail;
135
virtual bool AddSendStream(const StreamParams& sp) {
136
if (std::find(send_streams_.begin(), send_streams_.end(), sp) !=
137
send_streams_.end()) {
140
send_streams_.push_back(sp);
143
virtual bool RemoveSendStream(uint32 ssrc) {
144
return RemoveStreamBySsrc(&send_streams_, ssrc);
146
virtual bool AddRecvStream(const StreamParams& sp) {
147
if (std::find(receive_streams_.begin(), receive_streams_.end(), sp) !=
148
receive_streams_.end()) {
151
receive_streams_.push_back(sp);
154
virtual bool RemoveRecvStream(uint32 ssrc) {
155
return RemoveStreamBySsrc(&receive_streams_, ssrc);
157
const std::vector<StreamParams>& send_streams() const {
158
return send_streams_;
160
const std::vector<StreamParams>& recv_streams() const {
161
return receive_streams_;
163
bool HasRecvStream(uint32 ssrc) const {
164
return GetStreamBySsrc(receive_streams_, ssrc, NULL);
167
// TODO: This is to support legacy unit test that only check one
169
const uint32 send_ssrc() {
170
if (send_streams_.empty())
172
return send_streams_[0].first_ssrc();
175
// TODO: This is to support legacy unit test that only check one
177
const std::string rtcp_cname() {
178
if (send_streams_.empty())
180
return send_streams_[0].cname;
184
bool set_sending(bool send) {
188
void set_playout(bool playout) { playout_ = playout; }
189
virtual void OnPacketReceived(talk_base::Buffer* packet) {
190
rtp_packets_.push_back(std::string(packet->data(), packet->length()));
192
virtual void OnRtcpReceived(talk_base::Buffer* packet) {
193
rtcp_packets_.push_back(std::string(packet->data(), packet->length()));
195
bool fail_set_send_codecs() const {
196
return fail_set_send_codecs_;
198
bool fail_set_recv_codecs() const {
199
return fail_set_recv_codecs_;
206
std::vector<RtpHeaderExtension> recv_extensions_;
207
std::vector<RtpHeaderExtension> send_extensions_;
208
std::list<std::string> rtp_packets_;
209
std::list<std::string> rtcp_packets_;
210
std::vector<StreamParams> send_streams_;
211
std::vector<StreamParams> receive_streams_;
212
bool fail_set_send_codecs_;
213
bool fail_set_recv_codecs_;
215
std::string rtcp_cname_;
218
class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> {
220
typedef std::pair<int, bool> DtmfEvent;
221
explicit FakeVoiceMediaChannel(FakeVoiceEngine* engine)
224
fail_set_send_(false),
225
ringback_tone_ssrc_(0),
226
ringback_tone_play_(false),
227
ringback_tone_loop_(false) {
228
output_scalings_[0] = OutputScaling(); // For default channel.
230
~FakeVoiceMediaChannel();
231
const std::vector<AudioCodec>& recv_codecs() const { return recv_codecs_; }
232
const std::vector<AudioCodec>& send_codecs() const { return send_codecs_; }
233
const std::vector<AudioCodec>& codecs() const { return send_codecs(); }
234
bool muted() const { return muted_; }
235
const std::vector<DtmfEvent>& dtmf_queue() const { return dtmf_queue_; }
237
uint32 ringback_tone_ssrc() const { return ringback_tone_ssrc_; }
238
bool ringback_tone_play() const { return ringback_tone_play_; }
239
bool ringback_tone_loop() const { return ringback_tone_loop_; }
241
virtual bool SetRecvCodecs(const std::vector<AudioCodec> &codecs) {
242
if (fail_set_recv_codecs()) {
243
// Fake the failure in SetRecvCodecs.
246
recv_codecs_= codecs;
249
virtual bool SetSendCodecs(const std::vector<AudioCodec> &codecs) {
250
if (fail_set_send_codecs()) {
251
// Fake the failure in SetSendCodecs.
254
send_codecs_= codecs;
257
virtual bool SetPlayout(bool playout) {
258
set_playout(playout);
261
virtual bool SetSend(SendFlags flag) {
262
if (fail_set_send_) {
265
return set_sending(flag != SEND_NOTHING);
267
virtual bool SetSendBandwidth(bool autobw, int bps) { return true; }
268
virtual bool Mute(bool on) {
272
virtual bool AddRecvStream(const StreamParams& sp) {
273
if (!RtpHelper<VoiceMediaChannel>::AddRecvStream(sp))
275
output_scalings_[sp.first_ssrc()] = OutputScaling();
278
virtual bool RemoveRecvStream(uint32 ssrc) {
279
if (!RtpHelper<VoiceMediaChannel>::RemoveRecvStream(ssrc))
281
output_scalings_.erase(ssrc);
285
virtual bool GetActiveStreams(AudioInfo::StreamList* streams) {
288
virtual int GetOutputLevel() { return 0; }
290
virtual bool SetRingbackTone(const char *buf, int len) { return true; }
291
virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) {
292
ringback_tone_ssrc_ = ssrc;
293
ringback_tone_play_ = play;
294
ringback_tone_loop_ = loop;
298
virtual bool PressDTMF(int event, bool playout) {
299
dtmf_queue_.push_back(std::make_pair(event, playout));
303
virtual bool SetOutputScaling(uint32 ssrc, double left, double right) {
305
std::map<uint32, OutputScaling>::iterator it;
306
for (it = output_scalings_.begin(); it != output_scalings_.end(); ++it) {
307
it->second.left = left;
308
it->second.right = right;
311
} else if (output_scalings_.find(ssrc) != output_scalings_.end()) {
312
output_scalings_[ssrc].left = left;
313
output_scalings_[ssrc].right = right;
318
virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) {
319
if (output_scalings_.find(ssrc) == output_scalings_.end()) return false;
320
*left = output_scalings_[ssrc].left;
321
*right = output_scalings_[ssrc].right;
325
virtual bool GetStats(VoiceMediaInfo* info) { return false; }
326
virtual void GetLastMediaError(uint32* ssrc,
327
VoiceMediaChannel::Error* error) {
329
*error = fail_set_send_ ? VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED
330
: VoiceMediaChannel::ERROR_NONE;
333
void set_fail_set_send(bool fail) { fail_set_send_ = fail; }
334
void TriggerError(uint32 ssrc, VoiceMediaChannel::Error error) {
335
VoiceMediaChannel::SignalMediaError(ssrc, error);
339
struct OutputScaling {
340
OutputScaling() : left(1.0), right(1.0) {}
344
FakeVoiceEngine* engine_;
345
std::vector<AudioCodec> recv_codecs_;
346
std::vector<AudioCodec> send_codecs_;
348
std::map<uint32, OutputScaling> output_scalings_;
349
std::vector<DtmfEvent> dtmf_queue_;
351
uint32 ringback_tone_ssrc_;
352
bool ringback_tone_play_;
353
bool ringback_tone_loop_;
356
class FakeVideoMediaChannel : public RtpHelper<VideoMediaChannel> {
358
explicit FakeVideoMediaChannel(FakeVideoEngine* engine)
361
screen_casting_(false),
363
sent_intra_frame_(false),
364
requested_intra_frame_(false) {
366
~FakeVideoMediaChannel();
368
const std::vector<VideoCodec>& recv_codecs() const { return recv_codecs_; }
369
const std::vector<VideoCodec>& send_codecs() const { return send_codecs_; }
370
const std::vector<VideoCodec>& codecs() const { return send_codecs(); }
371
bool muted() const { return muted_; }
372
bool rendering() const { return playout(); }
373
const std::map<uint32, VideoRenderer*>& renderers() const {
376
bool GetSendStreamFormat(uint32 ssrc, VideoFormat* format) {
377
if (send_formats_.find(ssrc) == send_formats_.end()) {
380
*format = send_formats_[ssrc];
383
virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) {
384
if (send_formats_.find(ssrc) == send_formats_.end()) {
387
send_formats_[ssrc] = format;
391
virtual bool AddSendStream(const StreamParams& sp) {
392
if (!RtpHelper<VideoMediaChannel>::AddSendStream(sp)) {
395
SetSendStreamDefaultFormat(sp.first_ssrc());
398
virtual bool RemoveSendStream(uint32 ssrc) {
399
send_formats_.erase(ssrc);
400
return RtpHelper<VideoMediaChannel>::RemoveSendStream(ssrc);
403
virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) {
404
if (fail_set_recv_codecs()) {
405
// Fake the failure in SetRecvCodecs.
408
recv_codecs_= codecs;
411
virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) {
412
if (fail_set_send_codecs()) {
413
// Fake the failure in SetSendCodecs.
416
send_codecs_= codecs;
418
for (std::vector<StreamParams>::const_iterator it = send_streams().begin();
419
it != send_streams().end(); ++it) {
420
SetSendStreamDefaultFormat(it->first_ssrc());
424
virtual bool SetRender(bool render) {
428
virtual bool SetRenderer(uint32 ssrc, VideoRenderer* r) {
429
if (ssrc != 0 && renderers_.find(ssrc) == renderers_.end()) {
433
renderers_[ssrc] = r;
438
virtual bool SetSend(bool send) {
439
return set_sending(send);
441
virtual bool AddScreencast(uint32 ssrc, const ScreencastId& id, int fps) {
442
screen_casting_ = true;
443
screencast_fps_ = fps;
446
virtual bool RemoveScreencast(uint32 ssrc) {
447
screen_casting_ = false;
451
virtual bool SetSendBandwidth(bool autobw, int bps) { return true; }
452
virtual bool Mute(bool on) {
456
virtual bool AddRecvStream(const StreamParams& sp) {
457
if (!RtpHelper<VideoMediaChannel>::AddRecvStream(sp))
459
renderers_[sp.first_ssrc()] = NULL;
462
virtual bool RemoveRecvStream(uint32 ssrc) {
463
if (!RtpHelper<VideoMediaChannel>::RemoveRecvStream(ssrc))
465
renderers_.erase(ssrc);
469
virtual bool GetStats(VideoMediaInfo* info) { return false; }
470
virtual bool SendIntraFrame() {
471
sent_intra_frame_= true;
474
virtual bool RequestIntraFrame() {
475
requested_intra_frame_ = true;
478
void set_sent_intra_frame(bool v) { sent_intra_frame_ = v; }
479
bool sent_intra_frame() const { return sent_intra_frame_; }
480
void set_requested_intra_frame(bool v) { requested_intra_frame_ = v; }
481
bool requested_intra_frame() const { return requested_intra_frame_; }
482
bool screen_casting() const { return screen_casting_; }
483
int screencast_fps() const { return screencast_fps_; }
486
// Be default, each send stream uses the first send codec format.
487
void SetSendStreamDefaultFormat(uint32 ssrc) {
488
if (!send_codecs_.empty()) {
489
send_formats_[ssrc] = VideoFormat(
490
send_codecs_[0].width,
491
send_codecs_[0].height,
492
cricket::VideoFormat::FpsToInterval(send_codecs_[0].framerate),
493
cricket::FOURCC_I420);
497
FakeVideoEngine* engine_;
498
std::vector<VideoCodec> recv_codecs_;
499
std::vector<VideoCodec> send_codecs_;
500
std::map<uint32, VideoRenderer*> renderers_;
501
std::map<uint32, VideoFormat> send_formats_;
503
bool screen_casting_;
505
bool sent_intra_frame_;
506
bool requested_intra_frame_;
509
class FakeSoundclipMedia : public SoundclipMedia {
511
virtual bool PlaySound(const char *buf, int len, int flags) {
516
class FakeDataMediaChannel : public RtpHelper<DataMediaChannel> {
518
explicit FakeDataMediaChannel(void* unused)
521
~FakeDataMediaChannel() {}
522
const std::vector<DataCodec>& recv_codecs() const { return recv_codecs_; }
523
const std::vector<DataCodec>& send_codecs() const { return send_codecs_; }
524
const std::vector<DataCodec>& codecs() const { return send_codecs(); }
525
bool muted() const { return muted_; }
527
virtual bool SetRecvCodecs(const std::vector<DataCodec> &codecs) {
528
if (fail_set_recv_codecs()) {
529
// Fake the failure in SetRecvCodecs.
532
recv_codecs_= codecs;
535
virtual bool SetSendCodecs(const std::vector<DataCodec> &codecs) {
536
if (fail_set_send_codecs()) {
537
// Fake the failure in SetSendCodecs.
540
send_codecs_= codecs;
543
virtual bool SetSend(bool send) {
544
return set_sending(send);
546
virtual bool SetReceive(bool receive) {
547
set_playout(receive);
551
virtual bool SetSendBandwidth(bool autobw, int bps) { return true; }
552
virtual bool Mute(bool on) {
556
virtual bool AddRecvStream(const StreamParams& sp) {
557
if (!RtpHelper<DataMediaChannel>::AddRecvStream(sp))
561
virtual bool RemoveRecvStream(uint32 ssrc) {
562
if (!RtpHelper<DataMediaChannel>::RemoveRecvStream(ssrc))
567
virtual bool SendData(
568
const SendDataParams& params, const std::string& data) {
569
last_sent_data_params_ = params;
570
last_sent_data_ = data;
574
SendDataParams last_sent_data_params() { return last_sent_data_params_; }
575
std::string last_sent_data() { return last_sent_data_; }
578
std::vector<DataCodec> recv_codecs_;
579
std::vector<DataCodec> send_codecs_;
581
SendDataParams last_sent_data_params_;
582
std::string last_sent_data_;
585
// A base class for all of the shared parts between FakeVoiceEngine
586
// and FakeVideoEngine.
587
class FakeBaseEngine {
592
options_changed_(false),
593
fail_create_channel_(false) {
596
bool Init() { return true; }
599
bool SetOptions(int options) {
601
options_changed_ = true;
605
void SetLogging(int level, const char* filter) {
610
void set_fail_create_channel(bool fail) { fail_create_channel_ = fail; }
614
std::string logfilter_;
616
// Flag used by optionsmessagehandler_unittest for checking whether any
617
// relevant setting has been updated.
618
// TODO: Replace with explicit checks of before & after values.
619
bool options_changed_;
620
bool fail_create_channel_;
623
class FakeVoiceEngine : public FakeBaseEngine {
626
: output_volume_(-1),
628
tx_processor_(NULL) {
631
int GetCapabilities() {
632
return AUDIO_SEND | AUDIO_RECV;
635
VoiceMediaChannel* CreateChannel() {
636
if (fail_create_channel_) {
640
FakeVoiceMediaChannel* ch = new FakeVoiceMediaChannel(this);
641
channels_.push_back(ch);
644
FakeVoiceMediaChannel* GetChannel(size_t index) {
645
return (channels_.size() > index) ? channels_[index] : NULL;
647
void UnregisterChannel(VoiceMediaChannel* channel) {
648
channels_.erase(std::find(channels_.begin(), channels_.end(), channel));
650
SoundclipMedia* CreateSoundclip() {
651
return new FakeSoundclipMedia();
654
const std::vector<AudioCodec>& codecs() {
657
void SetCodecs(const std::vector<AudioCodec> codecs) {
661
bool SetDevices(const Device* in_device,
662
const Device* out_device) {
663
in_device_ = (in_device) ? in_device->name : "";
664
out_device_ = (out_device) ? out_device->name : "";
665
options_changed_ = true;
669
bool GetOutputVolume(int* level) {
670
*level = output_volume_;
674
bool SetOutputVolume(int level) {
675
output_volume_ = level;
676
options_changed_ = true;
680
int GetInputLevel() {
684
bool SetLocalMonitor(bool enable) {
688
bool RegisterProcessor(uint32 ssrc,
689
VoiceProcessor* voice_processor,
690
MediaProcessorDirection direction) {
691
if (direction == MPD_RX) {
692
rx_processor_ = voice_processor;
694
} else if (direction == MPD_TX) {
695
tx_processor_ = voice_processor;
701
bool UnregisterProcessor(uint32 ssrc,
702
VoiceProcessor* voice_processor,
703
MediaProcessorDirection direction) {
704
bool unregistered = false;
705
if (direction & MPD_RX) {
706
rx_processor_ = NULL;
709
if (direction & MPD_TX) {
710
tx_processor_ = NULL;
717
std::vector<FakeVoiceMediaChannel*> channels_;
718
std::vector<AudioCodec> codecs_;
720
std::string in_device_;
721
std::string out_device_;
722
VoiceProcessor* rx_processor_;
723
VoiceProcessor* tx_processor_;
725
friend class FakeMediaEngine;
728
class FakeVideoEngine : public FakeBaseEngine {
736
int GetCapabilities() {
737
return VIDEO_SEND | VIDEO_RECV;
739
bool SetDefaultEncoderConfig(const VideoEncoderConfig& config) {
740
default_encoder_config_ = config;
743
const VideoEncoderConfig& default_encoder_config() const {
744
return default_encoder_config_;
747
VideoMediaChannel* CreateChannel(VoiceMediaChannel* channel) {
748
if (fail_create_channel_) {
752
FakeVideoMediaChannel* ch = new FakeVideoMediaChannel(this);
753
channels_.push_back(ch);
756
FakeVideoMediaChannel* GetChannel(size_t index) {
757
return (channels_.size() > index) ? channels_[index] : NULL;
759
void UnregisterChannel(VideoMediaChannel* channel) {
760
channels_.erase(std::find(channels_.begin(), channels_.end(), channel));
763
const std::vector<VideoCodec>& codecs() const {
766
bool FindCodec(const VideoCodec& in) {
767
for (size_t i = 0; i < codecs_.size(); ++i) {
768
if (codecs_[i].Matches(in)) {
774
void SetCodecs(const std::vector<VideoCodec> codecs) {
778
bool SetCaptureDevice(const Device* device) {
779
in_device_ = (device) ? device->name : "";
780
options_changed_ = true;
783
bool SetLocalRenderer(VideoRenderer* r) {
787
bool SetVideoCapturer(VideoCapturer* /*capturer*/, uint32 /*ssrc*/) {
790
CaptureResult SetCapture(bool capture) {
794
bool RegisterProcessor(VideoProcessor* video_processor) {
795
processor_ = video_processor;
799
bool UnregisterProcessor(VideoProcessor* video_processor) {
804
sigslot::signal2<VideoCapturer*, CaptureResult> SignalCaptureResult;
807
std::vector<FakeVideoMediaChannel*> channels_;
808
std::vector<VideoCodec> codecs_;
809
VideoEncoderConfig default_encoder_config_;
810
std::string in_device_;
811
VideoRenderer* renderer_;
813
VideoProcessor* processor_;
815
friend class FakeMediaEngine;
818
class FakeMediaEngine
819
: public CompositeMediaEngine<FakeVoiceEngine, FakeVideoEngine> {
822
voice_ = FakeVoiceEngine();
823
video_ = FakeVideoEngine();
825
virtual ~FakeMediaEngine() {}
827
virtual void SetAudioCodecs(const std::vector<AudioCodec> codecs) {
828
voice_.SetCodecs(codecs);
831
virtual void SetVideoCodecs(const std::vector<VideoCodec> codecs) {
832
video_.SetCodecs(codecs);
835
FakeVoiceMediaChannel* GetVoiceChannel(size_t index) {
836
return voice_.GetChannel(index);
839
FakeVideoMediaChannel* GetVideoChannel(size_t index) {
840
return video_.GetChannel(index);
843
int audio_options() const { return voice_.options_; }
844
int output_volume() const { return voice_.output_volume_; }
845
const VideoEncoderConfig& default_video_encoder_config() const {
846
return video_.default_encoder_config_;
848
const std::string& audio_in_device() const { return voice_.in_device_; }
849
const std::string& audio_out_device() const { return voice_.out_device_; }
850
const std::string& video_in_device() const { return video_.in_device_; }
851
VideoRenderer* local_renderer() { return video_.renderer_; }
852
int voice_loglevel() const { return voice_.loglevel_; }
853
const std::string& voice_logfilter() const { return voice_.logfilter_; }
854
int video_loglevel() const { return video_.loglevel_; }
855
const std::string& video_logfilter() const { return video_.logfilter_; }
856
bool capture() const { return video_.capture_; }
857
bool options_changed() const {
858
return voice_.options_changed_ || video_.options_changed_;
860
void clear_options_changed() {
861
video_.options_changed_ = false;
862
voice_.options_changed_ = false;
864
void set_fail_create_channel(bool fail) {
865
voice_.set_fail_create_channel(fail);
866
video_.set_fail_create_channel(fail);
868
bool video_processor_registered () const {return video_.processor_ != NULL;}
869
bool voice_processor_registered(MediaProcessorDirection direction) const {
870
if (direction == MPD_RX) {
871
return voice_.rx_processor_ != NULL;
872
} else if (direction == MPD_TX) {
873
return voice_.tx_processor_ != NULL;
879
// CompositeMediaEngine with FakeVoiceEngine to expose SetAudioCodecs to
880
// establish a media connectionwith minimum set of audio codes required
881
template<class VIDEO>
882
class CompositeMediaEngineWithFakeVoiceEngine
883
: public CompositeMediaEngine<FakeVoiceEngine, VIDEO> {
885
CompositeMediaEngineWithFakeVoiceEngine() {}
886
virtual ~CompositeMediaEngineWithFakeVoiceEngine() {}
888
virtual void SetAudioCodecs(const std::vector<AudioCodec>& codecs) {
889
CompositeMediaEngine<FakeVoiceEngine, VIDEO>::voice_.SetCodecs(codecs);
893
// Have to come afterwards due to declaration order
894
inline FakeVoiceMediaChannel::~FakeVoiceMediaChannel() {
896
engine_->UnregisterChannel(this);
900
inline FakeVideoMediaChannel::~FakeVideoMediaChannel() {
902
engine_->UnregisterChannel(this);
906
class FakeDataEngine : public DataEngineInterface {
908
virtual DataMediaChannel* CreateChannel() {
909
FakeDataMediaChannel* ch = new FakeDataMediaChannel(this);
910
channels_.push_back(ch);
914
FakeDataMediaChannel* GetChannel(size_t index) {
915
return (channels_.size() > index) ? channels_[index] : NULL;
918
void UnregisterChannel(DataMediaChannel* channel) {
919
channels_.erase(std::find(channels_.begin(), channels_.end(), channel));
922
virtual void SetDataCodecs(const std::vector<DataCodec>& data_codecs) {
923
data_codecs_ = data_codecs;
926
virtual const std::vector<DataCodec>& data_codecs() {
931
std::vector<FakeDataMediaChannel*> channels_;
932
std::vector<DataCodec> data_codecs_;
935
} // namespace cricket
937
#endif // TALK_SESSION_PHONE_FAKEMEDIAENGINE_H_