[xiph-commits] r12356 - in trunk/xiph-qt: . CAFLAC/src OggImport/src build-macosx build-macosx/XiphQT.xcodeproj common tests tests/CAFLAC tests/common tests/data utils

arek at svn.xiph.org arek at svn.xiph.org
Fri Jan 19 16:18:19 PST 2007


Author: arek
Date: 2007-01-19 16:18:04 -0800 (Fri, 19 Jan 2007)
New Revision: 12356

Added:
   trunk/xiph-qt/tests/
   trunk/xiph-qt/tests/CAFLAC/
   trunk/xiph-qt/tests/CAFLAC/OggFLACTests.cpp
   trunk/xiph-qt/tests/CAFLAC/OggFLACTests.h
   trunk/xiph-qt/tests/common/
   trunk/xiph-qt/tests/common/RingBufferTests.cpp
   trunk/xiph-qt/tests/common/RingBufferTests.h
   trunk/xiph-qt/tests/data/
   trunk/xiph-qt/tests/data/flac.ogg.cookie
Modified:
   trunk/xiph-qt/CAFLAC/src/CAFLACDecoder.cpp
   trunk/xiph-qt/CAFLAC/src/CAOggFLACDecoder.cpp
   trunk/xiph-qt/CAFLAC/src/CAOggFLACDecoder.h
   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_flac.h
   trunk/xiph-qt/OggImport/src/stream_speex.h
   trunk/xiph-qt/OggImport/src/stream_theora.h
   trunk/xiph-qt/OggImport/src/stream_types_flac.h
   trunk/xiph-qt/OggImport/src/stream_vorbis.h
   trunk/xiph-qt/build-macosx/Info.plist
   trunk/xiph-qt/build-macosx/XiphQT.xcodeproj/project.pbxproj
   trunk/xiph-qt/common/XCACodec.cpp
   trunk/xiph-qt/utils/ringbuffer.cpp
   trunk/xiph-qt/utils/ringbuffer.h
Log:
Fixed decoding of "high-density" Ogg FLAC streams; started adding some unit tests; workaround for QuickTime VBR bug is back on by default.


Modified: trunk/xiph-qt/CAFLAC/src/CAFLACDecoder.cpp
===================================================================
--- trunk/xiph-qt/CAFLAC/src/CAFLACDecoder.cpp	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/CAFLAC/src/CAFLACDecoder.cpp	2007-01-20 00:18:04 UTC (rev 12356)
@@ -341,8 +341,6 @@
             float* theOutputData = static_cast<float*> (outOutputData) + i + (inFramesOffset * mFLACchannels);
             const FLAC__int32* mono = static_cast<const FLAC__int32*> (mBPtrs[i] + mFrame.header.blocksize - mNumFrames);
 
-            float tempFloat = 0;
-
             for (j = 0; j < inNumberFrames; j++) {
                 *theOutputData = ((float)mono[j]) / cnvrtr;
                 theOutputData += mFLACchannels;
@@ -476,6 +474,15 @@
 {
     const Byte * theData = static_cast<const Byte *> (inInputData) + inPacketDescription->mStartOffset;
     UInt32 size = inPacketDescription->mDataByteSize;
+
+    if (mBDCBuffer.GetSpaceAvailable() <= size) {
+        UInt32 new_size_inc = kFLACDecoderInBufferSize;
+        UInt32 space_needed = size - mBDCBuffer.GetSpaceAvailable() + 1;
+        while (new_size_inc < space_needed)
+            new_size_inc += kFLACDecoderInBufferSize;
+        mBDCBuffer.Reallocate(mBDCBuffer.GetBufferByteSize() + new_size_inc);
+    }
+
     mBDCBuffer.In(theData, size);
     mFLACFPList.push_back(FLACFramePacket(inPacketDescription->mVariableFramesInPacket, inPacketDescription->mDataByteSize));
 };
@@ -498,6 +505,11 @@
         }
     }
 
+    if (get_state() != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC && get_state() != FLAC__STREAM_DECODER_READ_FRAME) {
+        ret = false;
+        mBDCStatus = kBDCStatusAbort;
+    }
+
     return ret;
 };
 
