| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * libjingle | |
| 3 * Copyright 2004 Google Inc. | |
| 4 * | |
| 5 * Redistribution and use in source and binary forms, with or without | |
| 6 * modification, are permitted provided that the following conditions are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | |
| 9 * this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
| 11 * this list of conditions and the following disclaimer in the documentation | |
| 12 * and/or other materials provided with the distribution. | |
| 13 * 3. The name of the author may not be used to endorse or promote products | |
| 14 * derived from this software without specific prior written permission. | |
| 15 * | |
| 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
| 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
| 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
| 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
| 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
| 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
| 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
| 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 26 */ | |
| 27 | |
| 28 #ifndef TALK_MEDIA_BASE_FILEMEDIAENGINE_H_ | |
| 29 #define TALK_MEDIA_BASE_FILEMEDIAENGINE_H_ | |
| 30 | |
| 31 #include <string> | |
| 32 #include <vector> | |
| 33 | |
| 34 #include "talk/media/base/codec.h" | |
| 35 #include "talk/media/base/mediachannel.h" | |
| 36 #include "talk/media/base/mediaengine.h" | |
| 37 #include "webrtc/base/scoped_ptr.h" | |
| 38 #include "webrtc/base/stream.h" | |
| 39 | |
| 40 namespace rtc { | |
| 41 class StreamInterface; | |
| 42 } | |
| 43 | |
| 44 namespace cricket { | |
| 45 | |
| 46 // A media engine contains a capturer, an encoder, and a sender in the sender | |
| 47 // side and a receiver, a decoder, and a renderer in the receiver side. | |
| 48 // FileMediaEngine simulates the capturer and the encoder via an input RTP dump | |
| 49 // stream and simulates the decoder and the renderer via an output RTP dump | |
| 50 // stream. Depending on the parameters of the constructor, FileMediaEngine can | |
| 51 // act as file voice engine, file video engine, or both. Currently, we use | |
| 52 // only the RTP dump packets. TODO(whyuan): Enable RTCP packets. | |
| 53 class FileMediaEngine : public MediaEngineInterface { | |
| 54 public: | |
| 55 FileMediaEngine() : rtp_sender_thread_(NULL) {} | |
| 56 virtual ~FileMediaEngine() {} | |
| 57 | |
| 58 // Set the file name of the input or output RTP dump for voice or video. | |
| 59 // Should be called before the channel is created. | |
| 60 void set_voice_input_filename(const std::string& filename) { | |
| 61 voice_input_filename_ = filename; | |
| 62 } | |
| 63 void set_voice_output_filename(const std::string& filename) { | |
| 64 voice_output_filename_ = filename; | |
| 65 } | |
| 66 void set_video_input_filename(const std::string& filename) { | |
| 67 video_input_filename_ = filename; | |
| 68 } | |
| 69 void set_video_output_filename(const std::string& filename) { | |
| 70 video_output_filename_ = filename; | |
| 71 } | |
| 72 | |
| 73 // Should be called before codecs() and video_codecs() are called. We need to | |
| 74 // set the voice and video codecs; otherwise, Jingle initiation will fail. | |
| 75 void set_voice_codecs(const std::vector<AudioCodec>& codecs) { | |
| 76 voice_codecs_ = codecs; | |
| 77 } | |
| 78 void set_video_codecs(const std::vector<VideoCodec>& codecs) { | |
| 79 video_codecs_ = codecs; | |
| 80 } | |
| 81 | |
| 82 // Implement pure virtual methods of MediaEngine. | |
| 83 virtual bool Init(rtc::Thread* worker_thread) { | |
| 84 return true; | |
| 85 } | |
| 86 virtual void Terminate() {} | |
| 87 virtual int GetCapabilities(); | |
| 88 virtual VoiceMediaChannel* CreateChannel(const AudioOptions& options); | |
| 89 virtual VideoMediaChannel* CreateVideoChannel(const VideoOptions& options, | |
| 90 VoiceMediaChannel* voice_ch); | |
| 91 virtual AudioOptions GetAudioOptions() const { return AudioOptions(); } | |
| 92 virtual bool SetAudioOptions(const AudioOptions& options) { return true; } | |
| 93 virtual bool SetAudioDelayOffset(int offset) { return true; } | |
| 94 virtual bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config) { | |
| 95 return true; | |
| 96 } | |
| 97 virtual bool SetSoundDevices(const Device* in_dev, const Device* out_dev) { | |
| 98 return true; | |
| 99 } | |
| 100 virtual bool SetVideoCaptureDevice(const Device* cam_device) { return true; } | |
| 101 virtual bool SetVideoCapturer(VideoCapturer* /*capturer*/) { | |
| 102 return true; | |
| 103 } | |
| 104 virtual VideoCapturer* GetVideoCapturer() const { | |
| 105 return NULL; | |
| 106 } | |
| 107 virtual bool GetOutputVolume(int* level) { | |
| 108 *level = 0; | |
| 109 return true; | |
| 110 } | |
| 111 virtual bool SetOutputVolume(int level) { return true; } | |
| 112 virtual int GetInputLevel() { return 0; } | |
| 113 virtual bool SetLocalMonitor(bool enable) { 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 virtual bool StartAecDump(rtc::PlatformFile) { return false; } | |
| 134 | |
| 135 virtual bool RegisterVideoProcessor(VideoProcessor* processor) { | |
| 136 return true; | |
| 137 } | |
| 138 virtual bool UnregisterVideoProcessor(VideoProcessor* processor) { | |
| 139 return true; | |
| 140 } | |
| 141 virtual bool RegisterVoiceProcessor(uint32 ssrc, | |
| 142 VoiceProcessor* processor, | |
| 143 MediaProcessorDirection direction) { | |
| 144 return true; | |
| 145 } | |
| 146 virtual bool UnregisterVoiceProcessor(uint32 ssrc, | |
| 147 VoiceProcessor* processor, | |
| 148 MediaProcessorDirection direction) { | |
| 149 return true; | |
| 150 } | |
| 151 | |
| 152 virtual sigslot::repeater2<VideoCapturer*, CaptureState>& | |
| 153 SignalVideoCaptureStateChange() { | |
| 154 return signal_state_change_; | |
| 155 } | |
| 156 | |
| 157 void set_rtp_sender_thread(rtc::Thread* thread) { | |
| 158 rtp_sender_thread_ = thread; | |
| 159 } | |
| 160 | |
| 161 private: | |
| 162 std::string voice_input_filename_; | |
| 163 std::string voice_output_filename_; | |
| 164 std::string video_input_filename_; | |
| 165 std::string video_output_filename_; | |
| 166 std::vector<AudioCodec> voice_codecs_; | |
| 167 std::vector<VideoCodec> video_codecs_; | |
| 168 std::vector<RtpHeaderExtension> audio_rtp_header_extensions_; | |
| 169 std::vector<RtpHeaderExtension> video_rtp_header_extensions_; | |
| 170 sigslot::repeater2<VideoCapturer*, CaptureState> | |
| 171 signal_state_change_; | |
| 172 rtc::Thread* rtp_sender_thread_; | |
| 173 | |
| 174 DISALLOW_COPY_AND_ASSIGN(FileMediaEngine); | |
| 175 }; | |
| 176 | |
| 177 class RtpSenderReceiver; // Forward declaration. Defined in the .cc file. | |
| 178 | |
| 179 class FileVoiceChannel : public VoiceMediaChannel { | |
| 180 public: | |
| 181 FileVoiceChannel(rtc::StreamInterface* input_file_stream, | |
| 182 rtc::StreamInterface* output_file_stream, | |
| 183 rtc::Thread* rtp_sender_thread); | |
| 184 virtual ~FileVoiceChannel(); | |
| 185 | |
| 186 // Implement pure virtual methods of VoiceMediaChannel. | |
| 187 virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) { | |
| 188 return true; | |
| 189 } | |
| 190 virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs); | |
| 191 virtual bool SetRecvRtpHeaderExtensions( | |
| 192 const std::vector<RtpHeaderExtension>& extensions) { | |
| 193 return true; | |
| 194 } | |
| 195 virtual bool SetSendRtpHeaderExtensions( | |
| 196 const std::vector<RtpHeaderExtension>& extensions) { | |
| 197 return true; | |
| 198 } | |
| 199 virtual bool SetPlayout(bool playout) { return true; } | |
| 200 virtual bool SetSend(SendFlags flag); | |
| 201 virtual bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer) { | |
| 202 return false; | |
| 203 } | |
| 204 virtual bool SetLocalRenderer(uint32 ssrc, AudioRenderer* renderer) { | |
| 205 return false; | |
| 206 } | |
| 207 virtual bool GetActiveStreams(AudioInfo::StreamList* actives) { return true; } | |
| 208 virtual int GetOutputLevel() { return 0; } | |
| 209 virtual int GetTimeSinceLastTyping() { return -1; } | |
| 210 virtual void SetTypingDetectionParameters(int time_window, | |
| 211 int cost_per_typing, int reporting_threshold, int penalty_decay, | |
| 212 int type_event_delay) {} | |
| 213 | |
| 214 virtual bool SetOutputScaling(uint32 ssrc, double left, double right) { | |
| 215 return false; | |
| 216 } | |
| 217 virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) { | |
| 218 return false; | |
| 219 } | |
| 220 virtual bool SetRingbackTone(const char* buf, int len) { return true; } | |
| 221 virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) { | |
| 222 return true; | |
| 223 } | |
| 224 virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) { | |
| 225 return false; | |
| 226 } | |
| 227 virtual bool GetStats(VoiceMediaInfo* info) { return true; } | |
| 228 | |
| 229 // Implement pure virtual methods of MediaChannel. | |
| 230 virtual void OnPacketReceived(rtc::Buffer* packet, | |
| 231 const rtc::PacketTime& packet_time); | |
| 232 virtual void OnRtcpReceived(rtc::Buffer* packet, | |
| 233 const rtc::PacketTime& packet_time) {} | |
| 234 virtual void OnReadyToSend(bool ready) {} | |
| 235 virtual bool AddSendStream(const StreamParams& sp); | |
| 236 virtual bool RemoveSendStream(uint32 ssrc); | |
| 237 virtual bool AddRecvStream(const StreamParams& sp) { return true; } | |
| 238 virtual bool RemoveRecvStream(uint32 ssrc) { return true; } | |
| 239 virtual bool MuteStream(uint32 ssrc, bool on) { return false; } | |
| 240 virtual bool SetMaxSendBandwidth(int bps) { return true; } | |
| 241 virtual bool SetOptions(const AudioOptions& options) { | |
| 242 options_ = options; | |
| 243 return true; | |
| 244 } | |
| 245 virtual bool GetOptions(AudioOptions* options) const { | |
| 246 *options = options_; | |
| 247 return true; | |
| 248 } | |
| 249 | |
| 250 private: | |
| 251 uint32 send_ssrc_; | |
| 252 rtc::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_; | |
| 253 AudioOptions options_; | |
| 254 | |
| 255 DISALLOW_COPY_AND_ASSIGN(FileVoiceChannel); | |
| 256 }; | |
| 257 | |
| 258 class FileVideoChannel : public VideoMediaChannel { | |
| 259 public: | |
| 260 FileVideoChannel(rtc::StreamInterface* input_file_stream, | |
| 261 rtc::StreamInterface* output_file_stream, | |
| 262 rtc::Thread* rtp_sender_thread); | |
| 263 virtual ~FileVideoChannel(); | |
| 264 // Implement pure virtual methods of VideoMediaChannel. | |
| 265 void DetachVoiceChannel() override {} | |
| 266 virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) { | |
| 267 return true; | |
| 268 } | |
| 269 virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs); | |
| 270 virtual bool GetSendCodec(VideoCodec* send_codec) { | |
| 271 *send_codec = VideoCodec(); | |
| 272 return true; | |
| 273 } | |
| 274 virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) { | |
| 275 return true; | |
| 276 } | |
| 277 virtual bool SetRecvRtpHeaderExtensions( | |
| 278 const std::vector<RtpHeaderExtension>& extensions) { | |
| 279 return true; | |
| 280 } | |
| 281 virtual bool SetSendRtpHeaderExtensions( | |
| 282 const std::vector<RtpHeaderExtension>& extensions) { | |
| 283 return true; | |
| 284 } | |
| 285 virtual bool SetRender(bool render) { return true; } | |
| 286 virtual bool SetSend(bool send); | |
| 287 virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) { | |
| 288 return true; | |
| 289 } | |
| 290 virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) { | |
| 291 return false; | |
| 292 } | |
| 293 virtual bool GetStats(VideoMediaInfo* info) { return true; } | |
| 294 virtual bool SendIntraFrame() { return false; } | |
| 295 virtual bool RequestIntraFrame() { return false; } | |
| 296 | |
| 297 // Implement pure virtual methods of MediaChannel. | |
| 298 virtual void OnPacketReceived(rtc::Buffer* packet, | |
| 299 const rtc::PacketTime& packet_time); | |
| 300 virtual void OnRtcpReceived(rtc::Buffer* packet, | |
| 301 const rtc::PacketTime& packet_time) {} | |
| 302 virtual void OnReadyToSend(bool ready) {} | |
| 303 virtual bool AddSendStream(const StreamParams& sp); | |
| 304 virtual bool RemoveSendStream(uint32 ssrc); | |
| 305 virtual bool AddRecvStream(const StreamParams& sp) { return true; } | |
| 306 virtual bool RemoveRecvStream(uint32 ssrc) { return true; } | |
| 307 virtual bool MuteStream(uint32 ssrc, bool on) { return false; } | |
| 308 virtual bool SetMaxSendBandwidth(int bps) { return true; } | |
| 309 virtual bool SetOptions(const VideoOptions& options) { | |
| 310 options_ = options; | |
| 311 return true; | |
| 312 } | |
| 313 virtual bool GetOptions(VideoOptions* options) const { | |
| 314 *options = options_; | |
| 315 return true; | |
| 316 } | |
| 317 virtual void UpdateAspectRatio(int ratio_w, int ratio_h) {} | |
| 318 | |
| 319 private: | |
| 320 uint32 send_ssrc_; | |
| 321 rtc::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_; | |
| 322 VideoOptions options_; | |
| 323 | |
| 324 DISALLOW_COPY_AND_ASSIGN(FileVideoChannel); | |
| 325 }; | |
| 326 | |
| 327 } // namespace cricket | |
| 328 | |
| 329 #endif // TALK_MEDIA_BASE_FILEMEDIAENGINE_H_ | |
| OLD | NEW |