示例#1
0
FskErr mp3ReaderTrackGetProfile(void *readerState, void *track, UInt32 propertyID, FskMediaPropertyValue property)
{
	mp3Reader state = readerState;
	int profile = state->mi.profile;
	int level   = state->mi.level;
	const char *profile_str;
	char level_str[16];

	if (kFskAudioFormatAACADTS == state->mi.codec )
	{
			 if( profile == 1 )		profile_str = "AAC Main,";
		else if( profile == 2 )		profile_str = "AAC LC,";
		else if( profile == 3 )		profile_str = "AAC SSR,";
		else if( profile == 4 )		profile_str = "AAC LTP,";
		else if( profile == 5 )		profile_str = "SBR,";
		else if( profile == 6 )		profile_str = "AAC Scalable,";
		else if( profile == 7 )		profile_str = "TwinVQ,";
		else if( profile == 8 )		profile_str = "CELP,";
		else if( profile == 9 )		profile_str = "HXVC,";
		else
			profile_str = "unknown,";
	}
	else
		profile_str = "unknown,";

	FskStrNumToStr( level, level_str, sizeof(level_str));
	property->type = kFskMediaPropertyTypeString;
	property->value.str = FskStrDoCat( profile_str, level_str );

	return kFskErrNone;
}
示例#2
0
 void KprZeroconfDiscoverServerCallback(KprZeroconfBrowser self, KprZeroconfServiceInfo service, Boolean alive)
 {
 #define kKPRZeroconfKinomaDiscoverURL "xkpr://%s/discover"
 #define kKPRZeroconfKinomaDiscoverJSON "{\"id\":\"%s\",\"uuid\":\"%s\",\"url\":\"http://%s:%lu/\",\"protocol\":\"zeroconf\"}"
 #define kKPRZeroconfKinomaForgetURL "xkpr://%s/forget"
 #define kKPRZeroconfKinomaForgetJSON "{\"id\":\"%s\",\"uuid\":\"%s\",\"protocol\":\"zeroconf\"}"
 	FskErr err = kFskErrNone;
 	char id[256];
 	char url[1024];
 	char json[2048];
 	UInt32 size;
 	KprMessage message = NULL;
 	char* authority = NULL;
 	bailIfError(KprZeroconfServiceNewAuthority(service->type, &authority));
	if (alive) {
		snprintf(url, sizeof(url), kKPRZeroconfKinomaDiscoverURL, self->authority);
		snprintf(json, sizeof(json), kKPRZeroconfKinomaDiscoverJSON, authority, service->name, service->ip, service->port);
	}
	else {
		snprintf(url, sizeof(url), kKPRZeroconfKinomaForgetURL, self->authority);
		snprintf(json, sizeof(json), kKPRZeroconfKinomaForgetJSON, authority, service->name);
	}
 	size = FskStrLen(json);
 	bailIfError(KprMessageNew(&message, url));
 	bailIfError(KprMessageSetRequestBody(message, json, size));
 	FskStrNumToStr(size, id, sizeof(id));
 	bailIfError(KprMessageSetRequestHeader(message, kFskStrContentLength, id));
 	bailIfError(KprMessageSetRequestHeader(message, kFskStrContentType, "application/json"));
 	KprMessageInvoke(message, NULL, NULL, NULL);
  	FskMemPtrDispose(authority);
	return;
 bail:
	KprMessageDispose(message);
  	FskMemPtrDispose(authority);
 }
