UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
dummy.c
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2015-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#include <inttypes.h>
39#include <stdlib.h>
40#include <string.h>
41
43#include "audio/types.h"
44#include "debug.h"
45#include "lib_common.h"
46#include "types.h"
47#include "utils/color_out.h"
48
49#define MOD_NAME "[dummy a.] "
50
51enum {
52 NDEF_TS = -1,
53};
54
56 bool debug;
57 int64_t first_ts;
58 int64_t last_ts;
59};
60
61static void audio_play_dummy_probe(struct device_info **available_devices, int *count, void (**deleter)(void *))
62{
63 *deleter = free;
64 *available_devices = NULL;
65 *count = 0;
66}
67
68static void audio_play_dummy_help(void)
69{
70 color_printf(TBOLD("dummy") " audio playback\n\n");
71 color_printf("Usage:\n\t" TBOLD(TRED("-r dummy") "[:debug]") "\n");
72 color_printf("\nwhere:\n");
73 color_printf("\t" TBOLD("debug") " - audio print frame TS + len\n");
74}
75
76static void * audio_play_dummy_init(const char *cfg)
77{
78 struct state_dummy_aplay *s = calloc(1, sizeof *s);
79 if (strcmp(cfg, "debug") == 0) {
80 s->debug = true;
81 } else if (strcmp(cfg, "help") == 0) {
83 free(s);
84 return INIT_NOERR;
85 } else if (strlen(cfg) > 0) {
86 MSG(ERROR, "Wrong option: %s\n", cfg);
87 free(s);
88 return NULL;
89 }
90
91 s->first_ts = NDEF_TS;
92 return s;
93}
94
95static void audio_play_dummy_put_frame(void *state, const struct audio_frame *f)
96{
97 struct state_dummy_aplay *s = state;
98 if (!s->debug) {
99 return;
100 }
101 if (s->first_ts == NDEF_TS) {
102 s->first_ts = f->timestamp;
103 }
104
105 const long long frm_beg_off = f->timestamp - s->first_ts;
106 const long long frm_last_off = f->timestamp - s->last_ts;
107 printf(MOD_NAME "Received TS: %10" PRId64
108 ", offset: %6lld, sample: %6lld (+%lld), len: %d\n",
109 f->timestamp, frm_beg_off, frm_beg_off * f->sample_rate / kHz90,
110 frm_last_off * f->sample_rate / kHz90,
111 f->data_len / f->bps / f->ch_count);
112 s->last_ts = f->timestamp;
113}
114
115static void audio_play_dummy_done(void *state)
116{
117 free(state);
118}
119
120static bool audio_play_dummy_ctl(void *state, int request, void *data, size_t *len)
121{
122 UNUSED(state), UNUSED(data), UNUSED(len);
123 switch (request) {
125 return true; // we accept any format
126 default:
127 return false;
128 }
129}
130
132{
134 return true;
135}
136
145
147
#define UNUSED(x)
void ** state
struct video_desc desc
int void size_t * len
int void(** deleter)(void *))
@ NDEF_TS
Definition dummy.c:52
static void audio_play_dummy_put_frame(void *state, const struct audio_frame *f)
Definition dummy.c:95
static bool audio_play_dummy_ctl(void *state, int request, void *data, size_t *len)
Definition dummy.c:120
static void * audio_play_dummy_init(const char *cfg)
Definition dummy.c:76
static void audio_play_dummy_help(void)
Definition dummy.c:68
static void audio_play_dummy_done(void *state)
Definition dummy.c:115
static bool audio_play_dummy_reconfigure(void *state, struct audio_desc desc)
Definition dummy.c:131
#define MOD_NAME
Definition dummy.c:49
static const struct audio_playback_info aplay_dummy_info
Definition dummy.c:137
static void audio_play_dummy_probe(struct device_info **available_devices, int *count, void(**deleter)(void *))
Definition dummy.c:61
This file contains definition of some common audio types.
#define AUDIO_PLAYBACK_CTL_QUERY_FORMAT
#define AUDIO_PLAYBACK_ABI_VERSION
int color_printf(const char *format,...)
#define TRED(x)
Definition color_out.h:75
#define TBOLD(x)
Definition color_out.h:70
#define MSG(l, fmt,...)
Definition debug.h:96
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
struct used to comunicate with audio capture/playback device
Definition types.h:99
int sample_rate
Definition types.h:101
int64_t timestamp
Definition types.h:109
int ch_count
Definition types.h:104
int data_len
Definition types.h:103
int bps
Definition types.h:100
int64_t last_ts
Definition dummy.c:58
int64_t first_ts
Definition dummy.c:57
This file contains some common data types.
@ kHz90
timestamp time base
Definition types.h:149