|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <string.h> |
|
|
|
#include "avstring.h" |
|
#include "frame.h" |
|
#include "macros.h" |
|
#include "mem.h" |
|
#include "video_hint.h" |
|
|
|
AVVideoHint *av_video_hint_alloc(size_t nb_rects, |
|
size_t *out_size) |
|
{ |
|
struct TestStruct { |
|
AVVideoHint hint; |
|
AVVideoRect rect; |
|
}; |
|
const size_t rect_offset = offsetof(struct TestStruct, rect); |
|
size_t size = rect_offset; |
|
AVVideoHint *hint; |
|
|
|
*out_size = 0; |
|
if (nb_rects > (SIZE_MAX - size) / sizeof(AVVideoRect)) |
|
return NULL; |
|
size += sizeof(AVVideoRect) * nb_rects; |
|
|
|
hint = av_mallocz(size); |
|
if (!hint) |
|
return NULL; |
|
|
|
hint->nb_rects = nb_rects; |
|
hint->rect_offset = rect_offset; |
|
hint->rect_size = sizeof(AVVideoRect); |
|
|
|
*out_size = size; |
|
|
|
return hint; |
|
} |
|
|
|
AVVideoHint *av_video_hint_create_side_data(AVFrame *frame, |
|
size_t nb_rects) |
|
{ |
|
AVVideoHint *hint; |
|
AVBufferRef *buf; |
|
size_t size = 0; |
|
|
|
hint = av_video_hint_alloc(nb_rects, &size); |
|
if (!hint) |
|
return NULL; |
|
|
|
buf = av_buffer_create((uint8_t *)hint, size, NULL, NULL, 0); |
|
if (!buf) { |
|
av_freep(&hint); |
|
return NULL; |
|
} |
|
|
|
if (!av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_VIDEO_HINT, buf)) { |
|
av_buffer_unref(&buf); |
|
return NULL; |
|
} |
|
|
|
return hint; |
|
} |
|
|