LCOV - code coverage report
Current view: top level - libavformat - options.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 68 74 91.9 %
Date: 2017-12-15 11:05:35 Functions: 9 10 90.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
       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             : #include "avformat.h"
      21             : #include "avio_internal.h"
      22             : #include "internal.h"
      23             : 
      24             : #include "libavutil/internal.h"
      25             : #include "libavutil/opt.h"
      26             : 
      27             : /**
      28             :  * @file
      29             :  * Options definition for AVFormatContext.
      30             :  */
      31             : 
      32             : FF_DISABLE_DEPRECATION_WARNINGS
      33             : #include "options_table.h"
      34             : FF_ENABLE_DEPRECATION_WARNINGS
      35             : 
      36        2015 : static const char* format_to_name(void* ptr)
      37             : {
      38        2015 :     AVFormatContext* fc = (AVFormatContext*) ptr;
      39        2015 :     if(fc->iformat) return fc->iformat->name;
      40         897 :     else if(fc->oformat) return fc->oformat->name;
      41           0 :     else return "NULL";
      42             : }
      43             : 
      44     1290377 : static void *format_child_next(void *obj, void *prev)
      45             : {
      46     1290377 :     AVFormatContext *s = obj;
      47     1766630 :     if (!prev && s->priv_data &&
      48     1081531 :         ((s->iformat && s->iformat->priv_class) ||
      49      129029 :           s->oformat && s->oformat->priv_class))
      50      347228 :         return s->priv_data;
      51      943149 :     if (s->pb && s->pb->av_class && prev != s->pb)
      52      432412 :         return s->pb;
      53      510737 :     return NULL;
      54             : }
      55             : 
      56     9845286 : static const AVClass *format_child_class_next(const AVClass *prev)
      57             : {
      58     9845286 :     AVInputFormat  *ifmt = NULL;
      59     9845286 :     AVOutputFormat *ofmt = NULL;
      60             : 
      61     9845286 :     if (!prev)
      62       55963 :         return &ff_avio_class;
      63             : 
      64  2021941845 :     while ((ifmt = av_iformat_next(ifmt)))
      65  2008517708 :         if (ifmt->priv_class == prev)
      66     6154509 :             break;
      67             : 
      68     9789323 :     if (!ifmt)
      69   282141927 :         while ((ofmt = av_oformat_next(ofmt)))
      70   278451152 :             if (ofmt->priv_class == prev)
      71     3578853 :                 break;
      72     9789323 :     if (!ofmt)
      73    22380429 :         while (ifmt = av_iformat_next(ifmt))
      74    16114017 :             if (ifmt->priv_class)
      75     6154528 :                 return ifmt->priv_class;
      76             : 
      77    12581882 :     while (ofmt = av_oformat_next(ofmt))
      78     8891195 :         if (ofmt->priv_class)
      79     3578903 :             return ofmt->priv_class;
      80             : 
      81       55892 :     return NULL;
      82             : }
      83             : 
      84        2015 : static AVClassCategory get_category(void *ptr)
      85             : {
      86        2015 :     AVFormatContext* s = ptr;
      87        2015 :     if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER;
      88         897 :     else           return AV_CLASS_CATEGORY_MUXER;
      89             : }
      90             : 
      91             : static const AVClass av_format_context_class = {
      92             :     .class_name     = "AVFormatContext",
      93             :     .item_name      = format_to_name,
      94             :     .option         = avformat_options,
      95             :     .version        = LIBAVUTIL_VERSION_INT,
      96             :     .child_next     = format_child_next,
      97             :     .child_class_next = format_child_class_next,
      98             :     .category       = AV_CLASS_CATEGORY_MUXER,
      99             :     .get_category   = get_category,
     100             : };
     101             : 
     102       71062 : static int io_open_default(AVFormatContext *s, AVIOContext **pb,
     103             :                            const char *url, int flags, AVDictionary **options)
     104             : {
     105             :     int loglevel;
     106             : 
     107      138452 :     if (!strcmp(url, s->filename) ||
     108      134795 :         s->iformat && !strcmp(s->iformat->name, "image2") ||
     109         935 :         s->oformat && !strcmp(s->oformat->name, "image2")
     110             :     ) {
     111       71016 :         loglevel = AV_LOG_DEBUG;
     112             :     } else
     113          46 :         loglevel = AV_LOG_INFO;
     114             : 
     115       71062 :     av_log(s, loglevel, "Opening \'%s\' for %s\n", url, flags & AVIO_FLAG_WRITE ? "writing" : "reading");
     116             : 
     117             : #if FF_API_OLD_OPEN_CALLBACKS
     118             : FF_DISABLE_DEPRECATION_WARNINGS
     119       71062 :     if (s->open_cb)
     120           0 :         return s->open_cb(s, pb, url, flags, &s->interrupt_callback, options);
     121             : FF_ENABLE_DEPRECATION_WARNINGS
     122             : #endif
     123             : 
     124       71062 :     return ffio_open_whitelist(pb, url, flags, &s->interrupt_callback, options, s->protocol_whitelist, s->protocol_blacklist);
     125             : }
     126             : 
     127       67396 : static void io_close_default(AVFormatContext *s, AVIOContext *pb)
     128             : {
     129       67396 :     avio_close(pb);
     130       67396 : }
     131             : 
     132       11188 : static void avformat_get_context_defaults(AVFormatContext *s)
     133             : {
     134       11188 :     memset(s, 0, sizeof(AVFormatContext));
     135             : 
     136       11188 :     s->av_class = &av_format_context_class;
     137             : 
     138       11188 :     s->io_open  = io_open_default;
     139       11188 :     s->io_close = io_close_default;
     140             : 
     141       11188 :     av_opt_set_defaults(s);
     142       11188 : }
     143             : 
     144       11188 : AVFormatContext *avformat_alloc_context(void)
     145             : {
     146             :     AVFormatContext *ic;
     147       11188 :     ic = av_malloc(sizeof(AVFormatContext));
     148       11188 :     if (!ic) return ic;
     149       11188 :     avformat_get_context_defaults(ic);
     150             : 
     151       11188 :     ic->internal = av_mallocz(sizeof(*ic->internal));
     152       11188 :     if (!ic->internal) {
     153           0 :         avformat_free_context(ic);
     154           0 :         return NULL;
     155             :     }
     156       11188 :     ic->internal->offset = AV_NOPTS_VALUE;
     157       11188 :     ic->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
     158       11188 :     ic->internal->shortest_end = AV_NOPTS_VALUE;
     159             : 
     160       11188 :     return ic;
     161             : }
     162             : 
     163           0 : enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx)
     164             : {
     165           0 :     return ctx->duration_estimation_method;
     166             : }
     167             : 
     168       55963 : const AVClass *avformat_get_class(void)
     169             : {
     170       55963 :     return &av_format_context_class;
     171             : }

Generated by: LCOV version 1.13