[xiph-commits] r11369 - trunk/xiph-qt/OggImport/src

arek at svn.xiph.org arek at svn.xiph.org
Sun May 7 15:30:05 PDT 2006


Author: arek
Date: 2006-05-07 15:29:57 -0700 (Sun, 07 May 2006)
New Revision: 11369

Modified:
   trunk/xiph-qt/OggImport/src/OggImport.c
   trunk/xiph-qt/OggImport/src/importer_types.h
   trunk/xiph-qt/OggImport/src/stream_flac.c
   trunk/xiph-qt/OggImport/src/stream_speex.c
   trunk/xiph-qt/OggImport/src/stream_vorbis.c
Log:
Changed handling of track offsets.

Modified: trunk/xiph-qt/OggImport/src/OggImport.c
===================================================================
--- trunk/xiph-qt/OggImport/src/OggImport.c	2006-05-07 19:56:31 UTC (rev 11368)
+++ trunk/xiph-qt/OggImport/src/OggImport.c	2006-05-07 22:29:57 UTC (rev 11369)
@@ -839,8 +839,10 @@
                         if (si->sfhf->first_packet != NULL)
                             (*si->sfhf->first_packet)(si, op, &opckt); //check errors?
 
-                        if (globals->currentGroupOffset == -1)
+                        if (globals->currentGroupOffset == -1) {
                             globals->currentGroupOffset = globals->timeLoaded;
+                            globals->currentGroupOffsetSubSecond = globals->timeLoadedSubSecond;
+                        }
 
                         process_page = false;
                     }
@@ -868,6 +870,7 @@
             if (globals->streamCount == 0) {
                 globals->groupStreamsFound = false;
                 globals->currentGroupOffset = -1;
+                globals->currentGroupOffsetSubSecond = 0.0;
             }
         }
     }
@@ -896,10 +899,12 @@
             globals->dataOffset = globals->dataStartOffset;
             globals->numTracksSeen = 0;
             globals->timeLoaded = 0;
+            globals->timeLoadedSubSecond = 0.0;
             globals->dataRequested = false;
             globals->startTickCount = TickCount();
 
             globals->currentGroupOffset = globals->startTime;
