Skip to content

Commit 24a26f7

Browse files
committed
audiotrack: fix spdif with circular buffer
1 parent f27db0d commit 24a26f7

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

modules/audio_output/audiotrack.c

+14-19
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ struct aout_sys_t {
114114
} smoothpos;
115115

116116
uint32_t i_bytes_per_frame; /* byte per frame */
117+
uint32_t i_frame_length; /* frame length */
117118
uint32_t i_max_audiotrack_samples;
118119
bool b_spdif;
119120
uint8_t i_chans_to_reorder; /* do we need channel reordering */
@@ -461,21 +462,15 @@ frames_to_us( aout_sys_t *p_sys, uint64_t i_nb_frames )
461462
static inline uint64_t
462463
bytes_to_frames( aout_sys_t *p_sys, size_t i_bytes )
463464
{
464-
if( p_sys->b_spdif )
465-
return i_bytes * A52_FRAME_NB / p_sys->i_bytes_per_frame;
466-
else
467-
return i_bytes / p_sys->i_bytes_per_frame;
465+
return i_bytes * p_sys->i_frame_length / p_sys->i_bytes_per_frame;
468466
}
469467
#define BYTES_TO_FRAMES(x) bytes_to_frames( p_sys, (x) )
470468
#define BYTES_TO_US(x) frames_to_us( p_sys, bytes_to_frames( p_sys, (x) ) )
471469

472470
static inline size_t
473471
frames_to_bytes( aout_sys_t *p_sys, uint64_t i_frames )
474472
{
475-
if( p_sys->b_spdif )
476-
return i_frames * p_sys->i_bytes_per_frame / A52_FRAME_NB;
477-
else
478-
return i_frames * p_sys->i_bytes_per_frame;
473+
return i_frames * p_sys->i_bytes_per_frame / p_sys->i_frame_length;
479474
}
480475
#define FRAMES_TO_BYTES(x) frames_to_bytes( p_sys, (x) )
481476

@@ -881,10 +876,7 @@ AudioTrack_Create( JNIEnv *env, audio_output_t *p_aout,
881876
msg_Warn( p_aout, "getMinBufferSize returned an invalid size" ) ;
882877
return -1;
883878
}
884-
if( i_vlc_format == VLC_CODEC_SPDIFB )
885-
i_size = ( i_min_buffer_size / AOUT_SPDIF_SIZE + 1 ) * AOUT_SPDIF_SIZE;
886-
else
887-
i_size = i_min_buffer_size * 2;
879+
i_size = i_min_buffer_size * 2;
888880

889881
/* create AudioTrack object */
890882
if( AudioTrack_New( env, p_aout, i_rate, i_channel_config,
@@ -904,8 +896,7 @@ Start( audio_output_t *p_aout, audio_sample_format_t *restrict p_fmt )
904896
{
905897
aout_sys_t *p_sys = p_aout->sys;
906898
JNIEnv *env;
907-
int i_nb_channels, i_max_channels, i_bytes_per_frame, i_native_rate = 0,
908-
i_ret;
899+
int i_nb_channels, i_max_channels, i_native_rate = 0, i_ret;
909900
unsigned int i_rate;
910901
bool b_spdif;
911902

@@ -989,8 +980,6 @@ Start( audio_output_t *p_aout, audio_sample_format_t *restrict p_fmt )
989980
do
990981
{
991982
i_nb_channels = aout_FormatNbChannels( &p_sys->fmt );
992-
i_bytes_per_frame = i_nb_channels *
993-
aout_BitsPerSample( p_sys->fmt.i_format ) / 8;
994983
i_rate = p_sys->fmt.i_format == VLC_CODEC_SPDIFB ?
995984
VLC_CLIP( p_sys->fmt.i_rate, 32000, 48000 )
996985
: (unsigned int) i_native_rate;
@@ -1036,9 +1025,10 @@ Start( audio_output_t *p_aout, audio_sample_format_t *restrict p_fmt )
10361025
p_sys->b_spdif = p_sys->fmt.i_format == VLC_CODEC_SPDIFB;
10371026
if( p_sys->b_spdif )
10381027
{
1028+
p_sys->i_bytes_per_frame =
10391029
p_sys->fmt.i_bytes_per_frame = AOUT_SPDIF_SIZE;
1030+
p_sys->i_frame_length =
10401031
p_sys->fmt.i_frame_length = A52_FRAME_NB;
1041-
p_sys->i_bytes_per_frame = p_sys->fmt.i_bytes_per_frame;
10421032
}
10431033
else
10441034
{
@@ -1050,7 +1040,10 @@ Start( audio_output_t *p_aout, audio_sample_format_t *restrict p_fmt )
10501040
aout_CheckChannelReorder( NULL, p_chans_out,
10511041
p_sys->fmt.i_physical_channels,
10521042
p_sys->p_chan_table );
1053-
p_sys->i_bytes_per_frame = i_bytes_per_frame;
1043+
p_sys->i_bytes_per_frame = i_nb_channels
1044+
* aout_BitsPerSample( p_sys->fmt.i_format )
1045+
/ 8;
1046+
p_sys->i_frame_length = 1;
10541047
}
10551048
p_sys->i_max_audiotrack_samples = BYTES_TO_FRAMES( p_sys->audiotrack_args.i_size );
10561049

@@ -1091,7 +1084,9 @@ Start( audio_output_t *p_aout, audio_sample_format_t *restrict p_fmt )
10911084
p_sys->circular.i_read = p_sys->circular.i_write = 0;
10921085
/* 2 seconds of buffering */
10931086
p_sys->circular.i_size = (int)i_rate * AOUT_MAX_PREPARE_TIME
1094-
* i_bytes_per_frame / CLOCK_FREQ;
1087+
* p_sys->i_bytes_per_frame
1088+
/ p_sys->i_frame_length
1089+
/ CLOCK_FREQ;
10951090

10961091
/* Allocate circular buffer */
10971092
switch( p_sys->i_write_type )

0 commit comments

Comments
 (0)