修改渲染代码
This commit is contained in:
parent
2641cb0bb3
commit
04008c0ef8
11
main.cc
11
main.cc
@ -8,7 +8,7 @@
|
|||||||
#include "decoder.h"
|
#include "decoder.h"
|
||||||
#include "shaderService.h"
|
#include "shaderService.h"
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
using std::cout, std::endl;
|
using std::cout;
|
||||||
|
|
||||||
struct OpenglVideoParam
|
struct OpenglVideoParam
|
||||||
{
|
{
|
||||||
@ -22,6 +22,7 @@ int InitVideo(SDL_Window*& window, const char* targetFilepath, VideoParam& video
|
|||||||
InitDecoder(targetFilepath, videoParam);
|
InitDecoder(targetFilepath, videoParam);
|
||||||
//FIX: when app exited, the fmtCtx was freed, so need notify decode thread to stop decode and exit.
|
//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(RequestPacket, std::ref(videoParam)).detach();
|
||||||
|
std::jthread(RequestFrame, std::ref(videoParam)).detach();
|
||||||
const int client_width = videoParam.width / 2;
|
const int client_width = videoParam.width / 2;
|
||||||
const int client_height = videoParam.height / 2;
|
const int client_height = videoParam.height / 2;
|
||||||
window = SDL_CreateWindow(
|
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)
|
void OpenglRenderVideo(VideoParam& videoParam, const OpenglVideoParam& openglVideoParam, ShaderService* shaderService)
|
||||||
{
|
{
|
||||||
auto frame = RequestFrame(videoParam);
|
AVFrame* frame = av_frame_alloc();
|
||||||
if (frame == nullptr)
|
videoParam.frameQueue.pop(frame, true, videoParam.quit);
|
||||||
return;
|
|
||||||
// TODO: TIMER
|
// TODO: TIMER
|
||||||
glBindTexture(GL_TEXTURE_2D, openglVideoParam.texs[0]);
|
glBindTexture(GL_TEXTURE_2D, openglVideoParam.texs[0]);
|
||||||
glPixelStoref(GL_UNPACK_ROW_LENGTH, static_cast<float>(frame->linesize[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:
|
case FileType::VIDEO:
|
||||||
OpenglRenderVideo(videoParam, openglVideoParam, shaderService);
|
OpenglRenderVideo(videoParam, openglVideoParam, shaderService);
|
||||||
SDL_GL_SwapWindow(window);
|
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();
|
current_time = std::chrono::system_clock::now();
|
||||||
|
cout << SDL_GetTicks() << '\n';
|
||||||
break;
|
break;
|
||||||
case FileType::IMG:
|
case FileType::IMG:
|
||||||
RenderPicture(window, renderer, texture);
|
RenderPicture(window, renderer, texture);
|
||||||
|
Loading…
Reference in New Issue
Block a user