+            globals->currentGroupOffsetSubSecond = (Float64) (globals->startTime % GetMovieTimeScale(globals->theMovie)) / (Float64) GetMovieTimeScale(globals->theMovie);
             globals->groupStreamsFound = false;
 
             if (!globals->sizeInitialised) {
@@ -1143,6 +1148,8 @@
             if (err == noErr)
             {
                 globals->dataReadCompletion = NewDataHCompletionUPP(ReadCompletion);
+                dbg_printf("     - dataReadCompletion: %8lx; err = %lx\n",
+                           globals->dataReadCompletion, GetMoviesError());
             }
 
             if (err == noErr && globals->idleManager)
@@ -1497,11 +1504,16 @@
     if (err == noErr)
         dbg_printf("    SetupDataHandler() succeeded\n");
 
+#if 1
     globals->usingIdle = (globals->dataIsStream
                           && (inFlags & movieImportWithIdle) != 0);
 
     if (dataRefType != URLDataHandlerSubType)
         globals->usingIdle = false;
+#else
+    globals->usingIdle = ((inFlags & movieImportWithIdle) != 0);
+#endif /* 1 */
+
     dbg_printf("--> 2: globals->usingIdle: %d\n", globals->usingIdle);
 
     if (globals->usingIdle) {

Modified: trunk/xiph-qt/OggImport/src/importer_types.h
===================================================================
--- trunk/xiph-qt/OggImport/src/importer_types.h	2006-05-07 19:56:31 UTC (rev 11368)
+++ trunk/xiph-qt/OggImport/src/importer_types.h	2006-05-07 22:29:57 UTC (rev 11369)
@@ -107,8 +107,9 @@
     TimeValue           lastMediaInserted;
     TimeValue           mediaLength;
     TimeValue           insertTime;
+
     TimeValue           streamOffset;
-    // SInt32              sampleOffset;
+    SInt32              streamOffsetSamples;
 
     CFDictionaryRef		MDmapping;
     CFDictionaryRef		UDmapping;
@@ -156,6 +157,7 @@
     // ogg grouped and chained streams support variables
     Boolean                 groupStreamsFound;
     TimeValue               currentGroupOffset;
+    Float64                 currentGroupOffsetSubSecond;   // same as with timeLoaded
 
     long                    newMovieFlags;
 
@@ -192,6 +194,7 @@
     Track                   firstTrack;
 
     TimeValue               timeLoaded;
+    Float64                 timeLoadedSubSecond;        // last second fraction remainder
 
     unsigned long           startTickCount;
 

Modified: trunk/xiph-qt/OggImport/src/stream_flac.c
===================================================================
--- trunk/xiph-qt/OggImport/src/stream_flac.c	2006-05-07 19:56:31 UTC (rev 11368)
+++ trunk/xiph-qt/OggImport/src/stream_flac.c	2006-05-07 22:29:57 UTC (rev 11369)
@@ -138,6 +138,9 @@
     si->numChannels = (sib & 0x07) + 1;
     si->rate = (sib >> 3) & 0xfffff;
 
+    //si->lastMediaInserted = 0;
+    si->mediaLength = 0;
+
     dbg_printf("! -- - flac_first_packet: ch: %d, rate: %ld, bps: %ld\n", si->numChannels, si->rate, si->si_flac.bps);
 
     PtrAndHand(serialnoatom, si->soundDescExtension, sizeof(serialnoatom)); //check errors?
@@ -156,6 +159,10 @@
     Boolean loop = true;
     Boolean movie_changed = false;
 
+    TimeValue movieTS = GetMovieTimeScale(globals->theMovie);
+    TimeValue mediaTS = 0;
+    TimeValue mediaTS_fl = 0.0;
+
     ogg_packet op;
 
     switch(si->si_flac.state) {
@@ -227,6 +234,11 @@
 
                 si->insertTime = 0;
                 si->streamOffset = globals->currentGroupOffset;
+                mediaTS = GetMediaTimeScale(si->theMedia);
+                mediaTS_fl = (Float64) mediaTS;
+                si->streamOffsetSamples = (TimeValue) (mediaTS_fl * globals->currentGroupOffsetSubSecond) -
+                    ((globals->currentGroupOffset % movieTS) * mediaTS / movieTS);
+                dbg_printf("---/  / streamOffset: [%ld, %ld], %lg\n", si->streamOffset, si->streamOffsetSamples, globals->currentGroupOffsetSubSecond);
                 si->incompleteCompensation = 0;
                 si->si_flac.state = kFStateReadingFirstPacket;
 
@@ -303,12 +315,20 @@
                     }
                 }
 
+                if (si->insertTime == 0 && si->streamOffsetSamples > 0) {
+                    dbg_printf("   -   :++: increasing duration (%ld) by sampleOffset: %ld\n", duration, si->streamOffsetSamples);
+                    duration += si->streamOffsetSamples;
+                }
+
                 dbg_printf("   -   :++: adding sampleRef: %lld, len: %d, dur: %d\n", globals->dataOffset, len, duration);
                 ret = AddMediaSampleReference(si->theMedia, S32Set(globals->dataOffset),
                                               len, duration, si->sampleDesc, 1, smp_flags, &inserted); //@@@@ 64-bit enable
                 if (ret == noErr) {
                     TimeValue timeLoaded;
+                    Float64 timeLoadedSubSecond;
 
+                    si->mediaLength += duration;
+
                     dbg_printf("   -   :><: added page %04ld at %14ld (size: %5ld, tsize: %6d), f: %d\n",
                                ogg_page_pageno(opg), inserted,
                                opg->header_len + opg->body_len, len, !logg_page_last_packet_incomplete(opg));
@@ -326,22 +346,23 @@
                                 SetTrackEnabled(si->theTrack, true);
                             }
                         }
-                        if (GetMovieTimeScale(globals->theMovie) < GetMediaTimeScale(si->theMedia)) {
-                            dbg_printf("   # - changing movie time scale: %ld --> %ld\n",
-                                       GetMovieTimeScale(globals->theMovie), GetMediaTimeScale(si->theMedia));
-                            SetMovieTimeScale(globals->theMovie, GetMediaTimeScale(si->theMedia));
-                        }
                     }
                     si->insertTime = -1;
-                    timeLoaded = GetTrackOffset(si->theTrack) + GetTrackDuration(si->theTrack);
 
