Mercurial > mplayer.hg
annotate libmpcodecs/vd_libmpeg2.c @ 17050:cd540846d052
Add support to get the list of files from a file containing one filename
per line. Patch from devik (devik .at. cdi .dot. cz).
author | albeu |
---|---|
date | Sat, 26 Nov 2005 17:10:17 +0000 |
parents | 6ff3379a0862 |
children | bf150feefe40 |
rev | line source |
---|---|
4998 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 | |
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 | 7 #include "mp_msg.h" |
8 | |
9 #include "vd_internal.h" | |
10 | |
9859 | 11 //#undef MPEG12_POSTPROC |
12 | |
4998 | 13 static vd_info_t info = |
14 { | |
12932 | 15 "MPEG 1/2 Video decoder libmpeg2-v0.4.0b", |
4998 | 16 "libmpeg2", |
9859 | 17 "A'rpi & Fabian Franz", |
4998 | 18 "Aaron & Walken", |
19 "native" | |
20 }; | |
21 | |
22 LIBVD_EXTERN(libmpeg2) | |
23 | |
9859 | 24 //#include "libvo/video_out.h" // FIXME!!! |
5465 | 25 |
4998 | 26 #include "libmpeg2/mpeg2.h" |
12932 | 27 #include "libmpeg2/attributes.h" |
4998 | 28 #include "libmpeg2/mpeg2_internal.h" |
29 | |
17012 | 30 #include "cpudetect.h" |
5465 | 31 |
4998 | 32 // to set/get/query special features/parameters |
33 static int control(sh_video_t *sh,int cmd,void* arg,...){ | |
13995 | 34 mpeg2dec_t * mpeg2dec = sh->context; |
14012 | 35 const mpeg2_info_t * info = mpeg2_info (mpeg2dec); |
13995 | 36 |
37 switch(cmd) { | |
38 case VDCTRL_QUERY_FORMAT: | |
14012 | 39 if (info->sequence->width >> 1 == info->sequence->chroma_width && |
40 info->sequence->height >> 1 == info->sequence->chroma_height && | |
41 (*((int*)arg)) == IMGFMT_YV12) | |
13995 | 42 return CONTROL_TRUE; |
14012 | 43 if (info->sequence->width >> 1 == info->sequence->chroma_width && |
44 info->sequence->height == info->sequence->chroma_height && | |
45 (*((int*)arg)) == IMGFMT_422P) | |
13995 | 46 return CONTROL_TRUE; |
47 return CONTROL_FALSE; | |
48 } | |
49 | |
4998 | 50 return CONTROL_UNKNOWN; |
51 } | |
52 | |
53 // init driver | |
54 static int init(sh_video_t *sh){ | |
9859 | 55 mpeg2dec_t * mpeg2dec; |
13995 | 56 // const mpeg2_info_t * info; |
9859 | 57 int accel; |
5465 | 58 |
9859 | 59 accel = 0; |
60 if(gCpuCaps.hasMMX) | |
61 accel |= MPEG2_ACCEL_X86_MMX; | |
62 if(gCpuCaps.hasMMX2) | |
63 accel |= MPEG2_ACCEL_X86_MMXEXT; | |
64 if(gCpuCaps.has3DNow) | |
65 accel |= MPEG2_ACCEL_X86_3DNOW; | |
10267
d953763cc555
libmpeg2-altivec patch by Magnus Damm <damm@opensource.se>:
arpi
parents:
10250
diff
changeset
|
66 if(gCpuCaps.hasAltiVec) |
d953763cc555
libmpeg2-altivec patch by Magnus Damm <damm@opensource.se>:
arpi
parents:
10250
diff
changeset
|
67 accel |= MPEG2_ACCEL_PPC_ALTIVEC; |
13117 | 68 #ifdef HAVE_VIS |
69 accel |= MPEG2_ACCEL_SPARC_VIS; | |
9859 | 70 #endif |
71 mpeg2_accel(accel); | |
5465 | 72 |
9859 | 73 mpeg2dec = mpeg2_init (); |
74 | |
75 if(!mpeg2dec) return 0; | |
76 | |
77 mpeg2_custom_fbuf(mpeg2dec,1); // enable DR1 | |
5675
0ff1b9ab7afc
slices+field pictures fixed, initial sig11 workaround
arpi
parents:
5613
diff
changeset
|
78 |
9859 | 79 sh->context=mpeg2dec; |
80 | |
13112 | 81 mpeg2dec->pending_buffer = 0; |
82 mpeg2dec->pending_length = 0; | |
83 | |
9859 | 84 return 1; |
4998 | 85 } |
86 | |
87 // uninit driver | |
88 static void uninit(sh_video_t *sh){ | |
9859 | 89 mpeg2dec_t * mpeg2dec = sh->context; |
13112 | 90 if (mpeg2dec->pending_buffer) free(mpeg2dec->pending_buffer); |
14012 | 91 mpeg2dec->decoder.convert=NULL; |
92 mpeg2dec->decoder.convert_id=NULL; | |
9859 | 93 mpeg2_close (mpeg2dec); |
4998 | 94 } |
95 | |
13112 | 96 static void draw_slice (void * _sh, uint8_t * const * src, unsigned int y){ |
9859 | 97 sh_video_t* sh = (sh_video_t*) _sh; |
98 mpeg2dec_t* mpeg2dec = sh->context; | |
99 const mpeg2_info_t * info = mpeg2_info (mpeg2dec); | |
100 int stride[3]; | |
5465 | 101 |
13112 | 102 // printf("draw_slice() y=%d \n",y); |
5465 | 103 |
9859 | 104 stride[0]=mpeg2dec->decoder.stride; |
105 stride[1]=stride[2]=mpeg2dec->decoder.uv_stride; | |
5465 | 106 |
9859 | 107 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
|
108 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
|
109 (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
|
110 info->sequence->picture_height-y, |
9859 | 111 0, y); |
4998 | 112 } |
113 | |
5465 | 114 // decode a frame |
115 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ | |
9859 | 116 mpeg2dec_t * mpeg2dec = sh->context; |
117 const mpeg2_info_t * info = mpeg2_info (mpeg2dec); | |
118 int drop_frame, framedrop=flags&3; | |
119 | |
13995 | 120 // MPlayer registers its own draw_slice callback, prevent libmpeg2 from freeing the context |
14012 | 121 mpeg2dec->decoder.convert=NULL; |
122 mpeg2dec->decoder.convert_id=NULL; | |
13150 | 123 |
11080
26f1b3ad4a77
skip null frames in mpeg files, patch by Zoltan Hidvegi <mplayer@hzoli.2y.net>
attila
parents:
10663
diff
changeset
|
124 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
|
125 |
9859 | 126 // append extra 'end of frame' code: |
127 ((char*)data+len)[0]=0; | |
128 ((char*)data+len)[1]=0; | |
129 ((char*)data+len)[2]=1; | |
130 ((char*)data+len)[3]=0xff; | |
131 len+=4; | |
5465 | 132 |
13112 | 133 if (mpeg2dec->pending_length) { |
134 mpeg2_buffer (mpeg2dec, mpeg2dec->pending_buffer, mpeg2dec->pending_buffer + mpeg2dec->pending_length); | |
135 } else { | |
136 mpeg2_buffer (mpeg2dec, data, data+len); | |
137 } | |
9859 | 138 |
139 while(1){ | |
140 int state=mpeg2_parse (mpeg2dec); | |
13995 | 141 int type, use_callback; |
142 mp_image_t* mpi_new; | |
143 | |
9859 | 144 switch(state){ |
12932 | 145 case STATE_BUFFER: |
13112 | 146 if (mpeg2dec->pending_length) { |
13152 | 147 // just finished the pending data, continue with processing of the passed buffer |
13112 | 148 mpeg2dec->pending_length = 0; |
149 mpeg2_buffer (mpeg2dec, data, data+len); | |
150 } else { | |
151 // parsing of the passed buffer finished, return. | |
152 return 0; | |
153 } | |
154 break; | |
9859 | 155 case STATE_SEQUENCE: |
156 // video parameters inited/changed, (re)init libvo: | |
13995 | 157 if (info->sequence->width >> 1 == info->sequence->chroma_width && |
158 info->sequence->height >> 1 == info->sequence->chroma_height) { | |
159 if(!mpcodecs_config_vo(sh, | |
14016 | 160 info->sequence->picture_width, |
161 info->sequence->picture_height, IMGFMT_YV12)) return 0; | |
13995 | 162 } else if (info->sequence->width >> 1 == info->sequence->chroma_width && |
163 info->sequence->height == info->sequence->chroma_height) { | |
164 if(!mpcodecs_config_vo(sh, | |
14016 | 165 info->sequence->picture_width, |
166 info->sequence->picture_height, IMGFMT_422P)) return 0; | |
13995 | 167 } else return 0; |
9859 | 168 break; |
13995 | 169 case STATE_PICTURE: |
170 type=info->current_picture->flags&PIC_MASK_CODING_TYPE; | |
9859 | 171 |
172 drop_frame = framedrop && (mpeg2dec->decoder.coding_type == B_TYPE); | |
173 drop_frame |= framedrop>=2; // hard drop | |
174 if (drop_frame) { | |
175 mpeg2_skip(mpeg2dec, 1); | |
176 //printf("Dropping Frame ...\n"); | |
177 break; | |
178 } | |
179 mpeg2_skip(mpeg2dec, 0); //mpeg2skip skips frames until set again to 0 | |
180 | |
14012 | 181 use_callback = (!framedrop && vd_use_slices && |
182 (info->current_picture->flags&PIC_FLAG_PROGRESSIVE_FRAME)) ? | |
183 MP_IMGFLAG_DRAW_CALLBACK:0; | |
13995 | 184 |
9859 | 185 // get_buffer "callback": |
13995 | 186 mpi_new=mpcodecs_get_image(sh,MP_IMGTYPE_IPB, |
14012 | 187 (type==PIC_FLAG_CODING_TYPE_B) ? |
188 use_callback : (MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE), | |
14075 | 189 info->sequence->width, |
190 info->sequence->height); | |
13995 | 191 |
13112 | 192 if(!mpi_new) return 0; // VO ERROR!!!!!!!! |
193 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
|
194 if (info->current_picture->flags&PIC_FLAG_TOP_FIELD_FIRST) |
13112 | 195 mpi_new->fields |= MP_IMGFIELD_TOP_FIRST; |
196 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
|
197 if (info->current_picture->flags&PIC_FLAG_REPEAT_FIRST_FIELD) |
13112 | 198 mpi_new->fields |= MP_IMGFIELD_REPEAT_FIRST; |
199 else mpi_new->fields &= ~MP_IMGFIELD_REPEAT_FIRST; | |
200 mpi_new->fields |= MP_IMGFIELD_ORDERED; | |
9859 | 201 |
12935 | 202 #ifdef MPEG12_POSTPROC |
13112 | 203 if(!mpi_new->qscale){ |
14016 | 204 mpi_new->qstride=info->sequence->width>>4; |
205 mpi_new->qscale=malloc(mpi_new->qstride*(info->sequence->height>>4)); | |
12935 | 206 } |
13112 | 207 mpeg2dec->decoder.quant_store=mpi_new->qscale; |
208 mpeg2dec->decoder.quant_stride=mpi_new->qstride; | |
209 mpi_new->pict_type=type; // 1->I, 2->P, 3->B | |
210 mpi_new->qscale_type= 1; | |
12935 | 211 #endif |
212 | |
14012 | 213 if (mpi_new->flags&MP_IMGFLAG_DRAW_CALLBACK |
214 && !(mpi_new->flags&MP_IMGFLAG_DIRECT)) { | |
215 // nice, filter/vo likes draw_callback :) | |
216 mpeg2dec->decoder.convert=draw_slice; | |
217 mpeg2dec->decoder.convert_id=sh; | |
218 } else { | |
219 mpeg2dec->decoder.convert=NULL; | |
220 mpeg2dec->decoder.convert_id=NULL; | |
13995 | 221 } |
222 | |
9859 | 223 break; |
224 case STATE_SLICE: | |
225 case STATE_END: | |
12932 | 226 case STATE_INVALID_END: |
9859 | 227 // decoding done: |
13112 | 228 if(info->display_fbuf) { |
13152 | 229 mp_image_t* mpi = info->display_fbuf->id; |
230 if (mpeg2dec->pending_length == 0) { | |
13995 | 231 mpeg2dec->pending_length = mpeg2dec->buf_end - mpeg2dec->buf_start; |
232 mpeg2dec->pending_buffer = realloc(mpeg2dec->pending_buffer, mpeg2dec->pending_length); | |
233 memcpy(mpeg2dec->pending_buffer, mpeg2dec->buf_start, mpeg2dec->pending_length); | |
13152 | 234 } else { |
235 // still some data in the pending buffer, shouldn't happen | |
236 mpeg2dec->pending_length = mpeg2dec->buf_end - mpeg2dec->buf_start; | |
237 memmove(mpeg2dec->pending_buffer, mpeg2dec->buf_start, mpeg2dec->pending_length); | |
238 mpeg2dec->pending_buffer = realloc(mpeg2dec->pending_buffer, mpeg2dec->pending_length + len); | |
239 memcpy(mpeg2dec->pending_buffer+mpeg2dec->pending_length, data, len); | |
240 mpeg2dec->pending_length += len; | |
241 } | |
242 // fprintf(stderr, "pending = %d\n", mpeg2dec->pending_length); | |
13112 | 243 return mpi; |
244 } | |
7957
31fd09cc9ba2
passing picture_type (might be usefull for postprocessing)
michael
parents:
7756
diff
changeset
|
245 } |
31fd09cc9ba2
passing picture_type (might be usefull for postprocessing)
michael
parents:
7756
diff
changeset
|
246 } |
5465 | 247 } |
8026
b465ba5897a3
usage of libmpeg2, liba52, mp3lib & svq1 can be disabled
arpi
parents:
7957
diff
changeset
|
248 #endif |