agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2004-2020 Savoir-faire Linux Inc. |
| 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 | |
| 23 | // AvFrame |
| 24 | extern "C" { |
| 25 | #include <libavutil/frame.h> |
| 26 | } |
| 27 | #include <observer.h> |
| 28 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 29 | // STl |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 30 | #include <map> |
| 31 | #include <thread> |
| 32 | #include <condition_variable> |
| 33 | |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 34 | #include <opencv2/core.hpp> |
| 35 | |
| 36 | #include "pluginProcessor.h" |
agsantos | c9181b4 | 2020-11-26 12:03:04 -0500 | [diff] [blame] | 37 | #include <frameScaler.h> |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 38 | |
| 39 | namespace jami { |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 40 | |
| 41 | class FrameCopy |
| 42 | { |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 43 | public: |
| 44 | // This frame is a resized version of the original in RGB format |
| 45 | cv::Mat resizedFrameRGB; |
| 46 | cv::Size resizedSize; |
| 47 | // This frame is used to draw predictions into in RGB format |
| 48 | cv::Mat predictionsFrameRGB; |
| 49 | cv::Size originalSize; |
| 50 | // This frame is used to draw predictions into in RGB format on a resized frame |
| 51 | cv::Mat predictionsResizedFrameRGB; |
| 52 | }; |
| 53 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 54 | class VideoSubscriber : public jami::Observer<AVFrame*> |
| 55 | { |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 56 | public: |
agsantos | 796b5af | 2020-12-22 19:38:27 -0500 | [diff] [blame^] | 57 | VideoSubscriber(const std::string& dataPath, const std::string& model, const std::string& backgroundImage, bool acc); |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 58 | ~VideoSubscriber(); |
| 59 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 60 | virtual void update(jami::Observable<AVFrame*>*, AVFrame* const&) override; |
| 61 | virtual void attached(jami::Observable<AVFrame*>*) override; |
| 62 | virtual void detached(jami::Observable<AVFrame*>*) override; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 63 | |
| 64 | void detach(); |
| 65 | void stop(); |
agsantos | 9dcf430 | 2020-09-01 18:21:48 -0400 | [diff] [blame] | 66 | void setBackground(const std::string& backgroundPath); |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 67 | |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 68 | private: |
| 69 | // Observer pattern |
agsantos | b3c9084 | 2020-12-10 14:19:41 -0500 | [diff] [blame] | 70 | Observable<AVFrame*>* observable_{}; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 71 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 72 | // Data |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 73 | std::string path_; |
| 74 | |
| 75 | // Frame |
| 76 | FrameCopy fcopy; |
| 77 | cv::Mat frame; |
| 78 | |
| 79 | FrameScaler scaler; |
| 80 | |
| 81 | // Threading |
| 82 | std::thread processFrameThread; |
| 83 | std::mutex inputLock; |
| 84 | std::condition_variable inputCv; |
| 85 | |
| 86 | // Status variables of the processing |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 87 | bool firstRun {true}; |
| 88 | bool running {true}; |
| 89 | bool newFrame {false}; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 90 | |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 91 | // std::shared_ptr<PluginProcessor> pluginProcessor; |
agsantos | 5aa3965 | 2020-08-11 18:18:04 -0400 | [diff] [blame] | 92 | PluginProcessor pluginProcessor; |
| 93 | }; |
agsantos | ac1940d | 2020-09-17 10:18:40 -0400 | [diff] [blame] | 94 | } // namespace jami |