~ubuntu-branches/ubuntu/gutsy/ogmtools/gutsy

« back to all changes in this revision

Viewing changes to avilib/avilib.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Leeman
  • Date: 2005-03-07 09:31:25 UTC
  • mfrom: (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050307093125-sx176ww54zi0shin
Tags: 1:1.5-2
* When using -v and -s together, the verbose output is removed (Closes: #296741)
* Fix of wrong length reporting (Closes: #296739)
* depend on dpatch for patches
* Upload sponsored by Luigi Gangitano <luigi@debian.org>

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 *
26
26
 */
27
27
 
28
 
#include "os.h"
29
 
 
30
 
#if defined(COMP_MSC) || defined(COMP_MINGW)
31
 
#include <io.h>
32
 
#define ftruncate _chsize
33
 
#define strncasecmp _strnicmp
34
 
#else // COMP_...
35
28
#include <unistd.h>
36
 
#endif
37
29
 
38
30
#include "avilib.h"
39
31
 
344
336
    return 0;
345
337
}
346
338
 
347
 
static int avi_add_odml_index_entry_core(avi_t *AVI, long flags, off_t pos, unsigned long len, avistdindex_chunk *si) 
 
339
static int avi_add_odml_index_entry_core(avi_t *AVI, long flags, int64_t pos, unsigned long len, avistdindex_chunk *si) 
348
340
{
349
341
    int cur_chunk_idx;
350
342
    // put new chunk into index
373
365
    return 0;
374
366
}
375
367
 
376
 
static int avi_add_odml_index_entry(avi_t *AVI, unsigned char *tag, long flags, off_t pos, unsigned long len) 
 
368
static int avi_add_odml_index_entry(avi_t *AVI, unsigned char *tag, long flags, int64_t pos, unsigned long len) 
377
369
{
378
370
    char fcc[5];
379
371
 
382
374
 
383
375
    unsigned int cur_std_idx;
384
376
    int audtr;
385
 
    off_t towrite = 0LL;
 
377
    int64_t towrite = 0LL;
386
378
 
387
379
    if (video) {
388
380
 
442
434
    //printf("ODML: towrite = 0x%llX = %lld\n", towrite, towrite);
443
435
 
444
436
    if (AVI->video_superindex && 
445
 
            (off_t)(AVI->pos+towrite) > (off_t)((off_t)NEW_RIFF_THRES*AVI->video_superindex->nEntriesInUse)) {
 
437
            (int64_t)(AVI->pos+towrite) > (int64_t)((int64_t)NEW_RIFF_THRES*AVI->video_superindex->nEntriesInUse)) {
446
438
 
447
439
        fprintf(stderr, "Adding a new RIFF chunk: %d\n", AVI->video_superindex->nEntriesInUse);
448
440
 
631
623
   AVI->fdes = xio_open(filename, O_RDWR|O_CREAT,
632
624
                    S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
633
625
#elif defined(COMP_MINGW) || defined(COMP_CYGWIN)
634
 
   AVI->fdes = open(filename, O_RDWR|O_CREAT|O_BINARY, S_IRUSR | S_IWUSR);
 
626
   AVI->fdes = xio_open(filename, O_RDWR|O_CREAT|O_BINARY, S_IRUSR | S_IWUSR);
635
627
#else
636
 
   AVI->fdes = open(filename, O_RDWR|O_CREAT|O_BINARY,
 
628
   AVI->fdes = xio_open(filename, O_RDWR|O_CREAT|O_BINARY,
637
629
                    S_IRUSR | S_IWUSR | S_IGRP | S_IROTH);
638
630
#endif
639
631
 
1749
1741
 
1750
1742
int AVI_write_frame(avi_t *AVI, char *data, long bytes, int keyframe)
1751
1743
{
1752
 
  off_t pos;
 
1744
  int64_t pos;
1753
1745
  
1754
1746
  if(AVI->mode==AVI_MODE_READ) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
1755
1747
  
2090
2082
{
2091
2083
    char data[100]; // line buffer
2092
2084
    FILE *fd = NULL; // read from
2093
 
    off_t pos, len, f_pos, tot_chunks[AVI_MAX_TRACKS];
 
2085
    int64_t pos, len, f_pos, tot_chunks[AVI_MAX_TRACKS];
2094
2086
    int key=0, type;
2095
2087
    int vid_chunks=0, aud_chunks[AVI_MAX_TRACKS];
2096
2088
    long line_count=0;
2177
2169
 
2178
2170
        switch (i) {
2179
2171
            case 0: // video
2180
 
                AVI->video_index[vid_chunks].key = (off_t)(key?0x10:0);
 
2172
                AVI->video_index[vid_chunks].key = (int64_t)(key?0x10:0);
2181
2173
                AVI->video_index[vid_chunks].pos = pos+8;
2182
2174
                AVI->video_index[vid_chunks].len = len;
2183
2175
                vid_chunks++;
2206
2198
int avi_parse_input_file(avi_t *AVI, int getIndex)
2207
2199
{
2208
2200
  long i, rate, scale, idx_type;
2209
 
  off_t n;
 
2201
  int64_t n;
2210
2202
  unsigned char *hdrl_data;
2211
2203
  long header_offset=0, hdrl_len=0;
2212
2204
  long nvi, nai[AVI_MAX_TRACKS], ioff;
2219
2211
  //  int auds_strf_seen = 0;
2220
2212
  int num_stream = 0;
2221
2213
  char data[256];
2222
 
  off_t oldpos=-1, newpos=-1;
 
2214
  int64_t oldpos=-1, newpos=-1;
2223
2215
  
2224
2216
  /* Read first 12 bytes and check that this is an AVI file */
2225
2217
 
2267
2259
         else if(strncasecmp(data,"movi",4) == 0)
2268
2260
         {
2269
2261
            AVI->movi_start = xio_lseek(AVI->fdes,0,SEEK_CUR);
2270
 
            if (xio_lseek(AVI->fdes,n,SEEK_CUR)==(off_t)-1) break;
 
2262
            if (xio_lseek(AVI->fdes,n,SEEK_CUR)==(int64_t)-1) break;
2271
2263
         }
2272
2264
         else
2273
 
            if (xio_lseek(AVI->fdes,n,SEEK_CUR)==(off_t)-1) break;
 
2265
            if (xio_lseek(AVI->fdes,n,SEEK_CUR)==(int64_t)-1) break;
2274
2266
      }
2275
2267
      else if(strncasecmp(data,"idx1",4) == 0)
2276
2268
      {
2332
2324
            AVI->max_len = 0;
2333
2325
            vids_strh_seen = 1;
2334
2326
            lasttag = 1; /* vids */
 
2327
            memcpy(&AVI->video_stream_header, hdrl_data + i,
 
2328
                   sizeof(alAVISTREAMHEADER));
2335
2329
         }
2336
2330
         else if (strncasecmp ((char *)hdrl_data+i,"auds",4) ==0 && ! auds_strh_seen)
2337
2331
         {
2352
2346
           AVI->track[AVI->aptr].a_vbr = !str2ulong(hdrl_data+i+44);
2353
2347
 
2354
2348
           AVI->track[AVI->aptr].padrate = str2ulong(hdrl_data+i+24);
 
2349
           memcpy(&AVI->stream_headers[AVI->aptr], hdrl_data + i,
 
2350
                   sizeof(alAVISTREAMHEADER));
2355
2351
 
2356
2352
           //      auds_strh_seen = 1;
2357
2353
           lasttag = 2; /* auds */
2418
2414
                  realloc(wfe, sizeof(alWAVEFORMATEX) +
2419
2415
                          str2ushort((unsigned char *)&wfe->cb_size));
2420
2416
                if (nwfe != 0) {
2421
 
                  off_t lpos = xio_lseek(AVI->fdes, 0, SEEK_CUR);
 
2417
                  int64_t lpos = xio_lseek(AVI->fdes, 0, SEEK_CUR);
2422
2418
                  xio_lseek(AVI->fdes, header_offset + i + sizeof(alWAVEFORMATEX),
2423
2419
                        SEEK_SET);
2424
2420
                  wfe = (alWAVEFORMATEX *)nwfe;
2553
2549
         }
2554
2550
         i += 8;
2555
2551
      }
2556
 
      else if(strncasecmp(hdrl_data+i,"JUNK",4) == 0) {
 
2552
      else if((strncasecmp(hdrl_data+i,"JUNK",4) == 0) ||
 
2553
              (strncasecmp(hdrl_data+i,"strn",4) == 0) ||
 
2554
              (strncasecmp(hdrl_data+i,"vprp",4) == 0)){
2557
2555
         i += 8;
2558
2556
         // do not reset lasttag
2559
2557
      } else
2615
2613
 
2616
2614
   if(AVI->idx)
2617
2615
   {
2618
 
      off_t pos, len;
 
2616
      int64_t pos, len;
2619
2617
 
2620
2618
      /* Search the first videoframe in the idx1 and look where
2621
2619
         it is in the file */
2708
2706
         // read from file
2709
2707
         chunk_start = en = malloc (AVI->video_superindex->aIndex[j].dwSize+hdrl_len);
2710
2708
 
2711
 
         if (xio_lseek(AVI->fdes, AVI->video_superindex->aIndex[j].qwOffset, SEEK_SET) == (off_t)-1) {
 
2709
         if (xio_lseek(AVI->fdes, AVI->video_superindex->aIndex[j].qwOffset, SEEK_SET) == (int64_t)-1) {
2712
2710
            fprintf(stderr, "(%s) cannot seek to 0x%llx\n", __FILE__, 
2713
2711
                    (unsigned long long)AVI->video_superindex->aIndex[j].qwOffset);
2714
2712
            free(chunk_start);
2789
2787
            // read from file
2790
2788
            chunk_start = en = malloc (AVI->track[audtr].audio_superindex->aIndex[j].dwSize+hdrl_len);
2791
2789
 
2792
 
            if (xio_lseek(AVI->fdes, AVI->track[audtr].audio_superindex->aIndex[j].qwOffset, SEEK_SET) == (off_t)-1) {
 
2790
            if (xio_lseek(AVI->fdes, AVI->track[audtr].audio_superindex->aIndex[j].qwOffset, SEEK_SET) == (int64_t)-1) {
2793
2791
               fprintf(stderr, "(%s) cannot seek to 0x%llx\n", __FILE__, (unsigned long long)AVI->track[audtr].audio_superindex->aIndex[j].qwOffset);
2794
2792
               free(chunk_start);
2795
2793
               continue;
3260
3258
long AVI_read_audio(avi_t *AVI, char *audbuf, long bytes)
3261
3259
{
3262
3260
   long nr, left, todo;
3263
 
   off_t pos;
 
3261
   int64_t pos;
3264
3262
 
3265
3263
   if(AVI->mode==AVI_MODE_WRITE) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
3266
3264
   if(!AVI->track[AVI->aptr].audio_index)         { AVI_errno = AVI_ERR_NO_IDX;   return -1; }
3274
3272
   }
3275
3273
   while(bytes>0)
3276
3274
   {
3277
 
       off_t ret;
 
3275
       int64_t ret;
3278
3276
      left = AVI->track[AVI->aptr].audio_index[AVI->track[AVI->aptr].audio_posc].len - AVI->track[AVI->aptr].audio_posb;
3279
3277
      if(left==0)
3280
3278
      {
3305
3303
 
3306
3304
long AVI_read_audio_chunk(avi_t *AVI, char *audbuf)
3307
3305
{
3308
 
   long left;
3309
 
   off_t pos;
 
3306
   int64_t pos, left;
3310
3307
 
3311
3308
   if(AVI->mode==AVI_MODE_WRITE) { AVI_errno = AVI_ERR_NOT_PERM; return -1; }
3312
3309
   if(!AVI->track[AVI->aptr].audio_index)         { AVI_errno = AVI_ERR_NO_IDX;   return -1; }
3354
3351
 *   -2 = audio buffer too small
3355
3352
 */
3356
3353
 
3357
 
   off_t n;
 
3354
   int64_t n;
3358
3355
   char data[8];
3359
3356
 
3360
3357
   if(AVI->mode==AVI_MODE_WRITE) return 0;