You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mk_frame.h 3.4KB

8 maanden geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
  3. *
  4. * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
  5. *
  6. * Use of this source code is governed by MIT license that can be found in the
  7. * LICENSE file in the root of the source tree. All contributing project authors
  8. * may be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef ZLMEDIAKIT_MK_FRAME_H
  11. #define ZLMEDIAKIT_MK_FRAME_H
  12. #include "mk_common.h"
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. //是否为关键帧
  17. #define MK_FRAME_FLAG_IS_KEY (1 << 0)
  18. //是否为配置帧(sps/pps/vps等)
  19. #define MK_FRAME_FLAG_IS_CONFIG (1 << 1)
  20. //是否可丢弃的帧(sei/aud)
  21. #define MK_FRAME_FLAG_DROP_ABLE (1 << 2)
  22. //是否不可单独解码的帧(多slice的非vcl帧)
  23. #define MK_FRAME_FLAG_NOT_DECODE_ABLE (1 << 3)
  24. //codec id常量定义
  25. API_EXPORT extern const int MKCodecH264;
  26. API_EXPORT extern const int MKCodecH265;
  27. API_EXPORT extern const int MKCodecAAC;
  28. API_EXPORT extern const int MKCodecG711A;
  29. API_EXPORT extern const int MKCodecG711U;
  30. API_EXPORT extern const int MKCodecOpus;
  31. API_EXPORT extern const int MKCodecL16;
  32. API_EXPORT extern const int MKCodecVP8;
  33. API_EXPORT extern const int MKCodecVP9;
  34. API_EXPORT extern const int MKCodecAV1;
  35. API_EXPORT extern const int MKCodecJPEG;
  36. typedef void *mk_frame;
  37. // 用户自定义free回调函数
  38. typedef void(API_CALL *on_mk_frame_data_release)(void *user_data, char *ptr);
  39. /**
  40. * 创建frame对象,并返回其引用
  41. * @param codec_id 编解码类型,请参考MKCodecXXX定义
  42. * @param dts 解码时间戳,单位毫秒
  43. * @param pts 显示时间戳,单位毫秒
  44. * @param data 单帧数据
  45. * @param size 单帧数据长度
  46. * @param cb data指针free释放回调, 如果为空,内部会拷贝数据
  47. * @param user_data data指针free释放回调用户指针
  48. * @return frame对象引用
  49. */
  50. API_EXPORT mk_frame API_CALL mk_frame_create(int codec_id, uint64_t dts, uint64_t pts, const char *data, size_t size,
  51. on_mk_frame_data_release cb, void *user_data);
  52. /**
  53. * 减引用frame对象
  54. * @param frame 帧对象引用
  55. */
  56. API_EXPORT void API_CALL mk_frame_unref(mk_frame frame);
  57. /**
  58. * 引用frame对象
  59. * @param frame 被引用的frame对象
  60. * @return 新的对象引用
  61. */
  62. API_EXPORT mk_frame API_CALL mk_frame_ref(mk_frame frame);
  63. /**
  64. * 获取frame 编码codec类型,请参考MKCodecXXX定义
  65. */
  66. API_EXPORT int API_CALL mk_frame_codec_id(mk_frame frame);
  67. /**
  68. * 获取帧编码codec名称
  69. */
  70. API_EXPORT const char* API_CALL mk_frame_codec_name(mk_frame frame);
  71. /**
  72. * 帧是否为视频
  73. */
  74. API_EXPORT int API_CALL mk_frame_is_video(mk_frame frame);
  75. /**
  76. * 获取帧数据指针
  77. */
  78. API_EXPORT const char* API_CALL mk_frame_get_data(mk_frame frame);
  79. /**
  80. * 获取帧数据指针长度
  81. */
  82. API_EXPORT size_t API_CALL mk_frame_get_data_size(mk_frame frame);
  83. /**
  84. * 返回帧数据前缀长度,譬如H264/H265前缀一般是0x00 00 00 01,那么本函数返回4
  85. */
  86. API_EXPORT size_t API_CALL mk_frame_get_data_prefix_size(mk_frame frame);
  87. /**
  88. * 获取解码时间戳,单位毫秒
  89. */
  90. API_EXPORT uint64_t API_CALL mk_frame_get_dts(mk_frame frame);
  91. /**
  92. * 获取显示时间戳,单位毫秒
  93. */
  94. API_EXPORT uint64_t API_CALL mk_frame_get_pts(mk_frame frame);
  95. /**
  96. * 获取帧flag,请参考 MK_FRAME_FLAG
  97. */
  98. API_EXPORT uint32_t API_CALL mk_frame_get_flags(mk_frame frame);
  99. #ifdef __cplusplus
  100. }
  101. #endif
  102. #endif //ZLMEDIAKIT_MK_FRAME_H