History

Merge pull request #75 from martinellimarco/master

Ported @Pagten's target latency patch to pulseaudio IVSHMEM

Marco Martinelli committed 6 years ago

Commit 0f61a672 parents a7c3f9c 8b76c2e2 files · +40 −5Browse files

Unified · Split

2 files
  1. Receivers/pulseaudio-ivshmem/Makefile +1 −1
  2. Receivers/pulseaudio-ivshmem/scream-ivshmem-pulse.c +39 −4
Receivers/pulseaudio-ivshmem/Makefile+1−1
@@ -1,5 +1,5 @@
11 CC=gcc
2−CFLAGS = -Wall
2+CFLAGS = -Wall -O2
33
44 scream-pulse: scream-ivshmem-pulse.c
55 $(CC) $(CFLAGS) -o scream-ivshmem-pulse scream-ivshmem-pulse.c -lpulse-simple -lpulse
Receivers/pulseaudio-ivshmem/scream-ivshmem-pulse.c+39−4
@@ -20,7 +20,10 @@ · 19 unmodified lines
2020 static void show_usage(const char *arg0)
2121 {
2222 fprintf(stderr, "\n");
23− fprintf(stderr, "Usage: %s <ivshmem device path>\n", arg0);
23+ fprintf(stderr, "Usage: %s <ivshmem device path> [-t <latency>]\n", arg0);
24+ fprintf(stderr, "\n");
25+ fprintf(stderr, " All command line options are optional.\n");
26+ fprintf(stderr, " -t <latency>: Target latency in milliseconds. Defaults to 50ms.\n");
2427 fprintf(stderr, "\n");
2528 exit(1);
2629 }
@@ -61,7 +64,7 @@ struct shmheader { · 34 unmodified lines
6164 };
6265
6366 int main(int argc, char*argv[]) {
64− if (argc != 2) {
67+ if (argc < 2) {
6568 show_usage(argv[0]);
6669 }
6770
@@ -72,12 +75,32 @@ int main(int argc, char*argv[]) { · 4 unmodified lines
7275 pa_simple *s;
7376 pa_sample_spec ss;
7477 pa_channel_map channel_map;
78+ pa_buffer_attr buffer_attr;
7579
7680 unsigned char cur_sample_rate = 0;
7781 unsigned char cur_sample_size = 0;
7882 unsigned char cur_channels = 2;
7983 uint16_t cur_channel_map = 0x0003;
84+
85+ int target_latency_ms = 50;
8086
87+ int opt;
88+ while ((opt = getopt(argc, argv, "t:h")) != -1) {
89+ switch (opt) {
90+ case 't':
91+ target_latency_ms = atoi(optarg);
92+ if (target_latency_ms < 0) show_usage(argv[0]);
93+ break;
94+ default:
95+ show_usage(argv[0]);
96+ }
97+ }
98+ if (1+optind < argc) {
99+ fprintf(stderr, "Expected argument after options\n");
100+ show_usage(argv[0]);
101+ }
102+
103+
81104 // Opportunistic call to renice us, so we can keep up under
82105 // higher load conditions. This may fail when run as non-root.
83106 setpriority(PRIO_PROCESS, 0, -11);
@@ -92,6 +115,14 @@ int main(int argc, char*argv[]) { · 8 unmodified lines
92115 ss.format = PA_SAMPLE_S16LE;
93116 ss.rate = 44100;
94117 ss.channels = cur_channels;
118+
119+ // set buffer size for requested latency
120+ buffer_attr.maxlength = (uint32_t)-1;
121+ buffer_attr.tlength = pa_usec_to_bytes((pa_usec_t)target_latency_ms * 1000u, &ss);
122+ buffer_attr.prebuf = (uint32_t)-1;
123+ buffer_attr.minreq = (uint32_t)-1;
124+ buffer_attr.fragsize = (uint32_t)-1;
125+
95126 s = pa_simple_new(NULL,
96127 "Scream",
97128 PA_STREAM_PLAYBACK,
@@ -99,7 +130,7 @@ int main(int argc, char*argv[]) { · 1 unmodified line
99130 "Audio",
100131 &ss,
101132 &channel_map,
102− NULL,
133+ &buffer_attr,
103134 &error
104135 );
105136 if (!s) {
@@ -220,7 +251,11 @@ int main(int argc, char*argv[]) { · 114 unmodified lines
220251 }
221252
222253 if (ss.rate > 0) {
254+ // sample spec has changed, so the playback buffer size for the requested latency must be recalculated as well
255+ buffer_attr.tlength = pa_usec_to_bytes((pa_usec_t)target_latency_ms * 1000, &ss);
256+
223257 if (s) pa_simple_free(s);
258+
224259 s = pa_simple_new(NULL,
225260 "Scream",
226261 PA_STREAM_PLAYBACK,
@@ -228,7 +263,7 @@ int main(int argc, char*argv[]) { · 1 unmodified line
228263 "Audio",
229264 &ss,
230265 &channel_map,
231− NULL,
266+ &buffer_attr,
232267 NULL
233268 );
234269 if (s) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t