| 246 | } |
| 247 | |
| 248 | int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, |
| 249 | const AVFrameSideData *src, unsigned int flags) |
| 250 | { |
| 251 | const AVSideDataDescriptor *desc; |
| 252 | AVBufferRef *buf = NULL; |
| 253 | AVFrameSideData *sd_dst = NULL; |
| 254 | int ret = AVERROR_BUG; |
| 255 | |
| 256 | if (!sd || !src || !nb_sd || (*nb_sd && !*sd)) |
| 257 | return AVERROR(EINVAL); |
| 258 | |
| 259 | desc = av_frame_side_data_desc(src->type); |
| 260 | if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE) |
| 261 | av_frame_side_data_remove(sd, nb_sd, src->type); |
| 262 | if ((!desc || !(desc->props & AV_SIDE_DATA_PROP_MULTI)) && |
| 263 | (sd_dst = (AVFrameSideData *)av_frame_side_data_get(*sd, *nb_sd, src->type))) { |
| 264 | AVDictionary *dict = NULL; |
| 265 | |
| 266 | if (!(flags & AV_FRAME_SIDE_DATA_FLAG_REPLACE)) |
| 267 | return AVERROR(EEXIST); |
| 268 | |
| 269 | ret = av_dict_copy(&dict, src->metadata, 0); |
| 270 | if (ret < 0) |
| 271 | return ret; |
| 272 | |
| 273 | ret = av_buffer_replace(&sd_dst->buf, src->buf); |
| 274 | if (ret < 0) { |
| 275 | av_dict_free(&dict); |
| 276 | return ret; |
| 277 | } |
| 278 | |
| 279 | av_dict_free(&sd_dst->metadata); |
| 280 | sd_dst->metadata = dict; |
| 281 | sd_dst->data = src->data; |
| 282 | sd_dst->size = src->size; |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | buf = av_buffer_ref(src->buf); |
| 287 | if (!buf) |
| 288 | return AVERROR(ENOMEM); |
| 289 | |
| 290 | sd_dst = add_side_data_from_buf_ext(sd, nb_sd, src->type, buf, |
| 291 | src->data, src->size); |
| 292 | if (!sd_dst) { |
| 293 | av_buffer_unref(&buf); |
| 294 | return AVERROR(ENOMEM); |
| 295 | } |
| 296 | |
| 297 | ret = av_dict_copy(&sd_dst->metadata, src->metadata, 0); |
| 298 | if (ret < 0) { |
| 299 | remove_side_data_by_entry(sd, nb_sd, sd_dst); |
| 300 | return ret; |
| 301 | } |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 |
no test coverage detected