1 /* 2 * libjingle 3 * Copyright 2010, Google Inc. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 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. 15 * 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. 26 */ 27 28 // LinphoneMediaEngine is a Linphone implementation of MediaEngine 29 30 #ifndef TALK_SESSION_PHONE_LINPHONEMEDIAENGINE_H_ 31 #define TALK_SESSION_PHONE_LINPHONEMEDIAENGINE_H_ 32 33 #ifdef HAVE_LINPHONE 34 35 #include <string> 36 #include <vector> 37 38 extern "C" { 39 #include <mediastreamer2/mediastream.h> 40 } 41 42 #include "talk/base/scoped_ptr.h" 43 #include "talk/session/phone/codec.h" 44 #include "talk/session/phone/mediachannel.h" 45 #include "talk/session/phone/mediaengine.h" 46 47 namespace talk_base { 48 class StreamInterface; 49 } 50 51 namespace cricket { 52 53 class LinphoneMediaEngine : public MediaEngineInterface { 54 public: 55 LinphoneMediaEngine(const std::string& ringWav, const std::string& callWav); ~LinphoneMediaEngine()56 virtual ~LinphoneMediaEngine() {} 57 58 // Implement pure virtual methods of MediaEngine. Init()59 virtual bool Init() { return true; } 60 virtual void Terminate(); 61 virtual int GetCapabilities(); 62 virtual VoiceMediaChannel* CreateChannel(); 63 virtual VideoMediaChannel* CreateVideoChannel(VoiceMediaChannel* voice_ch); CreateSoundclip()64 virtual SoundclipMedia* CreateSoundclip() { return NULL; } SetAudioOptions(int options)65 virtual bool SetAudioOptions(int options) { return true; } SetVideoOptions(int options)66 virtual bool SetVideoOptions(int options) { return true; } SetDefaultVideoEncoderConfig(const VideoEncoderConfig & config)67 virtual bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config) { 68 return true; 69 } SetSoundDevices(const Device * in_dev,const Device * out_dev)70 virtual bool SetSoundDevices(const Device* in_dev, const Device* out_dev) { 71 return true; 72 } SetVideoCaptureDevice(const Device * cam_device)73 virtual bool SetVideoCaptureDevice(const Device* cam_device) { return true; } SetOutputVolume(int level)74 virtual bool SetOutputVolume(int level) { return true; } GetInputLevel()75 virtual int GetInputLevel() { return 0; } SetLocalMonitor(bool enable)76 virtual bool SetLocalMonitor(bool enable) { return true; } SetLocalRenderer(VideoRenderer * renderer)77 virtual bool SetLocalRenderer(VideoRenderer* renderer) { return true; } 78 // TODO: control channel send? SetVideoCapture(bool capture)79 virtual CaptureResult SetVideoCapture(bool capture) { return CR_SUCCESS; } audio_codecs()80 virtual const std::vector<AudioCodec>& audio_codecs() { return voice_codecs_; } video_codecs()81 virtual const std::vector<VideoCodec>& video_codecs() { return video_codecs_; } 82 virtual bool FindAudioCodec(const AudioCodec& codec); FindVideoCodec(const VideoCodec & codec)83 virtual bool FindVideoCodec(const VideoCodec& codec) { return true; } SetVoiceLogging(int min_sev,const char * filter)84 virtual void SetVoiceLogging(int min_sev, const char* filter) {} SetVideoLogging(int min_sev,const char * filter)85 virtual void SetVideoLogging(int min_sev, const char* filter) {} SetVideoCapturer(cricket::VideoCapturer *,uint32)86 virtual bool SetVideoCapturer(cricket::VideoCapturer*, uint32) { return true; } GetOutputVolume(int *)87 virtual bool GetOutputVolume(int*) { return true; } RegisterVideoProcessor(cricket::VideoProcessor *)88 virtual bool RegisterVideoProcessor(cricket::VideoProcessor*) { return true; } UnregisterVideoProcessor(cricket::VideoProcessor *)89 virtual bool UnregisterVideoProcessor(cricket::VideoProcessor*) { return true; } RegisterVoiceProcessor(uint32,cricket::VoiceProcessor *,cricket::MediaProcessorDirection)90 virtual bool RegisterVoiceProcessor(uint32, cricket::VoiceProcessor*, cricket::MediaProcessorDirection) { return true; } UnregisterVoiceProcessor(uint32,cricket::VoiceProcessor *,cricket::MediaProcessorDirection)91 virtual bool UnregisterVoiceProcessor(uint32, cricket::VoiceProcessor*, cricket::MediaProcessorDirection) { return true; } 92 GetRingWav()93 std::string GetRingWav(){return ring_wav_;} GetCallWav()94 std::string GetCallWav(){return call_wav_;} 95 96 bool have_ilbc; 97 bool have_speex; 98 bool have_gsm; 99 100 private: 101 std::vector<AudioCodec> voice_codecs_; 102 std::vector<VideoCodec> video_codecs_; 103 104 std::string ring_wav_; 105 std::string call_wav_; 106 107 DISALLOW_COPY_AND_ASSIGN(LinphoneMediaEngine); 108 }; 109 110 class LinphoneVoiceChannel : public VoiceMediaChannel { 111 public: 112 LinphoneVoiceChannel(LinphoneMediaEngine *eng); 113 virtual ~LinphoneVoiceChannel(); 114 115 // Implement pure virtual methods of VoiceMediaChannel. 116 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs); 117 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs); 118 virtual bool SetPlayout(bool playout); 119 virtual bool SetSend(SendFlags flag); GetActiveStreams(AudioInfo::StreamList * actives)120 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) { return true; } GetOutputLevel()121 virtual int GetOutputLevel() { return 0; } SetOutputScaling(uint32 ssrc,double left,double right)122 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) { 123 return false; 124 } GetOutputScaling(uint32 ssrc,double * left,double * right)125 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) { 126 return false; 127 } SetRingbackTone(const char * buf,int len)128 virtual bool SetRingbackTone(const char* buf, int len) { return true; } PlayRingbackTone(bool play,bool loop)129 virtual bool PlayRingbackTone(bool play, bool loop) { return true; } PressDTMF(int event,bool playout)130 virtual bool PressDTMF(int event, bool playout) { return true; } GetStats(VoiceMediaInfo * info)131 virtual bool GetStats(VoiceMediaInfo* info) { return true; } 132 133 // Implement pure virtual methods of MediaChannel. 134 virtual void OnPacketReceived(talk_base::Buffer* packet); 135 virtual void OnRtcpReceived(talk_base::Buffer* packet); 136 virtual bool Mute(bool on); SetSendBandwidth(bool autobw,int bps)137 virtual bool SetSendBandwidth(bool autobw, int bps) { return true; } SetOptions(int options)138 virtual bool SetOptions(int options) { return true; } SetRecvRtpHeaderExtensions(const std::vector<RtpHeaderExtension> & extensions)139 virtual bool SetRecvRtpHeaderExtensions( 140 const std::vector<RtpHeaderExtension>& extensions) { return true; } SetSendRtpHeaderExtensions(const std::vector<RtpHeaderExtension> & extensions)141 virtual bool SetSendRtpHeaderExtensions( 142 const std::vector<RtpHeaderExtension>& extensions) { return true; } 143 virtual bool AddSendStream(const cricket::StreamParams&); RemoveSendStream(uint32)144 virtual bool RemoveSendStream(uint32) { return true; } AddRecvStream(const cricket::StreamParams &)145 virtual bool AddRecvStream(const cricket::StreamParams&) { return true; } RemoveRecvStream(uint32)146 virtual bool RemoveRecvStream(uint32) { return true; } GetOptions()147 virtual int GetOptions() const { return 0; } PlayRingbackTone(uint32,bool,bool)148 virtual bool PlayRingbackTone(uint32, bool, bool) { return true; } 149 150 virtual void StartRing(bool bIncomingCall); 151 virtual void StopRing(); 152 153 private: 154 int pt_; 155 bool profile_; 156 bool mute_; 157 bool play_; 158 AudioStream *audio_stream_; 159 LinphoneMediaEngine *engine_; 160 RingStream* ring_stream_; 161 talk_base::scoped_ptr<talk_base::AsyncSocket> socket_; 162 talk_base::scoped_ptr<talk_base::AsyncSocket> socketRtcp_; 163 void OnIncomingData(talk_base::AsyncSocket *s); 164 void OnIncomingRtcp(talk_base::AsyncSocket *s); 165 bool StartCall(); 166 167 int captport; // local port for audio_stream 168 int playport; // local port for rtp 169 int playport2; // local port for rtcp 170 171 DISALLOW_COPY_AND_ASSIGN(LinphoneVoiceChannel); 172 }; 173 174 } // namespace cricket 175 176 #endif // HAVE_LINPHONE 177 178 #endif // TALK_SESSION_PHONE_LINPHONEMEDIAENGINE_H_ 179