1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
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 #include <mutex>
17 #include <memory>
18 #include <iostream>
19
20 #include "arkts_plugin.h"
21
22 namespace {
23 constexpr uint32_t MAX_BUFFER_SIZE = 4 * 1024 * 1024;
24 std::mutex g_taskMutex;
25 std::unique_ptr<ArkTSPlugin> g_plugin = nullptr;
26 } // namespace
27
ArkTSPluginSessionStart(const uint8_t * configData,uint32_t configSize)28 static int ArkTSPluginSessionStart(const uint8_t* configData, uint32_t configSize)
29 {
30 std::lock_guard<std::mutex> guard(g_taskMutex);
31 g_plugin->Start(configData, configSize);
32 return 0;
33 }
34
ArkTSPluginSessionStop()35 static int ArkTSPluginSessionStop()
36 {
37 std::lock_guard<std::mutex> guard(g_taskMutex);
38 g_plugin->Stop();
39 g_plugin = nullptr;
40 return 0;
41 }
42
ArkTSPluginRegisterWriterStruct(WriterStruct * writer)43 static int ArkTSPluginRegisterWriterStruct(WriterStruct* writer)
44 {
45 std::lock_guard<std::mutex> guard(g_taskMutex);
46 g_plugin = std::make_unique<ArkTSPlugin>();
47 g_plugin->SetWriter(writer);
48 return 0;
49 }
50
51 static PluginModuleCallbacks g_callbacks = {
52 .onPluginSessionStart = ArkTSPluginSessionStart,
53 .onPluginReportResult = 0,
54 .onPluginSessionStop = ArkTSPluginSessionStop,
55 .onRegisterWriterStruct = (RegisterWriterStructCallback)ArkTSPluginRegisterWriterStruct,
56 };
57
58 EXPORT_API PluginModuleStruct g_pluginModule = {
59 .callbacks = &g_callbacks,
60 .name = "arkts-plugin",
61 .version = "1.01",
62 .resultBufferSizeHint = MAX_BUFFER_SIZE,
63 };