Esempio n. 1
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);
}
Esempio n. 2
0
// ######################################################################
static void setVideoChannelBounds(SGChannel videoChannel,
                                  const Rect* scaledSourceBounds,
                                  const Rect* scaledVideoBounds)
{
  // Notes: see Q&A 1250

  // calculate the matrix to transform the
  // scaledSourceBounds to the source bounds
  Rect sourceBounds;
  SGGetSrcVideoBounds(videoChannel, &sourceBounds);

  MatrixRecord scaledSourceBoundsToSourceBounds;
  RectMatrix(&scaledSourceBoundsToSourceBounds,
             scaledSourceBounds, &sourceBounds);

  // apply the same transform to the
  // scaledVideoBounds to get the video bounds
  Rect videoBounds = *scaledVideoBounds;
  TransformRect(&scaledSourceBoundsToSourceBounds, &videoBounds, 0);

  if (noErr != SGSetVideoRect(videoChannel, &videoBounds))
    {
      // some video digitizers may only be able to capture full frame
      // and will return qtParamErr or possibly digiUnimpErr if they
      // can't handle working with less than full frame
      SGSetVideoRect(videoChannel, &sourceBounds);
    }

  // the channel bounds is scaledVideoBounds offset to (0, 0)
  Rect channelBounds = *scaledVideoBounds;
  OffsetRect(&channelBounds, -channelBounds.left, -channelBounds.top);

  // Note: SGSetChannelBounds merely allows the client to specify it's
  // preferred bounds. The actual bounds returned by the vDig in the
  // image description may be different
  if (noErr != SGSetChannelBounds(videoChannel, &channelBounds))
    LFATAL("SGSetChannelBounds() failed");
}
Esempio 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);
}
Esempio n. 4
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));
}