#ifndef FRAME_QUEUE_H
#define FRAME_QUEUE_H

#include <SDL2/SDL.h>

#define FRAME_QUEUE_CAPACITY 12

typedef struct FrameData {
    unsigned char *buffer;
    unsigned char *plane_y;
    unsigned char *plane_u;
    unsigned char *plane_v;
    int width;
    int height;
    int pitch_y;
    int pitch_u;
    int pitch_v;
    double pts_seconds;
} FrameData;

typedef struct FrameQueue {
    FrameData frames[FRAME_QUEUE_CAPACITY];
    int head;
    int count;
    SDL_mutex *mutex;
    SDL_cond *cond;
} FrameQueue;

int frame_queue_init(FrameQueue *queue);
void frame_queue_destroy(FrameQueue *queue);
void frame_queue_clear(FrameQueue *queue);
int frame_queue_push(FrameQueue *queue, FrameData *frame);
int frame_queue_pop_latest(FrameQueue *queue, FrameData *out);
int frame_queue_peek_first(FrameQueue *queue, FrameData *out);
int frame_queue_pop_first(FrameQueue *queue, FrameData *out);
void frame_data_free(FrameData *frame);

#endif
