]> git.sesse.net Git - vlc/blobdiff - modules/codec/rawvideo.c
Include vlc_plugin.h as needed
[vlc] / modules / codec / rawvideo.c
index 390d22dd8be5151c4921f7aca780e0c7587bc578..fa4add7a005d3b6ca4850c40dd021f7717aabdaa 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * rawvideo.c: Pseudo video decoder/packetizer for raw video data
  *****************************************************************************
- * Copyright (C) 2001, 2002 VideoLAN
- * $Id: rawvideo.c,v 1.8 2003/11/16 21:07:30 gbazin Exp $
+ * Copyright (C) 2001, 2002 the VideoLAN team
+ * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <string.h>                                              /* strdup() */
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <vlc/vlc.h>
-#include <vlc/decoder.h>
-#include <vlc/input.h>
-
-#include "codecs.h"
+#include <vlc_plugin.h>
+#include <vlc_codec.h>
+#include <vlc_vout.h>
 
 /*****************************************************************************
  * decoder_sys_t : raw video decoder descriptor
 struct decoder_sys_t
 {
     /* Module mode */
-    vlc_bool_t b_packetizer;
+    bool b_packetizer;
 
     /*
      * Input properties
      */
-    int i_raw_size;
+    size_t i_raw_size;
+    bool b_invert;
 
     /*
      * Common properties
@@ -69,12 +70,14 @@ static block_t   *SendFrame  ( decoder_t *, block_t * );
  * Module descriptor
  *****************************************************************************/
 vlc_module_begin();
-    set_description( _("Pseudo Raw Video decoder") );
+    set_description( _("Pseudo raw video decoder") );
     set_capability( "decoder", 50 );
+    set_category( CAT_INPUT );
+    set_subcategory( SUBCAT_INPUT_VCODEC );
     set_callbacks( OpenDecoder, CloseDecoder );
 
     add_submodule();
-    set_description( _("Pseudo Raw Video packetizer") );
+    set_description( _("Pseudo raw video packetizer") );
     set_capability( "packetizer", 100 );
     set_callbacks( OpenPacketizer, CloseDecoder );
 vlc_module_end();
@@ -97,10 +100,15 @@ static int OpenDecoder( vlc_object_t *p_this )
         case VLC_FOURCC('I','Y','U','V'):
         case VLC_FOURCC('I','4','1','1'):
         case VLC_FOURCC('I','4','1','0'):
+        case VLC_FOURCC('Y','V','U','9'):
+        case VLC_FOURCC('Y','4','2','B'):
+        case VLC_FOURCC('Y','4','1','B'):
 
         /* Packed YUV */
         case VLC_FOURCC('Y','U','Y','2'):
+        case VLC_FOURCC('Y','8','0','0'):
         case VLC_FOURCC('U','Y','V','Y'):
+        case VLC_FOURCC('H','D','Y','C'):
 
         /* RGB */
         case VLC_FOURCC('R','V','3','2'):
@@ -108,6 +116,14 @@ static int OpenDecoder( vlc_object_t *p_this )
         case VLC_FOURCC('R','V','1','6'):
         case VLC_FOURCC('R','V','1','5'):
             break;
+        case VLC_FOURCC('2','V','u','y'):
+        case VLC_FOURCC('2','v','u','y'):
+        case VLC_FOURCC('A','V','U','I'):
+            p_dec->fmt_in.i_codec = VLC_FOURCC('U','Y','V','Y');
+            break;
+        case VLC_FOURCC('y','v','1','2'):
+            p_dec->fmt_in.i_codec = VLC_FOURCC('Y','V','1','2');
+            break;
 
         default:
             return VLC_EGENERIC;
@@ -121,11 +137,19 @@ static int OpenDecoder( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
     /* Misc init */
-    p_dec->p_sys->b_packetizer = VLC_FALSE;
+    p_dec->p_sys->b_packetizer = false;
     p_sys->i_pts = 0;
+    p_sys->b_invert = 0;
+
+    if( (int)p_dec->fmt_in.video.i_height < 0 )
+    {
+        /* Frames are coded from bottom to top */
+        p_dec->fmt_in.video.i_height =
+            (unsigned int)(-(int)p_dec->fmt_in.video.i_height);
+        p_sys->b_invert = true;
+    }
 
-    if( p_dec->fmt_in.video.i_width <= 0 ||
-        p_dec->fmt_in.video.i_height <= 0 )
+    if( p_dec->fmt_in.video.i_width <= 0 || p_dec->fmt_in.video.i_height <= 0 )
     {
         msg_Err( p_dec, "invalid display size %dx%d",
                  p_dec->fmt_in.video.i_width, p_dec->fmt_in.video.i_height );
@@ -143,11 +167,19 @@ static int OpenDecoder( vlc_object_t *p_this )
     /* Set output properties */
     p_dec->fmt_out.i_cat = VIDEO_ES;
     p_dec->fmt_out.i_codec = p_dec->fmt_in.i_codec;
-    //if( !p_dec->fmt_in.video.i_aspect )
+    if( !p_dec->fmt_in.video.i_aspect )
     {
         p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR *
             p_dec->fmt_out.video.i_width / p_dec->fmt_out.video.i_height;
     }
+    else p_dec->fmt_out.video.i_aspect = p_dec->fmt_in.video.i_aspect;
+
+    if( p_dec->fmt_in.video.i_rmask )
+        p_dec->fmt_out.video.i_rmask = p_dec->fmt_in.video.i_rmask;
+    if( p_dec->fmt_in.video.i_gmask )
+        p_dec->fmt_out.video.i_gmask = p_dec->fmt_in.video.i_gmask;
+    if( p_dec->fmt_in.video.i_bmask )
+        p_dec->fmt_out.video.i_bmask = p_dec->fmt_in.video.i_bmask;
 
     /* Set callbacks */
     p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **))
