blob: 9841ec79ce9c3743b1ac3b21478d36a104b017e2 [file] [log] [blame]
agsantos5aa39652020-08-11 18:18:04 -04001/**
Sébastien Blincb783e32021-02-12 11:34:10 -05002 * Copyright (C) 2004-2021 Savoir-faire Linux Inc.
agsantos5aa39652020-08-11 18:18:04 -04003 *
4 * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU 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 * This program 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 General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#pragma once
22
agsantosdd6a62a2021-03-29 17:13:27 -040023#include "pluginProcessor.h"
24
agsantos5aa39652020-08-11 18:18:04 -040025extern "C" {
26#include <libavutil/frame.h>
27}
28#include <observer.h>
29
agsantos5aa39652020-08-11 18:18:04 -040030#include <thread>
31#include <condition_variable>
agsantosdd6a62a2021-03-29 17:13:27 -040032#include <frameFilter.h>
agsantos5aa39652020-08-11 18:18:04 -040033
34namespace jami {
agsantosac1940d2020-09-17 10:18:40 -040035
agsantosac1940d2020-09-17 10:18:40 -040036class VideoSubscriber : public jami::Observer<AVFrame*>
37{
agsantos5aa39652020-08-11 18:18:04 -040038public:
agsantosdd6a62a2021-03-29 17:13:27 -040039 VideoSubscriber(const std::string& model, bool acc = false);
agsantos5aa39652020-08-11 18:18:04 -040040 ~VideoSubscriber();
41
agsantosac1940d2020-09-17 10:18:40 -040042 virtual void update(jami::Observable<AVFrame*>*, AVFrame* const&) override;
43 virtual void attached(jami::Observable<AVFrame*>*) override;
44 virtual void detached(jami::Observable<AVFrame*>*) override;
agsantos5aa39652020-08-11 18:18:04 -040045
46 void detach();
47 void stop();
agsantos9dcf4302020-09-01 18:21:48 -040048 void setBackground(const std::string& backgroundPath);
agsantosdd6a62a2021-03-29 17:13:27 -040049 void setBlur(bool isBlur);
50 void setBlurLevel(const std::string& blurLevel);
51 void initFilters();
agsantos5aa39652020-08-11 18:18:04 -040052
agsantos5aa39652020-08-11 18:18:04 -040053private:
54 // Observer pattern
agsantos2c8525e2021-03-19 11:18:01 -040055 Observable<AVFrame*>* observable_ {};
agsantosdd6a62a2021-03-29 17:13:27 -040056 int angle_ {0};
57 gsFrame inputFrame_ = {av_frame_alloc(), frameFree};
58 FrameFilter inputFilter_;
59 std::string inputFilterDescription_;
agsantos5aa39652020-08-11 18:18:04 -040060
61 // Threading
62 std::thread processFrameThread;
63 std::mutex inputLock;
64 std::condition_variable inputCv;
65
66 // Status variables of the processing
agsantosac1940d2020-09-17 10:18:40 -040067 bool firstRun {true};
68 bool running {true};
69 bool newFrame {false};
agsantos5aa39652020-08-11 18:18:04 -040070
agsantos5aa39652020-08-11 18:18:04 -040071 PluginProcessor pluginProcessor;
72};
agsantosac1940d2020-09-17 10:18:40 -040073} // namespace jami