// Create the Sequence Grabber Audio Channel
void QuicktimeLiveImageStream::createSequenceGrabberAudioChannel()
{
    // Check capability and setting of Sequence Grabber
    GDHandle origDevice;
    CGrafPtr origPort;

    // Create GWorld
    GetGWorld (&origPort, &origDevice);
    SetGWorld (m_gw, NULL); // set current graphics port to offscreen
    // Setup
    // Get a video channel
    ComponentResult result = SGNewChannel (m_gSeqGrabber, SoundMediaType, &m_gSoundChannel);
    if ((m_gSoundChannel != nil) && (result == noErr))
    {
        result = SGInitChannel(m_gSoundChannel, m_gSeqGrabber);
        // result = SGSetChannelUsage (m_gSoundChannel, seqGrabPreview );
        // Usage
        if (g_s_use_sg_record)
            result = SGSetChannelUsage (m_gSoundChannel, seqGrabRecord | seqGrabLowLatencyCapture);
        else
        {
            result = SGSetChannelUsage (m_gSoundChannel, seqGrabPreview | seqGrabRecord | seqGrabLowLatencyCapture);
        }

        // Get
        Str255 deviceName;
        Str255 inputName;
        short  inputNumber;
        result = SGGetChannelDeviceAndInputNames(m_gSoundChannel, deviceName, inputName, &inputNumber);

        // Set
        // OSG_DEBUG << "Setting up audio component from input prefs" << std::endl;
        result = SGSetChannelDevice     (m_gSoundChannel, m_soundDeviceIDStr);
        result = SGSetChannelDeviceInput(m_gSoundChannel, m_soundDeviceInputID);
        // Set the volume low to prevent feedback when we start the preview,
        // in case the mic is anywhere near the speaker.
        short volume = 0;
        result = SGGetChannelVolume (m_gSoundChannel, &volume);
        // result = SGSetChannelVolume (m_gSoundChannel, 255);
        // Inform
        result = SGChangedSource        (m_gSeqGrabber,   m_gSoundChannel);
    }
    else
    {
        OSG_FATAL << "Could not create SGNewChannel for Sound Channel" << std::endl;
    }

    // Set GWorld back
    SetGWorld(origPort, origDevice);
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
// Create the Sequence Grabber Video Channel
void QuicktimeLiveImageStream::createSequenceGrabberVideoChannel()
{
    // Check capability and setting of Sequence Grabber
    GDHandle origDevice;
    CGrafPtr origPort;
    // Create GWorld
    GetGWorld (&origPort, &origDevice);
    SetGWorld (m_gw, NULL); // set current graphics port to offscreen
    // Setup
    // Get a video channel
    ComponentResult result = SGNewChannel (m_gSeqGrabber, VideoMediaType, &m_gVideoChannel);
    if ((m_gVideoChannel != nil) && (result == noErr))
    {
        result = SGInitChannel(m_gVideoChannel, m_gSeqGrabber);
        Rect gActiveVideoRect;
        // Usage
        if (g_s_use_sg_record)
            result = SGSetChannelUsage (m_gVideoChannel, seqGrabRecord | seqGrabLowLatencyCapture);
        else
        {
            result = SGSetChannelUsage (m_gVideoChannel, seqGrabPreview);
        }
        //  result = SGSetUseScreenBuffer(m_gVideoChannel, FALSE);
        // Set
        OSG_DEBUG << "Setting up vdig from input prefs" << std::endl;
        result = SGSetChannelDevice     ( m_gVideoChannel, m_videoDeviceIDStr);
        result = SGSetChannelDeviceInput( m_gVideoChannel, m_videoDeviceInputID);
        // result = SGSetChannelPlayFlags  ( m_gVideoChannel, channelPlayFast | channelPlayHighQuality | channelPlayAllData);
        result = SGSetChannelPlayFlags  ( m_gVideoChannel, channelPlayFast );

        VideoDigitizerComponent vdig = SGGetVideoDigitizerComponent(m_gVideoChannel);
        VideoDigitizerError vid_err;
        vid_err = VDSetInputStandard (vdig, palIn);
        OSG_DEBUG << "Setup vdig from input prefs:" << std::endl;
        print_video_component_capability(vdig);

        result = SGVideoDigitizerChanged( m_gVideoChannel);
        result = SGGetSrcVideoBounds    ( m_gVideoChannel, &gActiveVideoRect);     
        result = SGSetChannelBounds     ( m_gVideoChannel, &gActiveVideoRect);
        
        result = SGChangedSource (m_gSeqGrabber, m_gVideoChannel);

        Fixed frame_rate;
        result = SGGetFrameRate (m_gVideoChannel, &frame_rate);
        result = SGSetFrameRate (m_gVideoChannel, 100);
        //
        // Sound
        /*
        long                sound_id;
        Str255              sound_driver_name;
        char*               sound_driver_name_cstr;
        vid_err = VDGetSoundInputSource(vdig, (long)m_videoDeviceInputID, &sound_id);
        vid_err = VDGetSoundInputDriver(vdig, sound_driver_name);
        sound_driver_name_cstr = pstr_printable(sound_driver_name);
        OSG_DEBUG << "vdig sound driver name :" << sound_driver_name_cstr << std::endl;
        OSG_DEBUG << "vdig sound driver id   :" << sound_id << std::endl;
        */
    }
    else
    {
        OSG_FATAL << "Could not create SGNewChannel for Video Channel" << std::endl;
    }
    // Set GWorld back
    SetGWorld(origPort, origDevice);
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
//------------------------------------------------------
bool ofVideoGrabber::qtInitSeqGrabber(){

		if (bSgInited != true){

			OSErr err = noErr;

			ComponentDescription	theDesc;
			Component				sgCompID;

			// this crashes when we get to
			// SGNewChannel
			// we get -9405 as error code for the channel
			// -----------------------------------------
			// gSeqGrabber = OpenDefaultComponent(SeqGrabComponentType, 0);

			// this seems to work instead (got it from hackTV)
			// -----------------------------------------
			theDesc.componentType = SeqGrabComponentType;
			theDesc.componentSubType = NULL;
			theDesc.componentManufacturer = 'appl';
			theDesc.componentFlags = NULL;
			theDesc.componentFlagsMask = NULL;
			sgCompID = FindNextComponent (NULL, &theDesc);
			// -----------------------------------------

			if (sgCompID == NULL){
				ofLog(OF_LOG_ERROR, "error:FindNextComponent did not return a valid component");
				return false;
			}

			gSeqGrabber = OpenComponent(sgCompID);

			err = GetMoviesError();
			if (gSeqGrabber == NULL || err) {
				ofLog(OF_LOG_ERROR, "error: can't get default sequence grabber component");
				return false;
			}

			err = SGInitialize(gSeqGrabber);
			if (err != noErr) {
				ofLog(OF_LOG_ERROR, "error: can't initialize sequence grabber component");
				return false;
			}

			err = SGSetDataRef(gSeqGrabber, 0, 0, seqGrabDontMakeMovie);
			if (err != noErr) {
				ofLog(OF_LOG_ERROR, "error: can't set the destination data reference");
				return false;
			}

			// windows crashes w/ out gworld, make a dummy for now...
			// this took a long time to figure out.
			err = SGSetGWorld(gSeqGrabber, 0, 0);
			if (err != noErr) {
				ofLog(OF_LOG_ERROR, "error: setting up the gworld");
				return false;
			}

			err = SGNewChannel(gSeqGrabber, VideoMediaType, &(gVideoChannel));
			if (err != noErr) {
				ofLog(OF_LOG_ERROR, "error: creating a channel.  Check if you have any qt capable cameras attached");
				return false;
			}

			bSgInited = true;
			return true;
		}

		return false;
}
Exemplo n.º 6
0
static gboolean
gst_osx_video_src_start (GstBaseSrc * src)
{
  GstOSXVideoSrc *self;
  GObjectClass *gobject_class;
  GstOSXVideoSrcClass *klass;
  ComponentResult err;

  self = GST_OSX_VIDEO_SRC (src);
  gobject_class = G_OBJECT_GET_CLASS (src);
  klass = GST_OSX_VIDEO_SRC_CLASS (gobject_class);

  GST_DEBUG_OBJECT (src, "entering");

  if (!klass->movies_enabled)
    return FALSE;

  self->seq_num = 0;

  self->seq_grab = OpenDefaultComponent (SeqGrabComponentType, 0);
  if (self->seq_grab == NULL) {
    err = paramErr;
    GST_ERROR_OBJECT (self, "OpenDefaultComponent failed. paramErr=%d",
        (int) err);
    goto fail;
  }

  err = SGInitialize (self->seq_grab);
  if (err != noErr) {
    GST_ERROR_OBJECT (self, "SGInitialize returned %d", (int) err);
    goto fail;
  }

  err = SGSetDataRef (self->seq_grab, 0, 0, seqGrabDontMakeMovie);
  if (err != noErr) {
    GST_ERROR_OBJECT (self, "SGSetDataRef returned %d", (int) err);
    goto fail;
  }

  err = SGNewChannel (self->seq_grab, VideoMediaType, &self->video_chan);
  if (err != noErr) {
    GST_ERROR_OBJECT (self, "SGNewChannel returned %d", (int) err);
    goto fail;
  }

  if (!device_select (self))
    goto fail;

  GST_DEBUG_OBJECT (self, "started");
  return TRUE;

fail:
  self->video_chan = NULL;

  if (self->seq_grab) {
    err = CloseComponent (self->seq_grab);
    if (err != noErr)
      GST_WARNING_OBJECT (self, "CloseComponent returned %d", (int) err);
    self->seq_grab = NULL;
  }

  return FALSE;
}
Exemplo n.º 7
0
/* return a list of available devices.  the default device (if any) will be
 * the first in the list.
 */
static GList *
device_list (GstOSXVideoSrc * src)
{
  SeqGrabComponent component = NULL;
  SGChannel channel;
  SGDeviceList deviceList;
  SGDeviceName *deviceEntry;
  SGDeviceInputList inputList;
  SGDeviceInputName *inputEntry;
  ComponentResult err;
  int n, i;
  GList *list;
  video_device *dev, *default_dev;
  gchar sgname[256];
  gchar friendly_name[256];

  list = NULL;
  default_dev = NULL;

  if (src->video_chan) {
    /* if we already have a video channel allocated, use that */
    GST_DEBUG_OBJECT (src, "reusing existing channel for device_list");
    channel = src->video_chan;
  } else {
    /* otherwise, allocate a temporary one */
    component = OpenDefaultComponent (SeqGrabComponentType, 0);
    if (!component) {
      err = paramErr;
      GST_ERROR_OBJECT (src, "OpenDefaultComponent failed. paramErr=%d",
          (int) err);
      goto end;
    }

    err = SGInitialize (component);
    if (err != noErr) {
      GST_ERROR_OBJECT (src, "SGInitialize returned %d", (int) err);
      goto end;
    }

    err = SGSetDataRef (component, 0, 0, seqGrabDontMakeMovie);
    if (err != noErr) {
      GST_ERROR_OBJECT (src, "SGSetDataRef returned %d", (int) err);
      goto end;
    }

    err = SGNewChannel (component, VideoMediaType, &channel);
    if (err != noErr) {
      GST_ERROR_OBJECT (src, "SGNewChannel returned %d", (int) err);
      goto end;
    }
  }

  err =
      SGGetChannelDeviceList (channel, sgDeviceListIncludeInputs, &deviceList);
  if (err != noErr) {
    GST_ERROR_OBJECT (src, "SGGetChannelDeviceList returned %d", (int) err);
    goto end;
  }

  for (n = 0; n < (*deviceList)->count; ++n) {
    deviceEntry = &(*deviceList)->entry[n];

    if (deviceEntry->flags & sgDeviceNameFlagDeviceUnavailable)
      continue;

    p2cstrcpy (sgname, deviceEntry->name);
    inputList = deviceEntry->inputs;

    if (inputList && (*inputList)->count >= 1) {
      for (i = 0; i < (*inputList)->count; ++i) {
        inputEntry = &(*inputList)->entry[i];

        p2cstrcpy (friendly_name, inputEntry->name);

        dev = video_device_alloc ();
        dev->id = create_device_id (sgname, i);
        if (!dev->id) {
          video_device_free (dev);
          i = -1;
          break;
        }

        dev->name = g_strdup (friendly_name);
        list = g_list_append (list, dev);

        /* if this is the default device, note it */
        if (n == (*deviceList)->selectedIndex
            && i == (*inputList)->selectedIndex) {
          default_dev = dev;
        }
      }

      /* error */
      if (i == -1)
        break;
    } else {
      /* ### can a device have no defined inputs? */
      dev = video_device_alloc ();
      dev->id = create_device_id (sgname, -1);
      if (!dev->id) {
        video_device_free (dev);
        break;
      }

      dev->name = g_strdup (sgname);
      list = g_list_append (list, dev);

      /* if this is the default device, note it */
      if (n == (*deviceList)->selectedIndex) {
        default_dev = dev;
      }
    }
  }

  /* move default device to the front */
  if (default_dev) {
    list = g_list_remove (list, default_dev);
    list = g_list_prepend (list, default_dev);
  }

end:
  if (!src->video_chan && component) {
    err = CloseComponent (component);
    if (err != noErr)
      GST_WARNING_OBJECT (src, "CloseComponent returned %d", (int) err);
  }

  return list;
}
Exemplo n.º 8
0
/* Initialize the QuickTime grabber */
static int qt_open_grabber(struct qt_grabber_state *s, char *fmt)
{
        GrafPtr savedPort;
        WindowPtr gMonitor;
        //SGModalFilterUPP      seqGrabModalFilterUPP;

        assert(s != NULL);
        assert(s->magic == MAGIC_QT_GRABBER);

        /****************************************************************************************/
        /* Step 0: Initialise the QuickTime movie toolbox.                                      */
        InitCursor();
        EnterMovies();

        /****************************************************************************************/
        /* Step 1: Create an off-screen graphics world object, into which we can capture video. */
        /* Lock it into position, to prevent QuickTime from messing with it while capturing.    */
        OSType pixelFormat;
        pixelFormat = FOUR_CHAR_CODE('BGRA');
        /****************************************************************************************/
        /* Step 2: Open and initialise the default sequence grabber.                            */
        s->grabber = OpenDefaultComponent(SeqGrabComponentType, 0);
        if (s->grabber == 0) {
                debug_msg("Unable to open grabber\n");
                return 0;
        }

        gMonitor = GetDialogWindow(GetNewDialog(1000, NULL, (WindowPtr) - 1L));

        GetPort(&savedPort);
        SetPort((GrafPtr)gMonitor);

        if (SGInitialize(s->grabber) != noErr) {
                debug_msg("Unable to init grabber\n");
                return 0;
        }

        SGSetGWorld(s->grabber, GetDialogPort((DialogPtr)gMonitor), NULL);

        /****************************************************************************************/
        /* Specify the destination data reference for a record operation tell it */
        /* we're not making a movie if the flag seqGrabDontMakeMovie is used,    */
        /* the sequence grabber still calls your data function, but does not     */
        /* write any data to the movie file writeType will always be set to      */
        /* seqGrabWriteAppend                                                    */
        if (SGSetDataRef(s->grabber, 0, 0, seqGrabDontMakeMovie) != noErr) {
                CloseComponent(s->grabber);
                debug_msg("Unable to set data ref\n");
                return 0;
        }

        if (SGSetGWorld(s->grabber, NULL, NULL) != noErr) {
                debug_msg("Unable to get gworld from grabber\n");
                return 0;
        }

        if (SGNewChannel(s->grabber, VideoMediaType, &s->video_channel) !=
            noErr) {
                debug_msg("Unable to open video channel\n");
                return 0;
        }

        /* do not check for grab audio in case that we will only display usage */
        if (SGNewChannel(s->grabber, SoundMediaType, &s->audio_channel) !=
                noErr) {
                fprintf(stderr, "Warning: Creating audio channel failed. "
                                "Disabling sound output.\n");
                s->grab_audio = FALSE;
        }

        /* Print available devices */
        int i;
        int j;
        SGDeviceInputList inputList;
        SGDeviceList deviceList;
        if (strcmp(fmt, "help") == 0) {
                printf("\nUsage:\t-t quicktime:<device>:<mode>:<pixel_type>[:<audio_device>:<audio_mode>]\n\n");
                if (SGGetChannelDeviceList
                    (s->video_channel, sgDeviceListIncludeInputs,
                     &deviceList) == noErr) {
                        fprintf(stdout, "\nAvailable capture devices:\n");
                        for (i = 0; i < (*deviceList)->count; i++) {
                                SGDeviceName *deviceEntry =
                                    &(*deviceList)->entry[i];
                                fprintf(stdout, " Device %d: ", i);
                                nprintf((char *) deviceEntry->name);
                                if (deviceEntry->flags &
                                    sgDeviceNameFlagDeviceUnavailable) {
                                        fprintf(stdout,
                                                "  - ### NOT AVAILABLE ###");
                                }
                                if (i == (*deviceList)->selectedIndex) {
                                        fprintf(stdout, " - ### ACTIVE ###");
                                }
                                fprintf(stdout, "\n");
                                short activeInputIndex = 0;
                                inputList = deviceEntry->inputs;
                                if (inputList && (*inputList)->count >= 1) {
                                        SGGetChannelDeviceAndInputNames
                                            (s->video_channel, NULL, NULL,
                                             &activeInputIndex);
                                        for (j = 0; j < (*inputList)->count;
                                             j++) {
                                                fprintf(stdout, "\t");
                                                fprintf(stdout, "- %d. ", j);
                                                nprintf((char *) &(*inputList)->entry
                                                             [j].name);
                                                if ((i ==
                                                     (*deviceList)->selectedIndex)
                                                    && (j == activeInputIndex))
                                                        fprintf(stdout,
                                                                " - ### ACTIVE ###");
                                                fprintf(stdout, "\n");
                                        }
                                }
                        }
                        SGDisposeDeviceList(s->grabber, deviceList);
                        CodecNameSpecListPtr list;
                        GetCodecNameList(&list, 1);
                        printf("\nCompression types:\n");
                        for (i = 0; i < list->count; i++) {
                                int fcc = list->list[i].cType;
                                printf("\t%d) ", i);
                                nprintf((char *) list->list[i].typeName);
                                printf(" - FCC (%c%c%c%c)",
                                       fcc >> 24,
                                       (fcc >> 16) & 0xff,
                                       (fcc >> 8) & 0xff, (fcc) & 0xff);
                                printf(" - codec id %x",
                                       (unsigned int)(list->list[i].codec));
                                printf(" - cType %x",
                                       (unsigned int)list->list[i].cType);
                                printf("\n");
                        }
                }
Exemplo n.º 9
0
void pix_videoDarwin :: InitSeqGrabber()
{
    OSErr anErr;
    Rect m_srcRect = {0,0, m_vidYSize, m_vidXSize};

    SGDeviceList    devices;
    short            deviceIndex,inputIndex;
    short            deviceCount = 0;
    SGDeviceInputList theSGInputList = NULL;
    bool showInputsAsDevices;
//    UserData     *uD;


    /*
    int num_components = 0;
    Component c = 0;
    ComponentDescription cd;

     cd.componentType = SeqGrabComponentType;
     cd.componentSubType = 0;
     cd.componentManufacturer = 0;
     cd.componentFlags = 0;
     cd.componentFlagsMask = 0;

     while((c = FindNextComponent(c, &cd)) != 0) {
       num_components++;  }                 // add component c to the list.
  //   post("number of SGcomponents: %d",num_components);
  */
    m_sg = OpenDefaultComponent(SeqGrabComponentType, 0);
    if(m_sg==NULL){
        error("could not open default component");
        return;
    }
    anErr = SGInitialize(m_sg);
    if(anErr!=noErr){
        error("could not initialize SG error %d",anErr);
        return;
    }

    anErr = SGSetDataRef(m_sg, 0, 0, seqGrabDontMakeMovie);
        if (anErr != noErr){
            error("dataref failed with error %d",anErr);
        }

    anErr = SGNewChannel(m_sg, VideoMediaType, &m_vc);
    if(anErr!=noErr){
        error("could not make new SG channnel error %d",anErr);
        return;
    }

     anErr = SGGetChannelDeviceList(m_vc, sgDeviceListIncludeInputs, &devices);
    if(anErr!=noErr){
        error("could not get SG channnel Device List");
    }else{
        deviceCount = (*devices)->count;
        deviceIndex = (*devices)->selectedIndex;
        logpost(NULL, 3, "SG channnel Device List count %d index %d",deviceCount,deviceIndex);
        int i;
        for (i = 0; i < deviceCount; i++){
	  logpost(NULL, 3, "SG channnel Device List  %.*s",
	       (*devices)->entry[i].name[0],
	       (*devices)->entry[i].name+1);
            }
        SGGetChannelDeviceAndInputNames(m_vc, NULL, NULL, &inputIndex);

        showInputsAsDevices = ((*devices)->entry[deviceIndex].flags) & sgDeviceNameFlagShowInputsAsDevices;

        theSGInputList = ((SGDeviceName *)(&((*devices)->entry[deviceIndex])))->inputs; //fugly

        //we should have device names in big ass undocumented structs

        //walk through the list
        //for (i = 0; i < deviceCount; i++){
        for (i = 0; i < inputIndex; i++){
            logpost(NULL, 3, "SG channnel Input Device List %d %.*s",
		 i,
		 (*theSGInputList)->entry[i].name[0],
		 (*theSGInputList)->entry[i].name+1);
        }


    }

    //this call sets the input device
    if (m_inputDevice > 0 && m_inputDevice < deviceCount) //check that the device is not out of bounds
        //anErr = SGSetChannelDeviceInput(m_vc,m_inputDevice);
        logpost(NULL, 3, "SGSetChannelDevice trying %s", 
	     (*devices)->entry[m_inputDevice].name[0],
	     (*devices)->entry[m_inputDevice].name+1);
        anErr = SGSetChannelDevice(m_vc, (*devices)->entry[m_inputDevice].name);

        if(anErr!=noErr) error("SGSetChannelDevice returned error %d",anErr);

        anErr = SGSetChannelDeviceInput(m_vc,m_inputDeviceChannel);

        if(anErr!=noErr) error("SGSetChannelDeviceInput returned error %d",anErr);

    /*  //attempt to save SG settings to disk
    NewUserData(uD);
    SGGetSettings(m_sg,uD,0);
    short uDCount;
    uDCount = CountUserDataType(*uD,sgClipType);
    post("UserDataType count %d",uDCount);

    Handle myHandle;

    PutUserDataIntoHandle(*uD,myHandle);

    int myFile;
    myFile = open("/Users/lincoln/Documents/temp",O_CREAT | O_RDWR, 0600);
    write(myFile,myHandle,4096);
    close(myFile);
    */

    //grab the VDIG info from the SGChannel
    m_vdig = SGGetVideoDigitizerComponent(m_vc);
    vdigErr = VDGetDigitizerInfo(m_vdig,&m_vdigInfo); //not sure if this is useful

    Str255    vdigName;
    memset(vdigName,0,255);
    vdigErr = VDGetInputName(m_vdig,m_inputDevice,vdigName);
    logpost(NULL, 3, "vdigName is %s",vdigName); // pascal string?

    Rect vdRect;
    vdigErr = VDGetDigitizerRect(m_vdig,&vdRect);
    logpost(NULL, 3, "digitizer rect is top %d bottom %d left %d right %d",vdRect.top,vdRect.bottom,vdRect.left,vdRect.right);

    vdigErr = VDGetActiveSrcRect(m_vdig,0,&vdRect);
    logpost(NULL, 3, "active src rect is top %d bottom %d left %d right %d",vdRect.top,vdRect.bottom,vdRect.left,vdRect.right);

    anErr = SGSetChannelBounds(m_vc, &m_srcRect);
    if(anErr!=noErr){
        error("could not set SG ChannelBounds ");
    }

    anErr = SGSetVideoRect(m_vc, &m_srcRect);
    if(anErr!=noErr){
        error("could not set SG Rect ");
    }

    anErr = SGSetChannelUsage(m_vc, seqGrabPreview);
    if(anErr!=noErr){
        error("could not set SG ChannelUsage ");
    }

    switch (m_quality){
    case 0:
        anErr = SGSetChannelPlayFlags(m_vc, channelPlayNormal);
        post("set SG NormalQuality");
        break;
    case 1:
        anErr = SGSetChannelPlayFlags(m_vc, channelPlayHighQuality);
        post("set SG HighQuality");
        break;
    case 2:
        anErr = SGSetChannelPlayFlags(m_vc, channelPlayFast);
        post("set SG FastQuality");
        break;
    case 3:
        anErr = SGSetChannelPlayFlags(m_vc, channelPlayAllData);
        post("set SG PlayAlldata");
        break;
    }
    if (m_colorspace==GL_BGRA_EXT){
      m_pixBlock.image.xsize = m_vidXSize;
      m_pixBlock.image.ysize = m_vidYSize;
      m_pixBlock.image.setCsizeByFormat(GL_RGBA_GEM);
      m_pixBlock.image.reallocate();
      m_rowBytes = m_vidXSize*4;
      anErr = QTNewGWorldFromPtr (&m_srcGWorld,
                                  k32ARGBPixelFormat,
                                  &m_srcRect,
                                  NULL,
                                  NULL,
                                  0,
                                  m_pixBlock.image.data,
                                  m_rowBytes);

      post ("using RGB");
    }else{
      m_pixBlock.image.xsize = m_vidXSize;
      m_pixBlock.image.ysize = m_vidYSize;
      m_pixBlock.image.csize = 2;
      m_pixBlock.image.format = GL_YCBCR_422_APPLE;
#ifdef __VEC__
      m_pixBlock.image.type = GL_UNSIGNED_SHORT_8_8_REV_APPLE;
#else
      m_pixBlock.image.type = GL_UNSIGNED_SHORT_8_8_APPLE;
#endif

      m_pixBlock.image.reallocate();

      m_rowBytes = m_vidXSize*2;
      anErr = QTNewGWorldFromPtr (&m_srcGWorld,
                                  //  k422YpCbCr8CodecType,

                                  k422YpCbCr8PixelFormat,
                                  // '2vuy',
                                  // kComponentVideoUnsigned,
                                  &m_srcRect,
                                  NULL,
                                  NULL,
                                  0,
                                  m_pixBlock.image.data,
                                  m_rowBytes);
      post ("using YUV");
    }

    if (anErr!= noErr)
      {
      error("%d error at QTNewGWorldFromPtr", anErr);
      return;
    }
    if (NULL == m_srcGWorld)
      {
        error("could not allocate off screen");
        return;
      }
    SGSetGWorld(m_sg,(CGrafPtr)m_srcGWorld, NULL);
    SGStartPreview(m_sg); //moved to starttransfer?
    m_haveVideo = 1;
}
Exemplo n.º 10
0
// ######################################################################
QuickTimeGrabber::Impl::Impl(const Dims& dims)
  :
  itsSeqGrab(0, &CloseComponent),
  itsSGChanVideo(&itsSeqGrab.it),
  itsDrawSeq(0),
  itsTimeScale(0),
  itsTimeBase(0),
  itsQueuedFrameCount(0),
  itsSkipFrameCount(0),
  itsSkipFrameCountTotal(0),
  itsPrevTime(0),
  itsFrameCount(0),
  itsGWorld(0),
  itsGotFrame(false),
  itsCurrentImage(),
  itsErrorMsg(),
  itsStreamStarted(false)
{
  OSErr err;

  EnterMovies();

  // open the default sequence grabber
  itsSeqGrab.it = OpenDefaultComponent(SeqGrabComponentType, 0);
  if (itsSeqGrab.it == NULL)
    LFATAL("OpenDefaultComponent() failed");

  // initialize the default sequence grabber component
  if (noErr != (err = SGInitialize(itsSeqGrab.it)))
    LFATAL("SGInitialize() failed (err=%ld)", (long) err);

  Rect scaleRect;
  MacSetRect(&scaleRect, 0, 0, dims.w(), dims.h());
  ASSERT(itsGWorld == 0);
  QTNewGWorld(&itsGWorld,
              k32ARGBPixelFormat, &scaleRect,
              NULL, NULL,
              kNativeEndianPixMap);

  // set its graphics world
  if (noErr != (err = SGSetGWorld(itsSeqGrab.it, itsGWorld, NULL)))
    LFATAL("SGSetGWorld() failed (err=%ld)", (long) err);

  // specify the destination data reference for a record operation
  // tell it we're not making a movie if the flag seqGrabDontMakeMovie
  // is used, the sequence grabber still calls your data function, but
  // does not write any data to the movie file writeType will always
  // be set to seqGrabWriteAppend
  if (noErr !=
      (err = SGSetDataRef(itsSeqGrab.it, 0, 0,
                          seqGrabDontMakeMovie | seqGrabDataProcIsInterruptSafe)))
    LFATAL("SGSetDataRef() failed (err=%ld)", (long) err);

  Impl::SGChannelHolder sgchanSound(&itsSeqGrab.it);

  if (noErr != (err = SGNewChannel(itsSeqGrab.it,
                                   VideoMediaType, &itsSGChanVideo.it)))
    LFATAL("SGNewChannel(video) failed (err=%ld)", (long) err);

  if (noErr != (err = SGNewChannel(itsSeqGrab.it,
                                   SoundMediaType, &sgchanSound.it)))
    {
      // don't care if we couldn't get a sound channel
      sgchanSound.it = NULL;
      LERROR("SGNewChannel(audio) failed (err=%ld)", (long) err);
    }

  // get the active rectangle
  Rect srcBounds;
  if (noErr != (err = SGGetSrcVideoBounds(itsSGChanVideo.it, &srcBounds)))
    LFATAL("SGGetSrcVideoBounds() failed (err=%ld)", (long) err);

  // we always want all the source
  setVideoChannelBounds(itsSGChanVideo.it, &srcBounds, &srcBounds);

  // set usage for new video channel to avoid playthrough
  // note we don't set seqGrabPlayDuringRecord
  if (noErr != (err = SGSetChannelUsage(itsSGChanVideo.it,
                                        seqGrabRecord |
                                        seqGrabLowLatencyCapture |
                                        seqGrabAlwaysUseTimeBase)))
    LFATAL("SGSetChannelUsage(video) failed (err=%ld)", (long) err);

  if (noErr != (err = SGSetChannelUsage(sgchanSound.it, seqGrabRecord |
                                        //seqGrabPlayDuringRecord |
                                        seqGrabLowLatencyCapture |
                                        seqGrabAlwaysUseTimeBase)))
    LERROR("SGSetChannelUsage(audio) failed (err=%ld)", (long) err);

  // specify a sequence grabber data function
  if (noErr != (err = SGSetDataProc(itsSeqGrab.it,
                                    NewSGDataUPP(Impl::grabDataProc),
                                    (long)(this))))
    LFATAL("SGSetDataProc() failed (err=%ld)", (long) err);

  SGSetChannelRefCon(itsSGChanVideo.it, (long)(this));

  // set up the video bottlenecks so we can get our queued frame count
  VideoBottles vb = { 0 };
  if (noErr != (err = SGGetVideoBottlenecks(itsSGChanVideo.it, &vb)))
    LFATAL("SGGetVideoBottlenecks() failed (err=%ld)", (long) err);

  vb.procCount = 9; // there are 9 bottleneck procs; this must be filled in
  vb.grabCompressCompleteProc =
    NewSGGrabCompressCompleteBottleUPP
    (Impl::grabCompressCompleteBottle);

  if (noErr != (err = SGSetVideoBottlenecks(itsSGChanVideo.it, &vb)))
    LFATAL("SGSetVideoBottlenecks() failed (err=%ld)", (long) err);

  SGSetFrameRate(itsSGChanVideo.it, FixRatio(30, 1));
}
Exemplo n.º 11
0
static int sequence_grabber_start(V4lState *s)
{
  int err;
  Rect        theRect = {0, 0, s->vsize.height, s->vsize.width};

  err = QTNewGWorld(&(s->pgworld),  // returned GWorld
		    k24BGRPixelFormat,
		    &theRect,      // bounding rectangle
		    0,             // color table
		    NULL,          // graphic device handle
		    0);            // flags
  if (err!=noErr)
    {
      return -1;
    }

  if(!LockPixels(GetPortPixMap(s->pgworld)))
    {
      v4m_close(s);
      return -1;
    }

  s->seqgrab = OpenDefaultComponent(SeqGrabComponentType, 0);
  err = SGInitialize(s->seqgrab);
  if (err!=noErr)
    {
      v4m_close(s);
      return -1;
    }
  err = SGSetDataRef(s->seqgrab, 0, 0, seqGrabDontMakeMovie);
  if (err!=noErr)
    {
      v4m_close(s);
      return -1;
    }

  err = SGSetGWorld(s->seqgrab, s->pgworld, GetMainDevice());
  if (err!=noErr)
    {
      v4m_close(s);
      return -1;
    }

  err = SGNewChannel(s->seqgrab, VideoMediaType, &s->sgchanvideo);
  if (err!=noErr)
    {
      v4m_close(s);
      return -1;
    }

  err = SGSetChannelBounds(s->sgchanvideo, &theRect);
  if (err!=noErr)
    {
      v4m_close(s);
      return -1;
    }

  err = SGSetChannelUsage(s->sgchanvideo, seqGrabRecord);
  if (err!=noErr)
    {
      v4m_close(s);
      return -1;
    }

  err = SGSetDataProc(s->seqgrab,NewSGDataUPP(sgdata_callback),(long)s);
  if (err!=noErr)
    {
      v4m_close(s);
      return -1;
    }

  err = SGStartRecord(s->seqgrab);
  if (err!=noErr)
    {
      v4m_close(s);
      return -1;
    }

  return 0;
}