--- libavformat/rtmppkt.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ libavformat/rtmppkt.h | 43 +++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+)
diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c index 4ce238d..c592f61 100644 --- a/libavformat/rtmppkt.c +++ b/libavformat/rtmppkt.c @@ -71,6 +71,63 @@ void ff_amf_write_object_end(uint8_t **dst) bytestream_put_be24(dst, AMF_DATA_TYPE_OBJECT_END); } +int ff_amf_read_bool(const uint8_t **src, int src_size, int *val) +{ + GetByteContext bsc; + bytestream2_init(&bsc, *src, src_size); + if (bytestream2_get_byte(&bsc) != AMF_DATA_TYPE_BOOL) + return AVERROR_INVALIDDATA; + *val = bytestream2_get_byte(&bsc); + *src = bsc.buffer; + return 0; +} + +int ff_amf_read_number(const uint8_t **src, int src_size, double *val) +{ + uint64_t read; + GetByteContext bsc; + bytestream2_init(&bsc, *src, src_size); + if (bytestream2_get_byte(&bsc) != AMF_DATA_TYPE_NUMBER) + return AVERROR_INVALIDDATA; + read = bytestream2_get_be64(&bsc); + *val = av_int2double(read); + *src = bsc.buffer; + return 0; +} + +int ff_amf_read_string(const uint8_t **src, int src_size, uint8_t *str, + int strsize, int *strlen) +{ + int stringlen = 0; + int readsize; + GetByteContext bsc; + bytestream2_init(&bsc, *src, src_size); + if (bytestream2_get_byte(&bsc) != AMF_DATA_TYPE_STRING) + return AVERROR_INVALIDDATA; + stringlen = bytestream2_get_be16(&bsc); + if (stringlen + 1 > strsize) + return AVERROR(EINVAL); + readsize = bytestream2_get_buffer(&bsc, str, stringlen); + if (readsize != stringlen) { + av_log(NULL, AV_LOG_WARNING, "ff_amf_read_string length differs from" + " announced length\n"); + } + str[stringlen] = '\0'; + *strlen = stringlen; + *src = bsc.buffer; + return 0; +} + +int ff_amf_read_null(const uint8_t **src, int src_size) +{ + GetByteContext bsc; + bytestream2_init(&bsc, *src, src_size); + if (bytestream2_get_byte(&bsc) != AMF_DATA_TYPE_NULL) + return AVERROR_INVALIDDATA; + *src = bsc.buffer; + return 0; +} + int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, int chunk_size, RTMPPacket *prev_pkt) { diff --git a/libavformat/rtmppkt.h b/libavformat/rtmppkt.h index a83d0fe..8e32d1b 100644 --- a/libavformat/rtmppkt.h +++ b/libavformat/rtmppkt.h @@ -231,6 +231,49 @@ void ff_amf_write_field_name(uint8_t **dst, const char *str); */ void ff_amf_write_object_end(uint8_t **dst); +/** + * Read AMF boolean value from buffer + * + *@param src pointer to the buffer + *@param src_size size of src + *@param val returned read boolean value + *@return 0 if Success +*/ +int ff_amf_read_bool(const uint8_t **src, int src_size, int *val); + +/** + * Read AMF number value from buffer + * + *@param src pointer to the buffer + *@param src_size size of src + *@param val returned read double value + *@return 0 if Success +*/ +int ff_amf_read_number(const uint8_t **src, int src_size, double *val); + +/** + * Read AMF string value from buffer + * + *@param src pointer to the buffer + *@param src_size size of src + *@param str return read null terminated string + *@param strsize available buffer + *@param strlen readed string length + *@return 0 if Success +*/ +int ff_amf_read_string(const uint8_t **src, int src_size, uint8_t *str, + int strsize, int *strlen); + +/** + * Read AMF boolean value from buffer + * + *@param src pointer to the buffer + *@param src_size size of src + *@return 0 if Success +*/ +int ff_amf_read_null(const uint8_t **src, int src_size); + + /** @} */ // AMF funcs #endif /* AVFORMAT_RTMPPKT_H */ -- 1.7.10 _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel