NVIDIA DeepStream SDK API Reference

6.4 Release
deepstream_asr_tts_app.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2022, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 
24 #ifndef __DEEPSTREAM_TTS_APP_H_
25 #define __DEEPSTREAM_TTS_APP_H_
26 
27 #include <gst/gst.h>
28 #include <gst/audio/audio.h>
29 #include <glib.h>
30 #include <stdio.h>
31 #include <stdlib.h>
33 
34 #define CHECK_PTR(ptr) \
35  if(ptr == NULL) \
36  { \
37  return -1; \
38  }
39 
40 #define MAX_FILENAME_LENGTH (256)
41 #define MUX_AUDIO_VIDEO_OUT
42 
43 /* Macro for linking Gstreamer elements with source request pad and static sink pad */
44 #define LINK_REQUEST_PAD_STATIC_PAD(src, srcpadname, sink, sinkpadname) \
45 { \
46  GstPad *srcpad = gst_element_request_pad_simple (src, srcpadname); \
47  if (!srcpad) { \
48  g_printerr ("%s source pad %s request failed.\n", #src, #srcpadname); \
49  return -1; \
50  } \
51  GstPad *sinkpad = gst_element_get_static_pad (sink, sinkpadname); \
52  if (!sinkpad) { \
53  g_printerr ("%s sink pad %s request failed.\n", #sink, #sinkpadname); \
54  return -1; \
55  } \
56 \
57  if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK) { \
58  g_printerr ("Failed to link %s to %s\n", #src, #sink); \
59  return -1; \
60  } \
61  gst_object_unref (srcpad); \
62  gst_object_unref (sinkpad); \
63 }
64 
65 /* Macro for linking Gstreamer elements with source static pad and request sink pad */
66 #define LINK_STATIC_PAD_REQUEST_PAD(src, srcpadname, sink, sinkpadname) \
67 { \
68  GstPad *srcpad = gst_element_get_static_pad (src, srcpadname); \
69  if (!srcpad) { \
70  g_printerr ("%s source pad %s request failed.\n", #src, #srcpadname); \
71  return -1; \
72  } \
73  GstPad *sinkpad = gst_element_request_pad_simple (sink, sinkpadname); \
74  if (!sinkpad) { \
75  g_printerr ("%s sink pad %s request failed.\n", #sink, #sinkpadname); \
76  return -1; \
77  } \
78 \
79  if (gst_pad_link (srcpad, sinkpad) != GST_PAD_LINK_OK) { \
80  g_printerr ("Failed to link %s to %s\n", #src, #sink); \
81  return -1; \
82  } \
83  gst_object_unref (srcpad); \
84  gst_object_unref (sinkpad); \
85 }
86 
87 #define ATTACH_STATIC_PAD_PROBE(element, padname, probe_type, probe, dataptr) \
88 { \
89  GstPad *pad = gst_element_get_static_pad (element, padname); \
90  if (!pad) { \
91  g_printerr ("Get pad failed for %s %s. Exiting.\n",#element, padname); \
92  return -1; \
93  } \
94  gst_pad_add_probe (pad, probe_type, probe, dataptr, NULL); \
95  gst_object_unref (pad); \
96 }
97 
98 
99 typedef struct __StreamCtx
100 {
101  gchar *uri;
102  guint stream_id;
103  guint has_audio;
104  guint bus_id;
105  GstElement *asr_pipeline;
106  GstElement *input_downmixer;
109  FILE *FP_asr;
110 } StreamCtx;
111 
112 typedef struct __AppCtx
113 {
114  guint num_sources;
116  GstElement **proxy_audio_sinks;
117  GstElement **proxy_audio_sources;
118  GstElement *renderer_pipeline;
119  gboolean enable_playback;
121  gboolean pts_mode;
122  gboolean sync;
123  guint bus_id;
126 } AppCtx;
127 
128 
129 int create_pipeline(AppCtx *appctx, int stream_num, StreamCtx *sctx,
130  GstElement **p_proxy_audio_sink);
131 int create_renderer_pipeline(AppCtx *appctx);
132 int start_pipeline(int stream_num, StreamCtx *sctx);
133 int destroy_pipeline(StreamCtx *sctx);
134 
135 guint get_num_sources (gchar *cfg_file_path);
136 gboolean parse_config_file (AppCtx *appctx, gchar *config_file);
137 
138 G_BEGIN_DECLS
139 
140 guint get_num_sources_yaml (gchar *cfg_file_path);
141 gboolean parse_config_file_yaml (AppCtx *appctx, gchar *config_file);
142 
143 G_END_DECLS
144 #endif
__StreamCtx::input_downmixer
GstElement * input_downmixer
Definition: deepstream_asr_tts_app.h:106
__AppCtx::app_config
NvDsAppConfig app_config
Definition: deepstream_asr_tts_app.h:125
__StreamCtx::asr_pipeline
GstElement * asr_pipeline
Definition: deepstream_asr_tts_app.h:105
AppCtx
REST server application context.
Definition: nvds_appctx_server.h:57
__AppCtx::proxy_audio_sinks
GstElement ** proxy_audio_sinks
Definition: deepstream_asr_tts_app.h:116
__AppCtx::num_sources
guint num_sources
Definition: deepstream_asr_tts_app.h:114
__StreamCtx::eos_received
int eos_received
Definition: deepstream_asr_tts_app.h:107
parse_config_file
gboolean parse_config_file(AppCtx *appctx, gchar *config_file)
__AppCtx::playback_output_file_name
const char * playback_output_file_name
Definition: deepstream_asr_tts_app.h:120
__StreamCtx::stream_id
guint stream_id
Definition: deepstream_asr_tts_app.h:102
__StreamCtx
Definition: deepstream_asr_tts_app.h:99
__AppCtx::pts_mode
gboolean pts_mode
Definition: deepstream_asr_tts_app.h:121
create_pipeline
int create_pipeline(AppCtx *appctx, int stream_num, StreamCtx *sctx, GstElement **p_proxy_audio_sink)
get_num_sources_yaml
G_BEGIN_DECLS guint get_num_sources_yaml(gchar *cfg_file_path)
deepstream_asr_tts_config_file_parser.h
__StreamCtx::FP_asr
FILE * FP_asr
Definition: deepstream_asr_tts_app.h:109
parse_config_file_yaml
gboolean parse_config_file_yaml(AppCtx *appctx, gchar *config_file)
__NvDsAppConfig
Definition: deepstream_asr_tts_config_file_parser.h:36
AppCtx
struct __AppCtx AppCtx
get_num_sources
guint get_num_sources(gchar *cfg_file_path)
destroy_pipeline
int destroy_pipeline(StreamCtx *sctx)
__StreamCtx::bus_id
guint bus_id
Definition: deepstream_asr_tts_app.h:104
__NvDsAudioConfig
Definition: deepstream_asr_tts_config_file_parser.h:30
__AppCtx::enable_playback
gboolean enable_playback
Definition: deepstream_asr_tts_app.h:119
__AppCtx::eos_received
int eos_received
Definition: deepstream_asr_tts_app.h:124
__AppCtx::sctx
StreamCtx * sctx
Definition: deepstream_asr_tts_app.h:115
__AppCtx::proxy_audio_sources
GstElement ** proxy_audio_sources
Definition: deepstream_asr_tts_app.h:117
start_pipeline
int start_pipeline(int stream_num, StreamCtx *sctx)
create_renderer_pipeline
int create_renderer_pipeline(AppCtx *appctx)
__StreamCtx::audio_config
NvDsAudioConfig audio_config
Definition: deepstream_asr_tts_app.h:108
__StreamCtx::uri
gchar * uri
Definition: deepstream_asr_tts_app.h:101
__StreamCtx::has_audio
guint has_audio
Definition: deepstream_asr_tts_app.h:103
__AppCtx::bus_id
guint bus_id
Definition: deepstream_asr_tts_app.h:123
StreamCtx
struct __StreamCtx StreamCtx
__AppCtx::sync
gboolean sync
Definition: deepstream_asr_tts_app.h:122
__AppCtx
Definition: deepstream_asr_tts_app.h:112
__AppCtx::renderer_pipeline
GstElement * renderer_pipeline
Definition: deepstream_asr_tts_app.h:118