chiark
/
gitweb
/
~mdw
/
disorder
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
09ee2f0
)
sort of works
author
rjk@greenend.org.uk
<>
Sun, 16 Sep 2007 19:04:00 +0000
(20:04 +0100)
committer
rjk@greenend.org.uk
<>
Sun, 16 Sep 2007 19:04:00 +0000
(20:04 +0100)
clients/playrtp.c
patch
|
blob
|
blame
|
history
diff --git
a/clients/playrtp.c
b/clients/playrtp.c
index 5606fb5194f2d80e195bd6a4a4abea7d7db04aa2..75162eb83c8907a2223425d84883a8c4a43b19d1 100644
(file)
--- a/
clients/playrtp.c
+++ b/
clients/playrtp.c
@@
-296,6
+296,7
@@
static void play_rtp(void) {
size_t samples_written;
int prepared = 1;
int err;
size_t samples_written;
int prepared = 1;
int err;
+ int infilling = 0;
/* Open ALSA */
if((err = snd_pcm_open(&pcm,
/* Open ALSA */
if((err = snd_pcm_open(&pcm,
@@
-342,6
+343,7
@@
static void play_rtp(void) {
pthread_mutex_lock(&lock);
for(;;) {
/* Wait for the buffer to fill up a bit */
pthread_mutex_lock(&lock);
for(;;) {
/* Wait for the buffer to fill up a bit */
+ info("Buffering...");
while(nsamples < READAHEAD)
pthread_cond_wait(&cond, &lock);
if(!prepared) {
while(nsamples < READAHEAD)
pthread_cond_wait(&cond, &lock);
if(!prepared) {
@@
-352,6
+354,8
@@
static void play_rtp(void) {
/* Start at the first available packet */
next_timestamp = packets->timestamp;
active = 1;
/* Start at the first available packet */
next_timestamp = packets->timestamp;
active = 1;
+ infilling = 0;
+ info("Playing...");
/* Wait until the buffer empties out */
while(nsamples >= MINBUFFER) {
/* Wait for ALSA to ask us for more data */
/* Wait until the buffer empties out */
while(nsamples >= MINBUFFER) {
/* Wait for ALSA to ask us for more data */
@@
-368,7
+372,8
@@
static void play_rtp(void) {
packets->samples_raw + packets->nused,
frames_available);
if(frames_written < 0)
packets->samples_raw + packets->nused,
frames_available);
if(frames_written < 0)
- fatal(0, "error calling snd_pcm_writei: %d", err);
+ fatal(0, "error calling snd_pcm_writei: %ld",
+ (long)frames_written);
samples_written = frames_written * 2;
packets->nused += samples_written;
next_timestamp += samples_written;
samples_written = frames_written * 2;
packets->nused += samples_written;
next_timestamp += samples_written;
@@
-381,10
+386,16
@@
static void play_rtp(void) {
free(p);
pthread_cond_broadcast(&cond);
}
free(p);
pthread_cond_broadcast(&cond);
}
+ infilling = 0;
} else {
/* We don't have anything to play! We'd better play some 0s. */
static const uint16_t zeros[1024];
size_t samples_available = 1024, frames_available;
} else {
/* We don't have anything to play! We'd better play some 0s. */
static const uint16_t zeros[1024];
size_t samples_available = 1024, frames_available;
+
+ if(!infilling) {
+ info("Infilling...");
+ infilling = 1;
+ }
if(packets && next_timestamp + samples_available > packets->timestamp)
samples_available = packets->timestamp - next_timestamp;
frames_available = samples_available / 2;
if(packets && next_timestamp + samples_available > packets->timestamp)
samples_available = packets->timestamp - next_timestamp;
frames_available = samples_available / 2;
@@
-392,15
+403,20
@@
static void play_rtp(void) {
zeros,
frames_available);
if(frames_written < 0)
zeros,
frames_available);
if(frames_written < 0)
- fatal(0, "error calling snd_pcm_writei: %d", err);
+ fatal(0, "error calling snd_pcm_writei: %ld",
+ (long)frames_written);
next_timestamp += samples_written;
}
}
active = 0;
/* We stop playing for a bit until the buffer re-fills */
pthread_mutex_unlock(&lock);
next_timestamp += samples_written;
}
}
active = 0;
/* We stop playing for a bit until the buffer re-fills */
pthread_mutex_unlock(&lock);
+ if((err = snd_pcm_nonblock(pcm, 0)))
+ fatal(0, "error calling snd_pcm_nonblock: %d", err);
if((err = snd_pcm_drain(pcm)))
fatal(0, "error calling snd_pcm_drain: %d", err);
if((err = snd_pcm_drain(pcm)))
fatal(0, "error calling snd_pcm_drain: %d", err);
+ if((err = snd_pcm_nonblock(pcm, 1)))
+ fatal(0, "error calling snd_pcm_nonblock: %d", err);
prepared = 0;
pthread_mutex_lock(&lock);
}
prepared = 0;
pthread_mutex_lock(&lock);
}