Tutorial: persistent camera settings (was Re: Checking, no rush,
on my open questions)
Julien Letessier
lists at mezis.net
Mon Mar 21 23:23:21 GMT 2005
On 6 Sep 2004, at 20:50, Hank Roberts wrote:
> Unibrain cameras:
> Their support (finally) told me their "fire-i" camera settings last
> only as long as the application changing them is open. Unibrain makes
> a Windows app that supposedly saves and reloads settings, but again
> the settings are lost when that app closes. No other app can save
> settings and reapply them.
Hi all,
This seems to be a recurrent question, and the aforementioned lack of
persistence is true for several other cameras in addition to the fire-i
(e.g. some Sonys and Marlins, and at least one of my ToUcams).
So here's a rough sketch the solution I use for persistence of camera
settings.
I'm not saying that this is the one way to go, as this obviously works
only if you're using the SG (as I don't really dig VDigs), like in the
minimung, mungrab, sonofmungrab examples.
* saving settings:
- call SGSettingsDialog() or anything you use to modify the settings
- use SGGetChannelSettings() to put all settings into a UserData
- use PutUserDataIntoHandle() to serialize the UserData into a Handle
- use CFDataCreate() to transform you memory chunk into a CFDataRef
- use CFPreferencesSetAppValue(theKey, theCFSettings,
kCFPreferencesCurrentApplication)
to associate theKey to your settings [1], for the current application
- don't forget to CFPreferencesAppSynchronize()
to save to the .plist file
The tasks of locking/unlocking handles, and CFRelease'ing the right
stuff, if left as an exercice to the reader ;)
Once all's done settings are stored in the dictionary entry you
specified (theKey), in the application's [2] preferences file (that's
something like $HOME/Library/Preferences/com.gizmo.MyNiftyApp.plist)
* restoring settings
Basically it's the same, the other way around.
- CFPreferencesCopyAppValue(theKey, kCFPreferencesCurrentApplication)
fetches back your binary data from the .plist preferences file
- PtrToHand(CFDataGetBytePtr((CFDataRef)theCFSettings)
turns it back into a handle
- NewUserDataFromHandle() gives you the UserData
- finally, SGSetChannelSettings() restores the settings
This should be done pretty soon after calling SGNewChannel(), while
the SG isn't previewing/recording (yet).
[1] I recommend you use a key built from the DeviceName and the
InputName. Otherwise you're going to obtain very weird, mixed up
settings when plugging in a different camera, possible even ruining a
sensitive CCD. Don't laugh.
[2] This means each { user, application, camera } combination gets
unique persistent settings. This may or may not be what you're looking
for; in the latter case, tinkering with the options of
CFPreferencesSetAppValue() / CFPreferencesCopyAppValue() may provide
other combinations (e.g. user / host / camera).
G'd night,
--
Julien T. Letessier
PhD Intern /\/\
PRIMA group - GRAVIR-IMAG / _ _\ http://www.mezis.net/
IIHM group - CLIPS-IMAG \__._/ aim:jletessier
More information about the Video-Developers
mailing list