Files
crossdesk/src/media/video/encode/openh264/openh264_encoder.h

72 lines
1.7 KiB
C++

/*
* @Author: DI JUNKUN
* @Date: 2023-11-03
* Copyright (c) 2023 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _OPENH264_ENCODER_H_
#define _OPENH264_ENCODER_H_
#include <wels/codec_api.h>
#include <wels/codec_app_def.h>
#include <wels/codec_def.h>
#include <wels/codec_ver.h>
#include <functional>
#include <vector>
#include "video_encoder.h"
class OpenH264Encoder : public VideoEncoder {
public:
OpenH264Encoder();
virtual ~OpenH264Encoder();
int Init();
int Encode(const XVideoFrame* video_frame,
std::function<int(char* encoded_packets, size_t size,
VideoFrameType frame_type)>
on_encoded_image);
int ForceIdr();
std::string GetEncoderName() { return "OpenH264"; }
private:
int InitEncoderParams(int width, int height);
int ResetEncodeResolution(unsigned int width, unsigned int height);
int Release();
private:
uint32_t frame_width_ = 1280;
uint32_t frame_height_ = 720;
int key_frame_interval_ = 300;
int target_bitrate_ = 10000000;
int max_bitrate_ = 10000000;
int max_payload_size_ = 1400;
int max_frame_rate_ = 30;
std::vector<std::vector<uint8_t>> encoded_packets_;
unsigned char* encoded_image_ = nullptr;
FILE* file_h264_ = nullptr;
FILE* file_nv12_ = nullptr;
unsigned char* nv12_data_ = nullptr;
unsigned int seq_ = 0;
// openh264
ISVCEncoder* openh264_encoder_ = nullptr;
SEncParamExt encoder_params_;
int video_format_;
SSourcePicture raw_frame_;
unsigned char* yuv420p_frame_ = nullptr;
size_t yuv420p_frame_capacity_ = 0;
uint8_t* encoded_frame_ = nullptr;
size_t encoded_frame_capacity_ = 0;
size_t encoded_frame_size_ = 0;
bool got_output = false;
bool is_keyframe = false;
int temporal_ = 1;
};
#endif