diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-03-08 20:41:41 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-03-08 20:41:41 +0100 |
commit | 307dc32a1a7152ebacdcf9a0e58226f786ac639a (patch) | |
tree | bb770b3a3e958e762876fa395b0c7e2d114436f0 /libavutil/frame.c | |
parent | c4e8821732999f720535bb2eb1e8c7f1ea1db18f (diff) | |
parent | 77b2cd7b41d7ec8008b6fac753c04f77824c514c (diff) | |
download | ffmpeg-streaming-307dc32a1a7152ebacdcf9a0e58226f786ac639a.zip ffmpeg-streaming-307dc32a1a7152ebacdcf9a0e58226f786ac639a.tar.gz |
Merge commit '77b2cd7b41d7ec8008b6fac753c04f77824c514c'
* commit '77b2cd7b41d7ec8008b6fac753c04f77824c514c':
AVFrame: add side data.
Conflicts:
libavutil/frame.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/frame.c')
-rw-r--r-- | libavutil/frame.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/libavutil/frame.c b/libavutil/frame.c index c799a28..4f218ba 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -20,6 +20,7 @@ #include "audioconvert.h" #include "buffer.h" #include "common.h" +#include "dict.h" #include "frame.h" #include "imgutils.h" #include "mem.h" @@ -289,6 +290,13 @@ void av_frame_unref(AVFrame *frame) { int i; + for (i = 0; i < frame->nb_side_data; i++) { + av_freep(&frame->side_data[i]->data); + av_dict_free(&frame->side_data[i]->metadata); + av_freep(&frame->side_data[i]); + } + av_freep(&frame->side_data); + for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++) av_buffer_unref(&frame->buf[i]); for (i = 0; i < frame->nb_extended_buf; i++) @@ -369,6 +377,8 @@ int av_frame_make_writable(AVFrame *frame) int av_frame_copy_props(AVFrame *dst, const AVFrame *src) { + int i; + dst->key_frame = src->key_frame; dst->pict_type = src->pict_type; dst->sample_aspect_ratio = src->sample_aspect_ratio; @@ -383,6 +393,23 @@ int av_frame_copy_props(AVFrame *dst, const AVFrame *src) dst->coded_picture_number = src->coded_picture_number; dst->display_picture_number = src->display_picture_number; + for (i = 0; i < src->nb_side_data; i++) { + const AVFrameSideData *sd_src = src->side_data[i]; + AVFrameSideData *sd_dst = av_frame_new_side_data(dst, sd_src->type, + sd_src->size); + if (!sd_dst) { + for (i = 0; i < dst->nb_side_data; i++) { + av_freep(&dst->side_data[i]->data); + av_freep(&dst->side_data[i]); + av_dict_free(&dst->side_data[i]->metadata); + } + av_freep(&dst->side_data); + return AVERROR(ENOMEM); + } + memcpy(sd_dst->data, sd_src->data, sd_src->size); + av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0); + } + return 0; } @@ -415,3 +442,48 @@ AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane) } return NULL; } + +AVFrameSideData *av_frame_new_side_data(AVFrame *frame, + enum AVFrameSideDataType type, + int size) +{ + AVFrameSideData *ret, **tmp; + + if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1) + return NULL; + + tmp = av_realloc(frame->side_data, + (frame->nb_side_data + 1) * sizeof(*frame->side_data)); + if (!tmp) + return NULL; + frame->side_data = tmp; + + ret = av_mallocz(sizeof(*ret)); + if (!ret) + return NULL; + + ret->data = av_malloc(size); + if (!ret->data) { + av_freep(&ret); + return NULL; + } + + ret->size = size; + ret->type = type; + + frame->side_data[frame->nb_side_data++] = ret; + + return ret; +} + +AVFrameSideData *av_frame_get_side_data(AVFrame *frame, + enum AVFrameSideDataType type) +{ + int i; + + for (i = 0; i < frame->nb_side_data; i++) { + if (frame->side_data[i]->type == type) + return frame->side_data[i]; + } + return NULL; +} |