[pulseaudio-discuss] sink-input.c: pa_sink_input_new vs PA_CORE_HOOK_SINK_INPUT_FIXATE

Nick Thompson rextanka at comcast.net
Fri May 16 09:58:07 PDT 2008


I'm writing a module to tag streams so that a routing policy can be  
implemented.  Tanu suggested a mechanism by which I can get called  
back each time a new sink-input comes in and this mechanism works,  
however I'm having an issue trying to access the index for the stream.

The index is not assigned until the end of pa_sink_input_new where the  
data passed in has been verified.  Long after FIXATE.  Here's a bit of  
background.

There are two hooks in pa_sink_input_new (which is implemented in sink- 
input.c):

PA_CORE_HOOK_SINK_INPUT_NEW
PA_CORE_HOOK_SINK_INPUT_FIXATE

The callback associated with PA_CORE_HOOK_SINK_INPUT_NEW is called  
early on and is useful for messing with any fields in the  
pa_sink_input_new data structure that is passed in.

The fixate call is called late in the verification of data (prior to  
determining if there is a free sink-input slot and prior to verifying  
the requested resampling operation is supported).

The remaining code in the function deals with setting up all of the  
fields for the actual sink input based on the verified data.

It would be convenient to get at the sink-input (i.e. what is created  
in the pa_sink_input struct, i in this routine) immediately after it  
is created and verified from the verified pa_sink_input_new_data that  
is passed into pa_sink_input_new - I'd really like to get the index of  
the newly created sink input here so I can correlate it with the null  
sink I created it against and subsequently redirected, and which I may  
wish to further redirect in the future.  Alternatively I could add  
another hook, but I'd first like to understand why the FIXATE call is  
where it is in the routine.  I think it's to allow any changes to be  
made to data after verification has taken place, or for the verified  
data to be inspected prior to actual creation of the sink input.

Would moving FIXATE towards the end of the routine be appropriate (I  
suspect that moving it could have undesirable side effects if external  
hook functions in people's modules  were relying on returning anything  
other than PA_HOOK_OK, or in further manipulating data.  However  
manipulating the data after it's been verified is a potentially risky  
move).

So my question is: Is the FIXATE call in the correct place?

Would a reasonable way to get at the input_stream at creation time be  
to add another hook at the end of pa_sink_input_new to get access to  
the actual index assigned to the sink_input?  Or would it be "better"  
to move FIXATE to the end of the routine?

Now it's obvious that the index is not immediately available to the  
data passed into the fixate hook, however it could be obtained in the  
following way if this is called after the index has been assigned (it  
does the rely in the assumption that the index always increases, and  
that the last assigned index is the highest index extant in the  
idxset, but this seems to be true):

         inputcount = pa_idxset_size(data->sink->inputs);
         sinkinput = PA_SINK_INPUT(pa_idxset_first(data->sink->inputs,  
&idx));

         for (i = 0; i < inputcount ; i++) {

             if(idx > lastusedhighestindexforsink)
                 lastusedhighestindexforsink = idx;

             sinkinput = PA_SINK_INPUT(pa_idxset_next(data->sink- 
 >inputs, &idx));

         }

I just need to get a unique reference to the actual sink_input  
instance that is created to tie against the pa_sink_input_new_data  
that's passed in, the information in pa_sink_input_new_data is still  
generic until the actual sink_input is created.

Any pointers gratefully received.

Thanks

Nick



More information about the pulseaudio-discuss mailing list