You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

293 lines
11 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #ifndef TALK_MEDIA_BASE_FILEMEDIAENGINE_H_
  26. #define TALK_MEDIA_BASE_FILEMEDIAENGINE_H_
  27. #include <string>
  28. #include <vector>
  29. #include "talk/base/scoped_ptr.h"
  30. #include "talk/base/stream.h"
  31. #include "talk/media/base/codec.h"
  32. #include "talk/media/base/mediachannel.h"
  33. #include "talk/media/base/mediaengine.h"
  34. namespace talk_base {
  35. class StreamInterface;
  36. }
  37. namespace cricket {
  38. // A media engine contains a capturer, an encoder, and a sender in the sender
  39. // side and a receiver, a decoder, and a renderer in the receiver side.
  40. // FileMediaEngine simulates the capturer and the encoder via an input RTP dump
  41. // stream and simulates the decoder and the renderer via an output RTP dump
  42. // stream. Depending on the parameters of the constructor, FileMediaEngine can
  43. // act as file voice engine, file video engine, or both. Currently, we use
  44. // only the RTP dump packets. TODO(whyuan): Enable RTCP packets.
  45. class FileMediaEngine : public MediaEngineInterface {
  46. public:
  47. FileMediaEngine() {}
  48. virtual ~FileMediaEngine() {}
  49. // Set the file name of the input or output RTP dump for voice or video.
  50. // Should be called before the channel is created.
  51. void set_voice_input_filename(const std::string& filename) {
  52. voice_input_filename_ = filename;
  53. }
  54. void set_voice_output_filename(const std::string& filename) {
  55. voice_output_filename_ = filename;
  56. }
  57. void set_video_input_filename(const std::string& filename) {
  58. video_input_filename_ = filename;
  59. }
  60. void set_video_output_filename(const std::string& filename) {
  61. video_output_filename_ = filename;
  62. }
  63. // Should be called before codecs() and video_codecs() are called. We need to
  64. // set the voice and video codecs; otherwise, Jingle initiation will fail.
  65. void set_voice_codecs(const std::vector<AudioCodec>& codecs) {
  66. voice_codecs_ = codecs;
  67. }
  68. void set_video_codecs(const std::vector<VideoCodec>& codecs) {
  69. video_codecs_ = codecs;
  70. }
  71. // Implement pure virtual methods of MediaEngine.
  72. virtual bool Init() { return true; }
  73. virtual void Terminate() {}
  74. virtual int GetCapabilities();
  75. virtual VoiceMediaChannel* CreateChannel();
  76. virtual VideoMediaChannel* CreateVideoChannel(VoiceMediaChannel* voice_ch);
  77. virtual SoundclipMedia* CreateSoundclip() { return NULL; }
  78. virtual bool SetAudioOptions(int options) { return true; }
  79. virtual bool SetVideoOptions(int options) { return true; }
  80. virtual bool SetAudioDelayOffset(int offset) { return true; }
  81. virtual bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config) {
  82. return true;
  83. }
  84. virtual bool SetSoundDevices(const Device* in_dev, const Device* out_dev) {
  85. return true;
  86. }
  87. virtual bool SetVideoCaptureDevice(const Device* cam_device) { return true; }
  88. virtual bool SetVideoCapturer(VideoCapturer* /*capturer*/) {
  89. return true;
  90. }
  91. virtual VideoCapturer* GetVideoCapturer() const {
  92. return NULL;
  93. }
  94. virtual bool GetOutputVolume(int* level) {
  95. *level = 0;
  96. return true;
  97. }
  98. virtual bool SetOutputVolume(int level) { return true; }
  99. virtual int GetInputLevel() { return 0; }
  100. virtual bool SetLocalMonitor(bool enable) { return true; }
  101. virtual bool SetLocalRenderer(VideoRenderer* renderer) { return true; }
  102. // TODO(whyuan): control channel send?
  103. virtual bool SetVideoCapture(bool capture) { return true; }
  104. virtual const std::vector<AudioCodec>& audio_codecs() {
  105. return voice_codecs_;
  106. }
  107. virtual const std::vector<VideoCodec>& video_codecs() {
  108. return video_codecs_;
  109. }
  110. virtual bool FindAudioCodec(const AudioCodec& codec) { return true; }
  111. virtual bool FindVideoCodec(const VideoCodec& codec) { return true; }
  112. virtual void SetVoiceLogging(int min_sev, const char* filter) {}
  113. virtual void SetVideoLogging(int min_sev, const char* filter) {}
  114. virtual bool RegisterVideoProcessor(VideoProcessor* processor) {
  115. return true;
  116. }
  117. virtual bool UnregisterVideoProcessor(VideoProcessor* processor) {
  118. return true;
  119. }
  120. virtual bool RegisterVoiceProcessor(uint32 ssrc,
  121. VoiceProcessor* processor,
  122. MediaProcessorDirection direction) {
  123. return true;
  124. }
  125. virtual bool UnregisterVoiceProcessor(uint32 ssrc,
  126. VoiceProcessor* processor,
  127. MediaProcessorDirection direction) {
  128. return true;
  129. }
  130. VideoFormat GetStartCaptureFormat() const {
  131. return VideoFormat();
  132. }
  133. private:
  134. std::string voice_input_filename_;
  135. std::string voice_output_filename_;
  136. std::string video_input_filename_;
  137. std::string video_output_filename_;
  138. std::vector<AudioCodec> voice_codecs_;
  139. std::vector<VideoCodec> video_codecs_;
  140. DISALLOW_COPY_AND_ASSIGN(FileMediaEngine);
  141. };
  142. class RtpSenderReceiver; // Forward declaration. Defined in the .cc file.
  143. class FileVoiceChannel : public VoiceMediaChannel {
  144. public:
  145. FileVoiceChannel(talk_base::StreamInterface* input_file_stream,
  146. talk_base::StreamInterface* output_file_stream);
  147. virtual ~FileVoiceChannel();
  148. // Implement pure virtual methods of VoiceMediaChannel.
  149. virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) {
  150. return true;
  151. }
  152. virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs);
  153. virtual bool SetRecvRtpHeaderExtensions(
  154. const std::vector<RtpHeaderExtension>& extensions) {
  155. return true;
  156. }
  157. virtual bool SetSendRtpHeaderExtensions(
  158. const std::vector<RtpHeaderExtension>& extensions) {
  159. return true;
  160. }
  161. virtual bool SetPlayout(bool playout) { return true; }
  162. virtual bool SetSend(SendFlags flag);
  163. virtual bool GetActiveStreams(AudioInfo::StreamList* actives) { return true; }
  164. virtual int GetOutputLevel() { return 0; }
  165. virtual int GetTimeSinceLastTyping() { return -1; }
  166. virtual void SetTypingDetectionParameters(int time_window,
  167. int cost_per_typing, int reporting_threshold, int penalty_decay,
  168. int type_event_delay) {}
  169. virtual bool SetOutputScaling(uint32 ssrc, double left, double right) {
  170. return false;
  171. }
  172. virtual bool GetOutputScaling(uint32 ssrc, double* left, double* right) {
  173. return false;
  174. }
  175. virtual bool SetRingbackTone(const char* buf, int len) { return true; }
  176. virtual bool PlayRingbackTone(uint32 ssrc, bool play, bool loop) {
  177. return true;
  178. }
  179. virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags) {
  180. return false;
  181. }
  182. virtual bool GetStats(VoiceMediaInfo* info) { return true; }
  183. // Implement pure virtual methods of MediaChannel.
  184. virtual void OnPacketReceived(talk_base::Buffer* packet);
  185. virtual void OnRtcpReceived(talk_base::Buffer* packet) {}
  186. virtual bool AddSendStream(const StreamParams& sp);
  187. virtual bool RemoveSendStream(uint32 ssrc);
  188. virtual bool AddRecvStream(const StreamParams& sp) { return true; }
  189. virtual bool RemoveRecvStream(uint32 ssrc) { return true; }
  190. virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
  191. virtual bool SetSendBandwidth(bool autobw, int bps) { return true; }
  192. virtual bool SetOptions(const AudioOptions& options) {
  193. options_ = options;
  194. return true;
  195. }
  196. virtual bool GetOptions(AudioOptions* options) const {
  197. *options = options_;
  198. return true;
  199. }
  200. private:
  201. uint32 send_ssrc_;
  202. talk_base::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_;
  203. AudioOptions options_;
  204. DISALLOW_COPY_AND_ASSIGN(FileVoiceChannel);
  205. };
  206. class FileVideoChannel : public VideoMediaChannel {
  207. public:
  208. FileVideoChannel(talk_base::StreamInterface* input_file_stream,
  209. talk_base::StreamInterface* output_file_stream);
  210. virtual ~FileVideoChannel();
  211. // Implement pure virtual methods of VideoMediaChannel.
  212. virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) {
  213. return true;
  214. }
  215. virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs);
  216. virtual bool GetSendCodec(VideoCodec* send_codec) {
  217. *send_codec = VideoCodec();
  218. return true;
  219. }
  220. virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format) {
  221. return true;
  222. }
  223. virtual bool SetRecvRtpHeaderExtensions(
  224. const std::vector<RtpHeaderExtension>& extensions) {
  225. return true;
  226. }
  227. virtual bool SetSendRtpHeaderExtensions(
  228. const std::vector<RtpHeaderExtension>& extensions) {
  229. return true;
  230. }
  231. virtual bool SetRender(bool render) { return true; }
  232. virtual bool SetSend(bool send);
  233. virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) {
  234. return true;
  235. }
  236. virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) {
  237. return false;
  238. }
  239. virtual bool GetStats(VideoMediaInfo* info) { return true; }
  240. virtual bool SendIntraFrame() { return false; }
  241. virtual bool RequestIntraFrame() { return false; }
  242. // Implement pure virtual methods of MediaChannel.
  243. virtual void OnPacketReceived(talk_base::Buffer* packet);
  244. virtual void OnRtcpReceived(talk_base::Buffer* packet) {}
  245. virtual bool AddSendStream(const StreamParams& sp);
  246. virtual bool RemoveSendStream(uint32 ssrc);
  247. virtual bool AddRecvStream(const StreamParams& sp) { return true; }
  248. virtual bool RemoveRecvStream(uint32 ssrc) { return true; }
  249. virtual bool MuteStream(uint32 ssrc, bool on) { return false; }
  250. virtual bool SetSendBandwidth(bool autobw, int bps) { return true; }
  251. virtual bool SetOptions(const VideoOptions& options) {
  252. options_ = options;
  253. return true;
  254. }
  255. virtual bool GetOptions(VideoOptions* options) const {
  256. *options = options_;
  257. return true;
  258. }
  259. virtual void UpdateAspectRatio(int ratio_w, int ratio_h) {}
  260. private:
  261. uint32 send_ssrc_;
  262. talk_base::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_;
  263. VideoOptions options_;
  264. DISALLOW_COPY_AND_ASSIGN(FileVideoChannel);
  265. };
  266. } // namespace cricket
  267. #endif // TALK_MEDIA_BASE_FILEMEDIAENGINE_H_