Browse code

lavf: add libquvi demuxer.

Clément Bœsch authored on 2013/04/04 15:22:32
Showing 7 changed files
... ...
@@ -17,6 +17,7 @@ version <next>:
17 17
 - OpenCL support
18 18
 - audio phaser filter
19 19
 - separatefields filter
20
+- libquvi demuxer
20 21
 
21 22
 
22 23
 version 1.2:
... ...
@@ -215,6 +215,7 @@ External library support:
215 215
   --enable-libopenjpeg     enable JPEG 2000 de/encoding via OpenJPEG [no]
216 216
   --enable-libopus         enable Opus decoding via libopus [no]
217 217
   --enable-libpulse        enable Pulseaudio input via libpulse [no]
218
+  --enable-libquvi         enable quvi input via libquvi [no]
218 219
   --enable-librtmp         enable RTMP[E] support via librtmp [no]
219 220
   --enable-libschroedinger enable Dirac de/encoding via libschroedinger [no]
220 221
   --enable-libsoxr         enable Include libsoxr resampling [no]
... ...
@@ -1168,6 +1169,7 @@ EXTERNAL_LIBRARY_LIST="
1168 1168
     libopenjpeg
1169 1169
     libopus
1170 1170
     libpulse
1171
+    libquvi
1171 1172
     librtmp
1172 1173
     libschroedinger
1173 1174
     libsoxr
... ...
@@ -1958,6 +1960,7 @@ libopenjpeg_encoder_deps="libopenjpeg"
1958 1958
 libopus_decoder_deps="libopus"
1959 1959
 libopus_encoder_deps="libopus"
1960 1960
 libopus_encoder_select="audio_frame_queue"
1961
+libquvi_demuxer_deps="libquvi"
1961 1962
 libschroedinger_decoder_deps="libschroedinger"
1962 1963
 libschroedinger_encoder_deps="libschroedinger"
1963 1964
 libspeex_decoder_deps="libspeex"
... ...
@@ -3978,6 +3981,7 @@ enabled libopenjpeg && { check_lib openjpeg-1.5/openjpeg.h opj_version -lopenjpe
3978 3978
                          die "ERROR: libopenjpeg not found"; }
3979 3979
 enabled libopus    && require_pkg_config opus opus_multistream.h opus_multistream_decoder_create
3980 3980
 enabled libpulse && require_pkg_config libpulse-simple pulse/simple.h pa_simple_new
3981
+enabled libquvi    && require_pkg_config libquvi quvi/quvi.h quvi_init
3981 3982
 enabled librtmp    && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
3982 3983
 enabled libschroedinger && require_pkg_config schroedinger-1.0 schroedinger/schro.h schro_init
3983 3984
 enabled libsoxr    && require  libsoxr soxr.h soxr_create -lsoxr
... ...
@@ -103,6 +103,18 @@ probed and 0 otherwise.
103 103
 
104 104
 @end table
105 105
 
