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 */
87 /*****************************************************************************
89 *****************************************************************************/
90 static int OpenDecoder( vlc_object_t
* );
91 static void CloseDecoder( vlc_object_t
* );
93 static picture_t
*DecodeBlock( decoder_t
*, block_t
** );
94 static block_t
*GetCc( decoder_t
*p_dec
, bool pb_present
[4] );
96 static picture_t
*GetNewPicture( decoder_t
*, uint8_t ** );
97 static void GetAR( decoder_t
*p_dec
);
99 /*****************************************************************************
101 *****************************************************************************/
103 set_description( N_("MPEG I/II video decoder (using libmpeg2)") )
104 set_capability( "decoder", 150 )
105 set_category( CAT_INPUT
)
106 set_subcategory( SUBCAT_INPUT_VCODEC
)
107 set_callbacks( OpenDecoder
, CloseDecoder
)
108 add_shortcut( "libmpeg2" )
111 /*****************************************************************************
112 * OpenDecoder: probe the decoder and return score
113 *****************************************************************************/
114 static int OpenDecoder( vlc_object_t
*p_this
)
116 decoder_t
*p_dec
= (decoder_t
*)p_this
;
117 decoder_sys_t
*p_sys
;
118 uint32_t i_accel
= 0;
120 if( p_dec
->fmt_in
.i_codec
!= VLC_FOURCC('m','p','g','v') &&
121 p_dec
->fmt_in
.i_codec
!= VLC_FOURCC('m','p','g','1') &&
122 /* Pinnacle hardware-mpeg1 */
123 p_dec
->fmt_in
.i_codec
!= VLC_FOURCC('P','I','M','1') &&
124 p_dec
->fmt_in
.i_codec
!= VLC_FOURCC('m','p','2','v') &&
125 p_dec
->fmt_in
.i_codec
!= VLC_FOURCC('m','p','g','2') &&
126 p_dec
->fmt_in
.i_codec
!= VLC_FOURCC('h','d','v','2') )
131 /* Allocate the memory needed to store the decoder's structure */
132 if( ( p_dec
->p_sys
= p_sys
=
133 (decoder_sys_t
*)malloc(sizeof(decoder_sys_t
)) ) == NULL
)
136 /* Initialize the thread properties */
137 memset( p_sys
, 0, sizeof(decoder_sys_t
) );
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
);
160 #if defined( __i386__ ) || defined( __x86_64__ )
161 if( vlc_CPU() & CPU_CAPABILITY_MMX
)
163 i_accel
|= MPEG2_ACCEL_X86_MMX
;
166 if( vlc_CPU() & CPU_CAPABILITY_3DNOW
)
168 i_accel
|= MPEG2_ACCEL_X86_3DNOW
;
171 if( vlc_CPU() & CPU_CAPABILITY_MMXEXT
)
173 i_accel
|= MPEG2_ACCEL_X86_MMXEXT
;
176 #elif defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
177 if( vlc_CPU() & CPU_CAPABILITY_ALTIVEC
)
179 i_accel
|= MPEG2_ACCEL_PPC_ALTIVEC
;
183 /* If we do not know this CPU, trust libmpeg2's feature detection */
184 i_accel
= MPEG2_ACCEL_DETECT
;
188 /* Set CPU acceleration features */
189 mpeg2_accel( i_accel
);
191 /* Initialize decoder */
192 p_sys
->p_mpeg2dec
= mpeg2_init();
193 if( p_sys
->p_mpeg2dec
== NULL
)
195 msg_Err( p_dec
, "mpeg2_init() failed" );
200 p_sys
->p_info
= mpeg2_info( p_sys
->p_mpeg2dec
);
202 p_dec
->pf_decode_video
= DecodeBlock
;
207 /*****************************************************************************
208 * RunDecoder: the libmpeg2 decoder
209 *****************************************************************************/
210 static picture_t
*DecodeBlock( decoder_t
*p_dec
, block_t
**pp_block
)
212 decoder_sys_t
*p_sys
= p_dec
->p_sys
;
218 if( !pp_block
|| !*pp_block
) return NULL
;
224 state
= mpeg2_parse( p_sys
->p_mpeg2dec
);
229 if( !p_block
->i_buffer
)
231 block_Release( p_block
);
234 if( p_block
->i_flags
& (BLOCK_FLAG_DISCONTINUITY
235 | BLOCK_FLAG_CORRUPTED
))
236 cc_Flush( &p_sys
->cc
);
238 if( (p_block
->i_flags
& (BLOCK_FLAG_DISCONTINUITY
239 | BLOCK_FLAG_CORRUPTED
)) &&
241 p_sys
->p_info
->sequence
&&
242 p_sys
->p_info
->sequence
->width
!= (unsigned)-1 )
244 decoder_SynchroReset( p_sys
->p_synchro
);
245 if( p_sys
->p_info
->current_fbuf
!= NULL
246 && p_sys
->p_info
->current_fbuf
->id
!= NULL
)
248 p_sys
->b_garbage_pic
= 1;
249 p_pic
= p_sys
->p_info
->current_fbuf
->id
;
254 buf
[0] = buf
[1] = buf
[2] = NULL
;
255 if( (p_pic
= GetNewPicture( p_dec
, buf
)) == NULL
)
257 p_block
->i_buffer
= 0;
260 mpeg2_set_buf( p_sys
->p_mpeg2dec
, buf
, p_pic
);
261 mpeg2_stride( p_sys
->p_mpeg2dec
, p_pic
->p
[Y_PLANE
].i_pitch
);
263 p_sys
->p_picture_to_destroy
= p_pic
;
265 if ( p_sys
->b_slice_i
)
267 decoder_SynchroNewPicture( p_sys
->p_synchro
,
268 I_CODING_TYPE
, 2, 0, 0,
269 p_sys
->p_info
->sequence
->flags
& SEQ_FLAG_LOW_DELAY
);
270 decoder_SynchroDecode( p_sys
->p_synchro
);
271 decoder_SynchroEnd( p_sys
->p_synchro
, I_CODING_TYPE
, 0 );
275 if( p_block
->i_flags
& BLOCK_FLAG_PREROLL
)
277 p_sys
->b_preroll
= true;
279 else if( p_sys
->b_preroll
)
281 p_sys
->b_preroll
= false;
283 decoder_SynchroReset( p_sys
->p_synchro
);
289 mpeg2_pts( p_sys
->p_mpeg2dec
, (uint32_t)p_block
->i_pts
);
291 #else /* New interface */
292 if( p_block
->i_pts
|| p_block
->i_dts
)
294 mpeg2_tag_picture( p_sys
->p_mpeg2dec
,
295 (uint32_t)p_block
->i_pts
,
296 (uint32_t)p_block
->i_dts
);
298 p_sys
->i_previous_pts
= p_sys
->i_current_pts
;
299 p_sys
->i_current_pts
= p_block
->i_pts
;
300 p_sys
->i_previous_dts
= p_sys
->i_current_dts
;
301 p_sys
->i_current_dts
= p_block
->i_dts
;
304 mpeg2_buffer( p_sys
->p_mpeg2dec
, p_block
->p_buffer
,
305 p_block
->p_buffer
+ p_block
->i_buffer
);
307 p_block
->i_buffer
= 0;
310 #if MPEG2_RELEASE >= MPEG2_VERSION (0, 5, 0)
312 case STATE_SEQUENCE_MODIFIED
:
319 /* Initialize video output */
321 buf
[0] = buf
[1] = buf
[2] = NULL
;
325 mpeg2_custom_fbuf( p_sys
->p_mpeg2dec
, 1 );
327 /* Set the first 2 reference frames */
328 mpeg2_set_buf( p_sys
->p_mpeg2dec
, buf
, NULL
);
330 if( (p_pic
= GetNewPicture( p_dec
, buf
)) == NULL
)
332 block_Release( p_block
);
336 mpeg2_set_buf( p_sys
->p_mpeg2dec
, buf
, p_pic
);
337 mpeg2_stride( p_sys
->p_mpeg2dec
, p_pic
->p
[Y_PLANE
].i_pitch
);
339 /* This picture will never go through display_picture. */
342 /* For some reason, libmpeg2 will put this pic twice in
343 * discard_picture. This can be considered a bug in libmpeg2. */
344 decoder_LinkPicture( p_dec
, p_pic
);
346 if( p_sys
->p_synchro
)
348 decoder_SynchroRelease( p_sys
->p_synchro
);
350 p_sys
->p_synchro
= decoder_SynchroInit( p_dec
,
351 (uint32_t)((uint64_t)1001000000 * 27 /
352 p_sys
->p_info
->sequence
->frame_period
) );
353 p_sys
->b_after_sequence_header
= 1;
357 case STATE_PICTURE_2ND
:
358 p_sys
->b_second_field
= 1;
364 mtime_t i_pts
, i_dts
;
365 buf
[0] = buf
[1] = buf
[2] = NULL
;
367 if ( p_sys
->b_after_sequence_header
&&
368 ((p_sys
->p_info
->current_picture
->flags
&
369 PIC_MASK_CODING_TYPE
) == PIC_FLAG_CODING_TYPE_P
) )
371 /* Intra-slice refresh. Simulate a blank I picture. */
372 msg_Dbg( p_dec
, "intra-slice refresh stream" );
373 decoder_SynchroNewPicture( p_sys
->p_synchro
,
374 I_CODING_TYPE
, 2, 0, 0,
375 p_sys
->p_info
->sequence
->flags
& SEQ_FLAG_LOW_DELAY
);
376 decoder_SynchroDecode( p_sys
->p_synchro
);
377 decoder_SynchroEnd( p_sys
->p_synchro
, I_CODING_TYPE
, 0 );
378 p_sys
->b_slice_i
= 1;
380 p_sys
->b_after_sequence_header
= 0;
383 i_pts
= p_sys
->p_info
->current_picture
->flags
& PIC_FLAG_PTS
?
384 ( ( p_sys
->p_info
->current_picture
->pts
==
385 (uint32_t)p_sys
->i_current_pts
) ?
386 p_sys
->i_current_pts
: p_sys
->i_previous_pts
) : 0;
389 /* Hack to handle demuxers which only have DTS timestamps */
390 if( !i_pts
&& !p_block
->i_pts
&& p_block
->i_dts
> 0 )
392 if( p_sys
->p_info
->sequence
->flags
& SEQ_FLAG_LOW_DELAY
||
393 (p_sys
->p_info
->current_picture
->flags
&
394 PIC_MASK_CODING_TYPE
) == PIC_FLAG_CODING_TYPE_B
)
396 i_pts
= p_block
->i_dts
;
399 p_block
->i_pts
= p_block
->i_dts
= 0;
402 #else /* New interface */
404 i_pts
= p_sys
->p_info
->current_picture
->flags
& PIC_FLAG_TAGS
?
405 ( ( p_sys
->p_info
->current_picture
->tag
==
406 (uint32_t)p_sys
->i_current_pts
) ?
407 p_sys
->i_current_pts
: p_sys
->i_previous_pts
) : 0;
408 i_dts
= p_sys
->p_info
->current_picture
->flags
& PIC_FLAG_TAGS
?
409 ( ( p_sys
->p_info
->current_picture
->tag2
==
410 (uint32_t)p_sys
->i_current_dts
) ?
411 p_sys
->i_current_dts
: p_sys
->i_previous_dts
) : 0;
414 /* If nb_fields == 1, it is a field picture, and it will be
415 * followed by another field picture for which we won't call
416 * decoder_SynchroNewPicture() because this would have other
417 * problems, so we take it into account here.
418 * This kind of sucks, but I didn't think better. --Meuuh
420 decoder_SynchroNewPicture( p_sys
->p_synchro
,
421 p_sys
->p_info
->current_picture
->flags
& PIC_MASK_CODING_TYPE
,
422 p_sys
->p_info
->current_picture
->nb_fields
== 1 ? 2 :
423 p_sys
->p_info
->current_picture
->nb_fields
, i_pts
, i_dts
,
424 p_sys
->p_info
->sequence
->flags
& SEQ_FLAG_LOW_DELAY
);
428 if( !p_dec
->b_pace_control
&& !p_sys
->b_preroll
&&
430 && ((p_sys
->p_info
->current_picture
->flags
431 & PIC_MASK_CODING_TYPE
) == PIC_FLAG_CODING_TYPE_P
))
432 && !decoder_SynchroChoose( p_sys
->p_synchro
,
433 p_sys
->p_info
->current_picture
->flags
434 & PIC_MASK_CODING_TYPE
,
435 /*p_sys->p_vout->render_time*/ 0 /*FIXME*/,
436 p_sys
->p_info
->sequence
->flags
& SEQ_FLAG_LOW_DELAY
) )
443 p_pic
= GetNewPicture( p_dec
, buf
);
445 if( b_skip
|| !p_pic
)
447 mpeg2_skip( p_sys
->p_mpeg2dec
, 1 );
449 decoder_SynchroTrash( p_sys
->p_synchro
);
450 mpeg2_set_buf( p_sys
->p_mpeg2dec
, buf
, NULL
);
454 block_Release( p_block
);
460 mpeg2_skip( p_sys
->p_mpeg2dec
, 0 );
462 decoder_SynchroDecode( p_sys
->p_synchro
);
464 mpeg2_set_buf( p_sys
->p_mpeg2dec
, buf
, p_pic
);
465 mpeg2_stride( p_sys
->p_mpeg2dec
, p_pic
->p
[Y_PLANE
].i_pitch
);
467 if( p_sys
->p_info
->user_data_len
> 2 )
469 p_sys
->i_cc_pts
= i_pts
;
470 p_sys
->i_cc_dts
= i_dts
;
471 if( (p_sys
->p_info
->current_picture
->flags
472 & PIC_MASK_CODING_TYPE
) == PIC_FLAG_CODING_TYPE_P
)
473 p_sys
->i_cc_flags
= BLOCK_FLAG_TYPE_P
;
474 else if( (p_sys
->p_info
->current_picture
->flags
475 & PIC_MASK_CODING_TYPE
) == PIC_FLAG_CODING_TYPE_B
)
476 p_sys
->i_cc_flags
= BLOCK_FLAG_TYPE_B
;
477 else p_sys
->i_cc_flags
= BLOCK_FLAG_TYPE_I
;
479 cc_Extract( &p_sys
->cc
, &p_sys
->p_info
->user_data
[0], p_sys
->p_info
->user_data_len
);
487 if( p_sys
->p_info
->display_fbuf
488 && p_sys
->p_info
->display_fbuf
->id
)
490 p_pic
= (picture_t
*)p_sys
->p_info
->display_fbuf
->id
;
492 decoder_SynchroEnd( p_sys
->p_synchro
,
493 p_sys
->p_info
->display_picture
->flags
494 & PIC_MASK_CODING_TYPE
,
495 p_sys
->b_garbage_pic
);
496 p_sys
->b_garbage_pic
= 0;
498 if( p_sys
->p_picture_to_destroy
!= p_pic
)
500 p_pic
->date
= decoder_SynchroDate( p_sys
->p_synchro
);
504 p_sys
->p_picture_to_destroy
= NULL
;
509 if( p_sys
->p_info
->discard_fbuf
&&
510 p_sys
->p_info
->discard_fbuf
->id
)
512 decoder_UnlinkPicture( p_dec
,
513 p_sys
->p_info
->discard_fbuf
->id
);
516 /* For still frames */
517 if( state
== STATE_END
&& p_pic
) p_pic
->b_force
= true;
521 /* Avoid frames with identical timestamps.
522 * Especially needed for still frames in DVD menus. */
523 if( p_sys
->i_last_frame_pts
== p_pic
->date
) p_pic
->date
++;
524 p_sys
->i_last_frame_pts
= p_pic
->date
;
533 buf
[0] = buf
[1] = buf
[2] = NULL
;
535 msg_Warn( p_dec
, "invalid picture encountered" );
536 if ( ( p_sys
->p_info
->current_picture
== NULL
) ||
537 ( ( p_sys
->p_info
->current_picture
->flags
&
538 PIC_MASK_CODING_TYPE
) != PIC_FLAG_CODING_TYPE_B
) )
540 if( p_sys
->p_synchro
) decoder_SynchroReset( p_sys
->p_synchro
);
542 mpeg2_skip( p_sys
->p_mpeg2dec
, 1 );
544 cc_Flush( &p_sys
->cc
);
546 if( p_sys
->p_info
->current_fbuf
&&
547 p_sys
->p_info
->current_fbuf
->id
)
549 p_sys
->b_garbage_pic
= 1;
550 p_pic
= p_sys
->p_info
->current_fbuf
->id
;
552 else if( !p_sys
->p_info
->sequence
)
558 if( (p_pic
= GetNewPicture( p_dec
, buf
)) == NULL
)
560 mpeg2_set_buf( p_sys
->p_mpeg2dec
, buf
, p_pic
);
561 mpeg2_stride( p_sys
->p_mpeg2dec
, p_pic
->p
[Y_PLANE
].i_pitch
);
563 p_sys
->p_picture_to_destroy
= p_pic
;
565 memset( p_pic
->p
[0].p_pixels
, 0,
566 p_sys
->p_info
->sequence
->width
567 * p_sys
->p_info
->sequence
->height
);
568 memset( p_pic
->p
[1].p_pixels
, 0x80,
569 p_sys
->p_info
->sequence
->width
570 * p_sys
->p_info
->sequence
->height
/ 4 );
571 memset( p_pic
->p
[2].p_pixels
, 0x80,
572 p_sys
->p_info
->sequence
->width
573 * p_sys
->p_info
->sequence
->height
/ 4 );
575 if( p_sys
->b_slice_i
)
577 decoder_SynchroNewPicture( p_sys
->p_synchro
,
578 I_CODING_TYPE
, 2, 0, 0,
579 p_sys
->p_info
->sequence
->flags
& SEQ_FLAG_LOW_DELAY
);
580 decoder_SynchroDecode( p_sys
->p_synchro
);
581 decoder_SynchroEnd( p_sys
->p_synchro
, I_CODING_TYPE
, 0 );
595 /*****************************************************************************
596 * CloseDecoder: libmpeg2 decoder destruction
597 *****************************************************************************/
598 static void CloseDecoder( vlc_object_t
*p_this
)
600 decoder_t
*p_dec
= (decoder_t
*)p_this
;
601 decoder_sys_t
*p_sys
= p_dec
->p_sys
;
603 if( p_sys
->p_synchro
) decoder_SynchroRelease( p_sys
->p_synchro
);
605 if( p_sys
->p_mpeg2dec
) mpeg2_close( p_sys
->p_mpeg2dec
);
610 /*****************************************************************************
611 * GetNewPicture: Get a new picture from the vout and set the buf struct
612 *****************************************************************************/
613 static picture_t
*GetNewPicture( decoder_t
*p_dec
, uint8_t **pp_buf
)
615 decoder_sys_t
*p_sys
= p_dec
->p_sys
;
618 p_dec
->fmt_out
.video
.i_width
= p_sys
->p_info
->sequence
->width
;
619 p_dec
->fmt_out
.video
.i_visible_width
=
620 p_sys
->p_info
->sequence
->picture_width
;
621 p_dec
->fmt_out
.video
.i_height
= p_sys
->p_info
->sequence
->height
;
622 p_dec
->fmt_out
.video
.i_visible_height
=
623 p_sys
->p_info
->sequence
->picture_height
;
624 p_dec
->fmt_out
.video
.i_aspect
= p_sys
->i_aspect
;
625 p_dec
->fmt_out
.video
.i_sar_num
= p_sys
->i_sar_num
;
626 p_dec
->fmt_out
.video
.i_sar_den
= p_sys
->i_sar_den
;
628 if( p_sys
->p_info
->sequence
->frame_period
> 0 )
630 p_dec
->fmt_out
.video
.i_frame_rate
=
631 (uint32_t)( (uint64_t)1001000000 * 27 /
632 p_sys
->p_info
->sequence
->frame_period
);
633 p_dec
->fmt_out
.video
.i_frame_rate_base
= 1001;
636 p_dec
->fmt_out
.i_codec
=
637 ( p_sys
->p_info
->sequence
->chroma_height
<
638 p_sys
->p_info
->sequence
->height
) ?
639 VLC_FOURCC('I','4','2','0') : VLC_FOURCC('I','4','2','2');
641 /* Get a new picture */
642 p_pic
= decoder_NewPicture( p_dec
);
644 if( p_pic
== NULL
) return NULL
;
646 p_pic
->b_progressive
= p_sys
->p_info
->current_picture
!= NULL
?
647 p_sys
->p_info
->current_picture
->flags
& PIC_FLAG_PROGRESSIVE_FRAME
: 1;
648 p_pic
->b_top_field_first
= p_sys
->p_info
->current_picture
!= NULL
?
649 p_sys
->p_info
->current_picture
->flags
& PIC_FLAG_TOP_FIELD_FIRST
: 1;
650 p_pic
->i_nb_fields
= p_sys
->p_info
->current_picture
!= NULL
?
651 p_sys
->p_info
->current_picture
->nb_fields
: 2;
653 decoder_LinkPicture( p_dec
, p_pic
);
655 pp_buf
[0] = p_pic
->p
[0].p_pixels
;
656 pp_buf
[1] = p_pic
->p
[1].p_pixels
;
657 pp_buf
[2] = p_pic
->p
[2].p_pixels
;
662 /*****************************************************************************
663 * GetCc: Retrieves the Closed Captions for the CC decoder.
664 *****************************************************************************/
665 static block_t
*GetCc( decoder_t
*p_dec
, bool pb_present
[4] )
667 decoder_sys_t
*p_sys
= p_dec
->p_sys
;
668 block_t
*p_cc
= NULL
;
671 for( i
= 0; i
< 4; i
++ )
672 pb_present
[i
] = p_sys
->cc
.pb_present
[i
];
674 if( p_sys
->cc
.i_data
<= 0 )
677 p_cc
= block_New( p_dec
, p_sys
->cc
.i_data
);
680 memcpy( p_cc
->p_buffer
, p_sys
->cc
.p_data
, p_sys
->cc
.i_data
);
682 p_cc
->i_pts
= p_sys
->cc
.b_reorder
? p_sys
->i_cc_pts
: p_sys
->i_cc_dts
;
683 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
);
685 cc_Flush( &p_sys
->cc
);
689 /*****************************************************************************
690 * GetAR: Get aspect ratio
691 *****************************************************************************/
692 static void GetAR( decoder_t
*p_dec
)
694 decoder_sys_t
*p_sys
= p_dec
->p_sys
;
696 /* Check whether the input gave a particular aspect ratio */
697 if( p_dec
->fmt_in
.video
.i_aspect
)
699 p_sys
->i_aspect
= p_dec
->fmt_in
.video
.i_aspect
;
703 /* Use the value provided in the MPEG sequence header */
704 if( p_sys
->p_info
->sequence
->pixel_height
> 0 )
707 ((uint64_t)p_sys
->p_info
->sequence
->picture_width
) *
708 p_sys
->p_info
->sequence
->pixel_width
*
710 p_sys
->p_info
->sequence
->picture_height
/
711 p_sys
->p_info
->sequence
->pixel_height
;
712 p_sys
->i_sar_num
= p_sys
->p_info
->sequence
->pixel_width
;
713 p_sys
->i_sar_den
= p_sys
->p_info
->sequence
->pixel_height
;
717 /* Invalid aspect, assume 4:3.
718 * This shouldn't happen and if it does it is a bug
719 * in libmpeg2 (likely triggered by an invalid stream) */
720 p_sys
->i_aspect
= VOUT_ASPECT_FACTOR
* 4 / 3;
721 p_sys
->i_sar_num
= p_sys
->p_info
->sequence
->picture_height
* 4;
722 p_sys
->i_sar_den
= p_sys
->p_info
->sequence
->picture_width
* 3;
726 msg_Dbg( p_dec
, "%dx%d (display %d,%d), aspect %d, sar %i:%i, %u.%03u fps",
727 p_sys
->p_info
->sequence
->picture_width
,
728 p_sys
->p_info
->sequence
->picture_height
,
729 p_sys
->p_info
->sequence
->display_width
,
730 p_sys
->p_info
->sequence
->display_height
,
731 p_sys
->i_aspect
, p_sys
->i_sar_num
, p_sys
->i_sar_den
,
732 (uint32_t)((uint64_t)1001000000 * 27 /
733 p_sys
->p_info
->sequence
->frame_period
/ 1001),
734 (uint32_t)((uint64_t)1001000000 * 27 /
735 p_sys
->p_info
->sequence
->frame_period
% 1001) );