示例#1
0
int PortBurn_GetSpeeds(void *handle, int *cnt, int *speeds[])
{
   PBHandle *h = (PBHandle *)handle;
   CFDictionaryRef deviceStatus;
   CFDictionaryRef mediaInfo;
   CFStringRef mediaState;

   if (h == NULL) {
      return pbErrNoHandle;
   }

   if (h->device == NULL) {
      return pbErrDeviceNotOpen;
   }

   /* First we check to see that we have blank media in the drive. */
   deviceStatus = DRDeviceCopyStatus(h->device);
   if (deviceStatus == NULL) {
      return pbErrCannotAccessDevice;
   }

   mediaState = (CFStringRef) CFDictionaryGetValue(deviceStatus,
                                                   kDRDeviceMediaStateKey);
   if (mediaState == NULL) {
      CFRelease(deviceStatus);
      return pbErrCannotAccessDevice;
   }

   if (!CFEqual(mediaState, kDRDeviceMediaStateMediaPresent)) {
      CFRelease(deviceStatus);
      return pbErrNoMediaInDrive;
   }

   mediaInfo = (CFDictionaryRef) CFDictionaryGetValue(deviceStatus,
                                                      kDRDeviceMediaInfoKey);

   CFArrayRef sarray = (CFArrayRef)
      CFDictionaryGetValue(mediaInfo, kDRDeviceBurnSpeedsKey);

   if (sarray != NULL && CFArrayGetCount(sarray) != 0) {
      CFIndex ndx;
      *cnt = CFArrayGetCount(sarray);
      *speeds = (int *) malloc((*cnt + 1) * sizeof(int));
      for (ndx = 0; ndx < *cnt; ndx++) {
         float speed;

         CFNumberRef num = (CFNumberRef)
            CFArrayGetValueAtIndex(sarray, ndx);

         if (num != NULL) {
            CFNumberGetValue(num, kCFNumberFloatType, &speed);
            *speeds[ndx] = lrint(speed / kDRDeviceBurnSpeedCD1x);
         }
      }
   }
   CFRelease(deviceStatus);

   return pbSuccess;
}
示例#2
0
/*
	druDeviceIsBecomingReady
	
	Returns TRUE if the device is becoming ready (eg, spinning up).
*/
int
druDeviceIsBecomingReady(DRDeviceRef device)
{
	CFDictionaryRef		deviceStatus = DRDeviceCopyStatus(device);
	CFStringRef			mediaState = CFDictionaryGetValue(deviceStatus,kDRDeviceMediaStateKey);
	int					result;
	
	result = (mediaState != NULL && CFEqual(mediaState,kDRDeviceMediaStateInTransition)) ? 1:0;
	
	CFRelease(deviceStatus);
	return result;
}
示例#3
0
/*
	druMediaIsReserved
	
	Returns TRUE if the device contains blank media.
*/
int
druMediaIsReserved(DRDeviceRef device)
{
	CFDictionaryRef		deviceStatus = DRDeviceCopyStatus(device);
	CFStringRef			mediaState = CFDictionaryGetValue(deviceStatus,kDRDeviceMediaStateKey);
	int					result = 0;
	
	/* Check to see if there's media in the device */
	if (mediaState != NULL && CFEqual(mediaState,kDRDeviceMediaStateMediaPresent))
	{
		CFDictionaryRef	mediaInfo = CFDictionaryGetValue(deviceStatus,kDRDeviceMediaInfoKey);
		CFBooleanRef	reserved = CFDictionaryGetValue(mediaInfo,kDRDeviceMediaIsReservedKey);
		
		/* There's media, but do we have the reservation? */
		if (reserved != NULL && CFBooleanGetValue(reserved))
			result = 1;
	}
	
	CFRelease(deviceStatus);
	return result;
}
示例#4
0
/*
	druDeviceContainsErasableMedia
	
	Returns TRUE if the device contains blank media.
*/
int
druDeviceContainsErasableMedia(DRDeviceRef device)
{
	CFDictionaryRef		deviceStatus = DRDeviceCopyStatus(device);
	CFStringRef			mediaState = CFDictionaryGetValue(deviceStatus,kDRDeviceMediaStateKey);
	int					result = 0;
	
	/* Check to see if there's media in the device */
	if (mediaState != NULL && CFEqual(mediaState,kDRDeviceMediaStateMediaPresent))
	{
		CFDictionaryRef	mediaInfo = CFDictionaryGetValue(deviceStatus,kDRDeviceMediaInfoKey);
		CFBooleanRef	erasable = CFDictionaryGetValue(mediaInfo,kDRDeviceMediaIsErasableKey);
		
		/* There's media, but is it blank and writable? */
		if (erasable != NULL && CFBooleanGetValue(erasable))
			result = 1;
	}
	
	CFRelease(deviceStatus);
	return result;
}
示例#5
0
/* This indicates you're ready to start staging audio data for the
   currently opened device.  At this point you are committing to
   exclusive access to the CD burner, and this is the function that
   will fail if another program is using the device, or if there is
   no writable CD media in the device at this point.
   You should pass in the path to a temporary directory that has at
   least 700 MB of free space, to stage the audio, although note that
   not all implementations will make use of this directory. */
