mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
1.Use libyuv instead of ffmpeg to do nv12<->yuv420p convertion;2.Use local package to build libyuv(branch stable 2021.4.28 commit eb6e7bb63738e29efd82ea3cf2a115238a89fa51)
This commit is contained in:
@@ -2,14 +2,21 @@
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#define SAVE_DECODER_STREAM 0
|
||||
#define SAVE_RECEIVED_H264_STREAM 0
|
||||
#define SAVE_DECODED_NV12_STREAM 0
|
||||
|
||||
NvidiaVideoDecoder::NvidiaVideoDecoder() {}
|
||||
NvidiaVideoDecoder::~NvidiaVideoDecoder() {
|
||||
if (SAVE_DECODER_STREAM && file_) {
|
||||
fflush(file_);
|
||||
fclose(file_);
|
||||
file_ = nullptr;
|
||||
if (SAVE_RECEIVED_H264_STREAM && file_h264_) {
|
||||
fflush(file_h264_);
|
||||
fclose(file_h264_);
|
||||
file_h264_ = nullptr;
|
||||
}
|
||||
|
||||
if (SAVE_DECODED_NV12_STREAM && file_nv12_) {
|
||||
fflush(file_nv12_);
|
||||
fclose(file_nv12_);
|
||||
file_nv12_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,12 +41,20 @@ int NvidiaVideoDecoder::Init() {
|
||||
|
||||
decoder = new NvDecoder(cuContext, false, cudaVideoCodec_H264, true);
|
||||
|
||||
if (SAVE_DECODER_STREAM) {
|
||||
file_ = fopen("decode_stream.h264", "w+b");
|
||||
if (!file_) {
|
||||
LOG_WARN("Fail to open stream.h264");
|
||||
if (SAVE_RECEIVED_H264_STREAM) {
|
||||
file_h264_ = fopen("received_h264_stream.h264", "w+b");
|
||||
if (!file_h264_) {
|
||||
LOG_WARN("Fail to open received_h264_stream.h264");
|
||||
}
|
||||
}
|
||||
|
||||
if (SAVE_DECODED_NV12_STREAM) {
|
||||
file_nv12_ = fopen("decoded_nv12_stream.yuv", "w+b");
|
||||
if (!file_nv12_) {
|
||||
LOG_WARN("Fail to open decoded_nv12_stream.yuv");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -50,8 +65,8 @@ int NvidiaVideoDecoder::Decode(
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (SAVE_DECODER_STREAM) {
|
||||
fwrite((unsigned char *)data, 1, size, file_);
|
||||
if (SAVE_RECEIVED_H264_STREAM) {
|
||||
fwrite((unsigned char *)data, 1, size, file_h264_);
|
||||
}
|
||||
|
||||
if ((*(data + 4) & 0x1f) == 0x07) {
|
||||
@@ -71,6 +86,10 @@ int NvidiaVideoDecoder::Decode(
|
||||
data, decoder->GetWidth() * decoder->GetHeight() * 3 / 2,
|
||||
decoder->GetWidth(), decoder->GetHeight());
|
||||
on_receive_decoded_frame(decoded_frame);
|
||||
if (SAVE_DECODED_NV12_STREAM) {
|
||||
fwrite((unsigned char *)decoded_frame.Buffer(), 1,
|
||||
decoded_frame.Size(), file_nv12_);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user