# MSSync

## Name

MSSync -- The base object for implementing synchronization.

## Synopsis

    #include <mssync.h>

    struct      MSSync;
    int         ms_sync_attach                  (MSSync *sync,
                                                 MSFilter *f);
    int         ms_sync_detach                  (MSSync *sync,
                                                 MSFilter *f);

## Description

A mediastreamer thread executes the synchronize() function of the MSSync object, then all the processing functions of the chain of filters attached to the synchronisation. A synchronize function may do nothing, can wait for a timer, or can select for some file descriptors to change, etc... The developper is free to implement derivated objects of MSSync in order to satisfy its needs.

## Details

### struct MSSync

    struct MSSync {

    	struct _MSSyncClass *klass;
    	GMutex *lock;
    	MSFilter **attached_filters; /* pointer to a table of pointer of filters*/
    	GList *execution_list;     /* the list of filters to be executed. This is filled with compilation */
    	gint filters;   /*number of filters attached to the sync */
    	gint run;       /* flag to indicate whether the sync must be run or not */
    	GThread * thread;   /* the thread ressource if this sync is run by a thread*/
    	GCond *thread_cond;
    	GCond *stop_cond;
    	guint32 flags;
    	gint interval; /* in miliseconds*/
    #define MS_SYNC_NEED_UPDATE (0x0001)  /* a modification has occured in the processing chains
    							attached to this sync; so the execution list has to be updated */
    	guint samples_per_tick; /* number of bytes produced by sources of the processing chains*/
    	guint32 ticks;
    	guint32 time;	/* a time since the start of the sync expressed in milisec*/
    };

Only programmers creating new derivated objects of MSSync are interested in this object.

### ms_sync_attach ()

    int         ms_sync_attach                  (MSSync *sync,
                                                 MSFilter *f);

Attach a chain of filters to a synchronisation source sync. Filter f must be the first filter of the processing chain. In order to be run, each chain of filter must be attached to a synchronisation source, that will be responsible for scheduling the processing. Multiple chains can be attached to a single synchronisation.

sync : | A MSSync object.
f : | A MSFilter object.
Returns : | 0 if successfull, a negative value reprensenting the errno.h error.

### ms_sync_detach ()

    int         ms_sync_detach                  (MSSync *sync,
                                                 MSFilter *f);

Dettach a chain of filters to a synchronisation source. Filter f must be the first filter of the processing chain. The processing chain will no more be executed.

sync : | A MSSync object.
f : | A MSFilter object.
Returns : | 0 if successfull, a negative value reprensenting the errno.h error.