@@ -538,7 +550,7 @@
 
 ::FLAC__StreamDecoderReadStatus CAFLACDecoder::read_callback(FLAC__byte buffer[], size_t *bytes)
 {
-    dbg_printf(" | -> [%08lx] :: read_callback(%ld)\n", (UInt32) this, *bytes);
+    dbg_printf("[  FD]| -> [%08lx] :: read_callback(%ld)\n", (UInt32) this, *bytes);
     FLAC__StreamDecoderReadStatus ret = FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
 
     if (mFLACFPList.empty()) {
@@ -554,21 +566,21 @@
 
         BlockMoveData(mBDCBuffer.GetData(), buffer, *bytes);
 
-        if (*bytes == ffp.left) {
-            mBDCBuffer.Zap(ffp.bytes);
+        mBDCBuffer.Zap(*bytes);
+        ffp.left -= *bytes;
+        if (ffp.left == 0) {
             mFLACFPList.erase(mFLACFPList.begin());
-        } else
-            ffp.left -= *bytes;
+        }
     }
 
-    dbg_printf(" |<-. [%08lx] :: read_callback(%ld) = %ld\n", (UInt32) this, *bytes, ret);
+    dbg_printf("[  FD]|<-. [%08lx] :: read_callback(%ld) = %ld\n", (UInt32) this, *bytes, ret);
     return ret;
 }
 
 ::FLAC__StreamDecoderWriteStatus CAFLACDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
 {
     ::FLAC__StreamDecoderWriteStatus ret = FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
-    dbg_printf(" | +> [%08lx] :: write_callback(%ld)\n", (UInt32) this, frame->header.blocksize);
+    dbg_printf("[  FD]| +> [%08lx] :: write_callback(%ld) [%ld]\n", (UInt32) this, frame->header.blocksize, frame->header.channels);
 
     FLAC__int32** lbuffer = new FLAC__int32*[frame->header.channels];
     for (unsigned int i = 0; i < frame->header.channels; i++) {
@@ -580,7 +592,7 @@
 
     DFPinit(*frame, lbuffer); //MFDFPacket will free the lbuffer on .clear() call
 
-    dbg_printf(" |<+. [%08lx] :: write_callback()\n", (UInt32) this);
+    dbg_printf("[  FD]|<+. [%08lx] :: write_callback()\n", (UInt32) this);
     return ret;
 }
 

Modified: trunk/xiph-qt/CAFLAC/src/CAOggFLACDecoder.cpp
===================================================================
--- trunk/xiph-qt/CAFLAC/src/CAOggFLACDecoder.cpp	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/CAFLAC/src/CAOggFLACDecoder.cpp	2007-01-20 00:18:04 UTC (rev 12356)
@@ -6,7 +6,7 @@
  *    for the actual decoding.
  *
  *
- *  Copyright (c) 2005-2006  Arek Korbik
+ *  Copyright (c) 2005-2007  Arek Korbik
  *
  *  This file is part of XiphQT, the Xiph QuickTime Components.
  *
@@ -42,7 +42,8 @@
 
 CAOggFLACDecoder::CAOggFLACDecoder() :
     CAFLACDecoder(true),
-    mFramesBufferedList()
+    mFramesBufferedList(),
+    complete_pages(0)
 {
     CAStreamBasicDescription theInputFormat(kAudioStreamAnyRate, kAudioFormatXiphOggFramedFLAC,
                                             kFLACBytesPerPacket, kFLACFramesPerPacket,
@@ -99,7 +100,7 @@
 UInt32 CAOggFLACDecoder::ProduceOutputPackets(void* outOutputData, UInt32& ioOutputDataByteSize, UInt32& ioNumberPackets,
                                                 AudioStreamPacketDescription* outPacketDescription)
 {
-    dbg_printf(" >> [%08lx] CAOggFLACDecoder :: ProduceOutputPackets(%ld [%ld])\n", (UInt32) this, ioNumberPackets, ioOutputDataByteSize);
+    dbg_printf("[ oFD]  >> [%08lx] ProduceOutputPackets(%ld [%ld])\n", (UInt32) this, ioNumberPackets, ioOutputDataByteSize);
     UInt32 ret = kAudioCodecProduceOutputPacketSuccess;
 
     if (mFramesBufferedList.empty()) {
@@ -111,26 +112,53 @@
         return ret;
     }
 
-    UInt32 flac_frames = mFramesBufferedList.front();
+    OggPagePacket &opp = mFramesBufferedList.front();
+    UInt32 flac_frames = opp.packets;
+    UInt32 flac_bytes = opp.frames * mOutputFormat.mBytesPerFrame;
     UInt32 ogg_packets = 0;
     UInt32 flac_returned_data = ioOutputDataByteSize;
     UInt32 flac_total_returned_data = 0;
     Byte *the_data = static_cast<Byte*> (outOutputData);
+    Boolean empty_packet = false;
 
     while (true) {
-        UInt32 flac_return = CAFLACDecoder::ProduceOutputPackets(the_data, flac_returned_data, flac_frames, NULL);
+        UInt32 flac_return = kAudioCodecProduceOutputPacketSuccess;
+        empty_packet = false;
+        if (complete_pages < 1) {
+            flac_return = kAudioCodecProduceOutputPacketNeedsMoreInputData;
+            flac_frames = 0;
+            flac_returned_data = 0;
+        } else if (flac_frames == 0) {
+            UInt32 one_flac_frame = 1;
+            empty_packet = true;
+            if (flac_bytes < flac_returned_data) {
+                flac_returned_data = flac_bytes;
+            }
+            flac_return = CAFLACDecoder::ProduceOutputPackets(the_data, flac_returned_data, one_flac_frame, NULL);
+        } else {
+            flac_return = CAFLACDecoder::ProduceOutputPackets(the_data, flac_returned_data, flac_frames, NULL);
+        }
+
         if (flac_return == kAudioCodecProduceOutputPacketSuccess || flac_return == kAudioCodecProduceOutputPacketSuccessHasMore) {
             if (flac_frames > 0)
-                mFramesBufferedList.front() -= flac_frames;
+                opp.packets -= flac_frames;
 
-            if (mFramesBufferedList.front() <= 0) {
+            if (flac_returned_data > 0)
+                opp.frames -= flac_returned_data / mOutputFormat.mBytesPerFrame;
+
+            dbg_printf("[ oFD]     [%08lx] ProduceOutputPackets() p:%ld, f:%ld, c:%ld\n", (UInt32) this, opp.packets, opp.frames, complete_pages);
+            if (opp.packets <= 0 && opp.frames <= 0) {
                 ogg_packets++;
+                if (!empty_packet)
+                    complete_pages--;
                 mFramesBufferedList.erase(mFramesBufferedList.begin());
+                opp = mFramesBufferedList.front();
             }
 
             flac_total_returned_data += flac_returned_data;
 
-            if (flac_total_returned_data == ioOutputDataByteSize || flac_return == kAudioCodecProduceOutputPacketSuccess)
+            if (ogg_packets == ioNumberPackets || flac_total_returned_data == ioOutputDataByteSize ||
+                flac_return == kAudioCodecProduceOutputPacketSuccess)
             {
                 ioNumberPackets = ogg_packets;
                 ioOutputDataByteSize = flac_total_returned_data;
@@ -144,8 +172,28 @@
             } else {
                 the_data += flac_returned_data;
                 flac_returned_data = ioOutputDataByteSize - flac_total_returned_data;
-                flac_frames = mFramesBufferedList.front();
+                flac_frames = opp.packets;
+                flac_bytes = opp.frames * mOutputFormat.mBytesPerFrame;
             }
+        } else if (flac_return == kAudioCodecProduceOutputPacketNeedsMoreInputData) {
+            if (flac_frames > 0)
+                opp.packets -= flac_frames;
+
+            if (flac_returned_data > 0)
+                opp.frames -= flac_returned_data / mOutputFormat.mBytesPerFrame;
+
+            if (opp.packets <= 0 && opp.frames <= 0) {
+                ogg_packets++;
+                if (!empty_packet)
+                    complete_pages--;
+                mFramesBufferedList.erase(mFramesBufferedList.begin());
+                //opp = mFramesBufferedList.front();
+            }
+
+            ret = kAudioCodecProduceOutputPacketNeedsMoreInputData;
+            ioOutputDataByteSize = flac_total_returned_data + flac_returned_data;
+            ioNumberPackets = ogg_packets;
+            break;
         } else {
             ret = kAudioCodecProduceOutputPacketFailure;
             ioOutputDataByteSize = flac_total_returned_data;
@@ -154,7 +202,7 @@
         }
     }
 
-    dbg_printf("<.. [%08lx] CAOggFLACDecoder :: ProduceOutputPackets(%ld [%ld]) = %ld [%ld]\n",
+    dbg_printf("[ oFD] <.. [%08lx] ProduceOutputPackets(%ld [%ld]) = %ld [%ld]\n",
                (UInt32) this, ioNumberPackets, ioOutputDataByteSize, ret, FramesReady());
     return ret;
 }
@@ -168,12 +216,14 @@
 void CAOggFLACDecoder::BDCUninitialize()
 {
     mFramesBufferedList.clear();
+    complete_pages = 0;
     CAFLACDecoder::BDCUninitialize();
 }
 
 void CAOggFLACDecoder::BDCReset()
 {
     mFramesBufferedList.clear();
+    complete_pages = 0;
     if (mCompressionInitialized)
         ogg_stream_reset(&mO_st);
     CAFLACDecoder::BDCReset();
@@ -182,6 +232,7 @@
 void CAOggFLACDecoder::BDCReallocate(UInt32 inInputBufferByteSize)
 {
     mFramesBufferedList.clear();
+    complete_pages = 0;
     CAFLACDecoder::BDCReallocate(inInputBufferByteSize);
 }
 
@@ -193,9 +244,12 @@
 
     ogg_page op;
 
-    if (!WrapOggPage(&op, inInputData, inPacketDescription->mDataByteSize, inPacketDescription->mStartOffset))
+    if (!WrapOggPage(&op, static_cast<const Byte*> (inInputData) + inPacketDescription->mStartOffset, inPacketDescription->mDataByteSize, 0))
         CODEC_THROW(kAudioCodecUnspecifiedError);
 
+    dbg_printf("[ oFD]   : [%08lx] InPacket() [%4.4s] %ld\n", (UInt32) this, (char *) (static_cast<const Byte*> (inInputData) + inPacketDescription->mStartOffset),
+               ogg_page_pageno(&op));
+
     ogg_packet opk;
     SInt32 packet_count = 0;
     int oret;
@@ -216,7 +270,10 @@
         CAFLACDecoder::InPacket(opk.packet, &flac_packet_desc);
     }
 
-    mFramesBufferedList.push_back(packet_count);
+    if (packet_count > 0)
+        complete_pages += 1;
+
+    mFramesBufferedList.push_back(OggPagePacket(packet_count, inPacketDescription->mVariableFramesInPacket));
 }
 
 

Modified: trunk/xiph-qt/CAFLAC/src/CAOggFLACDecoder.h
===================================================================
--- trunk/xiph-qt/CAFLAC/src/CAOggFLACDecoder.h	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/CAFLAC/src/CAOggFLACDecoder.h	2007-01-20 00:18:04 UTC (rev 12356)
@@ -4,7 +4,7 @@
  *    CAOggFLACDecoder class definition.
  *
  *
- *  Copyright (c) 2005-2006  Arek Korbik
+ *  Copyright (c) 2005-2007  Arek Korbik
  *
  *  This file is part of XiphQT, the Xiph QuickTime Components.
  *
@@ -61,7 +61,20 @@
     void                    InitializeCompressionSettings();
 
     ogg_stream_state        mO_st;
-    std::vector<SInt32>     mFramesBufferedList;
+
+    struct OggPagePacket {
+        UInt32 packets;
+        UInt32 frames;
+        //UInt32 left;
+
+        OggPagePacket() : packets(0), frames(0) {};
+        OggPagePacket(UInt32 inPackets, UInt32 inFrames) : packets(inPackets), frames(inFrames) {};
+    };
+
+    typedef std::vector<OggPagePacket> OggPagePacketList;
+    OggPagePacketList mFramesBufferedList;
+
+    UInt32 complete_pages;
 };
 
 

Modified: trunk/xiph-qt/OggImport/src/OggImport.c
===================================================================
--- trunk/xiph-qt/OggImport/src/OggImport.c	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/OggImport/src/OggImport.c	2007-01-20 00:18:04 UTC (rev 12356)
@@ -347,6 +347,9 @@
 {
     ogg_stream_clear(&si->os);
 
+    if (si->sfhf->finish != NULL)
+        /* ret = */ (*si->sfhf->finish)(globals, si);
+
     if (si->sfhf->clear != NULL)
         (*si->sfhf->clear)(si);
 
@@ -476,7 +479,7 @@
     len = strcspn(str, "=");
 
     if (len > 0) {
-        CFStringRef tmpkstr = CFStringCreateWithBytes(NULL, str, len + 1, kCFStringEncodingUTF8, true);
+        CFStringRef tmpkstr = CFStringCreateWithBytes(NULL, (const UInt8 *) str, len + 1, kCFStringEncodingUTF8, true);
         if (tmpkstr != NULL) {
             CFMutableStringRef keystr = CFStringCreateMutableCopy(NULL, len + 1, tmpkstr);
             if (keystr != NULL) {
@@ -518,7 +521,7 @@
     len = strcspn(str, "=");
 
     if (len > 0) {
-        CFStringRef tmpkstr = CFStringCreateWithBytes(NULL, str, len + 1, kCFStringEncodingUTF8, true);
+        CFStringRef tmpkstr = CFStringCreateWithBytes(NULL, (const UInt8 *) str, len + 1, kCFStringEncodingUTF8, true);
         if (tmpkstr != NULL) {
             CFMutableStringRef keystr = CFStringCreateMutableCopy(NULL, len + 1, tmpkstr);
             if (keystr != NULL) {
@@ -553,7 +556,7 @@
     CFIndex numberOfCharsConverted = 0, usedBufferLength = 0;
     OSStatus ret = noErr;
 
-    CFStringRef tmpstr = CFStringCreateWithBytes(NULL, str, strlen(str), kCFStringEncodingUTF8, true);
+    CFStringRef tmpstr = CFStringCreateWithBytes(NULL, (const UInt8 *) str, strlen(str), kCFStringEncodingUTF8, true);
     if (tmpstr == NULL)
         return  kTextUnsupportedEncodingErr; //!??!?!
 
@@ -569,7 +572,7 @@
                 HLock(*h);
 
                 numberOfCharsConverted = CFStringGetBytes(tmpstr, range, encoding, 0,
-                                                          false, **h, usedBufferLength,
+                                                          false, (UInt8 *) **h, usedBufferLength,
                                                           &usedBufferLength);
                 HUnlock(*h);
             } else {
@@ -596,7 +599,7 @@
         dbg_printf("-- TAG: %08lx\n", tag);
 
         ret = QTMetaDataAddItem(md, kQTMetaDataStorageFormatQuickTime, kQTMetaDataKeyFormatCommon,
-                                &tag, sizeof(tag), str + tagLen, len - tagLen, kQTMetaDataTypeUTF8, NULL);
+                                (UInt8 *) &tag, sizeof(tag), (UInt8 *) (str + tagLen), len - tagLen, kQTMetaDataTypeUTF8, NULL);
         dbg_printf("-- TAG: %4.4s :: QT    = %ld\n", (char *)&tag, (long)ret);
     }
 
@@ -615,7 +618,7 @@
         if (ret == noErr) {
             HLock(h);
             ret = QTMetaDataAddItem(md, kQTMetaDataStorageFormatUserData, kQTMetaDataKeyFormatUserData,
-                                    &tag, sizeof(tag), *h, GetHandleSize(h), kQTMetaDataTypeMacEncodedText, &mdi);
+                                    (UInt8 *) &tag, sizeof(tag), (UInt8 *) *h, GetHandleSize(h), kQTMetaDataTypeMacEncodedText, &mdi);
             dbg_printf("-- TAG: %4.4s :: QT[X] = %ld\n", (char *)&tag, (long)ret);
             HUnlock(h);
             if (ret == noErr) {

Modified: trunk/xiph-qt/OggImport/src/importer_types.h
===================================================================
--- trunk/xiph-qt/OggImport/src/importer_types.h	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/OggImport/src/importer_types.h	2007-01-20 00:18:04 UTC (rev 12356)
@@ -220,6 +220,7 @@
 
 typedef int (*process_first_packet) (StreamInfo *si, ogg_page *op, ogg_packet *opckt);
 typedef ComponentResult (*process_stream_page) (OggImportGlobals *globals, StreamInfo *si, ogg_page *opg);
+typedef ComponentResult (*finish_stream) (OggImportGlobals *globals, StreamInfo *si);
 
 
 typedef struct stream_format_handle_funcs {
@@ -234,9 +235,10 @@
     create_track_media                  track_media;
 
     initialize_stream                   initialize;
+    finish_stream                       finish;
     clear_stream                        clear;
 } stream_format_handle_funcs;
 
-#define HANDLE_FUNCTIONS__NULL { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
+#define HANDLE_FUNCTIONS__NULL { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
 
 #endif /* __importer_types_h__ */

Modified: trunk/xiph-qt/OggImport/src/stream_flac.c
===================================================================
--- trunk/xiph-qt/OggImport/src/stream_flac.c	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/OggImport/src/stream_flac.c	2007-01-20 00:18:04 UTC (rev 12356)
@@ -41,9 +41,64 @@
 #include "data_types.h"
 #include "utils.h"
 
-#undef INCOMPLETE_PAGE_DURATION
-#define INCOMPLETE_PAGE_DURATION 10
+static ComponentResult _commit_srefs(OggImportGlobals *globals, StreamInfo *si, Boolean *movie_changed)
+{
+    ComponentResult ret = noErr;
+    TimeValue inserted  = 0;
 
+    TimeValue movieTS = GetMovieTimeScale(globals->theMovie);
+    TimeValue mediaTS = 0;
+    TimeValue mediaTS_fl = 0.0;
+
+    if (si->si_flac.sample_refs_count < 1)
+        return ret;
+
+    dbg_printf("   -   :++: adding sampleRefs: %lld, count: %ld, dur: %ld\n", globals->dataOffset, si->si_flac.sample_refs_count,
+               si->si_flac.sample_refs_duration);
+    ret = AddMediaSampleReferences64(si->theMedia, si->sampleDesc, si->si_flac.sample_refs_count, si->si_flac.sample_refs, &inserted);
+
+    if (ret == noErr) {
+        TimeValue timeLoaded;
+        Float64 timeLoadedSubSecond;
+
+        si->mediaLength += si->si_flac.sample_refs_duration;
+
+        ret = InsertMediaIntoTrack(si->theTrack, si->insertTime, inserted,
+                                   si->si_flac.sample_refs_duration, fixed1);
+        if (si->insertTime == 0) {
+            if (si->streamOffset != 0) {
+                SetTrackOffset(si->theTrack, si->streamOffset);
+                dbg_printf("   # -- SetTrackOffset(%ld) = %ld --> %ld\n",
+                           si->streamOffset, GetMoviesError(),
+                           GetTrackOffset(si->theTrack));
+                if (globals->dataIsStream) {
+                    SetTrackEnabled(si->theTrack, false);
+                    SetTrackEnabled(si->theTrack, true);
+                }
+            }
+        }
+        si->insertTime = -1;
+
+        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;
+
+        if (globals->timeLoaded < timeLoaded || (globals->timeLoaded == timeLoaded && globals->timeLoadedSubSecond < timeLoadedSubSecond)) {
+            globals->timeLoaded = timeLoaded;
+            globals->timeLoadedSubSecond = timeLoadedSubSecond;
+        }
+
+        *movie_changed = true;
+
+        si->si_flac.sample_refs_duration = 0;
+        si->si_flac.sample_refs_count = 0;
+    }
+
+    return ret;
+};
+
+
 int recognize_header__flac(ogg_page *op)
 {
     char fh[] = {0x7f, 'F', 'L', 'A', 'C', '\0'};
@@ -77,9 +132,7 @@
 
     si->si_flac.sample_refs_count = 0;
     si->si_flac.sample_refs_duration = 0;
-    //si->si_flac.sample_refs_size = kSRefsInitial;
-    //si->si_flac.sample_refs_size = 64;
-    si->si_flac.sample_refs_size = 1;
+    si->si_flac.sample_refs_size = kSRefsInitial;
     si->si_flac.sample_refs = calloc(si->si_flac.sample_refs_size, sizeof(SampleReference64Record));
 
     if (si->si_flac.sample_refs == NULL)
@@ -326,7 +379,6 @@
                 ogg_int64_t pos       = ogg_page_granulepos(opg);
                 int         len       = opg->header_len + opg->body_len;
                 TimeValue   duration  = pos - si->lastGranulePos;
-                TimeValue   inserted  = 0;
                 short       smp_flags = 0;
 
                 if (ogg_page_continued(opg) || si->incompleteCompensation != 0)
@@ -377,112 +429,13 @@
                 }
 
                 // change the condition...?
-                //if (si->si_flac.sample_refs_count >= si->si_flac.sample_refs_size || ogg_page_eos(opg)) {
-                if (/*si->si_flac.sample_refs_count >= si->si_flac.sample_refs_size ||*/ ogg_page_eos(opg)) {
-                    dbg_printf("   -   :++: adding sampleRefs: %lld, count: %ld, dur: %ld\n", globals->dataOffset, si->si_flac.sample_refs_count,
-                               si->si_flac.sample_refs_duration);
-                    ret = AddMediaSampleReferences64(si->theMedia, si->sampleDesc, si->si_flac.sample_refs_count, si->si_flac.sample_refs, &inserted);
-
-                    if (ret == noErr) {
-                        TimeValue timeLoaded;
-                        Float64 timeLoadedSubSecond;
-
-                        si->mediaLength += si->si_flac.sample_refs_duration;
-
-                        dbg_printf("   -   :><: added page %04ld at %14ld, f: %d\n",
-                                   ogg_page_pageno(opg), inserted, !logg_page_last_packet_incomplete(opg));
-                        dbg_printf("   -   :><: d:%ld, dd:%lld, ds:%ld\n", GetMediaDuration(si->theMedia), GetMediaDecodeDuration(si->theMedia),
-                                   GetMediaDataSize(si->theMedia, 0, inserted + duration));
-                        dbg_printf("   -   :/>: inserting media: %ld, mt: %ld, dur: %d\n", si->insertTime, /* si->lastGranulePos */ inserted,
-                                   si->si_flac.sample_refs_duration);
-                        ret = InsertMediaIntoTrack(si->theTrack, si->insertTime /*inserted*/, /* si->lastGranulePos */ inserted,
-                                                   si->si_flac.sample_refs_duration, fixed1);
-                        if (si->insertTime == 0) {
-                            if (si->streamOffset != 0) {
-                                SetTrackOffset(si->theTrack, si->streamOffset);
-                                dbg_printf("   # -- SetTrackOffset(%ld) = %ld --> %ld\n",
-                                           si->streamOffset, GetMoviesError(),
-                                           GetTrackOffset(si->theTrack));
-                                if (globals->dataIsStream) {
-                                    SetTrackEnabled(si->theTrack, false);
-                                    SetTrackEnabled(si->theTrack, true);
-                                }
-                            }
-                        }
-                        si->insertTime = -1;
-
-                        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, 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;
-
-                        si->si_flac.sample_refs_duration = 0;
-                        si->si_flac.sample_refs_count = 0;
-                    }
+#if !defined(XIPHQT_FORCE_SINGLE_SAMPLE_REF)
+                if (si->si_flac.sample_refs_count >= si->si_flac.sample_refs_size)
+#endif
+                {
+                    ret = _commit_srefs(globals, si, &movie_changed);
                 }
-#if 0
-                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));
-                    dbg_printf("   -   :><: d:%ld, dd:%lld, ds:%ld\n", GetMediaDuration(si->theMedia), GetMediaDecodeDuration(si->theMedia),
-                               GetMediaDataSize(si->theMedia, 0, inserted + duration));
-                    dbg_printf("   -   :/>: inserting media: %ld, mt: %ld, dur: %d\n", si->insertTime, /* si->lastGranulePos */ inserted, duration);
-                    ret = InsertMediaIntoTrack(si->theTrack, si->insertTime /*inserted*/, /* si->lastGranulePos */ inserted,
-                                               duration, fixed1);
-                    if (si->insertTime == 0) {
-                        if (si->streamOffset != 0) {
-                            SetTrackOffset(si->theTrack, si->streamOffset);
-                            dbg_printf("   # -- SetTrackOffset(%ld) = %ld --> %ld\n",
-                                       si->streamOffset, GetMoviesError(),
-                                       GetTrackOffset(si->theTrack));
-                            if (globals->dataIsStream) {
-                                SetTrackEnabled(si->theTrack, false);
-                                SetTrackEnabled(si->theTrack, true);
-                            }
-                        }
-                    }
-                    si->insertTime = -1;
-
-                    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, 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;
-                }
-#endif
-
                 if (pos != -1)
                     si->lastGranulePos = pos;
             }
@@ -499,3 +452,16 @@
 
     return ret;
 };
+
+ComponentResult finish_stream__flac(OggImportGlobals *globals, StreamInfo *si)
+{
+    ComponentResult ret = noErr;
+    Boolean movie_changed = false;
+
+    ret = _commit_srefs(globals, si, &movie_changed);
+
+    if (movie_changed)
+        NotifyMovieChanged(globals);
+
+    return ret;
+};

Modified: trunk/xiph-qt/OggImport/src/stream_flac.h
===================================================================
--- trunk/xiph-qt/OggImport/src/stream_flac.h	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/OggImport/src/stream_flac.h	2007-01-20 00:18:04 UTC (rev 12356)
@@ -47,10 +47,11 @@
 
 extern int process_first_packet__flac(StreamInfo *si, ogg_page *op, ogg_packet *opckt);
 extern ComponentResult process_stream_page__flac(OggImportGlobals *globals, StreamInfo *si, ogg_page *opg);
+extern ComponentResult finish_stream__flac(OggImportGlobals *globals, StreamInfo *si);
 
 #define HANDLE_FUNCTIONS__FLAC { &process_stream_page__flac, &recognize_header__flac, \
             &verify_header__flac, &process_first_packet__flac, &create_sample_description__flac, \
-            NULL, NULL, &initialize_stream__flac, &clear_stream__flac }
+            NULL, NULL, &initialize_stream__flac, &finish_stream__flac, &clear_stream__flac }
 
 
 #endif /* __stream_flac_h__ */

Modified: trunk/xiph-qt/OggImport/src/stream_speex.h
===================================================================
--- trunk/xiph-qt/OggImport/src/stream_speex.h	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/OggImport/src/stream_speex.h	2007-01-20 00:18:04 UTC (rev 12356)
@@ -48,7 +48,7 @@
 
 #define HANDLE_FUNCTIONS__SPEEX { &process_stream_page__speex, &recognize_header__speex, \
             &verify_header__speex, &process_first_packet__speex, &create_sample_description__speex, \
-            NULL, NULL, &initialize_stream__speex, &clear_stream__speex }
+            NULL, NULL, &initialize_stream__speex, NULL, &clear_stream__speex }
 
 
 #endif /* __stream_vorbis_h__ */

Modified: trunk/xiph-qt/OggImport/src/stream_theora.h
===================================================================
--- trunk/xiph-qt/OggImport/src/stream_theora.h	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/OggImport/src/stream_theora.h	2007-01-20 00:18:04 UTC (rev 12356)
@@ -51,7 +51,7 @@
 
 #define HANDLE_FUNCTIONS__THEORA { &process_stream_page__theora, &recognize_header__theora, \
             &verify_header__theora, &process_first_packet__theora, &create_sample_description__theora, \
-            &create_track__theora, &create_track_media__theora, &initialize_stream__theora, &clear_stream__theora }
+            &create_track__theora, &create_track_media__theora, &initialize_stream__theora, NULL, &clear_stream__theora }
 
 
 #endif /* __stream_theora_h__ */

