flac_plugin
git-svn-id: https://svn.musicpd.org/mpd/trunk@1246 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
fd6aa25359
commit
30424cb3e9
@ -1,11 +1,12 @@
|
||||
bin_PROGRAMS = mpd
|
||||
SUBDIRS = $(ID3_SUBDIR) $(MAD_SUBDIR) $(MP4FF_SUBDIR)
|
||||
|
||||
mpd_inputPlugins = inputPlugins/mp3_plugin.c inputPlugins/ogg_plugin.c
|
||||
mpd_inputPlugins = inputPlugins/mp3_plugin.c inputPlugins/ogg_plugin.c \
|
||||
inputPlugins/flac_plugin.c
|
||||
|
||||
mpd_headers = buffer2array.h interface.h command.h playlist.h ls.h \
|
||||
song.h list.h directory.h tables.h utils.h path.h \
|
||||
tag.h player.h listen.h conf.h volume.h flac_decode.h \
|
||||
tag.h player.h listen.h conf.h volume.h \
|
||||
audio.h playerData.h stats.h myfprintf.h sig_handlers.h decode.h log.h \
|
||||
audiofile_decode.h charConv.h permission.h mpd_types.h pcm_utils.h \
|
||||
mp4_decode.h aac_decode.h signal_check.h utf8.h inputStream.h \
|
||||
@ -13,7 +14,7 @@ mpd_headers = buffer2array.h interface.h command.h playlist.h ls.h \
|
||||
inputPlugin.h
|
||||
mpd_SOURCES = main.c buffer2array.c interface.c command.c playlist.c ls.c \
|
||||
song.c list.c directory.c tables.c utils.c path.c \
|
||||
tag.c player.c listen.c conf.c volume.c flac_decode.c \
|
||||
tag.c player.c listen.c conf.c volume.c \
|
||||
audio.c playerData.c stats.c myfprintf.c sig_handlers.c decode.c log.c \
|
||||
audiofile_decode.c charConv.c permission.c pcm_utils.c mp4_decode.c \
|
||||
aac_decode.c signal_check.c utf8.c inputStream.c outputBuffer.c \
|
||||
|
@ -1,31 +0,0 @@
|
||||
/* the Music Player Daemon (MPD)
|
||||
* (c)2003-2004 by Warren Dukes (shank@mercury.chem.pitt.edu)
|
||||
* This project's homepage is: http://www.musicpd.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef FLAC_DECODE_H
|
||||
#define FLAC_DECODE_H
|
||||
|
||||
#include "../config.h"
|
||||
|
||||
#include "playerData.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int flac_decode(OutputBuffer * cb, DecoderControl * dc);
|
||||
|
||||
#endif
|
||||
/* vim:set shiftwidth=8 tabstop=8 expandtab: */
|
@ -69,6 +69,7 @@ InputPlugin * getInputPluginFromName(char * name) {
|
||||
|
||||
extern InputPlugin mp3Plugin;
|
||||
extern InputPlugin oggPlugin;
|
||||
extern InputPlugin flacPlugin;
|
||||
|
||||
void initInputPlugins() {
|
||||
inputPlugin_list = makeList(NULL);
|
||||
@ -76,6 +77,7 @@ void initInputPlugins() {
|
||||
/* load plugins here */
|
||||
loadInputPlugin(&mp3Plugin);
|
||||
loadInputPlugin(&oggPlugin);
|
||||
loadInputPlugin(&flacPlugin);
|
||||
}
|
||||
|
||||
void finishInputPlugins() {
|
||||
|
@ -16,17 +16,18 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "flac_decode.h"
|
||||
#include "../inputPlugin.h"
|
||||
|
||||
#ifdef HAVE_FLAC
|
||||
|
||||
#include "utils.h"
|
||||
#include "log.h"
|
||||
#include "pcm_utils.h"
|
||||
#include "inputStream.h"
|
||||
#include "outputBuffer.h"
|
||||
#include "replayGain.h"
|
||||
#include "audio.h"
|
||||
#include "../utils.h"
|
||||
#include "../log.h"
|
||||
#include "../pcm_utils.h"
|
||||
#include "../inputStream.h"
|
||||
#include "../outputBuffer.h"
|
||||
#include "../replayGain.h"
|
||||
#include "../audio.h"
|
||||
#include "../path.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -437,5 +438,143 @@ FLAC__StreamDecoderWriteStatus flacWrite(const FLAC__SeekableStreamDecoder *dec,
|
||||
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
||||
}
|
||||
|
||||
MpdTag * flacMetadataDup(char * utf8file, int * vorbisCommentFound) {
|
||||
MpdTag * ret = NULL;
|
||||
FLAC__Metadata_SimpleIterator * it;
|
||||
FLAC__StreamMetadata * block = NULL;
|
||||
int offset;
|
||||
int len, pos;
|
||||
|
||||
*vorbisCommentFound = 0;
|
||||
|
||||
it = FLAC__metadata_simple_iterator_new();
|
||||
if(!FLAC__metadata_simple_iterator_init(it,rmp2amp(utf8ToFsCharset(utf8file)),1,0)) {
|
||||
FLAC__metadata_simple_iterator_delete(it);
|
||||
return ret;
|
||||
}
|
||||
|
||||
do {
|
||||
block = FLAC__metadata_simple_iterator_get_block(it);
|
||||
if(!block) break;
|
||||
if(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
|
||||
char * dup;
|
||||
|
||||
offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block,0,"artist");
|
||||
if(offset>=0) {
|
||||
*vorbisCommentFound = 1;
|
||||
if(!ret) ret = newMpdTag();
|
||||
pos = strlen("artist=");
|
||||
len = block->data.vorbis_comment.comments[offset].length-pos;
|
||||
if(len>0) {
|
||||
dup = malloc(len+1);
|
||||
memcpy(dup,&(block->data.vorbis_comment.comments[offset].entry[pos]),len);
|
||||
dup[len] = '\0';
|
||||
stripReturnChar(dup);
|
||||
ret->artist = dup;
|
||||
}
|
||||
}
|
||||
offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block,0,"album");
|
||||
if(offset>=0) {
|
||||
*vorbisCommentFound = 1;
|
||||
if(!ret) ret = newMpdTag();
|
||||
pos = strlen("album=");
|
||||
len = block->data.vorbis_comment.comments[offset].length-pos;
|
||||
if(len>0) {
|
||||
dup = malloc(len+1);
|
||||
memcpy(dup,&(block->data.vorbis_comment.comments[offset].entry[pos]),len);
|
||||
dup[len] = '\0';
|
||||
stripReturnChar(dup);
|
||||
ret->album = dup;
|
||||
}
|
||||
}
|
||||
offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block,0,"title");
|
||||
if(offset>=0) {
|
||||
*vorbisCommentFound = 1;
|
||||
if(!ret) ret = newMpdTag();
|
||||
pos = strlen("title=");
|
||||
len = block->data.vorbis_comment.comments[offset].length-pos;
|
||||
if(len>0) {
|
||||
dup = malloc(len+1);
|
||||
memcpy(dup,&(block->data.vorbis_comment.comments[offset].entry[pos]),len);
|
||||
dup[len] = '\0';
|
||||
stripReturnChar(dup);
|
||||
ret->title = dup;
|
||||
}
|
||||
}
|
||||
offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block,0,"tracknumber");
|
||||
if(offset>=0) {
|
||||
*vorbisCommentFound = 1;
|
||||
if(!ret) ret = newMpdTag();
|
||||
pos = strlen("tracknumber=");
|
||||
len = block->data.vorbis_comment.comments[offset].length-pos;
|
||||
if(len>0) {
|
||||
dup = malloc(len+1);
|
||||
memcpy(dup,&(block->data.vorbis_comment.comments[offset].entry[pos]),len);
|
||||
dup[len] = '\0';
|
||||
stripReturnChar(dup);
|
||||
ret->track = dup;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(block->type == FLAC__METADATA_TYPE_STREAMINFO) {
|
||||
if(!ret) ret = newMpdTag();
|
||||
ret->time = ((float)block->data.stream_info.
|
||||
total_samples) /
|
||||
block->data.stream_info.sample_rate +
|
||||
0.5;
|
||||
}
|
||||
FLAC__metadata_object_delete(block);
|
||||
} while(FLAC__metadata_simple_iterator_next(it));
|
||||
|
||||
FLAC__metadata_simple_iterator_delete(it);
|
||||
return ret;
|
||||
}
|
||||
|
||||
MpdTag * flacTagDup(char * utf8file) {
|
||||
MpdTag * ret = NULL;
|
||||
int foundVorbisComment = 0;
|
||||
|
||||
ret = flacMetadataDup(utf8file,&foundVorbisComment);
|
||||
if(!ret) return NULL;
|
||||
if(!foundVorbisComment) {
|
||||
MpdTag * temp = id3Dup(utf8file);
|
||||
if(temp) {
|
||||
temp->time = ret->time;
|
||||
freeMpdTag(ret);
|
||||
ret = temp;
|
||||
}
|
||||
}
|
||||
|
||||
if(ret) validateUtf8Tag(ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char * flacSuffixes[] = {"flac", NULL};
|
||||
|
||||
InputPlugin flacPlugin =
|
||||
{
|
||||
"flac",
|
||||
NULL,
|
||||
flac_decode,
|
||||
flacTagDup,
|
||||
INPUT_PLUGIN_STREAM_FILE,
|
||||
flacSuffixes,
|
||||
NULL
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
InputPlugin flacPlugin =
|
||||
{
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
#endif
|
||||
/* vim:set shiftwidth=8 tabstop=8 expandtab: */
|
@ -651,6 +651,7 @@ InputPlugin mp3Plugin =
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
NULL,
|
||||
NULL
|
||||
|
@ -353,6 +353,7 @@ InputPlugin oggPlugin =
|
||||
|
||||
InputPlugin oggPlugin =
|
||||
{
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
|
114
src/tag.c
114
src/tag.c
@ -279,120 +279,6 @@ MpdTag * mp4TagDup(char * utf8file) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FLAC
|
||||
MpdTag * flacMetadataDup(char * utf8file, int * vorbisCommentFound) {
|
||||
MpdTag * ret = NULL;
|
||||
FLAC__Metadata_SimpleIterator * it;
|
||||
FLAC__StreamMetadata * block = NULL;
|
||||
int offset;
|
||||
int len, pos;
|
||||
|
||||
*vorbisCommentFound = 0;
|
||||
|
||||
it = FLAC__metadata_simple_iterator_new();
|
||||
if(!FLAC__metadata_simple_iterator_init(it,rmp2amp(utf8ToFsCharset(utf8file)),1,0)) {
|
||||
FLAC__metadata_simple_iterator_delete(it);
|
||||
return ret;
|
||||
}
|
||||
|
||||
do {
|
||||
block = FLAC__metadata_simple_iterator_get_block(it);
|
||||
if(!block) break;
|
||||
if(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
|
||||
char * dup;
|
||||
|
||||
offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block,0,"artist");
|
||||
if(offset>=0) {
|
||||
*vorbisCommentFound = 1;
|
||||
if(!ret) ret = newMpdTag();
|
||||
pos = strlen("artist=");
|
||||
len = block->data.vorbis_comment.comments[offset].length-pos;
|
||||
if(len>0) {
|
||||
dup = malloc(len+1);
|
||||
memcpy(dup,&(block->data.vorbis_comment.comments[offset].entry[pos]),len);
|
||||
dup[len] = '\0';
|
||||
stripReturnChar(dup);
|
||||
ret->artist = dup;
|
||||
}
|
||||
}
|
||||
offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block,0,"album");
|
||||
if(offset>=0) {
|
||||
*vorbisCommentFound = 1;
|
||||
if(!ret) ret = newMpdTag();
|
||||
pos = strlen("album=");
|
||||
len = block->data.vorbis_comment.comments[offset].length-pos;
|
||||
if(len>0) {
|
||||
dup = malloc(len+1);
|
||||
memcpy(dup,&(block->data.vorbis_comment.comments[offset].entry[pos]),len);
|
||||
dup[len] = '\0';
|
||||
stripReturnChar(dup);
|
||||
ret->album = dup;
|
||||
}
|
||||
}
|
||||
offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block,0,"title");
|
||||
if(offset>=0) {
|
||||
*vorbisCommentFound = 1;
|
||||
if(!ret) ret = newMpdTag();
|
||||
pos = strlen("title=");
|
||||
len = block->data.vorbis_comment.comments[offset].length-pos;
|
||||
if(len>0) {
|
||||
dup = malloc(len+1);
|
||||
memcpy(dup,&(block->data.vorbis_comment.comments[offset].entry[pos]),len);
|
||||
dup[len] = '\0';
|
||||
stripReturnChar(dup);
|
||||
ret->title = dup;
|
||||
}
|
||||
}
|
||||
offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block,0,"tracknumber");
|
||||
if(offset>=0) {
|
||||
*vorbisCommentFound = 1;
|
||||
if(!ret) ret = newMpdTag();
|
||||
pos = strlen("tracknumber=");
|
||||
len = block->data.vorbis_comment.comments[offset].length-pos;
|
||||
if(len>0) {
|
||||
dup = malloc(len+1);
|
||||
memcpy(dup,&(block->data.vorbis_comment.comments[offset].entry[pos]),len);
|
||||
dup[len] = '\0';
|
||||
stripReturnChar(dup);
|
||||
ret->track = dup;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(block->type == FLAC__METADATA_TYPE_STREAMINFO) {
|
||||
if(!ret) ret = newMpdTag();
|
||||
ret->time = ((float)block->data.stream_info.
|
||||
total_samples) /
|
||||
block->data.stream_info.sample_rate +
|
||||
0.5;
|
||||
}
|
||||
FLAC__metadata_object_delete(block);
|
||||
} while(FLAC__metadata_simple_iterator_next(it));
|
||||
|
||||
FLAC__metadata_simple_iterator_delete(it);
|
||||
return ret;
|
||||
}
|
||||
|
||||
MpdTag * flacTagDup(char * utf8file) {
|
||||
MpdTag * ret = NULL;
|
||||
int foundVorbisComment = 0;
|
||||
|
||||
ret = flacMetadataDup(utf8file,&foundVorbisComment);
|
||||
if(!ret) return NULL;
|
||||
if(!foundVorbisComment) {
|
||||
MpdTag * temp = id3Dup(utf8file);
|
||||
if(temp) {
|
||||
temp->time = ret->time;
|
||||
freeMpdTag(ret);
|
||||
ret = temp;
|
||||
}
|
||||
}
|
||||
|
||||
if(ret) validateUtf8Tag(ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
MpdTag * newMpdTag() {
|
||||
MpdTag * ret = malloc(sizeof(MpdTag));
|
||||
ret->album = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user