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