int main(int argc, char **argv) { AS3_Val ilbc_lib = AS3_Object(""); AS3_Val encodeMethod = AS3_FunctionAsync( NULL, (AS3_ThunkProc) encodeForFlash); AS3_Val decodeMethod = AS3_FunctionAsync( NULL, (AS3_ThunkProc) decodeForFlash); AS3_SetS(ilbc_lib, "encode", encodeMethod); AS3_SetS(ilbc_lib, "decode", decodeMethod); AS3_Release( encodeMethod ); AS3_Release( decodeMethod ); //No code below here. AS3_LibInit does not return AS3_LibInit( ilbc_lib ); return 0; }
int resetPositionByteArray(AS3_Val byteArray) { AS3_Val zero = AS3_Int(0); /* just reset the position */ AS3_SetS((AS3_Val)byteArray, "position", zero); AS3_Release(zero); return 0; }
static AS3_Val thunk_InitSubPiecePacket(void *gg_clientData, AS3_Val gg_args) { AS3_Val packet; AS3_Val bytes; AS3_ArrayValue(gg_args, "AS3ValType, AS3ValType", &packet, &bytes); AS3_Val subpiece = AS3_GetS(packet, "subpiece"); AS3_Val blockIndexVal = AS3_CallTS("readUnsignedShort", bytes, ""); AS3_Val subPieceIndexVal = AS3_CallTS("readUnsignedShort", bytes, ""); AS3_SetS(subpiece, "blockIndex", blockIndexVal); AS3_SetS(subpiece, "subPieceIndex", subPieceIndexVal); AS3_Release(subpiece); AS3_Release(blockIndexVal); AS3_Release(subPieceIndexVal); AS3_Release(packet); AS3_Release(bytes); return NULL; }
int closeByteArray(void * cookie) { AS3_Val zero = AS3_Int(0); /* just reset the position */ AS3_SetS((AS3_Val)cookie, "position", zero); AS3_Release(zero); return 0; }
static AS3_Val thunk_InitAnnounceResponsePacket(void *gg_clientData, AS3_Val gg_args) { AS3_Val packet; AS3_Val bytes; AS3_ArrayValue(gg_args, "AS3ValType, AS3ValType", &packet, &bytes); AS3_Val paramArray = AS3_Array("AS3ValType", bytes); AS3_Val p2p_struct_namespace = AS3_String("com.pplive.p2p.struct"); AS3_Val PeerDownloadInfoClass = AS3_NSGetS(p2p_struct_namespace, "PeerDownloadInfo"); AS3_Val BlockMapClass = AS3_NSGetS(p2p_struct_namespace, "BlockMap"); AS3_Val peerDownloadInfo = AS3_New(PeerDownloadInfoClass, paramArray); AS3_Val blockMapInfo = AS3_New(BlockMapClass, paramArray); AS3_SetS(packet, "peerDownloadInfo", peerDownloadInfo); AS3_SetS(packet, "blockMap", blockMapInfo); AS3_Release(blockMapInfo); AS3_Release(peerDownloadInfo); AS3_Release(BlockMapClass); AS3_Release(PeerDownloadInfoClass); AS3_Release(p2p_struct_namespace); AS3_Release(paramArray); AS3_Release(bytes); AS3_Release(packet); return NULL; }
static AS3_Val thunk_InitBlockMap(void *gg_clientData, AS3_Val gg_args) { AS3_Val map; AS3_Val bytes; AS3_ArrayValue(gg_args, "AS3ValType, AS3ValType", &map, &bytes); AS3_Val blockCountVal = AS3_CallTS("readUnsignedInt", bytes, ""); AS3_Val bitset = AS3_GetS(map, "bitset"); AS3_SetS(map, "blockCount", blockCountVal); AS3_Release(AS3_CallTS("readBytes", bytes, "AS3ValType, IntType, IntType", bitset, 0, (int)((AS3_IntValue(blockCountVal) + 7) / 8))); AS3_Release(blockCountVal); AS3_Release(bitset); AS3_Release(map); AS3_Release(bytes); return NULL; }
static AS3_Val thunk_InitPeerDownloadInfo(void *gg_clientData, AS3_Val gg_args) { AS3_Val info; AS3_Val bytes; AS3_ArrayValue(gg_args, "AS3ValType, AS3ValType", &info, &bytes); AS3_Val isDownloadingVal = AS3_CallTS("readUnsignedByte", bytes, ""); if (AS3_IntValue(isDownloadingVal) == 1) { AS3_Val true = AS3_True(); AS3_SetS(info, "isDownloading", true); AS3_Release(true); } else { AS3_Val false = AS3_False(); AS3_SetS(info, "isDownloading", false); AS3_Release(false); } AS3_Val onLineTimeVal = AS3_CallTS("readUnsignedInt", bytes, ""); AS3_Val avgDownloadVal = AS3_CallTS("readUnsignedShort", bytes, ""); AS3_Val nowDownloadVal = AS3_CallTS("readUnsignedShort", bytes, ""); AS3_Val avgUploadVal = AS3_CallTS("readUnsignedShort", bytes, ""); AS3_Val nowUploadVal = AS3_CallTS("readUnsignedShort", bytes, ""); AS3_SetS(info, "onLineTime", onLineTimeVal); AS3_SetS(info, "avgDownload", avgDownloadVal); AS3_SetS(info, "nowDownload", nowDownloadVal); AS3_SetS(info, "avgUpload", avgUploadVal); AS3_SetS(info, "nowUpload", nowUploadVal); AS3_ByteArray_seek(bytes, 3, 1); // ignore 3 byte reserved bytes AS3_Release(isDownloadingVal); AS3_Release(onLineTimeVal); AS3_Release(avgDownloadVal); AS3_Release(nowDownloadVal); AS3_Release(avgUploadVal); AS3_Release(nowUploadVal); AS3_Release(bytes); AS3_Release(info); return NULL; }
void gg_reg(AS3_Val lib, const char *name, AS3_ThunkProc p) { AS3_Val fun = AS3_Function(NULL, p); AS3_SetS(lib, name, fun); AS3_Release(fun); }
int main() { // This method does not free all these strings and AS3 vals, but what-ev! // This app uses so much freaking memory anyway :p AS3_Val result = AS3_Object(""); AS3_SetS(result, "allocateSampleMemory", AS3_Function(NULL, allocateSampleMemory) ); AS3_SetS(result, "reallocateSampleMemory", AS3_Function(NULL, reallocateSampleMemory) ); AS3_SetS(result, "deallocateSampleMemory", AS3_Function(NULL, deallocateSampleMemory) ); AS3_SetS(result, "setSamples", AS3_Function(NULL, setSamples) ); AS3_SetS(result, "copy", AS3_Function(NULL, copy) ); AS3_SetS(result, "changeGain", AS3_Function(NULL, changeGain) ); AS3_SetS(result, "mixIn", AS3_Function(NULL, mixIn) ); AS3_SetS(result, "mixInPan", AS3_Function(NULL, mixInPan) ); AS3_SetS(result, "multiplyIn", AS3_Function(NULL, multiplyIn) ); AS3_SetS(result, "standardize", AS3_Function(NULL, standardize) ); AS3_SetS(result, "wavetableIn", AS3_Function(NULL, wavetableIn) ); AS3_SetS(result, "delay", AS3_Function(NULL, delay) ); AS3_SetS(result, "biquad", AS3_Function(NULL, biquad) ); AS3_SetS(result, "writeBytes", AS3_Function(NULL, writeBytes) ); AS3_SetS(result, "envelope", AS3_Function(NULL, envelope) ); AS3_SetS(result, "overdrive", AS3_Function(NULL, overdrive) ); AS3_SetS(result, "clip", AS3_Function(NULL, clip) ); AS3_SetS(result, "normalize", AS3_Function(NULL, normalize) ); AS3_SetS(result, "writeWavBytes", AS3_Function(NULL, writeWavBytes) ); AS3_SetS(result, "readWavBytes", AS3_Function(NULL, readWavBytes) ); // make our note number to frequency lookup table fillNoteLookupTable(); fillPowerLookupTable(); // notify that we initialized -- THIS DOES NOT RETURN! AS3_LibInit(result); return 0; }