Modified: trunk/xiph-qt/OggImport/src/stream_types_flac.h
===================================================================
--- trunk/xiph-qt/OggImport/src/stream_types_flac.h	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/OggImport/src/stream_types_flac.h	2007-01-20 00:18:04 UTC (rev 12356)
@@ -44,8 +44,8 @@
 } FLACImportStates;
 
 enum {
-    kSRefsInitial = 32,
-    kSRefsIncrement = 8
+    kSRefsInitial = 4096,
+    kSRefsIncrement = 4096
 };
 
 typedef struct {

Modified: trunk/xiph-qt/OggImport/src/stream_vorbis.h
===================================================================
--- trunk/xiph-qt/OggImport/src/stream_vorbis.h	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/OggImport/src/stream_vorbis.h	2007-01-20 00:18:04 UTC (rev 12356)
@@ -48,7 +48,7 @@
 
 #define HANDLE_FUNCTIONS__VORBIS { &process_stream_page__vorbis, &recognize_header__vorbis, \
             &verify_header__vorbis, &process_first_packet__vorbis, &create_sample_description__vorbis, \
-            NULL, NULL, &initialize_stream__vorbis, &clear_stream__vorbis }
+            NULL, NULL, &initialize_stream__vorbis, NULL, &clear_stream__vorbis }
 
 
 #endif /* __stream_vorbis_h__ */

