blob: 4e238d4317cade0609d2e9c88b702f0689a706e4 [file] [log] [blame]
agsantos5aa39652020-08-11 18:18:04 -04001/**
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
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// Frame Scaler
35#include <framescaler.h>
36
37// OpenCV headers
38#include <opencv2/core.hpp>
39
40#include "pluginProcessor.h"
41
42namespace jami {
43
44class FrameCopy {
45public:
46 // This frame is a resized version of the original in RGB format
47 cv::Mat resizedFrameRGB;
48 cv::Size resizedSize;
49 // This frame is used to draw predictions into in RGB format
50 cv::Mat predictionsFrameRGB;
51 cv::Size originalSize;
52 // This frame is used to draw predictions into in RGB format on a resized frame
53 cv::Mat predictionsResizedFrameRGB;
54};
55
56class VideoSubscriber : public jami::Observer<AVFrame*> {
57public:
58 VideoSubscriber(const std::string& dataPath);
59 ~VideoSubscriber();
60
61 virtual void update(jami::Observable<AVFrame*> *, AVFrame* const &) override;
62 virtual void attached(jami::Observable<AVFrame*> *) override;
63 virtual void detached(jami::Observable<AVFrame*> *) override;
64
65 void detach();
66 void stop();
67 void setBackground(const std::string& dataPath, const std::string& value);
68
69
70private:
71 // Observer pattern
72 Observable<AVFrame*> *observable_ = nullptr;
73
74 //Data
75 std::string path_;
76
77 // Frame
78 FrameCopy fcopy;
79 cv::Mat frame;
80
81 FrameScaler scaler;
82
83 // Threading
84 std::thread processFrameThread;
85 std::mutex inputLock;
86 std::condition_variable inputCv;
87
88 // Status variables of the processing
89 bool firstRun{true};
90 bool running{true};
91 bool newFrame{false};
92
93 //std::shared_ptr<PluginProcessor> pluginProcessor;
94 PluginProcessor pluginProcessor;
95};
96}