@@ -164,7 +196,7 @@ static int OpenPacketizer( vlc_object_t *p_this )
 
     int i_ret = OpenDecoder( p_this );
 
-    if( i_ret == VLC_SUCCESS ) p_dec->p_sys->b_packetizer = VLC_TRUE;
+    if( i_ret == VLC_SUCCESS ) p_dec->p_sys->b_packetizer = true;
 
     return i_ret;
 }
@@ -184,7 +216,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 
     p_block = *pp_block;
 
-    if( !p_sys->i_pts && !p_block->i_pts )
+    if( !p_sys->i_pts && !p_block->i_pts && !p_block->i_dts )
     {
         /* We've just started the stream, wait for the first PTS. */
         block_Release( p_block );
@@ -192,9 +224,10 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     }
 
     /* Date management */
-    if( p_block->i_pts > 0 && p_block->i_pts != p_sys->i_pts )
+    if( p_block->i_pts > 0 || p_block->i_dts > 0 )
     {
-        p_sys->i_pts = p_block->i_pts;
+        if( p_block->i_pts > 0 ) p_sys->i_pts = p_block->i_pts;
+        else if( p_block->i_dts > 0 ) p_sys->i_pts = p_block->i_dts;
     }
 
     if( p_block->i_buffer < p_sys->i_raw_size )
@@ -216,7 +249,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     }
 
     /* Date management: 1 frame per packet */
-    p_sys->i_pts += ( I64C(1000000) * 1.0 / 25 /*FIXME*/ );
+    p_sys->i_pts += ( INT64_C(1000000) * 1.0 / 25 /*FIXME*/ );
     *pp_block = NULL;
 
     return p_buf;
@@ -229,21 +262,28 @@ static void FillPicture( decoder_t *p_dec, block_t *p_block, picture_t *p_pic )
 {
     uint8_t *p_src, *p_dst;
     int i_src, i_plane, i_line, i_width;
+    decoder_sys_t *p_sys = p_dec->p_sys;
 
-    p_src  = p_block->p_buffer;
+    p_src = p_block->p_buffer;
     i_src = p_block->i_buffer;
 
     for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
     {
         p_dst = p_pic->p[i_plane].p_pixels;
-        i_width = p_pic->p[i_plane].i_visible_pitch;
+        i_width = p_pic->p[i_plane].i_pitch;
 
-        for( i_line = 0; i_line < p_pic->p[i_plane].i_lines; i_line++ )
+        if( p_sys->b_invert )
+            p_src += (i_width * (p_pic->p[i_plane].i_visible_lines - 1));
+
+        for( i_line = 0; i_line < p_pic->p[i_plane].i_visible_lines; i_line++ )
         {
-            p_dec->p_vlc->pf_memcpy( p_dst, p_src, i_width );
-            p_src += i_width;
-            p_dst += p_pic->p[i_plane].i_pitch;
+            vlc_memcpy( p_dst, p_src, i_width );
+            p_src += p_sys->b_invert ? -i_width : i_width;
+            p_dst += i_width;
         }
+
+        if( p_sys->b_invert )
+            p_src += (i_width * (p_pic->p[i_plane].i_visible_lines + 1));
     }
 }
 
@@ -280,6 +320,46 @@ static block_t *SendFrame( decoder_t *p_dec, block_t *p_block )
 
     p_block->i_dts = p_block->i_pts = p_sys->i_pts;
 
+    if( p_sys->b_invert )
+    {
+        picture_t pic;
+        uint8_t *p_tmp, *p_pixels;
+        int i, j;
+
+        /* Fill in picture_t fields */
+        vout_InitPicture( VLC_OBJECT(p_dec), &pic, p_dec->fmt_out.i_codec,
+                          p_dec->fmt_out.video.i_width,
+                          p_dec->fmt_out.video.i_height, VOUT_ASPECT_FACTOR );
+
+        if( !pic.i_planes )
+        {
+            msg_Err( p_dec, "unsupported chroma" );
+            return p_block;
+        }
+
+        p_tmp = malloc( pic.p[0].i_pitch );
+        p_pixels = p_block->p_buffer;
+        for( i = 0; i < pic.i_planes; i++ )
+        {
+            int i_pitch = pic.p[i].i_pitch;
+            uint8_t *p_top = p_pixels;
+            uint8_t *p_bottom = p_pixels + i_pitch *
+                (pic.p[i].i_visible_lines - 1);
+
+            for( j = 0; j < pic.p[i].i_visible_lines / 2; j++ )
+            {
+                vlc_memcpy( p_tmp, p_bottom, pic.p[i].i_visible_pitch  );
+                vlc_memcpy( p_bottom, p_top, pic.p[i].i_visible_pitch  );
+                vlc_memcpy( p_top, p_tmp, pic.p[i].i_visible_pitch  );
+                p_top += i_pitch;
+                p_bottom -= i_pitch;
+            }
+
+            p_pixels += i_pitch * pic.p[i].i_lines;
+        }
+        free( p_tmp );
+    }
+
     return p_block;
 }