[feat] support getting codec name

This commit is contained in:
dijunkun
2024-09-23 14:14:45 +08:00
parent 5eb455b6c8
commit c7b934026b
11 changed files with 38 additions and 0 deletions

View File

@@ -25,9 +25,12 @@ class AudioDecoder {
public:
int Init();
int Decode(const uint8_t *data, int size,
std::function<void(uint8_t *, int)> on_receive_decoded_frame);
std::string GetDecoderName() { return "Opus"; }
private:
/* data */
OpusDecoder *opus_decoder_ = nullptr;

View File

@@ -22,11 +22,15 @@ class AudioEncoder {
public:
int Init();
int Encode(const uint8_t* data, int size,
std::function<int(char* encoded_audio_buffer, size_t size)>
on_encoded_audio_buffer);
int OnEncodedAudioBuffer(char* encoded_audio_buffer, size_t size);
std::string GetEncoderName() { return "Opus"; }
private:
OpusEncoder* opus_encoder_ = nullptr;
int sample_rate_ = 48000;

View File

@@ -19,9 +19,12 @@ class Dav1dAv1Decoder : public VideoDecoder {
public:
int Init();
int Decode(const uint8_t *data, int size,
std::function<void(VideoFrame)> on_receive_decoded_frame);
std::string GetDecoderName() { return "Dav1dAv1"; }
private:
VideoFrame *nv12_frame_ = 0;
int nv12_frame_capacity_ = 0;

View File

@@ -13,9 +13,12 @@ class NvidiaVideoDecoder : public VideoDecoder {
public:
int Init();
int Decode(const uint8_t* data, int size,
std::function<void(VideoFrame)> on_receive_decoded_frame);
std::string GetDecoderName() { return "NvidiaH264"; }
private:
NvDecoder* decoder = nullptr;
bool get_first_keyframe_ = false;

View File

@@ -23,9 +23,12 @@ class OpenH264Decoder : public VideoDecoder {
public:
int Init();
int Decode(const uint8_t* data, int size,
std::function<void(VideoFrame)> on_receive_decoded_frame);
std::string GetDecoderName() { return "OpenH264"; }
private:
ISVCDecoder* openh264_decoder_ = nullptr;
bool get_first_keyframe_ = false;

View File

@@ -11,15 +11,20 @@
#include <cstdint>
#include <cstdio>
#include <functional>
#include <string>
#include "video_frame.h"
class VideoDecoder {
public:
virtual int Init() = 0;
virtual int Decode(
const uint8_t *data, int size,
std::function<void(VideoFrame)> on_receive_decoded_frame) = 0;
virtual std::string GetDecoderName() = 0;
VideoDecoder() = default;
virtual ~VideoDecoder() {}
};

View File

@@ -52,6 +52,8 @@ class AomAv1Encoder : public VideoEncoder {
int ForceIdr();
std::string GetEncoderName() { return "AomAV1"; }
private:
template <typename P>
bool SetEncoderControlParameters(int param_id, P param_value);

View File

@@ -28,6 +28,8 @@ class NvidiaVideoEncoder : public VideoEncoder {
int ForceIdr();
std::string GetEncoderName() { return "NvidiaH264"; }
private:
int ResetEncodeResolution(unsigned int width, unsigned int height);

View File

@@ -39,6 +39,8 @@ class OpenH264Encoder : public VideoEncoder {
int ForceIdr();
std::string GetEncoderName() { return "OpenH264"; }
private:
int InitEncoderParams(int width, int height);
int ResetEncodeResolution(unsigned int width, unsigned int height);

View File

@@ -5,6 +5,7 @@
#include <cstdint>
#include <cstdio>
#include <functional>
#include <string>
#include "x.h"
@@ -18,6 +19,7 @@ class VideoEncoder {
public:
virtual int Init() = 0;
virtual int Encode(const uint8_t* pData, int nSize,
std::function<int(char* encoded_packets, size_t size,
VideoFrameType frame_type)>
@@ -29,8 +31,11 @@ class VideoEncoder {
on_encoded_image) = 0;
virtual int OnEncodedImage(char* encoded_packets, size_t size) = 0;
virtual int ForceIdr() = 0;
virtual std::string GetEncoderName() = 0;
VideoEncoder() = default;
virtual ~VideoEncoder() {}
};