blob: 3e970e646fee37b4ca5cf1bc169b4d7551303f4b [file] [log] [blame]
Aline Gondim Santos329f8622022-11-08 08:04:22 -03001/**
2 * Copyright (C) 2022 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
23extern "C" {
24#include <libavutil/frame.h>
25}
26#include <observer.h>
27
28#include <frameFilter.h>
Adrien Beraud087d5592023-03-06 11:22:33 -050029#include <frameUtils.h>
Aline Gondim Santos329f8622022-11-08 08:04:22 -030030#include "TranscriptVideoSubscriber.h"
Aline Gondim Santosbd032f82022-11-25 15:39:12 -030031#include "PluginPreferenceHandler.h"
Adrien Beraud087d5592023-03-06 11:22:33 -050032#include "resampler.h"
Aline Gondim Santos329f8622022-11-08 08:04:22 -030033
34#include <thread>
35#include <condition_variable>
Adrien Beraud087d5592023-03-06 11:22:33 -050036#include <deque>
37#include <atomic>
38
39class RealtimeSttWhisper;
Aline Gondim Santos329f8622022-11-08 08:04:22 -030040
41namespace jami {
42
Aline Gondim Santos329f8622022-11-08 08:04:22 -030043class TranscriptAudioSubscriber : public Observer<AVFrame*>
44{
45public:
Adrien Beraud087d5592023-03-06 11:22:33 -050046 TranscriptAudioSubscriber(const std::string& dataPath,
47 TranscriptVideoSubscriber* videoSubscriber);
Aline Gondim Santos329f8622022-11-08 08:04:22 -030048 ~TranscriptAudioSubscriber();
49
50 virtual void update(Observable<AVFrame*>*, AVFrame* const&) override;
51 virtual void attached(Observable<AVFrame*>*) override;
52 virtual void detached(Observable<AVFrame*>*) override;
53
54 void detach();
55
Adrien Beraud087d5592023-03-06 11:22:33 -050056 void setParameter(const std::string& parameter, Parameter type);
Aline Gondim Santosbd032f82022-11-25 15:39:12 -030057
Aline Gondim Santos329f8622022-11-08 08:04:22 -030058private:
Aline Gondim Santos329f8622022-11-08 08:04:22 -030059 // Observer pattern
Adrien Beraud087d5592023-03-06 11:22:33 -050060 Observable<AVFrame*>* observable_ {};
Aline Gondim Santos440e8122023-01-09 14:03:49 -030061 std::string language_ {"auto"};
Aline Gondim Santos329f8622022-11-08 08:04:22 -030062
63 // Data
64 std::string path_;
65
66 // Status variables of the processing
67 bool firstRun {true};
Adrien Beraud087d5592023-03-06 11:22:33 -050068 std::atomic_bool running {false};
Aline Gondim Santos329f8622022-11-08 08:04:22 -030069
Aline Gondim Santos440e8122023-01-09 14:03:49 -030070 std::mutex inputLock;
Adrien Beraud087d5592023-03-06 11:22:33 -050071 std::condition_variable cv_;
Aline Gondim Santos329f8622022-11-08 08:04:22 -030072
73 // Model
Adrien Beraud087d5592023-03-06 11:22:33 -050074 std::unique_ptr<RealtimeSttWhisper> whisper_;
75 Resampler resampler_;
76 std::vector<uniqueFramePtr> frames_;
Aline Gondim Santos329f8622022-11-08 08:04:22 -030077
78 // Threading
79 std::thread processFrameThread;
Aline Gondim Santos440e8122023-01-09 14:03:49 -030080 void processFrame();
Aline Gondim Santos329f8622022-11-08 08:04:22 -030081 void stop();
Aline Gondim Santos440e8122023-01-09 14:03:49 -030082 void start();
Aline Gondim Santos329f8622022-11-08 08:04:22 -030083
84 // Video processor
Aline Gondim Santos440e8122023-01-09 14:03:49 -030085 TranscriptVideoSubscriber* mVS_ {};
Aline Gondim Santos329f8622022-11-08 08:04:22 -030086};
87} // namespace jami