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
4f3c079f
Commit
4f3c079f
authored
May 28, 2024
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avfilter/asubprocess: coding style changes
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
4874e76c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
140 additions
and
141 deletions
+140
-141
af_asubprocess.c
libavfilter/af_asubprocess.c
+140
-141
No files found.
libavfilter/af_asubprocess.c
View file @
4f3c079f
...
...
@@ -32,18 +32,18 @@
typedef
struct
SPB
{
struct
SPB
*
next
;
int
offset
;
int
count
;
char
data
[
BUFFER_SIZE
];
int
offset
;
int
count
;
char
data
[
BUFFER_SIZE
];
}
SPB
;
typedef
struct
SP
{
int
input_pipe
;
int
output_pipe
;
SPB
*
out_buffers
;
int
pid
;
bool
done
;
int
input_pipe
;
int
output_pipe
;
SPB
*
out_buffers
;
int
pid
;
bool
done
;
}
SP
;
static
SPB
*
spb_new
(
void
)
...
...
@@ -59,141 +59,140 @@ static SPB *spb_new(void)
static
SP
*
sp_new
(
const
char
*
command
)
{
SP
*
sp
=
calloc
(
1
,
sizeof
(
SP
));
int
output_pipe
[
2
];
int
input_pipe
[
2
];
int
pok
,
i
;
pid_t
pid
;
pok
=
pipe
(
output_pipe
);
if
(
pok
!=
0
)
printf
(
"pipe() failed
\n
"
);
pok
=
pipe
(
input_pipe
);
if
(
pok
!=
0
)
printf
(
"pipe() failed
\n
"
);
pid
=
fork
();
if
(
pid
<
0
)
printf
(
"fork() failed
\n
"
);
if
(
pid
==
0
)
{
if
(
dup2
(
input_pipe
[
0
],
0
)
<
0
)
printf
(
"dup2() failed
\n
"
);
if
(
dup2
(
output_pipe
[
1
],
1
)
<
0
)
printf
(
"dup2() failed
\n
"
);
close
(
output_pipe
[
1
]);
close
(
output_pipe
[
0
]);
close
(
input_pipe
[
1
]);
close
(
input_pipe
[
0
]);
execl
(
"/bin/sh"
,
"/bin/sh"
,
"-c"
,
command
,
NULL
);
}
sp
->
pid
=
pid
;
close
(
input_pipe
[
0
]);
close
(
output_pipe
[
1
]);
i
=
fcntl
(
output_pipe
[
0
],
F_GETFL
);
av_assert0
(
i
!=
-
1
);
i
|=
O_NONBLOCK
;
fcntl
(
output_pipe
[
0
],
F_SETFL
,
i
);
i
=
fcntl
(
input_pipe
[
1
],
F_GETFL
);
av_assert0
(
i
!=
-
1
);
i
|=
O_NONBLOCK
;
fcntl
(
input_pipe
[
1
],
F_SETFL
,
i
);
sp
->
input_pipe
=
input_pipe
[
1
];
sp
->
output_pipe
=
output_pipe
[
0
];
return
(
sp
);
SP
*
sp
=
calloc
(
1
,
sizeof
(
SP
));
int
output_pipe
[
2
];
int
input_pipe
[
2
];
int
pok
,
i
;
pid_t
pid
;
pok
=
pipe
(
output_pipe
);
if
(
pok
!=
0
)
printf
(
"pipe() failed
\n
"
);
pok
=
pipe
(
input_pipe
);
if
(
pok
!=
0
)
printf
(
"pipe() failed
\n
"
);
pid
=
fork
();
if
(
pid
<
0
)
printf
(
"fork() failed
\n
"
);
if
(
pid
==
0
)
{
if
(
dup2
(
input_pipe
[
0
],
0
)
<
0
)
printf
(
"dup2() failed
\n
"
);
if
(
dup2
(
output_pipe
[
1
],
1
)
<
0
)
printf
(
"dup2() failed
\n
"
);
close
(
output_pipe
[
1
]);
close
(
output_pipe
[
0
]);
close
(
input_pipe
[
1
]);
close
(
input_pipe
[
0
]);
execl
(
"/bin/sh"
,
"/bin/sh"
,
"-c"
,
command
,
NULL
);
}
sp
->
pid
=
pid
;
close
(
input_pipe
[
0
]);
close
(
output_pipe
[
1
]);
i
=
fcntl
(
output_pipe
[
0
],
F_GETFL
);
av_assert0
(
i
!=
-
1
);
i
|=
O_NONBLOCK
;
fcntl
(
output_pipe
[
0
],
F_SETFL
,
i
);
i
=
fcntl
(
input_pipe
[
1
],
F_GETFL
);
av_assert0
(
i
!=
-
1
);
i
|=
O_NONBLOCK
;
fcntl
(
input_pipe
[
1
],
F_SETFL
,
i
);
sp
->
input_pipe
=
input_pipe
[
1
];
sp
->
output_pipe
=
output_pipe
[
0
];
return
(
sp
);
}
static
int
sp_can_read
(
SP
*
sp
)
{
int
can_read
=
0
;
for
(
SPB
*
spb
=
sp
->
out_buffers
;
spb
;
spb
=
spb
->
next
)
{
can_read
+=
spb
->
count
-
spb
->
offset
;
}
return
can_read
;
int
can_read
=
0
;
for
(
SPB
*
spb
=
sp
->
out_buffers
;
spb
;
spb
=
spb
->
next
)
can_read
+=
spb
->
count
-
spb
->
offset
;
return
can_read
;
}
static
void
sp_read
(
SP
*
sp
,
char
*
buffer
,
int
count
)
{
SPB
*
spb
=
sp
->
out_buffers
;
while
(
spb
)
SPB
*
spb
=
sp
->
out_buffers
;
while
(
spb
)
{
int
n
=
spb
->
count
-
spb
->
offset
;
if
(
n
>
count
)
n
=
count
;
memcpy
(
buffer
,
spb
->
data
+
spb
->
offset
,
n
);
spb
->
offset
+=
n
;
count
-=
n
;
buffer
+=
n
;
if
(
spb
->
count
-
spb
->
offset
)
return
;
sp
->
out_buffers
=
spb
->
next
;
free
(
spb
);
spb
=
sp
->
out_buffers
;
int
n
=
spb
->
count
-
spb
->
offset
;
if
(
n
>
count
)
n
=
count
;
memcpy
(
buffer
,
spb
->
data
+
spb
->
offset
,
n
);
spb
->
offset
+=
n
;
count
-=
n
;
buffer
+=
n
;
if
(
spb
->
count
-
spb
->
offset
)
return
;
sp
->
out_buffers
=
spb
->
next
;
free
(
spb
);
spb
=
sp
->
out_buffers
;
}
}
static
int
sp_write
(
SP
*
sp
,
char
*
buffer
,
int
count
)
{
int
offset
=
0
;
if
(
count
==
0
&&
sp
->
input_pipe
>=
0
)
// eof
int
offset
=
0
;
if
(
count
==
0
&&
sp
->
input_pipe
>=
0
)
// eof
{
close
(
sp
->
input_pipe
);
sp
->
input_pipe
=
-
1
;
close
(
sp
->
input_pipe
);
sp
->
input_pipe
=
-
1
;
}
if
(
count
&&
sp
->
done
)
return
AVERROR_EXTERNAL
;
do
if
(
count
&&
sp
->
done
)
return
AVERROR_EXTERNAL
;
do
{
struct
pollfd
fds
[
2
]
=
{
{
.
fd
=
sp
->
input_pipe
,
.
events
=
POLLOUT
,
.
revents
=
0
},
{
.
fd
=
sp
->
output_pipe
,
.
events
=
POLLIN
,
.
revents
=
0
},
};
poll
(
fds
,
2
,
-
1
);
if
(
fds
[
0
].
revents
&
(
POLLOUT
|
POLLHUP
))
struct
pollfd
fds
[
2
]
=
{
{
.
fd
=
sp
->
input_pipe
,
.
events
=
POLLOUT
,
.
revents
=
0
},
{
.
fd
=
sp
->
output_pipe
,
.
events
=
POLLIN
,
.
revents
=
0
},
};
poll
(
fds
,
2
,
-
1
);
if
(
fds
[
0
].
revents
&
(
POLLOUT
|
POLLHUP
))
{
int
rc
=
write
(
sp
->
input_pipe
,
&
buffer
[
offset
],
count
);
if
(
rc
>
0
)
int
rc
=
write
(
sp
->
input_pipe
,
&
buffer
[
offset
],
count
);
if
(
rc
>
0
)
{
offset
+=
rc
;
count
-=
rc
;
offset
+=
rc
;
count
-=
rc
;
}
}
if
(
fds
[
1
].
revents
&
(
POLLIN
|
POLLHUP
))
if
(
fds
[
1
].
revents
&
(
POLLIN
|
POLLHUP
))
{
SPB
*
spb
=
spb_new
();
int
rc
=
read
(
sp
->
output_pipe
,
spb
->
data
,
sizeof
(
spb
->
data
));
if
(
rc
>
0
)
SPB
*
spb
=
spb_new
();
int
rc
=
read
(
sp
->
output_pipe
,
spb
->
data
,
sizeof
(
spb
->
data
));
if
(
rc
>
0
)
{
spb
->
count
=
rc
;
if
(
!
sp
->
out_buffers
)
sp
->
out_buffers
=
spb
;
else
spb
->
count
=
rc
;
if
(
!
sp
->
out_buffers
)
sp
->
out_buffers
=
spb
;
else
{
SPB
*
last
=
sp
->
out_buffers
;
while
(
last
->
next
)
last
=
last
->
next
;
last
->
next
=
spb
;
SPB
*
last
=
sp
->
out_buffers
;
while
(
last
->
next
)
last
=
last
->
next
;
last
->
next
=
spb
;
}
}
else
if
(
rc
==
0
)
else
if
(
rc
==
0
)
{
int
status
;
waitpid
(
sp
->
pid
,
&
status
,
0
);
printf
(
"wstatus=%d
\n
"
,
WEXITSTATUS
(
status
));
sp
->
done
=
true
;
if
(
count
)
return
AVERROR_EXTERNAL
;
return
0
;
int
status
;
waitpid
(
sp
->
pid
,
&
status
,
0
);
printf
(
"wstatus=%d
\n
"
,
WEXITSTATUS
(
status
));
sp
->
done
=
true
;
if
(
count
)
return
AVERROR_EXTERNAL
;
return
0
;
}
}
}
while
(
count
);
return
0
;
return
0
;
}
static
bool
...
...
@@ -215,16 +214,16 @@ enum {
typedef
struct
AndioWMarkContext
{
const
AVClass
*
class
;
const
char
*
command
;
const
char
*
command
;
int
fd
;
int
state
;
unsigned
int
chunk_size
;
int
in_bit_depth
;
int
out_bit_depth
;
SP
*
sp
;
void
*
sample_buffer
;
int
eof
;
int
fd
;
int
state
;
unsigned
int
chunk_size
;
int
in_bit_depth
;
int
out_bit_depth
;
SP
*
sp
;
void
*
sample_buffer
;
int
eof
;
}
ASubProcessContext
;
#define OFFSET(x) offsetof(ASubProcessContext, x)
...
...
@@ -265,7 +264,7 @@ static av_cold void uninit(AVFilterContext *ctx)
#define NB_BUFFER_SAMPLES 4096
static
int
write_wav_header
(
ASubProcessContext
*
s
,
int
nb_channels
,
int
sample_rate
)
static
int
write_wav_header
(
ASubProcessContext
*
s
,
int
nb_channels
,
int
sample_rate
)
{
int
bit_depth
=
s
->
in_bit_depth
;
AVIOContext
*
wav_header
=
NULL
;
...
...
@@ -279,20 +278,20 @@ static int write_wav_header (ASubProcessContext *s, int nb_channels, int sample_
ffio_wfourcc
(
wav_header
,
"WAVE"
);
// subchunk 1
ffio_wfourcc
(
wav_header
,
"fmt "
);
avio_wl32
(
wav_header
,
16
);
// subchunk size
avio_wl16
(
wav_header
,
1
);
// uncompressed audio
avio_wl16
(
wav_header
,
nb_channels
);
avio_wl32
(
wav_header
,
sample_rate
);
avio_wl32
(
wav_header
,
sample_rate
*
nb_channels
*
bit_depth
/
8
);
// byte rate
avio_wl16
(
wav_header
,
nb_channels
*
bit_depth
/
8
);
// block align
avio_wl16
(
wav_header
,
bit_depth
);
// bits per sample
avio_wl32
(
wav_header
,
16
);
// subchunk size
avio_wl16
(
wav_header
,
1
);
// uncompressed audio
avio_wl16
(
wav_header
,
nb_channels
);
avio_wl32
(
wav_header
,
sample_rate
);
avio_wl32
(
wav_header
,
sample_rate
*
nb_channels
*
bit_depth
/
8
);
// byte rate
avio_wl16
(
wav_header
,
nb_channels
*
bit_depth
/
8
);
// block align
avio_wl16
(
wav_header
,
bit_depth
);
// bits per sample
// subchunk 2
ffio_wfourcc
(
wav_header
,
"data"
);
avio_wl32
(
wav_header
,
-
1
);
size
=
avio_close_dyn_buf
(
wav_header
,
&
buffer
);
ret
=
sp_write
(
s
->
sp
,
buffer
,
size
);
av_free
(
buffer
);
ffio_wfourcc
(
wav_header
,
"data"
);
avio_wl32
(
wav_header
,
-
1
);
size
=
avio_close_dyn_buf
(
wav_header
,
&
buffer
);
ret
=
sp_write
(
s
->
sp
,
buffer
,
size
);
av_free
(
buffer
);
return
ret
;
}
...
...
@@ -413,16 +412,16 @@ static int try_read_frame(ASubProcessContext *s, AVFilterLink *outlink)
AVFrame
*
out
;
int
ret
;
if
(
s
->
state
==
STATE_EXPECT_RIFF
&&
sp_can_read
(
s
->
sp
)
>=
12
)
if
(
s
->
state
==
STATE_EXPECT_RIFF
&&
sp_can_read
(
s
->
sp
)
>=
12
)
{
char
buffer
[
12
];
sp_read
(
s
->
sp
,
buffer
,
12
);
sp_read
(
s
->
sp
,
buffer
,
12
);
s
->
state
=
STATE_EXPECT_CHUNK
;
}
if
(
s
->
state
==
STATE_EXPECT_CHUNK
&&
sp_can_read
(
s
->
sp
)
>=
8
)
if
(
s
->
state
==
STATE_EXPECT_CHUNK
&&
sp_can_read
(
s
->
sp
)
>=
8
)
{
unsigned
char
x
[
8
];
sp_read
(
s
->
sp
,
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'
)
s
->
state
=
STATE_IN_DATA_CHUNK
;
...
...
@@ -431,20 +430,20 @@ static int try_read_frame(ASubProcessContext *s, AVFilterLink *outlink)
else
s
->
state
=
STATE_SKIP_CHUNK
;
}
if
(
s
->
state
==
STATE_IN_FMT_CHUNK
&&
sp_can_read
(
s
->
sp
)
>=
16
)
if
(
s
->
state
==
STATE_IN_FMT_CHUNK
&&
sp_can_read
(
s
->
sp
)
>=
16
)
{
unsigned
char
data
[
16
];
sp_read
(
s
->
sp
,
data
,
16
);
sp_read
(
s
->
sp
,
data
,
16
);
s
->
out_bit_depth
=
AV_RL16
(
data
+
14
);
s
->
chunk_size
-=
16
;
s
->
state
=
STATE_SKIP_CHUNK
;
}
if
(
s
->
state
==
STATE_SKIP_CHUNK
&&
sp_can_read
(
s
->
sp
)
>=
s
->
chunk_size
)
if
(
s
->
state
==
STATE_SKIP_CHUNK
&&
sp_can_read
(
s
->
sp
)
>=
s
->
chunk_size
)
{
while
(
s
->
chunk_size
)
{
char
buffer
[
1024
];
unsigned
int
n
=
FFMIN
(
sizeof
(
buffer
),
s
->
chunk_size
);
unsigned
int
n
=
FFMIN
(
sizeof
(
buffer
),
s
->
chunk_size
);
sp_read
(
s
->
sp
,
buffer
,
n
);
s
->
chunk_size
-=
n
;
}
...
...
@@ -453,7 +452,7 @@ static int try_read_frame(ASubProcessContext *s, AVFilterLink *outlink)
if
(
s
->
state
==
STATE_IN_DATA_CHUNK
)
{
int
sample_size
=
s
->
out_bit_depth
/
8
;
int
avail
=
sp_can_read
(
s
->
sp
)
/
sample_size
/
outlink
->
ch_layout
.
nb_channels
;
int
avail
=
sp_can_read
(
s
->
sp
)
/
sample_size
/
outlink
->
ch_layout
.
nb_channels
;
if
(
avail
>
NB_BUFFER_SAMPLES
)
avail
=
NB_BUFFER_SAMPLES
;
if
(
avail
==
NB_BUFFER_SAMPLES
||
(
s
->
eof
&&
avail
>
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