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