-                    dbg_printf("   -   :><: added page %04ld at %14ld; offset: %ld, duration: %ld (%ld, %ld), mediats: %ld; moviets: %ld, ret = %ld\n",
+                    mediaTS = GetMediaTimeScale(si->theMedia);
+                    mediaTS_fl = (Float64) mediaTS;
+                    timeLoaded = si->streamOffset + si->mediaLength / mediaTS * movieTS + (si->mediaLength % mediaTS) * movieTS / mediaTS;
+                    timeLoadedSubSecond = (Float64) ((si->streamOffset % movieTS * mediaTS / movieTS + si->mediaLength) % mediaTS) / mediaTS_fl;
+
+                    dbg_printf("   -   :><: added page %04ld at %14ld; offset: %ld, duration: %ld (%ld(%lg); %ld; ml: %ld), mediats: %ld; moviets: %ld, ret = %ld\n",
                                ogg_page_pageno(opg), inserted,
-                               GetTrackOffset(si->theTrack), GetTrackDuration(si->theTrack), timeLoaded,
-                               (duration * GetMovieTimeScale(globals->theMovie)) / GetMediaTimeScale(si->theMedia),
-                               GetMediaTimeScale(si->theMedia), GetMovieTimeScale(globals->theMovie), ret);
-                    if (globals->timeLoaded < timeLoaded)
+                               GetTrackOffset(si->theTrack), GetTrackDuration(si->theTrack), timeLoaded, timeLoadedSubSecond,
+                               (duration * movieTS) / mediaTS, si->mediaLength,
+                               mediaTS, movieTS, ret);
+                    if (globals->timeLoaded < timeLoaded || (globals->timeLoaded == timeLoaded && globals->timeLoadedSubSecond < timeLoadedSubSecond)) {
                         globals->timeLoaded = timeLoaded;
+                        globals->timeLoadedSubSecond = timeLoadedSubSecond;
+                    }
 
                     movie_changed = true;
                 }

Modified: trunk/xiph-qt/OggImport/src/stream_speex.c
===================================================================
--- trunk/xiph-qt/OggImport/src/stream_speex.c	2006-05-07 19:56:31 UTC (rev 11368)
+++ trunk/xiph-qt/OggImport/src/stream_speex.c	2006-05-07 22:29:57 UTC (rev 11369)
@@ -136,6 +136,8 @@
     dbg_printf("! -- - speex_first_packet: ch: %d, rate: %ld\n", si->si_speex.header.nb_channels, si->si_speex.header.rate);
     si->numChannels = si->si_speex.header.nb_channels;
     si->rate = si->si_speex.header.rate;
+    //si->lastMediaInserted = 0;
+    si->mediaLength = 0;
 
     PtrAndHand(serialnoatom, si->soundDescExtension, sizeof(serialnoatom)); //check errors?
     PtrAndHand(atomhead, si->soundDescExtension, sizeof(atomhead)); //check errors?
@@ -153,6 +155,10 @@
     Boolean loop = true;
     Boolean movie_changed = false;
 
+    TimeValue movieTS = GetMovieTimeScale(globals->theMovie);
+    TimeValue mediaTS = 0;
+    TimeValue mediaTS_fl = 0.0;
+
     ogg_packet op;
 
     switch(si->si_speex.state) {
@@ -208,6 +214,11 @@
 
                 si->insertTime = 0;
                 si->streamOffset = globals->currentGroupOffset;
+                mediaTS = GetMediaTimeScale(si->theMedia);
+                mediaTS_fl = (Float64) mediaTS;
+                si->streamOffsetSamples = (TimeValue) (mediaTS_fl * globals->currentGroupOffsetSubSecond) -
+                    ((globals->currentGroupOffset % movieTS) * mediaTS / movieTS);
+                dbg_printf("---/  / streamOffset: [%ld, %ld], %lg\n", si->streamOffset, si->streamOffsetSamples, globals->currentGroupOffsetSubSecond);
                 si->incompleteCompensation = 0;
                 si->si_speex.state = kSStateReadingFirstPacket;
 
@@ -268,12 +279,20 @@
                     }
                 }
 
+                if (si->insertTime == 0 && si->streamOffsetSamples > 0) {
+                    dbg_printf("   -   :++: increasing duration (%ld) by sampleOffset: %ld\n", duration, si->streamOffsetSamples);
+                    duration += si->streamOffsetSamples;
+                }
+
                 dbg_printf("   -   :++: adding sampleRef: %lld, len: %d, dur: %d\n", globals->dataOffset, len, duration);
                 ret = AddMediaSampleReference(si->theMedia, S32Set(globals->dataOffset),
                                               len, duration, si->sampleDesc, 1, smp_flags, &inserted); //@@@@ 64-bit enable
                 if (ret == noErr) {
                     TimeValue timeLoaded;
+                    Float64 timeLoadedSubSecond;
 
+                    si->mediaLength += duration;
+
                     dbg_printf("   -   :><: added page %04ld at %14ld (size: %5ld, tsize: %6d), f: %d\n",
                                ogg_page_pageno(opg), inserted,
                                opg->header_len + opg->body_len, len, !logg_page_last_packet_incomplete(opg));
@@ -291,24 +310,23 @@
                                 SetTrackEnabled(si->theTrack, true);
                             }
                         }
