Re: Message negociation
"Toby Hudon" <[email protected]>
| Newsgroups | gmane.comp.multimedia.media-api |
|---|---|
| Message-ID | <[email protected]> |
----- Original Message ----- From: Steve Lhomme <[email protected]> Date: Thu, 08 Jan 2004 10:08:26 +0100 To: "The attempt to create a new, open standard codec API" <[email protected]> Subject: Re: [Media-api] Message negociation > Artem Baguinski wrote: > > > the vtables with NULLs for not-implemented "methods" will be even more > > efficient, cause you request all callbacks at once ;) > > Nop, that's not the same thing. If you request everything at once, that > means you know the order of things in the vtable, ie using a fixed > struct. Hopefully the impact of using a struct is less important than > "message" parameters. You can add new callbacks at the end. Hopefully we > will never have a system with 5000 callbacks/message :) (and even though > it can still be handled by mosts systems) > > So I agree with the vtable requested on "init". Something that would > look like this : > > typedef struct dialog_vtable { > int (*callback1)(void); > void (*callback2)(int); > long (*callback3)(long, void *); > .... > }; > > int get_your_vtable(dialog_vtable *table_to_fill, int size_of_this_table); > > Depending on the "size_of_this_table" you know when to stop filling the > structure (or fill it with NULL when you support less features). > > As said before, the structure has to be updated at the end, *always*. > What about passed it as a linked list? Then you could just pass list entries with the pointer to the function and an ID code for the function, which the reciever then uses to map into a static table. So for example you'd call GetSupportedFunctions(void* fList, int* count); The filter you call would then give you the number of functions it supports plus a linked list containing their pointers. Then you could just map the function pointers to functions on your side until you either have everything you need or you reach the end of the list, then assume the rest are NULL. If you still wanted a static table on your side with NULLs for the non-supported entries you could still build it, but this way would mean not having to have a huge table where many entries could be NULL all the time and passing it around. Obviously this has more overhead than passing an array in many cases but since it's dynamic there's never any wasted space, i.e. a filter that supports 4 functions out of a 250 function API that has basicly means we'll have static tables with 246 NULLs in them. Also since this is only done on init, the penalty would only be at setup, not during execution. So your call in init would look like this (pseudocode): ---------------------------- pNextFilter->GetSupportedFunctions(myList, listCount); listNode* head = myList; listNode* current = head; int i = 0; int j = 0; for(i = listCount-1; i >= 0; i--) // while we have entries { for(j = 0; j <= i; j++) // find the current end of the list { current = current->pNext; // follow list } // end for j switch(current->functionID) // check what function is at the end of the list { case FOO: fpMyFooFunction = current->fpointer; // map function to our pointer break; ... ... default: // we don't map functions we don't understand break; } } // end for i ------------------------- Sorry about the lack of indents, I can't figure out how to get tabs to preserve over email. Obviously anything we haven't mapped by the end of this code will be NULL, which it should have been set as when we set it up anyway. Anything we do not support gets ignored because we don't recognized the function ID and it defaults to do nothing. -- ___________________________________________________________ Sign-up for Ads Free at Mail.com http://promo.mail.com/adsfreejump.htm