1 // libjingle 2 // Copyright 2004--2005, 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_SESSION_PHONE_FILEMEDIAENGINE_H_ 27 #define TALK_SESSION_PHONE_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/session/phone/codec.h" 35 #include "talk/session/phone/mediachannel.h" 36 #include "talk/session/phone/mediaengine.h" 37 38 namespace talk_base { 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: Enable RTCP packets. 51 class FileMediaEngine : public MediaEngineInterface { 52 public: FileMediaEngine()53 FileMediaEngine() {} ~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. set_voice_input_filename(const std::string & filename)58 void set_voice_input_filename(const std::string& filename) { 59 voice_input_filename_ = filename; 60 } set_voice_output_filename(const std::string & filename)61 void set_voice_output_filename(const std::string& filename) { 62 voice_output_filename_ = filename; 63 } set_video_input_filename(const std::string & filename)64 void set_video_input_filename(const std::string& filename) { 65 video_input_filename_ = filename; 66 } set_video_output_filename(const std::string & filename)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. set_voice_codecs(const std::vector<AudioCodec> & codecs)73 void set_voice_codecs(const std::vector<AudioCodec>& codecs) { 74 voice_codecs_ = codecs; 75 } set_video_codecs(const std::vector<VideoCodec> & codecs)76 void set_video_codecs(const std::vector<VideoCodec>& codecs) { 77 video_codecs_ = codecs; 78 } 79 80 // Implement pure virtual methods of MediaEngine. Init()81 virtual bool Init() { return true; } Terminate()82 virtual void Terminate() {} 83 virtual int GetCapabilities(); 84 virtual VoiceMediaChannel* CreateChannel(); 85 virtual VideoMediaChannel* CreateVideoChannel(VoiceMediaChannel* voice_ch); CreateSoundclip()86 virtual SoundclipMedia* CreateSoundclip() { return NULL; } SetAudioOptions(int options)87 virtual bool SetAudioOptions(int options) { return true; } SetVideoOptions(int options)88 virtual bool SetVideoOptions(int options) { return true; } SetDefaultVideoEncoderConfig(const VideoEncoderConfig & config)89 virtual bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config) { 90 return true; 91 } SetSoundDevices(const Device * in_dev,const Device * out_dev)92 virtual bool SetSoundDevices(const Device* in_dev, const Device* out_dev) { 93 return true; 94 } SetVideoCaptureDevice(const Device * cam_device)95 virtual bool SetVideoCaptureDevice(const Device* cam_device) { return true; } SetVideoCapturer(VideoCapturer *,uint32)96 virtual bool SetVideoCapturer(VideoCapturer* /*capturer*/, uint32 /*ssrc*/) { 97 return true; 98 } GetOutputVolume(int * level)99 virtual bool GetOutputVolume(int* level) { 100 *level = 0; 101 return true; 102 } SetOutputVolume(int level)103 virtual bool SetOutputVolume(int level) { return true; } GetInputLevel()104 virtual int GetInputLevel() { return 0; } SetLocalMonitor(bool enable)105 virtual bool SetLocalMonitor(bool enable) { return true; } SetLocalRenderer(VideoRenderer * renderer)106 virtual bool SetLocalRenderer(VideoRenderer* renderer) { return true; } 107 // TODO: control channel send? SetVideoCapture(bool capture)108 virtual CaptureResult SetVideoCapture(bool capture) { return CR_SUCCESS; } audio_codecs()109 virtual const std::vector<AudioCodec>& audio_codecs() { 110 return voice_codecs_; 111 } video_codecs()112 virtual const std::vector<VideoCodec>& video_codecs() { 113 return video_codecs_; 114 } FindAudioCodec(const AudioCodec & codec)115 virtual bool FindAudioCodec(const AudioCodec& codec) { return true; } FindVideoCodec(const VideoCodec & codec)116 virtual bool FindVideoCodec(const VideoCodec& codec) { return true; } SetVoiceLogging(int min_sev,const char * filter)117 virtual void SetVoiceLogging(int min_sev, const char* filter) {} SetVideoLogging(int min_sev,const char * filter)118 virtual void SetVideoLogging(int min_sev, const char* filter) {} 119 RegisterVideoProcessor(VideoProcessor * processor)120 virtual bool RegisterVideoProcessor(VideoProcessor* processor) { 121 return true; 122 } UnregisterVideoProcessor(VideoProcessor * processor)123 virtual bool UnregisterVideoProcessor(VideoProcessor* processor) { 124 return true; 125 } RegisterVoiceProcessor(uint32 ssrc,VoiceProcessor * processor,MediaProcessorDirection direction)126 virtual bool RegisterVoiceProcessor(uint32 ssrc, 127 VoiceProcessor* processor, 128 MediaProcessorDirection direction) { 129 return true; 130 } UnregisterVoiceProcessor(uint32 ssrc,VoiceProcessor * processor,MediaProcessorDirection direction)131 virtual bool UnregisterVoiceProcessor(uint32 ssrc, 132 VoiceProcessor* processor, 133 MediaProcessorDirection direction) { 134 return true; 135 } 136 137 private: 138 std::string voice_input_filename_; 139 std::string voice_output_filename_; 140 std::string video_input_filename_; 141 std::string video_output_filename_; 142 std::vector<AudioCodec> voice_codecs_; 143 std::vector<VideoCodec> video_codecs_; 144 145 DISALLOW_COPY_AND_ASSIGN(FileMediaEngine); 146 }; 147 148 class RtpSenderReceiver; // Forward declaration. Defined in the .cc file. 149 150 class FileVoiceChannel : public VoiceMediaChannel { 151 public: 152 FileVoiceChannel(talk_base::StreamInterface* input_file_stream, 153 talk_base::StreamInterface* output_file_stream); 154 virtual ~FileVoiceChannel(); 155 156 // Implement pure virtual methods of VoiceMediaChannel. SetRecvCodecs(const std::vector<AudioCodec> & codecs)157 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) { 158 return true; 159 } 160 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs); SetRecvRtpHeaderExtensions(const std::vector<RtpHeaderExtension> & extensions)161 virtual bool SetRecvRtpHeaderExtensions( 162 const std::vector<RtpHeaderExtension>& extensions) { 163 return true; 164 } SetSendRtpHeaderExtensions(const std::vector<RtpHeaderExtension> & extensions)165 virtual bool SetSendRtpHeaderExtensions( 166 const std::vector<RtpHeaderExtension>& extensions) { 167 return true; 168 } SetPlayout(bool playout)169 virtual bool SetPlayout(bool playout) { return true; } 170 virtual bool SetSend(SendFlags flag); GetActiveStreams(AudioInfo::StreamList * actives)171 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) { return true; } GetOutputLevel()172 virtual int GetOutputLevel() { return 0; } SetOutputScaling(uint32 ssrc,double left,double right)173 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) { 174 return false; 175 } GetOutputScaling(uint32 ssrc,double * left,double * right)176 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) { 177 return false; 178 } SetRingbackTone(const char * buf,int len)179 virtual bool SetRingbackTone(const char* buf, int len) { return true; } PlayRingbackTone(uint32 ssrc,bool play,bool loop)180 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) { 181 return true; 182 } PressDTMF(int event,bool playout)183 virtual bool PressDTMF(int event, bool playout) { return true; } GetStats(VoiceMediaInfo * info)184 virtual bool GetStats(VoiceMediaInfo* info) { return true; } 185 186 // Implement pure virtual methods of MediaChannel. 187 virtual void OnPacketReceived(talk_base::Buffer* packet); OnRtcpReceived(talk_base::Buffer * packet)188 virtual void OnRtcpReceived(talk_base::Buffer* packet) {} 189 virtual bool AddSendStream(const StreamParams& sp); 190 virtual bool RemoveSendStream(uint32 ssrc); AddRecvStream(const StreamParams & sp)191 virtual bool AddRecvStream(const StreamParams& sp) { return true; } RemoveRecvStream(uint32 ssrc)192 virtual bool RemoveRecvStream(uint32 ssrc) { return true; } Mute(bool on)193 virtual bool Mute(bool on) { return false; } SetSendBandwidth(bool autobw,int bps)194 virtual bool SetSendBandwidth(bool autobw, int bps) { return true; } SetOptions(int options)195 virtual bool SetOptions(int options) { 196 options_ = options; 197 return true; 198 } GetOptions()199 virtual int GetOptions() const { return options_; } 200 201 private: 202 uint32 send_ssrc_; 203 talk_base::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_; 204 int options_; 205 206 DISALLOW_COPY_AND_ASSIGN(FileVoiceChannel); 207 }; 208 209 class FileVideoChannel : public VideoMediaChannel { 210 public: 211 FileVideoChannel(talk_base::StreamInterface* input_file_stream, 212 talk_base::StreamInterface* output_file_stream); 213 virtual ~FileVideoChannel(); 214 215 // Implement pure virtual methods of VideoMediaChannel. SetRecvCodecs(const std::vector<VideoCodec> & codecs)216 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) { 217 return true; 218 } 219 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs); SetSendStreamFormat(uint32 ssrc,const VideoFormat & format)220 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) { 221 return true; 222 } SetRecvRtpHeaderExtensions(const std::vector<RtpHeaderExtension> & extensions)223 virtual bool SetRecvRtpHeaderExtensions( 224 const std::vector<RtpHeaderExtension>& extensions) { 225 return true; 226 } SetSendRtpHeaderExtensions(const std::vector<RtpHeaderExtension> & extensions)227 virtual bool SetSendRtpHeaderExtensions( 228 const std::vector<RtpHeaderExtension>& extensions) { 229 return true; 230 } SetRender(bool render)231 virtual bool SetRender(bool render) { return true; } 232 virtual bool SetSend(bool send); SetRenderer(uint32 ssrc,VideoRenderer * renderer)233 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) { 234 return true; 235 } AddScreencast(uint32 ssrc,const ScreencastId & id,int fps)236 virtual bool AddScreencast(uint32 ssrc, const ScreencastId& id, int fps) { 237 return true; 238 } RemoveScreencast(uint32 ssrc)239 virtual bool RemoveScreencast(uint32 ssrc) { return true; } GetStats(VideoMediaInfo * info)240 virtual bool GetStats(VideoMediaInfo* info) { return true; } SendIntraFrame()241 virtual bool SendIntraFrame() { return false; } RequestIntraFrame()242 virtual bool RequestIntraFrame() { return false; } 243 244 // Implement pure virtual methods of MediaChannel. 245 virtual void OnPacketReceived(talk_base::Buffer* packet); OnRtcpReceived(talk_base::Buffer * packet)246 virtual void OnRtcpReceived(talk_base::Buffer* packet) {} 247 virtual bool AddSendStream(const StreamParams& sp); 248 virtual bool RemoveSendStream(uint32 ssrc); AddRecvStream(const StreamParams & sp)249 virtual bool AddRecvStream(const StreamParams& sp) { return true; } RemoveRecvStream(uint32 ssrc)250 virtual bool RemoveRecvStream(uint32 ssrc) { return true; } Mute(bool on)251 virtual bool Mute(bool on) { return false; } SetSendBandwidth(bool autobw,int bps)252 virtual bool SetSendBandwidth(bool autobw, int bps) { return true; } SetOptions(int options)253 virtual bool SetOptions(int options) { 254 options_ = options; 255 return true; 256 } GetOptions()257 virtual int GetOptions() const { return options_; } 258 259 private: 260 uint32 send_ssrc_; 261 talk_base::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_; 262 int options_; 263 264 DISALLOW_COPY_AND_ASSIGN(FileVideoChannel); 265 }; 266 267 } // namespace cricket 268 269 #endif // TALK_SESSION_PHONE_FILEMEDIAENGINE_H_ 270