Signed-off-by: Brad Hards <br...@frogmouth.net> --- libavutil/frame.c | 31 +++++++++++++++++++++++++++++++ libavutil/frame.h | 23 +++++++++++++++++++++++ 2 files changed, 54 insertions(+)
diff --git a/libavutil/frame.c b/libavutil/frame.c index 2ec59b44b1..9f9953c2b4 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -625,6 +625,37 @@ AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, return NULL; } +AVFrameSideData *av_frame_get_side_data_n(const AVFrame *frame, + enum AVFrameSideDataType type, + const int side_data_instance) +{ + int i; + int n = 0; + + for (i = 0; i < frame->nb_side_data; i++) { + if (frame->side_data[i]->type == type) { + if (n == side_data_instance) { + return frame->side_data[i]; + } else { + n++; + } + } + } + return NULL; +} + +int av_frame_num_side_data(const AVFrame *frame, enum AVFrameSideDataType type) +{ + int i; + int num = 0; + for (i = 0; i < frame->nb_side_data; i++) { + if (frame->side_data[i]->type == type) { + num += 1; + } + } + return num; +} + static int frame_copy_video(AVFrame *dst, const AVFrame *src) { const uint8_t *src_data[4]; diff --git a/libavutil/frame.h b/libavutil/frame.h index ff2540a20f..8e94e3f679 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -839,11 +839,34 @@ AVFrameSideData *av_frame_new_side_data_from_buf(AVFrame *frame, AVFrameSideData *av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type); +/** + * Find a specified instance of side data of a given type. + * + * @param frame a frame to find the side data in + * @param type type of the side data to find + * @param side_data_instance instance of the side data to return (0 base). + * + * @return a pointer to the n'th instance of side data of a given type on + * success, NULL if there are less than side_data_instance instances of the + * given type. + */ +AVFrameSideData *av_frame_get_side_data_n(const AVFrame *frame, + enum AVFrameSideDataType type, + const int side_data_instance); + /** * Remove and free all side data instances of the given type. */ void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type); +/** + * Get the number of instances of side data of a given type. + * + * @param frame a frame to find the side data in + * @param type type of the side data to find + * @return count of instances, which can be 0 + */ +int av_frame_num_side_data(const AVFrame *frame, enum AVFrameSideDataType type); /** * Flags for frame cropping. -- 2.27.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".