Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
ffmpeg
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ffmpeg
Commits
fbd8e042
Commit
fbd8e042
authored
Apr 12, 2014
by
Alessandro Ghedini
Committed by
Anton Khirnov
Apr 17, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mp3dec: move XING/Info and VBRI parsing into their own functions
Signed-off-by:
Anton Khirnov
<
anton@khirnov.net
>
parent
ae43c10e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
35 deletions
+58
-35
mp3dec.c
libavformat/mp3dec.c
+58
-35
No files found.
libavformat/mp3dec.c
View file @
fbd8e042
...
...
@@ -39,6 +39,9 @@
typedef
struct
MP3DecContext
{
int
xing_toc
;
unsigned
frames
;
/* Total number of frames in file */
unsigned
size
;
/* Total number of bytes in the stream */
int
is_cbr
;
}
MP3DecContext
;
/* mp3 read */
...
...
@@ -125,18 +128,60 @@ static void read_xing_toc(AVFormatContext *s, int64_t filesize, int64_t duration
mp3
->
xing_toc
=
1
;
}
static
void
mp3_parse_info_tag
(
AVFormatContext
*
s
,
AVStream
*
st
,
MPADecodeHeader
*
c
,
uint32_t
spf
)
{
uint32_t
v
;
MP3DecContext
*
mp3
=
s
->
priv_data
;
const
int64_t
xing_offtbl
[
2
][
2
]
=
{{
32
,
17
},
{
17
,
9
}};
/* Check for Xing / Info tag */
avio_skip
(
s
->
pb
,
xing_offtbl
[
c
->
lsf
==
1
][
c
->
nb_channels
==
1
]);
v
=
avio_rb32
(
s
->
pb
);
mp3
->
is_cbr
=
v
==
MKBETAG
(
'I'
,
'n'
,
'f'
,
'o'
);
if
(
v
==
MKBETAG
(
'X'
,
'i'
,
'n'
,
'g'
)
||
mp3
->
is_cbr
)
{
v
=
avio_rb32
(
s
->
pb
);
if
(
v
&
XING_FLAG_FRAMES
)
mp3
->
frames
=
avio_rb32
(
s
->
pb
);
if
(
v
&
XING_FLAG_SIZE
)
mp3
->
size
=
avio_rb32
(
s
->
pb
);
if
(
v
&
XING_FLAG_TOC
&&
mp3
->
frames
)
read_xing_toc
(
s
,
mp3
->
size
,
av_rescale_q
(
mp3
->
frames
,
(
AVRational
){
spf
,
c
->
sample_rate
},
st
->
time_base
));
}
}
static
void
mp3_parse_vbri_tag
(
AVFormatContext
*
s
,
AVStream
*
st
,
int64_t
base
)
{
uint32_t
v
;
MP3DecContext
*
mp3
=
s
->
priv_data
;
/* Check for VBRI tag (always 32 bytes after end of mpegaudio header) */
avio_seek
(
s
->
pb
,
base
+
4
+
32
,
SEEK_SET
);
v
=
avio_rb32
(
s
->
pb
);
if
(
v
==
MKBETAG
(
'V'
,
'B'
,
'R'
,
'I'
))
{
/* Check tag version */
if
(
avio_rb16
(
s
->
pb
)
==
1
)
{
/* skip delay and quality */
avio_skip
(
s
->
pb
,
4
);
mp3
->
size
=
avio_rb32
(
s
->
pb
);
mp3
->
frames
=
avio_rb32
(
s
->
pb
);
}
}
}
/**
* Try to find Xing/Info/VBRI tags and compute duration from info therein
*/
static
int
mp3_parse_vbr_tags
(
AVFormatContext
*
s
,
AVStream
*
st
,
int64_t
base
)
{
uint32_t
v
,
spf
;
unsigned
frames
=
0
;
/* Total number of frames in file */
unsigned
size
=
0
;
/* Total number of bytes in the stream */
const
int64_t
xing_offtbl
[
2
][
2
]
=
{{
32
,
17
},
{
17
,
9
}};
MPADecodeHeader
c
;
int
vbrtag_size
=
0
;
int
is_cbr
;
MP3DecContext
*
mp3
=
s
->
priv_data
;
v
=
avio_rb32
(
s
->
pb
);
if
(
ff_mpa_check_header
(
v
)
<
0
)
...
...
@@ -149,45 +194,23 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
spf
=
c
.
lsf
?
576
:
1152
;
/* Samples per frame, layer 3 */
/* Check for Xing / Info tag */
avio_skip
(
s
->
pb
,
xing_offtbl
[
c
.
lsf
==
1
][
c
.
nb_channels
==
1
]);
v
=
avio_rb32
(
s
->
pb
);
is_cbr
=
v
==
MKBETAG
(
'I'
,
'n'
,
'f'
,
'o'
);
if
(
v
==
MKBETAG
(
'X'
,
'i'
,
'n'
,
'g'
)
||
is_cbr
)
{
v
=
avio_rb32
(
s
->
pb
);
if
(
v
&
XING_FLAG_FRAMES
)
frames
=
avio_rb32
(
s
->
pb
);
if
(
v
&
XING_FLAG_SIZE
)
size
=
avio_rb32
(
s
->
pb
);
if
(
v
&
XING_FLAG_TOC
&&
frames
)
read_xing_toc
(
s
,
size
,
av_rescale_q
(
frames
,
(
AVRational
){
spf
,
c
.
sample_rate
},
st
->
time_base
));
}
mp3
->
frames
=
0
;
mp3
->
size
=
0
;
/* Check for VBRI tag (always 32 bytes after end of mpegaudio header) */
avio_seek
(
s
->
pb
,
base
+
4
+
32
,
SEEK_SET
);
v
=
avio_rb32
(
s
->
pb
);
if
(
v
==
MKBETAG
(
'V'
,
'B'
,
'R'
,
'I'
))
{
/* Check tag version */
if
(
avio_rb16
(
s
->
pb
)
==
1
)
{
/* skip delay and quality */
avio_skip
(
s
->
pb
,
4
);
size
=
avio_rb32
(
s
->
pb
);
frames
=
avio_rb32
(
s
->
pb
);
}
}
mp3_parse_info_tag
(
s
,
st
,
&
c
,
spf
);
mp3_parse_vbri_tag
(
s
,
st
,
base
);
if
(
!
frames
&&
!
size
)
if
(
!
mp3
->
frames
&&
!
mp3
->
size
)
return
-
1
;
/* Skip the vbr tag frame */
avio_seek
(
s
->
pb
,
base
+
vbrtag_size
,
SEEK_SET
);
if
(
frames
)
st
->
duration
=
av_rescale_q
(
frames
,
(
AVRational
){
spf
,
c
.
sample_rate
},
if
(
mp3
->
frames
)
st
->
duration
=
av_rescale_q
(
mp3
->
frames
,
(
AVRational
){
spf
,
c
.
sample_rate
},
st
->
time_base
);
if
(
size
&&
frames
&&
!
is_cbr
)
st
->
codec
->
bit_rate
=
av_rescale
(
size
,
8
*
c
.
sample_rate
,
frames
*
(
int64_t
)
spf
);
if
(
mp3
->
size
&&
mp3
->
frames
&&
!
mp3
->
is_cbr
)
st
->
codec
->
bit_rate
=
av_rescale
(
mp3
->
size
,
8
*
c
.
sample_rate
,
mp3
->
frames
*
(
int64_t
)
spf
);
return
0
;
}
...
...
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