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:
|
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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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() {}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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() {}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user