Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
ffmpeg
Project
Project
Details
Activity
Releases
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
ffmpeg
Commits
4a465a05
Commit
4a465a05
authored
May 30, 2024
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avfilter/asubprocess: add checks for subprocess output (should be wav)
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
58bad47d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
6 deletions
+43
-6
af_asubprocess.c
libavfilter/af_asubprocess.c
+43
-6
No files found.
libavfilter/af_asubprocess.c
View file @
4a465a05
...
...
@@ -486,14 +486,20 @@ static int write_frame(AVFilterContext *ctx, ASubProcessContext *s, AVFilterLink
return
ret
;
}
static
int
try_read_frame
(
A
SubProcessContext
*
s
,
AVFilterLink
*
outlink
)
static
int
try_read_frame
(
A
VFilterContext
*
ctx
)
{
AVFilterLink
*
outlink
=
ctx
->
outputs
[
0
];
ASubProcessContext
*
s
=
ctx
->
priv
;
int
ret
;
if
(
s
->
state
==
STATE_EXPECT_RIFF
&&
sp_can_read
(
s
->
sp
)
>=
12
)
{
char
buffer
[
12
];
sp_read
(
s
->
sp
,
buffer
,
12
);
if
((
memcmp
(
buffer
,
"RIFF"
,
4
)
&&
memcmp
(
buffer
,
"RF64"
,
4
))
||
memcmp
(
buffer
+
8
,
"WAVE"
,
4
))
{
av_log
(
ctx
,
AV_LOG_ERROR
,
"Subprocess output is not a valid wav file.
\n
"
);
return
AVERROR_INVALIDDATA
;
}
s
->
state
=
STATE_EXPECT_CHUNK
;
}
if
(
s
->
state
==
STATE_EXPECT_CHUNK
&&
sp_can_read
(
s
->
sp
)
>=
8
)
...
...
@@ -501,9 +507,9 @@ static int try_read_frame(ASubProcessContext *s, AVFilterLink *outlink)
unsigned
char
x
[
8
];
sp_read
(
s
->
sp
,
x
,
8
);
s
->
chunk_size
=
AV_RL32
(
x
+
4
);
if
(
x
[
0
]
==
'd'
&&
x
[
1
]
==
'a'
&&
x
[
2
]
==
't'
&&
x
[
3
]
==
'a'
)
if
(
!
memcmp
(
x
,
"data"
,
4
)
)
s
->
state
=
STATE_IN_DATA_CHUNK
;
else
if
(
x
[
0
]
==
'f'
&&
x
[
1
]
==
'm'
&&
x
[
2
]
==
't'
&&
x
[
3
]
==
' '
&&
s
->
chunk_size
>=
16
)
else
if
(
!
memcmp
(
x
,
"fmt "
,
4
)
&&
s
->
chunk_size
>=
16
)
s
->
state
=
STATE_IN_FMT_CHUNK
;
else
s
->
state
=
STATE_SKIP_CHUNK
;
...
...
@@ -511,8 +517,35 @@ static int try_read_frame(ASubProcessContext *s, AVFilterLink *outlink)
if
(
s
->
state
==
STATE_IN_FMT_CHUNK
&&
sp_can_read
(
s
->
sp
)
>=
16
)
{
unsigned
char
data
[
16
];
int
format
,
nb_channels
,
sample_rate
;
sp_read
(
s
->
sp
,
data
,
16
);
s
->
out_bit_depth
=
AV_RL16
(
data
+
14
);
format
=
AV_RL16
(
data
);
nb_channels
=
AV_RL16
(
data
+
2
);
sample_rate
=
AV_RL32
(
data
+
4
);
s
->
out_bit_depth
=
AV_RL16
(
data
+
14
);
if
(
format
!=
1
&&
format
!=
0xFFFE
)
{
// TODO: check extensible wav format: should be PCM
av_log
(
ctx
,
AV_LOG_ERROR
,
"Unsupported wav format (%d) from subprocess (expected PCM).
\n
"
,
format
);
return
AVERROR_INVALIDDATA
;
}
if
(
nb_channels
!=
outlink
->
ch_layout
.
nb_channels
)
{
av_log
(
ctx
,
AV_LOG_ERROR
,
"Number of output channels (%d) from subprocess doesn't match input channels (%d).
\n
"
,
nb_channels
,
outlink
->
ch_layout
.
nb_channels
);
return
AVERROR_INVALIDDATA
;
}
if
(
sample_rate
!=
outlink
->
sample_rate
)
{
av_log
(
ctx
,
AV_LOG_ERROR
,
"Sample rate (%d) from subprocess doesn't match input sample rate (%d).
\n
"
,
sample_rate
,
outlink
->
sample_rate
);
return
AVERROR_INVALIDDATA
;
}
if
(
s
->
out_bit_depth
!=
8
&&
s
->
out_bit_depth
!=
16
&&
s
->
out_bit_depth
!=
24
&&
s
->
out_bit_depth
!=
32
)
{
av_log
(
ctx
,
AV_LOG_ERROR
,
"Unsupported output wav bit depth (%d) from subprocess.
\n
"
,
s
->
out_bit_depth
);
return
AVERROR_INVALIDDATA
;
}
s
->
chunk_size
-=
16
;
s
->
state
=
STATE_SKIP_CHUNK
;
}
...
...
@@ -560,7 +593,7 @@ static int activate(AVFilterContext *ctx)
FF_FILTER_FORWARD_STATUS_BACK
(
outlink
,
inlink
);
ret
=
try_read_frame
(
s
,
outlink
);
ret
=
try_read_frame
(
ctx
);
if
(
ret
!=
0
)
return
ret
;
ret
=
ff_inlink_consume_frame
(
inlink
,
&
in
);
...
...
@@ -588,11 +621,15 @@ static int activate(AVFilterContext *ctx)
return
ret
;
}
}
ret
=
try_read_frame
(
s
,
outlink
);
ret
=
try_read_frame
(
ctx
);
if
(
ret
!=
0
)
return
ret
;
if
(
s
->
eof
)
{
if
(
s
->
state
!=
STATE_IN_DATA_CHUNK
)
{
av_log
(
ctx
,
AV_LOG_ERROR
,
"Subprocess output wav is incomplete (no data chunk found)
\n
"
);
return
AVERROR_INVALIDDATA
;
}
// s->last_pts
ff_outlink_set_status
(
outlink
,
AVERROR_EOF
,
AV_NOPTS_VALUE
);
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