2 // Copyright 2004 Google Inc.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
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.
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.
26 #ifndef TALK_MEDIA_BASE_FILEMEDIAENGINE_H_
27 #define TALK_MEDIA_BASE_FILEMEDIAENGINE_H_
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"
39 class StreamInterface;
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 {
53 FileMediaEngine() : rtp_sender_thread_(NULL) {}
54 virtual ~FileMediaEngine() {}
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;
61 void set_voice_output_filename(const std::string& filename) {
62 voice_output_filename_ = filename;
64 void set_video_input_filename(const std::string& filename) {
65 video_input_filename_ = filename;
67 void set_video_output_filename(const std::string& filename) {
68 video_output_filename_ = filename;
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;
76 void set_video_codecs(const std::vector<VideoCodec>& codecs) {
77 video_codecs_ = codecs;
80 // Implement pure virtual methods of MediaEngine.
81 virtual bool Init(rtc::Thread* worker_thread) {
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) {
96 virtual VideoEncoderConfig GetDefaultVideoEncoderConfig() const {
97 return VideoEncoderConfig();
99 virtual bool SetSoundDevices(const Device* in_dev, const Device* out_dev) {
102 virtual bool SetVideoCaptureDevice(const Device* cam_device) { return true; }
103 virtual bool SetVideoCapturer(VideoCapturer* /*capturer*/) {
106 virtual VideoCapturer* GetVideoCapturer() const {
109 virtual bool GetOutputVolume(int* level) {
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_;
122 virtual const std::vector<VideoCodec>& video_codecs() {
123 return video_codecs_;
125 virtual const std::vector<RtpHeaderExtension>& audio_rtp_header_extensions() {
126 return audio_rtp_header_extensions_;
128 virtual const std::vector<RtpHeaderExtension>& video_rtp_header_extensions() {
129 return video_rtp_header_extensions_;
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; }
138 virtual bool RegisterVideoProcessor(VideoProcessor* processor) {
141 virtual bool UnregisterVideoProcessor(VideoProcessor* processor) {
144 virtual bool RegisterVoiceProcessor(uint32 ssrc,
145 VoiceProcessor* processor,
146 MediaProcessorDirection direction) {
149 virtual bool UnregisterVoiceProcessor(uint32 ssrc,
150 VoiceProcessor* processor,
151 MediaProcessorDirection direction) {
154 VideoFormat GetStartCaptureFormat() const {
155 return VideoFormat();
158 virtual sigslot::repeater2<VideoCapturer*, CaptureState>&
159 SignalVideoCaptureStateChange() {
160 return signal_state_change_;
163 void set_rtp_sender_thread(rtc::Thread* thread) {
164 rtp_sender_thread_ = thread;
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_;
180 DISALLOW_COPY_AND_ASSIGN(FileMediaEngine);
183 class RtpSenderReceiver; // Forward declaration. Defined in the .cc file.
185 class FileVoiceChannel : public VoiceMediaChannel {
187 FileVoiceChannel(rtc::StreamInterface* input_file_stream,
188 rtc::StreamInterface* output_file_stream,
189 rtc::Thread* rtp_sender_thread);
190 virtual ~FileVoiceChannel();
192 // Implement pure virtual methods of VoiceMediaChannel.
193 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) {
196 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs);
197 virtual bool SetRecvRtpHeaderExtensions(
198 const std::vector<RtpHeaderExtension>& extensions) {
201 virtual bool SetSendRtpHeaderExtensions(
202 const std::vector<RtpHeaderExtension>& extensions) {
205 virtual bool SetPlayout(bool playout) { return true; }
206 virtual bool SetSend(SendFlags flag);
207 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) {
210 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) {
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) {}
220 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) {
223 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) {
226 virtual bool SetRingbackTone(const char* buf, int len) { return true; }
227 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) {
230 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) {
233 virtual bool GetStats(VoiceMediaInfo* info) { return true; }
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) {
252 virtual bool GetOptions(AudioOptions* options) const {
259 rtc::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_;
260 AudioOptions options_;
262 DISALLOW_COPY_AND_ASSIGN(FileVoiceChannel);
265 class FileVideoChannel : public VideoMediaChannel {
267 FileVideoChannel(rtc::StreamInterface* input_file_stream,
268 rtc::StreamInterface* output_file_stream,
269 rtc::Thread* rtp_sender_thread);
270 virtual ~FileVideoChannel();
272 // Implement pure virtual methods of VideoMediaChannel.
273 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) {
276 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs);
277 virtual bool GetSendCodec(VideoCodec* send_codec) {
278 *send_codec = VideoCodec();
281 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) {
284 virtual bool SetRecvRtpHeaderExtensions(
285 const std::vector<RtpHeaderExtension>& extensions) {
288 virtual bool SetSendRtpHeaderExtensions(
289 const std::vector<RtpHeaderExtension>& extensions) {
292 virtual bool SetRender(bool render) { return true; }
293 virtual bool SetSend(bool send);
294 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) {
297 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) {
300 virtual bool GetStats(const StatsOptions& options, VideoMediaInfo* info) {
303 virtual bool SendIntraFrame() { return false; }
304 virtual bool RequestIntraFrame() { return false; }
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) {
323 virtual bool GetOptions(VideoOptions* options) const {
327 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) {}
331 rtc::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_;
332 VideoOptions options_;
334 DISALLOW_COPY_AND_ASSIGN(FileVideoChannel);
337 } // namespace cricket
339 #endif // TALK_MEDIA_BASE_FILEMEDIAENGINE_H_