Sink elements uses the ISink interface to get notifications when it is allowed to and when it is not allowed to hold HAI resources.
On ISink::Activate, a sink element may open any HAI resource instance it needs, such as a video decoder in the case of a video sink element. All open HAI resources must be closed on ISink::Deactivate.
Every element that wish to receive event callbacks from the HAL must be prepared to initialize the callback channel. In ISink::Activate, the element must call the IHaiSystem_EnableCallbacks function. Although several elements may call this function, HAI makes sure that the callback channel from the HAL Server to the Streamer is initialized once for all elements collectively on the first call. An element cannot know if it is the first element using HAI callbacks, so it is important that all elements using HAI callbacks perform the same operation, and HAI will determine when to actually do the initialization.
The file descriptor parameter returned from the IHaiSystem_EnableCallbacks function must be registered in the event system using the IEvent interface. The element must call the IEvent::AddFileDescriptorFunction function with the file descriptor as first argument, EVENT_READ as second argument, and the IHaiSystem_HandleEventFd function as third argument. Do not use IEvent::AddFileDescriptor in this case, because that will prevent the event system from correctly handling situations when output pads are closed and elements therefore are removed from the pipeline.
When the HAI callback descriptor gets signalled because of a HAI callback, the event system will call the registered IHaiSystem_HandleEventFd function automatically to dispatch the event.
An element that calls IHaiSystem_EnableCallbacks and IEvent::AddFileDescriptorFunction on ISink::Activate must call IEvent::RemoveFileDescriptorFunction and IHaiSystem_DisableCallbacks on ISink::Deactivate. Every successful enable must be balanced by a disable, and every successful add must be balanced by a remove.