blob: 5ca66180d2286944a186370a1343751331446964 [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
agsantosac1940d2020-09-17 10:18:40 -040029// STl
agsantos5aa39652020-08-11 18:18:04 -040030#include <map>
31#include <thread>
32#include <condition_variable>
33
agsantos5aa39652020-08-11 18:18:04 -040034#include <opencv2/core.hpp>
35
36#include "pluginProcessor.h"
agsantosc9181b42020-11-26 12:03:04 -050037#include <frameScaler.h>
agsantos5aa39652020-08-11 18:18:04 -040038
39namespace jami {
agsantosac1940d2020-09-17 10:18:40 -040040
41class FrameCopy
42{
agsantos5aa39652020-08-11 18:18:04 -040043public:
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
agsantosac1940d2020-09-17 10:18:40 -040054class VideoSubscriber : public jami::Observer<AVFrame*>
55{
agsantos5aa39652020-08-11 18:18:04 -040056public:
57 VideoSubscriber(const std::string& dataPath);
58 ~VideoSubscriber();
59
agsantosac1940d2020-09-17 10:18:40 -040060 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;
agsantos5aa39652020-08-11 18:18:04 -040063
64 void detach();
65 void stop();
agsantos9dcf4302020-09-01 18:21:48 -040066 void setBackground(const std::string& backgroundPath);
agsantos5aa39652020-08-11 18:18:04 -040067
agsantos5aa39652020-08-11 18:18:04 -040068private:
69 // Observer pattern
agsantosac1940d2020-09-17 10:18:40 -040070 Observable<AVFrame*>* observable_ = nullptr;
agsantos5aa39652020-08-11 18:18:04 -040071
agsantosac1940d2020-09-17 10:18:40 -040072 // Data
agsantos5aa39652020-08-11 18:18:04 -040073 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
agsantosac1940d2020-09-17 10:18:40 -040087 bool firstRun {true};
88 bool running {true};
89 bool newFrame {false};
agsantos5aa39652020-08-11 18:18:04 -040090
agsantosac1940d2020-09-17 10:18:40 -040091 // std::shared_ptr<PluginProcessor> pluginProcessor;
agsantos5aa39652020-08-11 18:18:04 -040092 PluginProcessor pluginProcessor;
93};
agsantosac1940d2020-09-17 10:18:40 -040094} // namespace jami