Skip to content
Snippets Groups Projects
avcodec.h 41.6 KiB
Newer Older
  • Learn to ignore specific revisions
  •     int last_predictor_count;
    
         * pre pass for motion estimation.
         * - encoding: set by user.
         * - decoding: unused
    
         */
        int pre_me;
    
         * motion estimation pre pass compare function.
         * - encoding: set by user.
         * - decoding: unused
    
         */
        int me_pre_cmp;
    
         * ME pre pass diamond size & shape.
         * - encoding: set by user.
         * - decoding: unused
    
         */
        int pre_dia_size;
    
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
        /**
    
         * subpel ME quality.
         * - encoding: set by user.
         * - decoding: unused
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
         */
        int me_subpel_quality;
    
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
        /**
    
         * callback to negotiate the pixelFormat.
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
         * @param fmt is the list of formats which are supported by the codec,
         * its terminated by -1 as 0 is a valid format, the formats are ordered by quality
         * the first is allways the native one
         * @return the choosen format
    
         * - encoding: unused
         * - decoding: set by user, if not set then the native format will always be choosen
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
         */
        enum PixelFormat (*get_format)(struct AVCodecContext *s, enum PixelFormat * fmt);
    
    
        /**
         * DTG active format information (additionnal aspect ratio
         * information only used in DVB MPEG2 transport streams). 0 if
         * not set.
         * 
    
         * - encoding: unused.
         * - decoding: set by decoder 
    
         */
        int dtg_active_format;
    #define FF_DTG_AFD_SAME         8
    #define FF_DTG_AFD_4_3          9
    #define FF_DTG_AFD_16_9         10
    #define FF_DTG_AFD_14_9         11
    #define FF_DTG_AFD_4_3_SP_14_9  13
    #define FF_DTG_AFD_16_9_SP_14_9 14
    #define FF_DTG_AFD_SP_4_3       15
    
    
        /**
         * Maximum motion estimation search range in subpel units.
         * if 0 then no limit
         * 
    
         * - encoding: set by user.
         * - decoding: unused.
    
    Zdenek Kabelac's avatar
    Zdenek Kabelac committed
        int me_range;
    
        /**
         * frame_rate_base.
         * for variable fps this is 1
         * - encoding: set by user.
         * - decoding: set by lavc.
         * @todo move this after frame_rate
         */
    
    
        int frame_rate_base;
        /**
         * intra quantizer bias.
         * - encoding: set by user.
         * - decoding: unused
         */
        int intra_quant_bias;
    #define FF_DEFAULT_QUANT_BIAS 999999
        
        /**
         * inter quantizer bias.
         * - encoding: set by user.
         * - decoding: unused
         */
        int inter_quant_bias;
    
    
        /**
         * color table ID.
         * - encoding: unused.
         * - decoding: which clrtable should be used for 8bit RGB images
         *             table have to be stored somewhere FIXME
         */
        int color_table_id;
    
        /**
         * internal_buffer count. 
         * Dont touch, used by lavc default_get_buffer()
         */
        int internal_buffer_count;
        
        /**
         * internal_buffers. 
         * Dont touch, used by lavc default_get_buffer()
         */
        void *internal_buffer;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    } AVCodecContext;
    
    
    typedef struct AVOption {
        /** options' name */
        const char *name; /* if name is NULL, it indicates a link to next */
    
        /** short English text help or const struct AVOption* subpointer */
        const char *help; //	const struct AVOption* sub;
    
        /** offset to context structure where the parsed value should be stored */
        int offset;
        /** options' type */
        int type;
    
    #define FF_OPT_TYPE_BOOL 1      ///< boolean - true,1,on  (or simply presence)
    #define FF_OPT_TYPE_DOUBLE 2    ///< double
    #define FF_OPT_TYPE_INT 3       ///< integer
    #define FF_OPT_TYPE_STRING 4    ///< string (finished with \0)
    #define FF_OPT_TYPE_MASK 0x1f	///< mask for types - upper bits are various flags
    
    //#define FF_OPT_TYPE_EXPERT 0x20 // flag for expert option
    #define FF_OPT_TYPE_FLAG (FF_OPT_TYPE_BOOL | 0x40)
    #define FF_OPT_TYPE_RCOVERRIDE (FF_OPT_TYPE_STRING | 0x80)
        /** min value  (min == max   ->  no limits) */
        double min;
        /** maximum value for double/int */
        double max;
        /** default boo [0,1]l/double/int value */
        double defval;
        /**
         * default string value (with optional semicolon delimited extra option-list
         * i.e.   option1;option2;option3
         * defval might select other then first argument as default
         */
        const char *defstr;
    #define FF_OPT_MAX_DEPTH 10
    } AVOption;
    
    
    /**
     * Parse option(s) and sets fields in passed structure
     * @param strct	structure where the parsed results will be written
     * @param list  list with AVOptions
     * @param opts	string with options for parsing
     */
    int avoption_parse(void* strct, const AVOption* list, const char* opts);
    
    
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    typedef struct AVCodec {
    
        const char *name;
    
    Zdenek Kabelac's avatar
    Zdenek Kabelac committed
        enum CodecType type;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        int id;
        int priv_data_size;
        int (*init)(AVCodecContext *);
    
        int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        int (*close)(AVCodecContext *);
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
        int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
    
                      uint8_t *buf, int buf_size);
    
        int capabilities;
    
        const AVOption *options;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        struct AVCodec *next;
    } AVCodec;
    
    
     * four components are given, that's all.
     * the last component is alpha
     */
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    typedef struct AVPicture {
    
        uint8_t *data[4];
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    } AVPicture;
    
    extern AVCodec ac3_encoder;
    extern AVCodec mp2_encoder;
    
    extern AVCodec mp3lame_encoder;
    
    extern AVCodec oggvorbis_encoder;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    extern AVCodec mpeg1video_encoder;
    extern AVCodec h263_encoder;
    extern AVCodec h263p_encoder;
    extern AVCodec rv10_encoder;
    extern AVCodec mjpeg_encoder;
    
    extern AVCodec mpeg4_encoder;
    
    extern AVCodec msmpeg4v1_encoder;
    extern AVCodec msmpeg4v2_encoder;
    extern AVCodec msmpeg4v3_encoder;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    extern AVCodec wmv1_encoder;
    extern AVCodec wmv2_encoder;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    extern AVCodec huffyuv_encoder;
    
    extern AVCodec h264_encoder;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    
    extern AVCodec h263_decoder;
    
    extern AVCodec mpeg4_decoder;
    
    extern AVCodec msmpeg4v1_decoder;
    extern AVCodec msmpeg4v2_decoder;
    extern AVCodec msmpeg4v3_decoder;
    
    extern AVCodec wmv1_decoder;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    extern AVCodec wmv2_decoder;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    extern AVCodec mpeg_decoder;
    extern AVCodec h263i_decoder;
    extern AVCodec rv10_decoder;
    
    Nick Kurshev's avatar
    Nick Kurshev committed
    extern AVCodec svq1_decoder;
    
    extern AVCodec svq3_decoder;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    extern AVCodec dvvideo_decoder;
    extern AVCodec dvaudio_decoder;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    extern AVCodec wmav1_decoder;
    extern AVCodec wmav2_decoder;
    
    extern AVCodec mjpeg_decoder;
    
    extern AVCodec mjpegb_decoder;
    
    extern AVCodec mp2_decoder;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    extern AVCodec mp3_decoder;
    
    extern AVCodec mace3_decoder;
    extern AVCodec mace6_decoder;
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    extern AVCodec huffyuv_decoder;
    
    extern AVCodec oggvorbis_decoder;
    
    extern AVCodec h264_decoder;
    
    extern AVCodec indeo3_decoder;
    
    extern AVCodec vp3_decoder;
    
    extern AVCodec amr_nb_decoder;
    
    extern AVCodec aac_decoder;
    extern AVCodec mpeg4aac_decoder;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    /* pcm codecs */
    #define PCM_CODEC(id, name) \
    extern AVCodec name ## _decoder; \
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    
    PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
    PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
    PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
    PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
    PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
    PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
    PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
    PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
    
    
    /* adpcm codecs */
    
    PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
    PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
    PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
    
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    #undef PCM_CODEC
    
    /* dummy raw video codec */
    
    extern AVCodec rawvideo_encoder;
    extern AVCodec rawvideo_decoder;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    
    /* the following codecs use external GPL libs */
    extern AVCodec ac3_decoder;
    
    /* resample.c */
    
    struct ReSampleContext;
    
    typedef struct ReSampleContext ReSampleContext;
    
    ReSampleContext *audio_resample_init(int output_channels, int input_channels, 
                                         int output_rate, int input_rate);
    int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
    void audio_resample_close(ReSampleContext *s);
    
    /* YUV420 format is assumed ! */
    
    struct ImgReSampleContext;
    
    typedef struct ImgReSampleContext ImgReSampleContext;
    
    ImgReSampleContext *img_resample_init(int output_width, int output_height,
                                          int input_width, int input_height);
    
    
    ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
                                          int iwidth, int iheight,
                                          int topBand, int bottomBand,
                                          int leftBand, int rightBand);
    
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    void img_resample(ImgReSampleContext *s, 
                      AVPicture *output, AVPicture *input);
    
    void img_resample_close(ImgReSampleContext *s);
    
    
    int avpicture_fill(AVPicture *picture, uint8_t *ptr,
    
                       int pix_fmt, int width, int height);
    
    int avpicture_layout(AVPicture* src, int pix_fmt, int width, int height,
                         unsigned char *dest, int dest_size);
    
    int avpicture_get_size(int pix_fmt, int width, int height);
    
    void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
    const char *avcodec_get_pix_fmt_name(int pix_fmt);
    
    enum PixelFormat avcodec_get_pix_fmt(const char* name);
    
    #define FF_LOSS_RESOLUTION  0x0001 /* loss due to resolution change */
    #define FF_LOSS_DEPTH       0x0002 /* loss due to color depth change */
    #define FF_LOSS_COLORSPACE  0x0004 /* loss due to color space conversion */
    #define FF_LOSS_ALPHA       0x0008 /* loss of alpha bits */
    #define FF_LOSS_COLORQUANT  0x0010 /* loss due to color quantization */
    #define FF_LOSS_CHROMA      0x0020 /* loss of chroma (e.g. rgb to gray conversion) */
    
    int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
                                 int has_alpha);
    int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,
                                  int has_alpha, int *loss_ptr);
    
    
    #define FF_ALPHA_TRANSP       0x0001 /* image has some totally transparent pixels */
    #define FF_ALPHA_SEMI_TRANSP  0x0002 /* image has some transparent pixels */
    int img_get_alpha_info(AVPicture *src, int pix_fmt, int width, int height);
    
    
    /* convert among pixel formats */
    int img_convert(AVPicture *dst, int dst_pix_fmt,
                    AVPicture *src, int pix_fmt, 
                    int width, int height);
    
    /* deinterlace a picture */
    int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
                              int pix_fmt, int width, int height);
    
    /* external high level API */
    
    extern AVCodec *first_avcodec;
    
    
    Nick Kurshev's avatar
    Nick Kurshev committed
    /* returns LIBAVCODEC_VERSION_INT constant */
    
    unsigned avcodec_version(void);
    
    Nick Kurshev's avatar
    Nick Kurshev committed
    /* returns LIBAVCODEC_BUILD constant */
    
    unsigned avcodec_build(void);
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    void avcodec_init(void);
    
    void register_avcodec(AVCodec *format);
    AVCodec *avcodec_find_encoder(enum CodecID id);
    
    AVCodec *avcodec_find_encoder_by_name(const char *name);
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    AVCodec *avcodec_find_decoder(enum CodecID id);
    AVCodec *avcodec_find_decoder_by_name(const char *name);
    void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
    
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    void avcodec_get_context_defaults(AVCodecContext *s);
    
    Falk Hüffner's avatar
    Falk Hüffner committed
    AVCodecContext *avcodec_alloc_context(void);
    
    AVFrame *avcodec_alloc_frame(void);
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    
    
    int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
    void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
    
    void avcodec_default_free_buffers(AVCodecContext *s);
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
    
    int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples, 
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
                             int *frame_size_ptr,
    
                             uint8_t *buf, int buf_size);
    
    int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, 
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
                             int *got_picture_ptr,
    
                             uint8_t *buf, int buf_size);
    int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata, 
    
                            uint8_t *buf, int buf_size);
    int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, 
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
                             const short *samples);
    
    int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, 
    
                             const AVFrame *pict);
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    
    int avcodec_close(AVCodecContext *avctx);
    
    void avcodec_register_all(void);
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    
    
    void avcodec_flush_buffers(AVCodecContext *avctx);
    
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    
    /**
     * returns a single letter to describe the picture type
     */
    char av_get_pict_type_char(int pict_type);
    
    
    /**
     * reduce a fraction.
     * this is usefull for framerate calculations
     * @param max the maximum allowed for dst_nom & dst_den
     * @return 1 if exact, 0 otherwise
     */
    int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max);
    
    /**
     * rescale a 64bit integer.
     * a simple a*b/c isnt possible as it can overflow
     */
    int64_t av_rescale(int64_t a, int b, int c);
    
    /**
     * Interface for 0.5.0 version
     *
     * do not even think about it's usage for this moment
     */
    
    typedef struct {
    
        /// compressed size used from given memory buffer
    
        int size;
        /// I/P/B frame type
        int frame_type;
    } avc_enc_result_t;
    
    /**
     * Commands
     * order can't be changed - once it was defined
     */
    typedef enum {
        // general commands
        AVC_OPEN_BY_NAME = 0xACA000,
        AVC_OPEN_BY_CODEC_ID,
        AVC_OPEN_BY_FOURCC,
        AVC_CLOSE,
    
        AVC_FLUSH,
        // pin - struct { uint8_t* src, uint_t src_size }
        // pout - struct { AVPicture* img, consumed_bytes,
        AVC_DECODE,
        // pin - struct { AVPicture* img, uint8_t* dest, uint_t dest_size }
        // pout - uint_t used_from_dest_size
        AVC_ENCODE, 
    
        // query/get video commands
        AVC_GET_VERSION = 0xACB000,
        AVC_GET_WIDTH,
        AVC_GET_HEIGHT,
        AVC_GET_DELAY,
        AVC_GET_QUANT_TABLE,
        // ...
    
        // query/get audio commands
        AVC_GET_FRAME_SIZE = 0xABC000,
    
        // maybe define some simple structure which
        // might be passed to the user - but they can't
        // contain any codec specific parts and these
        // calls are usualy necessary only few times
    
        // set video commands
        AVC_SET_WIDTH = 0xACD000,
        AVC_SET_HEIGHT,
    
        // set video encoding commands
        AVC_SET_FRAME_RATE = 0xACD800,
        AVC_SET_QUALITY,
        AVC_SET_HURRY_UP,
    
        // set audio commands
        AVC_SET_SAMPLE_RATE = 0xACE000,
        AVC_SET_CHANNELS,
    
    } avc_cmd_t;
    
    /**
     * \param handle  allocated private structure by libavcodec
     *                for initialization pass NULL - will be returned pout
     *                user is supposed to know nothing about its structure
     * \param cmd     type of operation to be performed
     * \param pint    input parameter
     * \param pout    output parameter
     *
     * \returns  command status - eventually for query command it might return
     * integer resulting value
     */
    int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout);
    
    
    /* memory */
    
    void *av_malloc(unsigned int size);
    void *av_mallocz(unsigned int size);
    
    void *av_realloc(void *ptr, unsigned int size);
    
    void av_free(void *ptr);
    
    char *av_strdup(const char *s);
    
    void __av_freep(void **ptr);
    #define av_freep(p) __av_freep((void **)(p))
    
    void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
    
    /* for static data only */
    /* call av_free_static to release all staticaly allocated tables */
    
    void av_free_static(void);
    
    void *__av_mallocz_static(void** location, unsigned int size);
    #define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s)
    
    #ifdef __cplusplus
    }
    #endif
    
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    #endif /* AVCODEC_H */