Modified: trunk/xiph-qt/build-macosx/Info.plist
===================================================================
--- trunk/xiph-qt/build-macosx/Info.plist	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/build-macosx/Info.plist	2007-01-20 00:18:04 UTC (rev 12356)
@@ -7,7 +7,7 @@
 	<key>CFBundleExecutable</key>
 	<string>XiphQT</string>
 	<key>CFBundleGetInfoString</key>
-	<string>Xiph QuickTime Components 0.1.7, Copyright © 2005-2006 Arek Korbik</string>
+	<string>Xiph QuickTime Components 0.1.7, Copyright © 2005-2007 Arek Korbik</string>
 	<key>CFBundleIconFile</key>
 	<string></string>
 	<key>CFBundleIdentifier</key>
@@ -23,7 +23,7 @@
 	<key>CFBundleShortVersionString</key>
 	<string>0.1.7</string>
 	<key>NSHumanReadableCopyright</key>
-	<string>Xiph QuickTime Components 0.1.7, Copyright © 2005-2006 Arek Korbik</string>
+	<string>Xiph QuickTime Components 0.1.7, Copyright © 2005-2007 Arek Korbik</string>
 	<key>CSResourcesFileMapped</key>
 	<true/>
 </dict>

Modified: trunk/xiph-qt/build-macosx/XiphQT.xcodeproj/project.pbxproj
===================================================================
--- trunk/xiph-qt/build-macosx/XiphQT.xcodeproj/project.pbxproj	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/build-macosx/XiphQT.xcodeproj/project.pbxproj	2007-01-20 00:18:04 UTC (rev 12356)
@@ -53,6 +53,7 @@
 		7326B5480B5AC44B004CE9D3 /* TheoraDecoder.r in Rez */ = {isa = PBXBuildFile; fileRef = 73744A870B1A0AFF002B059E /* TheoraDecoder.r */; };
 		7326B54A0B5AC44B004CE9D3 /* CAFLACDecoderPublic.r in Rez */ = {isa = PBXBuildFile; fileRef = 73744C6C0B1A2B78002B059E /* CAFLACDecoderPublic.r */; };
 		7326B54D0B5AC44B004CE9D3 /* MetaDataConfig.plist in CopyFiles */ = {isa = PBXBuildFile; fileRef = 737449730B19F922002B059E /* MetaDataConfig.plist */; };
