[vlc-devel] Re: Overloading

Stephane stephane at virtuosomedia.nl
Tue Dec 10 11:43:44 CET 2002


part 2: my suggestion:

in modules.h:
typedef struct function_list_s
{
    union
    {
    ...
         /* Demux plugin */
        struct
        {
            int  ( * pf_init ) ( struct input_thread_s * );
            void ( * pf_end )  ( struct input_thread_s * );
            int  ( * pf_demux )( struct input_thread_s * );
            int  ( * pf_rewind )   ( struct input_thread_s * );
            /* default overloadable functions */
            void ( * pf_parse_pes ) ( struct input_thread_s * , struct
es_descriptor_s * p_es );
            void ( * pf_gather_pes) ( struct input_thread_s * p_input,
struct data_packet_s * p_data,
                      struct es_descriptor_s * p_es, boolean_t b_unit_start,
boolean_t b_packet_lost );
            ssize_t ( * pf_read_ps ) ( struct input_thread_s * p_input,
                      struct data_packet_s ** pp_data );
            struct es_descriptor_s * ( * pf_parse_ps ) ( struct
input_thread_s * p_input,
                      struct data_packet_s * p_data );
            void ( * pf_demux_ps ) ( struct input_thread_s * p_input, struct
data_packet_s * p_data );
            ssize_t ( * pf_read_ts ) ( struct input_thread_s * p_input,
                      struct data_packet_s ** pp_data );
            void  ( * pf_demux_ts ) ( struct input_thread_s * p_input,
                      struct data_packet_s * p_data,
                      void * );
            void ( * pf_delete_pes ) ( struct input_buffers_s * p_buffers,
                      struct pes_packet_s * p_pes );
            void ( * pf_decode_pes ) ( struct decoder_fifo_s *
p_decoder_fifo,
                      struct pes_packet_s * p_pes );
        } demux;
    ...
    }
};

in configuration.h:
/***************************************************************************
**
 * Macros used to build the 'overloadable' function table

****************************************************************************
/
#define  SETUPDEMUXDEFAULTS(demux) \
     demux.pf_parse_pes   = input_ParsePES; \
     demux.pf_gather_pes   = input_GatherPES; \
     demux.pf_read_ps   = input_ReadPS; \
     demux.pf_parse_ps   = input_ParsePS; \
     demux.pf_demux_ps   = input_DemuxPS; \
     demux.pf_read_ts   = input_ReadTS; \
     demux.pf_demux_ts   = input_DemuxTS; \
     demux.pf_delete_pes   = input_DeletePES; \
     demux.pf_decode_pes   = input_DecodePES;

in custom_demux.c:
/***************************************************************************
**
 * Functions exported as capabilities. They are declared as static so that
 * we don't pollute the namespace too much.

****************************************************************************
*/
static void input_getfunctions( function_list_t * p_function_list )
{
#define input p_function_list->functions.demux
    input.pf_init             = MyInit;
    input.pf_end              = MyEnd;
    input.pf_demux            = MyDemux;
    input.pf_rewind           = NULL;
 SETUPDEMUXDEFAULTS(input);
    input.pf_decode_pes    = MyDecodePES;
#undef input
}

and e.g. in mpeg_system.c, in input_ParsePES:
...
       /* Now we can eventually put the PES packet in the decoder's
         * PES fifo */
        if( p_es->p_decoder_fifo != NULL )
        {
#define ft p_input->p_demux_module->p_functions->demux.functions.demux
            ft.pf_decode_pes( p_es->p_decoder_fifo, p_pes );
        }
...
i. s. o.
       /* Now we can eventually put the PES packet in the decoder's
         * PES fifo */
        if( p_es->p_decoder_fifo != NULL )
        {
            input_DecodePES(  p_es->p_decoder_fifo, p_pes );
        }

In this way, one can easily overload some of the system functions, withaout
the necessity to rewrite all stuff. Most functions
are useful anyway, one only needs to add some functionality on a few places,
without breaking the code for other applications/plugins.

Problem with this solution is, all plugins will have to add the appropriate
macro to the <MODULE_TYPE>_getfunctions function.
Does anyone have a solution for this?  Maybe some smart macro in
MODULE_ACTIVATE_START?

And it have to be decided which functions will become 'virtual' and the call
to these functions will all have to be replaced with a
call with a function pointer, as above example in input_ParsePES. Quite some
work:)

Stephane
VirtuosoMedia
  -----Oorspronkelijk bericht-----
  Van: vlc-devel-bounce at videolan.org
[mailto:vlc-devel-bounce at videolan.org]Namens Stephane van Hardeveld
  Verzonden: maandag 9 december 2002 16:45
  Aan: vlc-devel at videolan.org
  Onderwerp: [vlc-devel] Overloading


  Hi all,

  I am trying to create some demux plugin for our MPEG PS streams. I
succeeded in parsing our
  PSM look-alike and create decode threads etc. I even succeeded in creating
video on screen and
  audio from the speakers (if I am able to do this, the code-base must be
built really good and structured :) )
  However, now I need to do something special just before calling
'input_DecodePES( p_es->p_decoder_fifo, p_pes )'
  namely descramble the pes payload. I could of course include all functions
of mpeg_system.c into my plugin,
  but I was wondering whether it is possible to use some form of overloading
or function table and just change the
  used Decode_PES function.

  Stephane van Hardeveld
  VirtuosoMedia

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20021210/b0a70e9d/attachment.html>


More information about the vlc-devel mailing list