• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef STREAM_PLUGIN_H
17 #define STREAM_PLUGIN_H
18 
19 #include "logging.h"
20 #include "plugin_module_api.h"
21 #include "stream_plugin_config.pb.h"
22 #include "stream_plugin_result.pb.h"
23 
24 #include <atomic>
25 #include <mutex>
26 #include <thread>
27 #include <vector>
28 
29 class StreamPlugin {
30 public:
31     StreamPlugin();
32     ~StreamPlugin();
33     int Start(const uint8_t* configData, uint32_t configSize);
34     int Stop();
35 
36     int SetWriter(WriterStruct* writer);
37     void Loop(void);
38     uint64_t GetTimeMS();
39 
40 private:
41     StreamConfig protoConfig_;
42     std::vector<char> buffer_;
43     WriterStruct* resultWriter_ = nullptr;
44 
45     std::mutex mutex_;
46     std::thread writeThread_;
47     std::atomic<bool> running_ = true;
48 };
49 
50 #endif // STREAM_PLUGIN_H