From cd1dd6f31509dbba290b6c0f9ae7eb281305c7f4 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Mon, 10 Dec 2018 15:25:42 +0100 Subject: [PATCH] rtmp: add rtmp_meta() to send metadata on stream (#173) --- include/re_rtmp.h | 3 ++- src/rtmp/amf.c | 2 +- src/rtmp/stream.c | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/include/re_rtmp.h b/include/re_rtmp.h index 71d4e8f..b7fc8fc 100644 --- a/include/re_rtmp.h +++ b/include/re_rtmp.h @@ -99,7 +99,7 @@ int rtmp_amf_request(struct rtmp_conn *conn, uint32_t stream_id, int rtmp_amf_reply(struct rtmp_conn *conn, uint32_t stream_id, bool success, const struct odict *req, unsigned body_propc, ...); -int rtmp_amf_data(struct rtmp_conn *conn, uint32_t stream_id, +int rtmp_amf_data(const struct rtmp_conn *conn, uint32_t stream_id, const char *command, unsigned body_propc, ...); @@ -125,6 +125,7 @@ int rtmp_stream_create(struct rtmp_stream **strmp, struct rtmp_conn *conn, void *arg); int rtmp_play(struct rtmp_stream *strm, const char *name); int rtmp_publish(struct rtmp_stream *strm, const char *name); +int rtmp_meta(struct rtmp_stream *strm); int rtmp_send_audio(struct rtmp_stream *strm, uint32_t timestamp, const uint8_t *pld, size_t len); int rtmp_send_video(struct rtmp_stream *strm, uint32_t timestamp, diff --git a/src/rtmp/amf.c b/src/rtmp/amf.c index 32dd0c9..c95763e 100644 --- a/src/rtmp/amf.c +++ b/src/rtmp/amf.c @@ -122,7 +122,7 @@ int rtmp_amf_reply(struct rtmp_conn *conn, uint32_t stream_id, bool success, } -int rtmp_amf_data(struct rtmp_conn *conn, uint32_t stream_id, +int rtmp_amf_data(const struct rtmp_conn *conn, uint32_t stream_id, const char *command, unsigned body_propc, ...) { struct mbuf *mb; diff --git a/src/rtmp/stream.c b/src/rtmp/stream.c index de6007b..fe8748d 100644 --- a/src/rtmp/stream.c +++ b/src/rtmp/stream.c @@ -210,6 +210,27 @@ int rtmp_publish(struct rtmp_stream *strm, const char *name) } +/** + * Send metadata on the stream to the RTMP Server + * + * @param strm RTMP Stream + * + * @return 0 if success, otherwise errorcode + */ +int rtmp_meta(struct rtmp_stream *strm) +{ + if (!strm) + return EINVAL; + + return rtmp_amf_data(strm->conn, strm->stream_id, "@setDataFrame", + 2, + RTMP_AMF_TYPE_STRING, "onMetaData", + RTMP_AMF_TYPE_ECMA_ARRAY, 2, + RTMP_AMF_TYPE_NUMBER, "audiocodecid", 10.0, + RTMP_AMF_TYPE_NUMBER, "videocodecid", 7.0); +} + + /** * Send audio packet on the RTMP Stream *