2 * Copyright (c) 2013 Clément Bœsch
4 * This file is part of FFmpeg.
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.
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.
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
21 #include <quvi/quvi.h>
23 #include "libavformat/avformat.h"
24 #include "libavformat/internal.h"
25 #include "libavutil/opt.h"
30 AVFormatContext
*fmtctx
;
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
},
40 static const AVClass libquvi_context_class
= {
41 .class_name
= "libquvi",
42 .item_name
= av_default_item_name
,
43 .option
= libquvi_options
,
44 .version
= LIBAVUTIL_VERSION_INT
,
47 static int libquvi_close(AVFormatContext
*s
)
49 LibQuviContext
*qc
= s
->priv_data
;
51 avformat_close_input(&qc
->fmtctx
);
55 static int libquvi_read_header(AVFormatContext
*s
)
61 LibQuviContext
*qc
= s
->priv_data
;
62 char *media_url
, *pagetitle
;
68 quvi_setopt(q
, QUVIOPT_FORMAT
, qc
->format
);
70 rc
= quvi_parse(q
, s
->filename
, &m
);
74 rc
= quvi_getprop(m
, QUVIPROP_MEDIAURL
, &media_url
);
78 ret
= avformat_open_input(&qc
->fmtctx
, media_url
, NULL
, NULL
);
82 rc
= quvi_getprop(m
, QUVIPROP_PAGETITLE
, &pagetitle
);
84 av_dict_set(&s
->metadata
, "title", pagetitle
, 0);
86 for (i
= 0; i
< qc
->fmtctx
->nb_streams
; i
++) {
87 AVStream
*st
= avformat_new_stream(s
, NULL
);
88 AVStream
*ist
= qc
->fmtctx
->streams
[i
];
90 ret
= AVERROR(ENOMEM
);
93 avpriv_set_pts_info(st
, ist
->pts_wrap_bits
, ist
->time_base
.num
, ist
->time_base
.den
);
94 avcodec_copy_context(st
->codec
, qc
->fmtctx
->streams
[i
]->codec
);
100 av_log(s
, AV_LOG_ERROR
, "%s\n", quvi_strerror(q
, rc
));
101 ret
= AVERROR_EXTERNAL
;
104 quvi_parse_close(&m
);
109 static int libquvi_read_packet(AVFormatContext
*s
, AVPacket
*pkt
)
111 LibQuviContext
*qc
= s
->priv_data
;
112 return av_read_frame(qc
->fmtctx
, pkt
);
115 static int libquvi_read_seek(AVFormatContext
*s
, int stream_index
, int64_t timestamp
, int flags
)
117 LibQuviContext
*qc
= s
->priv_data
;
118 return av_seek_frame(qc
->fmtctx
, stream_index
, timestamp
, flags
);
121 static int libquvi_probe(AVProbeData
*p
)
129 return AVERROR(ENOMEM
);
130 score
= quvi_supported(q
, (char *)p
->filename
) == QUVI_OK
? AVPROBE_SCORE_EXTENSION
: 0;
135 AVInputFormat ff_libquvi_demuxer
= {
137 .long_name
= NULL_IF_CONFIG_SMALL("libquvi demuxer"),
138 .priv_data_size
= sizeof(LibQuviContext
),
139 .read_probe
= libquvi_probe
,
140 .read_header
= libquvi_read_header
,
141 .read_packet
= libquvi_read_packet
,
142 .read_close
= libquvi_close
,
143 .read_seek
= libquvi_read_seek
,
144 .priv_class
= &libquvi_context_class
,
145 .flags
= AVFMT_NOFILE
,