106
+@section libquvi
107
+
108
+Play media from Internet services using the quvi project.
109
+
110
+The demuxer accepts a @option{format} option to request a specific quality. It
111
+is by default set to @var{best}.
112
+
113
+See @url{http://quvi.sourceforge.net/} for more information.
114
+
115
+FFmpeg needs to be built with @code{--enable-libquvi} for this demuxer to be
116
+enabled.
117
+
106 118
 @section image2
107 119
 
108 120
 Image file demuxer.
... ...
@@ -405,6 +405,7 @@ OBJS-$(CONFIG_YUV4MPEGPIPE_DEMUXER)      += yuv4mpeg.o
405 405
 OBJS-$(CONFIG_LIBMODPLUG_DEMUXER)        += libmodplug.o
406 406
 OBJS-$(CONFIG_LIBNUT_DEMUXER)            += libnut.o
407 407
 OBJS-$(CONFIG_LIBNUT_MUXER)              += libnut.o
408
+OBJS-$(CONFIG_LIBQUVI_DEMUXER)           += libquvi.o
408 409
 OBJS-$(CONFIG_LIBRTMP)                   += librtmp.o
409 410
 
410 411
 # protocols I/O
... ...
@@ -333,6 +333,7 @@ void av_register_all(void)
333 333
     /* external libraries */
334 334
     REGISTER_DEMUXER (LIBMODPLUG,       libmodplug);
335 335
     REGISTER_MUXDEMUX(LIBNUT,           libnut);
336
+    REGISTER_DEMUXER (LIBQUVI,          libquvi);
336 337
     REGISTER_PROTOCOL(LIBRTMP,          librtmp);
337 338
     REGISTER_PROTOCOL(LIBRTMPE,         librtmpe);
338 339
     REGISTER_PROTOCOL(LIBRTMPS,         librtmps);
339 340
new file mode 100644
... ...
@@ -0,0 +1,146 @@
0
+/*
1
+ * Copyright (c) 2013 Clément Bœsch
2
+ *
3
+ * This file is part of FFmpeg.
4
+ *
5
+ * FFmpeg is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * FFmpeg is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with FFmpeg; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+#include <quvi/quvi.h>
21
+
22
+#include "libavformat/avformat.h"
23
+#include "libavformat/internal.h"
24
+#include "libavutil/opt.h"
25
+
26
+typedef struct {
27
+    const AVClass *class;
28
+    char *format;
29
+    AVFormatContext *fmtctx;
30
+} LibQuviContext;
31
+
32
+#define OFFSET(x) offsetof(LibQuviContext, x)
33
+#define FLAGS AV_OPT_FLAG_DECODING_PARAM
34
+static const AVOption libquvi_options[] = {
35
+    { "format", "request specific format", OFFSET(format), AV_OPT_TYPE_STRING, {.str="best"}, .flags = FLAGS },
36
+    { NULL }
37
+};
38
+
39
+static const AVClass libquvi_context_class = {
40
+    .class_name     = "libquvi",
41
+    .item_name      = av_default_item_name,
42
+    .option         = libquvi_options,
43
+    .version        = LIBAVUTIL_VERSION_INT,
44
+};
45
+
46
+static int libquvi_close(AVFormatContext *s)
47
+{
48
+    LibQuviContext *qc = s->priv_data;
49
+    if (qc->fmtctx)
50
+        avformat_close_input(&qc->fmtctx);
51
+    return 0;
52
+}
53
+
54
+static int libquvi_read_header(AVFormatContext *s)
55
+{
56
+    int i, ret;
57
+    quvi_t q;
58
+    quvi_media_t m;
59
+    QUVIcode rc;
60
+    LibQuviContext *qc = s->priv_data;
61
+    char *media_url, *pagetitle;
62
+
63
+    rc = quvi_init(&q);
64
+    if (rc != QUVI_OK)
65
+        goto quvi_fail;
66
+
67
+    quvi_setopt(q, QUVIOPT_FORMAT, qc->format);
68
+
69
+    rc = quvi_parse(q, s->filename, &m);
70
+    if (rc != QUVI_OK)
71
+        goto quvi_fail;
72
+
73
+    rc = quvi_getprop(m, QUVIPROP_MEDIAURL, &media_url);
74
+    if (rc != QUVI_OK)
75
+        goto quvi_fail;
76
+
77
+    ret = avformat_open_input(&qc->fmtctx, media_url, NULL, NULL);
78
+    if (ret < 0)
79
+        goto end;
80
+
81
+    rc = quvi_getprop(m, QUVIPROP_PAGETITLE, &pagetitle);
82
+    if (rc == QUVI_OK)
83
+        av_dict_set(&s->metadata, "title", pagetitle, 0);
84
+
85
+    for (i = 0; i < qc->fmtctx->nb_streams; i++) {
86
+        AVStream *st = avformat_new_stream(s, NULL);
87
+        AVStream *ist = qc->fmtctx->streams[i];
88
+        if (!st) {
89
+            ret = AVERROR(ENOMEM);
90
+            goto end;
91
+        }
92
+        avpriv_set_pts_info(st, ist->pts_wrap_bits, ist->time_base.num, ist->time_base.den);
93
+        avcodec_copy_context(st->codec, qc->fmtctx->streams[i]->codec);
94
+    }
95
+
96
+    return 0;
97
+
98
+quvi_fail:
99
+    av_log(s, AV_LOG_ERROR, "%s\n", quvi_strerror(&q, rc));
100
+    ret = rc;
101
+
102
+end:
103
+    quvi_parse_close(&m);
104
+    quvi_close(&q);
105
+    return ret;
106
+}
107
+
108
+static int libquvi_read_packet(AVFormatContext *s, AVPacket *pkt)
109
+{
110
+    LibQuviContext *qc = s->priv_data;
111
+    return av_read_frame(qc->fmtctx, pkt);
112
+}
113
+
114
+static int libquvi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
115
+{
116
+    LibQuviContext *qc = s->priv_data;
117
+    return av_seek_frame(qc->fmtctx, stream_index, timestamp, flags);
118
+}
119
+
120
+static int libquvi_probe(AVProbeData *p)
121
+{
122
+    int score;
123
+    quvi_t q;
124
+    QUVIcode rc;
125
+
126
+    rc = quvi_init(&q);
127
+    if (rc != QUVI_OK)
128
+        return AVERROR(ENOMEM);
129
+    score = quvi_supported(q, (char *)p->filename) == QUVI_OK ? AVPROBE_SCORE_MAX/2 : 0;
130
+    quvi_close(&q);
131
+    return score;
132
+}
133
+
134
+AVInputFormat ff_libquvi_demuxer = {
135
+    .name           = "libquvi",
136
+    .long_name      = NULL_IF_CONFIG_SMALL("libquvi demuxer"),
137
+    .priv_data_size = sizeof(LibQuviContext),
138
+    .read_probe     = libquvi_probe,
139
+    .read_header    = libquvi_read_header,
140
+    .read_packet    = libquvi_read_packet,
141
+    .read_close     = libquvi_close,
142
+    .read_seek      = libquvi_read_seek,
143
+    .priv_class     = &libquvi_context_class,
144
+    .flags          = AVFMT_NOFILE,
145
+};
... ...
@@ -30,7 +30,7 @@
30 30
 #include "libavutil/avutil.h"
31 31
 
32 32
 #define LIBAVFORMAT_VERSION_MAJOR 55
33
-#define LIBAVFORMAT_VERSION_MINOR  1
33
+#define LIBAVFORMAT_VERSION_MINOR  2
34 34
 #define LIBAVFORMAT_VERSION_MICRO 100
35 35
 
36 36
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \