]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/postproc.c
quartztext: fix typo
[vlc] / modules / video_filter / postproc.c
index 16be58023fe32c2b4c812b21bf73c0a81fc740fd..0aeb92afd7612f2e9c28d01c03ba964e5637ded4 100644 (file)
@@ -1,28 +1,36 @@
 /*****************************************************************************
  * postproc.c: video postprocessing using libpostproc
  *****************************************************************************
- * Copyright (C) 1999-2009 the VideoLAN team
+ * Copyright (C) 1999-2009 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Gildas Bazin <gbazin@netcourrier.com>
  *          Antoine Cellerier <dionoea at videolan dot org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+/*****************************************************************************
+ * NOTA BENE: this module requires the linking against a library which is
+ * known to require licensing under the GNU General Public License version 2
+ * (or later). Therefore, the result of compiling this module will normally
+ * be subject to the terms of that later license.
+ *****************************************************************************/
+
+
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
@@ -30,6 +38,7 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_filter.h>
+#include <vlc_cpu.h>
 
 #include "filter_picture.h"
 
@@ -58,9 +67,10 @@ static int PPNameCallback( vlc_object_t *, char const *,
 
 #define Q_TEXT N_("Post processing quality")
 #define Q_LONGTEXT N_( \
-    "Quality of post processing. Valid range is 0 to 6\n" \
-    "Higher levels require considerable more CPU power, but produce " \
-    "better looking pictures." )
+    "Quality of post processing. Valid range is 0 (disabled) to 6 (highest)\n"     \
+    "Higher levels require more CPU power, but produce higher quality pictures.\n" \
+    "With default filter chain, the values map to the following filters:\n"        \
+    "1: hb, 2-4: hb+vb, 5-6: hb+vb+dr" )
 
 #define NAME_TEXT N_("FFmpeg post processing filter chains")
 #define NAME_LONGTEXT NAME_TEXT
@@ -73,8 +83,7 @@ static int PPNameCallback( vlc_object_t *, char const *,
 vlc_module_begin ()
     set_description( N_("Video post processing filter") )
     set_shortname( N_("Postproc" ) )
-    add_shortcut( "postprocess" ) /* name is "postproc" */
-    add_shortcut( "pp" )
+    add_shortcut( "postprocess", "pp" ) /* name is "postproc" */
     set_category( CAT_VIDEO )
     set_subcategory( SUBCAT_VIDEO_VFILTER )
 
@@ -83,12 +92,10 @@ vlc_module_begin ()
     set_callbacks( OpenPostproc, ClosePostproc )
 
     add_integer_with_range( FILTER_PREFIX "q", PP_QUALITY_MAX, 0,
-                            PP_QUALITY_MAX, NULL, Q_TEXT, Q_LONGTEXT, false )
-        add_deprecated_alias( "ffmpeg-pp-q" )
+                            PP_QUALITY_MAX, Q_TEXT, Q_LONGTEXT, false )
         change_safe()
