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" |
pbos@webrtc.org | 0a2087a | 2014-09-23 09:40:22 +0000 | [diff] [blame] | 37 | #include "talk/media/webrtc/webrtcvideodecoderfactory.h" |
| 38 | #include "talk/media/webrtc/webrtcvideoencoderfactory.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 39 | #include "webrtc/base/cpumonitor.h" |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 40 | #include "webrtc/base/criticalsection.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 41 | #include "webrtc/base/scoped_ptr.h" |
pbos@webrtc.org | 38344ed | 2014-09-24 06:05:00 +0000 | [diff] [blame] | 42 | #include "webrtc/base/thread_annotations.h" |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 43 | #include "webrtc/call.h" |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 44 | #include "webrtc/common_video/interface/i420_video_frame.h" |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 45 | #include "webrtc/transport.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 46 | #include "webrtc/video_receive_stream.h" |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 47 | #include "webrtc/video_renderer.h" |
| 48 | #include "webrtc/video_send_stream.h" |
| 49 | |
| 50 | namespace webrtc { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 51 | class VideoCaptureModule; |
| 52 | class VideoDecoder; |
| 53 | class VideoEncoder; |
| 54 | class VideoRender; |
| 55 | class VideoSendStreamInput; |
| 56 | class VideoReceiveStream; |
| 57 | } |
| 58 | |
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 | class CpuMonitor; |
| 61 | class Thread; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 62 | } // namespace rtc |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 63 | |
| 64 | namespace cricket { |
| 65 | |
| 66 | class VideoCapturer; |
| 67 | class VideoFrame; |
| 68 | class VideoProcessor; |
| 69 | class VideoRenderer; |
| 70 | class VoiceMediaChannel; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 71 | class WebRtcDecoderObserver; |
| 72 | class WebRtcEncoderObserver; |
| 73 | class WebRtcLocalStreamInfo; |
| 74 | class WebRtcRenderAdapter; |
| 75 | class WebRtcVideoChannelRecvInfo; |
| 76 | class WebRtcVideoChannelSendInfo; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 77 | class WebRtcVoiceEngine; |
| 78 | |
| 79 | struct CapturedFrame; |
| 80 | struct Device; |
| 81 | |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 82 | class WebRtcVideoRenderer; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 83 | |
pbos@webrtc.org | afb554f4 | 2014-08-12 23:17:13 +0000 | [diff] [blame] | 84 | class UnsignalledSsrcHandler { |
| 85 | public: |
| 86 | enum Action { |
| 87 | kDropPacket, |
| 88 | kDeliverPacket, |
| 89 | }; |
| 90 | virtual Action OnUnsignalledSsrc(VideoMediaChannel* engine, |
| 91 | uint32_t ssrc) = 0; |
| 92 | }; |
| 93 | |
| 94 | // TODO(pbos): Remove, use external handlers only. |
| 95 | class DefaultUnsignalledSsrcHandler : public UnsignalledSsrcHandler { |
| 96 | public: |
| 97 | DefaultUnsignalledSsrcHandler(); |
| 98 | virtual Action OnUnsignalledSsrc(VideoMediaChannel* engine, |
| 99 | uint32_t ssrc) OVERRIDE; |
| 100 | |
| 101 | VideoRenderer* GetDefaultRenderer() const; |
| 102 | void SetDefaultRenderer(VideoMediaChannel* channel, VideoRenderer* renderer); |
| 103 | |
| 104 | private: |
| 105 | uint32_t default_recv_ssrc_; |
| 106 | VideoRenderer* default_renderer_; |
| 107 | }; |
| 108 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 109 | // CallFactory, overridden for testing to verify that webrtc::Call is configured |
| 110 | // properly. |
| 111 | class WebRtcCallFactory { |
| 112 | public: |
| 113 | virtual ~WebRtcCallFactory(); |
| 114 | virtual webrtc::Call* CreateCall(const webrtc::Call::Config& config); |
| 115 | }; |
| 116 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 117 | // WebRtcVideoEngine2 is used for the new native WebRTC Video API (webrtc:1667). |
buildbot@webrtc.org | 3c16d8b | 2014-10-13 06:35:10 +0000 | [diff] [blame] | 118 | class WebRtcVideoEngine2 : public sigslot::has_slots<> { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 119 | public: |
| 120 | // Creates the WebRtcVideoEngine2 with internal VideoCaptureModule. |
| 121 | WebRtcVideoEngine2(); |
pbos@webrtc.org | b648b9d | 2014-08-26 11:08:06 +0000 | [diff] [blame] | 122 | virtual ~WebRtcVideoEngine2(); |
| 123 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 124 | // Used for testing to be able to check and use the webrtc::Call config. |
| 125 | void SetCallFactory(WebRtcCallFactory* call_factory); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 126 | |
| 127 | // Basic video engine implementation. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 128 | bool Init(rtc::Thread* worker_thread); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 129 | void Terminate(); |
| 130 | |
| 131 | int GetCapabilities(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 132 | bool SetDefaultEncoderConfig(const VideoEncoderConfig& config); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 133 | |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 134 | WebRtcVideoChannel2* CreateChannel(const VideoOptions& options, |
| 135 | VoiceMediaChannel* voice_channel); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 136 | |
| 137 | const std::vector<VideoCodec>& codecs() const; |
| 138 | const std::vector<RtpHeaderExtension>& rtp_header_extensions() const; |
| 139 | void SetLogging(int min_sev, const char* filter); |
| 140 | |
pbos@webrtc.org | 0a2087a | 2014-09-23 09:40:22 +0000 | [diff] [blame] | 141 | // Set a WebRtcVideoDecoderFactory for external decoding. Video engine does |
| 142 | // not take the ownership of |decoder_factory|. The caller needs to make sure |
| 143 | // that |decoder_factory| outlives the video engine. |
| 144 | void SetExternalDecoderFactory(WebRtcVideoDecoderFactory* decoder_factory); |
| 145 | // Set a WebRtcVideoEncoderFactory for external encoding. Video engine does |
| 146 | // not take the ownership of |encoder_factory|. The caller needs to make sure |
| 147 | // that |encoder_factory| outlives the video engine. |
| 148 | virtual void SetExternalEncoderFactory( |
| 149 | WebRtcVideoEncoderFactory* encoder_factory); |
| 150 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 151 | bool EnableTimedRender(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 152 | // This is currently ignored. |
| 153 | sigslot::repeater2<VideoCapturer*, CaptureState> SignalCaptureStateChange; |
| 154 | |
| 155 | // Set the VoiceEngine for A/V sync. This can only be called before Init. |
| 156 | bool SetVoiceEngine(WebRtcVoiceEngine* voice_engine); |
| 157 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 158 | bool FindCodec(const VideoCodec& in); |
| 159 | bool CanSendCodec(const VideoCodec& in, |
| 160 | const VideoCodec& current, |
| 161 | VideoCodec* out); |
| 162 | // Check whether the supplied trace should be ignored. |
| 163 | bool ShouldIgnoreTrace(const std::string& trace); |
| 164 | |
buildbot@webrtc.org | 992febb | 2014-09-05 16:39:08 +0000 | [diff] [blame] | 165 | VideoFormat GetStartCaptureFormat() const { return default_codec_format_; } |
| 166 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 167 | rtc::CpuMonitor* cpu_monitor() { return cpu_monitor_.get(); } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 168 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 169 | private: |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 170 | std::vector<VideoCodec> GetSupportedCodecs() const; |
| 171 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 172 | rtc::Thread* worker_thread_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 173 | WebRtcVoiceEngine* voice_engine_; |
| 174 | std::vector<VideoCodec> video_codecs_; |
| 175 | std::vector<RtpHeaderExtension> rtp_header_extensions_; |
buildbot@webrtc.org | 992febb | 2014-09-05 16:39:08 +0000 | [diff] [blame] | 176 | VideoFormat default_codec_format_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 177 | |
| 178 | bool initialized_; |
| 179 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 180 | rtc::scoped_ptr<rtc::CpuMonitor> cpu_monitor_; |
pbos@webrtc.org | 0a2087a | 2014-09-23 09:40:22 +0000 | [diff] [blame] | 181 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 182 | WebRtcCallFactory default_call_factory_; |
| 183 | WebRtcCallFactory* call_factory_; |
| 184 | |
pbos@webrtc.org | 0a2087a | 2014-09-23 09:40:22 +0000 | [diff] [blame] | 185 | WebRtcVideoDecoderFactory* external_decoder_factory_; |
| 186 | WebRtcVideoEncoderFactory* external_encoder_factory_; |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 187 | rtc::scoped_ptr<WebRtcVideoEncoderFactory> simulcast_encoder_factory_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 188 | }; |
| 189 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 190 | class WebRtcVideoChannel2 : public rtc::MessageHandler, |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 191 | public VideoMediaChannel, |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 192 | public webrtc::newapi::Transport, |
| 193 | public webrtc::LoadObserver { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 194 | public: |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 195 | WebRtcVideoChannel2(WebRtcCallFactory* call_factory, |
pbos@webrtc.org | 3bf3d23 | 2014-10-31 12:59:34 +0000 | [diff] [blame] | 196 | WebRtcVoiceEngine* voice_engine, |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 197 | VoiceMediaChannel* voice_channel, |
pbos@webrtc.org | fa553ef | 2014-10-20 11:07:07 +0000 | [diff] [blame] | 198 | const VideoOptions& options, |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 199 | WebRtcVideoEncoderFactory* external_encoder_factory, |
pbos@webrtc.org | f1c8b90 | 2015-01-14 17:29:27 +0000 | [diff] [blame^] | 200 | WebRtcVideoDecoderFactory* external_decoder_factory); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 201 | ~WebRtcVideoChannel2(); |
| 202 | bool Init(); |
| 203 | |
| 204 | // VideoMediaChannel implementation |
| 205 | virtual bool SetRecvCodecs(const std::vector<VideoCodec>& codecs) OVERRIDE; |
| 206 | virtual bool SetSendCodecs(const std::vector<VideoCodec>& codecs) OVERRIDE; |
| 207 | virtual bool GetSendCodec(VideoCodec* send_codec) OVERRIDE; |
| 208 | virtual bool SetSendStreamFormat(uint32 ssrc, |
| 209 | const VideoFormat& format) OVERRIDE; |
| 210 | virtual bool SetRender(bool render) OVERRIDE; |
| 211 | virtual bool SetSend(bool send) OVERRIDE; |
| 212 | |
| 213 | virtual bool AddSendStream(const StreamParams& sp) OVERRIDE; |
| 214 | virtual bool RemoveSendStream(uint32 ssrc) OVERRIDE; |
| 215 | virtual bool AddRecvStream(const StreamParams& sp) OVERRIDE; |
| 216 | virtual bool RemoveRecvStream(uint32 ssrc) OVERRIDE; |
| 217 | virtual bool SetRenderer(uint32 ssrc, VideoRenderer* renderer) OVERRIDE; |
| 218 | virtual bool GetStats(const StatsOptions& options, |
| 219 | VideoMediaInfo* info) OVERRIDE; |
| 220 | virtual bool SetCapturer(uint32 ssrc, VideoCapturer* capturer) OVERRIDE; |
| 221 | virtual bool SendIntraFrame() OVERRIDE; |
| 222 | virtual bool RequestIntraFrame() OVERRIDE; |
| 223 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 224 | virtual void OnPacketReceived(rtc::Buffer* packet, |
| 225 | const rtc::PacketTime& packet_time) |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 226 | OVERRIDE; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 227 | virtual void OnRtcpReceived(rtc::Buffer* packet, |
| 228 | const rtc::PacketTime& packet_time) |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 229 | OVERRIDE; |
| 230 | virtual void OnReadyToSend(bool ready) OVERRIDE; |
| 231 | virtual bool MuteStream(uint32 ssrc, bool mute) OVERRIDE; |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 232 | |
| 233 | // Set send/receive RTP header extensions. This must be done before creating |
| 234 | // streams as it only has effect on future streams. |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 235 | virtual bool SetRecvRtpHeaderExtensions( |
| 236 | const std::vector<RtpHeaderExtension>& extensions) OVERRIDE; |
| 237 | virtual bool SetSendRtpHeaderExtensions( |
| 238 | const std::vector<RtpHeaderExtension>& extensions) OVERRIDE; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 239 | virtual bool SetMaxSendBandwidth(int bps) OVERRIDE; |
| 240 | virtual bool SetOptions(const VideoOptions& options) OVERRIDE; |
| 241 | virtual bool GetOptions(VideoOptions* options) const OVERRIDE { |
| 242 | *options = options_; |
| 243 | return true; |
| 244 | } |
| 245 | virtual void SetInterface(NetworkInterface* iface) OVERRIDE; |
| 246 | virtual void UpdateAspectRatio(int ratio_w, int ratio_h) OVERRIDE; |
| 247 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 248 | virtual void OnMessage(rtc::Message* msg) OVERRIDE; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 249 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 250 | virtual void OnLoadUpdate(Load load) OVERRIDE; |
| 251 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 252 | // Implemented for VideoMediaChannelTest. |
| 253 | bool sending() const { return sending_; } |
buildbot@webrtc.org | 2c0fb05 | 2014-08-13 16:47:12 +0000 | [diff] [blame] | 254 | uint32 GetDefaultSendChannelSsrc() { return default_send_ssrc_; } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 255 | bool GetRenderer(uint32 ssrc, VideoRenderer** renderer); |
| 256 | |
| 257 | private: |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 258 | void ConfigureReceiverRtp(webrtc::VideoReceiveStream::Config* config, |
| 259 | const StreamParams& sp) const; |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 260 | bool CodecIsExternallySupported(const std::string& name) const; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 261 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 262 | struct VideoCodecSettings { |
| 263 | VideoCodecSettings(); |
andrew@webrtc.org | 8f27fcc | 2015-01-09 20:22:46 +0000 | [diff] [blame] | 264 | |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 265 | bool operator ==(const VideoCodecSettings& other) const; |
| 266 | |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 267 | VideoCodec codec; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 268 | webrtc::FecConfig fec; |
| 269 | int rtx_payload_type; |
| 270 | }; |
| 271 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 272 | // Wrapper for the sender part, this is where the capturer is connected and |
| 273 | // frames are then converted from cricket frames to webrtc frames. |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 274 | class WebRtcVideoSendStream : public sigslot::has_slots<> { |
| 275 | public: |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 276 | WebRtcVideoSendStream( |
| 277 | webrtc::Call* call, |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 278 | WebRtcVideoEncoderFactory* external_encoder_factory, |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 279 | const VideoOptions& options, |
| 280 | const Settable<VideoCodecSettings>& codec_settings, |
| 281 | const StreamParams& sp, |
| 282 | const std::vector<webrtc::RtpExtension>& rtp_extensions); |
| 283 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 284 | ~WebRtcVideoSendStream(); |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 285 | void SetOptions(const VideoOptions& options); |
| 286 | void SetCodec(const VideoCodecSettings& codec); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 287 | void SetRtpExtensions( |
| 288 | const std::vector<webrtc::RtpExtension>& rtp_extensions); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 289 | |
| 290 | void InputFrame(VideoCapturer* capturer, const VideoFrame* frame); |
| 291 | bool SetCapturer(VideoCapturer* capturer); |
| 292 | bool SetVideoFormat(const VideoFormat& format); |
pbos@webrtc.org | ef8bb8d | 2014-08-13 21:36:18 +0000 | [diff] [blame] | 293 | void MuteStream(bool mute); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 294 | bool DisconnectCapturer(); |
| 295 | |
| 296 | void Start(); |
| 297 | void Stop(); |
| 298 | |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 299 | VideoSenderInfo GetVideoSenderInfo(); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 300 | void FillBandwidthEstimationInfo(BandwidthEstimationInfo* bwe_info); |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 301 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 302 | void OnCpuResolutionRequest( |
| 303 | CoordinatedVideoAdapter::AdaptRequest adapt_request); |
| 304 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 305 | private: |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 306 | // Parameters needed to reconstruct the underlying stream. |
| 307 | // webrtc::VideoSendStream doesn't support setting a lot of options on the |
| 308 | // fly, so when those need to be changed we tear down and reconstruct with |
| 309 | // similar parameters depending on which options changed etc. |
| 310 | struct VideoSendStreamParameters { |
| 311 | VideoSendStreamParameters( |
| 312 | const webrtc::VideoSendStream::Config& config, |
| 313 | const VideoOptions& options, |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 314 | const Settable<VideoCodecSettings>& codec_settings); |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 315 | webrtc::VideoSendStream::Config config; |
| 316 | VideoOptions options; |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 317 | Settable<VideoCodecSettings> codec_settings; |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 318 | // Sent resolutions + bitrates etc. by the underlying VideoSendStream, |
| 319 | // typically changes when setting a new resolution or reconfiguring |
| 320 | // bitrates. |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 321 | webrtc::VideoEncoderConfig encoder_config; |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 322 | }; |
| 323 | |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 324 | struct AllocatedEncoder { |
| 325 | AllocatedEncoder(webrtc::VideoEncoder* encoder, |
| 326 | webrtc::VideoCodecType type, |
| 327 | bool external) |
| 328 | : encoder(encoder), type(type), external(external) {} |
| 329 | webrtc::VideoEncoder* encoder; |
| 330 | webrtc::VideoCodecType type; |
| 331 | bool external; |
| 332 | }; |
| 333 | |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 334 | struct Dimensions { |
| 335 | Dimensions() : width(-1), height(-1), is_screencast(false) {} |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 336 | int width; |
| 337 | int height; |
| 338 | bool is_screencast; |
| 339 | }; |
| 340 | |
pbos@webrtc.org | f1c8b90 | 2015-01-14 17:29:27 +0000 | [diff] [blame^] | 341 | union VideoEncoderSettings { |
| 342 | webrtc::VideoCodecVP8 vp8; |
| 343 | webrtc::VideoCodecVP9 vp9; |
| 344 | }; |
| 345 | |
| 346 | static std::vector<webrtc::VideoStream> CreateVideoStreams( |
| 347 | const VideoCodec& codec, |
| 348 | const VideoOptions& options, |
| 349 | size_t num_streams); |
| 350 | static std::vector<webrtc::VideoStream> CreateSimulcastVideoStreams( |
| 351 | const VideoCodec& codec, |
| 352 | const VideoOptions& options, |
| 353 | size_t num_streams); |
| 354 | |
| 355 | void* ConfigureVideoEncoderSettings(const VideoCodec& codec, |
| 356 | const VideoOptions& options) |
| 357 | EXCLUSIVE_LOCKS_REQUIRED(lock_); |
| 358 | |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 359 | AllocatedEncoder CreateVideoEncoder(const VideoCodec& codec) |
| 360 | EXCLUSIVE_LOCKS_REQUIRED(lock_); |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 361 | void DestroyVideoEncoder(AllocatedEncoder* encoder) |
| 362 | EXCLUSIVE_LOCKS_REQUIRED(lock_); |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 363 | void SetCodecAndOptions(const VideoCodecSettings& codec, |
pbos@webrtc.org | d60d79a | 2014-09-24 07:10:57 +0000 | [diff] [blame] | 364 | const VideoOptions& options) |
| 365 | EXCLUSIVE_LOCKS_REQUIRED(lock_); |
| 366 | void RecreateWebRtcStream() EXCLUSIVE_LOCKS_REQUIRED(lock_); |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 367 | webrtc::VideoEncoderConfig CreateVideoEncoderConfig( |
| 368 | const Dimensions& dimensions, |
| 369 | const VideoCodec& codec) const EXCLUSIVE_LOCKS_REQUIRED(lock_); |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 370 | void SetDimensions(int width, int height, bool is_screencast) |
pbos@webrtc.org | d60d79a | 2014-09-24 07:10:57 +0000 | [diff] [blame] | 371 | EXCLUSIVE_LOCKS_REQUIRED(lock_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 372 | |
| 373 | webrtc::Call* const call_; |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 374 | WebRtcVideoEncoderFactory* const external_encoder_factory_ |
| 375 | GUARDED_BY(lock_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 376 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 377 | rtc::CriticalSection lock_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 378 | webrtc::VideoSendStream* stream_ GUARDED_BY(lock_); |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 379 | VideoSendStreamParameters parameters_ GUARDED_BY(lock_); |
pbos@webrtc.org | f1c8b90 | 2015-01-14 17:29:27 +0000 | [diff] [blame^] | 380 | VideoEncoderSettings encoder_settings_ GUARDED_BY(lock_); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 381 | AllocatedEncoder allocated_encoder_ GUARDED_BY(lock_); |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 382 | Dimensions last_dimensions_ GUARDED_BY(lock_); |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 383 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 384 | VideoCapturer* capturer_ GUARDED_BY(lock_); |
| 385 | bool sending_ GUARDED_BY(lock_); |
| 386 | bool muted_ GUARDED_BY(lock_); |
| 387 | VideoFormat format_ GUARDED_BY(lock_); |
| 388 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 389 | rtc::CriticalSection frame_lock_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 390 | webrtc::I420VideoFrame video_frame_ GUARDED_BY(frame_lock_); |
| 391 | }; |
| 392 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 393 | // Wrapper for the receiver part, contains configs etc. that are needed to |
| 394 | // reconstruct the underlying VideoReceiveStream. Also serves as a wrapper |
| 395 | // between webrtc::VideoRenderer and cricket::VideoRenderer. |
| 396 | class WebRtcVideoReceiveStream : public webrtc::VideoRenderer { |
| 397 | public: |
| 398 | WebRtcVideoReceiveStream( |
| 399 | webrtc::Call*, |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 400 | WebRtcVideoDecoderFactory* external_decoder_factory, |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 401 | const webrtc::VideoReceiveStream::Config& config, |
| 402 | const std::vector<VideoCodecSettings>& recv_codecs); |
| 403 | ~WebRtcVideoReceiveStream(); |
| 404 | |
| 405 | void SetRecvCodecs(const std::vector<VideoCodecSettings>& recv_codecs); |
| 406 | void SetRtpExtensions(const std::vector<webrtc::RtpExtension>& extensions); |
| 407 | |
| 408 | virtual void RenderFrame(const webrtc::I420VideoFrame& frame, |
| 409 | int time_to_render_ms) OVERRIDE; |
| 410 | |
| 411 | void SetRenderer(cricket::VideoRenderer* renderer); |
| 412 | cricket::VideoRenderer* GetRenderer(); |
| 413 | |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 414 | VideoReceiverInfo GetVideoReceiverInfo(); |
| 415 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 416 | private: |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 417 | struct AllocatedDecoder { |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 418 | AllocatedDecoder(webrtc::VideoDecoder* decoder, |
| 419 | webrtc::VideoCodecType type, |
| 420 | bool external) |
| 421 | : decoder(decoder), type(type), external(external) {} |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 422 | webrtc::VideoDecoder* decoder; |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 423 | webrtc::VideoCodecType type; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 424 | bool external; |
| 425 | }; |
| 426 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 427 | void SetSize(int width, int height); |
| 428 | void RecreateWebRtcStream(); |
| 429 | |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 430 | AllocatedDecoder CreateOrReuseVideoDecoder( |
| 431 | std::vector<AllocatedDecoder>* old_decoder, |
| 432 | const VideoCodec& codec); |
| 433 | void ClearDecoders(std::vector<AllocatedDecoder>* allocated_decoders); |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 434 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 435 | webrtc::Call* const call_; |
| 436 | |
| 437 | webrtc::VideoReceiveStream* stream_; |
| 438 | webrtc::VideoReceiveStream::Config config_; |
| 439 | |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 440 | WebRtcVideoDecoderFactory* const external_decoder_factory_; |
| 441 | std::vector<AllocatedDecoder> allocated_decoders_; |
| 442 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 443 | rtc::CriticalSection renderer_lock_; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 444 | cricket::VideoRenderer* renderer_ GUARDED_BY(renderer_lock_); |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 445 | int last_width_ GUARDED_BY(renderer_lock_); |
| 446 | int last_height_ GUARDED_BY(renderer_lock_); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 447 | }; |
| 448 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 449 | void Construct(webrtc::Call* call, WebRtcVideoEngine2* engine); |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 450 | void SetDefaultOptions(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 451 | |
| 452 | virtual bool SendRtp(const uint8_t* data, size_t len) OVERRIDE; |
| 453 | virtual bool SendRtcp(const uint8_t* data, size_t len) OVERRIDE; |
| 454 | |
| 455 | void StartAllSendStreams(); |
| 456 | void StopAllSendStreams(); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 457 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 458 | static std::vector<VideoCodecSettings> MapCodecs( |
| 459 | const std::vector<VideoCodec>& codecs); |
| 460 | std::vector<VideoCodecSettings> FilterSupportedCodecs( |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 461 | const std::vector<VideoCodecSettings>& mapped_codecs) const; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 462 | |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 463 | void FillSenderStats(VideoMediaInfo* info); |
| 464 | void FillReceiverStats(VideoMediaInfo* info); |
pbos@webrtc.org | 2b19f06 | 2014-12-11 13:26:09 +0000 | [diff] [blame] | 465 | void FillBandwidthEstimationStats(const webrtc::Call::Stats& stats, |
| 466 | VideoMediaInfo* info); |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 467 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 468 | uint32_t rtcp_receiver_report_ssrc_; |
| 469 | bool sending_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 470 | rtc::scoped_ptr<webrtc::Call> call_; |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 471 | WebRtcCallFactory* call_factory_; |
| 472 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 473 | uint32_t default_send_ssrc_; |
pbos@webrtc.org | afb554f4 | 2014-08-12 23:17:13 +0000 | [diff] [blame] | 474 | |
| 475 | DefaultUnsignalledSsrcHandler default_unsignalled_ssrc_handler_; |
| 476 | UnsignalledSsrcHandler* const unsignalled_ssrc_handler_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 477 | |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 478 | rtc::CriticalSection stream_crit_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 479 | // Using primary-ssrc (first ssrc) as key. |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 480 | std::map<uint32, WebRtcVideoSendStream*> send_streams_ |
| 481 | GUARDED_BY(stream_crit_); |
| 482 | std::map<uint32, WebRtcVideoReceiveStream*> receive_streams_ |
| 483 | GUARDED_BY(stream_crit_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 484 | |
| 485 | Settable<VideoCodecSettings> send_codec_; |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 486 | std::vector<webrtc::RtpExtension> send_rtp_extensions_; |
| 487 | |
pbos@webrtc.org | 3bf3d23 | 2014-10-31 12:59:34 +0000 | [diff] [blame] | 488 | VoiceMediaChannel* const voice_channel_; |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 489 | WebRtcVideoEncoderFactory* const external_encoder_factory_; |
| 490 | WebRtcVideoDecoderFactory* const external_decoder_factory_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 491 | std::vector<VideoCodecSettings> recv_codecs_; |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 492 | std::vector<webrtc::RtpExtension> recv_rtp_extensions_; |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 493 | webrtc::Call::Config::BitrateConfig bitrate_config_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 494 | VideoOptions options_; |
| 495 | }; |
| 496 | |
| 497 | } // namespace cricket |
| 498 | |
| 499 | #endif // TALK_MEDIA_WEBRTC_WEBRTCVIDEOENGINE2_H_ |