58
58
#include "ADM_toolkit/ADM_debug.h"
61
extern void mpeg2_pop(mpeg2dec_t *m);
62
extern void mpeg2_popI(mpeg2dec_t *m);
63
static vo_instance_t *yv12_open (void);
64
static void yv12_close (vo_instance_t * _instance);
65
static int yv12_setup (vo_instance_t * _instance, unsigned int width,
66
unsigned int height,unsigned int chroma_w,
67
unsigned int chroma_h,vo_setup_result_t *result);
68
static void yv12_setup_fbuf (vo_instance_t * _instance, uint8_t ** buf, void ** id);
69
extern int mpeg2_cleanup(mpeg2dec_t * mpeg2dec);
61
extern void mpeg2_pop (mpeg2dec_t * m);
62
extern void mpeg2_popI (mpeg2dec_t * m);
63
static vo_instance_t *yv12_open (void);
64
static void yv12_close (vo_instance_t * _instance);
65
static int yv12_setup (vo_instance_t * _instance, unsigned int width,
66
unsigned int height, unsigned int chroma_w,
67
unsigned int chroma_h, vo_setup_result_t * result);
68
static void yv12_setup_fbuf (vo_instance_t * _instance, uint8_t ** buf,
70
extern int mpeg2_cleanup (mpeg2dec_t * mpeg2dec);
72
73
//static uint8_t *zero=NULL;
74
decoderMpeg *_father=NULL;
75
static vo_instance_t *output;
75
decoderMpeg *_father = NULL;
76
static vo_instance_t *output;
76
77
// avoid exporting our stuff...
77
78
typedef struct yv12_instance_s
85
86
static uint8_t *iBuff[3];
86
87
static uint8_t *oBuff[3];
87
static int strideTab[3],strideTab2[3];
88
static int strideTab[3], strideTab2[3];
89
90
decoderMpeg::~decoderMpeg ()
91
92
#warning clean up libmpeg2 here
93
delete [] unpackBuffer;
95
96
//____________________________________
96
uint8_t decoderMpeg::isMpeg1( void)
97
uint8_t decoderMpeg::isMpeg1 (void)
99
dec=&((MPEG2DEC)->decoder);
101
dec = &((MPEG2DEC)->decoder);
102
104
//____________________-un init ____________________
103
105
uint8_t decoderMpeg::kill_codec (void)
105
mpeg2_decoder_t *dec;
106
dec=&((MPEG2DEC)->decoder);
110
ADM_dealloc(dec->quant);
109
dec = &((MPEG2DEC)->decoder);
113
ADM_dealloc (dec->quant);
113
116
mpeg2_close (MPEG2DEC);
119
122
//________________________________________________
120
void decoderMpeg::setParam( void )
124
decoderMpeg::setParam (void)
127
131
______________________________________________________________________________________
128
132
Constructor for mpeg decoder
129
133
______________________________________________________________________________________
131
decoderMpeg::decoderMpeg(uint32_t w,uint32_t h,uint32_t extraLen, uint8_t *extraData)
135
decoderMpeg::decoderMpeg (uint32_t w, uint32_t h, uint32_t extraLen, uint8_t * extraData):decoders (w,
134
mpeg2_decoder_t *dec;
136
yv12_instance_t *inst;
140
_seqHeader=new uint8_t [extraLen];
141
memcpy(_seqHeader,extraData,extraLen);
147
// store for future use
151
printf ("\n initializing mpeg2 decoder %lu x %lu\n",_w,_h);
152
output =yv12_open ();
153
inst=(yv12_instance_t *)output;
154
unpackBuffer=new uint8_t [(w*h*9)>>1];
155
inst->buffer=unpackBuffer;
156
_decoder=mpeg2_init();
157
dec=&((MPEG2DEC)->decoder);
160
dec->quant_stride=wmb;
161
dec->quant=(int8_t*)ADM_alloc( (wmb*hmb)*sizeof(int8_t));
163
feedData(extraLen,_seqHeader);
164
feedData(extraLen,_seqHeader);
166
// Post processing settings
167
//___________________________
170
// Post Proc is disabled by default
172
printf ("\n done\n");
146
_seqHeader = new uint8_t[extraLen];
147
memcpy (_seqHeader, extraData, extraLen);
153
// store for future use
155
par_width=par_height=1;
156
postprocessed = NULL;
158
printf ("\n initializing mpeg2 decoder %lu x %lu\n", _w, _h);
159
output = yv12_open ();
160
inst = (yv12_instance_t *) output;
161
unpackBuffer = new uint8_t[(w * h * 9) >> 1];
162
inst->buffer = unpackBuffer;
163
_decoder = mpeg2_init ();
164
dec = &((MPEG2DEC)->decoder);
165
wmb = (_w + 15) >> 4;;
166
hmb = (_h + 15) >> 4;;
167
dec->quant_stride = wmb;
168
dec->quant = (int8_t *) ADM_alloc ((wmb * hmb) * sizeof (int8_t));
170
feedData (extraLen, _seqHeader);
171
feedData (extraLen, _seqHeader);
173
// Post processing settings
174
//___________________________
177
// Post Proc is disabled by default
179
printf ("\n done\n");
175
182
/*------------------------------------------------------------------*/
176
uint8_t decoderMpeg::uncompress(uint8_t *in,ADMImage *out,uint32_t len,uint32_t *flag)
184
decoderMpeg::uncompress (uint8_t * in, ADMImage * out, uint32_t len,
179
189
#if defined( REMOVE_PADDING)
180
while(*(in+len-1)==0) len--;
190
const mpeg2_info_t *info ;
193
t=(uint8_t *) MPEG2DEC->fbuf[0]->buf[0];
194
mpeg2_cleanup(MPEG2DEC);
195
info= mpeg2_info (MPEG2DEC);
196
out->_noPicture=0; // For mpeg1/2 we ALWAYS have a picture
197
if(out->quant && MPEG2DEC->decoder.quant_stride>=out->_qStride)
203
out->_qSize=((_w+15)>>4)*((_h+15)>>4);
204
out->_qStride=(_w+15)>>4;
205
out->quant=(uint8_t *)MPEG2DEC->decoder.quant;
208
memcpy(out->quant,MPEG2DEC->decoder.quant,out->_qSize);
213
uint32_t plane=_w*_h;
216
out->_planes[1]=t+plane;
217
out->_planes[2]=t+((plane*5)>>2);
218
out->_planeStride[0]=_w;
219
out->_planeStride[1]=_w>>1;
220
out->_planeStride[2]=_w>>1;
224
memcpy(out->data,t,(_w*_h*3)>>1);
227
switch(MPEG2DEC->decoder.coding_type)
229
case I_TYPE:out->flags=AVI_KEY_FRAME;break;
230
case B_TYPE:out->flags=AVI_B_FRAME;break;
231
case P_TYPE:out->flags=0;break;
233
printf("\n unknown frame type ! %d\n",MPEG2DEC->decoder.coding_type);
242
if(MPEG2DEC->ext_state & PIC_FLAG_PROGRESSIVE_FRAME)
244
aprintf("Progressive\n");
248
void decoderMpeg::feedData(uint32_t len, uint8_t *data)
250
decode_mpeg2(data,data+len);
253
void decoderMpeg::setFather( decoderMpeg *f)
190
while (*(in + len - 1) == 0)
201
const mpeg2_info_t *info;
204
t = (uint8_t *) MPEG2DEC->fbuf[0]->buf[0];
205
mpeg2_cleanup (MPEG2DEC);
206
info = mpeg2_info (MPEG2DEC);
208
if (info->sequence) {
209
par_width = info->sequence->pixel_width;
210
par_height = info->sequence->pixel_height;
213
aprintf("Mpeg %u * %u\n",par_width,par_height);
214
out->_noPicture = 0; // For mpeg1/2 we ALWAYS have a picture
215
if (out->quant && MPEG2DEC->decoder.quant_stride >= out->_qStride)
221
out->_qSize = ((_w + 15) >> 4) * ((_h + 15) >> 4);
222
out->_qStride = (_w + 15) >> 4;
223
out->quant = (uint8_t *) MPEG2DEC->decoder.quant;
226
memcpy (out->quant, MPEG2DEC->decoder.quant, out->_qSize);
231
uint32_t plane = _w * _h;
234
out->_planes[1] = t + plane;
235
out->_planes[2] = t + ((plane * 5) >> 2);
236
out->_planeStride[0] = _w;
237
out->_planeStride[1] = _w >> 1;
238
out->_planeStride[2] = _w >> 1;
242
memcpy (out->data, t, (_w * _h * 3) >> 1);
245
switch (MPEG2DEC->decoder.coding_type)
248
out->flags = AVI_KEY_FRAME;
251
out->flags = AVI_B_FRAME;
257
printf ("\n unknown frame type ! %d\n", MPEG2DEC->decoder.coding_type);
266
if (MPEG2DEC->ext_state & PIC_FLAG_PROGRESSIVE_FRAME)
268
aprintf ("Progressive\n");
273
decoderMpeg::feedData (uint32_t len, uint8_t * data)
275
decode_mpeg2 (data, data + len);
279
decoderMpeg::setFather (decoderMpeg * f)
260
286
decode_mpeg2: Just a copy/paste from mpeg2dec
263
void decoderMpeg::decode_mpeg2 (uint8_t * current, uint8_t * end)
290
decoderMpeg::decode_mpeg2 (uint8_t * current, uint8_t * end)
265
const mpeg2_info_t * info;
269
mpeg2_buffer (MPEG2DEC, current, end);
271
info = mpeg2_info (MPEG2DEC);
274
state = mpeg2_parse (MPEG2DEC);
275
aprintf("Mpeg2dec : %d \n",state);
292
const mpeg2_info_t *info;
296
mpeg2_buffer (MPEG2DEC, current, end);
298
info = mpeg2_info (MPEG2DEC);
302
state = mpeg2_parse (MPEG2DEC);
303
aprintf ("Mpeg2dec : %d \n", state);
277
306
case STATE_BUFFER:
281
aprintf("Mpeg2dec: Running empty...\n");
310
aprintf ("Mpeg2dec: Running empty...\n");
286
printf("Not ready \n");
315
printf ("Not ready \n");
288
317
case STATE_SEQUENCE:
289
/* might set nb fbuf, convert format, stride */
290
/* might set fbufs */
291
printf("\n Seq found\n");
293
vo_setup_result_t res;
318
/* might set nb fbuf, convert format, stride */
319
/* might set fbufs */
320
printf ("\n Seq found\n");
322
vo_setup_result_t res;
296
if (output->setup (output,
297
info->sequence->width,
298
info->sequence->height,
299
info->sequence->width>>1,
300
info->sequence->height>>1,
303
fprintf (stderr, "display setup failed\n");
308
//mpeg2_custom_fbuf(MPEG2DEC,1);
309
output->setup_fbuf (output, buf, (void **)0); // 3 buffer ...
310
mpeg2_set_buf (MPEG2DEC, buf, (void *)0);
311
output->setup_fbuf (output, buf, (void **)1);
312
mpeg2_set_buf (MPEG2DEC, buf, (void *)1);
313
output->setup_fbuf (output, buf, (void **)2);
314
mpeg2_set_buf (MPEG2DEC, buf, (void *)2);
325
if (output->setup (output,
326
info->sequence->width,
327
info->sequence->height,
328
info->sequence->width >> 1,
329
info->sequence->height >> 1, &res))
331
fprintf (stderr, "display setup failed\n");
318
printf("..already initialized...\n");
336
//mpeg2_custom_fbuf(MPEG2DEC,1);
337
output->setup_fbuf (output, buf, (void **) 0); // 3 buffer ...
338
mpeg2_set_buf (MPEG2DEC, buf, (void *) 0);
339
output->setup_fbuf (output, buf, (void **) 1);
340
mpeg2_set_buf (MPEG2DEC, buf, (void *) 1);
341
output->setup_fbuf (output, buf, (void **) 2);
342
mpeg2_set_buf (MPEG2DEC, buf, (void *) 2);
346
printf ("..already initialized...\n");
321
349
case STATE_PICTURE:
325
_seen=MPEG2DEC->decoder.coding_type;
326
//printf("1st %d\n",_seen);
353
_seen = MPEG2DEC->decoder.coding_type;
354
//printf("1st %d\n",_seen);
328
356
case STATE_PICTURE_2ND:
329
/* should not do anything */
357
/* should not do anything */
332
360
case STATE_SLICE:
334
/* draw current picture */
335
/* might free frame buffer */
362
/* draw current picture */
363
/* might free frame buffer */
344
372
yv12_open : set up the callbacks
346
vo_instance_t * yv12_open (void)
348
yv12_instance_t * instance;
350
instance = new yv12_instance_t;
351
if (instance == NULL)
353
memset(instance,0,sizeof(*instance));
355
instance->vo.setup = yv12_setup;
356
instance->vo.setup_fbuf = yv12_setup_fbuf;
357
instance->vo.set_fbuf = NULL;
358
instance->vo.draw = NULL;
359
instance->vo.discard = NULL;
360
instance->vo.close = yv12_close;
361
instance->father=_father;
363
printf(" YV12 open called\n");
365
return (vo_instance_t *) instance;
377
yv12_instance_t *instance;
379
instance = new yv12_instance_t;
380
if (instance == NULL)
382
memset (instance, 0, sizeof (*instance));
384
instance->vo.setup = yv12_setup;
385
instance->vo.setup_fbuf = yv12_setup_fbuf;
386
instance->vo.set_fbuf = NULL;
387
instance->vo.draw = NULL;
388
instance->vo.discard = NULL;
389
instance->vo.close = yv12_close;
390
instance->father = _father;
392
printf (" YV12 open called\n");
394
return (vo_instance_t *) instance;
368
397
yv12_setup : Nothing to do
370
int yv12_setup (vo_instance_t * _instance, unsigned int width, unsigned int height,unsigned int chroma_w,unsigned int chroma_h,vo_setup_result_t *result)
400
yv12_setup (vo_instance_t * _instance, unsigned int width,
401
unsigned int height, unsigned int chroma_w, unsigned int chroma_h,
402
vo_setup_result_t * result)
372
yv12_instance_t *ins;
404
yv12_instance_t *ins;
374
ins=(yv12_instance_t *)_instance;
377
result->convert=NULL;
378
printf(" YV12 setup called\n");
406
ins = (yv12_instance_t *) _instance;
409
result->convert = NULL;
410
printf (" YV12 setup called\n");
382
414
yv12_close : nothing to do
384
void yv12_close (vo_instance_t * _instance)
417
yv12_close (vo_instance_t * _instance)
386
UNUSED_ARG(_instance);
387
printf(" yv12close called\n");
419
UNUSED_ARG (_instance);
420
printf (" yv12close called\n");
391
424
yv12_setup_fbuf : Allocate some buffers
393
static void yv12_setup_fbuf (vo_instance_t * _instance, uint8_t ** buf, void ** id)
427
yv12_setup_fbuf (vo_instance_t * _instance, uint8_t ** buf, void **id)
406
yv12_instance_t * instance = (yv12_instance_t *) _instance;
407
printf(" **********YV12 setup fbuf called : %lu x %lu (%lu)\n",instance->w,instance->h,i);
409
page=instance->w*instance->h;
412
all=instance->buffer;
417
buf[1] =all+page+(page>>2);;
440
yv12_instance_t *instance = (yv12_instance_t *) _instance;
441
printf (" **********YV12 setup fbuf called : %lu x %lu (%lu)\n",
442
instance->w, instance->h, i);
444
page = instance->w * instance->h;
445
img = (page * 3) >> 1;
447
all = instance->buffer;
449
memset (all, 0, img);
451
buf[2] = all + page;;
452
buf[1] = all + page + (page >> 2);;