]> git.sesse.net Git - ffmpeg/commitdiff
hap: Move some per-stream setup into decoder init rather than per-frame
authorTom Butterworth <bangnoise@gmail.com>
Thu, 23 Jul 2015 18:37:08 +0000 (14:37 -0400)
committerVittorio Giovara <vittorio.giovara@gmail.com>
Mon, 27 Jul 2015 14:53:03 +0000 (15:53 +0100)
This change will reject frames with a texture type which does not match
the stream description.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
libavcodec/hapdec.c

index 71f7db53998d493e08d1c02de218bd3f6680c71b..46dda0400d457fc1988f81ef1d561f9f51d9b66a 100644 (file)
@@ -74,29 +74,14 @@ static int setup_texture(AVCodecContext *avctx, size_t length)
     HapContext *ctx = avctx->priv_data;
     GetByteContext *gbc = &ctx->gbc;
     int64_t snappy_size;
-    const char *texture_name;
     const char *compressorstr;
     int ret;
 
-    switch (ctx->section_type & 0x0F) {
-    case HAP_FMT_RGBDXT1:
-        ctx->tex_rat = 8;
-        ctx->tex_fun = ctx->dxtc.dxt1_block;
-        texture_name = "DXT1";
-        break;
-    case HAP_FMT_RGBADXT5:
-        ctx->tex_rat = 16;
-        ctx->tex_fun = ctx->dxtc.dxt5_block;
-        texture_name = "DXT5";
-        break;
-    case HAP_FMT_YCOCGDXT5:
-        ctx->tex_rat = 16;
-        ctx->tex_fun = ctx->dxtc.dxt5ys_block;
-        texture_name = "DXT5-YCoCg-scaled";
-        break;
-    default:
+    if ((avctx->codec_tag == MKTAG('H','a','p','1') && (ctx->section_type & 0x0F) != HAP_FMT_RGBDXT1) ||
+        (avctx->codec_tag == MKTAG('H','a','p','5') && (ctx->section_type & 0x0F) != HAP_FMT_RGBADXT5) ||
+        (avctx->codec_tag == MKTAG('H','a','p','Y') && (ctx->section_type & 0x0F) != HAP_FMT_YCOCGDXT5)) {
         av_log(avctx, AV_LOG_ERROR,
-               "Invalid format mode %02X.\n", ctx->section_type);
+               "Invalid texture format %#04x.\n", ctx->section_type & 0x0F);
         return AVERROR_INVALIDDATA;
     }
 
@@ -135,8 +120,7 @@ static int setup_texture(AVCodecContext *avctx, size_t length)
         return AVERROR_INVALIDDATA;
     }
 
-    av_log(avctx, AV_LOG_DEBUG, "%s texture with %s compressor\n",
-           texture_name, compressorstr);
+    av_log(avctx, AV_LOG_DEBUG, "%s compressor\n", compressorstr);
 
     return 0;
 }
@@ -220,6 +204,7 @@ static int hap_decode(AVCodecContext *avctx, void *data,
 static av_cold int hap_init(AVCodecContext *avctx)
 {
     HapContext *ctx = avctx->priv_data;
+    const char *texture_name;
     int ret = av_image_check_size(avctx->width, avctx->height, 0, avctx);
 
     if (ret < 0) {
@@ -237,6 +222,28 @@ static av_cold int hap_init(AVCodecContext *avctx)
 
     ff_texturedsp_init(&ctx->dxtc);
 
+    switch (avctx->codec_tag) {
+    case MKTAG('H','a','p','1'):
+        texture_name = "DXT1";
+        ctx->tex_rat = 8;
+        ctx->tex_fun = ctx->dxtc.dxt1_block;
+        break;
+    case MKTAG('H','a','p','5'):
+        texture_name = "DXT5";
+        ctx->tex_rat = 16;
+        ctx->tex_fun = ctx->dxtc.dxt5_block;
+        break;
+    case MKTAG('H','a','p','Y'):
+        texture_name = "DXT5-YCoCg-scaled";
+        ctx->tex_rat = 16;
+        ctx->tex_fun = ctx->dxtc.dxt5ys_block;
+        break;
+    default:
+        return AVERROR_DECODER_NOT_FOUND;
+    }
+
+    av_log(avctx, AV_LOG_DEBUG, "%s texture\n", texture_name);
+
     ctx->slice_count = av_clip(avctx->thread_count, 1,
                                avctx->coded_height / TEXTURE_BLOCK_H);