FFmpeg  2.6.9
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
libquvi.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Clément Bœsch
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <quvi/quvi.h>
22 
23 #include "libavformat/avformat.h"
24 #include "libavformat/internal.h"
25 #include "libavutil/avassert.h"
26 #include "libavutil/opt.h"
27 
28 typedef struct {
29  const AVClass *class;
30  char *format;
33 
34 #define OFFSET(x) offsetof(LibQuviContext, x)
35 #define FLAGS AV_OPT_FLAG_DECODING_PARAM
36 static const AVOption libquvi_options[] = {
37  { "format", "request specific format", OFFSET(format), AV_OPT_TYPE_STRING, {.str="best"}, .flags = FLAGS },
38  { NULL }
39 };
40 
42  .class_name = "libquvi",
43  .item_name = av_default_item_name,
44  .option = libquvi_options,
45  .version = LIBAVUTIL_VERSION_INT,
46 };
47 
49 {
50  LibQuviContext *qc = s->priv_data;
51  if (qc->fmtctx)
53  return 0;
54 }
55 
57 {
58  int i, ret;
59  quvi_t q;
60  quvi_media_t m;
61  QUVIcode rc;
62  LibQuviContext *qc = s->priv_data;
63  char *media_url, *pagetitle;
64 
65  rc = quvi_init(&q);
66  if (rc != QUVI_OK)
67  goto quvi_fail;
68 
69  quvi_setopt(q, QUVIOPT_FORMAT, qc->format);
70 
71  rc = quvi_parse(q, s->filename, &m);
72  if (rc != QUVI_OK)
73  goto quvi_fail;
74 
75  rc = quvi_getprop(m, QUVIPROP_MEDIAURL, &media_url);
76  if (rc != QUVI_OK)
77  goto quvi_fail;
78 
79  if ((ret = ff_copy_whitelists(qc->fmtctx, s)) < 0)
80  goto end;
81 
82  if (!qc->fmtctx->format_whitelist) {
83  qc->fmtctx->format_whitelist = av_strdup("avi,asf,flv,mov,mpeg,mpegts,aac,h264,hevc,mp3,ogg,matroska,mxf,mp2");
84  if (!qc->fmtctx->format_whitelist) {
86  qc->fmtctx = NULL;
87  goto err_quvi_cleanup;
88  }
89  }
90  if (strncmp(media_url, "http:", 5) && strncmp(media_url, "https:", 6)) {
92  qc->fmtctx = NULL;
93  goto err_quvi_cleanup;
94  }
95 
96  ret = avformat_open_input(&qc->fmtctx, media_url, NULL, NULL);
97  if (ret < 0)
98  goto end;
99 
100  rc = quvi_getprop(m, QUVIPROP_PAGETITLE, &pagetitle);
101  if (rc == QUVI_OK)
102  av_dict_set(&s->metadata, "title", pagetitle, 0);
103 
104  for (i = 0; i < qc->fmtctx->nb_streams; i++) {
106  AVStream *ist = qc->fmtctx->streams[i];
107  if (!st) {
108  ret = AVERROR(ENOMEM);
109  goto end;
110  }
113  }
114 
115  return 0;
116 
117 quvi_fail:
118  av_log(s, AV_LOG_ERROR, "%s\n", quvi_strerror(q, rc));
119  ret = AVERROR_EXTERNAL;
120 
121 end:
122  quvi_parse_close(&m);
123  quvi_close(&q);
124  return ret;
125 }
126 
128 {
129  LibQuviContext *qc = s->priv_data;
130  return av_read_frame(qc->fmtctx, pkt);
131 }
132 
133 static int libquvi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
134 {
135  LibQuviContext *qc = s->priv_data;
136  return av_seek_frame(qc->fmtctx, stream_index, timestamp, flags);
137 }
138 
140 {
141  int score;
142  quvi_t q;
143  QUVIcode rc;
144 
145  rc = quvi_init(&q);
146  if (rc != QUVI_OK)
147  return AVERROR(ENOMEM);
148  score = quvi_supported(q, (char *)p->filename) == QUVI_OK ? AVPROBE_SCORE_EXTENSION : 0;
149  quvi_close(&q);
150  return score;
151 }
152 
154  .name = "libquvi",
155  .long_name = NULL_IF_CONFIG_SMALL("libquvi demuxer"),
156  .priv_data_size = sizeof(LibQuviContext),
162  .priv_class = &libquvi_context_class,
163  .flags = AVFMT_NOFILE,
164 };