Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / media / base / filemediaengine.h
1 // libjingle
2 // Copyright 2004 Google Inc.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 //  1. Redistributions of source code must retain the above copyright notice,
8 //     this list of conditions and the following disclaimer.
9 //  2. Redistributions in binary form must reproduce the above copyright notice,
10 //     this list of conditions and the following disclaimer in the documentation
11 //     and/or other materials provided with the distribution.
12 //  3. The name of the author may not be used to endorse or promote products
13 //     derived from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26 #ifndef TALK_MEDIA_BASE_FILEMEDIAENGINE_H_
27 #define TALK_MEDIA_BASE_FILEMEDIAENGINE_H_
28
29 #include <string>
30 #include <vector>
31
32 #include "talk/media/base/codec.h"
33 #include "talk/media/base/mediachannel.h"
34 #include "talk/media/base/mediaengine.h"
35 #include "webrtc/base/scoped_ptr.h"
36 #include "webrtc/base/stream.h"
37
38 namespace rtc {
39 class StreamInterface;
40 }
41
42 namespace cricket {
43
44 // A media engine contains a capturer, an encoder, and a sender in the sender
45 // side and a receiver, a decoder, and a renderer in the receiver side.
46 // FileMediaEngine simulates the capturer and the encoder via an input RTP dump
47 // stream and simulates the decoder and the renderer via an output RTP dump
48 // stream. Depending on the parameters of the constructor, FileMediaEngine can
49 // act as file voice engine, file video engine, or both. Currently, we use
50 // only the RTP dump packets. TODO(whyuan): Enable RTCP packets.
51 class FileMediaEngine : public MediaEngineInterface {
52  public:
53   FileMediaEngine() : rtp_sender_thread_(NULL) {}
54   virtual ~FileMediaEngine() {}
55
56   // Set the file name of the input or output RTP dump for voice or video.
57   // Should be called before the channel is created.
58   void set_voice_input_filename(const std::string& filename) {
59     voice_input_filename_ = filename;
60   }
61   void set_voice_output_filename(const std::string& filename) {
62     voice_output_filename_ = filename;
63   }
64   void set_video_input_filename(const std::string& filename) {
65     video_input_filename_ = filename;
66   }
67   void set_video_output_filename(const std::string& filename) {
68     video_output_filename_ = filename;
69   }
70
71   // Should be called before codecs() and video_codecs() are called. We need to
72   // set the voice and video codecs; otherwise, Jingle initiation will fail.
73   void set_voice_codecs(const std::vector<AudioCodec>& codecs) {
74     voice_codecs_ = codecs;
75   }
76   void set_video_codecs(const std::vector<VideoCodec>& codecs) {
77     video_codecs_ = codecs;
78   }
79
80   // Implement pure virtual methods of MediaEngine.
81   virtual bool Init(rtc::Thread* worker_thread) {
82     return true;
83   }
84   virtual void Terminate() {}
85   virtual int GetCapabilities();
86   virtual VoiceMediaChannel* CreateChannel();
87   virtual VideoMediaChannel* CreateVideoChannel(VoiceMediaChannel* voice_ch);
88   virtual SoundclipMedia* CreateSoundclip() { return NULL; }
89   virtual AudioOptions GetAudioOptions() const { return AudioOptions(); }
90   virtual bool SetAudioOptions(const AudioOptions& options) { return true; }
91   virtual bool SetVideoOptions(const VideoOptions& options) { return true; }
92   virtual bool SetAudioDelayOffset(int offset) { return true; }
93   virtual bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config) {
94     return true;
95   }
96   virtual VideoEncoderConfig GetDefaultVideoEncoderConfig() const {
97     return VideoEncoderConfig();
98   }
99   virtual bool SetSoundDevices(const Device* in_dev, const Device* out_dev) {
100     return true;
101   }
102   virtual bool SetVideoCaptureDevice(const Device* cam_device) { return true; }
103   virtual bool SetVideoCapturer(VideoCapturer* /*capturer*/) {
104     return true;
105   }
106   virtual VideoCapturer* GetVideoCapturer() const {
107     return NULL;
108   }
109   virtual bool GetOutputVolume(int* level) {
110     *level = 0;
111     return true;
112   }
113   virtual bool SetOutputVolume(int level) { return true; }
114   virtual int GetInputLevel() { return 0; }
115   virtual bool SetLocalMonitor(bool enable) { return true; }
116   virtual bool SetLocalRenderer(VideoRenderer* renderer) { return true; }
117   // TODO(whyuan): control channel send?
118   virtual bool SetVideoCapture(bool capture) { return true; }
119   virtual const std::vector<AudioCodec>& audio_codecs() {
120     return voice_codecs_;
121   }
122   virtual const std::vector<VideoCodec>& video_codecs() {
123     return video_codecs_;
124   }
125   virtual const std::vector<RtpHeaderExtension>& audio_rtp_header_extensions() {
126     return audio_rtp_header_extensions_;
127   }
128   virtual const std::vector<RtpHeaderExtension>& video_rtp_header_extensions() {
129     return video_rtp_header_extensions_;
130   }
131
132   virtual bool FindAudioCodec(const AudioCodec& codec) { return true; }
133   virtual bool FindVideoCodec(const VideoCodec& codec) { return true; }
134   virtual void SetVoiceLogging(int min_sev, const char* filter) {}
135   virtual void SetVideoLogging(int min_sev, const char* filter) {}
136   virtual bool StartAecDump(rtc::PlatformFile) { return false; }
137
138   virtual bool RegisterVideoProcessor(VideoProcessor* processor) {
139     return true;
140   }
141   virtual bool UnregisterVideoProcessor(VideoProcessor* processor) {
142     return true;
143   }
144   virtual bool RegisterVoiceProcessor(uint32 ssrc,
145                                       VoiceProcessor* processor,
146                                       MediaProcessorDirection direction) {
147     return true;
148   }
149   virtual bool UnregisterVoiceProcessor(uint32 ssrc,
150                                         VoiceProcessor* processor,
151                                         MediaProcessorDirection direction) {
152     return true;
153   }
154   VideoFormat GetStartCaptureFormat() const {
155     return VideoFormat();
156   }
157
158   virtual sigslot::repeater2<VideoCapturer*, CaptureState>&
159       SignalVideoCaptureStateChange() {
160     return signal_state_change_;
161   }
162
163   void set_rtp_sender_thread(rtc::Thread* thread) {
164     rtp_sender_thread_ = thread;
165   }
166
167  private:
168   std::string voice_input_filename_;
169   std::string voice_output_filename_;
170   std::string video_input_filename_;
171   std::string video_output_filename_;
172   std::vector<AudioCodec> voice_codecs_;
173   std::vector<VideoCodec> video_codecs_;
174   std::vector<RtpHeaderExtension> audio_rtp_header_extensions_;
175   std::vector<RtpHeaderExtension> video_rtp_header_extensions_;
176   sigslot::repeater2<VideoCapturer*, CaptureState>
177      signal_state_change_;
178   rtc::Thread* rtp_sender_thread_;
179
180   DISALLOW_COPY_AND_ASSIGN(FileMediaEngine);
181 };
182
183 class RtpSenderReceiver;  // Forward declaration. Defined in the .cc file.
184
185 class FileVoiceChannel : public VoiceMediaChannel {
186  public:
187   FileVoiceChannel(rtc::StreamInterface* input_file_stream,
188       rtc::StreamInterface* output_file_stream,
189       rtc::Thread* rtp_sender_thread);
190   virtual ~FileVoiceChannel();
191
192   // Implement pure virtual methods of VoiceMediaChannel.
193   virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) {
194     return true;
195   }
196   virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs);
197   virtual bool SetRecvRtpHeaderExtensions(
198       const std::vector<RtpHeaderExtension>& extensions) {
199     return true;
200   }
201   virtual bool SetSendRtpHeaderExtensions(
202       const std::vector<RtpHeaderExtension>& extensions) {
203     return true;
204   }
205   virtual bool SetPlayout(bool playout) { return true; }
206   virtual bool SetSend(SendFlags flag);
207   virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) {
208     return false;
209   }
210   virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) {
211     return false;
212   }
213   virtual bool GetActiveStreams(AudioInfo::StreamList* actives) { return true; }
214   virtual int GetOutputLevel() { return 0; }
215   virtual int GetTimeSinceLastTyping() { return -1; }
216   virtual void SetTypingDetectionParameters(int time_window,
217     int cost_per_typing, int reporting_threshold, int penalty_decay,
218     int type_event_delay) {}
219
220   virtual bool SetOutputScaling(uint32 ssrc, double left, double right) {
221     return false;
222   }
223   virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) {
224     return false;
225   }
226   virtual bool SetRingbackTone(const char* buf, int len) { return true; }
227   virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) {
228     return true;
229   }
230   virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) {
231     return false;
232   }
233   virtual bool GetStats(VoiceMediaInfo* info) { return true; }
234
235   // Implement pure virtual methods of MediaChannel.
236   virtual void OnPacketReceived(rtc::Buffer* packet,
237                                 const rtc::PacketTime& packet_time);
238   virtual void OnRtcpReceived(rtc::Buffer* packet,
239                               const rtc::PacketTime& packet_time) {}
240   virtual void OnReadyToSend(bool ready) {}
241   virtual bool AddSendStream(const StreamParams& sp);
242   virtual bool RemoveSendStream(uint32 ssrc);
243   virtual bool AddRecvStream(const StreamParams& sp) { return true; }
244   virtual bool RemoveRecvStream(uint32 ssrc) { return true; }
245   virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
246   virtual bool SetStartSendBandwidth(int bps) { return true; }
247   virtual bool SetMaxSendBandwidth(int bps) { return true; }
248   virtual bool SetOptions(const AudioOptions& options) {
249     options_ = options;
250     return true;
251   }
252   virtual bool GetOptions(AudioOptions* options) const {
253     *options = options_;
254     return true;
255   }
256
257  private:
258   uint32 send_ssrc_;
259   rtc::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_;
260   AudioOptions options_;
261
262   DISALLOW_COPY_AND_ASSIGN(FileVoiceChannel);
263 };
264
265 class FileVideoChannel : public VideoMediaChannel {
266  public:
267   FileVideoChannel(rtc::StreamInterface* input_file_stream,
268       rtc::StreamInterface* output_file_stream,
269       rtc::Thread* rtp_sender_thread);
270   virtual ~FileVideoChannel();
271
272   // Implement pure virtual methods of VideoMediaChannel.
273   virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) {
274     return true;
275   }
276   virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs);
277   virtual bool GetSendCodec(VideoCodec* send_codec) {
278     *send_codec = VideoCodec();
279     return true;
280   }
281   virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) {
282     return true;
283   }
284   virtual bool SetRecvRtpHeaderExtensions(
285       const std::vector<RtpHeaderExtension>& extensions) {
286     return true;
287   }
288   virtual bool SetSendRtpHeaderExtensions(
289       const std::vector<RtpHeaderExtension>& extensions) {
290     return true;
291   }
292   virtual bool SetRender(bool render) { return true; }
293   virtual bool SetSend(bool send);
294   virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) {
295     return true;
296   }
297   virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) {
298     return false;
299   }
300   virtual bool GetStats(const StatsOptions& options, VideoMediaInfo* info) {
301     return true;
302   }
303   virtual bool SendIntraFrame() { return false; }
304   virtual bool RequestIntraFrame() { return false; }
305
306   // Implement pure virtual methods of MediaChannel.
307   virtual void OnPacketReceived(rtc::Buffer* packet,
308                                 const rtc::PacketTime& packet_time);
309   virtual void OnRtcpReceived(rtc::Buffer* packet,
310                               const rtc::PacketTime& packet_time) {}
311   virtual void OnReadyToSend(bool ready) {}
312   virtual bool AddSendStream(const StreamParams& sp);
313   virtual bool RemoveSendStream(uint32 ssrc);
314   virtual bool AddRecvStream(const StreamParams& sp) { return true; }
315   virtual bool RemoveRecvStream(uint32 ssrc) { return true; }
316   virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
317   virtual bool SetStartSendBandwidth(int bps) { return true; }
318   virtual bool SetMaxSendBandwidth(int bps) { return true; }
319   virtual bool SetOptions(const VideoOptions& options) {
320     options_ = options;
321     return true;
322   }
323   virtual bool GetOptions(VideoOptions* options) const {
324     *options = options_;
325     return true;
326   }
327   virtual void UpdateAspectRatio(int ratio_w, int ratio_h) {}
328
329  private:
330   uint32 send_ssrc_;
331   rtc::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_;
332   VideoOptions options_;
333
334   DISALLOW_COPY_AND_ASSIGN(FileVideoChannel);
335 };
336
337 }  // namespace cricket
338
339 #endif  // TALK_MEDIA_BASE_FILEMEDIAENGINE_H_