[xiph-commits] r12399 - in trunk/xiph-qt: CAVorbis/src OggExport/src

arek at svn.xiph.org arek at svn.xiph.org
Tue Jan 30 13:13:25 PST 2007


Author: arek
Date: 2007-01-30 13:13:19 -0800 (Tue, 30 Jan 2007)
New Revision: 12399

Modified:
   trunk/xiph-qt/CAVorbis/src/CAVorbisEncoder.cpp
   trunk/xiph-qt/OggExport/src/OggExport.c
   trunk/xiph-qt/OggExport/src/exporter_types.h
   trunk/xiph-qt/OggExport/src/stream_audio.c
Log:
Fixed using saved configs and channel layouts.

Modified: trunk/xiph-qt/CAVorbis/src/CAVorbisEncoder.cpp
===================================================================
--- trunk/xiph-qt/CAVorbis/src/CAVorbisEncoder.cpp	2007-01-30 05:00:25 UTC (rev 12398)
+++ trunk/xiph-qt/CAVorbis/src/CAVorbisEncoder.cpp	2007-01-30 21:13:19 UTC (rev 12399)
@@ -5,7 +5,7 @@
  *    encoding functionality.
  *
  *
- *  Copyright (c) 2006  Arek Korbik
+ *  Copyright (c) 2006-2007  Arek Korbik
  *
  *  This file is part of XiphQT, the Xiph QuickTime Components.
  *
@@ -1126,20 +1126,18 @@
             dbg_printf("[  VE]   Q [%08lx] :: ApplySettings() :: %1.1f\n", (UInt32) this, mCfgQuality);
         } else if (CFStringCompare(key, CFSTR("Target Bitrate"), 0) == kCFCompareEqualTo) {
             nval = (CFNumberRef) CFArrayGetValueAtIndex(available, current);
-            SInt32 br = 4;
-            CFNumberGetValue(nval, kCFNumberLongType, &br);
-            if (br < BitrateMin())
-                br = BitrateMin();
-            else if (br > BitrateMax())
-                br = BitrateMax();
-            mCfgBitrate = br;
+            CFNumberGetValue(nval, kCFNumberLongType, &mCfgBitrate);
             dbg_printf("[  VE]   B [%08lx] :: ApplySettings() :: %ld\n", (UInt32) this, mCfgBitrate);
         }
     }
 
     if (mOutputFormat.mSampleRate < 8000.0 || mOutputFormat.mSampleRate > 50000.0)
         mCfgMode = kVorbisEncoderModeQuality;
-    dbg_printf("[  VE]  !M [%08lx] :: ApplySettings() :: %d\n", (UInt32) this, mCfgMode);
+    if (mCfgBitrate < BitrateMin())
+        mCfgBitrate = BitrateMin();
+    else if (mCfgBitrate > BitrateMax())
+       mCfgBitrate = BitrateMax();
+    dbg_printf("[  VE]  != [%08lx] :: ApplySettings() :: %d [br: %ld]\n", (UInt32) this, mCfgMode, mCfgBitrate);
 
     ret = true;
     dbg_printf("[  VE] <   [%08lx] :: ApplySettings() = %d\n", (UInt32) this, ret);

Modified: trunk/xiph-qt/OggExport/src/OggExport.c
===================================================================
--- trunk/xiph-qt/OggExport/src/OggExport.c	2007-01-30 05:00:25 UTC (rev 12398)
+++ trunk/xiph-qt/OggExport/src/OggExport.c	2007-01-30 21:13:19 UTC (rev 12399)
@@ -190,13 +190,18 @@
         globals->set_a_rquality = 0x40; //!kRenderQuality_Medium;
         globals->set_a_settings = NULL;
         globals->set_a_custom = NULL;
+        globals->set_a_settings_dlg = NULL;
+        globals->set_a_custom_dlg = NULL;
         globals->set_a_ci = NULL;
 
         memset(&globals->set_a_asbd, 0, sizeof(AudioStreamBasicDescription));
         globals->set_a_asbd.mFormatID = kAudioFormatXiphVorbis;
         globals->set_a_asbd.mChannelsPerFrame = 6;
 
+        globals->set_a_layout = NULL;
+        globals->set_a_layout_size = 0;
 
+
         globals->setdlg_a_allow = true;
         globals->setdlg_v_allow = true;
 
