UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
sdi.c
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2011-2023 CESNET z.s.p.o.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, is permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of CESNET nor the names of its contributors may be
21 * used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
26 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
28 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifdef HAVE_CONFIG_H
39#include "config.h"
40#include "config_unix.h"
41#include "config_win32.h"
42#endif
43
44#include "audio/audio.h"
46#include "audio/playback/sdi.h"
47#include "debug.h"
48#include "lib_common.h"
49#include "video_display.h"
50
51#include <stdlib.h>
52#include <string.h>
53
55 void *udata;
56 void (*put_callback)(void *, const struct audio_frame *);
58 int channels, int sample_rate);
59 bool (*get_property_callback)(void *, int, void *, size_t *);
60};
61
62static void audio_play_sdi_probe_common(struct device_info **available_devices, int *count,
63 const char *dev, const char *name)
64{
65 *available_devices = (struct device_info *) calloc(1, sizeof(struct device_info));
66 strncpy((*available_devices)[0].dev, dev, sizeof (*available_devices)[0].dev - 1);
67 strncpy((*available_devices)[0].name, name, sizeof (*available_devices)[0].name - 1);
68 snprintf((*available_devices)[0].extra, sizeof (*available_devices)[0].extra, "\"isEmbeddedAudio\":\"t\"");
69 *count = 1;
70}
71
72static void audio_play_sdi_probe_embedded(struct device_info **available_devices, int *count, void (**deleter)(void *))
73{
74 *deleter = free;
75 audio_play_sdi_probe_common(available_devices, count, "", "Embedded SDI/HDMI audio");
76}
77
78static void audio_play_sdi_probe_aesebu(struct device_info **available_devices, int *count, void (**deleter)(void *))
79{
80 *deleter = free;
81 audio_play_sdi_probe_common(available_devices, count, "", "Digital AES/EBU audio");
82}
83
84static void audio_play_sdi_probe_analog(struct device_info **available_devices, int *count, void (**deleter)(void *))
85{
86 *deleter = free;
87 audio_play_sdi_probe_common(available_devices, count, "", "Analog audio through playback card");
88}
89
90static void audio_play_sdi_help(const char *driver_name)
91{
92 if(strcmp(driver_name, "embedded") == 0) {
93 printf("\tembedded : SDI audio (if available)\n");
94 } else if(strcmp(driver_name, "AESEBU") == 0) {
95 printf("\tAESEBU : separately connected AES/EBU cabling to grabbing card (if available)\n");
96 } else if(strcmp(driver_name, "analog") == 0) {
97 printf("\tanalog : separately connected audio input (if available)\n");
98 }
99}
100
101static void * audio_play_sdi_init(const char *cfg)
102{
103 if (strcmp(cfg, "help") == 0) {
104 printf("Available embedded devices:\n");
105 audio_play_sdi_help("embedded");
106 audio_play_sdi_help("AESEBU");
107 audio_play_sdi_help("analog");
108 return INIT_NOERR;
109 }
110 struct state_sdi_playback *s = malloc(sizeof(struct state_sdi_playback));
111 s->put_callback = NULL;
112 s->reconfigure_callback = NULL;
113 return s;
114}
115
116void
118 void (*putf)(void *, const struct audio_frame *),
119 bool (*reconfigure)(void *, int, int, int),
120 bool (*get_property)(void *, int, void *,
121 size_t *))
122{
123 struct state_sdi_playback *s = (struct state_sdi_playback *) state;
124
125 s->udata = udata;
126 s->put_callback = putf;
129}
130
131static void audio_play_sdi_put_frame(void *state, const struct audio_frame *frame)
132{
133 struct state_sdi_playback *s;
134 s = (struct state_sdi_playback *) state;
135
136 if(s->put_callback)
137 s->put_callback(s->udata, frame);
138}
139
140static bool audio_play_sdi_query_format(struct state_sdi_playback *s, void *data, size_t *len)
141{
143 return true;
144 } else {
145 log_msg(LOG_LEVEL_WARNING, "Cannot get audio format from playback card!\n");
146 struct audio_desc desc = {2, 48000, 2, AC_PCM};
147 if (*len >= sizeof desc) {
148 memcpy(data, &desc, sizeof desc);
149 *len = sizeof desc;
150 return true;
151 } else {
152 return false;
153 }
154 }
155}
156
157static bool audio_play_sdi_ctl(void *state, int request, void *data, size_t *len)
158{
159 struct state_sdi_playback *s = (struct state_sdi_playback *) state;
160 switch (request) {
162 return audio_play_sdi_query_format(s, data, len);
163 default:
164 return false;
165 }
166}
167
169{
170 struct state_sdi_playback *s = state;
171
172 if(s->reconfigure_callback) {
173 return s->reconfigure_callback(s->udata, desc.bps * 8,
174 desc.ch_count, desc.sample_rate);
175 }
176 return false;
177}
178
179static void audio_play_sdi_done(void *s)
180{
181 UNUSED(s);
182}
183
192
201
210
211
215
216
217/* vim: set expandtab sw=8: */
218
#define UNUSED(x)
void ** state
struct video_desc desc
int int int sample_rate
int int channels
struct video_frame * frame
int void size_t * len
int void(** deleter)(void *))
int quant_samples
@ AC_PCM
Definition types.h:53
#define AUDIO_PLAYBACK_CTL_QUERY_FORMAT
#define AUDIO_PLAYBACK_ABI_VERSION
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define LOG_LEVEL_WARNING
less severe errors
Definition debug.h:60
static int64_t get_property(int dri, drmModeObjectPropertiesPtr props, std::string_view name)
Definition drm.cpp:465
@ DISPLAY_PROPERTY_AUDIO_FORMAT
int count
Definition hd-rum.c:44
#define INIT_NOERR
Definition host.h:73
@ LIBRARY_CLASS_AUDIO_PLAYBACK
Definition lib_common.h:77
#define REGISTER_MODULE(name, info, lclass, abi)
Registers module to global modules' registry.
Definition lib_common.h:144
static const struct audio_playback_info aplay_sdi_info_aesebu
Definition sdi.c:193
static bool audio_play_sdi_query_format(struct state_sdi_playback *s, void *data, size_t *len)
Definition sdi.c:140
static void audio_play_sdi_probe_embedded(struct device_info **available_devices, int *count, void(**deleter)(void *))
Definition sdi.c:72
static void audio_play_sdi_probe_common(struct device_info **available_devices, int *count, const char *dev, const char *name)
Definition sdi.c:62
static void audio_play_sdi_help(const char *driver_name)
Definition sdi.c:90
static void audio_play_sdi_probe_aesebu(struct device_info **available_devices, int *count, void(**deleter)(void *))
Definition sdi.c:78
static void * audio_play_sdi_init(const char *cfg)
Definition sdi.c:101
static bool audio_play_sdi_ctl(void *state, int request, void *data, size_t *len)
Definition sdi.c:157
static bool audio_play_sdi_reconfigure(void *state, struct audio_desc desc)
Definition sdi.c:168
static void audio_play_sdi_put_frame(void *state, const struct audio_frame *frame)
Definition sdi.c:131
static void audio_play_sdi_probe_analog(struct device_info **available_devices, int *count, void(**deleter)(void *))
Definition sdi.c:84
static const struct audio_playback_info aplay_sdi_info_embedded
Definition sdi.c:184
static void audio_play_sdi_done(void *s)
Definition sdi.c:179
void sdi_register_display_callbacks(void *state, void *udata, void(*putf)(void *, const struct audio_frame *), bool(*reconfigure)(void *, int, int, int), bool(*get_property)(void *, int, void *, size_t *))
Definition sdi.c:117
static const struct audio_playback_info aplay_sdi_info_analog
Definition sdi.c:202
const char * name
Definition settings.cpp:193
struct used to comunicate with audio capture/playback device
Definition types.h:99
char extra[1024]
Definition types.h:389
char dev[1024]
Definition types.h:383
bool(* get_property_callback)(void *, int, void *, size_t *)
Definition sdi.c:59
bool(* reconfigure_callback)(void *state, int quant_samples, int channels, int sample_rate)
Definition sdi.c:57
void(* put_callback)(void *, const struct audio_frame *)
Definition sdi.c:56
void * udata
Definition sdi.c:55
static void reconfigure(struct state_vidcap_syphon *s, struct video_desc desc)
Definition syphon.m:166