[FFmpeg-devel] [PATCH v5] avformat/dashdec: add dash demuxer base version

Michael Niedermayer michael at niedermayer.cc
Tue Mar 21 14:56:09 EET 2017


On Tue, Mar 21, 2017 at 08:32:59PM +0800, Steven Liu wrote:
[...]

> +static char *strreplace(const char *str, const char *from, const char *to)
> +{
> +    /* Adjust each of the below values to suit your needs. */
> +    /* Increment positions cache size initially by this number. */
> +    size_t cache_sz_inc = 16;
> +    /* Thereafter, each time capacity needs to be increased,
> +     * multiply the increment by this factor. */
> +    const size_t cache_sz_inc_factor = 3;
> +    /* But never increment capacity by more than this number. */
> +    const size_t cache_sz_inc_max = 1048576;
> +
> +    char *pret, *ret = NULL;
> +    const char *pstr2, *pstr = str;
> +    size_t i, count = 0;
> +    uintptr_t *pos_cache_tmp, *pos_cache = NULL;
> +    size_t cache_sz = 0;
> +    size_t cpylen, orglen, retlen, tolen, fromlen = strlen(from);
> +
> +    /* Find all matches and cache their positions. */
> +    while ((pstr2 = av_stristr(pstr, from))) {
> +        count++;
> +        /* Increase the cache size when necessary. */
> +        if (cache_sz < count) {
> +            cache_sz += cache_sz_inc;

> +            pos_cache_tmp = realloc(pos_cache, sizeof(*pos_cache) * cache_sz);

should be av_realloc()

simiarly av_free() later where its freed


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

What does censorship reveal? It reveals fear. -- Julian Assange
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20170321/21c8d139/attachment.sig>


More information about the ffmpeg-devel mailing list