@@ -241,6 +246,15 @@
         if (globals->set_a_ci)
             CloseComponent(globals->set_a_ci);
 
+        if (globals->set_a_layout != NULL)
+            free(globals->set_a_layout);
+
+        if (globals->set_a_custom_dlg)
+            CFRelease(globals->set_a_custom_dlg);
+
+        if (globals->set_a_settings_dlg)
+            QTDisposeAtomContainer(globals->set_a_settings_dlg);
+
         if (globals->set_a_custom)
             CFRelease(globals->set_a_custom);
 
@@ -640,7 +654,7 @@
                                       kQTSCAudioPropertyID_ExtendedProcs,
                                       sizeof(xProcs), &xProcs);
 
-        if (globals->set_a_settings == NULL) {
+        if (globals->set_a_settings == NULL && globals->set_a_settings_dlg == NULL) {
             err = _setup_std_audio(globals, stdAudio);
             dbg_printf("[  OE]  ?' [%08lx] :: ConfigAndShowStdAudioDlg() = %ld\n", (UInt32) globals, err);
         }
@@ -659,13 +673,6 @@
                 GetMediaSampleDescription(media, 1, (SampleDescriptionHandle) sdh);
 
             if (GetHandleSize((Handle) sdh) > 0) {
-                /*
-                SoundDescriptionV2Handle sd2h;
-                QTSoundDescriptionConvert(kQTSoundDescriptionKind_Movie_AnyVersion,
-                                          (SoundDescriptionHandle) sdh,
-                                          kQTSoundDescriptionKind_Movie_Version2,
-                                          &sdh);
-                */
                 err = QTSetComponentProperty(stdAudio, kQTPropertyClass_SCAudio,
                                              kQTSCAudioPropertyID_InputSoundDescription,
                                              sizeof(SoundDescriptionHandle), &sdh);
@@ -673,20 +680,31 @@
             }
             DisposeHandle((Handle) sdh);
         } else {
-            /*
-            AudioStreamBasicDescription asbd = { 44100.0, kAudioFormatLinearPCM, kAudioFormatFlagsNativeFloatPacked, 24, 1, 24, 6, 32, 0 };
-
-            err = QTSetComponentProperty(stdAudio, kQTPropertyClass_SCAudio,
-                                         kQTSCAudioPropertyID_InputBasicDescription,
-                                         sizeof(AudioStreamBasicDescription), &asbd);
-            */
             err = _preconfig_stdaudio(stdAudio);
             dbg_printf("[  OE]  bd [%08lx] :: ConfigAndShowStdAudioDlg() = %ld\n", (UInt32) globals, err);
         }
 
