| 1 | #ifndef VAAPI_H264_ENCODER_IMPL_H_ |
| 2 | #define VAAPI_H264_ENCODER_IMPL_H_ |
| 3 | |
| 4 | #include <memory> |
| 5 | #include <vector> |
| 6 | |
| 7 | #include "absl/container/inlined_vector.h" |
| 8 | #include "api/transport/rtp/dependency_descriptor.h" |
| 9 | #include "api/video/i420_buffer.h" |
| 10 | #include "api/video/video_codec_constants.h" |
| 11 | #include "api/video_codecs/scalability_mode.h" |
| 12 | #include "api/video_codecs/video_encoder.h" |
| 13 | #include "common_video/h264/h264_bitstream_parser.h" |
| 14 | #include "modules/video_coding/codecs/h264/include/h264.h" |
| 15 | #include "modules/video_coding/svc/scalable_video_controller.h" |
| 16 | #include "modules/video_coding/utility/quality_scaler.h" |
| 17 | |
| 18 | #include "vaapi_h264_encoder_wrapper.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | class VAAPIH264EncoderWrapper : public VideoEncoder { |
| 23 | public: |
| 24 | struct LayerConfig { |
| 25 | int simulcast_idx = 0; |
| 26 | int width = -1; |
| 27 | int height = -1; |
| 28 | bool sending = true; |
| 29 | bool key_frame_request = false; |
| 30 | float max_frame_rate = 0; |
| 31 | uint32_t target_bps = 0; |
| 32 | uint32_t max_bps = 0; |
| 33 | bool frame_dropping_on = false; |
| 34 | int key_frame_interval = 0; |
| 35 | int num_temporal_layers = 1; |
| 36 | |
| 37 | void SetStreamState(bool send_stream); |
| 38 | }; |
| 39 | |
| 40 | public: |
| 41 | VAAPIH264EncoderWrapper(const webrtc::Environment& env, |
| 42 | const SdpVideoFormat& format); |
| 43 | ~VAAPIH264EncoderWrapper() override; |
| 44 | |
| 45 | int32_t InitEncode(const VideoCodec* codec_settings, |
| 46 | const Settings& settings) override; |
| 47 | |
| 48 | int32_t RegisterEncodeCompleteCallback( |
| 49 | EncodedImageCallback* callback) override; |
| 50 | |
| 51 | int32_t Release() override; |
| 52 | |
| 53 | int32_t Encode(const VideoFrame& frame, |
| 54 | const std::vector<VideoFrameType>* frame_types) override; |
| 55 | |
| 56 | void SetRates(const RateControlParameters& rc_parameters) override; |
| 57 | |
| 58 | EncoderInfo GetEncoderInfo() const override; |
| 59 | |
| 60 | private: |
| 61 | VAProfile GetVAProfile() const; |
| 62 | |
| 63 | private: |
| 64 | const webrtc::Environment& env_; |
| 65 | EncodedImageCallback* encoded_image_callback_ = nullptr; |
| 66 | std::unique_ptr<livekit_ffi::VaapiH264EncoderWrapper> encoder_; |
| 67 | LayerConfig configuration_; |
| 68 | EncodedImage encoded_image_; |
| 69 | H264PacketizationMode packetization_mode_; |
| 70 | VideoCodec codec_; |
| 71 | void ReportInit(); |
| 72 | void ReportError(); |
| 73 | bool has_reported_init_ = false; |
| 74 | bool has_reported_error_ = false; |
| 75 | webrtc::H264BitstreamParser h264_bitstream_parser_; |
| 76 | const SdpVideoFormat format_; |
| 77 | H264Profile profile_ = H264Profile::kProfileConstrainedBaseline; |
| 78 | H264Level level_ = H264Level::kLevel1_b; |
| 79 | }; |
| 80 | |
| 81 | } // namespace webrtc |
| 82 | |
| 83 | #endif // VAAPI_H264_ENCODER_IMPL_H_ |