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/opt.h"
26 
27 typedef struct {
28  const AVClass *class;
29  char *format;
32 
33 #define OFFSET(x) offsetof(LibQuviContext, x)
34 #define FLAGS AV_OPT_FLAG_DECODING_PARAM
35 static const AVOption libquvi_options[] = {
36  { "format", "request specific format", OFFSET(format), AV_OPT_TYPE_STRING, {.str="best"}, .flags = FLAGS },
37  { NULL }
38 };
39 
41  .class_name = "libquvi",
42  .item_name = av_default_item_name,
43  .option = libquvi_options,
44  .version = LIBAVUTIL_VERSION_INT,
45 };
46 
48 {
49  LibQuviContext *qc = s->priv_data;
50  if (qc->fmtctx)
52  return 0;
53 }
54 
56 {
57  int i, ret;
58  quvi_t q;
59  quvi_media_t m;
60  QUVIcode rc;
61  LibQuviContext *qc = s->priv_data;
62  char *media_url, *pagetitle;
63 
64  rc = quvi_init(&q);
65  if (rc != QUVI_OK)
66  goto quvi_fail;
67 
68  quvi_setopt(q, QUVIOPT_FORMAT, qc->format);
69 
70  rc = quvi_parse(q, s->filename, &m);
71  if (rc != QUVI_OK)
72  goto quvi_fail;
73 
74  rc = quvi_getprop(m, QUVIPROP_MEDIAURL, &media_url);
75  if (rc != QUVI_OK)
76  goto quvi_fail;
77 
78  ret = avformat_open_input(&qc->fmtctx, media_url, NULL, NULL);
79  if (ret < 0)
80  goto end;
81 
82  rc = quvi_getprop(m, QUVIPROP_PAGETITLE, &pagetitle);
83  if (rc == QUVI_OK)
84  av_dict_set(&s->metadata, "title", pagetitle, 0);
85 
86  for (i = 0; i < qc->fmtctx->nb_streams; i++) {
88  AVStream *ist = qc->fmtctx->streams[i];
89  if (!st) {
90  ret = AVERROR(ENOMEM);
91  goto end;
92  }
95  }
96 
97  return 0;
98 
99 quvi_fail:
100  av_log(s, AV_LOG_ERROR, "%s\n", quvi_strerror(q, rc));
101  ret = AVERROR_EXTERNAL;
102 
103 end:
104  quvi_parse_close(&m);
105  quvi_close(&q);
106  return ret;
107 }
108 
110 {
111  LibQuviContext *qc = s->priv_data;
112  return av_read_frame(qc->fmtctx, pkt);
113 }
114 
115 static int libquvi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
116 {
117  LibQuviContext *qc = s->priv_data;
118  return av_seek_frame(qc->fmtctx, stream_index, timestamp, flags);
119 }
120 
122 {
123  int score;
124  quvi_t q;
125  QUVIcode rc;
126 
127  rc = quvi_init(&q);
128  if (rc != QUVI_OK)
129  return AVERROR(ENOMEM);
130  score = quvi_supported(q, (char *)p->filename) == QUVI_OK ? AVPROBE_SCORE_MAX/2 : 0;
131  quvi_close(&q);
132  return score;
133 }
134 
136  .name = "libquvi",
137  .long_name = NULL_IF_CONFIG_SMALL("libquvi demuxer"),
138  .priv_data_size = sizeof(LibQuviContext),
144  .priv_class = &libquvi_context_class,
145  .flags = AVFMT_NOFILE,
146 };
const char * s
Definition: avisynth_c.h:668
AVFormatContext * fmtctx
Definition: libquvi.c:30
AVOption.
Definition: opt.h:251
av_default_item_name
const char * filename
Definition: avformat.h:335
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
int num
numerator
Definition: rational.h:44
char * format
Definition: libquvi.c:29
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
Copy the settings of the source AVCodecContext into the destination AVCodecContext.
Format I/O context.
Definition: avformat.h:944
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:55
AVOptions.
window constants for m
static AVPacket pkt
Definition: demuxing.c:56
end end
static int libquvi_read_header(AVFormatContext *s)
Definition: libquvi.c:55
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
Definition: avformat.h:992
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
static int libquvi_probe(AVProbeData *p)
Definition: libquvi.c:121
static const AVOption libquvi_options[]
Definition: libquvi.c:35
AVDictionary * metadata
Definition: avformat.h:1092
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:991
static const AVClass libquvi_context_class
Definition: libquvi.c:40
char filename[1024]
input or output filename
Definition: avformat.h:994
static int read_probe(AVProbeData *pd)
ret
Definition: avfilter.c:821
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate.The lists are not just lists
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
#define OFFSET(x)
Definition: libquvi.c:33
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:517
Stream structure.
Definition: avformat.h:643
NULL
Definition: eval.c:55
static int libquvi_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: libquvi.c:109
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:62
Describe the class of an AVClass context structure.
Definition: log.h:50
synthesis window for stochastic i
static int libquvi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: libquvi.c:115
This structure contains the data a format has to probe a file.
Definition: avformat.h:334
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
static int flags
Definition: cpu.c:23
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Seek to the keyframe at timestamp.
#define AVPROBE_SCORE_MAX
maximum score, half of that is used for file-extension-based detection
Definition: avformat.h:340
Main libavformat public API header.
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:345
AVInputFormat ff_libquvi_demuxer
Definition: libquvi.c:135
int pts_wrap_bits
number of bits in pts (used for wrapping control)
Definition: avformat.h:773
int den
denominator
Definition: rational.h:45
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
void * priv_data
Format private data.
Definition: avformat.h:964
static int libquvi_close(AVFormatContext *s)
Definition: libquvi.c:47
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:461
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:679
#define FLAGS
Definition: libquvi.c:34
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:57
This structure stores compressed data.