Created
October 29, 2012 20:31
-
-
Save j0sh/3976337 to your computer and use it in GitHub Desktop.
Support text data in RTMP.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From e47bd0899064ab4affbc5d3132d3593b8333a827 Mon Sep 17 00:00:00 2001 | |
| From: Josh Allmann <joshua.allmann@gmail.com> | |
| Date: Mon, 29 Oct 2012 13:27:12 -0700 | |
| Subject: [PATCH 1/2] flvdec: Allow plain strings in data packets. | |
| --- | |
| libavformat/flvdec.c | 3 +++ | |
| 1 file changed, 3 insertions(+) | |
| diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c | |
| index 868cc6b..2229eb2 100644 | |
| --- a/libavformat/flvdec.c | |
| +++ b/libavformat/flvdec.c | |
| @@ -582,6 +582,8 @@ static int flv_data_packet(AVFormatContext *s, AVPacket *pkt, | |
| type = avio_r8(pb); | |
| if (type == AMF_DATA_TYPE_MIXEDARRAY) | |
| avio_seek(pb, 4, SEEK_CUR); | |
| + else if (type == AMF_DATA_TYPE_STRING) | |
| + goto data; | |
| else if (type != AMF_DATA_TYPE_OBJECT) | |
| goto out; | |
| @@ -595,6 +597,7 @@ static int flv_data_packet(AVFormatContext *s, AVPacket *pkt, | |
| if (strcmp(buf, "text") || avio_r8(pb) != AMF_DATA_TYPE_STRING) | |
| goto out; | |
| +data: | |
| length = avio_rb16(pb); | |
| ret = av_get_packet(s->pb, pkt, length); | |
| if (ret < 0) { | |
| -- | |
| 1.7.9.5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 0b92ac3070b419ca5f2b28c6eca76ebf1ae8db71 Mon Sep 17 00:00:00 2001 | |
| From: Josh Allmann <joshua.allmann@gmail.com> | |
| Date: Mon, 29 Oct 2012 13:29:41 -0700 | |
| Subject: [PATCH 2/2] RTMP: Support Flex Stream messages. | |
| --- | |
| libavformat/rtmppkt.c | 4 +++- | |
| libavformat/rtmpproto.c | 12 ++++++++---- | |
| 2 files changed, 11 insertions(+), 5 deletions(-) | |
| diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c | |
| index f69ce82..7b2de05 100644 | |
| --- a/libavformat/rtmppkt.c | |
| +++ b/libavformat/rtmppkt.c | |
| @@ -491,8 +491,10 @@ void ff_rtmp_packet_dump(void *ctx, RTMPPacket *p) | |
| { | |
| av_log(ctx, AV_LOG_DEBUG, "RTMP packet type '%s'(%d) for channel %d, timestamp %d, extra field %d size %d\n", | |
| rtmp_packet_type(p->type), p->type, p->channel_id, p->timestamp, p->extra, p->data_size); | |
| - if (p->type == RTMP_PT_INVOKE || p->type == RTMP_PT_NOTIFY) { | |
| + if (p->type == RTMP_PT_INVOKE || p->type == RTMP_PT_NOTIFY || | |
| + p->type == RTMP_PT_FLEX_STREAM) { | |
| uint8_t *src = p->data, *src_end = p->data + p->data_size; | |
| + if (p->type == RTMP_PT_FLEX_STREAM) src += 1; | |
| while (src < src_end) { | |
| int sz; | |
| ff_amf_tag_contents(ctx, src, src_end); | |
| diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c | |
| index 3ab2e57..6f24e7d 100644 | |
| --- a/libavformat/rtmpproto.c | |
| +++ b/libavformat/rtmpproto.c | |
| @@ -1903,6 +1903,7 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt) | |
| case RTMP_PT_AUDIO: | |
| case RTMP_PT_METADATA: | |
| case RTMP_PT_NOTIFY: | |
| + case RTMP_PT_FLEX_STREAM: | |
| /* Audio, Video and Metadata packets are parsed in get_packet() */ | |
| break; | |
| default: | |
| @@ -1973,19 +1974,22 @@ static int get_packet(URLContext *s, int for_header) | |
| continue; | |
| } | |
| if (rpkt.type == RTMP_PT_VIDEO || rpkt.type == RTMP_PT_AUDIO || | |
| + rpkt.type == RTMP_PT_FLEX_STREAM || | |
| (rpkt.type == RTMP_PT_NOTIFY && !memcmp("\002\000\012onMetaData", rpkt.data, 13))) { | |
| + // flexstream messages have a mystery byte at the start | |
| + int fs = rpkt.type == RTMP_PT_FLEX_STREAM; | |
| ts = rpkt.timestamp; | |
| // generate packet header and put data into buffer for FLV demuxer | |
| rt->flv_off = 0; | |
| - rt->flv_size = rpkt.data_size + 15; | |
| + rt->flv_size = rpkt.data_size + 15 - fs; | |
| rt->flv_data = p = av_realloc(rt->flv_data, rt->flv_size); | |
| - bytestream_put_byte(&p, rpkt.type); | |
| - bytestream_put_be24(&p, rpkt.data_size); | |
| + bytestream_put_byte(&p, fs ? RTMP_PT_NOTIFY : rpkt.type); | |
| + bytestream_put_be24(&p, rpkt.data_size-fs); | |
| bytestream_put_be24(&p, ts); | |
| bytestream_put_byte(&p, ts >> 24); | |
| bytestream_put_be24(&p, 0); | |
| - bytestream_put_buffer(&p, rpkt.data, rpkt.data_size); | |
| + bytestream_put_buffer(&p, rpkt.data+fs, rpkt.data_size-fs); | |
| bytestream_put_be32(&p, 0); | |
| ff_rtmp_packet_destroy(&rpkt); | |
| return 0; | |
| -- | |
| 1.7.9.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment