]> git.sesse.net Git - vlc/blobdiff - plugins/dummy/vout_dummy.c
* Fixed aspect ratio handling.
[vlc] / plugins / dummy / vout_dummy.c
index c0b77eda89ec33fe20787e0d53a6317af704da01..aacff2dbacecac35672ea0cfe4457268ae7732e8 100644 (file)
@@ -1,9 +1,10 @@
 /*****************************************************************************
  * vout_dummy.c: Dummy video output display method for testing purposes
  *****************************************************************************
- * Copyright (C) 2000 VideoLAN
+ * Copyright (C) 2000, 2001 VideoLAN
+ * $Id: vout_dummy.c,v 1.11 2001/12/13 12:47:17 sam Exp $
  *
- * Authors:
+ * Authors: Samuel Hocevar <sam@zoy.org>
  *
  * 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
@@ -20,6 +21,9 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
+#define MODULE_NAME dummy
+#include "modules_inner.h"
+
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
 #include <stdlib.h>                                                /* free() */
 #include <string.h>                                            /* strerror() */
 
-#include "config.h"
 #include "common.h"
+#include "intf_msg.h"
 #include "threads.h"
 #include "mtime.h"
-#include "plugins.h"
+#include "tests.h"
 
 #include "video.h"
 #include "video_output.h"
 
-#include "intf_msg.h"
+#include "modules.h"
+#include "modules_export.h"
 
-#define WIDTH 128
-#define HEIGHT 64
-#define BITS_PER_PLANE 16
-#define BYTES_PER_PIXEL 2
+#define DUMMY_WIDTH 16
+#define DUMMY_HEIGHT 16
+#define DUMMY_MAX_DIRECTBUFFERS 5
 
 /*****************************************************************************
  * vout_sys_t: dummy video output method descriptor
  *****************************************************************************/
 typedef struct vout_sys_s
 {
-    /* Dummy video memory */
-    byte_t *                    p_video;                      /* base adress */
-    size_t                      i_page_size;                    /* page size */
+    /* Nothing needed here. Maybe stats ? */
 
 } vout_sys_t;
 
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int     DummyOpenDisplay   ( vout_thread_t *p_vout );
-static void    DummyCloseDisplay  ( vout_thread_t *p_vout );
+static int  vout_Probe     ( probedata_t *p_data );
+static int  vout_Create    ( struct vout_thread_s * );
+static int  vout_Init      ( struct vout_thread_s * );
+static void vout_End       ( struct vout_thread_s * );
+static void vout_Destroy   ( struct vout_thread_s * );
+static int  vout_Manage    ( struct vout_thread_s * );
+static void vout_Display   ( struct vout_thread_s *, struct picture_s * );
+
+static int  DummyNewPicture( struct vout_thread_s *, struct picture_s * );
 
 /*****************************************************************************
- * vout_SysCreate: allocates dummy video thread output method
+ * Functions exported as capabilities. They are declared as static so that
+ * we don't pollute the namespace too much.
+ *****************************************************************************/
+void _M( vout_getfunctions )( function_list_t * p_function_list )
+{
+    p_function_list->pf_probe = vout_Probe;
+    p_function_list->functions.vout.pf_create     = vout_Create;
+    p_function_list->functions.vout.pf_init       = vout_Init;
+    p_function_list->functions.vout.pf_end        = vout_End;
+    p_function_list->functions.vout.pf_destroy    = vout_Destroy;
+    p_function_list->functions.vout.pf_manage     = vout_Manage;
+    p_function_list->functions.vout.pf_display    = vout_Display;
+    p_function_list->functions.vout.pf_setpalette = NULL;
+}
+
+/*****************************************************************************
+ * intf_Probe: return a score
+ *****************************************************************************/
+static int vout_Probe( probedata_t *p_data )
+{
+    if( TestMethod( VOUT_METHOD_VAR, "dummy" ) )
+    {
+        return( 999 );
+    }
+
+    return( 1 );
+}
+
+/*****************************************************************************
+ * vout_Create: allocates dummy video thread output method
  *****************************************************************************
  * This function allocates and initializes a dummy vout method.
  *****************************************************************************/