int PortBurn_StartStaging(void *handle, const char *tmpdir)

{
   PBHandle *h = (PBHandle *)handle;
   CFDictionaryRef deviceStatus;
   CFStringRef mediaState;
   CFDictionaryRef mediaInfo;
   CFBooleanRef	blank;
   CFBooleanRef	writable;
   CFBooleanRef	reserved;

   if (!h)
      return pbErrNoHandle;

   if (!h->device)
      return pbErrDeviceNotOpen;

   if (h->staging)
      return pbErrAlreadyStagingOrBurning;

   /* First we check to see that we have blank media in the drive. */
   deviceStatus = DRDeviceCopyStatus(h->device);
   mediaState = (CFStringRef)CFDictionaryGetValue(deviceStatus,
                                                  kDRDeviceMediaStateKey);
   if (mediaState == NULL) {
      CFRelease(deviceStatus);
      return pbErrCannotAccessDevice;
   }

   if (!CFEqual(mediaState, kDRDeviceMediaStateMediaPresent)) {
      CFRelease(deviceStatus);
      return pbErrNoMediaInDrive;
   }

   mediaInfo = (CFDictionaryRef)CFDictionaryGetValue(deviceStatus,
                                                     kDRDeviceMediaInfoKey);
   blank = (CFBooleanRef)CFDictionaryGetValue(mediaInfo,
                                              kDRDeviceMediaIsBlankKey);

   if (blank == NULL || !CFBooleanGetValue(blank)) {
      CFRelease(deviceStatus);
      return pbErrMediaIsNotBlankAndWritable;
   }

   writable = (CFBooleanRef)CFDictionaryGetValue(mediaInfo,
                                                kDRDeviceMediaIsAppendableKey);

   if (writable == NULL || !CFBooleanGetValue(writable)) {
      CFRelease(deviceStatus);
      return pbErrMediaIsNotBlankAndWritable;
   }

   reserved = (CFBooleanRef)CFDictionaryGetValue(mediaInfo,
                                                 kDRDeviceMediaIsReservedKey);
   if (reserved == NULL || !CFBooleanGetValue(reserved)) {
      CFRelease(deviceStatus);
      return pbErrCannotReserveDevice;
   }
	
   CFRelease(deviceStatus);

   h->staging = PortBurn_TempDirStaging(tmpdir);

   if (!h->staging) {
      return pbErrCannotCreateStagingDirectory;
   }

   h->trackArray = CFArrayCreateMutable(kCFAllocatorDefault, 0,
                                        &kCFTypeArrayCallBacks);

   return pbSuccess;
}
示例#6
0
int PortBurn_GetMediaState(void *handle, int *state)
{
   PBHandle *h = (PBHandle *)handle;
   CFDictionaryRef deviceStatus;
   CFStringRef mediaState;
   CFDictionaryRef mediaInfo;
   CFBooleanRef	bref;
   int mstate = pbMediaNotWritable;

   if (h == NULL) {
      return pbErrNoHandle;
   }

   if (h->device == NULL) {
      return pbErrDeviceNotOpen;
   }

   /* First we check to see that we have blank media in the drive. */
   deviceStatus = DRDeviceCopyStatus(h->device);
   if (deviceStatus == NULL) {
      return pbErrCannotAccessDevice;
   }

   mediaState = (CFStringRef) CFDictionaryGetValue(deviceStatus,
                                                   kDRDeviceMediaStateKey);
   if (mediaState == NULL) {
      CFRelease(deviceStatus);
      return pbErrCannotAccessDevice;
   }

   if (!CFEqual(mediaState, kDRDeviceMediaStateMediaPresent)) {
      CFRelease(deviceStatus);
      *state = pbMediaNone;
      return pbSuccess;
   }

   mediaInfo = (CFDictionaryRef) CFDictionaryGetValue(deviceStatus,
                                                      kDRDeviceMediaInfoKey);
   bref = (CFBooleanRef) CFDictionaryGetValue(mediaInfo,
                                              kDRDeviceMediaIsBlankKey);

   if (bref != NULL && CFBooleanGetValue(bref)) {
      mstate |= pbMediaBlank;
   }

   bref = (CFBooleanRef) CFDictionaryGetValue(mediaInfo,
                                              kDRDeviceMediaIsErasableKey);

   if (bref != NULL && CFBooleanGetValue(bref)) {
      mstate |= pbMediaErasable;
   }

   bref = (CFBooleanRef) CFDictionaryGetValue(mediaInfo,
                                              kDRDeviceMediaIsAppendableKey);

   if (bref != NULL && CFBooleanGetValue(bref)) {
      mstate |= pbMediaAppendable;
   }

   bref = (CFBooleanRef) CFDictionaryGetValue(mediaInfo,
                                              kDRDeviceMediaIsOverwritableKey);

   if (bref != NULL && CFBooleanGetValue(bref)) {
      mstate |= pbMediaOverwritable;
   }

   CFRelease(deviceStatus);

   *state = mstate;

   return pbSuccess;
}