Changeset 2551

Show
Ignore:
Timestamp:
2006-11-19 16:50:21 (2 years ago)
Author:
shans
Message:

Fixed bug in anxenc that was causing duplicate eos packets
Modified anx_media_eos to check eos status of each track rather than stream as a whole
Some debug message and indenting changes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libannodex/trunk/src/importers/anx_import_anx.c

    r734 r2551  
    4242#include <annodex/annodex.h> 
    4343 
    44 /*#define DEBUG*/ 
     44#define DEBUG 
    4545#define ANX_ANX_DEPRECATED 1 
    4646 
  • libannodex/trunk/src/importers/anx_import_ogg.c

    r1325 r2551  
    320320      /* Check the CMML header is of correct length */ 
    321321      if (op->bytes > 28) 
    322        aod->cmml_granuleshift = (int)header[28]; 
     322        aod->cmml_granuleshift = (int)header[28]; 
    323323      else 
    324         aod->cmml_granuleshift = 0; 
    325  
     324        aod->cmml_granuleshift = 0; 
     325 
     326#ifdef DEBUG 
     327      printf("read_packet_headers: setting cmml_need_keygranule to %d\n", 
     328                      aod->cmml_granuleshift != 0); 
     329#endif 
    326330      if (aod->cmml_granuleshift == 0) 
    327        aod->cmml_need_keygranule = 0; 
     331        aod->cmml_need_keygranule = 0; 
    328332      else 
    329        aod->cmml_need_keygranule = 1; 
     333        aod->cmml_need_keygranule = 1; 
    330334    } else { 
    331335      if (aot == NULL) { 
    332        aot = (AnxOggTrack *) anx_malloc (sizeof (AnxOggTrack)); 
    333        memset (aot, 0, sizeof(AnxOggTrack)); 
    334        need_insert = 1; 
     336        aot = (AnxOggTrack *) anx_malloc (sizeof (AnxOggTrack)); 
     337        memset (aot, 0, sizeof(AnxOggTrack)); 
     338        need_insert = 1; 
    335339      } 
    336340       
     
    339343 
    340344      if (!strncmp ((char *)&header[1], "vorbis", 6)) { 
    341       track->content_type = anxogg_strdup (VORBIS_CONTENT_TYPE); 
    342        track->granule_rate_n = (anx_int64_t) INT32_LE_AT(&header[12]); 
    343        track->granule_rate_d = 1; 
    344        track->nr_header_packets = 3; 
    345        track->basegranule = 0; 
    346        track->preroll = 2; 
    347        track->granuleshift = 0; 
     345              track->content_type = anxogg_strdup (VORBIS_CONTENT_TYPE); 
     346        track->granule_rate_n = (anx_int64_t) INT32_LE_AT(&header[12]); 
     347        track->granule_rate_d = 1; 
     348        track->nr_header_packets = 3; 
     349        track->basegranule = 0; 
     350        track->preroll = 2; 
     351        track->granuleshift = 0; 
    348352      } else if (!strncmp ((char *)&op->packet[0], "Speex   ", 8)) { 
    349        track->content_type = anxogg_strdup (SPEEX_CONTENT_TYPE); 
    350        track->granule_rate_n = (ogg_int64_t) INT32_LE_AT(&header[36]); 
    351        track->granule_rate_d = 1; 
    352        track->nr_header_packets = 2 + (ogg_int64_t) INT32_LE_AT(&header[68]); 
    353        track->basegranule = 0; 
    354        track->preroll = 3; 
    355        track->granuleshift = 0; 
     353        track->content_type = anxogg_strdup (SPEEX_CONTENT_TYPE); 
     354        track->granule_rate_n = (ogg_int64_t) INT32_LE_AT(&header[36]); 
     355        track->granule_rate_d = 1; 
     356        track->nr_header_packets = 2 + (ogg_int64_t) INT32_LE_AT(&header[68]); 
     357        track->basegranule = 0; 
     358        track->preroll = 3; 
     359        track->granuleshift = 0; 
    356360      } else if (!strncmp ((char *)&op->packet[1], "theora", 6)) { 
    357        char keyframe_granule_shift = 0; 
    358        track->content_type = anxogg_strdup (THEORA_CONTENT_TYPE); 
     361        char keyframe_granule_shift = 0; 
     362        track->content_type = anxogg_strdup (THEORA_CONTENT_TYPE); 
    359363#if USE_THEORA_PRE_ALPHA_3_FORMAT 
    360        /* old header format, used by Theora alpha 2 and earlier */ 
    361        keyframe_granule_shift =  (header[36] & 0xf8) >> 3; 
     364        /* old header format, used by Theora alpha 2 and earlier */ 
     365        keyframe_granule_shift =  (header[36] & 0xf8) >> 3; 
    362366#else 
    363        keyframe_granule_shift =  (header[40] & 0x03) /* 00000011 */ << 3; 
    364        keyframe_granule_shift |= (header[41] & 0xe0) /* 11100000 */ >> 5; 
     367        keyframe_granule_shift =  (header[40] & 0x03) /* 00000011 */ << 3; 
     368        keyframe_granule_shift |= (header[41] & 0xe0) /* 11100000 */ >> 5; 
    365369#endif 
    366370 
    367371#if USE_ANNODEX2_GRANULERATE 
    368        track->granule_rate_n = INT32_BE_AT(&header[22]) * 
    369          (1 << keyframe_granule_shift) / 1000000; 
    370        track->granule_rate_d = INT32_BE_AT(&header[26]) / 1000000; 
     372        track->granule_rate_n = INT32_BE_AT(&header[22]) * 
     373          (1 << keyframe_granule_shift) / 1000000; 
     374        track->granule_rate_d = INT32_BE_AT(&header[26]) / 1000000; 
    371375#else /* anx v3 */ 
    372        track->granule_rate_n = INT32_BE_AT(&header[22]); 
    373        track->granule_rate_d = INT32_BE_AT(&header[26]); 
    374 #endif 
    375        track->nr_header_packets = 3; 
    376        track->basegranule = 0; 
    377        track->preroll = 0; 
    378        track->granuleshift = keyframe_granule_shift; 
     376        track->granule_rate_n = INT32_BE_AT(&header[22]); 
     377        track->granule_rate_d = INT32_BE_AT(&header[26]); 
     378#endif 
     379        track->nr_header_packets = 3; 
     380        track->basegranule = 0; 
     381        track->preroll = 0; 
     382        track->granuleshift = keyframe_granule_shift; 
    379383      } else if (!strncmp ((char *)&op->packet[0], "fishead", 8)) { 
    380        need_insert = 0; 
    381        aod->skeleton_serialno = serialno; 
     384        need_insert = 0; 
     385        aod->skeleton_serialno = serialno; 
    382386      } else if (!strncmp ((char *)&op->packet[0], "AnxData", 7)) { 
    383         AnxParams * params; 
    384         long n; 
    385         char * buf; 
    386  
    387         /* Mark this track as anxv2, and don't copy the AnxData packet 
    388          * into the bitstream */ 
    389         aot->anxv2_ignore_packet = 1; 
    390  
    391         /* Set default values, these will be overwritten if the track 
    392          * actually contains a content type we can parse */ 
    393  
    394         /* Ensure params is NUL terminated */ 
    395         n = op->bytes - ANX_DATA_SIZE; 
    396         buf = anx_malloc (n+1); 
    397         memcpy (buf, (char *)header + ANX_DATA_SIZE, n); 
    398         buf[n] = '\0'; 
    399  
    400         params = anx_params_new_parse (buf, ANX_PARAMS_HEADERS); 
    401         track->content_type = 
    402           anxogg_strdup (anx_params_get (params, "Content-Type")); 
    403         track->id = 
    404           anxogg_strdup (anx_params_get (params, "ID")); 
    405         anx_params_free (params); 
    406  
    407         anx_free (buf); 
    408  
    409         track->granule_rate_n = INT64_LE_AT(&header[8]); 
    410         track->granule_rate_d = INT64_LE_AT(&header[16]); 
    411         track->nr_header_packets = INT32_LE_AT(&header[24]); 
    412         track->preroll = 0; 
    413         track->granuleshift = 0; 
    414  
    415         if (!strcmp (track->content_type, CMML_CONTENT_TYPE)) { 
    416           need_insert = 0; 
    417           aod->cmml_serialno = serialno; 
    418           aod->cmml_granuleshift = 0; 
    419           aod->cmml_need_keygranule = 0; 
    420         } 
    421  
    422       } else if (!strncmp ((char *)&op->packet[1], "video", 5) &&  
    423                  !strncmp ((char *)&op->packet[9], "XVID", 4)) { 
    424         track->content_type = anxogg_strdup (XVID_CONTENT_TYPE); 
    425         track->granule_rate_n = (ogg_int64_t) 25; 
    426         track->granule_rate_d = 1; 
    427         track->nr_header_packets = 2; 
    428         track->basegranule = 0; 
    429         track->preroll = 0; 
    430         track->granuleshift = 0; 
     387        AnxParams * params; 
     388        long n; 
     389        char * buf; 
     390 
     391        /* Mark this track as anxv2, and don't copy the AnxData packet 
     392         * into the bitstream */ 
     393        aot->anxv2_ignore_packet = 1; 
     394 
     395        /* Set default values, these will be overwritten if the track 
     396         * actually contains a content type we can parse */ 
     397 
     398        /* Ensure params is NUL terminated */ 
     399        n = op->bytes - ANX_DATA_SIZE; 
     400        buf = anx_malloc (n+1); 
     401        memcpy (buf, (char *)header + ANX_DATA_SIZE, n); 
     402        buf[n] = '\0'; 
     403 
     404        params = anx_params_new_parse (buf, ANX_PARAMS_HEADERS); 
     405        track->content_type = 
     406                 anxogg_strdup (anx_params_get (params, "Content-Type")); 
     407        track->id = 
     408                 anxogg_strdup (anx_params_get (params, "ID")); 
     409        anx_params_free (params); 
     410 
     411        anx_free (buf); 
     412 
     413        track->granule_rate_n = INT64_LE_AT(&header[8]); 
     414        track->granule_rate_d = INT64_LE_AT(&header[16]); 
     415        track->nr_header_packets = INT32_LE_AT(&header[24]); 
     416        track->preroll = 0; 
     417        track->granuleshift = 0; 
     418 
     419        if (!strcmp (track->content_type, CMML_CONTENT_TYPE)) { 
     420           need_insert = 0; 
     421           aod->cmml_serialno = serialno; 
     422           aod->cmml_granuleshift = 0; 
     423#ifdef DEBUG 
     424           printf("read_packet_headers: setting need_keygranule to 0\n"); 
     425#endif 
     426                 aod->cmml_need_keygranule = 0; 
     427              } 
     428 
     429      }  
     430      else if  
     431      ( 
     432        !strncmp ((char *)&op->packet[1], "video", 5)  
     433        &&  
     434                    !strncmp ((char *)&op->packet[9], "XVID", 4) 
     435      ) { 
     436        track->content_type = anxogg_strdup (XVID_CONTENT_TYPE); 
     437        track->granule_rate_n = (ogg_int64_t) 25; 
     438        track->granule_rate_d = 1; 
     439        track->nr_header_packets = 2; 
     440        track->basegranule = 0; 
     441        track->preroll = 0; 
     442        track->granuleshift = 0; 
    431443      } else { 
    432        anx_free (aot); 
    433        return OGGZ_STOP_ERR; 
     444        anx_free (aot); 
     445        return OGGZ_STOP_ERR; 
    434446      } 
    435447 
     
    438450 
    439451      if (track->granuleshift > 0) { 
    440        aod->use_granule_seek = 1; 
    441        aot->need_keygranule = 1; 
     452        aod->use_granule_seek = 1; 
     453        aot->need_keygranule = 1; 
    442454      } 
    443455 
     
    593605  AnxSource * m = aod->anx_source; 
    594606  AnxSourceTrack * track = NULL; 
     607  anx_int64_t gp = oggz_tell_granulepos(oggz); 
    595608 
    596609#ifdef DEBUG 
    597610  fprintf (aod->df, "anxogg::read_packet_data IN: %010ld, granulepos %llx\n", 
    598           serialno, op->granulepos); 
     611          serialno, gp); 
    599612#endif 
    600613 
     
    622635#ifdef DEBUG 
    623636      fprintf (aod->df, "aod->cmml_serialno %010ld, op->granulepos %lld\n", 
    624               aod->cmml_serialno, op->granulepos); 
    625 #endif 
    626  
    627       if (op->granulepos == -1) { 
    628         return OGGZ_STOP_ERR; 
     637              aod->cmml_serialno, gp); 
     638#endif 
     639 
     640      if (gp == -1) { 
     641              return OGGZ_STOP_ERR; 
    629642      } 
    630       at_time = gp_to_time (aod->oggz, serialno, op->granulepos); 
     643      at_time = gp_to_time (aod->oggz, serialno, gp); 
    631644       
    632645#ifdef DEBUG 
    633646      { 
    634        char * header = (char *)op->packet; 
    635        fprintf (aod->df, 
    636                 "anxogg::read_packet_data: got CMML <%c%c%c%c> at %f\n", 
    637                header[1], header[2], header[3], header[4], at_time); 
     647        char * header = (char *)op->packet; 
     648        fprintf (aod->df, 
     649                  "anxogg::read_packet_data: got CMML <%c%c%c%c> at %f\n", 
     650                  header[1], header[2], header[3], header[4], at_time); 
    638651      } 
    639652#endif 
     
    641654      /* If this content doesn't use cmml_granuleshift, and this clip is 
    642655       * before the start_time, drop it */ 
    643       if (aod->cmml_granuleshift == 0 && op->bytes > 6 && 
    644           !strncmp ((char *)op->packet, "<clip", 5) && 
    645           at_time < aod->anx_source->start_time-TOLERANCE) { 
    646 #ifdef DEBUG 
    647         fprintf (aod->df, 
    648                  "anxogg::read_packet_data: CMML clip too early, dropping\n"); 
    649 #endif 
    650         return OGGZ_STOP_OK; 
     656      if  
     657      ( 
     658        aod->cmml_granuleshift == 0 && op->bytes > 6  
     659        && 
     660        !strncmp ((char *)op->packet, "<clip", 5)  
     661        && 
     662              at_time < aod->anx_source->start_time-TOLERANCE 
     663      )  
     664      { 
     665#ifdef DEBUG 
     666              fprintf (aod->df, 
     667                            "anxogg::read_packet_data: CMML clip too early, dropping\n"); 
     668#endif 
     669        return OGGZ_STOP_OK; 
    651670      } 
    652671 
    653       if (aod->import_cmml) 
    654         aod->import_cmml ((char *)op->packet, op->bytes, at_time, 
    655                           aod->import_user_data); 
     672      if (aod->import_cmml) { 
     673        aod->import_cmml ((char *)op->packet, op->bytes, at_time, 
     674                                              aod->import_user_data); 
     675      } 
    656676      return OGGZ_CONTINUE; 
    657677    } else { 
    658678      if (aot->anxv2_ignore_packet) { 
    659        aot->anxv2_ignore_packet = 0; 
    660        op->b_o_s = 1; 
     679        aot->anxv2_ignore_packet = 0; 
     680        op->b_o_s = 1; 
    661681      } else { 
    662        aod->got_non_bos = 1; 
     682        aod->got_non_bos = 1; 
    663683      } 
    664684    } 
     
    675695 
    676696  if (aod->nr_headers_remaining == 0 && !aod->got_end &&  
    677       (m->end_time != -1.0) && (op->granulepos != -1)) { 
    678     ogg_int64_t granule = gp_to_granule (oggz, serialno, op->granulepos); 
     697      (m->end_time != -1.0) && (gp != -1)) { 
     698        ogg_int64_t granule = gp_to_granule (oggz, serialno, gp); 
    679699    if (granule >= track->end_granule) { 
    680700#ifdef DEBUG 
     
    723743    } 
    724744 
    725     if (aod->need_seek == NEED_SEEK_PENDING && 
    726         aod->nr_headers_remaining == 0 && 
    727         m->start_time != 0.0) { 
     745    if  
     746    ( 
     747      aod->need_seek == NEED_SEEK_PENDING  
     748      && 
     749            aod->nr_headers_remaining == 0  
     750      && 
     751            m->start_time != 0.0 
     752    )  
     753    { 
    728754      if (oggz_seek_units (oggz, 0, SEEK_CUR) >= 0) { 
    729755#ifdef DEBUG 
    730       fprintf (aod->df, "anxogg::read_packet_data NEED seek\n"); 
    731 #endif 
    732        aod->need_seek = NEED_SEEK; 
    733        return OGGZ_CONTINUE; 
     756              fprintf (aod->df, "anxogg::read_packet_data NEED seek\n"); 
     757#endif 
     758        aod->need_seek = NEED_SEEK; 
     759        return OGGZ_CONTINUE; 
    734760      } 
    735761    } 
     
    746772 
    747773#ifdef DEBUG 
    748   fprintf (aod->df, "anxogg::granuleinfo_update_state cmml %010ld %s\n", 
    749            aod->cmml_serialno, 
    750            aod->cmml_need_keygranule ? "needs keygranule" : "no keygranule"); 
     774  //fprintf (aod->df, "anxogg::granuleinfo_update_state cmml %010ld %s\n", 
     775        //   aod->cmml_serialno, 
     776        //   aod->cmml_need_keygranule ? "needs keygranule" : "no keygranule"); 
    751777#endif 
    752778 
     
    774800} 
    775801 
     802/* 
     803 * look for tracks, extract granule information.  This is a preprocessor 
     804 * step that scans until info is found for all tracks.  When all tracks 
     805 * are found, granuleinfo_update_state will set the state to FILTER and the 
     806 * loop will end. 
     807 * 
     808 * NOTE THAT this starts scanning from the specified startpos for the media. 
     809 */ 
    776810static int 
    777811read_page_granuleinfo (OGGZ * oggz, const ogg_page * og, long serialno, 
     
    786820 
    787821#ifdef DEBUG 
    788   fprintf (aod->df, "read_page_granuleinfo: track %010ld\n", serialno); 
     822  static int page=0; 
     823  fprintf (aod->df, "read_page_granuleinfo: track %010ld page %d", serialno, 
     824                  page++); 
    789825#endif 
    790826 
    791827  granulepos = ogg_page_granulepos ((ogg_page *)og); 
    792828 
     829#ifdef DEBUG 
     830  fprintf(aod->df, " granulepos %llx cmml_serialno %d", granulepos,  
     831                  aod->cmml_serialno); 
     832  fprintf(aod->df, " bytepos %d\n", oggz_tell(oggz)); 
     833#endif 
     834   
    793835  if (aod->cmml_serialno != -1 && serialno == aod->cmml_serialno) { 
    794836    if (!aod->cmml_need_keygranule) return OGGZ_STOP_OK; 
    795837 
     838#ifdef DEBUG 
     839    fprintf (aod->df, "read_page_granuleinfo: cmml_need_keygranule -> 0\n"); 
     840#endif 
    796841    aod->cmml_need_keygranule = 0; 
    797842 
     
    816861    if (aot == NULL) { 
    817862      /* If this track is not in the table, ignore it. */ 
     863      printf("NULL aot\n"); 
    818864      return OGGZ_STOP_OK; 
    819865    } 
     
    830876      start_time = aod->anx_source->start_time; 
    831877      offset = gp_to_time (aod->oggz, serialno, granulepos); 
     878      printf("offset %f start_time %f TOLERANCE %f\n", offset, start_time, 
     879                      TOLERANCE); 
    832880      if (offset-TOLERANCE <= start_time) { 
    833        return OGGZ_STOP_OK; 
     881        return OGGZ_STOP_OK; 
    834882      } 
    835883      /* End XXX: */ 
     
    844892      aot->keygranule_time = offset; 
    845893      if (aod->min_granule_seek == 0.0 || offset < aod->min_granule_seek) 
    846        aod->min_granule_seek = offset; 
     894        aod->min_granule_seek = offset; 
    847895       
    848896#ifdef DEBUG 
    849897      fprintf (aod->df, 
    850                "read_page_granuleinfo: ^^^ has keygranule %lld (%lld|0) (%f seconds) (granuleshift %d)\n", 
     898              "read_page_granuleinfo: ^^^ has keygranule " 
     899        "%lld (%lld|0) (%f seconds) (granuleshift %d)\n", 
    851900              aot->keygranule, iframe, offset, track->granuleshift); 
    852901#endif 
     
    889938 
    890939  if (end_time == -1.0) { 
     940#ifdef DEBUG 
     941    printf("calling oggz_seek with whence of %d\n", SEEK_END); 
     942#endif 
    891943    end_offset = oggz_seek (aod->oggz, 0, SEEK_END); 
     944#ifdef DEBUG 
     945    fprintf (aod->df, "anxogg_setup: end_offset is %d\n", end_offset); 
     946#endif 
    892947 
    893948    /* Find the actual end time */ 
     
    10081063  long n; 
    10091064 
     1065   
    10101066  if ((oggz = oggz_open ((char *)path, OGGZ_READ | OGGZ_AUTO)) == NULL) 
    10111067    return NULL; 
  • libannodex/trunk/src/libannodex/anx_import.c

    r1353 r2551  
    5252#include "content_type.h" 
    5353 
    54 /* #define DEBUG */ 
    55  
    5654#include "fix_dl.h" 
    5755 
     
    6058#define S_ISREG(x) TRUE 
    6159#endif 
     60 
     61//#define DEBUG 
    6262 
    6363static AnxList * importer_plugins = NULL; 
     
    215215  for (l = media_importers; l; l = l->next) { 
    216216    importer = (AnxImporter *)l->data; 
    217     if (!strcasecmp (importer->content_type, content_type)) 
     217    if (!strcasecmp (importer->content_type, content_type)) { 
     218#ifdef DEBUG 
     219      printf("%s\n", importer->content_type); 
     220#endif 
    218221      return importer; 
     222    } 
    219223  } 
    220224 
     
    520524anx_media_eos (AnxSource * media) 
    521525{ 
     526  AnxSourceTrack  * track_data; 
     527  AnxList         * track_list; 
     528     
    522529  if (media == NULL) return 0; 
     530   
     531  track_list = media->tracks; 
     532    
     533  while (track_list != NULL) { 
     534    track_data = (AnxSourceTrack *)(track_list->data); 
     535#ifdef DEBUG 
     536    printf("track %p has eos %d\n", (void *)track_data, track_data->eos); 
     537#endif 
     538    if (track_data->eos == 0) 
     539      return 0; 
     540    track_list = track_list->next; 
     541 
     542  } 
     543 
     544  media->eos = 1; 
     545   
    523546  return media->eos; 
    524547} 
  • libannodex/trunk/src/libannodex/anx_write.c

    r1570 r2551  
    4545#include "anx_snprint.h" /* anx_strdup */ 
    4646 
    47 /*#define DEBUG*/ 
     47/* #define DEBUG */ 
    4848 
    4949/* set to 0 or 1 */ 
     
    393393  /* If we are at the end of the stream, mark media as done */ 
    394394  for (l = writer->medias; l; l = l->next) { 
     395     
    395396    media = (AnxSource *)l->data; 
    396397    if (!anx_media_eos (media)) { 
    397398#ifdef DEBUG 
    398       printf ("anx_writer_update_eos: found one not at eos\n"); 
     399      printf ("anx_writer_update_eos: found %p not at eos\n", media); 
    399400#endif 
    400401      at_eos = 0; 
     
    10561057} 
    10571058 
    1058  
    10591059static long 
    10601060anx_writer_sync (ANNODEX * annodex) 
     
    11031103#endif 
    11041104      for (l = writer->tracks; l; l = l->next) { 
    1105        wsub = (AnxWriterTrack *)l->data; 
    1106        if (!wsub->written_bos) { 
    1107  
    1108          anx_writer_set_wsub (annodex, wsub); 
    1109          if (anx_writer_read_media (annodex) == -1) { 
    1110 #ifdef DEBUG 
    1111            printf ("anx_writer_sync: fill_media returned -1\n"); 
    1112 #endif 
    1113          } 
    1114  
    1115          anx_init_media_packet (annodex, OGGZ_FLUSH_BEFORE|OGGZ_FLUSH_AFTER); 
    1116          writer->secondary_headers_remaining--; 
    1117          made_packet = 1; 
    1118          break; 
    1119        
     1105        wsub = (AnxWriterTrack *)l->data; 
     1106        if (!wsub->written_bos) { 
     1107 
     1108          anx_writer_set_wsub (annodex, wsub); 
     1109          if (anx_writer_read_media (annodex) == -1) { 
     1110#ifdef DEBUG 
     1111            printf ("anx_writer_sync: fill_media returned -1\n"); 
     1112#endif 
     1113          } 
     1114 
     1115          anx_init_media_packet (annodex, OGGZ_FLUSH_BEFORE|OGGZ_FLUSH_AFTER); 
     1116          writer->secondary_headers_remaining--; 
     1117          made_packet = 1; 
     1118          break; 
     1119       
    11201120      } 
    11211121 
    11221122      if (l == NULL) { 
    11231123#ifdef DEBUG 
    1124        if (!made_packet) printf ("anx_writer_sync: no BOS found\n"); 
    1125 #endif 
    1126        writer->need_bos = 0; 
     1124        if (!made_packet) printf ("anx_writer_sync: no BOS found\n"); 
     1125#endif 
     1126        writer->need_bos = 0; 
    11271127      } 
    11281128    } else if (writer->need_cmml_fisbone) { 
     
    11381138#endif 
    11391139      for (l = writer->tracks; l; l = l->next) { 
    1140        wsub = (AnxWriterTrack *)l->data; 
    1141        if (!wsub->written_fisbone) { 
    1142          anx_init_wsub_fisbone_packet (annodex, wsub); 
    1143          writer->secondary_headers_remaining--; 
    1144          made_packet = 1; 
    1145          break; 
    1146        
     1140        wsub = (AnxWriterTrack *)l->data; 
     1141        if (!wsub->written_fisbone) { 
     1142          anx_init_wsub_fisbone_packet (annodex, wsub); 
     1143          writer->secondary_headers_remaining--; 
     1144          made_packet = 1; 
     1145          break; 
     1146       
    11471147      } 
    11481148 
    11491149      if (l == NULL) { 
    1150        writer->need_fisbone = 0; 
     1150        writer->need_fisbone = 0; 
    11511151      } 
    11521152    } else if (writer->need_cmml_preamble) { 
     
    11671167#ifdef DEBUG 
    11681168      printf ("anx_write_sync: NEED %d secondaries remaing\n", 
    1169              writer->secondary_headers_remaining); 
     1169        writer->secondary_headers_remaining); 
    11701170#endif 
    11711171 
    11721172      if (anx_writer_get_soonest_media (annodex) == -1) { 
    11731173#ifdef DEBUG 
    1174        printf ("anx_writer_sync: get_soonest_media returned -1\n"); 
     1174        printf ("anx_writer_sync: get_soonest_media returned -1\n"); 
    11751175#endif 
    11761176      } 
     
    11781178      if (anx_writer_read_media (annodex) == -1) { 
    11791179#ifdef DEBUG 
    1180        printf ("anx_writer_sync: read_media returned -1\n"); 
     1180        printf ("anx_writer_sync: read_media returned -1\n"); 
    11811181#endif 
    11821182      } 
     
    11941194 
    11951195      command_offset = 
    1196        anx_command_get_time_offset (annodex, annodex->pending_command); 
     1196          anx_command_get_time_offset (annodex, annodex->pending_command); 
    11971197 
    11981198      current_offset = anx_tell_time (annodex); 
    1199  
     1199   
    12001200      /* While current offset >= pending offset and we haven't made a packet 
    12011201       * yet, handle next command */ 
     
    12031203#ifdef DEBUG 
    12041204      printf ("\nanx_write: [%f] next command at %f\n", current_offset, 
    1205              command_offset); 
     1205         command_offset); 
    12061206#endif 
    12071207       
    12081208      while (!made_packet && 
    1209             ((current_offset > command_offset-TOLERANCE) || 
    1210              (current_offset == 0.0 && command_offset == 0.0))) { 
    1211  
    1212        annodex->current_command = annodex->pending_command; 
    1213  
    1214 #ifdef DEBUG 
    1215        printf ("\t[%f] writing %p\n", current_offset, 
    1216                annodex->pending_command); 
    1217 #endif 
    1218  
    1219        command_type = 
    1220          anx_command_get_type (annodex, annodex->pending_command); 
    1221  
    1222        switch (command_type) { 
    1223        case ANX_CMD_NOOP: 
    1224          break; 
    1225        case ANX_CMD_INSERT_CLIP: 
    1226          anx_init_clip_packet (annodex); 
    1227          made_packet = 1; 
    1228          break; 
    1229        case ANX_CMD_CLEAR_CLIP: 
    1230          anx_init_clear_clip_packet (annodex); 
    1231          made_packet = 1; 
    1232          break; 
    1233        case ANX_CMD_LOAD_MEDIA: 
    1234          break; 
    1235        case ANX_CMD_UNLOAD_MEDIA: 
    1236          break; 
    1237        default: 
    1238          break; 
    1239        
    1240  
    1241 #ifdef DEBUG 
    1242        printf ("\t[%f] pending_command before: %p\n", 
    1243                current_offset, annodex->pending_command); 
     1209                ((current_offset > command_offset-TOLERANCE) || 
     1210                (current_offset == 0.0 && command_offset == 0.0))) { 
     1211 
     1212        annodex->current_command = annodex->pending_command; 
     1213 
     1214#ifdef DEBUG 
     1215        printf ("\t[%f] writing %p\n", current_offset, 
     1216                    annodex->pending_command); 
     1217#endif 
     1218 
     1219        command_type = 
     1220            anx_command_get_type (annodex, annodex->pending_command); 
     1221 
     1222        switch (command_type) { 
     1223        case ANX_CMD_NOOP: 
     1224          break; 
     1225        case ANX_CMD_INSERT_CLIP: 
     1226          anx_init_clip_packet (annodex); 
     1227          made_packet = 1; 
     1228          break; 
     1229        case ANX_CMD_CLEAR_CLIP: 
     1230          anx_init_clear_clip_packet (annodex); 
     1231          made_packet = 1; 
     1232          break; 
     1233        case ANX_CMD_LOAD_MEDIA: 
     1234          break; 
     1235        case ANX_CMD_UNLOAD_MEDIA: 
     1236          break; 
     1237        default: 
     1238          break; 
     1239       
     1240 
     1241#ifdef DEBUG 
     1242        printf ("\t[%f] pending_command before: %p\n", 
     1243              current_offset, annodex->pending_command); 
    12441244#endif 
    12451245         
    1246        annodex->pending_command = 
    1247          anx_command_next (annodex, annodex->pending_command); 
    1248  
    1249 #ifdef DEBUG 
    1250        printf ("\t[%f] pending_command after : %p\n", 
    1251                current_offset, annodex->pending_command); 
    1252 #endif 
    1253  
    1254        if (made_packet || annodex->pending_command == NULL) break; 
    1255  
    1256        command_offset = 
    1257          anx_command_get_time_offset (annodex, annodex->pending_command); 
    1258  
    1259        current_offset = anx_tell_time (annodex); 
    1260  
    1261 #ifdef DEBUG 
    1262        printf ("anx_write: [%f] next command at %f\n", current_offset, 
    1263               command_offset); 
     1246        annodex->pending_command = 
     1247                      anx_command_next (annodex, annodex->pending_command); 
     1248 
     1249#ifdef DEBUG 
     1250        printf ("\t[%f] pending_command after : %p\n", 
     1251                                current_offset, annodex->pending_command); 
     1252#endif 
     1253 
     1254        if (made_packet || annodex->pending_command == NULL) break; 
     1255 
     1256        command_offset = 
     1257              anx_command_get_time_offset (annodex, annodex->pending_command); 
     1258 
     1259        current_offset = anx_tell_time (annodex); 
     1260 
     1261#ifdef DEBUG 
     1262        printf ("anx_write: [%f] next command at %f\n", current_offset, 
     1263                      command_offset); 
    12641264#endif 
    12651265      } 
    12661266    } 
    12671267 
    1268     /* Create a media packet */ 
     1268  /* Create a media packet */ 
    12691269    if (made_packet == 0) { 
    12701270 
     1271#ifdef DEBUG 
     1272      printf ("anx_writer_sync: no packet, creating one\n"); 
     1273#endif 
     1274       
    12711275      if (anx_writer_get_soonest_media (annodex) == -1) { 
    12721276#ifdef DEBUG 
    1273        printf ("anx_writer_sync: get_soonest_media returned -1\n"); 
     1277        printf ("anx_writer_sync: get_soonest_media returned -1\n"); 
    12741278#endif 
    12751279      } 
     
    12771281      if (anx_writer_read_media (annodex) == -1) { 
    12781282#ifdef DEBUG 
    1279        printf ("anx_writer_sync: read_media returned -1\n"); 
     1283        printf ("anx_writer_sync: read_media returned -1\n"); 
    12801284#endif 
    12811285      } 
     
    12971301    } else { 
    12981302      for (l = writer->tracks; l; l = l->next) { 
    1299         wsub = (AnxWriterTrack *)l->data; 
    1300        if (!wsub->written_eos) { 
    1301          track = (AnxTrack *)wsub; 
    1302 #ifdef DEBUG 
    1303          printf ("anx_writer_sync: writing eos for %s\n",  
    1304                  track->content_type); 
     1303              wsub = (AnxWriterTrack *)l->data; 
     1304        if (!wsub->written_eos) { 
     1305          track = (AnxTrack *)wsub; 
     1306#ifdef DEBUG 
     1307          printf ("anx_writer_sync: writing eos for %s\n",  
     1308                        track->content_type); 
    13051309#endif 
    13061310#if 0 
     
    13091313#else 
    13101314          /* Hack a fake ++granulepos for this zero-length packet */ 
    1311          granulepos = wsub->last_granulepos+1; 
    1312 #endif 
    1313          anx_init_eos_packet (annodex, track->serialno, granulepos); 
    1314          wsub->written_eos = 1; 
    1315          made_packet = 1; 
    1316          break; 
    1317        
     1315          granulepos = wsub->last_granulepos+1; 
     1316#endif 
     1317          anx_init_eos_packet (annodex, track->serialno, granulepos); 
     1318          wsub->written_eos = 1; 
     1319          made_packet = 1; 
     1320          break; 
     1321       
    13181322      } 
    13191323       
    13201324      if (l == NULL) { 
    13211325#ifdef DEBUG 
    1322        printf ("anx_writer_sync: setting writer->eos\n"); 
    1323 #endif 
    1324        writer->eos = 1; 
     1326        printf ("anx_writer_sync: setting writer->eos\n"); 
     1327#endif 
     1328        writer->eos = 1; 
    13251329      } 
    13261330    } 
     
    13311335  } 
    13321336 
     1337#ifdef DEBUG 
     1338  printf("anx_writer_sync: returning %d\n", writer->eos); 
     1339#endif  
    13331340  return writer->eos; 
    13341341} 
  • libannodex/trunk/src/tools/anxenc.c

    r1093 r2551  
    4545 
    4646#include "common.h" 
     47 
     48/* #define DEBUG */ 
    4749 
    4850/* 
     
    169171    } 
    170172 
     173    if (n < 0) { 
     174      break; 
     175    } 
     176     
    171177    if ((n_written = fwrite (buf, 1, (size_t)n, outfile)) < n) { 
    172178      if (ferror(outfile) != 0) 
     
    175181        print_debug (2, "Error: short write; wrote %ld bytes\n", n_written); 
    176182    } 
     183 
     184#ifdef DEBUG 
     185    static int position = 0; 
     186    printf ("anxenc: writing %d(%d) bytes at %x\n", n, n_written, position); 
     187    position += n_written; 
     188#endif 
     189     
    177190  } 
    178191