"Fossies" - the Fresh Open Source Software Archive

Member "minidlna-1.3.0/libav.h" (24 Nov 2020, 6667 Bytes) of package /linux/privat/minidlna-1.3.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "libav.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.2.1_vs_1.3.0.

    1 /* MiniDLNA media server
    2  * Copyright (C) 2013  NETGEAR
    3  *
    4  * This file is part of MiniDLNA.
    5  *
    6  * MiniDLNA is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License version 2 as
    8  * published by the Free Software Foundation.
    9  *
   10  * MiniDLNA is distributed in the hope that it will be useful,
   11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  * GNU General Public License for more details.
   14  *
   15  * You should have received a copy of the GNU General Public License
   16  * along with MiniDLNA. If not, see <http://www.gnu.org/licenses/>.
   17  */
   18 #if HAVE_FFMPEG_LIBAVUTIL_AVUTIL_H
   19 #include <ffmpeg/libavutil/avutil.h>
   20 #elif HAVE_LIBAV_LIBAVUTIL_AVUTIL_H
   21 #include <libav/libavutil/avutil.h>
   22 #elif HAVE_LIBAVUTIL_AVUTIL_H
   23 #include <libavutil/avutil.h>
   24 #elif HAVE_FFMPEG_AVUTIL_H
   25 #include <ffmpeg/avutil.h>
   26 #elif HAVE_LIBAV_AVUTIL_H
   27 #include <libav/avutil.h>
   28 #elif HAVE_AVUTIL_H
   29 #include <avutil.h>
   30 #endif
   31 
   32 #if HAVE_FFMPEG_LIBAVCODEC_AVCODEC_H
   33 #include <ffmpeg/libavcodec/avcodec.h>
   34 #elif HAVE_LIBAV_LIBAVCODEC_AVCODEC_H
   35 #include <libav/libavcodec/avcodec.h>
   36 #elif HAVE_LIBAVCODEC_AVCODEC_H
   37 #include <libavcodec/avcodec.h>
   38 #elif HAVE_FFMPEG_AVCODEC_H
   39 #include <ffmpeg/avcodec.h>
   40 #elif HAVE_LIBAV_AVCODEC_H
   41 #include <libav/avcodec.h>
   42 #elif HAVE_AVCODEC_H
   43 #include <avcodec.h>
   44 #endif
   45 
   46 #if HAVE_FFMPEG_LIBAVFORMAT_AVFORMAT_H
   47 #include <ffmpeg/libavformat/avformat.h>
   48 #elif HAVE_LIBAV_LIBAVFORMAT_AVFORMAT_H
   49 #include <libav/libavformat/avformat.h>
   50 #elif HAVE_LIBAVFORMAT_AVFORMAT_H
   51 #include <libavformat/avformat.h>
   52 #elif HAVE_FFMPEG_AVFORMAT_H
   53 #include <ffmpeg/avformat.h>
   54 #elif HAVE_LIBAV_LIBAVFORMAT_H
   55 #include <libav/avformat.h>
   56 #elif HAVE_AVFORMAT_H
   57 #include <avformat.h>
   58 #endif
   59 
   60 #define USE_CODECPAR LIBAVFORMAT_VERSION_INT >= ((57<<16)+(50<<8)+100)
   61 
   62 #ifndef FF_PROFILE_H264_BASELINE
   63 #define FF_PROFILE_H264_BASELINE 66
   64 #endif
   65 #ifndef FF_PROFILE_H264_CONSTRAINED_BASELINE
   66 #define FF_PROFILE_H264_CONSTRAINED_BASELINE 578
   67 #endif
   68 #ifndef FF_PROFILE_H264_MAIN
   69 #define FF_PROFILE_H264_MAIN 77
   70 #endif
   71 #ifndef FF_PROFILE_H264_HIGH
   72 #define FF_PROFILE_H264_HIGH 100
   73 #endif
   74 #ifndef FF_PROFILE_SKIP
   75 #define FF_PROFILE_SKIP -100
   76 #endif
   77 
   78 #if LIBAVCODEC_VERSION_MAJOR < 53
   79 #define AVMEDIA_TYPE_AUDIO CODEC_TYPE_AUDIO
   80 #define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO
   81 #endif
   82 
   83 #if LIBAVCODEC_VERSION_INT <= ((51<<16)+(50<<8)+1)
   84 #define CODEC_ID_WMAPRO CODEC_ID_NONE
   85 #endif
   86 
   87 #if LIBAVCODEC_VERSION_MAJOR < 55
   88 #define AV_CODEC_ID_AAC CODEC_ID_AAC
   89 #define AV_CODEC_ID_AC3 CODEC_ID_AC3
   90 #define AV_CODEC_ID_ADPCM_IMA_QT CODEC_ID_ADPCM_IMA_QT
   91 #define AV_CODEC_ID_AMR_NB CODEC_ID_AMR_NB
   92 #define AV_CODEC_ID_DTS CODEC_ID_DTS
   93 #define AV_CODEC_ID_H264 CODEC_ID_H264
   94 #define AV_CODEC_ID_MP2 CODEC_ID_MP2
   95 #define AV_CODEC_ID_MP3 CODEC_ID_MP3
   96 #define AV_CODEC_ID_MPEG1VIDEO CODEC_ID_MPEG1VIDEO
   97 #define AV_CODEC_ID_MPEG2VIDEO CODEC_ID_MPEG2VIDEO
   98 #define AV_CODEC_ID_MPEG4 CODEC_ID_MPEG4
   99 #define AV_CODEC_ID_MSMPEG4V3 CODEC_ID_MSMPEG4V3
  100 #define AV_CODEC_ID_PCM_S16LE CODEC_ID_PCM_S16LE
  101 #define AV_CODEC_ID_VC1 CODEC_ID_VC1
  102 #define AV_CODEC_ID_WMAPRO CODEC_ID_WMAPRO
  103 #define AV_CODEC_ID_WMAV1 CODEC_ID_WMAV1
  104 #define AV_CODEC_ID_WMAV2 CODEC_ID_WMAV2
  105 #define AV_CODEC_ID_WMV3 CODEC_ID_WMV3
  106 #endif
  107 
  108 #if LIBAVUTIL_VERSION_INT < ((50<<16)+(13<<8)+0)
  109 #define av_strerror(x, y, z) snprintf(y, z, "%d", x)
  110 #endif
  111 
  112 #if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(31<<8)+0)
  113 # if LIBAVUTIL_VERSION_INT < ((51<<16)+(5<<8)+0) && !defined(FF_API_OLD_METADATA2)
  114 #define AV_DICT_IGNORE_SUFFIX AV_METADATA_IGNORE_SUFFIX
  115 #define av_dict_get av_metadata_get
  116 typedef AVMetadataTag AVDictionaryEntry;
  117 # endif
  118 #endif
  119 
  120 static inline int
  121 lav_open(AVFormatContext **ctx, const char *filename)
  122 {
  123     int ret;
  124 #if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(17<<8)+0)
  125     ret = avformat_open_input(ctx, filename, NULL, NULL);
  126     if (ret == 0)
  127         avformat_find_stream_info(*ctx, NULL);
  128 #else
  129     ret = av_open_input_file(ctx, filename, NULL, 0, NULL);
  130     if (ret == 0)
  131         av_find_stream_info(*ctx);
  132 #endif
  133     return ret;
  134 }
  135 
  136 static inline void
  137 lav_close(AVFormatContext *ctx)
  138 {
  139 #if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(17<<8)+0)
  140     avformat_close_input(&ctx);
  141 #else
  142     av_close_input_file(ctx);
  143 #endif
  144 }
  145 
  146 static inline int
  147 lav_get_fps(AVStream *s)
  148 {
  149 #if LIBAVCODEC_VERSION_MAJOR < 54
  150     if (s->r_frame_rate.den)
  151         return s->r_frame_rate.num / s->r_frame_rate.den;
  152 #else
  153     if (s->avg_frame_rate.den)
  154         return s->avg_frame_rate.num / s->avg_frame_rate.den;
  155 #endif
  156     return 0;
  157 }
  158 
  159 static inline int
  160 lav_get_interlaced(AVStream *s)
  161 {
  162 #if LIBAVCODEC_VERSION_MAJOR >= 57
  163     return (s->time_base.den ? (s->avg_frame_rate.num / s->time_base.den) : 0);
  164 #elif LIBAVCODEC_VERSION_MAJOR >= 54
  165     return (s->codec->time_base.den ? (s->avg_frame_rate.num / s->codec->time_base.den) : 0);
  166 #else
  167     return (s->codec->time_base.den ? (s->r_frame_rate.num / s->codec->time_base.den) : 0);
  168 #endif
  169 }
  170 
  171 #if USE_CODECPAR
  172 #define lav_codec_id(s) s->codecpar->codec_id
  173 #define lav_codec_type(s) s->codecpar->codec_type
  174 #define lav_codec_tag(s) s->codecpar->codec_tag
  175 #define lav_sample_rate(s) s->codecpar->sample_rate
  176 #define lav_bit_rate(s) s->codecpar->bit_rate
  177 #define lav_channels(s) s->codecpar->channels
  178 #define lav_width(s) s->codecpar->width
  179 #define lav_height(s) s->codecpar->height
  180 #define lav_profile(s) s->codecpar->profile
  181 #define lav_level(s) s->codecpar->level
  182 #define lav_sample_aspect_ratio(s) s->codecpar->sample_aspect_ratio
  183 #else
  184 #define lav_codec_id(x) x->codec->codec_id
  185 #define lav_codec_type(s) s->codec->codec_type
  186 #define lav_codec_tag(s) s->codec->codec_tag
  187 #define lav_sample_rate(s) s->codec->sample_rate
  188 #define lav_bit_rate(s) s->codec->bit_rate
  189 #define lav_channels(s) s->codec->channels
  190 #define lav_width(s) s->codec->width
  191 #define lav_height(s) s->codec->height
  192 #define lav_profile(s) s->codec->profile
  193 #define lav_level(s) s->codec->level
  194 #define lav_sample_aspect_ratio(s) s->codec->sample_aspect_ratio
  195 #endif
  196 
  197 static inline uint8_t *
  198 lav_codec_extradata(AVStream *s)
  199 {
  200 #if USE_CODECPAR
  201     if (!s->codecpar->extradata_size)
  202         return NULL;
  203     return s->codecpar->extradata;
  204 #else
  205     if (!s->codec->extradata_size)
  206         return NULL;
  207     return s->codec->extradata;
  208 #endif
  209 }
  210 
  211 static inline int
  212 lav_is_thumbnail_stream(AVStream *s, uint8_t **data, int *size)
  213 {
  214 #if LIBAVFORMAT_VERSION_INT >= ((54<<16)+(6<<8))
  215     if (s->disposition & AV_DISPOSITION_ATTACHED_PIC &&
  216         lav_codec_id(s) == AV_CODEC_ID_MJPEG)
  217     {
  218         if (data)
  219             *data = s->attached_pic.data;
  220         if (size)
  221             *size = s->attached_pic.size;
  222         return 1;
  223     }
  224 #endif
  225     return 0;
  226 }
  227 
  228 static inline void
  229 lav_register_all(void)
  230 {
  231 #if LIBAVFORMAT_VERSION_INT < ((58<<16)+(9<<8)+100)
  232     av_register_all();
  233 #endif
  234 }