添加音频结构, 添加MediaParam, 增加bugList
This commit is contained in:
32
main.cc
32
main.cc
@@ -6,7 +6,7 @@
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "videoDecoder.h"
|
||||
#include "mediaDecoder.h"
|
||||
#include "shaderService.h"
|
||||
#include "shader.h"
|
||||
using std::cout;
|
||||
@@ -18,14 +18,14 @@ struct OpenglVideoParam
|
||||
unsigned int texs[3];
|
||||
};
|
||||
|
||||
int InitVideo(SDL_Window*& window, const char* targetFilepath, VideoParam& videoParam, OpenglVideoParam& openglVideoParam, ShaderService*& shaderService)
|
||||
int InitVideo(SDL_Window*& window, const char* targetFilepath, MediaParam& param, OpenglVideoParam& openglVideoParam, ShaderService*& shaderService)
|
||||
{
|
||||
InitDecoder(targetFilepath, videoParam);
|
||||
InitDecoder(targetFilepath, param.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;
|
||||
std::jthread(RequestPacket, std::ref(param)).detach();
|
||||
std::jthread(RequestVideoFrame, std::ref(param)).detach();
|
||||
const int client_width = param.videoParam.width / 2;
|
||||
const int client_height = param.videoParam.height / 2;
|
||||
window = SDL_CreateWindow(
|
||||
"MP",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
@@ -125,10 +125,10 @@ void InitImg(SDL_Window*& window, const char* filepath, SDL_Renderer*& renderer,
|
||||
texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
}
|
||||
|
||||
void OpenglRenderVideo(VideoParam& videoParam, const OpenglVideoParam& openglVideoParam, ShaderService* shaderService)
|
||||
void OpenglRenderVideo(MediaParam& param, const OpenglVideoParam& openglVideoParam, ShaderService* shaderService)
|
||||
{
|
||||
AVFrame* frame = av_frame_alloc();
|
||||
videoParam.frameQueue.pop(frame, true, videoParam.quit);
|
||||
param.videoParam.frameQueue.pop(frame, true, param.videoParam.quit);
|
||||
// TODO: TIMER
|
||||
glBindTexture(GL_TEXTURE_2D, openglVideoParam.texs[0]);
|
||||
glPixelStoref(GL_UNPACK_ROW_LENGTH, static_cast<float>(frame->linesize[0]));
|
||||
@@ -171,9 +171,8 @@ int main(int argc, char** argv)
|
||||
|
||||
// INIT
|
||||
|
||||
int client_width, client_height;
|
||||
SDL_Window* window = nullptr;
|
||||
VideoParam videoParam{};
|
||||
MediaParam mediaParam{};
|
||||
OpenglVideoParam openglVideoParam{};
|
||||
ShaderService* shaderService = nullptr;
|
||||
SDL_Surface* surface = nullptr;
|
||||
@@ -189,8 +188,8 @@ int main(int argc, char** argv)
|
||||
{
|
||||
case FileType::VIDEO:
|
||||
{
|
||||
InitVideo(window, targetFilepath, videoParam, openglVideoParam, shaderService);
|
||||
const auto stream_frame_rate = videoParam.fmtCtx->streams[videoParam.videoStreamIndex]->avg_frame_rate;
|
||||
InitVideo(window, targetFilepath, mediaParam, openglVideoParam, shaderService);
|
||||
const auto stream_frame_rate = mediaParam.videoParam.fmtCtx->streams[mediaParam.videoParam.videoStreamIndex]->avg_frame_rate;
|
||||
framerate = static_cast<double>(stream_frame_rate.den) / stream_frame_rate.num;
|
||||
break;
|
||||
}
|
||||
@@ -238,11 +237,10 @@ int main(int argc, char** argv)
|
||||
switch (fileType)
|
||||
{
|
||||
case FileType::VIDEO:
|
||||
OpenglRenderVideo(videoParam, openglVideoParam, shaderService);
|
||||
OpenglRenderVideo(mediaParam, openglVideoParam, shaderService);
|
||||
SDL_GL_SwapWindow(window);
|
||||
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);
|
||||
@@ -252,8 +250,8 @@ int main(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
|
||||
avcodec_close(videoParam.codecCtx);
|
||||
avformat_close_input(&(videoParam.fmtCtx));
|
||||
avcodec_close(mediaParam.videoParam.codecCtx);
|
||||
avformat_close_input(&(mediaParam.videoParam.fmtCtx));
|
||||
SDL_GL_DeleteContext(openglVideoParam.glContext);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
|
||||
Reference in New Issue
Block a user