mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 20:55:38 +08:00
Use factory to create encoder/decoder
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include "ffmpeg_decoder.h"
|
||||
#include "ffmpeg_video_decoder.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
@@ -10,7 +10,7 @@ extern "C" {
|
||||
#include <libswscale/swscale.h>
|
||||
};
|
||||
|
||||
VideoDecoder::VideoDecoder() {
|
||||
FfmpegVideoDecoder::FfmpegVideoDecoder() {
|
||||
if (SAVE_ENCODER_STREAM) {
|
||||
file_ = fopen("decode_stream.yuv", "w+b");
|
||||
if (!file_) {
|
||||
@@ -19,7 +19,7 @@ VideoDecoder::VideoDecoder() {
|
||||
}
|
||||
}
|
||||
|
||||
VideoDecoder::~VideoDecoder() {
|
||||
FfmpegVideoDecoder::~FfmpegVideoDecoder() {
|
||||
if (SAVE_ENCODER_STREAM && file_) {
|
||||
fflush(file_);
|
||||
fclose(file_);
|
||||
@@ -38,7 +38,7 @@ VideoDecoder::~VideoDecoder() {
|
||||
av_free(codec_ctx_);
|
||||
}
|
||||
|
||||
int VideoDecoder::Init() {
|
||||
int FfmpegVideoDecoder::Init() {
|
||||
// av_log_set_level(AV_LOG_DEBUG);
|
||||
|
||||
codec_id_ = AV_CODEC_ID_H264;
|
||||
@@ -80,7 +80,7 @@ int VideoDecoder::Init() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VideoDecoder::Decode(
|
||||
int FfmpegVideoDecoder::Decode(
|
||||
const uint8_t *data, int size,
|
||||
std::function<void(VideoFrame)> on_receive_decoded_frame) {
|
||||
if (!first_) {
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef _FFMPEG_DECODER_H_
|
||||
#define _FFMPEG_DECODER_H_
|
||||
#ifndef _FFMPEG_VIDEO_DECODER_H_
|
||||
#define _FFMPEG_VIDEO_DECODER_H_
|
||||
|
||||
#ifdef _WIN32
|
||||
extern "C" {
|
||||
@@ -17,12 +17,12 @@ extern "C" {
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "frame.h"
|
||||
#include "video_decoder.h"
|
||||
|
||||
class VideoDecoder {
|
||||
class FfmpegVideoDecoder : public VideoDecoder {
|
||||
public:
|
||||
VideoDecoder();
|
||||
~VideoDecoder();
|
||||
FfmpegVideoDecoder();
|
||||
~FfmpegVideoDecoder();
|
||||
|
||||
public:
|
||||
int Init();
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "nv_decoder.h"
|
||||
#include "nvidia_video_decoder.h"
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#define SAVE_ENCODER_STREAM 0
|
||||
|
||||
VideoDecoder::VideoDecoder() {
|
||||
NvidiaVideoDecoder::NvidiaVideoDecoder() {
|
||||
if (SAVE_ENCODER_STREAM) {
|
||||
file_ = fopen("decode_stream.h264", "w+b");
|
||||
if (!file_) {
|
||||
@@ -12,7 +12,7 @@ VideoDecoder::VideoDecoder() {
|
||||
}
|
||||
}
|
||||
}
|
||||
VideoDecoder::~VideoDecoder() {
|
||||
NvidiaVideoDecoder::~NvidiaVideoDecoder() {
|
||||
if (SAVE_ENCODER_STREAM && file_) {
|
||||
fflush(file_);
|
||||
fclose(file_);
|
||||
@@ -20,7 +20,7 @@ VideoDecoder::~VideoDecoder() {
|
||||
}
|
||||
}
|
||||
|
||||
int VideoDecoder::Init() {
|
||||
int NvidiaVideoDecoder::Init() {
|
||||
ck(cuInit(0));
|
||||
int nGpu = 0;
|
||||
int iGpu = 0;
|
||||
@@ -43,7 +43,7 @@ int VideoDecoder::Init() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VideoDecoder::Decode(
|
||||
int NvidiaVideoDecoder::Decode(
|
||||
const uint8_t *data, int size,
|
||||
std::function<void(VideoFrame)> on_receive_decoded_frame) {
|
||||
if (!decoder) {
|
||||
@@ -1,15 +1,15 @@
|
||||
#ifndef _NV_DECODER_H_
|
||||
#define _NV_DECODER_H_
|
||||
#ifndef _NVIDIA_VIDEO_DECODER_H_
|
||||
#define _NVIDIA_VIDEO_DECODER_H_
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "NvDecoder.h"
|
||||
#include "frame.h"
|
||||
#include "video_decoder.h"
|
||||
|
||||
class VideoDecoder {
|
||||
class NvidiaVideoDecoder : public VideoDecoder {
|
||||
public:
|
||||
VideoDecoder();
|
||||
~VideoDecoder();
|
||||
NvidiaVideoDecoder();
|
||||
~NvidiaVideoDecoder();
|
||||
|
||||
public:
|
||||
int Init();
|
||||
16
src/media/video/decode/video_decoder.h
Normal file
16
src/media/video/decode/video_decoder.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef _VIDEO_DECODER_H_
|
||||
#define _VIDEO_DECODER_H_
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "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;
|
||||
};
|
||||
|
||||
#endif
|
||||
17
src/media/video/decode/video_decoder_factory.cpp
Normal file
17
src/media/video/decode/video_decoder_factory.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "video_decoder_factory.h"
|
||||
|
||||
#include "ffmpeg/ffmpeg_video_decoder.h"
|
||||
#include "nvcodec/nvidia_video_decoder.h"
|
||||
|
||||
VideoDecoderFactory::VideoDecoderFactory() {}
|
||||
|
||||
VideoDecoderFactory::~VideoDecoderFactory() {}
|
||||
|
||||
VideoDecoder *VideoDecoderFactory::CreateVideoDecoder(
|
||||
bool hardware_acceleration) {
|
||||
if (hardware_acceleration) {
|
||||
return new NvidiaVideoDecoder();
|
||||
} else {
|
||||
return new FfmpegVideoDecoder();
|
||||
}
|
||||
}
|
||||
16
src/media/video/decode/video_decoder_factory.h
Normal file
16
src/media/video/decode/video_decoder_factory.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef _VIDEO_DECODER_FACTORY_H_
|
||||
#define _VIDEO_DECODER_FACTORY_H_
|
||||
|
||||
#include "video_decoder.h"
|
||||
class VideoDecoderFactory {
|
||||
public:
|
||||
VideoDecoderFactory();
|
||||
~VideoDecoderFactory();
|
||||
|
||||
static VideoDecoder *CreateVideoDecoder(bool hardware_acceleration);
|
||||
|
||||
private:
|
||||
bool hardware_acceleration_ = false;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user