blob: 9cdfe8306806c94bdf84337d09048a96ede0bf1f [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001// 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/base/scoped_ptr.h"
33#include "talk/base/stream.h"
34#include "talk/media/base/codec.h"
35#include "talk/media/base/mediachannel.h"
36#include "talk/media/base/mediaengine.h"
37
38namespace talk_base {
39class StreamInterface;
40}
41
42namespace 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.
51class FileMediaEngine : public MediaEngineInterface {
52 public:
53 FileMediaEngine() {}
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(talk_base::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; }
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +000089 virtual AudioOptions GetAudioOptions() const { return AudioOptions(); }
90 virtual bool SetAudioOptions(const AudioOptions& options) { return true; }
91 virtual bool SetVideoOptions(const VideoOptions& options) { return true; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092 virtual bool SetAudioDelayOffset(int offset) { return true; }
93 virtual bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config) {
94 return true;
95 }
wu@webrtc.org78187522013-10-07 23:32:02 +000096 virtual VideoEncoderConfig GetDefaultVideoEncoderConfig() const {
97 return VideoEncoderConfig();
98 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099 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
137 virtual bool RegisterVideoProcessor(VideoProcessor* processor) {
138 return true;
139 }
140 virtual bool UnregisterVideoProcessor(VideoProcessor* processor) {
141 return true;
142 }
143 virtual bool RegisterVoiceProcessor(uint32 ssrc,
144 VoiceProcessor* processor,
145 MediaProcessorDirection direction) {
146 return true;
147 }
148 virtual bool UnregisterVoiceProcessor(uint32 ssrc,
149 VoiceProcessor* processor,
150 MediaProcessorDirection direction) {
151 return true;
152 }
153 VideoFormat GetStartCaptureFormat() const {
154 return VideoFormat();
155 }
156
157 virtual sigslot::repeater2<VideoCapturer*, CaptureState>&
158 SignalVideoCaptureStateChange() {
159 return signal_state_change_;
160 }
161
162 private:
163 std::string voice_input_filename_;
164 std::string voice_output_filename_;
165 std::string video_input_filename_;
166 std::string video_output_filename_;
167 std::vector<AudioCodec> voice_codecs_;
168 std::vector<VideoCodec> video_codecs_;
169 std::vector<RtpHeaderExtension> audio_rtp_header_extensions_;
170 std::vector<RtpHeaderExtension> video_rtp_header_extensions_;
171 sigslot::repeater2<VideoCapturer*, CaptureState>
172 signal_state_change_;
173
174 DISALLOW_COPY_AND_ASSIGN(FileMediaEngine);
175};
176
177class RtpSenderReceiver; // Forward declaration. Defined in the .cc file.
178
179class FileVoiceChannel : public VoiceMediaChannel {
180 public:
181 FileVoiceChannel(talk_base::StreamInterface* input_file_stream,
182 talk_base::StreamInterface* output_file_stream);
183 virtual ~FileVoiceChannel();
184
185 // Implement pure virtual methods of VoiceMediaChannel.
186 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) {
187 return true;
188 }
189 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs);
190 virtual bool SetRecvRtpHeaderExtensions(
191 const std::vector<RtpHeaderExtension>& extensions) {
192 return true;
193 }
194 virtual bool SetSendRtpHeaderExtensions(
195 const std::vector<RtpHeaderExtension>& extensions) {
196 return true;
197 }
198 virtual bool SetPlayout(bool playout) { return true; }
199 virtual bool SetSend(SendFlags flag);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000200 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) {
201 return false;
202 }
203 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204 return false;
205 }
206 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) { return true; }
207 virtual int GetOutputLevel() { return 0; }
208 virtual int GetTimeSinceLastTyping() { return -1; }
209 virtual void SetTypingDetectionParameters(int time_window,
210 int cost_per_typing, int reporting_threshold, int penalty_decay,
211 int type_event_delay) {}
212
213 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) {
214 return false;
215 }
216 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) {
217 return false;
218 }
219 virtual bool SetRingbackTone(const char* buf, int len) { return true; }
220 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) {
221 return true;
222 }
223 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) {
224 return false;
225 }
226 virtual bool GetStats(VoiceMediaInfo* info) { return true; }
227
228 // Implement pure virtual methods of MediaChannel.
229 virtual void OnPacketReceived(talk_base::Buffer* packet);
230 virtual void OnRtcpReceived(talk_base::Buffer* packet) {}
231 virtual void OnReadyToSend(bool ready) {}
232 virtual bool AddSendStream(const StreamParams& sp);
233 virtual bool RemoveSendStream(uint32 ssrc);
234 virtual bool AddRecvStream(const StreamParams& sp) { return true; }
235 virtual bool RemoveRecvStream(uint32 ssrc) { return true; }
236 virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
237 virtual bool SetSendBandwidth(bool autobw, int bps) { return true; }
238 virtual bool SetOptions(const AudioOptions& options) {
239 options_ = options;
240 return true;
241 }
242 virtual bool GetOptions(AudioOptions* options) const {
243 *options = options_;
244 return true;
245 }
246
247 private:
248 uint32 send_ssrc_;
249 talk_base::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_;
250 AudioOptions options_;
251
252 DISALLOW_COPY_AND_ASSIGN(FileVoiceChannel);
253};
254
255class FileVideoChannel : public VideoMediaChannel {
256 public:
257 FileVideoChannel(talk_base::StreamInterface* input_file_stream,
258 talk_base::StreamInterface* output_file_stream);
259 virtual ~FileVideoChannel();
260
261 // Implement pure virtual methods of VideoMediaChannel.
262 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) {
263 return true;
264 }
265 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs);
266 virtual bool GetSendCodec(VideoCodec* send_codec) {
267 *send_codec = VideoCodec();
268 return true;
269 }
270 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) {
271 return true;
272 }
273 virtual bool SetRecvRtpHeaderExtensions(
274 const std::vector<RtpHeaderExtension>& extensions) {
275 return true;
276 }
277 virtual bool SetSendRtpHeaderExtensions(
278 const std::vector<RtpHeaderExtension>& extensions) {
279 return true;
280 }
281 virtual bool SetRender(bool render) { return true; }
282 virtual bool SetSend(bool send);
283 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) {
284 return true;
285 }
286 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) {
287 return false;
288 }
289 virtual bool GetStats(VideoMediaInfo* info) { return true; }
290 virtual bool SendIntraFrame() { return false; }
291 virtual bool RequestIntraFrame() { return false; }
292
293 // Implement pure virtual methods of MediaChannel.
294 virtual void OnPacketReceived(talk_base::Buffer* packet);
295 virtual void OnRtcpReceived(talk_base::Buffer* packet) {}
296 virtual void OnReadyToSend(bool ready) {}
297 virtual bool AddSendStream(const StreamParams& sp);
298 virtual bool RemoveSendStream(uint32 ssrc);
299 virtual bool AddRecvStream(const StreamParams& sp) { return true; }
300 virtual bool RemoveRecvStream(uint32 ssrc) { return true; }
301 virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
302 virtual bool SetSendBandwidth(bool autobw, int bps) { return true; }
303 virtual bool SetOptions(const VideoOptions& options) {
304 options_ = options;
305 return true;
306 }
307 virtual bool GetOptions(VideoOptions* options) const {
308 *options = options_;
309 return true;
310 }
311 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) {}
312
313 private:
314 uint32 send_ssrc_;
315 talk_base::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_;
316 VideoOptions options_;
317
318 DISALLOW_COPY_AND_ASSIGN(FileVideoChannel);
319};
320
321} // namespace cricket
322
323#endif // TALK_MEDIA_BASE_FILEMEDIAENGINE_H_