forked from h4tr3d/avcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiltercontext.cpp
101 lines (79 loc) · 1.84 KB
/
filtercontext.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <mutex>
#include <cassert>
#include "filtercontext.h"
namespace av {
using namespace std;
FilterContext::FilterContext(AVFilterContext *ctx)
: FFWrapperPtr<AVFilterContext>(ctx)
{
}
Filter FilterContext::filter() const
{
return (m_raw ? Filter(m_raw->filter) : Filter());
}
string FilterContext::name() const
{
if (m_raw) {
if (m_raw->name) {
return m_raw->name;
} else if (m_raw->filter->name) {
return m_raw->filter->name;
}
}
return string();
}
size_t FilterContext::inputsCount() const
{
assert(m_raw);
#if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(3,17,100) // 1.0
auto count = m_raw->input_count;
#else
auto count = m_raw->nb_inputs;
#endif
return count;
}
void FilterContext::init(const string& args, OptionalErrorCode ec)
{
clear_if(ec);
if (!m_raw) {
throws_if(ec, Errors::Unallocated);
return;
}
const char* cargs = args.empty() ? nullptr : args.c_str();
int sts = avfilter_init_str(m_raw, cargs);
if (sts < 0) {
throws_if(ec, sts, ffmpeg_category());
}
}
void FilterContext::free()
{
avfilter_free(m_raw);
}
void FilterContext::link(unsigned srcPad, FilterContext &dstFilter, unsigned dstPad, OptionalErrorCode ec)
{
clear_if(ec);
if (!m_raw || !dstFilter) {
throws_if(ec, Errors::Unallocated);
return;
}
int sts = avfilter_link(m_raw, srcPad, dstFilter.raw(), dstPad);
if (sts < 0) {
throws_if(ec, sts, ffmpeg_category());
return;
}
}
FilterContext::operator bool() const
{
return !isNull();
}
size_t FilterContext::outputsCount() const
{
assert(m_raw);
#if LIBAVFILTER_VERSION_INT < AV_VERSION_INT(3,17,100) // 1.0
auto count = m_raw->output_count;
#else
auto count = m_raw->nb_outputs;
#endif
return count;
}
} // namespace av