mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-11-21 10:55:51 +02:00
rtmp: Factorize the code by adding handle_invoke
Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
parent
7be2a7d8ff
commit
6d1c9945dd
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user