15976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org/*
25976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * libjingle
35976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Copyright 2010 Google Inc.
45976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
55976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Redistribution and use in source and binary forms, with or without
65976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * modification, are permitted provided that the following conditions are met:
75976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
85976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  1. Redistributions of source code must retain the above copyright notice,
95976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     this list of conditions and the following disclaimer.
105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  2. Redistributions in binary form must reproduce the above copyright notice,
115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     this list of conditions and the following disclaimer in the documentation
125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     and/or other materials provided with the distribution.
135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  3. The name of the author may not be used to endorse or promote products
145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     derived from this software without specific prior written permission.
155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org */
275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// LinphoneMediaEngine is a Linphone implementation of MediaEngine
295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#ifndef TALK_SESSION_PHONE_LINPHONEMEDIAENGINE_H_
315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#define TALK_SESSION_PHONE_LINPHONEMEDIAENGINE_H_
325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include <string>
345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include <vector>
355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgextern "C" {
375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include <mediastreamer2/mediastream.h>
385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org}
395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/scoped_ptr.h"
415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/media/base/codec.h"
425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/media/base/mediachannel.h"
435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/media/base/mediaengine.h"
445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgnamespace talk_base {
465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass StreamInterface;
475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org}
485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgnamespace cricket {
505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass LinphoneMediaEngine : public MediaEngineInterface {
525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org public:
535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  LinphoneMediaEngine(const std::string& ringWav,  const std::string& callWav);
545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual ~LinphoneMediaEngine() {}
555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Should be called before codecs() and video_codecs() are called. We need to
575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // set the voice and video codecs; otherwise, Jingle initiation will fail.
585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void set_voice_codecs(const std::vector<AudioCodec>& codecs) {
595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    voice_codecs_ = codecs;
605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void set_video_codecs(const std::vector<VideoCodec>& codecs) {
625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    video_codecs_ = codecs;
635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Implement pure virtual methods of MediaEngine.
665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool Init();
675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual void Terminate();
685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual int GetCapabilities();
695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual VoiceMediaChannel* CreateChannel();
705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual VideoMediaChannel* CreateVideoChannel(VoiceMediaChannel* voice_ch);
715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual SoundclipMedia* CreateSoundclip() { return NULL; }
725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetAudioOptions(int options) { return true; }
735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetVideoOptions(int options) { return true; }
745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config) {
755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return true;
765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetSoundDevices(const Device* in_dev, const Device* out_dev) {
785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return true;
795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetVideoCaptureDevice(const Device* cam_device) { return true; }
815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetOutputVolume(int level) { return true; }
825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual int GetInputLevel() { return 0; }
835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetLocalMonitor(bool enable) { return true; }
845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetLocalRenderer(VideoRenderer* renderer) { return true; }
855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // TODO: control channel send?
865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetVideoCapture(bool capture) { return true; }
875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual const std::vector<AudioCodec>& audio_codecs() {
885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return voice_codecs_;
895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
905976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual const std::vector<VideoCodec>& video_codecs() {
915976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return video_codecs_;
925976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
935976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool FindAudioCodec(const AudioCodec& codec);
945976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool FindVideoCodec(const VideoCodec& codec) { return true; }
955976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual void SetVoiceLogging(int min_sev, const char* filter) {}
965976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual void SetVideoLogging(int min_sev, const char* filter) {}
975976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
985976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  std::string GetRingWav(){return ring_wav_;}
995976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  std::string GetCallWav(){return call_wav_;}
1005976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1015976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  int have_ilbc;
1025976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1035976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org private:
1045976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  std::string voice_input_filename_;
1055976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  std::string voice_output_filename_;
1065976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  std::string video_input_filename_;
1075976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  std::string video_output_filename_;
1085976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  std::vector<AudioCodec> voice_codecs_;
1095976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  std::vector<VideoCodec> video_codecs_;
1105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  std::string ring_wav_;
1125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  std::string call_wav_;
1135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  DISALLOW_COPY_AND_ASSIGN(LinphoneMediaEngine);
1155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org};
1165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass LinphoneVoiceChannel : public VoiceMediaChannel {
1185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org public:
1195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  LinphoneVoiceChannel(LinphoneMediaEngine *eng);
1205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual ~LinphoneVoiceChannel();
1215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Implement pure virtual methods of VoiceMediaChannel.
1235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) { return true; }
1245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs);
1255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetPlayout(bool playout);
1265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetSend(SendFlags flag);
1275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool AddStream(uint32 ssrc) { return true; }
1285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool RemoveStream(uint32 ssrc) { return true; }
1295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool GetActiveStreams(AudioInfo::StreamList* actives) { return true; }
1305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual int GetOutputLevel() { return 0; }
1315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetOutputScaling(uint32 ssrc, double left, double right) {
1325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return false;
1335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
1345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) {
1355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org    return false;
1365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  }
1375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual void SetRingbackTone(const char* buf, int len) {}
1385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool PlayRingbackTone(bool play, bool loop) { return true; }
1395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool PressDTMF(int event, bool playout) { return true; }
1405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool GetStats(VoiceMediaInfo* info) { return true; }
1415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Implement pure virtual methods of MediaChannel.
1435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual void OnPacketReceived(talk_base::Buffer* packet);
1445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual void OnRtcpReceived(talk_base::Buffer* packet) {}
1455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual void SetSendSsrc(uint32 id) {}  // TODO: change RTP packet?
1465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetRtcpCName(const std::string& cname) { return true; }
1475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool Mute(bool on) { return mute_; }
1485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetSendBandwidth(bool autobw, int bps) { return true; }
1495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetOptions(int options) { return true; }
1505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetRecvRtpHeaderExtensions(
1515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org      const std::vector<RtpHeaderExtension>& extensions) { return true; }
1525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetSendRtpHeaderExtensions(
1535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org      const std::vector<RtpHeaderExtension>& extensions) { return true; }
1545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual void StartRing(bool bIncomingCall);
1565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual void StopRing();
1575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org private:
1595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  int pt_;
1605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  bool mute_;
1615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  bool play_;
1625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  AudioStream *audio_stream_;
1635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  LinphoneMediaEngine *engine_;
1645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  RingStream* ring_stream_;
1655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  talk_base::scoped_ptr<talk_base::AsyncSocket> socket_;
1665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  void OnIncomingData(talk_base::AsyncSocket *s);
1675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  DISALLOW_COPY_AND_ASSIGN(LinphoneVoiceChannel);
1695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org};
1705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org}  // namespace cricket
1725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
1735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#endif  // TALK_SESSION_PHONE_LINPHONEMEDIAENGINE_H_
174