ZLMediaKit/api/include/mk_frame.h

351 lines
11 KiB
C++
Raw Permalink Normal View History

/*
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_FRAME_H
#define ZLMEDIAKIT_MK_FRAME_H
#include "mk_common.h"
#ifdef __cplusplus
extern "C" {
#endif
// 是否为关键帧 [AUTO-TRANSLATED:b999067c]
// cpp
2022-05-25 15:38:32 +08:00
//是否为关键帧
#define MK_FRAME_FLAG_IS_KEY (1 << 0)
// 是否为配置帧(sps/pps/vps等) [AUTO-TRANSLATED:cf504832]
// 是否为配置帧(sps/pps/vps等)
2022-05-25 15:38:32 +08:00
#define MK_FRAME_FLAG_IS_CONFIG (1 << 1)
// 是否可丢弃的帧(sei/aud) [AUTO-TRANSLATED:6481fe69]
// 是否可丢弃的帧(sei/aud)
2022-05-25 15:38:32 +08:00
#define MK_FRAME_FLAG_DROP_ABLE (1 << 2)
// 是否不可单独解码的帧(多slice的非vcl帧) [AUTO-TRANSLATED:cb4da662]
// 是否不可单独解码的帧(多slice的非vcl帧)
2022-05-25 15:38:32 +08:00
#define MK_FRAME_FLAG_NOT_DECODE_ABLE (1 << 3)
// codec id常量定义 [AUTO-TRANSLATED:dbc838b6]
// codec id常量定义
2024-07-21 20:38:41 +08:00
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;
2022-05-25 15:38:32 +08:00
typedef struct mk_frame_t *mk_frame;
2022-05-25 15:38:32 +08:00
// 用户自定义free回调函数 [AUTO-TRANSLATED:dc96ff2d]
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对象引用
* Create a frame object and return its reference.
* @param codec_id Encoding and decoding type, please refer to MKCodecXXX definition.
* @param dts Decoding timestamp, in milliseconds.
* @param pts Display timestamp, in milliseconds.
* @param data Single frame data.
* @param size Single frame data length.
* @param cb data pointer free release callback, if empty, the data will be copied internally.
* @param user_data data pointer free release callback user pointer.
* @return frame object reference.
* [AUTO-TRANSLATED:0481221b]
2022-05-25 15:38:32 +08:00
*/
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
* Decrement the reference of the frame object.
* @param frame Frame object reference.
* [AUTO-TRANSLATED:53b5a750]
2022-05-25 15:38:32 +08:00
*/
API_EXPORT void API_CALL mk_frame_unref(mk_frame frame);
/**
* frame对象
* @param frame frame对象
* @return
* Reference the frame object.
* @param frame The referenced frame object.
* @return New object reference.
* [AUTO-TRANSLATED:f772813d]
2022-05-25 15:38:32 +08:00
*/
API_EXPORT mk_frame API_CALL mk_frame_ref(mk_frame frame);
/**
* frame codec类型MKCodecXXX定义
* Get the frame encoding codec type, please refer to MKCodecXXX definition.
* [AUTO-TRANSLATED:b3a34bb8]
2022-05-25 15:38:32 +08:00
*/
API_EXPORT int API_CALL mk_frame_codec_id(mk_frame frame);
/**
* codec名称
* Get the frame encoding codec name.
* [AUTO-TRANSLATED:6c3129d7]
2022-05-25 15:38:32 +08:00
*/
API_EXPORT const char* API_CALL mk_frame_codec_name(mk_frame frame);
/**
*
* Whether the frame is video.
* [AUTO-TRANSLATED:c43dbd4e]
2022-05-25 15:38:32 +08:00
*/
API_EXPORT int API_CALL mk_frame_is_video(mk_frame frame);
/**
*
* Get the frame data pointer.
* [AUTO-TRANSLATED:bf454f3b]
2022-05-25 15:38:32 +08:00
*/
API_EXPORT const char* API_CALL mk_frame_get_data(mk_frame frame);
/**
*
* Get the length of the frame data pointer.
* [AUTO-TRANSLATED:8a76acf2]
2022-05-25 15:38:32 +08:00
*/
API_EXPORT size_t API_CALL mk_frame_get_data_size(mk_frame frame);
/**
* H264/H265前缀一般是0x00 00 00 01,4
* Return the length of the frame data prefix, for example, the H264/H265 prefix is generally 0x00 00 00 01, then this function returns 4.
* [AUTO-TRANSLATED:352c7cfc]
2022-05-25 15:38:32 +08:00
*/
API_EXPORT size_t API_CALL mk_frame_get_data_prefix_size(mk_frame frame);
/**
*
* Get the decoding timestamp, in milliseconds.
* [AUTO-TRANSLATED:049f1339]
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_dts(mk_frame frame);
2022-05-25 15:38:32 +08:00
/**
*
* Get the display timestamp, in milliseconds.
* [AUTO-TRANSLATED:4ab081a7]
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
* Get the frame flag, please refer to MK_FRAME_FLAG.
* [AUTO-TRANSLATED:6fdf971c]
2022-05-25 15:38:32 +08:00
*/
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
* Create a frame merger.
* @param type Starting header type, 0: none, 1: h264_prefix/AnnexB(0x 00 00 00 01), 2: mp4_nal_size(avcC)
* @return Frame merger.
* [AUTO-TRANSLATED:385eedd7]
2023-07-02 12:25:30 +08:00
*/
API_EXPORT mk_frame_merger API_CALL mk_frame_merger_create(int type);
/**
*
* @param ctx
* Destroy the frame merger.
* @param ctx Object pointer.
* [AUTO-TRANSLATED:0c9aad7b]
2023-07-02 12:25:30 +08:00
*/
API_EXPORT void API_CALL mk_frame_merger_release(mk_frame_merger ctx);
/**
* merger对象缓冲便
* @param ctx
* Clear the merger object buffer for reuse.
* @param ctx Object pointer.
* [AUTO-TRANSLATED:6b1d2209]
2023-07-02 12:25:30 +08:00
*/
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
* Frame merging callback function.
* @param user_data User data pointer.
* @param dts Decoding timestamp.
* @param pts Display timestamp.
* @param buffer Merged data buffer object.
* @param have_key_frame Whether the merged data contains a key frame.
* [AUTO-TRANSLATED:ff78df4f]
2023-07-02 12:25:30 +08:00
*/
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
* Input frame to the merger object and merge.
* @param ctx Object pointer.
* @param frame Frame data.
* @param cb Frame merging callback function.
* @param user_data Frame merging callback function user data pointer.
* [AUTO-TRANSLATED:83aa1436]
2023-07-02 12:25:30 +08:00
*/
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
* Force flush the merger object buffer. Before calling this API, make sure to call the mk_frame_merger_input function first and the callback parameters are valid.
* @param ctx Object pointer.
* [AUTO-TRANSLATED:42bb104c]
2023-07-02 12:25:30 +08:00
*/
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
* mpeg-ps/ts packer output callback function.
* @param user_data User data pointer set during callback.
* @param muxer Object.
* @param frame Frame data.
* @param size Frame data length.
* @param timestamp Timestamp.
* @param key_pos Whether it is a key frame.
* [AUTO-TRANSLATED:14c103a2]
*/
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
* mpeg-ps/ts packer.
* @param cb Packing callback function.
* @param user_data Callback user data pointer.
* @param is_ps Whether it is ps.
* @return Packer object.
* [AUTO-TRANSLATED:6526b871]
*/
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
* Delete the mpeg-ps/ts packer.
* @param ctx Packer.
* [AUTO-TRANSLATED:0b533391]
*/
API_EXPORT void API_CALL mk_mpeg_muxer_release(mk_mpeg_muxer ctx);
/**
* track
* @param ctx mk_mpeg_muxer对象
* @param track mk_track对象
* Add audio/video track.
* @param ctx mk_mpeg_muxer object.
* @param track mk_track object, audio/video track.
* [AUTO-TRANSLATED:f2082619]
*/
API_EXPORT void API_CALL mk_mpeg_muxer_init_track(mk_mpeg_muxer ctx, void* track);
/**
* track完毕后调用此函数
* track()ZLMediaKit不知道后续是否还要添加track3
* Track类型便(3)
* @param ctx
* Call this function after the track is initialized.
* In the case of a single track (only audio or video), because ZLMediaKit does not know whether to add more tracks later, it will wait for an additional 3 seconds.
* If the generated stream is a single Track type, please call this function to speed up the stream generation. Of course, if you don't call this function, the impact is not big (it will wait for an additional 3 seconds).
* @param ctx Object pointer.
* [AUTO-TRANSLATED:f40d41cb]
*/
API_EXPORT void API_CALL mk_mpeg_muxer_init_complete(mk_mpeg_muxer ctx);
/**
* frame对象
* @param ctx mk_mpeg_muxer对象
* @param frame
* @return 10
* Input frame object.
* @param ctx mk_mpeg_muxer object.
* @param frame Frame object.
* @return 1 means success, 0 means failure.
* [AUTO-TRANSLATED:46523906]
*/
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