Commit 3efee782 authored by Henri Fallon's avatar Henri Fallon

Ajout du layer II mono (non test�) et d�but de mise en conformit� avec
les r�gles de formattage du code
parent e6f64322
...@@ -97,10 +97,11 @@ static int adec_layer1_mono (audiodec_t * p_adec, s16 * buffer) ...@@ -97,10 +97,11 @@ static int adec_layer1_mono (audiodec_t * p_adec, s16 * buffer)
/* parse allocation */ /* parse allocation */
for (sb = 0; sb < 32; sb += 2) { for (sb = 0; sb < 32; sb += 2)
{
u8 tmp; u8 tmp;
tmp = GetByte (&p_adec->bit_stream); tmp = GetByte ( &p_adec->bit_stream );
if ((tmp >> 4) > 14) if ( (tmp >> 4) > 14 )
return 1; return 1;
allocation[sb] = adec_layer1_allocation_table [tmp >> 4]; allocation[sb] = adec_layer1_allocation_table [tmp >> 4];
if ((tmp & 15) > 14) if ((tmp & 15) > 14)
...@@ -110,45 +111,52 @@ static int adec_layer1_mono (audiodec_t * p_adec, s16 * buffer) ...@@ -110,45 +111,52 @@ static int adec_layer1_mono (audiodec_t * p_adec, s16 * buffer)
/* parse scalefactors */ /* parse scalefactors */
for (sb = 0; sb < 32; sb++) { for (sb = 0; sb < 32; sb++)
if (allocation[sb]) { {
int index; if ( allocation[sb] )
float scalefactor; {
int index;
NeedBits (&p_adec->bit_stream, 6); float scalefactor;
index = p_adec->bit_stream.buffer >> (32 - 6);
DumpBits (&p_adec->bit_stream, 6); NeedBits ( &p_adec->bit_stream, 6 );
index = p_adec->bit_stream.buffer >> (32 - 6);
scalefactor = adec_scalefactor_table[index]; DumpBits ( &p_adec->bit_stream, 6 );
slope[sb] = adec_slope_table[allocation[sb]-2] * scalefactor; scalefactor = adec_scalefactor_table[index];
offset[sb] = adec_offset_table[allocation[sb]-2] * scalefactor;
} slope[sb] = adec_slope_table[allocation[sb]-2] * scalefactor;
offset[sb] = adec_offset_table[allocation[sb]-2] * scalefactor;
}
} }
/* parse samples */ /* parse samples */
for (s = 0; s < 12; s++) { for (s = 0; s < 12; s++)
s16 * XXX_buf; {
s16 * XXX_buf;
for (sb = 0; sb < 32; sb++) {
if (!allocation[sb]) {
sample[sb] = 0;
} else {
int code;
NeedBits (&p_adec->bit_stream, allocation[sb]);
code = p_adec->bit_stream.buffer >> (32 - allocation[sb]);
DumpBits (&p_adec->bit_stream, allocation[sb]);
sample[sb] = slope[sb] * code + offset[sb];
}
}
DCT32 (sample, &p_adec->bank_0); for (sb = 0; sb < 32; sb++)
XXX_buf = buffer; {
PCM (&p_adec->bank_0, &XXX_buf, 1); if (!allocation[sb])
buffer += 32; {
sample[sb] = 0;
}
else
{
int code;
NeedBits (&p_adec->bit_stream, allocation[sb]);
code = p_adec->bit_stream.buffer >> (32 - allocation[sb]);
DumpBits (&p_adec->bit_stream, allocation[sb]);
sample[sb] = slope[sb] * code + offset[sb];
}
}
DCT32 (sample, &p_adec->bank_0);
XXX_buf = buffer;
PCM (&p_adec->bank_0, &XXX_buf, 1);
buffer += 32;
} }
return 0; return 0;
...@@ -168,118 +176,132 @@ static int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -168,118 +176,132 @@ static int adec_layer1_stereo (audiodec_t * p_adec, s16 * buffer)
/* calculate bound */ /* calculate bound */
bound = 32; bound = 32;
if ((p_adec->header & 0xc0) == 0x40) { /* intensity stereo */ if ( (p_adec->header & 0xc0) == 0x40)
int index; { /* intensity stereo */
index = (p_adec->header >> 4) & 3; int index;
bound = adec_bound_table[index]; index = (p_adec->header >> 4) & 3;
bound = adec_bound_table[index];
} }
/* parse allocation */ /* parse allocation */
for (sb = 0; sb < bound; sb++) { for (sb = 0; sb < bound; sb++)
u8 tmp; {
tmp = GetByte (&p_adec->bit_stream); u8 tmp;
if ((tmp >> 4) > 14) tmp = GetByte (&p_adec->bit_stream);
return 1; if ((tmp >> 4) > 14)
allocation_0[sb] = adec_layer1_allocation_table [tmp >> 4]; return 1;
if ((tmp & 15) > 14) allocation_0[sb] = adec_layer1_allocation_table [tmp >> 4];
return 1; if ((tmp & 15) > 14)
allocation_1[sb] = adec_layer1_allocation_table [tmp & 15]; return 1;
allocation_1[sb] = adec_layer1_allocation_table [tmp & 15];
} }
for (; sb < 32; sb += 2) { for (; sb < 32; sb += 2)
u8 tmp; {
tmp = GetByte (&p_adec->bit_stream); u8 tmp;
if ((tmp >> 4) > 14) tmp = GetByte (&p_adec->bit_stream);
return 1; if ((tmp >> 4) > 14)
allocation_0[sb] = allocation_1[sb] = adec_layer1_allocation_table [tmp >> 4]; return 1;
if ((tmp & 15) > 14) allocation_0[sb] = allocation_1[sb] = adec_layer1_allocation_table [tmp >> 4];
return 1; if ((tmp & 15) > 14)
allocation_0[sb+1] = allocation_1[sb+1] = adec_layer1_allocation_table [tmp & 15]; return 1;
allocation_0[sb+1] = allocation_1[sb+1] = adec_layer1_allocation_table [tmp & 15];
} }
/* parse scalefactors */ /* parse scalefactors */
for (sb = 0; sb < 32; sb++) { for ( sb = 0; sb < 32; sb++ )
if (allocation_0[sb]) { {
int index; if ( allocation_0[sb] )
float scalefactor; {
int index;
float scalefactor;
NeedBits (&p_adec->bit_stream, 6); NeedBits (&p_adec->bit_stream, 6);
index = p_adec->bit_stream.buffer >> (32 - 6); index = p_adec->bit_stream.buffer >> (32 - 6);
DumpBits (&p_adec->bit_stream, 6); DumpBits (&p_adec->bit_stream, 6);
scalefactor = adec_scalefactor_table[index]; scalefactor = adec_scalefactor_table[index];
slope_0[sb] = adec_slope_table[allocation_0[sb]-2] * scalefactor; slope_0[sb] = adec_slope_table[allocation_0[sb]-2] * scalefactor;
offset_0[sb] = adec_offset_table[allocation_0[sb]-2] * scalefactor; offset_0[sb] = adec_offset_table[allocation_0[sb]-2] * scalefactor;
} }
if (allocation_1[sb]) { if (allocation_1[sb])
int index; {
float scalefactor; int index;
float scalefactor;
NeedBits (&p_adec->bit_stream, 6); NeedBits (&p_adec->bit_stream, 6);
index = p_adec->bit_stream.buffer >> (32 - 6); index = p_adec->bit_stream.buffer >> (32 - 6);
DumpBits (&p_adec->bit_stream, 6); DumpBits (&p_adec->bit_stream, 6);
scalefactor = adec_scalefactor_table[index]; scalefactor = adec_scalefactor_table[index];
slope_1[sb] = adec_slope_table[allocation_1[sb]-2] * scalefactor; slope_1[sb] = adec_slope_table[allocation_1[sb]-2] * scalefactor;
offset_1[sb] = adec_offset_table[allocation_1[sb]-2] * scalefactor; offset_1[sb] = adec_offset_table[allocation_1[sb]-2] * scalefactor;
} }
} }
/* parse samples */ /* parse samples */
for (s = 0; s < 12; s++) { for (s = 0; s < 12; s++)
s16 * XXX_buf; {
s16 * XXX_buf;
for (sb = 0; sb < bound; sb++) {
if (!allocation_0[sb]) for (sb = 0; sb < bound; sb++)
sample_0[sb] = 0; {
else { if (!allocation_0[sb])
int code; sample_0[sb] = 0;
else
NeedBits (&p_adec->bit_stream, allocation_0[sb]); {
code = p_adec->bit_stream.buffer >> (32 - allocation_0[sb]); int code;
DumpBits (&p_adec->bit_stream, allocation_0[sb]);
NeedBits (&p_adec->bit_stream, allocation_0[sb]);
sample_0[sb] = slope_0[sb] * code + offset_0[sb]; code = p_adec->bit_stream.buffer >> (32 - allocation_0[sb]);
} DumpBits (&p_adec->bit_stream, allocation_0[sb]);
if (!allocation_1[sb])
sample_1[sb] = 0; sample_0[sb] = slope_0[sb] * code + offset_0[sb];
else { }
int code; if ( !allocation_1[sb] )
sample_1[sb] = 0;
NeedBits (&p_adec->bit_stream, allocation_1[sb]); else
code = p_adec->bit_stream.buffer >> (32 - allocation_1[sb]); {
DumpBits (&p_adec->bit_stream, allocation_1[sb]); int code;
sample_1[sb] = slope_1[sb] * code + offset_1[sb]; NeedBits (&p_adec->bit_stream, allocation_1[sb]);
} code = p_adec->bit_stream.buffer >> (32 - allocation_1[sb]);
} DumpBits (&p_adec->bit_stream, allocation_1[sb]);
for (; sb < 32; sb++) {
if (!allocation_0[sb]) { sample_1[sb] = slope_1[sb] * code + offset_1[sb];
sample_0[sb] = 0; }
sample_1[sb] = 0; }
} else { for (; sb < 32; sb++)
int sample; {
if (!allocation_0[sb])
NeedBits (&p_adec->bit_stream, allocation_0[sb]); {
sample = p_adec->bit_stream.buffer >> (32 - allocation_0[sb]); sample_0[sb] = 0;
DumpBits (&p_adec->bit_stream, allocation_0[sb]); sample_1[sb] = 0;
}
sample_0[sb] = slope_0[sb] * sample + offset_0[sb]; else
sample_1[sb] = slope_1[sb] * sample + offset_1[sb]; {
} int sample;
}
NeedBits (&p_adec->bit_stream, allocation_0[sb]);
DCT32 (sample_0, &p_adec->bank_0); sample = p_adec->bit_stream.buffer >> (32 - allocation_0[sb]);
XXX_buf = buffer; DumpBits (&p_adec->bit_stream, allocation_0[sb]);
PCM (&p_adec->bank_0, &XXX_buf, 2);
DCT32 (sample_1, &p_adec->bank_1); sample_0[sb] = slope_0[sb] * sample + offset_0[sb];
XXX_buf = buffer+1; sample_1[sb] = slope_1[sb] * sample + offset_1[sb];
PCM (&p_adec->bank_1, &XXX_buf, 2); }
buffer += 64; }
DCT32 (sample_0, &p_adec->bank_0);
XXX_buf = buffer;
PCM (&p_adec->bank_0, &XXX_buf, 2);
DCT32 (sample_1, &p_adec->bank_1);
XXX_buf = buffer+1;
PCM (&p_adec->bank_1, &XXX_buf, 2);
buffer += 64;
} }
return 0; return 0;
...@@ -375,7 +397,327 @@ static void adec_layer2_get_table (u32 header, u8 freq_table[15], ...@@ -375,7 +397,327 @@ static void adec_layer2_get_table (u32 header, u8 freq_table[15],
static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer) static int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
{ {
return 1; static u8 freq_table[15] = {3, 0, 0, 0, 1, 0, 1, 2, 2, 2, 3, 3, 3, 3, 3};
static float L3_table[3] = {-2/3.0, 0, 2/3.0};
static float L5_table[5] = {-4/5.0, -2/5.0, 0, 2/5.0, 4/5.0};
static float L9_table[9] = {-8/9.0, -6/9.0, -4/9.0, -2/9.0, 0,
2/9.0, 4/9.0, 6/9.0, 8/9.0};
s8 allocation[32];
u8 scfsi[32];
float slope[3][32];
float offset[3][32];
float sample[3][32];
alloc_table_t * alloc_table;
int sblimit;
int bound;
int sb;
int gr0, gr1;
int s;
/* get the right allocation table */
adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit);
/* bound -- not required for mono ! */
bound = sblimit;
/* parse allocation table */
for ( sb=0 ; sb < sblimit ; sb++ )
{
int index;
NeedBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
index = p_adec->bit_stream.buffer >> (32 - alloc_table->nbal[sb]);
DumpBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
allocation[sb] = alloc_table->alloc[sb][index];
}
/* parse scfsi */
for ( sb = 0 ; sb < sblimit ; sb++ )
{
if (allocation[sb])
{
NeedBits (&p_adec->bit_stream, 2);
scfsi[sb] = p_adec->bit_stream.buffer >> (32 - 2);
DumpBits (&p_adec->bit_stream, 2);
}
}
/* Parse scalefactors */
for ( sb = 0 ; sb < sblimit ; sb++ )
{
if ( allocation[sb] )
{
int index_0, index_1, index_2;
float r_slope,r_offset;
switch ( scfsi[sb] )
{
case 0 :
NeedBits (&p_adec->bit_stream, 18);
index_0 = p_adec->bit_stream.buffer >> (32 - 6);
index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
index_2 = (p_adec->bit_stream.buffer >> (32 - 18)) & 63;
DumpBits (&p_adec->bit_stream, 18);
if (allocation[sb] < 0)
{
slope[0][sb] = adec_scalefactor_table[index_0];
slope[1][sb] = adec_scalefactor_table[index_1];
slope[2][sb] = adec_scalefactor_table[index_2];
}
else
{
float scalefactor;
r_slope = adec_slope_table[allocation[sb]-2];
r_offset = adec_offset_table[allocation[sb]-2];
scalefactor = adec_scalefactor_table[index_0];
slope[0][sb] = r_slope * scalefactor;
offset[0][sb] = r_offset * scalefactor;
scalefactor = adec_scalefactor_table[index_1];
slope[1][sb] = r_slope * scalefactor;
offset[1][sb] = r_offset * scalefactor;
scalefactor = adec_scalefactor_table[index_2];
slope[2][sb] = r_slope * scalefactor;
offset[2][sb] = r_offset * scalefactor;
}
break;
case 1 :
NeedBits ( &p_adec->bit_stream, 12 );
index_0 = p_adec->bit_stream.buffer >> (32-6);
index_2 = ( p_adec->bit_stream.buffer >> (32-12) ) & 63;
if ( allocation[sb] < 0 )
{
slope[0][sb] = slope[1][sb] =
adec_scalefactor_table[index_0];
slope[2][sb] = adec_scalefactor_table[index_2];
}
else
{
float scalefactor;
r_slope = adec_slope_table[allocation[sb]-2];
r_offset = adec_offset_table[allocation[sb]-2];
scalefactor = adec_scalefactor_table[index_0];
slope[0][sb] = slope[1][sb] = r_slope * scalefactor;
offset[0][sb] = offset[1][sb] = r_offset * scalefactor;
scalefactor = adec_scalefactor_table[index_2];
slope[2][sb] = r_slope * scalefactor;
offset[2][sb] = r_offset * scalefactor;
}
break;
case 2:
NeedBits ( &p_adec->bit_stream, 6);
index_0 = p_adec->bit_stream.buffer >> (32 - 6);
if ( allocation[sb] < 0 )
{
slope[0][sb] = slope[1][sb] = slope[2][sb] =
adec_scalefactor_table[index_0];
}
else
{
float scalefactor;
r_slope = adec_slope_table[allocation[sb]-2];
r_offset = adec_offset_table[allocation[sb]-2];
scalefactor = adec_scalefactor_table[index_0];
slope[0][sb] = slope[1][sb] = slope[2][sb] =
r_slope * scalefactor;
offset[0][sb] = offset[1][sb] = offset[2][sb] =
r_offset * scalefactor;
}
break;
case 3 :
NeedBits ( &p_adec->bit_stream, 12 );
index_0 = p_adec->bit_stream.buffer >> (32-6);
index_2 = ( p_adec->bit_stream.buffer >> (32-12) ) & 63;
if ( allocation[sb] < 0 )
{
slope[0][sb] = adec_scalefactor_table[index_0];
slope[2][sb] = slope[1][sb] =
adec_scalefactor_table[index_2];
}
else
{
float scalefactor;
r_slope = adec_slope_table[allocation[sb]-2];
r_offset = adec_offset_table[allocation[sb]-2];
scalefactor = adec_scalefactor_table[index_0];
slope[0][sb] = r_slope * scalefactor;
offset[0][sb] = r_offset * scalefactor;
scalefactor = adec_scalefactor_table[index_2];
slope[2][sb] = slope[1][sb] = r_slope * scalefactor;
offset[2][sb] = offset[1][sb] = r_offset * scalefactor;
}
break;
}
}
}
/* parse samples */
for (gr0 = 0; gr0 < 3; gr0++)
for (gr1 = 0; gr1 < 4; gr1++)
{
s16 * XXX_buf;
for (sb = 0; sb < bound; sb++)
{
int code;
switch (allocation[sb])
{
case 0:
sample[0][sb] = sample[1][sb] = sample[2][sb] = 0;
break;
case L3:
NeedBits (&p_adec->bit_stream, 5);
code = p_adec->bit_stream.buffer >> (32 - 5);
DumpBits (&p_adec->bit_stream, 5);
sample[0][sb] = slope[gr0][sb] * L3_table[code % 3];
code /= 3;
sample[1][sb] = slope[gr0][sb] * L3_table[code % 3];
code /= 3;
sample[2][sb] = slope[gr0][sb] * L3_table[code];
break;
case L5:
NeedBits (&p_adec->bit_stream, 7);
code = p_adec->bit_stream.buffer >> (32 - 7);
DumpBits (&p_adec->bit_stream, 7);
sample[0][sb] = slope[gr0][sb] * L5_table[code % 5];
code /= 5;
sample[1][sb] = slope[gr0][sb] * L5_table[code % 5];
code /= 5;
sample[2][sb] = slope[gr0][sb] * L5_table[code];
break;
case L9:
NeedBits (&p_adec->bit_stream, 10);
code = p_adec->bit_stream.buffer >> (32 - 10);
DumpBits (&p_adec->bit_stream, 10);
sample[0][sb] = slope[gr0][sb] * L9_table[code % 9];
code /= 9;
sample[1][sb] = slope[gr0][sb] * L9_table[code % 9];
code /= 9;
sample[2][sb] = slope[gr0][sb] * L9_table[code];
break;
default:
for (s = 0; s < 3; s++) {
NeedBits (&p_adec->bit_stream, allocation[sb]);
code = (p_adec->bit_stream.buffer >>
(32 - allocation[sb]));
DumpBits (&p_adec->bit_stream, allocation[sb]);
sample[s][sb] =
slope[gr0][sb] * code + offset[gr0][sb];
}
}
}
for (; sb < sblimit; sb++) {
int code;
switch (allocation[sb]) {
case 0:
sample[0][sb] = sample[1][sb] = sample[2][sb] = 0;
break;
case L3:
NeedBits (&p_adec->bit_stream, 5);
code = p_adec->bit_stream.buffer >> (32 - 5);
DumpBits (&p_adec->bit_stream, 5);
sample[0][sb] = slope[gr0][sb] * L3_table[code % 3];
code /= 3;
sample[1][sb] = slope[gr0][sb] * L3_table[code % 3];
code /= 3;
sample[2][sb] = slope[gr0][sb] * L3_table[code];
break;
case L5:
NeedBits (&p_adec->bit_stream, 7);
code = p_adec->bit_stream.buffer >> (32 - 7);
DumpBits (&p_adec->bit_stream, 7);
sample[0][sb] = slope[gr0][sb] * L5_table[code % 5];
code /= 5;
sample[1][sb] = slope[gr0][sb] * L5_table[code % 5];
code /= 5;
sample[2][sb] = slope[gr0][sb] * L5_table[code];
break;
case L9:
NeedBits (&p_adec->bit_stream, 10);
code = p_adec->bit_stream.buffer >> (32 - 10);
DumpBits (&p_adec->bit_stream, 10);
sample[0][sb] = slope[gr0][sb] * L9_table[code % 9];
code /= 9;
sample[1][sb] = slope[gr0][sb] * L9_table[code % 9];
code /= 9;
sample[2][sb] = slope[gr0][sb] * L9_table[code];
break;
default:
for (s = 0; s < 3; s++) {
NeedBits (&p_adec->bit_stream, allocation[sb]);
code = (p_adec->bit_stream.buffer >>
(32 - allocation[sb]));
DumpBits (&p_adec->bit_stream, allocation[sb]);
sample[s][sb] =
slope[gr0][sb] * code + offset[gr0][sb];
}
}
}
for (; sb < 32; sb++)
{
sample[0][sb] = sample[1][sb] = sample[2][sb] = 0;
}
for (s = 0; s < 3; s++)
{
DCT32 (sample[s], &p_adec->bank_0);
XXX_buf = buffer;
PCM (&p_adec->bank_0, &XXX_buf, 1);
buffer += 32;
}
}
return 0;
} }
static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
...@@ -457,7 +799,8 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer) ...@@ -457,7 +799,8 @@ static int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
/* parse scalefactors */ /* parse scalefactors */
for (sb = 0; sb < sblimit; sb++) { for (sb = 0; sb < sblimit; sb++)
{
if (allocation_0[sb]) { if (allocation_0[sb]) {
int index_0, index_1, index_2; int index_0, index_1, index_2;
......
...@@ -76,15 +76,16 @@ static void EndThread (adec_thread_t * p_adec); ...@@ -76,15 +76,16 @@ static void EndThread (adec_thread_t * p_adec);
* This function creates a new audio decoder thread, and returns a pointer to * This function creates a new audio decoder thread, and returns a pointer to
* its description. On error, it returns NULL. * its description. On error, it returns NULL.
*****************************************************************************/ *****************************************************************************/
adec_thread_t * adec_CreateThread (input_thread_t * p_input) adec_thread_t * adec_CreateThread ( input_thread_t * p_input )
{ {
adec_thread_t * p_adec; adec_thread_t * p_adec;
intf_DbgMsg ("adec debug: creating audio decoder thread\n"); intf_DbgMsg ( "adec debug: creating audio decoder thread\n" );
/* Allocate the memory needed to store the thread's structure */ /* Allocate the memory needed to store the thread's structure */
if ((p_adec = (adec_thread_t *)malloc (sizeof(adec_thread_t))) == NULL) { if ( (p_adec = (adec_thread_t *)malloc (sizeof(adec_thread_t))) == NULL )
intf_ErrMsg ("adec error: not enough memory for adec_CreateThread() to create the new thread\n"); {
intf_ErrMsg ( "adec error: not enough memory for adec_CreateThread() to create the new thread\n" );
return NULL; return NULL;
} }
...@@ -99,8 +100,8 @@ adec_thread_t * adec_CreateThread (input_thread_t * p_input) ...@@ -99,8 +100,8 @@ adec_thread_t * adec_CreateThread (input_thread_t * p_input)
*/ */
/* Initialize the decoder fifo's data lock and conditional variable and set /* Initialize the decoder fifo's data lock and conditional variable and set
* its buffer as empty */ * its buffer as empty */
vlc_mutex_init (&p_adec->fifo.data_lock); vlc_mutex_init ( &p_adec->fifo.data_lock );
vlc_cond_init (&p_adec->fifo.data_wait); vlc_cond_init ( &p_adec->fifo.data_wait );
p_adec->fifo.i_start = 0; p_adec->fifo.i_start = 0;
p_adec->fifo.i_end = 0; p_adec->fifo.i_end = 0;
...@@ -110,7 +111,7 @@ adec_thread_t * adec_CreateThread (input_thread_t * p_input) ...@@ -110,7 +111,7 @@ adec_thread_t * adec_CreateThread (input_thread_t * p_input)
/* /*
* Initialize the decoder properties * Initialize the decoder properties
*/ */
adec_init (&p_adec->audio_decoder); adec_init ( &p_adec->audio_decoder );
/* /*
* Initialize the output properties * Initialize the output properties
...@@ -119,7 +120,8 @@ adec_thread_t * adec_CreateThread (input_thread_t * p_input) ...@@ -119,7 +120,8 @@ adec_thread_t * adec_CreateThread (input_thread_t * p_input)
p_adec->p_aout_fifo = NULL; p_adec->p_aout_fifo = NULL;
/* Spawn the audio decoder thread */ /* Spawn the audio decoder thread */
if (vlc_thread_create(&p_adec->thread_id, "audio decoder", (vlc_thread_func_t)RunThread, (void *)p_adec)) { if ( vlc_thread_create(&p_adec->thread_id, "audio decoder", (vlc_thread_func_t)RunThread, (void *)p_adec) )
{
intf_ErrMsg ("adec error: can't spawn audio decoder thread\n"); intf_ErrMsg ("adec error: can't spawn audio decoder thread\n");
free (p_adec); free (p_adec);
return NULL; return NULL;
...@@ -170,22 +172,24 @@ static int InitThread (adec_thread_t * p_adec) ...@@ -170,22 +172,24 @@ static int InitThread (adec_thread_t * p_adec)
/* Our first job is to initialize the bit stream structure with the /* Our first job is to initialize the bit stream structure with the
* beginning of the input stream */ * beginning of the input stream */
vlc_mutex_lock (&p_adec->fifo.data_lock); vlc_mutex_lock ( &p_adec->fifo.data_lock );
while (DECODER_FIFO_ISEMPTY(p_adec->fifo)) { while ( DECODER_FIFO_ISEMPTY(p_adec->fifo) )
if (p_adec->b_die) { {
vlc_mutex_unlock (&p_adec->fifo.data_lock); if (p_adec->b_die)
{
vlc_mutex_unlock ( &p_adec->fifo.data_lock );
return -1; return -1;
} }
vlc_cond_wait (&p_adec->fifo.data_wait, &p_adec->fifo.data_lock); vlc_cond_wait ( &p_adec->fifo.data_wait, &p_adec->fifo.data_lock );
} }
p_adec->p_ts = DECODER_FIFO_START (p_adec->fifo)->p_first_ts; p_adec->p_ts = DECODER_FIFO_START ( p_adec->fifo )->p_first_ts;
byte_stream = adec_byte_stream (&p_adec->audio_decoder); byte_stream = adec_byte_stream ( &p_adec->audio_decoder );
byte_stream->p_byte = byte_stream->p_byte =
p_adec->p_ts->buffer + p_adec->p_ts->i_payload_start; p_adec->p_ts->buffer + p_adec->p_ts->i_payload_start;
byte_stream->p_end = byte_stream->p_end =
p_adec->p_ts->buffer + p_adec->p_ts->i_payload_end; p_adec->p_ts->buffer + p_adec->p_ts->i_payload_end;
byte_stream->info = p_adec; byte_stream->info = p_adec;
vlc_mutex_unlock (&p_adec->fifo.data_lock); vlc_mutex_unlock ( &p_adec->fifo.data_lock );
aout_fifo.i_type = AOUT_ADEC_STEREO_FIFO; aout_fifo.i_type = AOUT_ADEC_STEREO_FIFO;
aout_fifo.i_channels = 2; aout_fifo.i_channels = 2;
...@@ -193,11 +197,12 @@ static int InitThread (adec_thread_t * p_adec) ...@@ -193,11 +197,12 @@ static int InitThread (adec_thread_t * p_adec)
aout_fifo.l_frame_size = ADEC_FRAME_SIZE; aout_fifo.l_frame_size = ADEC_FRAME_SIZE;
/* Creating the audio output fifo */ /* Creating the audio output fifo */
if ((p_adec->p_aout_fifo = aout_CreateFifo(p_adec->p_aout, &aout_fifo)) == NULL) { if ( (p_adec->p_aout_fifo = aout_CreateFifo(p_adec->p_aout, &aout_fifo)) == NULL )
{
return -1; return -1;
} }
intf_DbgMsg ("adec debug: audio decoder thread %p initialized\n", p_adec); intf_DbgMsg ( "adec debug: audio decoder thread %p initialized\n", p_adec );
return 0; return 0;
} }
...@@ -211,9 +216,9 @@ static void RunThread (adec_thread_t * p_adec) ...@@ -211,9 +216,9 @@ static void RunThread (adec_thread_t * p_adec)
{ {
int sync; int sync;
intf_DbgMsg ("adec debug: running audio decoder thread (%p) (pid == %i)\n", p_adec, getpid()); intf_DbgMsg ( "adec debug: running audio decoder thread (%p) (pid == %i)\n", p_adec, getpid() );
msleep (INPUT_PTS_DELAY); msleep ( INPUT_PTS_DELAY );
/* Initializing the audio decoder thread */ /* Initializing the audio decoder thread */
if( InitThread (p_adec) ) if( InitThread (p_adec) )
...@@ -229,26 +234,26 @@ static void RunThread (adec_thread_t * p_adec) ...@@ -229,26 +234,26 @@ static void RunThread (adec_thread_t * p_adec)
s16 * buffer; s16 * buffer;
adec_sync_info_t sync_info; adec_sync_info_t sync_info;
if (!sync) if ( !sync )
{ {
/* have to find a synchro point */ /* have to find a synchro point */
adec_byte_stream_t * p_byte_stream; adec_byte_stream_t * p_byte_stream;
printf ("sync\n"); printf ( "sync\n" );
p_adec->align = 0; p_adec->align = 0;
p_byte_stream = adec_byte_stream (&p_adec->audio_decoder); p_byte_stream = adec_byte_stream ( &p_adec->audio_decoder );
do do
{ {
adec_byte_stream_next (p_byte_stream); adec_byte_stream_next ( p_byte_stream );
} while ((!p_adec->align) && (!p_adec->b_die) && (!p_adec->b_error)); } while ( (!p_adec->align) && (!p_adec->b_die) && (!p_adec->b_error) );
sync = 1; sync = 1;
} }
if( DECODER_FIFO_START(p_adec->fifo)->b_has_pts ) if( DECODER_FIFO_START( p_adec->fifo)->b_has_pts )
{ {
p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] = DECODER_FIFO_START(p_adec->fifo)->i_pts; p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] = DECODER_FIFO_START( p_adec->fifo )->i_pts;
DECODER_FIFO_START(p_adec->fifo)->b_has_pts = 0; DECODER_FIFO_START(p_adec->fifo)->b_has_pts = 0;
} }
else else
...@@ -298,26 +303,28 @@ static void RunThread (adec_thread_t * p_adec) ...@@ -298,26 +303,28 @@ static void RunThread (adec_thread_t * p_adec)
* thread can still receive feed, but must be ready to terminate as soon as * thread can still receive feed, but must be ready to terminate as soon as
* possible. * possible.
*****************************************************************************/ *****************************************************************************/
static void ErrorThread (adec_thread_t *p_adec) static void ErrorThread ( adec_thread_t *p_adec )
{ {
/* We take the lock, because we are going to read/write the start/end /* We take the lock, because we are going to read/write the start/end
* indexes of the decoder fifo */ * indexes of the decoder fifo */
vlc_mutex_lock (&p_adec->fifo.data_lock); vlc_mutex_lock ( &p_adec->fifo.data_lock );
/* Wait until a `die' order is sent */ /* Wait until a `die' order is sent */
while (!p_adec->b_die) { while ( !p_adec->b_die )
{
/* Trash all received PES packets */ /* Trash all received PES packets */
while (!DECODER_FIFO_ISEMPTY(p_adec->fifo)) { while ( !DECODER_FIFO_ISEMPTY(p_adec->fifo) )
input_NetlistFreePES (p_adec->p_input, DECODER_FIFO_START(p_adec->fifo)); {
DECODER_FIFO_INCSTART (p_adec->fifo); input_NetlistFreePES ( p_adec->p_input, DECODER_FIFO_START(p_adec->fifo) );
DECODER_FIFO_INCSTART ( p_adec->fifo );
} }
/* Waiting for the input thread to put new PES packets in the fifo */ /* Waiting for the input thread to put new PES packets in the fifo */
vlc_cond_wait (&p_adec->fifo.data_wait, &p_adec->fifo.data_lock); vlc_cond_wait ( &p_adec->fifo.data_wait, &p_adec->fifo.data_lock );
} }
/* We can release the lock before leaving */ /* We can release the lock before leaving */
vlc_mutex_unlock (&p_adec->fifo.data_lock); vlc_mutex_unlock ( &p_adec->fifo.data_lock );
} }
/***************************************************************************** /*****************************************************************************
...@@ -326,13 +333,14 @@ static void ErrorThread (adec_thread_t *p_adec) ...@@ -326,13 +333,14 @@ static void ErrorThread (adec_thread_t *p_adec)
* This function is called when the thread ends after a sucessful * This function is called when the thread ends after a sucessful
* initialization. * initialization.
*****************************************************************************/ *****************************************************************************/
static void EndThread (adec_thread_t *p_adec) static void EndThread ( adec_thread_t *p_adec )
{ {
intf_DbgMsg ("adec debug: destroying audio decoder thread %p\n", p_adec); intf_DbgMsg ( "adec debug: destroying audio decoder thread %p\n", p_adec );
/* If the audio output fifo was created, we destroy it */ /* If the audio output fifo was created, we destroy it */
if (p_adec->p_aout_fifo != NULL) { if ( p_adec->p_aout_fifo != NULL )
aout_DestroyFifo (p_adec->p_aout_fifo); {
aout_DestroyFifo ( p_adec->p_aout_fifo );
/* Make sure the output thread leaves the NextFrame() function */ /* Make sure the output thread leaves the NextFrame() function */
vlc_mutex_lock (&(p_adec->p_aout_fifo->data_lock)); vlc_mutex_lock (&(p_adec->p_aout_fifo->data_lock));
...@@ -345,23 +353,26 @@ static void EndThread (adec_thread_t *p_adec) ...@@ -345,23 +353,26 @@ static void EndThread (adec_thread_t *p_adec)
intf_DbgMsg ("adec debug: audio decoder thread %p destroyed\n", p_adec); intf_DbgMsg ("adec debug: audio decoder thread %p destroyed\n", p_adec);
} }
void adec_byte_stream_next (adec_byte_stream_t * p_byte_stream) void adec_byte_stream_next ( adec_byte_stream_t * p_byte_stream )
{ {
adec_thread_t * p_adec = p_byte_stream->info; adec_thread_t * p_adec = p_byte_stream->info;
/* We are looking for the next TS packet that contains real data, /* We are looking for the next TS packet that contains real data,
* and not just a PES header */ * and not just a PES header */
do { do
{
/* We were reading the last TS packet of this PES packet... It's /* We were reading the last TS packet of this PES packet... It's
* time to jump to the next PES packet */ * time to jump to the next PES packet */
if (p_adec->p_ts->p_next_ts == NULL) { if (p_adec->p_ts->p_next_ts == NULL)
{
/* We are going to read/write the start and end indexes of the /* We are going to read/write the start and end indexes of the
* decoder fifo and to use the fifo's conditional variable, * decoder fifo and to use the fifo's conditional variable,
* that's why we need to take the lock before */ * that's why we need to take the lock before */
vlc_mutex_lock (&p_adec->fifo.data_lock); vlc_mutex_lock (&p_adec->fifo.data_lock);
/* Is the input thread dying ? */ /* Is the input thread dying ? */
if (p_adec->p_input->b_die) { if (p_adec->p_input->b_die)
{
vlc_mutex_unlock (&(p_adec->fifo.data_lock)); vlc_mutex_unlock (&(p_adec->fifo.data_lock));
return; return;
} }
...@@ -374,9 +385,11 @@ void adec_byte_stream_next (adec_byte_stream_t * p_byte_stream) ...@@ -374,9 +385,11 @@ void adec_byte_stream_next (adec_byte_stream_t * p_byte_stream)
input_NetlistFreePES (p_adec->p_input, DECODER_FIFO_START(p_adec->fifo)); input_NetlistFreePES (p_adec->p_input, DECODER_FIFO_START(p_adec->fifo));
DECODER_FIFO_INCSTART (p_adec->fifo); DECODER_FIFO_INCSTART (p_adec->fifo);
while (DECODER_FIFO_ISEMPTY(p_adec->fifo)) { while (DECODER_FIFO_ISEMPTY(p_adec->fifo))
{
vlc_cond_wait (&p_adec->fifo.data_wait, &p_adec->fifo.data_lock); vlc_cond_wait (&p_adec->fifo.data_wait, &p_adec->fifo.data_lock);
if (p_adec->p_input->b_die) { if (p_adec->p_input->b_die)
{
vlc_mutex_unlock (&(p_adec->fifo.data_lock)); vlc_mutex_unlock (&(p_adec->fifo.data_lock));
return; return;
} }
...@@ -392,7 +405,8 @@ void adec_byte_stream_next (adec_byte_stream_t * p_byte_stream) ...@@ -392,7 +405,8 @@ void adec_byte_stream_next (adec_byte_stream_t * p_byte_stream)
} }
/* Perhaps the next TS packet of the current PES packet contains /* Perhaps the next TS packet of the current PES packet contains
* real data (ie its payload's size is greater than 0) */ * real data (ie its payload's size is greater than 0) */
else { else
{
p_adec->p_ts = p_adec->p_ts->p_next_ts; p_adec->p_ts = p_adec->p_ts->p_next_ts;
} }
} while (p_adec->p_ts->i_payload_start == p_adec->p_ts->i_payload_end); } while (p_adec->p_ts->i_payload_start == p_adec->p_ts->i_payload_end);
......
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