]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/g722enc.c
alacenc: do not set bits_per_coded_sample
[ffmpeg] / libavcodec / g722enc.c
index ceb18b46dbaa8bc516231a53ecefd4b00ee10a51..1cb0070649254aacd9e650749318c8147485b4af 100644 (file)
    problems, so we limit it to a reasonable value */
 #define MAX_FRAME_SIZE 32768
 
+/* We clip the value of avctx->trellis to prevent data type overflows and
+   undefined behavior. Using larger values is insanely slow anyway. */
+#define MIN_TRELLIS 0
+#define MAX_TRELLIS 16
+
 static av_cold int g722_encode_init(AVCodecContext * avctx)
 {
     G722Context *c = avctx->priv_data;
@@ -83,6 +88,17 @@ static av_cold int g722_encode_init(AVCodecContext * avctx)
         avctx->frame_size = 320;
     }
 
+    if (avctx->trellis) {
+        /* validate trellis */
+        if (avctx->trellis < MIN_TRELLIS || avctx->trellis > MAX_TRELLIS) {
+            int new_trellis = av_clip(avctx->trellis, MIN_TRELLIS, MAX_TRELLIS);
+            av_log(avctx, AV_LOG_WARNING, "Requested trellis value is not "
+                   "allowed. Using %d instead of %d\n", new_trellis,
+                   avctx->trellis);
+            avctx->trellis = new_trellis;
+        }
+    }
+
     return 0;
 }