ZLMediaKit/api/include/mk_transcode.h

188 lines
6.4 KiB
C++
Raw Permalink Normal View History

2022-05-25 15:38:32 +08:00
/*
2023-12-09 16:23:51 +08:00
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
2022-05-25 15:38:32 +08:00
*
2023-12-09 16:23:51 +08:00
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
2022-05-25 15:38:32 +08:00
*
2023-12-09 16:23:51 +08:00
* Use of this source code is governed by MIT-like license that can be found in the
2022-05-25 15:38:32 +08:00
* 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"
2023-02-11 11:35:37 +08:00
#include "mk_tcp.h"
2022-05-25 15:38:32 +08:00
#ifdef __cplusplus
extern "C" {
#endif
//解码器对象
typedef struct mk_decoder_t *mk_decoder;
2022-05-25 15:38:32 +08:00
//解码后的frame
typedef struct mk_frame_pix_t *mk_frame_pix;
2022-05-25 15:38:32 +08:00
//SwsContext的包装
typedef struct mk_swscale_t *mk_swscale;
2022-05-25 15:38:32 +08:00
//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);
2023-02-11 11:35:37 +08:00
/**
*
* @param track track对象
* @param thread_num 线0
* @param codec_name_list ffmpeg codec name列表NULL结尾{"libopenh264", "h264_nvdec", NULL};
* ;codec不存在mk_track_codec_id类型不匹配时使codec列表
* @return NULL代表失败
*/
API_EXPORT mk_decoder API_CALL mk_decoder_create2(mk_track track, int thread_num, const char *codec_name_list[]);
2022-05-25 15:38:32 +08:00
/**
*
* @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);
API_EXPORT void API_CALL mk_decoder_set_cb2(mk_decoder ctx, on_mk_decode cb, void *user_data, on_user_data_free user_data_free);
2022-05-25 15:38:32 +08:00
/**
* 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);
2023-02-11 11:35:37 +08:00
/**
* mk_frame_pix对象
* @param plane_data , mk_buffer_get_data获取其数据指针
* @param line_size line size
* @param plane
* @return mk_frame_pix对象
*/
API_EXPORT mk_frame_pix API_CALL mk_frame_pix_from_buffer(mk_buffer plane_data[], int line_size[], int plane);
2022-05-25 15:38:32 +08:00
/**
* 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);
/////////////////////////////////////////////////////////////////////////////////////////////
2023-02-11 11:35:37 +08:00
API_EXPORT uint8_t **API_CALL mk_get_av_frame_data(AVFrame *frame);
API_EXPORT void API_CALL mk_set_av_frame_data(AVFrame *frame, uint8_t *data, int plane);
API_EXPORT int *API_CALL mk_get_av_frame_line_size(AVFrame *frame);
API_EXPORT void API_CALL mk_set_av_frame_line_size(AVFrame *frame, int line_size, int plane);
2022-05-25 15:38:32 +08:00
API_EXPORT int64_t API_CALL mk_get_av_frame_dts(AVFrame *frame);
2023-02-11 11:35:37 +08:00
API_EXPORT void API_CALL mk_set_av_frame_dts(AVFrame *frame, int64_t dts);
2022-05-25 15:38:32 +08:00
API_EXPORT int64_t API_CALL mk_get_av_frame_pts(AVFrame *frame);
2023-02-11 11:35:37 +08:00
API_EXPORT void API_CALL mk_set_av_frame_pts(AVFrame *frame, int64_t pts);
2022-05-25 15:38:32 +08:00
API_EXPORT int API_CALL mk_get_av_frame_width(AVFrame *frame);
2023-02-11 11:35:37 +08:00
API_EXPORT void API_CALL mk_set_av_frame_width(AVFrame *frame, int width);
2022-05-25 15:38:32 +08:00
API_EXPORT int API_CALL mk_get_av_frame_height(AVFrame *frame);
2023-02-11 11:35:37 +08:00
API_EXPORT void API_CALL mk_set_av_frame_height(AVFrame *frame, int height);
2022-05-25 15:38:32 +08:00
API_EXPORT int API_CALL mk_get_av_frame_format(AVFrame *frame);
2023-02-11 11:35:37 +08:00
API_EXPORT void API_CALL mk_set_av_frame_format(AVFrame *frame, int format);
2022-05-25 15:38:32 +08:00
#ifdef __cplusplus
}
#endif
#endif //ZLMEDIAKIT_MK_TRANSCODE_H