blob: b7a7ac17de783de5f3b51fc63eb07551a3e4ed1d [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 }
96 virtual bool SetSoundDevices(const Device* in_dev, const Device* out_dev) {
97 return true;
98 }
99 virtual bool SetVideoCaptureDevice(const Device* cam_device) { return true; }
100 virtual bool SetVideoCapturer(VideoCapturer* /*capturer*/) {
101 return true;
102 }
103 virtual VideoCapturer* GetVideoCapturer() const {
104 return NULL;
105 }
106 virtual bool GetOutputVolume(int* level) {
107 *level = 0;
108 return true;
109 }
110 virtual bool SetOutputVolume(int level) { return true; }
111 virtual int GetInputLevel() { return 0; }
112 virtual bool SetLocalMonitor(bool enable) { return true; }
113 virtual bool SetLocalRenderer(VideoRenderer* renderer) { return true; }
114 // TODO(whyuan): control channel send?
115 virtual bool SetVideoCapture(bool capture) { return true; }
116 virtual const std::vector<AudioCodec>& audio_codecs() {
117 return voice_codecs_;
118 }
119 virtual const std::vector<VideoCodec>& video_codecs() {
120 return video_codecs_;
121 }
122 virtual const std::vector<RtpHeaderExtension>& audio_rtp_header_extensions() {
123 return audio_rtp_header_extensions_;
124 }
125 virtual const std::vector<RtpHeaderExtension>& video_rtp_header_extensions() {
126 return video_rtp_header_extensions_;
127 }
128
129 virtual bool FindAudioCodec(const AudioCodec& codec) { return true; }
130 virtual bool FindVideoCodec(const VideoCodec& codec) { return true; }
131 virtual void SetVoiceLogging(int min_sev, const char* filter) {}
132 virtual void SetVideoLogging(int min_sev, const char* filter) {}
133
134 virtual bool RegisterVideoProcessor(VideoProcessor* processor) {
135 return true;
136 }
137 virtual bool UnregisterVideoProcessor(VideoProcessor* processor) {
138 return true;
139 }
140 virtual bool RegisterVoiceProcessor(uint32 ssrc,
141 VoiceProcessor* processor,
142 MediaProcessorDirection direction) {
143 return true;
144 }
145 virtual bool UnregisterVoiceProcessor(uint32 ssrc,
146 VoiceProcessor* processor,
147 MediaProcessorDirection direction) {
148 return true;
149 }
150 VideoFormat GetStartCaptureFormat() const {
151 return VideoFormat();
152 }
153
154 virtual sigslot::repeater2<VideoCapturer*, CaptureState>&
155 SignalVideoCaptureStateChange() {
156 return signal_state_change_;
157 }
158
159 private:
160 std::string voice_input_filename_;
161 std::string voice_output_filename_;
162 std::string video_input_filename_;
163 std::string video_output_filename_;
164 std::vector<AudioCodec> voice_codecs_;
165 std::vector<VideoCodec> video_codecs_;
166 std::vector<RtpHeaderExtension> audio_rtp_header_extensions_;
167 std::vector<RtpHeaderExtension> video_rtp_header_extensions_;
168 sigslot::repeater2<VideoCapturer*, CaptureState>
169 signal_state_change_;
170
171 DISALLOW_COPY_AND_ASSIGN(FileMediaEngine);
172};
173
174class RtpSenderReceiver; // Forward declaration. Defined in the .cc file.
175
176class FileVoiceChannel : public VoiceMediaChannel {
177 public:
178 FileVoiceChannel(talk_base::StreamInterface* input_file_stream,
179 talk_base::StreamInterface* output_file_stream);
180 virtual ~FileVoiceChannel();
181
182 // Implement pure virtual methods of VoiceMediaChannel.
183 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) {
184 return true;
185 }
186 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs);
187 virtual bool SetRecvRtpHeaderExtensions(
188 const std::vector<RtpHeaderExtension>& extensions) {
189 return true;
190 }
191 virtual bool SetSendRtpHeaderExtensions(
192 const std::vector<RtpHeaderExtension>& extensions) {
193 return true;
194 }
195 virtual bool SetPlayout(bool playout) { return true; }
196 virtual bool SetSend(SendFlags flag);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000197 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) {
198 return false;
199 }
200 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000201 return false;
202 }
203 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) { return true; }
204 virtual int GetOutputLevel() { return 0; }
205 virtual int GetTimeSinceLastTyping() { return -1; }
206 virtual void SetTypingDetectionParameters(int time_window,
207 int cost_per_typing, int reporting_threshold, int penalty_decay,
208 int type_event_delay) {}
209
210 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) {
211 return false;
212 }
213 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) {
214 return false;
215 }
216 virtual bool SetRingbackTone(const char* buf, int len) { return true; }
217 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) {
218 return true;
219 }
220 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) {
221 return false;
222 }
223 virtual bool GetStats(VoiceMediaInfo* info) { return true; }
224
225 // Implement pure virtual methods of MediaChannel.
226 virtual void OnPacketReceived(talk_base::Buffer* packet);
227 virtual void OnRtcpReceived(talk_base::Buffer* packet) {}
228 virtual void OnReadyToSend(bool ready) {}
229 virtual bool AddSendStream(const StreamParams& sp);
230 virtual bool RemoveSendStream(uint32 ssrc);
231 virtual bool AddRecvStream(const StreamParams& sp) { return true; }
232 virtual bool RemoveRecvStream(uint32 ssrc) { return true; }
233 virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
234 virtual bool SetSendBandwidth(bool autobw, int bps) { return true; }
235 virtual bool SetOptions(const AudioOptions& options) {
236 options_ = options;
237 return true;
238 }
239 virtual bool GetOptions(AudioOptions* options) const {
240 *options = options_;
241 return true;
242 }
243
244 private:
245 uint32 send_ssrc_;
246 talk_base::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_;
247 AudioOptions options_;
248
249 DISALLOW_COPY_AND_ASSIGN(FileVoiceChannel);
250};
251
252class FileVideoChannel : public VideoMediaChannel {
253 public:
254 FileVideoChannel(talk_base::StreamInterface* input_file_stream,
255 talk_base::StreamInterface* output_file_stream);
256 virtual ~FileVideoChannel();
257
258 // Implement pure virtual methods of VideoMediaChannel.
259 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) {
260 return true;
261 }
262 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs);
263 virtual bool GetSendCodec(VideoCodec* send_codec) {
264 *send_codec = VideoCodec();
265 return true;
266 }
267 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) {
268 return true;
269 }
270 virtual bool SetRecvRtpHeaderExtensions(
271 const std::vector<RtpHeaderExtension>& extensions) {
272 return true;
273 }
274 virtual bool SetSendRtpHeaderExtensions(
275 const std::vector<RtpHeaderExtension>& extensions) {
276 return true;
277 }
278 virtual bool SetRender(bool render) { return true; }
279 virtual bool SetSend(bool send);
280 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) {
281 return true;
282 }
283 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) {
284 return false;
285 }
286 virtual bool GetStats(VideoMediaInfo* info) { return true; }
287 virtual bool SendIntraFrame() { return false; }
288 virtual bool RequestIntraFrame() { return false; }
289
290 // Implement pure virtual methods of MediaChannel.
291 virtual void OnPacketReceived(talk_base::Buffer* packet);
292 virtual void OnRtcpReceived(talk_base::Buffer* packet) {}
293 virtual void OnReadyToSend(bool ready) {}
294 virtual bool AddSendStream(const StreamParams& sp);
295 virtual bool RemoveSendStream(uint32 ssrc);
296 virtual bool AddRecvStream(const StreamParams& sp) { return true; }
297 virtual bool RemoveRecvStream(uint32 ssrc) { return true; }
298 virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
299 virtual bool SetSendBandwidth(bool autobw, int bps) { return true; }
300 virtual bool SetOptions(const VideoOptions& options) {
301 options_ = options;
302 return true;
303 }
304 virtual bool GetOptions(VideoOptions* options) const {
305 *options = options_;
306 return true;
307 }
308 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) {}
309
310 private:
311 uint32 send_ssrc_;
312 talk_base::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_;
313 VideoOptions options_;
314
315 DISALLOW_COPY_AND_ASSIGN(FileVideoChannel);
316};
317
318} // namespace cricket
319
320#endif // TALK_MEDIA_BASE_FILEMEDIAENGINE_H_