| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ | 11 #ifndef WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ |
| 12 #define WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ | 12 #define WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ |
| 13 | 13 |
| 14 #include <map> | 14 // TODO(eladalon): Remove this legacy. |
| 15 #include <memory> | 15 #include "webrtc/media/engine/webrtcvideoengine.h" |
| 16 #include <set> | |
| 17 #include <string> | |
| 18 #include <vector> | |
| 19 | |
| 20 #include "webrtc/api/call/transport.h" | |
| 21 #include "webrtc/api/video/video_frame.h" | |
| 22 #include "webrtc/base/asyncinvoker.h" | |
| 23 #include "webrtc/base/criticalsection.h" | |
| 24 #include "webrtc/base/networkroute.h" | |
| 25 #include "webrtc/base/optional.h" | |
| 26 #include "webrtc/base/thread_annotations.h" | |
| 27 #include "webrtc/base/thread_checker.h" | |
| 28 #include "webrtc/call/call.h" | |
| 29 #include "webrtc/call/flexfec_receive_stream.h" | |
| 30 #include "webrtc/media/base/mediaengine.h" | |
| 31 #include "webrtc/media/base/videosinkinterface.h" | |
| 32 #include "webrtc/media/base/videosourceinterface.h" | |
| 33 #include "webrtc/media/engine/webrtcvideodecoderfactory.h" | |
| 34 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" | |
| 35 #include "webrtc/video_receive_stream.h" | |
| 36 #include "webrtc/video_send_stream.h" | |
| 37 | |
| 38 namespace webrtc { | |
| 39 class VideoDecoder; | |
| 40 class VideoEncoder; | |
| 41 struct MediaConfig; | |
| 42 } | |
| 43 | |
| 44 namespace rtc { | |
| 45 class Thread; | |
| 46 } // namespace rtc | |
| 47 | |
| 48 namespace cricket { | |
| 49 | |
| 50 class VideoCapturer; | |
| 51 class VideoProcessor; | |
| 52 class VideoRenderer; | |
| 53 class VoiceMediaChannel; | |
| 54 class WebRtcDecoderObserver; | |
| 55 class WebRtcEncoderObserver; | |
| 56 class WebRtcLocalStreamInfo; | |
| 57 class WebRtcRenderAdapter; | |
| 58 class WebRtcVideoChannel2; | |
| 59 class WebRtcVideoChannelRecvInfo; | |
| 60 class WebRtcVideoChannelSendInfo; | |
| 61 class WebRtcVoiceEngine; | |
| 62 class WebRtcVoiceMediaChannel; | |
| 63 | |
| 64 struct Device; | |
| 65 | |
| 66 class UnsignalledSsrcHandler { | |
| 67 public: | |
| 68 enum Action { | |
| 69 kDropPacket, | |
| 70 kDeliverPacket, | |
| 71 }; | |
| 72 virtual Action OnUnsignalledSsrc(WebRtcVideoChannel2* channel, | |
| 73 uint32_t ssrc) = 0; | |
| 74 virtual ~UnsignalledSsrcHandler() = default; | |
| 75 }; | |
| 76 | |
| 77 // TODO(pbos): Remove, use external handlers only. | |
| 78 class DefaultUnsignalledSsrcHandler : public UnsignalledSsrcHandler { | |
| 79 public: | |
| 80 DefaultUnsignalledSsrcHandler(); | |
| 81 Action OnUnsignalledSsrc(WebRtcVideoChannel2* channel, | |
| 82 uint32_t ssrc) override; | |
| 83 | |
| 84 rtc::VideoSinkInterface<webrtc::VideoFrame>* GetDefaultSink() const; | |
| 85 void SetDefaultSink(WebRtcVideoChannel2* channel, | |
| 86 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink); | |
| 87 | |
| 88 virtual ~DefaultUnsignalledSsrcHandler() = default; | |
| 89 | |
| 90 private: | |
| 91 rtc::VideoSinkInterface<webrtc::VideoFrame>* default_sink_; | |
| 92 }; | |
| 93 | |
| 94 // WebRtcVideoEngine2 is used for the new native WebRTC Video API (webrtc:1667). | |
| 95 class WebRtcVideoEngine2 { | |
| 96 public: | |
| 97 WebRtcVideoEngine2(); | |
| 98 virtual ~WebRtcVideoEngine2(); | |
| 99 | |
| 100 // Basic video engine implementation. | |
| 101 void Init(); | |
| 102 | |
| 103 WebRtcVideoChannel2* CreateChannel(webrtc::Call* call, | |
| 104 const MediaConfig& config, | |
| 105 const VideoOptions& options); | |
| 106 | |
| 107 std::vector<VideoCodec> codecs() const; | |
| 108 RtpCapabilities GetCapabilities() const; | |
| 109 | |
| 110 // Set a WebRtcVideoDecoderFactory for external decoding. Video engine does | |
| 111 // not take the ownership of |decoder_factory|. The caller needs to make sure | |
| 112 // that |decoder_factory| outlives the video engine. | |
| 113 void SetExternalDecoderFactory(WebRtcVideoDecoderFactory* decoder_factory); | |
| 114 // Set a WebRtcVideoEncoderFactory for external encoding. Video engine does | |
| 115 // not take the ownership of |encoder_factory|. The caller needs to make sure | |
| 116 // that |encoder_factory| outlives the video engine. | |
| 117 virtual void SetExternalEncoderFactory( | |
| 118 WebRtcVideoEncoderFactory* encoder_factory); | |
| 119 | |
| 120 private: | |
| 121 bool initialized_; | |
| 122 | |
| 123 WebRtcVideoDecoderFactory* external_decoder_factory_; | |
| 124 WebRtcVideoEncoderFactory* external_encoder_factory_; | |
| 125 std::unique_ptr<WebRtcVideoEncoderFactory> simulcast_encoder_factory_; | |
| 126 }; | |
| 127 | |
| 128 class WebRtcVideoChannel2 : public VideoMediaChannel, public webrtc::Transport { | |
| 129 public: | |
| 130 WebRtcVideoChannel2(webrtc::Call* call, | |
| 131 const MediaConfig& config, | |
| 132 const VideoOptions& options, | |
| 133 WebRtcVideoEncoderFactory* external_encoder_factory, | |
| 134 WebRtcVideoDecoderFactory* external_decoder_factory); | |
| 135 ~WebRtcVideoChannel2() override; | |
| 136 | |
| 137 // VideoMediaChannel implementation | |
| 138 rtc::DiffServCodePoint PreferredDscp() const override; | |
| 139 | |
| 140 bool SetSendParameters(const VideoSendParameters& params) override; | |
| 141 bool SetRecvParameters(const VideoRecvParameters& params) override; | |
| 142 webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const override; | |
| 143 bool SetRtpSendParameters(uint32_t ssrc, | |
| 144 const webrtc::RtpParameters& parameters) override; | |
| 145 webrtc::RtpParameters GetRtpReceiveParameters(uint32_t ssrc) const override; | |
| 146 bool SetRtpReceiveParameters( | |
| 147 uint32_t ssrc, | |
| 148 const webrtc::RtpParameters& parameters) override; | |
| 149 bool GetSendCodec(VideoCodec* send_codec) override; | |
| 150 bool SetSend(bool send) override; | |
| 151 bool SetVideoSend( | |
| 152 uint32_t ssrc, | |
| 153 bool enable, | |
| 154 const VideoOptions* options, | |
| 155 rtc::VideoSourceInterface<webrtc::VideoFrame>* source) override; | |
| 156 bool AddSendStream(const StreamParams& sp) override; | |
| 157 bool RemoveSendStream(uint32_t ssrc) override; | |
| 158 bool AddRecvStream(const StreamParams& sp) override; | |
| 159 bool AddRecvStream(const StreamParams& sp, bool default_stream); | |
| 160 bool RemoveRecvStream(uint32_t ssrc) override; | |
| 161 bool SetSink(uint32_t ssrc, | |
| 162 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override; | |
| 163 void FillBitrateInfo(BandwidthEstimationInfo* bwe_info) override; | |
| 164 bool GetStats(VideoMediaInfo* info) override; | |
| 165 | |
| 166 void OnPacketReceived(rtc::CopyOnWriteBuffer* packet, | |
| 167 const rtc::PacketTime& packet_time) override; | |
| 168 void OnRtcpReceived(rtc::CopyOnWriteBuffer* packet, | |
| 169 const rtc::PacketTime& packet_time) override; | |
| 170 void OnReadyToSend(bool ready) override; | |
| 171 void OnNetworkRouteChanged(const std::string& transport_name, | |
| 172 const rtc::NetworkRoute& network_route) override; | |
| 173 void OnTransportOverheadChanged(int transport_overhead_per_packet) override; | |
| 174 void SetInterface(NetworkInterface* iface) override; | |
| 175 | |
| 176 // Implemented for VideoMediaChannelTest. | |
| 177 bool sending() const { return sending_; } | |
| 178 | |
| 179 rtc::Optional<uint32_t> GetDefaultReceiveStreamSsrc(); | |
| 180 | |
| 181 // AdaptReason is used for expressing why a WebRtcVideoSendStream request | |
| 182 // a lower input frame size than the currently configured camera input frame | |
| 183 // size. There can be more than one reason OR:ed together. | |
| 184 enum AdaptReason { | |
| 185 ADAPTREASON_NONE = 0, | |
| 186 ADAPTREASON_CPU = 1, | |
| 187 ADAPTREASON_BANDWIDTH = 2, | |
| 188 }; | |
| 189 | |
| 190 private: | |
| 191 class WebRtcVideoReceiveStream; | |
| 192 struct VideoCodecSettings { | |
| 193 VideoCodecSettings(); | |
| 194 | |
| 195 // Checks if all members of |*this| are equal to the corresponding members | |
| 196 // of |other|. | |
| 197 bool operator==(const VideoCodecSettings& other) const; | |
| 198 bool operator!=(const VideoCodecSettings& other) const; | |
| 199 | |
| 200 // Checks if all members of |a|, except |flexfec_payload_type|, are equal | |
| 201 // to the corresponding members of |b|. | |
| 202 static bool EqualsDisregardingFlexfec(const VideoCodecSettings& a, | |
| 203 const VideoCodecSettings& b); | |
| 204 | |
| 205 VideoCodec codec; | |
| 206 webrtc::UlpfecConfig ulpfec; | |
| 207 int flexfec_payload_type; | |
| 208 int rtx_payload_type; | |
| 209 }; | |
| 210 | |
| 211 struct ChangedSendParameters { | |
| 212 // These optionals are unset if not changed. | |
| 213 rtc::Optional<VideoCodecSettings> codec; | |
| 214 rtc::Optional<std::vector<webrtc::RtpExtension>> rtp_header_extensions; | |
| 215 rtc::Optional<int> max_bandwidth_bps; | |
| 216 rtc::Optional<bool> conference_mode; | |
| 217 rtc::Optional<webrtc::RtcpMode> rtcp_mode; | |
| 218 }; | |
| 219 | |
| 220 struct ChangedRecvParameters { | |
| 221 // These optionals are unset if not changed. | |
| 222 rtc::Optional<std::vector<VideoCodecSettings>> codec_settings; | |
| 223 rtc::Optional<std::vector<webrtc::RtpExtension>> rtp_header_extensions; | |
| 224 // Keep track of the FlexFEC payload type separately from |codec_settings|. | |
| 225 // This allows us to recreate the FlexfecReceiveStream separately from the | |
| 226 // VideoReceiveStream when the FlexFEC payload type is changed. | |
| 227 rtc::Optional<int> flexfec_payload_type; | |
| 228 }; | |
| 229 | |
| 230 bool GetChangedSendParameters(const VideoSendParameters& params, | |
| 231 ChangedSendParameters* changed_params) const; | |
| 232 bool GetChangedRecvParameters(const VideoRecvParameters& params, | |
| 233 ChangedRecvParameters* changed_params) const; | |
| 234 | |
| 235 void SetMaxSendBandwidth(int bps); | |
| 236 | |
| 237 void ConfigureReceiverRtp( | |
| 238 webrtc::VideoReceiveStream::Config* config, | |
| 239 webrtc::FlexfecReceiveStream::Config* flexfec_config, | |
| 240 const StreamParams& sp) const; | |
| 241 bool ValidateSendSsrcAvailability(const StreamParams& sp) const | |
| 242 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); | |
| 243 bool ValidateReceiveSsrcAvailability(const StreamParams& sp) const | |
| 244 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); | |
| 245 void DeleteReceiveStream(WebRtcVideoReceiveStream* stream) | |
| 246 EXCLUSIVE_LOCKS_REQUIRED(stream_crit_); | |
| 247 | |
| 248 static std::string CodecSettingsVectorToString( | |
| 249 const std::vector<VideoCodecSettings>& codecs); | |
| 250 | |
| 251 // Wrapper for the sender part. | |
| 252 class WebRtcVideoSendStream | |
| 253 : public rtc::VideoSourceInterface<webrtc::VideoFrame> { | |
| 254 public: | |
| 255 WebRtcVideoSendStream( | |
| 256 webrtc::Call* call, | |
| 257 const StreamParams& sp, | |
| 258 webrtc::VideoSendStream::Config config, | |
| 259 const VideoOptions& options, | |
| 260 WebRtcVideoEncoderFactory* external_encoder_factory, | |
| 261 bool enable_cpu_overuse_detection, | |
| 262 int max_bitrate_bps, | |
| 263 const rtc::Optional<VideoCodecSettings>& codec_settings, | |
| 264 const rtc::Optional<std::vector<webrtc::RtpExtension>>& rtp_extensions, | |
| 265 const VideoSendParameters& send_params); | |
| 266 virtual ~WebRtcVideoSendStream(); | |
| 267 | |
| 268 void SetSendParameters(const ChangedSendParameters& send_params); | |
| 269 bool SetRtpParameters(const webrtc::RtpParameters& parameters); | |
| 270 webrtc::RtpParameters GetRtpParameters() const; | |
| 271 | |
| 272 // Implements rtc::VideoSourceInterface<webrtc::VideoFrame>. | |
| 273 // WebRtcVideoSendStream acts as a source to the webrtc::VideoSendStream | |
| 274 // in |stream_|. This is done to proxy VideoSinkWants from the encoder to | |
| 275 // the worker thread. | |
| 276 void AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink, | |
| 277 const rtc::VideoSinkWants& wants) override; | |
| 278 void RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override; | |
| 279 | |
| 280 bool SetVideoSend(bool mute, | |
| 281 const VideoOptions* options, | |
| 282 rtc::VideoSourceInterface<webrtc::VideoFrame>* source); | |
| 283 | |
| 284 void SetSend(bool send); | |
| 285 | |
| 286 const std::vector<uint32_t>& GetSsrcs() const; | |
| 287 VideoSenderInfo GetVideoSenderInfo(bool log_stats); | |
| 288 void FillBitrateInfo(BandwidthEstimationInfo* bwe_info); | |
| 289 | |
| 290 private: | |
| 291 // Parameters needed to reconstruct the underlying stream. | |
| 292 // webrtc::VideoSendStream doesn't support setting a lot of options on the | |
| 293 // fly, so when those need to be changed we tear down and reconstruct with | |
| 294 // similar parameters depending on which options changed etc. | |
| 295 struct VideoSendStreamParameters { | |
| 296 VideoSendStreamParameters( | |
| 297 webrtc::VideoSendStream::Config config, | |
| 298 const VideoOptions& options, | |
| 299 int max_bitrate_bps, | |
| 300 const rtc::Optional<VideoCodecSettings>& codec_settings); | |
| 301 webrtc::VideoSendStream::Config config; | |
| 302 VideoOptions options; | |
| 303 int max_bitrate_bps; | |
| 304 bool conference_mode; | |
| 305 rtc::Optional<VideoCodecSettings> codec_settings; | |
| 306 // Sent resolutions + bitrates etc. by the underlying VideoSendStream, | |
| 307 // typically changes when setting a new resolution or reconfiguring | |
| 308 // bitrates. | |
| 309 webrtc::VideoEncoderConfig encoder_config; | |
| 310 }; | |
| 311 | |
| 312 struct AllocatedEncoder { | |
| 313 AllocatedEncoder(webrtc::VideoEncoder* encoder, | |
| 314 const cricket::VideoCodec& codec, | |
| 315 bool external); | |
| 316 webrtc::VideoEncoder* encoder; | |
| 317 webrtc::VideoEncoder* external_encoder; | |
| 318 cricket::VideoCodec codec; | |
| 319 bool external; | |
| 320 }; | |
| 321 | |
| 322 rtc::scoped_refptr<webrtc::VideoEncoderConfig::EncoderSpecificSettings> | |
| 323 ConfigureVideoEncoderSettings(const VideoCodec& codec); | |
| 324 // If force_encoder_allocation is true, a new AllocatedEncoder is always | |
| 325 // created. If false, the allocated encoder may be reused, if the type | |
| 326 // matches. | |
| 327 AllocatedEncoder CreateVideoEncoder(const VideoCodec& codec, | |
| 328 bool force_encoder_allocation); | |
| 329 void DestroyVideoEncoder(AllocatedEncoder* encoder); | |
| 330 void SetCodec(const VideoCodecSettings& codec, | |
| 331 bool force_encoder_allocation); | |
| 332 void RecreateWebRtcStream(); | |
| 333 webrtc::VideoEncoderConfig CreateVideoEncoderConfig( | |
| 334 const VideoCodec& codec) const; | |
| 335 void ReconfigureEncoder(); | |
| 336 bool ValidateRtpParameters(const webrtc::RtpParameters& parameters); | |
| 337 | |
| 338 // Calls Start or Stop according to whether or not |sending_| is true, | |
| 339 // and whether or not the encoding in |rtp_parameters_| is active. | |
| 340 void UpdateSendState(); | |
| 341 | |
| 342 webrtc::VideoSendStream::DegradationPreference GetDegradationPreference() | |
| 343 const EXCLUSIVE_LOCKS_REQUIRED(&thread_checker_); | |
| 344 | |
| 345 rtc::ThreadChecker thread_checker_; | |
| 346 rtc::AsyncInvoker invoker_; | |
| 347 rtc::Thread* worker_thread_; | |
| 348 const std::vector<uint32_t> ssrcs_ ACCESS_ON(&thread_checker_); | |
| 349 const std::vector<SsrcGroup> ssrc_groups_ ACCESS_ON(&thread_checker_); | |
| 350 webrtc::Call* const call_; | |
| 351 const bool enable_cpu_overuse_detection_; | |
| 352 rtc::VideoSourceInterface<webrtc::VideoFrame>* source_ | |
| 353 ACCESS_ON(&thread_checker_); | |
| 354 WebRtcVideoEncoderFactory* const external_encoder_factory_ | |
| 355 ACCESS_ON(&thread_checker_); | |
| 356 const std::unique_ptr<WebRtcVideoEncoderFactory> internal_encoder_factory_ | |
| 357 ACCESS_ON(&thread_checker_); | |
| 358 | |
| 359 webrtc::VideoSendStream* stream_ ACCESS_ON(&thread_checker_); | |
| 360 rtc::VideoSinkInterface<webrtc::VideoFrame>* encoder_sink_ | |
| 361 ACCESS_ON(&thread_checker_); | |
| 362 // Contains settings that are the same for all streams in the MediaChannel, | |
| 363 // such as codecs, header extensions, and the global bitrate limit for the | |
| 364 // entire channel. | |
| 365 VideoSendStreamParameters parameters_ ACCESS_ON(&thread_checker_); | |
| 366 // Contains settings that are unique for each stream, such as max_bitrate. | |
| 367 // Does *not* contain codecs, however. | |
| 368 // TODO(skvlad): Move ssrcs_ and ssrc_groups_ into rtp_parameters_. | |
| 369 // TODO(skvlad): Combine parameters_ and rtp_parameters_ once we have only | |
| 370 // one stream per MediaChannel. | |
| 371 webrtc::RtpParameters rtp_parameters_ ACCESS_ON(&thread_checker_); | |
| 372 AllocatedEncoder allocated_encoder_ ACCESS_ON(&thread_checker_); | |
| 373 | |
| 374 bool sending_ ACCESS_ON(&thread_checker_); | |
| 375 }; | |
| 376 | |
| 377 // Wrapper for the receiver part, contains configs etc. that are needed to | |
| 378 // reconstruct the underlying VideoReceiveStream. | |
| 379 class WebRtcVideoReceiveStream | |
| 380 : public rtc::VideoSinkInterface<webrtc::VideoFrame> { | |
| 381 public: | |
| 382 WebRtcVideoReceiveStream( | |
| 383 webrtc::Call* call, | |
| 384 const StreamParams& sp, | |
| 385 webrtc::VideoReceiveStream::Config config, | |
| 386 WebRtcVideoDecoderFactory* external_decoder_factory, | |
| 387 bool default_stream, | |
| 388 const std::vector<VideoCodecSettings>& recv_codecs, | |
| 389 const webrtc::FlexfecReceiveStream::Config& flexfec_config); | |
| 390 ~WebRtcVideoReceiveStream(); | |
| 391 | |
| 392 const std::vector<uint32_t>& GetSsrcs() const; | |
| 393 rtc::Optional<uint32_t> GetFirstPrimarySsrc() const; | |
| 394 | |
| 395 void SetLocalSsrc(uint32_t local_ssrc); | |
| 396 // TODO(deadbeef): Move these feedback parameters into the recv parameters. | |
| 397 void SetFeedbackParameters(bool nack_enabled, | |
| 398 bool remb_enabled, | |
| 399 bool transport_cc_enabled, | |
| 400 webrtc::RtcpMode rtcp_mode); | |
| 401 void SetRecvParameters(const ChangedRecvParameters& recv_params); | |
| 402 | |
| 403 void OnFrame(const webrtc::VideoFrame& frame) override; | |
| 404 bool IsDefaultStream() const; | |
| 405 | |
| 406 void SetSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink); | |
| 407 | |
| 408 VideoReceiverInfo GetVideoReceiverInfo(bool log_stats); | |
| 409 | |
| 410 private: | |
| 411 struct AllocatedDecoder { | |
| 412 AllocatedDecoder(webrtc::VideoDecoder* decoder, | |
| 413 webrtc::VideoCodecType type, | |
| 414 bool external); | |
| 415 webrtc::VideoDecoder* decoder; | |
| 416 // Decoder wrapped into a fallback decoder to permit software fallback. | |
| 417 webrtc::VideoDecoder* external_decoder; | |
| 418 webrtc::VideoCodecType type; | |
| 419 bool external; | |
| 420 }; | |
| 421 | |
| 422 void RecreateWebRtcVideoStream(); | |
| 423 void MaybeRecreateWebRtcFlexfecStream(); | |
| 424 | |
| 425 void ConfigureCodecs(const std::vector<VideoCodecSettings>& recv_codecs, | |
| 426 std::vector<AllocatedDecoder>* old_codecs); | |
| 427 void ConfigureFlexfecCodec(int flexfec_payload_type); | |
| 428 AllocatedDecoder CreateOrReuseVideoDecoder( | |
| 429 std::vector<AllocatedDecoder>* old_decoder, | |
| 430 const VideoCodec& codec); | |
| 431 void ClearDecoders(std::vector<AllocatedDecoder>* allocated_decoders); | |
| 432 | |
| 433 std::string GetCodecNameFromPayloadType(int payload_type); | |
| 434 | |
| 435 webrtc::Call* const call_; | |
| 436 StreamParams stream_params_; | |
| 437 | |
| 438 // Both |stream_| and |flexfec_stream_| are managed by |this|. They are | |
| 439 // destroyed by calling call_->DestroyVideoReceiveStream and | |
| 440 // call_->DestroyFlexfecReceiveStream, respectively. | |
| 441 webrtc::VideoReceiveStream* stream_; | |
| 442 const bool default_stream_; | |
| 443 webrtc::VideoReceiveStream::Config config_; | |
| 444 webrtc::FlexfecReceiveStream::Config flexfec_config_; | |
| 445 webrtc::FlexfecReceiveStream* flexfec_stream_; | |
| 446 | |
| 447 WebRtcVideoDecoderFactory* const external_decoder_factory_; | |
| 448 std::vector<AllocatedDecoder> allocated_decoders_; | |
| 449 | |
| 450 rtc::CriticalSection sink_lock_; | |
| 451 rtc::VideoSinkInterface<webrtc::VideoFrame>* sink_ GUARDED_BY(sink_lock_); | |
| 452 // Expands remote RTP timestamps to int64_t to be able to estimate how long | |
| 453 // the stream has been running. | |
| 454 rtc::TimestampWrapAroundHandler timestamp_wraparound_handler_ | |
| 455 GUARDED_BY(sink_lock_); | |
| 456 int64_t first_frame_timestamp_ GUARDED_BY(sink_lock_); | |
| 457 // Start NTP time is estimated as current remote NTP time (estimated from | |
| 458 // RTCP) minus the elapsed time, as soon as remote NTP time is available. | |
| 459 int64_t estimated_remote_start_ntp_time_ms_ GUARDED_BY(sink_lock_); | |
| 460 }; | |
| 461 | |
| 462 void Construct(webrtc::Call* call, WebRtcVideoEngine2* engine); | |
| 463 | |
| 464 bool SendRtp(const uint8_t* data, | |
| 465 size_t len, | |
| 466 const webrtc::PacketOptions& options) override; | |
| 467 bool SendRtcp(const uint8_t* data, size_t len) override; | |
| 468 | |
| 469 static std::vector<VideoCodecSettings> MapCodecs( | |
| 470 const std::vector<VideoCodec>& codecs); | |
| 471 // Select what video codec will be used for sending, i.e. what codec is used | |
| 472 // for local encoding, based on supported remote codecs. The first remote | |
| 473 // codec that is supported locally will be selected. | |
| 474 rtc::Optional<VideoCodecSettings> SelectSendVideoCodec( | |
| 475 const std::vector<VideoCodecSettings>& remote_mapped_codecs) const; | |
| 476 | |
| 477 static bool NonFlexfecReceiveCodecsHaveChanged( | |
| 478 std::vector<VideoCodecSettings> before, | |
| 479 std::vector<VideoCodecSettings> after); | |
| 480 | |
| 481 void FillSenderStats(VideoMediaInfo* info, bool log_stats); | |
| 482 void FillReceiverStats(VideoMediaInfo* info, bool log_stats); | |
| 483 void FillBandwidthEstimationStats(const webrtc::Call::Stats& stats, | |
| 484 VideoMediaInfo* info); | |
| 485 void FillSendAndReceiveCodecStats(VideoMediaInfo* video_media_info); | |
| 486 | |
| 487 rtc::ThreadChecker thread_checker_; | |
| 488 | |
| 489 uint32_t rtcp_receiver_report_ssrc_; | |
| 490 bool sending_; | |
| 491 webrtc::Call* const call_; | |
| 492 | |
| 493 DefaultUnsignalledSsrcHandler default_unsignalled_ssrc_handler_; | |
| 494 UnsignalledSsrcHandler* const unsignalled_ssrc_handler_; | |
| 495 | |
| 496 const MediaConfig::Video video_config_; | |
| 497 | |
| 498 rtc::CriticalSection stream_crit_; | |
| 499 // Using primary-ssrc (first ssrc) as key. | |
| 500 std::map<uint32_t, WebRtcVideoSendStream*> send_streams_ | |
| 501 GUARDED_BY(stream_crit_); | |
| 502 std::map<uint32_t, WebRtcVideoReceiveStream*> receive_streams_ | |
| 503 GUARDED_BY(stream_crit_); | |
| 504 std::set<uint32_t> send_ssrcs_ GUARDED_BY(stream_crit_); | |
| 505 std::set<uint32_t> receive_ssrcs_ GUARDED_BY(stream_crit_); | |
| 506 | |
| 507 rtc::Optional<VideoCodecSettings> send_codec_; | |
| 508 rtc::Optional<std::vector<webrtc::RtpExtension>> send_rtp_extensions_; | |
| 509 | |
| 510 WebRtcVideoEncoderFactory* const external_encoder_factory_; | |
| 511 WebRtcVideoDecoderFactory* const external_decoder_factory_; | |
| 512 std::vector<VideoCodecSettings> recv_codecs_; | |
| 513 std::vector<webrtc::RtpExtension> recv_rtp_extensions_; | |
| 514 // See reason for keeping track of the FlexFEC payload type separately in | |
| 515 // comment in WebRtcVideoChannel2::ChangedRecvParameters. | |
| 516 int recv_flexfec_payload_type_; | |
| 517 webrtc::Call::Config::BitrateConfig bitrate_config_; | |
| 518 // TODO(deadbeef): Don't duplicate information between | |
| 519 // send_params/recv_params, rtp_extensions, options, etc. | |
| 520 VideoSendParameters send_params_; | |
| 521 VideoOptions default_send_options_; | |
| 522 VideoRecvParameters recv_params_; | |
| 523 int64_t last_stats_log_ms_; | |
| 524 }; | |
| 525 | |
| 526 } // namespace cricket | |
| 527 | 16 |
| 528 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ | 17 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOENGINE2_H_ |
| 18 |
| OLD | NEW |