• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gpu_data_plugin.h"
18 
19 namespace {
20 constexpr uint32_t MAX_BUFFER_SIZE = 4 * 1024 * 1024;
21 std::unique_ptr<GpuDataPlugin> g_plugin = nullptr;
22 std::mutex g_taskMutex;
23 } // namespace
24 
GpuDataPluginSessionStart(const uint8_t * configData,uint32_t configSize)25 static int GpuDataPluginSessionStart(const uint8_t* configData, uint32_t configSize)
26 {
27     std::lock_guard<std::mutex> guard(g_taskMutex);
28     CHECK_NOTNULL(g_plugin, -1, "%s: no GpuDataPlugin created!", __func__);
29     return g_plugin->Start(configData, configSize);
30 }
31 
GpuPluginSessionStop()32 static int GpuPluginSessionStop()
33 {
34     std::lock_guard<std::mutex> guard(g_taskMutex);
35     CHECK_NOTNULL(g_plugin, -1, "%s: no GpuDataPlugin created!", __func__);
36     g_plugin->Stop();
37     g_plugin.reset();
38     return 0;
39 }
40 
GpuDataRegisterWriterStruct(WriterStruct * writer)41 static int GpuDataRegisterWriterStruct(WriterStruct* writer)
42 {
43     std::lock_guard<std::mutex> guard(g_taskMutex);
44     g_plugin = std::make_unique<GpuDataPlugin>();
45     g_plugin->SetWriter(writer);
46     return 0;
47 }
48 
49 static PluginModuleCallbacks g_callbacks = {
50     .onPluginSessionStart = GpuDataPluginSessionStart,
51     .onPluginReportResult = 0,
52     .onPluginSessionStop = GpuPluginSessionStop,
53     .onRegisterWriterStruct = (RegisterWriterStructCallback)GpuDataRegisterWriterStruct,
54 };
55 
56 EXPORT_API PluginModuleStruct g_pluginModule = {
57     .callbacks = &g_callbacks,
58     .name = "gpu-plugin",
59     .version = "1.02",
60     .resultBufferSizeHint = MAX_BUFFER_SIZE,
61 };
62