pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2014 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_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_H_ |
| 29 | #define TALK_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_H_ |
| 30 | |
| 31 | #include <map> |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 32 | #include <string> |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 33 | #include <vector> |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 34 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 35 | #include "talk/media/base/mediaengine.h" |
| 36 | #include "talk/media/webrtc/webrtcvideochannelfactory.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 37 | #include "webrtc/base/cpumonitor.h" |
| 38 | #include "webrtc/base/scoped_ptr.h" |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 39 | #include "webrtc/common_video/interface/i420_video_frame.h" |
| 40 | #include "webrtc/system_wrappers/interface/thread_annotations.h" |
| 41 | #include "webrtc/transport.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 42 | #include "webrtc/video_receive_stream.h" |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 43 | #include "webrtc/video_renderer.h" |
| 44 | #include "webrtc/video_send_stream.h" |
| 45 | |
| 46 | namespace webrtc { |
| 47 | class Call; |
| 48 | class VideoCaptureModule; |
| 49 | class VideoDecoder; |
| 50 | class VideoEncoder; |
| 51 | class VideoRender; |
| 52 | class VideoSendStreamInput; |
| 53 | class VideoReceiveStream; |
| 54 | } |
| 55 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 56 | namespace rtc { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 57 | class CpuMonitor; |
| 58 | class Thread; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 59 | } // namespace rtc |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 60 | |
| 61 | namespace cricket { |
| 62 | |
| 63 | class VideoCapturer; |
| 64 | class VideoFrame; |
| 65 | class VideoProcessor; |
| 66 | class VideoRenderer; |
| 67 | class VoiceMediaChannel; |
| 68 | class WebRtcVideoChannel2; |
| 69 | class WebRtcDecoderObserver; |
| 70 | class WebRtcEncoderObserver; |
| 71 | class WebRtcLocalStreamInfo; |
| 72 | class WebRtcRenderAdapter; |
| 73 | class WebRtcVideoChannelRecvInfo; |
| 74 | class WebRtcVideoChannelSendInfo; |
| 75 | class WebRtcVideoDecoderFactory; |
| 76 | class WebRtcVoiceEngine; |
| 77 | |
| 78 | struct CapturedFrame; |
| 79 | struct Device; |
| 80 | |
| 81 | class WebRtcVideoEngine2; |
| 82 | class WebRtcVideoChannel2; |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 83 | class WebRtcVideoRenderer; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 84 | |
pbos@webrtc.org | afb554f4 | 2014-08-12 23:17:13 +0000 | [diff] [blame] | 85 | class UnsignalledSsrcHandler { |
| 86 | public: |
| 87 | enum Action { |
| 88 | kDropPacket, |
| 89 | kDeliverPacket, |
| 90 | }; |
| 91 | virtual Action OnUnsignalledSsrc(VideoMediaChannel* engine, |
| 92 | uint32_t ssrc) = 0; |
| 93 | }; |
| 94 | |
| 95 | // TODO(pbos): Remove, use external handlers only. |
| 96 | class DefaultUnsignalledSsrcHandler : public UnsignalledSsrcHandler { |
| 97 | public: |
| 98 | DefaultUnsignalledSsrcHandler(); |
| 99 | virtual Action OnUnsignalledSsrc(VideoMediaChannel* engine, |
| 100 | uint32_t ssrc) OVERRIDE; |
| 101 | |
| 102 | VideoRenderer* GetDefaultRenderer() const; |
| 103 | void SetDefaultRenderer(VideoMediaChannel* channel, VideoRenderer* renderer); |
| 104 | |
| 105 | private: |
| 106 | uint32_t default_recv_ssrc_; |
| 107 | VideoRenderer* default_renderer_; |
| 108 | }; |
| 109 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 110 | class WebRtcVideoEncoderFactory2 { |
| 111 | public: |
pbos@webrtc.org | 0d523ee | 2014-06-05 09:10:55 +0000 | [diff] [blame] | 112 | virtual ~WebRtcVideoEncoderFactory2(); |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 113 | virtual std::vector<webrtc::VideoStream> CreateVideoStreams( |
| 114 | const VideoCodec& codec, |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 115 | const VideoOptions& options, |
buildbot@webrtc.org | d41eaeb | 2014-06-12 07:13:26 +0000 | [diff] [blame] | 116 | size_t num_streams); |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 117 | |
| 118 | virtual webrtc::VideoEncoder* CreateVideoEncoder( |
| 119 | const VideoCodec& codec, |
buildbot@webrtc.org | d41eaeb | 2014-06-12 07:13:26 +0000 | [diff] [blame] | 120 | const VideoOptions& options); |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 121 | |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 122 | virtual void* CreateVideoEncoderSettings( |
| 123 | const VideoCodec& codec, |
| 124 | const VideoOptions& options); |
| 125 | |
| 126 | virtual void DestroyVideoEncoderSettings(const VideoCodec& codec, |
| 127 | void* encoder_settings); |
| 128 | |
buildbot@webrtc.org | d41eaeb | 2014-06-12 07:13:26 +0000 | [diff] [blame] | 129 | virtual bool SupportsCodec(const cricket::VideoCodec& codec); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | // WebRtcVideoEngine2 is used for the new native WebRTC Video API (webrtc:1667). |
| 133 | class WebRtcVideoEngine2 : public sigslot::has_slots<> { |
| 134 | public: |
| 135 | // Creates the WebRtcVideoEngine2 with internal VideoCaptureModule. |
| 136 | WebRtcVideoEngine2(); |
pbos@webrtc.org | b648b9d | 2014-08-26 11:08:06 +0000 | [diff] [blame] | 137 | virtual ~WebRtcVideoEngine2(); |
| 138 | |
| 139 | // Use a custom WebRtcVideoChannelFactory (for testing purposes). |
| 140 | void SetChannelFactory(WebRtcVideoChannelFactory* channel_factory); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 141 | |
| 142 | // Basic video engine implementation. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 143 | bool Init(rtc::Thread* worker_thread); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 144 | void Terminate(); |
| 145 | |
| 146 | int GetCapabilities(); |
| 147 | bool SetOptions(const VideoOptions& options); |
| 148 | bool SetDefaultEncoderConfig(const VideoEncoderConfig& config); |
| 149 | VideoEncoderConfig GetDefaultEncoderConfig() const; |
| 150 | |
| 151 | WebRtcVideoChannel2* CreateChannel(VoiceMediaChannel* voice_channel); |
| 152 | |
| 153 | const std::vector<VideoCodec>& codecs() const; |
| 154 | const std::vector<RtpHeaderExtension>& rtp_header_extensions() const; |
| 155 | void SetLogging(int min_sev, const char* filter); |
| 156 | |
| 157 | bool EnableTimedRender(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 158 | // This is currently ignored. |
| 159 | sigslot::repeater2<VideoCapturer*, CaptureState> SignalCaptureStateChange; |
| 160 | |
| 161 | // Set the VoiceEngine for A/V sync. This can only be called before Init. |
| 162 | bool SetVoiceEngine(WebRtcVoiceEngine* voice_engine); |
| 163 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 164 | bool FindCodec(const VideoCodec& in); |
| 165 | bool CanSendCodec(const VideoCodec& in, |
| 166 | const VideoCodec& current, |
| 167 | VideoCodec* out); |
| 168 | // Check whether the supplied trace should be ignored. |
| 169 | bool ShouldIgnoreTrace(const std::string& trace); |
| 170 | |
| 171 | VideoFormat GetStartCaptureFormat() const { return default_codec_format_; } |
| 172 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 173 | rtc::CpuMonitor* cpu_monitor() { return cpu_monitor_.get(); } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 174 | |
buildbot@webrtc.org | d41eaeb | 2014-06-12 07:13:26 +0000 | [diff] [blame] | 175 | virtual WebRtcVideoEncoderFactory2* GetVideoEncoderFactory(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 176 | |
| 177 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 178 | rtc::Thread* worker_thread_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 179 | WebRtcVoiceEngine* voice_engine_; |
| 180 | std::vector<VideoCodec> video_codecs_; |
| 181 | std::vector<RtpHeaderExtension> rtp_header_extensions_; |
| 182 | VideoFormat default_codec_format_; |
| 183 | |
| 184 | bool initialized_; |
| 185 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 186 | // Critical section to protect the media processor register/unregister |
| 187 | // while processing a frame |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 188 | rtc::CriticalSection signal_media_critical_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 189 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 190 | rtc::scoped_ptr<rtc::CpuMonitor> cpu_monitor_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 191 | WebRtcVideoChannelFactory* channel_factory_; |
buildbot@webrtc.org | d41eaeb | 2014-06-12 07:13:26 +0000 | [diff] [blame] | 192 | WebRtcVideoEncoderFactory2 default_video_encoder_factory_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 193 | }; |
| 194 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 195 | class WebRtcVideoChannel2 : public rtc::MessageHandler, |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 196 | public VideoMediaChannel, |
| 197 | public webrtc::newapi::Transport { |
| 198 | public: |
| 199 | WebRtcVideoChannel2(WebRtcVideoEngine2* engine, |
| 200 | VoiceMediaChannel* voice_channel, |
| 201 | WebRtcVideoEncoderFactory2* encoder_factory); |
| 202 | // For testing purposes insert a pre-constructed call to verify that |
| 203 | // WebRtcVideoChannel2 calls the correct corresponding methods. |
| 204 | WebRtcVideoChannel2(webrtc::Call* call, |
| 205 | WebRtcVideoEngine2* engine, |
| 206 | WebRtcVideoEncoderFactory2* encoder_factory); |
| 207 | ~WebRtcVideoChannel2(); |
| 208 | bool Init(); |
| 209 | |
| 210 | // VideoMediaChannel implementation |
| 211 | virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) OVERRIDE; |
| 212 | virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) OVERRIDE; |
| 213 | virtual bool GetSendCodec(VideoCodec* send_codec) OVERRIDE; |
| 214 | virtual bool SetSendStreamFormat(uint32 ssrc, |
| 215 | const VideoFormat& format) OVERRIDE; |
| 216 | virtual bool SetRender(bool render) OVERRIDE; |
| 217 | virtual bool SetSend(bool send) OVERRIDE; |
| 218 | |
| 219 | virtual bool AddSendStream(const StreamParams& sp) OVERRIDE; |
| 220 | virtual bool RemoveSendStream(uint32 ssrc) OVERRIDE; |
| 221 | virtual bool AddRecvStream(const StreamParams& sp) OVERRIDE; |
| 222 | virtual bool RemoveRecvStream(uint32 ssrc) OVERRIDE; |
| 223 | virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) OVERRIDE; |
| 224 | virtual bool GetStats(const StatsOptions& options, |
| 225 | VideoMediaInfo* info) OVERRIDE; |
| 226 | virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) OVERRIDE; |
| 227 | virtual bool SendIntraFrame() OVERRIDE; |
| 228 | virtual bool RequestIntraFrame() OVERRIDE; |
| 229 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 230 | virtual void OnPacketReceived(rtc::Buffer* packet, |
| 231 | const rtc::PacketTime& packet_time) |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 232 | OVERRIDE; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 233 | virtual void OnRtcpReceived(rtc::Buffer* packet, |
| 234 | const rtc::PacketTime& packet_time) |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 235 | OVERRIDE; |
| 236 | virtual void OnReadyToSend(bool ready) OVERRIDE; |
| 237 | virtual bool MuteStream(uint32 ssrc, bool mute) OVERRIDE; |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 238 | |
| 239 | // Set send/receive RTP header extensions. This must be done before creating |
| 240 | // streams as it only has effect on future streams. |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 241 | virtual bool SetRecvRtpHeaderExtensions( |
| 242 | const std::vector<RtpHeaderExtension>& extensions) OVERRIDE; |
| 243 | virtual bool SetSendRtpHeaderExtensions( |
| 244 | const std::vector<RtpHeaderExtension>& extensions) OVERRIDE; |
| 245 | virtual bool SetStartSendBandwidth(int bps) OVERRIDE; |
| 246 | virtual bool SetMaxSendBandwidth(int bps) OVERRIDE; |
| 247 | virtual bool SetOptions(const VideoOptions& options) OVERRIDE; |
| 248 | virtual bool GetOptions(VideoOptions* options) const OVERRIDE { |
| 249 | *options = options_; |
| 250 | return true; |
| 251 | } |
| 252 | virtual void SetInterface(NetworkInterface* iface) OVERRIDE; |
| 253 | virtual void UpdateAspectRatio(int ratio_w, int ratio_h) OVERRIDE; |
| 254 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 255 | virtual void OnMessage(rtc::Message* msg) OVERRIDE; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 256 | |
| 257 | // Implemented for VideoMediaChannelTest. |
| 258 | bool sending() const { return sending_; } |
buildbot@webrtc.org | 2c0fb05 | 2014-08-13 16:47:12 +0000 | [diff] [blame] | 259 | uint32 GetDefaultSendChannelSsrc() { return default_send_ssrc_; } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 260 | bool GetRenderer(uint32 ssrc, VideoRenderer** renderer); |
| 261 | |
| 262 | private: |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 263 | void ConfigureReceiverRtp(webrtc::VideoReceiveStream::Config* config, |
| 264 | const StreamParams& sp) const; |
| 265 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 266 | struct VideoCodecSettings { |
| 267 | VideoCodecSettings(); |
| 268 | |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 269 | VideoCodec codec; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 270 | webrtc::FecConfig fec; |
| 271 | int rtx_payload_type; |
| 272 | }; |
| 273 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 274 | // Wrapper for the sender part, this is where the capturer is connected and |
| 275 | // frames are then converted from cricket frames to webrtc frames. |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 276 | class WebRtcVideoSendStream : public sigslot::has_slots<> { |
| 277 | public: |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 278 | WebRtcVideoSendStream( |
| 279 | webrtc::Call* call, |
| 280 | WebRtcVideoEncoderFactory2* encoder_factory, |
| 281 | const VideoOptions& options, |
| 282 | const Settable<VideoCodecSettings>& codec_settings, |
| 283 | const StreamParams& sp, |
| 284 | const std::vector<webrtc::RtpExtension>& rtp_extensions); |
| 285 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 286 | ~WebRtcVideoSendStream(); |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 287 | void SetOptions(const VideoOptions& options); |
| 288 | void SetCodec(const VideoCodecSettings& codec); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 289 | void SetRtpExtensions( |
| 290 | const std::vector<webrtc::RtpExtension>& rtp_extensions); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 291 | |
| 292 | void InputFrame(VideoCapturer* capturer, const VideoFrame* frame); |
| 293 | bool SetCapturer(VideoCapturer* capturer); |
| 294 | bool SetVideoFormat(const VideoFormat& format); |
pbos@webrtc.org | ef8bb8d | 2014-08-13 21:36:18 +0000 | [diff] [blame] | 295 | void MuteStream(bool mute); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 296 | bool DisconnectCapturer(); |
| 297 | |
| 298 | void Start(); |
| 299 | void Stop(); |
| 300 | |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 301 | VideoSenderInfo GetVideoSenderInfo(); |
| 302 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 303 | private: |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 304 | // Parameters needed to reconstruct the underlying stream. |
| 305 | // webrtc::VideoSendStream doesn't support setting a lot of options on the |
| 306 | // fly, so when those need to be changed we tear down and reconstruct with |
| 307 | // similar parameters depending on which options changed etc. |
| 308 | struct VideoSendStreamParameters { |
| 309 | VideoSendStreamParameters( |
| 310 | const webrtc::VideoSendStream::Config& config, |
| 311 | const VideoOptions& options, |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 312 | const Settable<VideoCodecSettings>& codec_settings); |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 313 | webrtc::VideoSendStream::Config config; |
| 314 | VideoOptions options; |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 315 | Settable<VideoCodecSettings> codec_settings; |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 316 | // Sent resolutions + bitrates etc. by the underlying VideoSendStream, |
| 317 | // typically changes when setting a new resolution or reconfiguring |
| 318 | // bitrates. |
| 319 | std::vector<webrtc::VideoStream> video_streams; |
| 320 | }; |
| 321 | |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 322 | void SetCodecAndOptions(const VideoCodecSettings& codec, |
| 323 | const VideoOptions& options); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 324 | void RecreateWebRtcStream(); |
pbos@webrtc.org | c4175b9 | 2014-09-03 15:25:49 +0000 | [diff] [blame^] | 325 | // When |override_max| is false constrain width/height to codec dimensions. |
| 326 | void SetDimensions(int width, int height, bool override_max); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 327 | |
| 328 | webrtc::Call* const call_; |
| 329 | WebRtcVideoEncoderFactory2* const encoder_factory_; |
| 330 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 331 | rtc::CriticalSection lock_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 332 | webrtc::VideoSendStream* stream_ GUARDED_BY(lock_); |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 333 | VideoSendStreamParameters parameters_ GUARDED_BY(lock_); |
| 334 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 335 | VideoCapturer* capturer_ GUARDED_BY(lock_); |
| 336 | bool sending_ GUARDED_BY(lock_); |
| 337 | bool muted_ GUARDED_BY(lock_); |
| 338 | VideoFormat format_ GUARDED_BY(lock_); |
| 339 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 340 | rtc::CriticalSection frame_lock_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 341 | webrtc::I420VideoFrame video_frame_ GUARDED_BY(frame_lock_); |
| 342 | }; |
| 343 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 344 | // Wrapper for the receiver part, contains configs etc. that are needed to |
| 345 | // reconstruct the underlying VideoReceiveStream. Also serves as a wrapper |
| 346 | // between webrtc::VideoRenderer and cricket::VideoRenderer. |
| 347 | class WebRtcVideoReceiveStream : public webrtc::VideoRenderer { |
| 348 | public: |
| 349 | WebRtcVideoReceiveStream( |
| 350 | webrtc::Call*, |
| 351 | const webrtc::VideoReceiveStream::Config& config, |
| 352 | const std::vector<VideoCodecSettings>& recv_codecs); |
| 353 | ~WebRtcVideoReceiveStream(); |
| 354 | |
| 355 | void SetRecvCodecs(const std::vector<VideoCodecSettings>& recv_codecs); |
| 356 | void SetRtpExtensions(const std::vector<webrtc::RtpExtension>& extensions); |
| 357 | |
| 358 | virtual void RenderFrame(const webrtc::I420VideoFrame& frame, |
| 359 | int time_to_render_ms) OVERRIDE; |
| 360 | |
| 361 | void SetRenderer(cricket::VideoRenderer* renderer); |
| 362 | cricket::VideoRenderer* GetRenderer(); |
| 363 | |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 364 | VideoReceiverInfo GetVideoReceiverInfo(); |
| 365 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 366 | private: |
| 367 | void SetSize(int width, int height); |
| 368 | void RecreateWebRtcStream(); |
| 369 | |
| 370 | webrtc::Call* const call_; |
| 371 | |
| 372 | webrtc::VideoReceiveStream* stream_; |
| 373 | webrtc::VideoReceiveStream::Config config_; |
| 374 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 375 | rtc::CriticalSection renderer_lock_; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 376 | cricket::VideoRenderer* renderer_ GUARDED_BY(renderer_lock_); |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 377 | int last_width_ GUARDED_BY(renderer_lock_); |
| 378 | int last_height_ GUARDED_BY(renderer_lock_); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 379 | }; |
| 380 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 381 | void Construct(webrtc::Call* call, WebRtcVideoEngine2* engine); |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 382 | void SetDefaultOptions(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 383 | |
| 384 | virtual bool SendRtp(const uint8_t* data, size_t len) OVERRIDE; |
| 385 | virtual bool SendRtcp(const uint8_t* data, size_t len) OVERRIDE; |
| 386 | |
| 387 | void StartAllSendStreams(); |
| 388 | void StopAllSendStreams(); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 389 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 390 | static std::vector<VideoCodecSettings> MapCodecs( |
| 391 | const std::vector<VideoCodec>& codecs); |
| 392 | std::vector<VideoCodecSettings> FilterSupportedCodecs( |
| 393 | const std::vector<VideoCodecSettings>& mapped_codecs); |
| 394 | |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 395 | void FillSenderStats(VideoMediaInfo* info); |
| 396 | void FillReceiverStats(VideoMediaInfo* info); |
| 397 | void FillBandwidthEstimationStats(VideoMediaInfo* info); |
| 398 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 399 | uint32_t rtcp_receiver_report_ssrc_; |
| 400 | bool sending_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 401 | rtc::scoped_ptr<webrtc::Call> call_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 402 | uint32_t default_send_ssrc_; |
pbos@webrtc.org | afb554f4 | 2014-08-12 23:17:13 +0000 | [diff] [blame] | 403 | |
| 404 | DefaultUnsignalledSsrcHandler default_unsignalled_ssrc_handler_; |
| 405 | UnsignalledSsrcHandler* const unsignalled_ssrc_handler_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 406 | |
| 407 | // Using primary-ssrc (first ssrc) as key. |
| 408 | std::map<uint32, WebRtcVideoSendStream*> send_streams_; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 409 | std::map<uint32, WebRtcVideoReceiveStream*> receive_streams_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 410 | |
| 411 | Settable<VideoCodecSettings> send_codec_; |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 412 | std::vector<webrtc::RtpExtension> send_rtp_extensions_; |
| 413 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 414 | WebRtcVideoEncoderFactory2* const encoder_factory_; |
| 415 | std::vector<VideoCodecSettings> recv_codecs_; |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 416 | std::vector<webrtc::RtpExtension> recv_rtp_extensions_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 417 | VideoOptions options_; |
| 418 | }; |
| 419 | |
| 420 | } // namespace cricket |
| 421 | |
| 422 | #endif // TALK_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_H_ |