diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-08-10 16:19:23 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-08-10 16:25:23 +0200 |
commit | 18b0c39f99eee508107c47345494e535b8757434 (patch) | |
tree | b1418e52aab2f1fb8a171c3bb3fada3c7b0df531 /libavformat/rtmpproto.c | |
parent | d9d0c1ccc3df39fecbbbb6b600c18542741c5a51 (diff) | |
parent | 05c36e0e5fbf0b75dbbbd327ad2f6a62992f9262 (diff) | |
download | ffmpeg-18b0c39f99eee508107c47345494e535b8757434.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master:
g723.1: fix addition overflow
g723.1: simplify and fix multiplication overflow
g723.1: deobfuscate an expression
g723.1: remove unused #includes
ARM: add missing "cc" clobber in av_clipl_int32_arm()
rtmp: Factorize the code by adding handle_invoke_error
rtmp: Factorize the code by adding handle_invoke_status
rtmp: Factorize the code by adding handle_invoke_result
libavutil: remove unused av_abort() macro
ffmenc: replace if/abort with assert()
libavutil: drop offsetof() fallback definition
libavutil: drop fallback definitions of INTxx_MIN/MAX
configure: Check for a sctp struct instead of just the header
configure: suncc: Add -xc99 to dependency flags, required on Solaris
doxygen: Fix function parameter names to match the code
doc: Drop obsolete shared libs cflags hint to workaround Cygwin gcc bugs
swf: Move shared table out of the header file
swf: Move swf_audio_codec_tags table to the only place it is used
fate: add G.723.1 decoder tests
Conflicts:
configure
doc/platform.texi
libavformat/Makefile
libavutil/arm/intmath.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/rtmpproto.c')
-rw-r--r-- | libavformat/rtmpproto.c | 214 |
1 files changed, 121 insertions, 93 deletions
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index e48c740a2e..5dae64118b 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -1021,121 +1021,149 @@ static int handle_server_bw(URLContext *s, RTMPPacket *pkt) return 0; } -static int handle_invoke(URLContext *s, RTMPPacket *pkt) +static int handle_invoke_error(URLContext *s, RTMPPacket *pkt) { - RTMPContext *rt = s->priv_data; - int i, t; const uint8_t *data_end = pkt->data + pkt->data_size; + uint8_t tmpstr[256]; + + if (!ff_amf_get_field_value(pkt->data + 9, data_end, + "description", tmpstr, sizeof(tmpstr))) { + av_log(s, AV_LOG_ERROR, "Server error: %s\n", tmpstr); + return -1; + } + + return 0; +} + +static int handle_invoke_result(URLContext *s, RTMPPacket *pkt) +{ + RTMPContext *rt = s->priv_data; char *tracked_method = NULL; + GetByteContext gbc; + double pkt_id; int ret = 0; + int i; - //TODO: check for the messages sent for wrong state? - if (!memcmp(pkt->data, "\002\000\006_error", 9)) { - uint8_t tmpstr[256]; + bytestream2_init(&gbc, pkt->data + 10, pkt->data_size); + if ((ret = ff_amf_read_number(&gbc, &pkt_id)) < 0) + return ret; - if (!ff_amf_get_field_value(pkt->data + 9, data_end, - "description", tmpstr, sizeof(tmpstr))) - av_log(s, AV_LOG_ERROR, "Server error: %s\n",tmpstr); - return -1; - } else if (!memcmp(pkt->data, "\002\000\007_result", 10)) { - GetByteContext gbc; - double pkt_id; + for (i = 0; i < rt->nb_tracked_methods; i++) { + if (rt->tracked_methods[i].id != pkt_id) + continue; - bytestream2_init(&gbc, pkt->data + 10, pkt->data_size); - if ((ret = ff_amf_read_number(&gbc, &pkt_id)) < 0) - return ret; + tracked_method = rt->tracked_methods[i].name; + del_tracked_method(rt, i); + break; + } - for (i = 0; i < rt->nb_tracked_methods; i++) { - if (rt->tracked_methods[i].id != pkt_id) - continue; + if (!tracked_method) { + /* Ignore this reply when the current method is not tracked. */ + return ret; + } - tracked_method = rt->tracked_methods[i].name; - del_tracked_method(rt, i); - break; - } + if (!memcmp(tracked_method, "connect", 7)) { + if (!rt->is_input) { + if ((ret = gen_release_stream(s, rt)) < 0) + goto fail; - if (!tracked_method) { - /* Ignore this reply when the current method is not tracked. */ - return 0; + if ((ret = gen_fcpublish_stream(s, rt)) < 0) + goto fail; + } else { + if ((ret = gen_server_bw(s, rt)) < 0) + goto fail; } - if (!memcmp(tracked_method, "connect", 7)) { - if (!rt->is_input) { - if ((ret = gen_release_stream(s, rt)) < 0) - goto invoke_fail; - - if ((ret = gen_fcpublish_stream(s, rt)) < 0) - goto invoke_fail; - } else { - if ((ret = gen_server_bw(s, rt)) < 0) - goto invoke_fail; - } - - if ((ret = gen_create_stream(s, rt)) < 0) - goto invoke_fail; - - if (rt->is_input) { - /* Send the FCSubscribe command when the name of live - * stream is defined by the user or if it's a live stream. */ - if (rt->subscribe) { - if ((ret = gen_fcsubscribe_stream(s, rt, - rt->subscribe)) < 0) - goto invoke_fail; - } else if (rt->live == -1) { - if ((ret = gen_fcsubscribe_stream(s, rt, - rt->playpath)) < 0) - goto invoke_fail; - } - } - } else if (!memcmp(tracked_method, "createStream", 12)) { - //extract a number from the result - if (pkt->data[10] || pkt->data[19] != 5 || pkt->data[20]) { - av_log(s, AV_LOG_WARNING, "Unexpected reply on connect()\n"); - } else { - rt->main_channel_id = av_int2double(AV_RB64(pkt->data + 21)); - } + if ((ret = gen_create_stream(s, rt)) < 0) + goto fail; - if (!rt->is_input) { - if ((ret = gen_publish(s, rt)) < 0) - goto invoke_fail; - } else { - if ((ret = gen_play(s, rt)) < 0) - goto invoke_fail; - if ((ret = gen_buffer_time(s, rt)) < 0) - goto invoke_fail; + if (rt->is_input) { + /* Send the FCSubscribe command when the name of live + * stream is defined by the user or if it's a live stream. */ + if (rt->subscribe) { + if ((ret = gen_fcsubscribe_stream(s, rt, rt->subscribe)) < 0) + goto fail; + } else if (rt->live == -1) { + if ((ret = gen_fcsubscribe_stream(s, rt, rt->playpath)) < 0) + goto fail; } } - } else if (!memcmp(pkt->data, "\002\000\010onStatus", 11)) { - const uint8_t* ptr = pkt->data + 11; - uint8_t tmpstr[256]; - - for (i = 0; i < 2; i++) { - t = ff_amf_tag_size(ptr, data_end); - if (t < 0) - return 1; - ptr += t; + } else if (!memcmp(tracked_method, "createStream", 12)) { + //extract a number from the result + if (pkt->data[10] || pkt->data[19] != 5 || pkt->data[20]) { + av_log(s, AV_LOG_WARNING, "Unexpected reply on connect()\n"); + } else { + rt->main_channel_id = av_int2double(AV_RB64(pkt->data + 21)); } - t = ff_amf_get_field_value(ptr, data_end, - "level", tmpstr, sizeof(tmpstr)); - if (!t && !strcmp(tmpstr, "error")) { - if (!ff_amf_get_field_value(ptr, data_end, - "description", tmpstr, sizeof(tmpstr))) - av_log(s, AV_LOG_ERROR, "Server error: %s\n",tmpstr); - return -1; + + if (!rt->is_input) { + if ((ret = gen_publish(s, rt)) < 0) + goto fail; + } else { + if ((ret = gen_play(s, rt)) < 0) + goto fail; + if ((ret = gen_buffer_time(s, rt)) < 0) + goto fail; } - t = ff_amf_get_field_value(ptr, data_end, - "code", tmpstr, sizeof(tmpstr)); - if (!t && !strcmp(tmpstr, "NetStream.Play.Start")) rt->state = STATE_PLAYING; - if (!t && !strcmp(tmpstr, "NetStream.Play.Stop")) rt->state = STATE_STOPPED; - if (!t && !strcmp(tmpstr, "NetStream.Play.UnpublishNotify")) rt->state = STATE_STOPPED; - if (!t && !strcmp(tmpstr, "NetStream.Publish.Start")) rt->state = STATE_PUBLISHING; + } + +fail: + av_free(tracked_method); + return ret; +} + +static int handle_invoke_status(URLContext *s, RTMPPacket *pkt) +{ + RTMPContext *rt = s->priv_data; + const uint8_t *data_end = pkt->data + pkt->data_size; + const uint8_t *ptr = pkt->data + 11; + uint8_t tmpstr[256]; + int i, t; + + for (i = 0; i < 2; i++) { + t = ff_amf_tag_size(ptr, data_end); + if (t < 0) + return 1; + ptr += t; + } + + t = ff_amf_get_field_value(ptr, data_end, "level", tmpstr, sizeof(tmpstr)); + if (!t && !strcmp(tmpstr, "error")) { + if (!ff_amf_get_field_value(ptr, data_end, + "description", tmpstr, sizeof(tmpstr))) + av_log(s, AV_LOG_ERROR, "Server error: %s\n", tmpstr); + return -1; + } + + t = ff_amf_get_field_value(ptr, data_end, "code", tmpstr, sizeof(tmpstr)); + if (!t && !strcmp(tmpstr, "NetStream.Play.Start")) rt->state = STATE_PLAYING; + if (!t && !strcmp(tmpstr, "NetStream.Play.Stop")) rt->state = STATE_STOPPED; + if (!t && !strcmp(tmpstr, "NetStream.Play.UnpublishNotify")) rt->state = STATE_STOPPED; + if (!t && !strcmp(tmpstr, "NetStream.Publish.Start")) rt->state = STATE_PUBLISHING; + + return 0; +} + +static int handle_invoke(URLContext *s, RTMPPacket *pkt) +{ + RTMPContext *rt = s->priv_data; + int ret = 0; + + //TODO: check for the messages sent for wrong state? + if (!memcmp(pkt->data, "\002\000\006_error", 9)) { + if ((ret = handle_invoke_error(s, pkt)) < 0) + return ret; + } else if (!memcmp(pkt->data, "\002\000\007_result", 10)) { + if ((ret = handle_invoke_result(s, pkt)) < 0) + return ret; + } else if (!memcmp(pkt->data, "\002\000\010onStatus", 11)) { + if ((ret = handle_invoke_status(s, pkt)) < 0) + return ret; } else if (!memcmp(pkt->data, "\002\000\010onBWDone", 11)) { if ((ret = gen_check_bw(s, rt)) < 0) return ret; } -invoke_fail: - av_free(tracked_method); return ret; } |