vpxdec: Check that output width and height != 0
[platform/upstream/gstreamer.git] / ext / vpx / gstvpxdec.c
index 92c6377..e860715 100644 (file)
@@ -62,6 +62,20 @@ gst_vpx_dec_post_processing_flags_get_type (void)
     {C_FLAGS (VP8_DEBLOCK), "Deblock", "deblock"},
     {C_FLAGS (VP8_DEMACROBLOCK), "Demacroblock", "demacroblock"},
     {C_FLAGS (VP8_ADDNOISE), "Add noise", "addnoise"},
+#ifndef HAVE_VPX_1_8
+    {C_FLAGS (VP8_DEBUG_TXT_FRAME_INFO),
+          "Print frame information",
+        "visualize-frame-info"},
+    {C_FLAGS (VP8_DEBUG_TXT_MBLK_MODES),
+          "Show macroblock mode selection overlaid on image",
+        "visualize-macroblock-modes"},
+    {C_FLAGS (VP8_DEBUG_TXT_DC_DIFF),
+          "Show dc diff for each macro block overlaid on image",
+        "visualize-dc-diff"},
+    {C_FLAGS (VP8_DEBUG_TXT_RATE_INFO),
+          "Print video rate info",
+        "visualize-rate-info"},
+#endif
     {C_FLAGS (VP8_MFQE), "Multi-frame quality enhancement", "mfqe"},
     {0, NULL, NULL}
   };
@@ -361,7 +375,6 @@ gst_vpx_dec_default_send_tags (GstVPXDec * dec)
       gst_event_new_tag (list));
 }
 
-#ifdef HAVE_VPX_1_4
 struct Frame
 {
   GstMapInfo info;
@@ -495,7 +508,6 @@ gst_vpx_dec_release_buffer_cb (gpointer priv, vpx_codec_frame_buffer_t * fb)
 
   return 0;
 }
-#endif
 
 static void
 gst_vpx_dec_image_to_buffer (GstVPXDec * dec, const vpx_image_t * img,
@@ -574,6 +586,14 @@ gst_vpx_dec_open_codec (GstVPXDec * dec, GstVideoCodecFrame * frame)
     GST_WARNING_OBJECT (dec, "No keyframe, skipping");
     return GST_FLOW_CUSTOM_SUCCESS_1;
   }
+  if (stream_info.w == 0 || stream_info.h == 0) {
+    /* For VP8 it's possible to signal width or height to be 0, but it does
+     * not make sense to do so. For VP9 it's impossible. Hence, we most likely
+     * have a corrupt stream if width or height is 0. */
+    GST_INFO_OBJECT (dec, "Invalid resolution %d x %d", stream_info.w,
+        stream_info.h);
+    return GST_FLOW_CUSTOM_SUCCESS_1;
+  }
 
   gst_vpx_dec_set_stream_info (dec, &stream_info);
   gst_vpx_dec_set_default_format (dec, GST_VIDEO_FORMAT_I420, stream_info.w,
@@ -619,10 +639,8 @@ gst_vpx_dec_open_codec (GstVPXDec * dec, GstVideoCodecFrame * frame)
           gst_vpx_error_name (status));
     }
   }
-#ifdef HAVE_VPX_1_4
   vpx_codec_set_frame_buffer_functions (&dec->decoder,
       gst_vpx_dec_get_buffer_cb, gst_vpx_dec_release_buffer_cb, dec);
-#endif
 
   dec->decoder_inited = TRUE;
 
@@ -703,13 +721,10 @@ gst_vpx_dec_handle_frame (GstVideoDecoder * decoder, GstVideoCodecFrame * frame)
       gst_video_decoder_drop_frame (decoder, frame);
     } else {
       gst_vpx_dec_handle_resolution_change (dec, img, fmt);
-#ifdef HAVE_VPX_1_4
       if (img->fb_priv && dec->have_video_meta) {
         frame->output_buffer = gst_vpx_dec_prepare_image (dec, img);
         ret = gst_video_decoder_finish_frame (decoder, frame);
-      } else
-#endif
-      {
+      } else {
         ret = gst_video_decoder_allocate_output_frame (decoder, frame);
 
         if (ret == GST_FLOW_OK) {