Commit 4cff6916 authored by Pierre Baillet's avatar Pierre Baillet

- Added SDL sound support. Sounds a bit laggy sometimes but my streams are ill.

  please try.
- modified configure.in and all that stuff. Re-run configure
- SDL audio, video and interface are all part of the same .so now.
- remove YUV old files :->
parent 3a8481df
......@@ -291,7 +291,8 @@ PLUGIN_BEOS = plugins/beos/beos.o \
plugins/beos/vout_beos.o
PLUGIN_DSP = plugins/dsp/dsp.o \
plugins/dsp/aout_dsp.o \
plugins/dsp/aout_dsp.o
PLUGIN_DUMMY = plugins/dummy/dummy.o \
plugins/dummy/aout_dummy.o \
......@@ -311,9 +312,8 @@ PLUGIN_GGI = plugins/ggi/ggi.o \
PLUGIN_SDL = plugins/sdl/sdl.o \
plugins/sdl/intf_sdl.o \
plugins/sdl/vout_sdl.o
# plugins/sdl/video_yuv.o \
# plugins/sdl/video_yuvall.o
plugins/sdl/vout_sdl.o \
plugins/sdl/aout_sdl.o
PLUGIN_NULL = plugins/null/null.o
......
/*****************************************************************************
* aout_sdl.c : audio sdl functions library
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
* Pierre Baillet <oct@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
* the Free Software Foundation; either version 2 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.
*
* 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.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include "defs.h"
#include <errno.h> /* ENOMEM */
#include <fcntl.h> /* open(), O_WRONLY */
#include <sys/ioctl.h> /* ioctl() */
#include <string.h> /* strerror() */
#include <unistd.h> /* write(), close() */
#include <stdio.h> /* "intf_msg.h" */
#include <stdlib.h> /* calloc(), malloc(), free() */
#include "SDL/SDL.h" /* SDL base include */
#include "config.h"
#include "common.h" /* boolean_t, byte_t */
#include "threads.h"
#include "mtime.h"
#include "plugins.h"
#include "audio_output.h" /* aout_thread_t */
#include "intf_msg.h" /* intf_DbgMsg(), intf_ErrMsg() */
#include "main.h"
#include "modules.h"
/*****************************************************************************
* aout_sys_t: dsp audio output method descriptor
*****************************************************************************
* This structure is part of the audio output thread descriptor.
* It describes the dsp specific properties of an audio device.
*****************************************************************************/
/* the overflow limit is used to prevent the fifo from growing too big */
#define OVERFLOWLIMIT 100000
typedef struct aout_sys_s
{
byte_t * audio_buf;
int i_audio_end;
} aout_sys_t;
/*****************************************************************************
* Local prototypes.
*****************************************************************************/
static int aout_Probe ( probedata_t *p_data );
static int aout_Open ( aout_thread_t *p_aout );
static int aout_SetFormat ( aout_thread_t *p_aout );
static long aout_GetBufInfo ( aout_thread_t *p_aout, long l_buffer_info );
static void aout_Play ( aout_thread_t *p_aout,
byte_t *buffer, int i_size );
static void aout_Close ( aout_thread_t *p_aout );
static void SDL_aout_callback(void *userdata, Uint8 *stream, int len);
/*****************************************************************************
* Functions exported as capabilities. They are declared as static so that
* we don't pollute the namespace too much.
*****************************************************************************/
void aout_getfunctions( function_list_t * p_function_list )
{
p_function_list->pf_probe = aout_Probe;
p_function_list->functions.aout.pf_open = aout_Open;
p_function_list->functions.aout.pf_setformat = aout_SetFormat;
p_function_list->functions.aout.pf_getbufinfo = aout_GetBufInfo;
p_function_list->functions.aout.pf_play = aout_Play;
p_function_list->functions.aout.pf_close = aout_Close;
}
/*****************************************************************************
* aout_Probe: probes the audio device and return a score
*****************************************************************************
* This function tries to open the dps and returns a score to the plugin
* manager so that it can select the best plugin.
*****************************************************************************/
static int aout_Probe( probedata_t *p_data )
{
SDL_AudioSpec *desired, *obtained;
/* Start AudioSDL */
if( SDL_Init(SDL_INIT_AUDIO) != 0)
intf_ErrMsgImm( "aout_Probe: SDL init error: %s", SDL_GetError() );
/* asks for a minimum audio spec so that we are sure the dsp exists */
desired = (SDL_AudioSpec *)malloc( sizeof(SDL_AudioSpec) );
obtained = (SDL_AudioSpec *)malloc( sizeof(SDL_AudioSpec) );
desired->freq = 11025; /* frequency */
desired->format = AUDIO_U8; /* unsigned 8 bits */
desired->channels = 2; /* mono */
desired->callback = SDL_aout_callback; /* no callback function yet */
desired->userdata = NULL; /* null parm for callback */
desired->samples = 4096;
/* If we were unable to open the device, there is no way we can use
* the plugin. Return a score of 0. */
if(SDL_OpenAudio( desired, obtained ) < 0)
{
SDL_CloseAudio();
intf_ErrMsgImm( "aout_Probe: aout sdl error : %s", SDL_GetError() );
return( 0 );
}
/* Otherwise, there are good chances we can use this plugin, return 100. */
SDL_CloseAudio();
return( 100 );
}
/*****************************************************************************
* aout_Open: opens the audio device (the digital sound processor)
*****************************************************************************
* This function opens the dsp as a usual non-blocking write-only file, and
* modifies the p_aout->i_fd with the file's descriptor.
*****************************************************************************/
static int aout_Open( aout_thread_t *p_aout )
{
SDL_AudioSpec *desired;
int i_stereo = p_aout->b_stereo?2:1;
/* asks for a minimum audio spec so that we are sure the dsp exists */
desired = (SDL_AudioSpec *)malloc( sizeof(SDL_AudioSpec) );
/* Allocate structure */
p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
if( p_aout->p_sys == NULL )
{
intf_ErrMsg("aout_Open error: %s", strerror(ENOMEM) );
return( 1 );
}
p_aout->p_sys->i_audio_end = 0;
p_aout->p_sys->audio_buf = NULL;
/* Initialize some variables */
p_aout->psz_device = 0;
p_aout->i_format = AOUT_FORMAT_DEFAULT;
p_aout->i_channels = 1 + main_GetIntVariable( AOUT_STEREO_VAR,
AOUT_STEREO_DEFAULT );
p_aout->l_rate = main_GetIntVariable( AOUT_RATE_VAR,
AOUT_RATE_DEFAULT );
desired->freq = p_aout->l_rate;
/* TODO: write conversion beetween AOUT_FORMAT_DEFAULT
* AND AUDIO* from SDL. */
desired->format = AUDIO_S16LSB; /* stereo 16 bits */
desired->channels = i_stereo;
desired->callback = SDL_aout_callback;
desired->userdata = p_aout->p_sys;
desired->samples = 2048;
/* Open the sound device
* we just ask the SDL to wrap at the good frequency if the one we
* ask for is unavailable. This is done by setting the second parar
* to NULL
*/
if( SDL_OpenAudio(desired,NULL) < 0 )
{
intf_ErrMsgImm( "aout_Open error: can't open audio device: %s",
SDL_GetError() );
return( -1 );
}
SDL_PauseAudio(0);
return( 0 );
}
/*****************************************************************************
* aout_SetFormat: resets the dsp and sets its format
*****************************************************************************
* This functions resets the DSP device, tries to initialize the output
* format with the value contained in the dsp structure, and if this value
* could not be set, the default value returned by ioctl is set. It then
* does the same for the stereo mode, and for the output rate.
*****************************************************************************/
static int aout_SetFormat( aout_thread_t *p_aout )
{
/* TODO: finish and clean this */
SDL_AudioSpec *desired;
int i_stereo = p_aout->b_stereo?2:1;
desired = (SDL_AudioSpec *)malloc( sizeof(SDL_AudioSpec) );
/* i_format = p_aout->i_format;
*/
desired->freq = p_aout->l_rate; /* Set the output rate */
desired->format = AUDIO_S16LSB; /* stereo 16 bits */
desired->channels = i_stereo;
desired->callback = SDL_aout_callback;
desired->userdata = p_aout->p_sys;
desired->samples = 2048;
/* Open the sound device */
SDL_PauseAudio(1);
SDL_CloseAudio();
if( SDL_OpenAudio(desired,NULL) < 0 )
return( -1 );
SDL_PauseAudio(0);
return(0);
}
/*****************************************************************************
* aout_GetBufInfo: buffer status query
*****************************************************************************
* returns the number of bytes in the audio buffer compared to the size of
* l_buffer_limit...
*****************************************************************************/
static long aout_GetBufInfo( aout_thread_t *p_aout, long l_buffer_limit )
{
return( p_aout->p_sys->i_audio_end-l_buffer_limit);
}
static void SDL_aout_callback(void *userdata, byte_t *stream, int len)
{
struct aout_sys_s * p_sys = userdata;
int end = p_sys->i_audio_end;
if(end > OVERFLOWLIMIT)
{
intf_ErrMsgImm("aout SDL_aout_callback: Overflow.");
free(p_sys->audio_buf);
p_sys->audio_buf = NULL;
p_sys->i_audio_end = 0;
end = 0;
// we've gone to slow, increase output freq
}
/* if we are not in underrun */
if(end>len)
{
memcpy(stream, p_sys->audio_buf, len);
memmove(p_sys->audio_buf, &(p_sys->audio_buf[len]), end-len);
p_sys->audio_buf = realloc(p_sys->audio_buf, end-len);
p_sys->i_audio_end -= len;
}
}
/*****************************************************************************
* aout_Play: plays a sound samples buffer
*****************************************************************************
* This function writes a buffer of i_length bytes in the dsp
*****************************************************************************/
static void aout_Play( aout_thread_t *p_aout, byte_t *buffer, int i_size )
{
byte_t * audio_buf = p_aout->p_sys->audio_buf;
SDL_LockAudio(); /* Stop callbacking */
audio_buf = realloc(audio_buf, p_aout->p_sys->i_audio_end + i_size);
memcpy(&(audio_buf[p_aout->p_sys->i_audio_end]), buffer, i_size);
p_aout->p_sys->i_audio_end += i_size;
p_aout->p_sys->audio_buf = audio_buf;
SDL_UnlockAudio(); /* go on callbacking */
}
/*****************************************************************************
* aout_Close: closes the dsp audio device
*****************************************************************************/
static void aout_Close( aout_thread_t *p_aout )
{
SDL_LockAudio(); /* Stop callbacking */
SDL_PauseAudio(1); /* pause audio */
if(p_aout->p_sys->audio_buf != NULL) /* do we have a buffer now ? */
{
free(p_aout->p_sys->audio_buf);
}
free(p_aout->p_sys); /* Close the Output. */
SDL_CloseAudio();
}
......@@ -22,6 +22,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#define MODULE_NAME sdl
/*****************************************************************************
* Preamble
*****************************************************************************/
......@@ -41,15 +43,27 @@
#include "video.h"
#include "video_output.h"
/* audio includes */
#include "modules.h"
#include "modules_inner.h"
/*****************************************************************************
* Building configuration tree
*****************************************************************************/
MODULE_CONFIG_START
ADD_WINDOW( "Configuration for sdl module" )
ADD_COMMENT( "For now, the sdl module cannot be configured" )
MODULE_CONFIG_END
/*****************************************************************************
* Exported prototypes
*****************************************************************************/
static void vout_GetPlugin( p_vout_thread_t p_vout );
static void intf_GetPlugin( p_intf_thread_t p_intf );
#if 0
static void yuv_GetPlugin( p_vout_thread_t p_vout );
#endif
/* Video output */
int vout_SDLCreate ( vout_thread_t *p_vout, char *psz_display,
......@@ -61,19 +75,17 @@ int vout_SDLManage ( p_vout_thread_t p_vout );
void vout_SDLDisplay ( p_vout_thread_t p_vout );
void vout_SDLSetPalette ( p_vout_thread_t p_vout,
u16 *red, u16 *green, u16 *blue, u16 *transp );
#if 0
/* YUV transformations */
int yuv_CInit ( p_vout_thread_t p_vout );
int yuv_CReset ( p_vout_thread_t p_vout );
void yuv_CEnd ( p_vout_thread_t p_vout );
#endif
/* Interface */
int intf_SDLCreate ( p_intf_thread_t p_intf );
void intf_SDLDestroy ( p_intf_thread_t p_intf );
void intf_SDLManage ( p_intf_thread_t p_intf );
/*****************************************************************************
* * Capabilities defined in the other files.
******************************************************************************/
extern void aout_getfunctions( function_list_t * p_function_list );
/*****************************************************************************
* GetConfig: get the plugin structure and configuration
*****************************************************************************/
......@@ -88,17 +100,7 @@ plugin_info_t * GetConfig( void )
p_info->aout_GetPlugin = NULL;
p_info->vout_GetPlugin = vout_GetPlugin;
p_info->intf_GetPlugin = intf_GetPlugin;
/* TODO: before doing this, we have to know if the videoCard is capable of
* hardware YUV -> display acceleration....
*/
#if 0
p_info->yuv_GetPlugin = (void *) yuv_GetPlugin;
#else
p_info->yuv_GetPlugin = NULL;
#endif
/* if the SDL libraries are there, assume we can enter the
......@@ -138,12 +140,64 @@ static void intf_GetPlugin( p_intf_thread_t p_intf )
p_intf->p_sys_manage = intf_SDLManage;
}
#if 0
static void yuv_GetPlugin( p_vout_thread_t p_vout )
/*****************************************************************************
* Audio stuff: All the new modules things
*****************************************************************************/
/*****************************************************************************
* InitModule: get the module structure and configuration.
*****************************************************************************
* We have to fill psz_name, psz_longname and psz_version. These variables
* will be strdup()ed later by the main application because the module can
* be unloaded later to save memory, and we want to be able to access this
* data even after the module has been unloaded.
*****************************************************************************/
int InitModule( module_t * p_module )
{
p_module->psz_name = MODULE_STRING;
p_module->psz_longname = "Linux SDL audio module";
p_module->psz_version = VERSION;
p_module->i_capabilities = MODULE_CAPABILITY_NULL
| MODULE_CAPABILITY_AOUT;
return( 0 );
}
/*****************************************************************************
* ActivateModule: set the module to an usable state.
*****************************************************************************
* This function fills the capability functions and the configuration
* structure. Once ActivateModule() has been called, the i_usage can
* be set to 0 and calls to NeedModule() be made to increment it. To unload
* the module, one has to wait until i_usage == 0 and call DeactivateModule().
*****************************************************************************/
int ActivateModule( module_t * p_module )
{
p_vout->p_yuv_init = yuv_CInit;
p_vout->p_yuv_reset = yuv_CReset;
p_vout->p_yuv_end = yuv_CEnd;
p_module->p_functions = malloc( sizeof( module_functions_t ) );
if( p_module->p_functions == NULL )
{
return( -1 );
}
aout_getfunctions( &p_module->p_functions->aout );
p_module->p_config = p_config;
return( 0 );
}
/*****************************************************************************
* DeactivateModule: make sure the module can be unloaded.
*****************************************************************************
* This function must only be called when i_usage == 0. If it successfully
* returns, i_usage can be set to -1 and the module unloaded. Be careful to
* lock usage_lock during the whole process.
*****************************************************************************/
int DeactivateModule( module_t * p_module )
{
free( p_module->p_functions );
return( 0 );
}
#endif
/*****************************************************************************
* video_yuv.c: YUV transformation functions
* Provides functions to perform the YUV conversion. The functions provided here
* are a complete and portable C implementation, and may be replaced in certain
* case by optimized functions.
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
*
* Authors:
*
* 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
* (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.
*
* 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-1307, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include "defs.h"
#include <math.h> /* exp(), pow() */
#include <errno.h> /* ENOMEM */
#include <stdlib.h> /* free() */
#include <string.h> /* strerror() */
#include "config.h"
#include "common.h"
#include "threads.h"
#include "mtime.h"
#include "plugins.h"
#include "video.h"
#include "video_output.h"
#include "video_yuv.h"
#include "intf_msg.h"
/*****************************************************************************
* vout_InitYUV: allocate and initialize translations tables
*****************************************************************************
* This function will allocate memory to store translation tables, depending
* of the screen depth.
*****************************************************************************/
int yuv_CInit( vout_thread_t *p_vout )
{
/* Initialize tables */
SetSDLYUV( p_vout );
return( 0 );
}
/*****************************************************************************
* yuv_CEnd: destroy translations tables
*****************************************************************************
* Free memory allocated by yuv_CCreate.
*****************************************************************************/
void yuv_CEnd( vout_thread_t *p_vout )
{
free( p_vout->yuv.p_base );
free( p_vout->yuv.p_buffer );
free( p_vout->yuv.p_offset );
}
/*****************************************************************************
* yuv_CReset: re-initialize translations tables
*****************************************************************************
* This function will initialize the tables allocated by vout_CreateTables and
* set functions pointers.
*****************************************************************************/
int yuv_CReset( vout_thread_t *p_vout )
{
yuv_CEnd( p_vout );
return( yuv_CInit( p_vout ) );
}
/* following functions are local */
/*****************************************************************************
* SetYUV: compute tables and set function pointers
+ *****************************************************************************/
void SetSDLYUV( vout_thread_t *p_vout )
{
/*
* Set functions pointers
*/
if( p_vout->b_grayscale )
{
/* Grayscale */
switch( p_vout->i_bytes_per_pixel )
{
case 1:
p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) Convert8;
p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) Convert8;
p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) Convert8;
break;
case 2:
p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) Convert16;
p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) Convert16;
p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) Convert16;
break;
case 3:
p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) Convert24;
p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) Convert24;
p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) Convert24;
break;
case 4:
p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) Convert32;
p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) Convert32;
p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) Convert32;
break;
}
}
else
{
/* Color */
switch( p_vout->i_bytes_per_pixel )
{
case 1:
p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertRGB8;
p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertRGB8;
p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertRGB8;
break;
case 2:
p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertRGB16;
p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertRGB16;
p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertRGB16;
break;
case 3:
p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertRGB24;
p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertRGB24;
p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertRGB24;
break;
case 4:
p_vout->yuv.p_Convert420 = (vout_yuv_convert_t *) ConvertRGB32;
p_vout->yuv.p_Convert422 = (vout_yuv_convert_t *) ConvertRGB32;
p_vout->yuv.p_Convert444 = (vout_yuv_convert_t *) ConvertRGB32;
break;
}
}
}
/*****************************************************************************
* video_yuv.h: YUV transformation functions
* Provides functions to perform the YUV conversion. The functions provided here
* are a complete and portable C implementation, and may be replaced in certain
* case by optimized functions.
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
*
* Authors:
*
* 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
* (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.
*
* 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-1307, USA.
*****************************************************************************/
/*****************************************************************************
* Constants
*****************************************************************************/
/* Margins and offsets in conversion tables - Margins are used in case a RGB
* RGB conversion would give a value outside the 0-255 range. Offsets have been
* calculated to avoid using the same cache line for 2 tables. conversion tables
* are 2*MARGIN + 256 long and stores pixels.*/
#define RED_MARGIN 178
#define GREEN_MARGIN 135
#define BLUE_MARGIN 224
#define RED_OFFSET 1501 /* 1323 to 1935 */
#define GREEN_OFFSET 135 /* 0 to 526 */
#define BLUE_OFFSET 818 /* 594 to 1298 */
#define RGB_TABLE_SIZE 1935 /* total table size */
#define GRAY_MARGIN 384
#define GRAY_TABLE_SIZE 1024 /* total table size */
#define PALETTE_TABLE_SIZE 2176 /* YUV -> 8bpp palette lookup table */
/* macros used for YUV pixel conversions */
#define SHIFT 20
#define U_GREEN_COEF ((int)(-0.391 * (1<<SHIFT) / 1.164))
#define U_BLUE_COEF ((int)(2.018 * (1<<SHIFT) / 1.164))
#define V_RED_COEF ((int)(1.596 * (1<<SHIFT) / 1.164))
#define V_GREEN_COEF ((int)(-0.813 * (1<<SHIFT) / 1.164))
/* argument lists for YUV functions */
#define YUV_ARGS( word_size ) p_vout_thread_t p_vout, word_size *p_pic, \
yuv_data_t *p_y, yuv_data_t *p_u, yuv_data_t *p_v, int i_width, int i_height, \
int i_pic_width, int i_pic_height, int i_pic_line_width, \
int i_matrix_coefficients
#define YUV_ARGS_8BPP YUV_ARGS( u8 )
#define YUV_ARGS_16BPP YUV_ARGS( u16 )
#define YUV_ARGS_24BPP YUV_ARGS( u32 )
#define YUV_ARGS_32BPP YUV_ARGS( u32 )
/*****************************************************************************
* Local prototypes
*****************************************************************************/
void SetGammaTable ( int *pi_table, double f_gamma );
void SetYUV ( vout_thread_t *p_vout );
void SetOffset ( int i_width, int i_height, int i_pic_width,
int i_pic_height, boolean_t *pb_h_scaling,
int *pi_v_scaling, int *p_offset,
boolean_t b_double );
void Convert8 ( YUV_ARGS_8BPP );
void ConvertRGB8 ( YUV_ARGS_8BPP );
void Convert16 ( YUV_ARGS_16BPP );
void ConvertRGB16 ( YUV_ARGS_16BPP );
void Convert24 ( YUV_ARGS_24BPP );
void ConvertRGB24 ( YUV_ARGS_24BPP );
void Convert32 ( YUV_ARGS_32BPP );
void ConvertRGB32 ( YUV_ARGS_32BPP );
/*****************************************************************************
* video_yuv_macros_truecolor.h: YUV transformation macros for truecolor
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
*
* Authors:
*
* 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
* (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.
*
* 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-1307, USA.
*****************************************************************************/
/*****************************************************************************
* CONVERT_YUV_PIXEL, CONVERT_Y_PIXEL: pixel conversion blocks
*****************************************************************************
* These conversion routines are used by YUV conversion functions.
* conversion are made from p_y, p_u, p_v, which are modified, to p_buffer,
* which is also modified.
*****************************************************************************/
#define CONVERT_Y_PIXEL( BPP ) \
/* Only Y sample is present */ \
p_ybase = p_yuv + *p_y++; \
*p_buffer++ = p_ybase[RED_OFFSET-((V_RED_COEF*128)>>SHIFT) + i_red] | \
p_ybase[GREEN_OFFSET-(((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT) \
+ i_green ] | p_ybase[BLUE_OFFSET-((U_BLUE_COEF*128)>>SHIFT) + i_blue];
#define CONVERT_YUV_PIXEL( BPP ) \
/* Y, U and V samples are present */ \
i_uval = *p_u++; \
i_vval = *p_v++; \
i_red = (V_RED_COEF * i_vval) >> SHIFT; \
i_green = (U_GREEN_COEF * i_uval + V_GREEN_COEF * i_vval) >> SHIFT; \
i_blue = (U_BLUE_COEF * i_uval) >> SHIFT; \
CONVERT_Y_PIXEL( BPP ) \
/*****************************************************************************
* SCALE_WIDTH: scale a line horizontally
*****************************************************************************
* This macro scales a line using rendering buffer and offset array. It works
* for 1, 2 and 4 Bpp.
*****************************************************************************/
#define SCALE_WIDTH \
if( b_horizontal_scaling ) \
{ \
/* Horizontal scaling, conversion has been done to buffer. \
* Rewind buffer and offset, then copy and scale line */ \
p_buffer = p_buffer_start; \
p_offset = p_offset_start; \
for( i_x = i_pic_width / 16; i_x--; ) \
{ \
*p_pic++ = *p_buffer; p_buffer += *p_offset++; \
*p_pic++ = *p_buffer; p_buffer += *p_offset++; \
*p_pic++ = *p_buffer; p_buffer += *p_offset++; \
*p_pic++ = *p_buffer; p_buffer += *p_offset++; \
*p_pic++ = *p_buffer; p_buffer += *p_offset++; \
*p_pic++ = *p_buffer; p_buffer += *p_offset++; \
*p_pic++ = *p_buffer; p_buffer += *p_offset++; \
*p_pic++ = *p_buffer; p_buffer += *p_offset++; \
*p_pic++ = *p_buffer; p_buffer += *p_offset++; \
*p_pic++ = *p_buffer; p_buffer += *p_offset++; \
*p_pic++ = *p_buffer; p_buffer += *p_offset++; \
*p_pic++ = *p_buffer; p_buffer += *p_offset++; \
*p_pic++ = *p_buffer; p_buffer += *p_offset++; \
*p_pic++ = *p_buffer; p_buffer += *p_offset++; \
*p_pic++ = *p_buffer; p_buffer += *p_offset++; \
*p_pic++ = *p_buffer; p_buffer += *p_offset++; \
} \
p_pic += i_pic_line_width; \
} \
else \
{ \
/* No scaling, conversion has been done directly in picture memory. \
* Increment of picture pointer to end of line is still needed */ \
p_pic += i_pic_width + i_pic_line_width; \
} \
/*****************************************************************************
* SCALE_HEIGHT: handle vertical scaling
*****************************************************************************
* This macro handle vertical scaling for a picture. CHROMA may be 420, 422 or
* 444 for RGB conversion, or 400 for gray conversion. It works for 1, 2, 3
* and 4 Bpp.
*****************************************************************************/
#define SCALE_HEIGHT( CHROMA, BPP ) \
/* If line is odd, rewind 4:2:0 U and V samples */ \
if( ((CHROMA == 420) || (CHROMA == 422)) && !(i_y & 0x1) ) \
{ \
p_u -= i_chroma_width; \
p_v -= i_chroma_width; \
} \
\
/* \
* Handle vertical scaling. The current line can be copied or next one \
* can be ignored. \
*/ \
switch( i_vertical_scaling ) \
{ \
case -1: /* vertical scaling factor is < 1 */ \
while( (i_scale_count -= i_pic_height) > 0 ) \
{ \
/* Height reduction: skip next source line */ \
p_y += i_width; \
i_y++; \
if( (CHROMA == 420) || (CHROMA == 422) ) \
{ \
if( i_y & 0x1 ) \
{ \
p_u += i_chroma_width; \
p_v += i_chroma_width; \
} \
} \
else if( CHROMA == 444 ) \
{ \
p_u += i_width; \
p_v += i_width; \
} \
} \
i_scale_count += i_height; \
break; \
case 1: /* vertical scaling factor is > 1 */ \
while( (i_scale_count -= i_height) > 0 ) \
{ \
/* Height increment: copy previous picture line */ \
for( i_x = i_pic_width / 16; i_x--; ) \
{ \
*(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ ); \
*(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ ); \
if( BPP > 1 ) /* 2, 3, 4 Bpp */ \
{ \
*(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ ); \
*(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ ); \
} \
if( BPP > 2 ) /* 3, 4 Bpp */ \
{ \
*(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ ); \
*(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ ); \
} \
if( BPP > 3 ) /* 4 Bpp */ \
{ \
*(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ ); \
*(((u64 *) p_pic)++) = *(((u64 *) p_pic_start)++ ); \
} \
} \
p_pic += i_pic_line_width; \
p_pic_start += i_pic_line_width; \
} \
i_scale_count += i_pic_height; \
break; \
} \
/*****************************************************************************
* video_yuv32.c: YUV transformation functions for 32 bpp
* Provides functions to perform the YUV conversion. The functions provided here
* are a complete and portable C implementation, and may be replaced in certain
* case by optimized functions.
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
*
* Authors:
*
* 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
* (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.
*
* 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-1307, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include "defs.h"
#include <math.h> /* exp(), pow() */
#include <errno.h> /* ENOMEM */
#include <stdlib.h> /* free() */
#include <string.h> /* strerror() */
#include "config.h"
#include "common.h"
#include "threads.h"
#include "mtime.h"
#include "plugins.h"
#include "video.h"
#include "video_output.h"
#include "video_yuv.h"
#include "intf_msg.h"
#include "SDL/SDL.h"
typedef struct vout_sys_s
{
SDL_Surface * p_display; /* display device */
Uint8 * p_buffer[2];
/* Buffers informations */
boolean_t b_must_acquire; /* must be acquired before writing */
} vout_sys_t;
void Convert8( YUV_ARGS_8BPP )
{
}
void Convert16( YUV_ARGS_16BPP )
{
}
void Convert24( YUV_ARGS_24BPP )
{
}
void Convert32( YUV_ARGS_32BPP )
{
}
void ConvertRGB8( YUV_ARGS_8BPP )
{
}
void ConvertRGB16( YUV_ARGS_16BPP )
{
}
void ConvertRGB24( YUV_ARGS_24BPP )
{
}
void ConvertRGB32( YUV_ARGS_32BPP )
{
/* for now, the only function filled because I use 32bpp display :P */
SDL_Overlay * screen;
SDL_Rect disp;
screen=SDL_CreateYUVOverlay( i_width, i_height,SDL_IYUV_OVERLAY, p_vout->p_sys->p_display );
SDL_LockYUVOverlay(screen);
memcpy(screen->pixels, p_vout->yuv.p_buffer, screen->h * screen->pitch );
SDL_UnlockYUVOverlay(screen);
disp.x=0;
disp.y=0;
disp.w= i_width;
disp.h= i_height;
SDL_DisplayYUVOverlay(screen,&disp);
//memcpy(p_pic, p_vout->p_sys->p_display->pixels, screen->h * screen->pitch );
SDL_FreeYUVOverlay(screen);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment