diff --git a/src/media/video/decode/openh264/openh264_decoder.cpp b/src/media/video/decode/openh264/openh264_decoder.cpp index 0cc80a4..4cd9835 100644 --- a/src/media/video/decode/openh264/openh264_decoder.cpp +++ b/src/media/video/decode/openh264/openh264_decoder.cpp @@ -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() { if (openh264_decoder_) { @@ -138,15 +154,20 @@ int OpenH264Decoder::Decode( frame_width_ * frame_height_ * 3 / 2, nv12_stream_); } - libyuv::I420ToNV12( - (const uint8_t *)decoded_frame_, frame_width_, - (const uint8_t *)decoded_frame_ + frame_width_ * frame_height_, - frame_width_ / 2, - (const uint8_t *)decoded_frame_ + - frame_width_ * frame_height_ * 3 / 2, - frame_width_ / 2, nv12_frame_, frame_width_, - nv12_frame_ + frame_width_ * frame_height_, frame_width_, - frame_width_, frame_height_); + if (0) { + ConvertYUV420toNV12(decoded_frame_, nv12_frame_, frame_width_, + frame_height_); + } else { + libyuv::I420ToNV12( + (const uint8_t *)decoded_frame_, frame_width_, + (const uint8_t *)decoded_frame_ + frame_width_ * frame_height_, + frame_width_ / 2, + (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_, frame_width_ * frame_height_ * 3 / 2, diff --git a/src/media/video/decode/video_decoder_factory.cpp b/src/media/video/decode/video_decoder_factory.cpp index 1c78327..0391ee1 100644 --- a/src/media/video/decode/video_decoder_factory.cpp +++ b/src/media/video/decode/video_decoder_factory.cpp @@ -18,6 +18,7 @@ VideoDecoderFactory::~VideoDecoderFactory() {} std::unique_ptr VideoDecoderFactory::CreateVideoDecoder( bool hardware_acceleration, bool av1_encoding) { if (av1_encoding) { + LOG_INFO("Use dav1d decoder"); return std::make_unique(Dav1dAv1Decoder()); } else { #if __APPLE__ @@ -25,11 +26,13 @@ std::unique_ptr VideoDecoderFactory::CreateVideoDecoder( #else if (hardware_acceleration) { if (CheckIsHardwareAccerlerationSupported()) { + LOG_INFO("Use nvidia decoder"); return std::make_unique(NvidiaVideoDecoder()); } else { return nullptr; } } else { + LOG_INFO("Use openh264 decoder"); return std::make_unique(OpenH264Decoder()); } #endif diff --git a/src/media/video/encode/video_encoder_factory.cpp b/src/media/video/encode/video_encoder_factory.cpp index ee6d506..3b0b395 100644 --- a/src/media/video/encode/video_encoder_factory.cpp +++ b/src/media/video/encode/video_encoder_factory.cpp @@ -18,6 +18,7 @@ VideoEncoderFactory::~VideoEncoderFactory() {} std::unique_ptr VideoEncoderFactory::CreateVideoEncoder( bool hardware_acceleration, bool av1_encoding) { if (av1_encoding) { + LOG_INFO("Use AOM encoder"); return std::make_unique(AomAv1Encoder()); } else { #if __APPLE__ @@ -25,11 +26,13 @@ std::unique_ptr VideoEncoderFactory::CreateVideoEncoder( #else if (hardware_acceleration) { if (CheckIsHardwareAccerlerationSupported()) { + LOG_INFO("Use Nvidia encoder"); return std::make_unique(NvidiaVideoEncoder()); } else { return nullptr; } } else { + LOG_INFO("Use OpenH264 encoder"); return std::make_unique(OpenH264Encoder()); } #endif