Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1-only */
2 : /**
3 : * GStreamer / NNStreamer tensor_decoder subplugin, "protobuf"
4 : * Copyright (C) 2020 Yongjoo Ahn <yongjoo1.ahn@samsung.com>
5 : */
6 : /**
7 : * @file tensordec-protobuf.cc
8 : * @date 25 Mar 2020
9 : * @brief NNStreamer tensor-decoder subplugin, "protobuf",
10 : * which converts tensor or tensors to Protocol Buffers.
11 : * @see https://github.com/nnstreamer/nnstreamer
12 : * @author Yongjoo Ahn <yongjoo1.ahn@samsung.com>
13 : * @bug No known bugs except for NYI items
14 : *
15 : */
16 :
17 : #include <glib.h>
18 : #include <gst/gst.h>
19 : #include <nnstreamer_log.h>
20 : #include <nnstreamer_plugin_api.h>
21 : #include <nnstreamer_plugin_api_decoder.h>
22 : #include <nnstreamer_util.h>
23 : #include <tensor_typedef.h>
24 : #include "nnstreamer_protobuf.h"
25 : #include "tensordecutil.h"
26 :
27 : #ifdef __cplusplus
28 : extern "C" {
29 : #endif /* __cplusplus */
30 : void init_pb (void) __attribute__ ((constructor));
31 : void fini_pb (void) __attribute__ ((destructor));
32 : #ifdef __cplusplus
33 : }
34 : #endif /* __cplusplus */
35 :
36 : /**
37 : * @brief tensordec-plugin's GstTensorDecoderDef callback
38 : */
39 : static int
40 21 : pb_init (void **pdata)
41 : {
42 21 : *pdata = NULL; /* no private data are needed for this sub-plugin */
43 21 : return TRUE;
44 : }
45 :
46 : /**
47 : * @brief tensordec-plugin's GstTensorDecoderDef callback
48 : */
49 : static void
50 21 : pb_exit (void **pdata)
51 : {
52 : UNUSED (pdata);
53 21 : return;
54 : }
55 :
56 : /**
57 : * @brief tensordec-plugin's GstTensorDecoderDef callback
58 : */
59 : static int
60 0 : pb_setOption (void **pdata, int opNum, const char *param)
61 : {
62 : UNUSED (pdata);
63 : UNUSED (opNum);
64 : UNUSED (param);
65 0 : return TRUE;
66 : }
67 :
68 : /**
69 : * @brief tensordec-plugin's GstTensorDecoderDef callback
70 : */
71 : static GstCaps *
72 148 : pb_getOutCaps (void **pdata, const GstTensorsConfig *config)
73 : {
74 : GstCaps *caps;
75 : UNUSED (pdata);
76 148 : caps = gst_caps_from_string (GST_PROTOBUF_TENSOR_CAP_DEFAULT);
77 148 : setFramerateFromConfig (caps, config);
78 148 : return caps;
79 : }
80 :
81 : /** @brief tensordec-plugin's GstTensorDecoderDef callback */
82 : static GstFlowReturn
83 84 : pb_decode (void **pdata, const GstTensorsConfig *config,
84 : const GstTensorMemory *input, GstBuffer *outbuf)
85 : {
86 : UNUSED (pdata);
87 84 : return gst_tensor_decoder_protobuf (config, input, outbuf);
88 : }
89 :
90 : static gchar decoder_subplugin_protobuf[] = "protobuf";
91 :
92 : /**
93 : * @brief protocol buffers tensordec-plugin GstTensorDecoderDef instance
94 : */
95 : static GstTensorDecoderDef protobuf = { .modename = decoder_subplugin_protobuf,
96 : .init = pb_init,
97 : .exit = pb_exit,
98 : .setOption = pb_setOption,
99 : .getOutCaps = pb_getOutCaps,
100 : .decode = pb_decode,
101 : .getTransformSize = NULL };
102 :
103 : /**
104 : * @brief Initialize this object for tensordec-plugin
105 : */
106 : void
107 45 : init_pb (void)
108 : {
109 45 : nnstreamer_decoder_probe (&protobuf);
110 45 : }
111 :
112 : /** @brief Destruct this object for tensordec-plugin */
113 : void
114 45 : fini_pb (void)
115 : {
116 45 : nnstreamer_decoder_exit (protobuf.modename);
117 45 : }
|