aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/rtmpproto.c
diff options
context:
space:
mode:
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>2012-07-21 12:59:58 +0200
committerMartin Storsjö <martin@martin.st>2012-07-25 21:08:24 +0300
commit6d1c9945dd0a539aa9017697ac7572fde3dc5b83 (patch)
treec2fab9b86bf6947183eccad53b70a3f1910a70dc /libavformat/rtmpproto.c
parent7be2a7d8ff43fba8d64320c7b778da9f942a9c1b (diff)
downloadffmpeg-6d1c9945dd0a539aa9017697ac7572fde3dc5b83.tar.gz
rtmp: Factorize the code by adding handle_invoke
Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/rtmpproto.c')
-rw-r--r--libavformat/rtmpproto.c143
1 files changed, 77 insertions, 66 deletions
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 871c24eba0..31d1f69e94 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -953,50 +953,23 @@ static int handle_server_bw(URLContext *s, RTMPPacket *pkt)
return 0;
}
-/**
- * Parse received packet and possibly perform some action depending on
- * the packet contents.
- * @return 0 for no errors, negative values for serious errors which prevent
- * further communications, positive values for uncritical errors
- */
-static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
+static int handle_invoke(URLContext *s, RTMPPacket *pkt)
{
+ RTMPContext *rt = s->priv_data;
int i, t;
const uint8_t *data_end = pkt->data + pkt->data_size;
int ret;
-#ifdef DEBUG
- ff_rtmp_packet_dump(s, pkt);
-#endif
+ //TODO: check for the messages sent for wrong state?
+ if (!memcmp(pkt->data, "\002\000\006_error", 9)) {
+ uint8_t tmpstr[256];
- switch (pkt->type) {
- case RTMP_PT_CHUNK_SIZE:
- if ((ret = handle_chunk_size(s, pkt)) < 0)
- return ret;
- break;
- case RTMP_PT_PING:
- if ((ret = handle_ping(s, pkt)) < 0)
- return ret;
- break;
- case RTMP_PT_CLIENT_BW:
- if ((ret = handle_client_bw(s, pkt)) < 0)
- return ret;
- break;
- case RTMP_PT_SERVER_BW:
- if ((ret = handle_server_bw(s, pkt)) < 0)
- return ret;
- break;
- case RTMP_PT_INVOKE:
- //TODO: check for the messages sent for wrong state?
- if (!memcmp(pkt->data, "\002\000\006_error", 9)) {
- 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;
- } else if (!memcmp(pkt->data, "\002\000\007_result", 10)) {
- switch (rt->state) {
+ 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)) {
+ switch (rt->state) {
case STATE_HANDSHAKED:
if (!rt->is_input) {
if ((ret = gen_release_stream(s, rt)) < 0)
@@ -1044,35 +1017,73 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
}
rt->state = STATE_READY;
break;
- }
- } 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;
- }
- 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;
- } else if (!memcmp(pkt->data, "\002\000\010onBWDone", 11)) {
- if ((ret = gen_check_bw(s, rt)) < 0)
- return ret;
}
+ } 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;
+ }
+ 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;
+ } else if (!memcmp(pkt->data, "\002\000\010onBWDone", 11)) {
+ if ((ret = gen_check_bw(s, rt)) < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+/**
+ * Parse received packet and possibly perform some action depending on
+ * the packet contents.
+ * @return 0 for no errors, negative values for serious errors which prevent
+ * further communications, positive values for uncritical errors
+ */
+static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
+{
+ int ret;
+
+#ifdef DEBUG
+ ff_rtmp_packet_dump(s, pkt);
+#endif
+
+ switch (pkt->type) {
+ case RTMP_PT_CHUNK_SIZE:
+ if ((ret = handle_chunk_size(s, pkt)) < 0)
+ return ret;
+ break;
+ case RTMP_PT_PING:
+ if ((ret = handle_ping(s, pkt)) < 0)
+ return ret;
+ break;
+ case RTMP_PT_CLIENT_BW:
+ if ((ret = handle_client_bw(s, pkt)) < 0)
+ return ret;
+ break;
+ case RTMP_PT_SERVER_BW:
+ if ((ret = handle_server_bw(s, pkt)) < 0)
+ return ret;
+ break;
+ case RTMP_PT_INVOKE:
+ if ((ret = handle_invoke(s, pkt)) < 0)
+ return ret;
break;
case RTMP_PT_VIDEO:
case RTMP_PT_AUDIO: