Exemplo n.º 1
0
int __stdcall QuickTimeComponentVersion(char *type, char *subtype) {
    OSType real_type, real_subtype;
    ComponentInstance ci;
    long version;

    // If we don't have QuickTime, we can't have any components, either.
    if (QuickTimeVersion() == 0)
        return 0;

    // If our type or subtype is invalid, return 0.
    if (strlen(type) != 4 || strlen(subtype) != 4)
        return 0;

    // Convert our type strings to Macintosh OSType codes.
    real_type = (type[0] << 24 | type[1] << 16 | type[2] << 8 | type[3]);
    real_subtype =
        (subtype[0] << 24 | subtype[1] << 16 | subtype[2] << 8 | subtype[3]);

    // Open up an instance of our component.
    ci = OpenDefaultComponent(real_type, real_subtype);
    if (!ci)
        return 0;

    // Get the version of our component.
    version = GetComponentVersion(ci);
    if (GetComponentInstanceError(ci) != noErr)
        return 0;

    // Close our component instance.
    if (CloseComponent(ci) != noErr)
        return 0;
    
    return version;
}
Exemplo n.º 2
0
static boolean getcompiledscript (OSAID *scriptid, ComponentInstance *scriptcomp, bigstring errormessage) {
	
	/*
	the original version saves as much as possible from call to 
	call, using statics. not safe to multi-process card running.
	
	dmb 1.0b23: when we're running in Frontier, this can be called in any of our 
	client contexts. findlangcomponent already handle this, but we 
	need to make sure the we don't try to share the same script ID 
	between the component instances we have open in each client 
	process. We could maintain some kind of list, but now that we 
	make this call less often (we only SetRuntimeCard for major
	switches), it's fine to simple recompile the script each time. so 
	we don't use statics except for the script source resource.
	*/
	
	static Handle hcompiledscript = nil;
	#ifdef isFrontier
		boolean flinitialized = false;
		ComponentInstance comp = 0;
		OSAID id = 0;
	#else
		static boolean flinitialized = false;
		static ComponentInstance comp = 0;
		static OSAID id = 0;
	#endif
	
	if (flinitialized) { /*dmb 6.19.96: make sure the component is still around*/
		
		if (GetComponentVersion (comp) == badComponentInstance) { /*no longer valid*/
			
			comp = 0;
			
			id = 0;
			
			flinitialized = false;
			}
		}
	
	if (!flinitialized) { /*first time we're called, load the script from resource fork*/
		
		if (hcompiledscript == nil) {
		
			hcompiledscript = GetResource ('scpt', idscriptresource);
		
			if (hcompiledscript == nil) {
			
				copystring ("\pThere's no 'scpt' 128 resource available", errormessage);
			
				return (false);
				}
			}
Exemplo n.º 3
0
static PyObject *CmpInstObj_GetComponentVersion(ComponentInstanceObject *_self, PyObject *_args)
{
	PyObject *_res = NULL;
	long _rv;
#ifndef GetComponentVersion
	PyMac_PRECHECK(GetComponentVersion);
#endif
	if (!PyArg_ParseTuple(_args, ""))
		return NULL;
	_rv = GetComponentVersion(_self->ob_itself);
	_res = Py_BuildValue("l",
	                     _rv);
	return _res;
}
Exemplo n.º 4
0
void finalizeAtom(_TCHAR *path, int bitrate, int mode, int modeQuality, int samplerate, SInt64 frame, AudioStreamBasicDescription *asbd, mp4Metadata_t *metadata)
{
    unsigned int tmp;
    char atom[4];
    int udtaSize = 0;
    int bufferSize = 1024*1024;
    char *tmpbuf = (char *)malloc(bufferSize);
    char *tmpbuf2 = (char *)malloc(bufferSize);
    char *read = tmpbuf;
    char *write = tmpbuf2;
    char *swap;
    FILE *fp;
    unsigned char *udta = NULL;
    WIN32_FILE_ATTRIBUTE_DATA fi;

    GetFileAttributesEx(path,GetFileExInfoStandard,&fi);
    __int64 origSize = ((unsigned __int64)fi.nFileSizeHigh << 32)|fi.nFileSizeLow;

    if(_tfopen_s(&fp, path, _T("r+b"))) return;

    int actualFreq = getM4aFrequency(fp);
    if(actualFreq && (actualFreq != samplerate)) frame = (int)floor(0.5+(double)frame*actualFreq/samplerate);
    int padding = (int)((SInt64)ceil((frame + 2112)/1024.0)*1024 - (frame + 2112));

    ComponentDescription cd;
    cd.componentType = 'aenc';
    cd.componentSubType = asbd->mFormatID;
    cd.componentManufacturer = kAppleManufacturer;
    cd.componentFlags = 0;
    cd.componentFlagsMask = 0;
    int version = GetComponentVersion((ComponentInstance)FindNextComponent(NULL, &cd));

    if(!bitrate) {
        while(1) { //skip until mdat;
            if(fread(&tmp,4,1,fp) < 1) goto end;
            if(fread(atom,1,4,fp) < 4) goto end;
            tmp = SWAP32(tmp);
            if(!memcmp(atom,"mdat",4)) break;
            if(fseeko(fp,tmp-8,SEEK_CUR) != 0) goto end;
        }
        bitrate = (int)ceil(0.5+(tmp-8)/((double)frame/actualFreq)*8) ;
        rewind(fp);
    }

    udta = setupUdta(metadata,bitrate,mode,modeQuality,padding,frame,version,&udtaSize);
    int i;

    while(1) { //skip until moov;
        if(fread(&tmp,4,1,fp) < 1) goto end;
        if(fread(atom,1,4,fp) < 4) goto end;
        tmp = SWAP32(tmp);
        if(!memcmp(atom,"moov",4)) break;
        if(fseeko(fp,tmp-8,SEEK_CUR) != 0) goto end;
    }

    if(fseeko(fp,-8,SEEK_CUR) != 0) goto end;

    /* update moov atom size */
    __int64 pos_moov = ftello(fp);
    if(fread(&tmp,4,1,fp) < 1) goto end;
    int moovSize = SWAP32(tmp);
    if(fseeko(fp,-4,SEEK_CUR) != 0) goto end;
    tmp = SWAP32(moovSize + udtaSize);
    if(fwrite(&tmp,4,1,fp) < 1) goto end;

    if(fseeko(fp,4,SEEK_CUR) != 0) goto end;

    while(1) { //skip until trak;
        if(fread(&tmp,4,1,fp) < 1) goto end;
        if(fread(atom,1,4,fp) < 4) goto end;
        tmp = SWAP32(tmp);
        if(!memcmp(atom,"trak",4)) break;
        if(fseeko(fp,tmp-8,SEEK_CUR) != 0) goto end;
    }

    while(1) { //skip until mdia;
        if(fread(&tmp,4,1,fp) < 1) goto end;
        if(fread(atom,1,4,fp) < 4) goto end;
        tmp = SWAP32(tmp);
        if(!memcmp(atom,"mdia",4)) break;
        if(fseeko(fp,tmp-8,SEEK_CUR) != 0) goto end;
    }

    while(1) { //skip until minf;
        if(fread(&tmp,4,1,fp) < 1) goto end;
        if(fread(atom,1,4,fp) < 4) goto end;
        tmp = SWAP32(tmp);
        if(!memcmp(atom,"minf",4)) break;
        if(fseeko(fp,tmp-8,SEEK_CUR) != 0) goto end;
    }

    while(1) { //skip until stbl;
        if(fread(&tmp,4,1,fp) < 1) goto end;
        if(fread(atom,1,4,fp) < 4) goto end;
        tmp = SWAP32(tmp);
        if(!memcmp(atom,"stbl",4)) break;
        if(fseeko(fp,tmp-8,SEEK_CUR) != 0) goto end;
    }

    __int64 nextAtom = ftello(fp);

    while(1) { //skip until stsz;
        if(fread(&tmp,4,1,fp) < 1) goto end;
        if(fread(atom,1,4,fp) < 4) goto end;
        tmp = SWAP32(tmp);
        if(!memcmp(atom,"stsz",4)) break;
        if(fseeko(fp,tmp-8,SEEK_CUR) != 0) goto end;
    }

    if(fseeko(fp,4,SEEK_CUR) != 0) goto end;

    /* estimate maximum bitrate */
    int maxBitrate = 0;
    if(fread(&tmp,4,1,fp) < 1) goto end;
    tmp = SWAP32(tmp);
    if(tmp) maxBitrate = tmp * 8 * actualFreq / 1024;
    else {
        if(fread(&tmp,4,1,fp) < 1) goto end;
        int frameNum = SWAP32(tmp);
        int frameSize;
        int sample;
        for(i=0,sample=0,frameSize=0; i<frameNum; i++) {
            if(fread(&tmp,4,1,fp) < 1) goto end;
            tmp = SWAP32(tmp);
            if(sample + 1024 >= actualFreq) {
                frameSize += (int)((actualFreq - sample)/1024.0 * tmp);
                if(frameSize*8 > maxBitrate) maxBitrate = frameSize*8;
                sample = 1024 - (actualFreq - sample);
                frameSize = (int)(sample/1024.0 * tmp);
                continue;
            }
            frameSize += tmp;
            sample += 1024;
        }
    }

    if(fseeko(fp,nextAtom,SEEK_SET) != 0) goto end;

    /* write bitrate info */
    while(1) { //skip until esds;
        if(fread(atom,1,4,fp) < 4) goto end;
        if(!memcmp(atom,"esds",4)) break;
        if(fseeko(fp,-3,SEEK_CUR) != 0) goto end;
    }

    if(fseeko(fp,5,SEEK_CUR) != 0) goto end;
    for(i=0; i<3; i++) {
        if(fread(atom,1,1,fp) < 1) goto end;
        if((unsigned char)atom[0] != 0x80) {
            if(fseeko(fp,-1,SEEK_CUR) != 0) goto end;
            break;
        }
    }
    if(fseeko(fp,5,SEEK_CUR) != 0) goto end;
    for(i=0; i<3; i++) {
        if(fread(atom,1,1,fp) < 1) goto end;
        if((unsigned char)atom[0] != 0x80) {
            if(fseeko(fp,-1,SEEK_CUR) != 0) goto end;
            break;
        }
    }
    if(fseeko(fp,6,SEEK_CUR) != 0) goto end;
    tmp = SWAP32(maxBitrate);
    if(fwrite(&tmp,4,1,fp) < 1) goto end;
    tmp = SWAP32(bitrate);
    if(fwrite(&tmp,4,1,fp) < 1) goto end;

    if(fseeko(fp,nextAtom,SEEK_SET) != 0) goto end;

    while(1) { //skip until stco;
        if(fread(&tmp,4,1,fp) < 1) goto end;
        if(fread(atom,1,4,fp) < 4) goto end;
        tmp = SWAP32(tmp);
        if(!memcmp(atom,"stco",4)) break;
        if(fseeko(fp,tmp-8,SEEK_CUR) != 0) goto end;
    }

    int *stco = (int *)malloc(tmp-8);
    if(fread(stco,1,tmp-8,fp) < tmp-8) goto end;
    int nElement = SWAP32(stco[1]);

    /* update stco atom */

    for(i=0; i<nElement; i++) {
        stco[2+i] = SWAP32(SWAP32(stco[2+i])+udtaSize);
    }
    if(fseeko(fp,8-(int)tmp,SEEK_CUR) != 0) goto end;
    if(fwrite(stco,1,tmp-8,fp) < tmp-8) goto end;

    free(stco);

    /* write tags */
    if(fseeko(fp,pos_moov,SEEK_SET) != 0) goto end;
    if(fseeko(fp,moovSize,SEEK_CUR) != 0) goto end;

    __int64 pos_tag = ftello(fp);
    __int64 bytesToMove = origSize-pos_tag;

    if(bytesToMove < udtaSize) {
        if(bufferSize < udtaSize) {
            tmpbuf = (char *)realloc(tmpbuf,udtaSize);
            read = tmpbuf;
        }
        if((int)fread(read,1,(size_t)bytesToMove,fp) < bytesToMove) goto end;
        if(fseeko(fp,0,SEEK_END) != 0) goto end;
        if((int)fwrite(read,1,(size_t)(udtaSize-bytesToMove),fp) < (udtaSize-bytesToMove)) goto end;
        if((int)fwrite(read,1,(size_t)bytesToMove,fp) < bytesToMove) goto end;
    }
    else if(bytesToMove > bufferSize) {
        if(bufferSize < udtaSize) {
            tmpbuf = (char *)realloc(tmpbuf,udtaSize);
            tmpbuf2 = (char *)realloc(tmpbuf2,udtaSize);
            read = tmpbuf;
            write = tmpbuf2;
            bufferSize = udtaSize;
            if(bytesToMove <= bufferSize) goto moveBlock_is_smaller_than_buffer;
        }
        if((int)fread(write,1,bufferSize,fp) < bufferSize) goto end;
        bytesToMove -= bufferSize;
        while(bytesToMove > bufferSize) {
            if((int)fread(read,1,bufferSize,fp) < bufferSize) goto end;
            if(fseeko(fp,udtaSize-2*bufferSize,SEEK_CUR) != 0) goto end;
            if((int)fwrite(write,1,bufferSize,fp) < bufferSize) goto end;
            if(fseeko(fp,bufferSize-udtaSize,SEEK_CUR) != 0) goto end;
            swap = read;
            read = write;
            write = swap;
            bytesToMove -= bufferSize;
        }
        if((int)fread(read,1,(size_t)bytesToMove,fp) < bytesToMove) goto end;
        if(fseeko(fp,udtaSize-bufferSize-bytesToMove,SEEK_CUR) != 0) goto end;
        if((int)fwrite(write,1,bufferSize,fp) < bufferSize) goto end;
        if((int)fwrite(read,1,(size_t)bytesToMove,fp) < bytesToMove) goto end;
    }
    else {
moveBlock_is_smaller_than_buffer:
        if((int)fread(read,1,(size_t)bytesToMove,fp) < bytesToMove) goto end;
        if(udtaSize < bytesToMove) {
            if(fseeko(fp,udtaSize-bytesToMove,SEEK_CUR) != 0) goto end;
        }
        else {
            if(fseeko(fp,0-bytesToMove,SEEK_CUR) != 0) goto end;
            if((int)fwrite(udta,1,udtaSize,fp) < udtaSize) goto end;
        }
        if((int)fwrite(read,1,(size_t)bytesToMove,fp) < bytesToMove) goto end;
    }

    if(fseeko(fp,pos_tag,SEEK_SET) != 0) goto end;

    if((int)fwrite(udta,1,udtaSize,fp) < udtaSize) goto end;

end:
    fclose(fp);
    if(udta) free(udta);
    free(tmpbuf);
    free(tmpbuf2);
}