示例#3
0
// ------------------------------------------------------------------------
void FskHeaderAddInteger(char *headerName, SInt32 headerVal, FskHeaders *headers)
{
	char	foo[32];

	FskStrNumToStr(headerVal, foo, sizeof(foo));
	FskAssociativeArrayElementCatenateString(headers->theHeaders, headerName, foo, true);
}
示例#4
0
void fxErrorMessage(txMachine* the, txInteger theCode, txString theBuffer, txSize theSize)
{
    const char *name = FskInstrumentationGetErrorString((FskErr)theCode);
    
    if (name && ('(' != name[0]) && (1 + FskStrLen(name)) < (unsigned long)theSize)
        FskStrCopy(theBuffer, name);
    else
        FskStrNumToStr(theCode, theBuffer, theSize);
}
示例#5
0
// text
void KPR_canvasRenderingContext2D_get_font(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	const struct FskFontAttributes* font = FskCanvas2dGetFont(ctx);
	char buffer[1024] = "";
	if (font->style == kFskFontStyleItalic)
		FskStrCat(buffer, "italic ");
	else if (font->style == kFskFontStyleOblique)
		FskStrCat(buffer, "oblique ");
	if (font->weight == kFskFontWeightBold)
		FskStrCat(buffer, "bold ");
	else if (font->weight != kFskFontWeightNormal) {
		FskStrNumToStr(font->weight, buffer + FskStrLen(buffer), sizeof(buffer) - FskStrLen(buffer));
		FskStrCat(buffer, " ");
	}
	if (font->variant == kFskFontVariantSmallCaps)
		FskStrCat(buffer, "small-caps ");
	FskStrNumToStr((SInt32)(font->size), buffer + FskStrLen(buffer), sizeof(buffer) - FskStrLen(buffer));
	FskStrCat(buffer, "px ");
	FskStrCat(buffer, font->family);
	xsResult = xsString(buffer);
}
static FskErr KprWebSocketEndpointUpgradeConnection(KprWebSocketEndpoint self)
{
	FskErr err = kFskErrNone;
	FskHeaders *request;
	char buffer[1024], tmp[1024], portStr[10];
	int len, port;
	
	bailIfError(FskHeaderStructNew(&request));
	
	port = (self->parts->port ? port = self->parts->port : 80);
	
	if (port == 80) {
		FskHeaderAddString("Host", self->parts->host, request);
	} else {
		FskStrCopy(tmp, self->parts->host);
		FskStrCat(tmp, ":");
		FskStrNumToStr(port, portStr, 10);
		FskStrCat(tmp, portStr);
		FskHeaderAddString("Host", tmp, request);
	}
	
	if (self->origin) {
		FskHeaderAddString("Origin", self->origin, request);
	} else {
		FskStrCopy(tmp, "http://");
		FskStrCat(tmp, self->parts->host);
		FskHeaderAddString("Origin", tmp, request);
	}
	
	FskHeaderAddString("Upgrade", "websocket", request);
	FskHeaderAddString("Connection", "Upgrade", request);
	
	KprWebSocketCreateKey(&self->key);
	FskHeaderAddString("Sec-WebSocket-Key", self->key, request);
	FskHeaderAddInteger("Sec-WebSocket-Version", 13, request);
	
	FskStrCopy(buffer, "GET ");
	if (self->parts->path[0] != '/') FskStrCat(buffer, "/");
	FskStrCat(buffer, self->parts->path);
	FskStrCat(buffer, " HTTP/1.1\r\n");
	
	len = FskStrLen(buffer);
	FskHeaderGenerateOutputBlob(&buffer[len], 1024 - len, true, request);
	
	KprSocketWriterSendBytes(self->writer, buffer, FskStrLen(buffer));
	
bail:
	
	return err;
}
示例#7
0
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	int argc, i;
	UInt16 **argvUnicode;
	UInt8 **argvUTF8;
	int result;
	HANDLE startupCheck;
	UInt16 *moduleFileName, *mutexName;
	DWORD lastError;
	const UInt16 *kMutexBaseName = L"Fsk-startup-check-";

#if USE_TIMEBOMB
	if (!CheckDate())
		return -1;
