summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--audio.c13
-rw-r--r--ringbuffer.c20
-rw-r--r--ringbuffer.h9
4 files changed, 31 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index e0829be..72d32d9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
User johns
Date:
+ Make audio ring buffer size a multiple of 3,5,7,8.
+ Add reset ring buffer support.
Fix bug: alloca wrong size for audio buffer.
Handle jump in stream like stream start.
Always compile audio drift correction.
diff --git a/audio.c b/audio.c
index efc7ef0..6caef7e 100644
--- a/audio.c
+++ b/audio.c
@@ -178,8 +178,8 @@ static int AudioVolume; ///< current volume (0 .. 1000)
extern int VideoAudioDelay; ///< import audio/video delay
- /// default ring buffer size ~2s 8ch 16bit
-static const unsigned AudioRingBufferSize = 2 * 48000 * 8 * 2;
+ /// default ring buffer size ~2s 8ch 16bit (3 * 5 * 7 * 8)
+static const unsigned AudioRingBufferSize = 3 * 5 * 7 * 8 * 2 * 1000;
static int AudioChannelsInHw[9]; ///< table which channels are supported
enum _audio_rates
@@ -684,9 +684,7 @@ static int AudioRingAdd(unsigned sample_rate, int channels, int use_ac3)
AudioRing[AudioRingWrite].HwSampleRate = sample_rate;
AudioRing[AudioRingWrite].HwChannels = AudioChannelMatrix[u][channels];
AudioRing[AudioRingWrite].PTS = INT64_C(0x8000000000000000);
- // reset ring-buffer
- RingBufferReadAdvance(AudioRing[AudioRingWrite].RingBuffer,
- RingBufferUsedBytes(AudioRing[AudioRingWrite].RingBuffer));
+ RingBufferReset(AudioRing[AudioRingWrite].RingBuffer);
atomic_inc(&AudioRingFilled);
@@ -856,6 +854,11 @@ static int AlsaPlayRingbuffer(void)
// FIXME: if not all are written, we double amplify them
}
frames = snd_pcm_bytes_to_frames(AlsaPCMHandle, avail);
+ if (avail != snd_pcm_frames_to_bytes(AlsaPCMHandle, frames)) {
+ Error(_("audio/alsa: bytes lost -> out of sync\n"));
+ }
+#ifdef DEBUG
+#endif
for (;;) {
if (AlsaUseMmap) {
diff --git a/ringbuffer.c b/ringbuffer.c
index 81722e2..9466852 100644
--- a/ringbuffer.c
+++ b/ringbuffer.c
@@ -49,6 +49,18 @@ struct _ring_buffer_
};
/**
+** Reset ring buffer pointers.
+**
+** @param rb Ring buffer to reset read/write pointers.
+*/
+void RingBufferReset(RingBuffer * rb)
+{
+ rb->ReadPointer = rb->Buffer;
+ rb->WritePointer = rb->Buffer;
+ atomic_set(&rb->Filled, 0);
+}
+
+/**
** Allocate a new ring buffer.
**
** @param size Size of the ring buffer.
@@ -69,10 +81,8 @@ RingBuffer *RingBufferNew(size_t size)
}
rb->Size = size;
- rb->ReadPointer = rb->Buffer;
- rb->WritePointer = rb->Buffer;
rb->BufferEnd = rb->Buffer + size;
- atomic_set(&rb->Filled, 0);
+ RingBufferReset(rb);
return rb;
}
@@ -89,7 +99,7 @@ void RingBufferDel(RingBuffer * rb)
/**
** Advance write pointer in ring buffer.
**
-** @param rb Ring buffer to adance write pointer.
+** @param rb Ring buffer to advance write pointer.
** @param cnt Number of bytes to be adavanced.
**
** @returns Number of bytes that could be advanced in ring buffer.
@@ -198,7 +208,7 @@ size_t RingBufferGetWritePointer(RingBuffer * rb, void **wp)
/**
** Advance read pointer in ring buffer.
**
-** @param rb Ring buffer to adance read pointer.
+** @param rb Ring buffer to advance read pointer.
** @param cnt Number of bytes to be advanced.
**
** @returns Number of bytes that could be advanced in ring buffer.
diff --git a/ringbuffer.h b/ringbuffer.h
index a5e8a68..8a2b4c1 100644
--- a/ringbuffer.h
+++ b/ringbuffer.h
@@ -23,13 +23,16 @@
/// @addtogroup Ringbuffer
/// @{
- ///< ring buffer typedef
+ /// ring buffer typedef
typedef struct _ring_buffer_ RingBuffer;
- ///< create new ring buffer
+ /// reset ring buffer pointers
+extern void RingBufferReset(RingBuffer *);
+
+ /// create new ring buffer
extern RingBuffer *RingBufferNew(size_t);
- ///< free ring buffer
+ /// free ring buffer
extern void RingBufferDel(RingBuffer *);
/// write into ring buffer