diff options
author | Samuel Pitoiset <samuel.pitoiset@gmail.com> | 2012-08-11 12:41:32 +0200 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2012-08-11 15:15:51 +0300 |
commit | a8103503b348966d0bd83cd57f2b4e661d5d6458 (patch) | |
tree | d1fbd8bf742a0b4e3a057c1033a55f84701c8c74 /libavformat | |
parent | 885da7b08289321b88919e86d1574c8683a95a22 (diff) | |
download | ffmpeg-a8103503b348966d0bd83cd57f2b4e661d5d6458.tar.gz |
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>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/rtmpproto.c | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index c85424e32c..910e523950 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -154,6 +154,31 @@ static void del_tracked_method(RTMPContext *rt, int index) 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) { int i; @@ -1039,24 +1064,11 @@ 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; - bytestream2_init(&gbc, pkt->data + 10, pkt->data_size); - if ((ret = ff_amf_read_number(&gbc, &pkt_id)) < 0) + if ((ret = find_tracked_method(s, pkt, 10, &tracked_method)) < 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; - } - if (!tracked_method) { /* Ignore this reply when the current method is not tracked. */ return ret; |