1 /********************************************************************
3 * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2007 *
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
11 ********************************************************************
14 last mod: $Id: info.c 13884 2007-09-22 08:38:10Z giles $
16 ********************************************************************/
21 #include "../internal.h"
25 /*This is more or less the same as strncasecmp, but that doesn't exist
26 everywhere, and this is a fairly trivial function, so we include it.
27 Note: We take advantage of the fact that we know _n is less than or equal to
28 the length of at least one of the strings.*/
29 static int oc_tagcompare(const char *_s1
,const char *_s2
,int _n
){
32 if(toupper(_s1
[c
])!=toupper(_s2
[c
]))return !0;
39 void th_info_init(th_info
*_info
){
40 memset(_info
,0,sizeof(*_info
));
41 _info
->version_major
=TH_VERSION_MAJOR
;
42 _info
->version_minor
=TH_VERSION_MINOR
;
43 _info
->version_subminor
=TH_VERSION_SUB
;
44 _info
->keyframe_granule_shift
=6;
47 void th_info_clear(th_info
*_info
){
48 memset(_info
,0,sizeof(*_info
));
53 void th_comment_init(th_comment
*_tc
){
54 memset(_tc
,0,sizeof(*_tc
));
57 void th_comment_add(th_comment
*_tc
,char *_comment
){
59 _tc
->user_comments
=_ogg_realloc(_tc
->user_comments
,
60 (_tc
->comments
+2)*sizeof(*_tc
->user_comments
));
61 _tc
->comment_lengths
=_ogg_realloc(_tc
->comment_lengths
,
62 (_tc
->comments
+2)*sizeof(*_tc
->comment_lengths
));
63 comment_len
=strlen(_comment
);
64 _tc
->comment_lengths
[_tc
->comments
]=comment_len
;
65 _tc
->user_comments
[_tc
->comments
]=_ogg_malloc(comment_len
+1);
66 memcpy(_tc
->user_comments
[_tc
->comments
],_comment
,comment_len
+1);
68 _tc
->user_comments
[_tc
->comments
]=NULL
;
71 void th_comment_add_tag(th_comment
*_tc
,char *_tag
,char *_val
){
77 /*+2 for '=' and '\0'.*/
78 comment
=_ogg_malloc(tag_len
+val_len
+2);
79 memcpy(comment
,_tag
,tag_len
);
81 memcpy(comment
+tag_len
+1,_val
,val_len
+1);
82 th_comment_add(_tc
,comment
);
86 char *th_comment_query(th_comment
*_tc
,char *_tag
,int _count
){
92 for(i
=0;i
<_tc
->comments
;i
++){
93 if(!oc_tagcompare(_tc
->user_comments
[i
],_tag
,tag_len
)){
94 /*We return a pointer to the data, not a copy.*/
95 if(_count
==found
++)return _tc
->user_comments
[i
]+tag_len
+1;
98 /*Didn't find anything.*/
102 int th_comment_query_count(th_comment
*_tc
,char *_tag
){
106 tag_len
=strlen(_tag
);
108 for(i
=0;i
<_tc
->comments
;i
++){
109 if(!oc_tagcompare(_tc
->user_comments
[i
],_tag
,tag_len
))count
++;
114 void th_comment_clear(th_comment
*_tc
){
117 for(i
=0;i
<_tc
->comments
;i
++)_ogg_free(_tc
->user_comments
[i
]);
118 _ogg_free(_tc
->user_comments
);
119 _ogg_free(_tc
->comment_lengths
);
120 _ogg_free(_tc
->vendor
);
121 memset(_tc
,0,sizeof(*_tc
));