-    add_string( FILTER_PREFIX "name", "default", NULL, NAME_TEXT,
+    add_string( FILTER_PREFIX "name", "default", NAME_TEXT,
                 NAME_LONGTEXT, true )
-        add_deprecated_alias( "ffmpeg-pp-name" )
 vlc_module_end ()
 
 static const char *const ppsz_filter_options[] = {
@@ -101,14 +108,10 @@ static const char *const ppsz_filter_options[] = {
 struct filter_sys_t
 {
     /* Never changes after init */
-    pp_context_t *pp_context;
+    pp_context *pp_context;
 
     /* Set to NULL if post processing is disabled */
-    pp_mode_t    *pp_mode;
-
-    /* Set to true if previous pic had a quant matrix
-       (used to prevent spamming warning messages) */
-    bool b_had_matrix;
+    pp_mode *pp_mode;
 
     /* Lock when using or changing pp_mode */
     vlc_mutex_t lock;
@@ -123,7 +126,6 @@ static int OpenPostproc( vlc_object_t *p_this )
     filter_t *p_filter = (filter_t *)p_this;
     filter_sys_t *p_sys;
     vlc_value_t val, val_orig, text;
-    unsigned i_cpu = vlc_CPU();
     int i_flags = 0;
 
     if( p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma ||
@@ -135,14 +137,17 @@ static int OpenPostproc( vlc_object_t *p_this )
     }
 
     /* Set CPU capabilities */
-    if( i_cpu & CPU_CAPABILITY_MMX )
+#if defined(__i386__) || defined(__x86_64__)
+    if( vlc_CPU_MMX() )
         i_flags |= PP_CPU_CAPS_MMX;
-    if( i_cpu & CPU_CAPABILITY_MMXEXT )
+    if( vlc_CPU_MMXEXT() )
         i_flags |= PP_CPU_CAPS_MMX2;
-    if( i_cpu & CPU_CAPABILITY_3DNOW )
+    if( vlc_CPU_3dNOW() )
         i_flags |= PP_CPU_CAPS_3DNOW;
-    if( i_cpu & CPU_CAPABILITY_ALTIVEC )
+#elif defined(__ppc__) || defined(__ppc64__) || defined(__powerpc__)
+    if( vlc_CPU_ALTIVEC() )
         i_flags |= PP_CPU_CAPS_ALTIVEC;
+#endif
 
     switch( p_filter->fmt_in.video.i_chroma )
     {
@@ -167,7 +172,7 @@ static int OpenPostproc( vlc_object_t *p_this )
             i_flags |= PP_FORMAT_420;
             break;
         default:
-            msg_Err( p_filter, "Unsupported input chroma (%4s)",
+            msg_Err( p_filter, "Unsupported input chroma (%4.4s)",
                       (char*)&p_filter->fmt_in.video.i_chroma );
             return VLC_EGENERIC;
     }
@@ -249,8 +254,9 @@ static int OpenPostproc( vlc_object_t *p_this )
     var_AddCallback( p_filter, FILTER_PREFIX "name", PPNameCallback, NULL );
 
     p_filter->pf_video_filter = PostprocPict;
-    p_sys->b_had_matrix = true;
 
+    msg_Warn( p_filter, "Quantification table was not set by video decoder. "
+                        "Postprocessing won't look good." );
     return VLC_SUCCESS;
 }
 
@@ -269,7 +275,7 @@ static void ClosePostproc( vlc_object_t *p_this )
     /* Destroy the resources */
     vlc_mutex_destroy( &p_sys->lock );
     pp_free_context( p_sys->pp_context );
-    if( p_sys->pp_mode ) pp_free_mode( p_sys->pp_mode );
+    pp_free_mode( p_sys->pp_mode );
     free( p_sys );
 }
 
@@ -280,11 +286,6 @@ static picture_t *PostprocPict( filter_t *p_filter, picture_t *p_pic )
 {
     filter_sys_t *p_sys = p_filter->p_sys;
 
-    const uint8_t *src[3];
-    uint8_t *dst[3];
-    int i_plane;
-    int i_src_stride[3], i_dst_stride[3];
-
     picture_t *p_outpic = filter_NewPicture( p_filter );
     if( !p_outpic )
     {
@@ -294,41 +295,30 @@ static picture_t *PostprocPict( filter_t *p_filter, picture_t *p_pic )
 
     /* Lock to prevent issues if pp_mode is changed */
     vlc_mutex_lock( &p_sys->lock );
-    if( !p_sys->pp_mode )
+    if( p_sys->pp_mode != NULL )
     {
-        vlc_mutex_unlock( &p_sys->lock );
-        picture_CopyPixels( p_outpic, p_pic );
-        return CopyInfoAndRelease( p_outpic, p_pic );
-    }
-
+        const uint8_t *src[3];
+        uint8_t *dst[3];
+        int i_src_stride[3], i_dst_stride[3];
 
-    for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
-    {
-        src[i_plane] = p_pic->p[i_plane].p_pixels;
-        dst[i_plane] = p_outpic->p[i_plane].p_pixels;
+        for( int i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
+        {
+            src[i_plane] = p_pic->p[i_plane].p_pixels;
+            dst[i_plane] = p_outpic->p[i_plane].p_pixels;
 
-        /* I'm not sure what happens if i_pitch != i_visible_pitch ...
-         * at least it shouldn't crash. */
-        i_src_stride[i_plane] = p_pic->p[i_plane].i_pitch;
-        i_dst_stride[i_plane] = p_outpic->p[i_plane].i_pitch;
-    }
+            /* I'm not sure what happens if i_pitch != i_visible_pitch ...
+             * at least it shouldn't crash. */
+            i_src_stride[i_plane] = p_pic->p[i_plane].i_pitch;
+            i_dst_stride[i_plane] = p_outpic->p[i_plane].i_pitch;
+        }
 
-    if( !p_pic->p_q && p_sys->b_had_matrix )
-    {
-        msg_Warn( p_filter, "Quantification table was not set by video decoder. Postprocessing won't look good." );
-        p_sys->b_had_matrix = false;
+        pp_postprocess( src, i_src_stride, dst, i_dst_stride,
+                        p_filter->fmt_in.video.i_width,
+                        p_filter->fmt_in.video.i_height, NULL, 0,
+                        p_sys->pp_mode, p_sys->pp_context, 0 );
     }
-    else if( p_pic->p_q )
-    {
-        p_sys->b_had_matrix = true;
-    }
-
-    pp_postprocess( src, i_src_stride, dst, i_dst_stride,
-                    p_filter->fmt_in.video.i_width,
-                    p_filter->fmt_in.video.i_height,
-                    p_pic->p_q, p_pic->i_qstride,
-                    p_sys->pp_mode, p_sys->pp_context,
-                    p_pic->i_qtype == QTYPE_MPEG2 ? PP_PICT_TYPE_QP2 : 0 );
+    else
+        picture_CopyPixels( p_outpic, p_pic );
     vlc_mutex_unlock( &p_sys->lock );
 
     return CopyInfoAndRelease( p_outpic, p_pic );
@@ -341,28 +331,26 @@ static void PPChangeMode( filter_t *p_filter, const char *psz_name,
                           int i_quality )
 {
     filter_sys_t *p_sys = p_filter->p_sys;
-    vlc_mutex_lock( &p_sys->lock );
+    pp_mode *newmode = NULL, *oldmode;
+
     if( i_quality > 0 )
     {
-        pp_mode_t *pp_mode = pp_get_mode_by_name_and_quality( psz_name ?
-                                                              psz_name :
-                                                              "default",
-                                                              i_quality );
-        if( pp_mode )
-        {
-            pp_free_mode( p_sys->pp_mode );
-            p_sys->pp_mode = pp_mode;
+         newmode = pp_get_mode_by_name_and_quality( psz_name ? psz_name :
+                                                    "default", i_quality );
+         if( newmode == NULL )
+         {
+             msg_Warn( p_filter, "Error while changing post processing mode. "
+                       "Keeping previous mode." );
+             return;
         }
-        else
-            msg_Warn( p_filter, "Error while changing post processing mode. "
-                      "Keeping previous mode." );
-    }
-    else
-    {
-        pp_free_mode( p_sys->pp_mode );
-        p_sys->pp_mode = NULL;
     }
+
+    vlc_mutex_lock( &p_sys->lock );
+    oldmode = p_sys->pp_mode;
+    p_sys->pp_mode = newmode;
     vlc_mutex_unlock( &p_sys->lock );
+
+    pp_free_mode( oldmode );
 }
 
 static int PPQCallback( vlc_object_t *p_this, const char *psz_var,