Changeset 2551
- Timestamp:
- 2006-11-19 16:50:21 (2 years ago)
- Files:
-
- libannodex/trunk/src/importers/anx_import_anx.c (modified) (1 diff)
- libannodex/trunk/src/importers/anx_import_ogg.c (modified) (16 diffs)
- libannodex/trunk/src/libannodex/anx_import.c (modified) (4 diffs)
- libannodex/trunk/src/libannodex/anx_write.c (modified) (13 diffs)
- libannodex/trunk/src/tools/anxenc.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libannodex/trunk/src/importers/anx_import_anx.c
r734 r2551 42 42 #include <annodex/annodex.h> 43 43 44 /*#define DEBUG*/ 44 #define DEBUG 45 45 #define ANX_ANX_DEPRECATED 1 46 46 libannodex/trunk/src/importers/anx_import_ogg.c
r1325 r2551 320 320 /* Check the CMML header is of correct length */ 321 321 if (op->bytes > 28) 322 aod->cmml_granuleshift = (int)header[28];322 aod->cmml_granuleshift = (int)header[28]; 323 323 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 326 330 if (aod->cmml_granuleshift == 0) 327 aod->cmml_need_keygranule = 0;331 aod->cmml_need_keygranule = 0; 328 332 else 329 aod->cmml_need_keygranule = 1;333 aod->cmml_need_keygranule = 1; 330 334 } else { 331 335 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; 335 339 } 336 340 … … 339 343 340 344 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; 348 352 } 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; 356 360 } 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); 359 363 #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; 362 366 #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; 365 369 #endif 366 370 367 371 #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; 371 375 #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; 379 383 } 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; 382 386 } 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; 431 443 } else { 432 anx_free (aot);433 return OGGZ_STOP_ERR;444 anx_free (aot); 445 return OGGZ_STOP_ERR; 434 446 } 435 447 … … 438 450 439 451 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; 442 454 } 443 455 … … 593 605 AnxSource * m = aod->anx_source; 594 606 AnxSourceTrack * track = NULL; 607 anx_int64_t gp = oggz_tell_granulepos(oggz); 595 608 596 609 #ifdef DEBUG 597 610 fprintf (aod->df, "anxogg::read_packet_data IN: %010ld, granulepos %llx\n", 598 serialno, op->granulepos);611 serialno, gp); 599 612 #endif 600 613 … … 622 635 #ifdef DEBUG 623 636 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; 629 642 } 630 at_time = gp_to_time (aod->oggz, serialno, op->granulepos);643 at_time = gp_to_time (aod->oggz, serialno, gp); 631 644 632 645 #ifdef DEBUG 633 646 { 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); 638 651 } 639 652 #endif … … 641 654 /* If this content doesn't use cmml_granuleshift, and this clip is 642 655 * 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; 651 670 } 652 671 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 } 656 676 return OGGZ_CONTINUE; 657 677 } else { 658 678 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; 661 681 } else { 662 aod->got_non_bos = 1;682 aod->got_non_bos = 1; 663 683 } 664 684 } … … 675 695 676 696 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); 679 699 if (granule >= track->end_granule) { 680 700 #ifdef DEBUG … … 723 743 } 724 744 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 { 728 754 if (oggz_seek_units (oggz, 0, SEEK_CUR) >= 0) { 729 755 #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; 734 760 } 735 761 } … … 746 772 747 773 #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"); 751 777 #endif 752 778 … … 774 800 } 775 801 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 */ 776 810 static int 777 811 read_page_granuleinfo (OGGZ * oggz, const ogg_page * og, long serialno, … … 786 820 787 821 #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++); 789 825 #endif 790 826 791 827 granulepos = ogg_page_granulepos ((ogg_page *)og); 792 828 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 793 835 if (aod->cmml_serialno != -1 && serialno == aod->cmml_serialno) { 794 836 if (!aod->cmml_need_keygranule) return OGGZ_STOP_OK; 795 837 838 #ifdef DEBUG 839 fprintf (aod->df, "read_page_granuleinfo: cmml_need_keygranule -> 0\n"); 840 #endif 796 841 aod->cmml_need_keygranule = 0; 797 842 … … 816 861 if (aot == NULL) { 817 862 /* If this track is not in the table, ignore it. */ 863 printf("NULL aot\n"); 818 864 return OGGZ_STOP_OK; 819 865 } … … 830 876 start_time = aod->anx_source->start_time; 831 877 offset = gp_to_time (aod->oggz, serialno, granulepos); 878 printf("offset %f start_time %f TOLERANCE %f\n", offset, start_time, 879 TOLERANCE); 832 880 if (offset-TOLERANCE <= start_time) { 833 return OGGZ_STOP_OK;881 return OGGZ_STOP_OK; 834 882 } 835 883 /* End XXX: */ … … 844 892 aot->keygranule_time = offset; 845 893 if (aod->min_granule_seek == 0.0 || offset < aod->min_granule_seek) 846 aod->min_granule_seek = offset;894 aod->min_granule_seek = offset; 847 895 848 896 #ifdef DEBUG 849 897 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", 851 900 aot->keygranule, iframe, offset, track->granuleshift); 852 901 #endif … … 889 938 890 939 if (end_time == -1.0) { 940 #ifdef DEBUG 941 printf("calling oggz_seek with whence of %d\n", SEEK_END); 942 #endif 891 943 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 892 947 893 948 /* Find the actual end time */ … … 1008 1063 long n; 1009 1064 1065 1010 1066 if ((oggz = oggz_open ((char *)path, OGGZ_READ | OGGZ_AUTO)) == NULL) 1011 1067 return NULL; libannodex/trunk/src/libannodex/anx_import.c
r1353 r2551 52 52 #include "content_type.h" 53 53 54 /* #define DEBUG */55 56 54 #include "fix_dl.h" 57 55 … … 60 58 #define S_ISREG(x) TRUE 61 59 #endif 60 61 //#define DEBUG 62 62 63 63 static AnxList * importer_plugins = NULL; … … 215 215 for (l = media_importers; l; l = l->next) { 216 216 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 218 221 return importer; 222 } 219 223 } 220 224 … … 520 524 anx_media_eos (AnxSource * media) 521 525 { 526 AnxSourceTrack * track_data; 527 AnxList * track_list; 528 522 529 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 523 546 return media->eos; 524 547 } libannodex/trunk/src/libannodex/anx_write.c
r1570 r2551 45 45 #include "anx_snprint.h" /* anx_strdup */ 46 46 47 /* #define DEBUG*/47 /* #define DEBUG */ 48 48 49 49 /* set to 0 or 1 */ … … 393 393 /* If we are at the end of the stream, mark media as done */ 394 394 for (l = writer->medias; l; l = l->next) { 395 395 396 media = (AnxSource *)l->data; 396 397 if (!anx_media_eos (media)) { 397 398 #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); 399 400 #endif 400 401 at_eos = 0; … … 1056 1057 } 1057 1058 1058 1059 1059 static long 1060 1060 anx_writer_sync (ANNODEX * annodex) … … 1103 1103 #endif 1104 1104 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 } 1120 1120 } 1121 1121 1122 1122 if (l == NULL) { 1123 1123 #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; 1127 1127 } 1128 1128 } else if (writer->need_cmml_fisbone) { … … 1138 1138 #endif 1139 1139 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 } 1147 1147 } 1148 1148 1149 1149 if (l == NULL) { 1150 writer->need_fisbone = 0;1150 writer->need_fisbone = 0; 1151 1151 } 1152 1152 } else if (writer->need_cmml_preamble) { … … 1167 1167 #ifdef DEBUG 1168 1168 printf ("anx_write_sync: NEED %d secondaries remaing\n", 1169 writer->secondary_headers_remaining);1169 writer->secondary_headers_remaining); 1170 1170 #endif 1171 1171 1172 1172 if (anx_writer_get_soonest_media (annodex) == -1) { 1173 1173 #ifdef DEBUG 1174 printf ("anx_writer_sync: get_soonest_media returned -1\n");1174 printf ("anx_writer_sync: get_soonest_media returned -1\n"); 1175 1175 #endif 1176 1176 } … … 1178 1178 if (anx_writer_read_media (annodex) == -1) { 1179 1179 #ifdef DEBUG 1180 printf ("anx_writer_sync: read_media returned -1\n");1180 printf ("anx_writer_sync: read_media returned -1\n"); 1181 1181 #endif 1182 1182 } … … 1194 1194 1195 1195 command_offset = 1196 anx_command_get_time_offset (annodex, annodex->pending_command);1196 anx_command_get_time_offset (annodex, annodex->pending_command); 1197 1197 1198 1198 current_offset = anx_tell_time (annodex); 1199 1199 1200 1200 /* While current offset >= pending offset and we haven't made a packet 1201 1201 * yet, handle next command */ … … 1203 1203 #ifdef DEBUG 1204 1204 printf ("\nanx_write: [%f] next command at %f\n", current_offset, 1205 command_offset);1205 command_offset); 1206 1206 #endif 1207 1207 1208 1208 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); 1244 1244 #endif 1245 1245 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); 1264 1264 #endif 1265 1265 } 1266 1266 } 1267 1267 1268 /* Create a media packet */1268 /* Create a media packet */ 1269 1269 if (made_packet == 0) { 1270 1270 1271 #ifdef DEBUG 1272 printf ("anx_writer_sync: no packet, creating one\n"); 1273 #endif 1274 1271 1275 if (anx_writer_get_soonest_media (annodex) == -1) { 1272 1276 #ifdef DEBUG 1273 printf ("anx_writer_sync: get_soonest_media returned -1\n");1277 printf ("anx_writer_sync: get_soonest_media returned -1\n"); 1274 1278 #endif 1275 1279 } … … 1277 1281 if (anx_writer_read_media (annodex) == -1) { 1278 1282 #ifdef DEBUG 1279 printf ("anx_writer_sync: read_media returned -1\n");1283 printf ("anx_writer_sync: read_media returned -1\n"); 1280 1284 #endif 1281 1285 } … … 1297 1301 } else { 1298 1302 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); 1305 1309 #endif 1306 1310 #if 0 … … 1309 1313 #else 1310 1314 /* 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 } 1318 1322 } 1319 1323 1320 1324 if (l == NULL) { 1321 1325 #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; 1325 1329 } 1326 1330 } … … 1331 1335 } 1332 1336 1337 #ifdef DEBUG 1338 printf("anx_writer_sync: returning %d\n", writer->eos); 1339 #endif 1333 1340 return writer->eos; 1334 1341 } libannodex/trunk/src/tools/anxenc.c
r1093 r2551 45 45 46 46 #include "common.h" 47 48 /* #define DEBUG */ 47 49 48 50 /* … … 169 171 } 170 172 173 if (n < 0) { 174 break; 175 } 176 171 177 if ((n_written = fwrite (buf, 1, (size_t)n, outfile)) < n) { 172 178 if (ferror(outfile) != 0) … … 175 181 print_debug (2, "Error: short write; wrote %ld bytes\n", n_written); 176 182 } 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 177 190 } 178 191