simple_encoder_wrapper.h (2676B)
1 /* 2 * Copyright (c) 2024 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef API_VIDEO_CODECS_SIMPLE_ENCODER_WRAPPER_H_ 12 #define API_VIDEO_CODECS_SIMPLE_ENCODER_WRAPPER_H_ 13 14 #include <cstdint> 15 #include <functional> 16 #include <memory> 17 #include <optional> 18 #include <string> 19 #include <vector> 20 21 #include "absl/strings/string_view.h" 22 #include "api/scoped_refptr.h" 23 #include "api/transport/rtp/dependency_descriptor.h" 24 #include "api/units/timestamp.h" 25 #include "api/video/video_frame_buffer.h" 26 #include "api/video_codecs/video_encoder_factory_interface.h" 27 #include "api/video_codecs/video_encoder_interface.h" 28 #include "common_video/generic_frame_descriptor/generic_frame_info.h" 29 #include "modules/video_coding/svc/scalable_video_controller.h" 30 31 namespace webrtc { 32 class SimpleEncoderWrapper { 33 public: 34 struct EncodeResult { 35 bool oh_no = false; 36 std::vector<uint8_t> bitstream_data; 37 FrameType frame_type; 38 GenericFrameInfo generic_frame_info; 39 std::optional<FrameDependencyStructure> dependency_structure; 40 }; 41 42 using EncodeResultCallback = std::function<void(const EncodeResult& result)>; 43 44 static std::vector<std::string> SupportedWebrtcSvcModes( 45 const VideoEncoderFactoryInterface::Capabilities::PredictionConstraints& 46 prediction_constraints); 47 48 static std::unique_ptr<SimpleEncoderWrapper> Create( 49 std::unique_ptr<VideoEncoderInterface> encoder, 50 absl::string_view scalability_mode); 51 52 // Should be private, use the Create function instead. 53 SimpleEncoderWrapper(std::unique_ptr<VideoEncoderInterface> encoder, 54 std::unique_ptr<ScalableVideoController> svc_controller); 55 56 // We should really only support CBR, but then we have to think about layer 57 // allocations... eh... For this PoC just use CQP. 58 void SetEncodeQp(int qp); 59 60 void SetEncodeFps(int fps); 61 62 void Encode(scoped_refptr<VideoFrameBuffer> frame_buffer, 63 bool force_keyframe, 64 EncodeResultCallback callback); 65 66 private: 67 std::unique_ptr<VideoEncoderInterface> encoder_; 68 std::unique_ptr<ScalableVideoController> svc_controller_; 69 ScalableVideoController::StreamLayersConfig layer_configs_; 70 int target_qp_ = 0; 71 int fps_ = 0; 72 Timestamp presentation_timestamp_ = Timestamp::Zero(); 73 }; 74 75 } // namespace webrtc 76 #endif // API_VIDEO_CODECS_SIMPLE_ENCODER_WRAPPER_H_