修改渲染代码

This commit is contained in:
JIe Jie 2024-02-22 11:45:47 +08:00
parent 2641cb0bb3
commit 04008c0ef8

11
main.cc
View File

@ -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<float>(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<int>(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);