]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pcm.c
avcodec/vp3dsp: Use unsigned constant to avoid undefined integer overflow in ff_vp3ds...
[ffmpeg] / libavcodec / pcm.c
index 0c4b452b0e1ef111b6656ebe40dae4b4b01c005b..12d1b3a2c34897221ab44052e2ecfd905b276e05 100644 (file)
@@ -235,13 +235,15 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 
 typedef struct PCMDecode {
     short   table[256];
-    AVFloatDSPContext *fdsp;
+    void (*vector_fmul_scalar)(float *dst, const float *src, float mul,
+                               int len);
     float   scale;
 } PCMDecode;
 
 static av_cold int pcm_decode_init(AVCodecContext *avctx)
 {
     PCMDecode *s = avctx->priv_data;
+    AVFloatDSPContext *fdsp;
     int i;
 
     if (avctx->channels <= 0) {
@@ -268,9 +270,11 @@ static av_cold int pcm_decode_init(AVCodecContext *avctx)
             return AVERROR_INVALIDDATA;
 
         s->scale = 1. / (1 << (avctx->bits_per_coded_sample - 1));
-        s->fdsp = avpriv_float_dsp_alloc(0);
-        if (!s->fdsp)
+        fdsp = avpriv_float_dsp_alloc(0);
+        if (!fdsp)
             return AVERROR(ENOMEM);
+        s->vector_fmul_scalar = fdsp->vector_fmul_scalar;
+        av_free(fdsp);
         break;
     default:
         break;
@@ -284,15 +288,6 @@ static av_cold int pcm_decode_init(AVCodecContext *avctx)
     return 0;
 }
 
-static av_cold int pcm_decode_close(AVCodecContext *avctx)
-{
-    PCMDecode *s = avctx->priv_data;
-
-    av_freep(&s->fdsp);
-
-    return 0;
-}
-
 /**
  * Read PCM samples macro
  * @param size   Data size of native machine format
@@ -491,14 +486,6 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
             bytestream_get_buffer(&src, samples, n * sample_size);
         }
         break;
-    case AV_CODEC_ID_PCM_ZORK:
-        for (; n > 0; n--) {
-            int v = *src++;
-            if (v < 128)
-                v = 128 - v;
-            *samples++ = v;
-        }
-        break;
     case AV_CODEC_ID_PCM_ALAW:
     case AV_CODEC_ID_PCM_MULAW:
     case AV_CODEC_ID_PCM_VIDC:
@@ -521,7 +508,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
                                  ((src[2] & 0x0F) <<  8) |
                                    src[1];
                 // extract high 20 bits and expand to 32 bits
-                *dst_int32_t++ =  (src[4]         << 24) |
+                *dst_int32_t++ =  ((uint32_t)src[4]<<24) |
                                   (src[3]         << 16) |
                                  ((src[2] & 0xF0) <<  8) |
                                   (src[4]         <<  4) |
@@ -537,9 +524,9 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
 
     if (avctx->codec_id == AV_CODEC_ID_PCM_F16LE ||
         avctx->codec_id == AV_CODEC_ID_PCM_F24LE) {
-        s->fdsp->vector_fmul_scalar((float *)frame->extended_data[0],
-                                    (const float *)frame->extended_data[0],
-                                    s->scale, FFALIGN(frame->nb_samples * avctx->channels, 4));
+        s->vector_fmul_scalar((float *)frame->extended_data[0],
+                              (const float *)frame->extended_data[0],
+                              s->scale, FFALIGN(frame->nb_samples * avctx->channels, 4));
         emms_c();
     }
 
@@ -578,7 +565,6 @@ AVCodec ff_ ## name_ ## _decoder = {                                        \
     .id             = AV_CODEC_ID_ ## id_,                                  \
     .priv_data_size = sizeof(PCMDecode),                                    \
     .init           = pcm_decode_init,                                      \
-    .close          = pcm_decode_close,                                     \
     .decode         = pcm_decode_frame,                                     \
     .capabilities   = AV_CODEC_CAP_DR1,                                     \
     .sample_fmts    = (const enum AVSampleFormat[]){ sample_fmt_,           \
@@ -626,7 +612,6 @@ PCM_CODEC  (PCM_U24BE,        AV_SAMPLE_FMT_S32, pcm_u24be,        "PCM unsigned
 PCM_CODEC  (PCM_U24LE,        AV_SAMPLE_FMT_S32, pcm_u24le,        "PCM unsigned 24-bit little-endian");
 PCM_CODEC  (PCM_U32BE,        AV_SAMPLE_FMT_S32, pcm_u32be,        "PCM unsigned 32-bit big-endian");
 PCM_CODEC  (PCM_U32LE,        AV_SAMPLE_FMT_S32, pcm_u32le,        "PCM unsigned 32-bit little-endian");
-PCM_DECODER(PCM_ZORK,         AV_SAMPLE_FMT_U8,  pcm_zork,         "PCM Zork");
 PCM_CODEC  (PCM_S64BE,        AV_SAMPLE_FMT_S64, pcm_s64be,        "PCM signed 64-bit big-endian");
 PCM_CODEC  (PCM_S64LE,        AV_SAMPLE_FMT_S64, pcm_s64le,        "PCM signed 64-bit little-endian");
 PCM_CODEC  (PCM_VIDC,         AV_SAMPLE_FMT_S16, pcm_vidc,         "PCM Archimedes VIDC");