Commit fd0bc419 authored by Henri Fallon's avatar Henri Fallon

lpcm support (tested on 1 source only)

parent f213a1d6
This diff is collapsed.
/*****************************************************************************
* s16tofloat32.c : converter from signed 16 bits integer to float32
* with endianness change
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: s16tofloat32swab.c,v 1.1 2002/09/18 01:28:04 henri Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Henri Fallon <henri@videolan.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 <errno.h>
#include <stdlib.h> /* malloc(), free() */
#include <string.h>
#include <vlc/vlc.h>
#include "audio_output.h"
#include "aout_internal.h"
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int Create ( vlc_object_t * );
static void DoWork ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
aout_buffer_t * );
/*****************************************************************************
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description(
_("audio filter for s16->float32 with endianness conversion") );
set_capability( "audio filter", 1 );
set_callbacks( Create, NULL );
vlc_module_end();
/*****************************************************************************
* Create: allocate trivial mixer
*****************************************************************************
* This function allocates and initializes a Crop vout method.
*****************************************************************************/
static int Create( vlc_object_t *p_this )
{
aout_filter_t * p_filter = (aout_filter_t *)p_this;
if ( !AOUT_FMTS_SIMILAR( &p_filter->input, &p_filter->output ) )
{
return -1;
}
if ( (p_filter->input.i_format == AOUT_FMT_S16_LE ||
p_filter->input.i_format == AOUT_FMT_S16_BE)
&& p_filter->output.i_format == AOUT_FMT_FLOAT32
&& p_filter->input.i_format != AOUT_FMT_S16_NE )
{
p_filter->pf_do_work = DoWork;
p_filter->b_in_place = VLC_TRUE;
return 0;
}
return -1;
}
/*****************************************************************************
* DoWork: convert a buffer
*****************************************************************************/
static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
{
int i = p_in_buf->i_nb_samples * p_filter->input.i_channels;
/* We start from the end because b_in_place is true */
s16 * p_in = (s16 *)p_in_buf->p_buffer + i - 1;
float * p_out = (float *)p_out_buf->p_buffer + i - 1;
#ifdef HAVE_SWAB
s16 * p_swabbed = malloc( i * sizeof(s16) );
swab( p_in_buf->p_buffer, p_swabbed,
i * sizeof(s16) );
p_in = p_swabbed +i - 1;
#else
byte_t temp;
#endif
while( i-- )
{
#ifndef HAVE_SWAB
temp = *(byte_t*)p_in;
*(byte_t*)p_in = *(byte_t*)p_in+1;
*(byte_t*)p_in+1 = temp;
#endif
*p_out = (float)*p_in / 32768.0;
p_in--; p_out--;
}
p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * 2;
}
......@@ -2,7 +2,7 @@
* lpcm.c: lpcm decoder module
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: lpcm.c,v 1.3 2002/08/30 22:22:24 massiot Exp $
* $Id: lpcm.c,v 1.4 2002/09/18 01:28:05 henri Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Henri Fallon <henri@videolan.org>
......@@ -25,19 +25,19 @@
/*****************************************************************************
* Preamble
*****************************************************************************/
#include <string.h> /* memcpy(), memset() */
#include <stdlib.h> /* malloc(), free() */
#include <string.h> /* memcpy(), memset() */
#include <vlc/vlc.h>
#include <vlc/aout.h>
#include <vlc/decoder.h>
#include <input_ext-dec.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h> /* getpid() */
#endif
#include "lpcm.h"
/*****************************************************************************
* Local prototypes
*****************************************************************************/
......@@ -45,7 +45,7 @@ static int OpenDecoder ( vlc_object_t * );
static int RunDecoder ( decoder_fifo_t * );
void DecodeFrame ( lpcmdec_thread_t * );
static int InitThread ( lpcmdec_thread_t * );
// static int InitThread ( lpcmdec_thread_t * );
static void EndThread ( lpcmdec_thread_t * );
/*****************************************************************************
......@@ -95,10 +95,25 @@ static int RunDecoder( decoder_fifo_t * p_fifo )
*/
p_lpcmdec->p_fifo = p_fifo;
if( InitThread( p_lpcmdec ) )
/* Init the BitStream */
InitBitstream( &p_lpcmdec->bit_stream, p_lpcmdec->p_fifo,
NULL, NULL );
/* FIXME : I suppose the number of channel ans sampling rate
* are someway in the headers */
p_lpcmdec->output_format.i_format = AOUT_FMT_S16_BE;
p_lpcmdec->output_format.i_channels = 2;
p_lpcmdec->output_format.i_rate = 48000;
aout_DateInit( &p_lpcmdec->end_date, 48000 );
p_lpcmdec->p_aout_input = aout_InputNew( p_lpcmdec->p_fifo,
&p_lpcmdec->p_aout,
&p_lpcmdec->output_format );
if( p_lpcmdec->p_aout_input == NULL )
{
DecoderError( p_fifo );
free( p_lpcmdec );
msg_Err( p_lpcmdec->p_fifo, "failed to create aout fifo" );
p_lpcmdec->p_fifo->b_error = 1;
return( -1 );
}
......@@ -120,67 +135,41 @@ static int RunDecoder( decoder_fifo_t * p_fifo )
return( 0 );
}
/*****************************************************************************
* InitThread : initialize an lpcm decoder thread
*****************************************************************************/
static int InitThread (lpcmdec_thread_t * p_lpcmdec)
{
/* Init the BitStream */
InitBitstream( &p_lpcmdec->bit_stream, p_lpcmdec->p_fifo,
NULL, NULL);
/* Creating the audio output fifo */
p_lpcmdec->p_aout_fifo =
aout_CreateFifo( p_lpcmdec->p_fifo, AOUT_FIFO_PCM,
2, 48000, LPCMDEC_FRAME_SIZE / 2, NULL );
if ( p_lpcmdec->p_aout_fifo == NULL )
{
return( -1 );
}
return( 0 );
}
/*****************************************************************************
* DecodeFrame: decodes a frame.
*****************************************************************************/
void DecodeFrame( lpcmdec_thread_t * p_lpcmdec )
{
byte_t * buffer;
#ifndef WORDS_BIGENDIAN
byte_t * p_temp[LPCMDEC_FRAME_SIZE];
#endif
byte_t buffer[LPCMDEC_FRAME_SIZE];
aout_buffer_t * p_aout_buffer;
mtime_t i_pts;
vlc_bool_t b_sync;
int i_loop;
CurrentPTS( &p_lpcmdec->bit_stream,
&p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->i_end_frame],
NULL );
if( !p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->i_end_frame] )
NextPTS( &p_lpcmdec->bit_stream, &i_pts, NULL );
if( i_pts != 0 && i_pts != aout_DateGet( &p_lpcmdec->end_date ) )
{
p_lpcmdec->p_aout_fifo->date[p_lpcmdec->p_aout_fifo->i_end_frame] =
LAST_MDATE;
aout_DateSet( &p_lpcmdec->end_date, i_pts );
}
buffer = ((byte_t *)p_lpcmdec->p_aout_fifo->buffer) +
(p_lpcmdec->p_aout_fifo->i_end_frame * LPCMDEC_FRAME_SIZE);
RemoveBits32(&p_lpcmdec->bit_stream);
#if 0
byte1 = GetBits(&p_lpcmdec->bit_stream, 8) ;
byte2 = GetBits(&p_lpcmdec->bit_stream, 8) ;
/* I only have 2 test streams. As far as I understand
* after the RemoveBits and the 2 GetBits, we should be exactly
* where we want : the sync word : 0x0180.
* If not, we go and find it. */
while( ( byte1 != 0x01 || byte2 != 0x80 ) && (!p_lpcmdec->p_fifo->b_die)
&& (!p_lpcmdec->p_fifo->b_error) )
p_aout_buffer = aout_BufferNew( p_lpcmdec->p_aout,
p_lpcmdec->p_aout_input,
LPCMDEC_FRAME_SIZE/4 );
if( !p_aout_buffer )
{
byte1 = byte2;
byte2 = GetBits(&p_lpcmdec->bit_stream, 8);
msg_Err( p_lpcmdec->p_fifo, "cannot get aout buffer" );
p_lpcmdec->p_fifo->b_error = 1;
return;
}
#else
p_aout_buffer->start_date = aout_DateGet( &p_lpcmdec->end_date );
p_aout_buffer->end_date = aout_DateIncrement( &p_lpcmdec->end_date,
LPCMDEC_FRAME_SIZE/4 );
b_sync = 0;
while( ( !p_lpcmdec->p_fifo->b_die ) &&
( !p_lpcmdec->p_fifo->b_error ) &&
......@@ -191,33 +180,18 @@ void DecodeFrame( lpcmdec_thread_t * p_lpcmdec )
( GetBits( &p_lpcmdec->bit_stream, 8 ) != 0x01 ) );
b_sync = ( ShowBits( &p_lpcmdec->bit_stream, 8 ) == 0x80 );
}
RemoveBits( &p_lpcmdec->bit_stream, 8 );
#endif
#ifndef WORDS_BIGENDIAN
GetChunk( &p_lpcmdec->bit_stream, p_temp, LPCMDEC_FRAME_SIZE);
if( p_lpcmdec->p_fifo->b_die || p_lpcmdec->p_fifo->b_error ) return;
# ifdef HAVE_SWAB
swab( buffer, p_temp, LPCMDEC_FRAME_SIZE );
# else
for( i_loop = 0; i_loop < LPCMDEC_FRAME_SIZE/2; i_loop++ )
{
buffer[2*i_loop]=p_temp[2*i_loop+1];
buffer[2*i_loop+1]=p_temp[2*i_loop];
}
# endif
GetChunk( &p_lpcmdec->bit_stream, p_aout_buffer->p_buffer,
LPCMDEC_FRAME_SIZE);
#else
GetChunk( &p_lpcmdec->bit_stream, buffer, LPCMDEC_FRAME_SIZE);
if( p_lpcmdec->p_fifo->b_die ) return;
#endif
if( p_lpcmdec->p_fifo->b_die || p_lpcmdec->p_fifo->b_error )
return;
aout_BufferPlay( p_lpcmdec->p_aout, p_lpcmdec->p_aout_input,
p_aout_buffer );
vlc_mutex_lock (&p_lpcmdec->p_aout_fifo->data_lock);
p_lpcmdec->p_aout_fifo->i_end_frame =
(p_lpcmdec->p_aout_fifo->i_end_frame + 1) & AOUT_FIFO_SIZE;
vlc_cond_signal (&p_lpcmdec->p_aout_fifo->data_wait);
vlc_mutex_unlock (&p_lpcmdec->p_aout_fifo->data_lock);
}
/*****************************************************************************
......@@ -226,14 +200,10 @@ void DecodeFrame( lpcmdec_thread_t * p_lpcmdec )
static void EndThread( lpcmdec_thread_t * p_lpcmdec )
{
/* If the audio output fifo was created, we destroy it */
if( p_lpcmdec->p_aout_fifo != NULL )
if( p_lpcmdec->p_aout_input )
{
aout_DestroyFifo( p_lpcmdec->p_aout_fifo );
/* Make sure the output thread leaves the NextFrame() function */
vlc_mutex_lock( &(p_lpcmdec->p_aout_fifo->data_lock) );
vlc_cond_signal( &(p_lpcmdec->p_aout_fifo->data_wait) );
vlc_mutex_unlock( &(p_lpcmdec->p_aout_fifo->data_lock) );
aout_InputDelete( p_lpcmdec->p_aout, p_lpcmdec->p_aout_input );
}
/* Destroy descriptor */
......
......@@ -2,7 +2,7 @@
* lpcm.h : lpcm decoder module
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
* $Id: lpcm.h,v 1.1 2002/08/04 17:23:42 sam Exp $
* $Id: lpcm.h,v 1.2 2002/09/18 01:28:05 henri Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
......@@ -42,8 +42,11 @@ typedef struct lpcmdec_thread_s
/*
* Output properties
*/
aout_fifo_t * p_aout_fifo; /* stores the decompressed audio frames */
aout_instance_t *p_aout;
aout_input_t *p_aout_input;
audio_sample_format_t output_format;
audio_date_t end_date;
/* The bit stream structure handles the PES stream at the bit level */
bit_stream_t bit_stream;
......
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