[rtmpdump] [PATCH] AMF Object Callback
hyc at highlandsun.com
Sat Jul 30 01:12:09 CEST 2011
Chris Larsen wrote:
>> Static global variables that might get manipulated from multiple threads
> are absolutely forbidden. Changing the global library state like this is
> forbidden. Doing
>> either of these things invites all kinds of crashes and other mysterious
>> A patch that extends the RTMP structure might be acceptable. The AMF_Dump
> function is primarily a debug function, you should not abuse it this way.
> Good points. I moved the callback pointer to the RTMP struct as you said so
> that it's thread safe. It is initialized to NULL when RTMP_Init() is called.
> Then I moved the calls to the HandleInvoke and HandleMeta methods.
> RTMP_Close() will NULL out the pointer and I added another method that an
> app can call to explicitly release the callback. Please let me know what you
> think and thank you.
So I guess this list has become the C Programming workshop.
Except for very trivial cases, I don't see that the current approach is of
much use. If you wanted to write a callback that intercepts a particular type
of message and computes a reply to send back, the callback function at least
needs to also get the RTMP * pointer as an argument. If you want to write a
callback that accesses some other variables in the program, you at least need
to give it a context pointer that can be set to point to a structure
containing whatever other data it needs.
Also, if you want to intercept a particular message and then act on it, you
probably need to be able to return a result code. I would say
#define AMF_CB_CONTINUE 0xffff /* continue with normal processing */
#define AMF_CB_SUCCESS 0 /* callback did everything, stop processing */
/* any other value: error code, stop processing */
So your prototype should look like:
typedef int (AMF_ObjectCallback)(RTMP *, AMFObject *, void *);
void RTMP_SetAMFCallback(RTMP *r, AMFObject *obj, void *ctx)
The other problem with all of this is that it requires the callback to
duplicate a lot of librtmp's parsing before it can discover if it actually
needs to do anything.
So again, the question is - what good is this? How do you actually expect to
be able to use this feature? Give an actual example, one that would actually
work, given what you've proposed.
More information about the rtmpdump