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 &&
123 p_dec->fmt_in.i_codec != VLC_FOURCC('m','p','g','1') &&
124 /* Pinnacle hardware-mpeg1 */
125 p_dec->fmt_in.i_codec != VLC_FOURCC('P','I','M','1') &&
126 p_dec->fmt_in.i_codec != VLC_CODEC_MP2V &&
127 p_dec->fmt_in.i_codec != VLC_FOURCC('m','p','g','2') &&
128 p_dec->fmt_in.i_codec != VLC_FOURCC('h','d','v','2') )
133 /* Allocate the memory needed to store the decoder's structure */
134 if( ( p_dec->p_sys = p_sys = calloc( 1, sizeof(*p_sys)) ) == NULL )
137 /* Initialize the thread properties */
138 p_sys->p_mpeg2dec = NULL;
139 p_sys->p_synchro = NULL;
140 p_sys->p_info = NULL;
141 p_sys->i_current_pts = 0;
142 p_sys->i_previous_pts = 0;
143 p_sys->i_current_dts = 0;
144 p_sys->i_previous_dts = 0;
145 p_sys->p_picture_to_destroy = NULL;
146 p_sys->b_garbage_pic = 0;
147 p_sys->b_slice_i = 0;
148 p_sys->b_second_field = 0;
150 p_sys->b_preroll = false;
154 p_sys->i_cc_flags = 0;
155 #if MPEG2_RELEASE >= MPEG2_VERSION (0, 5, 0)
156 p_dec->pf_get_cc = GetCc;
157 cc_Init( &p_sys->cc );
159 p_sys->p_gop_user_data = NULL;
160 p_sys->i_gop_user_data = 0;
162 #if defined( __i386__ ) || defined( __x86_64__ )
163 if( vlc_CPU() & CPU_CAPABILITY_MMX )
165 i_accel |= MPEG2_ACCEL_X86_MMX;
168 if( vlc_CPU() & CPU_CAPABILITY_3DNOW )
170 i_accel |= MPEG2_ACCEL_X86_3DNOW;
173 if( vlc_CPU() & CPU_CAPABILITY_MMXEXT )
175 i_accel |= MPEG2_ACCEL_X86_MMXEXT;
178 #elif defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
179 if( vlc_CPU() & CPU_CAPABILITY_ALTIVEC )
181 i_accel |= MPEG2_ACCEL_PPC_ALTIVEC;
185 /* If we do not know this CPU, trust libmpeg2's feature detection */
186 i_accel = MPEG2_ACCEL_DETECT;
190 /* Set CPU acceleration features */
191 mpeg2_accel( i_accel );
193 /* Initialize decoder */
194 p_sys->p_mpeg2dec = mpeg2_init();
195 if( p_sys->p_mpeg2dec == NULL)
197 msg_Err( p_dec, "mpeg2_init() failed" );
202 p_sys->p_info = mpeg2_info( p_sys->p_mpeg2dec );
204 p_dec->pf_decode_video = DecodeBlock;
205 p_dec->fmt_out.i_cat = VIDEO_ES;
206 p_dec->fmt_out.i_codec = 0;
211 /*****************************************************************************
212 * RunDecoder: the libmpeg2 decoder
213 *****************************************************************************/
214 static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
216 decoder_sys_t *p_sys = p_dec->p_sys;
222 if( !pp_block || !*pp_block ) return NULL;
228 state = mpeg2_parse( p_sys->p_mpeg2dec );
233 if( !p_block->i_buffer )
235 block_Release( p_block );
238 if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY
239 | BLOCK_FLAG_CORRUPTED))
240 cc_Flush( &p_sys->cc );
242 if( (p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY
243 | BLOCK_FLAG_CORRUPTED)) &&
245 p_sys->p_info->sequence &&
246 p_sys->p_info->sequence->width != (unsigned)-1 )
248 decoder_SynchroReset( p_sys->p_synchro );
249 if( p_sys->p_info->current_fbuf != NULL
250 && p_sys->p_info->current_fbuf->id != NULL )
252 p_sys->b_garbage_pic = 1;
253 p_pic = p_sys->p_info->current_fbuf->id;
258 buf[0] = buf[1] = buf[2] = NULL;
259 if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
261 p_block->i_buffer = 0;
264 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
265 mpeg2_stride( p_sys->p_mpeg2dec, p_pic->p[Y_PLANE].i_pitch );
267 p_sys->p_picture_to_destroy = p_pic;
269 if ( p_sys->b_slice_i )
271 decoder_SynchroNewPicture( p_sys->p_synchro,
272 I_CODING_TYPE, 2, 0, 0,
273 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
274 decoder_SynchroDecode( p_sys->p_synchro );
275 decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
279 if( p_block->i_flags & BLOCK_FLAG_PREROLL )
281 p_sys->b_preroll = true;
283 else if( p_sys->b_preroll )
285 p_sys->b_preroll = false;
287 decoder_SynchroReset( p_sys->p_synchro );
293 mpeg2_pts( p_sys->p_mpeg2dec, (uint32_t)p_block->i_pts );
295 #else /* New interface */
296 if( p_block->i_pts || p_block->i_dts )
298 mpeg2_tag_picture( p_sys->p_mpeg2dec,
299 (uint32_t)p_block->i_pts,
300 (uint32_t)p_block->i_dts );
302 p_sys->i_previous_pts = p_sys->i_current_pts;
303 p_sys->i_current_pts = p_block->i_pts;
304 p_sys->i_previous_dts = p_sys->i_current_dts;
305 p_sys->i_current_dts = p_block->i_dts;
308 mpeg2_buffer( p_sys->p_mpeg2dec, p_block->p_buffer,
309 p_block->p_buffer + p_block->i_buffer );
311 p_block->i_buffer = 0;
314 #if MPEG2_RELEASE >= MPEG2_VERSION (0, 5, 0)
316 case STATE_SEQUENCE_MODIFIED:
323 /* Initialize video output */
325 buf[0] = buf[1] = buf[2] = NULL;
329 mpeg2_custom_fbuf( p_sys->p_mpeg2dec, 1 );
331 /* Set the first 2 reference frames */
332 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, NULL );
334 if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
336 block_Release( p_block );
340 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
341 mpeg2_stride( p_sys->p_mpeg2dec, p_pic->p[Y_PLANE].i_pitch );
343 /* This picture will never go through display_picture. */
346 /* For some reason, libmpeg2 will put this pic twice in
347 * discard_picture. This can be considered a bug in libmpeg2. */
348 decoder_LinkPicture( p_dec, p_pic );
350 if( p_sys->p_synchro )
352 decoder_SynchroRelease( p_sys->p_synchro );
354 p_sys->p_synchro = decoder_SynchroInit( p_dec,
355 (uint32_t)((uint64_t)1001000000 * 27 /
356 p_sys->p_info->sequence->frame_period) );
357 p_sys->b_after_sequence_header = 1;
361 case STATE_PICTURE_2ND:
362 p_sys->b_second_field = 1;
368 mtime_t i_pts, i_dts;
369 buf[0] = buf[1] = buf[2] = NULL;
371 if ( p_sys->b_after_sequence_header &&
372 ((p_sys->p_info->current_picture->flags &
373 PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P) )
375 /* Intra-slice refresh. Simulate a blank I picture. */
376 msg_Dbg( p_dec, "intra-slice refresh stream" );
377 decoder_SynchroNewPicture( p_sys->p_synchro,
378 I_CODING_TYPE, 2, 0, 0,
379 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
380 decoder_SynchroDecode( p_sys->p_synchro );
381 decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
382 p_sys->b_slice_i = 1;
384 p_sys->b_after_sequence_header = 0;
387 i_pts = p_sys->p_info->current_picture->flags & PIC_FLAG_PTS ?
388 ( ( p_sys->p_info->current_picture->pts ==
389 (uint32_t)p_sys->i_current_pts ) ?
390 p_sys->i_current_pts : p_sys->i_previous_pts ) : 0;
393 /* Hack to handle demuxers which only have DTS timestamps */
394 if( !i_pts && !p_block->i_pts && p_block->i_dts > 0 )
396 if( p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY ||
397 (p_sys->p_info->current_picture->flags &
398 PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B )
400 i_pts = p_block->i_dts;
403 p_block->i_pts = p_block->i_dts = 0;
406 #else /* New interface */
408 i_pts = p_sys->p_info->current_picture->flags & PIC_FLAG_TAGS ?
409 ( ( p_sys->p_info->current_picture->tag ==
410 (uint32_t)p_sys->i_current_pts ) ?
411 p_sys->i_current_pts : p_sys->i_previous_pts ) : 0;
412 i_dts = p_sys->p_info->current_picture->flags & PIC_FLAG_TAGS ?
413 ( ( p_sys->p_info->current_picture->tag2 ==
414 (uint32_t)p_sys->i_current_dts ) ?
415 p_sys->i_current_dts : p_sys->i_previous_dts ) : 0;
418 /* If nb_fields == 1, it is a field picture, and it will be
419 * followed by another field picture for which we won't call
420 * decoder_SynchroNewPicture() because this would have other
421 * problems, so we take it into account here.
422 * This kind of sucks, but I didn't think better. --Meuuh
424 decoder_SynchroNewPicture( p_sys->p_synchro,
425 p_sys->p_info->current_picture->flags & PIC_MASK_CODING_TYPE,
426 p_sys->p_info->current_picture->nb_fields == 1 ? 2 :
427 p_sys->p_info->current_picture->nb_fields, i_pts, i_dts,
428 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
432 if( !p_dec->b_pace_control && !p_sys->b_preroll &&
434 && ((p_sys->p_info->current_picture->flags
435 & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P))
436 && !decoder_SynchroChoose( p_sys->p_synchro,
437 p_sys->p_info->current_picture->flags
438 & PIC_MASK_CODING_TYPE,
439 /*p_sys->p_vout->render_time*/ 0 /*FIXME*/,
440 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY ) )
447 p_pic = GetNewPicture( p_dec, buf );
449 if( b_skip || !p_pic )
451 mpeg2_skip( p_sys->p_mpeg2dec, 1 );
453 decoder_SynchroTrash( p_sys->p_synchro );
454 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, NULL );
458 block_Release( p_block );
464 mpeg2_skip( p_sys->p_mpeg2dec, 0 );
466 decoder_SynchroDecode( p_sys->p_synchro );
468 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
469 mpeg2_stride( p_sys->p_mpeg2dec, p_pic->p[Y_PLANE].i_pitch );
471 if( p_sys->p_info->user_data_len > 2 || p_sys->i_gop_user_data > 2 )
473 p_sys->i_cc_pts = i_pts;
474 p_sys->i_cc_dts = i_dts;
475 if( (p_sys->p_info->current_picture->flags
476 & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P )
477 p_sys->i_cc_flags = BLOCK_FLAG_TYPE_P;
478 else if( (p_sys->p_info->current_picture->flags
479 & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B )
480 p_sys->i_cc_flags = BLOCK_FLAG_TYPE_B;
481 else p_sys->i_cc_flags = BLOCK_FLAG_TYPE_I;
483 if( p_sys->i_gop_user_data > 2 )
485 /* We now have picture info for any cached user_data out of the gop */
486 cc_Extract( &p_sys->cc, &p_sys->p_gop_user_data[0], p_sys->i_gop_user_data );
487 p_sys->i_gop_user_data = 0;
490 /* Extract the CC from the user_data of the picture */
491 if( p_sys->p_info->user_data_len > 2 )
492 cc_Extract( &p_sys->cc, &p_sys->p_info->user_data[0], p_sys->p_info->user_data_len );
498 /* There can be userdata in a GOP. It needs to be remembered for the next picture. */
499 if( p_sys->p_info->user_data_len > 2 )
501 free( p_sys->p_gop_user_data );
502 p_sys->p_gop_user_data = calloc( p_sys->p_info->user_data_len, sizeof(uint8_t) );
503 if( p_sys->p_gop_user_data )
505 p_sys->i_gop_user_data = p_sys->p_info->user_data_len;
506 memcpy( p_sys->p_gop_user_data, p_sys->p_info->user_data, p_sys->p_info->user_data_len );
514 if( p_sys->p_info->display_fbuf
515 && p_sys->p_info->display_fbuf->id )
517 p_pic = (picture_t *)p_sys->p_info->display_fbuf->id;
519 decoder_SynchroEnd( p_sys->p_synchro,
520 p_sys->p_info->display_picture->flags
521 & PIC_MASK_CODING_TYPE,
522 p_sys->b_garbage_pic );
523 p_sys->b_garbage_pic = 0;
525 if( p_sys->p_picture_to_destroy != p_pic )
527 p_pic->date = decoder_SynchroDate( p_sys->p_synchro );
531 p_sys->p_picture_to_destroy = NULL;
536 if( p_sys->p_info->discard_fbuf &&
537 p_sys->p_info->discard_fbuf->id )
539 decoder_UnlinkPicture( p_dec,
540 p_sys->p_info->discard_fbuf->id );
543 /* For still frames */
544 if( state == STATE_END && p_pic ) p_pic->b_force = true;
548 /* Avoid frames with identical timestamps.
549 * Especially needed for still frames in DVD menus. */
550 if( p_sys->i_last_frame_pts == p_pic->date ) p_pic->date++;
551 p_sys->i_last_frame_pts = p_pic->date;
560 buf[0] = buf[1] = buf[2] = NULL;
562 msg_Warn( p_dec, "invalid picture encountered" );
563 if ( ( p_sys->p_info->current_picture == NULL ) ||
564 ( ( p_sys->p_info->current_picture->flags &
565 PIC_MASK_CODING_TYPE) != PIC_FLAG_CODING_TYPE_B ) )
567 if( p_sys->p_synchro ) decoder_SynchroReset( p_sys->p_synchro );
569 mpeg2_skip( p_sys->p_mpeg2dec, 1 );
571 cc_Flush( &p_sys->cc );
573 if( p_sys->p_info->current_fbuf &&
574 p_sys->p_info->current_fbuf->id )
576 p_sys->b_garbage_pic = 1;
577 p_pic = p_sys->p_info->current_fbuf->id;
579 else if( !p_sys->p_info->sequence )
585 if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
587 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
588 mpeg2_stride( p_sys->p_mpeg2dec, p_pic->p[Y_PLANE].i_pitch );
590 p_sys->p_picture_to_destroy = p_pic;
592 memset( p_pic->p[0].p_pixels, 0,
593 p_sys->p_info->sequence->width
594 * p_sys->p_info->sequence->height );
595 memset( p_pic->p[1].p_pixels, 0x80,
596 p_sys->p_info->sequence->width
597 * p_sys->p_info->sequence->height / 4 );
598 memset( p_pic->p[2].p_pixels, 0x80,
599 p_sys->p_info->sequence->width
600 * p_sys->p_info->sequence->height / 4 );
602 if( p_sys->b_slice_i )
604 decoder_SynchroNewPicture( p_sys->p_synchro,
605 I_CODING_TYPE, 2, 0, 0,
606 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
607 decoder_SynchroDecode( p_sys->p_synchro );
608 decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
622 /*****************************************************************************
623 * CloseDecoder: libmpeg2 decoder destruction
624 *****************************************************************************/
625 static void CloseDecoder( vlc_object_t *p_this )
627 decoder_t *p_dec = (decoder_t *)p_this;
628 decoder_sys_t *p_sys = p_dec->p_sys;
630 free( p_sys->p_gop_user_data );
632 if( p_sys->p_synchro ) decoder_SynchroRelease( p_sys->p_synchro );
634 if( p_sys->p_mpeg2dec ) mpeg2_close( p_sys->p_mpeg2dec );
639 /*****************************************************************************
640 * GetNewPicture: Get a new picture from the vout and set the buf struct
641 *****************************************************************************/
642 static picture_t *GetNewPicture( decoder_t *p_dec, uint8_t **pp_buf )
644 decoder_sys_t *p_sys = p_dec->p_sys;
647 p_dec->fmt_out.video.i_width = p_sys->p_info->sequence->width;
648 p_dec->fmt_out.video.i_visible_width =
649 p_sys->p_info->sequence->picture_width;
650 p_dec->fmt_out.video.i_height = p_sys->p_info->sequence->height;
651 p_dec->fmt_out.video.i_visible_height =
652 p_sys->p_info->sequence->picture_height;
653 p_dec->fmt_out.video.i_aspect = p_sys->i_aspect;
654 p_dec->fmt_out.video.i_sar_num = p_sys->i_sar_num;
655 p_dec->fmt_out.video.i_sar_den = p_sys->i_sar_den;
657 if( p_sys->p_info->sequence->frame_period > 0 )
659 p_dec->fmt_out.video.i_frame_rate =
660 (uint32_t)( (uint64_t)1001000000 * 27 /
661 p_sys->p_info->sequence->frame_period );
662 p_dec->fmt_out.video.i_frame_rate_base = 1001;
665 p_dec->fmt_out.i_codec =
666 ( p_sys->p_info->sequence->chroma_height <
667 p_sys->p_info->sequence->height ) ?
668 VLC_CODEC_I420 : VLC_CODEC_I422;
670 /* Get a new picture */
671 p_pic = decoder_NewPicture( p_dec );
673 if( p_pic == NULL ) return NULL;
675 p_pic->b_progressive = p_sys->p_info->current_picture != NULL ?
676 p_sys->p_info->current_picture->flags & PIC_FLAG_PROGRESSIVE_FRAME : 1;
677 p_pic->b_top_field_first = p_sys->p_info->current_picture != NULL ?
678 p_sys->p_info->current_picture->flags & PIC_FLAG_TOP_FIELD_FIRST : 1;
679 p_pic->i_nb_fields = p_sys->p_info->current_picture != NULL ?
680 p_sys->p_info->current_picture->nb_fields : 2;
682 decoder_LinkPicture( p_dec, p_pic );
684 pp_buf[0] = p_pic->p[0].p_pixels;
685 pp_buf[1] = p_pic->p[1].p_pixels;
686 pp_buf[2] = p_pic->p[2].p_pixels;
691 /*****************************************************************************
692 * GetCc: Retrieves the Closed Captions for the CC decoder.
693 *****************************************************************************/
694 static block_t *GetCc( decoder_t *p_dec, bool pb_present[4] )
696 decoder_sys_t *p_sys = p_dec->p_sys;
697 block_t *p_cc = NULL;
700 for( i = 0; i < 4; i++ )
701 pb_present[i] = p_sys->cc.pb_present[i];
703 if( p_sys->cc.i_data <= 0 )
706 p_cc = block_New( p_dec, p_sys->cc.i_data);
709 memcpy( p_cc->p_buffer, p_sys->cc.p_data, p_sys->cc.i_data );
711 p_cc->i_pts = p_sys->cc.b_reorder ? p_sys->i_cc_pts : p_sys->i_cc_dts;
712 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);
714 cc_Flush( &p_sys->cc );
718 /*****************************************************************************
719 * GetAR: Get aspect ratio
720 *****************************************************************************/
721 static void GetAR( decoder_t *p_dec )
723 decoder_sys_t *p_sys = p_dec->p_sys;
725 /* Check whether the input gave a particular aspect ratio */
726 if( p_dec->fmt_in.video.i_aspect )
728 p_sys->i_aspect = p_dec->fmt_in.video.i_aspect;
732 /* Use the value provided in the MPEG sequence header */
733 if( p_sys->p_info->sequence->pixel_height > 0 )
736 ((uint64_t)p_sys->p_info->sequence->picture_width) *
737 p_sys->p_info->sequence->pixel_width *
739 p_sys->p_info->sequence->picture_height /
740 p_sys->p_info->sequence->pixel_height;
741 p_sys->i_sar_num = p_sys->p_info->sequence->pixel_width;
742 p_sys->i_sar_den = p_sys->p_info->sequence->pixel_height;
746 /* Invalid aspect, assume 4:3.
747 * This shouldn't happen and if it does it is a bug
748 * in libmpeg2 (likely triggered by an invalid stream) */
749 p_sys->i_aspect = VOUT_ASPECT_FACTOR * 4 / 3;
750 p_sys->i_sar_num = p_sys->p_info->sequence->picture_height * 4;
751 p_sys->i_sar_den = p_sys->p_info->sequence->picture_width * 3;
755 msg_Dbg( p_dec, "%dx%d (display %d,%d), aspect %d, sar %i:%i, %u.%03u fps",
756 p_sys->p_info->sequence->picture_width,
757 p_sys->p_info->sequence->picture_height,
758 p_sys->p_info->sequence->display_width,
759 p_sys->p_info->sequence->display_height,
760 p_sys->i_aspect, p_sys->i_sar_num, p_sys->i_sar_den,
761 (uint32_t)((uint64_t)1001000000 * 27 /
762 p_sys->p_info->sequence->frame_period / 1001),
763 (uint32_t)((uint64_t)1001000000 * 27 /
764 p_sys->p_info->sequence->frame_period % 1001) );