Skip to content
Snippets Groups Projects
avcodec.h 67 KiB
Newer Older
  • Learn to ignore specific revisions
  • 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);
    
    Falk Hüffner's avatar
    Falk Hüffner committed
    void avcodec_get_frame_defaults(AVFrame *pic);
    
    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);
    
    int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic);
    void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height);
    enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt);
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    
    
    Michael Niedermayer's avatar
    1l  
    Michael Niedermayer committed
    int avcodec_thread_init(AVCodecContext *s, int thread_count);
    void avcodec_thread_free(AVCodecContext *s);
    int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count);
    
    int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count);
    
    //FIXME func typedef
    
    
    Michael Niedermayer's avatar
    Michael Niedermayer committed
    /**
     * opens / inits the AVCodecContext.
     * not thread save!
     */
    
    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 with rounding to nearest.
    
    int64_t av_rescale(int64_t a, int64_t b, int64_t c);
    
    /**
     * rescale a 64bit integer with specified rounding.
     * a simple a*b/c isnt possible as it can overflow
     */
    int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding);
    
    /**
     * 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);
    
    
    /* frame parsing */
    typedef struct AVCodecParserContext {
        void *priv_data;
        struct AVCodecParser *parser;
        int64_t frame_offset; /* offset of the current frame */
        int64_t cur_offset; /* current offset 
                               (incremented by each av_parser_parse()) */
        int64_t last_frame_offset; /* offset of the last frame */
        /* video info */
        int pict_type; /* XXX: put it back in AVCodecContext */
        int repeat_pict; /* XXX: put it back in AVCodecContext */
    
        int64_t pts;     /* pts of the current frame */
        int64_t dts;     /* dts of the current frame */
    
        /* private data */
        int64_t last_pts;
        int64_t last_dts;
    
        int fetch_timestamp;
    
    
    #define AV_PARSER_PTS_NB 4
        int cur_frame_start_index;
        int64_t cur_frame_offset[AV_PARSER_PTS_NB];
        int64_t cur_frame_pts[AV_PARSER_PTS_NB];
        int64_t cur_frame_dts[AV_PARSER_PTS_NB];
    
    } AVCodecParserContext;
    
    typedef struct AVCodecParser {
        int codec_ids[3]; /* several codec IDs are permitted */
        int priv_data_size;
        int (*parser_init)(AVCodecParserContext *s);
        int (*parser_parse)(AVCodecParserContext *s, 
                            AVCodecContext *avctx,
                            uint8_t **poutbuf, int *poutbuf_size, 
                            const uint8_t *buf, int buf_size);
        void (*parser_close)(AVCodecParserContext *s);
        struct AVCodecParser *next;
    } AVCodecParser;
    
    extern AVCodecParser *av_first_parser;
    
    void av_register_codec_parser(AVCodecParser *parser);
    AVCodecParserContext *av_parser_init(int codec_id);
    int av_parser_parse(AVCodecParserContext *s, 
                        AVCodecContext *avctx,
                        uint8_t **poutbuf, int *poutbuf_size, 
    
                        const uint8_t *buf, int buf_size,
                        int64_t pts, int64_t dts);
    
    void av_parser_close(AVCodecParserContext *s);
    
    extern AVCodecParser mpegvideo_parser;
    extern AVCodecParser mpeg4video_parser;
    
    extern AVCodecParser h263_parser;
    extern AVCodecParser h264_parser;
    extern AVCodecParser mpegaudio_parser;
    extern AVCodecParser ac3_parser;
    
    
    /* memory */
    
    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);
    
    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(unsigned int size);
    
    /* add by bero : in adx.c */
    int is_adx(const unsigned char *buf,size_t bufsize);
    
    
    void img_copy(AVPicture *dst, const AVPicture *src,
                  int pix_fmt, int width, int height);
    
    
    #define AV_LOG_QUIET -1
    
    #define AV_LOG_ERROR 0
    #define AV_LOG_INFO 1
    #define AV_LOG_DEBUG 2
    
    
    extern void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
    
    #else
    extern void av_log(void*, int level, const char *fmt, ...);
    #endif
    
    
    extern void av_vlog(void*, int level, const char *fmt, va_list);
    
    extern int av_log_get_level(void);
    extern void av_log_set_level(int);
    
    extern void av_log_set_callback(void (*)(void*, int, const char*, va_list));
    
    #if !defined(BE_16) || !defined(BE_32) || !defined(LE_16) || !defined(LE_32)
    
    #define BE_16(x)  ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
    #define BE_32(x)  ((((uint8_t*)(x))[0] << 24) | \
                       (((uint8_t*)(x))[1] << 16) | \
                       (((uint8_t*)(x))[2] << 8) | \
                        ((uint8_t*)(x))[3])
    #define LE_16(x)  ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
    #define LE_32(x)  ((((uint8_t*)(x))[3] << 24) | \
                       (((uint8_t*)(x))[2] << 16) | \
                       (((uint8_t*)(x))[1] << 8) | \
                        ((uint8_t*)(x))[0])
    
    #ifdef __cplusplus
    }
    #endif
    
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
    #endif /* AVCODEC_H */