2020-08-01 10:22:12 +08:00
|
|
|
|
/*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
2017-09-27 16:20:30 +08:00
|
|
|
|
*
|
2021-01-17 18:31:50 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
2017-09-27 16:20:30 +08:00
|
|
|
|
*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* 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.
|
2017-09-27 16:20:30 +08:00
|
|
|
|
*/
|
2020-04-04 20:30:09 +08:00
|
|
|
|
|
2017-04-01 16:35:56 +08:00
|
|
|
|
#ifndef __rtmp_h
|
|
|
|
|
|
#define __rtmp_h
|
|
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
2017-04-25 11:35:41 +08:00
|
|
|
|
#include <string>
|
2019-01-16 14:26:06 +08:00
|
|
|
|
#include <cstdlib>
|
2019-06-28 17:25:53 +08:00
|
|
|
|
#include "amf.h"
|
2022-11-29 11:07:13 +08:00
|
|
|
|
#include "Network/Buffer.h"
|
2019-06-28 17:25:53 +08:00
|
|
|
|
#include "Extension/Track.h"
|
|
|
|
|
|
|
2020-08-30 10:48:34 +08:00
|
|
|
|
#define DEFAULT_CHUNK_LEN 128
|
2017-04-01 16:35:56 +08:00
|
|
|
|
#define HANDSHAKE_PLAINTEXT 0x03
|
|
|
|
|
|
#define RANDOM_LEN (1536 - 8)
|
|
|
|
|
|
|
|
|
|
|
|
#define MSG_SET_CHUNK 1 /*Set Chunk Size (1)*/
|
|
|
|
|
|
#define MSG_ABORT 2 /*Abort Message (2)*/
|
|
|
|
|
|
#define MSG_ACK 3 /*Acknowledgement (3)*/
|
|
|
|
|
|
#define MSG_USER_CONTROL 4 /*User Control Messages (4)*/
|
|
|
|
|
|
#define MSG_WIN_SIZE 5 /*Window Acknowledgement Size (5)*/
|
|
|
|
|
|
#define MSG_SET_PEER_BW 6 /*Set Peer Bandwidth (6)*/
|
|
|
|
|
|
#define MSG_AUDIO 8 /*Audio Message (8)*/
|
|
|
|
|
|
#define MSG_VIDEO 9 /*Video Message (9)*/
|
|
|
|
|
|
#define MSG_DATA 18 /*Data Message (18, 15) AMF0*/
|
|
|
|
|
|
#define MSG_DATA3 15 /*Data Message (18, 15) AMF3*/
|
|
|
|
|
|
#define MSG_CMD 20 /*Command Message AMF0 */
|
|
|
|
|
|
#define MSG_CMD3 17 /*Command Message AMF3 */
|
|
|
|
|
|
#define MSG_OBJECT3 16 /*Shared Object Message (19, 16) AMF3*/
|
|
|
|
|
|
#define MSG_OBJECT 19 /*Shared Object Message (19, 16) AMF0*/
|
|
|
|
|
|
#define MSG_AGGREGATE 22 /*Aggregate Message (22)*/
|
|
|
|
|
|
|
|
|
|
|
|
#define CONTROL_STREAM_BEGIN 0
|
|
|
|
|
|
#define CONTROL_STREAM_EOF 1
|
|
|
|
|
|
#define CONTROL_STREAM_DRY 2
|
|
|
|
|
|
#define CONTROL_SETBUFFER 3
|
|
|
|
|
|
#define CONTROL_STREAM_ISRECORDED 4
|
|
|
|
|
|
#define CONTROL_PING_REQUEST 6
|
|
|
|
|
|
#define CONTROL_PING_RESPONSE 7
|
|
|
|
|
|
|
|
|
|
|
|
#define STREAM_CONTROL 0
|
|
|
|
|
|
#define STREAM_MEDIA 1
|
|
|
|
|
|
|
2021-09-29 16:57:19 +08:00
|
|
|
|
#define CHUNK_NETWORK 2 /*网络相关的消息(参见 Protocol Control Messages)*/
|
|
|
|
|
|
#define CHUNK_SYSTEM 3 /*向服务器发送控制消息(反之亦可)*/
|
2017-04-01 16:35:56 +08:00
|
|
|
|
#define CHUNK_CLIENT_REQUEST_BEFORE 3 /*客户端在createStream前,向服务器发出请求的chunkID*/
|
|
|
|
|
|
#define CHUNK_CLIENT_REQUEST_AFTER 4 /*客户端在createStream后,向服务器发出请求的chunkID*/
|
2017-05-27 11:26:49 +08:00
|
|
|
|
#define CHUNK_AUDIO 6 /*音频chunkID*/
|
|
|
|
|
|
#define CHUNK_VIDEO 7 /*视频chunkID*/
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
2019-03-27 18:41:52 +08:00
|
|
|
|
namespace mediakit {
|
2017-08-09 18:39:30 +08:00
|
|
|
|
|
|
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
|
|
|
2017-04-01 16:35:56 +08:00
|
|
|
|
class RtmpHandshake {
|
|
|
|
|
|
public:
|
2022-11-29 11:07:13 +08:00
|
|
|
|
RtmpHandshake(uint32_t _time, uint8_t *_random = nullptr);
|
2020-08-30 10:48:34 +08:00
|
|
|
|
|
|
|
|
|
|
uint8_t time_stamp[4];
|
2017-05-13 17:25:31 +08:00
|
|
|
|
uint8_t zero[4] = {0};
|
2017-04-01 16:35:56 +08:00
|
|
|
|
uint8_t random[RANDOM_LEN];
|
2020-08-30 10:48:34 +08:00
|
|
|
|
|
2022-11-29 11:07:13 +08:00
|
|
|
|
void random_generate(char *bytes, int size);
|
2021-12-22 22:06:19 +08:00
|
|
|
|
|
|
|
|
|
|
void create_complex_c0c1();
|
|
|
|
|
|
|
2023-07-29 13:07:22 +08:00
|
|
|
|
};
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
|
|
|
|
|
class RtmpHeader {
|
|
|
|
|
|
public:
|
2021-06-22 10:39:16 +08:00
|
|
|
|
#if __BYTE_ORDER == __BIG_ENDIAN
|
|
|
|
|
|
uint8_t fmt : 2;
|
|
|
|
|
|
uint8_t chunk_id : 6;
|
|
|
|
|
|
#else
|
|
|
|
|
|
uint8_t chunk_id : 6;
|
|
|
|
|
|
//0、1、2、3分别对应 12、8、4、1长度
|
|
|
|
|
|
uint8_t fmt : 2;
|
|
|
|
|
|
#endif
|
2020-08-30 10:48:34 +08:00
|
|
|
|
uint8_t time_stamp[3];
|
|
|
|
|
|
uint8_t body_size[3];
|
|
|
|
|
|
uint8_t type_id;
|
|
|
|
|
|
uint8_t stream_index[4]; /* Note, this is little-endian while others are BE */
|
2023-07-29 13:07:22 +08:00
|
|
|
|
};
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
2021-07-15 11:16:11 +08:00
|
|
|
|
class FLVHeader {
|
|
|
|
|
|
public:
|
2023-06-17 10:29:27 +08:00
|
|
|
|
static constexpr uint8_t kFlvVersion = 1;
|
|
|
|
|
|
static constexpr uint8_t kFlvHeaderLength = 9;
|
2021-07-15 11:16:11 +08:00
|
|
|
|
//FLV
|
|
|
|
|
|
char flv[3];
|
|
|
|
|
|
//File version (for example, 0x01 for FLV version 1)
|
|
|
|
|
|
uint8_t version;
|
|
|
|
|
|
#if __BYTE_ORDER == __BIG_ENDIAN
|
|
|
|
|
|
//保留,置0
|
|
|
|
|
|
uint8_t : 5;
|
|
|
|
|
|
//是否有音频
|
|
|
|
|
|
uint8_t have_audio: 1;
|
|
|
|
|
|
//保留,置0
|
|
|
|
|
|
uint8_t : 1;
|
|
|
|
|
|
//是否有视频
|
|
|
|
|
|
uint8_t have_video: 1;
|
|
|
|
|
|
#else
|
|
|
|
|
|
//是否有视频
|
|
|
|
|
|
uint8_t have_video: 1;
|
|
|
|
|
|
//保留,置0
|
|
|
|
|
|
uint8_t : 1;
|
|
|
|
|
|
//是否有音频
|
|
|
|
|
|
uint8_t have_audio: 1;
|
|
|
|
|
|
//保留,置0
|
|
|
|
|
|
uint8_t : 5;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
//The length of this header in bytes,固定为9
|
|
|
|
|
|
uint32_t length;
|
2023-06-17 10:29:27 +08:00
|
|
|
|
//固定为0
|
|
|
|
|
|
uint32_t previous_tag_size0;
|
2023-07-29 13:07:22 +08:00
|
|
|
|
};
|
2021-07-15 11:16:11 +08:00
|
|
|
|
|
|
|
|
|
|
class RtmpTagHeader {
|
|
|
|
|
|
public:
|
|
|
|
|
|
uint8_t type = 0;
|
|
|
|
|
|
uint8_t data_size[3] = {0};
|
|
|
|
|
|
uint8_t timestamp[3] = {0};
|
|
|
|
|
|
uint8_t timestamp_ex = 0;
|
|
|
|
|
|
uint8_t streamid[3] = {0}; /* Always 0. */
|
2023-07-29 13:07:22 +08:00
|
|
|
|
};
|
2021-07-15 11:16:11 +08:00
|
|
|
|
|
2017-08-09 18:39:30 +08:00
|
|
|
|
#pragma pack(pop)
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
2022-02-02 20:34:50 +08:00
|
|
|
|
class RtmpPacket : public toolkit::Buffer{
|
2017-04-01 16:35:56 +08:00
|
|
|
|
public:
|
2021-02-07 23:01:22 +08:00
|
|
|
|
friend class RtmpProtocol;
|
2021-02-04 17:58:51 +08:00
|
|
|
|
using Ptr = std::shared_ptr<RtmpPacket>;
|
|
|
|
|
|
bool is_abs_stamp;
|
2020-08-30 10:48:34 +08:00
|
|
|
|
uint8_t type_id;
|
2021-02-04 17:58:51 +08:00
|
|
|
|
uint32_t time_stamp;
|
|
|
|
|
|
uint32_t ts_field;
|
2020-08-30 10:48:34 +08:00
|
|
|
|
uint32_t stream_index;
|
|
|
|
|
|
uint32_t chunk_id;
|
2021-02-04 17:58:51 +08:00
|
|
|
|
size_t body_size;
|
2022-02-02 20:34:50 +08:00
|
|
|
|
toolkit::BufferLikeString buffer;
|
2020-08-30 10:48:34 +08:00
|
|
|
|
|
2019-03-22 14:37:03 +08:00
|
|
|
|
public:
|
2021-02-04 17:58:51 +08:00
|
|
|
|
static Ptr create();
|
|
|
|
|
|
|
2019-03-22 14:37:03 +08:00
|
|
|
|
char *data() const override{
|
2020-08-30 10:48:34 +08:00
|
|
|
|
return (char*)buffer.data();
|
2019-03-22 14:37:03 +08:00
|
|
|
|
}
|
2021-01-17 18:31:50 +08:00
|
|
|
|
size_t size() const override {
|
2020-08-30 10:48:34 +08:00
|
|
|
|
return buffer.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-29 11:07:13 +08:00
|
|
|
|
void clear();
|
2023-07-22 19:40:28 +08:00
|
|
|
|
|
2023-07-22 19:32:01 +08:00
|
|
|
|
// video config frame和key frame都返回true
|
2023-07-22 19:40:28 +08:00
|
|
|
|
// 用于gop缓存定位
|
2022-11-29 11:07:13 +08:00
|
|
|
|
bool isVideoKeyFrame() const;
|
2023-07-22 19:40:28 +08:00
|
|
|
|
|
|
|
|
|
|
// aac config或h264/h265 config返回true,支持增强型rtmp
|
|
|
|
|
|
// 用于缓存解码配置信息
|
|
|
|
|
|
bool isConfigFrame() const;
|
|
|
|
|
|
|
2023-07-22 18:54:59 +08:00
|
|
|
|
int getRtmpCodecId() const;
|
2022-11-29 11:07:13 +08:00
|
|
|
|
int getAudioSampleRate() const;
|
|
|
|
|
|
int getAudioSampleBit() const;
|
|
|
|
|
|
int getAudioChannel() const;
|
2021-02-04 17:58:51 +08:00
|
|
|
|
|
|
|
|
|
|
private:
|
2022-02-02 20:34:50 +08:00
|
|
|
|
friend class toolkit::ResourcePool_l<RtmpPacket>;
|
2021-02-04 17:58:51 +08:00
|
|
|
|
RtmpPacket(){
|
|
|
|
|
|
clear();
|
|
|
|
|
|
}
|
2021-02-05 16:49:11 +08:00
|
|
|
|
|
2022-11-29 11:07:13 +08:00
|
|
|
|
RtmpPacket &operator=(const RtmpPacket &that);
|
2021-02-07 23:01:22 +08:00
|
|
|
|
|
2021-02-05 16:49:11 +08:00
|
|
|
|
private:
|
|
|
|
|
|
//对象个数统计
|
2022-02-02 20:34:50 +08:00
|
|
|
|
toolkit::ObjectStatistic<RtmpPacket> _statistic;
|
2017-04-01 16:35:56 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2019-06-28 17:25:53 +08:00
|
|
|
|
/**
|
2019-09-23 16:47:20 +08:00
|
|
|
|
* rtmp metadata基类,用于描述rtmp格式信息
|
2019-06-28 17:25:53 +08:00
|
|
|
|
*/
|
2019-09-23 16:47:20 +08:00
|
|
|
|
class Metadata : public CodecInfo{
|
2019-06-28 17:25:53 +08:00
|
|
|
|
public:
|
2022-12-02 14:43:06 +08:00
|
|
|
|
using Ptr = std::shared_ptr<Metadata>;
|
2019-06-28 17:25:53 +08:00
|
|
|
|
|
2023-04-22 21:59:26 +08:00
|
|
|
|
Metadata(): _metadata(AMF_OBJECT) {}
|
|
|
|
|
|
virtual ~Metadata() = default;
|
2019-09-23 16:47:20 +08:00
|
|
|
|
const AMFValue &getMetadata() const{
|
|
|
|
|
|
return _metadata;
|
2019-06-28 17:25:53 +08:00
|
|
|
|
}
|
2020-05-28 17:03:12 +08:00
|
|
|
|
|
|
|
|
|
|
static void addTrack(AMFValue &metadata, const Track::Ptr &track);
|
2019-06-28 17:25:53 +08:00
|
|
|
|
protected:
|
2019-09-23 16:47:20 +08:00
|
|
|
|
AMFValue _metadata;
|
2019-06-28 17:25:53 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2019-09-23 16:47:20 +08:00
|
|
|
|
* metadata中除音视频外的其他描述部分
|
2019-06-28 17:25:53 +08:00
|
|
|
|
*/
|
2019-09-23 16:47:20 +08:00
|
|
|
|
class TitleMeta : public Metadata{
|
2019-06-28 17:25:53 +08:00
|
|
|
|
public:
|
2022-12-02 14:43:06 +08:00
|
|
|
|
using Ptr = std::shared_ptr<TitleMeta>;
|
2019-06-28 17:25:53 +08:00
|
|
|
|
|
2019-09-23 16:47:20 +08:00
|
|
|
|
TitleMeta(float dur_sec = 0,
|
2021-01-17 18:31:50 +08:00
|
|
|
|
size_t fileSize = 0,
|
2022-11-29 11:07:13 +08:00
|
|
|
|
const std::map<std::string, std::string> &header = std::map<std::string, std::string>());
|
2019-06-28 17:25:53 +08:00
|
|
|
|
|
|
|
|
|
|
CodecId getCodecId() const override{
|
|
|
|
|
|
return CodecInvalid;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-09-23 16:47:20 +08:00
|
|
|
|
class VideoMeta : public Metadata{
|
2019-06-28 17:25:53 +08:00
|
|
|
|
public:
|
2022-12-02 14:43:06 +08:00
|
|
|
|
using Ptr = std::shared_ptr<VideoMeta>;
|
2019-06-28 17:25:53 +08:00
|
|
|
|
|
2020-12-05 12:22:17 +08:00
|
|
|
|
VideoMeta(const VideoTrack::Ptr &video);
|
2023-04-22 21:59:26 +08:00
|
|
|
|
virtual ~VideoMeta() = default;
|
2019-06-28 17:25:53 +08:00
|
|
|
|
|
|
|
|
|
|
CodecId getCodecId() const override{
|
|
|
|
|
|
return _codecId;
|
|
|
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
|
|
|
CodecId _codecId;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-09-23 16:47:20 +08:00
|
|
|
|
class AudioMeta : public Metadata{
|
2019-06-28 17:25:53 +08:00
|
|
|
|
public:
|
2022-12-02 14:43:06 +08:00
|
|
|
|
using Ptr = std::shared_ptr<AudioMeta>;
|
2019-06-28 17:25:53 +08:00
|
|
|
|
|
2020-12-05 12:22:17 +08:00
|
|
|
|
AudioMeta(const AudioTrack::Ptr &audio);
|
2023-04-22 21:59:26 +08:00
|
|
|
|
virtual ~AudioMeta() = default;
|
2019-06-28 17:25:53 +08:00
|
|
|
|
|
|
|
|
|
|
CodecId getCodecId() const override{
|
|
|
|
|
|
return _codecId;
|
|
|
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
|
|
|
CodecId _codecId;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2020-04-18 22:13:11 +08:00
|
|
|
|
//根据音频track获取flags
|
|
|
|
|
|
uint8_t getAudioRtmpFlags(const Track::Ptr &track);
|
2019-06-28 17:25:53 +08:00
|
|
|
|
|
2023-07-22 18:54:59 +08:00
|
|
|
|
////////////////// rtmp video //////////////////////////
|
|
|
|
|
|
//https://rtmp.veriskope.com/pdf/video_file_format_spec_v10_1.pdf
|
|
|
|
|
|
|
|
|
|
|
|
// UB [4]; Type of video frame.
|
2023-07-22 17:31:39 +08:00
|
|
|
|
enum class RtmpFrameType : uint8_t {
|
|
|
|
|
|
reserved = 0,
|
|
|
|
|
|
key_frame = 1, // key frame (for AVC, a seekable frame)
|
|
|
|
|
|
inter_frame = 2, // inter frame (for AVC, a non-seekable frame)
|
|
|
|
|
|
disposable_inter_frame = 3, // disposable inter frame (H.263 only)
|
|
|
|
|
|
generated_key_frame = 4, // generated key frame (reserved for server use only)
|
|
|
|
|
|
video_info_frame = 5, // video info/command frame
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-07-22 18:54:59 +08:00
|
|
|
|
// UB [4]; Codec Identifier.
|
2023-07-29 23:03:28 +08:00
|
|
|
|
enum class RtmpVideoCodec : uint32_t {
|
2023-07-22 17:31:39 +08:00
|
|
|
|
h263 = 2, // Sorenson H.263
|
|
|
|
|
|
screen_video = 3, // Screen video
|
|
|
|
|
|
vp6 = 4, // On2 VP6
|
|
|
|
|
|
vp6_alpha = 5, // On2 VP6 with alpha channel
|
|
|
|
|
|
screen_video2 = 6, // Screen video version 2
|
|
|
|
|
|
h264 = 7, // avc
|
|
|
|
|
|
h265 = 12, // 国内扩展
|
2023-07-29 23:03:28 +08:00
|
|
|
|
|
|
|
|
|
|
// 增强型rtmp FourCC
|
|
|
|
|
|
fourcc_vp9 = 'vp09',
|
|
|
|
|
|
fourcc_av1 = 'av01',
|
|
|
|
|
|
fourcc_hevc = 'hvc1'
|
2023-07-22 17:31:39 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2023-07-22 18:54:59 +08:00
|
|
|
|
// UI8;
|
2023-07-22 17:31:39 +08:00
|
|
|
|
enum class RtmpH264PacketType : uint8_t {
|
2023-07-22 18:54:59 +08:00
|
|
|
|
h264_config_header = 0, // AVC or HEVC sequence header(sps/pps)
|
|
|
|
|
|
h264_nalu = 1, // AVC or HEVC NALU
|
|
|
|
|
|
h264_end_seq = 2, // AVC or HEVC end of sequence (lower level NALU sequence ender is not REQUIRED or supported)
|
2023-07-22 17:31:39 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2023-07-22 18:54:59 +08:00
|
|
|
|
// https://github.com/veovera/enhanced-rtmp/blob/main/enhanced-rtmp.pdf
|
|
|
|
|
|
// UB[4]
|
2023-07-22 17:31:39 +08:00
|
|
|
|
enum class RtmpPacketType : uint8_t {
|
|
|
|
|
|
PacketTypeSequenceStart = 0,
|
|
|
|
|
|
PacketTypeCodedFrames = 1,
|
|
|
|
|
|
PacketTypeSequenceEnd = 2,
|
|
|
|
|
|
|
|
|
|
|
|
// CompositionTime Offset is implied to equal zero. This is
|
|
|
|
|
|
// an optimization to save putting SI24 composition time value of zero on
|
|
|
|
|
|
// the wire. See pseudo code below in the VideoTagBody section
|
|
|
|
|
|
PacketTypeCodedFramesX = 3,
|
|
|
|
|
|
|
|
|
|
|
|
// VideoTagBody does not contain video data. VideoTagBody
|
|
|
|
|
|
// instead contains an AMF encoded metadata. See Metadata Frame
|
|
|
|
|
|
// section for an illustration of its usage. As an example, the metadata
|
|
|
|
|
|
// can be HDR information. This is a good way to signal HDR
|
|
|
|
|
|
// information. This also opens up future ways to express additional
|
|
|
|
|
|
// metadata that is meant for the next video sequence.
|
|
|
|
|
|
//
|
|
|
|
|
|
// note: presence of PacketTypeMetadata means that FrameType
|
|
|
|
|
|
// flags at the top of this table should be ignored
|
|
|
|
|
|
PacketTypeMetadata = 4,
|
|
|
|
|
|
|
|
|
|
|
|
// Carriage of bitstream in MPEG-2 TS format
|
|
|
|
|
|
// note: PacketTypeSequenceStart and PacketTypeMPEG2TSSequenceStart
|
|
|
|
|
|
// are mutually exclusive
|
|
|
|
|
|
PacketTypeMPEG2TSSequenceStart = 5,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-07-22 18:54:59 +08:00
|
|
|
|
////////////////// rtmp audio //////////////////////////
|
|
|
|
|
|
//https://rtmp.veriskope.com/pdf/video_file_format_spec_v10_1.pdf
|
|
|
|
|
|
|
|
|
|
|
|
// UB [4]; Format of SoundData
|
|
|
|
|
|
enum class RtmpAudioCodec : uint8_t {
|
|
|
|
|
|
/**
|
|
|
|
|
|
0 = Linear PCM, platform endian
|
|
|
|
|
|
1 = ADPCM
|
|
|
|
|
|
2 = MP3
|
|
|
|
|
|
3 = Linear PCM, little endian
|
|
|
|
|
|
4 = Nellymoser 16 kHz mono
|
|
|
|
|
|
5 = Nellymoser 8 kHz mono
|
|
|
|
|
|
6 = Nellymoser
|
|
|
|
|
|
7 = G.711 A-law logarithmic PCM
|
|
|
|
|
|
8 = G.711 mu-law logarithmic PCM
|
|
|
|
|
|
9 = reserved
|
|
|
|
|
|
10 = AAC
|
|
|
|
|
|
11 = Speex
|
|
|
|
|
|
14 = MP3 8 kHz
|
|
|
|
|
|
15 = Device-specific sound
|
|
|
|
|
|
*/
|
|
|
|
|
|
g711a = 7,
|
|
|
|
|
|
g711u = 8,
|
|
|
|
|
|
aac = 10,
|
|
|
|
|
|
opus = 13 // 国内扩展
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// UI8;
|
|
|
|
|
|
enum class RtmpAACPacketType : uint8_t {
|
|
|
|
|
|
aac_config_header = 0, // AAC sequence header
|
|
|
|
|
|
aac_raw = 1, // AAC raw
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////
|
|
|
|
|
|
|
2023-07-22 17:31:39 +08:00
|
|
|
|
struct RtmpPacketInfo {
|
|
|
|
|
|
CodecId codec = CodecInvalid;
|
|
|
|
|
|
bool is_enhanced;
|
|
|
|
|
|
union {
|
|
|
|
|
|
struct {
|
|
|
|
|
|
RtmpFrameType frame_type;
|
2023-07-22 18:54:59 +08:00
|
|
|
|
RtmpPacketType pkt_type; // enhanced = true
|
|
|
|
|
|
RtmpH264PacketType h264_pkt_type; // enhanced = false
|
2023-07-22 17:31:39 +08:00
|
|
|
|
} video;
|
|
|
|
|
|
};
|
|
|
|
|
|
};
|
2023-07-22 23:11:40 +08:00
|
|
|
|
// https://github.com/veovera/enhanced-rtmp
|
2023-07-22 17:31:39 +08:00
|
|
|
|
CodecId parseVideoRtmpPacket(const uint8_t *data, size_t size, RtmpPacketInfo *info = nullptr);
|
|
|
|
|
|
|
2019-03-27 18:41:52 +08:00
|
|
|
|
}//namespace mediakit
|
2020-05-11 22:33:10 +08:00
|
|
|
|
#endif//__rtmp_h
|