Next: , Previous: , Up: Embedding API   [Contents][Index]


5.2.10 Codec functions

The codec interface of the Serveez core API supplies routines for setting up socket structures to perform encoding or decoding of its receive or send buffers. It is a transparent layer of buffer transition. The interface itself tries to unify different types of codecs. In order to add a new codec the programmer needs to write some wrapper functions around the actual implementation to fulfill certain entry and exit semantics of this interface.

Function: int svz_foreach_codec (svz_codec_do_t *func, void *closure)

Call func for each codec, passing additionally the second arg closure. If func returns a negative value, return immediately with that value (breaking out of the loop), otherwise, return 0.

Function: svz_codec_t * svz_codec_get (char *description, int type)

Find an appropriate codec for the given description and type (one of either SVZ_CODEC_ENCODER or SVZ_CODEC_DECODER). Return NULL if there is no such codec registered.

Function: void svz_codec_ratio (svz_codec_t *codec, svz_codec_data_t *data)

Print a text representation of a codec’s current ratio in percent if possible.

Function: int svz_codec_register (svz_codec_t *codec)

Register codec. Does not register invalid or duplicate codecs. Return zero on success, non-zero otherwise.

Function: int svz_codec_unregister (svz_codec_t *codec)

Remove codec from the list of known codecs. Return zero if the codec could be successfully removed, non-zero otherwise.

Function: int svz_codec_sock_receive_setup (svz_socket_t *sock, svz_codec_t *codec)

Arrange for sock to decode or encode its receive data via codec. Return zero on success, non-zero otherwise.

(You need to have set the check_request method previously for this to work.)

Function: int svz_codec_sock_receive (svz_socket_t *sock)

“This routine is the new check_request callback for reading codecs. It is applied in svz_codec_sock_receive_setup. Usually it gets called whenever there is data in the receive buffer. It lets the current receive buffer be the input of the codec. The output buffer of the codec gets the new receive buffer of sock. The old check_request callback of sock gets called afterwards. When leaving this function, the receive buffer gets restored again with the bytes snipped consumed by the codec itself.” [ttn sez: huh?]

Function: int svz_codec_sock_send_setup (svz_socket_t *sock, svz_codec_t *codec)

Arrange for sock to encode or decode its send buffer via codec. Return zero on success, non-zero otherwise.

(You need to have properly set the write_socket member of sock previously for this to work.)

Function: int svz_codec_sock_send (svz_socket_t *sock)

“This is the new write_socket callback for sock which is called whenever there is data within the send buffer available and sock is scheduled for writing. It uses the current send buffer as input buffer for the codec. The output buffer of the codec is used to invoke the write_socket callback saved within svz_codec_sock_send_setup. After this the send buffer is restored again without the bytes consumed by the codec.” [ttn sez: huh?]

Function: int svz_codec_sock_disconnect (svz_socket_t *sock)

Try to release the resources of both the receiving and sending codec of sock.

This callback is used as the disconnected_socket callback of the socket structure sock. It is called by default if the codec socket structure sock gets disconnected for some external reason.

Function: svz_codec_t * svz_codec_sock_detect (svz_socket_t *sock)

Return a valid codec detected by scanning the receive buffer of sock, or NULL if no codec could be detected.


Next: Server types, Previous: Coserver functions, Up: Embedding API   [Contents][Index]