blob: 4def1d1a3aca0b51d0bf68c2bb01d8f4e3d4f8e9 [file] [log] [blame]
James Kuszmaul82f6c042021-01-17 11:30:16 -08001/**
2 * @file re_rtmp.h Interface to Real Time Messaging Protocol (RTMP)
3 *
4 * Copyright (C) 2010 Creytiv.com
5 */
6
7
8/** RTMP Protocol values */
9enum {
10 RTMP_PORT = 1935,
11};
12
13/** RTMP Stream IDs */
14enum {
15
16 /* User Control messages SHOULD use message stream ID 0
17 (known as the control stream) */
18 RTMP_CONTROL_STREAM_ID = 0
19};
20
21/** RTMP Packet types */
22enum rtmp_packet_type {
23 RTMP_TYPE_SET_CHUNK_SIZE = 1, /**< Set Chunk Size */
24 RTMP_TYPE_ACKNOWLEDGEMENT = 3, /**< Acknowledgement */
25 RTMP_TYPE_USER_CONTROL_MSG = 4, /**< User Control Messages */
26 RTMP_TYPE_WINDOW_ACK_SIZE = 5, /**< Window Acknowledgement Size */
27 RTMP_TYPE_SET_PEER_BANDWIDTH = 6, /**< Set Peer Bandwidth */
28 RTMP_TYPE_AUDIO = 8, /**< Audio Message */
29 RTMP_TYPE_VIDEO = 9, /**< Video Message */
30 RTMP_TYPE_DATA = 18, /**< Data Message */
31 RTMP_TYPE_AMF0 = 20, /**< Action Message Format (AMF) */
32};
33
34/** RTMP AMF types */
35enum rtmp_amf_type {
36 RTMP_AMF_TYPE_ROOT = -1, /**< Special internal type */
37 RTMP_AMF_TYPE_NUMBER = 0x00, /**< Number Type */
38 RTMP_AMF_TYPE_BOOLEAN = 0x01, /**< Boolean Type */
39 RTMP_AMF_TYPE_STRING = 0x02, /**< String Type */
40 RTMP_AMF_TYPE_OBJECT = 0x03, /**< Object Type */
41 RTMP_AMF_TYPE_NULL = 0x05, /**< Null type */
42 RTMP_AMF_TYPE_ECMA_ARRAY = 0x08, /**< ECMA 'associative' Array */
43 RTMP_AMF_TYPE_OBJECT_END = 0x09, /**< Object End Type */
44 RTMP_AMF_TYPE_STRICT_ARRAY = 0x0a, /**< Array with ordinal indices */
45};
46
47/** RTMP Event types */
48enum rtmp_event_type {
49 RTMP_EVENT_STREAM_BEGIN = 0, /**< Stream begin */
50 RTMP_EVENT_STREAM_EOF = 1, /**< Stream End-Of-File */
51 RTMP_EVENT_STREAM_DRY = 2, /**< No more data on the stream */
52 RTMP_EVENT_SET_BUFFER_LENGTH = 3, /**< Set buffer size in [ms] */
53 RTMP_EVENT_STREAM_IS_RECORDED = 4, /**< Stream is recorded */
54 RTMP_EVENT_PING_REQUEST = 6, /**< Ping Request from server */
55 RTMP_EVENT_PING_RESPONSE = 7, /**< Ping Response to server */
56};
57
58
59/* forward declarations */
60struct dnsc;
61struct odict;
62struct tcp_sock;
63
64
65/*
66 * RTMP High-level API (connection, stream)
67 */
68
69
70/* conn */
71struct rtmp_conn;
72
73typedef void (rtmp_estab_h)(void *arg);
74typedef void (rtmp_command_h)(const struct odict *msg, void *arg);
75typedef void (rtmp_close_h)(int err, void *arg);
76
77int rtmp_connect(struct rtmp_conn **connp, struct dnsc *dnsc, const char *uri,
78 rtmp_estab_h *estabh, rtmp_command_h *cmdh,
79 rtmp_close_h *closeh, void *arg);
80int rtmp_accept(struct rtmp_conn **connp, struct tcp_sock *ts,
81 rtmp_command_h *cmdh, rtmp_close_h *closeh, void *arg);
82int rtmp_control(const struct rtmp_conn *conn,
83 enum rtmp_packet_type type, ...);
84void rtmp_set_handlers(struct rtmp_conn *conn, rtmp_command_h *cmdh,
85 rtmp_close_h *closeh, void *arg);
86struct tcp_conn *rtmp_conn_tcpconn(const struct rtmp_conn *conn);
87const char *rtmp_conn_stream(const struct rtmp_conn *conn);
88int rtmp_conn_debug(struct re_printf *pf, const struct rtmp_conn *conn);
89
90
91typedef void (rtmp_resp_h)(bool success, const struct odict *msg,
92 void *arg);
93
94/* amf */
95int rtmp_amf_command(const struct rtmp_conn *conn, uint32_t stream_id,
96 const char *command,
97 unsigned body_propc, ...);
98int rtmp_amf_request(struct rtmp_conn *conn, uint32_t stream_id,
99 const char *command,
100 rtmp_resp_h *resph, void *arg, unsigned body_propc, ...);
101int rtmp_amf_reply(struct rtmp_conn *conn, uint32_t stream_id, bool success,
102 const struct odict *req,
103 unsigned body_propc, ...);
104int rtmp_amf_data(const struct rtmp_conn *conn, uint32_t stream_id,
105 const char *command, unsigned body_propc, ...);
106
107
108/* stream */
109struct rtmp_stream;
110
111typedef void (rtmp_control_h)(enum rtmp_event_type event, struct mbuf *mb,
112 void *arg);
113typedef void (rtmp_audio_h)(uint32_t timestamp,
114 const uint8_t *pld, size_t len, void *arg);
115typedef void (rtmp_video_h)(uint32_t timestamp,
116 const uint8_t *pld, size_t len, void *arg);
117
118int rtmp_stream_alloc(struct rtmp_stream **strmp, struct rtmp_conn *conn,
119 uint32_t stream_id, rtmp_command_h *cmdh,
120 rtmp_control_h *ctrlh, rtmp_audio_h *auh,
121 rtmp_video_h *vidh, rtmp_command_h *datah,
122 void *arg);
123int rtmp_stream_create(struct rtmp_stream **strmp, struct rtmp_conn *conn,
124 rtmp_resp_h *resph, rtmp_command_h *cmdh,
125 rtmp_control_h *ctrlh, rtmp_audio_h *auh,
126 rtmp_video_h *vidh, rtmp_command_h *datah,
127 void *arg);
128int rtmp_play(struct rtmp_stream *strm, const char *name);
129int rtmp_publish(struct rtmp_stream *strm, const char *name);
130int rtmp_meta(struct rtmp_stream *strm);
131int rtmp_send_audio(struct rtmp_stream *strm, uint32_t timestamp,
132 const uint8_t *pld, size_t len);
133int rtmp_send_video(struct rtmp_stream *strm, uint32_t timestamp,
134 const uint8_t *pld, size_t len);
135struct rtmp_stream *rtmp_stream_find(const struct rtmp_conn *conn,
136 uint32_t stream_id);
137
138
139const char *rtmp_event_name(enum rtmp_event_type event);