Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Examples

cmml.h

Go to the documentation of this file.
00001 /* Copyright (C) 2003 CSIRO Australia
00002 
00003    Redistribution and use in source and binary forms, with or without
00004    modification, are permitted provided that the following conditions
00005    are met:
00006    
00007    - Redistributions of source code must retain the above copyright
00008    notice, this list of conditions and the following disclaimer.
00009    
00010    - Redistributions in binary form must reproduce the above copyright
00011    notice, this list of conditions and the following disclaimer in the
00012    documentation and/or other materials provided with the distribution.
00013    
00014    - Neither the name of the CSIRO nor the names of its
00015    contributors may be used to endorse or promote products derived from
00016    this software without specific prior written permission.
00017    
00018    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00021    PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
00022    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00025    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00026    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00027    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 */
00030 
00031 /* cmml.h */
00032 
00033 #ifndef __CMML_H__
00034 #define __CMML_H__
00035 
00043 #include <stdio.h>
00044 #include <expat.h>
00045 
00049 #ifndef _CMML_PRIVATE
00050 typedef void CMML;
00051 #endif
00052 
00053 /* ------------------------- TYPES --------------------------------- */
00054 /* CMML_Time and CMML_List are kept here and not in cmml_private.h   */
00055 /* because the library user may need detailed access to these fields */
00056 
00061 typedef struct {
00062   short   tm_hsec; 
00063   short   tm_sec;  
00064   short   tm_min;  
00065   short   tm_hour; 
00066   short   tm_mday; 
00067   short   tm_mon;  
00068   short   tm_year; 
00070 } CMML_UTC;
00071 
00075 typedef enum _CMML_Time_Type {
00076   CMML_SEC_TIME,   
00077   CMML_UTC_TIME    
00078 } CMML_Time_Type;
00079 
00080 
00085 typedef struct {
00086   char *tstr;          
00087   CMML_Time_Type type; 
00089   union {
00090     CMML_UTC * utc;    
00091     double sec;        
00092   } t;
00093 } CMML_Time ;
00094 
00095 
00099 typedef struct _CMML_List CMML_List;
00105 struct _CMML_List {
00106   CMML_List * prev; 
00107   CMML_List * next; 
00108   void * data;      
00109 };
00110 
00114 typedef void * (*CMML_CloneFunc) (void * data);
00115 
00119 typedef void * (*CMML_FreeFunc) (void * data);
00120 
00128 typedef int (*CMML_CmpFunc) (void * cmp_ctx, void * s1, void * s2);
00129 
00130 
00136 typedef struct {
00137   char *xml_version;      
00138   char *xml_encoding;     
00139   int   xml_standalone;   
00140   int   doctype_declared; 
00141   char *cmml_lang;        
00142   char *cmml_dir;         
00143   char *cmml_id;          
00144   char *cmml_xmlns;       
00145 } CMML_Preamble;
00146 
00147 
00152 typedef struct {
00153   char *id;    
00154   char *name;  
00155   char *value; 
00156 } CMML_ParamElement;
00157 
00161 typedef struct {
00162   char *id;               
00163   char *lang;             
00164   char *dir;              
00165   char *granulerate;      
00166   char *contenttype;      
00167   char *src;              
00168   CMML_Time * start_time; 
00169   CMML_Time * end_time;   
00170   char *title;            
00171   CMML_List * param;      
00173 } CMML_ImportElement;
00174 
00181 typedef struct {
00182   char *id;             
00183   CMML_Time * timebase; 
00184   CMML_Time * utc;      
00185   CMML_List * import;   
00186 } CMML_Stream;
00187 
00188 
00193 typedef struct {
00194   char *id;      
00195   char *lang;    
00196   char *dir;     
00197   char *name;    
00198   char *content; 
00199   char *scheme;  
00200 } CMML_MetaElement;
00201 
00205 typedef struct {
00206   char *head_id;    
00207   char *lang;       
00208   char *dir;        
00209   char *profile;    
00210   char *title;      
00211   char *title_id;   
00212   char *title_lang; 
00213   char *title_dir;  
00214   char *base_id;    
00215   char *base_href;  
00216   CMML_List * meta; 
00217 } CMML_Head;
00218 
00219 
00223 typedef struct {
00224   char *clip_id;         
00225   char *lang;            
00226   char *dir;             
00227   char *track;           
00228   CMML_Time *start_time; 
00229   CMML_Time *end_time;   
00230   CMML_List * meta;      
00231   char *anchor_id;       
00232   char *anchor_class;    
00233   char *anchor_lang;     
00234   char *anchor_dir;      
00235   char *anchor_href;     
00236   char *anchor_text;     
00237   char *img_id;          
00238   char *img_lang;        
00239   char *img_dir;         
00240   char *img_src;         
00241   char *img_alt;         
00242   char *desc_id;         
00243   char *desc_lang;       
00244   char *desc_dir;        
00245   char *desc_text;       
00246 } CMML_Clip;
00247 
00252 typedef enum _CMML_Element_Type {
00253   CMML_NONE,   
00254   CMML_CMML,   
00255   CMML_STREAM, 
00256   CMML_IMPORT, 
00257   CMML_HEAD,   
00258   CMML_CLIP    
00259 } CMML_Element_Type;
00260 
00261 
00267 typedef struct {
00268   CMML_Element_Type type; 
00270   union {
00271     CMML_Stream * stream; 
00272     CMML_Head   * head;   
00273     CMML_Clip   * clip;   
00274   } e;
00275 } CMML_Element;
00276 
00277 
00286 typedef enum _CMML_Error_Type {
00287   /* general processing feedback */
00288   CMML_OK,           
00289   CMML_EOF,          
00290   /* fatal errors */
00291   CMML_READ_ERROR,   
00292   CMML_TIME_ERROR,   
00293   CMML_MALLOC_ERROR, 
00294   CMML_EXPAT_ERROR,  
00295   CMML_PARSE_ERROR,  
00296   CMML_NO_CMML_TAG,  
00297   CMML_NO_HEAD_TAG,  
00298   CMML_STREAM_NOT_FIRST,  
00299   CMML_HEAD_AFTER_CLIP,   
00300   CMML_DUPLICATE_STREAM,  
00301   CMML_DUPLICATE_HEAD,    
00302   /* sloppy errors */
00303   CMML_FORMAT_ERROR,      
00304   CMML_UNKNOWN_TAG,       
00305   CMML_TAG_IGNORED,       
00306   CMML_XMLNS_REDEFINED,   
00307   CMML_NONSEQUENTIAL_CLIP 
00308 } CMML_Error_Type;
00309 
00314 typedef struct {
00315   CMML_Error_Type type; 
00316   long line;            
00317   long col;             
00318 } CMML_Error;
00319 
00331 typedef int (*CMMLReadStream)  (CMML *cmml, const CMML_Stream *stream,
00332                                void * user_data);
00344 typedef int (*CMMLReadHead)   (CMML *cmml, const CMML_Head *head,
00345                                void * user_data);
00346 
00358 typedef int (*CMMLReadClip) (CMML *cmml, const CMML_Clip *clip,
00359                                void * user_data);
00360 
00361 
00362 /* ----------------------  API  --------------------------------*/
00363 
00364 /* --------------------------------- *
00365  * CMML parsing: functions in cmml.c *
00366  * --------------------------------- */
00367 
00378 CMML * cmml_open (char *XMLfilename);
00379 
00391 CMML * cmml_new (FILE * file);
00392 
00401 FILE * cmml_destroy (CMML * cmml);
00402 
00411 CMML * cmml_close (CMML * cmml);
00412 
00428 int cmml_set_read_callbacks (CMML *cmml,
00429                              CMMLReadStream read_stream,
00430                              CMMLReadHead read_head,
00431                              CMMLReadClip read_clip,
00432                              void * user_data);
00433 
00446 long cmml_read (CMML *cmml, long n); /* file */
00447 
00457 void cmml_set_sloppy (CMML *cmml, int value);
00458 
00467 CMML_Preamble * cmml_get_preamble (CMML *cmml);
00468 
00477 CMML_Stream * cmml_get_last_stream (CMML *cmml);
00478 
00487 CMML_Head   * cmml_get_last_head   (CMML *cmml);
00488 
00497 CMML_Clip * cmml_get_last_clip (CMML *cmml);
00498 
00508 CMML_Clip * cmml_get_previous_clip (CMML *cmml);
00509 
00519 CMML_Error * cmml_get_last_error (CMML * cmml);
00520 
00521 
00527 void         cmml_error_clear (CMML * cmml);
00528 
00539 int cmml_set_window (CMML * cmml, CMML_Time * start, CMML_Time * end);
00540 
00550 double cmml_skip_to_secs (CMML *cmml, double seconds);
00551 
00561 double cmml_skip_to_utc  (CMML *cmml, const char * utc);
00562 
00572 double cmml_skip_to_id   (CMML *cmml, const char * id);
00573 
00583 double cmml_skip_to_offset (CMML *cmml, const char * offset);
00584 
00585 
00586 /* ---------------------------------------------------- *
00587  * CMML element handling: cmml_element.c cmml_snprint.c *
00588  * ---------------------------------------------------- */
00589 
00600 CMML_Preamble * cmml_preamble_new (char *encoding, char *id, char *lang, char *dir);
00601 
00609 CMML_Element * cmml_element_new (CMML_Element_Type type);
00610 
00616 CMML_Stream  * cmml_stream_new   (void);
00617 
00623 CMML_Head    * cmml_head_new    (void);
00624 
00633 CMML_Clip  * cmml_clip_new  (CMML_Time *start_time, CMML_Time *end_time);
00634 
00642 CMML_Error   * cmml_error_new   (CMML_Error_Type type);
00643 
00651 CMML_Preamble * cmml_preamble_clone (CMML_Preamble * src);
00652 
00660 CMML_Element * cmml_element_clone (CMML_Element * src);
00661 
00669 CMML_Stream  * cmml_stream_clone  (CMML_Stream  * src);
00670 
00678 CMML_Head    * cmml_head_clone    (CMML_Head    * src);
00679 
00687 CMML_Clip  * cmml_clip_clone  (CMML_Clip  * src);
00688 
00695 void cmml_preamble_destroy (CMML_Preamble *preamble);
00696 
00703 void cmml_element_destroy (CMML_Element *element);
00704 
00710 void cmml_stream_destroy  (CMML_Stream  *stream);
00711 
00717 void cmml_head_destroy    (CMML_Head    *head);
00718 
00724 void cmml_clip_destroy  (CMML_Clip  *clip);
00725 
00731 void cmml_error_destroy   (CMML_Error   *error);
00732 
00744 int cmml_preamble_snprint(char *buf, int n, CMML_Preamble *pre);
00745 
00758 int cmml_element_snprint        (char *buf, int n, CMML_Element *elem);
00759 
00770 int cmml_stream_snprint         (char *buf, int n, CMML_Stream  *stream);
00771 
00782 int cmml_stream_pretty_snprint  (char *buf, int n, CMML_Stream  *stream);
00783 
00794 int cmml_head_snprint           (char *buf, int n, CMML_Head    *head);
00795 
00806 int cmml_head_pretty_snprint    (char *buf, int n, CMML_Head    *head);
00807 
00818 int cmml_clip_snprint         (char *buf, int n, CMML_Clip  *clip);
00819 
00830 int cmml_clip_pretty_snprint  (char *buf, int n, CMML_Clip  *clip);
00831 
00843 int cmml_error_snprint (char *buf, int n, CMML_Error *error, CMML *cmml);
00844 
00845 
00846 /* ----------------------------------------------- *
00847  * helper functions for list handling: cmml_list.c *
00848  * ----------------------------------------------- */
00849 
00855 CMML_List * cmml_list_new        (void);
00856 
00864 CMML_List * cmml_list_clone      (CMML_List * list);
00865 
00874 CMML_List * cmml_list_clone_with (CMML_List * list, CMML_CloneFunc clone);
00875 
00883 CMML_List * cmml_list_tail       (CMML_List * list);
00884 
00893 CMML_List * cmml_list_prepend    (CMML_List * list, void * data);
00894 
00903 CMML_List * cmml_list_append     (CMML_List * list, void * data);
00904 
00915 CMML_List * cmml_list_add_before (CMML_List * list, void * data, 
00916                                   CMML_List * node);
00927 CMML_List * cmml_list_add_after  (CMML_List * list, void * data, 
00928                                   CMML_List * node);
00929 
00938 CMML_List * cmml_list_find       (CMML_List * list, void * data);
00939 
00948 CMML_List * cmml_list_remove     (CMML_List * list, CMML_List * node);
00949 
00957 int cmml_list_length             (CMML_List * list);
00958 
00966 int cmml_list_is_empty           (CMML_List * list);
00967 
00976 int cmml_list_is_singleton       (CMML_List * list);
00977 
00987 CMML_List * cmml_list_free_with   (CMML_List * list, 
00988                                    CMML_FreeFunc free_func);
00989 
00998 CMML_List * cmml_list_free       (CMML_List * list);
00999 
01000 
01001 /* ----------------------------------------------- *
01002  * helper functions for time handling: cmml_time.c *
01003  * ----------------------------------------------- */
01004 
01013 CMML_Time * cmml_time_new  (const char * s);
01014 
01022 CMML_Time * cmml_sec_new   (const char * s);
01023 
01031 CMML_Time * cmml_utc_new   (const char * s);
01032 
01046 int cmml_time_interval_new (const char * s, 
01047                             CMML_Time ** t_start, CMML_Time ** t_end);
01048 
01060 CMML_Time *cmml_time_new_in_sec (const char * s, CMML_Time * ref, double base);
01061 
01072 CMML_Time *cmml_time_utc_to_sec (CMML_Time * t, CMML_Time * ref, double base);
01073 
01079 void        cmml_time_free (CMML_Time *t);
01080 
01088 CMML_Time * cmml_time_clone   (CMML_Time *t);
01089 
01097 double cmml_sec_parse (const char *s);
01098 
01107 CMML_UTC * cmml_utc_parse (const char * s);
01108 
01116 CMML_UTC * cmml_utc_clone (CMML_UTC *t);
01117 
01127 double     cmml_utc_diff  (CMML_UTC *t2, CMML_UTC *t1);
01128 
01139 int        cmml_npt_snprint (char * buf, int n, double seconds);
01140 
01151 int        cmml_utc_snprint (char *buf, int n, CMML_UTC *t);
01152 
01163 int        cmml_utc_pretty_snprint (char *buf, int n, CMML_UTC *t);
01164 
01165 
01166 
01167 #endif /* __CMML_H__ */

Generated on Wed Apr 13 14:33:32 2005 for libcmml by  doxygen 1.4.2