more logging and a saner way to figure out what to play next
[disorder] / clients / playrtp.c
1 /*
2 * This file is part of DisOrder.
3 * Copyright (C) 2007 Richard Kettlewell
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
20
21 #include <config.h>
22 #include "types.h"
23
24 #include <getopt.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <sys/socket.h>
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <netdb.h>
31 #include <pthread.h>
32 #include <locale.h>
33
34 #include "log.h"
35 #include "mem.h"
36 #include "configuration.h"
37 #include "addr.h"
38 #include "syscalls.h"
39 #include "rtp.h"
40 #include "defs.h"
41
42 #if HAVE_COREAUDIO_AUDIOHARDWARE_H
43 # include <CoreAudio/AudioHardware.h>
44 #endif
45 #if API_ALSA
46 #include <alsa/asoundlib.h>
47 #endif
48
49 #define readahead linux_headers_are_borked
50
51 /** @brief RTP socket */
52 static int rtpfd;
53
54 /** @brief Output device */
55 static const char *device;
56
57 /** @brief Maximum samples per packet we'll support
58 *
59 * NB that two channels = two samples in this program.
60 */
61 #define MAXSAMPLES 2048
62
63 /** @brief Minimum buffer size
64 *
65 * We'll stop playing if there's only this many samples in the buffer. */
66 static unsigned minbuffer = 2 * 44100 / 10; /* 0.2 seconds */
67
68 /** @brief Maximum sample size
69 *
70 * The maximum supported size (in bytes) of one sample. */
71 #define MAXSAMPLESIZE 2
72
73 /** @brief Buffer size
74 *
75 * We'll only start playing when this many samples are available. */
76 static unsigned readahead = 4 * 2 * 44100; /* 4 seconds */
77
78 /** @brief Number of samples to infill by in one go */
79 #define INFILL_SAMPLES (44100 * 2) /* 1s */
80
81 #define MAXBUFFER (3 * 88200) /* maximum buffer contents */
82
83 /** @brief Received packet
84 *
85 * Packets are recorded in an ordered linked list. */
86 struct packet {
87 /** @brief Pointer to next packet
88 * The next packet might not be immediately next: if packets are dropped
89 * or mis-ordered there may be gaps at any given moment. */
90 struct packet *next;
91 /** @brief Number of samples in this packet */
92 uint32_t nsamples;
93 /** @brief Timestamp from RTP packet
94 *
95 * NB that "timestamps" are really sample counters.*/
96 uint32_t timestamp;
97 #if HAVE_COREAUDIO_AUDIOHARDWARE_H
98 /** @brief Converted sample data */
99 float samples_float[MAXSAMPLES];
100 #else
101 /** @brief Raw sample data */
102 unsigned char samples_raw[MAXSAMPLES * MAXSAMPLESIZE];
103 #endif
104 };
105
106 /** @brief Total number of samples available */
107 static unsigned long nsamples;
108
109 /** @brief Linked list of packets
110 *
111 * In ascending order of timestamp. */
112 static struct packet *packets;
113
114 /** @brief Timestamp of next packet to play.
115 *
116 * This is set to the timestamp of the last packet, plus the number of
117 * samples it contained. Only valid if @ref active is nonzero.
118 */
119 static uint32_t next_timestamp;
120
121 /** @brief True if actively playing
122 *
123 * This is true when playing and false when just buffering. */
124 static int active;
125
126 /** @brief Lock protecting @ref packets */
127 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
128
129 /** @brief Condition variable signalled whenever @ref packets is changed */
130 static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
131
132 static const struct option options[] = {
133 { "help", no_argument, 0, 'h' },
134 { "version", no_argument, 0, 'V' },
135 { "debug", no_argument, 0, 'd' },
136 { "device", required_argument, 0, 'D' },
137 { "min", required_argument, 0, 'm' },
138 { "buffer", required_argument, 0, 'b' },
139 { 0, 0, 0, 0 }
140 };
141
142 /** @brief Return true iff a < b in sequence-space arithmetic */
143 static inline int lt(uint32_t a, uint32_t b) {
144 return (uint32_t)(a - b) & 0x80000000;
145 }
146
147 /** @brief Return true iff a >= b in sequence-space arithmetic */
148 static inline int ge(uint32_t a, uint32_t b) {
149 return !lt(a, b);
150 }
151
152 /** @brief Return true iff a > b in sequence-space arithmetic */
153 static inline int gt(uint32_t a, uint32_t b) {
154 return lt(b, a);
155 }
156
157 /** @brief Return true iff a <= b in sequence-space arithmetic */
158 static inline int le(uint32_t a, uint32_t b) {
159 return !lt(b, a);
160 }
161
162 /** @brief Background thread collecting samples
163 *
164 * This function collects samples, perhaps converts them to the target format,
165 * and adds them to the packet list. */
166 static void *listen_thread(void attribute((unused)) *arg) {
167 struct packet *p = 0, **pp;
168 int n;
169 union {
170 struct rtp_header header;
171 uint8_t bytes[sizeof(uint16_t) * MAXSAMPLES + sizeof (struct rtp_header)];
172 } packet;
173 const uint16_t *const samples = (uint16_t *)(packet.bytes
174 + sizeof (struct rtp_header));
175
176 for(;;) {
177 if(!p)
178 p = xmalloc(sizeof *p);
179 n = read(rtpfd, packet.bytes, sizeof packet.bytes);
180 if(n < 0) {
181 switch(errno) {
182 case EINTR:
183 continue;
184 default:
185 fatal(errno, "error reading from socket");
186 }
187 }
188 /* Ignore too-short packets */
189 if((size_t)n <= sizeof (struct rtp_header))
190 continue;
191 p->timestamp = ntohl(packet.header.timestamp);
192 /* Ignore packets in the past */
193 if(active && lt(p->timestamp, next_timestamp)) {
194 info("dropping old packet, timestamp=%"PRIx32" < %"PRIx32,
195 p->timestamp, next_timestamp);
196 continue;
197 }
198 /* Convert to target format */
199 switch(packet.header.mpt & 0x7F) {
200 case 10:
201 p->nsamples = (n - sizeof (struct rtp_header)) / sizeof(uint16_t);
202 #if HAVE_COREAUDIO_AUDIOHARDWARE_H
203 /* Convert to what Core Audio expects */
204 for(n = 0; n < p->nsamples; ++n)
205 p->samples_float[n] = (int16_t)ntohs(samples[n]) * (0.5f / 32767);
206 #else
207 /* ALSA can do any necessary conversion itself (though it might be better
208 * to do any necessary conversion in the background) */
209 memcpy(p->samples_raw, samples, n - sizeof (struct rtp_header));
210 #endif
211 break;
212 /* TODO support other RFC3551 media types (when the speaker does) */
213 default:
214 fatal(0, "unsupported RTP payload type %d",
215 packet.header.mpt & 0x7F);
216 }
217 pthread_mutex_lock(&lock);
218 /* Stop reading if we've reached the maximum.
219 *
220 * This is rather unsatisfactory: it means that if packets get heavily
221 * out of order then we guarantee dropouts. But for now... */
222 while(nsamples >= MAXBUFFER)
223 pthread_cond_wait(&cond, &lock);
224 for(pp = &packets;
225 *pp && lt((*pp)->timestamp, p->timestamp);
226 pp = &(*pp)->next)
227 ;
228 /* So now either !*pp or *pp >= p */
229 if(*pp && p->timestamp == (*pp)->timestamp) {
230 /* *pp == p; a duplicate. Ideally we avoid the translation step here,
231 * but we'll worry about that another time. */
232 } else {
233 p->next = *pp;
234 *pp = p;
235 nsamples += p->nsamples;
236 pthread_cond_broadcast(&cond);
237 p = 0; /* we've consumed this packet */
238 }
239 pthread_mutex_unlock(&lock);
240 }
241 }
242
243 #if HAVE_COREAUDIO_AUDIOHARDWARE_H
244 /** @brief Callback from Core Audio */
245 static OSStatus adioproc(AudioDeviceID inDevice,
246 const AudioTimeStamp *inNow,
247 const AudioBufferList *inInputData,
248 const AudioTimeStamp *inInputTime,
249 AudioBufferList *outOutputData,
250 const AudioTimeStamp *inOutputTime,
251 void *inClientData) {
252 UInt32 nbuffers = outOutputData->mNumberBuffers;
253 AudioBuffer *ab = outOutputData->mBuffers;
254 float *samplesOut; /* where to write samples to */
255 size_t samplesOutLeft; /* space left */
256 size_t samplesInLeft;
257 size_t samplesToCopy;
258
259 pthread_mutex_lock(&lock);
260 samplesOut = ab->data;
261 samplesOutLeft = ab->mDataByteSize / sizeof (float);
262 while(packets && nbuffers > 0) {
263 if(packets->used == packets->nsamples) {
264 /* TODO if we dropped a packet then we should introduce a gap here */
265 struct packet *const p = packets;
266 packets = p->next;
267 free(p);
268 pthread_cond_broadcast(&cond);
269 continue;
270 }
271 if(samplesOutLeft == 0) {
272 --nbuffers;
273 ++ab;
274 samplesOut = ab->data;
275 samplesOutLeft = ab->mDataByteSize / sizeof (float);
276 continue;
277 }
278 /* Now: (1) there is some data left to read
279 * (2) there is some space to put it */
280 samplesInLeft = packets->nsamples - packets->used;
281 samplesToCopy = (samplesInLeft < samplesOutLeft
282 ? samplesInLeft : samplesOutLeft);
283 memcpy(samplesOut, packet->samples + packets->used, samplesToCopy);
284 packets->used += samplesToCopy;
285 samplesOut += samplesToCopy;
286 samesOutLeft -= samplesToCopy;
287 }
288 pthread_mutex_unlock(&lock);
289 return 0;
290 }
291 #endif
292
293 /** @brief Play an RTP stream
294 *
295 * This is the guts of the program. It is responsible for:
296 * - starting the listening thread
297 * - opening the audio device
298 * - reading ahead to build up a buffer
299 * - arranging for audio to be played
300 * - detecting when the buffer has got too small and re-buffering
301 */
302 static void play_rtp(void) {
303 pthread_t ltid;
304
305 /* We receive and convert audio data in a background thread */
306 pthread_create(&ltid, 0, listen_thread, 0);
307 #if API_ALSA
308 {
309 snd_pcm_t *pcm;
310 snd_pcm_hw_params_t *hwparams;
311 snd_pcm_sw_params_t *swparams;
312 /* Only support one format for now */
313 const int sample_format = SND_PCM_FORMAT_S16_BE;
314 unsigned rate = 44100;
315 const int channels = 2;
316 const int samplesize = channels * sizeof(uint16_t);
317 snd_pcm_uframes_t pcm_bufsize = MAXSAMPLES * samplesize * 3;
318 /* If we can write more than this many samples we'll get a wakeup */
319 const int avail_min = 256;
320 snd_pcm_sframes_t frames_written;
321 size_t samples_written;
322 int prepared = 1;
323 int err;
324 int infilling = 0, escape = 0;
325 time_t logged, now;
326 uint32_t packet_start, packet_end;
327
328 /* Open ALSA */
329 if((err = snd_pcm_open(&pcm,
330 device ? device : "default",
331 SND_PCM_STREAM_PLAYBACK,
332 SND_PCM_NONBLOCK)))
333 fatal(0, "error from snd_pcm_open: %d", err);
334 /* Set up 'hardware' parameters */
335 snd_pcm_hw_params_alloca(&hwparams);
336 if((err = snd_pcm_hw_params_any(pcm, hwparams)) < 0)
337 fatal(0, "error from snd_pcm_hw_params_any: %d", err);
338 if((err = snd_pcm_hw_params_set_access(pcm, hwparams,
339 SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
340 fatal(0, "error from snd_pcm_hw_params_set_access: %d", err);
341 if((err = snd_pcm_hw_params_set_format(pcm, hwparams,
342 sample_format)) < 0)
343 fatal(0, "error from snd_pcm_hw_params_set_format (%d): %d",
344 sample_format, err);
345 if((err = snd_pcm_hw_params_set_rate_near(pcm, hwparams, &rate, 0)) < 0)
346 fatal(0, "error from snd_pcm_hw_params_set_rate (%d): %d",
347 rate, err);
348 if((err = snd_pcm_hw_params_set_channels(pcm, hwparams,
349 channels)) < 0)
350 fatal(0, "error from snd_pcm_hw_params_set_channels (%d): %d",
351 channels, err);
352 if((err = snd_pcm_hw_params_set_buffer_size_near(pcm, hwparams,
353 &pcm_bufsize)) < 0)
354 fatal(0, "error from snd_pcm_hw_params_set_buffer_size (%d): %d",
355 MAXSAMPLES * samplesize * 3, err);
356 if((err = snd_pcm_hw_params(pcm, hwparams)) < 0)
357 fatal(0, "error calling snd_pcm_hw_params: %d", err);
358 /* Set up 'software' parameters */
359 snd_pcm_sw_params_alloca(&swparams);
360 if((err = snd_pcm_sw_params_current(pcm, swparams)) < 0)
361 fatal(0, "error calling snd_pcm_sw_params_current: %d", err);
362 if((err = snd_pcm_sw_params_set_avail_min(pcm, swparams, avail_min)) < 0)
363 fatal(0, "error calling snd_pcm_sw_params_set_avail_min %d: %d",
364 avail_min, err);
365 if((err = snd_pcm_sw_params(pcm, swparams)) < 0)
366 fatal(0, "error calling snd_pcm_sw_params: %d", err);
367
368 /* Ready to go */
369
370 time(&logged);
371 pthread_mutex_lock(&lock);
372 for(;;) {
373 /* Wait for the buffer to fill up a bit */
374 info("Buffering...");
375 while(nsamples < readahead)
376 pthread_cond_wait(&cond, &lock);
377 if(!prepared) {
378 if((err = snd_pcm_prepare(pcm)))
379 fatal(0, "error calling snd_pcm_prepare: %d", err);
380 prepared = 1;
381 }
382 /* Start at the first available packet */
383 next_timestamp = packets->timestamp;
384 active = 1;
385 infilling = 0;
386 escape = 0;
387 info("Playing...");
388 /* Wait until the buffer empties out */
389 while(nsamples >= minbuffer && !escape) {
390 time(&now);
391 if(now > logged + 10) {
392 logged = now;
393 info("%lu samples in buffer (%lus)", nsamples,
394 nsamples / (44100 * 2));
395 }
396 if(packets
397 && ge(next_timestamp, packets->timestamp + packets->nsamples)) {
398 struct packet *p = packets;
399
400 info("dropping buffered past packet %"PRIx32" < %"PRIx32,
401 packets->timestamp, next_timestamp);
402
403 packets = p->next;
404 if(packets)
405 assert(lt(p->timestamp, packets->timestamp));
406 nsamples -= p->nsamples;
407 free(p);
408 pthread_cond_broadcast(&cond);
409 continue;
410 }
411 /* Wait for ALSA to ask us for more data */
412 pthread_mutex_unlock(&lock);
413 snd_pcm_wait(pcm, -1);
414 pthread_mutex_lock(&lock);
415 /* ALSA is ready for more data */
416 packet_start = packets->timestamp;
417 packet_end = packets->timestamp + packets->nsamples;
418 if(ge(next_timestamp, packet_start)
419 && lt(next_timestamp, packet_end)) {
420 /* The target timestamp is somewhere in this packet */
421 const uint32_t offset = next_timestamp - packets->timestamp;
422 const uint32_t samples_available = (packets->timestamp + packets->nsamples) - next_timestamp;
423 const size_t frames_available = samples_available / 2;
424
425 frames_written = snd_pcm_writei(pcm,
426 packets->samples_raw + offset,
427 frames_available);
428 if(frames_written < 0) {
429 switch(frames_written) {
430 case -EAGAIN:
431 info("snd_pcm_wait() returned but we got -EAGAIN!");
432 break;
433 case -EPIPE:
434 error(0, "error calling snd_pcm_writei: %ld",
435 (long)frames_written);
436 escape = 1;
437 break;
438 default:
439 fatal(0, "error calling snd_pcm_writei: %ld",
440 (long)frames_written);
441 }
442 } else {
443 samples_written = frames_written * 2;
444 next_timestamp += samples_written;
445 if(ge(next_timestamp, packet_end)) {
446 /* We're done with this packet */
447 struct packet *p = packets;
448
449 packets = p->next;
450 if(packets)
451 assert(lt(p->timestamp, packets->timestamp));
452 nsamples -= p->nsamples;
453 free(p);
454 pthread_cond_broadcast(&cond);
455 }
456 infilling = 0;
457 }
458 } else {
459 /* We don't have anything to play! We'd better play some 0s. */
460 static const uint16_t zeros[INFILL_SAMPLES];
461 size_t samples_available = INFILL_SAMPLES, frames_available;
462
463 /* If the maximum infill would take us past the start of the next
464 * packet then we truncate the infill to the right amount. */
465 if(lt(packets->timestamp,
466 next_timestamp + samples_available))
467 samples_available = packets->timestamp - next_timestamp;
468 if((int)samples_available < 0) {
469 info("packets->timestamp: %"PRIx32" next_timestamp: %"PRIx32" next+max: %"PRIx32" available: %"PRIx32,
470 packets->timestamp, next_timestamp,
471 next_timestamp + INFILL_SAMPLES, samples_available);
472 }
473 frames_available = samples_available / 2;
474 if(!infilling) {
475 info("Infilling %d samples, next=%"PRIx32" but packet=%"PRIx32,
476 samples_available, next_timestamp, packets->timestamp);
477 //infilling++;
478 }
479 frames_written = snd_pcm_writei(pcm,
480 zeros,
481 frames_available);
482 if(frames_written < 0) {
483 switch(frames_written) {
484 case -EAGAIN:
485 info("snd_pcm_wait() returned but we got -EAGAIN!");
486 break;
487 case -EPIPE:
488 error(0, "error calling snd_pcm_writei: %ld",
489 (long)frames_written);
490 escape = 1;
491 break;
492 default:
493 fatal(0, "error calling snd_pcm_writei: %ld",
494 (long)frames_written);
495 }
496 } else {
497 samples_written = frames_written * 2;
498 next_timestamp += samples_written;
499 }
500 }
501 }
502 active = 0;
503 /* We stop playing for a bit until the buffer re-fills */
504 pthread_mutex_unlock(&lock);
505 if((err = snd_pcm_nonblock(pcm, 0)))
506 fatal(0, "error calling snd_pcm_nonblock: %d", err);
507 if(escape) {
508 if((err = snd_pcm_drop(pcm)))
509 fatal(0, "error calling snd_pcm_drop: %d", err);
510 escape = 0;
511 } else
512 if((err = snd_pcm_drain(pcm)))
513 fatal(0, "error calling snd_pcm_drain: %d", err);
514 if((err = snd_pcm_nonblock(pcm, 1)))
515 fatal(0, "error calling snd_pcm_nonblock: %d", err);
516 prepared = 0;
517 pthread_mutex_lock(&lock);
518 }
519
520 }
521 #elif HAVE_COREAUDIO_AUDIOHARDWARE_H
522 {
523 OSStatus status;
524 UInt32 propertySize;
525 AudioDeviceID adid;
526 AudioStreamBasicDescription asbd;
527
528 /* If this looks suspiciously like libao's macosx driver there's an
529 * excellent reason for that... */
530
531 /* TODO report errors as strings not numbers */
532 propertySize = sizeof adid;
533 status = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
534 &propertySize, &adid);
535 if(status)
536 fatal(0, "AudioHardwareGetProperty: %d", (int)status);
537 if(adid == kAudioDeviceUnknown)
538 fatal(0, "no output device");
539 propertySize = sizeof asbd;
540 status = AudioDeviceGetProperty(adid, 0, false,
541 kAudioDevicePropertyStreamFormat,
542 &propertySize, &asbd);
543 if(status)
544 fatal(0, "AudioHardwareGetProperty: %d", (int)status);
545 D(("mSampleRate %f", asbd.mSampleRate));
546 D(("mFormatID %08"PRIx32, asbd.mFormatID));
547 D(("mFormatFlags %08"PRIx32, asbd.mFormatFlags));
548 D(("mBytesPerPacket %08"PRIx32, asbd.mBytesPerPacket));
549 D(("mFramesPerPacket %08"PRIx32, asbd.mFramesPerPacket));
550 D(("mBytesPerFrame %08"PRIx32, asbd.mBytesPerFrame));
551 D(("mChannelsPerFrame %08"PRIx32, asbd.mChannelsPerFrame));
552 D(("mBitsPerChannel %08"PRIx32, asbd.mBitsPerChannel));
553 D(("mReserved %08"PRIx32, asbd.mReserved));
554 if(asbd.mFormatID != kAudioFormatLinearPCM)
555 fatal(0, "audio device does not support kAudioFormatLinearPCM");
556 status = AudioDeviceAddIOProc(adid, adioproc, 0);
557 if(status)
558 fatal(0, "AudioDeviceAddIOProc: %d", (int)status);
559 pthread_mutex_lock(&lock);
560 for(;;) {
561 /* Wait for the buffer to fill up a bit */
562 while(nsamples < readahead)
563 pthread_cond_wait(&cond, &lock);
564 /* Start playing now */
565 status = AudioDeviceStart(adid, adioproc);
566 if(status)
567 fatal(0, "AudioDeviceStart: %d", (int)status);
568 /* Wait until the buffer empties out */
569 while(nsamples >= minbuffer)
570 pthread_cond_wait(&cond, &lock);
571 /* Stop playing for a bit until the buffer re-fills */
572 status = AudioDeviceStop(adid, adioproc);
573 if(status)
574 fatal(0, "AudioDeviceStop: %d", (int)status);
575 /* Go back round */
576 }
577 }
578 #else
579 # error No known audio API
580 #endif
581 }
582
583 /* display usage message and terminate */
584 static void help(void) {
585 xprintf("Usage:\n"
586 " disorder-playrtp [OPTIONS] ADDRESS [PORT]\n"
587 "Options:\n"
588 " --help, -h Display usage message\n"
589 " --version, -V Display version number\n"
590 " --debug, -d Turn on debugging\n"
591 " --device, -D DEVICE Output device\n"
592 " --min, -m FRAMES Buffer low water mark\n"
593 " --buffer, -b FRAMES Buffer high water mark\n");
594 xfclose(stdout);
595 exit(0);
596 }
597
598 /* display version number and terminate */
599 static void version(void) {
600 xprintf("disorder-playrtp version %s\n", disorder_version_string);
601 xfclose(stdout);
602 exit(0);
603 }
604
605 int main(int argc, char **argv) {
606 int n;
607 struct addrinfo *res;
608 struct stringlist sl;
609 char *sockname;
610
611 static const struct addrinfo prefs = {
612 AI_PASSIVE,
613 PF_INET,
614 SOCK_DGRAM,
615 IPPROTO_UDP,
616 0,
617 0,
618 0,
619 0
620 };
621
622 mem_init();
623 if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
624 while((n = getopt_long(argc, argv, "hVdD:m:b:", options, 0)) >= 0) {
625 switch(n) {
626 case 'h': help();
627 case 'V': version();
628 case 'd': debugging = 1; break;
629 case 'D': device = optarg; break;
630 case 'm': minbuffer = 2 * atol(optarg); break;
631 case 'b': readahead = 2 * atol(optarg); break;
632 default: fatal(0, "invalid option");
633 }
634 }
635 argc -= optind;
636 argv += optind;
637 if(argc < 1 || argc > 2)
638 fatal(0, "usage: disorder-playrtp [OPTIONS] ADDRESS [PORT]");
639 sl.n = argc;
640 sl.s = argv;
641 /* Listen for inbound audio data */
642 if(!(res = get_address(&sl, &prefs, &sockname)))
643 exit(1);
644 if((rtpfd = socket(res->ai_family,
645 res->ai_socktype,
646 res->ai_protocol)) < 0)
647 fatal(errno, "error creating socket");
648 if(bind(rtpfd, res->ai_addr, res->ai_addrlen) < 0)
649 fatal(errno, "error binding socket to %s", sockname);
650 play_rtp();
651 return 0;
652 }
653
654 /*
655 Local Variables:
656 c-basic-offset:2
657 comment-column:40
658 fill-column:79
659 indent-tabs-mode:nil
660 End:
661 */