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
ef9f832f
Commit
ef9f832f
authored
May 06, 2004
by
Warren Dukes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mp4/aac now use InputStream
git-svn-id:
https://svn.musicpd.org/mpd/trunk@925
09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent
9ca135d7
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
53 deletions
+56
-53
aac_decode.c
src/aac_decode.c
+22
-25
mp4_decode.c
src/mp4_decode.c
+17
-15
mp4_decode.h
src/mp4_decode.h
+5
-3
tag.c
src/tag.c
+12
-10
No files found.
src/aac_decode.c
View file @
ef9f832f
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#include "utils.h"
#include "utils.h"
#include "audio.h"
#include "audio.h"
#include "log.h"
#include "log.h"
#include "inputStream.h"
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <unistd.h>
...
@@ -35,12 +36,12 @@
...
@@ -35,12 +36,12 @@
/* all code here is either based on or copied from FAAD2's frontend code */
/* all code here is either based on or copied from FAAD2's frontend code */
typedef
struct
{
typedef
struct
{
InputStream
*
inStream
;
long
bytesIntoBuffer
;
long
bytesIntoBuffer
;
long
bytesConsumed
;
long
bytesConsumed
;
long
fileOffset
;
long
fileOffset
;
unsigned
char
*
buffer
;
unsigned
char
*
buffer
;
int
atEof
;
int
atEof
;
FILE
*
infile
;
}
AacBuffer
;
}
AacBuffer
;
void
fillAacBuffer
(
AacBuffer
*
b
)
{
void
fillAacBuffer
(
AacBuffer
*
b
)
{
...
@@ -53,8 +54,9 @@ void fillAacBuffer(AacBuffer *b) {
...
@@ -53,8 +54,9 @@ void fillAacBuffer(AacBuffer *b) {
}
}
if
(
!
b
->
atEof
)
{
if
(
!
b
->
atEof
)
{
bread
=
fread
((
void
*
)(
b
->
buffer
+
b
->
bytesIntoBuffer
),
1
,
bread
=
readFromInputStream
(
b
->
inStream
,
b
->
bytesConsumed
,
b
->
infile
);
(
void
*
)(
b
->
buffer
+
b
->
bytesIntoBuffer
),
1
,
b
->
bytesConsumed
);
if
(
bread
!=
b
->
bytesConsumed
)
b
->
atEof
=
1
;
if
(
bread
!=
b
->
bytesConsumed
)
b
->
atEof
=
1
;
b
->
bytesIntoBuffer
+=
bread
;
b
->
bytesIntoBuffer
+=
bread
;
}
}
...
@@ -132,7 +134,7 @@ int adtsParse(AacBuffer * b, float * length) {
...
@@ -132,7 +134,7 @@ int adtsParse(AacBuffer * b, float * length) {
return
1
;
return
1
;
}
}
void
initAacBuffer
(
FILE
*
fp
,
AacBuffer
*
b
,
float
*
length
,
void
initAacBuffer
(
InputStream
*
inStream
,
AacBuffer
*
b
,
float
*
length
,
size_t
*
retFileread
,
size_t
*
retTagsize
)
size_t
*
retFileread
,
size_t
*
retTagsize
)
{
{
size_t
fileread
;
size_t
fileread
;
...
@@ -143,17 +145,15 @@ void initAacBuffer(FILE * fp, AacBuffer * b, float * length,
...
@@ -143,17 +145,15 @@ void initAacBuffer(FILE * fp, AacBuffer * b, float * length,
memset
(
b
,
0
,
sizeof
(
AacBuffer
));
memset
(
b
,
0
,
sizeof
(
AacBuffer
));
b
->
in
file
=
fp
;
b
->
in
Stream
=
inStream
;
fseek
(
b
->
infile
,
0
,
SEEK_END
);
fileread
=
inStream
->
size
;
fileread
=
ftell
(
b
->
infile
);
fseek
(
b
->
infile
,
0
,
SEEK_SET
);
b
->
buffer
=
malloc
(
FAAD_MIN_STREAMSIZE
*
AAC_MAX_CHANNELS
);
b
->
buffer
=
malloc
(
FAAD_MIN_STREAMSIZE
*
AAC_MAX_CHANNELS
);
memset
(
b
->
buffer
,
0
,
FAAD_MIN_STREAMSIZE
*
AAC_MAX_CHANNELS
);
memset
(
b
->
buffer
,
0
,
FAAD_MIN_STREAMSIZE
*
AAC_MAX_CHANNELS
);
bread
=
fread
(
b
->
buffer
,
1
,
FAAD_MIN_STREAMSIZE
*
AAC_MAX_CHANNELS
,
bread
=
readFromInputStream
(
inStream
,
b
->
buffer
,
1
,
b
->
infile
);
FAAD_MIN_STREAMSIZE
*
AAC_MAX_CHANNELS
);
b
->
bytesIntoBuffer
=
bread
;
b
->
bytesIntoBuffer
=
bread
;
b
->
bytesConsumed
=
0
;
b
->
bytesConsumed
=
0
;
b
->
fileOffset
=
0
;
b
->
fileOffset
=
0
;
...
@@ -177,11 +177,10 @@ void initAacBuffer(FILE * fp, AacBuffer * b, float * length,
...
@@ -177,11 +177,10 @@ void initAacBuffer(FILE * fp, AacBuffer * b, float * length,
if
((
b
->
buffer
[
0
]
==
0xFF
)
&&
((
b
->
buffer
[
1
]
&
0xF6
)
==
0xF0
))
{
if
((
b
->
buffer
[
0
]
==
0xFF
)
&&
((
b
->
buffer
[
1
]
&
0xF6
)
==
0xF0
))
{
adtsParse
(
b
,
length
);
adtsParse
(
b
,
length
);
fseek
(
b
->
infile
,
tagsize
,
SEEK_SET
);
seekInputStream
(
b
->
inStream
,
tagsize
,
SEEK_SET
);
bread
=
fread
(
b
->
buffer
,
1
,
bread
=
readFromInputStream
(
b
->
inStream
,
b
->
buffer
,
1
,
FAAD_MIN_STREAMSIZE
*
AAC_MAX_CHANNELS
,
FAAD_MIN_STREAMSIZE
*
AAC_MAX_CHANNELS
);
b
->
infile
);
if
(
bread
!=
FAAD_MIN_STREAMSIZE
*
AAC_MAX_CHANNELS
)
b
->
atEof
=
1
;
if
(
bread
!=
FAAD_MIN_STREAMSIZE
*
AAC_MAX_CHANNELS
)
b
->
atEof
=
1
;
else
b
->
atEof
=
0
;
else
b
->
atEof
=
0
;
b
->
bytesIntoBuffer
=
bread
;
b
->
bytesIntoBuffer
=
bread
;
...
@@ -209,12 +208,12 @@ float getAacFloatTotalTime(char * file) {
...
@@ -209,12 +208,12 @@ float getAacFloatTotalTime(char * file) {
faacDecConfigurationPtr
config
;
faacDecConfigurationPtr
config
;
unsigned
long
sampleRate
;
unsigned
long
sampleRate
;
unsigned
char
channels
;
unsigned
char
channels
;
FILE
*
fp
=
fopen
(
file
,
"r"
)
;
InputStream
inStream
;
size_t
bread
;
size_t
bread
;
if
(
fp
==
NULL
)
return
-
1
;
if
(
openInputStreamFromFile
(
&
inStream
,
file
)
<
0
)
return
-
1
;
initAacBuffer
(
fp
,
&
b
,
&
length
,
&
fileread
,
&
tagsize
);
initAacBuffer
(
&
inStream
,
&
b
,
&
length
,
&
fileread
,
&
tagsize
);
if
(
length
<
0
)
{
if
(
length
<
0
)
{
decoder
=
faacDecOpen
();
decoder
=
faacDecOpen
();
...
@@ -236,7 +235,7 @@ float getAacFloatTotalTime(char * file) {
...
@@ -236,7 +235,7 @@ float getAacFloatTotalTime(char * file) {
}
}
if
(
b
.
buffer
)
free
(
b
.
buffer
);
if
(
b
.
buffer
)
free
(
b
.
buffer
);
fclose
(
b
.
infile
);
closeInputStream
(
&
inStream
);
return
length
;
return
length
;
}
}
...
@@ -270,15 +269,13 @@ int aac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
...
@@ -270,15 +269,13 @@ int aac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
int seekPositionFound = 0;*/
int seekPositionFound = 0;*/
mpd_uint16
bitRate
=
0
;
mpd_uint16
bitRate
=
0
;
AacBuffer
b
;
AacBuffer
b
;
FILE
*
fp
;
InputStream
inStream
;
if
((
totalTime
=
getAacFloatTotalTime
(
dc
->
file
))
<
0
)
return
-
1
;
if
((
totalTime
=
getAacFloatTotalTime
(
dc
->
file
))
<
0
)
return
-
1
;
fp
=
fopen
(
dc
->
file
,
"r"
)
;
if
(
openInputStreamFromFile
(
&
inStream
,
dc
->
file
)
<
0
)
return
-
1
;
if
(
fp
==
NULL
)
return
-
1
;
initAacBuffer
(
&
inStream
,
&
b
,
NULL
,
NULL
,
NULL
);
initAacBuffer
(
fp
,
&
b
,
NULL
,
NULL
,
NULL
);
decoder
=
faacDecOpen
();
decoder
=
faacDecOpen
();
...
@@ -303,7 +300,7 @@ int aac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
...
@@ -303,7 +300,7 @@ int aac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
if
(
bread
<
0
)
{
if
(
bread
<
0
)
{
ERROR
(
"Error not a AAC stream.
\n
"
);
ERROR
(
"Error not a AAC stream.
\n
"
);
faacDecClose
(
decoder
);
faacDecClose
(
decoder
);
fclose
(
b
.
infile
);
closeInputStream
(
b
.
inStream
);
if
(
b
.
buffer
)
free
(
b
.
buffer
);
if
(
b
.
buffer
)
free
(
b
.
buffer
);
return
-
1
;
return
-
1
;
}
}
...
@@ -404,7 +401,7 @@ int aac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
...
@@ -404,7 +401,7 @@ int aac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
}
while
(
!
eof
);
}
while
(
!
eof
);
faacDecClose
(
decoder
);
faacDecClose
(
decoder
);
fclose
(
b
.
infile
);
closeInputStream
(
b
.
inStream
);
if
(
b
.
buffer
)
free
(
b
.
buffer
);
if
(
b
.
buffer
)
free
(
b
.
buffer
);
if
(
dc
->
start
)
return
-
1
;
if
(
dc
->
start
)
return
-
1
;
...
...
src/mp4_decode.c
View file @
ef9f832f
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
#include "audio.h"
#include "audio.h"
#include "log.h"
#include "log.h"
#include "pcm_utils.h"
#include "pcm_utils.h"
#include "inputStream.h"
#include "mp4ff/mp4ff.h"
#include "mp4ff/mp4ff.h"
...
@@ -72,17 +73,18 @@ int mp4_getAACTrack(mp4ff_t *infile) {
...
@@ -72,17 +73,18 @@ int mp4_getAACTrack(mp4ff_t *infile) {
return
-
1
;
return
-
1
;
}
}
uint32_t
mp4_readCallback
(
void
*
user_data
,
void
*
buffer
,
uint32_t
length
)
{
uint32_t
mp4_inputStreamReadCallback
(
void
*
inStream
,
void
*
buffer
,
return
fread
(
buffer
,
1
,
length
,
(
FILE
*
)
user_data
);
uint32_t
length
)
{
return
readFromInputStream
((
InputStream
*
)
inStream
,
buffer
,
1
,
length
);
}
}
uint32_t
mp4_
seekCallback
(
void
*
user_data
,
uint64_t
position
)
{
uint32_t
mp4_
inputStreamSeekCallback
(
void
*
inStream
,
uint64_t
position
)
{
return
fseek
((
FILE
*
)
user_data
,
position
,
SEEK_SET
);
return
seekInputStream
((
InputStream
*
)
inStream
,
position
,
SEEK_SET
);
}
}
int
mp4_decode
(
Buffer
*
cb
,
AudioFormat
*
af
,
DecoderControl
*
dc
)
{
int
mp4_decode
(
Buffer
*
cb
,
AudioFormat
*
af
,
DecoderControl
*
dc
)
{
FILE
*
fh
;
mp4ff_t
*
mp4fh
;
mp4ff_t
*
mp4fh
;
mp4ff_callback_t
*
mp4cb
;
mp4ff_callback_t
*
mp4cb
;
int32_t
track
;
int32_t
track
;
...
@@ -109,23 +111,23 @@ int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
...
@@ -109,23 +111,23 @@ int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
int
seekPositionFound
=
0
;
int
seekPositionFound
=
0
;
long
offset
;
long
offset
;
mpd_uint16
bitRate
=
0
;
mpd_uint16
bitRate
=
0
;
InputStream
inStream
;
fh
=
fopen
(
dc
->
file
,
"r"
);
if
(
openInputStreamFromFile
(
&
inStream
,
dc
->
file
)
<
0
)
{
if
(
!
fh
)
{
ERROR
(
"failed to open %s
\n
"
,
dc
->
file
);
ERROR
(
"failed to open %s
\n
"
,
dc
->
file
);
return
-
1
;
return
-
1
;
}
}
mp4cb
=
malloc
(
sizeof
(
mp4ff_callback_t
));
mp4cb
=
malloc
(
sizeof
(
mp4ff_callback_t
));
mp4cb
->
read
=
mp4_
r
eadCallback
;
mp4cb
->
read
=
mp4_
inputStreamR
eadCallback
;
mp4cb
->
seek
=
mp4_
s
eekCallback
;
mp4cb
->
seek
=
mp4_
inputStreamS
eekCallback
;
mp4cb
->
user_data
=
fh
;
mp4cb
->
user_data
=
&
inStream
;
mp4fh
=
mp4ff_open_read
(
mp4cb
);
mp4fh
=
mp4ff_open_read
(
mp4cb
);
if
(
!
mp4fh
)
{
if
(
!
mp4fh
)
{
ERROR
(
"Input does not appear to be a mp4 stream.
\n
"
);
ERROR
(
"Input does not appear to be a mp4 stream.
\n
"
);
free
(
mp4cb
);
free
(
mp4cb
);
fclose
(
fh
);
closeInputStream
(
&
inStream
);
return
-
1
;
return
-
1
;
}
}
...
@@ -133,7 +135,7 @@ int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
...
@@ -133,7 +135,7 @@ int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
if
(
track
<
0
)
{
if
(
track
<
0
)
{
ERROR
(
"No AAC track found in mp4 stream.
\n
"
);
ERROR
(
"No AAC track found in mp4 stream.
\n
"
);
mp4ff_close
(
mp4fh
);
mp4ff_close
(
mp4fh
);
fclose
(
fh
);
closeInputStream
(
&
inStream
);
free
(
mp4cb
);
free
(
mp4cb
);
return
-
1
;
return
-
1
;
}
}
...
@@ -163,7 +165,7 @@ int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
...
@@ -163,7 +165,7 @@ int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
faacDecClose
(
decoder
);
faacDecClose
(
decoder
);
mp4ff_close
(
mp4fh
);
mp4ff_close
(
mp4fh
);
free
(
mp4cb
);
free
(
mp4cb
);
fclose
(
fh
);
closeInputStream
(
&
inStream
);
return
-
1
;
return
-
1
;
}
}
...
@@ -178,7 +180,7 @@ int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
...
@@ -178,7 +180,7 @@ int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
ERROR
(
"Error getting audio format of mp4 AAC track.
\n
"
);
ERROR
(
"Error getting audio format of mp4 AAC track.
\n
"
);
faacDecClose
(
decoder
);
faacDecClose
(
decoder
);
mp4ff_close
(
mp4fh
);
mp4ff_close
(
mp4fh
);
fclose
(
fh
);
closeInputStream
(
&
inStream
);
free
(
mp4cb
);
free
(
mp4cb
);
return
-
1
;
return
-
1
;
}
}
...
@@ -316,7 +318,7 @@ int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
...
@@ -316,7 +318,7 @@ int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
free
(
seekTable
);
free
(
seekTable
);
faacDecClose
(
decoder
);
faacDecClose
(
decoder
);
mp4ff_close
(
mp4fh
);
mp4ff_close
(
mp4fh
);
fclose
(
fh
);
closeInputStream
(
&
inStream
);
free
(
mp4cb
);
free
(
mp4cb
);
if
(
dc
->
start
)
return
-
1
;
if
(
dc
->
start
)
return
-
1
;
...
...
src/mp4_decode.h
View file @
ef9f832f
...
@@ -29,11 +29,13 @@
...
@@ -29,11 +29,13 @@
int
mp4_getAACTrack
(
mp4ff_t
*
infile
);
int
mp4_getAACTrack
(
mp4ff_t
*
infile
);
uint32_t
mp4_readCallback
(
void
*
user_data
,
void
*
buffer
,
uint32_t
length
);
int
mp4_decode
(
Buffer
*
cb
,
AudioFormat
*
af
,
DecoderControl
*
dc
);
uint32_t
mp4_seekCallback
(
void
*
user_data
,
uint64_t
position
);
uint32_t
mp4_inputStreamReadCallback
(
void
*
inStream
,
void
*
buffer
,
uint32_t
length
);
uint32_t
mp4_inputStreamSeekCallback
(
void
*
inStream
,
uint64_t
position
);
int
mp4_decode
(
Buffer
*
cb
,
AudioFormat
*
af
,
DecoderControl
*
dc
);
#endif
/* HAVE_FAAD */
#endif
/* HAVE_FAAD */
...
...
src/tag.c
View file @
ef9f832f
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#include "utils.h"
#include "utils.h"
#include "utf8.h"
#include "utf8.h"
#include "log.h"
#include "log.h"
#include "inputStream.h"
#include <sys/stat.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdlib.h>
...
@@ -209,7 +210,7 @@ MpdTag * aacTagDup(char * utf8file) {
...
@@ -209,7 +210,7 @@ MpdTag * aacTagDup(char * utf8file) {
MpdTag
*
mp4DataDup
(
char
*
utf8file
,
int
*
mp4MetadataFound
)
{
MpdTag
*
mp4DataDup
(
char
*
utf8file
,
int
*
mp4MetadataFound
)
{
MpdTag
*
ret
=
NULL
;
MpdTag
*
ret
=
NULL
;
FILE
*
fh
;
InputStream
inStream
;
mp4ff_t
*
mp4fh
;
mp4ff_t
*
mp4fh
;
mp4ff_callback_t
*
cb
;
mp4ff_callback_t
*
cb
;
int32_t
track
;
int32_t
track
;
...
@@ -218,27 +219,28 @@ MpdTag * mp4DataDup(char * utf8file, int * mp4MetadataFound) {
...
@@ -218,27 +219,28 @@ MpdTag * mp4DataDup(char * utf8file, int * mp4MetadataFound) {
*
mp4MetadataFound
=
0
;
*
mp4MetadataFound
=
0
;
fh
=
fopen
(
rmp2amp
(
utf8ToFsCharset
(
utf8file
)),
"r"
);
if
(
openInputStreamFromFile
(
&
inStream
,
rmp2amp
(
utf8ToFsCharset
(
utf8file
)))
if
(
!
fh
)
{
<
0
)
{
return
NULL
;
return
NULL
;
}
}
cb
=
malloc
(
sizeof
(
mp4ff_callback_t
));
cb
=
malloc
(
sizeof
(
mp4ff_callback_t
));
cb
->
read
=
mp4_
r
eadCallback
;
cb
->
read
=
mp4_
inputStreamR
eadCallback
;
cb
->
seek
=
mp4_
s
eekCallback
;
cb
->
seek
=
mp4_
inputStreamS
eekCallback
;
cb
->
user_data
=
fh
;
cb
->
user_data
=
&
inStream
;
mp4fh
=
mp4ff_open_read
(
cb
);
mp4fh
=
mp4ff_open_read
(
cb
);
if
(
!
mp4fh
)
{
if
(
!
mp4fh
)
{
free
(
cb
);
free
(
cb
);
fclose
(
fh
);
closeInputStream
(
&
inStream
);
return
NULL
;
return
NULL
;
}
}
track
=
mp4_getAACTrack
(
mp4fh
);
track
=
mp4_getAACTrack
(
mp4fh
);
if
(
track
<
0
)
{
if
(
track
<
0
)
{
mp4ff_close
(
mp4fh
);
mp4ff_close
(
mp4fh
);
fclose
(
fh
);
closeInputStream
(
&
inStream
);
free
(
cb
);
free
(
cb
);
return
NULL
;
return
NULL
;
}
}
...
@@ -248,7 +250,7 @@ MpdTag * mp4DataDup(char * utf8file, int * mp4MetadataFound) {
...
@@ -248,7 +250,7 @@ MpdTag * mp4DataDup(char * utf8file, int * mp4MetadataFound) {
scale
=
mp4ff_time_scale
(
mp4fh
,
track
);
scale
=
mp4ff_time_scale
(
mp4fh
,
track
);
if
(
scale
<
0
)
{
if
(
scale
<
0
)
{
mp4ff_close
(
mp4fh
);
mp4ff_close
(
mp4fh
);
fclose
(
fh
);
closeInputStream
(
&
inStream
);
free
(
cb
);
free
(
cb
);
freeMpdTag
(
ret
);
freeMpdTag
(
ret
);
return
NULL
;
return
NULL
;
...
@@ -272,7 +274,7 @@ MpdTag * mp4DataDup(char * utf8file, int * mp4MetadataFound) {
...
@@ -272,7 +274,7 @@ MpdTag * mp4DataDup(char * utf8file, int * mp4MetadataFound) {
}
}
mp4ff_close
(
mp4fh
);
mp4ff_close
(
mp4fh
);
fclose
(
fh
);
closeInputStream
(
&
inStream
);
free
(
cb
);
free
(
cb
);
return
ret
;
return
ret
;
...
...
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