rtmp: Factorize the code by adding find_tracked_method

Also fix the bytestream reader size parameter to take the
offset into account.

Signed-off-by: Martin Storsjö <martin@martin.st>
pull/28/head
Samuel Pitoiset 12 years ago committed by Martin Storsjö
parent 885da7b082
commit a8103503b3
  1. 40
      libavformat/rtmpproto.c

@ -154,6 +154,31 @@ static void del_tracked_method(RTMPContext *rt, int index)
rt->nb_tracked_methods--; rt->nb_tracked_methods--;
} }
static int find_tracked_method(URLContext *s, RTMPPacket *pkt, int offset,
char **tracked_method)
{
RTMPContext *rt = s->priv_data;
GetByteContext gbc;
double pkt_id;
int ret;
int i;
bytestream2_init(&gbc, pkt->data + offset, pkt->data_size - offset);
if ((ret = ff_amf_read_number(&gbc, &pkt_id)) < 0)
return ret;
for (i = 0; i < rt->nb_tracked_methods; i++) {
if (rt->tracked_methods[i].id != pkt_id)
continue;
*tracked_method = rt->tracked_methods[i].name;
del_tracked_method(rt, i);
break;
}
return 0;
}
static void free_tracked_methods(RTMPContext *rt) static void free_tracked_methods(RTMPContext *rt)
{ {
int i; int i;
@ -1039,24 +1064,11 @@ static int handle_invoke_result(URLContext *s, RTMPPacket *pkt)
{ {
RTMPContext *rt = s->priv_data; RTMPContext *rt = s->priv_data;
char *tracked_method = NULL; char *tracked_method = NULL;
GetByteContext gbc;
double pkt_id;
int ret = 0; int ret = 0;
int i;
bytestream2_init(&gbc, pkt->data + 10, pkt->data_size); if ((ret = find_tracked_method(s, pkt, 10, &tracked_method)) < 0)
if ((ret = ff_amf_read_number(&gbc, &pkt_id)) < 0)
return ret; return ret;
for (i = 0; i < rt->nb_tracked_methods; i++) {
if (rt->tracked_methods[i].id != pkt_id)
continue;
tracked_method = rt->tracked_methods[i].name;
del_tracked_method(rt, i);
break;
}
if (!tracked_method) { if (!tracked_method) {
/* Ignore this reply when the current method is not tracked. */ /* Ignore this reply when the current method is not tracked. */
return ret; return ret;

Loading…
Cancel
Save