Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / source / talk / media / webrtc / webrtcvoiceengine.h
index 1721000..5557af0 100644 (file)
 #include <string>
 #include <vector>
 
-#include "talk/base/buffer.h"
-#include "talk/base/byteorder.h"
-#include "talk/base/logging.h"
-#include "talk/base/scoped_ptr.h"
-#include "talk/base/stream.h"
 #include "talk/media/base/rtputils.h"
 #include "talk/media/webrtc/webrtccommon.h"
 #include "talk/media/webrtc/webrtcexport.h"
 #include "talk/media/webrtc/webrtcvoe.h"
 #include "talk/session/media/channel.h"
+#include "webrtc/base/buffer.h"
+#include "webrtc/base/byteorder.h"
+#include "webrtc/base/logging.h"
+#include "webrtc/base/scoped_ptr.h"
+#include "webrtc/base/stream.h"
 #include "webrtc/common.h"
-#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
 
 #if !defined(LIBPEERCONNECTION_LIB) && \
     !defined(LIBPEERCONNECTION_IMPLEMENTATION)
+// If you hit this, then you've tried to include this header from outside
+// the shared library.  An instance of this class must only be created from
+// within the library that actually implements it.  Otherwise use the
+// WebRtcMediaEngine to construct an instance.
 #error "Bogus include."
 #endif
 
+namespace webrtc {
+class VideoEngine;
+}
 
 namespace cricket {
 
@@ -66,7 +72,7 @@ class WebRtcSoundclipStream : public webrtc::InStream {
   virtual int Rewind();
 
  private:
-  talk_base::MemoryStream mem_;
+  rtc::MemoryStream mem_;
   bool loop_;
 };
 
@@ -99,7 +105,7 @@ class WebRtcVoiceEngine
                     VoEWrapper* voe_wrapper_sc,
                     VoETraceWrapper* tracing);
   ~WebRtcVoiceEngine();
-  bool Init(talk_base::Thread* worker_thread);
+  bool Init(rtc::Thread* worker_thread);
   void Terminate();
 
   int GetCapabilities();
@@ -175,7 +181,7 @@ class WebRtcVoiceEngine
                             webrtc::AudioDeviceModule* adm_sc);
 
   // Starts AEC dump using existing file.
-  bool StartAecDump(talk_base::PlatformFile file);
+  bool StartAecDump(rtc::PlatformFile file);
 
   // Check whether the supplied trace should be ignored.
   bool ShouldIgnoreTrace(const std::string& trace);
@@ -201,9 +207,6 @@ class WebRtcVoiceEngine
   // allows us to selectively turn on and off different options easily
   // at any time.
   bool ApplyOptions(const AudioOptions& options);
-  // Configure for using ACM2, if |enable| is true, otherwise configure for
-  // ACM1.
-  void EnableExperimentalAcm(bool enable);
   virtual void Print(webrtc::TraceLevel level, const char* trace, int length);
   virtual void CallbackOnError(int channel, int errCode);
   // Given the device type, name, and id, find device id. Return true and
@@ -235,14 +238,14 @@ class WebRtcVoiceEngine
   FrameSignal SignalRxMediaFrame;
   FrameSignal SignalTxMediaFrame;
 
-  static const int kDefaultLogSeverity = talk_base::LS_WARNING;
+  static const int kDefaultLogSeverity = rtc::LS_WARNING;
 
   // The primary instance of WebRtc VoiceEngine.
-  talk_base::scoped_ptr<VoEWrapper> voe_wrapper_;
+  rtc::scoped_ptr<VoEWrapper> voe_wrapper_;
   // A secondary instance, for playing out soundclips (on the 'ring' device).
-  talk_base::scoped_ptr<VoEWrapper> voe_wrapper_sc_;
+  rtc::scoped_ptr<VoEWrapper> voe_wrapper_sc_;
   bool voe_wrapper_sc_initialized_;
-  talk_base::scoped_ptr<VoETraceWrapper> tracing_;
+  rtc::scoped_ptr<VoETraceWrapper> tracing_;
   // The external audio device manager
   webrtc::AudioDeviceModule* adm_;
   webrtc::AudioDeviceModule* adm_sc_;
@@ -252,16 +255,15 @@ class WebRtcVoiceEngine
   std::vector<AudioCodec> codecs_;
   std::vector<RtpHeaderExtension> rtp_header_extensions_;
   bool desired_local_monitor_enable_;
-  talk_base::scoped_ptr<WebRtcMonitorStream> monitor_;
+  rtc::scoped_ptr<WebRtcMonitorStream> monitor_;
   SoundclipList soundclips_;
   ChannelList channels_;
   // channels_ can be read from WebRtc callback thread. We need a lock on that
   // callback as well as the RegisterChannel/UnregisterChannel.
-  talk_base::CriticalSection channels_cs_;
+  rtc::CriticalSection channels_cs_;
   webrtc::AgcConfig default_agc_config_;
 
   webrtc::Config voe_config_;
-  bool use_experimental_acm_;
 
   bool initialized_;
   // See SetOptions and SetOptionOverrides for a description of the
@@ -281,7 +283,14 @@ class WebRtcVoiceEngine
   uint32 tx_processor_ssrc_;
   uint32 rx_processor_ssrc_;
 
