Reinstate libmpeg2 hook to export quantization
authorlu_zero <lu_zero@b3059339-0415-0410-9bf9-f77b7e298cf2>
Mon, 14 Jun 2010 08:55:32 +0000 (08:55 +0000)
committerlu_zero <lu_zero@b3059339-0415-0410-9bf9-f77b7e298cf2>
Mon, 14 Jun 2010 08:55:32 +0000 (08:55 +0000)
The quant value is used by the postproc filters to fine tune their application

git-svn-id: svn://git.mplayerhq.hu/mplayer/trunk@31395 b3059339-0415-0410-9bf9-f77b7e298cf2

configure
libmpcodecs/vd_libmpeg2.c
libmpeg2/header.c
libmpeg2/libmpeg2_changes.diff
libmpeg2/mpeg2_internal.h
libmpeg2/slice.c

index d5a56b9..4c7973c 100755 (executable)
--- a/configure
+++ b/configure
@@ -8913,7 +8913,8 @@ cat > $TMPH << EOF
 #undef FAST_OSD
 #undef FAST_OSD_TABLE
 
-/* needed for libmpeg2 */
+/* Define this to enable MPEG-1/2 image postprocessing in libmpeg2 */
+#define MPEG12_POSTPROC 1
 #define ATTRIBUTE_ALIGNED_MAX 16
 
 
index c458c8f..2968afa 100644 (file)
@@ -25,6 +25,8 @@
 
 #include "vd_internal.h"
 
