mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
[fix] fix crash due to yuv420p convert to nv12
This commit is contained in:
@@ -39,6 +39,22 @@ void CopyYUVWithStride(uint8_t *srcY, uint8_t *srcU, uint8_t *srcV, int width,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConvertYUV420toNV12(const unsigned char *yuvData, unsigned char *nv12Data,
|
||||||
|
int width, int height) {
|
||||||
|
int ySize = width * height;
|
||||||
|
int uvSize = ySize / 4;
|
||||||
|
const unsigned char *yData = yuvData;
|
||||||
|
const unsigned char *uData = yData + ySize;
|
||||||
|
const unsigned char *vData = uData + uvSize;
|
||||||
|
|
||||||
|
std::memcpy(nv12Data, yData, ySize);
|
||||||
|
|
||||||
|
for (int i = 0; i < uvSize; i++) {
|
||||||
|
nv12Data[ySize + i * 2] = uData[i];
|
||||||
|
nv12Data[ySize + i * 2 + 1] = vData[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
OpenH264Decoder::OpenH264Decoder() {}
|
OpenH264Decoder::OpenH264Decoder() {}
|
||||||
OpenH264Decoder::~OpenH264Decoder() {
|
OpenH264Decoder::~OpenH264Decoder() {
|
||||||
if (openh264_decoder_) {
|
if (openh264_decoder_) {
|
||||||
@@ -138,15 +154,20 @@ int OpenH264Decoder::Decode(
|
|||||||
frame_width_ * frame_height_ * 3 / 2, nv12_stream_);
|
frame_width_ * frame_height_ * 3 / 2, nv12_stream_);
|
||||||
}
|
}
|
||||||
|
|
||||||
libyuv::I420ToNV12(
|
if (0) {
|
||||||
(const uint8_t *)decoded_frame_, frame_width_,
|
ConvertYUV420toNV12(decoded_frame_, nv12_frame_, frame_width_,
|
||||||
(const uint8_t *)decoded_frame_ + frame_width_ * frame_height_,
|
frame_height_);
|
||||||
frame_width_ / 2,
|
} else {
|
||||||
(const uint8_t *)decoded_frame_ +
|
libyuv::I420ToNV12(
|
||||||
frame_width_ * frame_height_ * 3 / 2,
|
(const uint8_t *)decoded_frame_, frame_width_,
|
||||||
frame_width_ / 2, nv12_frame_, frame_width_,
|
(const uint8_t *)decoded_frame_ + frame_width_ * frame_height_,
|
||||||
nv12_frame_ + frame_width_ * frame_height_, frame_width_,
|
frame_width_ / 2,
|
||||||
frame_width_, frame_height_);
|
(const uint8_t *)decoded_frame_ +
|
||||||
|
frame_width_ * frame_height_ * 5 / 4,
|
||||||
|
frame_width_ / 2, nv12_frame_, frame_width_,
|
||||||
|
nv12_frame_ + frame_width_ * frame_height_, frame_width_,
|
||||||
|
frame_width_, frame_height_);
|
||||||
|
}
|
||||||
|
|
||||||
VideoFrame decoded_frame(nv12_frame_,
|
VideoFrame decoded_frame(nv12_frame_,
|
||||||
frame_width_ * frame_height_ * 3 / 2,
|
frame_width_ * frame_height_ * 3 / 2,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ VideoDecoderFactory::~VideoDecoderFactory() {}
|
|||||||
std::unique_ptr<VideoDecoder> VideoDecoderFactory::CreateVideoDecoder(
|
std::unique_ptr<VideoDecoder> VideoDecoderFactory::CreateVideoDecoder(
|
||||||
bool hardware_acceleration, bool av1_encoding) {
|
bool hardware_acceleration, bool av1_encoding) {
|
||||||
if (av1_encoding) {
|
if (av1_encoding) {
|
||||||
|
LOG_INFO("Use dav1d decoder");
|
||||||
return std::make_unique<Dav1dAv1Decoder>(Dav1dAv1Decoder());
|
return std::make_unique<Dav1dAv1Decoder>(Dav1dAv1Decoder());
|
||||||
} else {
|
} else {
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
@@ -25,11 +26,13 @@ std::unique_ptr<VideoDecoder> VideoDecoderFactory::CreateVideoDecoder(
|
|||||||
#else
|
#else
|
||||||
if (hardware_acceleration) {
|
if (hardware_acceleration) {
|
||||||
if (CheckIsHardwareAccerlerationSupported()) {
|
if (CheckIsHardwareAccerlerationSupported()) {
|
||||||
|
LOG_INFO("Use nvidia decoder");
|
||||||
return std::make_unique<NvidiaVideoDecoder>(NvidiaVideoDecoder());
|
return std::make_unique<NvidiaVideoDecoder>(NvidiaVideoDecoder());
|
||||||
} else {
|
} else {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
LOG_INFO("Use openh264 decoder");
|
||||||
return std::make_unique<OpenH264Decoder>(OpenH264Decoder());
|
return std::make_unique<OpenH264Decoder>(OpenH264Decoder());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ VideoEncoderFactory::~VideoEncoderFactory() {}
|
|||||||
std::unique_ptr<VideoEncoder> VideoEncoderFactory::CreateVideoEncoder(
|
std::unique_ptr<VideoEncoder> VideoEncoderFactory::CreateVideoEncoder(
|
||||||
bool hardware_acceleration, bool av1_encoding) {
|
bool hardware_acceleration, bool av1_encoding) {
|
||||||
if (av1_encoding) {
|
if (av1_encoding) {
|
||||||
|
LOG_INFO("Use AOM encoder");
|
||||||
return std::make_unique<AomAv1Encoder>(AomAv1Encoder());
|
return std::make_unique<AomAv1Encoder>(AomAv1Encoder());
|
||||||
} else {
|
} else {
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
@@ -25,11 +26,13 @@ std::unique_ptr<VideoEncoder> VideoEncoderFactory::CreateVideoEncoder(
|
|||||||
#else
|
#else
|
||||||
if (hardware_acceleration) {
|
if (hardware_acceleration) {
|
||||||
if (CheckIsHardwareAccerlerationSupported()) {
|
if (CheckIsHardwareAccerlerationSupported()) {
|
||||||
|
LOG_INFO("Use Nvidia encoder");
|
||||||
return std::make_unique<NvidiaVideoEncoder>(NvidiaVideoEncoder());
|
return std::make_unique<NvidiaVideoEncoder>(NvidiaVideoEncoder());
|
||||||
} else {
|
} else {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
LOG_INFO("Use OpenH264 encoder");
|
||||||
return std::make_unique<OpenH264Encoder>(OpenH264Encoder());
|
return std::make_unique<OpenH264Encoder>(OpenH264Encoder());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user