media/libtheora/lib/info.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libtheora/lib/info.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,131 @@
     1.4 +/********************************************************************
     1.5 + *                                                                  *
     1.6 + * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE.   *
     1.7 + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
     1.8 + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
     1.9 + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
    1.10 + *                                                                  *
    1.11 + * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009                *
    1.12 + * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
    1.13 + *                                                                  *
    1.14 + ********************************************************************
    1.15 +
    1.16 +  function:
    1.17 +    last mod: $Id: info.c 16503 2009-08-22 18:14:02Z giles $
    1.18 +
    1.19 + ********************************************************************/
    1.20 +
    1.21 +#include <stdlib.h>
    1.22 +#include <ctype.h>
    1.23 +#include <string.h>
    1.24 +#include "internal.h"
    1.25 +
    1.26 +
    1.27 +
    1.28 +/*This is more or less the same as strncasecmp, but that doesn't exist
    1.29 +   everywhere, and this is a fairly trivial function, so we include it.
    1.30 +  Note: We take advantage of the fact that we know _n is less than or equal to
    1.31 +   the length of at least one of the strings.*/
    1.32 +static int oc_tagcompare(const char *_s1,const char *_s2,int _n){
    1.33 +  int c;
    1.34 +  for(c=0;c<_n;c++){
    1.35 +    if(toupper(_s1[c])!=toupper(_s2[c]))return !0;
    1.36 +  }
    1.37 +  return _s1[c]!='=';
    1.38 +}
    1.39 +
    1.40 +
    1.41 +
    1.42 +void th_info_init(th_info *_info){
    1.43 +  memset(_info,0,sizeof(*_info));
    1.44 +  _info->version_major=TH_VERSION_MAJOR;
    1.45 +  _info->version_minor=TH_VERSION_MINOR;
    1.46 +  _info->version_subminor=TH_VERSION_SUB;
    1.47 +  _info->keyframe_granule_shift=6;
    1.48 +}
    1.49 +
    1.50 +void th_info_clear(th_info *_info){
    1.51 +  memset(_info,0,sizeof(*_info));
    1.52 +}
    1.53 +
    1.54 +
    1.55 +
    1.56 +void th_comment_init(th_comment *_tc){
    1.57 +  memset(_tc,0,sizeof(*_tc));
    1.58 +}
    1.59 +
    1.60 +void th_comment_add(th_comment *_tc,char *_comment){
    1.61 +  char **user_comments;
    1.62 +  int   *comment_lengths;
    1.63 +  int    comment_len;
    1.64 +  user_comments=_ogg_realloc(_tc->user_comments,
    1.65 +   (_tc->comments+2)*sizeof(*_tc->user_comments));
    1.66 +  if(user_comments==NULL)return;
    1.67 +  _tc->user_comments=user_comments;
    1.68 +  comment_lengths=_ogg_realloc(_tc->comment_lengths,
    1.69 +   (_tc->comments+2)*sizeof(*_tc->comment_lengths));
    1.70 +  if(comment_lengths==NULL)return;
    1.71 +  _tc->comment_lengths=comment_lengths;
    1.72 +  comment_len=strlen(_comment);
    1.73 +  comment_lengths[_tc->comments]=comment_len;
    1.74 +  user_comments[_tc->comments]=_ogg_malloc(comment_len+1);
    1.75 +  if(user_comments[_tc->comments]==NULL)return;
    1.76 +  memcpy(_tc->user_comments[_tc->comments],_comment,comment_len+1);
    1.77 +  _tc->comments++;
    1.78 +  _tc->user_comments[_tc->comments]=NULL;
    1.79 +}
    1.80 +
    1.81 +void th_comment_add_tag(th_comment *_tc,char *_tag,char *_val){
    1.82 +  char *comment;
    1.83 +  int   tag_len;
    1.84 +  int   val_len;
    1.85 +  tag_len=strlen(_tag);
    1.86 +  val_len=strlen(_val);
    1.87 +  /*+2 for '=' and '\0'.*/
    1.88 +  comment=_ogg_malloc(tag_len+val_len+2);
    1.89 +  if(comment==NULL)return;
    1.90 +  memcpy(comment,_tag,tag_len);
    1.91 +  comment[tag_len]='=';
    1.92 +  memcpy(comment+tag_len+1,_val,val_len+1);
    1.93 +  th_comment_add(_tc,comment);
    1.94 +  _ogg_free(comment);
    1.95 +}
    1.96 +
    1.97 +char *th_comment_query(th_comment *_tc,char *_tag,int _count){
    1.98 +  long i;
    1.99 +  int  found;
   1.100 +  int  tag_len;
   1.101 +  tag_len=strlen(_tag);
   1.102 +  found=0;
   1.103 +  for(i=0;i<_tc->comments;i++){
   1.104 +    if(!oc_tagcompare(_tc->user_comments[i],_tag,tag_len)){
   1.105 +      /*We return a pointer to the data, not a copy.*/
   1.106 +      if(_count==found++)return _tc->user_comments[i]+tag_len+1;
   1.107 +    }
   1.108 +  }
   1.109 +  /*Didn't find anything.*/
   1.110 +  return NULL;
   1.111 +}
   1.112 +
   1.113 +int th_comment_query_count(th_comment *_tc,char *_tag){
   1.114 +  long i;
   1.115 +  int  tag_len;
   1.116 +  int  count;
   1.117 +  tag_len=strlen(_tag);
   1.118 +  count=0;
   1.119 +  for(i=0;i<_tc->comments;i++){
   1.120 +    if(!oc_tagcompare(_tc->user_comments[i],_tag,tag_len))count++;
   1.121 +  }
   1.122 +  return count;
   1.123 +}
   1.124 +
   1.125 +void th_comment_clear(th_comment *_tc){
   1.126 +  if(_tc!=NULL){
   1.127 +    long i;
   1.128 +    for(i=0;i<_tc->comments;i++)_ogg_free(_tc->user_comments[i]);
   1.129 +    _ogg_free(_tc->user_comments);
   1.130 +    _ogg_free(_tc->comment_lengths);
   1.131 +    _ogg_free(_tc->vendor);
   1.132 +    memset(_tc,0,sizeof(*_tc));
   1.133 +  }
   1.134 +}

mercurial