More debug for flush buffers. Bigger audio buffer.

This commit is contained in:
Johns 2012-03-23 18:43:20 +01:00
parent 24ba8175a3
commit bd4503f30b
2 changed files with 46 additions and 15 deletions

55
audio.c
View File

@ -223,7 +223,7 @@ static void AudioRingInit(void)
for (i = 0; i < AUDIO_RING_MAX; ++i) { for (i = 0; i < AUDIO_RING_MAX; ++i) {
// FIXME: // FIXME:
//AlsaRingBuffer = RingBufferNew(48000 * 8 * 2); // ~1s 8ch 16bit //AlsaRingBuffer = RingBufferNew(2 * 48000 * 8 * 2); // ~2s 8ch 16bit
} }
// one slot always reservered // one slot always reservered
AudioRingWrite = 1; AudioRingWrite = 1;
@ -432,8 +432,24 @@ static void AlsaFlushBuffers(void)
snd_pcm_state_t state; snd_pcm_state_t state;
if (AlsaRingBuffer && AlsaPCMHandle) { if (AlsaRingBuffer && AlsaPCMHandle) {
#ifdef DEBUG
const void *r;
void *w;
#endif
RingBufferReadAdvance(AlsaRingBuffer, RingBufferReadAdvance(AlsaRingBuffer,
RingBufferUsedBytes(AlsaRingBuffer)); RingBufferUsedBytes(AlsaRingBuffer));
#ifdef DEBUG
RingBufferGetWritePointer(AlsaRingBuffer, &w);
RingBufferGetReadPointer(AlsaRingBuffer, &r);
if (r != w) {
Fatal(_("audio/alsa: ringbuffer out of sync %zd-%zd\n"),
RingBufferGetWritePointer(AlsaRingBuffer, &w),
RingBufferGetReadPointer(AlsaRingBuffer, &r));
abort();
}
#endif
state = snd_pcm_state(AlsaPCMHandle); state = snd_pcm_state(AlsaPCMHandle);
Debug(3, "audio/alsa: flush state %s\n", snd_pcm_state_name(state)); Debug(3, "audio/alsa: flush state %s\n", snd_pcm_state_name(state));
if (state != SND_PCM_STATE_OPEN) { if (state != SND_PCM_STATE_OPEN) {
@ -722,19 +738,31 @@ static void AlsaThreadEnqueue(const void *samples, int count)
*/ */
static void AlsaVideoReady(void) static void AlsaVideoReady(void)
{ {
if (AudioSampleRate && AudioChannels) {
Debug(3, "audio/alsa: start %4zdms video start\n",
(RingBufferUsedBytes(AlsaRingBuffer) * 1000)
/ (AudioSampleRate * AudioChannels * AudioBytesProSample));
}
if (!AudioRunning) { if (!AudioRunning) {
size_t used;
used = RingBufferUsedBytes(AlsaRingBuffer);
// enough video + audio buffered // enough video + audio buffered
if (AlsaStartThreshold < RingBufferUsedBytes(AlsaRingBuffer)) { if (AlsaStartThreshold < used) {
// too much audio buffered, skip it
if (AlsaStartThreshold * 2 < used) {
Debug(3, "audio/alsa: start %4zdms skip ready\n",
((used - AlsaStartThreshold * 2) * 1000)
/ (AudioSampleRate * AudioChannels * AudioBytesProSample));
RingBufferReadAdvance(AlsaRingBuffer,
used - AlsaStartThreshold * 2);
}
AudioRunning = 1; AudioRunning = 1;
pthread_cond_signal(&AudioStartCond); pthread_cond_signal(&AudioStartCond);
} }
} }
if (AudioSampleRate && AudioChannels) {
Debug(3, "audio/alsa: start %4zdms video ready\n",
(RingBufferUsedBytes(AlsaRingBuffer) * 1000)
/ (AudioSampleRate * AudioChannels * AudioBytesProSample));
}
} }
/** /**
@ -976,6 +1004,9 @@ static int AlsaSetup(int *freq, int *channels, int use_ac3)
#if 1 // easy alsa hw setup way #if 1 // easy alsa hw setup way
// flush any buffered data // flush any buffered data
AudioFlushBuffers(); AudioFlushBuffers();
Debug(3, "audio: %dms flush\n", (AudioUsedBytes() * 1000)
/ (!AudioSampleRate + !AudioChannels +
AudioSampleRate * AudioChannels * AudioBytesProSample));
if (1) { // close+open to fix hdmi no sound bugs if (1) { // close+open to fix hdmi no sound bugs
handle = AlsaPCMHandle; handle = AlsaPCMHandle;
@ -1241,7 +1272,7 @@ static void AlsaInit(void)
#else #else
(void)AlsaNoopCallback; (void)AlsaNoopCallback;
#endif #endif
AlsaRingBuffer = RingBufferNew(48000 * 8 * 2); // ~1s 8ch 16bit AlsaRingBuffer = RingBufferNew(2 * 48000 * 8 * 2); // ~2s 8ch 16bit
AlsaInitPCM(); AlsaInitPCM();
AlsaInitMixer(); AlsaInitMixer();
@ -1914,7 +1945,7 @@ void OssPause(void)
*/ */
static void OssInit(void) static void OssInit(void)
{ {
OssRingBuffer = RingBufferNew(48000 * 8 * 2); // ~1s 8ch 16bit OssRingBuffer = RingBufferNew(2 * 48000 * 8 * 2); // ~2s 8ch 16bit
OssInitPCM(); OssInitPCM();
OssInitMixer(); OssInitMixer();
@ -2270,8 +2301,8 @@ void AudioSetClock(int64_t pts)
{ {
#ifdef DEBUG #ifdef DEBUG
if (AudioPTS != pts) { if (AudioPTS != pts) {
Debug(4, "audio: set clock to %#012" PRIx64 " %#012" PRIx64 " pts\n", Debug(4, "audio: set clock %s -> %s pts\n", Timestamp2String(AudioPTS),
AudioPTS, pts); Timestamp2String(pts));
} }
#endif #endif
AudioPTS = pts; AudioPTS = pts;

6
misc.h
View File

@ -107,7 +107,9 @@ static inline void Syslog(const int level, const char *format, ...)
#define Debug(level, fmt...) /* disabled */ #define Debug(level, fmt...) /* disabled */
#endif #endif
#ifdef AV_NOPTS_VALUE #ifndef AV_NOPTS_VALUE
#define AV_NOPTS_VALUE INT64_C(0x8000000000000000)
#endif
/** /**
** Nice time-stamp string. ** Nice time-stamp string.
@ -130,8 +132,6 @@ static inline const char *Timestamp2String(int64_t ts)
return buf[idx]; return buf[idx];
} }
#endif
/** /**
** Get ticks in ms. ** Get ticks in ms.
** **