r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / libmpeg3 / video / mpeg3video.c
blob013529ea8f60afd3a3ad45e4824d2da7ceedb1cf
1 #include "../libmpeg3.h"
2 #include "../mpeg3private.h"
3 #include "../mpeg3protos.h"
4 #include "mpeg3video.h"
5 #include "mpeg3videoprotos.h"
6 #include <pthread.h>
7 #include <stdlib.h>
9 // "½Åµ¿ÈÆ" <doogle@shinbiro.com>
11 unsigned char mpeg3_zig_zag_scan_mmx[64] =
13 0*8+0 /* 0*/, 1*8+0 /* 1*/, 0*8+1 /* 8*/, 0*8+2 /*16*/, 1*8+1 /* 9*/, 2*8+0 /* 2*/, 3*8+0 /* 3*/, 2*8+1 /*10*/,
14 1*8+2 /*17*/, 0*8+3 /*24*/, 0*8+4 /*32*/, 1*8+3 /*25*/, 2*8+2 /*18*/, 3*8+1 /*11*/, 4*8+0 /* 4*/, 5*8+0 /* 5*/,
15 4*8+1 /*12*/, 3*8+2 /*19*/, 2*8+3 /*26*/, 1*8+4 /*33*/, 0*8+5 /*40*/, 0*8+6 /*48*/, 1*8+5 /*41*/, 2*8+4 /*34*/,
16 3*8+3 /*27*/, 4*8+2 /*20*/, 5*8+1 /*13*/, 6*8+0 /* 6*/, 7*8+0 /* 7*/, 6*8+1 /*14*/, 5*8+2 /*21*/, 4*8+3 /*28*/,
17 3*8+4 /*35*/, 2*8+5 /*42*/, 1*8+6 /*49*/, 0*8+7 /*56*/, 1*8+7 /*57*/, 2*8+6 /*50*/, 3*8+5 /*43*/, 4*8+4 /*36*/,
18 5*8+3 /*29*/, 6*8+2 /*22*/, 7*8+1 /*15*/, 7*8+2 /*23*/, 6*8+3 /*30*/, 5*8+4 /*37*/, 4*8+5 /*44*/, 3*8+6 /*51*/,
19 2*8+7 /*58*/, 3*8+7 /*59*/, 4*8+6 /*52*/, 5*8+5 /*45*/, 6*8+4 /*38*/, 7*8+3 /*31*/, 7*8+4 /*39*/, 6*8+5 /*46*/,
20 5*8+6 /*53*/, 4*8+7 /*60*/, 5*8+7 /*61*/, 6*8+6 /*54*/, 7*8+5 /*47*/, 7*8+6 /*55*/, 6*8+7 /*62*/, 7*8+7 /*63*/
23 /* alternate scan */
24 unsigned char mpeg3_alternate_scan_mmx[64] =
26 0*8+0 /*0 */, 0*8+1 /* 8*/, 0*8+2 /*16*/, 0*8+3 /*24*/, 1*8+0 /* 1*/, 1*8+1 /* 9*/, 2*8+0 /* 2*/, 2*8+1 /*10*/,
27 1*8+2 /*17*/, 1*8+3 /*25*/, 0*8+4 /*32*/, 0*8+5 /*40*/, 0*8+6 /*48*/, 0*8+7 /*56*/, 1*8+7 /*57*/, 1*8+6 /*49*/,
28 1*8+5 /*41*/, 1*8+4 /*33*/, 2*8+3 /*26*/, 2*8+2 /*18*/, 3*8+0 /* 3*/, 3*8+1 /*11*/, 4*8+0 /* 4*/, 4*8+1 /*12*/,
29 3*8+2 /*19*/, 3*8+3 /*27*/, 2*8+4 /*34*/, 2*8+5 /*42*/, 2*8+6 /*50*/, 2*8+7 /*58*/, 3*8+4 /*35*/, 3*8+5 /*43*/,
30 3*8+6 /*51*/, 3*8+7 /*59*/, 4*8+2 /*20*/, 4*8+3 /*28*/, 5*8+0 /* 5*/, 5*8+1 /*13*/, 6*8+0 /* 6*/, 6*8+1 /*14*/,
31 5*8+2 /*21*/, 5*8+3 /*29*/, 4*8+4 /*36*/, 4*8+5 /*44*/, 4*8+6 /*52*/, 4*8+7 /*60*/, 5*8+4 /*37*/, 5*8+5 /*45*/,
32 5*8+6 /*53*/, 5*8+7 /*61*/, 6*8+2 /*22*/, 6*8+3 /*30*/, 7*8+0 /* 7*/, 7*8+1 /*15*/, 7*8+2 /*23*/, 7*8+3 /*31*/,
33 6*8+4 /*38*/, 6*8+5 /*46*/, 6*8+6 /*54*/, 6*8+7 /*62*/, 7*8+4 /*39*/, 7*8+5 /*47*/, 7*8+6 /*55*/, 7*8+7 /*63*/
37 /* zig-zag scan */
38 unsigned char mpeg3_zig_zag_scan_nommx[64] =
40 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5,
41 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28,
42 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
43 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63
46 /* alternate scan */
47 unsigned char mpeg3_alternate_scan_nommx[64] =
49 0, 8, 16, 24, 1, 9, 2, 10, 17, 25, 32, 40, 48, 56, 57, 49,
50 41, 33, 26, 18, 3, 11, 4, 12, 19, 27, 34, 42, 50, 58, 35, 43,
51 51, 59, 20, 28, 5, 13, 6, 14, 21, 29, 36, 44, 52, 60, 37, 45,
52 53, 61, 22, 30, 7, 15, 23, 31, 38, 46, 54, 62, 39, 47, 55, 63
55 /* default intra quantization matrix */
56 unsigned char mpeg3_default_intra_quantizer_matrix[64] =
58 8, 16, 19, 22, 26, 27, 29, 34,
59 16, 16, 22, 24, 27, 29, 34, 37,
60 19, 22, 26, 27, 29, 34, 34, 38,
61 22, 22, 26, 27, 29, 34, 37, 40,
62 22, 26, 27, 29, 32, 35, 40, 48,
63 26, 27, 29, 32, 35, 40, 48, 58,
64 26, 27, 29, 34, 38, 46, 56, 69,
65 27, 29, 35, 38, 46, 56, 69, 83
68 unsigned char mpeg3_non_linear_mquant_table[32] =
70 0, 1, 2, 3, 4, 5, 6, 7,
71 8, 10, 12, 14, 16, 18, 20, 22,
72 24, 28, 32, 36, 40, 44, 48, 52,
73 56, 64, 72, 80, 88, 96, 104, 112
76 double mpeg3_frame_rate_table[16] =
78 0.0, /* Pad */
79 (double)24000.0/1001.0, /* Official frame rates */
80 (double)24.0,
81 (double)25.0,
82 (double)30000.0/1001.0,
83 (double)30.0,
84 (double)50.0,
85 (double)60000.0/1001.0,
86 (double)60.0,
88 1, /* Unofficial economy rates */
89 5,
90 10,
91 12,
92 15,
97 int mpeg3video_initdecoder(mpeg3video_t *video)
99 int blk_cnt_tab[3] = {6, 8, 12};
100 int cc;
101 int i;
102 long size[4], padding[2]; /* Size of Y, U, and V buffers */
104 if(!video->mpeg2)
106 /* force MPEG-1 parameters */
107 video->prog_seq = 1;
108 video->prog_frame = 1;
109 video->pict_struct = FRAME_PICTURE;
110 video->frame_pred_dct = 1;
111 video->chroma_format = CHROMA420;
112 video->matrix_coefficients = 5;
115 /* Get dimensions rounded to nearest multiple of coded macroblocks */
116 video->mb_width = (video->horizontal_size + 15) / 16;
117 video->mb_height = (video->mpeg2 && !video->prog_seq) ?
118 (2 * ((video->vertical_size + 31) / 32)) :
119 ((video->vertical_size + 15) / 16);
120 video->coded_picture_width = 16 * video->mb_width;
121 video->coded_picture_height = 16 * video->mb_height;
122 video->chrom_width = (video->chroma_format == CHROMA444) ?
123 video->coded_picture_width :
124 (video->coded_picture_width >> 1);
125 video->chrom_height = (video->chroma_format != CHROMA420) ?
126 video->coded_picture_height :
127 (video->coded_picture_height >> 1);
128 video->blk_cnt = blk_cnt_tab[video->chroma_format - 1];
130 /* Get sizes of YUV buffers */
131 padding[0] = 16 * video->coded_picture_width;
132 size[0] = video->coded_picture_width * video->coded_picture_height + padding[0] * 2;
134 padding[1] = 16 * video->chrom_width;
135 size[1] = video->chrom_width * video->chrom_height + 2 * padding[1];
137 size[2] = (video->llw * video->llh);
138 size[3] = (video->llw * video->llh) / 4;
140 /* Allocate contiguous fragments for YUV buffers for hardware YUV decoding */
141 video->yuv_buffer[0] = (unsigned char*)calloc(1, (size[0] + padding[0]) + 2 * (size[1] + padding[1]));
142 video->yuv_buffer[1] = (unsigned char*)calloc(1, (size[0] + padding[0]) + 2 * (size[1] + padding[1]));
143 video->yuv_buffer[2] = (unsigned char*)calloc(1, (size[0] + padding[0]) + 2 * (size[1] + padding[1]));
145 if(video->scalable_mode == SC_SPAT)
147 video->yuv_buffer[3] = (unsigned char*)calloc(1, size[2] + 2 * size[3]);
148 video->yuv_buffer[4] = (unsigned char*)calloc(1, size[2] + 2 * size[3]);
151 /* Direct pointers to areas of contiguous fragments in YVU order per Microsoft */
152 for(cc = 0; cc < 3; cc++)
154 video->llframe0[cc] = 0;
155 video->llframe1[cc] = 0;
156 video->newframe[cc] = 0;
159 video->refframe[0] = video->yuv_buffer[0];
160 video->oldrefframe[0] = video->yuv_buffer[1];
161 video->auxframe[0] = video->yuv_buffer[2];
162 video->refframe[2] = video->yuv_buffer[0] + size[0] + padding[0];
163 video->oldrefframe[2] = video->yuv_buffer[1] + size[0] + padding[0];
164 video->auxframe[2] = video->yuv_buffer[2] + size[0] + padding[0];
165 video->refframe[1] = video->yuv_buffer[0] + size[0] + padding[0] + size[1] + padding[1];
166 video->oldrefframe[1] = video->yuv_buffer[1] + size[0] + padding[0] + size[1] + padding[1];
167 video->auxframe[1] = video->yuv_buffer[2] + size[0] + padding[0] + size[1] + padding[1];
169 if(video->scalable_mode == SC_SPAT)
171 /* this assumes lower layer is 4:2:0 */
172 video->llframe0[0] = video->yuv_buffer[3] + padding[0] ;
173 video->llframe1[0] = video->yuv_buffer[4] + padding[0] ;
174 video->llframe0[2] = video->yuv_buffer[3] + padding[1] + size[2] ;
175 video->llframe1[2] = video->yuv_buffer[4] + padding[1] + size[2] ;
176 video->llframe0[1] = video->yuv_buffer[3] + padding[1] + size[2] + size[3];
177 video->llframe1[1] = video->yuv_buffer[4] + padding[1] + size[2] + size[3];
180 /* Initialize the YUV tables for software YUV decoding */
181 video->cr_to_r = malloc(sizeof(long) * 256);
182 video->cr_to_g = malloc(sizeof(long) * 256);
183 video->cb_to_g = malloc(sizeof(long) * 256);
184 video->cb_to_b = malloc(sizeof(long) * 256);
185 video->cr_to_r_ptr = video->cr_to_r + 128;
186 video->cr_to_g_ptr = video->cr_to_g + 128;
187 video->cb_to_g_ptr = video->cb_to_g + 128;
188 video->cb_to_b_ptr = video->cb_to_b + 128;
190 for(i = -128; i < 128; i++)
192 video->cr_to_r_ptr[i] = (long)( 1.371 * 65536 * i);
193 video->cr_to_g_ptr[i] = (long)(-0.698 * 65536 * i);
194 video->cb_to_g_ptr[i] = (long)(-0.336 * 65536 * i);
195 video->cb_to_b_ptr[i] = (long)( 1.732 * 65536 * i);
198 return 0;
201 int mpeg3video_deletedecoder(mpeg3video_t *video)
203 int i, padding;
205 free(video->yuv_buffer[0]);
206 free(video->yuv_buffer[1]);
207 free(video->yuv_buffer[2]);
209 if(video->llframe0[0])
211 free(video->yuv_buffer[3]);
212 free(video->yuv_buffer[4]);
215 free(video->cr_to_r);
216 free(video->cr_to_g);
217 free(video->cb_to_g);
218 free(video->cb_to_b);
219 return 0;
222 void mpeg3video_init_scantables(mpeg3video_t *video)
224 #ifdef HAVE_MMX
225 if(video->have_mmx)
227 video->mpeg3_zigzag_scan_table = mpeg3_zig_zag_scan_mmx;
228 video->mpeg3_alternate_scan_table = mpeg3_alternate_scan_mmx;
230 else
231 #endif
233 video->mpeg3_zigzag_scan_table = mpeg3_zig_zag_scan_nommx;
234 video->mpeg3_alternate_scan_table = mpeg3_alternate_scan_nommx;
238 mpeg3video_t* mpeg3video_allocate_struct(mpeg3_t *file, mpeg3_vtrack_t *track)
240 int i;
241 mpeg3video_t *video = calloc(1, sizeof(mpeg3video_t));
242 pthread_mutexattr_t mutex_attr;
244 video->file = file;
245 video->track = track;
246 video->vstream = mpeg3bits_new_stream(file, track->demuxer);
247 //printf("mpeg3video_allocate_struct %d\n", mpeg3bits_eof(video->vstream));
248 video->last_number = -1;
250 /* First frame is all green */
251 video->framenum = -1;
252 video->have_mmx = file->have_mmx;
254 video->percentage_seek = -1;
255 video->frame_seek = -1;
257 mpeg3video_init_scantables(video);
258 mpeg3video_init_output();
260 pthread_mutexattr_init(&mutex_attr);
261 // pthread_mutexattr_setkind_np(&mutex_attr, PTHREAD_MUTEX_FAST_NP);
262 pthread_mutex_init(&(video->test_lock), &mutex_attr);
263 pthread_mutex_init(&(video->slice_lock), &mutex_attr);
264 return video;
267 int mpeg3video_delete_struct(mpeg3video_t *video)
269 int i;
270 mpeg3bits_delete_stream(video->vstream);
271 pthread_mutex_destroy(&(video->test_lock));
272 pthread_mutex_destroy(&(video->slice_lock));
273 if(video->x_table)
275 free(video->x_table);
276 free(video->y_table);
278 if(video->total_slice_decoders)
280 for(i = 0; i < video->total_slice_decoders; i++)
281 mpeg3_delete_slice_decoder(&(video->slice_decoders[i]));
283 for(i = 0; i < video->slice_buffers_initialized; i++)
284 mpeg3_delete_slice_buffer(&(video->slice_buffers[i]));
286 free(video);
287 return 0;
291 int mpeg3video_read_frame_backend(mpeg3video_t *video, int skip_bframes)
293 int result = 0;
294 int got_top = 0, got_bottom = 0;
295 int i = 0;
297 //printf(__FUNCTION__ " 1\n");
300 if(mpeg3bits_eof(video->vstream)) result = 1;
301 //printf(__FUNCTION__ " 1.1\n");
303 if(!result) result = mpeg3video_get_header(video, 0);
304 //printf(__FUNCTION__ " 1\n");
307 /* skip_bframes is the number of bframes we can skip successfully. */
308 /* This is in case a skipped B-frame is repeated and the second repeat happens */
309 /* to be a B frame we need. */
310 video->skip_bframes = skip_bframes;
311 //printf(__FUNCTION__ " 1\n");
313 if(!result)
314 result = mpeg3video_getpicture(video, video->framenum);
316 //printf(__FUNCTION__ " 1\n");
318 if(video->pict_struct == TOP_FIELD)
320 got_top == 1;
322 else
323 if(video->pict_struct == BOTTOM_FIELD)
325 got_bottom = 1;
326 video->secondfield = 0;
328 else
329 if(video->pict_struct == FRAME_PICTURE)
331 got_top = got_bottom = 1;
333 //printf(__FUNCTION__ " 2\n");
335 i++;
336 }while(i < 2 &&
337 !got_bottom &&
338 video->framenum >= 0);
339 // The way they do field based encoding,
340 // the I frames have the top field but both the I frame and
341 // subsequent P frame make the keyframe.
343 //printf(__FUNCTION__ " 3 %d %d\n", video->pict_type, video->pict_struct);
345 #ifdef HAVE_MMX
346 if(video->have_mmx)
347 __asm__ __volatile__ ("emms");
348 #endif
350 if(!result)
352 video->last_number = video->framenum;
353 video->framenum++;
355 //printf(__FUNCTION__ " 100\n");
357 return result;
360 int* mpeg3video_get_scaletable(int input_w, int output_w)
362 int *result = malloc(sizeof(int) * output_w);
363 float i;
364 float scale = (float)input_w / output_w;
365 for(i = 0; i < output_w; i++)
367 result[(int)i] = (int)(scale * i);
369 return result;
372 /* Get the first I frame. */
373 int mpeg3video_get_firstframe(mpeg3video_t *video)
375 int result = 0;
376 video->repeat_count = video->current_repeat = 0;
377 result = mpeg3video_read_frame_backend(video, 0);
378 return result;
381 static long gop_to_frame(mpeg3video_t *video, mpeg3_timecode_t *gop_timecode)
383 int hour, minute, second, frame, fps;
384 long result;
386 // Mirror of what mpeg2enc does
387 fps = (int)(video->frame_rate + 0.5);
390 hour = gop_timecode->hour;
391 minute = gop_timecode->minute;
392 second = gop_timecode->second;
393 frame = gop_timecode->frame;
395 result = (long)hour * 60 * 60 * fps +
396 minute * 60 * fps +
397 second * fps +
398 frame;
400 return result;
404 /* ======================================================================= */
405 /* ENTRY POINTS */
406 /* ======================================================================= */
410 mpeg3video_t* mpeg3video_new(mpeg3_t *file, mpeg3_vtrack_t *track)
412 mpeg3video_t *video;
413 int result = 0;
415 video = mpeg3video_allocate_struct(file, track);
417 //printf("mpeg3video_new 1 %llx %llx\n", mpeg3bits_tell(video->vstream), mpeg3demux_tell(track->demuxer));
418 result = mpeg3video_get_header(video, 1);
419 //printf("mpeg3video_new 2 %d\n", result);
421 if(!result)
423 int hour, minute, second, frame;
424 int gop_found;
426 mpeg3video_initdecoder(video);
427 video->decoder_initted = 1;
428 track->width = video->horizontal_size;
429 track->height = video->vertical_size;
430 track->frame_rate = video->frame_rate;
432 /* Try to get the length of the file from GOP's */
433 if(!track->frame_offsets)
435 if(file->is_video_stream)
437 /* Load the first GOP */
438 mpeg3bits_seek_start(video->vstream);
439 result = mpeg3video_next_code(video->vstream, MPEG3_GOP_START_CODE);
440 if(!result) mpeg3bits_getbits(video->vstream, 32);
441 if(!result) result = mpeg3video_getgophdr(video);
443 hour = video->gop_timecode.hour;
444 minute = video->gop_timecode.minute;
445 second = video->gop_timecode.second;
446 frame = video->gop_timecode.frame;
448 video->first_frame = gop_to_frame(video, &video->gop_timecode);
451 * video->first_frame = (long)(hour * 3600 * video->frame_rate +
452 * minute * 60 * video->frame_rate +
453 * second * video->frame_rate +
454 * frame);
457 /* GOPs are supposed to have 16 frames */
459 video->frames_per_gop = 16;
461 /* Read the last GOP in the file by seeking backward. */
462 mpeg3bits_seek_end(video->vstream);
463 mpeg3bits_start_reverse(video->vstream);
464 result = mpeg3video_prev_code(video->vstream, MPEG3_GOP_START_CODE);
465 mpeg3bits_start_forward(video->vstream);
466 mpeg3bits_getbits(video->vstream, 8);
467 if(!result) result = mpeg3video_getgophdr(video);
469 hour = video->gop_timecode.hour;
470 minute = video->gop_timecode.minute;
471 second = video->gop_timecode.second;
472 frame = video->gop_timecode.frame;
474 video->last_frame = gop_to_frame(video, &video->gop_timecode);
477 * video->last_frame = (long)((double)hour * 3600 * video->frame_rate +
478 * minute * 60 * video->frame_rate +
479 * second * video->frame_rate +
480 * frame);
483 //printf("mpeg3video_new 3 %p\n", video);
485 /* Count number of frames to end */
486 while(!result)
488 result = mpeg3video_next_code(video->vstream, MPEG3_PICTURE_START_CODE);
489 //printf("mpeg3video_new 2 %d %ld\n", result, video->last_frame);
490 if(!result)
492 mpeg3bits_getbyte_noptr(video->vstream);
493 video->last_frame++;
497 track->total_frames = video->last_frame - video->first_frame + 1;
498 //printf("mpeg3video_new 3 %ld\n", track->total_frames);
499 mpeg3bits_seek_start(video->vstream);
501 else
502 // Try to get the length of the file from the multiplexing.
504 video->first_frame = 0;
505 track->total_frames = video->last_frame =
506 (long)(mpeg3demux_length(video->vstream->demuxer) *
507 video->frame_rate);
508 video->first_frame = 0;
511 else
512 // Get length from table of contents
514 track->total_frames = track->total_frame_offsets;
519 video->maxframe = track->total_frames;
520 mpeg3bits_seek_start(video->vstream);
521 mpeg3video_get_firstframe(video);
523 else
525 //printf("mpeg3video_new 3 %p\n", video);
526 mpeg3video_delete(video);
527 video = 0;
529 //printf("mpeg3video_new 100 %p\n", video);
531 return video;
534 int mpeg3video_delete(mpeg3video_t *video)
536 if(video->decoder_initted)
538 mpeg3video_deletedecoder(video);
540 mpeg3video_delete_struct(video);
541 return 0;
544 int mpeg3video_set_cpus(mpeg3video_t *video, int cpus)
546 return 0;
549 int mpeg3video_set_mmx(mpeg3video_t *video, int use_mmx)
551 video->have_mmx = use_mmx;
552 mpeg3video_init_scantables(video);
553 return 0;
556 /* Read all the way up to and including the next picture start code */
557 int mpeg3video_read_raw(mpeg3video_t *video, unsigned char *output, long *size, long max_size)
559 u_int32_t code = 0;
560 mpeg3_bits_t *vstream = video->vstream;
562 *size = 0;
563 while(code != MPEG3_PICTURE_START_CODE &&
564 code != MPEG3_SEQUENCE_END_CODE &&
565 *size < max_size &&
566 !mpeg3bits_eof(vstream))
568 code <<= 8;
569 *output = mpeg3bits_getbyte_noptr(vstream);
570 code |= *output++;
571 (*size)++;
573 return mpeg3bits_eof(vstream);
576 int mpeg3video_read_frame(mpeg3video_t *video,
577 long frame_number,
578 unsigned char **output_rows,
579 int in_x,
580 int in_y,
581 int in_w,
582 int in_h,
583 int out_w,
584 int out_h,
585 int color_model)
587 int result = 0;
589 video->want_yvu = 0;
590 video->output_rows = output_rows;
591 video->color_model = color_model;
593 /* Get scaling tables */
594 if(video->out_w != out_w || video->out_h != out_h ||
595 video->in_w != in_w || video->in_h != in_h ||
596 video->in_x != in_x || video->in_y != in_y)
598 if(video->x_table)
600 free(video->x_table);
601 free(video->y_table);
602 video->x_table = 0;
603 video->y_table = 0;
607 video->out_w = out_w;
608 video->out_h = out_h;
609 video->in_w = in_w;
610 video->in_h = in_h;
611 video->in_x = in_x;
612 video->in_y = in_y;
614 if(!video->x_table)
616 video->x_table = mpeg3video_get_scaletable(video->in_w, video->out_w);
617 video->y_table = mpeg3video_get_scaletable(video->in_h, video->out_h);
620 //printf("mpeg3video_read_frame 3\n");
621 if(!result) result = mpeg3video_seek(video);
623 //printf("mpeg3video_read_frame 4\n");
624 if(!result) result = mpeg3video_read_frame_backend(video, 0);
626 //printf("mpeg3video_read_frame 5\n");
627 if(video->output_src) mpeg3video_present_frame(video);
629 video->percentage_seek = -1;
630 return result;
633 int mpeg3video_read_yuvframe(mpeg3video_t *video,
634 long frame_number,
635 char *y_output,
636 char *u_output,
637 char *v_output,
638 int in_x,
639 int in_y,
640 int in_w,
641 int in_h)
643 int result = 0;
645 video->want_yvu = 1;
646 video->y_output = y_output;
647 video->u_output = u_output;
648 video->v_output = v_output;
649 video->in_x = in_x;
650 video->in_y = in_y;
651 video->in_w = in_w;
652 video->in_h = in_h;
654 if(!result) result = mpeg3video_seek(video);
656 if(!result) result = mpeg3video_read_frame_backend(video, 0);
658 if(video->output_src) mpeg3video_present_frame(video);
660 video->want_yvu = 0;
661 video->percentage_seek = -1;
662 return result;
665 int mpeg3video_read_yuvframe_ptr(mpeg3video_t *video,
666 long frame_number,
667 char **y_output,
668 char **u_output,
669 char **v_output)
671 int result = 0;
672 //printf("mpeg3video_read_yuvframe_ptr 1\n");
674 video->want_yvu = 1;
676 if(!result) result = mpeg3video_seek(video);
677 //printf("mpeg3video_read_yuvframe_ptr 10\n");
679 if(!result) result = mpeg3video_read_frame_backend(video, 0);
680 //printf("mpeg3video_read_yuvframe_ptr 20 %p\n", video->output_src);
683 *y_output = video->output_src[0];
684 *u_output = video->output_src[1];
685 *v_output = video->output_src[2];
687 video->want_yvu = 0;
688 video->percentage_seek = -1;
690 //printf("mpeg3video_read_yuvframe_ptr 100\n");
692 return result;
695 int mpeg3video_colormodel(mpeg3video_t *video)
697 switch(video->chroma_format)
699 case CHROMA422:
700 return MPEG3_YUV422P;
701 break;
703 case CHROMA420:
704 return MPEG3_YUV420P;
705 break;
708 return MPEG3_YUV420P;
711 void mpeg3video_dump(mpeg3video_t *video)
713 printf("mpeg3video_dump 1\n");
714 printf(" *** sequence extension 1\n");
715 printf("prog_seq=%d\n", video->prog_seq);
716 printf(" *** picture header 1\n");
717 printf("pict_type=%d field_sequence=%d\n", video->pict_type, video->field_sequence);
718 printf(" *** picture coding extension 1\n");
719 printf("field_sequence=%d repeatfirst=%d prog_frame=%d pict_struct=%d\n",
720 video->field_sequence,
721 video->repeatfirst,
722 video->prog_frame,
723 video->pict_struct);