Handle createPointerDataRefWithExtensions( void *data, size_t dataSize, const string &fileName, const string &mimeType )
{
	OSStatus err = noErr;
	Handle dataRef = NULL;
	ComponentInstance dataRefHandler = NULL;

	// First create a data reference handle for our data
	dataRef = createPointerReferenceHandle( data, dataSize );
	if( ! dataRef )
		goto bail;

	//  Get a data handler for our data reference
	err = OpenADataHandler(
			dataRef,                    /* data reference */
			PointerDataHandlerSubType,  /* data ref. type */
			NULL,                       /* anchor data ref. */
			(OSType)0,                  /* anchor data ref. type */
			NULL,                       /* time base for data handler */
			kDataHCanRead,              /* flag for data handler usage */
			&dataRefHandler);           /* returns the data handler */
	if( err ) goto bail;

	// We can add the filename to the data ref to help
	// importer finding process. Find uses the extension.
	// If we add a filetype or mimetype we must add a
	// filename -- even if it is an empty string
	if( ( ! fileName.empty() ) || ( ! mimeType.empty() ) ) {
		err = ptrDataRefAddFileNameExtension( dataRefHandler, fileName );
		if( err ) goto bail;
	}

	// to add MIME type information, add a classic atom followed by
	// a Pascal string holding the MIME type
	if ( ! mimeType.empty() ) {
		err = ptrDataRefAddMIMETypeExtension( dataRefHandler, mimeType );
		if( err ) goto bail;
	}

	// dispose old data ref handle because it does not contain our new changes
	::DisposeHandle( dataRef );
	dataRef = NULL;

	// re-acquire data reference from the data handler to get the new changes
	err = ::DataHGetDataRef( dataRefHandler, &dataRef );
	if( err ) goto bail;

	::CloseComponent( dataRefHandler );

	return dataRef;
 bail:
    if( dataRefHandler ) {
		::CloseComponent(dataRefHandler);
    }

    if( dataRef ) {         // make sure and dispose the data reference handle once we are done with it
        ::DisposeHandle( dataRef );
    }

    return NULL;
}
Exemple #2
0
ComponentResult FFAvi_MovieImportValidateDataRef(ff_global_ptr storage, Handle dataRef, OSType dataRefType, UInt8 *valid)
{
	ComponentResult result = noErr;
	DataHandler dataHandler = NULL;
	uint8_t buf[PROBE_BUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE] = {0};
	AVProbeData pd;
	ByteIOContext *byteContext;

	/* default */
	*valid = 0;
	
	/* Get a data handle and read a probe of data */
	result = OpenADataHandler(dataRef, dataRefType, NULL, 0, NULL, kDataHCanRead, &dataHandler);
	if(result || !dataHandler) goto bail;
	
	pd.buf = buf;
	pd.buf_size = PROBE_BUF_SIZE;
	
	result = DataHScheduleData(dataHandler, (Ptr)pd.buf, 0, PROBE_BUF_SIZE, 0, NULL, NULL);
	require_noerr(result,bail);
	
	FFInitFFmpeg();
	storage->format = av_probe_input_format(&pd, 1);
	if(storage->format != NULL) {
		*valid = 255; /* This means we can read the data */
		
		/* we don't do MJPEG's Huffman tables right yet, and DV video seems to have 
		an aspect ratio coded in the bitstream that ffmpeg doesn't read, so let Apple's 
		AVI importer handle AVIs with these two video types */
		if (IS_AVI(storage->componentType)) {
			/* Prepare the iocontext structure */
			result = url_open_dataref(&byteContext, dataRef, dataRefType, NULL, NULL, NULL);
			require_noerr(result, bail);
			
			OSType fourcc = get_avi_strf_fourcc(byteContext);
			enum CodecID id = ff_codec_get_id(ff_codec_bmp_tags, BSWAP(fourcc));
			
			if (id == CODEC_ID_MJPEG || id == CODEC_ID_DVVIDEO || id == CODEC_ID_RAWVIDEO || id == CODEC_ID_MSVIDEO1 || id == CODEC_ID_MSRLE)
				*valid = 0;
			
			url_fclose(byteContext);
		}
	}
		
bail:
		if(dataHandler)
			CloseComponent(dataHandler);
	
	return result;
} /* FFAvi_MovieImportValidateDataRef() */
Exemple #3
0
Handle getPtrDataRef(unsigned char *data, unsigned int size, const std::string &filename)
{
     // Load Data Reference
     Handle dataRef;
     Handle fileNameHandle;
     PointerDataRefRecord ptrDataRefRec;
     ComponentInstance dataRefHandler;
     unsigned char pstr[255];
 
     ptrDataRefRec.data = data;
     ptrDataRefRec.dataLength = size;
 
     /*err = */PtrToHand(&ptrDataRefRec, &dataRef, sizeof(PointerDataRefRecord));
 
     // Open a Data Handler for the Data Reference
     /*err = */OpenADataHandler(dataRef, PointerDataHandlerSubType, NULL,
         (OSType)0, NULL, kDataHCanRead, &dataRefHandler);
 
     // Convert From CString in filename to a PascalString in pstr
     if (filename.length() > 255) {
         //hmm...not good, pascal string limit is 255!
         //do some error handling maybe?!
         throw QTImportExportException(0, "filename length limit exceeded");
     }
     CopyCStringToPascal(filename.c_str(), pstr);
 
    // Add filename extension
     /*err = */PtrToHand(pstr, &fileNameHandle, filename.length() + 1);
     /*err = */DataHSetDataRefExtension(dataRefHandler, fileNameHandle,
         kDataRefExtensionFileName);
     DisposeHandle(fileNameHandle);
 
     // Release old handler which does not have the extensions
     DisposeHandle(dataRef);
 
     // Grab the SAFE_NEW version of the data ref from the data handler
     /*err = */ DataHGetDataRef(dataRefHandler, &dataRef);
     
     CloseComponent(dataRefHandler);
     
     return dataRef;
}