changeset 10510:73b3e4336cd4

Add mpeg2_flags to mp_image_t, copy flags in vd_libmpeg2.c, and add vf_softpulldown.c.
author ranma
date Sun, 03 Aug 2003 12:09:58 +0000
parents d9d24093db2e
children dc98cee9a50f
files libmpcodecs/Makefile libmpcodecs/mp_image.h libmpcodecs/vd_libmpeg2.c libmpcodecs/vf.c libmpcodecs/vf_softpulldown.c
diffstat 5 files changed, 174 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/Makefile	Sun Aug 03 12:04:57 2003 +0000
+++ b/libmpcodecs/Makefile	Sun Aug 03 12:09:58 2003 +0000
@@ -14,7 +14,7 @@
 VIDEO_SRCS_OPT=vd_realvid.c vd_ffmpeg.c vd_dshow.c vd_dmo.c vd_vfw.c vd_vfwex.c vd_odivx.c vd_divx4.c vd_xanim.c vd_xvid.c vd_libdv.c vd_qtvideo.c vd_theora.c
 VIDEO_SRCS=dec_video.c vd.c $(VIDEO_SRCS_NAT) $(VIDEO_SRCS_LIB) $(VIDEO_SRCS_OPT)
 
-VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c vf_eq.c vf_eq2.c vf_halfpack.c vf_dint.c vf_1bpp.c vf_bmovl.c vf_2xsai.c vf_unsharp.c vf_swapuv.c vf_il.c vf_boxblur.c vf_sab.c vf_smartblur.c vf_perspective.c vf_down3dright.c vf_field.c vf_denoise3d.c vf_hqdn3d.c vf_detc.c vf_telecine.c vf_tfields.c vf_ivtc.c vf_ilpack.c vf_dsize.c vf_decimate.c
+VFILTER_SRCS=vf.c vf_vo.c vf_crop.c vf_expand.c vf_pp.c vf_scale.c vf_format.c vf_yuy2.c vf_flip.c vf_rgb2bgr.c vf_rotate.c vf_mirror.c vf_palette.c vf_lavc.c vf_dvbscale.c vf_cropdetect.c vf_test.c vf_noise.c vf_yvu9.c vf_rectangle.c vf_lavcdeint.c vf_eq.c vf_eq2.c vf_halfpack.c vf_dint.c vf_1bpp.c vf_bmovl.c vf_2xsai.c vf_unsharp.c vf_swapuv.c vf_il.c vf_boxblur.c vf_sab.c vf_smartblur.c vf_perspective.c vf_down3dright.c vf_field.c vf_denoise3d.c vf_hqdn3d.c vf_detc.c vf_telecine.c vf_tfields.c vf_ivtc.c vf_ilpack.c vf_dsize.c vf_decimate.c vf_softpulldown.c
 ENCODER_SRCS=ve.c ve_divx4.c ve_lavc.c ve_vfw.c ve_rawrgb.c ve_libdv.c ve_xvid.c ve_qtvideo.c ve_nuv.c
 
 NATIVE_SRCS=native/RTjpegN.c native/cinepak.c native/fli.c native/minilzo.c native/msvidc.c native/nuppelvideo.c native/qtrle.c native/qtrpza.c native/qtsmc.c native/roqav.c native/xa_gsm.c native/decode144.c native/decode288.c
--- a/libmpcodecs/mp_image.h	Sun Aug 03 12:04:57 2003 +0000
+++ b/libmpcodecs/mp_image.h	Sun Aug 03 12:09:58 2003 +0000
@@ -64,6 +64,9 @@
 
 #define MP_MAX_PLANES	4
 
+#define MP_IMGMPEG2FLAG_TOP_FIELD_FIRST 0x01
+#define MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD 0x02
+
 typedef struct mp_image_s {
     unsigned short flags;
     unsigned char type;
@@ -76,6 +79,7 @@
     char * qscale;
     int qstride;
     int pict_type; // 0->unknown, 1->I, 2->P, 3->B
+    int mpeg2_flags;
     int qscale_type; // 0->mpeg1/4/h263, 1->mpeg2
     int num_planes;
     /* these are only used by planar formats Y,U(Cb),V(Cr) */
--- a/libmpcodecs/vd_libmpeg2.c	Sun Aug 03 12:04:57 2003 +0000
+++ b/libmpcodecs/vd_libmpeg2.c	Sun Aug 03 12:09:58 2003 +0000
@@ -143,6 +143,12 @@
 		(info->sequence->picture_height+15)&(~15) );
 	    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;
