mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
[feat] support getting codec name
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {}
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -28,6 +28,8 @@ class NvidiaVideoEncoder : public VideoEncoder {
|
||||
|
||||
int ForceIdr();
|
||||
|
||||
std::string GetEncoderName() { return "NvidiaH264"; }
|
||||
|
||||
private:
|
||||
int ResetEncodeResolution(unsigned int width, unsigned int height);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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() {}
|
||||
};
|
||||
|
||||
@@ -320,6 +320,9 @@ int PeerConnection::CreateVideoCodec(bool av1, bool hardware_acceleration) {
|
||||
}
|
||||
|
||||
video_codec_inited_ = true;
|
||||
LOG_INFO("Create video codec [{}|{}] finish",
|
||||
video_encoder_->GetEncoderName(), video_decoder_->GetDecoderName());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -341,6 +344,9 @@ int PeerConnection::CreateAudioCodec() {
|
||||
}
|
||||
|
||||
audio_codec_inited_ = true;
|
||||
LOG_INFO("Create audio codec [{}|{}] finish",
|
||||
audio_encoder_->GetEncoderName(), audio_decoder_->GetDecoderName());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user