]> git.sesse.net Git - ffmpeg/blobdiff - libavdevice/sndio_dec.c
mp3: exit on parsing error in mp_decode_frame
[ffmpeg] / libavdevice / sndio_dec.c
index ff2adeb0af449404918ba0654781ec8f1b3727dc..a29a088c4183057c5439cfe9e839f543185848b3 100644 (file)
 #include <sndio.h>
 
 #include "libavformat/avformat.h"
+#include "libavformat/internal.h"
+#include "libavutil/opt.h"
 
 #include "sndio_common.h"
 
-static av_cold int audio_read_header(AVFormatContext *s1,
-                                     AVFormatParameters *ap)
+static av_cold int audio_read_header(AVFormatContext *s1)
 {
     SndioData *s = s1->priv_data;
     AVStream *st;
     int ret;
 
-    if (ap->sample_rate <= 0 || ap->channels <= 0)
-        return AVERROR(EINVAL);
-
-    st = av_new_stream(s1, 0);
+    st = avformat_new_stream(s1, NULL);
     if (!st)
         return AVERROR(ENOMEM);
 
-    s->sample_rate = ap->sample_rate;
-    s->channels    = ap->channels;
-
     ret = ff_sndio_open(s1, 0, s1->filename);
     if (ret < 0)
         return ret;
@@ -53,7 +48,7 @@ static av_cold int audio_read_header(AVFormatContext *s1,
     st->codec->sample_rate = s->sample_rate;
     st->codec->channels    = s->channels;
 
-    av_set_pts_info(st, 64, 1, 1000000);  /* 64 bits pts in us */
+    avpriv_set_pts_info(st, 64, 1, 1000000);  /* 64 bits pts in us */
 
     return 0;
 }
@@ -97,6 +92,19 @@ static av_cold int audio_read_close(AVFormatContext *s1)
     return 0;
 }
 
+static const AVOption options[] = {
+    { "sample_rate", "", offsetof(SndioData, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+    { "channels",    "", offsetof(SndioData, channels),    AV_OPT_TYPE_INT, {.i64 = 2},     1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
+    { NULL },
+};
+
+static const AVClass sndio_demuxer_class = {
+    .class_name     = "sndio indev",
+    .item_name      = av_default_item_name,
+    .option         = options,
+    .version        = LIBAVUTIL_VERSION_INT,
+};
+
 AVInputFormat ff_sndio_demuxer = {
     .name           = "sndio",
     .long_name      = NULL_IF_CONFIG_SMALL("sndio audio capture"),
@@ -105,4 +113,5 @@ AVInputFormat ff_sndio_demuxer = {
     .read_packet    = audio_read_packet,
     .read_close     = audio_read_close,
     .flags          = AVFMT_NOFILE,
+    .priv_class     = &sndio_demuxer_class,
 };