📄 codecs.html
字号:
<p>There is one function, which will free all the data returned from the abovefunctions: </p><p><tt>void lqt_destroy_codec_info(lqt_codec_info_t ** info);</tt> <br><tt></tt> </p><p>Currently, there is no codec with support for decoding parameters, but this might change in future versions. </p><h3> <a name="codec_hacker"></a>3. API for Codec developers</h3> <a name="codec_intro"></a><b>3.1 Introduction</b> <p>The codecs itself work the same way as quicktime4linux codecs. Several codecs (any combination of audio/video en- and decoders) can be in one sharedmodule. How to define the codecs and how to write the interface functionsfor access by libquicktime is described here. For the codec interface specificparts of your module, you always need to include the file lqt_codecapi.h. </p><p>A quicktime codec is defined in qtprivate.h as:<tt></tt> </p><p><tt>typedef struct<br> {<br> int (*delete_vcodec)(quicktime_video_map_t *vtrack);<br> int (*delete_acodec)(quicktime_audio_map_t *atrack);<br> int (*decode_video)(quicktime_t *file, unsigned char **row_pointers, int track);<br> int (*encode_video)(quicktime_t *file, unsigned char **row_pointers, int track);<br> int (*decode_audio)(quicktime_t *file, int16_t *output_i, float *output_f, <br> long samples, int track, int channel);<br> int (*encode_audio)(quicktime_t *file, int16_t **input_i, float **input_f, <br> int track, long samples);<br> int (*reads_colormodel)(quicktime_t *file, int colormodel, int track);<br> int (*writes_colormodel)(quicktime_t *file, int colormodel, int track);<br> int (*set_parameter)(quicktime_t *file, int track, char *key, void *value);<br> void (*flush)(quicktime_t *file, int track);<br> <br> void *priv;<br> void *module; /* Needed by libquicktime for dynamic loading */</tt> <br><tt> char *name;<br> } quicktime_codec_t;</tt> </p><p>The module pointer is used by libquicktime to dlclose() us, if we are notlonger needed. It should not be touched. The functions pointers are youractual en- and decoding functions (how they are written and what they dois described below). </p><p><a name="new_delete"></a><b>3.2 Creating and deleting codecs</b> </p><p>The interface function, which creates one codec sets the members of thequicktime_codec_t structure to the functions defined in our module. It mustbe defined in the sourcecode for each codec separately. </p><p>Example: You have written a video codec blup, which keeps additional datain a structure blup_t. The structure is created by blup_create_codec() anddestroyed by blup_delete_codec(). Your initialization function will looklike this (if blup is a video codec): </p><p><tt>void quicktime_init_codec_blup(quicktime_video_map_t *vtrack)</tt> <br><tt> {</tt> <br><tt> blup_t *codec = blup_create_codec();</tt> <br><tt> /* Init public items */</tt> <br><tt> ((quicktime_codec_t*)vtrack->codec)->priv = codec;</tt> <br><tt> ((quicktime_codec_t*)vtrack->codec)->delete_vcodec = delete_codec;</tt> <br><tt> ((quicktime_codec_t*)vtrack->codec)->decode_video = decode;</tt> <br><tt> ((quicktime_codec_t*)vtrack->codec)->encode_video = encode;</tt> <br><tt> ((quicktime_codec_t*)vtrack->codec)->reads_colormodel = reads_colormodel;</tt> <br><tt> ((quicktime_codec_t*)vtrack->codec)->writes_colormodel = writes_colormodel;</tt> <br><tt> ((quicktime_codec_t*)vtrack->codec)->set_parameter = set_parameter;</tt> <br><tt> }</tt> </p><p>The functions delete_codec(), encode(), decode(), reads_colormodel(), writes_colormodel()and set_parameter() should be defined in your source (ideally as static functionsin the same sourcefile). If your codec has no parameters, you don't needto define set_parameter(). The function pointer is NULL by default and libquicktimewon't try to set parameters then. For an audio codec, you set just set delete_acodec(),encode_audio(), decode_audio(), set_parameter() and flush(). Note that track->codecis defined as a void pointer in qtprivate.h (for whatever reason), so youalways need to cast it to quicktime_codec_t. The priv member of the codecis for storing private data of the codec (like our blup_t). </p><p><b><font color="#ff0000">Note:</font></b> </p><p><font color="#ff0000">The quicktime4linux codecs don't do any internal initialization in this function. Instead, the private codec structures havea flag, which is set to zero at at the beginning. Depending on this flag,the real initialization is then done at the beginning of the first call ofone of the encoding or decoding functions. The reason for this could be,that it should be possible to call quicktime_set_parameter() after quicktime_set_audio()or quicktime_set_video() when writing or after quicktime_open() when reading.</font> </p><p>When playback or encoding is finished a call to quicktime_close() will release all memory associated with the audio and video tracks of the file. For your codec, this will mean, that our delete_vcodec() or delete_acodec() are called. Since we have some private data allocated, we should free it then.The delete function will look like this for our blup video codec: </p><p><tt>static int delete_codec(quicktime_video_map_t *vtrack)</tt> <br><tt> {</tt> <br><tt> blup_t *codec;</tt> </p><p><tt> codec = (blup_t*)(((quicktime_codec_t*)vtrack->codec)->priv);</tt> <br><tt> blup_delete_codec(codec);</tt> <br><tt> }</tt> </p><p><a name="codecinfo"></a><b>3.3 Presenting ourselves to the outer world</b> </p><p>Libquicktime users now want to know something about the codecs contained in the module, e.g. their descriptions, parameters, your developer website etc. This is done by functions, which pass information structures to libquicktime. Imagine, you have written blup and blop (which share many routines, so theyare in one module). You need to define some static data structures. Theseare the fourccs of each codec, the encoding parameters, the decoding parametersand structures for the other informations. These are defined as follows: </p><p><tt>static char * fourccs_blup[] = { "BLUP", "BLU1", (char*)0 };</tt><tt></tt> </p><p><tt>static int encoding_colormodels_blup[] =</tt> <br><tt> {</tt> <br><tt> BC_YUV420P,</tt> <br><tt> LQT_COLORMODEL_NONE</tt> <br><tt> };</tt> <br><tt></tt> <tt></tt> </p><p><tt>static lqt_parameter_info_static_t encode_parameters_jpeg[] =</tt> <br><tt> {</tt> <br><tt> {</tt> <br><tt> "blup_quality",</tt> <br><tt> "Quality",</tt> <br><tt> LQT_PARAMETER_INT,</tt> <br><tt> {95 },</tt> <br><tt> 1,</tt> <br><tt> 100,</tt> <br><tt> (char**)0</tt> <br><tt> },</tt> <br><tt> {</tt> <br><tt> "blup_motion_search_radius",</tt> <br><tt> "Motion search radius",</tt> <br><tt> LQT_PARAMETER_INT,</tt> <br><tt> { 0 },</tt> <br><tt> 0,</tt> <br><tt> 15,</tt> <br><tt> (char**)0</tt> <br><tt> },</tt> <br><tt> { /* End of parameters */ }</tt> <br><tt> };</tt><tt></tt> </p><p><tt>static lqt_codec_info_static_t codec_info_blup =</tt> <br><tt> {</tt> <br><tt> name: "blup",</tt> <br><tt> long_name: "Blup",</tt> <br><tt> description: "Videocodec based on the bluplet transform algorithm",</tt> <br><tt> fourccs: fourccs_blup,</tt> <br><tt> type: LQT_CODEC_VIDEO,</tt> <br><tt> direction: LQT_DIRECTION_BOTH,</tt> <br><tt> encoding_parameters: (lqt_parameter_info_static_t*)0,</tt> <br><tt> decoding_parameters: (lqt_parameter_info_static_t*)0,</tt> <br><tt> encoding_colormodels: encoding_colormodels_blup,</tt> <br><tt> decoding_colormodel: BC_YUV420P</tt> <br><tt> };</tt> <br><tt></tt> <br><tt></tt> </p><p>The structures lqt_codec_parameter_info_static_t and lqt_codec_info_static_t have the same members as their nonstatic counterparts (see above), with theexception that all arrays must be NULL terminated (the num_* members aremissing) and the members, which are set by libquicktime, aren't there. </p><p>Imagine you have similar structures defined for the blop codec also. Younow need to program 2 functions, which pass this information to libquicktime. These look as follows: </p><p><tt>extern int get_num_codecs() { return 2; }</tt> </p><p><tt>extern lqt_codec_info_static_t * get_codec_info(int index)</tt> <br><tt> {</tt> <br><tt> switch(index)</tt> <br><tt> {</tt> <br><tt> case 0:</tt> <br><tt> return &codec_info_blup;</tt> <br><tt> case 1:</tt> <br><tt> return &codec_info_blop;</tt> <br><tt> }</tt> <br><tt> return (lqt_codec_info_static_t*)0; /* Keep gcc happy */</tt> <br><tt> }</tt> </p><p>The function get_num_codecs() is self explaining. The function get_codec_info() returns the lqt_codec_info_static_t structure, which will then be converted into a lqt_codec_info_t structure by libquicktime. </p><p><a name="passing"></a><b>3.4 Passing codecs to libquicktime</b> </p><p>When libqucktime wants to create a codec from the module, it calles onethe following functions, which must be defined in the module: </p><p><tt>extern lqt_init_video_codec_func_t get_video_codec(int index);</tt> <br><tt>extern lqt_inif_audio_codec_func_t get_audio_codec(int index);</tt> </p><p>The return values are the same as the function prototypes, which create codecs in quicktime4linux: </p><p><tt>typedef void (* lqt_init_video_codec_func_t)(quicktime_video_map_t *);</tt> <br><tt>typedef void (* lqt_init_audio_codec_func_t)(quicktime_audio_map_t *);</tt> </p><p>You need only one of these functions if your module has only audio or onlyvideo codecs. For the blup and blop codecs we would write the following: </p><p><tt>extern lqt_init_video_codec_func_t get_video_codec(int index)</tt> <br><tt> {</tt> <br><tt> switch(index)</tt> <br><tt> {</tt> <br><tt> case 0:</tt> <br><tt> return quicktime_init_codec_blup;</tt> <br><tt> case 1:</tt> <br><tt> return quicktime_inif_codec_blop;</tt> <br><tt> }</tt> <br><tt> return (lqt_init_video_codec_func_t)0;</tt> <br><tt> }</tt> </p><p>The return values are the functions for creating single codecs as described above. </p><p><b>A note for all, who think, this is too complicated:</b> </p><p>Remember the flexibility, we can have with this interface. We can port codecs between libquicktime and quicktime4linux by just adding/removing thelibquicktime structures and functions described above. Since you must definethe interface functions yourself, you can give them an arbitrary level ofintellegence. The mjpa and jpeg codecs for example, share the functions andencoding parameters but have different names and descriptions. All this ispossible. </p><p><a name="encode_video"></a><b>3.5 Encoding video</b> </p><p>This part is currently unknown to the author. Use the codec source to reseachthis. </p><p><a name="decode_video"></a><b>3.6 Decoding video</b> </p><p>This part is currently unknown to the author. Use the codec source to reseachthis. </p><p><a name="encoding_audio"></a><b>3.7 Encoding audio</b> </p><p>This part is currently unknown to the author. Use the codec source to reseachthis. </p><p><a name="decode_audio"></a><b>3.8 Decoding audio</b> </p><p>This part is currently unknown to the author. Use the codec source to reseachthis. <br> </p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -