123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- #ifndef EASYCODEC_EASY_ENCODE_H_
- #define EASYCODEC_EASY_ENCODE_H_
- #include <functional>
- #include <memory>
- #include "cxxutil/edk_attribute.h"
- #include "cxxutil/exception.h"
- #include "easycodec/vformat.h"
- namespace edk {
- struct RateControl {
-
- bool vbr{false};
-
- uint32_t gop{0};
-
- uint32_t frame_rate_num{0};
-
- uint32_t frame_rate_den{0};
-
- uint32_t bit_rate{0};
-
- uint32_t max_bit_rate{0};
-
- uint32_t max_qp{0};
-
- uint32_t min_qp{0};
- };
- enum class VideoProfile {
- H264_BASELINE = 0,
- H264_MAIN,
- H264_HIGH,
- H264_HIGH_10,
- H265_MAIN,
- H265_MAIN_STILL,
- H265_MAIN_INTRA,
- H265_MAIN_10,
- PROFILE_MAX
- };
- enum class VideoLevel {
- H264_1 = 0,
- H264_1B,
- H264_11,
- H264_12,
- H264_13,
- H264_2,
- H264_21,
- H264_22,
- H264_3,
- H264_31,
- H264_32,
- H264_4,
- H264_41,
- H264_42,
- H264_5,
- H264_51,
- H265_MAIN_1,
- H265_HIGH_1,
- H265_MAIN_2,
- H265_HIGH_2,
- H265_MAIN_21,
- H265_HIGH_21,
- H265_MAIN_3,
- H265_HIGH_3,
- H265_MAIN_31,
- H265_HIGH_31,
- H265_MAIN_4,
- H265_HIGH_4,
- H265_MAIN_41,
- H265_HIGH_41,
- H265_MAIN_5,
- H265_HIGH_5,
- H265_MAIN_51,
- H265_HIGH_51,
- H265_MAIN_52,
- H265_HIGH_52,
- H265_MAIN_6,
- H265_HIGH_6,
- H265_MAIN_61,
- H265_HIGH_61,
- H265_MAIN_62,
- H265_HIGH_62,
- LEVEL_MAX
- };
- enum class GopType { BIDIRECTIONAL, LOW_DELAY, PYRAMID };
- using EncodePacketCallback = std::function<void(const CnPacket&)>;
- using EncodeEosCallback = std::function<void()>;
- class EncodeHandler;
- class EasyEncode {
- public:
- friend class EncodeHandler;
-
- struct Attr {
-
- Geometry frame_geometry;
-
- PixelFmt pixel_format;
-
- CodecType codec_type = CodecType::H264;
-
- ColorStd color_std = ColorStd::ITU_BT_709;
-
- uint32_t jpeg_qfactor = 50;
-
- VideoProfile profile = VideoProfile::H264_MAIN;
-
- VideoLevel level = VideoLevel::H264_41;
-
- RateControl rate_control;
-
- uint32_t input_buffer_num = 3;
-
- uint32_t output_buffer_num = 4;
-
- uint32_t p_frame_num = 0;
-
- uint32_t b_frame_num = 0;
-
- GopType gop_type = GopType::BIDIRECTIONAL;
-
- bool insert_spspps_when_idr = true;
-
- bool silent = false;
-
- EncodePacketCallback packet_callback = NULL;
-
- EncodeEosCallback eos_callback = NULL;
-
- int dev_id = 0;
- };
-
- static std::unique_ptr<EasyEncode> New(const Attr& attr);
-
- void AbortEncoder();
-
- Attr GetAttr() const;
-
- ~EasyEncode();
-
- bool SendDataCPU(const CnFrame& frame, bool eos = false);
-
- void ReleaseBuffer(uint64_t buf_id);
- private:
- EasyEncode();
- EncodeHandler* handler_ = nullptr;
- EasyEncode(const EasyEncode&) = delete;
- const EasyEncode& operator=(const EasyEncode&) = delete;
- };
- }
- #endif
|