]> git.sesse.net Git - ffmpeg/blobdiff - libavdevice/alsa.c
avformat/aviobuf: End grace period of allowing 0 from read_packet
[ffmpeg] / libavdevice / alsa.c
index 1bbff30d5cc43f9a7a27d1d8741be28bf4894f5b..ee282fac1681c8856dc1bfa53ef3e659fd98be8a 100644 (file)
@@ -177,8 +177,8 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
     snd_pcm_uframes_t buffer_size, period_size;
     uint64_t layout = ctx->streams[0]->codecpar->channel_layout;
 
-    if (ctx->filename[0] == 0) audio_device = "default";
-    else                       audio_device = ctx->filename;
+    if (ctx->url[0] == 0) audio_device = "default";
+    else                  audio_device = ctx->url;
 
     if (*codec_id == AV_CODEC_ID_NONE)
         *codec_id = DEFAULT_CODEC_ID;
@@ -286,6 +286,10 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
         }
     }
 
+    s->pkt = av_packet_alloc();
+    if (!s->pkt)
+        goto fail1;
+
     s->h = h;
     return 0;
 
@@ -300,12 +304,15 @@ av_cold int ff_alsa_close(AVFormatContext *s1)
 {
     AlsaData *s = s1->priv_data;
 
-    snd_pcm_nonblock(s->h, 0);
-    snd_pcm_drain(s->h);
+    if (snd_pcm_stream(s->h) == SND_PCM_STREAM_PLAYBACK) {
+        snd_pcm_nonblock(s->h, 0);
+        snd_pcm_drain(s->h);
+    }
     av_freep(&s->reorder_buf);
     if (CONFIG_ALSA_INDEV)
         ff_timefilter_destroy(s->timefilter);
     snd_pcm_close(s->h);
+    av_packet_free(&s->pkt);
     return 0;
 }