+		73271C840B610B2400175874 /* RingBufferTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73271C830B610B2400175874 /* RingBufferTests.cpp */; };
 		737448B60B19EC05002B059E /* common.c in Sources */ = {isa = PBXBuildFile; fileRef = 7374489F0B19EC05002B059E /* common.c */; };
 		737448B70B19EC05002B059E /* OggImport.c in Sources */ = {isa = PBXBuildFile; fileRef = 737448A20B19EC05002B059E /* OggImport.c */; };
 		737448B80B19EC05002B059E /* rb.c in Sources */ = {isa = PBXBuildFile; fileRef = 737448A50B19EC05002B059E /* rb.c */; };
@@ -106,6 +107,20 @@
 		73744CB20B1A3D07002B059E /* stream_video.c in Sources */ = {isa = PBXBuildFile; fileRef = 73744CA70B1A3D07002B059E /* stream_video.c */; };
 		73744CB70B1A3D5E002B059E /* OggExport.nib in Resources */ = {isa = PBXBuildFile; fileRef = 73744CB50B1A3D5E002B059E /* OggExport.nib */; };
 		73744CB80B1A3D5E002B059E /* OggExport.r in Rez */ = {isa = PBXBuildFile; fileRef = 73744CB60B1A3D5E002B059E /* OggExport.r */; };
+		73C752A90B5FB82C00615F6C /* OggFLACTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73C752A80B5FB82C00615F6C /* OggFLACTests.cpp */; };
+		73C752E40B5FC02D00615F6C /* CAOggFLACDecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73744C620B1A2AD8002B059E /* CAOggFLACDecoder.cpp */; };
+		73C752E60B5FD84400615F6C /* ACBaseCodec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73744A030B1A0270002B059E /* ACBaseCodec.cpp */; };
+		73C752E70B5FD84500615F6C /* ACCodec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73744A050B1A0270002B059E /* ACCodec.cpp */; };
+		73C752E90B5FD85400615F6C /* CAStreamBasicDescription.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73744A1B0B1A0288002B059E /* CAStreamBasicDescription.cpp */; };
+		73C752EB0B5FD87000615F6C /* wrap_ogg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 737449F50B1A0159002B059E /* wrap_ogg.cpp */; };
+		73C752EC0B5FD87400615F6C /* XCACodec.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 737449EF0B1A012B002B059E /* XCACodec.cpp */; };
+		73C752EE0B5FD89100615F6C /* CAFLACDecoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73744C600B1A2AD8002B059E /* CAFLACDecoder.cpp */; };
+		73C752F00B5FD8AD00615F6C /* CABundleLocker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73744A150B1A0288002B059E /* CABundleLocker.cpp */; };
+		73C752F10B5FD8BB00615F6C /* ringbuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 737449F30B1A0159002B059E /* ringbuffer.cpp */; };
+		73C752F30B5FD8D300615F6C /* GetCodecBundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 73744A0A0B1A0270002B059E /* GetCodecBundle.cpp */; };
+		73C752FA0B5FD91100615F6C /* libflac++.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 73744C420B1A25B2002B059E /* libflac++.a */; };
+		73C752FB0B5FD91200615F6C /* libflac.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 73744C400B1A25B2002B059E /* libflac.a */; };
+		73C752FD0B5FD92200615F6C /* libogg.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 730B1CC80B19C38700E06B34 /* libogg.a */; };
 		8D01CCCA0486CAD60068D4B7 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C167DFE841241C02AAC07 /* InfoPlist.strings */; };
 		8D01CCCE0486CAD60068D4B7 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08EA7FFBFE8413EDC02AAC07 /* Carbon.framework */; };
 /* End PBXBuildFile section */
@@ -352,6 +367,8 @@
 		32BAE0B30371A71500C91783 /* XiphQT_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XiphQT_Prefix.pch; sourceTree = "<group>"; };
 		7326B5510B5AC44B004CE9D3 /* XiphQT (decoders).component */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "XiphQT (decoders).component"; sourceTree = BUILT_PRODUCTS_DIR; };
 		7326B5520B5AC44B004CE9D3 /* Info (decoders).plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "Info (decoders).plist"; sourceTree = "<group>"; };
+		73271C820B610B2400175874 /* RingBufferTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RingBufferTests.h; path = ../tests/common/RingBufferTests.h; sourceTree = SOURCE_ROOT; };
+		73271C830B610B2400175874 /* RingBufferTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RingBufferTests.cpp; path = ../tests/common/RingBufferTests.cpp; sourceTree = SOURCE_ROOT; };
 		7374489F0B19EC05002B059E /* common.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = common.c; path = ../OggImport/src/common.c; sourceTree = SOURCE_ROOT; };
 		737448A00B19EC05002B059E /* common.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = common.h; path = ../OggImport/src/common.h; sourceTree = SOURCE_ROOT; };
 		737448A10B19EC05002B059E /* importer_types.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = importer_types.h; path = ../OggImport/src/importer_types.h; sourceTree = SOURCE_ROOT; };
@@ -462,6 +479,10 @@
 		738837D00B1938B1005C7A69 /* TheoraExp.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = TheoraExp.xcodeproj; path = "../external-libs/theora-exp/macosx/TheoraExp.xcodeproj"; sourceTree = SOURCE_ROOT; };
 		738837DE0B1938DC005C7A69 /* Theora.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Theora.xcodeproj; path = "../external-libs/theora/macosx/Theora.xcodeproj"; sourceTree = SOURCE_ROOT; };
 		738A452D0B18659A00B43A0C /* Ogg.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Ogg.xcodeproj; path = "../external-libs/ogg/macosx/Ogg.xcodeproj"; sourceTree = SOURCE_ROOT; };
+		73C752920B5FB59100615F6C /* tests.cptest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = tests.cptest; sourceTree = BUILT_PRODUCTS_DIR; };
+		73C752930B5FB59100615F6C /* tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "tests-Info.plist"; sourceTree = "<group>"; };
+		73C752A70B5FB82C00615F6C /* OggFLACTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OggFLACTests.h; path = ../tests/CAFLAC/OggFLACTests.h; sourceTree = SOURCE_ROOT; };
+		73C752A80B5FB82C00615F6C /* OggFLACTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = OggFLACTests.cpp; path = ../tests/CAFLAC/OggFLACTests.cpp; sourceTree = SOURCE_ROOT; };
 		8D01CCD10486CAD60068D4B7 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
 		8D01CCD20486CAD60068D4B7 /* XiphQT.component */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = XiphQT.component; sourceTree = BUILT_PRODUCTS_DIR; };
 /* End PBXFileReference section */
