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