//-------------------------------------------------------------------- void ofQuickTimeGrabber::videoSettings(void){ //--------------------------------- #ifdef OF_VIDEO_CAPTURE_QUICKTIME //--------------------------------- Rect curBounds, curVideoRect; ComponentResult err; // Get our current state err = SGGetChannelBounds (gVideoChannel, &curBounds); if (err != noErr){ ofLogError("ofQuickTimeGrabber") << "videoSettings(): couldn't get get channel bounds: ComponentResult " << err; return; } err = SGGetVideoRect (gVideoChannel, &curVideoRect); if (err != noErr){ ofLogError("ofQuickTimeGrabber") << "videoSettings(): couldn't get video rect: ComponentResult " << err; return; } // Pause err = SGPause (gSeqGrabber, true); if (err != noErr){ ofLogError("ofQuickTimeGrabber") << "videoSettings(): couldn't set pause: ComponentResult " << err; return; } #ifdef TARGET_OSX //load any saved camera settings from file loadSettings(); static SGModalFilterUPP gSeqGrabberModalFilterUPP = NewSGModalFilterUPP(SeqGrabberModalFilterUPP); ComponentResult result = SGSettingsDialog(gSeqGrabber, gVideoChannel, 0, nil, 0, gSeqGrabberModalFilterUPP, nil); if (result != noErr){ ofLogError("ofQuickTimeGrabber") << "videoSettings(): settings dialog error: ComponentResult " << err; return; } //save any changed settings to file saveSettings(); #else SGSettingsDialog(gSeqGrabber, gVideoChannel, 0, nil, seqGrabSettingsPreviewOnly, NULL, 0); #endif SGSetChannelBounds(gVideoChannel, &videoRect); SGPause (gSeqGrabber, false); //--------------------------------- #endif //--------------------------------- }
// SGSettingsDialog with the "Compression" panel removed static OSErr MinimalSGSettingsDialog(SeqGrabComponent seqGrab, SGChannel sgchanVideo, WindowPtr gMonitor) { OSErr err; Component *panelListPtr = NULL; UInt8 numberOfPanels = 0; ComponentDescription cd = { SeqGrabPanelType, VideoMediaType, 0, 0, 0 }; Component c = 0; Component *cPtr = NULL; numberOfPanels = CountComponents(&cd); panelListPtr = (Component *) NewPtr(sizeof(Component) * (numberOfPanels + 1)); cPtr = panelListPtr; numberOfPanels = 0; CFStringRef compressionCFSTR = CFSTR("Compression"); do { ComponentDescription compInfo; c = FindNextComponent(c, &cd); if (c) { Handle hName = NewHandle(0); GetComponentInfo(c, &compInfo, hName, NULL, NULL); CFStringRef nameCFSTR = CFStringCreateWithPascalString(kCFAllocatorDefault, (unsigned char *)(*hName), kCFStringEncodingASCII); if (CFStringCompare (nameCFSTR, compressionCFSTR, kCFCompareCaseInsensitive) != kCFCompareEqualTo) { *cPtr++ = c; numberOfPanels++; } DisposeHandle(hName); } } while (c); if ((err = SGSettingsDialog(seqGrab, sgchanVideo, numberOfPanels, panelListPtr, seqGrabSettingsPreviewOnly, (SGModalFilterUPP) NewSGModalFilterUPP(SeqGrabberModalFilterProc), (long)gMonitor))) { return err; } return 0; }
void pix_videoDarwin :: DoVideoSettings() { Rect newActiveVideoRect; Rect curBounds, curVideoRect, newVideoRect; ComponentResult err; // Get our current state - do i need this??? err = SGGetChannelBounds (m_vc, &curBounds); err = SGGetVideoRect (m_vc, &curVideoRect); // Pause err = SGPause (m_sg, true); // Do the dialog thang err = SGSettingsDialog( m_sg, m_vc, 0, nil, 0, nil, 0); // What happened? err = SGGetVideoRect (m_vc, &newVideoRect); err = SGGetSrcVideoBounds (m_vc, &newActiveVideoRect); /* //Attempt to save SG settings to disk UserData uD = NULL; //NewUserData(uD); SGGetSettings(m_sg,&uD,0); //short uDCount; //uDCount = CountUserDataType(*uD,sgClipType); //post("UserDataType count %d",uDCount); Handle myHandle = NewHandle(0); int length; PutUserDataIntoHandle(uD,myHandle); length = GetHandleSize(myHandle); int myFile; myFile = open("/Users/lincoln/Documents/temp",O_CREAT | O_RDWR, 0600); write(myFile,myHandle,length); close(myFile); */ err = SGPause (m_sg, false); }
OSErr CreateNewSGChannelForRecording(ComponentInstance seqGrab, SGDataUPP dataProc, CGrafPtr drawPort, Rect *theRect, SGChannel *sgChannel, long refCon) { OSErr err = noErr; BailErr((err = SGInitialize(seqGrab))); // tell it we're not making a movie BailErr((err = SGSetDataRef(seqGrab,0,0,seqGrabDontMakeMovie))); // It wants a port, even if its not drawing to it BailErr((err = SGSetGWorld(seqGrab, drawPort, GetMainDevice()))); BailErr((err = SGNewChannel(seqGrab, VideoMediaType, sgChannel))); // let the user configure the video channel BailErr((err = SGSettingsDialog(seqGrab, *sgChannel, 0, nil, 0, nil, 0))); BailErr((err = SGSetChannelBounds(*sgChannel, theRect))); // set usage for new video channel to avoid playthrough BailErr((err = SGSetChannelUsage(*sgChannel, seqGrabRecord ))); //note we don't set seqGrabPlayDuringRecord BailErr((err = SGSetDataProc(seqGrab, dataProc, refCon))); BailErr((err = SGStartRecord(seqGrab))); bail: return err; }
//-------------------------------------------------------------------- void ofVideoGrabber::videoSettings(void){ //--------------------------------- #ifdef OF_VIDEO_CAPTURE_QUICKTIME //--------------------------------- Rect curBounds, curVideoRect; ComponentResult err; // Get our current state err = SGGetChannelBounds (gVideoChannel, &curBounds); if (err != noErr){ ofLog(OF_LOG_ERROR, "Error in SGGetChannelBounds"); return; } err = SGGetVideoRect (gVideoChannel, &curVideoRect); if (err != noErr){ ofLog(OF_LOG_ERROR, "Error in SGGetVideoRect"); return; } // Pause err = SGPause (gSeqGrabber, true); if (err != noErr){ ofLog(OF_LOG_ERROR, "Error in SGPause"); return; } #ifdef TARGET_OSX //load any saved camera settings from file loadSettings(); static SGModalFilterUPP gSeqGrabberModalFilterUPP = NewSGModalFilterUPP(SeqGrabberModalFilterUPP); ComponentResult result = SGSettingsDialog(gSeqGrabber, gVideoChannel, 0, nil, seqGrabSettingsPreviewOnly, gSeqGrabberModalFilterUPP, nil); if (result != noErr){ ofLog(OF_LOG_ERROR, "error in dialogue"); return; } //save any changed settings to file saveSettings(); #else SGSettingsDialog(gSeqGrabber, gVideoChannel, 0, nil, seqGrabSettingsPreviewOnly, NULL, 0); #endif SGSetChannelBounds(gVideoChannel, &videoRect); SGPause (gSeqGrabber, false); //--------------------------------- #endif //--------------------------------- //--------------------------------- #ifdef OF_VIDEO_CAPTURE_DIRECTSHOW //--------------------------------- if (bGrabberInited == true) VI.showSettingsWindow(device); //--------------------------------- #endif //--------------------------------- //--------------------------------- #ifdef OF_VIDEO_CAPTURE_UNICAP //-------------------------------- ucGrabber.queryUC_imageProperties(); //--------------------------------- #endif //--------------------------------- //--------------------------------- #ifdef OF_VIDEO_CAPTURE_V4L //-------------------------------- queryV4L_imageProperties(); //--------------------------------- #endif //--------------------------------- }
bool macsgCamera::initCamera(int width, int height, bool colour) { if (cameraID < 0) return false; this->width = width; this->height = height; this->colour = colour; this->fps = 30; bytes = (colour?3:1); int rowlength= width*bytes; switch (colour) { case false: { pixelFormat = k8IndexedGrayPixelFormat; //pixelFormat = kYVYU422PixelFormat; break; } case true: { pixelFormat = k24RGBPixelFormat; break; } } OSErr result; Rect srcRect = {0,0, height, width}; sg = OpenDefaultComponent(SeqGrabComponentType, 0); if(sg==NULL){ fprintf(stderr, "could not open default component\n"); } result = SGInitialize(sg); if(result!=noErr){ fprintf(stdout, "could not initialize SG\n"); } result = SGSetDataRef(sg, 0, 0, seqGrabDontMakeMovie); if (result != noErr){ fprintf(stdout, "dataref failed\n"); } result = SGNewChannel(sg, VideoMediaType, &vc); if(result!=noErr){ //fprintf(stdout, "could not make new SG channnel\n"); return false; } result = SGSettingsDialog ( sg, vc ,0 ,NULL ,seqGrabSettingsPreviewOnly,NULL,0); if(result!=noErr){ fprintf(stdout, "could not get settings from dialog\n"); } result = SGSetChannelBounds(vc, &srcRect); if(result!=noErr){ fprintf(stdout, "could not set SG ChannelBounds\n"); } /*result = SGSetFrameRate (vc, fps); if(result!=noErr){ fprintf(stdout, "could not set SG FrameRate\n"); }*/ result = SGSetChannelUsage(vc, seqGrabPreview); if(result!=noErr){ fprintf(stdout, "could not set SG ChannelUsage\n"); } result = SGSetChannelPlayFlags(vc, channelPlayAllData); if(result!=noErr){ fprintf(stdout, "could not set SG AllData\n"); }; buffer = new unsigned char[width*height*bytes]; result = QTNewGWorldFromPtr (&srcGWorld, pixelFormat, &srcRect, NULL, NULL, 0, buffer, rowlength); if (result!= noErr) { fprintf(stdout, "%d error at QTNewGWorldFromPtr\n", result); delete []buffer; buffer = NULL; return false; } if (srcGWorld == NULL) { fprintf(stdout, "Could not allocate off screen\n"); delete []buffer; buffer = NULL; return false; } result = SGSetGWorld(sg,(CGrafPtr)srcGWorld, NULL); if (result != noErr) { fprintf(stdout, "Could not set SGSetGWorld\n"); delete []buffer; buffer = NULL; return false; } result = SGPrepare(sg, TRUE, FALSE); if (result != noErr) { fprintf(stderr, "SGPrepare Preview failed\n"); } pbuffer = new unsigned char[width*height*bytes]; return true; }