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#include <string> 34#include <vector> 35 36extern "C" { 37#include <mediastreamer2/mediastream.h> 38} 39 40#include "talk/media/base/codec.h" 41#include "talk/media/base/mediachannel.h" 42#include "talk/media/base/mediaengine.h" 43#include "webrtc/base/scoped_ptr.h" 44 45namespace rtc { 46class StreamInterface; 47} 48 49namespace cricket { 50 51class LinphoneMediaEngine : public MediaEngineInterface { 52 public: 53 LinphoneMediaEngine(const std::string& ringWav, const std::string& callWav); 54 virtual ~LinphoneMediaEngine() {} 55 56 // Should be called before codecs() and video_codecs() are called. We need to 57 // set the voice and video codecs; otherwise, Jingle initiation will fail. 58 void set_voice_codecs(const std::vector<AudioCodec>& codecs) { 59 voice_codecs_ = codecs; 60 } 61 void set_video_codecs(const std::vector<VideoCodec>& codecs) { 62 video_codecs_ = codecs; 63 } 64 65 // Implement pure virtual methods of MediaEngine. 66 virtual bool Init(); 67 virtual void Terminate(); 68 virtual int GetCapabilities(); 69 virtual VoiceMediaChannel* CreateChannel(); 70 virtual VideoMediaChannel* CreateVideoChannel(VoiceMediaChannel* voice_ch); 71 virtual SoundclipMedia* CreateSoundclip() { return NULL; } 72 virtual bool SetAudioOptions(int options) { return true; } 73 virtual bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config) { 74 return true; 75 } 76 virtual bool SetSoundDevices(const Device* in_dev, const Device* out_dev) { 77 return true; 78 } 79 virtual bool SetVideoCaptureDevice(const Device* cam_device) { return true; } 80 virtual bool SetOutputVolume(int level) { return true; } 81 virtual int GetInputLevel() { return 0; } 82 virtual bool SetLocalMonitor(bool enable) { return true; } 83 // TODO: control channel send? 84 virtual bool SetVideoCapture(bool capture) { return true; } 85 virtual const std::vector<AudioCodec>& audio_codecs() { 86 return voice_codecs_; 87 } 88 virtual const std::vector<VideoCodec>& video_codecs() { 89 return video_codecs_; 90 } 91 virtual bool FindAudioCodec(const AudioCodec& codec); 92 virtual bool FindVideoCodec(const VideoCodec& codec) { return true; } 93 virtual void SetVoiceLogging(int min_sev, const char* filter) {} 94 virtual void SetVideoLogging(int min_sev, const char* filter) {} 95 96 std::string GetRingWav(){return ring_wav_;} 97 std::string GetCallWav(){return call_wav_;} 98 99 int have_ilbc; 100 101 private: 102 std::string voice_input_filename_; 103 std::string voice_output_filename_; 104 std::string video_input_filename_; 105 std::string video_output_filename_; 106 std::vector<AudioCodec> voice_codecs_; 107 std::vector<VideoCodec> video_codecs_; 108 109 std::string ring_wav_; 110 std::string call_wav_; 111 112 DISALLOW_COPY_AND_ASSIGN(LinphoneMediaEngine); 113}; 114 115class LinphoneVoiceChannel : public VoiceMediaChannel { 116 public: 117 LinphoneVoiceChannel(LinphoneMediaEngine *eng); 118 virtual ~LinphoneVoiceChannel(); 119 120 // Implement pure virtual methods of VoiceMediaChannel. 121 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) { return true; } 122 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs); 123 virtual bool SetPlayout(bool playout); 124 virtual bool SetSend(SendFlags flag); 125 virtual bool AddStream(uint32 ssrc) { return true; } 126 virtual bool RemoveStream(uint32 ssrc) { return true; } 127 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) { return true; } 128 virtual int GetOutputLevel() { return 0; } 129 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) { 130 return false; 131 } 132 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) { 133 return false; 134 } 135 virtual void SetRingbackTone(const char* buf, int len) {} 136 virtual bool PlayRingbackTone(bool play, bool loop) { return true; } 137 virtual bool PressDTMF(int event, bool playout) { return true; } 138 virtual bool GetStats(VoiceMediaInfo* info) { return true; } 139 140 // Implement pure virtual methods of MediaChannel. 141 virtual void OnPacketReceived(rtc::Buffer* packet); 142 virtual void OnRtcpReceived(rtc::Buffer* packet) {} 143 virtual void SetSendSsrc(uint32 id) {} // TODO: change RTP packet? 144 virtual bool SetRtcpCName(const std::string& cname) { return true; } 145 virtual bool Mute(bool on) { return mute_; } 146 virtual bool SetStartSendBandwidth(int bps) { return true; } 147 virtual bool SetMaxSendBandwidth(int bps) { return true; } 148 virtual bool SetOptions(int options) { return true; } 149 virtual bool SetRecvRtpHeaderExtensions( 150 const std::vector<RtpHeaderExtension>& extensions) { return true; } 151 virtual bool SetSendRtpHeaderExtensions( 152 const std::vector<RtpHeaderExtension>& extensions) { return true; } 153 154 virtual void StartRing(bool bIncomingCall); 155 virtual void StopRing(); 156 157 private: 158 int pt_; 159 bool mute_; 160 bool play_; 161 AudioStream *audio_stream_; 162 LinphoneMediaEngine *engine_; 163 RingStream* ring_stream_; 164 rtc::scoped_ptr<rtc::AsyncSocket> socket_; 165 void OnIncomingData(rtc::AsyncSocket *s); 166 167 DISALLOW_COPY_AND_ASSIGN(LinphoneVoiceChannel); 168}; 169 170} // namespace cricket 171 172#endif // TALK_SESSION_PHONE_LINPHONEMEDIAENGINE_H_ 173