[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: public:
int Init(); int Init();
int Decode(const uint8_t *data, int size, int Decode(const uint8_t *data, int size,
std::function<void(uint8_t *, int)> on_receive_decoded_frame); std::function<void(uint8_t *, int)> on_receive_decoded_frame);
std::string GetDecoderName() { return "Opus"; }
private: private:
/* data */ /* data */
OpusDecoder *opus_decoder_ = nullptr; OpusDecoder *opus_decoder_ = nullptr;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -320,6 +320,9 @@ int PeerConnection::CreateVideoCodec(bool av1, bool hardware_acceleration) {
} }
video_codec_inited_ = true; video_codec_inited_ = true;
LOG_INFO("Create video codec [{}|{}] finish",
video_encoder_->GetEncoderName(), video_decoder_->GetDecoderName());
return 0; return 0;
} }
@@ -341,6 +344,9 @@ int PeerConnection::CreateAudioCodec() {
} }
audio_codec_inited_ = true; audio_codec_inited_ = true;
LOG_INFO("Create audio codec [{}|{}] finish",
audio_encoder_->GetEncoderName(), audio_decoder_->GetDecoderName());
return 0; return 0;
} }