| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * libjingle | |
| 3 * Copyright 2004 Google Inc. | |
| 4 * | |
| 5 * Redistribution and use in source and binary forms, with or without | |
| 6 * modification, are permitted provided that the following conditions are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | |
| 9 * this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
| 11 * this list of conditions and the following disclaimer in the documentation | |
| 12 * and/or other materials provided with the distribution. | |
| 13 * 3. The name of the author may not be used to endorse or promote products | |
| 14 * derived from this software without specific prior written permission. | |
| 15 * | |
| 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
| 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
| 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
| 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
| 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
| 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
| 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
| 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 26 */ | |
| 27 | |
| 28 #ifndef TALK_SESSION_MEDIA_CHANNELMANAGER_H_ | |
| 29 #define TALK_SESSION_MEDIA_CHANNELMANAGER_H_ | |
| 30 | |
| 31 #include <string> | |
| 32 #include <vector> | |
| 33 | |
| 34 #include "talk/session/media/voicechannel.h" | |
| 35 #include "webrtc/base/criticalsection.h" | |
| 36 #include "webrtc/base/fileutils.h" | |
| 37 #include "webrtc/base/sigslotrepeater.h" | |
| 38 #include "webrtc/base/thread.h" | |
| 39 #include "webrtc/media/base/capturemanager.h" | |
| 40 #include "webrtc/media/base/mediaengine.h" | |
| 41 | |
| 42 namespace webrtc { | |
| 43 class MediaControllerInterface; | |
| 44 } | |
| 45 namespace cricket { | |
| 46 | |
| 47 class VoiceChannel; | |
| 48 | |
| 49 // ChannelManager allows the MediaEngine to run on a separate thread, and takes | |
| 50 // care of marshalling calls between threads. It also creates and keeps track of | |
| 51 // voice and video channels; by doing so, it can temporarily pause all the | |
| 52 // channels when a new audio or video device is chosen. The voice and video | |
| 53 // channels are stored in separate vectors, to easily allow operations on just | |
| 54 // voice or just video channels. | |
| 55 // ChannelManager also allows the application to discover what devices it has | |
| 56 // using device manager. | |
| 57 class ChannelManager : public rtc::MessageHandler, | |
| 58 public sigslot::has_slots<> { | |
| 59 public: | |
| 60 // For testing purposes. Allows the media engine and data media | |
| 61 // engine and dev manager to be mocks. The ChannelManager takes | |
| 62 // ownership of these objects. | |
| 63 ChannelManager(MediaEngineInterface* me, | |
| 64 DataEngineInterface* dme, | |
| 65 CaptureManager* cm, | |
| 66 rtc::Thread* worker); | |
| 67 // Same as above, but gives an easier default DataEngine. | |
| 68 ChannelManager(MediaEngineInterface* me, | |
| 69 rtc::Thread* worker); | |
| 70 ~ChannelManager(); | |
| 71 | |
| 72 // Accessors for the worker thread, allowing it to be set after construction, | |
| 73 // but before Init. set_worker_thread will return false if called after Init. | |
| 74 rtc::Thread* worker_thread() const { return worker_thread_; } | |
| 75 bool set_worker_thread(rtc::Thread* thread) { | |
| 76 if (initialized_) return false; | |
| 77 worker_thread_ = thread; | |
| 78 return true; | |
| 79 } | |
| 80 | |
| 81 MediaEngineInterface* media_engine() { return media_engine_.get(); } | |
| 82 | |
| 83 // Retrieves the list of supported audio & video codec types. | |
| 84 // Can be called before starting the media engine. | |
| 85 void GetSupportedAudioCodecs(std::vector<AudioCodec>* codecs) const; | |
| 86 void GetSupportedAudioRtpHeaderExtensions(RtpHeaderExtensions* ext) const; | |
| 87 void GetSupportedVideoCodecs(std::vector<VideoCodec>* codecs) const; | |
| 88 void GetSupportedVideoRtpHeaderExtensions(RtpHeaderExtensions* ext) const; | |
| 89 void GetSupportedDataCodecs(std::vector<DataCodec>* codecs) const; | |
| 90 | |
| 91 // Indicates whether the media engine is started. | |
| 92 bool initialized() const { return initialized_; } | |
| 93 // Starts up the media engine. | |
| 94 bool Init(); | |
| 95 // Shuts down the media engine. | |
| 96 void Terminate(); | |
| 97 | |
| 98 // The operations below all occur on the worker thread. | |
| 99 // Creates a voice channel, to be associated with the specified session. | |
| 100 VoiceChannel* CreateVoiceChannel( | |
| 101 webrtc::MediaControllerInterface* media_controller, | |
| 102 TransportController* transport_controller, | |
| 103 const std::string& content_name, | |
| 104 bool rtcp, | |
| 105 const AudioOptions& options); | |
| 106 // Destroys a voice channel created with the Create API. | |
| 107 void DestroyVoiceChannel(VoiceChannel* voice_channel); | |
| 108 // Creates a video channel, synced with the specified voice channel, and | |
| 109 // associated with the specified session. | |
| 110 VideoChannel* CreateVideoChannel( | |
| 111 webrtc::MediaControllerInterface* media_controller, | |
| 112 TransportController* transport_controller, | |
| 113 const std::string& content_name, | |
| 114 bool rtcp, | |
| 115 const VideoOptions& options); | |
| 116 // Destroys a video channel created with the Create API. | |
| 117 void DestroyVideoChannel(VideoChannel* video_channel); | |
| 118 DataChannel* CreateDataChannel(TransportController* transport_controller, | |
| 119 const std::string& content_name, | |
| 120 bool rtcp, | |
| 121 DataChannelType data_channel_type); | |
| 122 // Destroys a data channel created with the Create API. | |
| 123 void DestroyDataChannel(DataChannel* data_channel); | |
| 124 | |
| 125 // Indicates whether any channels exist. | |
| 126 bool has_channels() const { | |
| 127 return (!voice_channels_.empty() || !video_channels_.empty()); | |
| 128 } | |
| 129 | |
| 130 bool GetOutputVolume(int* level); | |
| 131 bool SetOutputVolume(int level); | |
| 132 // RTX will be enabled/disabled in engines that support it. The supporting | |
| 133 // engines will start offering an RTX codec. Must be called before Init(). | |
| 134 bool SetVideoRtxEnabled(bool enable); | |
| 135 | |
| 136 // Starts/stops the local microphone and enables polling of the input level. | |
| 137 bool capturing() const { return capturing_; } | |
| 138 | |
| 139 // Gets capturer's supported formats in a thread safe manner | |
| 140 std::vector<cricket::VideoFormat> GetSupportedFormats( | |
| 141 VideoCapturer* capturer) const; | |
| 142 // The following are done in the new "CaptureManager" style that | |
| 143 // all local video capturers, processors, and managers should move to. | |
| 144 // TODO(pthatcher): Make methods nicer by having start return a handle that | |
| 145 // can be used for stop and restart, rather than needing to pass around | |
| 146 // formats a a pseudo-handle. | |
| 147 bool StartVideoCapture(VideoCapturer* video_capturer, | |
| 148 const VideoFormat& video_format); | |
| 149 // When muting, produce black frames then pause the camera. | |
| 150 // When unmuting, start the camera. Camera starts unmuted. | |
| 151 bool MuteToBlackThenPause(VideoCapturer* video_capturer, bool muted); | |
| 152 bool StopVideoCapture(VideoCapturer* video_capturer, | |
| 153 const VideoFormat& video_format); | |
| 154 bool RestartVideoCapture(VideoCapturer* video_capturer, | |
| 155 const VideoFormat& previous_format, | |
| 156 const VideoFormat& desired_format, | |
| 157 CaptureManager::RestartOptions options); | |
| 158 | |
| 159 virtual void AddVideoSink(VideoCapturer* video_capturer, | |
| 160 rtc::VideoSinkInterface<VideoFrame>* sink); | |
| 161 virtual void RemoveVideoSink(VideoCapturer* video_capturer, | |
| 162 rtc::VideoSinkInterface<VideoFrame>* sink); | |
| 163 bool IsScreencastRunning() const; | |
| 164 | |
| 165 // The operations below occur on the main thread. | |
| 166 | |
| 167 // Starts AEC dump using existing file, with a specified maximum file size in | |
| 168 // bytes. When the limit is reached, logging will stop and the file will be | |
| 169 // closed. If max_size_bytes is set to <= 0, no limit will be used. | |
| 170 bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes); | |
| 171 | |
| 172 // Stops recording AEC dump. | |
| 173 void StopAecDump(); | |
| 174 | |
| 175 // Starts RtcEventLog using existing file. | |
| 176 bool StartRtcEventLog(rtc::PlatformFile file); | |
| 177 | |
| 178 // Stops logging RtcEventLog. | |
| 179 void StopRtcEventLog(); | |
| 180 | |
| 181 sigslot::signal2<VideoCapturer*, CaptureState> SignalVideoCaptureStateChange; | |
| 182 | |
| 183 private: | |
| 184 typedef std::vector<VoiceChannel*> VoiceChannels; | |
| 185 typedef std::vector<VideoChannel*> VideoChannels; | |
| 186 typedef std::vector<DataChannel*> DataChannels; | |
| 187 | |
| 188 void Construct(MediaEngineInterface* me, | |
| 189 DataEngineInterface* dme, | |
| 190 CaptureManager* cm, | |
| 191 rtc::Thread* worker_thread); | |
| 192 bool InitMediaEngine_w(); | |
| 193 void DestructorDeletes_w(); | |
| 194 void Terminate_w(); | |
| 195 VoiceChannel* CreateVoiceChannel_w( | |
| 196 webrtc::MediaControllerInterface* media_controller, | |
| 197 TransportController* transport_controller, | |
| 198 const std::string& content_name, | |
| 199 bool rtcp, | |
| 200 const AudioOptions& options); | |
| 201 void DestroyVoiceChannel_w(VoiceChannel* voice_channel); | |
| 202 VideoChannel* CreateVideoChannel_w( | |
| 203 webrtc::MediaControllerInterface* media_controller, | |
| 204 TransportController* transport_controller, | |
| 205 const std::string& content_name, | |
| 206 bool rtcp, | |
| 207 const VideoOptions& options); | |
| 208 void DestroyVideoChannel_w(VideoChannel* video_channel); | |
| 209 DataChannel* CreateDataChannel_w(TransportController* transport_controller, | |
| 210 const std::string& content_name, | |
| 211 bool rtcp, | |
| 212 DataChannelType data_channel_type); | |
| 213 void DestroyDataChannel_w(DataChannel* data_channel); | |
| 214 void OnVideoCaptureStateChange(VideoCapturer* capturer, | |
| 215 CaptureState result); | |
| 216 void GetSupportedFormats_w( | |
| 217 VideoCapturer* capturer, | |
| 218 std::vector<cricket::VideoFormat>* out_formats) const; | |
| 219 bool IsScreencastRunning_w() const; | |
| 220 virtual void OnMessage(rtc::Message *message); | |
| 221 | |
| 222 rtc::scoped_ptr<MediaEngineInterface> media_engine_; | |
| 223 rtc::scoped_ptr<DataEngineInterface> data_media_engine_; | |
| 224 rtc::scoped_ptr<CaptureManager> capture_manager_; | |
| 225 bool initialized_; | |
| 226 rtc::Thread* main_thread_; | |
| 227 rtc::Thread* worker_thread_; | |
| 228 | |
| 229 VoiceChannels voice_channels_; | |
| 230 VideoChannels video_channels_; | |
| 231 DataChannels data_channels_; | |
| 232 | |
| 233 int audio_output_volume_; | |
| 234 VideoRenderer* local_renderer_; | |
| 235 bool enable_rtx_; | |
| 236 | |
| 237 bool capturing_; | |
| 238 }; | |
| 239 | |
| 240 } // namespace cricket | |
| 241 | |
| 242 #endif // TALK_SESSION_MEDIA_CHANNELMANAGER_H_ | |
| OLD | NEW |