"Fossies" - the Fresh Open Source Software Archive

Member "quicktime4linux-2.3/qtasf.c" (11 Jul 2007, 7996 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 "qtasf.h"
    3 #include "qtasf_codes.h"
    4 
    5 #include <string.h>
    6 
    7 /* We have lifted sections of ASF decoding from ffmpeg */
    8 /* to add direct copy support and seeking to it */
    9 
   10 int quicktime_read_guid(quicktime_t *file, quicktime_guid_t *guid)
   11 {
   12     int i;
   13     guid->v1 = quicktime_read_int32_le(file);
   14     guid->v2 = quicktime_read_int16_le(file);
   15     guid->v3 = quicktime_read_int16_le(file);
   16     for(i = 0; i < 8; i++)
   17         guid->v4[i] = quicktime_read_char(file);
   18     return 0;
   19 }
   20 
   21 quicktime_asfstream_t* new_asfstream()
   22 {
   23     quicktime_asfstream_t *result = calloc(1, sizeof(quicktime_asfstream_t));
   24     return result;
   25 }
   26 
   27 void delete_asfstream(quicktime_asfstream_t *stream)
   28 {
   29     if(stream->extradata)
   30         free(stream->extradata);
   31 }
   32 
   33 void quicktime_delete_asf(quicktime_asf_t *asf)
   34 {
   35     int i;
   36     if(asf)
   37     {
   38         for(i = 0; i < asf->total_streams; i++)
   39             delete_asfstream(asf->streams[i]);
   40     }
   41 }
   42 
   43 int quicktime_read_asf(quicktime_t *file)
   44 {
   45     quicktime_asf_t *asf = calloc(1, sizeof(quicktime_asf_t));
   46     int got_header = 0;
   47     int debug = 1;
   48     int i;
   49 
   50     file->asf = asf;
   51     quicktime_set_position(file, 16 + 14);
   52     
   53     while(1)
   54     {
   55         quicktime_guid_t guid;
   56         int64_t guid_size;
   57         int64_t guid_start = quicktime_position(file);
   58 
   59         bzero(&guid, sizeof(guid));
   60         quicktime_read_guid(file, &guid);
   61         guid_size = quicktime_read_int64_le(file);
   62 
   63         printf("quicktime_read_asf start=0x%llx size=0x%llx\n", guid_start, guid_size);
   64 
   65 // Glitch
   66         if(guid_size < 24) return 1;
   67         
   68         
   69         if(!memcmp(&guid, &file_header, sizeof(guid)))
   70         {
   71             quicktime_guid_t leaf_guid;
   72             got_header = 1;
   73             quicktime_read_guid(file, &leaf_guid);
   74             asf->header.file_size = quicktime_read_int64_le(file);
   75             asf->header.create_time = quicktime_read_int64_le(file);
   76             asf->header.total_packets = quicktime_read_int64_le(file);
   77             asf->header.send_time = quicktime_read_int64_le(file);
   78             asf->header.play_time = quicktime_read_int64_le(file);
   79             asf->header.preroll = quicktime_read_int32_le(file);
   80             asf->header.ignore = quicktime_read_int32_le(file);
   81             asf->header.flags = quicktime_read_int32_le(file);
   82             asf->header.min_packet = quicktime_read_int32_le(file);
   83             asf->header.max_packet = quicktime_read_int32_le(file);
   84             asf->header.max_bitrate = quicktime_read_int32_le(file);
   85             asf->header.packet_size = asf->header.max_packet;
   86         }
   87         else
   88         if(!memcmp(&guid, &index_guid, sizeof(guid)))
   89         {
   90             quicktime_guid_t leaf_guid;
   91             int max;
   92             int count;
   93             int total_packets = 0;
   94 
   95 // Leaf Guid
   96             quicktime_read_guid(file, &leaf_guid);
   97 // indexed interval
   98             quicktime_read_int64_le(file);
   99 // max
  100             max = quicktime_read_int32_le(file);
  101 // count
  102             asf->index_size = quicktime_read_int32_le(file);
  103             asf->index = calloc(sizeof(quicktime_asfpacket_t), asf->index_size);
  104 
  105             for(i = 0; i < asf->index_size; i++)
  106             {
  107                 asf->index[i].number = quicktime_read_int32_le(file);
  108                 asf->index[i].count = quicktime_read_int16_le(file);
  109             }
  110         }
  111         else
  112         if(!memcmp(&guid, &stream_header, sizeof(guid)))
  113         {
  114             quicktime_asfstream_t *stream = 
  115                 asf->streams[asf->total_streams++] = 
  116                 new_asfstream();
  117             quicktime_guid_t leaf_guid;
  118             quicktime_read_guid(file, &leaf_guid);
  119             if(!memcmp(&leaf_guid, &audio_stream, sizeof(leaf_guid)))
  120                 stream->is_audio = 1;
  121             else
  122             if(!memcmp(&leaf_guid, &video_stream, sizeof(leaf_guid)))
  123                 stream->is_video = 1;
  124             else
  125             if(!memcmp(&leaf_guid, &ext_stream_embed_stream_header, sizeof(leaf_guid)))
  126                 stream->is_ext_audio = 1;
  127             quicktime_read_guid(file, &leaf_guid);
  128             
  129             stream->total_size = quicktime_read_int64_le(file);
  130             stream->type_specific_size = quicktime_read_int32_le(file);
  131             quicktime_read_int32_le(file);
  132             stream->id = quicktime_read_int16_le(file) & 0x7f;
  133             quicktime_read_int32_le(file);
  134             if(stream->is_ext_audio)
  135             {
  136                 quicktime_read_guid(file, &leaf_guid);
  137                 if (!memcmp(&leaf_guid, &ext_stream_audio_stream, sizeof(leaf_guid)))
  138                 {
  139                     stream->is_audio = 1;
  140                     stream->is_ext_audio = 0;
  141                     quicktime_read_guid(file, &leaf_guid);
  142                     quicktime_read_int32_le(file);
  143                     quicktime_read_int32_le(file);
  144                     quicktime_read_int32_le(file);
  145                     quicktime_read_guid(file, &leaf_guid);
  146                     quicktime_read_int32_le(file);
  147                 }
  148             }
  149             
  150             
  151             if(stream->is_audio)
  152             {
  153 // Get WAV header
  154                 stream->codec_tag = quicktime_read_int16_le(file);
  155                 stream->channels = quicktime_read_int16_le(file);
  156                 stream->samplerate = quicktime_read_int32_le(file);
  157                 stream->bitrate = quicktime_read_int32_le(file);
  158                 stream->block_align = quicktime_read_int16_le(file);
  159                 if(stream->type_specific_size == 14)
  160                     stream->bits_per_sample = 8;
  161                 else
  162                     stream->bits_per_sample = quicktime_read_int16_le(file);
  163                 if(stream->type_specific_size > 16)
  164                 {
  165                     stream->extradata_size = quicktime_read_int16_le(file);
  166                     if (stream->extradata_size > 0) 
  167                     {
  168                         if (stream->extradata_size > stream->type_specific_size - 18)
  169                             stream->extradata_size = stream->type_specific_size - 18;
  170                         stream->extradata = calloc(1, stream->extradata_size + 1024);
  171                         quicktime_read_data(file, stream->extradata, stream->extradata_size);
  172                     }
  173                     else
  174                         stream->extradata_size = 0;
  175                     
  176                     if(stream->type_specific_size - stream->extradata_size - 18 > 0)
  177                         quicktime_set_position(file,
  178                             quicktime_position(file) + 
  179                             stream->type_specific_size - 
  180                             stream->extradata_size - 18);
  181                 }
  182 
  183 // Make fourcc from codec_tag and bits_per_sample
  184             }
  185             else
  186             if(stream->is_video)
  187             {
  188                 int size1;
  189                 int size2;
  190                 quicktime_read_int32_le(file);
  191                 quicktime_read_int32_le(file);
  192                 quicktime_read_char(file);
  193                 size1 = quicktime_read_int16_le(file);
  194                 size2 = quicktime_read_int32_le(file);
  195                 stream->width = quicktime_read_int32_le(file);
  196                 stream->height = quicktime_read_int32_le(file);
  197                 quicktime_read_int16_le(file);
  198                 stream->bits_per_sample = quicktime_read_int16_le(file);
  199                 stream->codec_tag = quicktime_read_int32_le(file);
  200                 quicktime_set_position(file, quicktime_position(file) + 20);
  201                 if(size1 > 40)
  202                 {
  203                     stream->extradata_size = size1 - 40;
  204                     stream->extradata = calloc(1, stream->extradata_size + 1024);
  205                     quicktime_read_data(file, stream->extradata, stream->extradata_size);
  206                 }
  207 
  208 // Make fourcc from codec_tag
  209                 stream->fourcc[0] = (stream->codec_tag & 0xff);
  210                 stream->fourcc[1] = (stream->codec_tag & 0xff00) >> 8;
  211                 stream->fourcc[2] = (stream->codec_tag & 0xff0000) >> 16;
  212                 stream->fourcc[3] = (stream->codec_tag & 0xff000000) >> 24;
  213             }
  214         }
  215 
  216         quicktime_set_position(file, guid_start + guid_size);
  217         if(quicktime_position(file) >= file->total_length) break;
  218     }
  219 
  220 quicktime_dump_asf(asf);
  221 return 1;
  222     return !got_header;
  223 }
  224 
  225 void quicktime_dump_asf(quicktime_asf_t *asf)
  226 {
  227     int i;
  228     printf("asf header:\n");
  229     printf("  total_packets=%d\n  min_packet=%d\n  max_packet=%d\n  packet_size=%d\n",
  230         asf->header.total_packets,
  231         asf->header.min_packet,
  232         asf->header.max_packet,
  233         asf->header.packet_size);
  234     printf("  total streams=%d\n", asf->total_streams);
  235 
  236     for(i = 0; i < asf->total_streams; i++)
  237     {
  238         quicktime_asfstream_t *stream = asf->streams[i];
  239         printf("  stream %d\n", i);
  240         printf("    is_audio=%d\n    is_video=%d\n", 
  241             stream->is_audio,
  242             stream->is_video);
  243         if(stream->is_audio)
  244         {
  245             printf("    codec_tag=0x%04x\n    channels=%d\n    samplerate=%d\n",
  246                 stream->codec_tag,
  247                 stream->channels,
  248                 stream->samplerate);
  249         }
  250         else
  251         if(stream->is_video)
  252         {
  253             printf("    codec_tag='%s'\n    width=%d\n    height=%d\n",
  254                 stream->fourcc,
  255                 stream->width,
  256                 stream->height);
  257         }
  258 
  259         printf("    extradata_size=%d\n", stream->extradata_size);
  260     }
  261 
  262     printf("  index size=%d\n", asf->index_size);
  263 
  264     for(i = 0; i < asf->index_size; i++)
  265     {
  266         printf("    packet_number=%d packet_count=%d\n",
  267             asf->index[i].number,
  268             asf->index[i].count);
  269     }
  270 }
  271 
  272 
  273