diff --git a/api/video_codecs/BUILD.gn b/api/video_codecs/BUILD.gn index 90ff19769a..9d68e50c1d 100644 --- a/api/video_codecs/BUILD.gn +++ b/api/video_codecs/BUILD.gn @@ -22,13 +22,14 @@ rtc_source_set("video_codecs_api") { "video_decoder_factory.h", "video_encoder.cc", "video_encoder.h", + "video_encoder_config.cc", + "video_encoder_config.h", "video_encoder_factory.h", ] deps = [ "..:optional", "../..:webrtc_common", - "../../:typedefs", "../../common_video", "../../rtc_base:checks", "../../rtc_base:rtc_base_approved", diff --git a/api/video_codecs/video_decoder.h b/api/video_codecs/video_decoder.h index 20505a16af..ee72736f8b 100644 --- a/api/video_codecs/video_decoder.h +++ b/api/video_codecs/video_decoder.h @@ -18,7 +18,6 @@ #include "api/video/video_frame.h" #include "common_types.h" // NOLINT(build/include) #include "common_video/include/video_frame.h" -#include "typedefs.h" // NOLINT(build/include) namespace webrtc { diff --git a/api/video_codecs/video_encoder.h b/api/video_codecs/video_encoder.h index 9d557a3163..9d881020ab 100644 --- a/api/video_codecs/video_encoder.h +++ b/api/video_codecs/video_encoder.h @@ -21,7 +21,6 @@ #include "common_types.h" // NOLINT(build/include) #include "common_video/include/video_frame.h" #include "rtc_base/checks.h" -#include "typedefs.h" // NOLINT(build/include) namespace webrtc { diff --git a/call/video_config.cc b/api/video_codecs/video_encoder_config.cc similarity index 98% rename from call/video_config.cc rename to api/video_codecs/video_encoder_config.cc index 6d7c226c99..ec4aad7a9e 100644 --- a/call/video_config.cc +++ b/api/video_codecs/video_encoder_config.cc @@ -7,7 +7,7 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ -#include "call/video_config.h" +#include "api/video_codecs/video_encoder_config.h" #include #include diff --git a/api/video_codecs/video_encoder_config.h b/api/video_codecs/video_encoder_config.h new file mode 100644 index 0000000000..aab5e8d77d --- /dev/null +++ b/api/video_codecs/video_encoder_config.h @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef API_VIDEO_CODECS_VIDEO_ENCODER_CONFIG_H_ +#define API_VIDEO_CODECS_VIDEO_ENCODER_CONFIG_H_ + +#include +#include + +#include "api/optional.h" +#include "api/video_codecs/sdp_video_format.h" +#include "common_types.h" // NOLINT(build/include) +#include "rtc_base/refcount.h" +#include "rtc_base/scoped_ref_ptr.h" + +namespace webrtc { + +struct VideoStream { + VideoStream(); + ~VideoStream(); + VideoStream(const VideoStream& other); + std::string ToString() const; + + size_t width; + size_t height; + int max_framerate; + + int min_bitrate_bps; + int target_bitrate_bps; + int max_bitrate_bps; + int max_qp; + + rtc::Optional num_temporal_layers; + + rtc::Optional bitrate_priority; + + // TODO(bugs.webrtc.org/8653): Support active per-simulcast layer. + bool active; +}; + +class VideoEncoderConfig { + public: + // These are reference counted to permit copying VideoEncoderConfig and be + // kept alive until all encoder_specific_settings go out of scope. + // TODO(kthelgason): Consider removing the need for copying VideoEncoderConfig + // and use rtc::Optional for encoder_specific_settings instead. + class EncoderSpecificSettings : public rtc::RefCountInterface { + public: + // TODO(pbos): Remove FillEncoderSpecificSettings as soon as VideoCodec is + // not in use and encoder implementations ask for codec-specific structs + // directly. + void FillEncoderSpecificSettings(VideoCodec* codec_struct) const; + + virtual void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const; + virtual void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const; + virtual void FillVideoCodecH264(VideoCodecH264* h264_settings) const; + + private: + ~EncoderSpecificSettings() override {} + friend class VideoEncoderConfig; + }; + + class H264EncoderSpecificSettings : public EncoderSpecificSettings { + public: + explicit H264EncoderSpecificSettings(const VideoCodecH264& specifics); + void FillVideoCodecH264(VideoCodecH264* h264_settings) const override; + + private: + VideoCodecH264 specifics_; + }; + + class Vp8EncoderSpecificSettings : public EncoderSpecificSettings { + public: + explicit Vp8EncoderSpecificSettings(const VideoCodecVP8& specifics); + void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const override; + + private: + VideoCodecVP8 specifics_; + }; + + class Vp9EncoderSpecificSettings : public EncoderSpecificSettings { + public: + explicit Vp9EncoderSpecificSettings(const VideoCodecVP9& specifics); + void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const override; + + private: + VideoCodecVP9 specifics_; + }; + + enum class ContentType { + kRealtimeVideo, + kScreen, + }; + + class VideoStreamFactoryInterface : public rtc::RefCountInterface { + public: + // An implementation should return a std::vector with the + // wanted VideoStream settings for the given video resolution. + // The size of the vector may not be larger than + // |encoder_config.number_of_streams|. + virtual std::vector CreateEncoderStreams( + int width, + int height, + const VideoEncoderConfig& encoder_config) = 0; + + protected: + ~VideoStreamFactoryInterface() override {} + }; + + VideoEncoderConfig& operator=(VideoEncoderConfig&&) = default; + VideoEncoderConfig& operator=(const VideoEncoderConfig&) = delete; + + // Mostly used by tests. Avoid creating copies if you can. + VideoEncoderConfig Copy() const { return VideoEncoderConfig(*this); } + + VideoEncoderConfig(); + VideoEncoderConfig(VideoEncoderConfig&&); + ~VideoEncoderConfig(); + std::string ToString() const; + + // TODO(nisse): Consolidate on one of these. + VideoCodecType codec_type; + SdpVideoFormat video_format; + + rtc::scoped_refptr video_stream_factory; + std::vector spatial_layers; + ContentType content_type; + rtc::scoped_refptr encoder_specific_settings; + + // Padding will be used up to this bitrate regardless of the bitrate produced + // by the encoder. Padding above what's actually produced by the encoder helps + // maintaining a higher bitrate estimate. Padding will however not be sent + // unless the estimated bandwidth indicates that the link can handle it. + int min_transmit_bitrate_bps; + int max_bitrate_bps; + // The bitrate priority used for all VideoStreams. + double bitrate_priority; + + // The simulcast layer's configurations set by the application for this video + // sender. These are modified by the video_stream_factory before being passed + // down to lower layers for the video encoding. + std::vector simulcast_layers; + + // Max number of encoded VideoStreams to produce. + size_t number_of_streams; + + private: + // Access to the copy constructor is private to force use of the Copy() + // method for those exceptional cases where we do use it. + VideoEncoderConfig(const VideoEncoderConfig&); +}; + +} // namespace webrtc + +#endif // API_VIDEO_CODECS_VIDEO_ENCODER_CONFIG_H_ diff --git a/call/BUILD.gn b/call/BUILD.gn index 57ee793a65..c509acedbb 100644 --- a/call/BUILD.gn +++ b/call/BUILD.gn @@ -208,7 +208,6 @@ rtc_static_library("call") { rtc_source_set("video_stream_api") { sources = [ - "video_config.cc", "video_config.h", "video_receive_stream.cc", "video_receive_stream.h", @@ -328,6 +327,7 @@ if (rtc_include_tests) { "..:webrtc_common", "../api/audio_codecs:builtin_audio_encoder_factory", "../api/video:video_bitrate_allocation", + "../api/video_codecs:video_codecs_api", "../logging:rtc_event_log_api", "../modules/audio_coding", "../modules/audio_device", diff --git a/call/call_perf_tests.cc b/call/call_perf_tests.cc index f0580857af..3b4264f9d4 100644 --- a/call/call_perf_tests.cc +++ b/call/call_perf_tests.cc @@ -15,8 +15,8 @@ #include "api/audio_codecs/builtin_audio_encoder_factory.h" #include "api/video/video_bitrate_allocation.h" +#include "api/video_codecs/video_encoder_config.h" #include "call/call.h" -#include "call/video_config.h" #include "logging/rtc_event_log/rtc_event_log.h" #include "modules/audio_coding/include/audio_coding_module.h" #include "modules/audio_device/include/test_audio_device.h" diff --git a/call/video_config.h b/call/video_config.h index 93f956201b..e05b5dc667 100644 --- a/call/video_config.h +++ b/call/video_config.h @@ -11,154 +11,8 @@ #ifndef CALL_VIDEO_CONFIG_H_ #define CALL_VIDEO_CONFIG_H_ -#include -#include - -#include "api/optional.h" -#include "api/video_codecs/sdp_video_format.h" -#include "common_types.h" // NOLINT(build/include) -#include "rtc_base/basictypes.h" -#include "rtc_base/refcount.h" -#include "rtc_base/scoped_ref_ptr.h" -#include "typedefs.h" // NOLINT(build/include) - -namespace webrtc { - -struct VideoStream { - VideoStream(); - ~VideoStream(); - VideoStream(const VideoStream& other); - std::string ToString() const; - - size_t width; - size_t height; - int max_framerate; - - int min_bitrate_bps; - int target_bitrate_bps; - int max_bitrate_bps; - int max_qp; - - rtc::Optional num_temporal_layers; - - rtc::Optional bitrate_priority; - - // TODO(bugs.webrtc.org/8653): Support active per-simulcast layer. - bool active; -}; - -class VideoEncoderConfig { - public: - // These are reference counted to permit copying VideoEncoderConfig and be - // kept alive until all encoder_specific_settings go out of scope. - // TODO(kthelgason): Consider removing the need for copying VideoEncoderConfig - // and use rtc::Optional for encoder_specific_settings instead. - class EncoderSpecificSettings : public rtc::RefCountInterface { - public: - // TODO(pbos): Remove FillEncoderSpecificSettings as soon as VideoCodec is - // not in use and encoder implementations ask for codec-specific structs - // directly. - void FillEncoderSpecificSettings(VideoCodec* codec_struct) const; - - virtual void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const; - virtual void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const; - virtual void FillVideoCodecH264(VideoCodecH264* h264_settings) const; - - private: - ~EncoderSpecificSettings() override {} - friend class VideoEncoderConfig; - }; - - class H264EncoderSpecificSettings : public EncoderSpecificSettings { - public: - explicit H264EncoderSpecificSettings(const VideoCodecH264& specifics); - void FillVideoCodecH264(VideoCodecH264* h264_settings) const override; - - private: - VideoCodecH264 specifics_; - }; - - class Vp8EncoderSpecificSettings : public EncoderSpecificSettings { - public: - explicit Vp8EncoderSpecificSettings(const VideoCodecVP8& specifics); - void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const override; - - private: - VideoCodecVP8 specifics_; - }; - - class Vp9EncoderSpecificSettings : public EncoderSpecificSettings { - public: - explicit Vp9EncoderSpecificSettings(const VideoCodecVP9& specifics); - void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const override; - - private: - VideoCodecVP9 specifics_; - }; - - enum class ContentType { - kRealtimeVideo, - kScreen, - }; - - class VideoStreamFactoryInterface : public rtc::RefCountInterface { - public: - // An implementation should return a std::vector with the - // wanted VideoStream settings for the given video resolution. - // The size of the vector may not be larger than - // |encoder_config.number_of_streams|. - virtual std::vector CreateEncoderStreams( - int width, - int height, - const VideoEncoderConfig& encoder_config) = 0; - - protected: - ~VideoStreamFactoryInterface() override {} - }; - - VideoEncoderConfig& operator=(VideoEncoderConfig&&) = default; - VideoEncoderConfig& operator=(const VideoEncoderConfig&) = delete; - - // Mostly used by tests. Avoid creating copies if you can. - VideoEncoderConfig Copy() const { return VideoEncoderConfig(*this); } - - VideoEncoderConfig(); - VideoEncoderConfig(VideoEncoderConfig&&); - ~VideoEncoderConfig(); - std::string ToString() const; - - // TODO(nisse): Consolidate on one of these. - VideoCodecType codec_type; - SdpVideoFormat video_format; - - rtc::scoped_refptr video_stream_factory; - std::vector spatial_layers; - ContentType content_type; - rtc::scoped_refptr encoder_specific_settings; - - // Padding will be used up to this bitrate regardless of the bitrate produced - // by the encoder. Padding above what's actually produced by the encoder helps - // maintaining a higher bitrate estimate. Padding will however not be sent - // unless the estimated bandwidth indicates that the link can handle it. - int min_transmit_bitrate_bps; - int max_bitrate_bps; - // The bitrate priority used for all VideoStreams. - double bitrate_priority; - - // The simulcast layer's configurations set by the application for this video - // sender. These are modified by the video_stream_factory before being passed - // down to lower layers for the video encoding. - std::vector simulcast_layers; - - // Max number of encoded VideoStreams to produce. - size_t number_of_streams; - - private: - // Access to the copy constructor is private to force use of the Copy() - // method for those exceptional cases where we do use it. - VideoEncoderConfig(const VideoEncoderConfig&); -}; - -} // namespace webrtc +// TODO(bugs.webrtc.org/8830): Header file moved to api/. Delete this +// file as soon as downstream applications are updated. +#include "api/video_codecs/video_encoder_config.h" #endif // CALL_VIDEO_CONFIG_H_ diff --git a/call/video_send_stream.h b/call/video_send_stream.h index 88cfddf54c..65e16873ff 100644 --- a/call/video_send_stream.h +++ b/call/video_send_stream.h @@ -21,9 +21,9 @@ #include "api/rtp_headers.h" #include "api/video/video_sink_interface.h" #include "api/videosourceinterface.h" +#include "api/video_codecs/video_encoder_config.h" #include "api/video_codecs/video_encoder_factory.h" #include "call/rtp_config.h" -#include "call/video_config.h" #include "common_types.h" // NOLINT(build/include) #include "common_video/include/frame_callback.h" #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" @@ -31,8 +31,6 @@ namespace webrtc { -class VideoEncoder; - class VideoSendStream { public: struct StreamStats { diff --git a/media/engine/simulcast.h b/media/engine/simulcast.h index 005c80e944..7ab5854fd1 100644 --- a/media/engine/simulcast.h +++ b/media/engine/simulcast.h @@ -14,7 +14,7 @@ #include #include -#include "call/video_config.h" +#include "api/video_codecs/video_encoder_config.h" #include "rtc_base/basictypes.h" namespace cricket { diff --git a/modules/video_coding/BUILD.gn b/modules/video_coding/BUILD.gn index b6a334a12d..d5a76a0ed8 100644 --- a/modules/video_coding/BUILD.gn +++ b/modules/video_coding/BUILD.gn @@ -145,7 +145,6 @@ rtc_static_library("video_coding") { "../../api/video:video_frame", "../../api/video:video_frame_i420", "../../api/video_codecs:video_codecs_api", - "../../call:video_stream_api", "../../common_video", "../../rtc_base:checks", "../../rtc_base:rtc_base", diff --git a/modules/video_coding/include/video_codec_initializer.h b/modules/video_coding/include/video_codec_initializer.h index 2df1fd2927..ee70810f62 100644 --- a/modules/video_coding/include/video_codec_initializer.h +++ b/modules/video_coding/include/video_codec_initializer.h @@ -15,7 +15,7 @@ #include #include -#include "call/video_config.h" +#include "api/video_codecs/video_encoder_config.h" namespace webrtc { diff --git a/test/call_test.cc b/test/call_test.cc index 1065463a5a..725a17144f 100644 --- a/test/call_test.cc +++ b/test/call_test.cc @@ -14,8 +14,8 @@ #include "api/audio_codecs/builtin_audio_decoder_factory.h" #include "api/audio_codecs/builtin_audio_encoder_factory.h" +#include "api/video_codecs/video_encoder_config.h" #include "call/rtp_transport_controller_send.h" -#include "call/video_config.h" #include "modules/audio_mixer/audio_mixer_impl.h" #include "rtc_base/checks.h" #include "rtc_base/event.h"