Commit a688d669 authored by Jean-Paul Saman's avatar Jean-Paul Saman

davinci: resizer.c: cleanup

- remove hackish code for direct framebuffer output
parent 3d7b2498
......@@ -21,11 +21,16 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#undef _FILE_OFFSET_BITS /* mmap() fails on 64 bits offsets */
#include "davinci.h" /* DAVINCI_HACK defined here */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <vlc_common.h>
#include <vlc_codec.h>
#ifdef DAVINCI_HACK
#undef _FILE_OFFSET_BITS /* mmap() fails on 64 bits offsets */
#include "davinci.h"
#include "resizer.h"
#include <assert.h>
......@@ -76,37 +81,6 @@ static void Resize_coeff( decoder_t *p_dec,
msg_Dbg( p_dec, "Destination fixed to %dx%d", *i_width, *i_height );
}
/* open() a framebuffer by its name (NOT device path) */
static int OpenFB( const char *psz_name )
{
int i_fd = -1;
int i_tries = 0; /* begin with /dev/fb0 */
char *psz_device;
struct fb_fix_screeninfo info;
do {
if( asprintf( &psz_device, "/dev/fb%d", i_tries++ ) == -1 )
return -1;
i_fd = open( psz_device, O_RDWR);
free( psz_device );
if( i_fd == -1 )
return -1; /* check errno */
if( ioctl( i_fd, FBIOGET_FSCREENINFO, &info ) == -1 )
{
close( i_fd );
continue;
}
if( !strcmp( info.id, psz_name ) )
return i_fd;
close( i_fd );
} while(1);
}
static float bicubic_core( float s )
{
if( s < 0 ) s = -s;
......@@ -119,7 +93,6 @@ static float bicubic_core( float s )
return 0.;
}
static void get_coeffs( short coefs[32], unsigned int i_in,
unsigned int i_out )
{
......@@ -159,6 +132,7 @@ static void get_coeffs( short coefs[32], unsigned int i_in,
i_phase_offset = 4;
}
i_winlen = i_nphases * i_ntaps;
/* calculating the cut-off frequency, normalized by fs/2 */
f_fc = ( i_rsz < 256) ? (1. / i_nphases) : 256. / (i_rsz * i_nphases);
......@@ -169,6 +143,7 @@ static void get_coeffs( short coefs[32], unsigned int i_in,
i_nphases = 8;
i_ntaps = 4;
i_phase_offset = 4;
/* calculating the bi-cubic coefficients */
for( i = 0 ; i < i_nphases ; i++ )
{
......@@ -234,13 +209,19 @@ static void get_coeffs( short coefs[32], unsigned int i_in,
}
}
void Resize( decoder_t *p_dec, bool b_scale, davinci_resizer_t *rsz,
davinci_fb_t *fb, XDM_BufDesc out )
/*
* Resizer functions
*/
int Resize( decoder_t *p_dec, davinci_resizer_t *rsz, bool b_scale,
XDM_BufDesc in, XDM_BufDesc out )
{
if( !rsz->i_yuyv )
assert( rsz );
assert( p_dec );
if( rsz->i_yuyv == 0)
{
/* use screen resolution for the buffer, we may be off by a few */
rsz->i_yuyv = fb->var_info.xres * fb->var_info.yres_virtual;
rsz->i_yuyv = rsz->i_out_width * rsz->i_out_height;
assert(rsz->i_yuyv);
rsz_reqbufs_t reqbufs;
......@@ -255,7 +236,7 @@ void Resize( decoder_t *p_dec, bool b_scale, davinci_resizer_t *rsz,
if( ioctl( rsz->i_fd, RSZ_REQBUF, &reqbufs ) )
{
msg_Err( p_dec, "RSZ_REQBUF failed (%m)" );
return;
return VLC_EGENERIC;
}
buffer.buf_type = RSZ_BUF_OUT;
......@@ -264,19 +245,19 @@ void Resize( decoder_t *p_dec, bool b_scale, davinci_resizer_t *rsz,
if( ioctl( rsz->i_fd, RSZ_QUERYBUF, &buffer ) )
{
msg_Err( p_dec, "RSZ_QUERYBUF failed (%m)" );
return;
return VLC_EGENERIC;
}
rsz->offset = buffer.offset;
rsz->p_yuyv = mmap( NULL, reqbufs.size, PROT_READ|PROT_WRITE,
MAP_SHARED, rsz->i_fd, buffer.offset );
MAP_SHARED, rsz->i_fd, buffer.offset );
if( rsz->p_yuyv == MAP_FAILED )
{
rsz->i_yuyv = 0;
msg_Err( p_dec, "mmap resizer to buffer failed (%m)" );
return;
return VLC_EGENERIC;
}
rsz->offset = buffer.offset;
}
/* Sets resizer parameters when video starts or when resolution changes */
......@@ -295,8 +276,8 @@ void Resize( decoder_t *p_dec, bool b_scale, davinci_resizer_t *rsz,
/* Sets the desired maximum destination resolution */
if( b_scale )
{
rsz_params.out_hsize = fb->var_info.xres;
rsz_params.out_vsize = fb->var_info.yres;
rsz_params.out_hsize = rsz->i_out_width;
rsz_params.out_vsize = rsz->i_out_height;
}
else
{
......@@ -311,8 +292,7 @@ void Resize( decoder_t *p_dec, bool b_scale, davinci_resizer_t *rsz,
/* RSZ_PIX_FMT_YUYV is 2 bytes per pixel */
rsz_params.out_pitch = ( rsz_params.out_hsize * 2 + 15 ) & ~15;
rsz->b_direct =
(unsigned)rsz_params.out_hsize == (unsigned)fb->var_info.xres;
rsz->b_direct = ((unsigned)rsz_params.out_hsize == (unsigned)width);
rsz->i_out_width = rsz_params.out_hsize;
rsz->i_out_height = rsz_params.out_vsize;
......@@ -340,18 +320,17 @@ void Resize( decoder_t *p_dec, bool b_scale, davinci_resizer_t *rsz,
);
rsz->i_width = rsz->i_height = 0;
return;
return VLC_EGENERIC;
}
}
rsz_resize_t rszh;
rszh.in_buf.index = -1;
rszh.in_buf.buf_type = RSZ_BUF_IN;
rszh.in_buf.size =
p_dec->fmt_out.video.i_height *
((p_dec->fmt_out.video.i_width * BPP / 8 + 31) & ~31);
rszh.in_buf.size = p_dec->fmt_out.video.i_height *
((p_dec->fmt_out.video.i_width * BPP / 8 + 31) & ~31);
rszh.in_buf.offset = Memory_getBufferPhysicalAddress(
out.bufs[0], rszh.in_buf.size, NULL );
out.bufs[0], rszh.in_buf.size, NULL );
assert( rszh.in_buf.offset );
rszh.out_buf.index = -1;
......@@ -360,8 +339,8 @@ void Resize( decoder_t *p_dec, bool b_scale, davinci_resizer_t *rsz,
if( b_scale && rsz->b_direct /* output video res is screen res */ )
{
/* FIXME: use NUM_BUFFERS if needed */
rszh.out_buf.offset = fb->p_physbufs[0];
rszh.out_buf.size = fb->var_info.xres * fb->var_info.yres_virtual;
rszh.out_buf.offset = fb->p_physbufs[0]; //FIXME:
rszh.out_buf.size = rsz->i_out_width * rsz->i_out_height;
}
else
{
......@@ -377,120 +356,44 @@ void Resize( decoder_t *p_dec, bool b_scale, davinci_resizer_t *rsz,
continue;
msg_Err( p_dec, "Resizing failed (%m)" );
return;
return VLC_EGENERIC;
}
} while(0);
return VLC_SUCCESS;
}
int DavinciInit( decoder_t *p_dec, davinci_fb_t *fb, davinci_resizer_t *rsz )
int ResizerOpen( vlc_object_t *p_this, davinci_resizer_t *rsz )
{
fb->i_fd = rsz->i_fd = -1;
/* Open framebuffer */
if( ( fb->i_fd = OpenFB( "dm_vid0_fb" ) ) == -1 )
{
msg_Err( p_dec, "Failed to open framebuffer (%m)" );
goto error;
}
if( ioctl( fb->i_fd, FBIOGET_VSCREENINFO, &fb->var_info ) == -1 )
{
msg_Err( p_dec, "Failed to get framebuffer info (%m)" );
goto error;
}
fb->var_info.yres_virtual = fb->var_info.yres * NUM_BUFFERS;
fb->var_info.bits_per_pixel = BPP;
if( ioctl( fb->i_fd, FBIOPUT_VSCREENINFO, &fb->var_info ) == -1 )
{
msg_Err( p_dec, "Can not set fb info (%m)" );
goto error;
}
if( fb->var_info.bits_per_pixel != BPP )
{
msg_Err( p_dec, "Can not use requested size (%dx%d at %d bpp)",
fb->var_info.xres, fb->var_info.yres,
fb->var_info.bits_per_pixel );
goto error;
}
if( ioctl( fb->i_fd, FBIOGET_FSCREENINFO, &fb->fix_info ) == -1 )
{
msg_Err( p_dec, "Failed to get framebuffer fixed info (%m)" );
goto error;
}
/* Yes, 32bits * 32bits fills 64 bits.
* * Oh and if you find a screen with 16 billions of billions of pixels ...
* * Keep it for yourself. */
uint64_t i_display_sz = fb->fix_info.line_length * fb->var_info.yres;
uint64_t i_display_total_sz =
fb->fix_info.line_length * fb->var_info.yres_virtual;
fb->p_map = mmap( NULL, i_display_total_sz,
PROT_READ | PROT_WRITE, MAP_SHARED, fb->i_fd, 0 );
if( fb->p_map == MAP_FAILED )
{
fb->p_map = NULL; /* set to NULL for error handling */
msg_Err( p_dec, "Memory mapping of framebuffer failed (%m)" );
goto error;
}
/* Clears fb */
unsigned int i;
for( i = 0 ; i < i_display_total_sz / 4 ; i++ )
((uint32_t*)fb->p_map)[i] = 0x10801080;
for( i = 0 ; i < NUM_BUFFERS ; i++ )
if( ( fb->p_physbufs[i] = Memory_getBufferPhysicalAddress(
fb->p_map + i * i_display_sz, i_display_sz, NULL ) ) == 0 )
{
msg_Err( p_dec, "Unable to get physical address of buffer "
"%d/%d (%"PRId64" bytes)", i, NUM_BUFFERS, i_display_sz );
goto error;
}
rsz->i_fd = -1;
/* Open and setup resizer */
if( ( rsz->i_fd = open( "/dev/davinci_resizer", O_RDWR ) ) == -1 )
{
msg_Err( p_dec, "Failed to open resizer (%m)" );
msg_Err( p_this, "Failed to open resizer (%m)" );
goto error;
}
rsz->p_yuyv = NULL;
rsz->p_yuyv = MAP_FAILED;
rsz->i_yuyv = 0;
rsz->i_height = rsz->i_width = 0;
rsz->offset = 0;
rsz->i_height = 0;
rsz->i_width = 0;
rsz->i_out_height = 0;
rsz->i_out_width = 0;
return VLC_SUCCESS;
error:
DavinciClose( fb, rsz );
ResizerClose( rsz );
return VLC_EGENERIC;
}
void DavinciClose( davinci_fb_t *fb, davinci_resizer_t *rsz )
void ResizerClose( davinci_resizer_t *rsz )
{
if( fb->p_map )
{
/* Clears fb */
unsigned int i;
uint64_t i_display_size =
fb->fix_info.line_length * fb->var_info.yres_virtual / 4;
for( i = 0 ; i < i_display_size ; i++ )
((uint32_t*)fb->p_map)[i] = 0x10801080;
munmap( fb->p_map, i_display_size );
}
if( fb->i_fd != -1 ) close( fb->i_fd );
if( rsz->i_fd != -1 ) close( rsz->i_fd );
rsz->i_fd = fb->i_fd = -1;
fb->p_map = NULL;
if( rsz->i_fd != -1 )
close( rsz->i_fd );
if( rsz->p_yuyv != MAP_FAILED )
munmap( rsz->p_yuyv, rsz->offset );
rsz->i_fd = -1;
}
#endif /* DAVINCI_HACK */
......@@ -42,15 +42,6 @@
#define PI 3.1415926535897932384626
typedef struct
{
int i_fd;
struct fb_var_screeninfo var_info;
struct fb_fix_screeninfo fix_info;
uint8_t *p_map;
UInt32 p_physbufs[NUM_BUFFERS];
} davinci_fb_t;
typedef struct
{
int i_fd;
......@@ -67,9 +58,18 @@ typedef struct
bool b_direct;
} davinci_resizer_t;
void Resize( decoder_t *, bool, davinci_resizer_t *, davinci_fb_t *,
XDM_BufDesc );
int DavinciInit( decoder_t *, davinci_fb_t *, davinci_resizer_t * );
void DavinciClose( davinci_fb_t *, davinci_resizer_t * );
/* Resize: resize and/or enhance input picture
* \param p_dec : pointer to decoder_t structure
* \param rsz : pointer to davinci_resizer_t structure
* \param b_scale : rescale to output size
* \param in : input buffer as XDM_BufDesc
* \param out : output buffer as XDM_BufDesc
* \return VLC_SUCCESS on success and VLC_EGENERIC on failure
*/
int Resize( decoder_t *p_dec, davinci_resizer_t *rsz, bool b_scale,
XDM_BufDesc in, XDM_BufDesc out );
int ResizerOpen( vlc_object_t *p_this, davinci_resizer_t *rsz );
void ResizerClose( davinci_resizer_t *rsz );
#endif /* RESIZER_H */
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