Update of /cvsroot/artoolkit/artoolkit/lib/SRC/VideoMacOSX
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21452
Modified Files:
video.c Makefile.in
Added Files:
ARVideoSettingsController.m ARVideoSettingsController.h
videoInternal.h
Log Message:
Save and restore video input settings in Mac OS X.
Index: Makefile.in
===================================================================
RCS file: /cvsroot/artoolkit/artoolkit/lib/SRC/VideoMacOSX/Makefile.in,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** Makefile.in 4 Nov 2004 08:51:50 -0000 1.1.1.1
--- Makefile.in 10 Mar 2005 04:00:38 -0000 1.2
***************
*** 1,44 ****
! #
! # For instalation. Change this to your settings.
! #
! INC_DIR = ../../../include
! LIB_DIR = ../..
! #
! # compiler
! #
! CC= cc
! CFLAG= @CFLAG@ -I$(INC_DIR)
! #
! # For making the library
! #
! AR= ar
! ARFLAGS= @ARFLAG@
! RANLIB= @RANLIB@
! #
! # products
! #
! LIB= ${LIB_DIR}/libARvideo.a
! INCLUDE= ${INC_DIR}/AR/video.h
! #
! # compilation control
! #
! LIBOBJS= ${LIB}(video.o)
! all: ${LIBOBJS}
! ${LIBOBJS}: ${INCLUDE}
! .c.a:
! ${CC} -c ${CFLAG} $<
! ${AR} ${ARFLAGS} $@ $*.o
! ${RANLIB}
! rm -f $*.o
clean:
! rm -f *.o
! rm -f ${LIB}
allclean:
! rm -f *.o
! rm -f ${LIB}
! rm -f Makefile
--- 1,44 ----
! UNAME = $(shell uname)
! AR_HOME = ../../..
! CPPFLAGS = -I$(AR_HOME)/include
! CFLAGS = -fpascal-strings @CFLAG@
! CXXFLAGS = @CFLAG@
! LDFLAGS = -L$(AR_HOME)/lib @LDFLAG@
! LIBS = @LIBS@
! AR = ar
! ARFLAGS = @ARFLAG@
! RANLIB = @RANLIB@
! TARGET = $(AR_HOME)/lib/libARvideo.a
!
! HEADERS = \
! $(AR_HOME)/include/AR/video.h \
! videoInternal.h \
! ARVideoSettingsController.h
!
! OBJS = \
! video.o \
! ARVideoSettingsController.o
!
! # Implicit rule, to compile Objective-C files with the .m suffix.
! %.o : %.m
! $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
!
! default build all: $(TARGET)
!
! $(OBJS) : $(HEADERS)
!
! $(TARGET): $(OBJS)
! $(AR) ruv $@ $?
! $(RANLIB) $@
clean:
! -rm -f *.o *~ *.bak
! -rm $(TARGET)
allclean:
! -rm -f *.o *~ *.bak
! -rm $(TARGET)
! -rm -f Makefile
--- NEW FILE: ARVideoSettingsController.h ---
/*
* Copyright (c) 2005-2005 Philip Lamb (PRL) ph...@ed.... All rights reserved.
*
* Rev Date Who Changes
* 1.0.0 2005-03-08 PRL Written.
*
*/
/*
*
* This file is part of ARToolKit.
*
* ARToolKit is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ARToolKit 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ARToolKit; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#import <Cocoa/Cocoa.h>
#import "videoInternal.h"
@interface ARVideoSettingsController : NSObject {
@private
int inputIndex;
SeqGrabComponent seqGrab;
SGChannel sgchanVideo;
int mVersion;
UserData mUserData;
}
- (id)initInput:(int)inInputIndex withSeqGrabComponent:(SeqGrabComponent)inSeqGrab withSGChannel:(SGChannel)inSgchanVideo;
- (void)dealloc;
- (IBAction)sgConfigurationDialog:(id)sender;
- (OSErr)loadUserData:(UserData *)outUserData fromDefaults:(NSUserDefaults *)inDefaults forKey:(NSString *)inKey;
- (OSErr)saveUserData:(UserData)inUserData toDefaults:(NSUserDefaults *)inDefaults withKey:(NSString *)outKey;
@end
--- NEW FILE: videoInternal.h ---
/*
* Copyright (c) 2005-2005 Philip Lamb (PRL) ph...@ed.... All rights reserved.
*
* Rev Date Who Changes
* 1.0.0 2005-03-08 PRL Written.
*
*/
/*
*
* This file is part of ARToolKit.
*
* ARToolKit is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ARToolKit 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ARToolKit; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef __videoSettings_h__
#define __videoSettings_h__
#include <Carbon/Carbon.h>
#include <QuickTime/QuickTime.h>
#ifdef __cplusplus
extern "C" {
#endif
OSStatus RequestSGSettings(const int inputIndex, SeqGrabComponent seqGrab, SGChannel sgchanVideo, const int showDialog);
#ifdef __cplusplus
}
#endif
#endif // __videoSettings_h__
Index: video.c
===================================================================
RCS file: /cvsroot/artoolkit/artoolkit/lib/SRC/VideoMacOSX/video.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** video.c 4 Mar 2005 01:31:56 -0000 1.4
--- video.c 10 Mar 2005 04:00:38 -0000 1.5
***************
*** 8,12 ****
*/
/*
! * Copyright (c) 2003-2004 Philip Lamb (PRL) ph...@ed.... All rights reserved.
*
* Rev Date Who Changes
--- 8,12 ----
*/
/*
! * Copyright (c) 2003-2005 Philip Lamb (PRL) ph...@ed.... All rights reserved.
*
* Rev Date Who Changes
***************
*** 22,26 ****
--- 22,28 ----
* 1.3.1 2004-12-07 PRL Added config option "-pixelformat=" to support pixel format
* specification at runtime, with default determined at compile time.
+ * 1.4.0 2005-03-08 PRL Video input settings now saved and restored.
*
+ * TODO: Check version of Quicktime available at runtime.
*/
/*
***************
*** 82,85 ****
--- 84,88 ----
#include <AR/ar.h>
#include <AR/video.h>
+ #include "videoInternal.h"
// ============================================================================
***************
*** 211,216 ****
// initialize the default sequence grabber component
! if(err = SGInitialize(seqGrab))
! {
fprintf(stderr, "SGInitialize err=%ld\n", err);
goto endFunc;
--- 214,218 ----
// initialize the default sequence grabber component
! if(err = SGInitialize(seqGrab)) {
fprintf(stderr, "SGInitialize err=%ld\n", err);
goto endFunc;
***************
*** 218,223 ****
// This should be defaulted to the current port according to QT doco
! if (err = SGSetGWorld(seqGrab, GetWindowPort(pWindow), NULL))
! {
fprintf(stderr, "SGSetGWorld err=%ld\n", err);
goto endFunc;
--- 220,224 ----
// This should be defaulted to the current port according to QT doco
! if (err = SGSetGWorld(seqGrab, GetWindowPort(pWindow), NULL)) {
fprintf(stderr, "SGSetGWorld err=%ld\n", err);
goto endFunc;
***************
*** 239,244 ****
endFunc:
! if (err && (seqGrab != NULL))
! { // clean up on failure
CloseComponent(seqGrab);
seqGrab = NULL;
--- 240,244 ----
endFunc:
! if (err && (seqGrab != NULL)) { // clean up on failure
CloseComponent(seqGrab);
seqGrab = NULL;
***************
*** 257,262 ****
ComponentResult err = noErr;
! if (err = SGNewChannel(seqGrab, VideoMediaType, psgchanVideo))
! {
fprintf(stderr, "SGNewChannel err=%ld\n", err);
goto endFunc;
--- 257,261 ----
ComponentResult err = noErr;
! if (err = SGNewChannel(seqGrab, VideoMediaType, psgchanVideo)) {
fprintf(stderr, "SGNewChannel err=%ld\n", err);
goto endFunc;
***************
*** 266,271 ****
// set usage for new video channel to avoid playthrough
// note we don't set seqGrabPlayDuringRecord
! if (err = SGSetChannelUsage(*psgchanVideo, flags | seqGrabRecord))
! {
fprintf(stderr, "SGSetChannelUsage err=%ld\n", err);
goto endFunc;
--- 265,269 ----
// set usage for new video channel to avoid playthrough
// note we don't set seqGrabPlayDuringRecord
! if (err = SGSetChannelUsage(*psgchanVideo, flags | seqGrabRecord)) {
fprintf(stderr, "SGSetChannelUsage err=%ld\n", err);
goto endFunc;
***************
*** 282,340 ****
}
- // From QT sample code
- // Declaration of a typical application-defined function
- static Boolean MySGModalFilterProc (
- DialogPtr theDialog,
- const EventRecord *theEvent,
- short *itemHit,
- long refCon )
- {
- // Ordinarily, if we had multiple windows we cared about, we'd handle
- // updating them in here, but since we don't, we'll just clear out
- // any update events meant for us
- Boolean handled = false;
-
- if ((theEvent->what == updateEvt) &&
- ((WindowPtr) theEvent->message == (WindowPtr) refCon))
- {
- BeginUpdate ((WindowPtr) refCon);
- EndUpdate ((WindowPtr) refCon);
- handled = true;
- }
- return (handled);
- }
-
- static ComponentResult RequestSGSettings( SeqGrabComponent seqGrab,
- SGChannel sgchanVideo )
- {
- ComponentResult err;
-
- SGModalFilterUPP MySGModalFilterUPP;
- if (!(MySGModalFilterUPP = NewSGModalFilterUPP (MySGModalFilterProc)))
- {
- fprintf(stderr, "NewSGModalFilterUPP error\n");
- err = -1L; // TODO appropriate error code
- goto endFunc;
- }
-
- // let the user configure and choose the device and settings
- // "Due to a bug in all versions QuickTime 6.x for the function call "SGSettingsDialog()"
- // when used with the "seqGrabSettingsPreviewOnly" parameter, all third party panels will
- // be excluded." from http://www.outcastsoft.com/ASCDFG1394.html 15/03/04
- //if (err = SGSettingsDialog(seqGrab, sgchanVideo, 0, NULL, seqGrabSettingsPreviewOnly, MySGModalFilterUPP, 0))
- if (err = SGSettingsDialog(seqGrab, sgchanVideo, 0, NULL, 0, MySGModalFilterUPP, 0))
- {
- fprintf(stderr, "SGSettingsDialog err=%ld\n", err);
- goto endFunc;
- }
-
- // Dispose of the UPP
- if (MySGModalFilterUPP)
- DisposeSGModalFilterUPP(MySGModalFilterUPP);
-
- endFunc:
- return err;
- }
-
static ComponentResult vdgGetSettings(VdigGrab* pVdg)
{
--- 280,283 ----
***************
*** 396,412 ****
}
! static ComponentResult vdgRequestSettings(VdigGrab* pVdg, int showDialog)
{
ComponentResult err;
// Use the SG Dialog to allow the user to select device and compression settings
! if (showDialog) {
! if (err = RequestSGSettings( pVdg->seqGrab,
! pVdg->sgchanVideo)) {
! fprintf(stderr, "RequestSGSettings err=%ld\n", err);
! goto endFunc;
! }
! }
!
if (err = vdgGetSettings(pVdg)) {
fprintf(stderr, "vdgGetSettings err=%ld\n", err);
--- 339,352 ----
}
! static ComponentResult vdgRequestSettings(VdigGrab* pVdg, const int showDialog, const int inputIndex)
{
ComponentResult err;
// Use the SG Dialog to allow the user to select device and compression settings
! if (err = RequestSGSettings(inputIndex, pVdg->seqGrab, pVdg->sgchanVideo, showDialog)) {
! fprintf(stderr, "RequestSGSettings err=%ld\n", err);
! goto endFunc;
! }
!
if (err = vdgGetSettings(pVdg)) {
fprintf(stderr, "vdgGetSettings err=%ld\n", err);
***************
*** 421,429 ****
{
VideoDigitizerError err;
! Str255 vdName;
UInt32 vdFlags;
! if (!pBuffSize)
! {
fprintf(stderr, "vdgGetDeviceName: NULL pointer error\n");
err = (VideoDigitizerError)qtParamErr;
--- 361,368 ----
{
VideoDigitizerError err;
! Str255 vdName; // Pascal string (first byte is string length.
UInt32 vdFlags;
! if (!pBuffSize) {
fprintf(stderr, "vdgGetDeviceName: NULL pointer error\n");
err = (VideoDigitizerError)qtParamErr;
***************
*** 433,438 ****
if (err = VDGetDeviceNameAndFlags( pVdg->vdCompInst,
vdName,
! &vdFlags))
! {
fprintf(stderr, "VDGetDeviceNameAndFlags err=%ld\n", err);
*pBuffSize = 0;
--- 372,376 ----
if (err = VDGetDeviceNameAndFlags( pVdg->vdCompInst,
vdName,
! &vdFlags)) {
fprintf(stderr, "VDGetDeviceNameAndFlags err=%ld\n", err);
*pBuffSize = 0;
***************
*** 440,445 ****
}
! if (szName)
! {
int copyLen = (*pBuffSize-1 < vdName[0] ? *pBuffSize-1 : vdName[0]);
--- 378,382 ----
}
! if (szName) {
int copyLen = (*pBuffSize-1 < vdName[0] ? *pBuffSize-1 : vdName[0]);
***************
*** 448,453 ****
*pBuffSize = copyLen + 1;
! } else
! {
*pBuffSize = vdName[0] + 1;
}
--- 385,389 ----
*pBuffSize = copyLen + 1;
! } else {
*pBuffSize = vdName[0] + 1;
}
***************
*** 1397,1401 ****
}
! if (err = vdgRequestSettings(vid->pVdg, showDialog)) {
fprintf(stderr, "vdgRequestSettings err=%ld\n", err);
goto out2;
--- 1333,1337 ----
}
! if (err = vdgRequestSettings(vid->pVdg, showDialog, gVidCount)) {
fprintf(stderr, "vdgRequestSettings err=%ld\n", err);
goto out2;
--- NEW FILE: ARVideoSettingsController.m ---
/*
* Copyright (c) 2005-2005 Philip Lamb (PRL) ph...@ed.... All rights reserved.
*
* Rev Date Who Changes
* 1.0.0 2005-03-08 PRL Written.
*
*/
/*
*
* This file is part of ARToolKit.
*
* ARToolKit is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ARToolKit 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ARToolKit; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#import "ARVideoSettingsController.h"
@implementation ARVideoSettingsController
- (id)initInput:(int)inInputIndex withSeqGrabComponent:(SeqGrabComponent)inSeqGrab withSGChannel:(SGChannel)inSgchanVideo
{
ComponentResult err;
self = [super init];
// initialize NSApplication, using an entry point that is specific to bundles
// this is a no-op for Cocoa apps, but is required by Carbon apps
NSApplicationLoad();
inputIndex = inInputIndex;
seqGrab = inSeqGrab;
sgchanVideo = inSgchanVideo;
// Grab the defaults.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// Try to load the version key, used to see if we have any saved settings.
mVersion = [defaults floatForKey:@"version"];
if (!mVersion) {
// No previous defaults so define new.
mVersion = 1;
// Write out the defaults.
[defaults setInteger:mVersion forKey:@"version"];
[defaults synchronize];
}
// Load defaults, first time though mUserData may be 0 which is fine.
[self loadUserData:&mUserData fromDefaults:defaults forKey:[NSString stringWithFormat:@"sgVideoSettings%03i", inputIndex]];
if (mUserData) {
if ((err = SGSetChannelSettings(seqGrab, sgchanVideo, mUserData, 0)) != noErr) {
fprintf(stderr, "-sgConfigurationDialog: error %ld in SGSetChannelSettings().\n", err);
}
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
// NOTE: There is a know bug in QuickTime 6.4 in which the
// Settings Dialog pops up in random locations...sigh...
- (IBAction) sgConfigurationDialog:(id)sender
{
ComponentResult err;
Component *PanelListPtr = NULL;
long PanelCount;
// Set up the settings panel list removing the "Compression" panel.
ComponentDescription cDesc;
Component c;
long cCount;
Component *cPtr;
cDesc.componentType = SeqGrabPanelType;
cDesc.componentSubType = VideoMediaType;
cDesc.componentManufacturer = cDesc.componentFlags = cDesc.componentFlagsMask = 0L;
cCount = CountComponents(&cDesc);
if (cCount == 0) {
fprintf(stderr, "-sgConfigurationDialog: error in CountComponents().\n");
goto bail;
}
PanelListPtr = (Component *)NewPtr(sizeof(Component) * (cCount + 1));
if (err = MemError() || NULL == PanelListPtr) {
fprintf(stderr, "-sgConfigurationDialog: error in NewPtr().\n");
goto bail;
}
PanelCount = 0;
cPtr = PanelListPtr;
c = 0L;
do {
ComponentDescription compInfo;
c = FindNextComponent(c, &cDesc);
if (c) {
Handle hName = NewHandle(0);
if (err = MemError() || NULL == hName) {
fprintf(stderr, "-sgConfigurationDialog: error in NewHandle().\n");
goto bail;
}
GetComponentInfo(c, &compInfo, hName, NULL, NULL);
if (PLstrcmp(*hName, "\pCompression") != 0) {
*cPtr++ = c;
PanelCount++;
}
DisposeHandle(hName);
}
} while (c);
// Bring up the dialog and if the user didn't cancel
// save the new channel settings for later.
err = SGSettingsDialog(seqGrab, sgchanVideo, PanelCount, PanelListPtr, 0, NULL, NULL);
if (err == noErr) {
// Dispose the old settings and get the new channel settings.
if (mUserData) DisposeUserData(mUserData);
if ((err = SGGetChannelSettings(seqGrab, sgchanVideo, &mUserData, 0)) != noErr) {
fprintf(stderr, "-sgConfigurationDialog: error %ld in SGGetChannelSettings().\n", err);
}
// Grab the defaults.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// Write the defaults.
[self saveUserData:mUserData toDefaults:defaults withKey:[NSString stringWithFormat:@"sgVideoSettings%03i", inputIndex]];
[defaults synchronize];
} else if (err != userCanceledErr) {
fprintf(stderr, "-sgConfigurationDialog: error %ld in SGSettingsDialog().\n", err);
}
bail:
DisposePtr((Ptr)PanelListPtr);
}
// Get the Channel Settings as UserData from the preferences
- (OSErr)loadUserData:(UserData *)outUserData fromDefaults:(NSUserDefaults *)inDefaults forKey:(NSString *)inKey
{
NSData *theSettings;
Handle theHandle = NULL;
UserData theUserData = NULL;
OSErr err = paramErr;
// read the new setttings from our preferences
theSettings = [inDefaults objectForKey:inKey];
if (theSettings) {
err = PtrToHand([theSettings bytes], &theHandle, [theSettings length]);
if (theHandle) {
err = NewUserDataFromHandle(theHandle, &theUserData);
if (theUserData) {
*outUserData = theUserData;
}
DisposeHandle(theHandle);
}
}
return err;
}
// Save the Channel Settings from UserData in the preferences
- (OSErr)saveUserData:(UserData)inUserData toDefaults:(NSUserDefaults *)inDefaults withKey:(NSString *)outKey
{
NSData *theSettings;
Handle hSettings;
OSErr err;
if (NULL == inUserData) return paramErr;
hSettings = NewHandle(0);
err = MemError();
if (noErr == err) {
err = PutUserDataIntoHandle(inUserData, hSettings);
if (noErr == err) {
HLock(hSettings);
theSettings = [NSData dataWithBytes:(UInt8 *)*hSettings length:GetHandleSize(hSettings)];
// save the new setttings to our preferences
if (theSettings) {
[inDefaults setObject:theSettings forKey:outKey];
[inDefaults synchronize];
}
}
DisposeHandle(hSettings);
}
return err;
}
@end
OSStatus RequestSGSettings(const int inputIndex, SeqGrabComponent seqGrab, SGChannel sgchanVideo, const int showDialog)
{
NSAutoreleasePool *localPool;
ARVideoSettingsController *localController;
// Sanity check.
if (inputIndex < 0 || !seqGrab || !sgchanVideo) return (paramErr);
// Calling Objective-C from C necessitates an autorelease pool.
localPool = [[NSAutoreleasePool alloc] init];
localController = [[ARVideoSettingsController alloc] initInput:inputIndex withSeqGrabComponent:seqGrab withSGChannel:sgchanVideo];
if (showDialog) [localController sgConfigurationDialog:NULL];
[localController release];
[localPool release];
return (noErr);
}
|