File: yrecinfo.c

package info (click to toggle)
yiff 2.06-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 3,464 kB
  • ctags: 3,028
  • sloc: ansic: 47,463; makefile: 218; sh: 77
file content (241 lines) | stat: -rw-r--r-- 4,890 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <unistd.h>

#include <Y2/Y.h>
#include <Y2/Ylib.h>

#include "../include/string.h"

#ifndef DEF_CON_ARG
# define DEF_CON_ARG    "127.0.0.1:9433"
#endif            



/*
 *	Print help.
 */
void PrintUsage()
{
	printf("\
Usage: yrecinfo [options]\n\
\n\
    [options] can be any of the following:\n\
\n\
        --modes                      Print list of Audio modes.\n\
        --recorder <address:port>    Specify which YIFF server to connect to.\n\
\n"
	);


	return;
}



int main(int argc, char *argv[])
{
	int i, total;
	int print_audio_modes = 0;
	char *con_arg = NULL;

	YConnection *con = NULL;
	YEventAudioStats astats;
	YEventServerStats sstats;
	YAudioModeValuesStruct **audio_mode;


	/* Parse arguments. */
	for(i = 1; i < argc; i++)
	{
	    if(argv[i] == NULL)
		continue;

	    /* Help. */
	    if(strcasepfx(argv[i], "--h") ||
               strcasepfx(argv[i], "-h") ||
               !strcmp(argv[i], "?")
	    )
	    {
		PrintUsage();
		return(0);
	    }
	    /* Print Audio modes list. */
	    else if(strcasepfx(argv[i], "--m") ||
                    strcasepfx(argv[i], "-m")
            )
	    {
		print_audio_modes = 1;
	    }
	    /* Connect address. */
	    else if(strcasepfx(argv[i], "--rec") ||
                    strcasepfx(argv[i], "-rec")
	    )
	    {
		i++;
		if(i < argc)
		{
		    free(con_arg);
		    con_arg = StringCopyAlloc(argv[i]);
		}
		else
		{
		    fprintf(stderr,
			"%s: Requires argument.\n",
			argv[i - 1]
		    );
		}
	    }
	}


	/*
	 *	Connect to YIFF server.
	 */
	con = YOpenConnection(
	    NULL,		/* No start argument. */
	    con_arg
	);
	if(con == NULL)
	{
	    printf("%s: Cannot connect to YIFF server.\n",
		(con_arg == NULL) ? DEF_CON_ARG : con_arg
	    );

            free(con_arg);
            con_arg = NULL;

	    return(-1);
	}



	/*
	 *	Request and print stats.
	 */
        printf("recorder: %s\n",
            ((con_arg == NULL) ? DEF_CON_ARG : con_arg)
        );

	/* Server stats. */
	if(!YGetServerStats(con, &sstats))
	{
            printf("version: %i.%i\n",
                sstats.protocol_version_major,
		sstats.protocol_version_minor
            );

            printf("cycle load: %.1lf%%\n",
                sstats.cycle_load * 100
            );

            printf("maximum protocol statement: %i bytes\n",
                YNetRecvBufLen
            );
	}

	/* Audio mode values. */
	if(!YGetAudioStats(con, &astats))
	{
	    printf("cycle set: %i\n",
		astats.cycle_set
	    );

            printf("cycle: %i microseconds\n",
		astats.cycle_us
	    );
            printf("compensated cycle: %i microseconds\n",
                astats.compensated_cycle_us
            );

            printf("write ahead: %i microseconds\n",
                astats.write_ahead_us
            );
            printf("cumulative latency: %i microseconds\n",
                astats.cumulative_latency_us
            );

            printf("sample rate: %i Hz\n",
                astats.sample_rate
            );
            printf("channels: %i\n",
                astats.channels
            );
            printf("sample size: %i bits\n",
                astats.sample_size
            );
            printf("bytes per second: %i bytes\n",
                astats.bytes_per_sec
            );

            printf("allow sound buffer fragments: %s\n",  
                ((astats.allow_fragments) ? "yes" : "no")
            );
            printf("sound buffer fragments: %i\n",
		astats.num_fragments
	    );
	    printf("sound buffer size: %i bytes\n",
		astats.fragment_size
	    );

            printf("flip stereo: %s\n",
                ((astats.flip_stereo) ? "yes" : "no")
            );

            printf("direction: %i\n",
                astats.direction
            );
	}

	/* Print audio modes. */
	if(print_audio_modes)
	{
	 printf("\n");
	 audio_mode = YGetAudioModes(con, &total);
	 for(i = 0; i < total; i++)
	 {
	    if(audio_mode[i] == NULL)
		continue;

	    printf(
		"audio: %s\n",
		audio_mode[i]->name
	    );
	    printf("  sample rate: %i Hz\n",
		audio_mode[i]->sample_rate
            );
            printf("  channels: %i\n",
                audio_mode[i]->channels
            );
            printf("  sample size: %i bits\n",
                audio_mode[i]->sample_size
            );
	    if(audio_mode[i]->allow_fragmenting)
	    {
                printf("  sound buffer size: %i bytes\n",
                    audio_mode[i]->fragment_size_bytes
                );
                printf("  sound buffer fragments: %i\n",
                    audio_mode[i]->num_fragments
                );
	    }
	    printf("\n");
	 }
	 YFreeAudioModesList(audio_mode, total);
	}

	/*
	 *	Disconnect from YIFF server
	 */
	YCloseConnection(con, False);
	con = NULL;

	free(con_arg);
	con_arg = NULL;


	return(0);
}