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_SESSION_MEDIA_CHANNELMANAGER_H_
290e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#define TALK_SESSION_MEDIA_CHANNELMANAGER_H_
300e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include <string>
320e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#include <vector>
330e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
347d284f2eabf6ada1e31707ba7c3decd3c61da4dcbuildbot@webrtc.org#include "talk/media/base/capturemanager.h"
357d284f2eabf6ada1e31707ba7c3decd3c61da4dcbuildbot@webrtc.org#include "talk/media/base/mediaengine.h"
367d284f2eabf6ada1e31707ba7c3decd3c61da4dcbuildbot@webrtc.org#include "talk/p2p/base/session.h"
377d284f2eabf6ada1e31707ba7c3decd3c61da4dcbuildbot@webrtc.org#include "talk/session/media/voicechannel.h"
38c7416745e9d35902e62517d1bddcd546623e1c34buildbot@webrtc.org#include "webrtc/base/criticalsection.h"
39c7416745e9d35902e62517d1bddcd546623e1c34buildbot@webrtc.org#include "webrtc/base/fileutils.h"
40c7416745e9d35902e62517d1bddcd546623e1c34buildbot@webrtc.org#include "webrtc/base/sigslotrepeater.h"
41c7416745e9d35902e62517d1bddcd546623e1c34buildbot@webrtc.org#include "webrtc/base/thread.h"
420e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
430e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgnamespace cricket {
440e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
45e9db8f6d27d05dcf0f549ee0a1266c7374154f59henrike@webrtc.orgconst int kDefaultAudioDelayOffset = 0;
46e9db8f6d27d05dcf0f549ee0a1266c7374154f59henrike@webrtc.org
470e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass Soundclip;
480e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass VideoProcessor;
490e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass VoiceChannel;
500e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.orgclass VoiceProcessor;
510e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
520e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// ChannelManager allows the MediaEngine to run on a separate thread, and takes
530e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// care of marshalling calls between threads. It also creates and keeps track of
540e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// voice and video channels; by doing so, it can temporarily pause all the
550e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// channels when a new audio or video device is chosen. The voice and video
560e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// channels are stored in separate vectors, to easily allow operations on just
570e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// voice or just video channels.
580e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// ChannelManager also allows the application to discover what devices it has
590e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org// using device manager.
602a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.orgclass ChannelManager : public rtc::MessageHandler,
610e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                       public sigslot::has_slots<> {
620e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org public:
630e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#if !defined(DISABLE_MEDIA_ENGINE_FACTORY)
640e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Creates the channel manager, and specifies the worker thread to use.
652a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  explicit ChannelManager(rtc::Thread* worker);
660e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#endif
670e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
680e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // For testing purposes. Allows the media engine and data media
690e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // engine and dev manager to be mocks.  The ChannelManager takes
700e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // ownership of these objects.
710e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  ChannelManager(MediaEngineInterface* me,
720e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                 DataEngineInterface* dme,
730e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                 DeviceManagerInterface* dm,
740e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                 CaptureManager* cm,
752a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org                 rtc::Thread* worker);
760e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Same as above, but gives an easier default DataEngine.
770e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  ChannelManager(MediaEngineInterface* me,
780e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                 DeviceManagerInterface* dm,
792a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org                 rtc::Thread* worker);
800e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  ~ChannelManager();
810e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
820e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Accessors for the worker thread, allowing it to be set after construction,
830e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // but before Init. set_worker_thread will return false if called after Init.
842a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::Thread* worker_thread() const { return worker_thread_; }
852a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  bool set_worker_thread(rtc::Thread* thread) {
860e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    if (initialized_) return false;
870e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    worker_thread_ = thread;
880e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    return true;
890e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
900e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
910e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Gets capabilities. Can be called prior to starting the media engine.
920e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  int GetCapabilities();
930e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
940e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Retrieves the list of supported audio & video codec types.
950e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Can be called before starting the media engine.
960e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void GetSupportedAudioCodecs(std::vector<AudioCodec>* codecs) const;
970e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void GetSupportedAudioRtpHeaderExtensions(RtpHeaderExtensions* ext) const;
980e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void GetSupportedVideoCodecs(std::vector<VideoCodec>* codecs) const;
990e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void GetSupportedVideoRtpHeaderExtensions(RtpHeaderExtensions* ext) const;
1000e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void GetSupportedDataCodecs(std::vector<DataCodec>* codecs) const;
1010e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1020e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Indicates whether the media engine is started.
1030e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool initialized() const { return initialized_; }
1040e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Starts up the media engine.
1050e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool Init();
1060e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Shuts down the media engine.
1070e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void Terminate();
1080e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1090e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // The operations below all occur on the worker thread.
1100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Creates a voice channel, to be associated with the specified session.
1120e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VoiceChannel* CreateVoiceChannel(
1130e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      BaseSession* session, const std::string& content_name, bool rtcp);
1140e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Destroys a voice channel created with the Create API.
1150e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void DestroyVoiceChannel(VoiceChannel* voice_channel);
1160e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Creates a video channel, synced with the specified voice channel, and
1170e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // associated with the specified session.
1180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VideoChannel* CreateVideoChannel(
1190e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      BaseSession* session, const std::string& content_name, bool rtcp,
1200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      VoiceChannel* voice_channel);
1210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Destroys a video channel created with the Create API.
1220e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void DestroyVideoChannel(VideoChannel* video_channel);
1230e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  DataChannel* CreateDataChannel(
1240e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      BaseSession* session, const std::string& content_name,
1250e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      bool rtcp, DataChannelType data_channel_type);
1260e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Destroys a data channel created with the Create API.
1270e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void DestroyDataChannel(DataChannel* data_channel);
1280e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1290e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Creates a soundclip.
1300e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  Soundclip* CreateSoundclip();
1310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Destroys a soundclip created with the Create API.
1320e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void DestroySoundclip(Soundclip* soundclip);
1330e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1340e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Indicates whether any channels exist.
1350e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool has_channels() const {
1360e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org    return (!voice_channels_.empty() || !video_channels_.empty() ||
1370e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org            !soundclips_.empty());
1380e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  }
1390e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1400e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Configures the audio and video devices. A null pointer can be passed to
1410e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // GetAudioOptions() for any parameter of no interest.
1420e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool GetAudioOptions(std::string* wave_in_device,
1435528070a0c76057a000b877fc56ca4180ad2087bmallinath@webrtc.org                       std::string* wave_out_device,
1445528070a0c76057a000b877fc56ca4180ad2087bmallinath@webrtc.org                       AudioOptions* options);
1450e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SetAudioOptions(const std::string& wave_in_device,
1465528070a0c76057a000b877fc56ca4180ad2087bmallinath@webrtc.org                       const std::string& wave_out_device,
1475528070a0c76057a000b877fc56ca4180ad2087bmallinath@webrtc.org                       const AudioOptions& options);
1483d341e220ccc19b41d865dcca6ff4d7194e2689fbuildbot@webrtc.org  // Sets Engine-specific audio options according to enabled experiments.
1493d341e220ccc19b41d865dcca6ff4d7194e2689fbuildbot@webrtc.org  bool SetEngineAudioOptions(const AudioOptions& options);
1500e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool GetOutputVolume(int* level);
1510e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SetOutputVolume(int level);
1520e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool IsSameCapturer(const std::string& capturer_name,
1530e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                      VideoCapturer* capturer);
154a113c08d77afcecf042d96eacc23a0ed512ec122henrike@webrtc.org  // TODO(noahric): Nearly everything called "device" in this API is actually a
155a113c08d77afcecf042d96eacc23a0ed512ec122henrike@webrtc.org  // device name, so this should really be GetCaptureDeviceName, and the
156a113c08d77afcecf042d96eacc23a0ed512ec122henrike@webrtc.org  // next method should be GetCaptureDevice.
1570e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool GetCaptureDevice(std::string* cam_device);
158a113c08d77afcecf042d96eacc23a0ed512ec122henrike@webrtc.org  // Gets the current capture Device.
159a113c08d77afcecf042d96eacc23a0ed512ec122henrike@webrtc.org  bool GetVideoCaptureDevice(Device* device);
1600e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Create capturer based on what has been set in SetCaptureDevice().
1610e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VideoCapturer* CreateVideoCapturer();
162c7416745e9d35902e62517d1bddcd546623e1c34buildbot@webrtc.org  // Create capturer from a screen.
163c7416745e9d35902e62517d1bddcd546623e1c34buildbot@webrtc.org  VideoCapturer* CreateScreenCapturer(const ScreencastId& screenid);
1640e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SetCaptureDevice(const std::string& cam_device);
1650e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SetDefaultVideoEncoderConfig(const VideoEncoderConfig& config);
1660e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // RTX will be enabled/disabled in engines that support it. The supporting
1670e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // engines will start offering an RTX codec. Must be called before Init().
1680e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SetVideoRtxEnabled(bool enable);
1690e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1700e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Starts/stops the local microphone and enables polling of the input level.
1710e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SetLocalMonitor(bool enable);
1720e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool monitoring() const { return monitoring_; }
1730e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool capturing() const { return capturing_; }
1740e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1750e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Configures the logging output of the mediaengine(s).
1760e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void SetVoiceLogging(int level, const char* filter);
1770e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void SetVideoLogging(int level, const char* filter);
1780e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
1790e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // The channel manager handles the Tx side for Video processing,
1800e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // as well as Tx and Rx side for Voice processing.
1810e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // (The Rx Video processing will go throug the simplerenderingmanager,
1820e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  //  to be implemented).
1830e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool RegisterVideoProcessor(VideoCapturer* capturer,
1840e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                              VideoProcessor* processor);
1850e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool UnregisterVideoProcessor(VideoCapturer* capturer,
1860e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                VideoProcessor* processor);
1870e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool RegisterVoiceProcessor(uint32 ssrc,
1880e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                              VoiceProcessor* processor,
1890e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                              MediaProcessorDirection direction);
1900e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool UnregisterVoiceProcessor(uint32 ssrc,
1910e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                VoiceProcessor* processor,
1920e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                MediaProcessorDirection direction);
1930e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // The following are done in the new "CaptureManager" style that
1940e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // all local video capturers, processors, and managers should move to.
1950e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // TODO(pthatcher): Make methods nicer by having start return a handle that
1960e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // can be used for stop and restart, rather than needing to pass around
1970e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // formats a a pseudo-handle.
1980e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool StartVideoCapture(VideoCapturer* video_capturer,
1990e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                         const VideoFormat& video_format);
2000e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // When muting, produce black frames then pause the camera.
2010e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // When unmuting, start the camera. Camera starts unmuted.
2020e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool MuteToBlackThenPause(VideoCapturer* video_capturer, bool muted);
2030e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool StopVideoCapture(VideoCapturer* video_capturer,
2040e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                        const VideoFormat& video_format);
2050e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool RestartVideoCapture(VideoCapturer* video_capturer,
2060e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                           const VideoFormat& previous_format,
2070e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                           const VideoFormat& desired_format,
2080e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                           CaptureManager::RestartOptions options);
2090e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool AddVideoRenderer(VideoCapturer* capturer, VideoRenderer* renderer);
2110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool RemoveVideoRenderer(VideoCapturer* capturer, VideoRenderer* renderer);
2120e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool IsScreencastRunning() const;
2130e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2140e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // The operations below occur on the main thread.
2150e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2160e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool GetAudioInputDevices(std::vector<std::string>* names);
2170e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool GetAudioOutputDevices(std::vector<std::string>* names);
2180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool GetVideoCaptureDevices(std::vector<std::string>* names);
2190e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void SetVideoCaptureDeviceMaxFormat(const std::string& usb_id,
2200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                      const VideoFormat& max_format);
2210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
222f89a403cd8db88001322bbb0765c4636fd123700wu@webrtc.org  // Starts AEC dump using existing file.
2232a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  bool StartAecDump(rtc::PlatformFile file);
224f89a403cd8db88001322bbb0765c4636fd123700wu@webrtc.org
2250e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  sigslot::repeater0<> SignalDevicesChange;
2260e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  sigslot::signal2<VideoCapturer*, CaptureState> SignalVideoCaptureStateChange;
2270e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2280e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Returns the current selected device. Note: Subtly different from
2290e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // GetCaptureDevice(). See member video_device_ for more details.
2300e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // This API is mainly a hook used by unittests.
2310e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  const std::string& video_device_name() const { return video_device_name_; }
2320e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2330e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // TODO(hellner): Remove this function once the engine capturer has been
2340e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // removed.
2350e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VideoFormat GetStartCaptureFormat();
23697fbd309a28be4e38d138b40662507d50cab6d26sergeyu@chromium.org
2370e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org protected:
2380e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // Adds non-transient parameters which can only be changed through the
2390e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // options store.
2400e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SetAudioOptions(const std::string& wave_in_device,
2415528070a0c76057a000b877fc56ca4180ad2087bmallinath@webrtc.org                       const std::string& wave_out_device,
2425528070a0c76057a000b877fc56ca4180ad2087bmallinath@webrtc.org                       const AudioOptions& options,
2430e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                       int delay_offset);
2440e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  int audio_delay_offset() const { return audio_delay_offset_; }
245c7416745e9d35902e62517d1bddcd546623e1c34buildbot@webrtc.org  // This is here so that ChannelManager subclasses can set the video
246c7416745e9d35902e62517d1bddcd546623e1c34buildbot@webrtc.org  // capturer factories to use.
247c7416745e9d35902e62517d1bddcd546623e1c34buildbot@webrtc.org  DeviceManagerInterface* device_manager() { return device_manager_.get(); }
2480e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2490e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org private:
2500e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  typedef std::vector<VoiceChannel*> VoiceChannels;
2510e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  typedef std::vector<VideoChannel*> VideoChannels;
2520e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  typedef std::vector<DataChannel*> DataChannels;
2530e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  typedef std::vector<Soundclip*> Soundclips;
2540e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2550e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void Construct(MediaEngineInterface* me,
2560e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                 DataEngineInterface* dme,
2570e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                 DeviceManagerInterface* dm,
2580e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                 CaptureManager* cm,
2592a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org                 rtc::Thread* worker_thread);
2600e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void Terminate_w();
2610e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VoiceChannel* CreateVoiceChannel_w(
2620e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      BaseSession* session, const std::string& content_name, bool rtcp);
2630e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void DestroyVoiceChannel_w(VoiceChannel* voice_channel);
2640e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VideoChannel* CreateVideoChannel_w(
2650e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      BaseSession* session, const std::string& content_name, bool rtcp,
2660e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      VoiceChannel* voice_channel);
2670e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void DestroyVideoChannel_w(VideoChannel* video_channel);
2680e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  DataChannel* CreateDataChannel_w(
2690e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      BaseSession* session, const std::string& content_name,
2700e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org      bool rtcp, DataChannelType data_channel_type);
2710e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void DestroyDataChannel_w(DataChannel* data_channel);
2720e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  Soundclip* CreateSoundclip_w();
2730e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void DestroySoundclip_w(Soundclip* soundclip);
2745528070a0c76057a000b877fc56ca4180ad2087bmallinath@webrtc.org  bool SetAudioOptions_w(const AudioOptions& options, int delay_offset,
2755528070a0c76057a000b877fc56ca4180ad2087bmallinath@webrtc.org                         const Device* in_dev, const Device* out_dev);
2763d341e220ccc19b41d865dcca6ff4d7194e2689fbuildbot@webrtc.org  bool SetEngineAudioOptions_w(const AudioOptions& options);
2770e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool SetCaptureDevice_w(const Device* cam_device);
2780e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  void OnVideoCaptureStateChange(VideoCapturer* capturer,
2790e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                 CaptureState result);
2800e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool RegisterVideoProcessor_w(VideoCapturer* capturer,
2810e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                VideoProcessor* processor);
2820e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool UnregisterVideoProcessor_w(VideoCapturer* capturer,
2830e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org                                  VideoProcessor* processor);
2840e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool IsScreencastRunning_w() const;
2852a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  virtual void OnMessage(rtc::Message *message);
2860e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2872a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::scoped_ptr<MediaEngineInterface> media_engine_;
2882a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::scoped_ptr<DataEngineInterface> data_media_engine_;
2892a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::scoped_ptr<DeviceManagerInterface> device_manager_;
2902a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::scoped_ptr<CaptureManager> capture_manager_;
2910e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool initialized_;
2922a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::Thread* main_thread_;
2932a86ce22ccc387dfa6f8a98ce3eba5c1e6f9e538buildbot@webrtc.org  rtc::Thread* worker_thread_;
2940e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
2950e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VoiceChannels voice_channels_;
2960e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VideoChannels video_channels_;
2970e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  DataChannels data_channels_;
2980e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  Soundclips soundclips_;
2990e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
3000e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  std::string audio_in_device_;
3010e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  std::string audio_out_device_;
3025528070a0c76057a000b877fc56ca4180ad2087bmallinath@webrtc.org  AudioOptions audio_options_;
3030e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  int audio_delay_offset_;
3040e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  int audio_output_volume_;
3050e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  std::string camera_device_;
3060e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VideoEncoderConfig default_video_encoder_config_;
3070e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  VideoRenderer* local_renderer_;
3080e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool enable_rtx_;
3090e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
3100e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool capturing_;
3110e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  bool monitoring_;
3120e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
3130e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // String containing currently set device. Note that this string is subtly
3140e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // different from camera_device_. E.g. camera_device_ will list unplugged
3150e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // but selected devices while this sting will be empty or contain current
3160e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // selected device.
3170e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // TODO(hellner): refactor the code such that there is no need to keep two
3180e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  // strings for video devices that have subtle differences in behavior.
3190e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org  std::string video_device_name_;
3200e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org};
3210e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
3220e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org}  // namespace cricket
3230e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org
3240e118e7129884fbea117e78d6f2068139a414dbhenrike@webrtc.org#endif  // TALK_SESSION_MEDIA_CHANNELMANAGER_H_
325