#endif

	FskMainSetHInstance(hInstance);

	argvUnicode = CommandLineToArgvW(GetCommandLineW(), &argc);
	argvUTF8 = (UInt8 **)calloc(sizeof(UInt16 *), argc);
	for (i= 0; i< argc; i++) {
		int charCount = wcslen(argvUnicode[i]);
		argvUTF8[i] = malloc((charCount + 1) * 3);
		WideCharToMultiByte(CP_UTF8, 0, argvUnicode[i], charCount + 1, argvUTF8[i], (charCount + 1) * 3, NULL, NULL);
	}
	GlobalFree(argvUnicode);

	moduleFileName = (UInt16 *)malloc(sizeof(UInt16) * 520);
	GetModuleFileNameW(0, moduleFileName, 512);
	mutexName = malloc((1 + wcslen(moduleFileName) + wcslen(kMutexBaseName)) * 2);
	wcscpy(mutexName, kMutexBaseName);
	wcscat(mutexName, wcsrchr(moduleFileName, '\\') + 1);
	free(moduleFileName);
	startupCheck = CreateMutexW(0, true, mutexName);
	lastError = GetLastError();
	free(mutexName);
	
   for (i = 0; i < argc; i++){
      if(strcmp(argvUTF8[i],"-new-instance")==0) {
         lastError=0;
         break;
      }
	}
	switch (lastError) {
		case 0:
			result = doMain(kFskMainNetwork | kFskMainServer, argc, argvUTF8);
			break;

		case ERROR_ALREADY_EXISTS: {
			char *fileList;
			UInt32 fileListSize;

			result = 0;
			FskUtilsSetArgs(argc, argvUTF8);
			fileList = FskUtilsGetFileArgs(&fileListSize);
			if (NULL != fileList) {
				char *fileName;
				HANDLE hMapFile;
				char number[64];
				SInt32 val;
				
				val = FskRandom() ^ GetTickCount();
				FskStrNumToStr(val, number, sizeof(number));
				fileName = FskStrDoCat("FskFileOpen-", number);

				hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, fileListSize, fileName);
				if ((NULL != hMapFile) && (INVALID_HANDLE_VALUE != hMapFile)) {
					unsigned char *pBuf = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, fileListSize);
					if (NULL != pBuf) {
						memmove(pBuf, fileList, fileListSize);
						UnmapViewOfFile(pBuf);
						PostMessage(FindWindow("projectf-utils", NULL), RegisterWindowMessage("FskOpenFiles"), 0, val);
					}
					CloseHandle(hMapFile);
				}
				FskMemPtrDispose(fileName);
			}
			}
			break;

		default:
			result = -1;
			break;
	}

	CloseHandle(startupCheck);

	for (i = 0; i < argc; i++)
		free(argvUTF8[i]);
	free(argvUTF8);

	return result;
}
示例#8
0
FskErr FskEnvironmentInitialize(void)
{
	char *appPath;

	gEnvironment = FskAssociativeArrayNew();

	appPath = FskGetApplicationPath();
	FskEnvironmentSet("applicationPath", appPath);
	FskMemPtrDispose(appPath);

#if TARGET_OS_KPL
	KplEnvironmentInitialize(gEnvironment);
#elif TARGET_OS_ANDROID
	FskEnvironmentSet("application", "PLAY");
#elif TARGET_OS_WIN32 || TARGET_OS_MAC || TARGET_OS_LINUX
	FskEnvironmentSet("application", FSK_APPLICATION);
#else
	FskEnvironmentSet("application", "PLAY");
#endif

#if TARGET_OS_WIN32
	{
	char name[256], *nameTemp = NULL;
	UInt16 nameW[256];
	char num[32];
	DWORD nameSize = sizeof(nameW) / sizeof(UInt16);
	EXTENDED_NAME_FORMAT exNameFormat = NameSamCompatible;

	if (GetUserNameExW(exNameFormat, (LPWSTR)nameW, &nameSize)) {
		FskTextUnicode16LEToUTF8(nameW, nameSize * 2, &nameTemp, NULL);
		FskStrCopy(name, nameTemp);
		FskEnvironmentSet("loginName", name);
		FskMemPtrDispose(nameTemp);
	}

	FskEnvironmentSet("OS", "Windows");
	FskStrNumToStr(gWindowsVersionInfo.dwMajorVersion, name, sizeof(name));
	FskStrCat(name, ".");
	FskStrNumToStr(gWindowsVersionInfo.dwMinorVersion, num, sizeof(num));
	FskStrCat(name, num);
	FskEnvironmentSet("OSVersion", name);
	}
#elif TARGET_OS_MAC
	{
		struct utsname un;
		char name[256], *model;
		SInt32 gen;
	#if TARGET_OS_IPHONE
		FskEnvironmentSet("OS", "iPhone");
	#else
		FskEnvironmentSet("OS", "Mac");
	#endif
		FskCocoaSystemGetVersion(name);
		FskEnvironmentSet("OSVersion", name);
		if (uname(&un) == 0) {
			model = un.machine;
			if (FskStrCompareWithLength(model, "iPhone", 6) == 0)
				gen = FskStrToNum(model + 6);
			else if (FskStrCompareWithLength(model, "iPad", 4) == 0) {
				gen = FskStrToNum(model + 4);
				if (gen == 3) {
					SInt32 minor = FskStrToNum(model + 6);
					if (minor == 4)	/* 4th gen */
						gen = 5;
					else
						gen = 4;	/* Only the 3rd gen iPad doesn't follow the numbering system */
				}
				else
					gen += 2;
			}
			else if (FskStrCompareWithLength(model, "iPod", 4) == 0) {
				gen = FskStrToNum(model + 4);
				if (gen > 1)
					--gen;
			}
			else
				gen = 99;
		}
		else {
			model = "unknown";
			gen = 99;
		}
		FskEnvironmentSet("Model", model);
		FskStrNumToStr(gen, name, sizeof(name));
		FskEnvironmentSet("Generation", name);
	}
		
#elif TARGET_OS_LINUX
	{
	struct utsname name;
	uname(&name);

	if (getlogin())
		FskEnvironmentSet("loginName", getlogin());
	else
		FskEnvironmentSet("loginName", "User");
	FskEnvironmentSet("OS", name.sysname);
	FskEnvironmentSet("OSVersion", name.release);		//@@
	}
#endif

	return kFskErrNone;
}