10e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org/*
20e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * libjingle
30e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * Copyright 2004 Google Inc.
40e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *
50e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * Redistribution and use in source and binary forms, with or without
60e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * modification, are permitted provided that the following conditions are met:
70e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *
80e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *  1. Redistributions of source code must retain the above copyright notice,
90e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *     this list of conditions and the following disclaimer.
100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *  2. Redistributions in binary form must reproduce the above copyright notice,
110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *     this list of conditions and the following disclaimer in the documentation
120e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *     and/or other materials provided with the distribution.
130e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *  3. The name of the author may not be used to endorse or promote products
140e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *     derived from this software without specific prior written permission.
150e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org *
160e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
170e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
190e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
220e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
230e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
240e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
250e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
260e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org */
270e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
280e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#ifndef TALK_MEDIA_WEBRTCVIDEOENGINE_H_
290e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#define TALK_MEDIA_WEBRTCVIDEOENGINE_H_
300e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include <map>
320e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include <vector>
330e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
340e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "talk/media/base/codec.h"
350e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "talk/media/base/videocommon.h"
360e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "talk/media/webrtc/webrtccommon.h"
370e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "talk/media/webrtc/webrtcexport.h"
380e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "talk/media/webrtc/webrtcvideoencoderfactory.h"
390e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "talk/session/media/channel.h"
40cf81adffe15fa8ea0f333432e41f6d504148f18abuildbot@webrtc.org#include "webrtc/base/scoped_ptr.h"
410e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include "webrtc/video_engine/include/vie_base.h"
420e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
430e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#if !defined(LIBPEERCONNECTION_LIB) && \
440e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    !defined(LIBPEERCONNECTION_IMPLEMENTATION)
45145623d67f2794361b37f11e945b8f1bcb11a407buildbot@webrtc.org// If you hit this, then you've tried to include this header from outside
46145623d67f2794361b37f11e945b8f1bcb11a407buildbot@webrtc.org// a shared library.  An instance of this class must only be created from
47145623d67f2794361b37f11e945b8f1bcb11a407buildbot@webrtc.org// within the library that actually implements it.
480e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#error "Bogus include."
490e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#endif
500e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
510e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgnamespace webrtc {
520e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass VideoCaptureModule;
530e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass VideoDecoder;
540e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass VideoEncoder;
550e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass VideoRender;
560e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass ViEExternalCapture;
570e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass ViERTP_RTCP;
580e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org}
590e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
602a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.orgnamespace rtc {
610e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass CpuMonitor;
622a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org}  // namespace rtc
630e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
640e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgnamespace cricket {
650e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
66b881d27f23e9a8f52dc6a60fc66ebd75f9c2f15cmallinath@webrtc.orgclass CoordinatedVideoAdapter;
67b881d27f23e9a8f52dc6a60fc66ebd75f9c2f15cmallinath@webrtc.orgclass ViETraceWrapper;
68b881d27f23e9a8f52dc6a60fc66ebd75f9c2f15cmallinath@webrtc.orgclass ViEWrapper;
690e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass VideoCapturer;
700e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass VideoFrame;
710e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass VideoProcessor;
720e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass VideoRenderer;
730e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass VoiceMediaChannel;
740e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass WebRtcDecoderObserver;
750e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass WebRtcEncoderObserver;
760e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass WebRtcLocalStreamInfo;
770e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass WebRtcRenderAdapter;
780e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass WebRtcVideoChannelRecvInfo;
790e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass WebRtcVideoChannelSendInfo;
800e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass WebRtcVideoDecoderFactory;
810e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass WebRtcVideoEncoderFactory;
820e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass WebRtcVideoMediaChannel;
830e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass WebRtcVoiceEngine;
840e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
850e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgstruct CapturedFrame;
860e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgstruct Device;
870e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
880e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass WebRtcVideoEngine : public sigslot::has_slots<>,
890e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                          public webrtc::TraceCallback,
900e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                          public WebRtcVideoEncoderFactory::Observer {
910e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org public:
920e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Creates the WebRtcVideoEngine with internal VideoCaptureModule.
930e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  WebRtcVideoEngine();
940e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // For testing purposes. Allows the WebRtcVoiceEngine,
950e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // ViEWrapper and CpuMonitor to be mocks.
960e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // TODO(juberti): Remove the 3-arg ctor once fake tracing is implemented.
970e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  WebRtcVideoEngine(WebRtcVoiceEngine* voice_engine,
980e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                    ViEWrapper* vie_wrapper,
992a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org                    rtc::CpuMonitor* cpu_monitor);
1000e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  WebRtcVideoEngine(WebRtcVoiceEngine* voice_engine,
1010e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                    ViEWrapper* vie_wrapper,
1020e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                    ViETraceWrapper* tracing,
1032a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org                    rtc::CpuMonitor* cpu_monitor);
10410fc3fc968451899a055b36f0ea00e9469bff514buildbot@webrtc.org  virtual ~WebRtcVideoEngine();
1050e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1060e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Basic video engine implementation.
1072a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  bool Init(rtc::Thread* worker_thread);
1080e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void Terminate();
1090e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  int GetCapabilities();
1110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SetDefaultEncoderConfig(const VideoEncoderConfig& config);
112861d07361a4559a72e96236f27b758a56f6f59f0wu@webrtc.org  VideoEncoderConfig GetDefaultEncoderConfig() const;
1130e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
114145623d67f2794361b37f11e945b8f1bcb11a407buildbot@webrtc.org  virtual WebRtcVideoMediaChannel* CreateChannel(
115145623d67f2794361b37f11e945b8f1bcb11a407buildbot@webrtc.org      VoiceMediaChannel* voice_channel);
1160e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1170e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  const std::vector<VideoCodec>& codecs() const;
1180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  const std::vector<RtpHeaderExtension>& rtp_header_extensions() const;
1190e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void SetLogging(int min_sev, const char* filter);
1200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  sigslot::repeater2<VideoCapturer*, CaptureState> SignalCaptureStateChange;
1220e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1230e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Set the VoiceEngine for A/V sync. This can only be called before Init.
1240e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SetVoiceEngine(WebRtcVoiceEngine* voice_engine);
1250e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Set a WebRtcVideoDecoderFactory for external decoding. Video engine does
1260e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // not take the ownership of |decoder_factory|. The caller needs to make sure
1270e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // that |decoder_factory| outlives the video engine.
1280e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void SetExternalDecoderFactory(WebRtcVideoDecoderFactory* decoder_factory);
1290e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Set a WebRtcVideoEncoderFactory for external encoding. Video engine does
1300e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // not take the ownership of |encoder_factory|. The caller needs to make sure
1310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // that |encoder_factory| outlives the video engine.
13210fc3fc968451899a055b36f0ea00e9469bff514buildbot@webrtc.org  virtual void SetExternalEncoderFactory(
13310fc3fc968451899a055b36f0ea00e9469bff514buildbot@webrtc.org      WebRtcVideoEncoderFactory* encoder_factory);
1340e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Enable the render module with timing control.
1350e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool EnableTimedRender();
1360e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1370e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Returns an external decoder for the given codec type. The return value
1380e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // can be NULL if decoder factory is not given or it does not support the
1390e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // codec type. The caller takes the ownership of the returned object.
1400e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  webrtc::VideoDecoder* CreateExternalDecoder(webrtc::VideoCodecType type);
1410e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Releases the decoder instance created by CreateExternalDecoder().
1420e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void DestroyExternalDecoder(webrtc::VideoDecoder* decoder);
1430e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1440e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Returns an external encoder for the given codec type. The return value
1450e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // can be NULL if encoder factory is not given or it does not support the
1460e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // codec type. The caller takes the ownership of the returned object.
1470e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  webrtc::VideoEncoder* CreateExternalEncoder(webrtc::VideoCodecType type);
1480e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Releases the encoder instance created by CreateExternalEncoder().
1490e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void DestroyExternalEncoder(webrtc::VideoEncoder* encoder);
1500e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1510e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Returns true if the codec type is supported by the external encoder.
1520e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool IsExternalEncoderCodecType(webrtc::VideoCodecType type) const;
1530e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1540e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Functions called by WebRtcVideoMediaChannel.
1552a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::Thread* worker_thread() { return worker_thread_; }
1560e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  ViEWrapper* vie() { return vie_wrapper_.get(); }
1570e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  const VideoFormat& default_codec_format() const {
1580e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    return default_codec_format_;
1590e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
1600e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  int GetLastEngineError();
1610e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool FindCodec(const VideoCodec& in);
1620e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool CanSendCodec(const VideoCodec& in, const VideoCodec& current,
1630e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                    VideoCodec* out);
1640e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void RegisterChannel(WebRtcVideoMediaChannel* channel);
1650e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void UnregisterChannel(WebRtcVideoMediaChannel* channel);
1660e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool ConvertFromCricketVideoCodec(const VideoCodec& in_codec,
1670e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                    webrtc::VideoCodec* out_codec);
1680e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Check whether the supplied trace should be ignored.
1690e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool ShouldIgnoreTrace(const std::string& trace);
1700e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  int GetNumOfChannels();
1710e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1720fbcf962cd3d7148bf77a996c6f31ba4afc99bacbuildbot@webrtc.org  VideoFormat GetStartCaptureFormat() const { return default_codec_format_; }
1730fbcf962cd3d7148bf77a996c6f31ba4afc99bacbuildbot@webrtc.org
1742a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::CpuMonitor* cpu_monitor() { return cpu_monitor_.get(); }
1750e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1760e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org protected:
1770e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // When a video processor registers with the engine.
1780e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // SignalMediaFrame will be invoked for every video frame.
1790e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // See videoprocessor.h for param reference.
1800e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  sigslot::signal3<uint32, VideoFrame*, bool*> SignalMediaFrame;
1810e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1820e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org private:
1830e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  typedef std::vector<WebRtcVideoMediaChannel*> VideoChannels;
1840e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  struct VideoCodecPref {
1850e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    const char* name;
1860e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    int payload_type;
18797fbd309a28be4e38d138b40662507d50cab6d26sergeyu@chromium.org    // For RTX, this field is the payload-type that RTX applies to.
18897fbd309a28be4e38d138b40662507d50cab6d26sergeyu@chromium.org    // For other codecs, it should be set to -1.
18997fbd309a28be4e38d138b40662507d50cab6d26sergeyu@chromium.org    int associated_payload_type;
1900e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    int pref;
1910e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  };
1920e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1930e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  static const VideoCodecPref kVideoCodecPrefs[];
1940e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  static const VideoFormatPod kVideoFormats[];
195a26d7d6ee1c4d74b8996d19dbb46fc130df3ac17buildbot@webrtc.org  static const VideoFormatPod kDefaultMaxVideoFormat;
1960e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1970e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void Construct(ViEWrapper* vie_wrapper,
1980e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                 ViETraceWrapper* tracing,
1990e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                 WebRtcVoiceEngine* voice_engine,
2002a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org                 rtc::CpuMonitor* cpu_monitor);
2010e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SetDefaultCodec(const VideoCodec& codec);
2020e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool RebuildCodecList(const VideoCodec& max_codec);
2030e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void SetTraceFilter(int filter);
2040e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void SetTraceOptions(const std::string& options);
2050e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool InitVideoEngine();
2066049526e284c9ffb1629b963dc5a1fc09c84ae83buildbot@webrtc.org  bool VerifyApt(const VideoCodec& in, int expected_apt) const;
2070e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2080e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // webrtc::TraceCallback implementation.
2090e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void Print(webrtc::TraceLevel level, const char* trace, int length);
2100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // WebRtcVideoEncoderFactory::Observer implementation.
2120e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void OnCodecsAvailable();
2130e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2142a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::Thread* worker_thread_;
2152a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::scoped_ptr<ViEWrapper> vie_wrapper_;
2160e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool vie_wrapper_base_initialized_;
2172a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::scoped_ptr<ViETraceWrapper> tracing_;
2180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  WebRtcVoiceEngine* voice_engine_;
2192a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::scoped_ptr<webrtc::VideoRender> render_module_;
2200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  WebRtcVideoEncoderFactory* encoder_factory_;
2210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  WebRtcVideoDecoderFactory* decoder_factory_;
2220e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  std::vector<VideoCodec> video_codecs_;
2230e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  std::vector<RtpHeaderExtension> rtp_header_extensions_;
2240e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VideoFormat default_codec_format_;
2250e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2260e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool initialized_;
2272a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::CriticalSection channels_crit_;
2280e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VideoChannels channels_;
2290e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2300e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool capture_started_;
2310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2322a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::scoped_ptr<rtc::CpuMonitor> cpu_monitor_;
2330e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org};
2340e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2352a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.orgclass WebRtcVideoMediaChannel : public rtc::MessageHandler,
2360e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                public VideoMediaChannel,
2370e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                public webrtc::Transport {
2380e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org public:
2390e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  WebRtcVideoMediaChannel(WebRtcVideoEngine* engine,
2400e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                          VoiceMediaChannel* voice_channel);
24110fc3fc968451899a055b36f0ea00e9469bff514buildbot@webrtc.org  virtual ~WebRtcVideoMediaChannel();
2420e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool Init();
2430e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2440e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  WebRtcVideoEngine* engine() { return engine_; }
2450e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VoiceMediaChannel* voice_channel() { return voice_channel_; }
2460e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool sending() const { return sending_; }
2470e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
248bf64da011cfd8fc4c0243d7c52caa6db0d298bddhenrike@webrtc.org  // Public for testing purpose.
24929232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  uint32 GetDefaultSendChannelSsrc();
25029232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  int GetDefaultChannelId() const { return default_channel_id_; }
251bf64da011cfd8fc4c0243d7c52caa6db0d298bddhenrike@webrtc.org
2520e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // VideoMediaChannel implementation
2530e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool SetRecvCodecs(const std::vector<VideoCodec> &codecs);
2540e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool SetSendCodecs(const std::vector<VideoCodec> &codecs);
2550e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool GetSendCodec(VideoCodec* send_codec);
2560e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool SetSendStreamFormat(uint32 ssrc, const VideoFormat& format);
2570e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool SetRender(bool render);
2580e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool SetSend(bool send);
2590e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2600e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool AddSendStream(const StreamParams& sp);
2610e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool RemoveSendStream(uint32 ssrc);
2620e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool AddRecvStream(const StreamParams& sp);
2630e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool RemoveRecvStream(uint32 ssrc);
2640e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer);
2658a77f5bd83ba9386c19ff92f277c7268c1e9ef4awu@webrtc.org  virtual bool GetStats(const StatsOptions& options, VideoMediaInfo* info);
2660e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer);
2670e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool SendIntraFrame();
2680e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool RequestIntraFrame();
2690e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2702a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  virtual void OnPacketReceived(rtc::Buffer* packet,
2712a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org                                const rtc::PacketTime& packet_time);
2722a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  virtual void OnRtcpReceived(rtc::Buffer* packet,
2732a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org                              const rtc::PacketTime& packet_time);
2740e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void OnReadyToSend(bool ready);
2750e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool MuteStream(uint32 ssrc, bool on);
2760e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool SetRecvRtpHeaderExtensions(
2770e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      const std::vector<RtpHeaderExtension>& extensions);
2780e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool SetSendRtpHeaderExtensions(
2790e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      const std::vector<RtpHeaderExtension>& extensions);
2805a1feaee7445019eac8c125a2cedcd377d90be74mallinath@webrtc.org  virtual int GetRtpSendTimeExtnId() const;
281f32dd31e14521d7f845e7776af6d44d411573370sergeyu@chromium.org  virtual bool SetStartSendBandwidth(int bps);
282f32dd31e14521d7f845e7776af6d44d411573370sergeyu@chromium.org  virtual bool SetMaxSendBandwidth(int bps);
2830e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool SetOptions(const VideoOptions &options);
2840e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual bool GetOptions(VideoOptions *options) const {
2850e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    *options = options_;
2860e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    return true;
2870e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
2880e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void SetInterface(NetworkInterface* iface);
2890e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual void UpdateAspectRatio(int ratio_w, int ratio_h);
2900e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2910e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Public functions for use by tests and other specialized code.
2920e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  uint32 send_ssrc() const { return 0; }
2930e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool GetRenderer(uint32 ssrc, VideoRenderer** renderer);
294b881d27f23e9a8f52dc6a60fc66ebd75f9c2f15cmallinath@webrtc.org  bool GetVideoAdapter(uint32 ssrc, CoordinatedVideoAdapter** video_adapter);
29537367930af165586e9c9dae094e7e8bc4ac276cawu@webrtc.org  void SendFrame(VideoCapturer* capturer, const VideoFrame* frame);
29637367930af165586e9c9dae094e7e8bc4ac276cawu@webrtc.org  bool SendFrame(WebRtcVideoChannelSendInfo* channel_info,
29737367930af165586e9c9dae094e7e8bc4ac276cawu@webrtc.org                 const VideoFrame* frame, bool is_screencast);
2980e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2990e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Thunk functions for use with HybridVideoEngine
3000e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void OnLocalFrame(VideoCapturer* capturer, const VideoFrame* frame) {
3010e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    SendFrame(0u, frame, capturer->IsScreencast());
3020e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
3030e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void OnLocalFrameFormat(VideoCapturer* capturer, const VideoFormat* format) {
3040e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
3050e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
3062a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  virtual void OnMessage(rtc::Message* msg);
3070e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
3080e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org protected:
3090e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  int GetLastEngineError() { return engine()->GetLastEngineError(); }
3100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual int SendPacket(int channel, const void* data, int len);
3110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  virtual int SendRTCPPacket(int channel, const void* data, int len);
3120e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
313f87a4357b10d8ed582b351081d7fbda87bb83e5abuildbot@webrtc.org  // Checks the current bitrate estimate and modifies the bitrates
314f87a4357b10d8ed582b351081d7fbda87bb83e5abuildbot@webrtc.org  // accordingly, including converting kAutoBandwidth to the correct defaults.
315f87a4357b10d8ed582b351081d7fbda87bb83e5abuildbot@webrtc.org  virtual void SanitizeBitrates(
316f87a4357b10d8ed582b351081d7fbda87bb83e5abuildbot@webrtc.org      int channel_id, webrtc::VideoCodec* video_codec);
317c76cc079d28a03d104bb75f9aad9be5ce899b2b0buildbot@webrtc.org  virtual void LogSendCodecChange(const std::string& reason);
3187aa6baa9a213c4ca2d51a8d2d3b4bbc46a695ca7buildbot@webrtc.org  bool SetPrimaryAndRtxSsrcs(
3197aa6baa9a213c4ca2d51a8d2d3b4bbc46a695ca7buildbot@webrtc.org      int channel_id, int idx, uint32 primary_ssrc,
3207aa6baa9a213c4ca2d51a8d2d3b4bbc46a695ca7buildbot@webrtc.org      const StreamParams& send_params);
3217aa6baa9a213c4ca2d51a8d2d3b4bbc46a695ca7buildbot@webrtc.org  bool SetLimitedNumberOfSendSsrcs(
3227aa6baa9a213c4ca2d51a8d2d3b4bbc46a695ca7buildbot@webrtc.org      int channel_id, const StreamParams& send_params, size_t limit);
3237aa6baa9a213c4ca2d51a8d2d3b4bbc46a695ca7buildbot@webrtc.org  virtual bool SetSendSsrcs(
3247aa6baa9a213c4ca2d51a8d2d3b4bbc46a695ca7buildbot@webrtc.org      int channel_id, const StreamParams& send_params,
3257aa6baa9a213c4ca2d51a8d2d3b4bbc46a695ca7buildbot@webrtc.org      const webrtc::VideoCodec& codec);
3267aa6baa9a213c4ca2d51a8d2d3b4bbc46a695ca7buildbot@webrtc.org
3270e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org private:
3280e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  typedef std::map<uint32, WebRtcVideoChannelRecvInfo*> RecvChannelMap;
3290e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  typedef std::map<uint32, WebRtcVideoChannelSendInfo*> SendChannelMap;
3306049526e284c9ffb1629b963dc5a1fc09c84ae83buildbot@webrtc.org  typedef std::map<uint32, uint32> SsrcMap;
3310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  typedef int (webrtc::ViERTP_RTCP::* ExtensionSetterFunction)(int, bool, int);
3320e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
3330e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  enum MediaDirection { MD_RECV, MD_SEND, MD_SENDRECV };
3340e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
33529232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // Creates and initializes a ViE channel. When successful
33629232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // |channel_id| will contain the new channel's ID. If |receiving| is
33729232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // true |ssrc| is the remote ssrc. If |sending| is true the ssrc is
33829232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // local ssrc. If both |receiving| and |sending| is true the ssrc
33929232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // must be kDefaultChannelSsrcKey and the channel will be created as
34029232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // a default channel. The ssrc must be different for receive
34129232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // channels and it must be different for send channels. If the same
34229232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // SSRC is being used for creating channel more than once, this
34329232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // function will fail returning false.
3440e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool CreateChannel(uint32 ssrc_key, MediaDirection direction,
3450e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                     int* channel_id);
3467587c5e0b2fb5100b52bf271370ee1369ba18690henrike@webrtc.org  bool CreateUnsignalledRecvChannel(uint32 ssrc_key, int* channel_id);
3470e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool ConfigureChannel(int channel_id, MediaDirection direction,
3480e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                        uint32 ssrc_key);
3490e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool ConfigureReceiving(int channel_id, uint32 remote_ssrc_key);
3500e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool ConfigureSending(int channel_id, uint32 local_ssrc_key);
3510e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SetNackFec(int channel_id, int red_payload_type, int fec_payload_type,
3520e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                  bool nack_enabled);
3533a3e319c05a9901a33e0ddeb80e0aff11d3c8c85buildbot@webrtc.org  bool SetSendCodec(const webrtc::VideoCodec& codec);
3540e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SetSendCodec(WebRtcVideoChannelSendInfo* send_channel,
3553a3e319c05a9901a33e0ddeb80e0aff11d3c8c85buildbot@webrtc.org                    const webrtc::VideoCodec& codec);
3560e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Prepares the channel with channel id |info->channel_id()| to receive all
3570e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // codecs in |receive_codecs_| and start receive packets.
3580e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SetReceiveCodecs(WebRtcVideoChannelRecvInfo* info);
35929232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // Returns the channel ID that receives the stream with SSRC |ssrc|.
36029232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  int GetRecvChannelId(uint32 ssrc);
361214cc46d76a141e2633debfb5ae8379fd50e5992buildbot@webrtc.org  bool MaybeSetRtxSsrc(const StreamParams& sp, int channel_id);
362a585cf053d3fef4d8b6e6747bcb32357c308c322buildbot@webrtc.org  // Create and register an external endcoder if it's possible to do
363a585cf053d3fef4d8b6e6747bcb32357c308c322buildbot@webrtc.org  // so and one isn't already registered.
364a585cf053d3fef4d8b6e6747bcb32357c308c322buildbot@webrtc.org  bool MaybeRegisterExternalEncoder(
365a585cf053d3fef4d8b6e6747bcb32357c308c322buildbot@webrtc.org      WebRtcVideoChannelSendInfo* send_channel,
366a585cf053d3fef4d8b6e6747bcb32357c308c322buildbot@webrtc.org      const webrtc::VideoCodec& codec);
3670e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Given captured video frame size, checks if we need to reset vie send codec.
3680e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // |reset| is set to whether resetting has happened on vie or not.
3690e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Returns false on error.
3700e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool MaybeResetVieSendCodec(WebRtcVideoChannelSendInfo* send_channel,
3710e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                              int new_width, int new_height, bool is_screencast,
3720e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                              bool* reset);
3730e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Helper function for starting the sending of media on all channels or
3740e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // |channel_id|. Note that these two function do not change |sending_|.
3750e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool StartSend();
3760e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool StartSend(WebRtcVideoChannelSendInfo* send_channel);
3770e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Helper function for stop the sending of media on all channels or
3780e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // |channel_id|. Note that these two function do not change |sending_|.
3790e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool StopSend();
3800e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool StopSend(WebRtcVideoChannelSendInfo* send_channel);
3810e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SendIntraFrame(int channel_id);
3820e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
3830e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool HasReadySendChannels();
38429232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  bool DefaultSendChannelInUse();
38529232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org
38629232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // Returns the ssrc key corresponding to the provided local SSRC in
38729232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // |ssrc_key|. The return value is true upon success.  If the local
38829232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // ssrc correspond to that of the default channel the key is
389145623d67f2794361b37f11e945b8f1bcb11a407buildbot@webrtc.org  // kDefaultChannelSsrcKey.  For all other channels the returned ssrc
390145623d67f2794361b37f11e945b8f1bcb11a407buildbot@webrtc.org  // key will be the same as the local ssrc.  If a stream has more
391145623d67f2794361b37f11e945b8f1bcb11a407buildbot@webrtc.org  // than one ssrc, the first (corresponding to
392145623d67f2794361b37f11e945b8f1bcb11a407buildbot@webrtc.org  // StreamParams::first_ssrc()) is used as the key.
39329232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  bool GetSendChannelSsrcKey(uint32 local_ssrc, uint32* ssrc_key);
39429232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  WebRtcVideoChannelSendInfo* GetDefaultSendChannel();
39529232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  WebRtcVideoChannelSendInfo* GetSendChannelBySsrcKey(uint32 ssrc_key);
39629232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  WebRtcVideoChannelSendInfo* GetSendChannelBySsrc(uint32 local_ssrc);
39729232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // Creates a new unique ssrc key that can be used for inserting a
39829232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // new send channel into |send_channels_|
39929232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  bool CreateSendChannelSsrcKey(uint32 local_ssrc, uint32* ssrc_key);
40040ce06146a24b60291ebcbec6f49e02ce381ba7bwu@webrtc.org  // Get the number of the send channels |capturer| registered with.
40140ce06146a24b60291ebcbec6f49e02ce381ba7bwu@webrtc.org  int GetSendChannelNum(VideoCapturer* capturer);
4020e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
40329232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  bool IsDefaultChannelId(int channel_id) const {
40429232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org    return channel_id == default_channel_id_;
4050e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
4060e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool DeleteSendChannel(uint32 ssrc_key);
4070e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
40829232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  WebRtcVideoChannelRecvInfo* GetDefaultRecvChannel();
40929232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  WebRtcVideoChannelRecvInfo* GetRecvChannelBySsrc(uint32 ssrc);
41029232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org
4110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool InConferenceMode() const {
4120e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    return options_.conference_mode.GetWithDefaultIfUnset(false);
4130e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
4140e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool RemoveCapturer(uint32 ssrc);
4150e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
4162a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::MessageQueue* worker_thread() { return engine_->worker_thread(); }
4170e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void QueueBlackFrame(uint32 ssrc, int64 timestamp, int framerate);
4180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void FlushBlackFrame(uint32 ssrc, int64 timestamp);
4190e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
4200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void SetNetworkTransmissionState(bool is_transmitting);
4210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
4220e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SetHeaderExtension(ExtensionSetterFunction setter, int channel_id,
4230e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                          const RtpHeaderExtension* extension);
4240e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SetHeaderExtension(ExtensionSetterFunction setter, int channel_id,
4250e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                          const std::vector<RtpHeaderExtension>& extensions,
4260e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                          const char header_extension_uri[]);
4270e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
428d156f12e9ee96258b7b79d0e3d8ddab6b4b87fbbwu@webrtc.org  // Signal when cpu adaptation has no further scope to adapt.
429d156f12e9ee96258b7b79d0e3d8ddab6b4b87fbbwu@webrtc.org  void OnCpuAdaptationUnable();
430d156f12e9ee96258b7b79d0e3d8ddab6b4b87fbbwu@webrtc.org
43140ce06146a24b60291ebcbec6f49e02ce381ba7bwu@webrtc.org  // Connect |capturer| to WebRtcVideoMediaChannel if it is only registered
43240ce06146a24b60291ebcbec6f49e02ce381ba7bwu@webrtc.org  // to one send channel, i.e. the first send channel.
43340ce06146a24b60291ebcbec6f49e02ce381ba7bwu@webrtc.org  void MaybeConnectCapturer(VideoCapturer* capturer);
43440ce06146a24b60291ebcbec6f49e02ce381ba7bwu@webrtc.org  // Disconnect |capturer| from WebRtcVideoMediaChannel if it is only registered
43540ce06146a24b60291ebcbec6f49e02ce381ba7bwu@webrtc.org  // to one send channel, i.e. the last send channel.
43640ce06146a24b60291ebcbec6f49e02ce381ba7bwu@webrtc.org  void MaybeDisconnectCapturer(VideoCapturer* capturer);
43740ce06146a24b60291ebcbec6f49e02ce381ba7bwu@webrtc.org
438bf64da011cfd8fc4c0243d7c52caa6db0d298bddhenrike@webrtc.org  bool RemoveRecvStreamInternal(uint32 ssrc);
439bf64da011cfd8fc4c0243d7c52caa6db0d298bddhenrike@webrtc.org
440defbcb5af99d51d0128bca9447f9e357addffb1dbuildbot@webrtc.org  // Set the ssrc to use for RTCP receiver reports.
441defbcb5af99d51d0128bca9447f9e357addffb1dbuildbot@webrtc.org  void SetReceiverReportSsrc(uint32 ssrc);
442defbcb5af99d51d0128bca9447f9e357addffb1dbuildbot@webrtc.org
4430e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Global state.
4440e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  WebRtcVideoEngine* engine_;
4450e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VoiceMediaChannel* voice_channel_;
44629232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  int default_channel_id_;
4470e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool nack_enabled_;
4480e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Receiver Estimated Max Bitrate
4490e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool remb_enabled_;
4500e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VideoOptions options_;
4510e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
4520e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Global recv side state.
45329232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // Note the default channel (default_channel_id_), i.e. the send channel
4540e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // corresponding to all the receive channels (this must be done for REMB to
4550e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // work properly), resides in both recv_channels_ and send_channels_ with the
45629232ae880effa5c7e5645e477b316df674d60efbuildbot@webrtc.org  // ssrc key kDefaultChannelSsrcKey.
4570e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  RecvChannelMap recv_channels_;  // Contains all receive channels.
4586049526e284c9ffb1629b963dc5a1fc09c84ae83buildbot@webrtc.org  // A map from the SSRCs on which RTX packets are received to the media SSRCs
4596049526e284c9ffb1629b963dc5a1fc09c84ae83buildbot@webrtc.org  // the RTX packets are associated with. RTX packets will be delivered to the
4606049526e284c9ffb1629b963dc5a1fc09c84ae83buildbot@webrtc.org  // streams matching the primary SSRC.
4616049526e284c9ffb1629b963dc5a1fc09c84ae83buildbot@webrtc.org  SsrcMap rtx_to_primary_ssrc_;
4620e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  std::vector<webrtc::VideoCodec> receive_codecs_;
4636049526e284c9ffb1629b963dc5a1fc09c84ae83buildbot@webrtc.org  // A map from codec payload types to their associated payload types, if any.
4646049526e284c9ffb1629b963dc5a1fc09c84ae83buildbot@webrtc.org  // TODO(holmer): This is a temporary solution until webrtc::VideoCodec has
4656049526e284c9ffb1629b963dc5a1fc09c84ae83buildbot@webrtc.org  // an associated payload type member, when it does we can rely on
4666049526e284c9ffb1629b963dc5a1fc09c84ae83buildbot@webrtc.org  // receive_codecs_.
4676049526e284c9ffb1629b963dc5a1fc09c84ae83buildbot@webrtc.org  std::map<int, int> associated_payload_types_;
4680e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool render_started_;
4690e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  uint32 first_receive_ssrc_;
470defbcb5af99d51d0128bca9447f9e357addffb1dbuildbot@webrtc.org  uint32 receiver_report_ssrc_;
4710e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  std::vector<RtpHeaderExtension> receive_extensions_;
4727587c5e0b2fb5100b52bf271370ee1369ba18690henrike@webrtc.org  int num_unsignalled_recv_channels_;
4730e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
4740e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Global send side state.
4750e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  SendChannelMap send_channels_;
4762a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::scoped_ptr<webrtc::VideoCodec> send_codec_;
47797fbd309a28be4e38d138b40662507d50cab6d26sergeyu@chromium.org  int send_rtx_type_;
4780e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  int send_red_type_;
4790e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  int send_fec_type_;
4800e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool sending_;
4810e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  std::vector<RtpHeaderExtension> send_extensions_;
4820e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
4830e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // The aspect ratio that the channel desires. 0 means there is no desired
4840e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // aspect ratio
4850e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  int ratio_w_;
4860e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  int ratio_h_;
4870e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org};
4880e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
4890e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org}  // namespace cricket
4900e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
4910e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#endif  // TALK_MEDIA_WEBRTCVIDEOENGINE_H_
492