Aline Gondim Santos | 329f862 | 2022-11-08 08:04:22 -0300 | [diff] [blame] | 1 | /** |
| 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 | |
| 23 | extern "C" { |
| 24 | #include <libavutil/frame.h> |
| 25 | } |
| 26 | #include <observer.h> |
| 27 | |
| 28 | #include <frameFilter.h> |
Adrien Beraud | 087d559 | 2023-03-06 11:22:33 -0500 | [diff] [blame] | 29 | #include <frameUtils.h> |
Aline Gondim Santos | 329f862 | 2022-11-08 08:04:22 -0300 | [diff] [blame] | 30 | #include "TranscriptVideoSubscriber.h" |
Aline Gondim Santos | bd032f8 | 2022-11-25 15:39:12 -0300 | [diff] [blame] | 31 | #include "PluginPreferenceHandler.h" |
Adrien Beraud | 087d559 | 2023-03-06 11:22:33 -0500 | [diff] [blame] | 32 | #include "resampler.h" |
Aline Gondim Santos | 329f862 | 2022-11-08 08:04:22 -0300 | [diff] [blame] | 33 | |
| 34 | #include <thread> |
| 35 | #include <condition_variable> |
Adrien Beraud | 087d559 | 2023-03-06 11:22:33 -0500 | [diff] [blame] | 36 | #include <deque> |
| 37 | #include <atomic> |
| 38 | |
| 39 | class RealtimeSttWhisper; |
Aline Gondim Santos | 329f862 | 2022-11-08 08:04:22 -0300 | [diff] [blame] | 40 | |
| 41 | namespace jami { |
| 42 | |
Aline Gondim Santos | 329f862 | 2022-11-08 08:04:22 -0300 | [diff] [blame] | 43 | class TranscriptAudioSubscriber : public Observer<AVFrame*> |
| 44 | { |
| 45 | public: |
Adrien Beraud | 087d559 | 2023-03-06 11:22:33 -0500 | [diff] [blame] | 46 | TranscriptAudioSubscriber(const std::string& dataPath, |
| 47 | TranscriptVideoSubscriber* videoSubscriber); |
Aline Gondim Santos | 329f862 | 2022-11-08 08:04:22 -0300 | [diff] [blame] | 48 | ~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 Beraud | 087d559 | 2023-03-06 11:22:33 -0500 | [diff] [blame] | 56 | void setParameter(const std::string& parameter, Parameter type); |
Aline Gondim Santos | bd032f8 | 2022-11-25 15:39:12 -0300 | [diff] [blame] | 57 | |
Aline Gondim Santos | 329f862 | 2022-11-08 08:04:22 -0300 | [diff] [blame] | 58 | private: |
Aline Gondim Santos | 329f862 | 2022-11-08 08:04:22 -0300 | [diff] [blame] | 59 | // Observer pattern |
Adrien Beraud | 087d559 | 2023-03-06 11:22:33 -0500 | [diff] [blame] | 60 | Observable<AVFrame*>* observable_ {}; |
Aline Gondim Santos | 440e812 | 2023-01-09 14:03:49 -0300 | [diff] [blame] | 61 | std::string language_ {"auto"}; |
Aline Gondim Santos | 329f862 | 2022-11-08 08:04:22 -0300 | [diff] [blame] | 62 | |
| 63 | // Data |
| 64 | std::string path_; |
| 65 | |
| 66 | // Status variables of the processing |
| 67 | bool firstRun {true}; |
Adrien Beraud | 087d559 | 2023-03-06 11:22:33 -0500 | [diff] [blame] | 68 | std::atomic_bool running {false}; |
Aline Gondim Santos | 329f862 | 2022-11-08 08:04:22 -0300 | [diff] [blame] | 69 | |
Aline Gondim Santos | 440e812 | 2023-01-09 14:03:49 -0300 | [diff] [blame] | 70 | std::mutex inputLock; |
Adrien Beraud | 087d559 | 2023-03-06 11:22:33 -0500 | [diff] [blame] | 71 | std::condition_variable cv_; |
Aline Gondim Santos | 329f862 | 2022-11-08 08:04:22 -0300 | [diff] [blame] | 72 | |
| 73 | // Model |
Adrien Beraud | 087d559 | 2023-03-06 11:22:33 -0500 | [diff] [blame] | 74 | std::unique_ptr<RealtimeSttWhisper> whisper_; |
| 75 | Resampler resampler_; |
| 76 | std::vector<uniqueFramePtr> frames_; |
Aline Gondim Santos | 329f862 | 2022-11-08 08:04:22 -0300 | [diff] [blame] | 77 | |
| 78 | // Threading |
| 79 | std::thread processFrameThread; |
Aline Gondim Santos | 440e812 | 2023-01-09 14:03:49 -0300 | [diff] [blame] | 80 | void processFrame(); |
Aline Gondim Santos | 329f862 | 2022-11-08 08:04:22 -0300 | [diff] [blame] | 81 | void stop(); |
Aline Gondim Santos | 440e812 | 2023-01-09 14:03:49 -0300 | [diff] [blame] | 82 | void start(); |
Aline Gondim Santos | 329f862 | 2022-11-08 08:04:22 -0300 | [diff] [blame] | 83 | |
| 84 | // Video processor |
Aline Gondim Santos | 440e812 | 2023-01-09 14:03:49 -0300 | [diff] [blame] | 85 | TranscriptVideoSubscriber* mVS_ {}; |
Aline Gondim Santos | 329f862 | 2022-11-08 08:04:22 -0300 | [diff] [blame] | 86 | }; |
| 87 | } // namespace jami |