-  talk_base::CriticalSection signal_media_critical_;
+  rtc::CriticalSection signal_media_critical_;
+
+  // Cache received experimental_aec and experimental_ns values, and apply them
+  // in case they are missing in the audio options. We need to do this because
+  // SetExtraOptions() will revert to defaults for options which are not
+  // provided.
+  Settable<bool> experimental_aec_;
+  Settable<bool> experimental_ns_;
 };
 
 // WebRtcMediaChannel is a class that implements the common WebRtc channel
@@ -298,7 +307,7 @@ class WebRtcMediaChannel : public T, public webrtc::Transport {
  protected:
   // implements Transport interface
   virtual int SendPacket(int channel, const void *data, int len) {
-    talk_base::Buffer packet(data, len, kMaxRtpPacketLen);
+    rtc::Buffer packet(data, len, kMaxRtpPacketLen);
     if (!T::SendPacket(&packet)) {
       return -1;
     }
@@ -306,7 +315,7 @@ class WebRtcMediaChannel : public T, public webrtc::Transport {
   }
 
   virtual int SendRTCPPacket(int channel, const void *data, int len) {
-    talk_base::Buffer packet(data, len, kMaxRtpPacketLen);
+    rtc::Buffer packet(data, len, kMaxRtpPacketLen);
     return T::SendRtcp(&packet) ? len : -1;
   }
 
@@ -359,10 +368,10 @@ class WebRtcVoiceMediaChannel
   virtual bool CanInsertDtmf();
   virtual bool InsertDtmf(uint32 ssrc, int event, int duration, int flags);
 
-  virtual void OnPacketReceived(talk_base::Buffer* packet,
-                                const talk_base::PacketTime& packet_time);
-  virtual void OnRtcpReceived(talk_base::Buffer* packet,
-                              const talk_base::PacketTime& packet_time);
+  virtual void OnPacketReceived(rtc::Buffer* packet,
+                                const rtc::PacketTime& packet_time);
+  virtual void OnRtcpReceived(rtc::Buffer* packet,
+                              const rtc::PacketTime& packet_time);
   virtual void OnReadyToSend(bool ready) {}
   virtual bool MuteStream(uint32 ssrc, bool on);
   virtual bool SetStartSendBandwidth(int bps);
@@ -379,6 +388,8 @@ class WebRtcVoiceMediaChannel
   int GetReceiveChannelNum(uint32 ssrc);
   int GetSendChannelNum(uint32 ssrc);
 
+  bool SetupSharedBandwidthEstimation(webrtc::VideoEngine* vie,
+                                      int vie_channel);
  protected:
   int GetLastEngineError() { return engine()->GetLastEngineError(); }
   int GetOutputLevel(int channel);
@@ -421,12 +432,20 @@ class WebRtcVoiceMediaChannel
 
   bool SetHeaderExtension(ExtensionSetterFunction setter, int channel_id,
                           const RtpHeaderExtension* extension);
+  bool SetupSharedBweOnChannel(int voe_channel);
+
+  bool SetChannelRecvRtpHeaderExtensions(
+    int channel_id,
+    const std::vector<RtpHeaderExtension>& extensions);
+  bool SetChannelSendRtpHeaderExtensions(
+    int channel_id,
+    const std::vector<RtpHeaderExtension>& extensions);
 
-  talk_base::scoped_ptr<WebRtcSoundclipStream> ringback_tone_;
+  rtc::scoped_ptr<WebRtcSoundclipStream> ringback_tone_;
   std::set<int> ringback_channels_;  // channels playing ringback
   std::vector<AudioCodec> recv_codecs_;
   std::vector<AudioCodec> send_codecs_;
-  talk_base::scoped_ptr<webrtc::CodecInst> send_codec_;
+  rtc::scoped_ptr<webrtc::CodecInst> send_codec_;
   bool send_bw_setting_;
   int send_bw_bps_;
   AudioOptions options_;
@@ -437,11 +456,17 @@ class WebRtcVoiceMediaChannel
   bool typing_noise_detected_;
   SendFlags desired_send_;
   SendFlags send_;
+  // shared_bwe_vie_ and shared_bwe_vie_channel_ together identifies a WebRTC
+  // VideoEngine channel that this voice channel should forward incoming packets
+  // to for Bandwidth Estimation purposes.
+  webrtc::VideoEngine* shared_bwe_vie_;
+  int shared_bwe_vie_channel_;
 
   // send_channels_ contains the channels which are being used for sending.
   // When the default channel (voe_channel) is used for sending, it is
   // contained in send_channels_, otherwise not.
   ChannelMap send_channels_;
+  std::vector<RtpHeaderExtension> send_extensions_;
   uint32 default_receive_ssrc_;
   // Note the default channel (voe_channel()) can reside in both
   // receive_channels_ and send_channels_ in non-conference mode and in that
@@ -451,9 +476,10 @@ class WebRtcVoiceMediaChannel
   // the WebRtc thread must be synchronized with edits on the worker thread.
   // Reads on the worker thread are ok.
   //
+  std::vector<RtpHeaderExtension> receive_extensions_;
   // Do not lock this on the VoE media processor thread; potential for deadlock
   // exists.
-  mutable talk_base::CriticalSection receive_channels_cs_;
+  mutable rtc::CriticalSection receive_channels_cs_;
 };
 
 }  // namespace cricket