BlueGit

ict rusty-teams

Files

rusty-teams / vendor / webrtc-sys / src / jetson / h264_encoder_impl.h

h264_encoder_impl.h

h264_encoder_impl.h 3.2 KiB Download Raw
1/*
2 * Copyright 2026 LiveKit, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef WEBRTC_JETSON_H264_ENCODER_IMPL_H_
18#define WEBRTC_JETSON_H264_ENCODER_IMPL_H_
19
20#include <cstdint>
21#include <memory>
22#include <vector>
23
24#include "absl/container/inlined_vector.h"
25#include "api/environment/environment.h"
26#include "api/transport/rtp/dependency_descriptor.h"
27#include "api/video/i420_buffer.h"
28#include "api/video/video_codec_constants.h"
29#include "api/video_codecs/sdp_video_format.h"
30#include "api/video_codecs/scalability_mode.h"
31#include "api/video_codecs/video_encoder.h"
32#include "common_video/h264/h264_bitstream_parser.h"
33#include "modules/video_coding/codecs/h264/include/h264.h"
34#include "modules/video_coding/svc/scalable_video_controller.h"
35#include "modules/video_coding/utility/quality_scaler.h"
36
37#include "jetson_mmapi_encoder.h"
38
39namespace webrtc {
40
41class JetsonH264EncoderImpl : public VideoEncoder {
42 public:
43 struct LayerConfig {
44 int simulcast_idx = 0;
45 int width = -1;
46 int height = -1;
47 bool sending = true;
48 bool key_frame_request = false;
49 float max_frame_rate = 0;
50 uint32_t target_bps = 0;
51 uint32_t max_bps = 0;
52 bool frame_dropping_on = false;
53 int key_frame_interval = 0;
54 int num_temporal_layers = 1;
55
56 void SetStreamState(bool send_stream);
57 };
58
59 public:
60 JetsonH264EncoderImpl(const webrtc::Environment& env,
61 const SdpVideoFormat& format);
62 ~JetsonH264EncoderImpl() override;
63
64 int32_t InitEncode(const VideoCodec* codec_settings,
65 const Settings& settings) override;
66
67 int32_t RegisterEncodeCompleteCallback(
68 EncodedImageCallback* callback) override;
69
70 int32_t Release() override;
71
72 int32_t Encode(const VideoFrame& frame,
73 const std::vector<VideoFrameType>* frame_types) override;
74
75 void SetRates(const RateControlParameters& rc_parameters) override;
76
77 EncoderInfo GetEncoderInfo() const override;
78
79 private:
80 int32_t ProcessEncodedFrame(std::vector<uint8_t>& packet,
81 const ::webrtc::VideoFrame& input_frame,
82 bool is_keyframe);
83
84 const webrtc::Environment& env_;
85 EncodedImageCallback* encoded_image_callback_ = nullptr;
86 livekit::JetsonMmapiEncoder encoder_;
87 LayerConfig configuration_;
88 EncodedImage encoded_image_;
89 H264PacketizationMode packetization_mode_;
90 VideoCodec codec_;
91 void ReportInit();
92 void ReportError();
93 bool has_reported_init_ = false;
94 bool has_reported_error_ = false;
95 webrtc::H264BitstreamParser h264_bitstream_parser_;
96 const SdpVideoFormat format_;
97 H264Profile profile_ = H264Profile::kProfileConstrainedBaseline;
98 H264Level level_ = H264Level::kLevel1_b;
99};
100
101} // namespace webrtc
102
103#endif // WEBRTC_JETSON_H264_ENCODER_IMPL_H_