2017-12-12 22:12:07 +08:00
|
|
|
#include "frames.h"
|
|
|
|
|
|
|
|
#include <SDL2/SDL_mutex.h>
|
|
|
|
#include <libavutil/avutil.h>
|
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
|
2017-12-15 18:27:11 +08:00
|
|
|
SDL_bool frames_init(struct frames *frames) {
|
2017-12-12 22:12:07 +08:00
|
|
|
if (!(frames->decoding_frame = av_frame_alloc())) {
|
|
|
|
goto error_0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(frames->rendering_frame = av_frame_alloc())) {
|
|
|
|
goto error_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(frames->mutex = SDL_CreateMutex())) {
|
|
|
|
goto error_2;
|
|
|
|
}
|
|
|
|
|
2018-02-07 19:25:52 +08:00
|
|
|
#ifndef SKIP_FRAMES
|
2017-12-12 22:12:07 +08:00
|
|
|
if (!(frames->rendering_frame_consumed_cond = SDL_CreateCond())) {
|
2018-02-07 19:25:52 +08:00
|
|
|
SDL_DestroyMutex(frames->mutex);
|
|
|
|
goto error_2;
|
2017-12-12 22:12:07 +08:00
|
|
|
}
|
2018-02-07 19:25:52 +08:00
|
|
|
#endif
|
2017-12-12 22:12:07 +08:00
|
|
|
|
|
|
|
frames->rendering_frame_consumed = SDL_TRUE;
|
|
|
|
|
2017-12-15 18:27:11 +08:00
|
|
|
return SDL_TRUE;
|
2017-12-12 22:12:07 +08:00
|
|
|
|
|
|
|
error_2:
|
|
|
|
av_frame_free(&frames->rendering_frame);
|
|
|
|
error_1:
|
|
|
|
av_frame_free(&frames->decoding_frame);
|
|
|
|
error_0:
|
2017-12-15 18:27:11 +08:00
|
|
|
return SDL_FALSE;
|
2017-12-12 22:12:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void frames_destroy(struct frames *frames) {
|
2018-02-07 19:25:52 +08:00
|
|
|
#ifndef SKIP_FRAMES
|
2017-12-15 18:12:02 +08:00
|
|
|
SDL_DestroyCond(frames->rendering_frame_consumed_cond);
|
2018-02-07 19:25:52 +08:00
|
|
|
#endif
|
2017-12-18 23:26:38 +08:00
|
|
|
SDL_DestroyMutex(frames->mutex);
|
2017-12-12 22:12:07 +08:00
|
|
|
av_frame_free(&frames->rendering_frame);
|
|
|
|
av_frame_free(&frames->decoding_frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void frames_swap(struct frames *frames) {
|
|
|
|
AVFrame *tmp = frames->decoding_frame;
|
|
|
|
frames->decoding_frame = frames->rendering_frame;
|
|
|
|
frames->rendering_frame = tmp;
|
|
|
|
}
|