yading@10: /* yading@10: * This file is part of FFmpeg. yading@10: * yading@10: * FFmpeg is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * FFmpeg is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with FFmpeg; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: yading@10: /** yading@10: * @file yading@10: * common internal api header. yading@10: */ yading@10: yading@10: #ifndef AVCODEC_INTERNAL_H yading@10: #define AVCODEC_INTERNAL_H yading@10: yading@10: #include yading@10: yading@10: #include "libavutil/buffer.h" yading@10: #include "libavutil/mathematics.h" yading@10: #include "libavutil/pixfmt.h" yading@10: #include "avcodec.h" yading@10: #include "config.h" yading@10: yading@10: #define FF_SANE_NB_CHANNELS 63U yading@10: yading@10: typedef struct FramePool { yading@10: /** yading@10: * Pools for each data plane. For audio all the planes have the same size, yading@10: * so only pools[0] is used. yading@10: */ yading@10: AVBufferPool *pools[4]; yading@10: yading@10: /* yading@10: * Pool parameters yading@10: */ yading@10: int format; yading@10: int width, height; yading@10: int stride_align[AV_NUM_DATA_POINTERS]; yading@10: int linesize[4]; yading@10: int planes; yading@10: int channels; yading@10: int samples; yading@10: } FramePool; yading@10: yading@10: typedef struct AVCodecInternal { yading@10: /** yading@10: * Whether the parent AVCodecContext is a copy of the context which had yading@10: * init() called on it. yading@10: * This is used by multithreading - shared tables and picture pointers yading@10: * should be freed from the original context only. yading@10: */ yading@10: int is_copy; yading@10: yading@10: /** yading@10: * Whether to allocate progress for frame threading. yading@10: * yading@10: * The codec must set it to 1 if it uses ff_thread_await/report_progress(), yading@10: * then progress will be allocated in ff_thread_get_buffer(). The frames yading@10: * then MUST be freed with ff_thread_release_buffer(). yading@10: * yading@10: * If the codec does not need to call the progress functions (there are no yading@10: * dependencies between the frames), it should leave this at 0. Then it can yading@10: * decode straight to the user-provided frames (which the user will then yading@10: * free with av_frame_unref()), there is no need to call yading@10: * ff_thread_release_buffer(). yading@10: */ yading@10: int allocate_progress; yading@10: yading@10: #if FF_API_OLD_ENCODE_AUDIO yading@10: /** yading@10: * Internal sample count used by avcodec_encode_audio() to fabricate pts. yading@10: * Can be removed along with avcodec_encode_audio(). yading@10: */ yading@10: int sample_count; yading@10: #endif yading@10: yading@10: /** yading@10: * An audio frame with less than required samples has been submitted and yading@10: * padded with silence. Reject all subsequent frames. yading@10: */ yading@10: int last_audio_frame; yading@10: yading@10: AVFrame to_free; yading@10: yading@10: FramePool *pool; yading@10: yading@10: /** yading@10: * temporary buffer used for encoders to store their bitstream yading@10: */ yading@10: uint8_t *byte_buffer; yading@10: unsigned int byte_buffer_size; yading@10: yading@10: void *frame_thread_encoder; yading@10: yading@10: /** yading@10: * Number of audio samples to skip at the start of the next decoded frame yading@10: */ yading@10: int skip_samples; yading@10: } AVCodecInternal; yading@10: yading@10: struct AVCodecDefault { yading@10: const uint8_t *key; yading@10: const uint8_t *value; yading@10: }; yading@10: yading@10: /** yading@10: * Return the hardware accelerated codec for codec codec_id and yading@10: * pixel format pix_fmt. yading@10: * yading@10: * @param codec_id the codec to match yading@10: * @param pix_fmt the pixel format to match yading@10: * @return the hardware accelerated codec, or NULL if none was found. yading@10: */ yading@10: AVHWAccel *ff_find_hwaccel(enum AVCodecID codec_id, enum AVPixelFormat pix_fmt); yading@10: yading@10: /** yading@10: * Return the index into tab at which {a,b} match elements {[0],[1]} of tab. yading@10: * If there is no such matching pair then size is returned. yading@10: */ yading@10: int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b); yading@10: yading@10: unsigned int avpriv_toupper4(unsigned int x); yading@10: yading@10: /** yading@10: * does needed setup of pkt_pts/pos and such for (re)get_buffer(); yading@10: */ yading@10: int ff_init_buffer_info(AVCodecContext *s, AVFrame *frame); yading@10: yading@10: yading@10: void avpriv_color_frame(AVFrame *frame, const int color[4]); yading@10: yading@10: /** yading@10: * Remove and free all side data from packet. yading@10: */ yading@10: void ff_packet_free_side_data(AVPacket *pkt); yading@10: yading@10: extern volatile int ff_avcodec_locked; yading@10: int ff_lock_avcodec(AVCodecContext *log_ctx); yading@10: int ff_unlock_avcodec(void); yading@10: yading@10: int avpriv_lock_avformat(void); yading@10: int avpriv_unlock_avformat(void); yading@10: yading@10: /** yading@10: * Maximum size in bytes of extradata. yading@10: * This value was chosen such that every bit of the buffer is yading@10: * addressable by a 32-bit signed integer as used by get_bits. yading@10: */ yading@10: #define FF_MAX_EXTRADATA_SIZE ((1 << 28) - FF_INPUT_BUFFER_PADDING_SIZE) yading@10: yading@10: /** yading@10: * Check AVPacket size and/or allocate data. yading@10: * yading@10: * Encoders supporting AVCodec.encode2() can use this as a convenience to yading@10: * ensure the output packet data is large enough, whether provided by the user yading@10: * or allocated in this function. yading@10: * yading@10: * @param avctx the AVCodecContext of the encoder yading@10: * @param avpkt the AVPacket yading@10: * If avpkt->data is already set, avpkt->size is checked yading@10: * to ensure it is large enough. yading@10: * If avpkt->data is NULL, a new buffer is allocated. yading@10: * avpkt->size is set to the specified size. yading@10: * All other AVPacket fields will be reset with av_init_packet(). yading@10: * @param size the minimum required packet size yading@10: * @return 0 on success, negative error code on failure yading@10: */ yading@10: int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int size); yading@10: yading@10: int ff_alloc_packet(AVPacket *avpkt, int size); yading@10: yading@10: /** yading@10: * Rescale from sample rate to AVCodecContext.time_base. yading@10: */ yading@10: static av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx, yading@10: int64_t samples) yading@10: { yading@10: if(samples == AV_NOPTS_VALUE) yading@10: return AV_NOPTS_VALUE; yading@10: return av_rescale_q(samples, (AVRational){ 1, avctx->sample_rate }, yading@10: avctx->time_base); yading@10: } yading@10: yading@10: /** yading@10: * Get a buffer for a frame. This is a wrapper around yading@10: * AVCodecContext.get_buffer() and should be used instead calling get_buffer() yading@10: * directly. yading@10: */ yading@10: int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags); yading@10: yading@10: /** yading@10: * Identical in function to av_frame_make_writable(), except it uses yading@10: * ff_get_buffer() to allocate the buffer when needed. yading@10: */ yading@10: int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame); yading@10: yading@10: int ff_thread_can_start_frame(AVCodecContext *avctx); yading@10: yading@10: int ff_get_logical_cpus(AVCodecContext *avctx); yading@10: yading@10: int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx); yading@10: yading@10: /** yading@10: * Call avcodec_open2 recursively by decrementing counter, unlocking mutex, yading@10: * calling the function and then restoring again. Assumes the mutex is yading@10: * already locked yading@10: */ yading@10: int ff_codec_open2_recursive(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options); yading@10: yading@10: /** yading@10: * Call avcodec_close recursively, counterpart to avcodec_open2_recursive. yading@10: */ yading@10: int ff_codec_close_recursive(AVCodecContext *avctx); yading@10: yading@10: /** yading@10: * Finalize buf into extradata and set its size appropriately. yading@10: */ yading@10: int avpriv_bprint_to_extradata(AVCodecContext *avctx, struct AVBPrint *buf); yading@10: yading@10: const uint8_t *avpriv_find_start_code(const uint8_t *p, yading@10: const uint8_t *end, yading@10: uint32_t *state); yading@10: yading@10: #endif /* AVCODEC_INTERNAL_H */