+//#undef MPEG12_POSTPROC
+
 static const vd_info_t info =
 {
        "libmpeg2 MPEG 1/2 Video decoder",
@@ -253,6 +255,23 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
            mpi_new->fields |= MP_IMGFIELD_ORDERED;
             if (!(info->current_picture->flags&PIC_FLAG_PROGRESSIVE_FRAME))
                 mpi_new->fields |= MP_IMGFIELD_INTERLACED;
+/*
+ * internal libmpeg2 does export quantization values per slice
+ * we let postproc know them to fine tune it's strength
+ */
+#if defined(MPEG12_POSTPROC) && defined(CONFIG_LIBMPEG2_INTERNAL)
+           mpi_new->qstride=info->sequence->width>>4;
+           {
+           char **p = &context->quant_store[type==PIC_FLAG_CODING_TYPE_B ?
+                                       2 : (context->quant_store_idx ^= 1)];
+           *p = realloc(*p, mpi_new->qstride*(info->sequence->height>>4));
+           mpi_new->qscale = *p;
+           }
+           mpeg2dec->decoder.quant_store=mpi_new->qscale;
+           mpeg2dec->decoder.quant_stride=mpi_new->qstride;
+           mpi_new->pict_type=type; // 1->I, 2->P, 3->B
+           mpi_new->qscale_type= 1;
+#endif
 
            if (mpi_new->flags&MP_IMGFLAG_DRAW_CALLBACK
                && !(mpi_new->flags&MP_IMGFLAG_DIRECT)) {
index ac3f16f..f76b028 100644 (file)
  * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Modified for use with MPlayer, see libmpeg2_changes.diff for the exact changes.
+ * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/
+ * $Id$
  */
 
 #include "config.h"
@@ -872,6 +876,7 @@ static void prescale (mpeg2dec_t * mpeg2dec, int idx)
        mpeg2dec->scaled[idx] = decoder->q_scale_type;
        for (i = 0; i < 32; i++) {
            k = decoder->q_scale_type ? non_linear_scale[i] : (i << 1);
+           decoder->quantizer_scales[i] = k;
            for (j = 0; j < 64; j++)
                decoder->quantizer_prescale[idx][i][j] =
                    k * mpeg2dec->quantizer_matrix[idx][j];
index 3aa4319..edb1068 100644 (file)
@@ -126,6 +126,16 @@ Index: libmpeg2/cpu_state.c
      if (accel & MPEG2_ACCEL_PPC_ALTIVEC) {
        mpeg2_cpu_state_save = state_save_altivec;
        mpeg2_cpu_state_restore = state_restore_altivec;
+--- libmpeg2/header.c  2006-06-16 20:12:26.000000000 +0200
++++ libmpeg2/header.c  2006-06-16 20:12:50.000000000 +0200
+@@ -872,6 +879,7 @@
+       mpeg2dec->scaled[idx] = decoder->q_scale_type;
+       for (i = 0; i < 32; i++) {
+           k = decoder->q_scale_type ? non_linear_scale[i] : (i << 1);
++          decoder->quantizer_scales[i] = k;
+           for (j = 0; j < 64; j++)
+               decoder->quantizer_prescale[idx][i][j] =
+                   k * mpeg2dec->quantizer_matrix[idx][j];
 --- libmpeg2/idct.c    (revision 26652)
 +++ libmpeg2/idct.c    (working copy)
 @@ -235,34 +239,40 @@
@@ -333,6 +343,18 @@ Index: libmpeg2/motion_comp_vis.c
 
 --- libmpeg2/mpeg2_internal.h  2006-06-16 20:12:26.000000000 +0200
 +++ libmpeg2/mpeg2_internal.h  2006-06-16 20:12:50.000000000 +0200
+@@ -152,6 +156,11 @@
+
+     /* XXX: stuff due to xine shit */
+     int8_t q_scale_type;
++
++    int quantizer_scales[32];
++    int quantizer_scale;
++    char* quant_store;
++    int quant_stride;
+ };
+
+ typedef struct {
 @@ -226,7 +238,7 @@
  };
 
@@ -342,3 +364,38 @@ Index: libmpeg2/motion_comp_vis.c
      uint8_t regv[12*16];
  #endif
      int dummy;
+--- libmpeg2/slice.c   2006-06-16 20:12:26.000000000 +0200
++++ libmpeg2/slice.c   2006-06-16 20:12:50.000000000 +0200
+@@ -142,6 +146,7 @@
+
+     quantizer_scale_code = UBITS (bit_buf, 5);
+     DUMPBITS (bit_buf, bits, 5);
++    decoder->quantizer_scale = decoder->quantizer_scales[quantizer_scale_code];
+
+     decoder->quantizer_matrix[0] =
+       decoder->quantizer_prescale[0][quantizer_scale_code];
+@@ -1564,6 +1569,24 @@
+
+ #define NEXT_MACROBLOCK                                                       \
+ do {                                                                  \
++    if(decoder->quant_store) {                                                \
++      if (decoder->picture_structure == TOP_FIELD)                    \
++          decoder->quant_store[2 * decoder->quant_stride              \
++                               * (decoder->v_offset >> 4)             \
++                               + (decoder->offset >> 4)]              \
++              = decoder->quantizer_scale;                             \
++      else if (decoder->picture_structure == BOTTOM_FIELD)            \
++          decoder->quant_store[2 * decoder->quant_stride              \
++                               * (decoder->v_offset >> 4)             \
++                               + decoder->quant_stride                \
++                               + (decoder->offset >> 4)]              \
++              = decoder->quantizer_scale;                             \
++      else                                                            \
++          decoder->quant_store[decoder->quant_stride                  \
++                               * (decoder->v_offset >> 4)             \
++                               + (decoder->offset >> 4)]              \
++              = decoder->quantizer_scale;                             \
++    }                                                                 \
+     decoder->offset += 16;                                            \
+     if (decoder->offset == decoder->width) {                          \
+       do { /* just so we can use the break statement */               \
index 72101fa..76b17e9 100644 (file)
@@ -156,6 +156,11 @@ struct mpeg2_decoder_s {
 
     /* XXX: stuff due to xine shit */
     int8_t q_scale_type;
+
+    int quantizer_scales[32];
+    int quantizer_scale;
+    char* quant_store;
+    int quant_stride;
 };
 
 typedef struct {
index a035b87..60a6119 100644 (file)
  * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Modified for use with MPlayer, see libmpeg2_changes.diff for the exact changes.
+ * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/
+ * $Id$
  */
 
 #include "config.h"
@@ -142,6 +146,7 @@ static inline void get_quantizer_scale (mpeg2_decoder_t * const decoder)
 
     quantizer_scale_code = UBITS (bit_buf, 5);
     DUMPBITS (bit_buf, bits, 5);
+    decoder->quantizer_scale = decoder->quantizer_scales[quantizer_scale_code];
 
     decoder->quantizer_matrix[0] =
        decoder->quantizer_prescale[0][quantizer_scale_code];
@@ -1564,6 +1569,24 @@ do {                                                             \
 
 #define NEXT_MACROBLOCK                                                        \
 do {                                                                   \
+    if(decoder->quant_store) {                                         \
+       if (decoder->picture_structure == TOP_FIELD)                    \
+           decoder->quant_store[2 * decoder->quant_stride              \
+                                * (decoder->v_offset >> 4)             \
+                                + (decoder->offset >> 4)]              \
+               = decoder->quantizer_scale;                             \
+       else if (decoder->picture_structure == BOTTOM_FIELD)            \
+           decoder->quant_store[2 * decoder->quant_stride              \
+                                * (decoder->v_offset >> 4)             \
+                                + decoder->quant_stride                \
+                                + (decoder->offset >> 4)]              \
+               = decoder->quantizer_scale;                             \
+       else                                                            \
+           decoder->quant_store[decoder->quant_stride                  \
+                                * (decoder->v_offset >> 4)             \
+                                + (decoder->offset >> 4)]              \
+               = decoder->quantizer_scale;                             \
+    }                                                                  \
     decoder->offset += 16;                                             \
     if (decoder->offset == decoder->width) {                           \
        do { /* just so we can use the break statement */               \