Browse code

jack: add 'channels' private option.

Get rid of AVFormatParameters usage.

Anton Khirnov authored on 2011/07/17 15:08:57
Showing 1 changed files
... ...
@@ -26,6 +26,7 @@
26 26
 
27 27
 #include "libavutil/log.h"
28 28
 #include "libavutil/fifo.h"
29
+#include "libavutil/opt.h"
29 30
 #include "libavcodec/avcodec.h"
30 31
 #include "libavformat/avformat.h"
31 32
 #include "libavformat/timefilter.h"
... ...
@@ -36,6 +37,7 @@
36 36
 #define FIFO_PACKETS_NUM 16
37 37
 
38 38
 typedef struct {
39
+    AVClass        *class;
39 40
     jack_client_t * client;
40 41
     int             activated;
41 42
     sem_t           packet_count;
... ...
@@ -136,7 +138,7 @@ static int supply_new_packets(JackData *self, AVFormatContext *context)
136 136
     return 0;
137 137
 }
138 138
 
139
-static int start_jack(AVFormatContext *context, AVFormatParameters *params)
139
+static int start_jack(AVFormatContext *context)
140 140
 {
141 141
     JackData *self = context->priv_data;
142 142
     jack_status_t status;
... ...
@@ -153,7 +155,6 @@ static int start_jack(AVFormatContext *context, AVFormatParameters *params)
153 153
     sem_init(&self->packet_count, 0, 0);
154 154
 
155 155
     self->sample_rate = jack_get_sample_rate(self->client);
156
-    self->nports      = params->channels;
157 156
     self->ports       = av_malloc(self->nports * sizeof(*self->ports));
158 157
     self->buffer_size = jack_get_buffer_size(self->client);
159 158
 
... ...
@@ -225,10 +226,7 @@ static int audio_read_header(AVFormatContext *context, AVFormatParameters *param
225 225
     AVStream *stream;
226 226
     int test;
227 227
 
228
-    if (params->sample_rate <= 0 || params->channels <= 0)
229
-        return -1;
230
-
231
-    if ((test = start_jack(context, params)))
228
+    if ((test = start_jack(context)))
232 229
         return test;
233 230
 
234 231
     stream = av_new_stream(context, 0);
... ...
@@ -314,6 +312,19 @@ static int audio_read_close(AVFormatContext *context)
314 314
     return 0;
315 315
 }
316 316
 
317
+#define OFFSET(x) offsetof(JackData, x)
318
+static const AVOption options[] = {
319
+    { "channels", "Number of audio channels.", OFFSET(nports), FF_OPT_TYPE_INT, { 2 }, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
320
+    { NULL },
321
+};
322
+
323
+static const AVClass jack_indev_class = {
324
+    .class_name     = "JACK indev",
325
+    .item_name      = av_default_item_name,
326
+    .option         = options,
327
+    .version        = LIBAVUTIL_VERSION_INT,
328
+};
329
+
317 330
 AVInputFormat ff_jack_demuxer = {
318 331
     "jack",
319 332
     NULL_IF_CONFIG_SMALL("JACK Audio Connection Kit"),
... ...
@@ -323,4 +334,5 @@ AVInputFormat ff_jack_demuxer = {
323 323
     audio_read_packet,
324 324
     audio_read_close,
325 325
     .flags = AVFMT_NOFILE,
326
+    .priv_class = &jack_indev_class,
326 327
 };