]> git.sesse.net Git - vlc/blobdiff - modules/codec/rawvideo.c
omxil: If OMX_IndexParamVideoInit failed, assume 2 ports with index 0 and 1
[vlc] / modules / codec / rawvideo.c
index d6998325d1d73fb7cdd63c013a5dba9b417ac706..3cd8719d030f165535837744313de5efdada5a11 100644 (file)
@@ -1,24 +1,24 @@
 /*****************************************************************************
  * rawvideo.c: Pseudo video decoder/packetizer for raw video data
  *****************************************************************************
- * Copyright (C) 2001, 2002 the VideoLAN team
+ * Copyright (C) 2001, 2002 VLC authors and VideoLAN
  * $Id$
  *
  * 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.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -45,6 +45,7 @@ struct decoder_sys_t
      */
     size_t i_raw_size;
     bool b_invert;
+    plane_t planes[PICTURE_PLANE_MAX];
 
     /*
      * Common properties
@@ -92,13 +93,23 @@ static int OpenDecoder( vlc_object_t *p_this )
     {
         /* Planar YUV */
         case VLC_CODEC_I444:
+        case VLC_CODEC_J444:
+        case VLC_CODEC_I440:
+        case VLC_CODEC_J440:
         case VLC_CODEC_I422:
+        case VLC_CODEC_J422:
         case VLC_CODEC_I420:
+        case VLC_CODEC_J420:
         case VLC_CODEC_YV12:
+        case VLC_CODEC_YV9:
         case VLC_CODEC_I411:
         case VLC_CODEC_I410:
         case VLC_CODEC_GREY:
         case VLC_CODEC_YUVP:
+        case VLC_CODEC_NV12:
+        case VLC_CODEC_NV21:
+        case VLC_CODEC_I422_10L:
+        case VLC_CODEC_I422_10B:
 
         /* Packed YUV */
         case VLC_CODEC_YUYV:
@@ -113,6 +124,7 @@ static int OpenDecoder( vlc_object_t *p_this )
         case VLC_CODEC_RGB15:
         case VLC_CODEC_RGB8:
         case VLC_CODEC_RGBP:
+        case VLC_CODEC_RGBA:
             break;
 
         default:
@@ -125,7 +137,7 @@ static int OpenDecoder( vlc_object_t *p_this )
         return VLC_ENOMEM;
     /* Misc init */
     p_dec->p_sys->b_packetizer = false;
-    p_sys->b_invert = 0;
+    p_sys->b_invert = false;
 
     if( (int)p_dec->fmt_in.video.i_height < 0 )
     {
@@ -159,14 +171,24 @@ static int OpenDecoder( vlc_object_t *p_this )
     video_format_Setup( &p_dec->fmt_out.video, p_dec->fmt_in.i_codec,
                         p_dec->fmt_in.video.i_width,
                         p_dec->fmt_in.video.i_height,
-                        p_dec->fmt_in.video.i_aspect );
-    p_sys->i_raw_size = p_dec->fmt_out.video.i_bits_per_pixel *
-        p_dec->fmt_out.video.i_width * p_dec->fmt_out.video.i_height / 8;
+                        p_dec->fmt_in.video.i_sar_num,
+                        p_dec->fmt_in.video.i_sar_den );
+    picture_t picture;
+    picture_Setup( &picture, p_dec->fmt_out.i_codec,
+                   p_dec->fmt_in.video.i_width,
+                   p_dec->fmt_in.video.i_height, 0, 1 );
+    p_sys->i_raw_size = 0;
+    for( int i = 0; i < picture.i_planes; i++ )
+    {
+        p_sys->i_raw_size += picture.p[i].i_visible_pitch *
+                             picture.p[i].i_visible_lines;
+        p_sys->planes[i] = picture.p[i];
+    }
 
-    if( !p_dec->fmt_in.video.i_aspect )
+    if( !p_dec->fmt_in.video.i_sar_num || !p_dec->fmt_in.video.i_sar_den )
     {
-        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;
     }
 
     /* Set callbacks */
