[rtmpdump] r486 - in trunk/librtmp: rtmp.c rtmp.h
hyc
subversion at mplayerhq.hu
Thu May 27 19:35:00 CEST 2010
Author: hyc
Date: Thu May 27 19:34:59 2010
New Revision: 486
Log:
Finally fix the half-assed request/result queue
Modified:
trunk/librtmp/rtmp.c
trunk/librtmp/rtmp.h
Modified: trunk/librtmp/rtmp.c
==============================================================================
--- trunk/librtmp/rtmp.c Wed May 26 17:16:25 2010 (r485)
+++ trunk/librtmp/rtmp.c Thu May 27 19:34:59 2010 (r486)
@@ -2130,17 +2130,18 @@ RTMP_SendCtrl(RTMP *r, short nType, unsi
}
static void
-AV_erase(AVal *vals, int *num, int i, bool freeit)
+AV_erase(RTMP_METHOD *vals, int *num, int i, bool freeit)
{
if (freeit)
- free(vals[i].av_val);
+ free(vals[i].name.av_val);
(*num)--;
for (; i < *num; i++)
{
vals[i] = vals[i + 1];
}
- vals[i].av_val = NULL;
- vals[i].av_len = 0;
+ vals[i].name.av_val = NULL;
+ vals[i].name.av_len = 0;
+ vals[i].num = 0;
}
void
@@ -2150,24 +2151,25 @@ RTMP_DropRequest(RTMP *r, int i, bool fr
}
static void
-AV_queue(AVal **vals, int *num, AVal *av)
+AV_queue(RTMP_METHOD **vals, int *num, AVal *av, int txn)
{
char *tmp;
if (!(*num & 0x0f))
- *vals = realloc(*vals, (*num + 16) * sizeof(AVal));
+ *vals = realloc(*vals, (*num + 16) * sizeof(RTMP_METHOD));
tmp = malloc(av->av_len + 1);
memcpy(tmp, av->av_val, av->av_len);
tmp[av->av_len] = '\0';
- (*vals)[*num].av_len = av->av_len;
- (*vals)[(*num)++].av_val = tmp;
+ (*vals)[*num].num = txn;
+ (*vals)[*num].name.av_len = av->av_len;
+ (*vals)[(*num)++].name.av_val = tmp;
}
static void
-AV_clear(AVal *vals, int num)
+AV_clear(RTMP_METHOD *vals, int num)
{
int i;
for (i = 0; i < num; i++)
- free(vals[i].av_val);
+ free(vals[i].name.av_val);
free(vals);
}
@@ -2203,7 +2205,7 @@ HandleInvoke(RTMP *r, const char *body,
{
AMFObject obj;
AVal method;
- double txn;
+ int txn;
int ret = 0, nRes;
if (body[0] != 0x02) /* make sure it is a string method name we start with */
{
@@ -2221,13 +2223,26 @@ HandleInvoke(RTMP *r, const char *body,
AMF_Dump(&obj);
AMFProp_GetString(AMF_GetProp(&obj, NULL, 0), &method);
- txn = AMFProp_GetNumber(AMF_GetProp(&obj, NULL, 1));
+ txn = (int)AMFProp_GetNumber(AMF_GetProp(&obj, NULL, 1));
RTMP_Log(RTMP_LOGDEBUG, "%s, server invoking <%s>", __FUNCTION__, method.av_val);
if (AVMATCH(&method, &av__result))
{
- AVal methodInvoked = r->m_methodCalls[0];
- AV_erase(r->m_methodCalls, &r->m_numCalls, 0, false);
+ AVal methodInvoked = {0};
+ int i;
+
+ for (i=0; i<r->m_numCalls; i++) {
+ if (r->m_methodCalls[i].num == txn) {
+ methodInvoked = r->m_methodCalls[i].name;
+ AV_erase(r->m_methodCalls, &r->m_numCalls, i, false);
+ break;
+ }
+ }
+ if (!methodInvoked.av_val) {
+ RTMP_Log(RTMP_LOGDEBUG, "%s, received result id %d without matching request",
+ __FUNCTION__, txn);
+ goto leave;
+ }
RTMP_Log(RTMP_LOGDEBUG, "%s, received result for method call <%s>", __FUNCTION__,
methodInvoked.av_val);
@@ -2308,7 +2323,7 @@ HandleInvoke(RTMP *r, const char *body,
{
int i;
for (i = 0; i < r->m_numCalls; i++)
- if (AVMATCH(&r->m_methodCalls[i], &av__checkbw))
+ if (AVMATCH(&r->m_methodCalls[i].name, &av__checkbw))
{
AV_erase(r->m_methodCalls, &r->m_numCalls, i, true);
break;
@@ -2348,7 +2363,7 @@ HandleInvoke(RTMP *r, const char *body,
r->m_bPlaying = true;
for (i = 0; i < r->m_numCalls; i++)
{
- if (AVMATCH(&r->m_methodCalls[i], &av_play))
+ if (AVMATCH(&r->m_methodCalls[i].name, &av_play))
{
AV_erase(r->m_methodCalls, &r->m_numCalls, i, true);
break;
@@ -2362,7 +2377,7 @@ HandleInvoke(RTMP *r, const char *body,
r->m_bPlaying = true;
for (i = 0; i < r->m_numCalls; i++)
{
- if (AVMATCH(&r->m_methodCalls[i], &av_publish))
+ if (AVMATCH(&r->m_methodCalls[i].name, &av_publish))
{
AV_erase(r->m_methodCalls, &r->m_numCalls, i, true);
break;
@@ -2398,7 +2413,7 @@ HandleInvoke(RTMP *r, const char *body,
int i;
for (i = 0; i < r->m_numCalls; i++)
{
- if (AVMATCH(&r->m_methodCalls[i], &av_set_playlist))
+ if (AVMATCH(&r->m_methodCalls[i].name, &av_set_playlist))
{
AV_erase(r->m_methodCalls, &r->m_numCalls, i, true);
break;
@@ -2409,6 +2424,7 @@ HandleInvoke(RTMP *r, const char *body,
{
}
+leave:
AMF_Reset(&obj);
return ret;
}
@@ -3257,11 +3273,17 @@ RTMP_SendPacket(RTMP *r, RTMPPacket *pac
if (packet->m_packetType == 0x14)
{
AVal method;
- AMF_DecodeString(packet->m_body + 1, &method);
+ char *ptr;
+ ptr = packet->m_body + 1;
+ AMF_DecodeString(ptr, &method);
RTMP_Log(RTMP_LOGDEBUG, "Invoking %s", method.av_val);
/* keep it in call queue till result arrives */
- if (queue)
- AV_queue(&r->m_methodCalls, &r->m_numCalls, &method);
+ if (queue) {
+ int txn;
+ ptr += 3 + method.av_len;
+ txn = (int)AMF_DecodeNumber(ptr);
+ AV_queue(&r->m_methodCalls, &r->m_numCalls, &method, txn);
+ }
}
if (!r->m_vecChannelsOut[packet->m_nChannel])
Modified: trunk/librtmp/rtmp.h
==============================================================================
--- trunk/librtmp/rtmp.h Wed May 26 17:16:25 2010 (r485)
+++ trunk/librtmp/rtmp.h Thu May 27 19:34:59 2010 (r486)
@@ -200,6 +200,12 @@ extern "C"
uint32_t nIgnoredFlvFrameCounter;
} RTMP_READ;
+ typedef struct RTMP_METHOD
+ {
+ AVal name;
+ int num;
+ } RTMP_METHOD;
+
typedef struct RTMP
{
int m_inChunkSize;
@@ -222,7 +228,7 @@ extern "C"
int m_numInvokes;
int m_numCalls;
- AVal *m_methodCalls; /* remote method calls queue */
+ RTMP_METHOD *m_methodCalls; /* remote method calls queue */
RTMPPacket *m_vecChannelsIn[RTMP_CHANNELS];
RTMPPacket *m_vecChannelsOut[RTMP_CHANNELS];
More information about the rtmpdump
mailing list