-                        /*
-                        if (GetMovieTimeScale(globals->theMovie) < GetMediaTimeScale(si->theMedia)) {
-                            dbg_printf("   # - changing movie time scale: %ld --> %ld\n",
-                                       GetMovieTimeScale(globals->theMovie), GetMediaTimeScale(si->theMedia));
-                            SetMovieTimeScale(globals->theMovie, GetMediaTimeScale(si->theMedia));
-                        }
-                        */
                     }
                     si->insertTime = -1;
-                    timeLoaded = GetTrackOffset(si->theTrack) + GetTrackDuration(si->theTrack);
 
-                    dbg_printf("   -   :><: added page %04ld at %14ld; offset: %ld, duration: %ld (%ld, %ld), mediats: %ld; moviets: %ld, ret = %ld\n",
+                    mediaTS = GetMediaTimeScale(si->theMedia);
+                    mediaTS_fl = (Float64) mediaTS;
+                    timeLoaded = si->streamOffset + si->mediaLength / mediaTS * movieTS + (si->mediaLength % mediaTS) * movieTS / mediaTS;
+                    timeLoadedSubSecond = (Float64) ((si->streamOffset % movieTS * mediaTS / movieTS + si->mediaLength) % mediaTS) / mediaTS_fl;
+
+                    dbg_printf("   -   :><: added page %04ld at %14ld; offset: %ld, duration: %ld (%ld(%lg); %ld; ml: %ld), mediats: %ld; moviets: %ld, ret = %ld\n",
                                ogg_page_pageno(opg), inserted,
-                               GetTrackOffset(si->theTrack), GetTrackDuration(si->theTrack), timeLoaded,
-                               (duration * GetMovieTimeScale(globals->theMovie)) / GetMediaTimeScale(si->theMedia),
-                               GetMediaTimeScale(si->theMedia), GetMovieTimeScale(globals->theMovie), ret);
-                    if (globals->timeLoaded < timeLoaded)
+                               GetTrackOffset(si->theTrack), GetTrackDuration(si->theTrack), timeLoaded, timeLoadedSubSecond,
+                               (duration * movieTS) / mediaTS, si->mediaLength,
+                               mediaTS, movieTS, ret);
+                    if (globals->timeLoaded < timeLoaded || (globals->timeLoaded == timeLoaded && globals->timeLoadedSubSecond < timeLoadedSubSecond)) {
                         globals->timeLoaded = timeLoaded;
+                        globals->timeLoadedSubSecond = timeLoadedSubSecond;
+                    }
 
                     movie_changed = true;
                 }

Modified: trunk/xiph-qt/OggImport/src/stream_vorbis.c
===================================================================
--- trunk/xiph-qt/OggImport/src/stream_vorbis.c	2006-05-07 19:56:31 UTC (rev 11368)
+++ trunk/xiph-qt/OggImport/src/stream_vorbis.c	2006-05-07 22:29:57 UTC (rev 11369)
@@ -144,6 +144,8 @@
 
     si->numChannels = si->si_vorbis.vi.channels;
     si->rate = si->si_vorbis.vi.rate;
+    //si->lastMediaInserted = 0;
+    si->mediaLength = 0;
 
     PtrAndHand(serialnoatom, si->soundDescExtension, sizeof(serialnoatom)); //check errors?
     PtrAndHand(atomhead, si->soundDescExtension, sizeof(atomhead)); //check errors?
@@ -161,6 +163,10 @@
     Boolean loop = true;
     Boolean movie_changed = false;
 
