708ec8fb |
/*
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h" |
32caa7b1 |
#include "avio_internal.h" |
33c859c1 |
#include "internal.h" |
f046c3b5 |
#include "libavutil/internal.h" |
6ed04040 |
#include "libavutil/opt.h" |
708ec8fb |
/** |
ba87f080 |
* @file |
708ec8fb |
* Options definition for AVFormatContext.
*/
|
f046c3b5 |
FF_DISABLE_DEPRECATION_WARNINGS |
56266971 |
#include "options_table.h" |
f046c3b5 |
FF_ENABLE_DEPRECATION_WARNINGS |
56266971 |
|
708ec8fb |
static const char* format_to_name(void* ptr)
{
AVFormatContext* fc = (AVFormatContext*) ptr;
if(fc->iformat) return fc->iformat->name;
else if(fc->oformat) return fc->oformat->name;
else return "NULL";
}
|
641c7afe |
static void *format_child_next(void *obj, void *prev)
{
AVFormatContext *s = obj;
if (!prev && s->priv_data &&
((s->iformat && s->iformat->priv_class) ||
s->oformat && s->oformat->priv_class))
return s->priv_data; |
32caa7b1 |
if (s->pb && s->pb->av_class && prev != s->pb)
return s->pb; |
641c7afe |
return NULL;
}
static const AVClass *format_child_class_next(const AVClass *prev) |
05e84c95 |
{
AVInputFormat *ifmt = NULL;
AVOutputFormat *ofmt = NULL; |
641c7afe |
|
5f268ca5 |
if (!prev) |
c86d8aed |
return &ff_avio_class; |
caf27e37 |
while ((ifmt = av_iformat_next(ifmt))) |
641c7afe |
if (ifmt->priv_class == prev)
break; |
caf27e37 |
if (!ifmt)
while ((ofmt = av_oformat_next(ofmt)))
if (ofmt->priv_class == prev)
break;
if (!ofmt) |
641c7afe |
while (ifmt = av_iformat_next(ifmt))
if (ifmt->priv_class)
return ifmt->priv_class;
|
caf27e37 |
while (ofmt = av_oformat_next(ofmt))
if (ofmt->priv_class)
return ofmt->priv_class; |
641c7afe |
|
05e84c95 |
return NULL;
}
|
938e4470 |
static AVClassCategory get_category(void *ptr) |
08613d50 |
{ |
938e4470 |
AVFormatContext* s = ptr; |
08613d50 |
if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER;
else return AV_CLASS_CATEGORY_MUXER;
}
|
4a7a1b7d |
static const AVClass av_format_context_class = {
.class_name = "AVFormatContext",
.item_name = format_to_name, |
b5a13865 |
.option = avformat_options, |
4a7a1b7d |
.version = LIBAVUTIL_VERSION_INT, |
641c7afe |
.child_next = format_child_next,
.child_class_next = format_child_class_next, |
a5c7525b |
.category = AV_CLASS_CATEGORY_MUXER, |
08613d50 |
.get_category = get_category, |
4a7a1b7d |
}; |
708ec8fb |
|
9f61abc8 |
static int io_open_default(AVFormatContext *s, AVIOContext **pb,
const char *url, int flags, AVDictionary **options)
{ |
53e0d5d7 |
int loglevel;
if (!strcmp(url, s->filename) ||
s->iformat && !strcmp(s->iformat->name, "image2") ||
s->oformat && !strcmp(s->oformat->name, "image2")
) {
loglevel = AV_LOG_DEBUG;
} else
loglevel = AV_LOG_INFO;
av_log(s, loglevel, "Opening \'%s\' for %s\n", url, flags & AVIO_FLAG_WRITE ? "writing" : "reading");
|
bc9a5965 |
#if FF_API_OLD_OPEN_CALLBACKS
FF_DISABLE_DEPRECATION_WARNINGS
if (s->open_cb)
return s->open_cb(s, pb, url, flags, &s->interrupt_callback, options);
FF_ENABLE_DEPRECATION_WARNINGS
#endif
|
93629735 |
return ffio_open_whitelist(pb, url, flags, &s->interrupt_callback, options, s->protocol_whitelist, s->protocol_blacklist); |
9f61abc8 |
}
static void io_close_default(AVFormatContext *s, AVIOContext *pb)
{
avio_close(pb);
}
|
708ec8fb |
static void avformat_get_context_defaults(AVFormatContext *s)
{
memset(s, 0, sizeof(AVFormatContext));
s->av_class = &av_format_context_class;
|
9f61abc8 |
s->io_open = io_open_default;
s->io_close = io_close_default;
|
708ec8fb |
av_opt_set_defaults(s);
}
|
88a28965 |
AVFormatContext *avformat_alloc_context(void) |
708ec8fb |
{
AVFormatContext *ic;
ic = av_malloc(sizeof(AVFormatContext));
if (!ic) return ic;
avformat_get_context_defaults(ic); |
33c859c1 |
ic->internal = av_mallocz(sizeof(*ic->internal));
if (!ic->internal) {
avformat_free_context(ic);
return NULL;
} |
9deaec78 |
ic->internal->offset = AV_NOPTS_VALUE; |
5af62127 |
ic->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; |
cb114ed4 |
ic->internal->shortest_end = AV_NOPTS_VALUE; |
33c859c1 |
|
708ec8fb |
return ic;
} |
fb4ca26b |
|
fc5999d0 |
enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx) |
2243f0d0 |
{
return ctx->duration_estimation_method;
}
|
fb4ca26b |
const AVClass *avformat_get_class(void)
{
return &av_format_context_class;
} |