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_MP1V &&
123 p_dec->fmt_in.i_codec != VLC_CODEC_MP2V &&
124 p_dec->fmt_in.i_codec != VLC_CODEC_MPGV )
127 /* Select onl recognized original format (standard mpeg video) */
128 switch( p_dec->fmt_in.i_original_fourcc )
130 case VLC_FOURCC('m','p','g','1'):
131 case VLC_FOURCC('m','p','g','2'):
132 case VLC_FOURCC('m','p','g','v'):
133 case VLC_FOURCC('P','I','M','1'):
134 case VLC_FOURCC('h','d','v','2'):
137 if( p_dec->fmt_in.i_original_fourcc )
142 /* Allocate the memory needed to store the decoder's structure */
143 if( ( p_dec->p_sys = p_sys = calloc( 1, sizeof(*p_sys)) ) == NULL )
146 /* Initialize the thread properties */
147 p_sys->p_mpeg2dec = NULL;
148 p_sys->p_synchro = NULL;
149 p_sys->p_info = NULL;
150 p_sys->i_current_pts = 0;
151 p_sys->i_previous_pts = 0;
152 p_sys->i_current_dts = 0;
153 p_sys->i_previous_dts = 0;
154 p_sys->p_picture_to_destroy = NULL;
155 p_sys->b_garbage_pic = 0;
156 p_sys->b_slice_i = 0;
157 p_sys->b_second_field = 0;
159 p_sys->b_preroll = false;
163 p_sys->i_cc_flags = 0;
164 #if MPEG2_RELEASE >= MPEG2_VERSION (0, 5, 0)
165 p_dec->pf_get_cc = GetCc;
166 cc_Init( &p_sys->cc );
168 p_sys->p_gop_user_data = NULL;
169 p_sys->i_gop_user_data = 0;
171 #if defined( __i386__ ) || defined( __x86_64__ )
172 if( vlc_CPU() & CPU_CAPABILITY_MMX )
174 i_accel |= MPEG2_ACCEL_X86_MMX;
177 if( vlc_CPU() & CPU_CAPABILITY_3DNOW )
179 i_accel |= MPEG2_ACCEL_X86_3DNOW;
182 if( vlc_CPU() & CPU_CAPABILITY_MMXEXT )
184 i_accel |= MPEG2_ACCEL_X86_MMXEXT;
187 #elif defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
188 if( vlc_CPU() & CPU_CAPABILITY_ALTIVEC )
190 i_accel |= MPEG2_ACCEL_PPC_ALTIVEC;
194 /* If we do not know this CPU, trust libmpeg2's feature detection */
195 i_accel = MPEG2_ACCEL_DETECT;
199 /* Set CPU acceleration features */
200 mpeg2_accel( i_accel );
202 /* Initialize decoder */
203 p_sys->p_mpeg2dec = mpeg2_init();
204 if( p_sys->p_mpeg2dec == NULL)
206 msg_Err( p_dec, "mpeg2_init() failed" );
211 p_sys->p_info = mpeg2_info( p_sys->p_mpeg2dec );
213 p_dec->pf_decode_video = DecodeBlock;
214 p_dec->fmt_out.i_cat = VIDEO_ES;
215 p_dec->fmt_out.i_codec = 0;
220 /*****************************************************************************
221 * RunDecoder: the libmpeg2 decoder
222 *****************************************************************************/
223 static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
225 decoder_sys_t *p_sys = p_dec->p_sys;
231 if( !pp_block || !*pp_block ) return NULL;
237 state = mpeg2_parse( p_sys->p_mpeg2dec );
242 if( !p_block->i_buffer )
244 block_Release( p_block );
247 if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY
248 | BLOCK_FLAG_CORRUPTED))
249 cc_Flush( &p_sys->cc );
251 if( (p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY
252 | BLOCK_FLAG_CORRUPTED)) &&
254 p_sys->p_info->sequence &&
255 p_sys->p_info->sequence->width != (unsigned)-1 )
257 decoder_SynchroReset( p_sys->p_synchro );
258 if( p_sys->p_info->current_fbuf != NULL
259 && p_sys->p_info->current_fbuf->id != NULL )
261 p_sys->b_garbage_pic = 1;
262 p_pic = p_sys->p_info->current_fbuf->id;
267 buf[0] = buf[1] = buf[2] = NULL;
268 if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
270 p_block->i_buffer = 0;
273 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
274 mpeg2_stride( p_sys->p_mpeg2dec, p_pic->p[Y_PLANE].i_pitch );
276 p_sys->p_picture_to_destroy = p_pic;
278 if ( p_sys->b_slice_i )
280 decoder_SynchroNewPicture( p_sys->p_synchro,
281 I_CODING_TYPE, 2, 0, 0,
282 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
283 decoder_SynchroDecode( p_sys->p_synchro );
284 decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
288 if( p_block->i_flags & BLOCK_FLAG_PREROLL )
290 p_sys->b_preroll = true;
292 else if( p_sys->b_preroll )
294 p_sys->b_preroll = false;
296 decoder_SynchroReset( p_sys->p_synchro );
302 mpeg2_pts( p_sys->p_mpeg2dec, (uint32_t)p_block->i_pts );
304 #else /* New interface */
305 if( p_block->i_pts || p_block->i_dts )
307 mpeg2_tag_picture( p_sys->p_mpeg2dec,
308 (uint32_t)p_block->i_pts,
309 (uint32_t)p_block->i_dts );
311 p_sys->i_previous_pts = p_sys->i_current_pts;
312 p_sys->i_current_pts = p_block->i_pts;
313 p_sys->i_previous_dts = p_sys->i_current_dts;
314 p_sys->i_current_dts = p_block->i_dts;
317 mpeg2_buffer( p_sys->p_mpeg2dec, p_block->p_buffer,
318 p_block->p_buffer + p_block->i_buffer );
320 p_block->i_buffer = 0;
323 #if MPEG2_RELEASE >= MPEG2_VERSION (0, 5, 0)
325 case STATE_SEQUENCE_MODIFIED:
332 /* Initialize video output */
334 buf[0] = buf[1] = buf[2] = NULL;
338 mpeg2_custom_fbuf( p_sys->p_mpeg2dec, 1 );
340 /* Set the first 2 reference frames */
341 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, NULL );
343 if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
345 block_Release( p_block );
349 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
350 mpeg2_stride( p_sys->p_mpeg2dec, p_pic->p[Y_PLANE].i_pitch );
352 /* This picture will never go through display_picture. */
355 /* For some reason, libmpeg2 will put this pic twice in
356 * discard_picture. This can be considered a bug in libmpeg2. */
357 decoder_LinkPicture( p_dec, p_pic );
359 if( p_sys->p_synchro )
361 decoder_SynchroRelease( p_sys->p_synchro );
363 p_sys->p_synchro = decoder_SynchroInit( p_dec,
364 (uint32_t)((uint64_t)1001000000 * 27 /
365 p_sys->p_info->sequence->frame_period) );
366 p_sys->b_after_sequence_header = 1;
370 case STATE_PICTURE_2ND:
371 p_sys->b_second_field = 1;
377 mtime_t i_pts, i_dts;
378 buf[0] = buf[1] = buf[2] = NULL;
380 if ( p_sys->b_after_sequence_header &&
381 ((p_sys->p_info->current_picture->flags &
382 PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P) )
384 /* Intra-slice refresh. Simulate a blank I picture. */
385 msg_Dbg( p_dec, "intra-slice refresh stream" );
386 decoder_SynchroNewPicture( p_sys->p_synchro,
387 I_CODING_TYPE, 2, 0, 0,
388 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
389 decoder_SynchroDecode( p_sys->p_synchro );
390 decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
391 p_sys->b_slice_i = 1;
393 p_sys->b_after_sequence_header = 0;
396 i_pts = p_sys->p_info->current_picture->flags & PIC_FLAG_PTS ?
397 ( ( p_sys->p_info->current_picture->pts ==
398 (uint32_t)p_sys->i_current_pts ) ?
399 p_sys->i_current_pts : p_sys->i_previous_pts ) : 0;
402 /* Hack to handle demuxers which only have DTS timestamps */
403 if( !i_pts && !p_block->i_pts && p_block->i_dts > 0 )
405 if( p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY ||
406 (p_sys->p_info->current_picture->flags &
407 PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B )
409 i_pts = p_block->i_dts;
412 p_block->i_pts = p_block->i_dts = 0;
415 #else /* New interface */
417 i_pts = p_sys->p_info->current_picture->flags & PIC_FLAG_TAGS ?
418 ( ( p_sys->p_info->current_picture->tag ==
419 (uint32_t)p_sys->i_current_pts ) ?
420 p_sys->i_current_pts : p_sys->i_previous_pts ) : 0;
421 i_dts = p_sys->p_info->current_picture->flags & PIC_FLAG_TAGS ?
422 ( ( p_sys->p_info->current_picture->tag2 ==
423 (uint32_t)p_sys->i_current_dts ) ?
424 p_sys->i_current_dts : p_sys->i_previous_dts ) : 0;
427 /* If nb_fields == 1, it is a field picture, and it will be
428 * followed by another field picture for which we won't call
429 * decoder_SynchroNewPicture() because this would have other
430 * problems, so we take it into account here.
431 * This kind of sucks, but I didn't think better. --Meuuh
433 decoder_SynchroNewPicture( p_sys->p_synchro,
434 p_sys->p_info->current_picture->flags & PIC_MASK_CODING_TYPE,
435 p_sys->p_info->current_picture->nb_fields == 1 ? 2 :
436 p_sys->p_info->current_picture->nb_fields, i_pts, i_dts,
437 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
441 if( !p_dec->b_pace_control && !p_sys->b_preroll &&
443 && ((p_sys->p_info->current_picture->flags
444 & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P))
445 && !decoder_SynchroChoose( p_sys->p_synchro,
446 p_sys->p_info->current_picture->flags
447 & PIC_MASK_CODING_TYPE,
448 /*p_sys->p_vout->render_time*/ 0 /*FIXME*/,
449 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY ) )
456 p_pic = GetNewPicture( p_dec, buf );
458 if( b_skip || !p_pic )
460 mpeg2_skip( p_sys->p_mpeg2dec, 1 );
462 decoder_SynchroTrash( p_sys->p_synchro );
463 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, NULL );
467 block_Release( p_block );
473 mpeg2_skip( p_sys->p_mpeg2dec, 0 );
475 decoder_SynchroDecode( p_sys->p_synchro );
477 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
478 mpeg2_stride( p_sys->p_mpeg2dec, p_pic->p[Y_PLANE].i_pitch );
480 if( p_sys->p_info->user_data_len > 2 || p_sys->i_gop_user_data > 2 )
482 p_sys->i_cc_pts = i_pts;
483 p_sys->i_cc_dts = i_dts;
484 if( (p_sys->p_info->current_picture->flags
485 & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_P )
486 p_sys->i_cc_flags = BLOCK_FLAG_TYPE_P;
487 else if( (p_sys->p_info->current_picture->flags
488 & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B )
489 p_sys->i_cc_flags = BLOCK_FLAG_TYPE_B;
490 else p_sys->i_cc_flags = BLOCK_FLAG_TYPE_I;
492 if( p_sys->i_gop_user_data > 2 )
494 /* We now have picture info for any cached user_data out of the gop */
495 cc_Extract( &p_sys->cc, &p_sys->p_gop_user_data[0], p_sys->i_gop_user_data );
496 p_sys->i_gop_user_data = 0;
499 /* Extract the CC from the user_data of the picture */
500 if( p_sys->p_info->user_data_len > 2 )
501 cc_Extract( &p_sys->cc, &p_sys->p_info->user_data[0], p_sys->p_info->user_data_len );
507 /* There can be userdata in a GOP. It needs to be remembered for the next picture. */
508 if( p_sys->p_info->user_data_len > 2 )
510 free( p_sys->p_gop_user_data );
511 p_sys->p_gop_user_data = calloc( p_sys->p_info->user_data_len, sizeof(uint8_t) );
512 if( p_sys->p_gop_user_data )
514 p_sys->i_gop_user_data = p_sys->p_info->user_data_len;
515 memcpy( p_sys->p_gop_user_data, p_sys->p_info->user_data, p_sys->p_info->user_data_len );
523 if( p_sys->p_info->display_fbuf
524 && p_sys->p_info->display_fbuf->id )
526 p_pic = (picture_t *)p_sys->p_info->display_fbuf->id;
528 decoder_SynchroEnd( p_sys->p_synchro,
529 p_sys->p_info->display_picture->flags
530 & PIC_MASK_CODING_TYPE,
531 p_sys->b_garbage_pic );
532 p_sys->b_garbage_pic = 0;
534 if( p_sys->p_picture_to_destroy != p_pic )
536 p_pic->date = decoder_SynchroDate( p_sys->p_synchro );
540 p_sys->p_picture_to_destroy = NULL;
545 if( p_sys->p_info->discard_fbuf &&
546 p_sys->p_info->discard_fbuf->id )
548 decoder_UnlinkPicture( p_dec,
549 p_sys->p_info->discard_fbuf->id );
552 /* For still frames */
553 if( state == STATE_END && p_pic ) p_pic->b_force = true;
557 /* Avoid frames with identical timestamps.
558 * Especially needed for still frames in DVD menus. */
559 if( p_sys->i_last_frame_pts == p_pic->date ) p_pic->date++;
560 p_sys->i_last_frame_pts = p_pic->date;
569 buf[0] = buf[1] = buf[2] = NULL;
571 msg_Warn( p_dec, "invalid picture encountered" );
572 if ( ( p_sys->p_info->current_picture == NULL ) ||
573 ( ( p_sys->p_info->current_picture->flags &
574 PIC_MASK_CODING_TYPE) != PIC_FLAG_CODING_TYPE_B ) )
576 if( p_sys->p_synchro ) decoder_SynchroReset( p_sys->p_synchro );
578 mpeg2_skip( p_sys->p_mpeg2dec, 1 );
580 cc_Flush( &p_sys->cc );
582 if( p_sys->p_info->current_fbuf &&
583 p_sys->p_info->current_fbuf->id )
585 p_sys->b_garbage_pic = 1;
586 p_pic = p_sys->p_info->current_fbuf->id;
588 else if( !p_sys->p_info->sequence )
594 if( (p_pic = GetNewPicture( p_dec, buf )) == NULL )
596 mpeg2_set_buf( p_sys->p_mpeg2dec, buf, p_pic );
597 mpeg2_stride( p_sys->p_mpeg2dec, p_pic->p[Y_PLANE].i_pitch );
599 p_sys->p_picture_to_destroy = p_pic;
601 memset( p_pic->p[0].p_pixels, 0,
602 p_sys->p_info->sequence->width
603 * p_sys->p_info->sequence->height );
604 memset( p_pic->p[1].p_pixels, 0x80,
605 p_sys->p_info->sequence->width
606 * p_sys->p_info->sequence->height / 4 );
607 memset( p_pic->p[2].p_pixels, 0x80,
608 p_sys->p_info->sequence->width
609 * p_sys->p_info->sequence->height / 4 );
611 if( p_sys->b_slice_i )
613 decoder_SynchroNewPicture( p_sys->p_synchro,
614 I_CODING_TYPE, 2, 0, 0,
615 p_sys->p_info->sequence->flags & SEQ_FLAG_LOW_DELAY );
616 decoder_SynchroDecode( p_sys->p_synchro );
617 decoder_SynchroEnd( p_sys->p_synchro, I_CODING_TYPE, 0 );
631 /*****************************************************************************
632 * CloseDecoder: libmpeg2 decoder destruction
633 *****************************************************************************/
634 static void CloseDecoder( vlc_object_t *p_this )
636 decoder_t *p_dec = (decoder_t *)p_this;
637 decoder_sys_t *p_sys = p_dec->p_sys;
639 free( p_sys->p_gop_user_data );
641 if( p_sys->p_synchro ) decoder_SynchroRelease( p_sys->p_synchro );
643 if( p_sys->p_mpeg2dec ) mpeg2_close( p_sys->p_mpeg2dec );
648 /*****************************************************************************
649 * GetNewPicture: Get a new picture from the vout and set the buf struct
650 *****************************************************************************/
651 static picture_t *GetNewPicture( decoder_t *p_dec, uint8_t **pp_buf )
653 decoder_sys_t *p_sys = p_dec->p_sys;
656 p_dec->fmt_out.video.i_width = p_sys->p_info->sequence->width;
657 p_dec->fmt_out.video.i_visible_width =
658 p_sys->p_info->sequence->picture_width;
659 p_dec->fmt_out.video.i_height = p_sys->p_info->sequence->height;
660 p_dec->fmt_out.video.i_visible_height =
661 p_sys->p_info->sequence->picture_height;
662 p_dec->fmt_out.video.i_aspect = p_sys->i_aspect;
663 p_dec->fmt_out.video.i_sar_num = p_sys->i_sar_num;
664 p_dec->fmt_out.video.i_sar_den = p_sys->i_sar_den;
666 if( p_sys->p_info->sequence->frame_period > 0 )
668 p_dec->fmt_out.video.i_frame_rate =
669 (uint32_t)( (uint64_t)1001000000 * 27 /
670 p_sys->p_info->sequence->frame_period );
671 p_dec->fmt_out.video.i_frame_rate_base = 1001;
674 p_dec->fmt_out.i_codec =
675 ( p_sys->p_info->sequence->chroma_height <
676 p_sys->p_info->sequence->height ) ?
677 VLC_CODEC_I420 : VLC_CODEC_I422;
679 /* Get a new picture */
680 p_pic = decoder_NewPicture( p_dec );
682 if( p_pic == NULL ) return NULL;
684 p_pic->b_progressive = p_sys->p_info->current_picture != NULL ?
685 p_sys->p_info->current_picture->flags & PIC_FLAG_PROGRESSIVE_FRAME : 1;
686 p_pic->b_top_field_first = p_sys->p_info->current_picture != NULL ?
687 p_sys->p_info->current_picture->flags & PIC_FLAG_TOP_FIELD_FIRST : 1;
688 p_pic->i_nb_fields = p_sys->p_info->current_picture != NULL ?
689 p_sys->p_info->current_picture->nb_fields : 2;
691 decoder_LinkPicture( p_dec, p_pic );
693 pp_buf[0] = p_pic->p[0].p_pixels;
694 pp_buf[1] = p_pic->p[1].p_pixels;
695 pp_buf[2] = p_pic->p[2].p_pixels;
700 /*****************************************************************************
701 * GetCc: Retrieves the Closed Captions for the CC decoder.
702 *****************************************************************************/
703 static block_t *GetCc( decoder_t *p_dec, bool pb_present[4] )
705 decoder_sys_t *p_sys = p_dec->p_sys;
706 block_t *p_cc = NULL;
709 for( i = 0; i < 4; i++ )
710 pb_present[i] = p_sys->cc.pb_present[i];
712 if( p_sys->cc.i_data <= 0 )
715 p_cc = block_New( p_dec, p_sys->cc.i_data);
718 memcpy( p_cc->p_buffer, p_sys->cc.p_data, p_sys->cc.i_data );
720 p_cc->i_pts = p_sys->cc.b_reorder ? p_sys->i_cc_pts : p_sys->i_cc_dts;
721 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);
723 cc_Flush( &p_sys->cc );
727 /*****************************************************************************
728 * GetAR: Get aspect ratio
729 *****************************************************************************/
730 static void GetAR( decoder_t *p_dec )
732 decoder_sys_t *p_sys = p_dec->p_sys;
734 /* Check whether the input gave a particular aspect ratio */
735 if( p_dec->fmt_in.video.i_aspect )
737 p_sys->i_aspect = p_dec->fmt_in.video.i_aspect;
741 /* Use the value provided in the MPEG sequence header */
742 if( p_sys->p_info->sequence->pixel_height > 0 )
745 ((uint64_t)p_sys->p_info->sequence->picture_width) *
746 p_sys->p_info->sequence->pixel_width *
748 p_sys->p_info->sequence->picture_height /
749 p_sys->p_info->sequence->pixel_height;
750 p_sys->i_sar_num = p_sys->p_info->sequence->pixel_width;
751 p_sys->i_sar_den = p_sys->p_info->sequence->pixel_height;
755 /* Invalid aspect, assume 4:3.
756 * This shouldn't happen and if it does it is a bug
757 * in libmpeg2 (likely triggered by an invalid stream) */
758 p_sys->i_aspect = VOUT_ASPECT_FACTOR * 4 / 3;
759 p_sys->i_sar_num = p_sys->p_info->sequence->picture_height * 4;
760 p_sys->i_sar_den = p_sys->p_info->sequence->picture_width * 3;
764 msg_Dbg( p_dec, "%dx%d (display %d,%d), aspect %d, sar %i:%i, %u.%03u fps",
765 p_sys->p_info->sequence->picture_width,
766 p_sys->p_info->sequence->picture_height,
767 p_sys->p_info->sequence->display_width,
768 p_sys->p_info->sequence->display_height,
769 p_sys->i_aspect, p_sys->i_sar_num, p_sys->i_sar_den,
770 (uint32_t)((uint64_t)1001000000 * 27 /
771 p_sys->p_info->sequence->frame_period / 1001),
772 (uint32_t)((uint64_t)1001000000 * 27 /
773 p_sys->p_info->sequence->frame_period % 1001) );