]> git.sesse.net Git - vlc/blobdiff - modules/codec/cdg.c
libav*: create a new avcommon_compat.h file for backward compatibility
[vlc] / modules / codec / cdg.c
index 5823563141fc9df78f17dd3f074d02455878cc8e..3d132f9700217ce27735c1d63216de798a7730fc 100644 (file)
@@ -6,19 +6,19 @@
  *
  * Authors: Laurent Aimar <fenrir # via.ecp.fr>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_codec.h>
-#include <vlc_vout.h>
 
 /*****************************************************************************
  * decoder_sys_t : decoder descriptor
  *****************************************************************************/
 
 /* The screen size */
-#define CDG_SCREEN_WIDTH (300)
-#define CDG_SCREEN_HEIGHT (216)
+#define CDG_SCREEN_WIDTH 300u
+#define CDG_SCREEN_HEIGHT 216u
 
 /* The border of the screen size */
-#define CDG_SCREEN_BORDER_WIDTH (6)
-#define CDG_SCREEN_BORDER_HEIGHT (12)
+#define CDG_SCREEN_BORDER_WIDTH 6u
+#define CDG_SCREEN_BORDER_HEIGHT 12u
 
 /* The display part */
 #define CDG_DISPLAY_WIDTH  (CDG_SCREEN_WIDTH-2*CDG_SCREEN_BORDER_WIDTH)
 #define CDG_DISPLAY_HEIGHT (CDG_SCREEN_HEIGHT-2*CDG_SCREEN_BORDER_HEIGHT)
 
-#define CDG_SCREEN_PITCH (CDG_SCREEN_WIDTH)
+#define CDG_SCREEN_PITCH CDG_SCREEN_WIDTH
 
 struct decoder_sys_t
 {
-    uint8_t color[16][3];
-    int     i_offseth;
-    int     i_offsetv;
-    uint8_t screen[CDG_SCREEN_PITCH*CDG_SCREEN_HEIGHT];
-    uint8_t *p_screen;
+    uint8_t  color[16][3];
+    unsigned i_offseth;
+    unsigned i_offsetv;
+    uint8_t  screen[CDG_SCREEN_PITCH*CDG_SCREEN_HEIGHT];
+    uint8_t  *p_screen;
+
+    int      i_packet;
 };
 
-#define CDG_PACKET_SIZE (24)
+#define CDG_PACKET_SIZE 24u
 
-#define CDG_COLOR_R_SHIFT ( 0)
-#define CDG_COLOR_G_SHIFT ( 8)
-#define CDG_COLOR_B_SHIFT (16)
+#define CDG_COLOR_R_SHIFT  0
+#define CDG_COLOR_G_SHIFT  8
+#define CDG_COLOR_B_SHIFT 16
 
 /*****************************************************************************
  * Local prototypes
@@ -80,14 +81,14 @@ static int Render( decoder_sys_t *p_cdg, picture_t *p_picture );
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-vlc_module_begin();
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_VCODEC );
-    set_description( _("CDG video decoder") );
-    set_capability( "decoder", 1000 );
-    set_callbacks( Open, Close );
-    add_shortcut( "cdg" );
-vlc_module_end();
+vlc_module_begin ()
+    set_category( CAT_INPUT )
+    set_subcategory( SUBCAT_INPUT_VCODEC )
+    set_description( N_("CDG video decoder") )
+    set_capability( "decoder", 1000 )
+    set_callbacks( Open, Close )
+    add_shortcut( "cdg" )
+vlc_module_end ()
 
 /*****************************************************************************
  * Open: probe the decoder and return score
@@ -97,28 +98,26 @@ static int Open( vlc_object_t *p_this )
     decoder_t *p_dec = (decoder_t*)p_this;
     decoder_sys_t *p_sys;
 
-    if( p_dec->fmt_in.i_codec != VLC_FOURCC('C','D','G',' ') )
+    if( p_dec->fmt_in.i_codec != VLC_CODEC_CDG )
         return VLC_EGENERIC;
 
     /* Allocate the memory needed to store the decoder's structure */
-    p_dec->p_sys = p_sys = malloc(sizeof(decoder_sys_t));
+    p_dec->p_sys = p_sys = calloc( 1, sizeof(decoder_sys_t) );
     if( !p_sys )
         return VLC_ENOMEM;
 
     /* Init */
-    memset( p_sys, 0, sizeof(*p_sys) );
-    p_sys->i_offseth = 0;
-    p_sys->i_offsetv = 0;
     p_sys->p_screen = p_sys->screen;
+    p_sys->i_packet = 0;
 
     /* Set output properties
      * TODO maybe it would be better to use RV16 or RV24 ? */
     p_dec->fmt_out.i_cat = VIDEO_ES;
-    p_dec->fmt_out.i_codec = VLC_FOURCC('R','V','3','2');
+    p_dec->fmt_out.i_codec = VLC_CODEC_RGB32;
     p_dec->fmt_out.video.i_width = CDG_DISPLAY_WIDTH;
     p_dec->fmt_out.video.i_height = CDG_DISPLAY_HEIGHT;
