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
71a5311b
Commit
71a5311b
authored
Aug 24, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/ffmpeg/Filter: eliminate class FilterContext
Since AVFilterContext are freed automatically, this wrapper class serves no purpose. Let's remove it.
parent
a62a35e1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
80 deletions
+62
-80
FfmpegFilter.cxx
src/filter/plugins/FfmpegFilter.cxx
+6
-6
FfmpegFilter.hxx
src/filter/plugins/FfmpegFilter.hxx
+3
-3
FfmpegFilterPlugin.cxx
src/filter/plugins/FfmpegFilterPlugin.cxx
+9
-10
HdcdFilterPlugin.cxx
src/filter/plugins/HdcdFilterPlugin.cxx
+7
-7
Filter.cxx
src/lib/ffmpeg/Filter.cxx
+31
-6
Filter.hxx
src/lib/ffmpeg/Filter.hxx
+6
-48
No files found.
src/filter/plugins/FfmpegFilter.cxx
View file @
71a5311b
...
@@ -32,12 +32,12 @@ extern "C" {
...
@@ -32,12 +32,12 @@ extern "C" {
FfmpegFilter
::
FfmpegFilter
(
const
AudioFormat
&
in_audio_format
,
FfmpegFilter
::
FfmpegFilter
(
const
AudioFormat
&
in_audio_format
,
const
AudioFormat
&
_out_audio_format
,
const
AudioFormat
&
_out_audio_format
,
Ffmpeg
::
FilterGraph
&&
_graph
,
Ffmpeg
::
FilterGraph
&&
_graph
,
Ffmpeg
::
FilterContext
&
&
_buffer_src
,
AVFilterContext
&
_buffer_src
,
Ffmpeg
::
FilterContext
&
&
_buffer_sink
)
noexcept
AVFilterContext
&
_buffer_sink
)
noexcept
:
Filter
(
_out_audio_format
),
:
Filter
(
_out_audio_format
),
graph
(
std
::
move
(
_graph
)),
graph
(
std
::
move
(
_graph
)),
buffer_src
(
std
::
move
(
_buffer_src
)
),
buffer_src
(
_buffer_src
),
buffer_sink
(
std
::
move
(
_buffer_sink
)
),
buffer_sink
(
_buffer_sink
),
in_format
(
Ffmpeg
::
ToFfmpegSampleFormat
(
in_audio_format
.
format
)),
in_format
(
Ffmpeg
::
ToFfmpegSampleFormat
(
in_audio_format
.
format
)),
in_sample_rate
(
in_audio_format
.
sample_rate
),
in_sample_rate
(
in_audio_format
.
sample_rate
),
in_channels
(
in_audio_format
.
channels
),
in_channels
(
in_audio_format
.
channels
),
...
@@ -61,7 +61,7 @@ FfmpegFilter::FilterPCM(ConstBuffer<void> src)
...
@@ -61,7 +61,7 @@ FfmpegFilter::FilterPCM(ConstBuffer<void> src)
memcpy
(
frame
.
GetData
(
0
),
src
.
data
,
src
.
size
);
memcpy
(
frame
.
GetData
(
0
),
src
.
data
,
src
.
size
);
int
err
=
av_buffersrc_add_frame
(
buffer_src
.
get
()
,
frame
.
get
());
int
err
=
av_buffersrc_add_frame
(
&
buffer_src
,
frame
.
get
());
if
(
err
<
0
)
if
(
err
<
0
)
throw
MakeFfmpegError
(
err
,
"av_buffersrc_write_frame() failed"
);
throw
MakeFfmpegError
(
err
,
"av_buffersrc_write_frame() failed"
);
...
@@ -69,7 +69,7 @@ FfmpegFilter::FilterPCM(ConstBuffer<void> src)
...
@@ -69,7 +69,7 @@ FfmpegFilter::FilterPCM(ConstBuffer<void> src)
frame
.
Unref
();
frame
.
Unref
();
err
=
av_buffersink_get_frame
(
buffer_sink
.
get
()
,
frame
.
get
());
err
=
av_buffersink_get_frame
(
&
buffer_sink
,
frame
.
get
());
if
(
err
<
0
)
{
if
(
err
<
0
)
{
if
(
err
==
AVERROR
(
EAGAIN
)
||
err
==
AVERROR_EOF
)
if
(
err
==
AVERROR
(
EAGAIN
)
||
err
==
AVERROR_EOF
)
return
nullptr
;
return
nullptr
;
...
...
src/filter/plugins/FfmpegFilter.hxx
View file @
71a5311b
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
*/
*/
class
FfmpegFilter
final
:
public
Filter
{
class
FfmpegFilter
final
:
public
Filter
{
Ffmpeg
::
FilterGraph
graph
;
Ffmpeg
::
FilterGraph
graph
;
Ffmpeg
::
FilterContext
buffer_src
,
buffer_sink
;
AVFilterContext
&
buffer_src
,
&
buffer_sink
;
Ffmpeg
::
Frame
frame
;
Ffmpeg
::
Frame
frame
;
FfmpegBuffer
interleave_buffer
;
FfmpegBuffer
interleave_buffer
;
...
@@ -51,8 +51,8 @@ public:
...
@@ -51,8 +51,8 @@ public:
FfmpegFilter
(
const
AudioFormat
&
in_audio_format
,
FfmpegFilter
(
const
AudioFormat
&
in_audio_format
,
const
AudioFormat
&
_out_audio_format
,
const
AudioFormat
&
_out_audio_format
,
Ffmpeg
::
FilterGraph
&&
_graph
,
Ffmpeg
::
FilterGraph
&&
_graph
,
Ffmpeg
::
FilterContext
&
&
_buffer_src
,
AVFilterContext
&
_buffer_src
,
Ffmpeg
::
FilterContext
&
&
_buffer_sink
)
noexcept
;
AVFilterContext
&
_buffer_sink
)
noexcept
;
/* virtual methods from class Filter */
/* virtual methods from class Filter */
ConstBuffer
<
void
>
FilterPCM
(
ConstBuffer
<
void
>
src
)
override
;
ConstBuffer
<
void
>
FilterPCM
(
ConstBuffer
<
void
>
src
)
override
;
...
...
src/filter/plugins/FfmpegFilterPlugin.cxx
View file @
71a5311b
...
@@ -42,14 +42,13 @@ PreparedFfmpegFilter::Open(AudioFormat &in_audio_format)
...
@@ -42,14 +42,13 @@ PreparedFfmpegFilter::Open(AudioFormat &in_audio_format)
{
{
Ffmpeg
::
FilterGraph
graph
;
Ffmpeg
::
FilterGraph
graph
;
auto
buffer_src
=
auto
&
buffer_src
=
Ffmpeg
::
FilterContext
::
MakeAudioBufferSource
(
in_audio_format
,
Ffmpeg
::
MakeAudioBufferSource
(
in_audio_format
,
*
graph
);
*
graph
);
auto
buffer_sink
=
Ffmpeg
::
FilterContext
::
MakeAudioBufferSink
(
*
graph
);
auto
&
buffer_sink
=
Ffmpeg
::
MakeAudioBufferSink
(
*
graph
);
Ffmpeg
::
FilterInOut
io_sink
(
"out"
,
*
buffer_sink
);
Ffmpeg
::
FilterInOut
io_sink
(
"out"
,
buffer_sink
);
Ffmpeg
::
FilterInOut
io_src
(
"in"
,
*
buffer_src
);
Ffmpeg
::
FilterInOut
io_src
(
"in"
,
buffer_src
);
auto
io
=
graph
.
Parse
(
graph_string
,
std
::
move
(
io_sink
),
auto
io
=
graph
.
Parse
(
graph_string
,
std
::
move
(
io_sink
),
std
::
move
(
io_src
));
std
::
move
(
io_src
));
...
@@ -62,14 +61,14 @@ PreparedFfmpegFilter::Open(AudioFormat &in_audio_format)
...
@@ -62,14 +61,14 @@ PreparedFfmpegFilter::Open(AudioFormat &in_audio_format)
graph
.
CheckAndConfigure
();
graph
.
CheckAndConfigure
();
const
auto
out_audio_format
=
const
auto
out_audio_format
=
Ffmpeg
::
DetectFilterOutputFormat
(
in_audio_format
,
*
buffer_src
,
Ffmpeg
::
DetectFilterOutputFormat
(
in_audio_format
,
buffer_src
,
*
buffer_sink
);
buffer_sink
);
return
std
::
make_unique
<
FfmpegFilter
>
(
in_audio_format
,
return
std
::
make_unique
<
FfmpegFilter
>
(
in_audio_format
,
out_audio_format
,
out_audio_format
,
std
::
move
(
graph
),
std
::
move
(
graph
),
std
::
move
(
buffer_src
)
,
buffer_src
,
std
::
move
(
buffer_sink
)
);
buffer_sink
);
}
}
static
std
::
unique_ptr
<
PreparedFilter
>
static
std
::
unique_ptr
<
PreparedFilter
>
...
...
src/filter/plugins/HdcdFilterPlugin.cxx
View file @
71a5311b
...
@@ -42,14 +42,14 @@ OpenHdcdFilter(AudioFormat &in_audio_format)
...
@@ -42,14 +42,14 @@ OpenHdcdFilter(AudioFormat &in_audio_format)
{
{
Ffmpeg
::
FilterGraph
graph
;
Ffmpeg
::
FilterGraph
graph
;
auto
buffer_src
=
auto
&
buffer_src
=
Ffmpeg
::
FilterContext
::
MakeAudioBufferSource
(
in_audio_format
,
Ffmpeg
::
MakeAudioBufferSource
(
in_audio_format
,
*
graph
);
*
graph
);
auto
buffer_sink
=
Ffmpeg
::
FilterContext
::
MakeAudioBufferSink
(
*
graph
);
auto
&
buffer_sink
=
Ffmpeg
::
MakeAudioBufferSink
(
*
graph
);
Ffmpeg
::
FilterInOut
io_sink
(
"out"
,
*
buffer_sink
);
Ffmpeg
::
FilterInOut
io_sink
(
"out"
,
buffer_sink
);
Ffmpeg
::
FilterInOut
io_src
(
"in"
,
*
buffer_src
);
Ffmpeg
::
FilterInOut
io_src
(
"in"
,
buffer_src
);
auto
io
=
graph
.
Parse
(
hdcd_graph
,
std
::
move
(
io_sink
),
auto
io
=
graph
.
Parse
(
hdcd_graph
,
std
::
move
(
io_sink
),
std
::
move
(
io_src
));
std
::
move
(
io_src
));
...
@@ -69,8 +69,8 @@ OpenHdcdFilter(AudioFormat &in_audio_format)
...
@@ -69,8 +69,8 @@ OpenHdcdFilter(AudioFormat &in_audio_format)
return
std
::
make_unique
<
FfmpegFilter
>
(
in_audio_format
,
return
std
::
make_unique
<
FfmpegFilter
>
(
in_audio_format
,
out_audio_format
,
out_audio_format
,
std
::
move
(
graph
),
std
::
move
(
graph
),
std
::
move
(
buffer_src
)
,
buffer_src
,
std
::
move
(
buffer_sink
)
);
buffer_sink
);
}
}
class
PreparedHdcdFilter
final
:
public
PreparedFilter
{
class
PreparedHdcdFilter
final
:
public
PreparedFilter
{
...
...
src/lib/ffmpeg/Filter.cxx
View file @
71a5311b
...
@@ -39,8 +39,31 @@ RequireFilterByName(const char *name)
...
@@ -39,8 +39,31 @@ RequireFilterByName(const char *name)
return
*
filter
;
return
*
filter
;
}
}
FilterContext
static
AVFilterContext
&
FilterContext
::
MakeAudioBufferSource
(
AudioFormat
&
audio_format
,
CreateFilter
(
const
AVFilter
&
filt
,
const
char
*
name
,
const
char
*
args
,
void
*
opaque
,
AVFilterGraph
&
graph_ctx
)
{
AVFilterContext
*
context
=
nullptr
;
int
err
=
avfilter_graph_create_filter
(
&
context
,
&
filt
,
name
,
args
,
opaque
,
&
graph_ctx
);
if
(
err
<
0
)
throw
MakeFfmpegError
(
err
,
"avfilter_graph_create_filter() failed"
);
return
*
context
;
}
static
AVFilterContext
&
CreateFilter
(
const
AVFilter
&
filt
,
const
char
*
name
,
AVFilterGraph
&
graph_ctx
)
{
return
CreateFilter
(
filt
,
name
,
nullptr
,
nullptr
,
graph_ctx
);
}
AVFilterContext
&
MakeAudioBufferSource
(
AudioFormat
&
audio_format
,
AVFilterGraph
&
graph_ctx
)
AVFilterGraph
&
graph_ctx
)
{
{
AVSampleFormat
src_format
=
ToFfmpegSampleFormat
(
audio_format
.
format
);
AVSampleFormat
src_format
=
ToFfmpegSampleFormat
(
audio_format
.
format
);
...
@@ -66,13 +89,15 @@ FilterContext::MakeAudioBufferSource(AudioFormat &audio_format,
...
@@ -66,13 +89,15 @@ FilterContext::MakeAudioBufferSource(AudioFormat &audio_format,
ToFfmpegChannelLayout
(
audio_format
.
channels
),
ToFfmpegChannelLayout
(
audio_format
.
channels
),
audio_format
.
sample_rate
);
audio_format
.
sample_rate
);
return
{
RequireFilterByName
(
"abuffer"
),
"abuffer"
,
abuffer_args
,
nullptr
,
graph_ctx
};
return
CreateFilter
(
RequireFilterByName
(
"abuffer"
),
"abuffer"
,
abuffer_args
,
nullptr
,
graph_ctx
);
}
}
FilterContext
AVFilterContext
&
FilterContext
::
MakeAudioBufferSink
(
AVFilterGraph
&
graph_ctx
)
MakeAudioBufferSink
(
AVFilterGraph
&
graph_ctx
)
{
{
return
{
RequireFilterByName
(
"abuffersink"
),
"abuffersink"
,
graph_ctx
};
return
CreateFilter
(
RequireFilterByName
(
"abuffersink"
),
"abuffersink"
,
graph_ctx
);
}
}
}
// namespace Ffmpeg
}
// namespace Ffmpeg
src/lib/ffmpeg/Filter.hxx
View file @
71a5311b
...
@@ -77,63 +77,21 @@ public:
...
@@ -77,63 +77,21 @@ public:
}
}
};
};
class
FilterContext
{
/**
AVFilterContext
*
context
=
nullptr
;
public
:
FilterContext
()
=
default
;
FilterContext
(
const
AVFilter
&
filt
,
const
char
*
name
,
const
char
*
args
,
void
*
opaque
,
AVFilterGraph
&
graph_ctx
)
{
int
err
=
avfilter_graph_create_filter
(
&
context
,
&
filt
,
name
,
args
,
opaque
,
&
graph_ctx
);
if
(
err
<
0
)
throw
MakeFfmpegError
(
err
,
"avfilter_graph_create_filter() failed"
);
}
FilterContext
(
const
AVFilter
&
filt
,
const
char
*
name
,
AVFilterGraph
&
graph_ctx
)
:
FilterContext
(
filt
,
name
,
nullptr
,
nullptr
,
graph_ctx
)
{}
FilterContext
(
FilterContext
&&
src
)
noexcept
:
context
(
std
::
exchange
(
src
.
context
,
nullptr
))
{}
/* note: we don't need a destructor calling avfilter_free()
here because the AVFilterGraph owns and frees all the
AVFilterContext instances */
// TODO: do we really need this wrapper class anymore?
FilterContext
&
operator
=
(
FilterContext
&&
src
)
noexcept
{
using
std
::
swap
;
swap
(
context
,
src
.
context
);
return
*
this
;
}
/**
* Create an "abuffer" filter.
* Create an "abuffer" filter.
*
*
* @param the input audio format; may be modified by the
* @param the input audio format; may be modified by the
* function to ask the caller to do format conversion
* function to ask the caller to do format conversion
*/
*/
static
FilterContext
MakeAudioBufferSource
(
AudioFormat
&
audio_format
,
AVFilterContext
&
MakeAudioBufferSource
(
AudioFormat
&
audio_format
,
AVFilterGraph
&
graph_ctx
);
AVFilterGraph
&
graph_ctx
);
/**
/**
* Create an "abuffersink" filter.
* Create an "abuffersink" filter.
*/
*/
static
FilterContext
MakeAudioBufferSink
(
AVFilterGraph
&
graph_ctx
);
AVFilterContext
&
MakeAudioBufferSink
(
AVFilterGraph
&
graph_ctx
);
auto
&
operator
*
()
noexcept
{
return
*
context
;
}
auto
*
get
()
noexcept
{
return
context
;
}
};
class
FilterGraph
{
class
FilterGraph
{
AVFilterGraph
*
graph
=
nullptr
;
AVFilterGraph
*
graph
=
nullptr
;
...
...
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