annotate libmpcodecs/vd_libmpeg2.c @ 13308:8ff17d153414

info packet is now file global, while meta pakcet is stream specific, as discussed with Rich
author alex
date Sat, 11 Sep 2004 09:18:07 +0000
parents e264e6d6eb76
children cbadd7b190b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4998
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
1 #include <stdio.h>
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
2 #include <stdlib.h>
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
3
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
4 #include "config.h"
8026
b465ba5897a3 usage of libmpeg2, liba52, mp3lib & svq1 can be disabled
arpi
parents: 7957
diff changeset
5 #ifdef USE_LIBMPEG2
b465ba5897a3 usage of libmpeg2, liba52, mp3lib & svq1 can be disabled
arpi
parents: 7957
diff changeset
6
4998
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
7 #include "mp_msg.h"
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
8
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
9 #include "vd_internal.h"
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
10
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
11 //#undef MPEG12_POSTPROC
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
12
4998
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
13 static vd_info_t info =
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
14 {
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 12572
diff changeset
15 "MPEG 1/2 Video decoder libmpeg2-v0.4.0b",
4998
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
16 "libmpeg2",
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
17 "A'rpi & Fabian Franz",
4998
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
18 "Aaron & Walken",
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
19 "native"
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
20 };
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
21
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
22 LIBVD_EXTERN(libmpeg2)
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
23
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
24 //#include "libvo/video_out.h" // FIXME!!!
5465
1f9c8301a7f2 rewritten - it replaces libmpeg2/decode.c now
arpi
parents: 5360
diff changeset
25
4998
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
26 #include "libmpeg2/mpeg2.h"
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 12572
diff changeset
27 #include "libmpeg2/attributes.h"
4998
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
28 #include "libmpeg2/mpeg2_internal.h"
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
29 //#include "libmpeg2/convert.h"
4998
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
30
5465
1f9c8301a7f2 rewritten - it replaces libmpeg2/decode.c now
arpi
parents: 5360
diff changeset
31 #include "../cpudetect.h"
1f9c8301a7f2 rewritten - it replaces libmpeg2/decode.c now
arpi
parents: 5360
diff changeset
32
4998
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
33 // to set/get/query special features/parameters
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
34 static int control(sh_video_t *sh,int cmd,void* arg,...){
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
35 return CONTROL_UNKNOWN;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
36 }
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
37
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
38 // init driver
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
39 static int init(sh_video_t *sh){
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
40 mpeg2dec_t * mpeg2dec;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
41 const mpeg2_info_t * info;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
42 int accel;
5465
1f9c8301a7f2 rewritten - it replaces libmpeg2/decode.c now
arpi
parents: 5360
diff changeset
43
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
44 accel = 0;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
45 if(gCpuCaps.hasMMX)
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
46 accel |= MPEG2_ACCEL_X86_MMX;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
47 if(gCpuCaps.hasMMX2)
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
48 accel |= MPEG2_ACCEL_X86_MMXEXT;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
49 if(gCpuCaps.has3DNow)
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
50 accel |= MPEG2_ACCEL_X86_3DNOW;
10267
d953763cc555 libmpeg2-altivec patch by Magnus Damm <damm@opensource.se>:
arpi
parents: 10250
diff changeset
51 if(gCpuCaps.hasAltiVec)
d953763cc555 libmpeg2-altivec patch by Magnus Damm <damm@opensource.se>:
arpi
parents: 10250
diff changeset
52 accel |= MPEG2_ACCEL_PPC_ALTIVEC;
13117
9bba611637fb actually use the acceleration on SPARC
henry
parents: 13112
diff changeset
53 #ifdef HAVE_VIS
9bba611637fb actually use the acceleration on SPARC
henry
parents: 13112
diff changeset
54 accel |= MPEG2_ACCEL_SPARC_VIS;
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
55 #endif
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
56 mpeg2_accel(accel);
5465
1f9c8301a7f2 rewritten - it replaces libmpeg2/decode.c now
arpi
parents: 5360
diff changeset
57
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
58 mpeg2dec = mpeg2_init ();
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
59
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
60 if(!mpeg2dec) return 0;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
61
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
62 mpeg2_custom_fbuf(mpeg2dec,1); // enable DR1
5675
0ff1b9ab7afc slices+field pictures fixed, initial sig11 workaround
arpi
parents: 5613
diff changeset
63
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
64 sh->context=mpeg2dec;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
65
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
66 mpeg2dec->pending_buffer = 0;
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
67 mpeg2dec->pending_length = 0;
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
68
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
69 return 1;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
70 //return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12);
4998
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
71 }
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
72
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
73 // uninit driver
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
74 static void uninit(sh_video_t *sh){
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
75 mpeg2dec_t * mpeg2dec = sh->context;
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
76 if (mpeg2dec->pending_buffer) free(mpeg2dec->pending_buffer);
13139
653df8deffc7 prevent libmpeg2 from freeing sh
faust3
parents: 13117
diff changeset
77 mpeg2dec->decoder.convert_id=NULL;
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
78 mpeg2_close (mpeg2dec);
4998
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
79 }
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
80
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
81 static void draw_slice (void * _sh, uint8_t * const * src, unsigned int y){
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
82 sh_video_t* sh = (sh_video_t*) _sh;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
83 mpeg2dec_t* mpeg2dec = sh->context;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
84 const mpeg2_info_t * info = mpeg2_info (mpeg2dec);
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
85 int stride[3];
5465
1f9c8301a7f2 rewritten - it replaces libmpeg2/decode.c now
arpi
parents: 5360
diff changeset
86
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
87 // printf("draw_slice() y=%d \n",y);
5465
1f9c8301a7f2 rewritten - it replaces libmpeg2/decode.c now
arpi
parents: 5360
diff changeset
88
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
89 stride[0]=mpeg2dec->decoder.stride;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
90 stride[1]=stride[2]=mpeg2dec->decoder.uv_stride;
5465
1f9c8301a7f2 rewritten - it replaces libmpeg2/decode.c now
arpi
parents: 5360
diff changeset
91
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
92 mpcodecs_draw_slice(sh, (uint8_t **)src,
12572
7d681d8ebab8 display height may be a lot smaller or larger than picture height, sample provided by winnicki
iive
parents: 11080
diff changeset
93 stride, info->sequence->picture_width,
7d681d8ebab8 display height may be a lot smaller or larger than picture height, sample provided by winnicki
iive
parents: 11080
diff changeset
94 (y+16<=info->sequence->picture_height) ? 16 :
7d681d8ebab8 display height may be a lot smaller or larger than picture height, sample provided by winnicki
iive
parents: 11080
diff changeset
95 info->sequence->picture_height-y,
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
96 0, y);
4998
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
97 }
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
98
5465
1f9c8301a7f2 rewritten - it replaces libmpeg2/decode.c now
arpi
parents: 5360
diff changeset
99 // decode a frame
1f9c8301a7f2 rewritten - it replaces libmpeg2/decode.c now
arpi
parents: 5360
diff changeset
100 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
101 mpeg2dec_t * mpeg2dec = sh->context;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
102 const mpeg2_info_t * info = mpeg2_info (mpeg2dec);
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
103 int drop_frame, framedrop=flags&3;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
104
13150
a7542243d695 some more segfault fixes
faust3
parents: 13139
diff changeset
105 //MPlayer registers its own draw_slice callback, prevent libmpeg2 from freeing the context
a7542243d695 some more segfault fixes
faust3
parents: 13139
diff changeset
106 mpeg2dec->decoder.convert=NULL;
a7542243d695 some more segfault fixes
faust3
parents: 13139
diff changeset
107 mpeg2dec->decoder.convert_id=NULL;
a7542243d695 some more segfault fixes
faust3
parents: 13139
diff changeset
108
a7542243d695 some more segfault fixes
faust3
parents: 13139
diff changeset
109
11080
26f1b3ad4a77 skip null frames in mpeg files, patch by Zoltan Hidvegi <mplayer@hzoli.2y.net>
attila
parents: 10663
diff changeset
110 if(len<=0) return NULL; // skipped null frame
26f1b3ad4a77 skip null frames in mpeg files, patch by Zoltan Hidvegi <mplayer@hzoli.2y.net>
attila
parents: 10663
diff changeset
111
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
112 // append extra 'end of frame' code:
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
113 ((char*)data+len)[0]=0;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
114 ((char*)data+len)[1]=0;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
115 ((char*)data+len)[2]=1;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
116 ((char*)data+len)[3]=0xff;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
117 len+=4;
5465
1f9c8301a7f2 rewritten - it replaces libmpeg2/decode.c now
arpi
parents: 5360
diff changeset
118
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
119 if (mpeg2dec->pending_length) {
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
120 mpeg2_buffer (mpeg2dec, mpeg2dec->pending_buffer, mpeg2dec->pending_buffer + mpeg2dec->pending_length);
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
121 } else {
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
122 mpeg2_buffer (mpeg2dec, data, data+len);
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
123 }
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
124
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
125 while(1){
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
126 int state=mpeg2_parse (mpeg2dec);
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
127 switch(state){
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 12572
diff changeset
128 case STATE_BUFFER:
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
129 if (mpeg2dec->pending_length) {
13152
e264e6d6eb76 clenups
henry
parents: 13150
diff changeset
130 // just finished the pending data, continue with processing of the passed buffer
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
131 mpeg2dec->pending_length = 0;
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
132 mpeg2_buffer (mpeg2dec, data, data+len);
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
133 } else {
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
134 // parsing of the passed buffer finished, return.
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
135 return 0;
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
136 }
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
137 break;
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
138 case STATE_SEQUENCE:
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
139 // video parameters inited/changed, (re)init libvo:
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
140 if(!mpcodecs_config_vo(sh,
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
141 info->sequence->width,
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
142 info->sequence->height, IMGFMT_YV12)) return 0;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
143 break;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
144 case STATE_PICTURE: {
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
145 int type=info->current_picture->flags&PIC_MASK_CODING_TYPE;
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
146 mp_image_t* mpi_new;
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
147
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
148 drop_frame = framedrop && (mpeg2dec->decoder.coding_type == B_TYPE);
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
149 drop_frame |= framedrop>=2; // hard drop
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
150 if (drop_frame) {
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
151 mpeg2_skip(mpeg2dec, 1);
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
152 //printf("Dropping Frame ...\n");
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
153 break;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
154 }
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
155 mpeg2_skip(mpeg2dec, 0); //mpeg2skip skips frames until set again to 0
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
156
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
157 // get_buffer "callback":
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
158 mpi_new=mpcodecs_get_image(sh,MP_IMGTYPE_IPB,
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
159 (type==PIC_FLAG_CODING_TYPE_B)
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
160 ? ((!framedrop && vd_use_slices &&
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
161 (info->current_picture->flags&PIC_FLAG_PROGRESSIVE_FRAME)) ?
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
162 MP_IMGFLAG_DRAW_CALLBACK:0)
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
163 : (MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE),
10250
2bf4914e2253 fixed mem corruption bugs
arpi
parents: 9938
diff changeset
164 (info->sequence->picture_width+15)&(~15),
2bf4914e2253 fixed mem corruption bugs
arpi
parents: 9938
diff changeset
165 (info->sequence->picture_height+15)&(~15) );
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
166 if(!mpi_new) return 0; // VO ERROR!!!!!!!!
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
167 mpeg2_set_buf(mpeg2dec, mpi_new->planes, mpi_new);
10510
73b3e4336cd4 Add mpeg2_flags to mp_image_t, copy flags in vd_libmpeg2.c,
ranma
parents: 10267
diff changeset
168 if (info->current_picture->flags&PIC_FLAG_TOP_FIELD_FIRST)
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
169 mpi_new->fields |= MP_IMGFIELD_TOP_FIRST;
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
170 else mpi_new->fields &= ~MP_IMGFIELD_TOP_FIRST;
10510
73b3e4336cd4 Add mpeg2_flags to mp_image_t, copy flags in vd_libmpeg2.c,
ranma
parents: 10267
diff changeset
171 if (info->current_picture->flags&PIC_FLAG_REPEAT_FIRST_FIELD)
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
172 mpi_new->fields |= MP_IMGFIELD_REPEAT_FIRST;
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
173 else mpi_new->fields &= ~MP_IMGFIELD_REPEAT_FIRST;
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
174 mpi_new->fields |= MP_IMGFIELD_ORDERED;
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
175
12935
cda4ad0d3e70 forgotten libmpeg2 postprocessing
henry
parents: 12932
diff changeset
176 #ifdef MPEG12_POSTPROC
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
177 if(!mpi_new->qscale){
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
178 mpi_new->qstride=(info->sequence->picture_width+15)>>4;
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
179 mpi_new->qscale=malloc(mpi_new->qstride*((info->sequence->picture_height+15)>>4));
12935
cda4ad0d3e70 forgotten libmpeg2 postprocessing
henry
parents: 12932
diff changeset
180 }
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
181 mpeg2dec->decoder.quant_store=mpi_new->qscale;
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
182 mpeg2dec->decoder.quant_stride=mpi_new->qstride;
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
183 mpi_new->pict_type=type; // 1->I, 2->P, 3->B
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
184 mpi_new->qscale_type= 1;
12935
cda4ad0d3e70 forgotten libmpeg2 postprocessing
henry
parents: 12932
diff changeset
185 #endif
cda4ad0d3e70 forgotten libmpeg2 postprocessing
henry
parents: 12932
diff changeset
186
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
187 if(mpi_new->flags&MP_IMGFLAG_DRAW_CALLBACK &&
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
188 !(mpi_new->flags&MP_IMGFLAG_DIRECT)){
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
189 // nice, filter/vo likes draw_callback :)
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
190 mpeg2dec->decoder.convert=draw_slice;
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 12572
diff changeset
191 mpeg2dec->decoder.convert_id=sh;
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
192 } else
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
193 mpeg2dec->decoder.convert=NULL;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
194 break;
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
195 }
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
196 case STATE_SLICE:
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
197 case STATE_END:
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 12572
diff changeset
198 case STATE_INVALID_END:
9859
16a7d1f4da38 Rewritten, to use new libmpeg2 0.3.1 API
arpi
parents: 8026
diff changeset
199 // decoding done:
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
200 if(info->display_fbuf) {
13152
e264e6d6eb76 clenups
henry
parents: 13150
diff changeset
201 mp_image_t* mpi = info->display_fbuf->id;
e264e6d6eb76 clenups
henry
parents: 13150
diff changeset
202 if (mpeg2dec->pending_length == 0) {
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
203 mpeg2dec->pending_length = mpeg2dec->buf_end - mpeg2dec->buf_start;
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
204 mpeg2dec->pending_buffer = realloc(mpeg2dec->pending_buffer, mpeg2dec->pending_length);
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
205 memcpy(mpeg2dec->pending_buffer, mpeg2dec->buf_start, mpeg2dec->pending_length);
13152
e264e6d6eb76 clenups
henry
parents: 13150
diff changeset
206 } else {
e264e6d6eb76 clenups
henry
parents: 13150
diff changeset
207 // still some data in the pending buffer, shouldn't happen
e264e6d6eb76 clenups
henry
parents: 13150
diff changeset
208 mpeg2dec->pending_length = mpeg2dec->buf_end - mpeg2dec->buf_start;
e264e6d6eb76 clenups
henry
parents: 13150
diff changeset
209 memmove(mpeg2dec->pending_buffer, mpeg2dec->buf_start, mpeg2dec->pending_length);
e264e6d6eb76 clenups
henry
parents: 13150
diff changeset
210 mpeg2dec->pending_buffer = realloc(mpeg2dec->pending_buffer, mpeg2dec->pending_length + len);
e264e6d6eb76 clenups
henry
parents: 13150
diff changeset
211 memcpy(mpeg2dec->pending_buffer+mpeg2dec->pending_length, data, len);
e264e6d6eb76 clenups
henry
parents: 13150
diff changeset
212 mpeg2dec->pending_length += len;
e264e6d6eb76 clenups
henry
parents: 13150
diff changeset
213 }
e264e6d6eb76 clenups
henry
parents: 13150
diff changeset
214 // fprintf(stderr, "pending = %d\n", mpeg2dec->pending_length);
13112
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
215 return mpi;
3e4bea88c1c1 libmpeg2 B-frame fix
henry
parents: 12935
diff changeset
216 }
7957
31fd09cc9ba2 passing picture_type (might be usefull for postprocessing)
michael
parents: 7756
diff changeset
217 }
31fd09cc9ba2 passing picture_type (might be usefull for postprocessing)
michael
parents: 7756
diff changeset
218 }
5465
1f9c8301a7f2 rewritten - it replaces libmpeg2/decode.c now
arpi
parents: 5360
diff changeset
219 }
8026
b465ba5897a3 usage of libmpeg2, liba52, mp3lib & svq1 can be disabled
arpi
parents: 7957
diff changeset
220 #endif