[FFmpeg-cvslog] ALSA: fix use of period_size.

Nicolas George git at videolan.org
Fri Jul 1 18:25:30 CEST 2011


ffmpeg | branch: master | Nicolas George <nicolas.george at normalesup.org> | Fri Jul  1 14:58:24 2011 +0200| [392acaedcb052fa64386d5d0aea4931386f72d64] | committer: Nicolas George

ALSA: fix use of period_size.

period_size is in frames, while the demuxer assumed it was in bytes,
resulting in short reads.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=392acaedcb052fa64386d5d0aea4931386f72d64
---

 libavdevice/alsa-audio-dec.c |    4 ++--
 libavdevice/alsa-audio.h     |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavdevice/alsa-audio-dec.c b/libavdevice/alsa-audio-dec.c
index 2424c02..e3ad98b 100644
--- a/libavdevice/alsa-audio-dec.c
+++ b/libavdevice/alsa-audio-dec.c
@@ -127,11 +127,11 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
     snd_htimestamp_t timestamp;
     snd_pcm_uframes_t ts_delay;
 
-    if (av_new_packet(pkt, s->period_size) < 0) {
+    if (av_new_packet(pkt, s->period_size * s->frame_size) < 0) {
         return AVERROR(EIO);
     }
 
-    while ((res = snd_pcm_readi(s->h, pkt->data, pkt->size / s->frame_size)) < 0) {
+    while ((res = snd_pcm_readi(s->h, pkt->data, s->period_size)) < 0) {
         if (res == -EAGAIN) {
             av_free_packet(pkt);
 
diff --git a/libavdevice/alsa-audio.h b/libavdevice/alsa-audio.h
index 0f467e3..9b1ecb1 100644
--- a/libavdevice/alsa-audio.h
+++ b/libavdevice/alsa-audio.h
@@ -45,8 +45,8 @@ typedef void (*ff_reorder_func)(const void *, void *, int);
 typedef struct {
     AVClass *class;
     snd_pcm_t *h;
-    int frame_size;  ///< preferred size for reads and writes
-    int period_size; ///< bytes per sample * channels
+    int frame_size;  ///< bytes per sample * channels
+    int period_size; ///< preferred size for reads and writes, in frames
     int sample_rate; ///< sample rate set by user
     int channels;    ///< number of channels set by user
     void (*reorder_func)(const void *, void *, int);



More information about the ffmpeg-cvslog mailing list