ZLMediaKit/api/include/mk_media.h

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

2019-12-18 11:47:49 +08:00
/*
2023-12-09 16:23:51 +08:00
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
2019-12-17 18:45:31 +08:00
*
2023-12-09 16:23:51 +08:00
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
2019-12-17 18:45:31 +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
2020-04-04 20:30:09 +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.
2019-12-17 18:45:31 +08:00
*/
#ifndef MK_MEDIA_H_
#define MK_MEDIA_H_
#include "mk_common.h"
2022-05-25 15:38:32 +08:00
#include "mk_track.h"
#include "mk_frame.h"
2020-07-02 18:14:39 +08:00
#include "mk_events_objects.h"
2022-08-27 10:17:06 +08:00
#include "mk_thread.h"
#include "mk_util.h"
2019-12-17 18:45:31 +08:00
#ifdef __cplusplus
extern "C" {
#endif
typedef struct mk_media_t *mk_media;
2019-12-17 18:45:31 +08:00
/**
*
2019-12-18 14:43:32 +08:00
* @param vhost __defaultVhost__
2019-12-17 18:45:31 +08:00
* @param app live
* @param stream idcamera
* @param duration ()0
* @param hls_enabled hls
* @param mp4_enabled mp4
* @return
*/
2020-09-20 09:26:00 +08:00
API_EXPORT mk_media API_CALL mk_media_create(const char *vhost, const char *app, const char *stream,
float duration, int hls_enabled, int mp4_enabled);
2019-12-17 18:45:31 +08:00
/**
*
* @param vhost __defaultVhost__
* @param app live
* @param stream idcamera
* @param duration ()0
* @param option ProtocolOption相关配置
* @return
*/
API_EXPORT mk_media API_CALL mk_media_create2(const char *vhost, const char *app, const char *stream, float duration, mk_ini option);
2019-12-17 18:45:31 +08:00
/**
*
* @param ctx
*/
API_EXPORT void API_CALL mk_media_release(mk_media ctx);
/**
2022-05-25 15:38:32 +08:00
* track
* @param ctx mk_media对象
* @param track mk_track对象
*/
API_EXPORT void API_CALL mk_media_init_track(mk_media ctx, mk_track track);
/**
* mk_media_init_track方法
2019-12-17 18:45:31 +08:00
* @param ctx
2021-02-02 15:11:16 +08:00
* @param codec_id 0:CodecH264/1:CodecH265
2022-05-25 15:38:32 +08:00
* @param width ;
* @param height ;
* @param fps fps;
* @param bit_rate ,bps;
2019-12-17 18:45:31 +08:00
* @param width
* @param height
* @param fps fps
2021-09-27 14:34:26 +08:00
* @return 10
2019-12-17 18:45:31 +08:00
*/
2022-05-25 15:38:32 +08:00
API_EXPORT int API_CALL mk_media_init_video(mk_media ctx, int codec_id, int width, int height, float fps, int bit_rate);
2019-12-17 18:45:31 +08:00
/**
2022-05-25 15:38:32 +08:00
* mk_media_init_track方法
2019-12-17 18:45:31 +08:00
* @param ctx
2021-02-02 15:11:16 +08:00
* @param codec_id 2:CodecAAC/3:CodecG711A/4:CodecG711U/5:OPUS
* @param channel
* @param sample_bit 16
* @param sample_rate
2021-09-27 14:34:26 +08:00
* @return 10
*/
2021-09-27 14:34:26 +08:00
API_EXPORT int API_CALL mk_media_init_audio(mk_media ctx, int codec_id, int sample_rate, int channels, int sample_bit);
2020-02-27 11:40:38 +08:00
/**
* h264/h265/aac完毕后调用此函数
* track()ZLMediaKit不知道后续是否还要添加track3
* Track类型便(3)
* @param ctx
*/
API_EXPORT void API_CALL mk_media_init_complete(mk_media ctx);
2019-12-17 18:45:31 +08:00
/**
2022-05-25 15:38:32 +08:00
* frame对象
* @param ctx mk_media对象
* @param frame
* @return 10
*/
API_EXPORT int API_CALL mk_media_input_frame(mk_media ctx, mk_frame frame);
/**
* H264视频00 00 01,00 00 00 01mk_media_input_frame方法
2019-12-17 18:45:31 +08:00
* @param ctx
* @param data H264数据
* @param len H264数据字节数
* @param dts
2020-01-09 17:17:48 +08:00
* @param pts
2021-09-27 14:34:26 +08:00
* @return 10
2019-12-17 18:45:31 +08:00
*/
2022-08-08 17:13:39 +08:00
API_EXPORT int API_CALL mk_media_input_h264(mk_media ctx, const void *data, int len, uint64_t dts, uint64_t pts);
2019-12-17 18:45:31 +08:00
/**
2022-05-25 15:38:32 +08:00
* H265视频00 00 01,00 00 00 01mk_media_input_frame方法
2019-12-17 18:45:31 +08:00
* @param ctx
* @param data H265数据
* @param len H265数据字节数
* @param dts
2020-01-09 17:17:48 +08:00
* @param pts
2021-09-27 14:34:26 +08:00
* @return 10
2019-12-17 18:45:31 +08:00
*/
2022-08-08 17:13:39 +08:00
API_EXPORT int API_CALL mk_media_input_h265(mk_media ctx, const void *data, int len, uint64_t dts, uint64_t pts);
2019-12-17 18:45:31 +08:00
/**
2022-05-25 15:38:32 +08:00
* YUV视频数据
* @param ctx
* @param yuv yuv420p数据
* @param linesize yuv420p linesize
* @param cts
*/
2022-08-08 17:13:39 +08:00
API_EXPORT void API_CALL mk_media_input_yuv(mk_media ctx, const char *yuv[3], int linesize[3], uint64_t cts);
2022-05-25 15:38:32 +08:00
/**
* AAC音频(adts头)mk_media_input_frame方法
2019-12-17 18:45:31 +08:00
* @param ctx
* @param data adts头的单帧AAC数据adts头7个字节
2019-12-17 18:45:31 +08:00
* @param len AAC数据字节数
* @param dts
2020-08-01 10:22:12 +08:00
* @param adts adts头null
2021-09-27 14:34:26 +08:00
* @return 10
2019-12-17 18:45:31 +08:00
*/
2022-08-08 17:13:39 +08:00
API_EXPORT int API_CALL mk_media_input_aac(mk_media ctx, const void *data, int len, uint64_t dts, void *adts);
2019-12-17 18:45:31 +08:00
/**
2020-06-24 11:18:04 +08:00
* PCM音频,ENABLE_FAAC编译时
* @param ctx
* @param data PCM数据
* @param len PCM数据字节数
* @param dts
2021-09-27 14:34:26 +08:00
* @return 10
*/
2022-08-08 17:13:39 +08:00
API_EXPORT int API_CALL mk_media_input_pcm(mk_media ctx, void *data, int len, uint64_t pts);
2020-06-24 11:18:04 +08:00
/**
2022-05-25 15:38:32 +08:00
* OPUS/G711音频帧mk_media_input_frame方法
* @param ctx
2020-08-01 10:22:12 +08:00
* @param data
* @param len
* @param dts
2021-09-27 14:34:26 +08:00
* @return 10
*/
2022-08-08 17:13:39 +08:00
API_EXPORT int API_CALL mk_media_input_audio(mk_media ctx, const void* data, int len, uint64_t dts);
2020-02-28 17:53:21 +08:00
/**
2020-03-10 22:55:19 +08:00
* MediaSource.close()
* MediaSource时
* mk_media_release函数并且释放其他资源
* mk_media_release函数MediaSource.close()
2020-02-28 17:53:21 +08:00
* @param user_data mk_media_set_on_close函数设置
*/
2020-03-10 22:55:19 +08:00
typedef void(API_CALL *on_mk_media_close)(void *user_data);
2020-02-28 17:53:21 +08:00
/**
* MediaSource.close()
2020-03-10 22:55:19 +08:00
* MediaSource时
* mk_media_release函数并且释放其他资源
2020-02-28 17:53:21 +08:00
* @param ctx
* @param cb
* @param user_data
*/
API_EXPORT void API_CALL mk_media_set_on_close(mk_media ctx, on_mk_media_close cb, void *user_data);
API_EXPORT void API_CALL mk_media_set_on_close2(mk_media ctx, on_mk_media_close cb, void *user_data, on_user_data_free user_data_free);
2020-02-28 17:53:21 +08:00
2020-04-02 10:31:33 +08:00
/**
* seek请求时触发该回调
* @param user_data ,mk_media_set_on_seek设置
* @param stamp_ms seek至的时间轴位置
* @return 1seek请求0
*/
typedef int(API_CALL *on_mk_media_seek)(void *user_data,uint32_t stamp_ms);
/**
2021-08-12 16:07:31 +08:00
* pause或resume请求时触发该回调
* @param user_data ,mk_media_set_on_pause设置
2021-08-12 16:07:31 +08:00
* @param pause 1:, 0:
*/
2021-08-12 16:07:31 +08:00
typedef int(API_CALL* on_mk_media_pause)(void* user_data, int pause);
/**
* speed请求时触发该回调
* @param user_data ,mk_media_set_on_pause设置
* @param speed 0.5 1.0 2.0
*/
typedef int(API_CALL* on_mk_media_speed)(void* user_data, float speed);
2020-04-02 10:31:33 +08:00
/**
* seek请求事件
* @param ctx
* @param cb
* @param user_data
*/
API_EXPORT void API_CALL mk_media_set_on_seek(mk_media ctx, on_mk_media_seek cb, void *user_data);
API_EXPORT void API_CALL mk_media_set_on_seek2(mk_media ctx, on_mk_media_seek cb, void *user_data, on_user_data_free user_data_free);
2020-04-02 10:31:33 +08:00
/**
* pause请求事件
* @param ctx
* @param cb
* @param user_data
*/
API_EXPORT void API_CALL mk_media_set_on_pause(mk_media ctx, on_mk_media_pause cb, void *user_data);
API_EXPORT void API_CALL mk_media_set_on_pause2(mk_media ctx, on_mk_media_pause cb, void *user_data, on_user_data_free user_data_free);
/**
* pause请求事件
* @param ctx
* @param cb
* @param user_data
*/
API_EXPORT void API_CALL mk_media_set_on_speed(mk_media ctx, on_mk_media_speed cb, void *user_data);
API_EXPORT void API_CALL mk_media_set_on_speed2(mk_media ctx, on_mk_media_speed cb, void *user_data, on_user_data_free user_data_free);
2020-02-28 17:53:21 +08:00
/**
*
* @param ctx
* @return
*/
API_EXPORT int API_CALL mk_media_total_reader_count(mk_media ctx);
2020-07-02 18:14:39 +08:00
/**
* MediaSource注册或注销事件
* @param user_data
* @param sender MediaSource对象
* @param regist 10
*/
typedef void(API_CALL *on_mk_media_source_regist)(void *user_data, mk_media_source sender, int regist);
/**
* MediaSource注册或注销事件回调函数
* @param ctx
* @param cb
* @param user_data
*/
API_EXPORT void API_CALL mk_media_set_on_regist(mk_media ctx, on_mk_media_source_regist cb, void *user_data);
API_EXPORT void API_CALL mk_media_set_on_regist2(mk_media ctx, on_mk_media_source_regist cb, void *user_data, on_user_data_free user_data_free);
2020-07-02 18:14:39 +08:00
2020-11-21 22:13:08 +08:00
/**
* rtp推流成功与否的回调()
*/
typedef on_mk_media_source_send_rtp_result on_mk_media_send_rtp_result;
/**
2022-08-27 10:17:06 +08:00
* ps-rtp流(ssrc区分多路)api线程安全
2020-11-21 22:13:08 +08:00
* @param ctx
* @param dst_url ip或域名
* @param dst_port
* @param ssrc rtp的ssrc10
* @param is_udp udp
* @param cb
* @param user_data
*/
API_EXPORT void API_CALL mk_media_start_send_rtp(mk_media ctx, const char *dst_url, uint16_t dst_port, const char *ssrc, int is_udp, on_mk_media_send_rtp_result cb, void *user_data);
API_EXPORT void API_CALL mk_media_start_send_rtp2(mk_media ctx, const char *dst_url, uint16_t dst_port, const char *ssrc, int is_udp, on_mk_media_send_rtp_result cb, void *user_data, on_user_data_free user_data_free);
2020-11-21 22:13:08 +08:00
/**
2022-08-27 10:17:06 +08:00
* ps-rtp发送api线程安全
2020-11-21 22:13:08 +08:00
* @param ctx
* @param ssrc rtp的ssrc10null或空字符串rtp推流
2020-11-21 22:13:08 +08:00
*/
2022-08-27 10:17:06 +08:00
API_EXPORT void API_CALL mk_media_stop_send_rtp(mk_media ctx, const char *ssrc);
/**
* 线
* @param ctx
*/
API_EXPORT mk_thread API_CALL mk_media_get_owner_thread(mk_media ctx);
2020-11-21 22:13:08 +08:00
2019-12-17 18:45:31 +08:00
#ifdef __cplusplus
}
#endif
#endif /* MK_MEDIA_H_ */