Skip to content

Commit d441d25

Browse files
author
Clement Champetier
committed
filter: added Filter class
Describe a filter and its options.
1 parent bb02458 commit d441d25

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

src/AvTranscoder/filter/Filter.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "Filter.hpp"
2+
3+
extern "C" {
4+
#include <libavfilter/avfilter.h>
5+
}
6+
7+
#include <stdexcept>
8+
9+
namespace avtranscoder
10+
{
11+
12+
Filter::Filter(const std::string& name, const std::string& options, const std::string& instanceName)
13+
: _filter(NULL)
14+
, _context(NULL)
15+
, _options(options)
16+
, _instanceName(instanceName.empty() ? name : instanceName)
17+
{
18+
_filter = avfilter_get_by_name(name.c_str());
19+
if(!_filter)
20+
{
21+
std::string msg("Cannot find filter ");
22+
msg += name;
23+
msg += ". It will not be added to the filter graph.";
24+
throw std::runtime_error(msg);
25+
}
26+
}
27+
28+
Filter::~Filter()
29+
{
30+
avfilter_free(_context);
31+
}
32+
33+
std::string Filter::getName() const
34+
{
35+
return _filter->name ? std::string(_filter->name) : "";
36+
}
37+
}

src/AvTranscoder/filter/Filter.hpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef _AV_TRANSCODER_FILTER_FILTER_HPP_
2+
#define _AV_TRANSCODER_FILTER_FILTER_HPP_
3+
4+
#include <AvTranscoder/common.hpp>
5+
6+
struct AVFilter;
7+
struct AVFilterContext;
8+
9+
namespace avtranscoder
10+
{
11+
12+
/**
13+
* @brief Describe a filter and its options.
14+
**/
15+
class AvExport Filter
16+
{
17+
public:
18+
Filter(const std::string& name, const std::string& options = "", const std::string& instanceName = "");
19+
~Filter();
20+
21+
std::string getName() const;
22+
std::string getOptions() const { return _options; }
23+
std::string getInstanceName() const { return _instanceName; }
24+
25+
#ifndef SWIG
26+
AVFilter& getAVFilter() { return *_filter; }
27+
AVFilterContext* getAVFilterContext() { return _context; }
28+
29+
void setAVFilterContext(AVFilterContext* newContext) { _context = newContext; }
30+
#endif
31+
32+
private:
33+
AVFilter* _filter;
34+
AVFilterContext* _context;
35+
std::string _options;
36+
std::string _instanceName;
37+
};
38+
}
39+
40+
#endif

0 commit comments

Comments
 (0)