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