Commit 7ba73a88 authored by Sam Hocevar's avatar Sam Hocevar
Browse files

* Removed the plugins/ directory.

parent a46b3001
*.a
*.so
*.so.*
*.tds
*.lib
.dep
*.lo
*.o.*
*.lo.*
/*****************************************************************************
* a52.c: ATSC A/52 aka AC-3 decoder plugin for vlc.
* This plugin makes use of liba52 to decode A/52 audio
* (http://liba52.sf.net/).
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: a52.c,v 1.22 2002/07/31 20:56:50 sam Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
*
* 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 <vlc/vlc.h>
#include <vlc/aout.h>
#include <vlc/decoder.h>
#include <stdlib.h> /* malloc(), free() */
#include <string.h> /* strdup() */
#ifdef HAVE_STDINT_H
# include <stdint.h> /* int16_t .. */
#elif HAVE_INTTYPES_H
# include <inttypes.h> /* int16_t .. */
#endif
#ifdef USE_A52DEC_TREE /* liba52 header file */
# include "include/a52.h"
#else
# include "a52dec/a52.h"
#endif
#include "a52.h"
#define AC3DEC_FRAME_SIZE 1536
/*
* Global lock for accessing liba52 functions.
* Currently, liba52 isn't thread-safe. So to prevent two threads from
* using liba52 at the same time, we have to set up a global lock.
* I know static variables aren't a good idea in multi-threaded programs,
* but believe me, this is the way to go.
* --Meuuh 2002-07-19
*/
static vlc_mutex_t a52_lock;
static vlc_bool_t b_liba52_initialized = 0;
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int OpenDecoder ( vlc_object_t * );
static int RunDecoder ( decoder_fifo_t * );
static int DecodeFrame ( a52_adec_thread_t * );
static int InitThread ( a52_adec_thread_t * );
static void EndThread ( a52_adec_thread_t * );
static void BitstreamCallback ( bit_stream_t *, vlc_bool_t );
static void float2s16_2 ( float *, int16_t * );
static inline int16_t convert ( int32_t );
/*****************************************************************************
* Module descriptor
*****************************************************************************/
#define DYNRNG_TEXT N_("A/52 dynamic range compression")
#define DYNRNG_LONGTEXT N_( \
"Dynamic range compression makes the loud sounds softer, and the soft " \
"sounds louder, so you can more easily listen to the stream in a noisy " \
"environment without disturbing anyone. If you disable the dynamic range "\
"compression the playback will be more adapted to a movie theater or a " \
"listening room.")
vlc_module_begin();
add_category_hint( N_("Miscellaneous"), NULL );
add_bool( "a52-dynrng", 1, NULL, DYNRNG_TEXT, DYNRNG_LONGTEXT );
set_description( _("a52 ATSC A/52 aka AC-3 audio decoder module") );
set_capability( "decoder", 60 );
set_callbacks( OpenDecoder, NULL );
vlc_module_end();
/*****************************************************************************
* OpenDecoder: probe the decoder and return score
*****************************************************************************
* Tries to launch a decoder and return score so that the interface is able
* to choose.
*****************************************************************************/
static int OpenDecoder( vlc_object_t *p_this )
{
decoder_fifo_t *p_fifo = (decoder_fifo_t*) p_this;
if( p_fifo->i_fourcc != VLC_FOURCC('a','5','2',' ') )
{
return VLC_EGENERIC;
}
p_fifo->pf_run = RunDecoder;
return VLC_SUCCESS;
}
/*****************************************************************************
* RunDecoder: this function is called just after the thread is created
*****************************************************************************/
static int RunDecoder( decoder_fifo_t *p_fifo )
{
a52_adec_thread_t *p_a52_adec;
/* Allocate the memory needed to store the thread's structure */
p_a52_adec = (a52_adec_thread_t *)malloc( sizeof(a52_adec_thread_t) );
if (p_a52_adec == NULL)
{
msg_Err( p_fifo, "out of memory" );
DecoderError( p_fifo );
return( -1 );
}
/* FIXME */
p_a52_adec->i_channels = 2;
/*
* Initialize the thread properties
*/
p_a52_adec->p_aout_fifo = NULL;
p_a52_adec->p_fifo = p_fifo;
if( InitThread( p_a52_adec ) )
{
msg_Err( p_a52_adec->p_fifo, "could not initialize thread" );
DecoderError( p_fifo );
free( p_a52_adec );
return( -1 );
}
/* liba52 decoder thread's main loop */
while( !p_a52_adec->p_fifo->b_die && !p_a52_adec->p_fifo->b_error )
{
/* look for sync word - should be 0x0b77 */
RealignBits(&p_a52_adec->bit_stream);
while( (ShowBits( &p_a52_adec->bit_stream, 16 ) ) != 0x0b77 &&
(!p_a52_adec->p_fifo->b_die) && (!p_a52_adec->p_fifo->b_error))
{
RemoveBits( &p_a52_adec->bit_stream, 8 );
}
/* get a52 frame header */
GetChunk( &p_a52_adec->bit_stream, p_a52_adec->p_frame_buffer, 7 );
if( p_a52_adec->p_fifo->b_die ) break;
/* check if frame is valid and get frame info */
vlc_mutex_lock( &a52_lock );
p_a52_adec->frame_size = a52_syncinfo( p_a52_adec->p_frame_buffer,
&p_a52_adec->flags,
&p_a52_adec->sample_rate,
&p_a52_adec->bit_rate );
vlc_mutex_unlock( &a52_lock );
if( !p_a52_adec->frame_size )
{
msg_Warn( p_a52_adec->p_fifo, "a52_syncinfo failed" );
continue;
}
if( DecodeFrame( p_a52_adec ) && !p_a52_adec->p_fifo->b_die )
{
DecoderError( p_fifo );
free( p_a52_adec );
return( -1 );
}
}
/* If b_error is set, the decoder thread enters the error loop */
if( p_a52_adec->p_fifo->b_error )
{
DecoderError( p_a52_adec->p_fifo );
}
/* End of the liba52 decoder thread */
EndThread( p_a52_adec );
return( 0 );
}
/*****************************************************************************
* InitThread: initialize data before entering main loop
*****************************************************************************/
static int InitThread( a52_adec_thread_t * p_a52_adec )
{
/* Initialize the global lock */
vlc_mutex_lock( p_a52_adec->p_fifo->p_vlc->p_global_lock );
if ( !b_liba52_initialized )
{
vlc_mutex_init( p_a52_adec->p_fifo, &a52_lock );
b_liba52_initialized = 1;
}
vlc_mutex_unlock( p_a52_adec->p_fifo->p_vlc->p_global_lock );
/* Initialize liba52 */
vlc_mutex_lock( &a52_lock );
p_a52_adec->p_a52_state = a52_init( 0 );
vlc_mutex_unlock( &a52_lock );
if( p_a52_adec->p_a52_state == NULL )
{
msg_Err( p_a52_adec->p_fifo, "unable to initialize liba52" );
return -1;
}
p_a52_adec->b_dynrng = config_GetInt( p_a52_adec->p_fifo, "a52-dynrng" );
/* Init the BitStream */
InitBitstream( &p_a52_adec->bit_stream,
p_a52_adec->p_fifo,
BitstreamCallback, NULL );
return( 0 );
}
/*****************************************************************************
* DecodeFrame: decodes an ATSC A/52 frame.
*****************************************************************************/
static int DecodeFrame( a52_adec_thread_t * p_a52_adec )
{
sample_t sample_level = 1;
byte_t *p_buffer;
int i;
if( ( p_a52_adec->p_aout_fifo != NULL ) &&
( p_a52_adec->p_aout_fifo->i_rate != p_a52_adec->sample_rate ) )
{
/* Make sure the output thread leaves the NextFrame() function */
vlc_mutex_lock (&(p_a52_adec->p_aout_fifo->data_lock));
aout_DestroyFifo (p_a52_adec->p_aout_fifo);
vlc_cond_signal (&(p_a52_adec->p_aout_fifo->data_wait));
vlc_mutex_unlock (&(p_a52_adec->p_aout_fifo->data_lock));
p_a52_adec->p_aout_fifo = NULL;
}
/* Creating the audio output fifo if not created yet */
if( p_a52_adec->p_aout_fifo == NULL )
{
p_a52_adec->p_aout_fifo = aout_CreateFifo( p_a52_adec->p_fifo,
AOUT_FIFO_PCM, p_a52_adec->i_channels,
p_a52_adec->sample_rate,
AC3DEC_FRAME_SIZE * p_a52_adec->i_channels,
NULL );
if ( p_a52_adec->p_aout_fifo == NULL )
{
return( -1 );
}
}
/* Set the Presentation Time Stamp */
CurrentPTS( &p_a52_adec->bit_stream,
&p_a52_adec->p_aout_fifo->date[
p_a52_adec->p_aout_fifo->i_end_frame],
NULL );
if( !p_a52_adec->p_aout_fifo->date[
p_a52_adec->p_aout_fifo->i_end_frame] )
{
p_a52_adec->p_aout_fifo->date[
p_a52_adec->p_aout_fifo->i_end_frame] = LAST_MDATE;
}
p_buffer = ((byte_t *)p_a52_adec->p_aout_fifo->buffer) +
( p_a52_adec->p_aout_fifo->i_end_frame * AC3DEC_FRAME_SIZE *
p_a52_adec->i_channels * sizeof(s16) );
/* FIXME */
p_a52_adec->flags = A52_STEREO | A52_ADJUST_LEVEL;
/* Get the complete frame */
GetChunk( &p_a52_adec->bit_stream, p_a52_adec->p_frame_buffer + 7,
p_a52_adec->frame_size - 7 );
if( p_a52_adec->p_fifo->b_die ) return( -1 );
/* do the actual decoding now */
vlc_mutex_lock( &a52_lock );
a52_frame( p_a52_adec->p_a52_state, p_a52_adec->p_frame_buffer,
&p_a52_adec->flags, &sample_level, 384 );
if( !p_a52_adec->b_dynrng )
a52_dynrng( p_a52_adec->p_a52_state, NULL, NULL );
for( i = 0; i < 6; i++ )
{
if( a52_block( p_a52_adec->p_a52_state ) )
{
msg_Warn( p_a52_adec->p_fifo, "a52_block failed for block %i", i );
}
float2s16_2( a52_samples( p_a52_adec->p_a52_state ),
((int16_t *)p_buffer) + i * 256 * p_a52_adec->i_channels );
}
vlc_mutex_unlock( &a52_lock );
vlc_mutex_lock( &p_a52_adec->p_aout_fifo->data_lock );
p_a52_adec->p_aout_fifo->i_end_frame =
(p_a52_adec->p_aout_fifo->i_end_frame + 1) & AOUT_FIFO_SIZE;
vlc_cond_signal (&p_a52_adec->p_aout_fifo->data_wait);
vlc_mutex_unlock (&p_a52_adec->p_aout_fifo->data_lock);
return 0;
}
/*****************************************************************************
* EndThread : liba52 decoder thread destruction
*****************************************************************************/
static void EndThread (a52_adec_thread_t *p_a52_adec)
{
/* If the audio output fifo was created, we destroy it */
if (p_a52_adec->p_aout_fifo != NULL)
{
aout_DestroyFifo (p_a52_adec->p_aout_fifo);
/* Make sure the output thread leaves the NextFrame() function */
vlc_mutex_lock (&(p_a52_adec->p_aout_fifo->data_lock));
vlc_cond_signal (&(p_a52_adec->p_aout_fifo->data_wait));
vlc_mutex_unlock (&(p_a52_adec->p_aout_fifo->data_lock));
}
vlc_mutex_lock( &a52_lock );
a52_free( p_a52_adec->p_a52_state );
vlc_mutex_unlock( &a52_lock );
free( p_a52_adec );
}
/*****************************************************************************
* float2s16_2 : converts floats to ints using a trick based on the IEEE
* floating-point format
*****************************************************************************/
static inline int16_t convert (int32_t i)
{
if (i > 0x43c07fff)
return 32767;
else if (i < 0x43bf8000)
return -32768;
else
return i - 0x43c00000;
}
static void float2s16_2 (float * _f, int16_t * s16)
{
int i;
int32_t * f = (int32_t *) _f;
for (i = 0; i < 256; i++) {
s16[2*i] = convert (f[i]);
s16[2*i+1] = convert (f[i+256]);
}
}
/*****************************************************************************
* BitstreamCallback: Import parameters from the new data/PES packet
*****************************************************************************
* This function is called by input's NextDataPacket.
*****************************************************************************/
static void BitstreamCallback ( bit_stream_t * p_bit_stream,
vlc_bool_t b_new_pes )
{
if( b_new_pes )
{
/* Drop special AC3 header */
/* p_bit_stream->p_byte += 3; */
}
}
/*****************************************************************************
* a52.h: ATSC A/52 aka AC-3 decoder plugin for vlc.
* This plugin makes use of liba52 to decode A/52 audio
* (http://liba52.sf.net/).
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: a52.h,v 1.4 2002/06/01 12:31:58 sam Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
*
* 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.
*****************************************************************************/
/*****************************************************************************
* a52_adec_thread_t : a52 decoder thread descriptor
*****************************************************************************/
typedef struct a52_adec_thread_s
{
/*
* liba52 properties
*/
a52_state_t *p_a52_state;
int frame_size;
int flags;
int sample_rate;
int bit_rate;
vlc_bool_t b_dynrng;
/* The bit stream structure handles the PES stream at the bit level */
bit_stream_t bit_stream;
/*
* Input properties
*/
decoder_fifo_t *p_fifo; /* stores the PES stream data */
data_packet_t *p_data;
/*
* Output properties
*/
aout_fifo_t *p_aout_fifo; /* stores the decompressed audio frames */
int i_channels;
/* temporary buffer to store the raw frame to be decoded */
u8 p_frame_buffer[3840];
} a52_adec_thread_t;
a52_system_SOURCES = a52_system.c
/*****************************************************************************
* a52_system.c : A52 input module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: a52_system.c,v 1.3 2002/07/31 20:56:50 sam Exp $
*
* Authors: Arnaud de Bossoreille de Ribou <bozo@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
* (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 <stdlib.h> /* malloc(), free() */
#include <string.h> /* strdup() */
#include <errno.h>
#include <vlc/vlc.h>
#include <vlc/input.h>
#include <sys/types.h>
/*****************************************************************************
* Constants
*****************************************************************************/
#define A52_PACKET_SIZE 16384
#define MAX_PACKETS_IN_FIFO 3
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int Init ( vlc_object_t * );
static int Demux ( input_thread_t * );
/*****************************************************************************
* Module descriptor
*****************************************************************************/
vlc_module_begin();
set_description( "A52 demuxer" );
set_capability( "demux", 150 );
set_callbacks( Init, NULL );
add_shortcut( "a52sys" );
vlc_module_end();
/*****************************************************************************
* Init: initializes ES structures
*****************************************************************************/
static int Init( vlc_object_t * p_this )
{
input_thread_t * p_input = (input_thread_t *)p_this;
es_descriptor_t * p_es;
byte_t * p_peek;
/* Initialize access plug-in structures. */
if( p_input->i_mtu == 0 )
{
/* Improve speed. */
p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE;
}
p_input->pf_demux = Demux;
p_input->pf_rewind = NULL;
/* Have a peep at the show. */
if( input_Peek( p_input, &p_peek, 2 ) < 2 )
{
/* Stream shorter than 4 bytes... */
msg_Err( p_input, "cannot peek()" );
return( -1 );
}
if( *p_peek != 0x0b || *(p_peek + 1) != 0x77 )
{
if( *p_input->psz_demux && !strncmp( p_input->psz_demux, "a52sys", 3 ) )
{
/* User forced */
msg_Err( p_input, "this doesn't look like an a52 stream, continuing" );
}
else
{
msg_Warn( p_input, "a52 module discarded (no startcode)" );
return( -1 );
}
}
if( input_InitStream( p_input, 0 ) == -1 )
{
return( -1 );
}
input_AddProgram( p_input, 0, 0 );
p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
vlc_mutex_lock( &p_input->stream.stream_lock );
p_es = input_AddES( p_input, p_input->stream.p_selected_program, 0xBD, 0 );
p_es->i_stream_id = 0xBD;
p_es->i_fourcc = VLC_FOURCC('a','5','2',' ');
p_es->i_cat = AUDIO_ES;
input_SelectES( p_input, p_es );
p_input->stream.p_selected_area->i_tell = 0;
p_input->stream.p_selected_program->b_is_ok = 1;
vlc_mutex_unlock( &p_input->stream.stream_lock );
return( 0 );
}
/*****************************************************************************
* Demux: reads and demuxes data packets
*****************************************************************************
* Returns -1 in case of error, 0 in case of EOF, 1 otherwise
*****************************************************************************/
static int Demux( input_thread_t * p_input )
{
ssize_t i_read;
decoder_fifo_t * p_fifo =
p_input->stream.p_selected_program->pp_es[0]->p_decoder_fifo;
pes_packet_t * p_pes;
data_packet_t * p_data;
i_read = input_SplitBuffer( p_input, &p_data, A52_PACKET_SIZE );
if ( i_read <= 0 )
{
return( i_read );
}
p_pes = input_NewPES( p_input->p_method_data );
if( p_pes == NULL )
{
msg_Err( p_input, "out of memory" );
input_DeletePacket( p_input->p_method_data, p_data );
return( -1 );
}
p_pes->i_rate = p_input->stream.control.i_rate;
p_pes->p_first = p_pes->p_last = p_data;
p_pes->i_nb_data = 1;