AVPKit
MediaFilter.cpp
1 /*******************************************************************************
2  * Copyright (c) 2024, 2026, Olivier Ayache. All rights reserved.
3  *
4  * This file is part of AVPKit.
5  *
6  * AVPKit is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * AVPKit is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with AVPKit. If not, see <http://www.gnu.org/licenses/>.
18  *******************************************************************************/
19 
20 #include "MediaFilter.h"
21 #include "BufferSink.h"
22 #include <com/avpkit/ferry/Logger.h>
23 
24 VS_LOG_SETUP(VS_CPP_PACKAGE);
25 
26 namespace com {
27  namespace avpkit {
28  namespace core {
29 
30  MediaFilter* MediaFilter::make(AVFilterGraph* graph, const char* name) {
31  MediaFilter* retval = MediaFilter::make();
32  if (retval) {
33  retval->mFilter = avfilter_get_by_name(name);
34  retval->mFilterContext = avfilter_graph_alloc_filter(graph, retval->mFilter, name);
35  if (!retval->mFilterContext) {
36  VS_REF_RELEASE(retval);
37  }
38  }
39  return retval;
40  }
41 
43  MediaFilter* f = dynamic_cast<MediaFilter*> (filter);
44  //VS_LOG_WARN("type of filter %s %p %p", typeid (filter).name(), f, filter);
45  if (f) {
46  return avfilter_link(mFilterContext, getAvailableOutput(), f->getAVFilter(), f->getAvailableInput());
47  }
48  return -1;
49  }
50 
52  BufferSink* f = dynamic_cast<BufferSink*> (filter);
53  if (f) {
54  return avfilter_link(mFilterContext, getAvailableOutput(), f->getAVFilter(), f->getAvailableInput());
55  }
56  return -1;
57  }
58 
59 
60 
61  MediaFilter::MediaFilter() {
62  //VS_LOG_WARN("type of filter %s %p", typeid (this).name(), this);
63  mFilter = NULL;
64  mFilterContext = NULL;
65  ready = false;
66  }
67 
68  MediaFilter::~MediaFilter() {
69  //mFilterContext freed by FilterChain
70  mFilterContext = NULL;
71  mFilter = NULL;
72  }
73 
74 
75  }
76  }
77 }
78 
virtual int addSink(IBufferSink *filterSink)
Add a filter as an output of this filter.
Definition: MediaFilter.cpp:51
virtual int addFilter(IMediaFilter *filter)
Add a filter as an output of this filter.
Definition: MediaFilter.cpp:42
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...