History

avutil/frame: add helper for adding existing side data to array

Jan Ekström committed 3 years ago

Commit 3c52f731 parent 53335f62 files · +69 −0Browse files

Unified · Split

2 files
  1. libavutil/frame.c +49 −0
  2. libavutil/frame.h +20 −0
libavutil/frame.c+49−0
@@ -98,6 +98,23 @@ static void remove_side_data(AVFrameSideData ***sd, int *nb_side_data, · 97 unmodified lines
98 }98 }
99}99}
100 100
101static void remove_side_data_by_entry(AVFrameSideData ***sd, int *nb_sd,
102 const AVFrameSideData *target)
103{
104 for (int i = *nb_sd - 1; i >= 0; i--) {
105 AVFrameSideData *entry = ((*sd)[i]);
106 if (entry != target)
107 continue;
108
109 free_side_data(&entry);
110
111 ((*sd)[i]) = ((*sd)[*nb_sd - 1]);
112 (*nb_sd)--;
113
114 return;
115 }
116}
117
101AVFrame *av_frame_alloc(void)118AVFrame *av_frame_alloc(void)
102{119{
103 AVFrame *frame = av_malloc(sizeof(*frame));120 AVFrame *frame = av_malloc(sizeof(*frame));
@@ -764,6 +781,38 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, · 660 unmodified lines
764 return ret;781 return ret;
765}782}
766 783
784int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd,
785 const AVFrameSideData *src, unsigned int flags)
786{
787 AVBufferRef *buf = NULL;
788 AVFrameSideData *sd_dst = NULL;
789 int ret = AVERROR_BUG;
790
791 if (!sd || !src || !nb_sd || (*nb_sd && !*sd))
792 return AVERROR(EINVAL);
793
794 buf = av_buffer_ref(src->buf);
795 if (!buf)
796 return AVERROR(ENOMEM);
797
798 if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE)
799 remove_side_data(sd, nb_sd, src->type);
800
801 sd_dst = add_side_data_from_buf(sd, nb_sd, src->type, buf);
802 if (!sd_dst) {
803 av_buffer_unref(&buf);
804 return AVERROR(ENOMEM);
805 }
806
807 ret = av_dict_copy(&sd_dst->metadata, src->metadata, 0);
808 if (ret < 0) {
809 remove_side_data_by_entry(sd, nb_sd, sd_dst);
810 return ret;
811 }
812
813 return 0;
814}
815
767AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,816AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
768 enum AVFrameSideDataType type)817 enum AVFrameSideDataType type)
769{818{
libavutil/frame.h+20−0
@@ -1021,6 +1021,26 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData ***sd, int *nb_sd, · 1020 unmodified lines
1021 enum AVFrameSideDataType type,1021 enum AVFrameSideDataType type,
1022 size_t size, unsigned int flags);1022 size_t size, unsigned int flags);
1023 1023
1024/**
1025 * Add a new side data entry to an array based on existing side data, taking
1026 * a reference towards the contained AVBufferRef.
1027 *
1028 * @param sd pointer to array of side data to which to add another entry,
1029 * or to NULL in order to start a new array.
1030 * @param nb_sd pointer to an integer containing the number of entries in
1031 * the array.
1032 * @param src side data to be cloned, with a new reference utilized
1033 * for the buffer.
1034 * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0.
1035 *
1036 * @return negative error code on failure, >=0 on success. In case of
1037 * AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of matching
1038 * AVFrameSideDataType will be removed before the addition is
1039 * attempted.
1040 */
1041int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd,
1042 const AVFrameSideData *src, unsigned int flags);
1043
1024/**1044/**
1025 * @}1045 * @}
1026 */1046 */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t