From 698762727a7f78482b8a8cb71e477bddb2d2d51e Mon Sep 17 00:00:00 2001 From: haoruiwang <1905811497@qq.com> Date: Fri, 20 Sep 2024 23:01:09 +0800 Subject: [PATCH] =?UTF-8?q?[what]=20=E9=80=82=E9=85=8D=20YUV420P=20?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core | 2 +- source/DisplaySDL.cpp | 19 +++++++++++++++++++ test_decoder.cpp | 13 +++++++------ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Core b/Core index 70c6f88..d58a7a6 160000 --- a/Core +++ b/Core @@ -1 +1 @@ -Subproject commit 70c6f883399fe99f1a1d6b62b67604c84d1a6928 +Subproject commit d58a7a69e4f0a6f23552c546705c97f1ff6ea63a diff --git a/source/DisplaySDL.cpp b/source/DisplaySDL.cpp index 0e7a9d8..81f09c3 100644 --- a/source/DisplaySDL.cpp +++ b/source/DisplaySDL.cpp @@ -119,6 +119,10 @@ bool DisplaySDL::Open(PixelsInfo info) { format = SDL_PIXELFORMAT_NV12; } + else if (info.format == PixelFormat::YUV420P) + { + format = SDL_PIXELFORMAT_IYUV; + } else { DISPLAY_LOG_ERROR << "Unsupport pixel format, pixel format is: " << _format; @@ -198,6 +202,21 @@ void DisplaySDL::UpdateWindow(const uint32_t* frameBuffer, PixelsInfo info) SDL_UpdateTexture(_texture, NULL, reinterpret_cast(frameBuffer), sizeof(uint32_t)*_windowWidth); break; } + case PixelFormat::YUV420P: + { + uint8_t* yData = (uint8_t*)frameBuffer; + uint8_t* uData = yData + (info.virStride * info.horStride); + uint8_t* vData = uData + (info.virStride * info.horStride / 4); + SDL_Rect rect; + { + rect.x = 0; + rect.y = 0; + rect.w = info.width; + rect.h = info.height; + } + SDL_UpdateYUVTexture(_texture, &rect, yData, info.horStride, uData, info.horStride/2, vData, info.horStride/2); + break; + } default: { return; diff --git a/test_decoder.cpp b/test_decoder.cpp index 147437d..e74ba06 100644 --- a/test_decoder.cpp +++ b/test_decoder.cpp @@ -7,6 +7,7 @@ #include "Common/AbstractLogger.h" #include "Common/LogMessage.h" #include "Common/ThreadPool.h" +#include "Codec/StreamPack.h" #include "Codec/StreamFrame.h" #include "Codec/CodecConfig.h" #include "Codec/CodecFactory.h" @@ -25,7 +26,7 @@ class H26XFileByteReader explicit H26XFileByteReader(const std::string& path); ~H26XFileByteReader(); public: - NormalPack::ptr GetNalUint(); + Codec::StreamPack::ptr GetNalUint(); public: size_t Read(void* data, size_t bytes); bool Seek(size_t offset); @@ -40,7 +41,7 @@ class H26XFileByteReader uint32_t _len; }; -NormalPack::ptr H26XFileByteReader::GetNalUint() +Codec::StreamPack::ptr H26XFileByteReader::GetNalUint() { std::vector bufs; bufs.reserve(1024 * 1024); @@ -79,7 +80,7 @@ NormalPack::ptr H26XFileByteReader::GetNalUint() } std::shared_ptr> alloc = std::make_shared>(); alloc->container.swap(bufs); - return std::make_shared(alloc->container.size(), alloc); + return std::make_shared(Codec::CodecType::H264, alloc->container.size(), alloc); } H26XFileByteReader::H26XFileByteReader(const std::string& path) @@ -219,7 +220,7 @@ void App::displayHelp() helpFormatter.format(ss); ss << std::endl; ss << "Available Decoder Info" << std::endl; - std::vector descriptions = Codec::DecoderFactory::DecoderFactory().GetDecoderDescriptions(); + std::vector descriptions = Codec::DecoderFactory::DefaultFactory().GetDecoderDescriptions(); for (auto& description : descriptions) { ss << "-- CodecType(" << description.codecType << ") CodecProcessType(" << description.processType @@ -366,7 +367,7 @@ int App::main(const ArgVec& args) display->Init(); } std::shared_ptr byteReader = std::make_shared(inputFile); - NormalPack::ptr pack = nullptr; + Codec::StreamPack::ptr pack = nullptr; // // Input File Read -> VDEC PUSH @@ -396,7 +397,7 @@ int App::main(const ArgVec& args) } if (display) { - display->UpdateWindow((const uint32_t*)streamFrame->GetData(0)); + display->UpdateWindow((const uint32_t*)streamFrame->GetData(0), streamFrame->info); if (intervalMs > sw.elapsed() / 1000) { std::this_thread::sleep_for(std::chrono::milliseconds(intervalMs - sw.elapsed() / 1000));