+	    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;
 
 #ifdef MPEG12_POSTPROC
 	    if(!mpi->qscale){
--- a/libmpcodecs/vf.c	Sun Aug 03 12:04:57 2003 +0000
+++ b/libmpcodecs/vf.c	Sun Aug 03 12:09:58 2003 +0000
@@ -69,6 +69,7 @@
 extern vf_info_t vf_info_ilpack;
 extern vf_info_t vf_info_dsize;
 extern vf_info_t vf_info_decimate;
+extern vf_info_t vf_info_softpulldown;
 
 // list of available filters:
 static vf_info_t* filter_list[]={
@@ -127,6 +128,7 @@
     &vf_info_ilpack,
     &vf_info_dsize,
     &vf_info_decimate,
+    &vf_info_softpulldown,
     NULL
 };
 
@@ -435,6 +437,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->qscale_type= src->qscale_type;
     if(dst->width == src->width && dst->height == src->height){
 	dst->qstride= src->qstride;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libmpcodecs/vf_softpulldown.c	Sun Aug 03 12:09:58 2003 +0000
@@ -0,0 +1,160 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../config.h"
+#include "../mp_msg.h"
+
+#include "img_format.h"
+#include "mp_image.h"
+#include "vf.h"
+
+#include "../libvo/fastmemcpy.h"
+#include "../libvo/sub.h"
+
+struct vf_priv_s {
+	int state;
+	long long in;
+	long long out;
+};
+
+static inline void *my_memcpy_pic(void * dst, void * src, int bytesPerLine, int height, int dstStride, int srcStride)
+{
+	int i;
+	void *retval=dst;
+
+	for(i=0; i<height; i++)
+	{
+		memcpy(dst, src, bytesPerLine);
+		src+= srcStride;
+		dst+= dstStride;
+	}
+
+	return retval;
+}
+
+static int put_image(struct vf_instance_s* vf, mp_image_t *mpi)
+{
+	mp_image_t *dmpi;
+	int ret = 0;
+	int flags = mpi->mpeg2_flags;
+	int state = vf->priv->state;
+
+	dmpi = vf_get_image(vf->next, mpi->imgfmt,
+	                    MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
+	                    MP_IMGFLAG_PRESERVE, mpi->width, mpi->height);
+
+	vf->priv->in++;
+
+	if ((state == 0 &&
+	     !(flags & MP_IMGMPEG2FLAG_TOP_FIELD_FIRST)) ||
+	    (state == 1 &&
+	     flags & MP_IMGMPEG2FLAG_TOP_FIELD_FIRST))
+		mp_msg(MSGT_VFILTER, MSGL_WARN,
+		       "softpulldown: Unexpected mpeg2 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);
+
+	if (state == 0) {
+		ret = vf_next_put_image(vf, mpi);
+		vf->priv->out++;
+		if (flags & MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD) {
+			my_memcpy_pic(dmpi->planes[0],
+			           mpi->planes[0], mpi->w, mpi->h/2,
+			           dmpi->stride[0]*2, mpi->stride[0]*2);
+			if (mpi->flags & MP_IMGFLAG_PLANAR) {
+				my_memcpy_pic(dmpi->planes[1],
+				              mpi->planes[1],
+				              mpi->chroma_width,
+				              mpi->chroma_height/2,
+				              dmpi->stride[1]*2,
+				              mpi->stride[1]*2);
+				my_memcpy_pic(dmpi->planes[2],
+				              mpi->planes[2],
+				              mpi->chroma_width,
+				              mpi->chroma_height/2,
+				              dmpi->stride[2]*2,
+				              mpi->stride[2]*2);
+			}
+			state=1;
+		}
+	} else {
+		my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
+		              mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
+		              dmpi->stride[0]*2, mpi->stride[0]*2);
+		if (mpi->flags & MP_IMGFLAG_PLANAR) {
+			my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
+			              mpi->planes[1]+mpi->stride[1],
+			              mpi->chroma_width, mpi->chroma_height/2,
+			              dmpi->stride[1]*2, mpi->stride[1]*2);
+			my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
+			              mpi->planes[2]+mpi->stride[2],
+			              mpi->chroma_width, mpi->chroma_height/2,
+			              dmpi->stride[2]*2, mpi->stride[2]*2);
+		}
+		ret = vf_next_put_image(vf, dmpi);
+		vf->priv->out++;
+		if (flags & MP_IMGMPEG2FLAG_REPEAT_FIRST_FIELD) {
+			ret |= vf_next_put_image(vf, mpi);
+			vf->priv->out++;
+			state=0;
+		} else {
+			my_memcpy_pic(dmpi->planes[0],
+			              mpi->planes[0], mpi->w, mpi->h/2,
+			              dmpi->stride[0]*2, mpi->stride[0]*2);
+			if (mpi->flags & MP_IMGFLAG_PLANAR) {
+				my_memcpy_pic(dmpi->planes[1],
+				              mpi->planes[1],
+				              mpi->chroma_width,
+				              mpi->chroma_height/2,
+				              dmpi->stride[1]*2,
+				              mpi->stride[1]*2);
+				my_memcpy_pic(dmpi->planes[2],
+				              mpi->planes[2],
+				              mpi->chroma_width,
+				              mpi->chroma_height/2,
+				              dmpi->stride[2]*2,
+				              mpi->stride[2]*2);
+			}
+		}
+	}
+
+	vf->priv->state = state;
+
+	return ret;
+}
+
+static int config(struct vf_instance_s* vf,
+        int width, int height, int d_width, int d_height,
+	unsigned int flags, unsigned int outfmt)
+{
+	return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
+}
+
+static void uninit(struct vf_instance_s* vf)
+{
+	mp_msg(MSGT_VFILTER, MSGL_INFO, "softpulldown: %lld frames in, %lld frames out\n", vf->priv->in, vf->priv->out);
+	free(vf->priv);
+}
+
+static int open(vf_instance_t *vf, char* args)
+{
+	struct vf_priv_s *p;
+	vf->config = config;
+	vf->put_image = put_image;
+	vf->uninit = uninit;
+	vf->default_reqs = VFCAP_ACCEPT_STRIDE;
+	vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
+	vf->priv->state = 0;
+	return 1;
+}
+
+vf_info_t vf_info_softpulldown = {
+    "mpeg2 soft 3:2 pulldown",
+    "softpulldown",
+    "Tobias Diedrich",
+    "",
+    open,
+    NULL
+};