Home | History | Annotate | Download | only in phone
      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/session/phone/codec.h"
     34 #include "talk/session/phone/mediachannel.h"
     35 #include "talk/session/phone/mediaengine.h"
     36 
     37 namespace talk_base {
     38 class StreamInterface;
     39 }
     40 
     41 namespace cricket {
     42 
     43 // A media engine contains a capturer, an encoder, and a sender in the sender
     44 // side and a receiver, a decoder, and a renderer in the receiver side.
     45 // FileMediaEngine simulates the capturer and the encoder via an input RTP dump
     46 // stream and simulates the decoder and the renderer via an output RTP dump
     47 // stream. Depending on the parameters of the constructor, FileMediaEngine can
     48 // act as file voice engine, file video engine, or both. Currently, we use
     49 // only the RTP dump packets. TODO: Enable RTCP packets.
     50 class FileMediaEngine : public MediaEngine {
     51  public:
     52   FileMediaEngine() {}
     53   virtual ~FileMediaEngine() {}
     54 
     55   // Set the file name of the input or output RTP dump for voice or video.
     56   // Should be called before the channel is created.
     57   void set_voice_input_filename(const std::string& filename) {
     58     voice_input_filename_ = filename;
     59   }
     60   void set_voice_output_filename(const std::string& filename) {
     61     voice_output_filename_ = filename;
     62   }
     63   void set_video_input_filename(const std::string& filename) {
     64     video_input_filename_ = filename;
     65   }
     66   void set_video_output_filename(const std::string& filename) {
     67     video_output_filename_ = filename;
     68   }
     69 
     70   // Should be called before codecs() and video_codecs() are called. We need to
     71   // set the voice and video codecs; otherwise, Jingle initiation will fail.
     72   void set_voice_codecs(const std::vector<AudioCodec>& codecs) {
     73     voice_codecs_ = codecs;
     74   }
     75   void set_video_codecs(const std::vector<VideoCodec>& codecs) {
     76     video_codecs_ = codecs;
     77   }
     78 
     79   // Implement pure virtual methods of MediaEngine.
     80   virtual bool Init() { return true; }
     81   virtual void Terminate() {}
     82   virtual int GetCapabilities();
     83   virtual VoiceMediaChannel* CreateChannel();
     84   virtual VideoMediaChannel* CreateVideoChannel(VoiceMediaChannel* voice_ch);
     85   virtual SoundclipMedia* CreateSoundclip() { return NULL; }
     86   virtual bool SetAudioOptions(int options) { return true; }
     87   virtual bool SetVideoOptions(int options) { return true; }
     88   virtual bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config) {
     89     return true;
     90   }
     91   virtual bool SetSoundDevices(const Device* in_dev, const Device* out_dev) {
     92     return true;
     93   }
     94   virtual bool SetVideoCaptureDevice(const Device* cam_device) { return true; }
     95   virtual bool SetOutputVolume(int level) { return true; }
     96   virtual int GetInputLevel() { return 0; }
     97   virtual bool SetLocalMonitor(bool enable) { return true; }
     98   virtual bool SetLocalRenderer(VideoRenderer* renderer) { return true; }
     99   // TODO: control channel send?
    100   virtual CaptureResult SetVideoCapture(bool capture) { return CR_SUCCESS; }
    101   virtual const std::vector<AudioCodec>& audio_codecs() {
    102     return voice_codecs_;
    103   }
    104   virtual const std::vector<VideoCodec>& video_codecs() {
    105     return video_codecs_;
    106   }
    107   virtual bool FindAudioCodec(const AudioCodec& codec) { return true; }
    108   virtual bool FindVideoCodec(const VideoCodec& codec) { return true; }
    109   virtual void SetVoiceLogging(int min_sev, const char* filter) {}
    110   virtual void SetVideoLogging(int min_sev, const char* filter) {}
    111 
    112  private:
    113   std::string voice_input_filename_;
    114   std::string voice_output_filename_;
    115   std::string video_input_filename_;
    116   std::string video_output_filename_;
    117   std::vector<AudioCodec> voice_codecs_;
    118   std::vector<VideoCodec> video_codecs_;
    119 
    120   DISALLOW_COPY_AND_ASSIGN(FileMediaEngine);
    121 };
    122 
    123 class RtpSenderReceiver;  // Forward declaration. Defined in the .cc file.
    124 
    125 class FileVoiceChannel : public VoiceMediaChannel {
    126  public:
    127   FileVoiceChannel(const std::string& in_file, const std::string& out_file);
    128   virtual ~FileVoiceChannel();
    129 
    130   // Implement pure virtual methods of VoiceMediaChannel.
    131   virtual bool SetRecvCodecs(const std::vector<AudioCodec>& codecs) {
    132     return true;
    133   }
    134   virtual bool SetSendCodecs(const std::vector<AudioCodec>& codecs);
    135   virtual bool SetPlayout(bool playout) { return true; }
    136   virtual bool SetSend(SendFlags flag);
    137   virtual bool AddStream(uint32 ssrc) { return true; }
    138   virtual bool RemoveStream(uint32 ssrc) { return true; }
    139   virtual bool GetActiveStreams(AudioInfo::StreamList* actives) { return true; }
    140   virtual int GetOutputLevel() { return 0; }
    141   virtual void SetRingbackTone(const char* buf, int len) {}
    142   virtual bool PlayRingbackTone(bool play, bool loop) { return true; }
    143   virtual bool PressDTMF(int event, bool playout) { return true; }
    144   virtual bool GetStats(VoiceMediaInfo* info) { return true; }
    145 
    146   // Implement pure virtual methods of MediaChannel.
    147   virtual void OnPacketReceived(talk_base::Buffer* packet);
    148   virtual void OnRtcpReceived(talk_base::Buffer* packet) {}
    149   virtual void SetSendSsrc(uint32 id) {}  // TODO: change RTP packet?
    150   virtual bool SetRtcpCName(const std::string& cname) { return true; }
    151   virtual bool Mute(bool on) { return false; }
    152   virtual bool SetSendBandwidth(bool autobw, int bps) { return true; }
    153   virtual bool SetOptions(int options) { return true; }
    154 
    155  private:
    156   talk_base::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_;
    157   DISALLOW_COPY_AND_ASSIGN(FileVoiceChannel);
    158 };
    159 
    160 class FileVideoChannel : public VideoMediaChannel {
    161  public:
    162   FileVideoChannel(const std::string& in_file, const std::string& out_file);
    163   virtual ~FileVideoChannel();
    164 
    165   // Implement pure virtual methods of VideoMediaChannel.
    166   virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) {
    167     return true;
    168   }
    169   virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs);
    170   virtual bool SetRender(bool render) { return true; }
    171   virtual bool SetSend(bool send);
    172   virtual bool AddStream(uint32 ssrc, uint32 voice_ssrc) { return true; }
    173   virtual bool RemoveStream(uint32 ssrc) { return true; }
    174   virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) {
    175     return true;
    176   }
    177   virtual bool GetStats(VideoMediaInfo* info) { return true; }
    178   virtual bool SendIntraFrame() { return false; }
    179   virtual bool RequestIntraFrame() { return false; }
    180 
    181   // Implement pure virtual methods of MediaChannel.
    182   virtual void OnPacketReceived(talk_base::Buffer* packet);
    183   virtual void OnRtcpReceived(talk_base::Buffer* packet) {}
    184   virtual void SetSendSsrc(uint32 id) {}  // TODO: change RTP packet?
    185   virtual bool SetRtcpCName(const std::string& cname) { return true; }
    186   virtual bool Mute(bool on) { return false; }
    187   virtual bool SetSendBandwidth(bool autobw, int bps) { return true; }
    188   virtual bool SetOptions(int options) { return true; }
    189 
    190  private:
    191   talk_base::scoped_ptr<RtpSenderReceiver> rtp_sender_receiver_;
    192   DISALLOW_COPY_AND_ASSIGN(FileVideoChannel);
    193 };
    194 
    195 }  // namespace cricket
    196 
    197 #endif  // TALK_SESSION_PHONE_FILEMEDIAENGINE_H_
    198