diff mbox series

[FFmpeg-devel,02/16] avcodec/pcm-dvd: Avoid allocation of buffer

Message ID 20200913025753.274772-2-andreas.rheinhardt@gmail.com
State Accepted
Commit 7a84ee84ec2b1413f14d81af4b9266de2e83ca2c
Headers show
Series [FFmpeg-devel,01/16] avcodec/snowdec: Use ff_snow_common_init() directly
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 13, 2020, 2:57 a.m. UTC
In this case, it also allows to remove the decoder's close function.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/pcm-dvd.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

Comments

Andreas Rheinhardt Sept. 16, 2020, 1:10 a.m. UTC | #1
Andreas Rheinhardt:
> In this case, it also allows to remove the decoder's close function.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/pcm-dvd.c | 16 ++--------------
>  1 file changed, 2 insertions(+), 14 deletions(-)
> 
> diff --git a/libavcodec/pcm-dvd.c b/libavcodec/pcm-dvd.c
> index 0a751a8191..725c2f5b29 100644
> --- a/libavcodec/pcm-dvd.c
> +++ b/libavcodec/pcm-dvd.c
> @@ -34,8 +34,9 @@ typedef struct PCMDVDContext {
>      int last_block_size;     // Size of the last block of samples in bytes
>      int samples_per_block;   // Number of samples per channel per block
>      int groups_per_block;    // Number of 20/24-bit sample groups per block
> -    uint8_t *extra_samples;  // Pointer to leftover samples from a frame
>      int extra_sample_count;  // Number of leftover samples in the buffer
> +    uint8_t extra_samples[8 * 3 * 4];  // Space for leftover samples from a frame
> +                                       // (8 channels, 3B/sample, 4 samples/block)
>  } PCMDVDContext;
>  
>  static av_cold int pcm_dvd_decode_init(AVCodecContext *avctx)
> @@ -44,18 +45,6 @@ static av_cold int pcm_dvd_decode_init(AVCodecContext *avctx)
>  
>      /* Invalid header to force parsing of the first header */
>      s->last_header = -1;
> -    /* reserve space for 8 channels, 3 bytes/sample, 4 samples/block */
> -    if (!(s->extra_samples = av_malloc(8 * 3 * 4)))
> -        return AVERROR(ENOMEM);
> -
> -    return 0;
> -}
> -
> -static av_cold int pcm_dvd_decode_uninit(AVCodecContext *avctx)
> -{
> -    PCMDVDContext *s = avctx->priv_data;
> -
> -    av_freep(&s->extra_samples);
>  
>      return 0;
>  }
> @@ -310,7 +299,6 @@ AVCodec ff_pcm_dvd_decoder = {
>      .priv_data_size = sizeof(PCMDVDContext),
>      .init           = pcm_dvd_decode_init,
>      .decode         = pcm_dvd_decode_frame,
> -    .close          = pcm_dvd_decode_uninit,
>      .capabilities   = AV_CODEC_CAP_DR1,
>      .sample_fmts    = (const enum AVSampleFormat[]) {
>          AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE
> 
Will apply the patches in the first batch (i.e. everything until #16)
tomorrow if there are no objections.

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/pcm-dvd.c b/libavcodec/pcm-dvd.c
index 0a751a8191..725c2f5b29 100644
--- a/libavcodec/pcm-dvd.c
+++ b/libavcodec/pcm-dvd.c
@@ -34,8 +34,9 @@  typedef struct PCMDVDContext {
     int last_block_size;     // Size of the last block of samples in bytes
     int samples_per_block;   // Number of samples per channel per block
     int groups_per_block;    // Number of 20/24-bit sample groups per block
-    uint8_t *extra_samples;  // Pointer to leftover samples from a frame
     int extra_sample_count;  // Number of leftover samples in the buffer
+    uint8_t extra_samples[8 * 3 * 4];  // Space for leftover samples from a frame
+                                       // (8 channels, 3B/sample, 4 samples/block)
 } PCMDVDContext;
 
 static av_cold int pcm_dvd_decode_init(AVCodecContext *avctx)
@@ -44,18 +45,6 @@  static av_cold int pcm_dvd_decode_init(AVCodecContext *avctx)
 
     /* Invalid header to force parsing of the first header */
     s->last_header = -1;
-    /* reserve space for 8 channels, 3 bytes/sample, 4 samples/block */
-    if (!(s->extra_samples = av_malloc(8 * 3 * 4)))
-        return AVERROR(ENOMEM);
-
-    return 0;
-}
-
-static av_cold int pcm_dvd_decode_uninit(AVCodecContext *avctx)
-{
-    PCMDVDContext *s = avctx->priv_data;
-
-    av_freep(&s->extra_samples);
 
     return 0;
 }
@@ -310,7 +299,6 @@  AVCodec ff_pcm_dvd_decoder = {
     .priv_data_size = sizeof(PCMDVDContext),
     .init           = pcm_dvd_decode_init,
     .decode         = pcm_dvd_decode_frame,
-    .close          = pcm_dvd_decode_uninit,
     .capabilities   = AV_CODEC_CAP_DR1,
     .sample_fmts    = (const enum AVSampleFormat[]) {
         AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE