2017-02-18 00:17:38 +01:00
|
|
|
#include "coding.h"
|
|
|
|
#include "../util.h"
|
2008-07-05 13:49:29 +02:00
|
|
|
#include "../vgmstream.h"
|
|
|
|
|
|
|
|
#ifdef VGM_USE_MPEG
|
2017-07-29 23:14:04 +02:00
|
|
|
#include "mpeg_decoder.h"
|
|
|
|
|
|
|
|
|
2017-12-01 17:32:12 +01:00
|
|
|
#define MPEG_DATA_BUFFER_SIZE 0x1000 /* at least one MPEG frame (max ~0x5A1 plus some more in case of free bitrate) */
|
2017-02-19 20:20:13 +01:00
|
|
|
|
2021-05-08 15:31:01 +02:00
|
|
|
static mpg123_handle* init_mpg123_handle();
|
|
|
|
static void decode_mpeg_standard(VGMSTREAMCHANNEL* stream, mpeg_codec_data* data, sample_t* outbuf, int32_t samples_to_do, int channels);
|
|
|
|
static void decode_mpeg_custom(VGMSTREAM* vgmstream, mpeg_codec_data* data, sample_t* outbuf, int32_t samples_to_do, int channels);
|
|
|
|
static void decode_mpeg_custom_stream(VGMSTREAMCHANNEL *stream, mpeg_codec_data* data, int num_stream);
|
2008-07-05 13:49:29 +02:00
|
|
|
|
2017-08-05 17:54:50 +02:00
|
|
|
|
2017-07-29 23:14:04 +02:00
|
|
|
/* Inits regular MPEG */
|
2021-05-08 15:31:01 +02:00
|
|
|
mpeg_codec_data* init_mpeg(STREAMFILE* sf, off_t start_offset, coding_t* coding_type, int channels) {
|
|
|
|
mpeg_codec_data* data = NULL;
|
2017-02-18 00:17:38 +01:00
|
|
|
|
|
|
|
/* init codec */
|
2021-05-08 15:31:01 +02:00
|
|
|
data = calloc(1, sizeof(mpeg_codec_data));
|
2017-02-18 00:17:38 +01:00
|
|
|
if (!data) goto fail;
|
|
|
|
|
2017-07-29 23:14:04 +02:00
|
|
|
data->buffer_size = MPEG_DATA_BUFFER_SIZE;
|
2017-02-18 00:17:38 +01:00
|
|
|
data->buffer = calloc(sizeof(uint8_t), data->buffer_size);
|
|
|
|
if (!data->buffer) goto fail;
|
2010-09-10 23:49:56 +02:00
|
|
|
|
2017-02-18 18:27:21 +01:00
|
|
|
data->m = init_mpg123_handle();
|
|
|
|
if (!data->m) goto fail;
|
2010-09-10 23:49:56 +02:00
|
|
|
|
|
|
|
/* check format */
|
|
|
|
{
|
2017-02-18 18:27:21 +01:00
|
|
|
mpg123_handle *main_m = data->m;
|
|
|
|
off_t read_offset = 0;
|
|
|
|
int rc;
|
|
|
|
|
2017-02-19 20:20:13 +01:00
|
|
|
long sample_rate_per_frame;
|
|
|
|
int channels_per_frame, encoding;
|
|
|
|
size_t samples_per_frame;
|
2010-09-10 23:49:56 +02:00
|
|
|
struct mpg123_frameinfo mi;
|
2017-02-18 00:17:38 +01:00
|
|
|
|
2021-05-08 15:31:01 +02:00
|
|
|
//todo read single big buffer then add +1 up to a few max bytes, or just read once only
|
2017-02-18 18:27:21 +01:00
|
|
|
/* read first frame(s) */
|
|
|
|
do {
|
2021-05-08 15:31:01 +02:00
|
|
|
size_t bytes_read, bytes_done;
|
|
|
|
|
|
|
|
/* don't check max as sfx can be smaller than buffer */
|
|
|
|
bytes_read = read_streamfile(data->buffer, start_offset + read_offset, data->buffer_size, sf);
|
|
|
|
read_offset += 1;
|
2017-02-18 18:27:21 +01:00
|
|
|
|
2021-05-08 15:31:01 +02:00
|
|
|
rc = mpg123_decode(main_m, data->buffer, bytes_read, NULL,0, &bytes_done);
|
2017-03-13 20:04:09 +01:00
|
|
|
if (rc != MPG123_OK && rc != MPG123_NEW_FORMAT && rc != MPG123_NEED_MORE) {
|
2018-09-23 03:01:13 +02:00
|
|
|
VGM_LOG("MPEG: unable to set up mpg123 at start offset\n");
|
2017-07-29 23:14:04 +02:00
|
|
|
goto fail; //handle MPG123_DONE?
|
2017-03-13 20:04:09 +01:00
|
|
|
}
|
|
|
|
if (read_offset > 0x5000) { /* don't hang in some incorrectly detected formats */
|
2018-09-23 03:01:13 +02:00
|
|
|
VGM_LOG("MPEG: unable to find mpeg data at start offset\n");
|
2017-03-13 20:04:09 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2017-02-18 18:27:21 +01:00
|
|
|
} while (rc != MPG123_NEW_FORMAT);
|
|
|
|
|
|
|
|
/* check first frame header and validate */
|
2017-02-19 20:20:13 +01:00
|
|
|
rc = mpg123_getformat(main_m,&sample_rate_per_frame,&channels_per_frame,&encoding);
|
2017-02-18 00:17:38 +01:00
|
|
|
if (rc != MPG123_OK) goto fail;
|
|
|
|
|
2017-02-19 20:20:13 +01:00
|
|
|
mpg123_info(main_m,&mi);
|
|
|
|
|
2017-02-18 18:27:21 +01:00
|
|
|
if (encoding != MPG123_ENC_SIGNED_16)
|
|
|
|
goto fail;
|
2017-02-19 20:20:13 +01:00
|
|
|
if (sample_rate_per_frame != mi.rate)
|
2017-02-18 00:17:38 +01:00
|
|
|
goto fail;
|
2017-03-13 20:04:09 +01:00
|
|
|
if ((channels != -1 && channels_per_frame != channels))
|
2017-02-18 00:17:38 +01:00
|
|
|
goto fail;
|
2010-09-10 23:49:56 +02:00
|
|
|
|
2017-07-29 13:05:23 +02:00
|
|
|
switch(mi.layer) {
|
|
|
|
case 1: *coding_type = coding_MPEG_layer1; break;
|
|
|
|
case 2: *coding_type = coding_MPEG_layer2; break;
|
|
|
|
case 3: *coding_type = coding_MPEG_layer3; break;
|
|
|
|
default: goto fail;
|
|
|
|
}
|
2011-01-19 14:54:59 +01:00
|
|
|
|
2017-02-19 20:20:13 +01:00
|
|
|
if (mi.layer == 1)
|
|
|
|
samples_per_frame = 384;
|
|
|
|
else if (mi.layer == 2)
|
|
|
|
samples_per_frame = 1152;
|
|
|
|
else if (mi.layer == 3 && mi.version == MPG123_1_0) //MP3
|
|
|
|
samples_per_frame = 1152;
|
|
|
|
else if (mi.layer == 3)
|
|
|
|
samples_per_frame = 576;
|
|
|
|
else goto fail;
|
|
|
|
|
|
|
|
data->channels_per_frame = channels_per_frame;
|
|
|
|
data->samples_per_frame = samples_per_frame;
|
2017-07-29 23:14:04 +02:00
|
|
|
if (channels_per_frame != channels)
|
|
|
|
goto fail;
|
|
|
|
|
2017-12-03 17:24:32 +01:00
|
|
|
/* copy current as open_feed may invalidate until data is fed */
|
|
|
|
memcpy(&data->mi, &mi, sizeof(struct mpg123_frameinfo));
|
2017-02-19 20:20:13 +01:00
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
/* reinit, to ignore the reading done */
|
2017-02-18 18:27:21 +01:00
|
|
|
mpg123_open_feed(main_m);
|
2010-09-10 23:49:56 +02:00
|
|
|
}
|
|
|
|
|
2017-03-13 20:04:09 +01:00
|
|
|
return data;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
free_mpeg(data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-29 23:14:04 +02:00
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
/* Init custom MPEG, with given type and config */
|
2021-05-08 15:31:01 +02:00
|
|
|
mpeg_codec_data* init_mpeg_custom(STREAMFILE* sf, off_t start_offset, coding_t* coding_type, int channels, mpeg_custom_t type, mpeg_custom_config* config) {
|
|
|
|
mpeg_codec_data* data = NULL;
|
2017-07-29 23:14:04 +02:00
|
|
|
int i, ok;
|
2017-03-13 20:04:09 +01:00
|
|
|
|
|
|
|
/* init codec */
|
2021-05-08 15:31:01 +02:00
|
|
|
data = calloc(1, sizeof(mpeg_codec_data));
|
2017-03-13 20:04:09 +01:00
|
|
|
if (!data) goto fail;
|
|
|
|
|
2017-07-29 23:14:04 +02:00
|
|
|
/* keep around to decode */
|
|
|
|
data->custom = 1;
|
|
|
|
data->type = type;
|
|
|
|
memcpy(&data->config, config, sizeof(mpeg_custom_config));
|
|
|
|
data->config.channels = channels;
|
2017-03-13 20:04:09 +01:00
|
|
|
|
2018-04-07 11:31:43 +02:00
|
|
|
data->default_buffer_size = MPEG_DATA_BUFFER_SIZE;
|
|
|
|
|
2017-07-29 23:14:04 +02:00
|
|
|
/* init per subtype */
|
|
|
|
switch(data->type) {
|
|
|
|
case MPEG_EAL31:
|
2017-12-01 17:32:12 +01:00
|
|
|
case MPEG_EAL31b:
|
2017-07-29 23:14:04 +02:00
|
|
|
case MPEG_EAL32P:
|
2021-05-08 15:31:01 +02:00
|
|
|
case MPEG_EAL32S: ok = mpeg_custom_setup_init_ealayer3(sf, start_offset, data, coding_type); break;
|
|
|
|
case MPEG_AWC: ok = mpeg_custom_setup_init_awc(sf, start_offset, data, coding_type); break;
|
|
|
|
case MPEG_EAMP3: ok = mpeg_custom_setup_init_eamp3(sf, start_offset, data, coding_type); break;
|
|
|
|
default: ok = mpeg_custom_setup_init_default(sf, start_offset, data, coding_type); break;
|
2017-07-29 23:14:04 +02:00
|
|
|
}
|
|
|
|
if (!ok)
|
|
|
|
goto fail;
|
2017-02-19 20:20:13 +01:00
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
if (channels <= 0 || channels > 16) goto fail; /* arbitrary max */
|
2017-07-29 23:14:04 +02:00
|
|
|
if (channels < data->channels_per_frame) goto fail;
|
2018-05-27 17:28:48 +02:00
|
|
|
//todo simplify/unify XVAG/P3D/SCD/LYN and just feed arbitrary chunks to the decoder
|
|
|
|
if (data->default_buffer_size > 0x10000) goto fail; /* max for some Ubi Lyn */
|
2017-02-19 20:20:13 +01:00
|
|
|
|
2010-09-10 23:49:56 +02:00
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
/* init streams */
|
|
|
|
data->streams_size = channels / data->channels_per_frame;
|
2019-02-09 23:42:59 +01:00
|
|
|
|
|
|
|
/* 2ch streams + odd channels = last stream must be 1ch */
|
|
|
|
/* (known channels combos are 2ch+..+2ch, 1ch+..+1ch, or rarely 2ch+..+2ch+1ch in EALayer3) */
|
|
|
|
if (data->channels_per_frame == 2 && channels % 2)
|
|
|
|
data->streams_size += 1;
|
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
data->streams = calloc(data->streams_size, sizeof(mpeg_custom_stream*));
|
2019-02-09 23:42:59 +01:00
|
|
|
for (i = 0; i < data->streams_size; i++) {
|
2017-08-04 21:29:58 +02:00
|
|
|
data->streams[i] = calloc(1, sizeof(mpeg_custom_stream));
|
|
|
|
data->streams[i]->m = init_mpg123_handle(); /* decoder not shared as may need several frames to decode)*/
|
|
|
|
if (!data->streams[i]->m) goto fail;
|
2010-09-10 23:49:56 +02:00
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
/* size could be any value */
|
|
|
|
data->streams[i]->output_buffer_size = sizeof(sample) * data->channels_per_frame * data->samples_per_frame;
|
|
|
|
data->streams[i]->output_buffer = calloc(data->streams[i]->output_buffer_size, sizeof(uint8_t));
|
|
|
|
if (!data->streams[i]->output_buffer) goto fail;
|
2017-12-01 20:02:30 +01:00
|
|
|
|
|
|
|
/* one per stream as sometimes mpg123 can't read the whole buffer in one pass */
|
2018-04-07 11:31:43 +02:00
|
|
|
data->streams[i]->buffer_size = data->default_buffer_size;
|
2017-12-01 20:02:30 +01:00
|
|
|
data->streams[i]->buffer = calloc(sizeof(uint8_t), data->streams[i]->buffer_size);
|
|
|
|
if (!data->streams[i]->buffer) goto fail;
|
2017-02-17 18:35:58 +01:00
|
|
|
|
2019-02-09 23:42:59 +01:00
|
|
|
data->streams[i]->channels_per_frame = data->channels_per_frame;
|
|
|
|
if (i + 1 == data->streams_size && data->channels_per_frame == 2 && channels % 2)
|
|
|
|
data->streams[i]->channels_per_frame = 1;
|
|
|
|
}
|
2017-03-13 20:04:09 +01:00
|
|
|
|
2017-02-18 18:27:21 +01:00
|
|
|
return data;
|
2017-02-17 18:35:58 +01:00
|
|
|
|
2017-02-18 18:27:21 +01:00
|
|
|
fail:
|
|
|
|
free_mpeg(data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-08 15:31:01 +02:00
|
|
|
static mpg123_handle* init_mpg123_handle() {
|
|
|
|
mpg123_handle* m = NULL;
|
2017-02-18 18:27:21 +01:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* inits a new mpg123 handle */
|
2021-05-08 15:31:01 +02:00
|
|
|
m = mpg123_new(NULL, &rc);
|
2017-02-18 18:27:21 +01:00
|
|
|
if (rc == MPG123_NOT_INITIALIZED) {
|
|
|
|
/* inits the library if needed */
|
|
|
|
if (mpg123_init() != MPG123_OK)
|
|
|
|
goto fail;
|
|
|
|
m = mpg123_new(NULL,&rc);
|
2017-02-17 18:35:58 +01:00
|
|
|
if (rc != MPG123_OK) goto fail;
|
2017-02-18 18:27:21 +01:00
|
|
|
} else if (rc != MPG123_OK) {
|
2017-02-17 18:35:58 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2017-07-29 23:14:04 +02:00
|
|
|
mpg123_param(m,MPG123_REMOVE_FLAGS,MPG123_GAPLESS,0.0); /* wonky support */
|
2019-11-04 23:31:23 +01:00
|
|
|
mpg123_param(m,MPG123_RESYNC_LIMIT, -1, 0x2000); /* just in case, games shouldn't ever need this */
|
2017-02-18 18:27:21 +01:00
|
|
|
|
|
|
|
if (mpg123_open_feed(m) != MPG123_OK) {
|
2017-02-17 18:35:58 +01:00
|
|
|
goto fail;
|
2010-09-10 23:49:56 +02:00
|
|
|
}
|
2017-02-17 18:35:58 +01:00
|
|
|
|
2017-02-18 18:27:21 +01:00
|
|
|
return m;
|
2017-02-17 18:35:58 +01:00
|
|
|
|
|
|
|
fail:
|
2017-02-18 18:27:21 +01:00
|
|
|
mpg123_delete(m);
|
2010-09-10 23:49:56 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-02-17 18:35:58 +01:00
|
|
|
|
2017-02-18 18:27:21 +01:00
|
|
|
/************/
|
|
|
|
/* DECODERS */
|
|
|
|
/************/
|
|
|
|
|
2021-05-08 15:31:01 +02:00
|
|
|
void decode_mpeg(VGMSTREAM* vgmstream, sample_t* outbuf, int32_t samples_to_do, int channels) {
|
|
|
|
mpeg_codec_data* data = vgmstream->codec_data;
|
2017-02-18 18:27:21 +01:00
|
|
|
|
2017-07-29 23:14:04 +02:00
|
|
|
if (!data->custom) {
|
|
|
|
decode_mpeg_standard(&vgmstream->ch[0], data, outbuf, samples_to_do, channels);
|
2017-02-19 20:20:13 +01:00
|
|
|
} else {
|
2017-07-29 23:14:04 +02:00
|
|
|
decode_mpeg_custom(vgmstream, data, outbuf, samples_to_do, channels);
|
2017-02-19 20:20:13 +01:00
|
|
|
}
|
2017-02-18 18:27:21 +01:00
|
|
|
}
|
|
|
|
|
2017-02-18 00:17:38 +01:00
|
|
|
/**
|
|
|
|
* Decode anything mpg123 can.
|
|
|
|
* Feeds raw data and extracts decoded samples as needed.
|
|
|
|
*/
|
2021-05-08 15:31:01 +02:00
|
|
|
static void decode_mpeg_standard(VGMSTREAMCHANNEL* stream, mpeg_codec_data* data, sample_t* outbuf, int32_t samples_to_do, int channels) {
|
2008-07-06 17:33:38 +02:00
|
|
|
int samples_done = 0;
|
2019-09-29 20:09:28 +02:00
|
|
|
unsigned char *outbytes = (unsigned char *)outbuf;
|
2008-07-06 17:33:38 +02:00
|
|
|
|
|
|
|
while (samples_done < samples_to_do) {
|
|
|
|
size_t bytes_done;
|
2019-09-29 20:09:28 +02:00
|
|
|
int rc, bytes_to_do;
|
2008-07-06 17:33:38 +02:00
|
|
|
|
2017-02-18 00:17:38 +01:00
|
|
|
/* read more raw data */
|
2008-07-06 17:33:38 +02:00
|
|
|
if (!data->buffer_full) {
|
2017-02-18 00:17:38 +01:00
|
|
|
data->bytes_in_buffer = read_streamfile(data->buffer,stream->offset,data->buffer_size,stream->streamfile);
|
2008-07-06 17:33:38 +02:00
|
|
|
|
2017-02-18 00:17:38 +01:00
|
|
|
/* end of stream, fill rest with 0s */
|
2019-09-29 20:09:28 +02:00
|
|
|
if (data->bytes_in_buffer <= 0) {
|
|
|
|
VGM_ASSERT(samples_to_do < samples_done, "MPEG: end of stream, filling %i\n", (samples_to_do - samples_done));
|
2017-11-24 23:42:11 +01:00
|
|
|
memset(outbuf + samples_done * channels, 0, (samples_to_do - samples_done) * channels * sizeof(sample));
|
2011-01-19 14:54:59 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-07-06 17:33:38 +02:00
|
|
|
data->buffer_full = 1;
|
|
|
|
data->buffer_used = 0;
|
|
|
|
|
|
|
|
stream->offset += data->bytes_in_buffer;
|
|
|
|
}
|
|
|
|
|
2019-09-29 20:09:28 +02:00
|
|
|
bytes_to_do = (samples_to_do-samples_done)*sizeof(sample)*channels;
|
|
|
|
|
2017-02-19 20:20:13 +01:00
|
|
|
/* feed new raw data to the decoder if needed, copy decoded results to output */
|
2008-07-06 17:33:38 +02:00
|
|
|
if (!data->buffer_used) {
|
2019-09-29 20:09:28 +02:00
|
|
|
rc = mpg123_decode(data->m, data->buffer,data->bytes_in_buffer, outbytes, bytes_to_do, &bytes_done);
|
2008-07-06 17:33:38 +02:00
|
|
|
data->buffer_used = 1;
|
2017-07-29 23:14:04 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-09-29 20:09:28 +02:00
|
|
|
rc = mpg123_decode(data->m, NULL,0, outbytes, bytes_to_do, &bytes_done);
|
2008-07-06 17:33:38 +02:00
|
|
|
}
|
|
|
|
|
2017-02-18 00:17:38 +01:00
|
|
|
/* not enough raw data, request more */
|
|
|
|
if (rc == MPG123_NEED_MORE) {
|
|
|
|
data->buffer_full = 0;
|
|
|
|
}
|
2019-09-29 20:09:28 +02:00
|
|
|
VGM_ASSERT(rc != MPG123_NEED_MORE && rc != MPG123_OK, "MPEG: error %i\n", rc);
|
2008-07-06 17:33:38 +02:00
|
|
|
|
2017-02-18 00:17:38 +01:00
|
|
|
/* update copied samples */
|
2008-07-06 17:33:38 +02:00
|
|
|
samples_done += bytes_done/sizeof(sample)/channels;
|
2019-09-29 20:09:28 +02:00
|
|
|
outbytes += bytes_done;
|
2008-07-06 17:33:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-19 20:20:13 +01:00
|
|
|
|
2017-02-18 00:17:38 +01:00
|
|
|
/**
|
2017-08-04 21:29:58 +02:00
|
|
|
* Decode custom MPEG, for: single frames, mutant frames, interleave/multiple streams (Nch = 2ch*N/2 or 1ch*N), etc.
|
2017-02-19 20:20:13 +01:00
|
|
|
*
|
2017-08-04 21:29:58 +02:00
|
|
|
* Copies to outbuf when there are samples in all streams and calls decode_mpeg_custom_stream to decode.
|
|
|
|
. Depletes the stream's sample buffers before decoding more, so it doesn't run out of buffer space.
|
2017-02-19 20:20:13 +01:00
|
|
|
*/
|
2021-05-08 15:31:01 +02:00
|
|
|
static void decode_mpeg_custom(VGMSTREAM* vgmstream, mpeg_codec_data* data, sample_t* outbuf, int32_t samples_to_do, int channels) {
|
2017-08-04 21:29:58 +02:00
|
|
|
int i, samples_done = 0;
|
|
|
|
|
2017-02-19 20:20:13 +01:00
|
|
|
while (samples_done < samples_to_do) {
|
2017-08-04 21:29:58 +02:00
|
|
|
int samples_to_copy = -1;
|
2017-02-19 20:20:13 +01:00
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
/* find max to copy from all streams (equal for all channels) */
|
|
|
|
for (i = 0; i < data->streams_size; i++) {
|
|
|
|
size_t samples_in_stream = data->streams[i]->samples_filled - data->streams[i]->samples_used;
|
|
|
|
if (samples_to_copy < 0 || samples_in_stream < samples_to_copy)
|
|
|
|
samples_to_copy = samples_in_stream;
|
2017-02-19 20:20:13 +01:00
|
|
|
}
|
|
|
|
|
2017-07-29 23:14:04 +02:00
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
/* discard if needed (for looping) */
|
|
|
|
if (data->samples_to_discard) {
|
|
|
|
int samples_to_discard = samples_to_copy;
|
|
|
|
if (samples_to_discard > data->samples_to_discard)
|
|
|
|
samples_to_discard = data->samples_to_discard;
|
2017-07-29 23:14:04 +02:00
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
for (i = 0; i < data->streams_size; i++) {
|
|
|
|
data->streams[i]->samples_used += samples_to_discard;
|
|
|
|
}
|
|
|
|
data->samples_to_discard -= samples_to_discard;
|
|
|
|
samples_to_copy -= samples_to_discard;
|
|
|
|
}
|
|
|
|
|
2019-02-09 23:42:59 +01:00
|
|
|
/* mux streams channels (1/2ch combos) to outbuf (Nch) */
|
2017-08-04 21:29:58 +02:00
|
|
|
if (samples_to_copy > 0) {
|
2019-02-09 23:42:59 +01:00
|
|
|
int ch, stream;
|
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
if (samples_to_copy > samples_to_do - samples_done)
|
|
|
|
samples_to_copy = samples_to_do - samples_done;
|
|
|
|
|
2019-02-09 23:42:59 +01:00
|
|
|
ch = 0;
|
|
|
|
for (stream = 0; stream < data->streams_size; stream++) {
|
|
|
|
mpeg_custom_stream *ms = data->streams[stream];
|
2019-03-02 19:23:37 +01:00
|
|
|
sample_t *inbuf = (sample_t *)ms->output_buffer;
|
2019-02-09 23:42:59 +01:00
|
|
|
int stream_channels = ms->channels_per_frame;
|
|
|
|
int stream_ch, s;
|
2017-08-04 21:29:58 +02:00
|
|
|
|
2019-02-09 23:42:59 +01:00
|
|
|
for (stream_ch = 0; stream_ch < stream_channels; stream_ch++) {
|
2017-08-04 21:29:58 +02:00
|
|
|
for (s = 0; s < samples_to_copy; s++) {
|
2019-02-09 23:42:59 +01:00
|
|
|
size_t stream_sample = (ms->samples_used+s)*stream_channels + stream_ch;
|
|
|
|
size_t buffer_sample = (samples_done+s)*channels + ch;
|
2017-08-04 21:29:58 +02:00
|
|
|
|
2019-02-09 23:42:59 +01:00
|
|
|
outbuf[buffer_sample] = inbuf[stream_sample];
|
2017-08-04 21:29:58 +02:00
|
|
|
}
|
2019-02-09 23:42:59 +01:00
|
|
|
ch++;
|
2017-07-29 23:14:04 +02:00
|
|
|
}
|
2017-08-04 21:29:58 +02:00
|
|
|
|
|
|
|
ms->samples_used += samples_to_copy;
|
2017-02-19 20:20:13 +01:00
|
|
|
}
|
2017-03-13 20:04:09 +01:00
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
samples_done += samples_to_copy;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* decode more into stream sample buffers */
|
2017-03-13 20:04:09 +01:00
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
/* Handle offsets depending on the data layout (may only use half VGMSTREAMCHANNELs with 2ch streams)
|
|
|
|
* With multiple offsets they should already start in the first frame of each stream. */
|
|
|
|
for (i=0; i < data->streams_size; i++) {
|
|
|
|
switch(data->type) {
|
|
|
|
//case MPEG_FSB:
|
|
|
|
/* same offset: alternate frames between streams (maybe needed for weird layouts?) */
|
|
|
|
//decode_mpeg_custom_stream(&vgmstream->ch[0], data, i);
|
2017-03-13 20:04:09 +01:00
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
default:
|
|
|
|
/* offset per stream: absolute offsets, fixed interleave (skips other streams/interleave) */
|
|
|
|
decode_mpeg_custom_stream(&vgmstream->ch[i], data, i);
|
|
|
|
break;
|
|
|
|
}
|
2017-03-13 20:04:09 +01:00
|
|
|
}
|
2017-02-19 20:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
/* Decodes frames from a stream into the stream's sample buffer, feeding mpg123 buffer data.
|
|
|
|
* If not enough data to decode (as N data-frames = 1 full-frame) this will exit but be called again. */
|
2021-05-08 15:31:01 +02:00
|
|
|
static void decode_mpeg_custom_stream(VGMSTREAMCHANNEL* stream, mpeg_codec_data* data, int num_stream) {
|
2017-08-05 17:54:50 +02:00
|
|
|
size_t bytes_done = 0, bytes_filled, samples_filled;
|
2017-07-29 23:14:04 +02:00
|
|
|
size_t stream_size = get_streamfile_size(stream->streamfile);
|
|
|
|
int rc, ok;
|
2017-08-04 21:29:58 +02:00
|
|
|
mpeg_custom_stream *ms = data->streams[num_stream];
|
2019-02-09 23:42:59 +01:00
|
|
|
int channels_per_frame = ms->channels_per_frame;
|
2017-02-19 20:20:13 +01:00
|
|
|
|
2017-12-01 20:02:30 +01:00
|
|
|
//;VGM_LOG("MPEG: decode stream%i @ 0x%08lx (filled=%i, used=%i, buffer_full=%i)\n", num_stream, stream->offset, ms->samples_filled, ms->samples_used, ms->buffer_full);
|
2017-04-13 15:04:46 +02:00
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
/* wait until samples are depleted, so buffers don't grow too big */
|
|
|
|
if (ms->samples_filled - ms->samples_used > 0) {
|
|
|
|
return; /* common with multi-streams, as they decode at different rates) */
|
|
|
|
}
|
2017-03-13 20:04:09 +01:00
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
/* no samples = reset the counters */
|
|
|
|
ms->samples_filled = 0;
|
|
|
|
ms->samples_used = 0;
|
2017-02-19 20:20:13 +01:00
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
/* extra EOF check for edge cases when the caller tries to read more samples than possible */
|
2017-12-01 20:02:30 +01:00
|
|
|
if (!ms->buffer_full && stream->offset >= stream_size) {
|
2017-12-17 16:39:36 +01:00
|
|
|
VGM_LOG("MPEG: EOF found but more data is requested in stream %i\n", num_stream);
|
2017-08-04 21:29:58 +02:00
|
|
|
goto decode_fail;
|
|
|
|
}
|
2017-02-19 20:20:13 +01:00
|
|
|
|
2017-04-13 15:04:46 +02:00
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
/* read more raw data (could fill the sample buffer too in some cases, namely EALayer3) */
|
2017-12-01 20:02:30 +01:00
|
|
|
if (!ms->buffer_full) {
|
2017-08-05 17:54:50 +02:00
|
|
|
//;VGM_LOG("MPEG: reading more raw data\n");
|
2017-08-04 21:29:58 +02:00
|
|
|
switch(data->type) {
|
|
|
|
case MPEG_EAL31:
|
2017-12-01 17:32:12 +01:00
|
|
|
case MPEG_EAL31b:
|
2017-08-04 21:29:58 +02:00
|
|
|
case MPEG_EAL32P:
|
2017-08-05 17:54:50 +02:00
|
|
|
case MPEG_EAL32S: ok = mpeg_custom_parse_frame_ealayer3(stream, data, num_stream); break;
|
2017-12-01 20:02:30 +01:00
|
|
|
case MPEG_AHX: ok = mpeg_custom_parse_frame_ahx(stream, data, num_stream); break;
|
2017-08-28 15:14:24 +02:00
|
|
|
case MPEG_AWC: ok = mpeg_custom_parse_frame_awc(stream, data, num_stream); break;
|
2018-12-15 11:17:47 +01:00
|
|
|
case MPEG_EAMP3: ok = mpeg_custom_parse_frame_eamp3(stream, data, num_stream); break;
|
2017-12-01 20:02:30 +01:00
|
|
|
default: ok = mpeg_custom_parse_frame_default(stream, data, num_stream); break;
|
2017-07-29 23:14:04 +02:00
|
|
|
}
|
2017-08-04 21:29:58 +02:00
|
|
|
if (!ok) {
|
2018-12-01 18:52:30 +01:00
|
|
|
VGM_LOG("MPEG: cannot parse frame @ around %x\n",(uint32_t)stream->offset);
|
2017-08-04 21:29:58 +02:00
|
|
|
goto decode_fail; /* mpg123 could resync but custom MPEGs wouldn't need that */
|
2017-02-19 20:20:13 +01:00
|
|
|
}
|
2017-12-01 20:02:30 +01:00
|
|
|
//;VGM_LOG("MPEG: read results: bytes_in_buffer=0x%x, new offset=%lx\n", ms->bytes_in_buffer, stream->offset);
|
2017-08-04 21:29:58 +02:00
|
|
|
|
2017-08-05 17:54:50 +02:00
|
|
|
/* parse frame may not touch the buffer (only move offset, or fill the sample buffer) */
|
2017-12-01 20:02:30 +01:00
|
|
|
if (ms->bytes_in_buffer) {
|
|
|
|
ms->buffer_full = 1;
|
|
|
|
ms->buffer_used = 0;
|
2017-08-05 17:54:50 +02:00
|
|
|
}
|
2017-08-04 21:29:58 +02:00
|
|
|
}
|
|
|
|
|
2017-06-25 02:09:12 +02:00
|
|
|
|
2019-02-09 23:42:59 +01:00
|
|
|
bytes_filled = sizeof(sample) * ms->samples_filled * channels_per_frame;
|
2017-08-04 21:29:58 +02:00
|
|
|
/* feed new raw data to the decoder if needed, copy decoded results to frame buffer output */
|
2017-12-01 20:02:30 +01:00
|
|
|
if (!ms->buffer_used) {
|
2017-12-01 17:32:12 +01:00
|
|
|
//;VGM_LOG("MPEG: feed new data and get samples\n");
|
2017-08-04 21:29:58 +02:00
|
|
|
rc = mpg123_decode(ms->m,
|
2017-12-01 20:02:30 +01:00
|
|
|
ms->buffer, ms->bytes_in_buffer,
|
2017-08-04 21:29:58 +02:00
|
|
|
(unsigned char*)ms->output_buffer + bytes_filled, ms->output_buffer_size - bytes_filled,
|
|
|
|
&bytes_done);
|
2017-12-01 20:02:30 +01:00
|
|
|
ms->buffer_used = 1;
|
2017-08-04 21:29:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-08-05 17:54:50 +02:00
|
|
|
//;VGM_LOG("MPEG: get samples from old data\n");
|
2017-08-04 21:29:58 +02:00
|
|
|
rc = mpg123_decode(ms->m,
|
|
|
|
NULL, 0,
|
|
|
|
(unsigned char*)ms->output_buffer + bytes_filled, ms->output_buffer_size - bytes_filled,
|
|
|
|
&bytes_done);
|
|
|
|
}
|
2019-02-09 23:42:59 +01:00
|
|
|
samples_filled = (bytes_done / sizeof(sample) / channels_per_frame);
|
2017-08-05 17:54:50 +02:00
|
|
|
|
2017-08-28 15:14:24 +02:00
|
|
|
/* discard for weird features (EALayer3 and PCM blocks, AWC and repeated frames) */
|
|
|
|
if (ms->decode_to_discard) {
|
2017-08-05 17:54:50 +02:00
|
|
|
size_t bytes_to_discard = 0;
|
2017-08-28 15:14:24 +02:00
|
|
|
size_t decode_to_discard = ms->decode_to_discard;
|
2017-08-05 17:54:50 +02:00
|
|
|
if (decode_to_discard > samples_filled)
|
|
|
|
decode_to_discard = samples_filled;
|
2019-02-09 23:42:59 +01:00
|
|
|
bytes_to_discard = sizeof(sample) * decode_to_discard * channels_per_frame;
|
2017-08-05 17:54:50 +02:00
|
|
|
|
|
|
|
bytes_done -= bytes_to_discard;
|
2017-08-28 15:14:24 +02:00
|
|
|
ms->decode_to_discard -= decode_to_discard;
|
2017-08-05 17:54:50 +02:00
|
|
|
ms->samples_used += decode_to_discard;
|
|
|
|
}
|
2017-02-19 20:20:13 +01:00
|
|
|
|
2017-08-04 21:29:58 +02:00
|
|
|
/* if no decoding was done bytes_done will be zero */
|
2017-08-05 17:54:50 +02:00
|
|
|
ms->samples_filled += samples_filled;
|
2017-02-19 20:20:13 +01:00
|
|
|
|
2017-08-05 17:54:50 +02:00
|
|
|
/* not enough raw data, set flag to request more next time
|
|
|
|
* (but only with empty mpg123 buffer, EA blocks wait for all samples decoded before advancing blocks) */
|
|
|
|
if (!bytes_done && rc == MPG123_NEED_MORE) {
|
2017-12-01 17:32:12 +01:00
|
|
|
//;VGM_LOG("MPEG: need more raw data to get samples (bytes_done=%x)\n", bytes_done);
|
2017-12-01 20:02:30 +01:00
|
|
|
ms->buffer_full = 0;
|
2017-07-01 23:55:10 +02:00
|
|
|
}
|
2017-08-04 21:29:58 +02:00
|
|
|
|
2017-08-05 17:54:50 +02:00
|
|
|
|
2017-12-01 17:32:12 +01:00
|
|
|
//;VGM_LOG("MPEG: stream samples now=%i, filled=%i)\n\n", ms->samples_filled, samples_filled);
|
2017-08-04 21:29:58 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
decode_fail:
|
|
|
|
/* 0-fill but continue with other streams */
|
2019-02-09 23:42:59 +01:00
|
|
|
bytes_filled = ms->samples_filled * channels_per_frame * sizeof(sample);
|
2017-08-04 21:29:58 +02:00
|
|
|
memset(ms->output_buffer + bytes_filled, 0, ms->output_buffer_size - bytes_filled);
|
2019-02-09 23:42:59 +01:00
|
|
|
ms->samples_filled = (ms->output_buffer_size / channels_per_frame / sizeof(sample));
|
2017-02-19 20:20:13 +01:00
|
|
|
}
|
|
|
|
|
2017-02-17 18:35:58 +01:00
|
|
|
|
2017-02-18 18:27:21 +01:00
|
|
|
/*********/
|
|
|
|
/* UTILS */
|
|
|
|
/*********/
|
2017-02-17 17:20:40 +01:00
|
|
|
|
2021-05-08 15:31:01 +02:00
|
|
|
void free_mpeg(mpeg_codec_data* data) {
|
2017-02-17 17:20:40 +01:00
|
|
|
if (!data)
|
|
|
|
return;
|
|
|
|
|
2017-07-29 23:14:04 +02:00
|
|
|
if (!data->custom) {
|
|
|
|
mpg123_delete(data->m);
|
|
|
|
}
|
|
|
|
else {
|
2017-02-19 20:20:13 +01:00
|
|
|
int i;
|
2017-08-04 21:29:58 +02:00
|
|
|
for (i=0; i < data->streams_size; i++) {
|
|
|
|
mpg123_delete(data->streams[i]->m);
|
2017-12-01 20:02:30 +01:00
|
|
|
free(data->streams[i]->buffer);
|
2017-08-04 21:29:58 +02:00
|
|
|
free(data->streams[i]->output_buffer);
|
|
|
|
free(data->streams[i]);
|
2017-02-19 20:20:13 +01:00
|
|
|
}
|
2017-08-04 21:29:58 +02:00
|
|
|
free(data->streams);
|
2017-02-19 20:20:13 +01:00
|
|
|
}
|
|
|
|
|
2017-02-18 00:17:38 +01:00
|
|
|
free(data->buffer);
|
2017-02-17 17:20:40 +01:00
|
|
|
free(data);
|
|
|
|
|
|
|
|
/* The astute reader will note that a call to mpg123_exit is never
|
|
|
|
* made. While is is evilly breaking our contract with mpg123, it
|
|
|
|
* doesn't actually do anything except set the "initialized" flag
|
|
|
|
* to 0. And if we exit we run the risk of turning it off when
|
|
|
|
* someone else in another thread is using it. */
|
|
|
|
}
|
|
|
|
|
2018-12-28 11:04:18 +01:00
|
|
|
/* seeks stream to 0 */
|
2020-07-17 22:35:32 +02:00
|
|
|
void reset_mpeg(mpeg_codec_data* data) {
|
2018-03-10 16:59:00 +01:00
|
|
|
if (!data) return;
|
2017-02-17 17:20:40 +01:00
|
|
|
|
2019-02-16 01:23:43 +01:00
|
|
|
flush_mpeg(data);
|
2017-07-29 23:14:04 +02:00
|
|
|
|
2019-02-16 01:23:43 +01:00
|
|
|
#if 0
|
|
|
|
/* flush_mpeg properly resets mpg123 with mpg123_open_feed, and
|
|
|
|
* offsets are reset in the VGMSTREAM externally, but for posterity: */
|
2017-07-29 23:14:04 +02:00
|
|
|
if (!data->custom) {
|
2019-02-16 01:23:43 +01:00
|
|
|
off_t input_offset = 0;
|
2017-07-29 23:14:04 +02:00
|
|
|
mpg123_feedseek(data->m,0,SEEK_SET,&input_offset);
|
|
|
|
}
|
|
|
|
else {
|
2019-02-16 01:23:43 +01:00
|
|
|
off_t input_offset = 0;
|
2017-02-19 20:20:13 +01:00
|
|
|
int i;
|
2018-12-28 11:04:18 +01:00
|
|
|
for (i = 0; i < data->streams_size; i++) {
|
2017-08-04 21:29:58 +02:00
|
|
|
mpg123_feedseek(data->streams[i]->m,0,SEEK_SET,&input_offset);
|
2017-02-19 20:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-16 01:23:43 +01:00
|
|
|
#endif
|
2017-02-17 17:20:40 +01:00
|
|
|
}
|
|
|
|
|
2018-12-28 11:04:18 +01:00
|
|
|
/* seeks to a point */
|
2021-05-08 15:31:01 +02:00
|
|
|
void seek_mpeg(VGMSTREAM* vgmstream, int32_t num_sample) {
|
|
|
|
mpeg_codec_data* data = vgmstream->codec_data;
|
2018-03-10 16:59:00 +01:00
|
|
|
if (!data) return;
|
2017-02-17 17:20:40 +01:00
|
|
|
|
2018-12-28 11:04:18 +01:00
|
|
|
|
2017-07-29 23:14:04 +02:00
|
|
|
if (!data->custom) {
|
2019-02-16 01:23:43 +01:00
|
|
|
off_t input_offset = 0;
|
2019-04-09 20:40:48 +02:00
|
|
|
|
2017-07-29 23:14:04 +02:00
|
|
|
mpg123_feedseek(data->m, num_sample,SEEK_SET,&input_offset);
|
2017-12-01 20:02:30 +01:00
|
|
|
|
2018-12-28 11:04:18 +01:00
|
|
|
/* adjust loop with mpg123's offset (useful?) */
|
2017-07-29 23:14:04 +02:00
|
|
|
if (vgmstream->loop_ch)
|
|
|
|
vgmstream->loop_ch[0].offset = vgmstream->loop_ch[0].channel_start_offset + input_offset;
|
|
|
|
}
|
|
|
|
else {
|
2017-02-19 20:20:13 +01:00
|
|
|
int i;
|
2019-04-09 20:40:48 +02:00
|
|
|
|
|
|
|
flush_mpeg(data);
|
|
|
|
|
2019-02-16 01:23:43 +01:00
|
|
|
/* restart from 0 and manually discard samples, since we don't really know the correct offset */
|
2018-12-28 11:04:18 +01:00
|
|
|
for (i = 0; i < data->streams_size; i++) {
|
2019-02-16 01:23:43 +01:00
|
|
|
//mpg123_feedseek(data->streams[i]->m,0,SEEK_SET,&input_offset); /* already reset */
|
2017-08-04 21:29:58 +02:00
|
|
|
|
2017-12-01 20:02:30 +01:00
|
|
|
/* force first offset as discard-looping needs to start from the beginning */
|
2017-04-14 01:22:53 +02:00
|
|
|
if (vgmstream->loop_ch)
|
|
|
|
vgmstream->loop_ch[i].offset = vgmstream->loop_ch[i].channel_start_offset;
|
2017-02-19 20:20:13 +01:00
|
|
|
}
|
|
|
|
|
2019-02-16 01:23:43 +01:00
|
|
|
data->samples_to_discard += num_sample;
|
2017-02-19 20:20:13 +01:00
|
|
|
}
|
2017-02-17 17:20:40 +01:00
|
|
|
}
|
|
|
|
|
2018-12-28 11:04:18 +01:00
|
|
|
/* resets mpg123 decoder and its internals without seeking, useful when a new MPEG substream starts */
|
2021-05-08 15:31:01 +02:00
|
|
|
void flush_mpeg(mpeg_codec_data* data) {
|
2017-08-05 17:54:50 +02:00
|
|
|
if (!data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!data->custom) {
|
|
|
|
/* input_offset is ignored as we can assume it will be 0 for a seek to sample 0 */
|
2018-12-28 11:04:18 +01:00
|
|
|
mpg123_open_feed(data->m); /* mpg123_feedseek won't work */
|
2017-08-05 17:54:50 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
int i;
|
|
|
|
/* re-start from 0 */
|
|
|
|
for (i=0; i < data->streams_size; i++) {
|
|
|
|
mpg123_open_feed(data->streams[i]->m);
|
2017-12-01 20:02:30 +01:00
|
|
|
data->streams[i]->bytes_in_buffer = 0;
|
|
|
|
data->streams[i]->buffer_full = 0;
|
|
|
|
data->streams[i]->buffer_used = 0;
|
2018-12-28 11:04:18 +01:00
|
|
|
data->streams[i]->samples_filled = 0;
|
|
|
|
data->streams[i]->samples_used = 0;
|
|
|
|
data->streams[i]->current_size_count = 0;
|
|
|
|
data->streams[i]->current_size_target = 0;
|
|
|
|
data->streams[i]->decode_to_discard = 0;
|
2017-08-05 17:54:50 +02:00
|
|
|
}
|
|
|
|
|
2018-12-28 11:04:18 +01:00
|
|
|
data->samples_to_discard = data->skip_samples;
|
2017-08-05 17:54:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
data->bytes_in_buffer = 0;
|
|
|
|
data->buffer_full = 0;
|
|
|
|
data->buffer_used = 0;
|
|
|
|
}
|
2017-02-17 17:20:40 +01:00
|
|
|
|
2020-07-17 19:42:05 +02:00
|
|
|
int mpeg_get_sample_rate(mpeg_codec_data* data) {
|
|
|
|
return data->sample_rate_per_frame;
|
|
|
|
}
|
|
|
|
|
2021-05-08 15:31:01 +02:00
|
|
|
long mpeg_bytes_to_samples(long bytes, const mpeg_codec_data* data) {
|
2017-07-29 23:14:04 +02:00
|
|
|
/* if not found just return 0 and expect to fail (if used for num_samples) */
|
|
|
|
if (!data->custom) {
|
|
|
|
/* We would need to read all VBR frames headers to count samples */
|
2017-12-03 17:24:32 +01:00
|
|
|
if (data->mi.vbr != MPG123_CBR) { //maybe abr_rate could be used to get an approx
|
|
|
|
VGM_LOG("MPEG: vbr mp3 can't do bytes_to_samples\n");
|
2017-07-29 23:14:04 +02:00
|
|
|
return 0;
|
2017-12-03 17:24:32 +01:00
|
|
|
}
|
2017-02-18 00:17:38 +01:00
|
|
|
|
2017-12-03 17:24:32 +01:00
|
|
|
return (int64_t)bytes * data->mi.rate * 8 / (data->mi.bitrate * 1000);
|
2017-07-29 23:14:04 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-12-17 16:39:36 +01:00
|
|
|
/* needed for SCD */
|
|
|
|
if (data->streams_size && data->bitrate_per_frame) {
|
|
|
|
return (int64_t)(bytes / data->streams_size) * data->sample_rate_per_frame * 8 / (data->bitrate_per_frame * 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2017-07-29 23:14:04 +02:00
|
|
|
}
|
2010-09-11 01:56:39 +02:00
|
|
|
}
|
|
|
|
|
2017-12-03 17:24:32 +01:00
|
|
|
#if 0
|
2017-08-04 21:29:58 +02:00
|
|
|
/* disables/enables stderr output, for MPEG known to contain recoverable errors */
|
2021-05-08 15:31:01 +02:00
|
|
|
void mpeg_set_error_logging(mpeg_codec_data* data, int enable) {
|
2017-07-29 23:14:04 +02:00
|
|
|
if (!data->custom) {
|
|
|
|
mpg123_param(data->m, MPG123_ADD_FLAGS, MPG123_QUIET, !enable);
|
|
|
|
}
|
|
|
|
else {
|
2017-02-19 20:20:13 +01:00
|
|
|
int i;
|
2017-08-04 21:29:58 +02:00
|
|
|
for (i=0; i < data->streams_size; i++) {
|
|
|
|
mpg123_param(data->streams[i]->m, MPG123_ADD_FLAGS, MPG123_QUIET, !enable);
|
2017-02-19 20:20:13 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-28 01:38:56 +01:00
|
|
|
}
|
2017-12-03 17:24:32 +01:00
|
|
|
#endif
|
2008-07-05 13:49:29 +02:00
|
|
|
#endif
|