agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 1 | /** |
Sébastien Blin | cb783e3 | 2021-02-12 11:34:10 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2021 Savoir-faire Linux Inc. |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 3 | * |
| 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 | |
agsantos | dd6a62a | 2021-03-29 17:13:27 -0400 | [diff] [blame] | 23 | #include "pluginProcessor.h" |
| 24 | |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 25 | extern "C" { |
| 26 | #include <libavutil/frame.h> |
| 27 | } |
| 28 | #include <observer.h> |
| 29 | |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 30 | #include <thread> |
| 31 | #include <condition_variable> |
agsantos | dd6a62a | 2021-03-29 17:13:27 -0400 | [diff] [blame] | 32 | #include <frameFilter.h> |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 33 | |
| 34 | namespace jami { |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 35 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 36 | class VideoSubscriber : public jami::Observer<AVFrame*> |
| 37 | { |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 38 | public: |
agsantos | dd6a62a | 2021-03-29 17:13:27 -0400 | [diff] [blame] | 39 | VideoSubscriber(const std::string& model, bool acc = false); |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 40 | ~VideoSubscriber(); |
| 41 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 42 | 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; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 45 | |
| 46 | void detach(); |
| 47 | void stop(); |
agsantos | 9dcf430 | 2020-09-01 18:21:48 -0400 | [diff] [blame] | 48 | void setBackground(const std::string& backgroundPath); |
agsantos | dd6a62a | 2021-03-29 17:13:27 -0400 | [diff] [blame] | 49 | void setBlur(bool isBlur); |
| 50 | void setBlurLevel(const std::string& blurLevel); |
| 51 | void initFilters(); |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 52 | |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 53 | private: |
| 54 | // Observer pattern |
agsantos | 2c8525e | 2021-03-19 11:18:01 -0400 | [diff] [blame] | 55 | Observable<AVFrame*>* observable_ {}; |
agsantos | dd6a62a | 2021-03-29 17:13:27 -0400 | [diff] [blame] | 56 | int angle_ {0}; |
| 57 | gsFrame inputFrame_ = {av_frame_alloc(), frameFree}; |
| 58 | FrameFilter inputFilter_; |
| 59 | std::string inputFilterDescription_; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 60 | |
| 61 | // Threading |
| 62 | std::thread processFrameThread; |
| 63 | std::mutex inputLock; |
| 64 | std::condition_variable inputCv; |
| 65 | |
| 66 | // Status variables of the processing |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 67 | bool firstRun {true}; |
| 68 | bool running {true}; |
| 69 | bool newFrame {false}; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 70 | |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 71 | PluginProcessor pluginProcessor; |
| 72 | }; |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 73 | } // namespace jami |