[MPlayer-dev-eng] [PATCH] clean up mpeg2 field flags

D Richard Felker III dalias at aerifal.cx
Mon Aug 18 15:26:07 CEST 2003


This patch is partly cosmetic, but the cosmetics are just there to go
along with fixing a fundamental design flaw. Without this patch,
there's no way for a filter to tell if the TFF/RFF flags are valid,
and this is very bad since top-field-first is standard, while a 0 in
the mpeg2_flags would imply bottom-field-first.

Anyway, I figure having the flags be limited to mpeg2 is kinda silly.
It makes much more sense to have a general 'fields' header that can be
used to convey information about the image's fields. Hopefully this
can be extended in G2 so that filters made to work with interlaced
images can pass one field at a time, and of course so field-coded
mpeg2 can be output directly as fields if desired.

If no one objects to this patch right away I'll go ahead and commit.
The new long-awaited inverse pulldown filter I've been working on
depends on it (for handling mixed hard/soft telecine -- finally!) and
I'll be committing that for testing soon.

Rich

-------------- next part --------------
Index: libmpcodecs/mp_image.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/mp_image.h,v
retrieving revision 1.25
diff -u -r1.25 mp_image.h
--- libmpcodecs/mp_image.h	3 Aug 2003 12:09:58 -0000	1.25
+++ libmpcodecs/mp_image.h	18 Aug 2003 13:20:19 -0000
@@ -64,8 +64,11 @@
 
 #define MP_MAX_PLANES	4
 
-#define MP_IMGMPEG2FLAG_TOP_FIELD_FIRST 0x01
-#define MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD 0x02
+#define MP_IMGFIELD_ORDERED 0x01
+#define MP_IMGFIELD_TOP_FIRST 0x02
+#define MP_IMGFIELD_REPEAT_FIRST 0x04
+#define MP_IMGFIELD_TOP 0x08
+#define MP_IMGFIELD_BOTTOM 0x10
 
 typedef struct mp_image_s {
     unsigned short flags;
@@ -79,7 +82,7 @@
     char * qscale;
     int qstride;
     int pict_type; // 0->unknown, 1->I, 2->P, 3->B
-    int mpeg2_flags;
+    int fields;
     int qscale_type; // 0->mpeg1/4/h263, 1->mpeg2
     int num_planes;
     /* these are only used by planar formats Y,U(Cb),V(Cr) */
Index: libmpcodecs/vd_libmpeg2.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vd_libmpeg2.c,v
retrieving revision 1.25
diff -u -r1.25 vd_libmpeg2.c
--- libmpcodecs/vd_libmpeg2.c	3 Aug 2003 12:09:58 -0000	1.25
+++ libmpcodecs/vd_libmpeg2.c	18 Aug 2003 13:20:19 -0000
@@ -144,11 +144,12 @@
 	    if(!mpi) return 0; // VO ERROR!!!!!!!!
 	    mpeg2_set_buf(mpeg2dec, mpi->planes, mpi);
 	    if (info->current_picture->flags&PIC_FLAG_TOP_FIELD_FIRST)
-		mpi->mpeg2_flags |= MP_IMGMPEG2FLAG_TOP_FIELD_FIRST;
-	    else mpi->mpeg2_flags &= ~MP_IMGMPEG2FLAG_TOP_FIELD_FIRST;
+		mpi->fields |= MP_IMGFIELD_TOP_FIRST;
+	    else mpi->fields &= ~MP_IMGFIELD_TOP_FIRST;
 	    if (info->current_picture->flags&PIC_FLAG_REPEAT_FIRST_FIELD)
-		mpi->mpeg2_flags |= MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD;
-	    else mpi->mpeg2_flags &= ~MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD;
+		mpi->fields |= MP_IMGFIELD_REPEAT_FIRST;
+	    else mpi->fields &= ~MP_IMGFIELD_REPEAT_FIRST;
+	    mpi->fields |= MP_IMGFIELD_ORDERED;
 
 #ifdef MPEG12_POSTPROC
 	    if(!mpi->qscale){
Index: libmpcodecs/vf.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vf.c,v
retrieving revision 1.87
diff -u -r1.87 vf.c
--- libmpcodecs/vf.c	11 Aug 2003 20:04:30 -0000	1.87
+++ libmpcodecs/vf.c	18 Aug 2003 13:20:20 -0000
@@ -439,7 +441,7 @@
 
 void vf_clone_mpi_attributes(mp_image_t* dst, mp_image_t* src){
     dst->pict_type= src->pict_type;
-    dst->mpeg2_flags = src->mpeg2_flags;
+    dst->fields = src->fields;
     dst->qscale_type= src->qscale_type;
     if(dst->width == src->width && dst->height == src->height){
 	dst->qstride= src->qstride;
Index: libmpcodecs/vf_softpulldown.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vf_softpulldown.c,v
retrieving revision 1.1
diff -u -r1.1 vf_softpulldown.c
--- libmpcodecs/vf_softpulldown.c	3 Aug 2003 12:09:58 -0000	1.1
+++ libmpcodecs/vf_softpulldown.c	18 Aug 2003 13:20:20 -0000
@@ -37,7 +37,7 @@
 {
 	mp_image_t *dmpi;
 	int ret = 0;
-	int flags = mpi->mpeg2_flags;
+	int flags = mpi->fields;
 	int state = vf->priv->state;
 
 	dmpi = vf_get_image(vf->next, mpi->imgfmt,
@@ -47,19 +47,21 @@
 	vf->priv->in++;
 
 	if ((state == 0 &&
-	     !(flags & MP_IMGMPEG2FLAG_TOP_FIELD_FIRST)) ||
+	     !(flags & MP_IMGFIELD_TOP_FIRST)) ||
 	    (state == 1 &&
-	     flags & MP_IMGMPEG2FLAG_TOP_FIELD_FIRST))
+	     flags & MP_IMGFIELD_TOP_FIRST)) {
 		mp_msg(MSGT_VFILTER, MSGL_WARN,
-		       "softpulldown: Unexpected mpeg2 flags: state=%d top_field_first=%d repeat_first_field=%d\n",
+		       "softpulldown: Unexpected field flags: state=%d top_field_first=%d repeat_first_field=%d\n",
 		       state,
-		       (flags & MP_IMGMPEG2FLAG_TOP_FIELD_FIRST) == 1,
-		       (flags & MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD) == 1);
+		       (flags & MP_IMGFIELD_TOP_FIRST) != 0,
+		       (flags & MP_IMGFIELD_REPEAT_FIRST) != 0);
+		state ^= 1;
+	}
 
 	if (state == 0) {
 		ret = vf_next_put_image(vf, mpi);
 		vf->priv->out++;
-		if (flags & MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD) {
+		if (flags & MP_IMGFIELD_REPEAT_FIRST) {
 			my_memcpy_pic(dmpi->planes[0],
 			           mpi->planes[0], mpi->w, mpi->h/2,
 			           dmpi->stride[0]*2, mpi->stride[0]*2);
@@ -95,7 +97,7 @@
 		}
 		ret = vf_next_put_image(vf, dmpi);
 		vf->priv->out++;
-		if (flags & MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD) {
+		if (flags & MP_IMGFIELD_REPEAT_FIRST) {
 			ret |= vf_next_put_image(vf, mpi);
 			vf->priv->out++;
 			state=0;


More information about the MPlayer-dev-eng mailing list