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(); |
| 137 | // Custom WebRtcVideoChannelFactory for testing purposes. |
| 138 | explicit WebRtcVideoEngine2(WebRtcVideoChannelFactory* channel_factory); |
| 139 | ~WebRtcVideoEngine2(); |
| 140 | |
| 141 | // Basic video engine implementation. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 142 | bool Init(rtc::Thread* worker_thread); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 143 | void Terminate(); |
| 144 | |
| 145 | int GetCapabilities(); |
| 146 | bool SetOptions(const VideoOptions& options); |
| 147 | bool SetDefaultEncoderConfig(const VideoEncoderConfig& config); |
| 148 | VideoEncoderConfig GetDefaultEncoderConfig() const; |
| 149 | |
| 150 | WebRtcVideoChannel2* CreateChannel(VoiceMediaChannel* voice_channel); |
| 151 | |
| 152 | const std::vector<VideoCodec>& codecs() const; |
| 153 | const std::vector<RtpHeaderExtension>& rtp_header_extensions() const; |
| 154 | void SetLogging(int min_sev, const char* filter); |
| 155 | |
| 156 | bool EnableTimedRender(); |
| 157 | // No-op, never used. |
| 158 | bool SetLocalRenderer(VideoRenderer* renderer); |
| 159 | // This is currently ignored. |
| 160 | sigslot::repeater2<VideoCapturer*, CaptureState> SignalCaptureStateChange; |
| 161 | |
| 162 | // Set the VoiceEngine for A/V sync. This can only be called before Init. |
| 163 | bool SetVoiceEngine(WebRtcVoiceEngine* voice_engine); |
| 164 | |
| 165 | // Functions called by WebRtcVideoChannel2. |
| 166 | const VideoFormat& default_codec_format() const { |
| 167 | return default_codec_format_; |
| 168 | } |
| 169 | |
| 170 | bool FindCodec(const VideoCodec& in); |
| 171 | bool CanSendCodec(const VideoCodec& in, |
| 172 | const VideoCodec& current, |
| 173 | VideoCodec* out); |
| 174 | // Check whether the supplied trace should be ignored. |
| 175 | bool ShouldIgnoreTrace(const std::string& trace); |
| 176 | |
| 177 | VideoFormat GetStartCaptureFormat() const { return default_codec_format_; } |
| 178 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 179 | rtc::CpuMonitor* cpu_monitor() { return cpu_monitor_.get(); } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 180 | |
buildbot@webrtc.org | d41eaeb | 2014-06-12 07:13:26 +0000 | [diff] [blame] | 181 | virtual WebRtcVideoEncoderFactory2* GetVideoEncoderFactory(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 182 | |
| 183 | private: |
| 184 | void Construct(WebRtcVideoChannelFactory* channel_factory, |
| 185 | WebRtcVoiceEngine* voice_engine, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 186 | rtc::CpuMonitor* cpu_monitor); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 187 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 188 | rtc::Thread* worker_thread_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 189 | WebRtcVoiceEngine* voice_engine_; |
| 190 | std::vector<VideoCodec> video_codecs_; |
| 191 | std::vector<RtpHeaderExtension> rtp_header_extensions_; |
| 192 | VideoFormat default_codec_format_; |
| 193 | |
| 194 | bool initialized_; |
| 195 | |
| 196 | bool capture_started_; |
| 197 | |
| 198 | // Critical section to protect the media processor register/unregister |
| 199 | // while processing a frame |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 200 | rtc::CriticalSection signal_media_critical_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 201 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 202 | rtc::scoped_ptr<rtc::CpuMonitor> cpu_monitor_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 203 | WebRtcVideoChannelFactory* channel_factory_; |
buildbot@webrtc.org | d41eaeb | 2014-06-12 07:13:26 +0000 | [diff] [blame] | 204 | WebRtcVideoEncoderFactory2 default_video_encoder_factory_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 205 | }; |
| 206 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 207 | class WebRtcVideoChannel2 : public rtc::MessageHandler, |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 208 | public VideoMediaChannel, |
| 209 | public webrtc::newapi::Transport { |
| 210 | public: |
| 211 | WebRtcVideoChannel2(WebRtcVideoEngine2* engine, |
| 212 | VoiceMediaChannel* voice_channel, |
| 213 | WebRtcVideoEncoderFactory2* encoder_factory); |
| 214 | // For testing purposes insert a pre-constructed call to verify that |
| 215 | // WebRtcVideoChannel2 calls the correct corresponding methods. |
| 216 | WebRtcVideoChannel2(webrtc::Call* call, |
| 217 | WebRtcVideoEngine2* engine, |
| 218 | WebRtcVideoEncoderFactory2* encoder_factory); |
| 219 | ~WebRtcVideoChannel2(); |
| 220 | bool Init(); |
| 221 | |
| 222 | // VideoMediaChannel implementation |
| 223 | virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) OVERRIDE; |
| 224 | virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) OVERRIDE; |
| 225 | virtual bool GetSendCodec(VideoCodec* send_codec) OVERRIDE; |
| 226 | virtual bool SetSendStreamFormat(uint32 ssrc, |
| 227 | const VideoFormat& format) OVERRIDE; |
| 228 | virtual bool SetRender(bool render) OVERRIDE; |
| 229 | virtual bool SetSend(bool send) OVERRIDE; |
| 230 | |
| 231 | virtual bool AddSendStream(const StreamParams& sp) OVERRIDE; |
| 232 | virtual bool RemoveSendStream(uint32 ssrc) OVERRIDE; |
| 233 | virtual bool AddRecvStream(const StreamParams& sp) OVERRIDE; |
| 234 | virtual bool RemoveRecvStream(uint32 ssrc) OVERRIDE; |
| 235 | virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) OVERRIDE; |
| 236 | virtual bool GetStats(const StatsOptions& options, |
| 237 | VideoMediaInfo* info) OVERRIDE; |
| 238 | virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) OVERRIDE; |
| 239 | virtual bool SendIntraFrame() OVERRIDE; |
| 240 | virtual bool RequestIntraFrame() OVERRIDE; |
| 241 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 242 | virtual void OnPacketReceived(rtc::Buffer* packet, |
| 243 | const rtc::PacketTime& packet_time) |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 244 | OVERRIDE; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 245 | virtual void OnRtcpReceived(rtc::Buffer* packet, |
| 246 | const rtc::PacketTime& packet_time) |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 247 | OVERRIDE; |
| 248 | virtual void OnReadyToSend(bool ready) OVERRIDE; |
| 249 | virtual bool MuteStream(uint32 ssrc, bool mute) OVERRIDE; |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 250 | |
| 251 | // Set send/receive RTP header extensions. This must be done before creating |
| 252 | // streams as it only has effect on future streams. |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 253 | virtual bool SetRecvRtpHeaderExtensions( |
| 254 | const std::vector<RtpHeaderExtension>& extensions) OVERRIDE; |
| 255 | virtual bool SetSendRtpHeaderExtensions( |
| 256 | const std::vector<RtpHeaderExtension>& extensions) OVERRIDE; |
| 257 | virtual bool SetStartSendBandwidth(int bps) OVERRIDE; |
| 258 | virtual bool SetMaxSendBandwidth(int bps) OVERRIDE; |
| 259 | virtual bool SetOptions(const VideoOptions& options) OVERRIDE; |
| 260 | virtual bool GetOptions(VideoOptions* options) const OVERRIDE { |
| 261 | *options = options_; |
| 262 | return true; |
| 263 | } |
| 264 | virtual void SetInterface(NetworkInterface* iface) OVERRIDE; |
| 265 | virtual void UpdateAspectRatio(int ratio_w, int ratio_h) OVERRIDE; |
| 266 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 267 | virtual void OnMessage(rtc::Message* msg) OVERRIDE; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 268 | |
| 269 | // Implemented for VideoMediaChannelTest. |
| 270 | bool sending() const { return sending_; } |
buildbot@webrtc.org | 2c0fb05 | 2014-08-13 16:47:12 +0000 | [diff] [blame] | 271 | uint32 GetDefaultSendChannelSsrc() { return default_send_ssrc_; } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 272 | bool GetRenderer(uint32 ssrc, VideoRenderer** renderer); |
| 273 | |
| 274 | private: |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 275 | void ConfigureReceiverRtp(webrtc::VideoReceiveStream::Config* config, |
| 276 | const StreamParams& sp) const; |
| 277 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 278 | struct VideoCodecSettings { |
| 279 | VideoCodecSettings(); |
| 280 | |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 281 | VideoCodec codec; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 282 | webrtc::FecConfig fec; |
| 283 | int rtx_payload_type; |
| 284 | }; |
| 285 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 286 | // Wrapper for the sender part, this is where the capturer is connected and |
| 287 | // frames are then converted from cricket frames to webrtc frames. |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 288 | class WebRtcVideoSendStream : public sigslot::has_slots<> { |
| 289 | public: |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 290 | WebRtcVideoSendStream( |
| 291 | webrtc::Call* call, |
| 292 | WebRtcVideoEncoderFactory2* encoder_factory, |
| 293 | const VideoOptions& options, |
| 294 | const Settable<VideoCodecSettings>& codec_settings, |
| 295 | const StreamParams& sp, |
| 296 | const std::vector<webrtc::RtpExtension>& rtp_extensions); |
| 297 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 298 | ~WebRtcVideoSendStream(); |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 299 | void SetOptions(const VideoOptions& options); |
| 300 | void SetCodec(const VideoCodecSettings& codec); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 301 | void SetRtpExtensions( |
| 302 | const std::vector<webrtc::RtpExtension>& rtp_extensions); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 303 | |
| 304 | void InputFrame(VideoCapturer* capturer, const VideoFrame* frame); |
| 305 | bool SetCapturer(VideoCapturer* capturer); |
| 306 | bool SetVideoFormat(const VideoFormat& format); |
pbos@webrtc.org | ef8bb8d | 2014-08-13 21:36:18 +0000 | [diff] [blame^] | 307 | void MuteStream(bool mute); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 308 | bool DisconnectCapturer(); |
| 309 | |
| 310 | void Start(); |
| 311 | void Stop(); |
| 312 | |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 313 | VideoSenderInfo GetVideoSenderInfo(); |
| 314 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 315 | private: |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 316 | // Parameters needed to reconstruct the underlying stream. |
| 317 | // webrtc::VideoSendStream doesn't support setting a lot of options on the |
| 318 | // fly, so when those need to be changed we tear down and reconstruct with |
| 319 | // similar parameters depending on which options changed etc. |
| 320 | struct VideoSendStreamParameters { |
| 321 | VideoSendStreamParameters( |
| 322 | const webrtc::VideoSendStream::Config& config, |
| 323 | const VideoOptions& options, |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 324 | const Settable<VideoCodecSettings>& codec_settings); |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 325 | webrtc::VideoSendStream::Config config; |
| 326 | VideoOptions options; |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 327 | Settable<VideoCodecSettings> codec_settings; |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 328 | // Sent resolutions + bitrates etc. by the underlying VideoSendStream, |
| 329 | // typically changes when setting a new resolution or reconfiguring |
| 330 | // bitrates. |
| 331 | std::vector<webrtc::VideoStream> video_streams; |
| 332 | }; |
| 333 | |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 334 | void SetCodecAndOptions(const VideoCodecSettings& codec, |
| 335 | const VideoOptions& options); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 336 | void RecreateWebRtcStream(); |
| 337 | void SetDimensions(int width, int height); |
| 338 | |
| 339 | webrtc::Call* const call_; |
| 340 | WebRtcVideoEncoderFactory2* const encoder_factory_; |
| 341 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 342 | rtc::CriticalSection lock_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 343 | webrtc::VideoSendStream* stream_ GUARDED_BY(lock_); |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 344 | VideoSendStreamParameters parameters_ GUARDED_BY(lock_); |
| 345 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 346 | VideoCapturer* capturer_ GUARDED_BY(lock_); |
| 347 | bool sending_ GUARDED_BY(lock_); |
| 348 | bool muted_ GUARDED_BY(lock_); |
| 349 | VideoFormat format_ GUARDED_BY(lock_); |
| 350 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 351 | rtc::CriticalSection frame_lock_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 352 | webrtc::I420VideoFrame video_frame_ GUARDED_BY(frame_lock_); |
| 353 | }; |
| 354 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 355 | // Wrapper for the receiver part, contains configs etc. that are needed to |
| 356 | // reconstruct the underlying VideoReceiveStream. Also serves as a wrapper |
| 357 | // between webrtc::VideoRenderer and cricket::VideoRenderer. |
| 358 | class WebRtcVideoReceiveStream : public webrtc::VideoRenderer { |
| 359 | public: |
| 360 | WebRtcVideoReceiveStream( |
| 361 | webrtc::Call*, |
| 362 | const webrtc::VideoReceiveStream::Config& config, |
| 363 | const std::vector<VideoCodecSettings>& recv_codecs); |
| 364 | ~WebRtcVideoReceiveStream(); |
| 365 | |
| 366 | void SetRecvCodecs(const std::vector<VideoCodecSettings>& recv_codecs); |
| 367 | void SetRtpExtensions(const std::vector<webrtc::RtpExtension>& extensions); |
| 368 | |
| 369 | virtual void RenderFrame(const webrtc::I420VideoFrame& frame, |
| 370 | int time_to_render_ms) OVERRIDE; |
| 371 | |
| 372 | void SetRenderer(cricket::VideoRenderer* renderer); |
| 373 | cricket::VideoRenderer* GetRenderer(); |
| 374 | |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 375 | VideoReceiverInfo GetVideoReceiverInfo(); |
| 376 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 377 | private: |
| 378 | void SetSize(int width, int height); |
| 379 | void RecreateWebRtcStream(); |
| 380 | |
| 381 | webrtc::Call* const call_; |
| 382 | |
| 383 | webrtc::VideoReceiveStream* stream_; |
| 384 | webrtc::VideoReceiveStream::Config config_; |
| 385 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 386 | rtc::CriticalSection renderer_lock_; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 387 | cricket::VideoRenderer* renderer_ GUARDED_BY(renderer_lock_); |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 388 | int last_width_ GUARDED_BY(renderer_lock_); |
| 389 | int last_height_ GUARDED_BY(renderer_lock_); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 390 | }; |
| 391 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 392 | void Construct(webrtc::Call* call, WebRtcVideoEngine2* engine); |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 393 | void SetDefaultOptions(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 394 | |
| 395 | virtual bool SendRtp(const uint8_t* data, size_t len) OVERRIDE; |
| 396 | virtual bool SendRtcp(const uint8_t* data, size_t len) OVERRIDE; |
| 397 | |
| 398 | void StartAllSendStreams(); |
| 399 | void StopAllSendStreams(); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 400 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 401 | static std::vector<VideoCodecSettings> MapCodecs( |
| 402 | const std::vector<VideoCodec>& codecs); |
| 403 | std::vector<VideoCodecSettings> FilterSupportedCodecs( |
| 404 | const std::vector<VideoCodecSettings>& mapped_codecs); |
| 405 | |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 406 | void FillSenderStats(VideoMediaInfo* info); |
| 407 | void FillReceiverStats(VideoMediaInfo* info); |
| 408 | void FillBandwidthEstimationStats(VideoMediaInfo* info); |
| 409 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 410 | uint32_t rtcp_receiver_report_ssrc_; |
| 411 | bool sending_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 412 | rtc::scoped_ptr<webrtc::Call> call_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 413 | uint32_t default_send_ssrc_; |
pbos@webrtc.org | afb554f4 | 2014-08-12 23:17:13 +0000 | [diff] [blame] | 414 | |
| 415 | DefaultUnsignalledSsrcHandler default_unsignalled_ssrc_handler_; |
| 416 | UnsignalledSsrcHandler* const unsignalled_ssrc_handler_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 417 | |
| 418 | // Using primary-ssrc (first ssrc) as key. |
| 419 | std::map<uint32, WebRtcVideoSendStream*> send_streams_; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 420 | std::map<uint32, WebRtcVideoReceiveStream*> receive_streams_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 421 | |
| 422 | Settable<VideoCodecSettings> send_codec_; |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 423 | std::vector<webrtc::RtpExtension> send_rtp_extensions_; |
| 424 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 425 | WebRtcVideoEncoderFactory2* const encoder_factory_; |
| 426 | std::vector<VideoCodecSettings> recv_codecs_; |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 427 | std::vector<webrtc::RtpExtension> recv_rtp_extensions_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 428 | VideoOptions options_; |
| 429 | }; |
| 430 | |
| 431 | } // namespace cricket |
| 432 | |
| 433 | #endif // TALK_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_H_ |