From 04008c0ef832f0f37e93d9345fd8d57f2e1cb728 Mon Sep 17 00:00:00 2001 From: JIe Jie Date: Thu, 22 Feb 2024 11:45:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B8=B2=E6=9F=93=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/main.cc b/main.cc index b346a77..860f923 100644 --- a/main.cc +++ b/main.cc @@ -8,7 +8,7 @@ #include "decoder.h" #include "shaderService.h" #include "shader.h" -using std::cout, std::endl; +using std::cout; struct OpenglVideoParam { @@ -22,6 +22,7 @@ int InitVideo(SDL_Window*& window, const char* targetFilepath, VideoParam& video InitDecoder(targetFilepath, videoParam); //FIX: when app exited, the fmtCtx was freed, so need notify decode thread to stop decode and exit. std::jthread(RequestPacket, std::ref(videoParam)).detach(); + std::jthread(RequestFrame, std::ref(videoParam)).detach(); const int client_width = videoParam.width / 2; const int client_height = videoParam.height / 2; window = SDL_CreateWindow( @@ -125,9 +126,8 @@ void InitImg(SDL_Window*& window, const char* filepath, SDL_Renderer*& renderer, void OpenglRenderVideo(VideoParam& videoParam, const OpenglVideoParam& openglVideoParam, ShaderService* shaderService) { - auto frame = RequestFrame(videoParam); - if (frame == nullptr) - return; + AVFrame* frame = av_frame_alloc(); + videoParam.frameQueue.pop(frame, true, videoParam.quit); // TODO: TIMER glBindTexture(GL_TEXTURE_2D, openglVideoParam.texs[0]); glPixelStoref(GL_UNPACK_ROW_LENGTH, static_cast(frame->linesize[0])); @@ -238,8 +238,9 @@ int main(int argc, char** const argv) case FileType::VIDEO: OpenglRenderVideo(videoParam, openglVideoParam, shaderService); SDL_GL_SwapWindow(window); - std::this_thread::sleep_until(current_time + std::chrono::milliseconds(static_cast(framerate * 1000))); + std::this_thread::sleep_until(current_time + std::chrono::milliseconds(30)); current_time = std::chrono::system_clock::now(); + cout << SDL_GetTicks() << '\n'; break; case FileType::IMG: RenderPicture(window, renderer, texture);