- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / media / other / linphonemediaengine.h
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
36 extern "C" {
37 #include <mediastreamer2/mediastream.h>
38 }
39
40 #include "talk/base/scoped_ptr.h"
41 #include "talk/media/base/codec.h"
42 #include "talk/media/base/mediachannel.h"
43 #include "talk/media/base/mediaengine.h"
44
45 namespace talk_base {
46 class StreamInterface;
47 }
48
49 namespace cricket {
50
51 class 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 SetVideoOptions(int options) { return true; }
74   virtual bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config) {
75     return true;
76   }
77   virtual bool SetSoundDevices(const Device* in_dev, const Device* out_dev) {
78     return true;
79   }
80   virtual bool SetVideoCaptureDevice(const Device* cam_device) { return true; }
81   virtual bool SetOutputVolume(int level) { return true; }
82   virtual int GetInputLevel() { return 0; }
83   virtual bool SetLocalMonitor(bool enable) { return true; }
84   virtual bool SetLocalRenderer(VideoRenderer* renderer) { return true; }
85   // TODO: control channel send?
86   virtual bool SetVideoCapture(bool capture) { return true; }
87   virtual const std::vector<AudioCodec>& audio_codecs() {
88     return voice_codecs_;
89   }
90   virtual const std::vector<VideoCodec>& video_codecs() {
91     return video_codecs_;
92   }
93   virtual bool FindAudioCodec(const AudioCodec& codec);
94   virtual bool FindVideoCodec(const VideoCodec& codec) { return true; }
95   virtual void SetVoiceLogging(int min_sev, const char* filter) {}
96   virtual void SetVideoLogging(int min_sev, const char* filter) {}
97
98   std::string GetRingWav(){return ring_wav_;}
99   std::string GetCallWav(){return call_wav_;}
100
101   int have_ilbc;
102
103  private:
104   std::string voice_input_filename_;
105   std::string voice_output_filename_;
106   std::string video_input_filename_;
107   std::string video_output_filename_;
108   std::vector<AudioCodec> voice_codecs_;
109   std::vector<VideoCodec> video_codecs_;
110
111   std::string ring_wav_;
112   std::string call_wav_;
113
114   DISALLOW_COPY_AND_ASSIGN(LinphoneMediaEngine);
115 };
116
117 class LinphoneVoiceChannel : public VoiceMediaChannel {
118  public:
119   LinphoneVoiceChannel(LinphoneMediaEngine *eng);
120   virtual ~LinphoneVoiceChannel();
121
122   // Implement pure virtual methods of VoiceMediaChannel.
123   virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) { return true; }
124   virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs);
125   virtual bool SetPlayout(bool playout);
126   virtual bool SetSend(SendFlags flag);
127   virtual bool AddStream(uint32 ssrc) { return true; }
128   virtual bool RemoveStream(uint32 ssrc) { return true; }
129   virtual bool GetActiveStreams(AudioInfo::StreamList* actives) { return true; }
130   virtual int GetOutputLevel() { return 0; }
131   virtual bool SetOutputScaling(uint32 ssrc, double left, double right) {
132     return false;
133   }
134   virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) {
135     return false;
136   }
137   virtual void SetRingbackTone(const char* buf, int len) {}
138   virtual bool PlayRingbackTone(bool play, bool loop) { return true; }
139   virtual bool PressDTMF(int event, bool playout) { return true; }
140   virtual bool GetStats(VoiceMediaInfo* info) { return true; }
141
142   // Implement pure virtual methods of MediaChannel.
143   virtual void OnPacketReceived(talk_base::Buffer* packet);
144   virtual void OnRtcpReceived(talk_base::Buffer* packet) {}
145   virtual void SetSendSsrc(uint32 id) {}  // TODO: change RTP packet?
146   virtual bool SetRtcpCName(const std::string& cname) { return true; }
147   virtual bool Mute(bool on) { return mute_; }
148   virtual bool SetSendBandwidth(bool autobw, int bps) { return true; }
149   virtual bool SetOptions(int options) { return true; }
150   virtual bool SetRecvRtpHeaderExtensions(
151       const std::vector<RtpHeaderExtension>& extensions) { return true; }
152   virtual bool SetSendRtpHeaderExtensions(
153       const std::vector<RtpHeaderExtension>& extensions) { return true; }
154
155   virtual void StartRing(bool bIncomingCall);
156   virtual void StopRing();
157
158  private:
159   int pt_;
160   bool mute_;
161   bool play_;
162   AudioStream *audio_stream_;
163   LinphoneMediaEngine *engine_;
164   RingStream* ring_stream_;
165   talk_base::scoped_ptr<talk_base::AsyncSocket> socket_;
166   void OnIncomingData(talk_base::AsyncSocket *s);
167
168   DISALLOW_COPY_AND_ASSIGN(LinphoneVoiceChannel);
169 };
170
171 }  // namespace cricket
172
173 #endif  // TALK_SESSION_PHONE_LINPHONEMEDIAENGINE_H_