[vlc-commits] codec: aom: store frame private data locally
vlc/vlc-3.0 | branch: master | Francois Cartegnie | Thu Jul 19 16:21:05 2018 +0200| [4ca48e61e939b09b45c04b0f5483d80be9a6bb6e] | committer: Francois Cartegnie codec: aom: store frame private data locally fix leaks on error (cherry picked from commit 135bdbbe75913a2a210a9273fe078eac705e56ac) > http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=4ca48e61e939b09b45c04b0f5483d80be9a6bb6e --- modules/codec/aom.c | 32 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/codec/aom.c b/modules/codec/aom.c index b76b19c954..87649cefb4 100644 --- a/modules/codec/aom.c +++ b/modules/codec/aom.c @@ -65,13 +65,21 @@ static void aom_err_msg(vlc_object_t *this, aom_codec_ctx_t *ctx, } #define AOM_ERR(this, ctx, msg) aom_err_msg(VLC_OBJECT(this), ctx, msg ": %s (%s)") +#define AOM_MAX_FRAMES_DEPTH 64 /* * decoder_sys_t: libaom decoder descriptor */ +struct frame_priv_s +{ +mtime_t pts; +}; + struct decoder_sys_t { aom_codec_ctx_t ctx; +struct frame_priv_s frame_priv[AOM_MAX_FRAMES_DEPTH]; +unsigned i_next_frame_priv; }; static const struct @@ -133,21 +141,16 @@ static int Decode(decoder_t *dec, block_t *block) } /* Associate packet PTS with decoded frame */ -mtime_t *pkt_pts = malloc(sizeof(*pkt_pts)); -if (!pkt_pts) { -block_Release(block); -return VLCDEC_SUCCESS; -} - -*pkt_pts = (block->i_pts != VLC_TS_INVALID) ? block->i_pts : block->i_dts; +struct frame_priv_s *priv = >p_sys->frame_priv[dec->p_sys->i_next_frame_priv++ +% AOM_MAX_FRAMES_DEPTH]; +priv->pts = (block->i_pts != VLC_TS_INVALID) ? block->i_pts : block->i_dts; aom_codec_err_t err; -err = aom_codec_decode(ctx, block->p_buffer, block->i_buffer, pkt_pts); +err = aom_codec_decode(ctx, block->p_buffer, block->i_buffer, priv); block_Release(block); if (err != AOM_CODEC_OK) { -free(pkt_pts); AOM_ERR(dec, ctx, "Failed to decode frame"); if (err == AOM_CODEC_UNSUP_BITSTREAM) return VLCDEC_ECRITICAL; @@ -157,15 +160,11 @@ static int Decode(decoder_t *dec, block_t *block) const void *iter = NULL; struct aom_image *img = aom_codec_get_frame(ctx, ); -if (!img) { -free(pkt_pts); +if (!img) return VLCDEC_SUCCESS; -} /* fetches back the PTS */ -pkt_pts = img->user_priv; -mtime_t pts = *pkt_pts; -free(pkt_pts); +mtime_t pts = ((struct frame_priv_s *) img->user_priv)->pts; dec->fmt_out.i_codec = FindVlcChroma(img); if (dec->fmt_out.i_codec == 0) { @@ -256,6 +255,8 @@ static int OpenDecoder(vlc_object_t *p_this) return VLC_ENOMEM; dec->p_sys = sys; +sys->i_next_frame_priv = 0; + struct aom_codec_dec_cfg deccfg = { .threads = __MIN(vlc_GetCPUCount(), 16), .allow_lowbitdepth = 1 @@ -305,7 +306,6 @@ static void CloseDecoder(vlc_object_t *p_this) struct aom_image *img = aom_codec_get_frame(>ctx, ); if (!img) break; -free(img->user_priv); } aom_codec_destroy(>ctx); ___ vlc-commits mailing list vlc-commits@videolan.org https://mailman.videolan.org/listinfo/vlc-commits
[vlc-commits] codec: aom: store frame private data locally
vlc | branch: master | Francois Cartegnie | Thu Jul 19 16:21:05 2018 +0200| [135bdbbe75913a2a210a9273fe078eac705e56ac] | committer: Francois Cartegnie codec: aom: store frame private data locally fix leaks on error > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=135bdbbe75913a2a210a9273fe078eac705e56ac --- modules/codec/aom.c | 31 +++ 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/modules/codec/aom.c b/modules/codec/aom.c index 70c0e26c56..c5cd4fc62c 100644 --- a/modules/codec/aom.c +++ b/modules/codec/aom.c @@ -92,13 +92,21 @@ static void aom_err_msg(vlc_object_t *this, aom_codec_ctx_t *ctx, } #define AOM_ERR(this, ctx, msg) aom_err_msg(VLC_OBJECT(this), ctx, msg ": %s (%s)") +#define AOM_MAX_FRAMES_DEPTH 64 /* * decoder_sys_t: libaom decoder descriptor */ +struct frame_priv_s +{ +vlc_tick_t pts; +}; + typedef struct { aom_codec_ctx_t ctx; +struct frame_priv_s frame_priv[AOM_MAX_FRAMES_DEPTH]; +unsigned i_next_frame_priv; } decoder_sys_t; static const struct @@ -161,21 +169,15 @@ static int Decode(decoder_t *dec, block_t *block) } /* Associate packet PTS with decoded frame */ -vlc_tick_t *pkt_pts = malloc(sizeof(*pkt_pts)); -if (!pkt_pts) { -block_Release(block); -return VLCDEC_SUCCESS; -} - -*pkt_pts = (block->i_pts != VLC_TICK_INVALID) ? block->i_pts : block->i_dts; +struct frame_priv_s *priv = _sys->frame_priv[p_sys->i_next_frame_priv++ % AOM_MAX_FRAMES_DEPTH]; +priv->pts = (block->i_pts != VLC_TICK_INVALID) ? block->i_pts : block->i_dts; aom_codec_err_t err; -err = aom_codec_decode(ctx, block->p_buffer, block->i_buffer, pkt_pts); +err = aom_codec_decode(ctx, block->p_buffer, block->i_buffer, priv); block_Release(block); if (err != AOM_CODEC_OK) { -free(pkt_pts); AOM_ERR(dec, ctx, "Failed to decode frame"); if (err == AOM_CODEC_UNSUP_BITSTREAM) return VLCDEC_ECRITICAL; @@ -185,15 +187,11 @@ static int Decode(decoder_t *dec, block_t *block) const void *iter = NULL; struct aom_image *img = aom_codec_get_frame(ctx, ); -if (!img) { -free(pkt_pts); +if (!img) return VLCDEC_SUCCESS; -} /* fetches back the PTS */ -pkt_pts = img->user_priv; -vlc_tick_t pts = *pkt_pts; -free(pkt_pts); +vlc_tick_t pts = ((struct frame_priv_s *) img->user_priv)->pts; dec->fmt_out.i_codec = FindVlcChroma(img); if (dec->fmt_out.i_codec == 0) { @@ -284,6 +282,8 @@ static int OpenDecoder(vlc_object_t *p_this) return VLC_ENOMEM; dec->p_sys = sys; +sys->i_next_frame_priv = 0; + struct aom_codec_dec_cfg deccfg = { .threads = __MIN(vlc_GetCPUCount(), 16), .allow_lowbitdepth = 1 @@ -333,7 +333,6 @@ static void CloseDecoder(vlc_object_t *p_this) struct aom_image *img = aom_codec_get_frame(>ctx, ); if (!img) break; -free(img->user_priv); } aom_codec_destroy(>ctx); ___ vlc-commits mailing list vlc-commits@videolan.org https://mailman.videolan.org/listinfo/vlc-commits