-int vout_SysCreate( vout_thread_t *p_vout, char *psz_display,
-                    int i_root_window, void *p_data )
+static int vout_Create( vout_thread_t *p_vout )
 {
     /* Allocate structure */
     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
     if( p_vout->p_sys == NULL )
     {
-        intf_ErrMsg("error: %s\n", strerror(ENOMEM) );
-        return( 1 );
-    }
-
-    /* Open and initialize device */
-    if( DummyOpenDisplay( p_vout ) )
-    {
-        intf_ErrMsg("vout error: can't open display\n");
-        free( p_vout->p_sys );
+        intf_ErrMsg("error: %s", strerror(ENOMEM) );
         return( 1 );
     }
 
@@ -93,97 +122,179 @@ int vout_SysCreate( vout_thread_t *p_vout, char *psz_display,
 }
 
 /*****************************************************************************
- * vout_SysInit: initialize dummy video thread output method
+ * vout_Init: initialize dummy video thread output method
  *****************************************************************************/
-int vout_SysInit( vout_thread_t *p_vout )
+static int vout_Init( vout_thread_t *p_vout )
 {
+    int i_index;
+    picture_t *p_pic;
+    
+    I_OUTPUTPICTURES = 0;
+
+    /* Initialize the output structure */
+    switch( p_vout->render.i_chroma )
+    {
+        case YUV_420_PICTURE:
+            p_vout->output.i_chroma = p_vout->render.i_chroma;
+            p_vout->output.i_width  = p_vout->render.i_width;
+            p_vout->output.i_height = p_vout->render.i_height;
+            p_vout->output.i_aspect = p_vout->render.i_aspect;
+            break;
+
+        default:
+            p_vout->output.i_chroma = RGB_16BPP_PICTURE;
+            p_vout->output.i_width  = p_vout->render.i_width;
+            p_vout->output.i_height = p_vout->render.i_height;
+            p_vout->output.i_aspect = p_vout->render.i_aspect;
+            break;
+    }
+
+    /* Try to initialize DUMMY_MAX_DIRECTBUFFERS direct buffers */
+    while( I_OUTPUTPICTURES < DUMMY_MAX_DIRECTBUFFERS )
+    {
+        p_pic = NULL;
+
+        /* Find an empty picture slot */
+        for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
+        {
+            if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
+            {
+                p_pic = p_vout->p_picture + i_index;
+                break;
+            }
+        }
+
+        /* Allocate the picture */
+        if( DummyNewPicture( p_vout, p_pic ) )
+        {
+            break;
+        }
+
+        p_pic->i_status        = DESTROYED_PICTURE;
+        p_pic->i_type          = DIRECT_PICTURE;
+
+        p_pic->i_left_margin   =
+        p_pic->i_right_margin  =
+        p_pic->i_top_margin    =
+        p_pic->i_bottom_margin = 0;
+
+        PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
+
+        I_OUTPUTPICTURES++;
+    }
+
     return( 0 );
 }
 
 /*****************************************************************************
- * vout_SysEnd: terminate dummy video thread output method
+ * vout_End: terminate dummy video thread output method
  *****************************************************************************/
-void vout_SysEnd( vout_thread_t *p_vout )
+static void vout_End( vout_thread_t *p_vout )
 {
-    ;
+    int i_index;
+
+    /* Free the fake output buffers we allocated */
+    for( i_index = I_OUTPUTPICTURES ; i_index ; )
+    {
+        i_index--;
+        free( PP_OUTPUTPICTURE[ i_index ]->planes[ 0 ].p_data );
+    }
 }
 
 /*****************************************************************************
- * vout_SysDestroy: destroy dummy video thread output method
+ * vout_Destroy: destroy dummy video thread output method
  *****************************************************************************
  * Terminate an output method created by DummyCreateOutputMethod
  *****************************************************************************/
-void vout_SysDestroy( vout_thread_t *p_vout )
+static void vout_Destroy( vout_thread_t *p_vout )
 {
-    DummyCloseDisplay( p_vout );
     free( p_vout->p_sys );
 }
 
 /*****************************************************************************
- * vout_SysManage: handle dummy events
+ * vout_Manage: handle dummy events
  *****************************************************************************
  * This function should be called regularly by video output thread. It manages
  * console events. It returns a non null value on error.
  *****************************************************************************/
-int vout_SysManage( vout_thread_t *p_vout )
+static int vout_Manage( vout_thread_t *p_vout )
 {
     return( 0 );
 }
 
 /*****************************************************************************
- * vout_SysDisplay: displays previously rendered output
+ * vout_Display: displays previously rendered output
  *****************************************************************************
  * This function send the currently rendered image to dummy image, waits until
  * it is displayed and switch the two rendering buffers, preparing next frame.
  *****************************************************************************/
-void vout_SysDisplay( vout_thread_t *p_vout )
+static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
 {
-    ;
+    /* No need to do anything, the fake direct buffers stay as they are */
 }
 
-/* following functions are local */
 
 /*****************************************************************************
- * DummyOpenDisplay: open and initialize dummy device
+ * DummyNewPicture: allocate a picture
  *****************************************************************************
- * XXX?? The framebuffer mode is only provided as a fast and efficient way to
- * display video, providing the card is configured and the mode ok. It is
- * not portable, and is not supposed to work with many cards. Use at your
- * own risk !
+ * Returns 0 on success, -1 otherwise
  *****************************************************************************/
-
-static int DummyOpenDisplay( vout_thread_t *p_vout )
+static int DummyNewPicture( vout_thread_t *p_vout, picture_t *p_pic )
 {
-    p_vout->i_width =                   WIDTH;
-    p_vout->i_height =                  HEIGHT;
-    p_vout->i_screen_depth =            BITS_PER_PLANE;
-    p_vout->i_bytes_per_pixel =         BYTES_PER_PIXEL;
-    p_vout->i_bytes_per_line =          WIDTH * BYTES_PER_PIXEL;
+    int i_luma_bytes, i_chroma_bytes;
 
-    p_vout->p_sys->i_page_size = WIDTH * HEIGHT * BYTES_PER_PIXEL;
+    int i_width  = p_vout->output.i_width;
+    int i_height = p_vout->output.i_height;
 
-    /* Map two framebuffers a the very beginning of the fb */
-    p_vout->p_sys->p_video = malloc( p_vout->p_sys->i_page_size * 2 );
-    if( (int)p_vout->p_sys->p_video == -1 )
+    switch( p_vout->output.i_chroma )
     {
-        intf_ErrMsg("vout error: can't map video memory (%s)\n", strerror(errno) );
-        return( 1 );
-    }
+    /* We know this chroma, allocate a buffer which will be used
+     * directly by the decoder */
+    case YUV_420_PICTURE:
 
-    /* Set and initialize buffers */
-    vout_SetBuffers( p_vout, p_vout->p_sys->p_video,
-                     p_vout->p_sys->p_video + p_vout->p_sys->i_page_size );
-    return( 0 );
-}
+        /* Precalculate some values */
+        p_pic->i_size         = i_width * i_height;
+        p_pic->i_chroma_width = i_width / 2;
+        p_pic->i_chroma_size  = i_width * i_height / 2;
 
-/*****************************************************************************
- * DummyCloseDisplay: close and reset dummy device
- *****************************************************************************
- * Returns all resources allocated by DummyOpenDisplay and restore the original
- * state of the device.
- *****************************************************************************/
-static void DummyCloseDisplay( vout_thread_t *p_vout )
-{
-    free( p_vout->p_sys->p_video );
+        /* Allocate the memory buffer */
+        i_luma_bytes = p_pic->i_size * sizeof(pixel_data_t);
+        i_chroma_bytes = p_pic->i_chroma_size * sizeof(pixel_data_t);
+
+        /* Y buffer */
+        p_pic->planes[ Y_PLANE ].p_data = malloc( i_luma_bytes + 2 * i_chroma_bytes );
+        p_pic->planes[ Y_PLANE ].i_bytes = i_luma_bytes;
+
+        /* U buffer */
+        p_pic->planes[ U_PLANE ].p_data = p_pic->planes[ Y_PLANE ].p_data + i_height * i_width;
+        p_pic->planes[ U_PLANE ].i_bytes = i_chroma_bytes;
+
+        /* V buffer */
+        p_pic->planes[ V_PLANE ].p_data = p_pic->planes[ U_PLANE ].p_data + i_height * p_pic->i_chroma_width;
+        p_pic->planes[ V_PLANE ].i_bytes = i_chroma_bytes;
+
+        /* We allocated 3 planes */
+        p_pic->i_planes = 3;
+
+        return( 0 );
+        break;
+
+    /* Unknown chroma, allocate an RGB buffer, the video output's job
+     * will be to do the chroma->RGB conversion */
+    default:
+
+        /* Precalculate some values */
+        i_luma_bytes = sizeof(u16) * i_width * i_height;
+
+        /* Allocate the memory buffer */
+        p_pic->planes[ RGB_PLANE ].p_data = malloc( i_luma_bytes );
+        p_pic->planes[ RGB_PLANE ].i_bytes = i_luma_bytes;
+
+        /* We allocated 1 plane */
+        p_pic->i_planes = 1;
+
+        return( 0 );
+        break;
+    }
 }