1 /*****************************************************************************
2 * libmpeg2.c: mpeg2 video decoder module making use of libmpeg2.
3 *****************************************************************************
4 * Copyright (C) 1999-2001 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
8 * Christophe Massiot <massiot@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
35 #include <vlc_codec.h>
36 #include <vlc_block_helper.h>
37 #include "../codec/cc.h"
41 #include <vlc_codec_synchro.h>
43 /*****************************************************************************
44 * decoder_sys_t : libmpeg2 decoder descriptor
45 *****************************************************************************/
51 mpeg2dec_t *p_mpeg2dec;
52 const mpeg2_info_t *p_info;
58 mtime_t i_previous_pts;
59 mtime_t i_current_pts;
60 mtime_t i_previous_dts;
61 mtime_t i_current_dts;
62 picture_t * p_picture_to_destroy;
64 bool b_after_sequence_header; /* is it the next frame after
65 * the sequence header ? */
66 bool b_slice_i; /* intra-slice refresh stream */
74 decoder_synchro_t *p_synchro;
78 mtime_t i_last_frame_pts;
80 /* Closed captioning support */
85 uint8_t *p_gop_user_data;
86 uint32_t i_gop_user_data;
89 /*****************************************************************************
91 *****************************************************************************/
92 static int OpenDecoder( vlc_object_t * );
93 static void CloseDecoder( vlc_object_t * );
95 static picture_t *DecodeBlock( decoder_t *, block_t ** );
96 static block_t *GetCc( decoder_t *p_dec, bool pb_present[4] );
98 static picture_t *GetNewPicture( decoder_t *, uint8_t ** );
99 static void GetAR( decoder_t *p_dec );
101 /*****************************************************************************
103 *****************************************************************************/
105 set_description( N_("MPEG I/II video decoder (using libmpeg2)") )
106 set_capability( "decoder", 150 )
107 set_category( CAT_INPUT )
108 set_subcategory( SUBCAT_INPUT_VCODEC )
109 set_callbacks( OpenDecoder, CloseDecoder )
110 add_shortcut( "libmpeg2" )
113 /*****************************************************************************
114 * OpenDecoder: probe the decoder and return score
115 *****************************************************************************/
116 static int OpenDecoder( vlc_object_t *p_this )
118 decoder_t *p_dec = (decoder_t*)p_this;
119 decoder_sys_t *p_sys;
120 uint32_t i_accel = 0;
122 if( p_dec->fmt_in.i_codec != VLC_CODEC_MPGV )
124 /* Select onl recognized original format (standard mpeg video) */
125 switch( p_dec->fmt_in.i_original_fourcc )
127 case VLC_FOURCC('m','p','g','1'):
128 case VLC_FOURCC('m','p','g','2'):
129 case VLC_FOURCC('m','p','g','v'):
130 case VLC_FOURCC('P','I','M','1'):
131 case VLC_FOURCC('h','d','v','2'):
134 if( p_dec->fmt_in.i_original_fourcc )
139 /* Allocate the memory needed to store the decoder's structure */
140 if( ( p_dec->p_sys = p_sys = calloc( 1, sizeof(*p_sys)) ) == NULL )
143 /* Initialize the thread properties */
144 p_sys->p_mpeg2dec = NULL;
145 p_sys->p_synchro = NULL;
146 p_sys->p_info = NULL;
147 p_sys->i_current_pts = 0;
148 p_sys->i_previous_pts = 0;
149 p_sys->i_current_dts = 0;
150 p_sys->i_previous_dts = 0;
151 p_sys->p_picture_to_destroy = NULL;
152 p_sys->b_garbage_pic = 0;
153 p_sys->b_slice_i = 0;
154 p_sys->b_second_field = 0;
156 p_sys->b_preroll = false;
160 p_sys->i_cc_flags = 0;
161 #if MPEG2_RELEASE >= MPEG2_VERSION (0, 5, 0)
162 p_dec->pf_get_cc = GetCc;
163 cc_Init( &p_sys->cc );
165 p_sys->p_gop_user_data = NULL;
166 p_sys->i_gop_user_data = 0;
168 #if defined( __i386__ ) || defined( __x86_64__ )
169 if( vlc_CPU() & CPU_CAPABILITY_MMX )
171 i_accel |= MPEG2_ACCEL_X86_MMX;
174 if( vlc_CPU() & CPU_CAPABILITY_3DNOW )
176 i_accel |= MPEG2_ACCEL_X86_3DNOW;
179 if( vlc_CPU() & CPU_CAPABILITY_MMXEXT )
181 i_accel |= MPEG2_ACCEL_X86_MMXEXT;
184 #elif defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
185 if( vlc_CPU() & CPU_CAPABILITY_ALTIVEC )
187 i_accel |= MPEG2_ACCEL_PPC_ALTIVEC;
191 /* If we do not know this CPU, trust libmpeg2's feature detection */
192 i_accel = MPEG2_ACCEL_DETECT;
196 /* Set CPU acceleration features */
197 mpeg2_accel( i_accel );
199 /* Initialize decoder */
200 p_sys->p_mpeg2dec = mpeg2_init();
201 if( p_sys->p_mpeg2dec == NULL)
203 msg_Err( p_dec, "mpeg2_init() failed" );
208 p_sys->p_info = mpeg2_info( p_sys->p_mpeg2dec );
210 p_dec->pf_decode_video = DecodeBlock;
211 p_dec->fmt_out.i_cat = VIDEO_ES;
212 p_dec->fmt_out.i_codec = 0;
217 /*****************************************************************************
218 * RunDecoder: the libmpeg2 decoder
219 *****************************************************************************/
220 static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
222 decoder_sys_t *p_sys = p_dec->p_sys;
228 if( !pp_block || !*pp_block ) return NULL;
234 state = mpeg2_parse( p_sys->p_mpeg2dec );
239 if( !p_block->i_buffer )
241 block_Release( p_block );
244 if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY
245 | BLOCK_FLAG_CORRUPTED))
246 cc_Flush( &p_sys->cc );
248 if( (p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY
249 | BLOCK_FLAG_CORRUPTED)) &&
251 p_sys->p_info->sequence &&
252 p_sys->p_info->sequence->width != (unsigned)-1 )
254 decoder_SynchroReset( p_sys->p_synchro );
255 if( p_sys->p_info->current_fbuf != NULL
256 && p_sys->p_info->current_fbuf->id != NULL )
258 p_sys->b_garbage_pic = 1;
259 p_pic = p_sys->p_info->current_fbuf->id;
264 buf[0] = buf[1] = buf[2] = NULL;
265 if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
267 p_block->i_buffer = 0;
270 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
271 mpeg2_stride( p_sys->p_mpeg2dec, p_pic->p[Y_PLANE].i_pitch );
273 p_sys->p_picture_to_destroy = p_pic;
275 if ( p_sys->b_slice_i )
277 decoder_SynchroNewPicture( p_sys->p_synchro,
278 I_CODING_TYPE, 2, 0, 0,
279 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
280 decoder_SynchroDecode( p_sys->p_synchro );
281 decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
285 if( p_block->i_flags & BLOCK_FLAG_PREROLL )
287 p_sys->b_preroll = true;
289 else if( p_sys->b_preroll )
291 p_sys->b_preroll = false;
293 decoder_SynchroReset( p_sys->p_synchro );
299 mpeg2_pts( p_sys->p_mpeg2dec, (uint32_t)p_block->i_pts );
301 #else /* New interface */
302 if( p_block->i_pts || p_block->i_dts )
304 mpeg2_tag_picture( p_sys->p_mpeg2dec,
305 (uint32_t)p_block->i_pts,
306 (uint32_t)p_block->i_dts );
308 p_sys->i_previous_pts = p_sys->i_current_pts;
309 p_sys->i_current_pts = p_block->i_pts;
310 p_sys->i_previous_dts = p_sys->i_current_dts;
311 p_sys->i_current_dts = p_block->i_dts;
314 mpeg2_buffer( p_sys->p_mpeg2dec, p_block->p_buffer,
315 p_block->p_buffer + p_block->i_buffer );
317 p_block->i_buffer = 0;
320 #if MPEG2_RELEASE >= MPEG2_VERSION (0, 5, 0)
322 case STATE_SEQUENCE_MODIFIED:
329 /* Initialize video output */
331 buf[0] = buf[1] = buf[2] = NULL;
335 mpeg2_custom_fbuf( p_sys->p_mpeg2dec, 1 );
337 /* Set the first 2 reference frames */
338 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, NULL );
340 if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
342 block_Release( p_block );
346 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
347 mpeg2_stride( p_sys->p_mpeg2dec, p_pic->p[Y_PLANE].i_pitch );
349 /* This picture will never go through display_picture. */
352 /* For some reason, libmpeg2 will put this pic twice in
353 * discard_picture. This can be considered a bug in libmpeg2. */
354 decoder_LinkPicture( p_dec, p_pic );
356 if( p_sys->p_synchro )
358 decoder_SynchroRelease( p_sys->p_synchro );
360 p_sys->p_synchro = decoder_SynchroInit( p_dec,
361 (uint32_t)((uint64_t)1001000000 * 27 /
362 p_sys->p_info->sequence->frame_period) );
363 p_sys->b_after_sequence_header = 1;
367 case STATE_PICTURE_2ND:
368 p_sys->b_second_field = 1;
374 mtime_t i_pts, i_dts;
375 buf[0] = buf[1] = buf[2] = NULL;
377 if ( p_sys->b_after_sequence_header &&
378 ((p_sys->p_info->current_picture->flags &
379 PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P) )
381 /* Intra-slice refresh. Simulate a blank I picture. */
382 msg_Dbg( p_dec, "intra-slice refresh stream" );
383 decoder_SynchroNewPicture( p_sys->p_synchro,
384 I_CODING_TYPE, 2, 0, 0,
385 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
386 decoder_SynchroDecode( p_sys->p_synchro );
387 decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
388 p_sys->b_slice_i = 1;
390 p_sys->b_after_sequence_header = 0;
393 i_pts = p_sys->p_info->current_picture->flags & PIC_FLAG_PTS ?
394 ( ( p_sys->p_info->current_picture->pts ==
395 (uint32_t)p_sys->i_current_pts ) ?
396 p_sys->i_current_pts : p_sys->i_previous_pts ) : 0;
399 /* Hack to handle demuxers which only have DTS timestamps */
400 if( !i_pts && !p_block->i_pts && p_block->i_dts > 0 )
402 if( p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY ||
403 (p_sys->p_info->current_picture->flags &
404 PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B )
406 i_pts = p_block->i_dts;
409 p_block->i_pts = p_block->i_dts = 0;
412 #else /* New interface */
414 i_pts = p_sys->p_info->current_picture->flags & PIC_FLAG_TAGS ?
415 ( ( p_sys->p_info->current_picture->tag ==
416 (uint32_t)p_sys->i_current_pts ) ?
417 p_sys->i_current_pts : p_sys->i_previous_pts ) : 0;
418 i_dts = p_sys->p_info->current_picture->flags & PIC_FLAG_TAGS ?
419 ( ( p_sys->p_info->current_picture->tag2 ==
420 (uint32_t)p_sys->i_current_dts ) ?
421 p_sys->i_current_dts : p_sys->i_previous_dts ) : 0;
424 /* If nb_fields == 1, it is a field picture, and it will be
425 * followed by another field picture for which we won't call
426 * decoder_SynchroNewPicture() because this would have other
427 * problems, so we take it into account here.
428 * This kind of sucks, but I didn't think better. --Meuuh
430 decoder_SynchroNewPicture( p_sys->p_synchro,
431 p_sys->p_info->current_picture->flags & PIC_MASK_CODING_TYPE,
432 p_sys->p_info->current_picture->nb_fields == 1 ? 2 :
433 p_sys->p_info->current_picture->nb_fields, i_pts, i_dts,
434 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
438 if( !p_dec->b_pace_control && !p_sys->b_preroll &&
440 && ((p_sys->p_info->current_picture->flags
441 & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P))
442 && !decoder_SynchroChoose( p_sys->p_synchro,
443 p_sys->p_info->current_picture->flags
444 & PIC_MASK_CODING_TYPE,
445 /*p_sys->p_vout->render_time*/ 0 /*FIXME*/,
446 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY ) )
453 p_pic = GetNewPicture( p_dec, buf );
455 if( b_skip || !p_pic )
457 mpeg2_skip( p_sys->p_mpeg2dec, 1 );
459 decoder_SynchroTrash( p_sys->p_synchro );
460 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, NULL );
464 block_Release( p_block );
470 mpeg2_skip( p_sys->p_mpeg2dec, 0 );
472 decoder_SynchroDecode( p_sys->p_synchro );
474 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
475 mpeg2_stride( p_sys->p_mpeg2dec, p_pic->p[Y_PLANE].i_pitch );
477 if( p_sys->p_info->user_data_len > 2 || p_sys->i_gop_user_data > 2 )
479 p_sys->i_cc_pts = i_pts;
480 p_sys->i_cc_dts = i_dts;
481 if( (p_sys->p_info->current_picture->flags
482 & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P )
483 p_sys->i_cc_flags = BLOCK_FLAG_TYPE_P;
484 else if( (p_sys->p_info->current_picture->flags
485 & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B )
486 p_sys->i_cc_flags = BLOCK_FLAG_TYPE_B;
487 else p_sys->i_cc_flags = BLOCK_FLAG_TYPE_I;
489 if( p_sys->i_gop_user_data > 2 )
491 /* We now have picture info for any cached user_data out of the gop */
492 cc_Extract( &p_sys->cc, &p_sys->p_gop_user_data[0], p_sys->i_gop_user_data );
493 p_sys->i_gop_user_data = 0;
496 /* Extract the CC from the user_data of the picture */
497 if( p_sys->p_info->user_data_len > 2 )
498 cc_Extract( &p_sys->cc, &p_sys->p_info->user_data[0], p_sys->p_info->user_data_len );
504 /* There can be userdata in a GOP. It needs to be remembered for the next picture. */
505 if( p_sys->p_info->user_data_len > 2 )
507 free( p_sys->p_gop_user_data );
508 p_sys->p_gop_user_data = calloc( p_sys->p_info->user_data_len, sizeof(uint8_t) );
509 if( p_sys->p_gop_user_data )
511 p_sys->i_gop_user_data = p_sys->p_info->user_data_len;
512 memcpy( p_sys->p_gop_user_data, p_sys->p_info->user_data, p_sys->p_info->user_data_len );
520 if( p_sys->p_info->display_fbuf
521 && p_sys->p_info->display_fbuf->id )
523 p_pic = (picture_t *)p_sys->p_info->display_fbuf->id;
525 decoder_SynchroEnd( p_sys->p_synchro,
526 p_sys->p_info->display_picture->flags
527 & PIC_MASK_CODING_TYPE,
528 p_sys->b_garbage_pic );
529 p_sys->b_garbage_pic = 0;
531 if( p_sys->p_picture_to_destroy != p_pic )
533 p_pic->date = decoder_SynchroDate( p_sys->p_synchro );
537 p_sys->p_picture_to_destroy = NULL;
542 if( p_sys->p_info->discard_fbuf &&
543 p_sys->p_info->discard_fbuf->id )
545 decoder_UnlinkPicture( p_dec,
546 p_sys->p_info->discard_fbuf->id );
549 /* For still frames */
550 if( state == STATE_END && p_pic ) p_pic->b_force = true;
554 /* Avoid frames with identical timestamps.
555 * Especially needed for still frames in DVD menus. */
556 if( p_sys->i_last_frame_pts == p_pic->date ) p_pic->date++;
557 p_sys->i_last_frame_pts = p_pic->date;
566 buf[0] = buf[1] = buf[2] = NULL;
568 msg_Warn( p_dec, "invalid picture encountered" );
569 if ( ( p_sys->p_info->current_picture == NULL ) ||
570 ( ( p_sys->p_info->current_picture->flags &
571 PIC_MASK_CODING_TYPE) != PIC_FLAG_CODING_TYPE_B ) )
573 if( p_sys->p_synchro ) decoder_SynchroReset( p_sys->p_synchro );
575 mpeg2_skip( p_sys->p_mpeg2dec, 1 );
577 cc_Flush( &p_sys->cc );
579 if( p_sys->p_info->current_fbuf &&
580 p_sys->p_info->current_fbuf->id )
582 p_sys->b_garbage_pic = 1;
583 p_pic = p_sys->p_info->current_fbuf->id;
585 else if( !p_sys->p_info->sequence )
591 if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
593 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
594 mpeg2_stride( p_sys->p_mpeg2dec, p_pic->p[Y_PLANE].i_pitch );
596 p_sys->p_picture_to_destroy = p_pic;
598 memset( p_pic->p[0].p_pixels, 0,
599 p_sys->p_info->sequence->width
600 * p_sys->p_info->sequence->height );
601 memset( p_pic->p[1].p_pixels, 0x80,
602 p_sys->p_info->sequence->width
603 * p_sys->p_info->sequence->height / 4 );
604 memset( p_pic->p[2].p_pixels, 0x80,
605 p_sys->p_info->sequence->width
606 * p_sys->p_info->sequence->height / 4 );
608 if( p_sys->b_slice_i )
610 decoder_SynchroNewPicture( p_sys->p_synchro,
611 I_CODING_TYPE, 2, 0, 0,
612 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
613 decoder_SynchroDecode( p_sys->p_synchro );
614 decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
628 /*****************************************************************************
629 * CloseDecoder: libmpeg2 decoder destruction
630 *****************************************************************************/
631 static void CloseDecoder( vlc_object_t *p_this )
633 decoder_t *p_dec = (decoder_t *)p_this;
634 decoder_sys_t *p_sys = p_dec->p_sys;
636 free( p_sys->p_gop_user_data );
638 if( p_sys->p_synchro ) decoder_SynchroRelease( p_sys->p_synchro );
640 if( p_sys->p_mpeg2dec ) mpeg2_close( p_sys->p_mpeg2dec );
645 /*****************************************************************************
646 * GetNewPicture: Get a new picture from the vout and set the buf struct
647 *****************************************************************************/
648 static picture_t *GetNewPicture( decoder_t *p_dec, uint8_t **pp_buf )
650 decoder_sys_t *p_sys = p_dec->p_sys;
653 p_dec->fmt_out.video.i_width = p_sys->p_info->sequence->width;
654 p_dec->fmt_out.video.i_visible_width =
655 p_sys->p_info->sequence->picture_width;
656 p_dec->fmt_out.video.i_height = p_sys->p_info->sequence->height;
657 p_dec->fmt_out.video.i_visible_height =
658 p_sys->p_info->sequence->picture_height;
659 p_dec->fmt_out.video.i_aspect = p_sys->i_aspect;
660 p_dec->fmt_out.video.i_sar_num = p_sys->i_sar_num;
661 p_dec->fmt_out.video.i_sar_den = p_sys->i_sar_den;
663 if( p_sys->p_info->sequence->frame_period > 0 )
665 p_dec->fmt_out.video.i_frame_rate =
666 (uint32_t)( (uint64_t)1001000000 * 27 /
667 p_sys->p_info->sequence->frame_period );
668 p_dec->fmt_out.video.i_frame_rate_base = 1001;
671 p_dec->fmt_out.i_codec =
672 ( p_sys->p_info->sequence->chroma_height <
673 p_sys->p_info->sequence->height ) ?
674 VLC_CODEC_I420 : VLC_CODEC_I422;
676 /* Get a new picture */
677 p_pic = decoder_NewPicture( p_dec );
679 if( p_pic == NULL ) return NULL;
681 p_pic->b_progressive = p_sys->p_info->current_picture != NULL ?
682 p_sys->p_info->current_picture->flags & PIC_FLAG_PROGRESSIVE_FRAME : 1;
683 p_pic->b_top_field_first = p_sys->p_info->current_picture != NULL ?
684 p_sys->p_info->current_picture->flags & PIC_FLAG_TOP_FIELD_FIRST : 1;
685 p_pic->i_nb_fields = p_sys->p_info->current_picture != NULL ?
686 p_sys->p_info->current_picture->nb_fields : 2;
688 decoder_LinkPicture( p_dec, p_pic );
690 pp_buf[0] = p_pic->p[0].p_pixels;
691 pp_buf[1] = p_pic->p[1].p_pixels;
692 pp_buf[2] = p_pic->p[2].p_pixels;
697 /*****************************************************************************
698 * GetCc: Retrieves the Closed Captions for the CC decoder.
699 *****************************************************************************/
700 static block_t *GetCc( decoder_t *p_dec, bool pb_present[4] )
702 decoder_sys_t *p_sys = p_dec->p_sys;
703 block_t *p_cc = NULL;
706 for( i = 0; i < 4; i++ )
707 pb_present[i] = p_sys->cc.pb_present[i];
709 if( p_sys->cc.i_data <= 0 )
712 p_cc = block_New( p_dec, p_sys->cc.i_data);
715 memcpy( p_cc->p_buffer, p_sys->cc.p_data, p_sys->cc.i_data );
717 p_cc->i_pts = p_sys->cc.b_reorder ? p_sys->i_cc_pts : p_sys->i_cc_dts;
718 p_cc->i_flags = ( p_sys->cc.b_reorder ? p_sys->i_cc_flags : BLOCK_FLAG_TYPE_P ) & ( BLOCK_FLAG_TYPE_I|BLOCK_FLAG_TYPE_P|BLOCK_FLAG_TYPE_B);
720 cc_Flush( &p_sys->cc );
724 /*****************************************************************************
725 * GetAR: Get aspect ratio
726 *****************************************************************************/
727 static void GetAR( decoder_t *p_dec )
729 decoder_sys_t *p_sys = p_dec->p_sys;
731 /* Check whether the input gave a particular aspect ratio */
732 if( p_dec->fmt_in.video.i_aspect )
734 p_sys->i_aspect = p_dec->fmt_in.video.i_aspect;
738 /* Use the value provided in the MPEG sequence header */
739 if( p_sys->p_info->sequence->pixel_height > 0 )
742 ((uint64_t)p_sys->p_info->sequence->picture_width) *
743 p_sys->p_info->sequence->pixel_width *
745 p_sys->p_info->sequence->picture_height /
746 p_sys->p_info->sequence->pixel_height;
747 p_sys->i_sar_num = p_sys->p_info->sequence->pixel_width;
748 p_sys->i_sar_den = p_sys->p_info->sequence->pixel_height;
752 /* Invalid aspect, assume 4:3.
753 * This shouldn't happen and if it does it is a bug
754 * in libmpeg2 (likely triggered by an invalid stream) */
755 p_sys->i_aspect = VOUT_ASPECT_FACTOR * 4 / 3;
756 p_sys->i_sar_num = p_sys->p_info->sequence->picture_height * 4;
757 p_sys->i_sar_den = p_sys->p_info->sequence->picture_width * 3;
761 msg_Dbg( p_dec, "%dx%d (display %d,%d), aspect %d, sar %i:%i, %u.%03u fps",
762 p_sys->p_info->sequence->picture_width,
763 p_sys->p_info->sequence->picture_height,
764 p_sys->p_info->sequence->display_width,
765 p_sys->p_info->sequence->display_height,
766 p_sys->i_aspect, p_sys->i_sar_num, p_sys->i_sar_den,
767 (uint32_t)((uint64_t)1001000000 * 27 /
768 p_sys->p_info->sequence->frame_period / 1001),
769 (uint32_t)((uint64_t)1001000000 * 27 /
770 p_sys->p_info->sequence->frame_period % 1001) );