Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
9a0076f5
Commit
9a0076f5
authored
Feb 20, 2013
by
Clément Bœsch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lavf/swfdec: factorize the creation of a new stream.
This also makes the changes of
a3949fe1
applicable in both cases.
parent
da7672b2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
26 deletions
+25
-26
swfdec.c
libavformat/swfdec.c
+25
-26
No files found.
libavformat/swfdec.c
View file @
9a0076f5
...
...
@@ -138,6 +138,29 @@ static int swf_read_header(AVFormatContext *s)
return
0
;
}
static
AVStream
*
create_new_audio_stream
(
AVFormatContext
*
s
,
int
id
,
int
info
)
{
int
sample_rate_code
;
AVStream
*
ast
=
avformat_new_stream
(
s
,
NULL
);
if
(
!
ast
)
return
NULL
;
ast
->
id
=
id
;
if
(
info
&
1
)
{
ast
->
codec
->
channels
=
2
;
ast
->
codec
->
channel_layout
=
AV_CH_LAYOUT_STEREO
;
}
else
{
ast
->
codec
->
channels
=
1
;
ast
->
codec
->
channel_layout
=
AV_CH_LAYOUT_MONO
;
}
ast
->
codec
->
codec_type
=
AVMEDIA_TYPE_AUDIO
;
ast
->
codec
->
codec_id
=
ff_codec_get_id
(
swf_audio_codec_tags
,
info
>>
4
&
15
);
ast
->
need_parsing
=
AVSTREAM_PARSE_FULL
;
sample_rate_code
=
info
>>
2
&
3
;
ast
->
codec
->
sample_rate
=
44100
>>
(
3
-
sample_rate_code
);
avpriv_set_pts_info
(
ast
,
64
,
1
,
ast
->
codec
->
sample_rate
);
return
ast
;
}
static
int
swf_read_packet
(
AVFormatContext
*
s
,
AVPacket
*
pkt
)
{
SWFContext
*
swf
=
s
->
priv_data
;
...
...
@@ -184,7 +207,6 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
len
-=
8
;
}
else
if
(
tag
==
TAG_STREAMHEAD
||
tag
==
TAG_STREAMHEAD2
)
{
/* streaming found */
int
sample_rate_code
;
for
(
i
=
0
;
i
<
s
->
nb_streams
;
i
++
)
{
st
=
s
->
streams
[
i
];
...
...
@@ -195,27 +217,12 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
avio_r8
(
pb
);
v
=
avio_r8
(
pb
);
swf
->
samples_per_frame
=
avio_rl16
(
pb
);
ast
=
avformat_new_stream
(
s
,
NULL
);
ast
=
create_new_audio_stream
(
s
,
-
1
,
v
);
/* -1 to avoid clash with video stream ch_id */
if
(
!
ast
)
return
AVERROR
(
ENOMEM
);
ast
->
id
=
-
1
;
/* -1 to avoid clash with video stream ch_id */
if
(
v
&
1
)
{
ast
->
codec
->
channels
=
2
;
ast
->
codec
->
channel_layout
=
AV_CH_LAYOUT_STEREO
;
}
else
{
ast
->
codec
->
channels
=
1
;
ast
->
codec
->
channel_layout
=
AV_CH_LAYOUT_MONO
;
}
ast
->
codec
->
codec_type
=
AVMEDIA_TYPE_AUDIO
;
ast
->
codec
->
codec_id
=
ff_codec_get_id
(
swf_audio_codec_tags
,
(
v
>>
4
)
&
15
);
ast
->
need_parsing
=
AVSTREAM_PARSE_FULL
;
sample_rate_code
=
(
v
>>
2
)
&
3
;
ast
->
codec
->
sample_rate
=
44100
>>
(
3
-
sample_rate_code
);
avpriv_set_pts_info
(
ast
,
64
,
1
,
ast
->
codec
->
sample_rate
);
len
-=
4
;
}
else
if
(
tag
==
TAG_DEFINESOUND
)
{
/* audio stream */
int
sample_rate_code
;
int
ch_id
=
avio_rl16
(
pb
);
for
(
i
=
0
;
i
<
s
->
nb_streams
;
i
++
)
{
...
...
@@ -229,17 +236,9 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
// these are smaller audio streams in DEFINESOUND tags, but it's technically
// possible they could be huge. Break it up into multiple packets if it's big.
v
=
avio_r8
(
pb
);
ast
=
avformat_new_stream
(
s
,
NULL
);
ast
=
create_new_audio_stream
(
s
,
ch_id
,
v
);
if
(
!
ast
)
return
AVERROR
(
ENOMEM
);
ast
->
id
=
ch_id
;
ast
->
codec
->
channels
=
1
+
(
v
&
1
);
ast
->
codec
->
codec_type
=
AVMEDIA_TYPE_AUDIO
;
ast
->
codec
->
codec_id
=
ff_codec_get_id
(
swf_audio_codec_tags
,
(
v
>>
4
)
&
15
);
ast
->
need_parsing
=
AVSTREAM_PARSE_FULL
;
sample_rate_code
=
(
v
>>
2
)
&
3
;
ast
->
codec
->
sample_rate
=
44100
>>
(
3
-
sample_rate_code
);
avpriv_set_pts_info
(
ast
,
64
,
1
,
ast
->
codec
->
sample_rate
);
ast
->
duration
=
avio_rl32
(
pb
);
// number of samples
if
(((
v
>>
4
)
&
15
)
==
2
)
{
// MP3 sound data record
ast
->
skip_samples
=
avio_rl16
(
pb
);
...
...
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