| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 #include "webrtc/media/engine/webrtcvideoengine.h" | 11 #include "webrtc/media/engine/webrtcvideoengine.h" |
| 12 | 12 |
| 13 #include <stdio.h> | 13 #include <stdio.h> |
| 14 #include <algorithm> | 14 #include <algorithm> |
| 15 #include <set> | 15 #include <set> |
| 16 #include <string> | 16 #include <string> |
| 17 #include <utility> | 17 #include <utility> |
| 18 | 18 |
| 19 #include "webrtc/api/video/i420_buffer.h" | 19 #include "webrtc/api/video/i420_buffer.h" |
| 20 #include "webrtc/api/video_codecs/video_decoder.h" | 20 #include "webrtc/api/video_codecs/video_decoder.h" |
| 21 #include "webrtc/api/video_codecs/video_encoder.h" | 21 #include "webrtc/api/video_codecs/video_encoder.h" |
| 22 #include "webrtc/call/call.h" | 22 #include "webrtc/call/call.h" |
| 23 #include "webrtc/common_video/h264/profile_level_id.h" | 23 #include "webrtc/common_video/h264/profile_level_id.h" |
| 24 #include "webrtc/media/engine/constants.h" | 24 #include "webrtc/media/engine/constants.h" |
| 25 #include "webrtc/media/engine/internaldecoderfactory.h" | 25 #include "webrtc/media/engine/internaldecoderfactory.h" |
| 26 #include "webrtc/media/engine/internalencoderfactory.h" | 26 #include "webrtc/media/engine/internalencoderfactory.h" |
| 27 #include "webrtc/media/engine/simulcast.h" | 27 #include "webrtc/media/engine/simulcast.h" |
| 28 #include "webrtc/media/engine/simulcast_encoder_adapter.h" |
| 28 #include "webrtc/media/engine/videodecodersoftwarefallbackwrapper.h" | 29 #include "webrtc/media/engine/videodecodersoftwarefallbackwrapper.h" |
| 29 #include "webrtc/media/engine/videoencodersoftwarefallbackwrapper.h" | 30 #include "webrtc/media/engine/videoencodersoftwarefallbackwrapper.h" |
| 30 #include "webrtc/media/engine/webrtcmediaengine.h" | 31 #include "webrtc/media/engine/webrtcmediaengine.h" |
| 31 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" | 32 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" |
| 32 #include "webrtc/media/engine/webrtcvoiceengine.h" | 33 #include "webrtc/media/engine/webrtcvoiceengine.h" |
| 33 #include "webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter.h" | |
| 34 #include "webrtc/rtc_base/copyonwritebuffer.h" | 34 #include "webrtc/rtc_base/copyonwritebuffer.h" |
| 35 #include "webrtc/rtc_base/logging.h" | 35 #include "webrtc/rtc_base/logging.h" |
| 36 #include "webrtc/rtc_base/stringutils.h" | 36 #include "webrtc/rtc_base/stringutils.h" |
| 37 #include "webrtc/rtc_base/timeutils.h" | 37 #include "webrtc/rtc_base/timeutils.h" |
| 38 #include "webrtc/rtc_base/trace_event.h" | 38 #include "webrtc/rtc_base/trace_event.h" |
| 39 #include "webrtc/system_wrappers/include/field_trial.h" | 39 #include "webrtc/system_wrappers/include/field_trial.h" |
| 40 | 40 |
| 41 using DegradationPreference = webrtc::VideoSendStream::DegradationPreference; | 41 using DegradationPreference = webrtc::VideoSendStream::DegradationPreference; |
| 42 | 42 |
| 43 namespace cricket { | 43 namespace cricket { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 55 return webrtc::field_trial::IsEnabled("WebRTC-FlexFEC-03-Advertised"); | 55 return webrtc::field_trial::IsEnabled("WebRTC-FlexFEC-03-Advertised"); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // If this field trial is enabled, we will report VideoContentType RTP extension | 58 // If this field trial is enabled, we will report VideoContentType RTP extension |
| 59 // in capabilities (thus, it will end up in the default SDP and extension will | 59 // in capabilities (thus, it will end up in the default SDP and extension will |
| 60 // be sent for all key-frames). | 60 // be sent for all key-frames). |
| 61 bool IsVideoContentTypeExtensionFieldTrialEnabled() { | 61 bool IsVideoContentTypeExtensionFieldTrialEnabled() { |
| 62 return webrtc::field_trial::IsEnabled("WebRTC-VideoContentTypeExtension"); | 62 return webrtc::field_trial::IsEnabled("WebRTC-VideoContentTypeExtension"); |
| 63 } | 63 } |
| 64 | 64 |
| 65 // Wrap cricket::WebRtcVideoEncoderFactory as a webrtc::VideoEncoderFactory. | |
| 66 class EncoderFactoryAdapter : public webrtc::VideoEncoderFactory { | |
| 67 public: | |
| 68 // EncoderFactoryAdapter doesn't take ownership of |factory|, which is owned | |
| 69 // by e.g. PeerConnectionFactory. | |
| 70 explicit EncoderFactoryAdapter(cricket::WebRtcVideoEncoderFactory* factory) | |
| 71 : factory_(factory) {} | |
| 72 virtual ~EncoderFactoryAdapter() {} | |
| 73 | |
| 74 // Implement webrtc::VideoEncoderFactory. | |
| 75 webrtc::VideoEncoder* Create() override { | |
| 76 return factory_->CreateVideoEncoder(VideoCodec(kVp8CodecName)); | |
| 77 } | |
| 78 | |
| 79 void Destroy(webrtc::VideoEncoder* encoder) override { | |
| 80 return factory_->DestroyVideoEncoder(encoder); | |
| 81 } | |
| 82 | |
| 83 private: | |
| 84 cricket::WebRtcVideoEncoderFactory* const factory_; | |
| 85 }; | |
| 86 | |
| 87 // An encoder factory that wraps Create requests for simulcastable codec types | 65 // An encoder factory that wraps Create requests for simulcastable codec types |
| 88 // with a webrtc::SimulcastEncoderAdapter. Non simulcastable codec type | 66 // with a webrtc::SimulcastEncoderAdapter. Non simulcastable codec type |
| 89 // requests are just passed through to the contained encoder factory. | 67 // requests are just passed through to the contained encoder factory. |
| 90 class WebRtcSimulcastEncoderFactory | 68 class WebRtcSimulcastEncoderFactory |
| 91 : public cricket::WebRtcVideoEncoderFactory { | 69 : public cricket::WebRtcVideoEncoderFactory { |
| 92 public: | 70 public: |
| 93 // WebRtcSimulcastEncoderFactory doesn't take ownership of |factory|, which is | 71 // WebRtcSimulcastEncoderFactory doesn't take ownership of |factory|, which is |
| 94 // owned by e.g. PeerConnectionFactory. | 72 // owned by e.g. PeerConnectionFactory. |
| 95 explicit WebRtcSimulcastEncoderFactory( | 73 explicit WebRtcSimulcastEncoderFactory( |
| 96 cricket::WebRtcVideoEncoderFactory* factory) | 74 cricket::WebRtcVideoEncoderFactory* factory) |
| 97 : factory_(factory) {} | 75 : factory_(factory) {} |
| 98 | 76 |
| 99 static bool UseSimulcastEncoderFactory( | 77 static bool UseSimulcastEncoderFactory( |
| 100 const std::vector<cricket::VideoCodec>& codecs) { | 78 const std::vector<cricket::VideoCodec>& codecs) { |
| 101 // If any codec is VP8, use the simulcast factory. If asked to create a | 79 // If any codec is VP8, use the simulcast factory. If asked to create a |
| 102 // non-VP8 codec, we'll just return a contained factory encoder directly. | 80 // non-VP8 codec, we'll just return a contained factory encoder directly. |
| 103 for (const auto& codec : codecs) { | 81 for (const auto& codec : codecs) { |
| 104 if (CodecNamesEq(codec.name.c_str(), kVp8CodecName)) { | 82 if (CodecNamesEq(codec.name.c_str(), kVp8CodecName)) { |
| 105 return true; | 83 return true; |
| 106 } | 84 } |
| 107 } | 85 } |
| 108 return false; | 86 return false; |
| 109 } | 87 } |
| 110 | 88 |
| 111 webrtc::VideoEncoder* CreateVideoEncoder( | 89 webrtc::VideoEncoder* CreateVideoEncoder( |
| 112 const cricket::VideoCodec& codec) override { | 90 const cricket::VideoCodec& codec) override { |
| 113 RTC_DCHECK(factory_ != NULL); | 91 RTC_DCHECK(factory_ != NULL); |
| 114 // If it's a codec type we can simulcast, create a wrapped encoder. | 92 // If it's a codec type we can simulcast, create a wrapped encoder. |
| 115 if (CodecNamesEq(codec.name.c_str(), kVp8CodecName)) { | 93 if (CodecNamesEq(codec.name.c_str(), kVp8CodecName)) { |
| 116 return new webrtc::SimulcastEncoderAdapter( | 94 return new webrtc::SimulcastEncoderAdapter(factory_); |
| 117 new EncoderFactoryAdapter(factory_)); | |
| 118 } | 95 } |
| 119 webrtc::VideoEncoder* encoder = factory_->CreateVideoEncoder(codec); | 96 webrtc::VideoEncoder* encoder = factory_->CreateVideoEncoder(codec); |
| 120 if (encoder) { | 97 if (encoder) { |
| 121 non_simulcast_encoders_.push_back(encoder); | 98 non_simulcast_encoders_.push_back(encoder); |
| 122 } | 99 } |
| 123 return encoder; | 100 return encoder; |
| 124 } | 101 } |
| 125 | 102 |
| 126 const std::vector<cricket::VideoCodec>& supported_codecs() const override { | 103 const std::vector<cricket::VideoCodec>& supported_codecs() const override { |
| 127 return factory_->supported_codecs(); | 104 return factory_->supported_codecs(); |
| (...skipping 2536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2664 stream.temporal_layer_thresholds_bps.resize(GetDefaultVp9TemporalLayers() - | 2641 stream.temporal_layer_thresholds_bps.resize(GetDefaultVp9TemporalLayers() - |
| 2665 1); | 2642 1); |
| 2666 } | 2643 } |
| 2667 | 2644 |
| 2668 std::vector<webrtc::VideoStream> streams; | 2645 std::vector<webrtc::VideoStream> streams; |
| 2669 streams.push_back(stream); | 2646 streams.push_back(stream); |
| 2670 return streams; | 2647 return streams; |
| 2671 } | 2648 } |
| 2672 | 2649 |
| 2673 } // namespace cricket | 2650 } // namespace cricket |
| OLD | NEW |