ZLMediaKit/api/include/mk_transcode.h

154 lines
4.7 KiB
C++
Raw Normal View History

2022-05-25 15:38:32 +08:00
/*
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
*
* Use of this source code is governed by MIT license that can be found in the
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
*/
#ifndef ZLMEDIAKIT_MK_TRANSCODE_H
#define ZLMEDIAKIT_MK_TRANSCODE_H
#include "mk_common.h"
#include "mk_track.h"
#ifdef __cplusplus
extern "C" {
#endif
//解码器对象
typedef void *mk_decoder;
//解码后的frame
typedef void *mk_frame_pix;
//SwsContext的包装
typedef void *mk_swscale;
//FFmpeg原始解码帧对象
typedef struct AVFrame AVFrame;
//FFmpeg编解码器对象
typedef struct AVCodecContext AVCodecContext;
//解码输出回调
typedef void(API_CALL *on_mk_decode)(void *user_data, mk_frame_pix frame);
/**
*
* @param track track对象
* @param thread_num 线0
* @return NULL代表失败
*/
API_EXPORT mk_decoder API_CALL mk_decoder_create(mk_track track, int thread_num);
/**
*
* @param ctx
* @param flush_frame
*/
API_EXPORT void API_CALL mk_decoder_release(mk_decoder ctx, int flush_frame);
/**
*
* @param ctx
* @param frame
* @param async
* @param enable_merge slice合并输入到解码器才能解码
*/
API_EXPORT void API_CALL mk_decoder_decode(mk_decoder ctx, mk_frame frame, int async, int enable_merge);
/**
*
*/
API_EXPORT void API_CALL mk_decoder_set_max_async_frame_size(mk_decoder ctx, size_t size);
/**
*
* @param ctx
* @param cb
* @param user_data
*/
API_EXPORT void API_CALL mk_decoder_set_cb(mk_decoder ctx, on_mk_decode cb, void *user_data);
/**
* FFmpeg原始AVCodecContext对象
* @param ctx
*/
API_EXPORT const AVCodecContext* API_CALL mk_decoder_get_context(mk_decoder ctx);
/////////////////////////////////////////////////////////////////////////////////////////////
/**
* mk_frame_pix新引用
* @param frame
* @return
*/
API_EXPORT mk_frame_pix API_CALL mk_frame_pix_ref(mk_frame_pix frame);
/**
* mk_frame_pix减引用
* @param frame
*/
API_EXPORT void API_CALL mk_frame_pix_unref(mk_frame_pix frame);
/**
* FFmpeg AVFrame转换为mk_frame_pix
* @param frame FFmpeg AVFrame
* @return mk_frame_pix对象
*/
API_EXPORT mk_frame_pix API_CALL mk_frame_pix_from_av_frame(AVFrame *frame);
/**
* FFmpeg AVFrame对象
* @param frame mk_frame_pix
* @return FFmpeg AVFrame对象
*/
API_EXPORT AVFrame* API_CALL mk_frame_pix_get_av_frame(mk_frame_pix frame);
/////////////////////////////////////////////////////////////////////////////////////////////
/**
* ffmpeg SwsContext wrapper实例
* @param output AVPixelFormat类型AV_PIX_FMT_BGR24==3
* @param width 0
* @param height 0
* @return SwsContext wrapper
*/
API_EXPORT mk_swscale mk_swscale_create(int output, int width, int height);
/**
* ffmpeg SwsContext wrapper实例
* @param ctx SwsContext wrapper实例
*/
API_EXPORT void mk_swscale_release(mk_swscale ctx);
/**
* 使SwsContext转换pix format
* @param ctx SwsContext wrapper实例
* @param frame pix frame
* @param out
* @return sws_scale()the height of the output slice
*/
API_EXPORT int mk_swscale_input_frame(mk_swscale ctx, mk_frame_pix frame, uint8_t *out);
/**
* 使SwsContext转换pix format
* @param ctx SwsContext wrapper实例
* @param frame pix frame
* @return pix frame对象使mk_frame_pix_unref销毁
*/
API_EXPORT mk_frame_pix mk_swscale_input_frame2(mk_swscale ctx, mk_frame_pix frame);
/////////////////////////////////////////////////////////////////////////////////////////////
API_EXPORT uint8_t** API_CALL mk_get_av_frame_data(AVFrame *frame);
API_EXPORT int* API_CALL mk_get_av_frame_line_size(AVFrame *frame);
API_EXPORT int64_t API_CALL mk_get_av_frame_dts(AVFrame *frame);
API_EXPORT int64_t API_CALL mk_get_av_frame_pts(AVFrame *frame);
API_EXPORT int API_CALL mk_get_av_frame_width(AVFrame *frame);
API_EXPORT int API_CALL mk_get_av_frame_height(AVFrame *frame);
API_EXPORT int API_CALL mk_get_av_frame_format(AVFrame *frame);
#ifdef __cplusplus
}
#endif
#endif //ZLMEDIAKIT_MK_TRANSCODE_H