added parameter total_time to decoder_initialized()
Similar to the previous patch: pass total_time instead of manipulating dc->totalTime directly.
This commit is contained in:
parent
4590a98f0e
commit
0d8b551c5a
@ -25,7 +25,8 @@
|
|||||||
#include "gcc.h"
|
#include "gcc.h"
|
||||||
|
|
||||||
void decoder_initialized(mpd_unused struct decoder * decoder,
|
void decoder_initialized(mpd_unused struct decoder * decoder,
|
||||||
const AudioFormat * audio_format)
|
const AudioFormat * audio_format,
|
||||||
|
float total_time)
|
||||||
{
|
{
|
||||||
assert(dc.state == DECODE_STATE_START);
|
assert(dc.state == DECODE_STATE_START);
|
||||||
|
|
||||||
@ -35,6 +36,8 @@ void decoder_initialized(mpd_unused struct decoder * decoder,
|
|||||||
&(ob.audioFormat));
|
&(ob.audioFormat));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dc.totalTime = total_time;
|
||||||
|
|
||||||
dc.state = DECODE_STATE_DECODE;
|
dc.state = DECODE_STATE_DECODE;
|
||||||
notify_signal(&pc.notify);
|
notify_signal(&pc.notify);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,8 @@ struct decoder;
|
|||||||
* that it has read the song's meta data.
|
* that it has read the song's meta data.
|
||||||
*/
|
*/
|
||||||
void decoder_initialized(struct decoder * decoder,
|
void decoder_initialized(struct decoder * decoder,
|
||||||
const AudioFormat * audio_format);
|
const AudioFormat * audio_format,
|
||||||
|
float total_time);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is called by the decoder plugin when it has
|
* This function is called by the decoder plugin when it has
|
||||||
|
@ -165,7 +165,7 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
|
|||||||
data->audio_format.bits = (mpd_sint8)si->bits_per_sample;
|
data->audio_format.bits = (mpd_sint8)si->bits_per_sample;
|
||||||
data->audio_format.sampleRate = si->sample_rate;
|
data->audio_format.sampleRate = si->sample_rate;
|
||||||
data->audio_format.channels = (mpd_sint8)si->channels;
|
data->audio_format.channels = (mpd_sint8)si->channels;
|
||||||
dc.totalTime = ((float)si->total_samples) / (si->sample_rate);
|
data->total_time = ((float)si->total_samples) / (si->sample_rate);
|
||||||
break;
|
break;
|
||||||
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
|
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
|
||||||
flacParseReplayGain(block, data);
|
flacParseReplayGain(block, data);
|
||||||
|
@ -144,6 +144,7 @@ typedef struct {
|
|||||||
float time;
|
float time;
|
||||||
unsigned int bitRate;
|
unsigned int bitRate;
|
||||||
AudioFormat audio_format;
|
AudioFormat audio_format;
|
||||||
|
float total_time;
|
||||||
FLAC__uint64 position;
|
FLAC__uint64 position;
|
||||||
struct decoder *decoder;
|
struct decoder *decoder;
|
||||||
InputStream *inStream;
|
InputStream *inStream;
|
||||||
|
@ -338,8 +338,6 @@ static int aac_decode(struct decoder * mpd_decoder, char *path)
|
|||||||
|
|
||||||
audio_format.bits = 16;
|
audio_format.bits = 16;
|
||||||
|
|
||||||
dc.totalTime = totalTime;
|
|
||||||
|
|
||||||
file_time = 0.0;
|
file_time = 0.0;
|
||||||
|
|
||||||
advanceAacBuffer(&b, bread);
|
advanceAacBuffer(&b, bread);
|
||||||
@ -372,7 +370,8 @@ static int aac_decode(struct decoder * mpd_decoder, char *path)
|
|||||||
if (dc.state != DECODE_STATE_DECODE) {
|
if (dc.state != DECODE_STATE_DECODE) {
|
||||||
audio_format.channels = frameInfo.channels;
|
audio_format.channels = frameInfo.channels;
|
||||||
audio_format.sampleRate = sampleRate;
|
audio_format.sampleRate = sampleRate;
|
||||||
decoder_initialized(mpd_decoder, &audio_format);
|
decoder_initialized(mpd_decoder, &audio_format,
|
||||||
|
totalTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
advanceAacBuffer(&b, frameInfo.bytesconsumed);
|
advanceAacBuffer(&b, frameInfo.bytesconsumed);
|
||||||
|
@ -46,6 +46,7 @@ static int audiofile_decode(struct decoder * decoder, char *path)
|
|||||||
AFfilehandle af_fp;
|
AFfilehandle af_fp;
|
||||||
int bits;
|
int bits;
|
||||||
AudioFormat audio_format;
|
AudioFormat audio_format;
|
||||||
|
float total_time;
|
||||||
mpd_uint16 bitRate;
|
mpd_uint16 bitRate;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
@ -71,10 +72,9 @@ static int audiofile_decode(struct decoder * decoder, char *path)
|
|||||||
|
|
||||||
frame_count = afGetFrameCount(af_fp, AF_DEFAULT_TRACK);
|
frame_count = afGetFrameCount(af_fp, AF_DEFAULT_TRACK);
|
||||||
|
|
||||||
dc.totalTime =
|
total_time = ((float)frame_count / (float)audio_format.sampleRate);
|
||||||
((float)frame_count / (float)audio_format.sampleRate);
|
|
||||||
|
|
||||||
bitRate = (mpd_uint16)(st.st_size * 8.0 / dc.totalTime / 1000.0 + 0.5);
|
bitRate = (mpd_uint16)(st.st_size * 8.0 / total_time / 1000.0 + 0.5);
|
||||||
|
|
||||||
if (audio_format.bits != 8 && audio_format.bits != 16) {
|
if (audio_format.bits != 8 && audio_format.bits != 16) {
|
||||||
ERROR("Only 8 and 16-bit files are supported. %s is %i-bit\n",
|
ERROR("Only 8 and 16-bit files are supported. %s is %i-bit\n",
|
||||||
@ -85,7 +85,7 @@ static int audiofile_decode(struct decoder * decoder, char *path)
|
|||||||
|
|
||||||
fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1);
|
fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1);
|
||||||
|
|
||||||
decoder_initialized(decoder, &audio_format);
|
decoder_initialized(decoder, &audio_format, total_time);
|
||||||
|
|
||||||
{
|
{
|
||||||
int ret, eof = 0, current = 0;
|
int ret, eof = 0, current = 0;
|
||||||
|
@ -415,7 +415,7 @@ static int flac_decode_internal(struct decoder * decoder,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
decoder_initialized(decoder, &data.audio_format);
|
decoder_initialized(decoder, &data.audio_format, data.total_time);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (!flac_process_single(flacDec))
|
if (!flac_process_single(flacDec))
|
||||||
|
@ -176,7 +176,6 @@ static int mod_decode(struct decoder * decoder, char *path)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
dc.totalTime = 0;
|
|
||||||
audio_format.bits = 16;
|
audio_format.bits = 16;
|
||||||
audio_format.sampleRate = 44100;
|
audio_format.sampleRate = 44100;
|
||||||
audio_format.channels = 2;
|
audio_format.channels = 2;
|
||||||
@ -185,7 +184,7 @@ static int mod_decode(struct decoder * decoder, char *path)
|
|||||||
1.0 / ((audio_format.bits * audio_format.channels / 8.0) *
|
1.0 / ((audio_format.bits * audio_format.channels / 8.0) *
|
||||||
(float)audio_format.sampleRate);
|
(float)audio_format.sampleRate);
|
||||||
|
|
||||||
decoder_initialized(decoder, &audio_format);
|
decoder_initialized(decoder, &audio_format, 0);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (dc.command == DECODE_COMMAND_SEEK) {
|
if (dc.command == DECODE_COMMAND_SEEK) {
|
||||||
|
@ -1035,8 +1035,6 @@ static int mp3_decode(struct decoder * decoder, InputStream * inStream)
|
|||||||
|
|
||||||
initAudioFormatFromMp3DecodeData(&data, &audio_format);
|
initAudioFormatFromMp3DecodeData(&data, &audio_format);
|
||||||
|
|
||||||
dc.totalTime = data.totalTime;
|
|
||||||
|
|
||||||
if (inStream->metaTitle) {
|
if (inStream->metaTitle) {
|
||||||
if (tag)
|
if (tag)
|
||||||
freeMpdTag(tag);
|
freeMpdTag(tag);
|
||||||
@ -1062,7 +1060,7 @@ static int mp3_decode(struct decoder * decoder, InputStream * inStream)
|
|||||||
freeMpdTag(tag);
|
freeMpdTag(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
decoder_initialized(decoder, &audio_format);
|
decoder_initialized(decoder, &audio_format, data.totalTime);
|
||||||
|
|
||||||
while (mp3Read(&data, decoder, &replayGainInfo) != DECODE_BREAK) ;
|
while (mp3Read(&data, decoder, &replayGainInfo) != DECODE_BREAK) ;
|
||||||
/* send last little bit if not DECODE_COMMAND_STOP */
|
/* send last little bit if not DECODE_COMMAND_STOP */
|
||||||
|
@ -83,7 +83,7 @@ static int mp4_decode(struct decoder * mpd_decoder, InputStream * inStream)
|
|||||||
mp4ff_t *mp4fh;
|
mp4ff_t *mp4fh;
|
||||||
mp4ff_callback_t *mp4cb;
|
mp4ff_callback_t *mp4cb;
|
||||||
int32_t track;
|
int32_t track;
|
||||||
float file_time;
|
float file_time, total_time;
|
||||||
int32_t scale;
|
int32_t scale;
|
||||||
faacDecHandle decoder;
|
faacDecHandle decoder;
|
||||||
faacDecFrameInfo frameInfo;
|
faacDecFrameInfo frameInfo;
|
||||||
@ -170,7 +170,7 @@ static int mp4_decode(struct decoder * mpd_decoder, InputStream * inStream)
|
|||||||
free(mp4cb);
|
free(mp4cb);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
dc.totalTime = ((float)file_time) / scale;
|
total_time = ((float)file_time) / scale;
|
||||||
|
|
||||||
numSamples = mp4ff_num_samples(mp4fh, track);
|
numSamples = mp4ff_num_samples(mp4fh, track);
|
||||||
|
|
||||||
@ -248,7 +248,8 @@ static int mp4_decode(struct decoder * mpd_decoder, InputStream * inStream)
|
|||||||
#endif
|
#endif
|
||||||
audio_format.sampleRate = scale;
|
audio_format.sampleRate = scale;
|
||||||
audio_format.channels = frameInfo.channels;
|
audio_format.channels = frameInfo.channels;
|
||||||
decoder_initialized(mpd_decoder, &audio_format);
|
decoder_initialized(mpd_decoder, &audio_format,
|
||||||
|
total_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channels * (unsigned long)(dur + offset) > frameInfo.samples) {
|
if (channels * (unsigned long)(dur + offset) > frameInfo.samples) {
|
||||||
|
@ -160,8 +160,6 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
dc.totalTime = mpc_streaminfo_get_length(&info);
|
|
||||||
|
|
||||||
audio_format.bits = 16;
|
audio_format.bits = 16;
|
||||||
audio_format.channels = info.channels;
|
audio_format.channels = info.channels;
|
||||||
audio_format.sampleRate = info.sample_freq;
|
audio_format.sampleRate = info.sample_freq;
|
||||||
@ -172,7 +170,8 @@ static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream)
|
|||||||
replayGainInfo->trackGain = info.gain_title * 0.01;
|
replayGainInfo->trackGain = info.gain_title * 0.01;
|
||||||
replayGainInfo->trackPeak = info.peak_title / 32767.0;
|
replayGainInfo->trackPeak = info.peak_title / 32767.0;
|
||||||
|
|
||||||
decoder_initialized(mpd_decoder, &audio_format);
|
decoder_initialized(mpd_decoder, &audio_format,
|
||||||
|
mpc_streaminfo_get_length(&info));
|
||||||
|
|
||||||
while (!eof) {
|
while (!eof) {
|
||||||
if (dc.command == DECODE_COMMAND_SEEK) {
|
if (dc.command == DECODE_COMMAND_SEEK) {
|
||||||
|
@ -345,7 +345,7 @@ static int oggflac_decode(struct decoder * mpd_decoder, InputStream * inStream)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
decoder_initialized(mpd_decoder, &data.audio_format);
|
decoder_initialized(mpd_decoder, &data.audio_format, data.total_time);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
OggFLAC__seekable_stream_decoder_process_single(decoder);
|
OggFLAC__seekable_stream_decoder_process_single(decoder);
|
||||||
|
@ -262,9 +262,6 @@ static int oggvorbis_decode(struct decoder * decoder, InputStream * inStream)
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
dc.totalTime = ov_time_total(&vf, -1);
|
|
||||||
if (dc.totalTime < 0)
|
|
||||||
dc.totalTime = 0;
|
|
||||||
audio_format.bits = 16;
|
audio_format.bits = 16;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -285,7 +282,11 @@ static int oggvorbis_decode(struct decoder * decoder, InputStream * inStream)
|
|||||||
audio_format.channels = vi->channels;
|
audio_format.channels = vi->channels;
|
||||||
audio_format.sampleRate = vi->rate;
|
audio_format.sampleRate = vi->rate;
|
||||||
if (dc.state == DECODE_STATE_START) {
|
if (dc.state == DECODE_STATE_START) {
|
||||||
decoder_initialized(decoder, &audio_format);
|
float total_time = ov_time_total(&vf, -1);
|
||||||
|
if (total_time < 0)
|
||||||
|
total_time = 0;
|
||||||
|
decoder_initialized(decoder, &audio_format,
|
||||||
|
total_time);
|
||||||
}
|
}
|
||||||
comments = ov_comment(&vf, -1)->user_comments;
|
comments = ov_comment(&vf, -1)->user_comments;
|
||||||
putOggCommentsIntoOutputBuffer(inStream->metaName,
|
putOggCommentsIntoOutputBuffer(inStream->metaName,
|
||||||
|
@ -164,10 +164,10 @@ static void wavpack_decode(struct decoder * decoder,
|
|||||||
|
|
||||||
samplesreq = sizeof(chunk) / (4 * audio_format.channels);
|
samplesreq = sizeof(chunk) / (4 * audio_format.channels);
|
||||||
|
|
||||||
dc.totalTime = (float)allsamples / audio_format.sampleRate;
|
|
||||||
dc.seekable = canseek;
|
dc.seekable = canseek;
|
||||||
|
|
||||||
decoder_initialized(decoder, &audio_format);
|
decoder_initialized(decoder, &audio_format,
|
||||||
|
(float)allsamples / audio_format.sampleRate);
|
||||||
|
|
||||||
position = 0;
|
position = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user