Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
86dc7929
Commit
86dc7929
authored
Jan 15, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flac: no CamelCase
Renamed types, functions, variables.
parent
a7461dc2
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
201 additions
and
183 deletions
+201
-183
_flac_common.c
src/decoder/_flac_common.c
+41
-36
_flac_common.h
src/decoder/_flac_common.h
+15
-11
flac_plugin.c
src/decoder/flac_plugin.c
+89
-80
oggflac_plugin.c
src/decoder/oggflac_plugin.c
+52
-52
decoder_list.c
src/decoder_list.c
+4
-4
No files found.
src/decoder/_flac_common.c
View file @
86dc7929
...
...
@@ -26,19 +26,21 @@
#include <FLAC/format.h>
#include <FLAC/metadata.h>
void
init_FlacData
(
FlacData
*
data
,
struct
decoder
*
decoder
,
struct
input_stream
*
inStream
)
void
flac_data_init
(
struct
flac_data
*
data
,
struct
decoder
*
decoder
,
struct
input_stream
*
input_stream
)
{
data
->
time
=
0
;
data
->
position
=
0
;
data
->
bit
R
ate
=
0
;
data
->
bit
_r
ate
=
0
;
data
->
decoder
=
decoder
;
data
->
in
Stream
=
inS
tream
;
data
->
replay
GainI
nfo
=
NULL
;
data
->
in
put_stream
=
input_s
tream
;
data
->
replay
_gain_i
nfo
=
NULL
;
data
->
tag
=
NULL
;
}
static
int
flacFindVorbisCommentFloat
(
const
FLAC__StreamMetadata
*
block
,
static
int
flac_find_float_comment
(
const
FLAC__StreamMetadata
*
block
,
const
char
*
cmnt
,
float
*
fl
)
{
int
offset
=
...
...
@@ -65,28 +67,29 @@ static int flacFindVorbisCommentFloat(const FLAC__StreamMetadata * block,
}
/* replaygain stuff by AliasMrJones */
static
void
flacParseReplayGain
(
const
FLAC__StreamMetadata
*
block
,
FlacData
*
data
)
static
void
flac_parse_replay_gain
(
const
FLAC__StreamMetadata
*
block
,
struct
flac_data
*
data
)
{
int
found
=
0
;
if
(
data
->
replay
GainI
nfo
)
replay_gain_info_free
(
data
->
replay
GainI
nfo
);
if
(
data
->
replay
_gain_i
nfo
)
replay_gain_info_free
(
data
->
replay
_gain_i
nfo
);
data
->
replay
GainI
nfo
=
replay_gain_info_new
();
data
->
replay
_gain_i
nfo
=
replay_gain_info_new
();
found
|=
flac
FindVorbisCommentFloa
t
(
block
,
"replaygain_album_gain"
,
&
data
->
replayGainI
nfo
->
tuples
[
REPLAY_GAIN_ALBUM
].
gain
);
found
|=
flac
FindVorbisCommentFloa
t
(
block
,
"replaygain_album_peak"
,
&
data
->
replayGainI
nfo
->
tuples
[
REPLAY_GAIN_ALBUM
].
peak
);
found
|=
flac
FindVorbisCommentFloa
t
(
block
,
"replaygain_track_gain"
,
&
data
->
replayGainI
nfo
->
tuples
[
REPLAY_GAIN_TRACK
].
gain
);
found
|=
flac
FindVorbisCommentFloa
t
(
block
,
"replaygain_track_peak"
,
&
data
->
replayGainI
nfo
->
tuples
[
REPLAY_GAIN_TRACK
].
peak
);
found
|=
flac
_find_float_commen
t
(
block
,
"replaygain_album_gain"
,
&
data
->
replay_gain_i
nfo
->
tuples
[
REPLAY_GAIN_ALBUM
].
gain
);
found
|=
flac
_find_float_commen
t
(
block
,
"replaygain_album_peak"
,
&
data
->
replay_gain_i
nfo
->
tuples
[
REPLAY_GAIN_ALBUM
].
peak
);
found
|=
flac
_find_float_commen
t
(
block
,
"replaygain_track_gain"
,
&
data
->
replay_gain_i
nfo
->
tuples
[
REPLAY_GAIN_TRACK
].
gain
);
found
|=
flac
_find_float_commen
t
(
block
,
"replaygain_track_peak"
,
&
data
->
replay_gain_i
nfo
->
tuples
[
REPLAY_GAIN_TRACK
].
peak
);
if
(
!
found
)
{
replay_gain_info_free
(
data
->
replay
GainI
nfo
);
data
->
replay
GainI
nfo
=
NULL
;
replay_gain_info_free
(
data
->
replay
_gain_i
nfo
);
data
->
replay
_gain_i
nfo
=
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_DISC_KEY
=
"discnumber"
;
static
unsigned
int
commentMatchesAddToTag
(
const
FLAC__StreamMetadata_VorbisComment_Entry
*
entry
,
unsigned
int
itemType
,
static
unsigned
int
flac_copy_vorbis_comment
(
const
FLAC__StreamMetadata_VorbisComment_Entry
*
entry
,
enum
tag_type
type
,
struct
tag
**
tag
)
{
const
char
*
str
;
size_t
slen
;
int
vlen
;
switch
(
itemT
ype
)
{
switch
(
t
ype
)
{
case
TAG_ITEM_TRACK
:
str
=
VORBIS_COMMENT_TRACK_KEY
;
break
;
...
...
@@ -112,7 +116,7 @@ static unsigned int commentMatchesAddToTag(const
str
=
VORBIS_COMMENT_DISC_KEY
;
break
;
default:
str
=
mpdTagItemKeys
[
itemT
ype
];
str
=
mpdTagItemKeys
[
t
ype
];
}
slen
=
strlen
(
str
);
vlen
=
entry
->
length
-
slen
-
1
;
...
...
@@ -122,7 +126,7 @@ static unsigned int commentMatchesAddToTag(const
if
(
!*
tag
)
*
tag
=
tag_new
();
tag_add_item_n
(
*
tag
,
itemT
ype
,
tag_add_item_n
(
*
tag
,
t
ype
,
(
char
*
)(
entry
->
entry
+
slen
+
1
),
vlen
);
return
1
;
...
...
@@ -131,7 +135,8 @@ static unsigned int commentMatchesAddToTag(const
return
0
;
}
struct
tag
*
copyVorbisCommentBlockToMpdTag
(
const
FLAC__StreamMetadata
*
block
,
struct
tag
*
flac_vorbis_comments_to_tag
(
const
FLAC__StreamMetadata
*
block
,
struct
tag
*
tag
)
{
unsigned
int
i
,
j
;
...
...
@@ -141,7 +146,7 @@ struct tag *copyVorbisCommentBlockToMpdTag(const FLAC__StreamMetadata * block,
for
(
i
=
block
->
data
.
vorbis_comment
.
num_comments
;
i
!=
0
;
--
i
)
{
for
(
j
=
TAG_NUM_OF_ITEM_TYPES
;
j
--
;)
{
if
(
commentMatchesAddToTag
(
comments
,
j
,
&
tag
))
if
(
flac_copy_vorbis_comment
(
comments
,
j
,
&
tag
))
break
;
}
comments
++
;
...
...
@@ -151,7 +156,7 @@ struct tag *copyVorbisCommentBlockToMpdTag(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
);
...
...
@@ -163,7 +168,7 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
data
->
total_time
=
((
float
)
si
->
total_samples
)
/
(
si
->
sample_rate
);
break
;
case
FLAC__METADATA_TYPE_VORBIS_COMMENT
:
flac
ParseReplayG
ain
(
block
,
data
);
flac
_parse_replay_g
ain
(
block
,
data
);
default:
break
;
}
...
...
@@ -171,7 +176,7 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
void
flac_error_common_cb
(
const
char
*
plugin
,
const
FLAC__StreamDecoderErrorStatus
status
,
G_GNUC_UNUSED
FlacData
*
data
)
struct
flac_data
*
data
)
{
if
(
decoder_get_command
(
data
->
decoder
)
==
DECODE_COMMAND_STOP
)
return
;
...
...
@@ -272,7 +277,7 @@ static void flac_convert(unsigned char *dest,
}
FLAC__StreamDecoderWriteStatus
flac_common_write
(
FlacD
ata
*
data
,
const
FLAC__Frame
*
frame
,
flac_common_write
(
struct
flac_d
ata
*
data
,
const
FLAC__Frame
*
frame
,
const
FLAC__int32
*
const
buf
[])
{
unsigned
int
c_samp
;
...
...
@@ -300,11 +305,11 @@ flac_common_write(FlacData *data, const FLAC__Frame * frame,
num_channels
,
bytes_per_sample
,
buf
,
c_samp
,
c_samp
+
num_samples
);
cmd
=
decoder_data
(
data
->
decoder
,
data
->
in
S
tream
,
cmd
=
decoder_data
(
data
->
decoder
,
data
->
in
put_s
tream
,
data
->
chunk
,
num_samples
*
bytes_per_channel
,
data
->
time
,
data
->
bit
R
ate
,
data
->
replay
GainI
nfo
);
data
->
time
,
data
->
bit
_r
ate
,
data
->
replay
_gain_i
nfo
);
switch
(
cmd
)
{
case
DECODE_COMMAND_NONE
:
case
DECODE_COMMAND_START
:
...
...
src/decoder/_flac_common.h
View file @
86dc7929
...
...
@@ -141,33 +141,37 @@ typedef size_t flac_read_status_size_t;
#define FLAC_CHUNK_SIZE 4080
typedef
struct
{
struct
flac_data
{
unsigned
char
chunk
[
FLAC_CHUNK_SIZE
];
float
time
;
unsigned
int
bit
R
ate
;
unsigned
int
bit
_r
ate
;
struct
audio_format
audio_format
;
float
total_time
;
FLAC__uint64
position
;
struct
decoder
*
decoder
;
struct
input_stream
*
in
S
tream
;
struct
replay_gain_info
*
replay
GainI
nfo
;
struct
input_stream
*
in
put_s
tream
;
struct
replay_gain_info
*
replay
_gain_i
nfo
;
struct
tag
*
tag
;
}
FlacData
;
};
/* initializes a given FlacData struct */
void
init_FlacData
(
FlacData
*
data
,
struct
decoder
*
decoder
,
struct
input_stream
*
inStream
);
void
flac_data_init
(
struct
flac_data
*
data
,
struct
decoder
*
decoder
,
struct
input_stream
*
input_stream
);
void
flac_metadata_common_cb
(
const
FLAC__StreamMetadata
*
block
,
FlacData
*
data
);
struct
flac_data
*
data
);
void
flac_error_common_cb
(
const
char
*
plugin
,
FLAC__StreamDecoderErrorStatus
status
,
FlacData
*
data
);
struct
flac_data
*
data
);
struct
tag
*
copyVorbisCommentBlockToMpdTag
(
const
FLAC__StreamMetadata
*
block
,
struct
tag
*
flac_vorbis_comments_to_tag
(
const
FLAC__StreamMetadata
*
block
,
struct
tag
*
tag
);
FLAC__StreamDecoderWriteStatus
flac_common_write
(
FlacD
ata
*
data
,
const
FLAC__Frame
*
frame
,
flac_common_write
(
struct
flac_d
ata
*
data
,
const
FLAC__Frame
*
frame
,
const
FLAC__int32
*
const
buf
[]);
#endif
/* _FLAC_COMMON_H */
src/decoder/flac_plugin.c
View file @
86dc7929
...
...
@@ -25,20 +25,21 @@
/* this code was based on flac123, from flac-tools */
static
flac_read_status
flacRead
(
G_GNUC_UNUSED
const
flac_decoder
*
flacDec
,
FLAC__byte
buf
[]
,
flac_read_status_size_t
*
bytes
,
static
flac_read_status
flac_read_cb
(
G_GNUC_UNUSED
const
flac_decoder
*
fd
,
FLAC__byte
buf
[],
flac_read_status_size_t
*
bytes
,
void
*
fdata
)
{
FlacData
*
data
=
(
FlacData
*
)
fdata
;
struct
flac_data
*
data
=
fdata
;
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
;
if
(
r
==
0
)
{
if
(
decoder_get_command
(
data
->
decoder
)
!=
DECODE_COMMAND_NONE
||
input_stream_eof
(
data
->
in
S
tream
))
input_stream_eof
(
data
->
in
put_s
tream
))
return
flac_read_status_eof
;
else
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
;
}
static
flac_seek_status
flacSeek
(
G_GNUC_UNUSED
const
flac_decoder
*
flacDec
,
FLAC__uint64
offset
,
void
*
fdata
)
static
flac_seek_status
flac_seek_cb
(
G_GNUC_UNUSED
const
flac_decoder
*
fd
,
FLAC__uint64
offset
,
void
*
fdata
)
{
FlacData
*
data
=
(
FlacD
ata
*
)
fdata
;
struct
flac_data
*
data
=
(
struct
flac_d
ata
*
)
fdata
;
if
(
!
input_stream_seek
(
data
->
in
S
tream
,
offset
,
SEEK_SET
))
if
(
!
input_stream_seek
(
data
->
in
put_s
tream
,
offset
,
SEEK_SET
))
return
flac_seek_status_error
;
return
flac_seek_status_ok
;
}
static
flac_tell_status
flacTell
(
G_GNUC_UNUSED
const
flac_decoder
*
flacDec
,
FLAC__uint64
*
offset
,
void
*
fdata
)
static
flac_tell_status
flac_tell_cb
(
G_GNUC_UNUSED
const
flac_decoder
*
fd
,
FLAC__uint64
*
offset
,
void
*
fdata
)
{
FlacData
*
data
=
(
FlacD
ata
*
)
fdata
;
struct
flac_data
*
data
=
(
struct
flac_d
ata
*
)
fdata
;
*
offset
=
(
long
)(
data
->
in
S
tream
->
offset
);
*
offset
=
(
long
)(
data
->
in
put_s
tream
->
offset
);
return
flac_tell_status_ok
;
}
static
flac_length_status
flacLength
(
G_GNUC_UNUSED
const
flac_decoder
*
flacDec
,
FLAC__uint64
*
length
,
void
*
fdata
)
static
flac_length_status
flac_length_cb
(
G_GNUC_UNUSED
const
flac_decoder
*
fd
,
FLAC__uint64
*
length
,
void
*
fdata
)
{
FlacData
*
data
=
(
FlacD
ata
*
)
fdata
;
struct
flac_data
*
data
=
(
struct
flac_d
ata
*
)
fdata
;
if
(
data
->
in
S
tream
->
size
<
0
)
if
(
data
->
in
put_s
tream
->
size
<
0
)
return
flac_length_status_unsupported
;
*
length
=
(
size_t
)
(
data
->
in
S
tream
->
size
);
*
length
=
(
size_t
)
(
data
->
in
put_s
tream
->
size
);
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
=
(
FlacD
ata
*
)
fdata
;
struct
flac_data
*
data
=
(
struct
flac_d
ata
*
)
fdata
;
return
(
decoder_get_command
(
data
->
decoder
)
!=
DECODE_COMMAND_NONE
&&
decoder_get_command
(
data
->
decoder
)
!=
DECODE_COMMAND_SEEK
)
||
input_stream_eof
(
data
->
in
S
tream
);
input_stream_eof
(
data
->
in
put_s
tream
);
}
static
void
flacError
(
G_GNUC_UNUSED
const
flac_decoder
*
dec
,
static
void
flac_error_cb
(
G_GNUC_UNUSED
const
flac_decoder
*
fd
,
FLAC__StreamDecoderErrorStatus
status
,
void
*
fdata
)
{
flac_error_common_cb
(
"flac"
,
status
,
(
FlacD
ata
*
)
fdata
);
flac_error_common_cb
(
"flac"
,
status
,
(
struct
flac_d
ata
*
)
fdata
);
}
#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
,
const
FLAC__StreamMetadata
*
block
,
void
*
vdata
)
{
flac_metadata_common_cb
(
block
,
(
FlacD
ata
*
)
vdata
);
flac_metadata_common_cb
(
block
,
(
struct
flac_d
ata
*
)
vdata
);
}
static
FLAC__StreamDecoderWriteStatus
flacWrite
(
const
flac_decoder
*
dec
,
const
FLAC__Frame
*
frame
,
const
FLAC__int32
*
const
buf
[],
void
*
vdata
)
static
FLAC__StreamDecoderWriteStatus
flac_write_cb
(
const
flac_decoder
*
dec
,
const
FLAC__Frame
*
frame
,
const
FLAC__int32
*
const
buf
[],
void
*
vdata
)
{
FLAC__uint32
samples
=
frame
->
header
.
blocksize
;
FlacData
*
data
=
(
FlacD
ata
*
)
vdata
;
struct
flac_data
*
data
=
(
struct
flac_d
ata
*
)
vdata
;
float
timeChange
;
FLAC__uint64
newPosition
=
0
;
...
...
@@ -216,7 +218,7 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec,
if
(
data
->
position
&&
newPosition
>=
data
->
position
)
{
assert
(
timeChange
>=
0
);
data
->
bit
R
ate
=
data
->
bit
_r
ate
=
((
newPosition
-
data
->
position
)
*
8
.
0
/
timeChange
)
/
1000
+
0
.
5
;
}
...
...
@@ -226,13 +228,13 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec,
}
static
struct
tag
*
flac
MetadataDup
(
const
char
*
file
,
bool
*
vorbisCommentF
ound
)
flac
_tag_load
(
const
char
*
file
,
bool
*
vorbis_comment_f
ound
)
{
struct
tag
*
ret
=
NULL
;
FLAC__Metadata_SimpleIterator
*
it
;
FLAC__StreamMetadata
*
block
=
NULL
;
*
vorbis
CommentF
ound
=
false
;
*
vorbis
_comment_f
ound
=
false
;
it
=
FLAC__metadata_simple_iterator_new
();
if
(
!
FLAC__metadata_simple_iterator_init
(
it
,
file
,
1
,
0
))
{
...
...
@@ -265,10 +267,10 @@ flacMetadataDup(const char *file, bool *vorbisCommentFound)
if
(
!
block
)
break
;
if
(
block
->
type
==
FLAC__METADATA_TYPE_VORBIS_COMMENT
)
{
ret
=
copyVorbisCommentBlockToMpdT
ag
(
block
,
ret
);
ret
=
flac_vorbis_comments_to_t
ag
(
block
,
ret
);
if
(
ret
)
*
vorbis
CommentF
ound
=
true
;
*
vorbis
_comment_f
ound
=
true
;
}
else
if
(
block
->
type
==
FLAC__METADATA_TYPE_STREAMINFO
)
{
if
(
!
ret
)
ret
=
tag_new
();
...
...
@@ -283,17 +285,18 @@ flacMetadataDup(const char *file, bool *vorbisCommentFound)
return
ret
;
}
static
struct
tag
*
flacTagDup
(
const
char
*
file
)
static
struct
tag
*
flac_tag_dup
(
const
char
*
file
)
{
struct
tag
*
ret
=
NULL
;
bool
foundVorbisComment
=
false
;
bool
vorbis_comment_found
=
false
;
ret
=
flac
MetadataDup
(
file
,
&
foundVorbisComment
);
ret
=
flac
_tag_load
(
file
,
&
vorbis_comment_found
);
if
(
!
ret
)
{
g_debug
(
"Failed to grab information from: %s
\n
"
,
file
);
return
NULL
;
}
if
(
!
foundVorbisComment
)
{
if
(
!
vorbis_comment_found
)
{
struct
tag
*
temp
=
tag_id3_load
(
file
);
if
(
temp
)
{
temp
->
time
=
ret
->
time
;
...
...
@@ -306,19 +309,20 @@ static struct tag *flacTagDup(const char *file)
}
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
)
{
flac_decoder
*
flac
D
ec
;
FlacD
ata
data
;
flac_decoder
*
flac
_d
ec
;
struct
flac_d
ata
data
;
const
char
*
err
=
NULL
;
if
(
!
(
flac
D
ec
=
flac_new
()))
if
(
!
(
flac
_d
ec
=
flac_new
()))
return
;
init_FlacData
(
&
data
,
decoder
,
inS
tream
);
flac_data_init
(
&
data
,
decoder
,
input_s
tream
);
#if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7
if
(
!
FLAC__stream_decoder_set_metadata_respond
(
flac
D
ec
,
FLAC__METADATA_TYPE_VORBIS_COMMENT
))
if
(
!
FLAC__stream_decoder_set_metadata_respond
(
flac
_d
ec
,
FLAC__METADATA_TYPE_VORBIS_COMMENT
))
{
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
(
!
flac_ogg_init
(
flacDec
,
flacRead
,
flacSeek
,
flacTell
,
flacLength
,
flacEOF
,
flacWrite
,
flacMetadata
,
flacError
,
(
void
*
)
&
data
))
{
if
(
!
flac_ogg_init
(
flac_dec
,
flac_read_cb
,
flac_seek_cb
,
flac_tell_cb
,
flac_length_cb
,
flac_eof_cb
,
flac_write_cb
,
flacMetadata
,
flac_error_cb
,
(
void
*
)
&
data
))
{
err
=
"doing Ogg init()"
;
goto
fail
;
}
}
else
{
if
(
!
flac_init
(
flacDec
,
flacRead
,
flacSeek
,
flacTell
,
flacLength
,
flacEOF
,
flacWrite
,
flacMetadata
,
flacError
,
(
void
*
)
&
data
))
{
if
(
!
flac_init
(
flac_dec
,
flac_read_cb
,
flac_seek_cb
,
flac_tell_cb
,
flac_length_cb
,
flac_eof_cb
,
flac_write_cb
,
flacMetadata
,
flac_error_cb
,
(
void
*
)
&
data
))
{
err
=
"doing init()"
;
goto
fail
;
}
}
if
(
!
flac_process_metadata
(
flac
D
ec
))
{
if
(
!
flac_process_metadata
(
flac
_d
ec
))
{
err
=
"problem reading metadata"
;
goto
fail
;
}
...
...
@@ -355,44 +363,44 @@ flac_decode_internal(struct decoder * decoder, struct input_stream *inStream,
}
decoder_initialized
(
decoder
,
&
data
.
audio_format
,
in
S
tream
->
seekable
,
data
.
total_time
);
in
put_s
tream
->
seekable
,
data
.
total_time
);
while
(
true
)
{
if
(
!
flac_process_single
(
flac
D
ec
))
if
(
!
flac_process_single
(
flac
_d
ec
))
break
;
if
(
decoder_get_command
(
decoder
)
==
DECODE_COMMAND_SEEK
)
{
FLAC__uint64
s
ampleToSeek
=
decoder_seek_where
(
decoder
)
*
FLAC__uint64
s
eek_sample
=
decoder_seek_where
(
decoder
)
*
data
.
audio_format
.
sample_rate
+
0
.
5
;
if
(
flac_seek_absolute
(
flac
Dec
,
sampleToSeek
))
{
data
.
time
=
((
float
)
s
ampleToSeek
)
/
if
(
flac_seek_absolute
(
flac
_dec
,
seek_sample
))
{
data
.
time
=
((
float
)
s
eek_sample
)
/
data
.
audio_format
.
sample_rate
;
data
.
position
=
0
;
decoder_command_finished
(
decoder
);
}
else
decoder_seek_error
(
decoder
);
}
else
if
(
flac_get_state
(
flac
D
ec
)
==
flac_decoder_eof
)
}
else
if
(
flac_get_state
(
flac
_d
ec
)
==
flac_decoder_eof
)
break
;
}
if
(
decoder_get_command
(
decoder
)
!=
DECODE_COMMAND_STOP
)
{
flacPrintErroredState
(
flac_get_state
(
flac
D
ec
));
flac_finish
(
flac
D
ec
);
flacPrintErroredState
(
flac_get_state
(
flac
_d
ec
));
flac_finish
(
flac
_d
ec
);
}
fail:
if
(
data
.
replay
GainI
nfo
)
replay_gain_info_free
(
data
.
replay
GainI
nfo
);
if
(
data
.
replay
_gain_i
nfo
)
replay_gain_info_free
(
data
.
replay
_gain_i
nfo
);
if
(
flac
D
ec
)
flac_delete
(
flac
D
ec
);
if
(
flac
_d
ec
)
flac_delete
(
flac
_d
ec
);
if
(
err
)
g_warning
(
"%s
\n
"
,
err
);
}
static
void
flac_decode
(
struct
decoder
*
decoder
,
struct
input_stream
*
in
S
tream
)
flac_decode
(
struct
decoder
*
decoder
,
struct
input_stream
*
in
put_s
tream
)
{
flac_decode_internal
(
decoder
,
in
S
tream
,
false
);
flac_decode_internal
(
decoder
,
in
put_s
tream
,
false
);
}
#ifndef HAVE_OGGFLAC
...
...
@@ -410,7 +418,8 @@ oggflac_init(void)
#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
;
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
)))
break
;
if
(
block
->
type
==
FLAC__METADATA_TYPE_VORBIS_COMMENT
)
{
ret
=
copyVorbisCommentBlockToMpdT
ag
(
block
,
ret
);
ret
=
flac_vorbis_comments_to_t
ag
(
block
,
ret
);
}
else
if
(
block
->
type
==
FLAC__METADATA_TYPE_STREAMINFO
)
{
if
(
!
ret
)
ret
=
tag_new
();
...
...
@@ -441,16 +450,16 @@ out:
}
static
void
oggflac_decode
(
struct
decoder
*
decoder
,
struct
input_stream
*
in
S
tream
)
oggflac_decode
(
struct
decoder
*
decoder
,
struct
input_stream
*
in
put_s
tream
)
{
if
(
ogg_stream_type_detect
(
in
S
tream
)
!=
FLAC
)
if
(
ogg_stream_type_detect
(
in
put_s
tream
)
!=
FLAC
)
return
;
/* rewind the stream, because ogg_stream_type_detect() has
moved it */
input_stream_seek
(
in
S
tream
,
0
,
SEEK_SET
);
input_stream_seek
(
in
put_s
tream
,
0
,
SEEK_SET
);
flac_decode_internal
(
decoder
,
in
S
tream
,
true
);
flac_decode_internal
(
decoder
,
in
put_s
tream
,
true
);
}
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 */
const
struct
decoder_plugin
oggflac
P
lugin
=
{
const
struct
decoder_plugin
oggflac
_decoder_p
lugin
=
{
.
name
=
"oggflac"
,
.
init
=
oggflac_init
,
#if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7
...
...
@@ -476,15 +485,15 @@ const struct decoder_plugin oggflacPlugin = {
#endif
/* HAVE_OGGFLAC */
static
const
char
*
const
flac
S
uffixes
[]
=
{
"flac"
,
NULL
};
static
const
char
*
const
flac
_s
uffixes
[]
=
{
"flac"
,
NULL
};
static
const
char
*
const
flac_mime_types
[]
=
{
"audio/x-flac"
,
"application/x-flac"
,
NULL
};
const
struct
decoder_plugin
flac
P
lugin
=
{
const
struct
decoder_plugin
flac
_decoder_p
lugin
=
{
.
name
=
"flac"
,
.
stream_decode
=
flac_decode
,
.
tag_dup
=
flac
TagD
up
,
.
suffixes
=
flac
S
uffixes
,
.
tag_dup
=
flac
_tag_d
up
,
.
suffixes
=
flac
_s
uffixes
,
.
mime_types
=
flac_mime_types
};
src/decoder/oggflac_plugin.c
View file @
86dc7929
...
...
@@ -26,11 +26,11 @@
#include <OggFLAC/seekable_stream_decoder.h>
#include <unistd.h>
static
void
oggflac_cleanup
(
FlacData
*
data
,
static
void
oggflac_cleanup
(
struct
flac_data
*
data
,
OggFLAC__SeekableStreamDecoder
*
decoder
)
{
if
(
data
->
replay
GainI
nfo
)
replay_gain_info_free
(
data
->
replay
GainI
nfo
);
if
(
data
->
replay
_gain_i
nfo
)
replay_gain_info_free
(
data
->
replay
_gain_i
nfo
);
if
(
decoder
)
OggFLAC__seekable_stream_decoder_delete
(
decoder
);
}
...
...
@@ -42,13 +42,14 @@ static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(G_GNUC_UNUSED const
unsigned
*
bytes
,
void
*
fdata
)
{
FlacData
*
data
=
(
FlacD
ata
*
)
fdata
;
struct
flac_data
*
data
=
(
struct
flac_d
ata
*
)
fdata
;
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
;
if
(
r
==
0
&&
!
input_stream_eof
(
data
->
in
S
tream
)
&&
if
(
r
==
0
&&
!
input_stream_eof
(
data
->
in
put_s
tream
)
&&
decoder_get_command
(
data
->
decoder
)
==
DECODE_COMMAND_NONE
)
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
,
void
*
fdata
)
{
FlacData
*
data
=
(
FlacD
ata
*
)
fdata
;
struct
flac_data
*
data
=
(
struct
flac_d
ata
*
)
fdata
;
if
(
!
input_stream_seek
(
data
->
in
S
tream
,
offset
,
SEEK_SET
))
if
(
!
input_stream_seek
(
data
->
in
put_s
tream
,
offset
,
SEEK_SET
))
return
OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR
;
return
OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK
;
...
...
@@ -75,9 +76,9 @@ static OggFLAC__SeekableStreamDecoderTellStatus of_tell_cb(G_GNUC_UNUSED const
FLAC__uint64
*
offset
,
void
*
fdata
)
{
FlacData
*
data
=
(
FlacD
ata
*
)
fdata
;
struct
flac_data
*
data
=
(
struct
flac_d
ata
*
)
fdata
;
*
offset
=
(
long
)(
data
->
in
S
tream
->
offset
);
*
offset
=
(
long
)(
data
->
in
put_s
tream
->
offset
);
return
OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK
;
}
...
...
@@ -89,12 +90,12 @@ static OggFLAC__SeekableStreamDecoderLengthStatus of_length_cb(G_GNUC_UNUSED con
length
,
void
*
fdata
)
{
FlacData
*
data
=
(
FlacD
ata
*
)
fdata
;
struct
flac_data
*
data
=
(
struct
flac_d
ata
*
)
fdata
;
if
(
data
->
in
S
tream
->
size
<
0
)
if
(
data
->
in
put_s
tream
->
size
<
0
)
return
OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR
;
*
length
=
(
size_t
)
(
data
->
in
S
tream
->
size
);
*
length
=
(
size_t
)
(
data
->
in
put_s
tream
->
size
);
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
,
void
*
fdata
)
{
FlacData
*
data
=
(
FlacD
ata
*
)
fdata
;
struct
flac_data
*
data
=
(
struct
flac_d
ata
*
)
fdata
;
return
(
decoder_get_command
(
data
->
decoder
)
!=
DECODE_COMMAND_NONE
&&
decoder_get_command
(
data
->
decoder
)
!=
DECODE_COMMAND_SEEK
)
||
input_stream_eof
(
data
->
in
S
tream
);
input_stream_eof
(
data
->
in
put_s
tream
);
}
static
void
of_error_cb
(
G_GNUC_UNUSED
const
OggFLAC__SeekableStreamDecoder
*
decoder
,
FLAC__StreamDecoderErrorStatus
status
,
void
*
fdata
)
{
flac_error_common_cb
(
"oggflac"
,
status
,
(
FlacD
ata
*
)
fdata
);
flac_error_common_cb
(
"oggflac"
,
status
,
(
struct
flac_d
ata
*
)
fdata
);
}
static
void
oggflacPrintErroredState
(
OggFLAC__SeekableStreamDecoderState
state
)
...
...
@@ -146,19 +147,17 @@ static void oggflacPrintErroredState(OggFLAC__SeekableStreamDecoderState state)
}
}
static
FLAC__StreamDecoderWriteStatus
oggflacWrite
(
G_GNUC_UNUSED
const
OggFLAC__SeekableStreamDecoder
*
decoder
,
const
FLAC__Frame
*
frame
,
const
FLAC__int32
*
const
buf
[],
void
*
vdata
)
static
FLAC__StreamDecoderWriteStatus
oggflac_write_cb
(
G_GNUC_UNUSED
const
OggFLAC__SeekableStreamDecoder
*
decoder
,
const
FLAC__Frame
*
frame
,
const
FLAC__int32
*
const
buf
[],
void
*
vdata
)
{
FlacData
*
data
=
(
FlacD
ata
*
)
vdata
;
struct
flac_data
*
data
=
(
struct
flac_d
ata
*
)
vdata
;
FLAC__uint32
samples
=
frame
->
header
.
blocksize
;
float
time
C
hange
;
float
time
_c
hange
;
time
C
hange
=
((
float
)
samples
)
/
frame
->
header
.
sample_rate
;
data
->
time
+=
time
C
hange
;
time
_c
hange
=
((
float
)
samples
)
/
frame
->
header
.
sample_rate
;
data
->
time
+=
time
_c
hange
;
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
,
const
FLAC__StreamMetadata
*
block
,
void
*
vdata
)
{
FlacData
*
data
=
(
FlacD
ata
*
)
vdata
;
struct
flac_data
*
data
=
(
struct
flac_d
ata
*
)
vdata
;
switch
(
block
->
type
)
{
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
;
return
;
case
FLAC__METADATA_TYPE_VORBIS_COMMENT
:
copyVorbisCommentBlockToMpdT
ag
(
block
,
data
->
tag
);
flac_vorbis_comments_to_t
ag
(
block
,
data
->
tag
);
default:
break
;
}
...
...
@@ -189,11 +188,11 @@ static void of_metadata_decode_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDec
const
FLAC__StreamMetadata
*
block
,
void
*
vdata
)
{
flac_metadata_common_cb
(
block
,
(
FlacD
ata
*
)
vdata
);
flac_metadata_common_cb
(
block
,
(
struct
flac_d
ata
*
)
vdata
);
}
static
OggFLAC__SeekableStreamDecoder
*
full_decoder_init_and_read_metadata
(
FlacData
*
data
,
static
OggFLAC__SeekableStreamDecoder
*
full_decoder_init_and_read_metadata
(
struct
flac_data
*
data
,
unsigned
int
metadata_only
)
{
OggFLAC__SeekableStreamDecoder
*
decoder
=
NULL
;
...
...
@@ -223,7 +222,7 @@ static OggFLAC__SeekableStreamDecoder
s
&=
OggFLAC__seekable_stream_decoder_set_eof_callback
(
decoder
,
of_EOF_cb
);
s
&=
OggFLAC__seekable_stream_decoder_set_write_callback
(
decoder
,
oggflac
Write
);
oggflac
_write_cb
);
s
&=
OggFLAC__seekable_stream_decoder_set_metadata_respond
(
decoder
,
FLAC__METADATA_TYPE_VORBIS_COMMENT
);
s
&=
OggFLAC__seekable_stream_decoder_set_error_callback
(
decoder
,
...
...
@@ -256,41 +255,42 @@ fail:
}
/* public functions: */
static
struct
tag
*
oggflac_TagDup
(
const
char
*
file
)
static
struct
tag
*
oggflac_tag_dup
(
const
char
*
file
)
{
struct
input_stream
in
S
tream
;
struct
input_stream
in
put_s
tream
;
OggFLAC__SeekableStreamDecoder
*
decoder
;
FlacD
ata
data
;
struct
flac_d
ata
data
;
if
(
!
input_stream_open
(
&
in
S
tream
,
file
))
if
(
!
input_stream_open
(
&
in
put_s
tream
,
file
))
return
NULL
;
if
(
ogg_stream_type_detect
(
&
in
S
tream
)
!=
FLAC
)
{
input_stream_close
(
&
in
S
tream
);
if
(
ogg_stream_type_detect
(
&
in
put_s
tream
)
!=
FLAC
)
{
input_stream_close
(
&
in
put_s
tream
);
return
NULL
;
}
init_FlacData
(
&
data
,
NULL
,
&
inS
tream
);
flac_data_init
(
&
data
,
NULL
,
&
input_s
tream
);
/* errors here won't matter,
* data.tag will be set or unset, that's all we care about */
decoder
=
full_decoder_init_and_read_metadata
(
&
data
,
1
);
oggflac_cleanup
(
&
data
,
decoder
);
input_stream_close
(
&
in
S
tream
);
input_stream_close
(
&
in
put_s
tream
);
return
data
.
tag
;
}
static
void
oggflac_decode
(
struct
decoder
*
mpd_decoder
,
struct
input_stream
*
in
S
tream
)
oggflac_decode
(
struct
decoder
*
mpd_decoder
,
struct
input_stream
*
in
put_s
tream
)
{
OggFLAC__SeekableStreamDecoder
*
decoder
=
NULL
;
FlacD
ata
data
;
struct
flac_d
ata
data
;
if
(
ogg_stream_type_detect
(
in
S
tream
)
!=
FLAC
)
if
(
ogg_stream_type_detect
(
in
put_s
tream
)
!=
FLAC
)
return
;
init_FlacData
(
&
data
,
mpd_decoder
,
inS
tream
);
flac_data_init
(
&
data
,
mpd_decoder
,
input_s
tream
);
if
(
!
(
decoder
=
full_decoder_init_and_read_metadata
(
&
data
,
0
)))
{
goto
fail
;
...
...
@@ -305,7 +305,7 @@ oggflac_decode(struct decoder * mpd_decoder, struct input_stream *inStream)
}
decoder_initialized
(
mpd_decoder
,
&
data
.
audio_format
,
in
S
tream
->
seekable
,
data
.
total_time
);
in
put_s
tream
->
seekable
,
data
.
total_time
);
while
(
true
)
{
OggFLAC__seekable_stream_decoder_process_single
(
decoder
);
...
...
@@ -314,11 +314,11 @@ oggflac_decode(struct decoder * mpd_decoder, struct input_stream *inStream)
break
;
}
if
(
decoder_get_command
(
mpd_decoder
)
==
DECODE_COMMAND_SEEK
)
{
FLAC__uint64
s
ampleToSeek
=
decoder_seek_where
(
mpd_decoder
)
*
FLAC__uint64
s
eek_sample
=
decoder_seek_where
(
mpd_decoder
)
*
data
.
audio_format
.
sample_rate
+
0
.
5
;
if
(
OggFLAC__seekable_stream_decoder_seek_absolute
(
decoder
,
s
ampleToSeek
))
{
data
.
time
=
((
float
)
s
ampleToSeek
)
/
(
decoder
,
s
eek_sample
))
{
data
.
time
=
((
float
)
s
eek_sample
)
/
data
.
audio_format
.
sample_rate
;
data
.
position
=
0
;
decoder_command_finished
(
mpd_decoder
);
...
...
@@ -337,7 +337,7 @@ fail:
oggflac_cleanup
(
&
data
,
decoder
);
}
static
const
char
*
const
oggflac_
S
uffixes
[]
=
{
"ogg"
,
"oga"
,
NULL
};
static
const
char
*
const
oggflac_
s
uffixes
[]
=
{
"ogg"
,
"oga"
,
NULL
};
static
const
char
*
const
oggflac_mime_types
[]
=
{
"audio/x-flac+ogg"
,
"application/ogg"
,
...
...
@@ -345,10 +345,10 @@ static const char *const oggflac_mime_types[] = {
NULL
};
const
struct
decoder_plugin
oggflac
P
lugin
=
{
const
struct
decoder_plugin
oggflac
_decoder_p
lugin
=
{
.
name
=
"oggflac"
,
.
stream_decode
=
oggflac_decode
,
.
tag_dup
=
oggflac_
TagD
up
,
.
suffixes
=
oggflac_
S
uffixes
,
.
tag_dup
=
oggflac_
tag_d
up
,
.
suffixes
=
oggflac_
s
uffixes
,
.
mime_types
=
oggflac_mime_types
};
src/decoder_list.c
View file @
86dc7929
...
...
@@ -25,8 +25,8 @@
extern
const
struct
decoder_plugin
mp3Plugin
;
extern
const
struct
decoder_plugin
vorbis_decoder_plugin
;
extern
const
struct
decoder_plugin
flac
P
lugin
;
extern
const
struct
decoder_plugin
oggflac
P
lugin
;
extern
const
struct
decoder_plugin
flac
_decoder_p
lugin
;
extern
const
struct
decoder_plugin
oggflac
_decoder_p
lugin
;
extern
const
struct
decoder_plugin
audiofilePlugin
;
extern
const
struct
decoder_plugin
mp4_plugin
;
extern
const
struct
decoder_plugin
aacPlugin
;
...
...
@@ -44,10 +44,10 @@ static const struct decoder_plugin *const decoder_plugins[] = {
&
vorbis_decoder_plugin
,
#endif
#if defined(HAVE_FLAC) || defined(HAVE_OGGFLAC)
&
oggflac
P
lugin
,
&
oggflac
_decoder_p
lugin
,
#endif
#ifdef HAVE_FLAC
&
flac
P
lugin
,
&
flac
_decoder_p
lugin
,
#endif
#ifdef HAVE_AUDIOFILE
&
audiofilePlugin
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment