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
659df586
Commit
659df586
authored
May 04, 2004
by
Warren Dukes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement input abstraction for ogg and mp3
git-svn-id:
https://svn.musicpd.org/mpd/trunk@904
09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent
638817fc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
27 deletions
+52
-27
inputStream.c
src/inputStream.c
+8
-13
inputStream.h
src/inputStream.h
+5
-5
mp3_decode.c
src/mp3_decode.c
+4
-5
ogg_decode.c
src/ogg_decode.c
+35
-4
No files found.
src/inputStream.c
View file @
659df586
...
...
@@ -23,7 +23,7 @@
#include <unistd.h>
#include <errno.h>
int
init
InputStreamFromFile
(
InputStream
*
inStream
,
char
*
filename
)
{
int
open
InputStreamFromFile
(
InputStream
*
inStream
,
char
*
filename
)
{
inStream
->
fp
=
fopen
(
filename
,
"r"
);
if
(
!
inStream
->
fp
)
{
inStream
->
error
=
errno
;
...
...
@@ -39,14 +39,9 @@ int initInputStreamFromFile(InputStream * inStream, char * filename) {
return
0
;
}
int
seekInputStream
(
InputStream
*
inStream
,
long
offset
)
{
if
(
offset
<
0
)
{
inStream
->
error
=
EINVAL
;
return
-
1
;
}
if
(
fseek
(
inStream
->
fp
,
offset
,
SEEK_SET
)
==
0
)
{
inStream
->
offset
=
offset
;
int
seekInputStream
(
InputStream
*
inStream
,
long
offset
,
int
whence
)
{
if
(
fseek
(
inStream
->
fp
,
offset
,
whence
)
==
0
)
{
inStream
->
offset
=
ftell
(
inStream
->
fp
);
}
else
{
inStream
->
error
=
errno
;
...
...
@@ -56,19 +51,19 @@ int seekInputStream(InputStream * inStream, long offset) {
return
0
;
}
size_t
fillBufferFromInputStream
(
InputStream
*
inStream
,
char
*
buffer
,
size_t
buflen
)
size_t
readFromInputStream
(
InputStream
*
inStream
,
void
*
ptr
,
size_t
size
,
size_t
nmemb
)
{
size_t
readSize
;
readSize
=
fread
(
buffer
,
1
,
buflen
,
inStream
->
fp
);
readSize
=
fread
(
ptr
,
size
,
nmemb
,
inStream
->
fp
);
if
(
readSize
>
0
)
inStream
->
offset
+=
readSize
;
return
readSize
;
}
int
finish
InputStream
(
InputStream
*
inStream
)
{
int
close
InputStream
(
InputStream
*
inStream
)
{
if
(
fclose
(
inStream
->
fp
)
<
0
)
{
inStream
->
error
=
errno
;
}
...
...
src/inputStream.h
View file @
659df586
...
...
@@ -31,11 +31,11 @@ typedef struct _InputStream {
/* if an error occurs for these 3 functions, then -1 is returned and errno
for the input stream is set */
int
init
InputStreamFromFile
(
InputStream
*
inStream
,
char
*
filename
);
int
seekInputStream
(
InputStream
*
inStream
,
long
offset
);
int
finish
InputStream
(
InputStream
*
inStream
);
int
open
InputStreamFromFile
(
InputStream
*
inStream
,
char
*
filename
);
int
seekInputStream
(
InputStream
*
inStream
,
long
offset
,
int
whence
);
int
close
InputStream
(
InputStream
*
inStream
);
size_t
fillBufferFromInputStream
(
InputStream
*
inStream
,
char
*
buffer
,
size_t
buflen
);
size_t
readFromInputStream
(
InputStream
*
inStream
,
void
*
ptr
,
size_t
size
,
size_t
nmemb
);
#endif
src/mp3_decode.c
View file @
659df586
...
...
@@ -136,7 +136,7 @@ typedef struct _mp3DecodeData {
int
initMp3DecodeData
(
mp3DecodeData
*
data
,
char
*
file
)
{
int
ret
;
while
(((
ret
=
init
InputStreamFromFile
(
&
(
data
->
inStream
),
file
))
<
0
)
&&
while
(((
ret
=
open
InputStreamFromFile
(
&
(
data
->
inStream
),
file
))
<
0
)
&&
data
->
inStream
.
error
==
EINTR
);
if
(
ret
<
0
)
return
-
1
;
...
...
@@ -164,7 +164,7 @@ int fillMp3InputBuffer(mp3DecodeData * data, long offset) {
unsigned
char
*
readStart
;
if
(
offset
>=
0
)
{
seekInputStream
(
&
(
data
->
inStream
),
offset
);
seekInputStream
(
&
(
data
->
inStream
),
offset
,
SEEK_SET
);
}
if
(
offset
==-
1
&&
(
data
->
stream
).
next_frame
!=
NULL
)
{
...
...
@@ -179,8 +179,7 @@ int fillMp3InputBuffer(mp3DecodeData * data, long offset) {
remaining
=
0
;
}
readSize
=
fillBufferFromInputStream
(
&
(
data
->
inStream
),
readStart
,
readSize
);
readSize
=
readFromInputStream
(
&
(
data
->
inStream
),
readStart
,
1
,
readSize
);
if
(
readSize
<=
0
)
return
-
1
;
mad_stream_buffer
(
&
data
->
stream
,
data
->
readBuffer
,
readSize
+
remaining
);
...
...
@@ -375,7 +374,7 @@ void mp3DecodeDataFinalize(mp3DecodeData * data) {
mad_frame_finish
(
&
data
->
frame
);
mad_stream_finish
(
&
data
->
stream
);
while
(
finish
InputStream
(
&
(
data
->
inStream
))
<
0
&&
while
(
close
InputStream
(
&
(
data
->
inStream
))
<
0
&&
data
->
inStream
.
error
==
EINTR
);
if
(
data
->
frameOffset
)
free
(
data
->
frameOffset
);
if
(
data
->
times
)
free
(
data
->
times
);
...
...
src/ogg_decode.c
View file @
659df586
...
...
@@ -25,12 +25,14 @@
#include "audio.h"
#include "log.h"
#include "pcm_utils.h"
#include "inputStream.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <vorbis/vorbisfile.h>
#include <errno.h>
#ifdef WORDS_BIGENDIAN
#define OGG_DECODE_USE_BIGENDIAN 1
...
...
@@ -38,6 +40,7 @@
#define OGG_DECODE_USE_BIGENDIAN 0
#endif
/* this is just for tag parsing for db import! */
int
getOggTotalTime
(
char
*
file
)
{
OggVorbis_File
vf
;
FILE
*
oggfp
;
...
...
@@ -57,19 +60,47 @@ int getOggTotalTime(char * file) {
return
totalTime
;
}
size_t
ogg_read_cb
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
inStream
)
{
size_t
ret
;
ret
=
readFromInputStream
((
InputStream
*
)
inStream
,
ptr
,
size
,
nmemb
);
if
(
ret
<
0
)
errno
=
((
InputStream
*
)
inStream
)
->
error
;
return
ret
;
}
int
ogg_seek_cb
(
void
*
inStream
,
ogg_int64_t
offset
,
int
whence
)
{
return
seekInputStream
((
InputStream
*
)
inStream
,
offset
,
whence
);
}
int
ogg_close_cb
(
void
*
inStream
)
{
return
closeInputStream
((
InputStream
*
)
inStream
);
}
long
ogg_tell_cb
(
void
*
inStream
)
{
return
((
InputStream
*
)
inStream
)
->
offset
;
}
int
ogg_decode
(
Buffer
*
cb
,
AudioFormat
*
af
,
DecoderControl
*
dc
)
{
OggVorbis_File
vf
;
FILE
*
oggfp
;
ov_callbacks
callbacks
;
InputStream
inStream
;
callbacks
.
read_func
=
ogg_read_cb
;
callbacks
.
seek_func
=
ogg_seek_cb
;
callbacks
.
close_func
=
ogg_close_cb
;
callbacks
.
tell_func
=
ogg_tell_cb
;
if
(
!
(
oggfp
=
fopen
(
dc
->
file
,
"r"
))
)
{
if
(
openInputStreamFromFile
(
&
inStream
,
dc
->
file
)
<
0
)
{
ERROR
(
"failed to open ogg
\n
"
);
return
-
1
;
}
if
(
ov_open
(
oggfp
,
&
vf
,
NULL
,
0
)
<
0
)
{
if
(
ov_open
_callbacks
(
&
inStream
,
&
vf
,
NULL
,
0
,
callbacks
)
<
0
)
{
ERROR
(
"Input does not appear to be an Ogg bit stream.
\n
"
);
fclose
(
oggfp
);
closeInputStream
(
&
inStream
);
return
-
1
;
}
...
...
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