]> git.sesse.net Git - ffmpeg/commitdiff
ALSA: fix use of period_size.
authorNicolas George <nicolas.george@normalesup.org>
Fri, 1 Jul 2011 12:58:24 +0000 (14:58 +0200)
committerNicolas George <nicolas.george@normalesup.org>
Fri, 1 Jul 2011 16:18:53 +0000 (18:18 +0200)
period_size is in frames, while the demuxer assumed it was in bytes,
resulting in short reads.

libavdevice/alsa-audio-dec.c
libavdevice/alsa-audio.h

index 2424c022d33f58114c9034380d27168b7a7557c7..e3ad98b7f350f4e41c8fbeb727afe73cfb70d32a 100644 (file)
@@ -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);
 
index 0f467e34c9bf786b5b6de51215a47c6ffd7ea435..9b1ecb1696c813a6c98fe9cc798ac5ff7a9b2cb7 100644 (file)
@@ -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);