diff --git a/sdk/android/BUILD.gn b/sdk/android/BUILD.gn index e8505ece08..ea25065ee2 100644 --- a/sdk/android/BUILD.gn +++ b/sdk/android/BUILD.gn @@ -655,6 +655,7 @@ if (current_os == "linux" || is_android) { "../../modules/video_coding:codec_globals_headers", "../../modules/video_coding:video_codec_interface", "../../modules/video_coding:video_coding_utility", + "../../modules/video_coding/svc:scalable_video_controller", "../../rtc_base", "../../rtc_base:checks", "../../rtc_base:rtc_task_queue", diff --git a/sdk/android/src/jni/video_encoder_wrapper.cc b/sdk/android/src/jni/video_encoder_wrapper.cc index 4a1faeb0bd..4e6d764457 100644 --- a/sdk/android/src/jni/video_encoder_wrapper.cc +++ b/sdk/android/src/jni/video_encoder_wrapper.cc @@ -15,6 +15,7 @@ #include "common_video/h264/h264_common.h" #include "modules/video_coding/include/video_codec_interface.h" #include "modules/video_coding/include/video_error_codes.h" +#include "modules/video_coding/svc/scalable_video_controller_no_layering.h" #include "modules/video_coding/utility/vp8_header_parser.h" #include "modules/video_coding/utility/vp9_uncompressed_header_parser.h" #include "rtc_base/logging.h" @@ -325,6 +326,19 @@ CodecSpecificInfo VideoEncoderWrapper::ParseCodecSpecificInfo( const bool key_frame = frame._frameType == VideoFrameType::kVideoFrameKey; CodecSpecificInfo info; + // For stream with scalability, NextFrameConfig should be called before + // encoding and used to configure encoder, then passed here e.g. via + // FrameExtraInfo structure. But while this encoder wrapper uses only trivial + // scalability, NextFrameConfig can be called here. + auto layer_frames = svc_controller_.NextFrameConfig(/*reset=*/key_frame); + RTC_DCHECK_EQ(layer_frames.size(), 1); + info.generic_frame_info = svc_controller_.OnEncodeDone(layer_frames[0]); + if (key_frame) { + info.template_structure = svc_controller_.DependencyStructure(); + info.template_structure->resolutions = { + RenderResolution(frame._encodedWidth, frame._encodedHeight)}; + } + info.codecType = codec_settings_.codecType; switch (codec_settings_.codecType) { diff --git a/sdk/android/src/jni/video_encoder_wrapper.h b/sdk/android/src/jni/video_encoder_wrapper.h index bb098bb7c7..1a42b05bc6 100644 --- a/sdk/android/src/jni/video_encoder_wrapper.h +++ b/sdk/android/src/jni/video_encoder_wrapper.h @@ -12,6 +12,7 @@ #define SDK_ANDROID_SRC_JNI_VIDEO_ENCODER_WRAPPER_H_ #include + #include #include #include @@ -21,6 +22,7 @@ #include "api/video_codecs/video_encoder.h" #include "common_video/h264/h264_bitstream_parser.h" #include "modules/video_coding/codecs/vp9/include/vp9_globals.h" +#include "modules/video_coding/svc/scalable_video_controller_no_layering.h" #include "rtc_base/synchronization/mutex.h" #include "sdk/android/src/jni/jni_helpers.h" #include "sdk/android/src/jni/video_frame.h" @@ -96,6 +98,8 @@ class VideoEncoderWrapper : public VideoEncoder { EncoderInfo encoder_info_; H264BitstreamParser h264_bitstream_parser_; + // Fills frame dependencies in codec-agnostic format. + ScalableVideoControllerNoLayering svc_controller_; // VP9 variables to populate codec specific structure. GofInfoVP9 gof_; // Contains each frame's temporal information for // non-flexible VP9 mode.