@@ -485,6 +506,16 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
+		73C7528F0B5FB59100615F6C /* Frameworks */ = {
+			isa = PBXFrameworksBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				73C752FA0B5FD91100615F6C /* libflac++.a in Frameworks */,
+				73C752FB0B5FD91200615F6C /* libflac.a in Frameworks */,
+				73C752FD0B5FD92200615F6C /* libogg.a in Frameworks */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 		8D01CCCD0486CAD60068D4B7 /* Frameworks */ = {
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
@@ -511,9 +542,11 @@
 			children = (
 				08FB77ADFE841716C02AAC07 /* Source */,
 				089C167CFE841241C02AAC07 /* Resources */,
+				73C752A30B5FB78300615F6C /* Tests */,
 				738A45290B18604100B43A0C /* libs */,
 				089C1671FE841209C02AAC07 /* External Frameworks and Libraries */,
 				19C28FB4FE9D528D11CA2CBB /* Products */,
+				73C752930B5FB59100615F6C /* tests-Info.plist */,
 			);
 			name = XiphQT;
 			sourceTree = "<group>";
@@ -566,6 +599,7 @@
 			children = (
 				8D01CCD20486CAD60068D4B7 /* XiphQT.component */,
 				7326B5510B5AC44B004CE9D3 /* XiphQT (decoders).component */,
+				73C752920B5FB59100615F6C /* tests.cptest */,
 			);
 			name = Products;
 			sourceTree = "<group>";
@@ -617,6 +651,15 @@
 			name = Products;
 			sourceTree = "<group>";
 		};
+		73271C7F0B610A9600175874 /* common */ = {
+			isa = PBXGroup;
+			children = (
+				73271C820B610B2400175874 /* RingBufferTests.h */,
+				73271C830B610B2400175874 /* RingBufferTests.cpp */,
+			);
+			name = common;
+			sourceTree = "<group>";
+		};
 		737448880B19EAE7002B059E /* OggImport */ = {
 			isa = PBXGroup;
 			children = (
@@ -920,6 +963,24 @@
 			name = libs;
 			sourceTree = "<group>";
 		};
+		73C752A30B5FB78300615F6C /* Tests */ = {
+			isa = PBXGroup;
+			children = (
+				73C752A40B5FB79A00615F6C /* CAFLAC */,
+				73271C7F0B610A9600175874 /* common */,
+			);
+			name = Tests;
+			sourceTree = "<group>";
+		};
+		73C752A40B5FB79A00615F6C /* CAFLAC */ = {
+			isa = PBXGroup;
+			children = (
+				73C752A70B5FB82C00615F6C /* OggFLACTests.h */,
+				73C752A80B5FB82C00615F6C /* OggFLACTests.cpp */,
+			);
+			name = CAFLAC;
+			sourceTree = "<group>";
+		};
 /* End PBXGroup section */
 
 /* Begin PBXNativeTarget section */
@@ -949,6 +1010,24 @@
 			productReference = 7326B5510B5AC44B004CE9D3 /* XiphQT (decoders).component */;
 			productType = "com.apple.product-type.bundle";
 		};
+		73C752910B5FB59100615F6C /* tests */ = {
+			isa = PBXNativeTarget;
+			buildConfigurationList = 73C752940B5FB59200615F6C /* Build configuration list for PBXNativeTarget "tests" */;
+			buildPhases = (
+				73C7528D0B5FB59100615F6C /* Resources */,
+				73C7528E0B5FB59100615F6C /* Sources */,
+				73C7528F0B5FB59100615F6C /* Frameworks */,
+				73C752900B5FB59100615F6C /* ShellScript */,
+			);
+			buildRules = (
+			);
+			dependencies = (
+			);
+			name = tests;
+			productName = tests;
+			productReference = 73C752920B5FB59100615F6C /* tests.cptest */;
+			productType = "com.apple.product-type.bundle";
+		};
 		8D01CCC60486CAD60068D4B7 /* XiphQT */ = {
 			isa = PBXNativeTarget;
 			buildConfigurationList = 4FADC23308B4156C00ABE55E /* Build configuration list for PBXNativeTarget "XiphQT" */;
@@ -1015,6 +1094,7 @@
 			targets = (
 				8D01CCC60486CAD60068D4B7 /* XiphQT */,
 				7326B5010B5AC44B004CE9D3 /* XiphQT (decoders) */,
+				73C752910B5FB59100615F6C /* tests */,
 			);
 		};
 /* End PBXProject section */
@@ -1143,6 +1223,13 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
+		73C7528D0B5FB59100615F6C /* Resources */ = {
+			isa = PBXResourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 		8D01CCC90486CAD60068D4B7 /* Resources */ = {
 			isa = PBXResourcesBuildPhase;
 			buildActionMask = 2147483647;
@@ -1184,6 +1271,22 @@
 		};
 /* End PBXRezBuildPhase section */
 
+/* Begin PBXShellScriptBuildPhase section */
+		73C752900B5FB59100615F6C /* ShellScript */ = {
+			isa = PBXShellScriptBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			inputPaths = (
+			);
+			outputPaths = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+			shellPath = /bin/sh;
+			shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n";
+		};
+/* End PBXShellScriptBuildPhase section */
+
 /* Begin PBXSourcesBuildPhase section */
 		7326B5150B5AC44B004CE9D3 /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
@@ -1220,6 +1323,25 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
+		73C7528E0B5FB59100615F6C /* Sources */ = {
+			isa = PBXSourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				73C752A90B5FB82C00615F6C /* OggFLACTests.cpp in Sources */,
+				73C752E40B5FC02D00615F6C /* CAOggFLACDecoder.cpp in Sources */,
+				73C752E60B5FD84400615F6C /* ACBaseCodec.cpp in Sources */,
+				73C752E70B5FD84500615F6C /* ACCodec.cpp in Sources */,
+				73C752E90B5FD85400615F6C /* CAStreamBasicDescription.cpp in Sources */,
+				73C752EB0B5FD87000615F6C /* wrap_ogg.cpp in Sources */,
+				73C752EC0B5FD87400615F6C /* XCACodec.cpp in Sources */,
+				73C752EE0B5FD89100615F6C /* CAFLACDecoder.cpp in Sources */,
+				73C752F00B5FD8AD00615F6C /* CABundleLocker.cpp in Sources */,
+				73C752F10B5FD8BB00615F6C /* ringbuffer.cpp in Sources */,
+				73C752F30B5FD8D300615F6C /* GetCodecBundle.cpp in Sources */,
+				73271C840B610B2400175874 /* RingBufferTests.cpp in Sources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 		8D01CCCB0486CAD60068D4B7 /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
@@ -1357,7 +1479,7 @@
 				GCC_PREFIX_HEADER = XiphQT_Prefix.pch;
 				GCC_PREPROCESSOR_DEFINITIONS = (
 					"$(inherited)",
-					"XIPHQT_BUNDLE_ID=org.xiph.xiph-qt.xiphqt",
+					XIPHQT_BUNDLE_ID,
 				);
 				HEADER_SEARCH_PATHS = (
 					"$(inherited)",
@@ -1389,7 +1511,7 @@
 				GCC_PREFIX_HEADER = XiphQT_Prefix.pch;
 				GCC_PREPROCESSOR_DEFINITIONS = (
 					"$(inherited)",
-					"XIPHQT_BUNDLE_ID=org.xiph.xiph-qt.xiphqt",
+					XIPHQT_BUNDLE_ID,
 				);
 				HEADER_SEARCH_PATHS = (
 					"$(inherited)",
@@ -1420,6 +1542,7 @@
 				GCC_PREPROCESSOR_DEFINITIONS = (
 					"$(inherited)",
 					__MACOSX__,
+					QT_IA32__VBR_BROKEN,
 				);
 				GCC_WARN_ABOUT_RETURN_TYPE = YES;
 				GCC_WARN_UNUSED_VARIABLE = YES;
@@ -1436,6 +1559,7 @@
 					"$(inherited)",
 					__MACOSX__,
 					NDEBUG,
+					QT_IA32__VBR_BROKEN,
 				);
 				GCC_WARN_ABOUT_RETURN_TYPE = YES;
 				GCC_WARN_UNUSED_VARIABLE = YES;
@@ -1454,7 +1578,7 @@
 				GCC_PREFIX_HEADER = XiphQT_Prefix.pch;
 				GCC_PREPROCESSOR_DEFINITIONS = (
 					"$(inherited)",
-					"XIPHQT_BUNDLE_ID=org.xiph.xiph-qt.xiphqt-decoders",
+					XIPHQT_BUNDLE_ID,
 					XIPHQT_NO_ENCODERS,
 				);
 				HEADER_SEARCH_PATHS = (
@@ -1487,7 +1611,7 @@
 				GCC_PREFIX_HEADER = XiphQT_Prefix.pch;
 				GCC_PREPROCESSOR_DEFINITIONS = (
 					"$(inherited)",
-					"XIPHQT_BUNDLE_ID=org.xiph.xiph-qt.xiphqt-decoders",
+					XIPHQT_BUNDLE_ID,
 					XIPHQT_NO_ENCODERS,
 				);
 				HEADER_SEARCH_PATHS = (
@@ -1512,6 +1636,86 @@
 			};
 			name = Release;
 		};
+		73C752950B5FB59200615F6C /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				COPY_PHASE_STRIP = NO;
+				GCC_DYNAMIC_NO_PIC = NO;
+				GCC_ENABLE_FIX_AND_CONTINUE = NO;
+				GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
+				GCC_MODEL_TUNING = G4;
+				GCC_OPTIMIZATION_LEVEL = 0;
+				GCC_PRECOMPILE_PREFIX_HEADER = YES;
+				GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/Carbon.framework/Headers/Carbon.h";
+				GCC_PREPROCESSOR_DEFINITIONS = (
+					"$(inherited)",
+					NDEBUG,
+				);
+				HEADER_SEARCH_PATHS = (
+					"$(inherited)",
+					"../external-libs/ogg/include",
+					"../external-libs/vorbis/include",
+					"../external-libs/speex/include",
+					"../external-libs/theora-exp/include",
+					"../external-libs/theora/include",
+					"../external-libs/flac/include",
+					../CAFLAC/src,
+					../utils,
+				);
+				INFOPLIST_FILE = "tests-Info.plist";
+				INSTALL_PATH = "$(USER_LIBRARY_DIR)/Bundles";
+				OTHER_LDFLAGS = (
+					"-framework",
+					Carbon,
+					"-framework",
+					CPlusTest,
+				);
+				PREBINDING = NO;
+				PRODUCT_NAME = tests;
+				WRAPPER_EXTENSION = cptest;
+				ZERO_LINK = NO;
+			};
+			name = Debug;
+		};
+		73C752960B5FB59200615F6C /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				COPY_PHASE_STRIP = YES;
+				GCC_ENABLE_FIX_AND_CONTINUE = NO;
+				GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
+				GCC_MODEL_TUNING = G4;
+				GCC_PRECOMPILE_PREFIX_HEADER = YES;
+				GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/Carbon.framework/Headers/Carbon.h";
+				GCC_PREPROCESSOR_DEFINITIONS = (
+					"$(inherited)",
+					NDEBUG,
+				);
+				HEADER_SEARCH_PATHS = (
+					"$(inherited)",
+					"../external-libs/ogg/include",
+					"../external-libs/vorbis/include",
+					"../external-libs/speex/include",
+					"../external-libs/theora-exp/include",
+					"../external-libs/theora/include",
+					"../external-libs/flac/include",
+					../CAFLAC/src,
+					../utils,
+				);
+				INFOPLIST_FILE = "tests-Info.plist";
+				INSTALL_PATH = "$(USER_LIBRARY_DIR)/Bundles";
+				OTHER_LDFLAGS = (
+					"-framework",
+					Carbon,
+					"-framework",
+					CPlusTest,
+				);
+				PREBINDING = NO;
+				PRODUCT_NAME = tests;
+				WRAPPER_EXTENSION = cptest;
+				ZERO_LINK = NO;
+			};
+			name = Release;
+		};
 /* End XCBuildConfiguration section */
 
 /* Begin XCConfigurationList section */
@@ -1542,6 +1746,15 @@
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;
 		};
+		73C752940B5FB59200615F6C /* Build configuration list for PBXNativeTarget "tests" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				73C752950B5FB59200615F6C /* Debug */,
+				73C752960B5FB59200615F6C /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
 /* End XCConfigurationList section */
 	};
 	rootObject = 089C1669FE841209C02AAC07 /* Project object */;

Modified: trunk/xiph-qt/common/XCACodec.cpp
===================================================================
--- trunk/xiph-qt/common/XCACodec.cpp	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/common/XCACodec.cpp	2007-01-20 00:18:04 UTC (rev 12356)
@@ -4,7 +4,7 @@
  *    XCACodec class implementation; shared packet i/o functionality.
  *
  *
- *  Copyright (c) 2005  Arek Korbik
+ *  Copyright (c) 2005,2007  Arek Korbik
  *
  *  This file is part of XiphQT, the Xiph QuickTime Components.
  *
@@ -61,7 +61,7 @@
             while (packet < ioNumberPackets) {
                 if (bytes + inPacketDescription[packet].mDataByteSize > bytesToCopy)
                     break;
-                dbg_printf("     ----  :: %ld: %ld [%ld]\n", packet, inPacketDescription[packet].mDataByteSize,
+                dbg_printf("[ XC ]                %ld: %ld [%ld]\n", packet, inPacketDescription[packet].mDataByteSize,
                            inPacketDescription[packet].mVariableFramesInPacket);
                 InPacket(inInputData, &inPacketDescription[packet]);
 
@@ -89,7 +89,7 @@
     } else {
         CODEC_THROW(kAudioCodecNotEnoughBufferSpaceError);
     }
-    dbg_printf("[ XC ] <.. [%08lx] AppendInputData()\n", (UInt32) this);
+    dbg_printf("[ XC ] <.. [%08lx] AppendInputData(%ld [%ld])\n", (UInt32) this, ioNumberPackets, ioInputDataByteSize);
 }
 
 UInt32 XCACodec::ProduceOutputPackets(void* outOutputData, UInt32& ioOutputDataByteSize, UInt32& ioNumberPackets,
@@ -190,8 +190,13 @@
 
 void XCACodec::BDCReallocate(UInt32 inInputBufferByteSize)
 {
-    mBDCBuffer.Uninitialize();
-    mBDCBuffer.Initialize(inInputBufferByteSize);
+    if (mBDCBuffer.GetBufferByteSize() < inInputBufferByteSize) {
+        mBDCBuffer.Reallocate(inInputBufferByteSize);
+    } else {
+        // temporary left here until reallocation allows decreasing buffer size
+        mBDCBuffer.Uninitialize();
+        mBDCBuffer.Initialize(inInputBufferByteSize);
+    }
 }
 
 

Added: trunk/xiph-qt/tests/CAFLAC/OggFLACTests.cpp
===================================================================
--- trunk/xiph-qt/tests/CAFLAC/OggFLACTests.cpp	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/tests/CAFLAC/OggFLACTests.cpp	2007-01-20 00:18:04 UTC (rev 12356)
@@ -0,0 +1,110 @@
+/*
+ *  OggFLACTests.cpp
+ *
+ *    CAOggFLACDecoder class test cases.
+ *
+ *
+ *  Copyright (c) 2007  Arek Korbik
+ *
+ *  This file is part of XiphQT, the Xiph QuickTime Components.
+ *
+ *  XiphQT is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  XiphQT is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with XiphQT; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *
+ *  Last modified: $Id$
+ *
+ */
+
+
+#include "OggFLACTests.h"
+#include <iostream>
+#include <fstream>
+
+
+OggFLACTests::OggFLACTests(TestInvocation *invocation)
+    : TestCase(invocation)
+{
+}
+
+
+OggFLACTests::~OggFLACTests()
+{
+}
+
+void OggFLACTests::setUp()
+{
+    mOggDecoder = new CAOggFLACDecoder();
+}
+
+void OggFLACTests::tearDown()
+{
+    delete mOggDecoder;
+    mOggDecoder = NULL;
+}
+
+void OggFLACTests::noop()
+{
+}
+
+void OggFLACTests::append_uninitialized()
+{
+    UInt32 bytes = 0;
+    UInt32 packets = 0;
+
+    Boolean appended = false;
+
+    try {
+        mOggDecoder->AppendInputData(NULL, bytes, packets, NULL);
+        appended = true;
+    } catch (...) {
+    };
+
+    CPTAssert(appended == false);
+}
+
+void OggFLACTests::init_cookie()
+{
+    std::ifstream f_in;
+    char cookie[8192];
+
+    f_in.open("../tests/data/flac.ogg.cookie", std::ios::in);
+
+    CPTAssert(f_in.good());
+
+    f_in.read(cookie, 8192);
+    f_in.close();
+
+    AudioStreamBasicDescription in_dsc = {96000.0, 'XoFL', 0, 0, 0, 0, 6, 24, 0};
+    AudioStreamBasicDescription out_dsc = {96000.0, kAudioFormatLinearPCM,
+                                           kAudioFormatFlagsNativeFloatPacked,
+                                           24, 1, 24, 6, 32, 0};
+
+    mOggDecoder->Initialize(&in_dsc, &out_dsc, NULL, 0);
+
+    CPTAssert(mOggDecoder->IsInitialized());
+
+    mOggDecoder->Uninitialize();
+
+    CPTAssert(!mOggDecoder->IsInitialized());
+
+    mOggDecoder->Initialize(NULL, NULL, cookie, 4264);
+
+    CPTAssert(mOggDecoder->IsInitialized());
+}
+
+OggFLACTests t_noop(TEST_INVOCATION(OggFLACTests, noop));
+OggFLACTests t_append_uninitialized(TEST_INVOCATION(OggFLACTests,
+                                                    append_uninitialized));
+OggFLACTests t_init_cookie(TEST_INVOCATION(OggFLACTests, init_cookie));


Property changes on: trunk/xiph-qt/tests/CAFLAC/OggFLACTests.cpp
___________________________________________________________________
Name: svn:keywords
   + Id

Added: trunk/xiph-qt/tests/CAFLAC/OggFLACTests.h
===================================================================
--- trunk/xiph-qt/tests/CAFLAC/OggFLACTests.h	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/tests/CAFLAC/OggFLACTests.h	2007-01-20 00:18:04 UTC (rev 12356)
@@ -0,0 +1,47 @@
+/*
+ *  OggFLACTests.h
+ *
+ *    CAOggFLACDecoder class test cases header file.
+ *
+ *
+ *  Copyright (c) 2007  Arek Korbik
+ *
+ *  This file is part of XiphQT, the Xiph QuickTime Components.
+ *
+ *  XiphQT is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  XiphQT is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with XiphQT; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *
+ *  Last modified: $Id$
+ *
+ */
+
+
+#include <CPlusTest/CPlusTest.h>
+#include "CAOggFLACDecoder.h"
+
+class OggFLACTests : public TestCase {
+public:
+    OggFLACTests(TestInvocation* invocation);
+    virtual ~OggFLACTests();
+
+    void setUp();
+    void tearDown();
+
+    CAOggFLACDecoder *mOggDecoder;
+
+    void noop();
+    void append_uninitialized();
+    void init_cookie();
+};


Property changes on: trunk/xiph-qt/tests/CAFLAC/OggFLACTests.h
___________________________________________________________________
Name: svn:keywords
   + Id

Added: trunk/xiph-qt/tests/common/RingBufferTests.cpp
===================================================================
--- trunk/xiph-qt/tests/common/RingBufferTests.cpp	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/tests/common/RingBufferTests.cpp	2007-01-20 00:18:04 UTC (rev 12356)
@@ -0,0 +1,142 @@
+/*
+ *  RingBufferTests.cpp
+ *
+ *    RingBuffer class test cases.
+ *
+ *
+ *  Copyright (c) 2007  Arek Korbik
+ *
+ *  This file is part of XiphQT, the Xiph QuickTime Components.
+ *
+ *  XiphQT is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  XiphQT is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with XiphQT; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *
+ *  Last modified: $Id$
+ *
+ */
+
+
+#include "RingBufferTests.h"
+
+
+RingBufferTests::RingBufferTests(TestInvocation *invocation)
+    : TestCase(invocation)
+{
+}
+
+
+RingBufferTests::~RingBufferTests()
+{
+}
+
+void RingBufferTests::setUp()
+{
+    mBuffer = new RingBuffer();
+}
+
+void RingBufferTests::tearDown()
+{
+    delete mBuffer;
+    mBuffer = NULL;
+}
+
+void RingBufferTests::basic()
+{
+    mBuffer->Initialize(32);
+
+    CPTAssert(mBuffer->GetBufferByteSize() == 32);
+    CPTAssert(mBuffer->GetSpaceAvailable() == 32);
+    CPTAssert(mBuffer->GetDataAvailable() == 0);
+
+    UInt32 b_size = mBuffer->Reallocate(16); // shouldn't reallocate
+
+    CPTAssert(b_size == 32);
+    CPTAssert(mBuffer->GetBufferByteSize() == 32);
+    CPTAssert(mBuffer->GetSpaceAvailable() == 32);
+    CPTAssert(mBuffer->GetDataAvailable() == 0);
+
+    Byte *tmp_buf = new Byte[64];
+    memset(tmp_buf, 0, 64);
+
+    tmp_buf[0] = 255;
+    tmp_buf[1] = 15;
+    tmp_buf[16] = 137;
+
+    b_size = 63;
+    mBuffer->In(tmp_buf, b_size);
+
+    CPTAssert(b_size == 31);
+    CPTAssert(mBuffer->GetBufferByteSize() == 32);
+    CPTAssert(mBuffer->GetSpaceAvailable() == 0);
+    CPTAssert(mBuffer->GetDataAvailable() == 32);
+    CPTAssert(mBuffer->GetData()[0] == 255 && mBuffer->GetData()[1] == 15);
+
+    mBuffer->Zap(32);
+    CPTAssert(mBuffer->GetSpaceAvailable() == 32);
+    CPTAssert(mBuffer->GetDataAvailable() == 0);
+
+    b_size = mBuffer->Reallocate(48);
+
+    CPTAssert(b_size == 48);
+    CPTAssert(mBuffer->GetBufferByteSize() == 48);
+    CPTAssert(mBuffer->GetSpaceAvailable() == 48);
+    CPTAssert(mBuffer->GetDataAvailable() == 0);
+
+    b_size = 32;
+    mBuffer->In(tmp_buf, b_size);
+    CPTAssert(b_size == 0);
+    CPTAssert(mBuffer->GetDataAvailable() == 32);
+
+    mBuffer->Zap(16);
+    CPTAssert(mBuffer->GetDataAvailable() == 16);
+    CPTAssert(mBuffer->GetData()[0] == 137);
+    CPTAssert(mBuffer->GetDataAvailable() == 16);
+    CPTAssert(mBuffer->GetSpaceAvailable() == 32);
+
+    b_size = 31;
+    mBuffer->In(tmp_buf, b_size); // should be wrapped now
+    CPTAssert(b_size == 0);
+    CPTAssert(mBuffer->GetDataAvailable() == 47);
+    CPTAssert(mBuffer->GetSpaceAvailable() == 1);
+    CPTAssert(mBuffer->GetData()[0] == 137);
+
+    b_size = mBuffer->Reallocate(64);
+    CPTAssert(b_size == 64);
+    CPTAssert(mBuffer->GetBufferByteSize() == 64);
+    CPTAssert(mBuffer->GetSpaceAvailable() == 17);
+    CPTAssert(mBuffer->GetDataAvailable() == 47);
+    //std::cout << "mBuffer->GetData()[0] == " << (UInt32) mBuffer->GetData()[0] << std::endl;
+    CPTAssert(mBuffer->GetData()[0] == 137);
+
+    mBuffer->Zap(16); // [255, 15] should be at the head
+    CPTAssert(mBuffer->GetData()[0] == 255 && mBuffer->GetData()[1] == 15);
+
+    b_size = 32;
+    mBuffer->In(tmp_buf, b_size); // should be wrapped again
+    b_size = mBuffer->Reallocate(96);
+    CPTAssert(b_size == 96);
+    CPTAssert(mBuffer->GetBufferByteSize() == 96);
+    CPTAssert(mBuffer->GetSpaceAvailable() == 33);
+    CPTAssert(mBuffer->GetDataAvailable() == 63);
+    CPTAssert(mBuffer->GetData()[0] == 255 && mBuffer->GetData()[1] == 15);
+
+    mBuffer->Uninitialize();
+
+    b_size = 32;
+    mBuffer->In(tmp_buf, b_size);
+    CPTAssert(b_size == 32);
+}
+
+RingBufferTests t_basic(TEST_INVOCATION(RingBufferTests, basic));


Property changes on: trunk/xiph-qt/tests/common/RingBufferTests.cpp
___________________________________________________________________
Name: svn:keywords
   + Id

Added: trunk/xiph-qt/tests/common/RingBufferTests.h
===================================================================
--- trunk/xiph-qt/tests/common/RingBufferTests.h	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/tests/common/RingBufferTests.h	2007-01-20 00:18:04 UTC (rev 12356)
@@ -0,0 +1,46 @@
+/*
+ *  RingBufferTests.h
+ *
+ *    RingBuffer class test cases header file.
+ *
+ *
+ *  Copyright (c) 2007  Arek Korbik
+ *
+ *  This file is part of XiphQT, the Xiph QuickTime Components.
+ *
+ *  XiphQT is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  XiphQT is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with XiphQT; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *
+ *  Last modified: $Id$
+ *
+ */
+
+
+#include <CPlusTest/CPlusTest.h>
+#include "ringbuffer.h"
+
+
+class RingBufferTests : public TestCase {
+public:
+    RingBufferTests(TestInvocation* invocation);
+    virtual ~RingBufferTests();
+
+    void setUp();
+    void tearDown();
+
+    RingBuffer *mBuffer;
+
+    void basic();
+};


Property changes on: trunk/xiph-qt/tests/common/RingBufferTests.h
___________________________________________________________________
Name: svn:keywords
   + Id

Added: trunk/xiph-qt/tests/data/flac.ogg.cookie
===================================================================
(Binary files differ)


Property changes on: trunk/xiph-qt/tests/data/flac.ogg.cookie
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: trunk/xiph-qt/utils/ringbuffer.cpp
===================================================================
--- trunk/xiph-qt/utils/ringbuffer.cpp	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/utils/ringbuffer.cpp	2007-01-20 00:18:04 UTC (rev 12356)
@@ -5,7 +5,7 @@
  *    expressed as a c++ class.
  *
  *
- *  Copyright (c) 2005  Arek Korbik
+ *  Copyright (c) 2005,2007  Arek Korbik
  *
  *  This file is part of XiphQT, the Xiph QuickTime Components.
  *
@@ -77,6 +77,33 @@
     mNeedsWrapping = false;
 }
 
+UInt32 RingBuffer::Reallocate(UInt32 inBufferByteSize) {
+    Byte *bptr = NULL;
+    UInt32 data_size = 0;
+
+    // can't decrease the size at the moment
+    if (inBufferByteSize > mBSize) {
+        bptr = new Byte[inBufferByteSize * 2];
+        data_size = GetDataAvailable();
+        if (mNeedsWrapping) {
+            UInt32 headBytes = mBSize - mBStart;
+            BlockMoveData(mBuffer + mBStart, bptr, headBytes);
+            BlockMoveData(mBuffer, bptr + headBytes, mBEnd);
+            mNeedsWrapping = false;
+        } else {
+            BlockMoveData(mBuffer + mBStart, bptr, data_size);
+        }
+        mBEnd = data_size;
+        mBStart = 0;
+
+        delete[] mBuffer;
+        mBuffer = bptr;
+        mBSize = inBufferByteSize;
+    }
+
+    return mBSize;
+}
+
 UInt32 RingBuffer::GetBufferByteSize() const {
     return mBSize;
 }
@@ -118,9 +145,9 @@
     } else {
         UInt32 wrappedBytes = mBSize - mBEnd;
         const Byte* dataSplit = static_cast<const Byte*>(data) + wrappedBytes;
+        BlockMoveData(data, mBuffer + mBEnd, wrappedBytes);
+
         mBEnd = copiedBytes - wrappedBytes;
-
-        BlockMoveData(data, mBuffer + mBEnd, wrappedBytes);
         BlockMoveData(dataSplit, mBuffer, mBEnd);
 
         mNeedsWrapping = true;

Modified: trunk/xiph-qt/utils/ringbuffer.h
===================================================================
--- trunk/xiph-qt/utils/ringbuffer.h	2007-01-19 17:44:17 UTC (rev 12355)
+++ trunk/xiph-qt/utils/ringbuffer.h	2007-01-20 00:18:04 UTC (rev 12356)
@@ -4,7 +4,7 @@
  *    RingBuffer class definition. Simple ring buffer implementation.
  *
  *
- *  Copyright (c) 2005  Arek Korbik
+ *  Copyright (c) 2005,2007  Arek Korbik
  *
  *  This file is part of XiphQT, the Xiph QuickTime Components.
  *
@@ -44,6 +44,7 @@
     virtual void   Initialize(UInt32 inBufferByteSize);
     virtual void   Uninitialize();
     virtual void   Reset();
+    virtual UInt32 Reallocate(UInt32 inBufferByteSize);
 
     virtual UInt32 GetBufferByteSize() const;
     virtual UInt32 GetDataAvailable() const;



More information about the commits mailing list