-        if (globals->set_a_settings != NULL) {
-            err = SCSetSettingsFromAtomContainer(stdAudio, globals->set_a_settings);
+        if (globals->set_a_settings != NULL || globals->set_a_settings_dlg != NULL) {
+            if (globals->set_a_settings_dlg != NULL)
+                err = SCSetSettingsFromAtomContainer(stdAudio, globals->set_a_settings_dlg);
+            else
+                err = SCSetSettingsFromAtomContainer(stdAudio, globals->set_a_settings);
             dbg_printf("[  OE]  ?\" [%08lx] :: ConfigAndShowStdAudioDlg() = %ld\n", (UInt32) globals, err);
+
+            /* If the current input/output format doesn't match exactly saved settings stdAudio component will reset
+               codec custom settings when set all-together using SCSetSettingsFromAtomContainer - we need to set those
+               custom settings again seperately */
+            if (!err) {
+                CFArrayRef custom = globals->set_a_custom_dlg;
+                if (custom == NULL)
+                    custom = globals->set_a_custom;
+                if (custom != NULL) {
+                    err = QTSetComponentProperty(stdAudio, kQTPropertyClass_SCAudio,
+                                                 kQTSCAudioPropertyID_CodecSpecificSettingsArray,
+                                                 sizeof(CFArrayRef), &custom);
+                    dbg_printf("[  OE] *cs [%08lx] :: ConfigAndShowStdAudioDlg() = %ld\n", (UInt32) globals, err);
+                }
+            }
         }
 
         if (!err) {
@@ -711,15 +729,31 @@
             err = SCRequestImageSettings(stdAudio);
 
         if (!err) {
-            if (globals->set_a_settings) {
-                QTDisposeAtomContainer(globals->set_a_settings);
-                globals->set_a_settings = NULL;
+            if (globals->set_a_settings_dlg) {
+                QTDisposeAtomContainer(globals->set_a_settings_dlg);
+                globals->set_a_settings_dlg = NULL;
             }
-            err = SCGetSettingsAsAtomContainer(stdAudio, &globals->set_a_settings);
-            if (err && globals->set_a_settings) {
-                QTDisposeAtomContainer(globals->set_a_settings);
-                globals->set_a_settings = NULL;
+            err = SCGetSettingsAsAtomContainer(stdAudio, &globals->set_a_settings_dlg);
+            if (err && globals->set_a_settings_dlg) {
+                QTDisposeAtomContainer(globals->set_a_settings_dlg);
+                globals->set_a_settings_dlg = NULL;
             }
+            if (!err) {
+                if (globals->set_a_custom_dlg != NULL) {
+                    CFRelease(globals->set_a_custom_dlg);
+                    globals->set_a_custom_dlg = NULL;
+                }
+                err = QTGetComponentProperty(stdAudio, kQTPropertyClass_SCAudio,
+                                             kQTSCAudioPropertyID_CodecSpecificSettingsArray,
+                                             sizeof(CFArrayRef),
+                                             &globals->set_a_custom_dlg, NULL);
+                if (err && globals->set_a_custom_dlg != NULL) {
+                    globals->set_a_custom_dlg = NULL;
+                } else if (!err) {
+                    CFRetain(globals->set_a_custom_dlg);
+                }
+
+            }
         }
 
         if (globals->set_a_ci == NULL)
@@ -783,11 +817,19 @@
 
         if (globals->set_a_ci != NULL) {
             /* result = */ _get_std_audio_config(globals, globals->set_a_ci);
-        } else if (globals->set_a_settings != NULL) {
+        } else if (globals->set_a_settings_dlg != NULL) {
+            if (globals->set_a_settings != NULL) {
+                QTDisposeAtomContainer(globals->set_a_settings);
+                globals->set_a_settings = NULL;
+            }
+            globals->set_a_settings = globals->set_a_settings_dlg;
+            globals->set_a_settings_dlg = NULL;
             /* result = */ _ac_to_audio_settings(globals, globals->set_a_settings);
-            //QTDisposeAtomContainer(globals->set_v_settings);
-            //globals->set_v_settings = NULL;
         }
+        if (globals->set_a_custom_dlg != NULL) {
+            CFRelease(globals->set_a_custom_dlg);
+            globals->set_a_custom_dlg = NULL;
+        }
 
         QuitAppModalLoopForWindow(window);
         result = noErr;
@@ -795,6 +837,15 @@
 
     case kHICommandCancel:
         globals->canceled = true;
+        if (globals->set_a_settings_dlg != NULL) {
+            QTDisposeAtomContainer(globals->set_a_settings_dlg);
+            globals->set_a_settings_dlg = NULL;
+        }
+        if (globals->set_a_custom_dlg != NULL) {
+            CFRelease(globals->set_a_custom_dlg);
+            globals->set_a_custom_dlg = NULL;
+        }
+
         QuitAppModalLoopForWindow(window);
         result = noErr;
         break;
@@ -1624,17 +1675,10 @@
 static ComponentResult _setup_std_audio(OggExportGlobalsPtr globals, ComponentInstance stdAudio)
 {
     ComponentResult err = noErr;
-    /* isbd's mChannelsPerFrame should be set to the highest number of
-       channels supported by the supported audio encoder, and mSampleRate should be non-zero */
-    AudioStreamBasicDescription isbd = { 44100.0, kAudioFormatLinearPCM, kAudioFormatFlagsNativeFloatPacked, 24, 1, 24, 6, 32, 0 };
 
     dbg_printf("[  OE]  >> [%08lx] :: _setup_std_audio()\n", (UInt32) globals);
 
-    /* Can't set output description (if it contains 0.0 samplerate?) without input format set :( */
-    err = QTSetComponentProperty(stdAudio, kQTPropertyClass_SCAudio,
-                                 kQTSCAudioPropertyID_InputBasicDescription,
-                                 sizeof(isbd), &isbd);
-    dbg_printf("[  OE]  i? [%08lx] :: _setup_std_audio() = %ld\n", (UInt32) globals, err);
+    err = _preconfig_stdaudio(stdAudio);
 
     if (!err) {
         err = QTSetComponentProperty(stdAudio, kQTPropertyClass_SCAudio,
@@ -1643,6 +1687,14 @@
         dbg_printf("[  OE]  o! [%08lx] :: _setup_std_audio() = %ld\n", (UInt32) globals, err);
     }
 
+    if (!err && globals->set_a_layout != NULL) {
+        err = QTSetComponentProperty(stdAudio, kQTPropertyClass_SCAudio,
+                                     kQTSCAudioPropertyID_ChannelLayout,
+                                     globals->set_a_layout_size, globals->set_a_layout);
+        dbg_printf("[  OE]  cl [%08lx] :: _setup_std_audio() = %ld\n", (UInt32) globals, err);
+        //err = noErr;
+    }
+
     if (!err) {
         err = QTSetComponentProperty(stdAudio, kQTPropertyClass_SCAudio,
                                      kQTSCAudioPropertyID_RenderQuality,
@@ -1721,6 +1773,41 @@
     }
 
     if (!err) {
+        err = QTGetComponentPropertyInfo(stdAudio, kQTPropertyClass_SCAudio,
+                                         kQTSCAudioPropertyID_ChannelLayout,
+                                         NULL, &globals->set_a_layout_size, NULL);
+
+        if (err) {
+            globals->set_a_layout_size = 0;
+            if (globals->set_a_layout != NULL) {
+                free(globals->set_a_layout);
+                globals->set_a_layout = NULL;
+            }
+        } else if (globals->set_a_layout_size > 0) {
+            // TODO: realloc?
+            if (globals->set_a_layout != NULL) {
+                free(globals->set_a_layout);
+                globals->set_a_layout = NULL;
+            }
+            globals->set_a_layout = calloc(1, globals->set_a_layout_size);
+            if (globals->set_a_layout == NULL) {
+                globals->set_a_layout_size = 0;
+            } else {
+                err = QTGetComponentProperty(stdAudio, kQTPropertyClass_SCAudio,
+                                             kQTSCAudioPropertyID_ChannelLayout,
+                                             globals->set_a_layout_size,
+                                             globals->set_a_layout, NULL);
+                if (err) {
+                    free(globals->set_a_layout);
+                    globals->set_a_layout = NULL;
+                    globals->set_a_layout_size = 0;
+                }
+            }
+            //err = noErr;
+        }
+    }
+
+    if (!err) {
         err = QTGetComponentProperty(stdAudio, kQTPropertyClass_SCAudio,
                                      kQTSCAudioPropertyID_RenderQuality,
                                      sizeof(UInt32),
@@ -1737,7 +1824,6 @@
                                      sizeof(CFArrayRef),
                                      &globals->set_a_custom, NULL);
         if (err && globals->set_a_custom != NULL) {
-            CFRelease(globals->set_a_custom);
             globals->set_a_custom = NULL;
         } else if (!err) {
             CFRetain(globals->set_a_custom);
@@ -1844,6 +1930,8 @@
 {
     ComponentResult err = noErr;
     /* Can't set output description (if it contains 0.0 samplerate?) without input format set :( */
+    /* isbd's mChannelsPerFrame should be set to the highest number of
+       channels supported by the supported audio encoder, and mSampleRate should be non-zero */
     AudioStreamBasicDescription isbd = { 44100.0, kAudioFormatLinearPCM, kAudioFormatFlagsNativeFloatPacked, 24, 1, 24, 6, 32, 0 };
 
     err = QTSetComponentProperty(stdAudio, kQTPropertyClass_SCAudio,

Modified: trunk/xiph-qt/OggExport/src/exporter_types.h
===================================================================
--- trunk/xiph-qt/OggExport/src/exporter_types.h	2007-01-30 05:00:25 UTC (rev 12398)
+++ trunk/xiph-qt/OggExport/src/exporter_types.h	2007-01-30 21:13:19 UTC (rev 12399)
@@ -138,8 +138,12 @@
 
     CodecQ             set_a_rquality;        /**< processing chain's render quality */
     AudioStreamBasicDescription set_a_asbd;   /**< audio codec's target output format settings */
+    AudioChannelLayout *set_a_layout;         /**< audio codec's target output channel layout  */
+    UInt32             set_a_layout_size;
     QTAtomContainer    set_a_settings;        /**< all audio codec's settings */
     CFArrayRef         set_a_custom;          /**< specific codec-only settings */
+    QTAtomContainer    set_a_settings_dlg;
+    CFArrayRef         set_a_custom_dlg;
     ComponentInstance  set_a_ci;
 
     /* settings dialog vars */

Modified: trunk/xiph-qt/OggExport/src/stream_audio.c
===================================================================
--- trunk/xiph-qt/OggExport/src/stream_audio.c	2007-01-30 05:00:25 UTC (rev 12398)
+++ trunk/xiph-qt/OggExport/src/stream_audio.c	2007-01-30 21:13:19 UTC (rev 12399)
@@ -4,7 +4,7 @@
  *    Audio tracks related part of OggExporter.
  *
  *
- *  Copyright (c) 2006  Arek Korbik
+ *  Copyright (c) 2006-2007  Arek Korbik
  *
  *  This file is part of XiphQT, the Xiph QuickTime Components.
  *
@@ -346,8 +346,6 @@
                 err = paramErr;
             } else {
                 AudioStreamBasicDescription *asbd = &si->si_a.qte_out_asbd;
-                UInt32 acl_size = 0;
-                AudioChannelLayout *acl = NULL;
 
                 asbd->mFormatID = kAudioFormatLinearPCM;
                 asbd->mFormatFlags = sd->formatSpecificFlags;
@@ -379,8 +377,7 @@
 
             DisposeHandle((Handle) sdh);
 
-#if 0
-            if (!acl) {
+            if (!acl && si->si_a.qte_out_asbd.mChannelsPerFrame < 3) {
                 acl_size = sizeof(AudioChannelLayout);
                 acl = (AudioChannelLayout *) calloc(1, acl_size);
                 acl->mChannelLayoutTag =
@@ -389,18 +386,12 @@
                 acl->mChannelBitmap = 0;
                 acl->mNumberChannelDescriptions = 0;
             }
-#endif
 
             err = QTSetComponentProperty(si->si_a.stdAudio, kQTPropertyClass_SCAudio, kQTSCAudioPropertyID_InputBasicDescription,
                                          sizeof(si->si_a.qte_out_asbd), &si->si_a.qte_out_asbd);
             dbg_printf("[ aOE]  iD [%08lx] :: configure_stream__audio() = %ld\n", (UInt32) globals, err);
-            {
-                AudioStreamBasicDescription *asbd = &si->si_a.qte_out_asbd;
-                dbg_printf("[ aOE]  iD [%08lx] :: configure_stream__audio() = %ld, {%lf, '%4.4s', %04lx, %ld, %ld, %ld, %ld, %ld}\n", (UInt32) globals, err,
-                           asbd->mSampleRate, (char *) &asbd->mFormatID, asbd->mFormatFlags, asbd->mBytesPerPacket, asbd->mFramesPerPacket,
-                           asbd->mBytesPerFrame, asbd->mChannelsPerFrame, asbd->mBitsPerChannel);
-            }
-            if (!err && acl != NULL && false) {
+
+            if (!err && acl != NULL) {
                 err = QTSetComponentProperty(si->si_a.stdAudio, kQTPropertyClass_SCAudio, kQTSCAudioPropertyID_InputChannelLayout,
                                              acl_size, acl);
                 dbg_printf("[ aOE]  iL [%08lx] :: configure_stream__audio() = %ld\n", (UInt32) globals, err);
@@ -430,6 +421,16 @@
             dbg_printf("[ aOE]  rq [%08lx] :: configure_stream__audio() = %ld\n", (UInt32) globals, err);
         }
 
+        if (!err && globals->set_a_layout != NULL) {
+            err = QTSetComponentProperty(si->si_a.stdAudio, kQTPropertyClass_SCAudio,
+                                         kQTSCAudioPropertyID_ChannelLayout,
+                                         globals->set_a_layout_size, globals->set_a_layout);
+            dbg_printf("[ aOE] ocl [%08lx] :: configure_stream__audio() = %ld, {0x%08lx, %ld, %ld}\n",
+                       (UInt32) globals, err, globals->set_a_layout->mChannelLayoutTag,
+                       globals->set_a_layout->mChannelBitmap, globals->set_a_layout->mNumberChannelDescriptions);
+            err = noErr;
+        }
+
         if (!err && globals->set_a_custom != NULL) {
             err = QTSetComponentProperty(si->si_a.stdAudio, kQTPropertyClass_SCAudio,
                                          kQTSCAudioPropertyID_CodecSpecificSettingsArray,



More information about the commits mailing list