Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1-only */
2 : /**
3 : * GStreamer / NNStreamer tensor_converter subplugin, "protobuf"
4 : * Copyright (C) 2020 Gichan Jang <gichan2.jang@samsung.com>
5 : */
6 : /**
7 : * @file tensor_converter_protobuf.cc
8 : * @date 2 June 2020
9 : * @brief NNStreamer tensor-converter subplugin, "protobuf",
10 : * which converts protobuf byte stream to tensors.
11 : * @see https://github.com/nnstreamer/nnstreamer
12 : * @author Gichan Jang <gichan2.jang@samsung.com>
13 : * @bug No known bugs except for NYI items
14 : *
15 : */
16 :
17 : /**
18 : * Install protobuf
19 : * We assume that you use Ubuntu linux distribution.
20 : * You may simply download binary packages from PPA
21 : *
22 : * $ sudo apt-add-repository ppa:nnstreamer
23 : * $ sudo apt update
24 : * $ sudo apt install libprotobuf-dev libprotobuf-lite17 libprotobuf17
25 : * protobuf-compiler17
26 : */
27 :
28 : #include <fstream>
29 : #include <glib.h>
30 : #include <gst/gstinfo.h>
31 : #include <iostream>
32 : #include <nnstreamer_log.h>
33 : #include <nnstreamer_plugin_api.h>
34 : #include <nnstreamer_plugin_api_converter.h>
35 : #include <nnstreamer_util.h>
36 : #include <string>
37 : #include <typeinfo>
38 : #include "nnstreamer_protobuf.h"
39 : #include "tensor_converter_util.h"
40 :
41 : #ifdef __cplusplus
42 : extern "C" {
43 : #endif /* __cplusplus */
44 : void init_pbc (void) __attribute__ ((constructor));
45 : void fini_pbc (void) __attribute__ ((destructor));
46 : #ifdef __cplusplus
47 : }
48 : #endif /* __cplusplus */
49 : /** @brief tensor converter plugin's NNStreamerExternalConverter callback */
50 : static GstCaps *
51 439 : pbc_query_caps (const GstTensorsConfig *config)
52 : {
53 : UNUSED (config);
54 439 : return gst_caps_from_string (GST_PROTOBUF_TENSOR_CAP_DEFAULT);
55 : }
56 :
57 : /** @brief tensor converter plugin's NNStreamerExternalConverter callback */
58 : static GstBuffer *
59 83 : pbc_convert (GstBuffer *in_buf, GstTensorsConfig *config, void *priv_data)
60 : {
61 : UNUSED (priv_data);
62 83 : return gst_tensor_converter_protobuf (in_buf, config, NULL);
63 : }
64 :
65 : static gchar converter_subplugin_protobuf[] = "protobuf";
66 :
67 : /** @brief protobuf tensor converter sub-plugin NNStreamerExternalConverter instance */
68 : static NNStreamerExternalConverter protobuf = { .name = converter_subplugin_protobuf,
69 : .convert = pbc_convert,
70 : .get_out_config = tcu_get_out_config,
71 : .query_caps = pbc_query_caps,
72 : .open = NULL,
73 : .close = NULL };
74 :
75 : /** @brief Initialize this object for tensor converter sub-plugin */
76 : void
77 420 : init_pbc (void)
78 : {
79 420 : registerExternalConverter (&protobuf);
80 420 : }
81 :
82 : /** @brief Destruct this object for tensor converter sub-plugin */
83 : void
84 420 : fini_pbc (void)
85 : {
86 420 : unregisterExternalConverter (protobuf.name);
87 420 : }
|