avcommon.h 2.99 KB
Newer Older
1
/*****************************************************************************
2
 * avcommon.h: common code for libav*
3
 *****************************************************************************
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
4
 * Copyright (C) 2012 VLC authors and VideoLAN
5 6 7 8
 * $Id$
 *
 * Authors: Rafaël Carré <funman@videolanorg>
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
9 10 11
 * This program 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
12 13 14 15
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
16 17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
18
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
19 20 21
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23 24 25 26 27 28
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_avcodec.h>
29 30
#include <vlc_configuration.h>
#include <vlc_variables.h>
31

32 33
#include <limits.h>

34 35 36 37 38 39 40 41 42
/* LIBAVUTIL_VERSION_CHECK checks for the right version of libav and FFmpeg
 * a is the major version
 * b and c the minor and micro versions of libav
 * d and e the minor and micro versions of FFmpeg */
#define LIBAVUTIL_VERSION_CHECK( a, b, c, d, e ) \
    (LIBAVUTIL_VERSION_MICRO <  100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT( a, b, c ) ) || \
    (LIBAVUTIL_VERSION_MICRO >= 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT( a, d, e ) )


43 44
unsigned GetVlcDspMask( void );

45 46 47 48 49
#ifdef HAVE_LIBAVFORMAT_AVFORMAT_H
# include <libavformat/avformat.h>
static inline void vlc_init_avformat(void)
{
    vlc_avcodec_lock();
50

51
#if LIBAVUTIL_VERSION_CHECK(51, 25, 0, 42, 100)
52
    av_set_cpu_flags_mask( INT_MAX & ~GetVlcDspMask() );
53
#endif
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

    av_register_all();

    vlc_avcodec_unlock();
}
#endif

#ifdef HAVE_LIBAVCODEC_AVCODEC_H
# include <libavcodec/avcodec.h>
static inline void vlc_init_avcodec(void)
{
    vlc_avcodec_lock();
    avcodec_register_all();
    vlc_avcodec_unlock();
}
#endif
70 71 72

#ifdef HAVE_LIBAVUTIL_AVUTIL_H
# include <libavutil/avutil.h>
73
# include <libavutil/dict.h>
74

75 76 77 78
#if LIBAVUTIL_VERSION_MAJOR < 52 && !defined(AV_CPU_FLAG_MMXEXT)
#   define AV_CPU_FLAG_MMXEXT       AV_CPU_FLAG_MMX2
#endif

79 80
#define AV_OPTIONS_TEXT     "Advanced options."
#define AV_OPTIONS_LONGTEXT "Advanced options, in the form {opt=val,opt2=val2} ."
81 82 83 84

static inline AVDictionary *vlc_av_get_options(const char *psz_opts)
{
    AVDictionary *options = NULL;
85
    config_chain_t *cfg = NULL;
86 87 88 89 90 91 92 93 94 95 96
    config_ChainParseOptions(&cfg, psz_opts);
    while (cfg) {
        config_chain_t *next = cfg->p_next;
        av_dict_set(&options, cfg->psz_name, cfg->psz_value,
            AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
        free(cfg);
        cfg = next;
    }
    return options;
}
#endif