-    p_dec->fmt_out.video.i_aspect =
-        VOUT_ASPECT_FACTOR * p_dec->fmt_out.video.i_width / p_dec->fmt_out.video.i_height;
+    p_dec->fmt_out.video.i_sar_num = 1;
+    p_dec->fmt_out.video.i_sar_den = 1;
     p_dec->fmt_out.video.i_rmask = 0xff << CDG_COLOR_R_SHIFT;
     p_dec->fmt_out.video.i_gmask = 0xff << CDG_COLOR_G_SHIFT;
     p_dec->fmt_out.video.i_bmask = 0xff << CDG_COLOR_B_SHIFT;
@@ -144,6 +143,12 @@ static picture_t *Decode( decoder_t *p_dec, block_t **pp_block )
         return NULL;
     p_block = *pp_block;
 
+    if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
+    {
+        p_sys->i_packet = 0;
+        goto exit;
+    }
+
     /* Decode packet */
     while( p_block->i_buffer >= CDG_PACKET_SIZE )
     {
@@ -152,20 +157,21 @@ static picture_t *Decode( decoder_t *p_dec, block_t **pp_block )
         p_block->p_buffer += CDG_PACKET_SIZE;
     }
 
-    /* Get a new picture */
-    p_pic = p_dec->pf_vout_buffer_new( p_dec );
-    if( !p_pic )
-        goto error;
+    /* Only display 25 frame per second (there is 75 packets per second) */
+    if( (p_sys->i_packet%3) == 1 )
+    {
+        /* Get a new picture */
+        p_pic = decoder_NewPicture( p_dec );
+        if( !p_pic )
+            goto exit;
 
-    Render( p_sys, p_pic );
-    p_pic->date = p_block->i_pts > 0 ? p_block->i_pts : p_block->i_dts;
+        Render( p_sys, p_pic );
+        p_pic->date = p_block->i_pts > VLC_TS_INVALID ? p_block->i_pts : p_block->i_dts;
+    }
 
+exit:
     block_Release( p_block ); *pp_block = NULL;
     return p_pic;
-
-error:
-    block_Release( p_block ); *pp_block = NULL;
-    return NULL;
 }
 
 /*****************************************************************************
@@ -248,7 +254,13 @@ static int DecodeTileBlock( decoder_sys_t *p_cdg, const uint8_t *p_data, int doX
         for( x = 0; x < 6; x++ )
         {
             const int idx = ( p_data[4+y] >> (5-x) ) & 0x01;
-            uint8_t *p = &p_cdg->p_screen[(sy+y)*CDG_SCREEN_PITCH+(sx+x)];
+
+            unsigned index = (sy+y)*CDG_SCREEN_PITCH+(sx+x);
+            if( index >= CDG_SCREEN_PITCH*CDG_SCREEN_HEIGHT )
+                return 0;
+
+            uint8_t *p = &p_cdg->p_screen[index];
+
             if( doXor )
                 *p ^= p_color[idx];
             else
@@ -265,7 +277,6 @@ static int DecodeScroll( decoder_sys_t *p_cdg, const uint8_t *p_data, int b_copy
     uint8_t color = p_data[0]&0x0f;
     int i_shifth;
     int i_shiftv;
-    int x, y;
 
     /* */
     p_cdg->i_offseth = p_data[1]&0x7;
@@ -304,17 +315,17 @@ static int DecodeScroll( decoder_sys_t *p_cdg, const uint8_t *p_data, int b_copy
     ScreenFill( p_cdg, 0, 0, CDG_SCREEN_WIDTH, CDG_SCREEN_HEIGHT, color );
 
     /* Copy back */
-    for( y = 0; y < CDG_SCREEN_HEIGHT; y++ )
+    for( unsigned y = 0; y < CDG_SCREEN_HEIGHT; y++ )
     {
         int dy = i_shiftv + y;
-        for( x = 0; x < CDG_SCREEN_WIDTH; x++ )
+        for( unsigned x = 0; x < CDG_SCREEN_WIDTH; x++ )
         {
             int dx = i_shifth + x;
 
             if( b_copy )
             {
-                dy = ( dy + CDG_SCREEN_HEIGHT ) % CDG_SCREEN_HEIGHT;
-                dy = ( dy + CDG_SCREEN_WIDTH  ) % CDG_SCREEN_WIDTH;
+                dy = (dy + CDG_SCREEN_HEIGHT) % CDG_SCREEN_HEIGHT;
+                dx = (dx + CDG_SCREEN_WIDTH ) % CDG_SCREEN_WIDTH;
             }
             else
             {
@@ -339,6 +350,8 @@ static int DecodePacket( decoder_sys_t *p_cdg, uint8_t *p_buffer, int i_buffer )
     if( i_buffer != CDG_PACKET_SIZE )
         return -1;
 
+    p_cdg->i_packet++;
+
     /* Handle CDG command only */
     if( i_cmd != 0x09 )
         return 0;
@@ -394,11 +407,9 @@ static uint32_t RenderRGB( int r, int g, int b )
 
 static int Render( decoder_sys_t *p_cdg, picture_t *p_picture )
 {
-    int x, y;
-
-    for( y = 0; y < CDG_DISPLAY_HEIGHT; y++ )
+    for( unsigned y = 0; y < CDG_DISPLAY_HEIGHT; y++ )
     {
-        for( x = 0; x < CDG_DISPLAY_WIDTH; x++ )
+        for( unsigned x = 0; x < CDG_DISPLAY_WIDTH; x++ )
         {
             const int sx = x + p_cdg->i_offseth + CDG_SCREEN_BORDER_WIDTH;
             const int sy = y + p_cdg->i_offsetv + CDG_SCREEN_BORDER_HEIGHT;