flac: no CamelCase
Renamed types, functions, variables.
This commit is contained in:
		| @@ -26,20 +26,22 @@ | |||||||
| #include <FLAC/format.h> | #include <FLAC/format.h> | ||||||
| #include <FLAC/metadata.h> | #include <FLAC/metadata.h> | ||||||
|  |  | ||||||
| void init_FlacData(FlacData * data, struct decoder * decoder, | void | ||||||
| 		   struct input_stream *inStream) | flac_data_init(struct flac_data *data, struct decoder * decoder, | ||||||
|  | 	       struct input_stream *input_stream) | ||||||
| { | { | ||||||
| 	data->time = 0; | 	data->time = 0; | ||||||
| 	data->position = 0; | 	data->position = 0; | ||||||
| 	data->bitRate = 0; | 	data->bit_rate = 0; | ||||||
| 	data->decoder = decoder; | 	data->decoder = decoder; | ||||||
| 	data->inStream = inStream; | 	data->input_stream = input_stream; | ||||||
| 	data->replayGainInfo = NULL; | 	data->replay_gain_info = NULL; | ||||||
| 	data->tag = NULL; | 	data->tag = NULL; | ||||||
| } | } | ||||||
|  |  | ||||||
| static int flacFindVorbisCommentFloat(const FLAC__StreamMetadata * block, | static int | ||||||
| 				      const char *cmnt, float *fl) | flac_find_float_comment(const FLAC__StreamMetadata *block, | ||||||
|  | 			const char *cmnt, float *fl) | ||||||
| { | { | ||||||
| 	int offset = | 	int offset = | ||||||
| 	    FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, cmnt); | 	    FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0, cmnt); | ||||||
| @@ -65,28 +67,29 @@ static int flacFindVorbisCommentFloat(const FLAC__StreamMetadata * block, | |||||||
| } | } | ||||||
|  |  | ||||||
| /* replaygain stuff by AliasMrJones */ | /* replaygain stuff by AliasMrJones */ | ||||||
| static void flacParseReplayGain(const FLAC__StreamMetadata * block, | static void | ||||||
| 				FlacData * data) | flac_parse_replay_gain(const FLAC__StreamMetadata *block, | ||||||
|  | 		       struct flac_data *data) | ||||||
| { | { | ||||||
| 	int found = 0; | 	int found = 0; | ||||||
|  |  | ||||||
| 	if (data->replayGainInfo) | 	if (data->replay_gain_info) | ||||||
| 		replay_gain_info_free(data->replayGainInfo); | 		replay_gain_info_free(data->replay_gain_info); | ||||||
|  |  | ||||||
| 	data->replayGainInfo = replay_gain_info_new(); | 	data->replay_gain_info = replay_gain_info_new(); | ||||||
|  |  | ||||||
| 	found |= flacFindVorbisCommentFloat(block, "replaygain_album_gain", | 	found |= flac_find_float_comment(block, "replaygain_album_gain", | ||||||
| 					    &data->replayGainInfo->tuples[REPLAY_GAIN_ALBUM].gain); | 					 &data->replay_gain_info->tuples[REPLAY_GAIN_ALBUM].gain); | ||||||
| 	found |= flacFindVorbisCommentFloat(block, "replaygain_album_peak", | 	found |= flac_find_float_comment(block, "replaygain_album_peak", | ||||||
| 					    &data->replayGainInfo->tuples[REPLAY_GAIN_ALBUM].peak); | 					 &data->replay_gain_info->tuples[REPLAY_GAIN_ALBUM].peak); | ||||||
| 	found |= flacFindVorbisCommentFloat(block, "replaygain_track_gain", | 	found |= flac_find_float_comment(block, "replaygain_track_gain", | ||||||
| 					    &data->replayGainInfo->tuples[REPLAY_GAIN_TRACK].gain); | 					 &data->replay_gain_info->tuples[REPLAY_GAIN_TRACK].gain); | ||||||
| 	found |= flacFindVorbisCommentFloat(block, "replaygain_track_peak", | 	found |= flac_find_float_comment(block, "replaygain_track_peak", | ||||||
| 					    &data->replayGainInfo->tuples[REPLAY_GAIN_TRACK].peak); | 					 &data->replay_gain_info->tuples[REPLAY_GAIN_TRACK].peak); | ||||||
|  |  | ||||||
| 	if (!found) { | 	if (!found) { | ||||||
| 		replay_gain_info_free(data->replayGainInfo); | 		replay_gain_info_free(data->replay_gain_info); | ||||||
| 		data->replayGainInfo = NULL; | 		data->replay_gain_info = NULL; | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -95,16 +98,17 @@ static void flacParseReplayGain(const FLAC__StreamMetadata * block, | |||||||
| static const char *VORBIS_COMMENT_TRACK_KEY = "tracknumber"; | static const char *VORBIS_COMMENT_TRACK_KEY = "tracknumber"; | ||||||
| static const char *VORBIS_COMMENT_DISC_KEY = "discnumber"; | static const char *VORBIS_COMMENT_DISC_KEY = "discnumber"; | ||||||
|  |  | ||||||
| static unsigned int commentMatchesAddToTag(const | static unsigned int | ||||||
| 					   FLAC__StreamMetadata_VorbisComment_Entry | flac_copy_vorbis_comment(const | ||||||
| 					   * entry, unsigned int itemType, | 			 FLAC__StreamMetadata_VorbisComment_Entry * entry, | ||||||
| 					   struct tag ** tag) | 			 enum tag_type type, | ||||||
|  | 			 struct tag ** tag) | ||||||
| { | { | ||||||
| 	const char *str; | 	const char *str; | ||||||
| 	size_t slen; | 	size_t slen; | ||||||
| 	int vlen; | 	int vlen; | ||||||
|  |  | ||||||
| 	switch (itemType) { | 	switch (type) { | ||||||
| 	case TAG_ITEM_TRACK: | 	case TAG_ITEM_TRACK: | ||||||
| 		str = VORBIS_COMMENT_TRACK_KEY; | 		str = VORBIS_COMMENT_TRACK_KEY; | ||||||
| 		break; | 		break; | ||||||
| @@ -112,7 +116,7 @@ static unsigned int commentMatchesAddToTag(const | |||||||
| 		str = VORBIS_COMMENT_DISC_KEY; | 		str = VORBIS_COMMENT_DISC_KEY; | ||||||
| 		break; | 		break; | ||||||
| 	default: | 	default: | ||||||
| 		str = mpdTagItemKeys[itemType]; | 		str = mpdTagItemKeys[type]; | ||||||
| 	} | 	} | ||||||
| 	slen = strlen(str); | 	slen = strlen(str); | ||||||
| 	vlen = entry->length - slen - 1; | 	vlen = entry->length - slen - 1; | ||||||
| @@ -122,7 +126,7 @@ static unsigned int commentMatchesAddToTag(const | |||||||
| 		if (!*tag) | 		if (!*tag) | ||||||
| 			*tag = tag_new(); | 			*tag = tag_new(); | ||||||
|  |  | ||||||
| 		tag_add_item_n(*tag, itemType, | 		tag_add_item_n(*tag, type, | ||||||
| 			       (char *)(entry->entry + slen + 1), vlen); | 			       (char *)(entry->entry + slen + 1), vlen); | ||||||
|  |  | ||||||
| 		return 1; | 		return 1; | ||||||
| @@ -131,8 +135,9 @@ static unsigned int commentMatchesAddToTag(const | |||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| struct tag *copyVorbisCommentBlockToMpdTag(const FLAC__StreamMetadata * block, | struct tag * | ||||||
| 					   struct tag * tag) | flac_vorbis_comments_to_tag(const FLAC__StreamMetadata * block, | ||||||
|  | 			    struct tag * tag) | ||||||
| { | { | ||||||
| 	unsigned int i, j; | 	unsigned int i, j; | ||||||
| 	FLAC__StreamMetadata_VorbisComment_Entry *comments; | 	FLAC__StreamMetadata_VorbisComment_Entry *comments; | ||||||
| @@ -141,7 +146,7 @@ struct tag *copyVorbisCommentBlockToMpdTag(const FLAC__StreamMetadata * block, | |||||||
|  |  | ||||||
| 	for (i = block->data.vorbis_comment.num_comments; i != 0; --i) { | 	for (i = block->data.vorbis_comment.num_comments; i != 0; --i) { | ||||||
| 		for (j = TAG_NUM_OF_ITEM_TYPES; j--;) { | 		for (j = TAG_NUM_OF_ITEM_TYPES; j--;) { | ||||||
| 			if (commentMatchesAddToTag(comments, j, &tag)) | 			if (flac_copy_vorbis_comment(comments, j, &tag)) | ||||||
| 				break; | 				break; | ||||||
| 		} | 		} | ||||||
| 		comments++; | 		comments++; | ||||||
| @@ -151,7 +156,7 @@ struct tag *copyVorbisCommentBlockToMpdTag(const FLAC__StreamMetadata * block, | |||||||
| } | } | ||||||
|  |  | ||||||
| void flac_metadata_common_cb(const FLAC__StreamMetadata * block, | void flac_metadata_common_cb(const FLAC__StreamMetadata * block, | ||||||
| 			     FlacData * data) | 			     struct flac_data *data) | ||||||
| { | { | ||||||
| 	const FLAC__StreamMetadata_StreamInfo *si = &(block->data.stream_info); | 	const FLAC__StreamMetadata_StreamInfo *si = &(block->data.stream_info); | ||||||
|  |  | ||||||
| @@ -163,7 +168,7 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block, | |||||||
| 		data->total_time = ((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); | 		flac_parse_replay_gain(block, data); | ||||||
| 	default: | 	default: | ||||||
| 		break; | 		break; | ||||||
| 	} | 	} | ||||||
| @@ -171,7 +176,7 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block, | |||||||
|  |  | ||||||
| void flac_error_common_cb(const char *plugin, | void flac_error_common_cb(const char *plugin, | ||||||
| 			  const FLAC__StreamDecoderErrorStatus status, | 			  const FLAC__StreamDecoderErrorStatus status, | ||||||
| 			  G_GNUC_UNUSED FlacData * data) | 			  struct flac_data *data) | ||||||
| { | { | ||||||
| 	if (decoder_get_command(data->decoder) == DECODE_COMMAND_STOP) | 	if (decoder_get_command(data->decoder) == DECODE_COMMAND_STOP) | ||||||
| 		return; | 		return; | ||||||
| @@ -272,7 +277,7 @@ static void flac_convert(unsigned char *dest, | |||||||
| } | } | ||||||
|  |  | ||||||
| FLAC__StreamDecoderWriteStatus | FLAC__StreamDecoderWriteStatus | ||||||
| flac_common_write(FlacData *data, const FLAC__Frame * frame, | flac_common_write(struct flac_data *data, const FLAC__Frame * frame, | ||||||
| 		  const FLAC__int32 *const buf[]) | 		  const FLAC__int32 *const buf[]) | ||||||
| { | { | ||||||
| 	unsigned int c_samp; | 	unsigned int c_samp; | ||||||
| @@ -300,11 +305,11 @@ flac_common_write(FlacData *data, const FLAC__Frame * frame, | |||||||
| 			     num_channels, bytes_per_sample, buf, | 			     num_channels, bytes_per_sample, buf, | ||||||
| 			     c_samp, c_samp + num_samples); | 			     c_samp, c_samp + num_samples); | ||||||
|  |  | ||||||
| 		cmd = decoder_data(data->decoder, data->inStream, | 		cmd = decoder_data(data->decoder, data->input_stream, | ||||||
| 				   data->chunk, | 				   data->chunk, | ||||||
| 				   num_samples * bytes_per_channel, | 				   num_samples * bytes_per_channel, | ||||||
| 				   data->time, data->bitRate, | 				   data->time, data->bit_rate, | ||||||
| 				   data->replayGainInfo); | 				   data->replay_gain_info); | ||||||
| 		switch (cmd) { | 		switch (cmd) { | ||||||
| 		case DECODE_COMMAND_NONE: | 		case DECODE_COMMAND_NONE: | ||||||
| 		case DECODE_COMMAND_START: | 		case DECODE_COMMAND_START: | ||||||
|   | |||||||
| @@ -141,33 +141,37 @@ typedef size_t flac_read_status_size_t; | |||||||
|  |  | ||||||
| #define FLAC_CHUNK_SIZE 4080 | #define FLAC_CHUNK_SIZE 4080 | ||||||
|  |  | ||||||
| typedef struct { | struct flac_data { | ||||||
| 	unsigned char chunk[FLAC_CHUNK_SIZE]; | 	unsigned char chunk[FLAC_CHUNK_SIZE]; | ||||||
| 	float time; | 	float time; | ||||||
| 	unsigned int bitRate; | 	unsigned int bit_rate; | ||||||
| 	struct audio_format audio_format; | 	struct audio_format audio_format; | ||||||
| 	float total_time; | 	float total_time; | ||||||
| 	FLAC__uint64 position; | 	FLAC__uint64 position; | ||||||
| 	struct decoder *decoder; | 	struct decoder *decoder; | ||||||
| 	struct input_stream *inStream; | 	struct input_stream *input_stream; | ||||||
| 	struct replay_gain_info *replayGainInfo; | 	struct replay_gain_info *replay_gain_info; | ||||||
| 	struct tag *tag; | 	struct tag *tag; | ||||||
| } FlacData; | }; | ||||||
|  |  | ||||||
| /* initializes a given FlacData struct */ | /* initializes a given FlacData struct */ | ||||||
| void init_FlacData(FlacData * data, struct decoder * decoder, | void | ||||||
| 		   struct input_stream *inStream); | flac_data_init(struct flac_data *data, struct decoder * decoder, | ||||||
|  | 	       struct input_stream *input_stream); | ||||||
|  |  | ||||||
| void flac_metadata_common_cb(const FLAC__StreamMetadata * block, | void flac_metadata_common_cb(const FLAC__StreamMetadata * block, | ||||||
| 			     FlacData * data); | 			     struct flac_data *data); | ||||||
|  |  | ||||||
| void flac_error_common_cb(const char *plugin, | void flac_error_common_cb(const char *plugin, | ||||||
| 			  FLAC__StreamDecoderErrorStatus status, | 			  FLAC__StreamDecoderErrorStatus status, | ||||||
| 			  FlacData * data); | 			  struct flac_data *data); | ||||||
|  |  | ||||||
| struct tag *copyVorbisCommentBlockToMpdTag(const FLAC__StreamMetadata * block, | struct tag * | ||||||
| 					   struct tag *tag); | flac_vorbis_comments_to_tag(const FLAC__StreamMetadata * block, | ||||||
|  | 			    struct tag *tag); | ||||||
|  |  | ||||||
| FLAC__StreamDecoderWriteStatus | FLAC__StreamDecoderWriteStatus | ||||||
| flac_common_write(FlacData *data, const FLAC__Frame * frame, | flac_common_write(struct flac_data *data, const FLAC__Frame * frame, | ||||||
| 		  const FLAC__int32 *const buf[]); | 		  const FLAC__int32 *const buf[]); | ||||||
|  |  | ||||||
| #endif /* _FLAC_COMMON_H */ | #endif /* _FLAC_COMMON_H */ | ||||||
|   | |||||||
| @@ -25,20 +25,21 @@ | |||||||
|  |  | ||||||
| /* this code was based on flac123, from flac-tools */ | /* this code was based on flac123, from flac-tools */ | ||||||
|  |  | ||||||
| static flac_read_status flacRead(G_GNUC_UNUSED const flac_decoder * flacDec, | static flac_read_status | ||||||
|                                   FLAC__byte buf[], | flac_read_cb(G_GNUC_UNUSED const flac_decoder *fd, | ||||||
| 				  flac_read_status_size_t *bytes, | 	     FLAC__byte buf[], flac_read_status_size_t *bytes, | ||||||
| 				  void *fdata) | 	     void *fdata) | ||||||
| { | { | ||||||
| 	FlacData *data = (FlacData *) fdata; | 	struct flac_data *data = fdata; | ||||||
| 	size_t r; | 	size_t r; | ||||||
|  |  | ||||||
| 	r = decoder_read(data->decoder, data->inStream, (void *)buf, *bytes); | 	r = decoder_read(data->decoder, data->input_stream, | ||||||
|  | 			 (void *)buf, *bytes); | ||||||
| 	*bytes = r; | 	*bytes = r; | ||||||
|  |  | ||||||
| 	if (r == 0) { | 	if (r == 0) { | ||||||
| 		if (decoder_get_command(data->decoder) != DECODE_COMMAND_NONE || | 		if (decoder_get_command(data->decoder) != DECODE_COMMAND_NONE || | ||||||
| 		    input_stream_eof(data->inStream)) | 		    input_stream_eof(data->input_stream)) | ||||||
| 			return flac_read_status_eof; | 			return flac_read_status_eof; | ||||||
| 		else | 		else | ||||||
| 			return flac_read_status_abort; | 			return flac_read_status_abort; | ||||||
| @@ -47,56 +48,58 @@ static flac_read_status flacRead(G_GNUC_UNUSED const flac_decoder * flacDec, | |||||||
| 	return flac_read_status_continue; | 	return flac_read_status_continue; | ||||||
| } | } | ||||||
|  |  | ||||||
| static flac_seek_status flacSeek(G_GNUC_UNUSED const flac_decoder * flacDec, | static flac_seek_status | ||||||
| 				 FLAC__uint64 offset, | flac_seek_cb(G_GNUC_UNUSED const flac_decoder *fd, | ||||||
| 				 void *fdata) | 	     FLAC__uint64 offset, void *fdata) | ||||||
| { | { | ||||||
| 	FlacData *data = (FlacData *) fdata; | 	struct flac_data *data = (struct flac_data *) fdata; | ||||||
|  |  | ||||||
| 	if (!input_stream_seek(data->inStream, offset, SEEK_SET)) | 	if (!input_stream_seek(data->input_stream, offset, SEEK_SET)) | ||||||
| 		return flac_seek_status_error; | 		return flac_seek_status_error; | ||||||
|  |  | ||||||
| 	return flac_seek_status_ok; | 	return flac_seek_status_ok; | ||||||
| } | } | ||||||
|  |  | ||||||
| static flac_tell_status flacTell(G_GNUC_UNUSED const flac_decoder * flacDec, | static flac_tell_status | ||||||
| 				 FLAC__uint64 * offset, | flac_tell_cb(G_GNUC_UNUSED const flac_decoder *fd, | ||||||
| 				 void *fdata) | 	     FLAC__uint64 * offset, void *fdata) | ||||||
| { | { | ||||||
| 	FlacData *data = (FlacData *) fdata; | 	struct flac_data *data = (struct flac_data *) fdata; | ||||||
|  |  | ||||||
| 	*offset = (long)(data->inStream->offset); | 	*offset = (long)(data->input_stream->offset); | ||||||
|  |  | ||||||
| 	return flac_tell_status_ok; | 	return flac_tell_status_ok; | ||||||
| } | } | ||||||
|  |  | ||||||
| static flac_length_status flacLength(G_GNUC_UNUSED const flac_decoder * flacDec, | static flac_length_status | ||||||
| 				     FLAC__uint64 * length, | flac_length_cb(G_GNUC_UNUSED const flac_decoder *fd, | ||||||
| 				     void *fdata) | 	       FLAC__uint64 * length, void *fdata) | ||||||
| { | { | ||||||
| 	FlacData *data = (FlacData *) fdata; | 	struct flac_data *data = (struct flac_data *) fdata; | ||||||
|  |  | ||||||
| 	if (data->inStream->size < 0) | 	if (data->input_stream->size < 0) | ||||||
| 		return flac_length_status_unsupported; | 		return flac_length_status_unsupported; | ||||||
|  |  | ||||||
| 	*length = (size_t) (data->inStream->size); | 	*length = (size_t) (data->input_stream->size); | ||||||
|  |  | ||||||
| 	return flac_length_status_ok; | 	return flac_length_status_ok; | ||||||
| } | } | ||||||
|  |  | ||||||
| static FLAC__bool flacEOF(G_GNUC_UNUSED const flac_decoder * flacDec, void *fdata) | static FLAC__bool | ||||||
|  | flac_eof_cb(G_GNUC_UNUSED const flac_decoder *fd, void *fdata) | ||||||
| { | { | ||||||
| 	FlacData *data = (FlacData *) fdata; | 	struct flac_data *data = (struct flac_data *) fdata; | ||||||
|  |  | ||||||
| 	return (decoder_get_command(data->decoder) != DECODE_COMMAND_NONE && | 	return (decoder_get_command(data->decoder) != DECODE_COMMAND_NONE && | ||||||
| 		decoder_get_command(data->decoder) != DECODE_COMMAND_SEEK) || | 		decoder_get_command(data->decoder) != DECODE_COMMAND_SEEK) || | ||||||
| 		input_stream_eof(data->inStream); | 		input_stream_eof(data->input_stream); | ||||||
| } | } | ||||||
|  |  | ||||||
| static void flacError(G_GNUC_UNUSED const flac_decoder *dec, | static void | ||||||
| 		      FLAC__StreamDecoderErrorStatus status, void *fdata) | flac_error_cb(G_GNUC_UNUSED const flac_decoder *fd, | ||||||
|  | 	      FLAC__StreamDecoderErrorStatus status, void *fdata) | ||||||
| { | { | ||||||
| 	flac_error_common_cb("flac", status, (FlacData *) fdata); | 	flac_error_common_cb("flac", status, (struct flac_data *) fdata); | ||||||
| } | } | ||||||
|  |  | ||||||
| #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7 | #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7 | ||||||
| @@ -196,16 +199,15 @@ static void flacPrintErroredState(FLAC__StreamDecoderState state) | |||||||
| static void flacMetadata(G_GNUC_UNUSED const flac_decoder * dec, | static void flacMetadata(G_GNUC_UNUSED const flac_decoder * dec, | ||||||
| 			 const FLAC__StreamMetadata * block, void *vdata) | 			 const FLAC__StreamMetadata * block, void *vdata) | ||||||
| { | { | ||||||
| 	flac_metadata_common_cb(block, (FlacData *) vdata); | 	flac_metadata_common_cb(block, (struct flac_data *) vdata); | ||||||
| } | } | ||||||
|  |  | ||||||
| static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec, | static FLAC__StreamDecoderWriteStatus | ||||||
|                                                 const FLAC__Frame * frame, | flac_write_cb(const flac_decoder *dec, const FLAC__Frame *frame, | ||||||
| 						const FLAC__int32 * const buf[], | 	      const FLAC__int32 *const buf[], void *vdata) | ||||||
| 						void *vdata) |  | ||||||
| { | { | ||||||
| 	FLAC__uint32 samples = frame->header.blocksize; | 	FLAC__uint32 samples = frame->header.blocksize; | ||||||
| 	FlacData *data = (FlacData *) vdata; | 	struct flac_data *data = (struct flac_data *) vdata; | ||||||
| 	float timeChange; | 	float timeChange; | ||||||
| 	FLAC__uint64 newPosition = 0; | 	FLAC__uint64 newPosition = 0; | ||||||
|  |  | ||||||
| @@ -216,7 +218,7 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec, | |||||||
| 	if (data->position && newPosition >= data->position) { | 	if (data->position && newPosition >= data->position) { | ||||||
| 		assert(timeChange >= 0); | 		assert(timeChange >= 0); | ||||||
|  |  | ||||||
| 		data->bitRate = | 		data->bit_rate = | ||||||
| 		    ((newPosition - data->position) * 8.0 / timeChange) | 		    ((newPosition - data->position) * 8.0 / timeChange) | ||||||
| 		    / 1000 + 0.5; | 		    / 1000 + 0.5; | ||||||
| 	} | 	} | ||||||
| @@ -226,13 +228,13 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec, | |||||||
| } | } | ||||||
|  |  | ||||||
| static struct tag * | static struct tag * | ||||||
| flacMetadataDup(const char *file, bool *vorbisCommentFound) | flac_tag_load(const char *file, bool *vorbis_comment_found) | ||||||
| { | { | ||||||
| 	struct tag *ret = NULL; | 	struct tag *ret = NULL; | ||||||
| 	FLAC__Metadata_SimpleIterator *it; | 	FLAC__Metadata_SimpleIterator *it; | ||||||
| 	FLAC__StreamMetadata *block = NULL; | 	FLAC__StreamMetadata *block = NULL; | ||||||
|  |  | ||||||
| 	*vorbisCommentFound = false; | 	*vorbis_comment_found = false; | ||||||
|  |  | ||||||
| 	it = FLAC__metadata_simple_iterator_new(); | 	it = FLAC__metadata_simple_iterator_new(); | ||||||
| 	if (!FLAC__metadata_simple_iterator_init(it, file, 1, 0)) { | 	if (!FLAC__metadata_simple_iterator_init(it, file, 1, 0)) { | ||||||
| @@ -265,10 +267,10 @@ flacMetadataDup(const char *file, bool *vorbisCommentFound) | |||||||
| 		if (!block) | 		if (!block) | ||||||
| 			break; | 			break; | ||||||
| 		if (block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { | 		if (block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { | ||||||
| 			ret = copyVorbisCommentBlockToMpdTag(block, ret); | 			ret = flac_vorbis_comments_to_tag(block, ret); | ||||||
|  |  | ||||||
| 			if (ret) | 			if (ret) | ||||||
| 				*vorbisCommentFound = true; | 				*vorbis_comment_found = true; | ||||||
| 		} else if (block->type == FLAC__METADATA_TYPE_STREAMINFO) { | 		} else if (block->type == FLAC__METADATA_TYPE_STREAMINFO) { | ||||||
| 			if (!ret) | 			if (!ret) | ||||||
| 				ret = tag_new(); | 				ret = tag_new(); | ||||||
| @@ -283,17 +285,18 @@ flacMetadataDup(const char *file, bool *vorbisCommentFound) | |||||||
| 	return ret; | 	return ret; | ||||||
| } | } | ||||||
|  |  | ||||||
| static struct tag *flacTagDup(const char *file) | static struct tag * | ||||||
|  | flac_tag_dup(const char *file) | ||||||
| { | { | ||||||
| 	struct tag *ret = NULL; | 	struct tag *ret = NULL; | ||||||
| 	bool foundVorbisComment = false; | 	bool vorbis_comment_found = false; | ||||||
|  |  | ||||||
| 	ret = flacMetadataDup(file, &foundVorbisComment); | 	ret = flac_tag_load(file, &vorbis_comment_found); | ||||||
| 	if (!ret) { | 	if (!ret) { | ||||||
| 		g_debug("Failed to grab information from: %s\n", file); | 		g_debug("Failed to grab information from: %s\n", file); | ||||||
| 		return NULL; | 		return NULL; | ||||||
| 	} | 	} | ||||||
| 	if (!foundVorbisComment) { | 	if (!vorbis_comment_found) { | ||||||
| 		struct tag *temp = tag_id3_load(file); | 		struct tag *temp = tag_id3_load(file); | ||||||
| 		if (temp) { | 		if (temp) { | ||||||
| 			temp->time = ret->time; | 			temp->time = ret->time; | ||||||
| @@ -306,19 +309,20 @@ static struct tag *flacTagDup(const char *file) | |||||||
| } | } | ||||||
|  |  | ||||||
| static void | static void | ||||||
| flac_decode_internal(struct decoder * decoder, struct input_stream *inStream, | flac_decode_internal(struct decoder * decoder, | ||||||
|  | 		     struct input_stream *input_stream, | ||||||
| 		     bool is_ogg) | 		     bool is_ogg) | ||||||
| { | { | ||||||
| 	flac_decoder *flacDec; | 	flac_decoder *flac_dec; | ||||||
| 	FlacData data; | 	struct flac_data data; | ||||||
| 	const char *err = NULL; | 	const char *err = NULL; | ||||||
|  |  | ||||||
| 	if (!(flacDec = flac_new())) | 	if (!(flac_dec = flac_new())) | ||||||
| 		return; | 		return; | ||||||
| 	init_FlacData(&data, decoder, inStream); | 	flac_data_init(&data, decoder, input_stream); | ||||||
|  |  | ||||||
| #if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7 | #if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7 | ||||||
|         if(!FLAC__stream_decoder_set_metadata_respond(flacDec, FLAC__METADATA_TYPE_VORBIS_COMMENT)) |         if(!FLAC__stream_decoder_set_metadata_respond(flac_dec, FLAC__METADATA_TYPE_VORBIS_COMMENT)) | ||||||
|         { |         { | ||||||
|                 g_debug("Failed to set metadata respond\n"); |                 g_debug("Failed to set metadata respond\n"); | ||||||
|         } |         } | ||||||
| @@ -326,22 +330,26 @@ flac_decode_internal(struct decoder * decoder, struct input_stream *inStream, | |||||||
|  |  | ||||||
|  |  | ||||||
| 	if (is_ogg) { | 	if (is_ogg) { | ||||||
| 		if (!flac_ogg_init(flacDec, flacRead, flacSeek, flacTell, | 		if (!flac_ogg_init(flac_dec, flac_read_cb, | ||||||
| 		                   flacLength, flacEOF, flacWrite, flacMetadata, | 				   flac_seek_cb, flac_tell_cb, | ||||||
| 			           flacError, (void *)&data)) { | 				   flac_length_cb, flac_eof_cb, | ||||||
|  | 				   flac_write_cb, flacMetadata, | ||||||
|  | 				   flac_error_cb, (void *)&data)) { | ||||||
| 			err = "doing Ogg init()"; | 			err = "doing Ogg init()"; | ||||||
| 			goto fail; | 			goto fail; | ||||||
| 		} | 		} | ||||||
| 	} else { | 	} else { | ||||||
| 		if (!flac_init(flacDec, flacRead, flacSeek, flacTell, | 		if (!flac_init(flac_dec, flac_read_cb, | ||||||
| 		               flacLength, flacEOF, flacWrite, flacMetadata, | 			       flac_seek_cb, flac_tell_cb, | ||||||
| 			       flacError, (void *)&data)) { | 			       flac_length_cb, flac_eof_cb, | ||||||
|  | 			       flac_write_cb, flacMetadata, | ||||||
|  | 			       flac_error_cb, (void *)&data)) { | ||||||
| 			err = "doing init()"; | 			err = "doing init()"; | ||||||
| 			goto fail; | 			goto fail; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (!flac_process_metadata(flacDec)) { | 	if (!flac_process_metadata(flac_dec)) { | ||||||
| 		err = "problem reading metadata"; | 		err = "problem reading metadata"; | ||||||
| 		goto fail; | 		goto fail; | ||||||
| 	} | 	} | ||||||
| @@ -355,44 +363,44 @@ flac_decode_internal(struct decoder * decoder, struct input_stream *inStream, | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	decoder_initialized(decoder, &data.audio_format, | 	decoder_initialized(decoder, &data.audio_format, | ||||||
| 			    inStream->seekable, data.total_time); | 			    input_stream->seekable, data.total_time); | ||||||
|  |  | ||||||
| 	while (true) { | 	while (true) { | ||||||
| 		if (!flac_process_single(flacDec)) | 		if (!flac_process_single(flac_dec)) | ||||||
| 			break; | 			break; | ||||||
| 		if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) { | 		if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) { | ||||||
| 			FLAC__uint64 sampleToSeek = decoder_seek_where(decoder) * | 			FLAC__uint64 seek_sample = decoder_seek_where(decoder) * | ||||||
| 			    data.audio_format.sample_rate + 0.5; | 			    data.audio_format.sample_rate + 0.5; | ||||||
| 			if (flac_seek_absolute(flacDec, sampleToSeek)) { | 			if (flac_seek_absolute(flac_dec, seek_sample)) { | ||||||
| 				data.time = ((float)sampleToSeek) / | 				data.time = ((float)seek_sample) / | ||||||
| 				    data.audio_format.sample_rate; | 				    data.audio_format.sample_rate; | ||||||
| 				data.position = 0; | 				data.position = 0; | ||||||
| 				decoder_command_finished(decoder); | 				decoder_command_finished(decoder); | ||||||
| 			} else | 			} else | ||||||
| 				decoder_seek_error(decoder); | 				decoder_seek_error(decoder); | ||||||
| 		} else if (flac_get_state(flacDec) == flac_decoder_eof) | 		} else if (flac_get_state(flac_dec) == flac_decoder_eof) | ||||||
| 			break; | 			break; | ||||||
| 	} | 	} | ||||||
| 	if (decoder_get_command(decoder) != DECODE_COMMAND_STOP) { | 	if (decoder_get_command(decoder) != DECODE_COMMAND_STOP) { | ||||||
| 		flacPrintErroredState(flac_get_state(flacDec)); | 		flacPrintErroredState(flac_get_state(flac_dec)); | ||||||
| 		flac_finish(flacDec); | 		flac_finish(flac_dec); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| fail: | fail: | ||||||
| 	if (data.replayGainInfo) | 	if (data.replay_gain_info) | ||||||
| 		replay_gain_info_free(data.replayGainInfo); | 		replay_gain_info_free(data.replay_gain_info); | ||||||
|  |  | ||||||
| 	if (flacDec) | 	if (flac_dec) | ||||||
| 		flac_delete(flacDec); | 		flac_delete(flac_dec); | ||||||
|  |  | ||||||
| 	if (err) | 	if (err) | ||||||
| 		g_warning("%s\n", err); | 		g_warning("%s\n", err); | ||||||
| } | } | ||||||
|  |  | ||||||
| static void | static void | ||||||
| flac_decode(struct decoder * decoder, struct input_stream *inStream) | flac_decode(struct decoder * decoder, struct input_stream *input_stream) | ||||||
| { | { | ||||||
| 	flac_decode_internal(decoder, inStream, false); | 	flac_decode_internal(decoder, input_stream, false); | ||||||
| } | } | ||||||
|  |  | ||||||
| #ifndef HAVE_OGGFLAC | #ifndef HAVE_OGGFLAC | ||||||
| @@ -410,7 +418,8 @@ oggflac_init(void) | |||||||
|  |  | ||||||
| #if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7 | #if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7 | ||||||
|  |  | ||||||
| static struct tag *oggflac_tag_dup(const char *file) | static struct tag * | ||||||
|  | oggflac_tag_dup(const char *file) | ||||||
| { | { | ||||||
| 	struct tag *ret = NULL; | 	struct tag *ret = NULL; | ||||||
| 	FLAC__Metadata_Iterator *it; | 	FLAC__Metadata_Iterator *it; | ||||||
| @@ -425,7 +434,7 @@ static struct tag *oggflac_tag_dup(const char *file) | |||||||
| 		if (!(block = FLAC__metadata_iterator_get_block(it))) | 		if (!(block = FLAC__metadata_iterator_get_block(it))) | ||||||
| 			break; | 			break; | ||||||
| 		if (block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { | 		if (block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { | ||||||
| 			ret = copyVorbisCommentBlockToMpdTag(block, ret); | 			ret = flac_vorbis_comments_to_tag(block, ret); | ||||||
| 		} else if (block->type == FLAC__METADATA_TYPE_STREAMINFO) { | 		} else if (block->type == FLAC__METADATA_TYPE_STREAMINFO) { | ||||||
| 			if (!ret) | 			if (!ret) | ||||||
| 				ret = tag_new(); | 				ret = tag_new(); | ||||||
| @@ -441,16 +450,16 @@ out: | |||||||
| } | } | ||||||
|  |  | ||||||
| static void | static void | ||||||
| oggflac_decode(struct decoder *decoder, struct input_stream *inStream) | oggflac_decode(struct decoder *decoder, struct input_stream *input_stream) | ||||||
| { | { | ||||||
| 	if (ogg_stream_type_detect(inStream) != FLAC) | 	if (ogg_stream_type_detect(input_stream) != FLAC) | ||||||
| 		return; | 		return; | ||||||
|  |  | ||||||
| 	/* rewind the stream, because ogg_stream_type_detect() has | 	/* rewind the stream, because ogg_stream_type_detect() has | ||||||
| 	   moved it */ | 	   moved it */ | ||||||
| 	input_stream_seek(inStream, 0, SEEK_SET); | 	input_stream_seek(input_stream, 0, SEEK_SET); | ||||||
|  |  | ||||||
| 	flac_decode_internal(decoder, inStream, true); | 	flac_decode_internal(decoder, input_stream, true); | ||||||
| } | } | ||||||
|  |  | ||||||
| static const char *const oggflac_suffixes[] = { "ogg", "oga", NULL }; | static const char *const oggflac_suffixes[] = { "ogg", "oga", NULL }; | ||||||
| @@ -463,7 +472,7 @@ static const char *const oggflac_mime_types[] = { | |||||||
|  |  | ||||||
| #endif /* FLAC_API_VERSION_CURRENT >= 7 */ | #endif /* FLAC_API_VERSION_CURRENT >= 7 */ | ||||||
|  |  | ||||||
| const struct decoder_plugin oggflacPlugin = { | const struct decoder_plugin oggflac_decoder_plugin = { | ||||||
| 	.name = "oggflac", | 	.name = "oggflac", | ||||||
| 	.init = oggflac_init, | 	.init = oggflac_init, | ||||||
| #if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7 | #if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7 | ||||||
| @@ -476,15 +485,15 @@ const struct decoder_plugin oggflacPlugin = { | |||||||
|  |  | ||||||
| #endif /* HAVE_OGGFLAC */ | #endif /* HAVE_OGGFLAC */ | ||||||
|  |  | ||||||
| static const char *const flacSuffixes[] = { "flac", NULL }; | static const char *const flac_suffixes[] = { "flac", NULL }; | ||||||
| static const char *const flac_mime_types[] = { | static const char *const flac_mime_types[] = { | ||||||
| 	"audio/x-flac", "application/x-flac", NULL | 	"audio/x-flac", "application/x-flac", NULL | ||||||
| }; | }; | ||||||
|  |  | ||||||
| const struct decoder_plugin flacPlugin = { | const struct decoder_plugin flac_decoder_plugin = { | ||||||
| 	.name = "flac", | 	.name = "flac", | ||||||
| 	.stream_decode = flac_decode, | 	.stream_decode = flac_decode, | ||||||
| 	.tag_dup = flacTagDup, | 	.tag_dup = flac_tag_dup, | ||||||
| 	.suffixes = flacSuffixes, | 	.suffixes = flac_suffixes, | ||||||
| 	.mime_types = flac_mime_types | 	.mime_types = flac_mime_types | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -26,11 +26,11 @@ | |||||||
| #include <OggFLAC/seekable_stream_decoder.h> | #include <OggFLAC/seekable_stream_decoder.h> | ||||||
| #include <unistd.h> | #include <unistd.h> | ||||||
|  |  | ||||||
| static void oggflac_cleanup(FlacData * data, | static void oggflac_cleanup(struct flac_data *data, | ||||||
| 			    OggFLAC__SeekableStreamDecoder * decoder) | 			    OggFLAC__SeekableStreamDecoder * decoder) | ||||||
| { | { | ||||||
| 	if (data->replayGainInfo) | 	if (data->replay_gain_info) | ||||||
| 		replay_gain_info_free(data->replayGainInfo); | 		replay_gain_info_free(data->replay_gain_info); | ||||||
| 	if (decoder) | 	if (decoder) | ||||||
| 		OggFLAC__seekable_stream_decoder_delete(decoder); | 		OggFLAC__seekable_stream_decoder_delete(decoder); | ||||||
| } | } | ||||||
| @@ -42,13 +42,14 @@ static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(G_GNUC_UNUSED const | |||||||
| 							   unsigned *bytes, | 							   unsigned *bytes, | ||||||
| 							   void *fdata) | 							   void *fdata) | ||||||
| { | { | ||||||
| 	FlacData *data = (FlacData *) fdata; | 	struct flac_data *data = (struct flac_data *) fdata; | ||||||
| 	size_t r; | 	size_t r; | ||||||
|  |  | ||||||
| 	r = decoder_read(data->decoder, data->inStream, (void *)buf, *bytes); | 	r = decoder_read(data->decoder, data->input_stream, | ||||||
|  | 			 (void *)buf, *bytes); | ||||||
| 	*bytes = r; | 	*bytes = r; | ||||||
|  |  | ||||||
| 	if (r == 0 && !input_stream_eof(data->inStream) && | 	if (r == 0 && !input_stream_eof(data->input_stream) && | ||||||
| 	    decoder_get_command(data->decoder) == DECODE_COMMAND_NONE) | 	    decoder_get_command(data->decoder) == DECODE_COMMAND_NONE) | ||||||
| 		return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; | 		return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; | ||||||
|  |  | ||||||
| @@ -61,9 +62,9 @@ static OggFLAC__SeekableStreamDecoderSeekStatus of_seek_cb(G_GNUC_UNUSED const | |||||||
| 							   FLAC__uint64 offset, | 							   FLAC__uint64 offset, | ||||||
| 							   void *fdata) | 							   void *fdata) | ||||||
| { | { | ||||||
| 	FlacData *data = (FlacData *) fdata; | 	struct flac_data *data = (struct flac_data *) fdata; | ||||||
|  |  | ||||||
| 	if (!input_stream_seek(data->inStream, offset, SEEK_SET)) | 	if (!input_stream_seek(data->input_stream, offset, SEEK_SET)) | ||||||
| 		return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR; | 		return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR; | ||||||
|  |  | ||||||
| 	return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK; | 	return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK; | ||||||
| @@ -75,9 +76,9 @@ static OggFLAC__SeekableStreamDecoderTellStatus of_tell_cb(G_GNUC_UNUSED const | |||||||
| 							   FLAC__uint64 * | 							   FLAC__uint64 * | ||||||
| 							   offset, void *fdata) | 							   offset, void *fdata) | ||||||
| { | { | ||||||
| 	FlacData *data = (FlacData *) fdata; | 	struct flac_data *data = (struct flac_data *) fdata; | ||||||
|  |  | ||||||
| 	*offset = (long)(data->inStream->offset); | 	*offset = (long)(data->input_stream->offset); | ||||||
|  |  | ||||||
| 	return OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK; | 	return OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK; | ||||||
| } | } | ||||||
| @@ -89,12 +90,12 @@ static OggFLAC__SeekableStreamDecoderLengthStatus of_length_cb(G_GNUC_UNUSED con | |||||||
| 							       length, | 							       length, | ||||||
| 							       void *fdata) | 							       void *fdata) | ||||||
| { | { | ||||||
| 	FlacData *data = (FlacData *) fdata; | 	struct flac_data *data = (struct flac_data *) fdata; | ||||||
|  |  | ||||||
| 	if (data->inStream->size < 0) | 	if (data->input_stream->size < 0) | ||||||
| 		return OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR; | 		return OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR; | ||||||
|  |  | ||||||
| 	*length = (size_t) (data->inStream->size); | 	*length = (size_t) (data->input_stream->size); | ||||||
|  |  | ||||||
| 	return OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK; | 	return OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK; | ||||||
| } | } | ||||||
| @@ -102,17 +103,17 @@ static OggFLAC__SeekableStreamDecoderLengthStatus of_length_cb(G_GNUC_UNUSED con | |||||||
| static FLAC__bool of_EOF_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecoder * decoder, | static FLAC__bool of_EOF_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecoder * decoder, | ||||||
| 			    void *fdata) | 			    void *fdata) | ||||||
| { | { | ||||||
| 	FlacData *data = (FlacData *) fdata; | 	struct flac_data *data = (struct flac_data *) fdata; | ||||||
|  |  | ||||||
| 	return (decoder_get_command(data->decoder) != DECODE_COMMAND_NONE && | 	return (decoder_get_command(data->decoder) != DECODE_COMMAND_NONE && | ||||||
| 		decoder_get_command(data->decoder) != DECODE_COMMAND_SEEK) || | 		decoder_get_command(data->decoder) != DECODE_COMMAND_SEEK) || | ||||||
| 		input_stream_eof(data->inStream); | 		input_stream_eof(data->input_stream); | ||||||
| } | } | ||||||
|  |  | ||||||
| static void of_error_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecoder * decoder, | static void of_error_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecoder * decoder, | ||||||
| 			FLAC__StreamDecoderErrorStatus status, void *fdata) | 			FLAC__StreamDecoderErrorStatus status, void *fdata) | ||||||
| { | { | ||||||
| 	flac_error_common_cb("oggflac", status, (FlacData *) fdata); | 	flac_error_common_cb("oggflac", status, (struct flac_data *) fdata); | ||||||
| } | } | ||||||
|  |  | ||||||
| static void oggflacPrintErroredState(OggFLAC__SeekableStreamDecoderState state) | static void oggflacPrintErroredState(OggFLAC__SeekableStreamDecoderState state) | ||||||
| @@ -146,19 +147,17 @@ static void oggflacPrintErroredState(OggFLAC__SeekableStreamDecoderState state) | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| static FLAC__StreamDecoderWriteStatus oggflacWrite(G_GNUC_UNUSED const | static FLAC__StreamDecoderWriteStatus | ||||||
| 						   OggFLAC__SeekableStreamDecoder | oggflac_write_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecoder *decoder, | ||||||
| 						   * decoder, | 		 const FLAC__Frame *frame, const FLAC__int32 *const buf[], | ||||||
| 						   const FLAC__Frame * frame, | 		 void *vdata) | ||||||
| 						   const FLAC__int32 * |  | ||||||
| 						   const buf[], void *vdata) |  | ||||||
| { | { | ||||||
| 	FlacData *data = (FlacData *) vdata; | 	struct flac_data *data = (struct flac_data *) vdata; | ||||||
| 	FLAC__uint32 samples = frame->header.blocksize; | 	FLAC__uint32 samples = frame->header.blocksize; | ||||||
| 	float timeChange; | 	float time_change; | ||||||
|  |  | ||||||
| 	timeChange = ((float)samples) / frame->header.sample_rate; | 	time_change = ((float)samples) / frame->header.sample_rate; | ||||||
| 	data->time += timeChange; | 	data->time += time_change; | ||||||
|  |  | ||||||
| 	return flac_common_write(data, frame, buf); | 	return flac_common_write(data, frame, buf); | ||||||
| } | } | ||||||
| @@ -167,7 +166,7 @@ static FLAC__StreamDecoderWriteStatus oggflacWrite(G_GNUC_UNUSED const | |||||||
| static void of_metadata_dup_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecoder * decoder, | static void of_metadata_dup_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecoder * decoder, | ||||||
| 			       const FLAC__StreamMetadata * block, void *vdata) | 			       const FLAC__StreamMetadata * block, void *vdata) | ||||||
| { | { | ||||||
| 	FlacData *data = (FlacData *) vdata; | 	struct flac_data *data = (struct flac_data *) vdata; | ||||||
|  |  | ||||||
| 	switch (block->type) { | 	switch (block->type) { | ||||||
| 	case FLAC__METADATA_TYPE_STREAMINFO: | 	case FLAC__METADATA_TYPE_STREAMINFO: | ||||||
| @@ -178,7 +177,7 @@ static void of_metadata_dup_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecode | |||||||
| 		    block->data.stream_info.sample_rate + 0.5; | 		    block->data.stream_info.sample_rate + 0.5; | ||||||
| 		return; | 		return; | ||||||
| 	case FLAC__METADATA_TYPE_VORBIS_COMMENT: | 	case FLAC__METADATA_TYPE_VORBIS_COMMENT: | ||||||
| 		copyVorbisCommentBlockToMpdTag(block, data->tag); | 		flac_vorbis_comments_to_tag(block, data->tag); | ||||||
| 	default: | 	default: | ||||||
| 		break; | 		break; | ||||||
| 	} | 	} | ||||||
| @@ -189,12 +188,12 @@ static void of_metadata_decode_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDec | |||||||
| 				  const FLAC__StreamMetadata * block, | 				  const FLAC__StreamMetadata * block, | ||||||
| 				  void *vdata) | 				  void *vdata) | ||||||
| { | { | ||||||
| 	flac_metadata_common_cb(block, (FlacData *) vdata); | 	flac_metadata_common_cb(block, (struct flac_data *) vdata); | ||||||
| } | } | ||||||
|  |  | ||||||
| static OggFLAC__SeekableStreamDecoder | static OggFLAC__SeekableStreamDecoder * | ||||||
|     * full_decoder_init_and_read_metadata(FlacData * data, | full_decoder_init_and_read_metadata(struct flac_data *data, | ||||||
| 					  unsigned int metadata_only) | 				    unsigned int metadata_only) | ||||||
| { | { | ||||||
| 	OggFLAC__SeekableStreamDecoder *decoder = NULL; | 	OggFLAC__SeekableStreamDecoder *decoder = NULL; | ||||||
| 	unsigned int s = 1; | 	unsigned int s = 1; | ||||||
| @@ -223,7 +222,7 @@ static OggFLAC__SeekableStreamDecoder | |||||||
| 	s &= OggFLAC__seekable_stream_decoder_set_eof_callback(decoder, | 	s &= OggFLAC__seekable_stream_decoder_set_eof_callback(decoder, | ||||||
| 							       of_EOF_cb); | 							       of_EOF_cb); | ||||||
| 	s &= OggFLAC__seekable_stream_decoder_set_write_callback(decoder, | 	s &= OggFLAC__seekable_stream_decoder_set_write_callback(decoder, | ||||||
| 								 oggflacWrite); | 								 oggflac_write_cb); | ||||||
| 	s &= OggFLAC__seekable_stream_decoder_set_metadata_respond(decoder, | 	s &= OggFLAC__seekable_stream_decoder_set_metadata_respond(decoder, | ||||||
| 								   FLAC__METADATA_TYPE_VORBIS_COMMENT); | 								   FLAC__METADATA_TYPE_VORBIS_COMMENT); | ||||||
| 	s &= OggFLAC__seekable_stream_decoder_set_error_callback(decoder, | 	s &= OggFLAC__seekable_stream_decoder_set_error_callback(decoder, | ||||||
| @@ -256,41 +255,42 @@ fail: | |||||||
| } | } | ||||||
|  |  | ||||||
| /* public functions: */ | /* public functions: */ | ||||||
| static struct tag *oggflac_TagDup(const char *file) | static struct tag * | ||||||
|  | oggflac_tag_dup(const char *file) | ||||||
| { | { | ||||||
| 	struct input_stream inStream; | 	struct input_stream input_stream; | ||||||
| 	OggFLAC__SeekableStreamDecoder *decoder; | 	OggFLAC__SeekableStreamDecoder *decoder; | ||||||
| 	FlacData data; | 	struct flac_data data; | ||||||
|  |  | ||||||
| 	if (!input_stream_open(&inStream, file)) | 	if (!input_stream_open(&input_stream, file)) | ||||||
| 		return NULL; | 		return NULL; | ||||||
| 	if (ogg_stream_type_detect(&inStream) != FLAC) { | 	if (ogg_stream_type_detect(&input_stream) != FLAC) { | ||||||
| 		input_stream_close(&inStream); | 		input_stream_close(&input_stream); | ||||||
| 		return NULL; | 		return NULL; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	init_FlacData(&data, NULL, &inStream); | 	flac_data_init(&data, NULL, &input_stream); | ||||||
|  |  | ||||||
| 	/* errors here won't matter, | 	/* errors here won't matter, | ||||||
| 	 * data.tag will be set or unset, that's all we care about */ | 	 * data.tag will be set or unset, that's all we care about */ | ||||||
| 	decoder = full_decoder_init_and_read_metadata(&data, 1); | 	decoder = full_decoder_init_and_read_metadata(&data, 1); | ||||||
|  |  | ||||||
| 	oggflac_cleanup(&data, decoder); | 	oggflac_cleanup(&data, decoder); | ||||||
| 	input_stream_close(&inStream); | 	input_stream_close(&input_stream); | ||||||
|  |  | ||||||
| 	return data.tag; | 	return data.tag; | ||||||
| } | } | ||||||
|  |  | ||||||
| static void | static void | ||||||
| oggflac_decode(struct decoder * mpd_decoder, struct input_stream *inStream) | oggflac_decode(struct decoder * mpd_decoder, struct input_stream *input_stream) | ||||||
| { | { | ||||||
| 	OggFLAC__SeekableStreamDecoder *decoder = NULL; | 	OggFLAC__SeekableStreamDecoder *decoder = NULL; | ||||||
| 	FlacData data; | 	struct flac_data data; | ||||||
|  |  | ||||||
| 	if (ogg_stream_type_detect(inStream) != FLAC) | 	if (ogg_stream_type_detect(input_stream) != FLAC) | ||||||
| 		return; | 		return; | ||||||
|  |  | ||||||
| 	init_FlacData(&data, mpd_decoder, inStream); | 	flac_data_init(&data, mpd_decoder, input_stream); | ||||||
|  |  | ||||||
| 	if (!(decoder = full_decoder_init_and_read_metadata(&data, 0))) { | 	if (!(decoder = full_decoder_init_and_read_metadata(&data, 0))) { | ||||||
| 		goto fail; | 		goto fail; | ||||||
| @@ -305,7 +305,7 @@ oggflac_decode(struct decoder * mpd_decoder, struct input_stream *inStream) | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	decoder_initialized(mpd_decoder, &data.audio_format, | 	decoder_initialized(mpd_decoder, &data.audio_format, | ||||||
| 			    inStream->seekable, data.total_time); | 			    input_stream->seekable, data.total_time); | ||||||
|  |  | ||||||
| 	while (true) { | 	while (true) { | ||||||
| 		OggFLAC__seekable_stream_decoder_process_single(decoder); | 		OggFLAC__seekable_stream_decoder_process_single(decoder); | ||||||
| @@ -314,11 +314,11 @@ oggflac_decode(struct decoder * mpd_decoder, struct input_stream *inStream) | |||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
| 		if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK) { | 		if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK) { | ||||||
| 			FLAC__uint64 sampleToSeek = decoder_seek_where(mpd_decoder) * | 			FLAC__uint64 seek_sample = decoder_seek_where(mpd_decoder) * | ||||||
| 			    data.audio_format.sample_rate + 0.5; | 			    data.audio_format.sample_rate + 0.5; | ||||||
| 			if (OggFLAC__seekable_stream_decoder_seek_absolute | 			if (OggFLAC__seekable_stream_decoder_seek_absolute | ||||||
| 			    (decoder, sampleToSeek)) { | 			    (decoder, seek_sample)) { | ||||||
| 				data.time = ((float)sampleToSeek) / | 				data.time = ((float)seek_sample) / | ||||||
| 				    data.audio_format.sample_rate; | 				    data.audio_format.sample_rate; | ||||||
| 				data.position = 0; | 				data.position = 0; | ||||||
| 				decoder_command_finished(mpd_decoder); | 				decoder_command_finished(mpd_decoder); | ||||||
| @@ -337,7 +337,7 @@ fail: | |||||||
| 	oggflac_cleanup(&data, decoder); | 	oggflac_cleanup(&data, decoder); | ||||||
| } | } | ||||||
|  |  | ||||||
| static const char *const oggflac_Suffixes[] = { "ogg", "oga", NULL }; | static const char *const oggflac_suffixes[] = { "ogg", "oga", NULL }; | ||||||
| static const char *const oggflac_mime_types[] = { | static const char *const oggflac_mime_types[] = { | ||||||
| 	"audio/x-flac+ogg", | 	"audio/x-flac+ogg", | ||||||
| 	"application/ogg", | 	"application/ogg", | ||||||
| @@ -345,10 +345,10 @@ static const char *const oggflac_mime_types[] = { | |||||||
| 	NULL | 	NULL | ||||||
| }; | }; | ||||||
|  |  | ||||||
| const struct decoder_plugin oggflacPlugin = { | const struct decoder_plugin oggflac_decoder_plugin = { | ||||||
| 	.name = "oggflac", | 	.name = "oggflac", | ||||||
| 	.stream_decode = oggflac_decode, | 	.stream_decode = oggflac_decode, | ||||||
| 	.tag_dup = oggflac_TagDup, | 	.tag_dup = oggflac_tag_dup, | ||||||
| 	.suffixes = oggflac_Suffixes, | 	.suffixes = oggflac_suffixes, | ||||||
| 	.mime_types = oggflac_mime_types | 	.mime_types = oggflac_mime_types | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -25,8 +25,8 @@ | |||||||
|  |  | ||||||
| extern const struct decoder_plugin mp3Plugin; | extern const struct decoder_plugin mp3Plugin; | ||||||
| extern const struct decoder_plugin vorbis_decoder_plugin; | extern const struct decoder_plugin vorbis_decoder_plugin; | ||||||
| extern const struct decoder_plugin flacPlugin; | extern const struct decoder_plugin flac_decoder_plugin; | ||||||
| extern const struct decoder_plugin oggflacPlugin; | extern const struct decoder_plugin oggflac_decoder_plugin; | ||||||
| extern const struct decoder_plugin audiofilePlugin; | extern const struct decoder_plugin audiofilePlugin; | ||||||
| extern const struct decoder_plugin mp4_plugin; | extern const struct decoder_plugin mp4_plugin; | ||||||
| extern const struct decoder_plugin aacPlugin; | extern const struct decoder_plugin aacPlugin; | ||||||
| @@ -44,10 +44,10 @@ static const struct decoder_plugin *const decoder_plugins[] = { | |||||||
| 	&vorbis_decoder_plugin, | 	&vorbis_decoder_plugin, | ||||||
| #endif | #endif | ||||||
| #if defined(HAVE_FLAC) || defined(HAVE_OGGFLAC) | #if defined(HAVE_FLAC) || defined(HAVE_OGGFLAC) | ||||||
| 	&oggflacPlugin, | 	&oggflac_decoder_plugin, | ||||||
| #endif | #endif | ||||||
| #ifdef HAVE_FLAC | #ifdef HAVE_FLAC | ||||||
| 	&flacPlugin, | 	&flac_decoder_plugin, | ||||||
| #endif | #endif | ||||||
| #ifdef HAVE_AUDIOFILE | #ifdef HAVE_AUDIOFILE | ||||||
| 	&audiofilePlugin, | 	&audiofilePlugin, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Max Kellermann
					Max Kellermann