@@ -205,7 +227,8 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     p_block = *pp_block;
 
 
-    if( !p_block->i_pts && !p_block->i_dts && !date_Get( &p_sys->pts ) )
+    if( p_block->i_pts <= VLC_TS_INVALID && p_block->i_dts <= VLC_TS_INVALID &&
+        !date_Get( &p_sys->pts ) )
     {
         /* We've just started the stream, wait for the first PTS. */
         block_Release( p_block );
@@ -213,11 +236,11 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
     }
 
     /* Date management: If there is a pts avaliable, use that. */
-    if( p_block->i_pts )
+    if( p_block->i_pts > VLC_TS_INVALID )
     {
         date_Set( &p_sys->pts, p_block->i_pts );
     }
-    else if( p_block->i_dts )
+    else if( p_block->i_dts > VLC_TS_INVALID )
     {
         /* NB, davidf doesn't quite agree with this in general, it is ok
          * for rawvideo since it is in order (ie pts=dts), however, it
@@ -263,19 +286,19 @@ static void FillPicture( decoder_t *p_dec, block_t *p_block, picture_t *p_pic )
     for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
     {
         int i_pitch = p_pic->p[i_plane].i_pitch;
-        int i_visible_pitch = p_pic->p[i_plane].i_visible_pitch;
-        int i_visible_lines = p_pic->p[i_plane].i_visible_lines;
+        int i_visible_pitch = p_sys->planes[i_plane].i_visible_pitch;
+        int i_visible_lines = p_sys->planes[i_plane].i_visible_lines;
         uint8_t *p_dst = p_pic->p[i_plane].p_pixels;
         uint8_t *p_dst_end = p_dst+i_pitch*i_visible_lines;
 
         if( p_sys->b_invert )
             for( p_dst_end -= i_pitch; p_dst <= p_dst_end;
                  p_dst_end -= i_pitch, p_src += i_visible_pitch )
-                vlc_memcpy( p_dst_end, p_src, i_visible_pitch );
+                memcpy( p_dst_end, p_src, i_visible_pitch );
         else
             for( ; p_dst < p_dst_end;
                  p_dst += i_pitch, p_src += i_visible_pitch )
-                vlc_memcpy( p_dst, p_src, i_visible_pitch );
+                memcpy( p_dst, p_src, i_visible_pitch );
     }
 }
 
@@ -298,7 +321,17 @@ static picture_t *DecodeFrame( decoder_t *p_dec, block_t *p_block )
     FillPicture( p_dec, p_block, p_pic );
 
     p_pic->date = date_Get( &p_sys->pts );
-    p_pic->b_progressive = true;
+    if( p_block->i_flags & BLOCK_FLAG_INTERLACED_MASK )
+    {
+        p_pic->b_progressive = false;
+        p_pic->i_nb_fields = 2;
+        if( p_block->i_flags & BLOCK_FLAG_TOP_FIELD_FIRST )
+            p_pic->b_top_field_first = true;
+        else
+            p_pic->b_top_field_first = false;
+    }
+    else
+        p_pic->b_progressive = true;
 
     block_Release( p_block );
     return p_pic;
@@ -322,7 +355,7 @@ static block_t *SendFrame( decoder_t *p_dec, block_t *p_block )
         /* Fill in picture_t fields */
         picture_Setup( &pic, p_dec->fmt_out.i_codec,
                        p_dec->fmt_out.video.i_width,
-                       p_dec->fmt_out.video.i_height, VOUT_ASPECT_FACTOR );
+                       p_dec->fmt_out.video.i_height, 0, 1 );
 
         if( !pic.i_planes )
         {
@@ -343,9 +376,9 @@ static block_t *SendFrame( decoder_t *p_dec, block_t *p_block )
 
             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  );
+                memcpy( p_tmp, p_bottom, pic.p[i].i_visible_pitch  );
+                memcpy( p_bottom, p_top, pic.p[i].i_visible_pitch  );
+                memcpy( p_top, p_tmp, pic.p[i].i_visible_pitch  );
                 p_top += i_pitch;
                 p_bottom -= i_pitch;
             }