[PATCH] libmpeg2 post-processing support
Fabian Franz <[email protected]>
| Newsgroups | gmane.comp.video.mplayer.g2.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, attached patch enables libmpeg2 to support post-processing. It also enables it in vd_libmpeg2.c. I've tested it and it works (at least for me :) ). (Slow, but the image got "better". Heh, my comptuer is slow ;) ) If this patch is correct, I'll try to get it into official libmpeg2-cvs. A'rpi, could you please check ? cu Fabian _______________________________________________ MPlayer-G2-dev mailing list [email protected] http://mplayerhq.hu/mailman/listinfo/mplayer-g2-dev
g2-libmpeg2-pp.diff
(text/x-diff, 5.1 KB)
diff -ur g2-orig/video/libmpeg2/decode.c g2/video/libmpeg2/decode.c
--- g2-orig/video/libmpeg2/decode.c 2003-05-06 00:44:11.000000000 +0200
+++ g2/video/libmpeg2/decode.c 2003-05-25 18:22:30.000000000 +0200
@@ -372,6 +372,11 @@
mpeg2dec->custom_fbuf = custom_fbuf;
}
+void mpeg2_store_quant (mpeg2dec_t * mpeg2dec, int qstore)
+{
+ mpeg2dec->qstore = qstore;
+}
+
void mpeg2_skip (mpeg2dec_t * mpeg2dec, int skip)
{
mpeg2dec->first_decode_slice = 1;
@@ -447,6 +452,9 @@
if (!mpeg2dec->custom_fbuf)
for (i = mpeg2dec->alloc_index_user; i < mpeg2dec->alloc_index; i++)
mpeg2_free (mpeg2dec->fbuf_alloc[i].fbuf.buf[0]);
+ for (i = 0; i < 3; i++)
+ if (mpeg2dec->fbuf_alloc[i].fbuf.qstore)
+ mpeg2_free (mpeg2dec->fbuf_alloc[i].fbuf.qstore);
if (mpeg2dec->convert_start)
for (i = 0; i < 3; i++)
mpeg2_free (mpeg2dec->yuv_buf[i][0]);
Nur in g2/video/libmpeg2: decode.c.orig.
Nur in g2/video/libmpeg2: decode.o.
diff -ur g2-orig/video/libmpeg2/header.c g2/video/libmpeg2/header.c
--- g2-orig/video/libmpeg2/header.c 2003-05-11 15:14:28.000000000 +0200
+++ g2/video/libmpeg2/header.c 2003-05-25 18:22:30.000000000 +0200
@@ -78,6 +78,7 @@
{
mpeg2dec->decoder.scan = mpeg2_scan_norm;
mpeg2dec->picture = mpeg2dec->pictures;
+ memset(mpeg2dec->fbuf_alloc,0, sizeof(fbuf_alloc_t)*3);
mpeg2dec->fbuf[0] = &mpeg2dec->fbuf_alloc[0].fbuf;
mpeg2dec->fbuf[1] = &mpeg2dec->fbuf_alloc[1].fbuf;
mpeg2dec->fbuf[2] = &mpeg2dec->fbuf_alloc[2].fbuf;
@@ -372,6 +373,15 @@
}
break;
}
+
+ if (mpeg2dec->qstore && mpeg2dec->info.current_fbuf)
+ {
+ mpeg2dec->decoder.quant_stride=mpeg2dec->info.sequence->picture_width>>4;
+ if (!mpeg2dec->info.current_fbuf->qstore)
+ mpeg2dec->info.current_fbuf->qstore=mpeg2_malloc(mpeg2dec->decoder.quant_stride*(mpeg2dec->info.sequence->picture_height>>4), ALLOC_QSTORE);
+ if (mpeg2dec->info.current_fbuf->qstore)
+ mpeg2dec->decoder.quant_store=mpeg2dec->info.current_fbuf->qstore;
+ }
}
mpeg2_state_t mpeg2_header_picture_start (mpeg2dec_t * mpeg2dec)
diff -ur g2-orig/video/libmpeg2/mpeg2.h g2/video/libmpeg2/mpeg2.h
--- g2-orig/video/libmpeg2/mpeg2.h 2003-04-26 22:01:10.000000000 +0200
+++ g2/video/libmpeg2/mpeg2.h 2003-05-25 18:22:30.000000000 +0200
@@ -97,6 +97,7 @@
typedef struct {
uint8_t * buf[3];
void * id;
+ uint8_t * qstore;
} mpeg2_fbuf_t;
typedef struct {
diff -ur g2-orig/video/libmpeg2/mpeg2_internal.h g2/video/libmpeg2/mpeg2_internal.h
--- g2-orig/video/libmpeg2/mpeg2_internal.h 2003-03-23 20:06:30.000000000 +0100
+++ g2/video/libmpeg2/mpeg2_internal.h 2003-05-25 18:22:30.000000000 +0200
@@ -135,6 +135,10 @@
int second_field;
int mpeg1;
+
+ /* data for post-processing */
+ char* quant_store;
+ int quant_stride;
};
typedef struct {
@@ -181,6 +185,8 @@
fbuf_alloc_t fbuf_alloc[3];
int custom_fbuf;
+ /* flag to store data for post-processing */
+ int qstore;
uint8_t * yuv_buf[3][3];
int yuv_index;
@@ -213,6 +219,8 @@
#define ALLOC_YUV 2
#define ALLOC_CONVERT_ID 3
#define ALLOC_CONVERTED 4
+#define ALLOC_QSTORE 5
+
void * mpeg2_malloc (int size, int reason);
void mpeg2_free (void * buf);
diff -ur g2-orig/video/libmpeg2/slice.c g2/video/libmpeg2/slice.c
--- g2-orig/video/libmpeg2/slice.c 2003-04-26 22:01:13.000000000 +0200
+++ g2/video/libmpeg2/slice.c 2003-05-25 18:22:30.000000000 +0200
@@ -1432,6 +1432,9 @@
#define NEXT_MACROBLOCK \
do { \
+ if(decoder->quant_store) \
+ 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 */ \
diff -ur g2-orig/video/vd_libmpeg2.c g2/video/vd_libmpeg2.c
--- g2-orig/video/vd_libmpeg2.c 2003-05-11 15:35:34.000000000 +0200
+++ g2/video/vd_libmpeg2.c 2003-05-25 18:34:05.000000000 +0200
@@ -8,7 +8,7 @@
#include "vd_internal.h"
-#undef MPEG12_POSTPROC
+//#undef MPEG12_POSTPROC
#define PTS_SCALE 90000.0
@@ -59,6 +59,9 @@
if(!mpeg2dec) return 0;
mpeg2_custom_fbuf(mpeg2dec,1); // enable DR1
+#ifdef MPEG12_POSTPROC
+ mpeg2_store_quant(mpeg2dec,1); // enable pp
+#endif
sh->context=mpeg2dec;
@@ -163,14 +166,6 @@
if(!mpi) return 0; // VO ERROR!!!!!!!!
mpeg2_set_buf(mpeg2dec, mpi->planes, mpi);
-#ifdef MPEG12_POSTPROC
- if(!mpi->qscale){
- mpi->qstride=info->sequence->picture_width>>4;
- mpi->qscale=malloc(mpi->qstride*(info->sequence->picture_height>>4));
- }
- mpeg2dec->decoder.quant_store=mpi->qscale;
- mpeg2dec->decoder.quant_stride=mpi->qstride;
-#endif
mpi->pict_type=type; // 1->I, 2->P, 3->B
if(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK &&
@@ -191,6 +186,10 @@
if(mpi) printf("AJAJJJJJJJJ2!\n");
if(info->display_fbuf){
mpi=info->display_fbuf->id;
+#ifdef MPEG12_POSTPROC
+ mpi->qscale=info->display_fbuf->qstore;
+ mpi->qstride=info->sequence->picture_width>>4;
+#endif
if(info->display_picture){
if((info->display_picture->flags&PIC_FLAG_PTS)){
// && info->display_picture->pts){