mirror of https://git.ffmpeg.org/ffmpeg.git
avformat/matroskadec: use av_fast_realloc to reallocate ebml list arrays
Speeds up the process considerably. Fixes ticket #8109. Suggested-by: nevcairiel Suggested-by: cehoyos Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
f34aabfbae
commit
3b3150c45f
|
@ -110,6 +110,7 @@ typedef const struct EbmlSyntax {
|
||||||
|
|
||||||
typedef struct EbmlList {
|
typedef struct EbmlList {
|
||||||
int nb_elem;
|
int nb_elem;
|
||||||
|
unsigned int alloc_elem_size;
|
||||||
void *elem;
|
void *elem;
|
||||||
} EbmlList;
|
} EbmlList;
|
||||||
|
|
||||||
|
@ -1236,8 +1237,13 @@ static int ebml_parse(MatroskaDemuxContext *matroska,
|
||||||
data = (char *) data + syntax->data_offset;
|
data = (char *) data + syntax->data_offset;
|
||||||
if (syntax->list_elem_size) {
|
if (syntax->list_elem_size) {
|
||||||
EbmlList *list = data;
|
EbmlList *list = data;
|
||||||
void *newelem = av_realloc_array(list->elem, list->nb_elem + 1,
|
void *newelem;
|
||||||
syntax->list_elem_size);
|
|
||||||
|
if ((unsigned)list->nb_elem + 1 >= UINT_MAX / syntax->list_elem_size)
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
newelem = av_fast_realloc(list->elem,
|
||||||
|
&list->alloc_elem_size,
|
||||||
|
(list->nb_elem + 1) * syntax->list_elem_size);
|
||||||
if (!newelem)
|
if (!newelem)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
list->elem = newelem;
|
list->elem = newelem;
|
||||||
|
@ -1490,6 +1496,7 @@ static void ebml_free(EbmlSyntax *syntax, void *data)
|
||||||
ebml_free(syntax[i].def.n, ptr);
|
ebml_free(syntax[i].def.n, ptr);
|
||||||
av_freep(&list->elem);
|
av_freep(&list->elem);
|
||||||
list->nb_elem = 0;
|
list->nb_elem = 0;
|
||||||
|
list->alloc_elem_size = 0;
|
||||||
} else
|
} else
|
||||||
ebml_free(syntax[i].def.n, data_off);
|
ebml_free(syntax[i].def.n, data_off);
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue