blob: 8f37c54d9012bab1a1251d30986961fc4b025d27 [file] [log] [blame]
agsantos796b5af2020-12-22 19:38:27 -05001/**
Sébastien Blincb783e32021-02-12 11:34:10 -05002 * Copyright (C) 2004-2021 Savoir-faire Linux Inc.
agsantos796b5af2020-12-22 19:38:27 -05003 *
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
24extern "C" {
25#include <libavutil/frame.h>
26}
27#include <observer.h>
28
29// STl
30#include <map>
31#include <thread>
32#include <condition_variable>
33
34#include <opencv2/core.hpp>
35
36#include "pluginProcessor.h"
37#include <frameScaler.h>
38
39namespace jami {
40
41class FrameCopy
42{
43public:
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
54class VideoSubscriber : public jami::Observer<AVFrame*>
55{
56public:
57 VideoSubscriber(const std::string& dataPath);
58 ~VideoSubscriber();
59
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;
63
64 void detach();
65 void stop();
66 void setBackground(const std::string& backgroundPath);
67
68private:
69 // Observer pattern
70 Observable<AVFrame*>* observable_{};
71
72 // Data
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
87 bool firstRun {true};
88 bool running {true};
89 bool newFrame {false};
90
91 // std::shared_ptr<PluginProcessor> pluginProcessor;
92 PluginProcessor pluginProcessor;
93};
94} // namespace jami