ZLMediaKit/api/include/mk_frame.h

227 lines
6.9 KiB
C++
Raw Permalink 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_FRAME_H
#define ZLMEDIAKIT_MK_FRAME_H
#include "mk_common.h"
#ifdef __cplusplus
extern "C" {
#endif
//是否为关键帧
#define MK_FRAME_FLAG_IS_KEY (1 << 0)
//是否为配置帧(sps/pps/vps等)
#define MK_FRAME_FLAG_IS_CONFIG (1 << 1)
//是否可丢弃的帧(sei/aud)
#define MK_FRAME_FLAG_DROP_ABLE (1 << 2)
//是否不可单独解码的帧(多slice的非vcl帧)
#define MK_FRAME_FLAG_NOT_DECODE_ABLE (1 << 3)
//codec id常量定义
API_EXPORT extern const int MKCodecH264;
API_EXPORT extern const int MKCodecH265;
API_EXPORT extern const int MKCodecAAC;
API_EXPORT extern const int MKCodecG711A;
API_EXPORT extern const int MKCodecG711U;
API_EXPORT extern const int MKCodecOpus;
API_EXPORT extern const int MKCodecL16;
API_EXPORT extern const int MKCodecVP8;
API_EXPORT extern const int MKCodecVP9;
API_EXPORT extern const int MKCodecAV1;
API_EXPORT extern const int MKCodecJPEG;
typedef struct mk_frame_t *mk_frame;
2022-05-25 15:38:32 +08:00
// 用户自定义free回调函数
typedef void(API_CALL *on_mk_frame_data_release)(void *user_data, char *ptr);
/**
* frame对象
* @param codec_id MKCodecXXX定义
* @param dts
* @param pts
* @param data
* @param size
* @param cb data指针free释放回调,
* @param user_data data指针free释放回调用户指针
* @return frame对象引用
*/
2022-08-08 17:13:39 +08:00
API_EXPORT mk_frame API_CALL mk_frame_create(int codec_id, uint64_t dts, uint64_t pts, const char *data, size_t size,
2022-05-25 15:38:32 +08:00
on_mk_frame_data_release cb, void *user_data);
API_EXPORT mk_frame API_CALL mk_frame_create2(int codec_id, uint64_t dts, uint64_t pts, const char *data, size_t size,
on_mk_frame_data_release cb, void *user_data, on_user_data_free user_data_free);
2022-05-25 15:38:32 +08:00
/**
* frame对象
* @param frame
*/
API_EXPORT void API_CALL mk_frame_unref(mk_frame frame);
/**
* frame对象
* @param frame frame对象
* @return
*/
API_EXPORT mk_frame API_CALL mk_frame_ref(mk_frame frame);
/**
* frame codec类型MKCodecXXX定义
*/
API_EXPORT int API_CALL mk_frame_codec_id(mk_frame frame);
/**
* codec名称
*/
API_EXPORT const char* API_CALL mk_frame_codec_name(mk_frame frame);
/**
*
*/
API_EXPORT int API_CALL mk_frame_is_video(mk_frame frame);
/**
*
*/
API_EXPORT const char* API_CALL mk_frame_get_data(mk_frame frame);
/**
*
*/
API_EXPORT size_t API_CALL mk_frame_get_data_size(mk_frame frame);
/**
* H264/H265前缀一般是0x00 00 00 01,4
*/
API_EXPORT size_t API_CALL mk_frame_get_data_prefix_size(mk_frame frame);
/**
*
*/
2022-08-08 17:13:39 +08:00
API_EXPORT uint64_t API_CALL mk_frame_get_dts(mk_frame frame);
2022-05-25 15:38:32 +08:00
/**
*
*/
2022-08-08 17:13:39 +08:00
API_EXPORT uint64_t API_CALL mk_frame_get_pts(mk_frame frame);
2022-05-25 15:38:32 +08:00
/**
* flag MK_FRAME_FLAG
*/
API_EXPORT uint32_t API_CALL mk_frame_get_flags(mk_frame frame);
2023-07-02 12:25:30 +08:00
//////////////////////////////////////////////////////////////////////
typedef struct mk_buffer_t *mk_buffer;
typedef struct mk_frame_merger_t *mk_frame_merger;
/**
*
* @param type 0: none, 1: h264_prefix/AnnexB(0x 00 00 00 01), 2: mp4_nal_size(avcC)
* @return
*/
API_EXPORT mk_frame_merger API_CALL mk_frame_merger_create(int type);
/**
*
* @param ctx
*/
API_EXPORT void API_CALL mk_frame_merger_release(mk_frame_merger ctx);
/**
* merger对象缓冲便
* @param ctx
*/
API_EXPORT void API_CALL mk_frame_merger_clear(mk_frame_merger ctx);
/**
*
* @param user_data
* @param dts
* @param pts
* @param buffer buffer对象
* @param have_key_frame
*/
typedef void(API_CALL *on_mk_frame_merger)(void *user_data, uint64_t dts, uint64_t pts, mk_buffer buffer, int have_key_frame);
/**
* frame到merger对象并合并
* @param ctx
* @param frame
* @param cb
* @param user_data
*/
API_EXPORT void API_CALL mk_frame_merger_input(mk_frame_merger ctx, mk_frame frame, on_mk_frame_merger cb, void *user_data);
/**
* flush merger对象缓冲api前需要确保先调用mk_frame_merger_input函数并且回调参数有效
* @param ctx
*/
API_EXPORT void API_CALL mk_frame_merger_flush(mk_frame_merger ctx);
//////////////////////////////////////////////////////////////////////
typedef struct mk_mpeg_muxer_t *mk_mpeg_muxer;
/**
* mpeg-ps/ts
* @param user_data
* @param muxer
* @param frame
* @param size
* @param timestamp
* @param key_pos
*/
typedef void(API_CALL *on_mk_mpeg_muxer_frame)(void *user_data, mk_mpeg_muxer muxer, const char *frame, size_t size, uint64_t timestamp, int key_pos);
/**
* mpeg-ps/ts
* @param cb
* @param user_data
* @param is_ps ps
* @return
*/
API_EXPORT mk_mpeg_muxer API_CALL mk_mpeg_muxer_create(on_mk_mpeg_muxer_frame cb, void *user_data, int is_ps);
/**
* mpeg-ps/ts
* @param ctx
*/
API_EXPORT void API_CALL mk_mpeg_muxer_release(mk_mpeg_muxer ctx);
/**
* track
* @param ctx mk_mpeg_muxer对象
* @param track mk_track对象
*/
API_EXPORT void API_CALL mk_mpeg_muxer_init_track(mk_mpeg_muxer ctx, void* track);
/**
* track完毕后调用此函数
* track()ZLMediaKit不知道后续是否还要添加track3
* Track类型便(3)
* @param ctx
*/
API_EXPORT void API_CALL mk_mpeg_muxer_init_complete(mk_mpeg_muxer ctx);
/**
* frame对象
* @param ctx mk_mpeg_muxer对象
* @param frame
* @return 10
*/
API_EXPORT int API_CALL mk_mpeg_muxer_input_frame(mk_mpeg_muxer ctx, mk_frame frame);
2022-05-25 15:38:32 +08:00
#ifdef __cplusplus
}
#endif
#endif //ZLMEDIAKIT_MK_FRAME_H