* modules/codec/libmpeg2.c: fixed pts handling and aspect-ratio bug.
authorGildas Bazin <gbazin@videolan.org>
Thu, 20 Mar 2003 21:45:01 +0000 (21:45 +0000)
committerGildas Bazin <gbazin@videolan.org>
Thu, 20 Mar 2003 21:45:01 +0000 (21:45 +0000)
modules/codec/libmpeg2.c

index e59ba62..40bbbc2 100755 (executable)
@@ -2,7 +2,7 @@
  * libmpeg2.c: mpeg2 video decoder module making use of libmpeg2.\r
  *****************************************************************************\r
  * Copyright (C) 1999-2001 VideoLAN\r
- * $Id: libmpeg2.c,v 1.2 2003/02/25 21:09:34 gbazin Exp $\r
+ * $Id: libmpeg2.c,v 1.3 2003/03/20 21:45:01 gbazin Exp $\r
  *\r
  * Authors: Gildas Bazin <gbazin@netcourrier.com>\r
  *\r
@@ -119,7 +119,7 @@ static int RunDecoder( decoder_fifo_t *p_fifo )
     p_dec->p_vout     = NULL;\r
     p_dec->p_mpeg2dec = NULL;\r
     p_dec->p_info     = NULL;\r
-    p_dec->i_pts      = 0;\r
+    p_dec->i_pts      = mdate() + DEFAULT_PTS_DELAY;\r
     p_dec->i_current_pts  = 0;\r
     p_dec->i_previous_pts = 0;\r
 \r
@@ -175,9 +175,9 @@ static int RunDecoder( decoder_fifo_t *p_fifo )
 \r
         case STATE_SEQUENCE:\r
             /* Initialize video output */\r
-            i_aspect = p_dec->p_info->sequence->width *\r
-                p_dec->p_info->sequence->pixel_width /\r
-                p_dec->p_info->sequence->height * VOUT_ASPECT_FACTOR /\r
+            i_aspect = ((uint64_t)p_dec->p_info->sequence->width) *\r
+                p_dec->p_info->sequence->pixel_width * VOUT_ASPECT_FACTOR /\r
+                p_dec->p_info->sequence->height /\r
                 p_dec->p_info->sequence->pixel_height;\r
 \r
             i_chroma = VLC_FOURCC('Y','V','1','2');\r
@@ -189,8 +189,8 @@ static int RunDecoder( decoder_fifo_t *p_fifo )
             break;\r
 \r
         case STATE_PICTURE:\r
-          {\r
-            uint8_t * buf[3];\r
+        {\r
+            uint8_t *buf[3];\r
 \r
             /* Get a new picture */\r
             while( !(p_pic = vout_CreatePicture( p_dec->p_vout, 0, 0, 0 ) ) )\r
@@ -207,35 +207,33 @@ static int RunDecoder( decoder_fifo_t *p_fifo )
             buf[1] = p_pic->p[1].p_pixels;\r
             buf[2] = p_pic->p[2].p_pixels;\r
             mpeg2_set_buf( p_dec->p_mpeg2dec, buf, p_pic );\r
-          }\r
-          break;\r
+\r
+            /* Store the date for the picture */\r
+            if( p_dec->p_info->current_picture->flags & PIC_FLAG_PTS )\r
+            {\r
+                p_pic->date = ( p_dec->p_info->current_picture->pts ==\r
+                                (uint32_t)p_dec->i_current_pts ) ?\r
+                              p_dec->i_current_pts : p_dec->i_previous_pts;\r
+            }\r
+        }\r
+        break;\r
 \r
         case STATE_END:\r
-#if 0\r
-            msg_Err( p_dec->p_fifo, "STATE_END" );\r
-#endif\r
         case STATE_SLICE:\r
-#if 0\r
-            msg_Err( p_dec->p_fifo, "STATE_SLICE: %i",\r
-                     p_dec->p_info->display_fbuf ?\r
-                     p_dec->p_info->display_fbuf->id : -1 );\r
-#endif\r
             if( p_dec->p_info->display_fbuf\r
                 && p_dec->p_info->display_fbuf->id )\r
             {\r
                 p_pic = (picture_t *)p_dec->p_info->display_fbuf->id;\r
 \r
+                /* Date the new picture */\r
                 if( p_dec->p_info->display_picture->flags & PIC_FLAG_PTS )\r
                 {\r
-                    p_dec->i_pts = ( p_dec->p_info->display_picture->pts ==\r
-                                     (uint32_t)p_dec->i_current_pts ) ?\r
-                        p_dec->i_current_pts : p_dec->i_previous_pts;\r
+                    p_dec->i_pts = p_pic->date;\r
                 }\r
                 else\r
                 {\r
                     p_dec->i_pts += (p_dec->p_info->sequence->frame_period/27);\r
                 }\r
-\r
                 vout_DatePicture( p_dec->p_vout, p_pic, p_dec->i_pts );\r
 \r
                 vout_DisplayPicture( p_dec->p_vout, p_pic );\r