"Fossies" - the Fresh Open Source Software Archive

Member "quicktime4linux-2.3/udta.c" (9 Jan 2007, 4665 Bytes) of package /linux/privat/old/quicktime4linux-2.3-src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include "funcprotos.h"
    2 #include "quicktime.h"
    3 #include <string.h>
    4 
    5 #define DEFAULT_INFO "Made with Quicktime for Linux"
    6 static unsigned char cpy_tag[] = {0xa9, 'c', 'p', 'y'};
    7 static unsigned char nam_tag[] = {0xa9, 'n', 'a', 'm'};
    8 static unsigned char inf_tag[] = {0xa9, 'i', 'n', 'f'};
    9 static unsigned char req_tag[] = {0xa9, 'r', 'e', 'q'};
   10 static unsigned char enc_tag[] = {0xa9, 'e', 'n', 'c'};
   11 
   12 int quicktime_udta_init(quicktime_udta_t *udta)
   13 {
   14     udta->copyright = 0;
   15     udta->copyright_len = 0;
   16     udta->name = 0;
   17     udta->name_len = 0;
   18     udta->require = 0;
   19     udta->require_len = 0;
   20     udta->encoder = 0;
   21     udta->encoder_len = 0;
   22 
   23     udta->info = malloc(strlen(DEFAULT_INFO) + 1);
   24     udta->info_len = strlen(DEFAULT_INFO);
   25     sprintf(udta->info, DEFAULT_INFO);
   26     return 0;
   27 }
   28 
   29 int quicktime_udta_delete(quicktime_udta_t *udta)
   30 {
   31     if(udta->copyright_len)
   32     {
   33         free(udta->copyright);
   34     }
   35     if(udta->name_len)
   36     {
   37         free(udta->name);
   38     }
   39     if(udta->info_len)
   40     {
   41         free(udta->info);
   42     }
   43     if(udta->require_len)
   44     {
   45         free(udta->require);
   46     }
   47     if(udta->encoder_len)
   48     {
   49         free(udta->encoder);
   50     }
   51 //  quicktime_udta_init(udta);
   52     return 0;
   53 }
   54 
   55 void quicktime_udta_dump(quicktime_udta_t *udta)
   56 {
   57     printf(" user data (udta)\n");
   58     if(udta->copyright_len) printf("  copyright -> %s\n", udta->copyright);
   59     if(udta->name_len) printf("  name -> %s\n", udta->name);
   60     if(udta->info_len) printf("  info -> %s\n", udta->info);
   61     if(udta->require_len) printf("  require -> %s\n", udta->require);
   62     if(udta->encoder_len) printf("  encoder -> %s\n", udta->encoder);
   63 }
   64 
   65 int quicktime_read_udta(quicktime_t *file, quicktime_udta_t *udta, quicktime_atom_t *udta_atom)
   66 {
   67     quicktime_atom_t leaf_atom;
   68     int result = 0;
   69 
   70     do
   71     {
   72         quicktime_atom_read_header(file, &leaf_atom);
   73 
   74 
   75         if(quicktime_atom_is(&leaf_atom, cpy_tag))
   76         {
   77             result += quicktime_read_udta_string(file, &(udta->copyright), &(udta->copyright_len));
   78         }
   79         else
   80         if(quicktime_atom_is(&leaf_atom, nam_tag))
   81         {
   82             result += quicktime_read_udta_string(file, &(udta->name), &(udta->name_len));
   83         }
   84         else
   85         if(quicktime_atom_is(&leaf_atom, inf_tag))
   86         {
   87             result += quicktime_read_udta_string(file, &(udta->info), &(udta->info_len));
   88         }
   89         else
   90         if(quicktime_atom_is(&leaf_atom, req_tag))
   91         {
   92             result += quicktime_read_udta_string(file, &(udta->require), &(udta->require_len));
   93         }
   94         else
   95         if(quicktime_atom_is(&leaf_atom, enc_tag))
   96         {
   97             result += quicktime_read_udta_string(file, &(udta->encoder), &(udta->encoder_len));
   98         }
   99         else
  100         {
  101             quicktime_atom_skip(file, &leaf_atom);
  102         }
  103     }while(quicktime_position(file) < udta_atom->end);
  104 
  105 
  106     return result;
  107 }
  108 
  109 void quicktime_write_udta(quicktime_t *file, quicktime_udta_t *udta)
  110 {
  111     quicktime_atom_t atom, subatom;
  112     quicktime_atom_write_header(file, &atom, "udta");
  113 
  114     if(udta->copyright_len)
  115     {
  116         quicktime_atom_write_header(file, &subatom, cpy_tag);
  117         quicktime_write_udta_string(file, udta->copyright, udta->copyright_len);
  118         quicktime_atom_write_footer(file, &subatom);
  119     }
  120 
  121     if(udta->name_len)
  122     {
  123         quicktime_atom_write_header(file, &subatom, nam_tag);
  124         quicktime_write_udta_string(file, udta->name, udta->name_len);
  125         quicktime_atom_write_footer(file, &subatom);
  126     }
  127 
  128     if(udta->info_len)
  129     {
  130         quicktime_atom_write_header(file, &subatom, inf_tag);
  131         quicktime_write_udta_string(file, udta->info, udta->info_len);
  132         quicktime_atom_write_footer(file, &subatom);
  133     }
  134 
  135     if(udta->require_len)
  136     {
  137         quicktime_atom_write_header(file, &subatom, req_tag);
  138         quicktime_write_udta_string(file, udta->require, udta->require_len);
  139         quicktime_atom_write_footer(file, &subatom);
  140     }
  141 
  142     if(udta->encoder_len)
  143     {
  144         quicktime_atom_write_header(file, &subatom, enc_tag);
  145         quicktime_write_udta_string(file, udta->encoder, udta->encoder_len);
  146         quicktime_atom_write_footer(file, &subatom);
  147     }
  148 
  149     quicktime_atom_write_footer(file, &atom);
  150 }
  151 
  152 int quicktime_read_udta_string(quicktime_t *file, char **string, int *size)
  153 {
  154     int result;
  155 
  156     if(*size) free(*string);
  157     *size = quicktime_read_int16(file);  /* Size of string */
  158     quicktime_read_int16(file);  /* Discard language code */
  159     *string = malloc(*size + 1);
  160     result = quicktime_read_data(file, *string, *size);
  161     (*string)[*size] = 0;
  162     return !result;
  163 }
  164 
  165 int quicktime_write_udta_string(quicktime_t *file, char *string, int size)
  166 {
  167     int new_size = strlen(string);
  168     int result;
  169 
  170     quicktime_write_int16(file, new_size);    /* String size */
  171     quicktime_write_int16(file, 0);    /* Language code */
  172     result = quicktime_write_data(file, string, new_size);
  173     return !result;
  174 }
  175 
  176 int quicktime_set_udta_string(char **string, int *size, char *new_string)
  177 {
  178     if(*size) free(*string);
  179     *size = strlen(new_string) + 1;
  180     *string = malloc(*size);
  181     strcpy(*string, new_string);
  182     return 0;
  183 }