[xiph-commits] r12378 - trunk/xiph-qt/OggExport/src
arek at svn.xiph.org
arek at svn.xiph.org
Mon Jan 22 09:52:31 PST 2007
Author: arek
Date: 2007-01-22 09:52:27 -0800 (Mon, 22 Jan 2007)
New Revision: 12378
Modified:
trunk/xiph-qt/OggExport/src/OggExport.c
trunk/xiph-qt/OggExport/src/exporter_types.h
trunk/xiph-qt/OggExport/src/stream_types_video.h
trunk/xiph-qt/OggExport/src/stream_video.c
Log:
Exporter video settings working and being used now; some clean-up.
Modified: trunk/xiph-qt/OggExport/src/OggExport.c
===================================================================
--- trunk/xiph-qt/OggExport/src/OggExport.c 2007-01-22 17:50:40 UTC (rev 12377)
+++ trunk/xiph-qt/OggExport/src/OggExport.c 2007-01-22 17:52:27 UTC (rev 12378)
@@ -133,7 +133,9 @@
static ComponentResult _video_settings_to_ac(OggExportGlobalsPtr globals, QTAtomContainer *settings);
static ComponentResult _ac_to_video_settings(OggExportGlobalsPtr globals, QTAtomContainer settings);
+static ComponentResult _movie_fps(Movie theMovie, Fixed *fps);
+
#define CALLCOMPONENT_BASENAME() OggExport
#define CALLCOMPONENT_GLOBALS() OggExportGlobalsPtr storage
@@ -167,6 +169,7 @@
if (!err) {
globals->self = self;
globals->use_hires_audio = false;
+ globals->movie_fps = 0;
globals->set_v_disable = 0;
globals->set_a_disable = 0;
@@ -177,6 +180,7 @@
globals->set_v_keyrate = 64;
globals->set_v_settings = NULL;
globals->set_v_custom = NULL;
+ globals->set_v_ci = NULL;
globals->set_a_quality = codecNormalQuality;
globals->set_a_bitrate = 0;
@@ -217,6 +221,9 @@
DisposeHandle((Handle) globals->streamInfoHandle);
}
+ if (globals->set_v_ci)
+ CloseComponent(globals->set_v_ci);
+
if (globals->set_v_settings)
QTDisposeAtomContainer(globals->set_v_settings);
@@ -380,44 +387,6 @@
// TODO: loop for all tracks
-#if 0
- {
- SCSpatialSettings ss = {k422YpCbCr8PixelFormat, NULL, 32, 512};
- ComponentInstance stdcomp = NULL;
- QTAtomContainer mes = NULL;
- ComponentResult terr;
-
- terr = OpenADefaultComponent(StandardCompressionType, StandardCompressionSubType, &stdcomp);
- if (terr)
- goto tbail;
-
- //ss.codecType = k422YpCbCr8PixelFormat;
- ss.codecType = 'XiVs';
- terr = SCSetInfo(stdcomp, scSpatialSettingsType, &ss);
- if (terr)
- goto tbail;
-
- terr = SCGetSettingsAsAtomContainer(stdcomp, &mes);
- if (terr)
- goto tbail;
-
- terr = MovieExportSetSettingsFromAtomContainer(globals->quickTimeMovieExporter, mes);
- if (terr)
- goto tbail;
-
- dbg_printf("[ vOE] ss [%08lx] :: configure_stream() = %ld, ['%4.4s', %08lx, %d, %ld]\n", (UInt32) globals, err,
- (char *) &ss.codecType, (UInt32) ss.codec, ss.depth, ss.spatialQuality);
-
- tbail:
- dbg_printf("[ OE] ?? [%08lx] :: ToDataRef() = %ld\n", (UInt32) globals, terr);
- if (stdcomp)
- CloseComponent(stdcomp);
-
- if (mes)
- DisposeHandle(mes);
- }
-#endif
-
if (globals->set_v_disable != 1) {
err = MovieExportNewGetDataAndPropertiesProcs(globals->quickTimeMovieExporter, VideoMediaType, &scale, theMovie,
onlyThisTrack, startTime, duration, &getVideoPropertyProc,
@@ -429,6 +398,8 @@
if (!err)
have_sources = true;
}
+ if (globals->movie_fps == 0)
+ _movie_fps(theMovie, &globals->movie_fps);
}
if (globals->set_a_disable != 1) {
@@ -545,15 +516,14 @@
ComponentResult ConfigAndShowStdVideoDlg(OggExportGlobalsPtr globals, WindowRef window)
{
ComponentResult err = noErr;
- SCExtendedProcs xProcs;
- ComponentInstance stdVideo;
+ ComponentInstance stdVideo = globals->set_v_ci;
PicHandle ph = NULL;
long sc_prefs;
- Boolean full_cfg = true;
dbg_printf("[ OE] >> [%08lx] :: ConfigAndShowStdVideoDlg()\n", (UInt32) globals);
- err = OpenADefaultComponent(StandardCompressionType, StandardCompressionSubType, &stdVideo);
+ if (stdVideo == NULL)
+ err = OpenADefaultComponent(StandardCompressionType, StandardCompressionSubType, &stdVideo);
if (!err) {
sc_prefs = scAllowZeroFrameRate | scAllowZeroKeyFrameRate | scShowDataRateAsKilobits;
@@ -613,160 +583,12 @@
}
}
- CloseComponent(stdVideo);
+ //CloseComponent(stdVideo);
if (ph != NULL)
DisposeHandle((Handle) ph);
}
-
-#if 0
-
- if (!err && globals->set_v_settings) {
- err = SCSetSettingsFromAtomContainer(stdVideo, globals->set_v_settings);
- dbg_printf("[ OE] =S [%08lx] :: ConfigAndShowStdVideoDlg() = %ld\n", (UInt32) globals, err);
- if (!err)
- full_cfg = false;
- }
-
- if (!err) {
- sc_prefs = scAllowZeroFrameRate | scAllowZeroKeyFrameRate | scShowDataRateAsKilobits;
- //sc_prefs |= scDontDetermineSettingsFromTestImage;
-#if USE_VIDE_COMPONENT
- sc_prefs |= scAllowEncodingWithCompressionSession; // Don't set with the StandardCompressionSubType
-#endif /* USE_VIDE_COMPONENT */
-
- err = SCSetInfo(stdVideo, scPreferenceFlagsType, &sc_prefs);
- dbg_printf("[ OE] uS [%08lx] :: ConfigAndShowStdVideoDlg() = %ld\n", (UInt32) globals, err);
-
- memset(&xProcs, 0, sizeof(xProcs));
- strcpy((char*)xProcs.customName + 1, "Select Output Format");
- xProcs.customName[0] = (unsigned char) strlen((char*) xProcs.customName + 1);
- /*
- (void) QTSetComponentProperty(stdVideo, kQTPropertyClass_SCAudio,
- kQTSCAudioPropertyID_ExtendedProcs,
- sizeof(xProcs), &xProcs);
- */
- err = SCSetInfo(stdVideo, scExtendedProcsType, &xProcs);
- dbg_printf("[ OE] pS [%08lx] :: ConfigAndShowStdVideoDlg() = %ld\n", (UInt32) globals, err);
-
- if (!err)
- {
- Handle codec_types = NewHandleClear(sizeof(OSType));
- SCSpatialSettings ss;
- SCTemporalSettings ts = {codecNormalQuality, 0, 64};
- SCDataRateSettings ds = {0, 0, 0, 0};
-
-
- *(OSType *)*codec_types = kVideoFormatXiphTheora;
- err = SCSetInfo(stdVideo, scCompressionListType, &codec_types);
- dbg_printf("[ OE] =L [%08lx] :: ConfigAndShowStdVideoDlg() = %ld\n", (UInt32) globals, err);
-
- if (!err) {
- *(OSType *)*codec_types = kXiphComponentsManufacturer;
- err = SCSetInfo(stdVideo, scCodecManufacturerType, &codec_types);
- dbg_printf("[ OE] =M [%08lx] :: ConfigAndShowStdVideoDlg() = %ld\n", (UInt32) globals, err);
- }
-
- DisposeHandle(codec_types);
-
- if (!err) {
- if (full_cfg || SCGetInfo(stdVideo, scSpatialSettingsType, &ss)) {
- dbg_printf("[ OE] sS [%08lx] :: ConfigAndShowStdVideoDlg() = %ld %d\n", (UInt32) globals, err, full_cfg);
- ss.depth = 0;
- ss.spatialQuality = codecNormalQuality;
- }
-
- ss.codecType = kVideoFormatXiphTheora;
- ss.codec = NULL;
-
- if (!full_cfg)
- SCGetInfo(stdVideo, scTemporalSettingsType, &ts);
-
- if (!full_cfg)
- SCGetInfo(stdVideo, scDataRateSettingsType, &ds);
-
- err = SCSetInfo(stdVideo, scSpatialSettingsType, &ss);
- dbg_printf("[ OE] _s [%08lx] :: ConfigAndShowStdVideoDlg() = %ld\n", (UInt32) globals, err);
- if (!err) {
- err = SCSetInfo(stdVideo, scTemporalSettingsType, &ts);
- dbg_printf("[ OE] _t [%08lx] :: ConfigAndShowStdVideoDlg() = %ld\n", (UInt32) globals, err);
- }
- if (!err) {
- err = SCSetInfo(stdVideo, scDataRateSettingsType, &ds);
- dbg_printf("[ OE] _d [%08lx] :: ConfigAndShowStdVideoDlg() = %ld\n", (UInt32) globals, err);
- }
- }
-
-#if 0
- if (!err) {
- Handle custom = NewHandleClear(0);
- err = SCGetInfo(stdVideo, scCodecSettingsType, &custom);
- dbg_printf("[ OE] cS [%08lx] :: ConfigAndShowStdVideoDlg() = %ld, %ld\n", (UInt32) globals, err, GetHandleSize(custom));
-
- if (!IsHandleValid(custom))
- custom = NewHandleClear(0);
- err = SCSetInfo(stdVideo, scCodecSettingsType, &custom);
- dbg_printf("[ OE] CS [%08lx] :: ConfigAndShowStdVideoDlg() = %ld %ld\n", (UInt32) globals, err, GetHandleSize(custom));
-
- DisposeHandle(custom);
- }
-#endif /* 0 */
- }
-
- if (!err && globals->setdlg_movie != NULL) {
- TimeScale mt = GetMovieTime(globals->setdlg_movie, NULL);
- Rect pr;
-
- if (mt == 0)
- mt = GetMoviePosterTime(globals->setdlg_movie);
- err = GetMoviesError();
- dbg_printf("[ OE] [ ] [%08lx] :: ConfigAndShowStdVideoDlg() = %ld\n", (UInt32) globals, err);
- if (!err) {
- ph = GetMoviePict(globals->setdlg_movie, mt);
- if (ph != NULL) {
- QDGetPictureBounds(ph, &pr);
- //sc_prefs = scPreferScalingAnd;
- //sc_prefs = scPreferScalingAndCropping;
- sc_prefs = scPreferScalingAndCropping | scDontDetermineSettingsFromTestImage;
- err = SCSetTestImagePictHandle(stdVideo, ph, &pr, sc_prefs);
- }
- }
- }
-
- if (!err) {
- QTAtomContainer std_v_settings = NULL;
- err = SCGetSettingsAsAtomContainer(stdVideo, &std_v_settings);
- dbg_printf("[ OE] ?S [%08lx] :: ConfigAndShowStdVideoDlg() = %ld\n", (UInt32) globals, err);
- if (!err) {
- err = SCSetSettingsFromAtomContainer(stdVideo, std_v_settings);
- dbg_printf("[ OE] !S [%08lx] :: ConfigAndShowStdVideoDlg() = %ld\n", (UInt32) globals, err);
- }
- }
-
- if (!err)
- err = SCRequestSequenceSettings(stdVideo);
-
- if (!err) {
- /* TODO: get config from the stdComp and store it */
- if (globals->set_v_settings) {
- QTDisposeAtomContainer(globals->set_v_settings);
- globals->set_v_settings = NULL;
- }
- err = SCGetSettingsAsAtomContainer(stdVideo, &globals->set_v_settings);
- if (err && globals->set_v_settings) {
- QTDisposeAtomContainer(globals->set_v_settings);
- globals->set_v_settings = NULL;
- }
- }
-
- CloseComponent(stdVideo);
-
- if (ph != NULL)
- DisposeHandle((Handle) ph);
- }
-#endif /* 0 */
-
dbg_printf("[ OE] < [%08lx] :: ConfigAndShowStdVideoDlg() = %ld\n", (UInt32) globals, err);
return err;
}
@@ -815,7 +637,9 @@
}
}
- if (globals->set_v_settings != NULL) {
+ if (globals->set_v_ci != NULL) {
+ /* result = */ _get_std_video_config(globals, globals->set_v_ci);
+ } else if (globals->set_v_settings != NULL) {
/* result = */ _ac_to_video_settings(globals, globals->set_v_settings);
//QTDisposeAtomContainer(globals->set_v_settings);
//globals->set_v_settings = NULL;
@@ -901,8 +725,6 @@
pascal ComponentResult OggExportDoUserDialog(OggExportGlobalsPtr globals, Movie theMovie, Track onlyThisTrack,
TimeValue startTime, TimeValue duration, Boolean *canceledPtr)
{
-#pragma unused(theMovie, onlyThisTrack, startTime, duration)
-
CFBundleRef bundle = NULL;
IBNibRef nibRef = NULL;
WindowRef window = NULL;
@@ -936,10 +758,12 @@
if (theMovie != NULL) {
if (onlyThisTrack == NULL) {
- if (GetMovieIndTrackType(theMovie, 1, VisualMediaCharacteristic, movieTrackCharacteristic | movieTrackEnabledOnly) == NULL)
+ if (GetMovieIndTrackType(theMovie, 1, VisualMediaCharacteristic, movieTrackCharacteristic | movieTrackEnabledOnly) == NULL) {
globals->setdlg_v_allow = false;
- else
+ } else {
globals->setdlg_v_allow = true;
+ _movie_fps(theMovie, &globals->movie_fps);
+ }
if (GetMovieIndTrackType(theMovie, 1, AudioMediaCharacteristic, movieTrackCharacteristic | movieTrackEnabledOnly) == NULL)
globals->setdlg_a_allow = false;
@@ -950,10 +774,12 @@
Boolean has_char = false;
MediaHasCharacteristic(mh, VisualMediaCharacteristic, &has_char);
- if (has_char)
+ if (has_char) {
globals->setdlg_v_allow = true;
- else
+ _movie_fps(theMovie, &globals->movie_fps);
+ } else {
globals->setdlg_v_allow = false;
+ }
MediaHasCharacteristic(mh, AudioMediaCharacteristic, &has_char);
if (has_char)
@@ -1038,7 +864,7 @@
pascal ComponentResult OggExportGetSettingsAsAtomContainer(OggExportGlobalsPtr globals, QTAtomContainer *settings)
{
- QTAtom atom;
+ //QTAtom atom;
QTAtomContainer ac = NULL;
ComponentResult err;
Boolean b_true = true;
@@ -1087,13 +913,17 @@
HUnlock((Handle) globals->set_v_settings);
*/
QTAtomContainer vs = NULL;
- if (globals->set_v_settings != NULL)
+ err = noErr;
+ if (globals->set_v_settings != NULL) {
vs = globals->set_v_settings;
- else
+ } else {
err = QTNewAtomContainer(&vs);
+ if (!err)
+ err = _video_settings_to_ac(globals, &vs);
+ }
if (!err) {
- err = _video_settings_to_ac(globals, &vs);
+ //err = _video_settings_to_ac(globals, &vs);
dbg_printf("[ OE] vAC [%08lx] :: GetSettingsAsAtomContainer() = %ld %ld\n", (UInt32) globals, err, GetHandleSize(vs));
if (!err)
@@ -1711,3 +1541,57 @@
return err;
}
+
+static ComponentResult _movie_fps(Movie theMovie, Fixed *fps)
+{
+ ComponentResult err = noErr;
+ UInt32 frames = 0;
+ TimeValue m_time = 0;
+ TimeValue m_time_tmp = 0;
+ TimeValue m_time_start = 0;
+ TimeValue m_time_end = 0;
+ TimeValue ts = 0;
+ OSType vis_type = VisualMediaCharacteristic;
+
+ dbg_printf("[ OE] >> [%08lx] _movie_fps()\n", (UInt32) -1);
+
+ // seems it's not needed in QuickTime 7...?
+ //MoviesTask(theMovie, 0);
+
+ GetMovieNextInterestingTime(theMovie, nextTimeStep, 1, &vis_type, m_time, fixed1, &m_time_start, NULL);
+ if (m_time_start > 0) {
+ m_time = m_time_start;
+ frames = 1;
+
+ while (m_time >= 0) {
+ GetMovieNextInterestingTime(theMovie, nextTimeStep, 1, &vis_type, m_time, fixed1, &m_time_tmp, NULL);
+ if (m_time_tmp > 0)
+ m_time_end = m_time;
+ m_time = m_time_tmp;
+ //dbg_printf("[ OE] [%08lx] _movie_frame_count() = %ld [%ld]\n", (UInt32) -1, m_time, ret);
+ frames++;
+ }
+ frames--;
+
+ if (m_time_end > m_time_start) {
+ m_time = m_time_end - m_time_start;
+ frames -= 2;
+ }
+ }
+
+ if (m_time > 0) {
+ ts = GetMovieTimeScale(theMovie);
+ err = GetMoviesError();
+ if (!err) {
+ // nominator = (double) (frames * ts * ts) / (double) m_time;
+ // denominator = ts;
+ *fps = FloatToFixed((double) (frames * ts) / (double) m_time);
+ }
+ } else {
+ err = GetMoviesError();
+ }
+
+ dbg_printf("[ OE] < [%08lx] _movie_fps() = %ld (%ld.%04ld) [%ld, %ld, %ld, %ld, %ld]\n", (UInt32) -1, err, *fps >> 16, (*fps & 0xffff) * 10000 / 65536, m_time, ts,
+ m_time_start, m_time_end, frames, *fps);
+ return err;
+}
Modified: trunk/xiph-qt/OggExport/src/exporter_types.h
===================================================================
--- trunk/xiph-qt/OggExport/src/exporter_types.h 2007-01-22 17:50:40 UTC (rev 12377)
+++ trunk/xiph-qt/OggExport/src/exporter_types.h 2007-01-22 17:52:27 UTC (rev 12378)
@@ -4,7 +4,7 @@
* Definitions of OggExporter data structures.
*
*
- * Copyright (c) 2006 Arek Korbik
+ * Copyright (c) 2006-2007 Arek Korbik
*
* This file is part of XiphQT, the Xiph QuickTime Components.
*
@@ -41,10 +41,9 @@
#if defined(TARGET_OS_WIN32)
#define _WINIOCTL_
#include <windows.h>
-#endif
+#endif /* TARGET_OS_WIN32 */
-#endif
-//#include "rb.h"
+#endif /* __APPLE_CC__ */
#include "stream_types_audio.h"
@@ -90,20 +89,12 @@
TimeScale sourceTimeScale;
TimeValue time;
- //long numOfFrames;
- //Ptr compressBuffer;
- //Size compressBufferSize;
-
void * out_buffer;
UInt32 out_buffer_size;
long lastDescSeed;
- //ImageSequence decompressSequence;
- //GWorldPtr gw;
- //PixMapHandle hPixMap;
-
struct stream_format_handle_funcs *sfhf;
union {
@@ -131,6 +122,8 @@
Boolean use_hires_audio;
+ Fixed movie_fps;
+
/* settings */
UInt16 set_v_disable;
UInt16 set_a_disable;
@@ -141,6 +134,7 @@
UInt32 set_v_keyrate;
QTAtomContainer set_v_settings;
Handle set_v_custom;
+ ComponentInstance set_v_ci;
CodecQ set_a_quality;
UInt32 set_a_bitrate;
Modified: trunk/xiph-qt/OggExport/src/stream_types_video.h
===================================================================
--- trunk/xiph-qt/OggExport/src/stream_types_video.h 2007-01-22 17:50:40 UTC (rev 12377)
+++ trunk/xiph-qt/OggExport/src/stream_types_video.h 2007-01-22 17:52:27 UTC (rev 12378)
@@ -4,7 +4,7 @@
* Definition of video stream data structures for OggExport.
*
*
- * Copyright (c) 2006 Arek Korbik
+ * Copyright (c) 2006-2007 Arek Korbik
*
* This file is part of XiphQT, the Xiph QuickTime Components.
*
@@ -35,6 +35,11 @@
kOES_V_init_op_size = 1024,
};
+enum {
+ kEOS_V_default_fps = 24 << 16,
+ kEOS_V_default_keyrate = 64,
+};
+
typedef struct {
ComponentInstance stdVideo;
@@ -48,11 +53,6 @@
float frames_time;
- Fixed width;
- Fixed height;
- Fixed fps;
- SInt16 depth;
-
ogg_packet op;
UInt32 op_duration;
void * op_buffer;
@@ -62,6 +62,16 @@
UInt32 max_packet_size;
UInt32 grpos_shift;
+
+ /* settings */
+ Fixed width;
+ Fixed height;
+ CodecQ quality;
+ Fixed fps;
+ UInt32 bitrate;
+ UInt32 keyrate;
+ SInt16 depth; // is this needed?
+ Handle custom;
} StreamInfo__video;
#define _HAVE__OE_VIDEO 1
Modified: trunk/xiph-qt/OggExport/src/stream_video.c
===================================================================
--- trunk/xiph-qt/OggExport/src/stream_video.c 2007-01-22 17:50:40 UTC (rev 12377)
+++ trunk/xiph-qt/OggExport/src/stream_video.c 2007-01-22 17:52:27 UTC (rev 12378)
@@ -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.
*
@@ -66,8 +66,9 @@
CVPixelBufferGetDataSize(pixelBuffer), (char *) &pf,
CVPixelBufferGetWidth(pixelBuffer),
CVPixelBufferGetHeight(pixelBuffer));
- displayDuration = 25;
+ displayDuration = 25; //?
+
// Feed the frame to the compression session.
err = ICMCompressionSessionEncodeFrame(si->si_v.cs, pixelBuffer,
displayTime, displayDuration,
@@ -86,15 +87,12 @@
ComponentResult err = noErr;
CFNumberRef number = NULL;
CFMutableDictionaryRef pba = NULL;
- //ICMDecompressionSessionOptionsRef sessionOptions = NULL;
ICMDecompressionTrackingCallbackRecord dtcr;
SInt32 w, h;
OSType pbf = k422YpCbCr8PixelFormat;
dbg_printf("[ vOE] >> [%08lx] :: _setup_ds()\n", (UInt32) -1);
- // via the kICMCompressionSessionPropertyID_CompressorPixelBufferAttributes
-
if (si->si_v.ds) {
ICMDecompressionSessionFlush(si->si_v.ds);
ICMDecompressionSessionRelease(si->si_v.ds);
@@ -107,10 +105,6 @@
w = si->si_v.width >> 16;
h = si->si_v.height >> 16;
- // TMP:
- //w = 480;
- //h = 260;
-
number = CFNumberCreate(NULL, kCFNumberSInt32Type, &w);
CFDictionaryAddValue(pba, kCVPixelBufferWidthKey, number);
CFRelease(number);
@@ -123,11 +117,6 @@
CFDictionaryAddValue(pba, kCVPixelBufferPixelFormatTypeKey, number);
CFRelease(number);
- //CFDictionaryAddValue(pba, kCVPixelBufferCGBitmapContextCompatibilityKey,
- // kCFBooleanTrue );
- //CFDictionaryAddValue(pba, kCVPixelBufferCGImageCompatibilityKey,
- // kCFBooleanTrue );
-
dtcr.decompressionTrackingCallback = _frame_decompressed;
dtcr.decompressionTrackingRefCon = (void *) si;
@@ -138,7 +127,6 @@
&si->si_v.ds);
CFRelease(pba);
- //ICMDecompressionSessionOptionsRelease( sessionOptions );
dbg_printf("[ vOE] < [%08lx] :: _setup_ds() = %ld\n", (UInt32) -1, err);
return err;
@@ -197,8 +185,7 @@
{
ComponentResult err = noErr;
ICMEncodedFrameOutputRecord efor;
- //long sc_prefs;
- SInt32 averageDataRate = 819200;
+ SInt32 tmpval = 0;
dbg_printf("[ vOE] >> [%08lx] :: _setup_cs()\n", (UInt32) -1);
@@ -208,66 +195,55 @@
si->si_v.cs = NULL;
}
-#if 0
- {
- long sc_prefs;
- sc_prefs = scAllowEncodingWithCompressionSession;
- err = SCSetInfo(si->si_v.stdVideo, scPreferenceFlagsType, &sc_prefs);
- dbg_printf("[ vOE] .? [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
-
- err = SCCopyCompressionSessionOptions(si->si_v.stdVideo, &si->si_v.cs_opts);
- dbg_printf("[ vOE] +? [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
- }
-#else
err = ICMCompressionSessionOptionsCreate(NULL, &si->si_v.cs_opts);
if (err)
goto bail;
// We must set this flag to enable P or B frames.
- err = ICMCompressionSessionOptionsSetAllowTemporalCompression( si->si_v.cs_opts, true );
+ err = ICMCompressionSessionOptionsSetAllowTemporalCompression(si->si_v.cs_opts,
+ true);
dbg_printf("[ vOE] ?1 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
- if( err ) {
+ if (err)
goto bail;
- }
// We must set this flag to enable B frames.
- err = ICMCompressionSessionOptionsSetAllowFrameReordering(si->si_v.cs_opts, true);
+ err = ICMCompressionSessionOptionsSetAllowFrameReordering(si->si_v.cs_opts,
+ true);
dbg_printf("[ vOE] ?2 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
- if( err ) {
+ if (err)
goto bail;
- }
- // Set the maximum key frame interval, also known as the key frame rate.
- err = ICMCompressionSessionOptionsSetMaxKeyFrameInterval( si->si_v.cs_opts, 30 );
+ // Set the maximum key frame rate.
+ err = ICMCompressionSessionOptionsSetMaxKeyFrameInterval(si->si_v.cs_opts,
+ si->si_v.keyrate);
dbg_printf("[ vOE] ?3 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
- if( err ) {
+ if (err)
goto bail;
- }
- // This allows the compressor more flexibility (ie, dropping and coalescing frames).
- err = ICMCompressionSessionOptionsSetAllowFrameTimeChanges( si->si_v.cs_opts, true );
+ // This allows the compressor more flexibility
+ // (ie, dropping and coalescing frames).
+ err = ICMCompressionSessionOptionsSetAllowFrameTimeChanges(si->si_v.cs_opts,
+ true);
dbg_printf("[ vOE] ?4 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
- if( err ) {
- fprintf( stderr, "ICMCompressionSessionOptionsSetAllowFrameTimeChanges() failed (%ld)\n", err );
+ if (err)
goto bail;
- }
// We need durations when we store frames.
- err = ICMCompressionSessionOptionsSetDurationsNeeded( si->si_v.cs_opts, true );
+ err = ICMCompressionSessionOptionsSetDurationsNeeded(si->si_v.cs_opts, true);
dbg_printf("[ vOE] ?5 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
- if( err ) {
- fprintf( stderr, "ICMCompressionSessionOptionsSetDurationsNeeded() failed (%ld)\n", err );
+ if (err)
goto bail;
- }
- averageDataRate = 480;
+ tmpval = si->si_v.quality;
err = ICMCompressionSessionOptionsSetProperty(si->si_v.cs_opts,
kQTPropertyClass_ICMCompressionSessionOptions,
kICMCompressionSessionOptionsPropertyID_Quality,
- sizeof( averageDataRate ),
- &averageDataRate );
+ sizeof(tmpval),
+ &tmpval);
dbg_printf("[ vOE] ?6 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
+ if (err)
+ goto bail;
err = ICMCompressionSessionOptionsSetProperty(si->si_v.cs_opts,
kQTPropertyClass_ICMCompressionSessionOptions,
@@ -275,40 +251,41 @@
sizeof(si->si_v.fps),
&si->si_v.fps);
dbg_printf("[ vOE] ?7 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
+ if (err)
+ goto bail;
- // Set the average data rate.
- averageDataRate = 0; //819200;
- err = ICMCompressionSessionOptionsSetProperty( si->si_v.cs_opts,
- kQTPropertyClass_ICMCompressionSessionOptions,
- kICMCompressionSessionOptionsPropertyID_AverageDataRate,
- sizeof( averageDataRate ),
- &averageDataRate );
+ tmpval = si->si_v.bitrate;
+ err = ICMCompressionSessionOptionsSetProperty(si->si_v.cs_opts,
+ kQTPropertyClass_ICMCompressionSessionOptions,
+ kICMCompressionSessionOptionsPropertyID_AverageDataRate,
+ sizeof(tmpval),
+ &tmpval);
dbg_printf("[ vOE] ?8 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
- if( err ) {
- fprintf( stderr, "ICMCompressionSessionOptionsSetProperty(AverageDataRate) failed (%ld)\n", err );
+ if (err)
goto bail;
+
+ if (si->si_v.custom != NULL) {
+ err = ICMCompressionSessionOptionsSetProperty(si->si_v.cs_opts,
+ kQTPropertyClass_ICMCompressionSessionOptions,
+ kICMCompressionSessionOptionsPropertyID_CompressorSettings,
+ sizeof(si->si_v.custom),
+ &si->si_v.custom);
+ dbg_printf("[ vOE] ?9 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
+ if (err)
+ goto bail;
}
-#endif
if (!err) {
efor.encodedFrameOutputCallback = _frame_compressed;
efor.encodedFrameOutputRefCon = (void *) si;
efor.frameDataAllocator = NULL;
-#if 1
err = ICMCompressionSessionCreate(NULL, si->si_v.width >> 16,
si->si_v.height >> 16,
- 'XiTh', /* !!! :P */
+ kVideoFormatXiphTheora, /* fixed for now... */
si->sourceTimeScale, si->si_v.cs_opts,
NULL, &efor, &si->si_v.cs);
-#else
- err = ICMCompressionSessionCreate(NULL, 320,
- 240,
- 'XiTh', /* !!! :P */
- si->sourceTimeScale, si->si_v.cs_opts,
- NULL, &efor, &si->si_v.cs);
-#endif
- dbg_printf("[ vOE] ?9 [%08lx] :: _setup_cs() = %ld [%lx x %lx]\n",
+ dbg_printf("[ vOE] ?A [%08lx] :: _setup_cs() = %ld [%lx x %lx]\n",
(UInt32) -1, err, si->si_v.width, si->si_v.height);
}
@@ -390,167 +367,9 @@
si->eos = true;
}
-/*
-static ComponentResult
-_get_frame_old(OggExportGlobalsPtr globals, StreamInfoPtr si)
-{
- ComponentResult err = noErr;
- CodecFlags whoCares;
-
- if (!si->src_extract_complete) {
- si->gdp.recordSize = sizeof(MovieExportGetDataParams);
- si->gdp.trackID = si->trackID;
- si->gdp.requestedTime = si->time;
- si->gdp.sourceTimeScale = si->sourceTimeScale;
- si->gdp.actualTime = 0;
- si->gdp.dataPtr = NULL;
- si->gdp.dataSize = 0;
- si->gdp.desc = NULL;
- si->gdp.descType = 0;
- si->gdp.descSeed = 0;
- si->gdp.requestedSampleCount = 0;
- si->gdp.actualSampleCount = 0;
- si->gdp.durationPerSample = 1;
- si->gdp.sampleFlags = 0;
-
- err = InvokeMovieExportGetDataUPP(si->refCon, &si->gdp,
- si->getDataProc);
- dbg_printf("[ vOE] D> [%08lx] :: _get_frame() = %ld; %ld [%ld] %ld [%ld] [%ld @ %ld] %ld '%4.4s'\n",
- (UInt32) globals, err, si->gdp.requestedSampleCount,
- si->gdp.actualSampleCount, si->gdp.requestedTime,
- si->gdp.actualTime, si->gdp.durationPerSample,
- si->gdp.sourceTimeScale, si->gdp.dataSize, (char *) &si->gdp.descType);
-
- if (!err)
- //si->time += si->gdp.durationPerSample * si->gdp.actualSampleCount;
- si->time += si->gdp.durationPerSample;
-
- if (err == eofErr) {
- err = noErr;
- si->src_extract_complete = true;
- }
-
- if (!err && si->gdp.descType == VideoMediaType) {
- ImageDescription *id = *(ImageDescriptionHandle) si->gdp.desc;
- dbg_printf("[ vOE] I> [%08lx] :: _get_frame() = '%4.4s' %08lx %08lx"
- " [%d x %d] [%f x %f] %ld %d %d %d\n",
- (UInt32) globals, (char *) &id->cType, id->temporalQuality,
- id->spatialQuality, id->width, id->height,
- id->hRes / 65536.0, id->vRes / 65536.0,
- id->dataSize, id->frameCount, id->depth, id->clutID);
-
- if (si->gdp.actualSampleCount == 0) {
- //si->src_extract_complete = true;
- } else {
- if (si->gdp.descType != VideoMediaType) {
- err = paramErr;
- goto bail;
- }
-
- if (si->gdp.descSeed != si->lastDescSeed) {
- MatrixRecord mr;
- SInt16 depth;
- short width, height;
- Rect dstRect, srcRect;
-
- // Initialize outputTrack...
- if (si->out_buffer) {
- free(si->out_buffer);
- si->out_buffer = NULL;
- si->out_buffer_size = 0;
- }
-
- if (si->si_v.decompressSequence) {
- CDSequenceEnd(si->si_v.decompressSequence);
- si->si_v.decompressSequence = 0;
- }
-
- if (si->si_v.gw) {
- DisposeGWorld(si->si_v.gw);
- si->si_v.gw = NULL;
- si->si_v.hPixMap = NULL;
- }
-
- if (si->si_v.width == 0)
- width = (**(ImageDescriptionHandle) si->gdp.desc).width;
- else
- width = FixRound(si->si_v.width);
-
- if (si->si_v.height == 0)
- height = (**(ImageDescriptionHandle) si->gdp.desc).height;
- else
- height = FixRound(si->si_v.height);
-
- dstRect.left = 0;
- dstRect.top = 0;
- dstRect.right = width;
- dstRect.bottom = height;
-
- srcRect.left = 0;
- srcRect.top = 0;
- srcRect.right = (**(ImageDescriptionHandle) si->gdp.desc).width;
- srcRect.bottom = (**(ImageDescriptionHandle)
- si->gdp.desc).height;
-
- RectMatrix(&mr, &srcRect, &dstRect);
-
- if (si->si_v.depth == 0)
- depth = (**(ImageDescriptionHandle) si->gdp.desc).depth;
- else
- depth = si->si_v.depth;
-
- // for k32ARGBPixelFormat when presented with 24.
- if (k24RGBPixelFormat == depth)
- depth = k32ARGBPixelFormat;
-
- // Create a GWorld for the approprate depth property
- err = QTNewGWorld(&si->si_v.gw, depth, &dstRect,
- NULL, NULL, kICMTempThenAppMemory);
- if (err || NULL == si->si_v.gw) goto bail;
-
- si->si_v.hPixMap = GetGWorldPixMap(si->si_v.gw);
-
- LockPixels(si->si_v.hPixMap);
-
- err =
- DecompressSequenceBeginS(&si->si_v.decompressSequence,
- (ImageDescriptionHandle)
- si->gdp.desc, si->gdp.dataPtr,
- si->gdp.dataSize, si->si_v.gw,
- NULL, NULL, &mr, ditherCopy,
- NULL, 0, codecHighQuality, NULL);
- if (err) goto bail;
-
- // Allocate memory enough to store maximum compressed data
- si->out_buffer_size = width * height * depth * 2;
- si->out_buffer = calloc(1, si->out_buffer_size);
-
- err = MemError();
- if (err) goto bail;
-
- si->lastDescSeed = si->gdp.descSeed;
- }
-
- err = DecompressSequenceFrameS(si->si_v.decompressSequence,
- si->gdp.dataPtr, si->gdp.dataSize,
- 0, &whoCares, NULL);
- if (err) goto bail;
-
- }
-
- si->gdp.actualSampleCount = 0;
- }
- }
-
- bail:
- return err;
-}
-*/
-
static ComponentResult _get_frame(StreamInfoPtr si)
{
ComponentResult err = noErr;
- //CodecFlags whoCares;
ICMFrameTimeRecord ft;
dbg_printf("[ vOE] >> [%08lx] :: _get_frame()\n", (UInt32) -1);
@@ -670,13 +489,6 @@
si->si_v.height / 65536.0, si->si_v.depth);
}
- /*
- err = DecompressSequenceFrameS(si->si_v.decompressSequence,
- si->gdp.dataPtr, si->gdp.dataSize,
- 0, &whoCares, NULL);
- if (err) goto bail;
- */
-
memset(&ft, 0, sizeof(ICMFrameTimeRecord));
ft.recordSize = sizeof(ICMFrameTimeRecord);
*(TimeValue64 *) &ft.value = si->time;
@@ -747,18 +559,19 @@
si->si_v.width = 0;
si->si_v.height = 0;
- si->si_v.fps = 24 << 16; //0;
- // si->si_v.depth = 0;
+ si->si_v.fps = kEOS_V_default_fps;
+ si->si_v.quality = 0;
+ si->si_v.bitrate = 0;
+ si->si_v.keyrate = kEOS_V_default_keyrate;
+ si->si_v.custom = NULL;
- si->si_v.grpos_shift = 6; //0;
+ si->si_v.grpos_shift = 0;
si->si_v.op_flags = 0;
- //si->last_grpos = -1;
si->si_v.frames_time = 0;
si->stream_type = VideoMediaType;
// allocate initial space for ogg_package
- //si->si_v.op_buffer = NULL;
si->si_v.op_buffer_size = kOES_V_init_op_size;
si->si_v.op_buffer = calloc(1, kOES_V_init_op_size);
@@ -766,11 +579,12 @@
if (!err) {
si->si_v.stdVideo = NULL;
-#if 0
+#if 1
err = OpenADefaultComponent(StandardCompressionType,
StandardCompressionSubType,
&si->si_v.stdVideo);
#else
+ // the 'vide' one is not documented :/
err = OpenADefaultComponent(StandardCompressionType,
'vide',
&si->si_v.stdVideo);
@@ -812,126 +626,87 @@
StreamInfo *si)
{
ComponentResult err = noErr;
+ SCSpatialSettings ss = {0, NULL, 0, 0};
+ SCTemporalSettings ts = {0, 0, 0};
+ SCDataRateSettings ds = {0, 0, 0, 0};
+ UInt32 tmp = 0;
+ Fixed tmp_fixed = 0;
dbg_printf("[ vOE] >> [%08lx] :: configure_stream()\n", (UInt32) globals);
- {
- SCSpatialSettings ss = {k422YpCbCr8PixelFormat, NULL, 32, 512};
- //SCSpatialSettings ss = {0, NULL, 0, 0};
- SCTemporalSettings ts = {0, 0, 0};
- SCDataRateSettings ds = {0, 0, 0, 0};
- ComponentInstance stdcomp = NULL;
- QTAtomContainer mes = NULL;
- Fixed tmp_fixed = 0;
+ err = InvokeMovieExportGetPropertyUPP(si->refCon, si->trackID,
+ scTemporalSettingsType, &ts,
+ si->getPropertyProc);
+ dbg_printf("[ vOE] ts [%08lx] :: configure_stream() = %ld, [%ld, %f, %ld]\n", (UInt32) globals, err,
+ ts.temporalQuality, ts.frameRate / 65536.0, ts.keyFrameRate);
+ if (!err) {
+ if (ts.frameRate != 0)
+ si->si_v.fps = ts.frameRate;
+ else if (globals->set_v_fps != 0)
+ si->si_v.fps = globals->set_v_fps;
+ else if (globals->movie_fps != 0)
+ si->si_v.fps = globals->movie_fps;
+ //else leave the default setting
- err = OpenADefaultComponent(StandardCompressionType, StandardCompressionSubType, &stdcomp);
- if (err)
- goto bail;
+ if (ts.keyFrameRate != 0)
+ si->si_v.keyrate = ts.keyFrameRate;
+ else if (globals->set_v_keyrate != 0)
+ si->si_v.keyrate = globals->set_v_keyrate;
+ //else leave the default setting
+ }
- ts.frameRate = 12 << 16;
- //err = SCSetInfo(stdcomp, scTemporalSettingsType, &ts);
- if (err)
- goto bail;
+ err = InvokeMovieExportGetPropertyUPP(si->refCon, si->trackID,
+ scSpatialSettingsType, &ss,
+ si->getPropertyProc);
+ dbg_printf("[ vOE] ss [%08lx] :: configure_stream() = %ld, ['%4.4s', %08lx, %d, %ld]\n", (UInt32) globals, err,
+ (char *) &ss.codecType, (UInt32) ss.codec, ss.depth, ss.spatialQuality);
+ if (!err) {
+ si->si_v.quality = ss.spatialQuality;
+ }
- ss.codecType = 'XiVs';
- //err = SCSetInfo(stdcomp, scSpatialSettingsType, &ss);
- if (err)
- goto bail;
+ err = InvokeMovieExportGetPropertyUPP(si->refCon, si->trackID,
+ scDataRateSettingsType, &ds,
+ si->getPropertyProc);
+ dbg_printf("[ vOE] ds [%08lx] :: configure_stream() = %ld, [%ld, %ld, %ld, %ld]\n", (UInt32) globals, err,
+ ds.dataRate, ds.frameDuration, ds.minSpatialQuality, ds.minTemporalQuality);
+ if (!err) {
+ if (ds.dataRate != 0)
+ si->si_v.bitrate = ds.dataRate;
+ else if (globals->set_v_bitrate != 0)
+ si->si_v.bitrate = globals->set_v_bitrate;
+ }
- err = SCGetSettingsAsAtomContainer(stdcomp, &mes);
- if (err)
- goto bail;
+ if (InvokeMovieExportGetPropertyUPP(si->refCon, si->trackID,
+ movieExportWidth, &tmp_fixed,
+ si->getPropertyProc) == noErr)
+ si->si_v.width = tmp_fixed;
- //err = MovieExportSetSettingsFromAtomContainer(globals->quickTimeMovieExporter, mes);
- if (err)
- goto bail;
+ if (InvokeMovieExportGetPropertyUPP(si->refCon, si->trackID,
+ movieExportHeight, &tmp_fixed,
+ si->getPropertyProc) == noErr)
+ si->si_v.height = tmp_fixed;
- err = InvokeMovieExportGetPropertyUPP(si->refCon, si->trackID,
- scTemporalSettingsType, &ts,
- si->getPropertyProc);
- dbg_printf("[ vOE] ts [%08lx] :: configure_stream() = %ld, [%ld, %f, %ld]\n", (UInt32) globals, err,
- ts.temporalQuality, ts.frameRate / 65536.0, ts.keyFrameRate);
-
- err = InvokeMovieExportGetPropertyUPP(si->refCon, si->trackID,
- scSpatialSettingsType, &ss,
- si->getPropertyProc);
- dbg_printf("[ vOE] ss [%08lx] :: configure_stream() = %ld, ['%4.4s', %08lx, %d, %ld]\n", (UInt32) globals, err,
- (char *) &ss.codecType, (UInt32) ss.codec, ss.depth, ss.spatialQuality);
-
- err = InvokeMovieExportGetPropertyUPP(si->refCon, si->trackID,
- scDataRateSettingsType, &ds,
- si->getPropertyProc);
- dbg_printf("[ vOE] ds [%08lx] :: configure_stream() = %ld, [%ld, %ld, %ld, %ld]\n", (UInt32) globals, err,
- ds.dataRate, ds.frameDuration, ds.minSpatialQuality, ds.minTemporalQuality);
-
- if (InvokeMovieExportGetPropertyUPP(si->refCon, si->trackID,
- movieExportWidth, &tmp_fixed,
- si->getPropertyProc) == noErr)
- si->si_v.width = tmp_fixed;
-
- if (InvokeMovieExportGetPropertyUPP(si->refCon, si->trackID,
- movieExportHeight, &tmp_fixed,
- si->getPropertyProc) == noErr)
- si->si_v.height = tmp_fixed;
-
- dbg_printf("[ vOE] x [%08lx] :: configure_stream() = [%f x %f]\n",
- (UInt32) globals, si->si_v.width / 65536.0,
- si->si_v.height / 65536.0);
-
- /*
- if (InvokeMovieExportGetPropertyUPP(outputTrack->refCon, outputTrack->trackID, scSpatialSettingsType, &spatialSettings, outputTrack->getPropertyProc) == noErr)
- outputTrack->depth = spatialSettings.depth;
-
- */
-
- bail:
- if (stdcomp)
- CloseComponent(stdcomp);
-
- if (mes)
- DisposeHandle(mes);
+ tmp = si->si_v.keyrate - 1;
+ si->si_v.grpos_shift = 0;
+ while (tmp > 0) {
+ si->si_v.grpos_shift += 1;
+ tmp >>= 1;
}
+ if (globals->set_v_custom != NULL)
+ si->si_v.custom = globals->set_v_custom;
+ dbg_printf("[ vOE] x [%08lx] :: configure_stream() = [%f x %f]\n",
+ (UInt32) globals, si->si_v.width / 65536.0,
+ si->si_v.height / 65536.0);
+
dbg_printf("[ vOE] < [%08lx] :: configure_stream() = %ld\n", (UInt32) globals, err);
return err;
}
-/*
ComponentResult
fill_page__video(OggExportGlobalsPtr globals, StreamInfoPtr si,
- Float64 max_duration, UInt32 *pos_sec, Float64 *pos_subsec)
-{
- ComponentResult err = noErr;
-
- Boolean eos_hit = false;
- Boolean do_loop = true;
-
-
- UInt32 max_page_duration = (UInt32) (max_duration *
- si->si_a.stda_asbd.mSampleRate);
-
- dbg_printf("[ vOE] >> [%08lx] :: fill_page__video(%lf)\n",
- (UInt32) globals, max_duration);
-
- _get_frame(globals, si);
-
- if (si->src_extract_complete) {
- si->eos = true;
- } else {
- si->og.header_len = 0;
- si->og.body_len = 0;
- si->og_ready = true;
- }
- dbg_printf("[ vOE] < [%08lx] :: fill_page__video() = %ld (%ld, %lf)\n",
- (UInt32) globals, err, *pos_sec, *pos_subsec);
- return err;
-}
-*/
-
-ComponentResult
-fill_page__video(OggExportGlobalsPtr globals, StreamInfoPtr si,
Float64 max_duration)
{
ComponentResult err = noErr;
@@ -981,7 +756,7 @@
si->si_v.op.granulepos = si->last_grpos;
result = ogg_stream_packetin(&si->os, &si->si_v.op);
dbg_printf("[ vOE] _i [%08lx] :: fill_page(): "
- "ogg_stream_packetin(%lld, %ld, %lld) = %d\n",
+ "ogg_stream_packetin(%lld, %ld, %016llx) = %d\n",
(UInt32) globals, si->si_v.op.packetno,
si->si_v.op.bytes, si->si_v.op.granulepos,
result);
@@ -1023,7 +798,7 @@
ComponentResult err = noErr;
Handle ext;
- /* pull frames until we got one, thus being able to get
+ /* pull frames until we get one, thus being able to get
video-encoded frame's sample description and the magic
cookie */
More information about the commits
mailing list