+    TimeValue movieTS = GetMovieTimeScale(globals->theMovie);
+    TimeValue mediaTS = 0;
+    TimeValue mediaTS_fl = 0.0;
+
     ogg_packet op;
 
     switch(si->si_vorbis.state) {
@@ -217,6 +223,11 @@
                 si->si_vorbis.state = kVStateReadingFirstPacket;
                 si->insertTime = 0;
                 si->streamOffset = globals->currentGroupOffset;
+                mediaTS = GetMediaTimeScale(si->theMedia);
+                mediaTS_fl = (Float64) mediaTS;
+                si->streamOffsetSamples = (TimeValue) (mediaTS_fl * globals->currentGroupOffsetSubSecond) -
+                    ((globals->currentGroupOffset % movieTS) * mediaTS / movieTS);
+                dbg_printf("---/  / streamOffset: [%ld, %ld], %lg\n", si->streamOffset, si->streamOffsetSamples, globals->currentGroupOffsetSubSecond);
                 si->incompleteCompensation = 0;
                 loop = false; //there should be an end of page here according to specs...
             }
@@ -273,12 +284,20 @@
                     }
                 }
 
+                if (si->insertTime == 0 && si->streamOffsetSamples > 0) {
+                    dbg_printf("   -   :++: increasing duration (%ld) by sampleOffset: %ld\n", duration, si->streamOffsetSamples);
+                    duration += si->streamOffsetSamples;
+                }
+
                 dbg_printf("   -   :++: adding sampleRef: %lld, len: %d, dur: %d\n", globals->dataOffset, len, duration);
                 ret = AddMediaSampleReference(si->theMedia, S32Set(globals->dataOffset),
                                               len, duration, si->sampleDesc, 1, smp_flags, &inserted); //@@@@ 64-bit enable
                 if (ret == noErr) {
                     TimeValue timeLoaded;
+                    Float64 timeLoadedSubSecond;
 
+                    si->mediaLength += duration;
+
                     dbg_printf("   -   :><: added page %04ld at %14ld (size: %5ld, tsize: %6d), f: %d\n",
                                ogg_page_pageno(opg), inserted,
                                opg->header_len + opg->body_len, len, !logg_page_last_packet_incomplete(opg));
@@ -296,24 +315,23 @@
                                 SetTrackEnabled(si->theTrack, true);
                             }
                         }
-                        /*
-                        if (GetMovieTimeScale(globals->theMovie) < GetMediaTimeScale(si->theMedia)) {
-                            dbg_printf("   # - changing movie time scale: %ld --> %ld\n",
-                                       GetMovieTimeScale(globals->theMovie), GetMediaTimeScale(si->theMedia));
-                            SetMovieTimeScale(globals->theMovie, GetMediaTimeScale(si->theMedia));
-                        }
-                        */
                     }
                     si->insertTime = -1;
-                    timeLoaded = GetTrackDuration(si->theTrack);
 
-                    dbg_printf("   -   :><: added page %04ld at %14ld; offset: %ld, duration: %ld (%ld, %ld), mediats: %ld; moviets: %ld, ret = %ld\n",
+                    mediaTS = GetMediaTimeScale(si->theMedia);
+                    mediaTS_fl = (Float64) mediaTS;
+                    timeLoaded = si->streamOffset + si->mediaLength / mediaTS * movieTS + (si->mediaLength % mediaTS) * movieTS / mediaTS;
+                    timeLoadedSubSecond = (Float64) ((si->streamOffset % movieTS * mediaTS / movieTS + si->mediaLength) % mediaTS) / mediaTS_fl;
+
+                    dbg_printf("   -   :><: added page %04ld at %14ld; offset: %ld, duration: %ld (%ld(%lg); %ld; ml: %ld), mediats: %ld; moviets: %ld, ret = %ld\n",
                                ogg_page_pageno(opg), inserted,
-                               GetTrackOffset(si->theTrack), GetTrackDuration(si->theTrack), timeLoaded,
-                               (duration * GetMovieTimeScale(globals->theMovie)) / GetMediaTimeScale(si->theMedia),
-                               GetMediaTimeScale(si->theMedia), GetMovieTimeScale(globals->theMovie), ret);
-                    if (globals->timeLoaded < timeLoaded)
+                               GetTrackOffset(si->theTrack), GetTrackDuration(si->theTrack), timeLoaded, timeLoadedSubSecond,
+                               (duration * movieTS) / mediaTS, si->mediaLength,
+                               mediaTS, movieTS, ret);
+                    if (globals->timeLoaded < timeLoaded || (globals->timeLoaded == timeLoaded && globals->timeLoadedSubSecond < timeLoadedSubSecond)) {
                         globals->timeLoaded = timeLoaded;
+                        globals->timeLoadedSubSecond = timeLoadedSubSecond;
+                    }
 
                     movie_changed = true;
                 }



More information about the commits mailing list