$OpenBSD: patch-src_combined_ffmpeg_ff_video_decoder_c,v 1.12 2012/06/10 07:35:30 ajacoutot Exp $

Enable direct rendering for H.264.

--- src/combined/ffmpeg/ff_video_decoder.c.orig	Fri Jun  8 09:36:36 2012
+++ src/combined/ffmpeg/ff_video_decoder.c	Sat Jun  9 20:29:04 2012
@@ -69,6 +69,7 @@ typedef struct ff_video_class_s {
   int                     thread_count;
   int8_t                  skip_loop_filter_enum;
   int8_t                  choose_speed_over_accuracy;
+  uint8_t                 enable_dri;
 
   xine_t                 *xine;
 } ff_video_class_t;
@@ -95,7 +96,7 @@ struct ff_video_decoder_s {
   uint8_t           is_mpeg12:1;
   uint8_t           pp_available:1;
   uint8_t           yuv_init:1;
-  uint8_t           is_direct_rendering_disabled:1;
+  uint8_t           is_direct_rendering_disabled:1;  /* used only to avoid flooding log */
   uint8_t           cs_convert_init:1;
   uint8_t           assume_bad_field_picture:1;
 
@@ -241,6 +242,8 @@ static int get_buffer(AVCodecContext *context, AVFrame
     }
   }
 
+  this->is_direct_rendering_disabled = 0;
+
   img = this->stream->video_out->get_frame (this->stream->video_out,
                                             width,
                                             height,
@@ -360,7 +363,7 @@ static void init_video_codec (ff_video_decoder_t *this
 
   /* Some codecs (eg rv10) copy flags in init so it's necessary to set
    * this flag here in case we are going to use direct rendering */
-  if(this->codec->capabilities & CODEC_CAP_DR1 && this->codec->id != CODEC_ID_H264) {
+  if(this->codec->capabilities & CODEC_CAP_DR1 && this->class->enable_dri) {
     this->context->flags |= CODEC_FLAG_EMU_EDGE;
   }
 
@@ -440,7 +443,7 @@ static void init_video_codec (ff_video_decoder_t *this
   /* enable direct rendering by default */
   this->output_format = XINE_IMGFMT_YV12;
 #ifdef ENABLE_DIRECT_RENDERING
-  if( this->codec->capabilities & CODEC_CAP_DR1 && this->codec->id != CODEC_ID_H264 ) {
+  if( this->codec->capabilities & CODEC_CAP_DR1 && this->class->enable_dri ) {
     this->context->get_buffer = get_buffer;
     this->context->release_buffer = release_buffer;
     xprintf(this->stream->xine, XINE_VERBOSITY_LOG,
@@ -500,6 +503,12 @@ static void pp_quality_cb(void *user_data, xine_cfg_en
   class->pp_quality = entry->num_value;
 }
 
+static void dri_cb(void *user_data, xine_cfg_entry_t *entry) {
+  ff_video_class_t   *class = (ff_video_class_t *) user_data;
+
+  class->enable_dri = entry->num_value;
+}
+
 static void pp_change_quality (ff_video_decoder_t *this) {
   this->pp_quality = this->class->pp_quality;
 
@@ -1984,6 +1993,12 @@ void *init_video_plugin (xine_t *xine, void *data) {
       "Cheating may speed up decoding but can also lead to decoding artefacts.\n"
       "A change of this setting will take effect with playing the next stream."),
     10, choose_speed_over_accuracy_cb, this);
+
+  this->enable_dri = xine->config->register_bool(config, "video.processing.ffmpeg_direct_rendering", 1,
+    _("Enable direct rendering"),
+    _("Disable direct rendering if you are experiencing lock-ups with\n"
+      "streams with lot of reference frames."),
+    10, dri_cb, this);
 
   return this;
 }
