fix: Resource leak in video player initializer and call cleanup before returning false
- use early returns in `init_video_player` to use `goto error` pattern - fix formatting
This commit is contained in:
45
src/video.h
45
src/video.h
@@ -2,33 +2,32 @@
|
||||
#define VIDEO_H
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libswscale/swscale.h>
|
||||
#include <libavutil/imgutils.h>
|
||||
#include <libswscale/swscale.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct VideoPlayer
|
||||
{
|
||||
AVFormatContext *format_ctx;
|
||||
AVCodecContext *codec_ctx;
|
||||
struct SwsContext *sws_ctx;
|
||||
AVFrame *frame;
|
||||
AVFrame *rgba_frame;
|
||||
uint8_t *rgba_buffer;
|
||||
int rgba_buffer_size;
|
||||
int stream_index;
|
||||
int width;
|
||||
int height;
|
||||
int frame_delay_ms;
|
||||
Uint32 next_frame_tick;
|
||||
SDL_Texture *texture;
|
||||
typedef struct VideoPlayer {
|
||||
AVFormatContext* format_ctx;
|
||||
AVCodecContext* codec_ctx;
|
||||
struct SwsContext* sws_ctx;
|
||||
AVFrame* frame;
|
||||
AVFrame* rgba_frame;
|
||||
uint8_t* rgba_buffer;
|
||||
int rgba_buffer_size;
|
||||
int stream_index;
|
||||
int width;
|
||||
int height;
|
||||
int frame_delay_ms;
|
||||
Uint32 next_frame_tick;
|
||||
SDL_Texture* texture;
|
||||
} VideoPlayer;
|
||||
|
||||
bool has_video_extension(const char *path);
|
||||
bool init_video_player(VideoPlayer *player, SDL_Renderer *renderer, const char *path);
|
||||
void cleanup_video_player(VideoPlayer *player);
|
||||
bool decode_next_frame(VideoPlayer *player);
|
||||
bool has_video_extension(const char* path);
|
||||
bool init_video_player(VideoPlayer* player, SDL_Renderer* renderer,
|
||||
const char* path);
|
||||
void cleanup_video_player(VideoPlayer* player);
|
||||
bool decode_next_frame(VideoPlayer* player);
|
||||
|
||||
#endif // VIDEO_H
|
||||
#endif // VIDEO_H
|
||||
|
||||
Reference in New Issue
Block a user