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