Exemple #1
0
/* This callback is called before the burn is to begin. It it we open up the AIFF file to read
   from and make sure it's valid (this could have been done before we started also). We also
   set up the final length of the track */
OSStatus preBurnCallback(DRTrackRef track)
{
	CFDictionaryRef	properties = DRTrackGetProperties(track);
	CFStringRef		fileStr = CFDictionaryGetValue(properties, CFSTR("kTrackSourceFilePath"));
	char			filepath[PATH_MAX];
	AIFFFileInfo*	info = (AIFFFileInfo*)DRGetRefCon(track);

	/* Get the file string from the properties dictionary and get the c string from that 
	   to open the file using open */
	CFStringGetCString(fileStr, filepath, PATH_MAX, kCFStringEncodingUTF8);
	
	info->fd = open(filepath, O_RDONLY, 0);
	if (info->fd == -1) return kDRDataProductionErr;

	fcntl(info->fd, F_NOCACHE, 1);						/* Don't cache the file in the UBC */
	lseek(info->fd, info->dataStart, SEEK_SET);			/* put the file pointer at the start of the sound data */
	info->mask = ((int)-0x10000) >> info->sampleBits;	/* set up the mask to do channel mixing */
	info->cursor = info->dataStart;
	
	return noErr;
}
/* Finish the current audio track. */
int PortBurn_EndTrack(void *handle)
{
   PBHandle *h = (PBHandle *)handle;
   DRAudioTrackRef track;
   Boolean isDirectory;
   const char *filename;
   FSRef fsref;
   int index;

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

   if (h->staging == NULL) {
      return pbErrMustCallStartStaging;
   }

   if (PortBurn_EndStagingTrack(h->staging) != 0) {
      return pbErrCannotStageTrack;
   }

   index = PortBurn_GetNumStagedTracks(h->staging);
   if (index <= 0) {
      return pbErrCannotStageTrack;
   }

   filename = PortBurn_GetStagedFilename(h->staging, index - 1);
   if (filename == NULL) {
      return pbErrCannotAccessStagedFile;
   }

   h->err = FSPathMakeRef((const UInt8*)filename, &fsref, &isDirectory);
   if (h->err != noErr) {
      return pbErrCannotAccessStagedFile;
   }

   if (isDirectory) {
      return pbErrCannotAccessStagedFile;
   }

   track = DRAudioTrackCreate(&fsref);
   if (track == NULL) {
      return pbErrCannotUseStagedFileForBurning;
   }

   if (h->gapless) {
      CFMutableDictionaryRef props;

      props = CFDictionaryCreateMutableCopy(NULL, 0, DRTrackGetProperties(track));
      if (props == NULL) {
         CFRelease(track);
         return pbErrCannotUseStagedFileForBurning;
      }

      SInt64 gap = 0;
      CFNumberRef num = CFNumberCreate(NULL, kCFNumberSInt64Type, &gap);
      if (num != NULL) {
         CFDictionarySetValue(props,
                              kDRPreGapLengthKey,
                              num);
         CFRelease(num);
      }
   
      DRTrackSetProperties(track, props);

      CFRelease(props);
   }

   CFArrayAppendValue(h->trackArray, track);

   CFRelease(track);

   return pbSuccess;
}