1 #pragma once 2 3 #include <stdbool.h> 4 5 enum mp_frame_type { 6 MP_FRAME_NONE = 0, // NULL, placeholder, no frame available (_not_ EOF) 7 MP_FRAME_VIDEO, // struct mp_image* 8 MP_FRAME_AUDIO, // struct mp_aframe* 9 MP_FRAME_PACKET, // struct demux_packet* 10 MP_FRAME_EOF, // NULL, signals end of stream (but frames after it can 11 // resume filtering!) 12 }; 13 14 const char *mp_frame_type_str(enum mp_frame_type t); 15 16 // Generic container for a piece of data, such as a video frame, or a collection 17 // of audio samples. Wraps an actual media-specific frame data types in a 18 // generic way. Also can be an empty frame for signaling (MP_FRAME_EOF and 19 // possibly others). 20 // This struct is usually allocated on the stack and can be copied by value. 21 // You need to consider that the underlying pointer is ref-counted, and that 22 // the _unref/_ref functions must be used accordingly. 23 struct mp_frame { 24 enum mp_frame_type type; 25 void *data; 26 }; 27 28 // Return whether the frame contains actual data (audio, video, ...). If false, 29 // it's either signaling, or MP_FRAME_NONE. 30 bool mp_frame_is_data(struct mp_frame frame); 31 32 // Return whether the frame is for signaling (data flow commands like 33 // MP_FRAME_EOF). If false, it's either data (mp_frame_is_data()), or 34 // MP_FRAME_NONE. 35 bool mp_frame_is_signaling(struct mp_frame frame); 36 37 // Unreferences any frame data, and sets *frame to MP_FRAME_NONE. (It does 38 // _not_ deallocate the memory block the parameter points to, only frame->data.) 39 void mp_frame_unref(struct mp_frame *frame); 40 41 // Return a new reference to the given frame. The caller owns the returned 42 // frame. On failure returns a MP_FRAME_NONE. 43 struct mp_frame mp_frame_ref(struct mp_frame frame); 44 45 double mp_frame_get_pts(struct mp_frame frame); 46 void mp_frame_set_pts(struct mp_frame frame, double pts); 47 48 // Estimation of total size in bytes. This is for buffering purposes. 49 int mp_frame_approx_size(struct mp_frame frame); 50 51 struct AVFrame; 52 struct AVRational; 53 struct AVFrame *mp_frame_to_av(struct mp_frame frame, struct AVRational *tb); 54 struct mp_frame mp_frame_from_av(enum mp_frame_type type, struct AVFrame *frame, 55 struct AVRational *tb); 56 57 #define MAKE_FRAME(type, frame) ((struct mp_frame){(type), (frame)}) 58 #define MP_NO_FRAME MAKE_FRAME(0, 0) 59 #define MP_EOF_FRAME MAKE_FRAME(MP_FRAME_EOF, 0) 60