Fixed initialisation of tf in file_open(). Without setting the memory to 0,
[cinelerra_cv/mob.git] / libmpeg3 / video / mpeg3video.c
blob7cf8a14853db58d02b22b5631799db98ecb95a9d
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>
12 /* zig-zag scan */
13 unsigned char mpeg3_zig_zag_scan_nommx[64] =
15 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5,
16 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28,
17 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
18 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63
21 /* alternate scan */
22 unsigned char mpeg3_alternate_scan_nommx[64] =
24 0, 8, 16, 24, 1, 9, 2, 10, 17, 25, 32, 40, 48, 56, 57, 49,
25 41, 33, 26, 18, 3, 11, 4, 12, 19, 27, 34, 42, 50, 58, 35, 43,
26 51, 59, 20, 28, 5, 13, 6, 14, 21, 29, 36, 44, 52, 60, 37, 45,
27 53, 61, 22, 30, 7, 15, 23, 31, 38, 46, 54, 62, 39, 47, 55, 63
30 /* default intra quantization matrix */
31 unsigned char mpeg3_default_intra_quantizer_matrix[64] =
33 8, 16, 19, 22, 26, 27, 29, 34,
34 16, 16, 22, 24, 27, 29, 34, 37,
35 19, 22, 26, 27, 29, 34, 34, 38,
36 22, 22, 26, 27, 29, 34, 37, 40,
37 22, 26, 27, 29, 32, 35, 40, 48,
38 26, 27, 29, 32, 35, 40, 48, 58,
39 26, 27, 29, 34, 38, 46, 56, 69,
40 27, 29, 35, 38, 46, 56, 69, 83
43 unsigned char mpeg3_non_linear_mquant_table[32] =
45 0, 1, 2, 3, 4, 5, 6, 7,
46 8, 10, 12, 14, 16, 18, 20, 22,
47 24, 28, 32, 36, 40, 44, 48, 52,
48 56, 64, 72, 80, 88, 96, 104, 112
51 double mpeg3_frame_rate_table[16] =
53 0.0, /* Pad */
54 (double)24000.0/1001.0, /* Official frame rates */
55 (double)24.0,
56 (double)25.0,
57 (double)30000.0/1001.0,
58 (double)30.0,
59 (double)50.0,
60 (double)60000.0/1001.0,
61 (double)60.0,
63 1, /* Unofficial economy rates */
64 5,
65 10,
66 12,
67 15,
72 int mpeg3video_initdecoder(mpeg3video_t *video)
74 int blk_cnt_tab[3] = {6, 8, 12};
75 int cc;
76 int i;
77 long size[4], padding[2]; /* Size of Y, U, and V buffers */
79 if(!video->mpeg2)
81 /* force MPEG-1 parameters */
82 video->prog_seq = 1;
83 video->prog_frame = 1;
84 video->pict_struct = FRAME_PICTURE;
85 video->frame_pred_dct = 1;
86 video->chroma_format = CHROMA420;
87 video->matrix_coefficients = 5;
90 /* Get dimensions rounded to nearest multiple of coded macroblocks */
91 video->mb_width = (video->horizontal_size + 15) / 16;
92 video->mb_height = (video->mpeg2 && !video->prog_seq) ?
93 (2 * ((video->vertical_size + 31) / 32)) :
94 ((video->vertical_size + 15) / 16);
95 video->coded_picture_width = 16 * video->mb_width;
96 video->coded_picture_height = 16 * video->mb_height;
97 video->chrom_width = (video->chroma_format == CHROMA444) ?
98 video->coded_picture_width :
99 (video->coded_picture_width >> 1);
100 video->chrom_height = (video->chroma_format != CHROMA420) ?
101 video->coded_picture_height :
102 (video->coded_picture_height >> 1);
103 video->blk_cnt = blk_cnt_tab[video->chroma_format - 1];
105 /* Get sizes of YUV buffers */
106 padding[0] = 16 * video->coded_picture_width;
107 size[0] = video->coded_picture_width * video->coded_picture_height + padding[0] * 2;
109 padding[1] = 16 * video->chrom_width;
110 size[1] = video->chrom_width * video->chrom_height + 2 * padding[1];
112 size[2] = (video->llw * video->llh);
113 size[3] = (video->llw * video->llh) / 4;
115 /* Allocate contiguous fragments for YUV buffers for hardware YUV decoding */
116 video->yuv_buffer[0] = (unsigned char*)calloc(1, (size[0] + padding[0]) + 2 * (size[1] + padding[1]));
117 video->yuv_buffer[1] = (unsigned char*)calloc(1, (size[0] + padding[0]) + 2 * (size[1] + padding[1]));
118 video->yuv_buffer[2] = (unsigned char*)calloc(1, (size[0] + padding[0]) + 2 * (size[1] + padding[1]));
120 if(video->scalable_mode == SC_SPAT)
122 video->yuv_buffer[3] = (unsigned char*)calloc(1, size[2] + 2 * size[3]);
123 video->yuv_buffer[4] = (unsigned char*)calloc(1, size[2] + 2 * size[3]);
126 /* Direct pointers to areas of contiguous fragments in YVU order per Microsoft */
127 for(cc = 0; cc < 3; cc++)
129 video->llframe0[cc] = 0;
130 video->llframe1[cc] = 0;
131 video->newframe[cc] = 0;
134 video->refframe[0] = video->yuv_buffer[0];
135 video->oldrefframe[0] = video->yuv_buffer[1];
136 video->auxframe[0] = video->yuv_buffer[2];
137 video->refframe[2] = video->yuv_buffer[0] + size[0] + padding[0];
138 video->oldrefframe[2] = video->yuv_buffer[1] + size[0] + padding[0];
139 video->auxframe[2] = video->yuv_buffer[2] + size[0] + padding[0];
140 video->refframe[1] = video->yuv_buffer[0] + size[0] + padding[0] + size[1] + padding[1];
141 video->oldrefframe[1] = video->yuv_buffer[1] + size[0] + padding[0] + size[1] + padding[1];
142 video->auxframe[1] = video->yuv_buffer[2] + size[0] + padding[0] + size[1] + padding[1];
144 if(video->scalable_mode == SC_SPAT)
146 /* this assumes lower layer is 4:2:0 */
147 video->llframe0[0] = video->yuv_buffer[3] + padding[0] ;
148 video->llframe1[0] = video->yuv_buffer[4] + padding[0] ;
149 video->llframe0[2] = video->yuv_buffer[3] + padding[1] + size[2] ;
150 video->llframe1[2] = video->yuv_buffer[4] + padding[1] + size[2] ;
151 video->llframe0[1] = video->yuv_buffer[3] + padding[1] + size[2] + size[3];
152 video->llframe1[1] = video->yuv_buffer[4] + padding[1] + size[2] + size[3];
155 /* Initialize the YUV tables for software YUV decoding */
156 video->cr_to_r = malloc(sizeof(long) * 256);
157 video->cr_to_g = malloc(sizeof(long) * 256);
158 video->cb_to_g = malloc(sizeof(long) * 256);
159 video->cb_to_b = malloc(sizeof(long) * 256);
160 video->cr_to_r_ptr = video->cr_to_r + 128;
161 video->cr_to_g_ptr = video->cr_to_g + 128;
162 video->cb_to_g_ptr = video->cb_to_g + 128;
163 video->cb_to_b_ptr = video->cb_to_b + 128;
165 for(i = -128; i < 128; i++)
167 video->cr_to_r_ptr[i] = (long)( 1.371 * 65536 * i);
168 video->cr_to_g_ptr[i] = (long)(-0.698 * 65536 * i);
169 video->cb_to_g_ptr[i] = (long)(-0.336 * 65536 * i);
170 video->cb_to_b_ptr[i] = (long)( 1.732 * 65536 * i);
173 return 0;
176 int mpeg3video_deletedecoder(mpeg3video_t *video)
178 int i, padding;
180 if(video->yuv_buffer[0]) free(video->yuv_buffer[0]);
181 if(video->yuv_buffer[1]) free(video->yuv_buffer[1]);
182 if(video->yuv_buffer[2]) free(video->yuv_buffer[2]);
184 if(video->subtitle_frame[0]) free(video->subtitle_frame[0]);
185 if(video->subtitle_frame[1]) free(video->subtitle_frame[1]);
186 if(video->subtitle_frame[2]) free(video->subtitle_frame[2]);
188 if(video->llframe0[0])
190 free(video->yuv_buffer[3]);
191 free(video->yuv_buffer[4]);
194 free(video->cr_to_r);
195 free(video->cr_to_g);
196 free(video->cb_to_g);
197 free(video->cb_to_b);
198 return 0;
201 void mpeg3video_init_scantables(mpeg3video_t *video)
204 video->mpeg3_zigzag_scan_table = mpeg3_zig_zag_scan_nommx;
205 video->mpeg3_alternate_scan_table = mpeg3_alternate_scan_nommx;
209 mpeg3video_t* mpeg3video_allocate_struct(mpeg3_t *file, mpeg3_vtrack_t *track)
211 int i;
212 mpeg3video_t *video = calloc(1, sizeof(mpeg3video_t));
213 pthread_mutexattr_t mutex_attr;
215 video->file = file;
216 video->track = track;
217 video->vstream = mpeg3bits_new_stream(file, track->demuxer);
218 //printf("mpeg3video_allocate_struct %d\n", mpeg3bits_eof(video->vstream));
219 video->last_number = -1;
221 /* First frame is all green */
222 video->framenum = -1;
224 video->byte_seek = -1;
225 video->frame_seek = -1;
227 mpeg3video_init_scantables(video);
228 mpeg3video_init_output();
230 pthread_mutexattr_init(&mutex_attr);
231 // pthread_mutexattr_setkind_np(&mutex_attr, PTHREAD_MUTEX_FAST_NP);
232 pthread_mutex_init(&(video->test_lock), &mutex_attr);
233 pthread_mutex_init(&(video->slice_lock), &mutex_attr);
234 return video;
237 int mpeg3video_delete_struct(mpeg3video_t *video)
239 int i;
240 mpeg3bits_delete_stream(video->vstream);
241 pthread_mutex_destroy(&(video->test_lock));
242 pthread_mutex_destroy(&(video->slice_lock));
243 if(video->x_table)
245 free(video->x_table);
246 free(video->y_table);
248 if(video->total_slice_decoders)
250 for(i = 0; i < video->total_slice_decoders; i++)
251 mpeg3_delete_slice_decoder(&(video->slice_decoders[i]));
253 for(i = 0; i < video->slice_buffers_initialized; i++)
254 mpeg3_delete_slice_buffer(&(video->slice_buffers[i]));
257 free(video);
258 return 0;
262 int mpeg3video_read_frame_backend(mpeg3video_t *video, int skip_bframes)
264 int result = 0;
265 int got_top = 0, got_bottom = 0;
266 int i = 0;
267 mpeg3_vtrack_t *track = video->track;
268 mpeg3_t *file = (mpeg3_t*)video->file;
270 //printf("mpeg3video_read_frame_backend 1\n");
274 if(mpeg3bits_eof(video->vstream)) result = 1;
276 if(!result) result = mpeg3video_get_header(video, 0);
279 /* skip_bframes is the number of bframes we can skip successfully. */
280 /* This is in case a skipped B-frame is repeated and the second repeat happens */
281 /* to be a B frame we need. */
282 video->skip_bframes = skip_bframes;
284 if(!result)
285 result = mpeg3video_getpicture(video, video->framenum);
288 if(video->pict_struct == TOP_FIELD)
290 got_top == 1;
292 else
293 if(video->pict_struct == BOTTOM_FIELD)
295 got_bottom = 1;
296 video->secondfield = 0;
298 else
299 if(video->pict_struct == FRAME_PICTURE)
301 got_top = got_bottom = 1;
304 i++;
305 }while(i < 2 &&
306 !got_bottom &&
307 video->framenum >= 0);
308 // The way they do field based encoding,
309 // the I frames have the top field but both the I frame and
310 // subsequent P frame are interlaced to make the keyframe.
314 //printf("mpeg3video_read_frame_backend 10\n");
316 // Composite subtitles
317 mpeg3_decode_subtitle(video);
322 if(!result)
324 video->last_number = video->framenum;
325 video->framenum++;
327 //printf("mpeg3video_read_frame_backend 100\n");
329 return result;
332 int* mpeg3video_get_scaletable(int input_w, int output_w)
334 int *result = malloc(sizeof(int) * output_w);
335 float i;
336 float scale = (float)input_w / output_w;
337 for(i = 0; i < output_w; i++)
339 result[(int)i] = (int)(scale * i);
341 return result;
344 /* Get the first I frame. */
345 int mpeg3video_get_firstframe(mpeg3video_t *video)
347 int result = 0;
348 video->repeat_count = video->current_repeat = 0;
349 result = mpeg3video_read_frame_backend(video, 0);
350 return result;
353 static long gop_to_frame(mpeg3video_t *video, mpeg3_timecode_t *gop_timecode)
355 int hour, minute, second, frame, fps;
356 long result;
358 // Mirror of what mpeg2enc does
359 fps = (int)(video->frame_rate + 0.5);
362 hour = gop_timecode->hour;
363 minute = gop_timecode->minute;
364 second = gop_timecode->second;
365 frame = gop_timecode->frame;
367 result = (long)hour * 60 * 60 * fps +
368 minute * 60 * fps +
369 second * fps +
370 frame;
372 return result;
376 /* ======================================================================= */
377 /* ENTRY POINTS */
378 /* ======================================================================= */
382 mpeg3video_t* mpeg3video_new(mpeg3_t *file,
383 mpeg3_vtrack_t *track)
385 mpeg3video_t *video;
386 mpeg3_bits_t *bitstream;
387 mpeg3_demuxer_t *demuxer;
388 int result = 0;
390 video = mpeg3video_allocate_struct(file, track);
391 bitstream = video->vstream;
392 demuxer = bitstream->demuxer;
394 // Get encoding parameters from stream
395 if(file->seekable)
397 result = mpeg3video_get_header(video, 1);
399 if(!result)
401 int hour, minute, second, frame;
402 int gop_found;
404 mpeg3video_initdecoder(video);
405 video->decoder_initted = 1;
406 track->width = video->horizontal_size;
407 track->height = video->vertical_size;
408 track->frame_rate = video->frame_rate;
410 /* Try to get the length of the file from GOP's */
411 if(!track->frame_offsets)
413 if(file->is_video_stream)
415 /* Load the first GOP */
416 mpeg3_rewind_video(video);
417 result = mpeg3video_next_code(bitstream,
418 MPEG3_GOP_START_CODE);
419 if(!result) mpeg3bits_getbits(bitstream, 32);
420 if(!result) result = mpeg3video_getgophdr(video);
422 hour = video->gop_timecode.hour;
423 minute = video->gop_timecode.minute;
424 second = video->gop_timecode.second;
425 frame = video->gop_timecode.frame;
427 video->first_frame = gop_to_frame(video, &video->gop_timecode);
430 * video->first_frame = (long)(hour * 3600 * video->frame_rate +
431 * minute * 60 * video->frame_rate +
432 * second * video->frame_rate +
433 * frame);
436 /* GOPs are supposed to have 16 frames */
438 video->frames_per_gop = 16;
440 /* Read the last GOP in the file by seeking backward. */
441 mpeg3demux_seek_byte(demuxer,
442 mpeg3demux_movie_size(demuxer));
443 mpeg3demux_start_reverse(demuxer);
444 result = mpeg3video_prev_code(demuxer,
445 MPEG3_GOP_START_CODE);
446 mpeg3demux_start_forward(demuxer);
450 mpeg3bits_reset(bitstream);
451 mpeg3bits_getbits(bitstream, 8);
452 if(!result) result = mpeg3video_getgophdr(video);
454 hour = video->gop_timecode.hour;
455 minute = video->gop_timecode.minute;
456 second = video->gop_timecode.second;
457 frame = video->gop_timecode.frame;
459 video->last_frame = gop_to_frame(video, &video->gop_timecode);
462 * video->last_frame = (long)((double)hour * 3600 * video->frame_rate +
463 * minute * 60 * video->frame_rate +
464 * second * video->frame_rate +
465 * frame);
468 //printf("mpeg3video_new 3 %p\n", video);
470 /* Count number of frames to end */
471 while(!result)
473 result = mpeg3video_next_code(bitstream, MPEG3_PICTURE_START_CODE);
474 if(!result)
476 mpeg3bits_getbyte_noptr(bitstream);
477 video->last_frame++;
481 track->total_frames = video->last_frame - video->first_frame + 1;
482 //printf("mpeg3video_new 3 %ld\n", track->total_frames);
483 mpeg3_rewind_video(video);
485 else
486 // Try to get the length of the file from the multiplexing.
487 // Need a table of contents
490 * video->first_frame = 0;
491 * track->total_frames = video->last_frame =
492 * (long)(mpeg3demux_length(video->vstream->demuxer) *
493 * video->frame_rate);
494 * video->first_frame = 0;
498 else
499 // Get length from table of contents
501 track->total_frames = track->total_frame_offsets;
506 video->maxframe = track->total_frames;
507 video->repeat_count = 0;
508 mpeg3_rewind_video(video);
509 mpeg3video_get_firstframe(video);
511 else
513 mpeg3video_delete(video);
514 video = 0;
518 return video;
521 int mpeg3video_delete(mpeg3video_t *video)
523 if(video->decoder_initted)
525 mpeg3video_deletedecoder(video);
527 mpeg3video_delete_struct(video);
528 return 0;
531 int mpeg3video_set_cpus(mpeg3video_t *video, int cpus)
533 return 0;
536 int mpeg3video_set_mmx(mpeg3video_t *video, int use_mmx)
538 mpeg3video_init_scantables(video);
539 return 0;
542 /* Read all the way up to and including the next picture start code */
543 int mpeg3video_read_raw(mpeg3video_t *video,
544 unsigned char *output,
545 long *size,
546 long max_size)
548 u_int32_t code = 0;
549 mpeg3_bits_t *vstream = video->vstream;
551 *size = 0;
552 while(code != MPEG3_PICTURE_START_CODE &&
553 code != MPEG3_SEQUENCE_END_CODE &&
554 *size < max_size &&
555 !mpeg3bits_eof(vstream))
557 code <<= 8;
558 *output = mpeg3bits_getbyte_noptr(vstream);
559 code |= *output++;
560 (*size)++;
562 return mpeg3bits_eof(vstream);
576 int mpeg3video_read_frame(mpeg3video_t *video,
577 unsigned char **output_rows,
578 int in_x,
579 int in_y,
580 int in_w,
581 int in_h,
582 int out_w,
583 int out_h,
584 int color_model)
586 int result = 0;
587 mpeg3_vtrack_t *track = video->track;
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);
619 //printf("mpeg3video_read_frame 1 %d\n", video->framenum);
622 // Recover from cache
623 unsigned char *y, *u, *v;
624 int frame_number = video->frame_seek >= 0 ? video->frame_seek : video->framenum;
625 if(mpeg3_cache_get_frame(track->frame_cache,
626 frame_number,
627 &y,
628 &u,
629 &v))
631 //printf("mpeg3video_read_frame 1 %d\n", frame_number);
632 // Swap output data for cache data
633 unsigned char *temp[3];
634 temp[0] = video->output_src[0];
635 temp[1] = video->output_src[1];
636 temp[2] = video->output_src[2];
638 video->output_src[0] = y;
639 video->output_src[1] = u;
640 video->output_src[2] = v;
641 // Transfer with cropping
642 if(video->output_src[0]) mpeg3video_present_frame(video);
643 video->output_src[0] = temp[0];
644 video->output_src[1] = temp[1];
645 video->output_src[2] = temp[2];
647 // Advance either framenum or frame_seek
648 if(frame_number == video->framenum)
649 video->framenum = ++frame_number;
650 else
651 if(frame_number == video->frame_seek)
652 video->frame_seek = ++frame_number;
654 else
657 // Only decode if it's a different frame
658 if(video->frame_seek < 0 ||
659 video->last_number < 0 ||
660 video->frame_seek != video->last_number)
662 if(!result) result = mpeg3video_seek(video);
663 if(!result) result = mpeg3video_read_frame_backend(video, 0);
665 else
667 video->framenum = video->frame_seek + 1;
668 video->last_number = video->frame_seek;
669 video->frame_seek = -1;
672 if(video->output_src[0]) mpeg3video_present_frame(video);
675 return result;
678 int mpeg3video_read_yuvframe(mpeg3video_t *video,
679 char *y_output,
680 char *u_output,
681 char *v_output,
682 int in_x,
683 int in_y,
684 int in_w,
685 int in_h)
687 int result = 0;
688 mpeg3_vtrack_t *track = video->track;
690 //printf("mpeg3video_read_yuvframe 1 %d\n", video->framenum);
691 video->want_yvu = 1;
692 video->y_output = y_output;
693 video->u_output = u_output;
694 video->v_output = v_output;
695 video->in_x = in_x;
696 video->in_y = in_y;
697 video->in_w = in_w;
698 video->in_h = in_h;
701 // Recover from cache if framenum exists
702 unsigned char *y, *u, *v;
703 int frame_number = video->frame_seek >= 0 ? video->frame_seek : video->framenum;
705 if(mpeg3_cache_get_frame(track->frame_cache, frame_number, &y, &u, &v))
707 int chroma_denominator;
708 int size0, size1;
711 //printf("mpeg3video_read_yuvframe 1 %d\n", frame_number);
712 if(video->chroma_format == CHROMA420)
713 chroma_denominator = 2;
714 else
715 chroma_denominator = 1;
716 size0 = video->coded_picture_width * video->in_h;
717 size1 = video->chrom_width * (int)((float)video->in_h / chroma_denominator + 0.5);
720 // Swap output data for cache data
721 unsigned char *temp[3];
722 temp[0] = video->output_src[0];
723 temp[1] = video->output_src[1];
724 temp[2] = video->output_src[2];
726 video->output_src[0] = y;
727 video->output_src[1] = u;
728 video->output_src[2] = v;
729 // Transfer with cropping
730 if(video->output_src[0]) mpeg3video_present_frame(video);
731 video->output_src[0] = temp[0];
732 video->output_src[1] = temp[1];
733 video->output_src[2] = temp[2];
735 // Advance either framenum or frame_seek
736 if(frame_number == video->framenum)
737 video->framenum = ++frame_number;
738 else
739 if(frame_number == video->frame_seek)
740 video->frame_seek = ++frame_number;
742 else
744 if(!result) result = mpeg3video_seek(video);
745 if(!result) result = mpeg3video_read_frame_backend(video, 0);
746 if(video->output_src[0]) mpeg3video_present_frame(video);
752 video->want_yvu = 0;
753 video->byte_seek = -1;
754 return result;
757 int mpeg3video_read_yuvframe_ptr(mpeg3video_t *video,
758 char **y_output,
759 char **u_output,
760 char **v_output)
762 int result = 0;
763 mpeg3_vtrack_t *track = video->track;
765 video->want_yvu = 1;
767 *y_output = *u_output = *v_output = 0;
769 unsigned char *y, *u, *v;
770 int frame_number = video->frame_seek >= 0 ? video->frame_seek : video->framenum;
771 if(mpeg3_cache_get_frame(track->frame_cache, frame_number, &y, &u, &v))
773 *y_output = (char*)y;
774 *u_output = (char*)u;
775 *v_output = (char*)v;
777 // Advance either framenum or frame_seek
778 if(frame_number == video->framenum)
779 video->framenum = ++frame_number;
780 else
781 if(frame_number == video->frame_seek)
782 video->frame_seek = ++frame_number;
784 else
785 // Only decode if it's a different frame
786 if(video->frame_seek < 0 ||
787 video->last_number < 0 ||
788 video->frame_seek != video->last_number)
790 if(!result) result = mpeg3video_seek(video);
791 if(!result) result = mpeg3video_read_frame_backend(video, 0);
793 if(video->output_src[0])
795 *y_output = (char*)video->output_src[0];
796 *u_output = (char*)video->output_src[1];
797 *v_output = (char*)video->output_src[2];
800 else
802 video->framenum = video->frame_seek + 1;
803 video->last_number = video->frame_seek;
804 video->frame_seek = -1;
806 if(video->output_src[0])
808 *y_output = (char*)video->output_src[0];
809 *u_output = (char*)video->output_src[1];
810 *v_output = (char*)video->output_src[2];
815 video->want_yvu = 0;
816 // Caching not used if byte seek
817 video->byte_seek = -1;
820 return result;
823 int mpeg3video_colormodel(mpeg3video_t *video)
825 switch(video->chroma_format)
827 case CHROMA422:
828 return MPEG3_YUV422P;
829 break;
831 case CHROMA420:
832 return MPEG3_YUV420P;
833 break;
836 return MPEG3_YUV420P;
839 void mpeg3video_dump(mpeg3video_t *video)
841 printf("mpeg3video_dump 1\n");
842 printf(" *** sequence extension 1\n");
843 printf("prog_seq=%d\n", video->prog_seq);
844 printf(" *** picture header 1\n");
845 printf("pict_type=%d field_sequence=%d\n", video->pict_type, video->field_sequence);
846 printf(" *** picture coding extension 1\n");
847 printf("field_sequence=%d repeatfirst=%d prog_frame=%d pict_struct=%d\n",
848 video->field_sequence,
849 video->repeatfirst,
850 video->prog_frame,
851 video->pict_struct);