/* private native int nSetLocator ( int handle , String locator ) ; */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_mmedia_DirectRecord_nSetLocator() { jint handle = KNI_GetParameterAsInt(1); KNIPlayerInfo* pKniInfo = (KNIPlayerInfo*)handle; jint locatorLength; jchar* locator = NULL; jint returnValue = 0; javacall_result ret; KNI_StartHandles(1); KNI_DeclareHandle(locatorHandle); KNI_GetParameterAsObject(2, locatorHandle); locatorLength = KNI_GetStringLength(locatorHandle); locator = MMP_MALLOC(locatorLength * sizeof(jchar)); if (locator) { KNI_GetStringRegion(locatorHandle, 0, locatorLength, locator); if (pKniInfo && pKniInfo->pNativeHandle) { ret = javacall_media_recording_handled_by_native(pKniInfo->pNativeHandle, locator, locatorLength); if (JAVACALL_INVALID_ARGUMENT == ret) { returnValue = -1; REPORT_ERROR1(LC_MMAPI, "[kni_record] Set recording location \ return JAVACALL_INVALID_ARGUMENT handle=%d\n", pKniInfo->pNativeHandle); } else { if (JAVACALL_OK == ret) {
KNIEXPORT KNI_RETURNTYPE_OBJECT KNIDECL(com_sun_mmedia_DefaultConfiguration_nListProtocolsNext) { ListIterator *iterator; char *p; unsigned int len; char stack_string_buffer[MAX_PROTOCOLNAME_LEN], *proto = NULL; KNI_StartHandles(1); KNI_DeclareHandle(stringObj); iterator = (ListIterator *)KNI_GetParameterAsInt(1); KNI_ReleaseHandle(stringObj); do { if (iterator == NULL || iterator->current == NULL) { /* Wrong parameter */ KNI_ThrowNew(jsropIllegalArgumentException, "Illegal iterator"); break; } /* finding next item in the list */ if ((p = strchr(iterator->current, ' ')) != NULL) { len = (int)(p - iterator->current); } else { len = strlen(iterator->current); } if (len == 0) { /* End of list */ break; } /* is the stack buffer enough for the item? */ if (len >= sizeof stack_string_buffer / sizeof stack_string_buffer[0]) { proto = MMP_MALLOC(len + 1); if (proto == NULL) { KNI_ThrowNew(jsropOutOfMemoryError, NULL); break; } } else { proto = stack_string_buffer; } /* shift to next item in the list */ memcpy(proto, iterator->current, len); proto[len] = '\0'; iterator->current += len; while (*iterator->current == ' ') { iterator->current++; } } while (0); if (proto != NULL) { KNI_NewStringUTF(proto, stringObj); if (proto != stack_string_buffer) { MMP_FREE(proto); } } KNI_EndHandlesAndReturnObject(stringObj); }
KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_mmedia_DefaultConfiguration_nListContentTypesOpen) { javacall_int32 proto_mask = 0; javacall_bool deviceProtocol = JAVACALL_FALSE; const javacall_media_configuration *cfg; const javacall_media_caps *caps; unsigned int len; ListIterator *iterator = NULL; char *p; /* stack buffers. Trying to avoid malloc if a string is not big */ jchar stack_string16_buffer[MAX_PROTOCOLNAME_LEN], *string16 = NULL; char stack_string_buffer[MAX_PROTOCOLNAME_LEN], *proto = NULL; KNI_StartHandles(1); KNI_DeclareHandle(stringObj); KNI_GetParameterAsObject(1, stringObj); do { if (KNI_IsNullHandle(stringObj)) { proto = NULL; } else { len = KNI_GetStringLength(stringObj); /* if the string is longer than the stack buffer try to malloc it */ if (len >= sizeof stack_string16_buffer / sizeof stack_string16_buffer[0]) { string16 = MMP_MALLOC((len + 1) * sizeof *string16); if (string16 == NULL) { KNI_ThrowNew(jsropOutOfMemoryError, NULL); break; } } else { string16 = stack_string16_buffer; } if (len >= sizeof stack_string_buffer) { proto = MMP_MALLOC(len + 1); if (proto == NULL) { KNI_ThrowNew(jsropOutOfMemoryError, NULL); break; } } else { proto = stack_string_buffer; } KNI_GetStringRegion(stringObj, 0, len, string16); if (simple_jcharString_to_asciiString(string16, len, proto, len + 1) != JAVACALL_OK) { KNI_ThrowNew(jsropIllegalArgumentException, "Illegal character in protocol name"); break; } } if (proto != NULL) { unsigned int i; /* trying to find protocol by name */ for (i = 0; i < sizeof protocolNames / sizeof protocolNames[0]; i++) { if (protocolNames[i].proto_name != NULL && !javautil_stricmp(protocolNames[i].proto_name, proto)) { proto_mask |= protocolNames[i].proto_mask; } } if (!javautil_stricmp(proto, DEVICE_PROTOCOL)) { deviceProtocol = JAVACALL_TRUE; } } if (proto != NULL && proto_mask == 0 && !deviceProtocol) { /* Requested protocol wasn't found. Return 0 */ break; } if (javacall_media_get_configuration(&cfg) != JAVACALL_OK) { KNI_ThrowNew(jsropRuntimeException, "Couldn't get MMAPI configuration"); break; } /* how long will be list of content types? */ len = 0; for (caps = cfg->mediaCaps; caps != NULL && caps->mediaFormat != NULL; caps++) { if (proto == NULL || (caps->wholeProtocols & proto_mask) != 0 || (caps->streamingProtocols & proto_mask) != 0) { len += strlen(caps->contentTypes) + 1; /* +1 for space char */ } } if (proto == NULL || deviceProtocol) { if (cfg->supportDeviceMIDI) { len += strlen(MIME_AUDIO_MIDI) + 1; } if (cfg->supportDeviceTone) { len += strlen(MIME_AUDIO_TONE) + 1; } } if (len == 0) { /* No MIME types were found for provided protocol. Return 0 */ break; } iterator = (ListIterator*)MMP_MALLOC( sizeof *iterator + len); /* zero terminator instead of last space */ if (iterator == NULL) { KNI_ThrowNew(jsropOutOfMemoryError, NULL); break; } /* initialize the iterator */ iterator->current = iterator->list; /* filling the list of content types */ p = iterator->list; for (caps = cfg->mediaCaps; caps != NULL && caps->mediaFormat != NULL; caps++) { if (proto == NULL || (caps->wholeProtocols & proto_mask) != 0 || (caps->streamingProtocols & proto_mask) != 0) { int types_len = strlen(caps->contentTypes); memcpy(p, caps->contentTypes, types_len); p += types_len; *p++ = ' '; } } if (proto == NULL || deviceProtocol) { int types_len; if (cfg->supportDeviceMIDI) { types_len = strlen(MIME_AUDIO_MIDI); memcpy(p, MIME_AUDIO_MIDI, types_len); p += types_len; *p++ = ' '; } if (cfg->supportDeviceTone) { types_len = strlen(MIME_AUDIO_TONE); memcpy(p, MIME_AUDIO_TONE, types_len); p += types_len; *p++ = ' '; } } p--; *p = '\0'; /* replace last space with zero */ mmapi_string_delete_duplicates(iterator->list); } while (0); /* freeing buffers */ if (proto != NULL && proto != stack_string_buffer) { MMP_FREE(proto); } if (string16 != NULL && string16 != stack_string16_buffer) { MMP_FREE(string16); } KNI_EndHandles(); KNI_ReturnInt((jint)iterator); }
KNIEXPORT KNI_RETURNTYPE_INT KNIDECL(com_sun_mmedia_DefaultConfiguration_nListProtocolsOpen) { const javacall_media_configuration *cfg; javacall_media_caps *caps; ListIterator *iterator = NULL; javacall_int32 proto_mask = 0; javacall_bool supportDeviceProtocol = JAVACALL_FALSE; char *p = NULL; /* stack buffers. Trying to avoid malloc if a string is not big */ jchar stack_string16_buffer[MAX_PROTOCOLNAME_LEN], *string16 = NULL; char stack_string_buffer[MAX_PROTOCOLNAME_LEN], *mime = NULL; KNI_StartHandles(1); KNI_DeclareHandle(stringObj); KNI_GetParameterAsObject(1, stringObj); do { if (KNI_IsNullHandle(stringObj)) { mime = NULL; } else { unsigned int len = KNI_GetStringLength(stringObj); /* if the string is longer than the stack buffer try to malloc it */ if (len >= sizeof stack_string16_buffer / sizeof stack_string16_buffer[0]) { string16 = MMP_MALLOC((len + 1) * sizeof *string16); if (string16 == NULL) { KNI_ThrowNew(jsropOutOfMemoryError, NULL); break; } } else { string16 = stack_string16_buffer; } if (len >= sizeof stack_string_buffer / sizeof stack_string_buffer[0]) { mime = MMP_MALLOC(len + 1); if (mime == NULL) { KNI_ThrowNew(jsropOutOfMemoryError, NULL); break; } } else { mime = stack_string_buffer; } KNI_GetStringRegion(stringObj, 0, len, string16); if (simple_jcharString_to_asciiString(string16, len, mime, len + 1) != JAVACALL_OK) { KNI_ThrowNew(jsropIllegalArgumentException, "Illegal character in MIME type name"); break; } } if (javacall_media_get_configuration(&cfg) != JAVACALL_OK) { KNI_ThrowNew(jsropRuntimeException, "Couldn't get MMAPI configuration"); break; } if ((mime == NULL || !javautil_stricmp(mime, MIME_AUDIO_MIDI)) && cfg->supportDeviceMIDI) { supportDeviceProtocol = JAVACALL_TRUE; } if (!supportDeviceProtocol && (mime == NULL || !javautil_stricmp(mime, MIME_AUDIO_TONE)) && cfg->supportDeviceTone) { supportDeviceProtocol = JAVACALL_TRUE; } /* trying to find given MIME type among caps->contentTypes */ for (caps = cfg->mediaCaps; caps != NULL && caps->mediaFormat != NULL; caps++) { if (caps->wholeProtocols != 0 || caps->streamingProtocols != 0) { if (mime != NULL) { char *s; int m_len = strlen(mime); for (p = (char *)caps->contentTypes; p != NULL; p = s) { int p_len; while (*p == ' ') { p++; } if ((s = strchr(p, ' ')) != NULL) { p_len = (int)(s - p); } else { p_len = strlen(p); } if (p_len == m_len && !javautil_strnicmp(mime, p, p_len)) { break; } } } if (mime == NULL || p != NULL) { proto_mask |= caps->wholeProtocols; proto_mask |= caps->streamingProtocols; } } } if (proto_mask != 0 || supportDeviceProtocol) { /* some protocols were found */ unsigned int i; unsigned int len = 0; /* trying to resolve protocol names: calculating needed memory */ for (i = 0; i < sizeof protocolNames / sizeof protocolNames[0]; i++) { if ((protocolNames[i].proto_mask & proto_mask) != 0 && protocolNames[i].proto_name != NULL) { len += strlen(protocolNames[i].proto_name) + 1; /* +1 for space char */ } } if (supportDeviceProtocol) { len += strlen(DEVICE_PROTOCOL) + 1; } if (len == 0) { /* Protocol wasn't found in the protocol name table */ KNI_ThrowNew(jsropRuntimeException, "Incorrect MMAPI configuration: missing protocol name"); break; } iterator = (ListIterator*)MMP_MALLOC( sizeof *iterator + len); /* zero terminator instead of last space */ if (iterator == NULL) { KNI_ThrowNew(jsropOutOfMemoryError, NULL); break; } /* initialize the iterator */ iterator->current = iterator->list; /* building the list of protocols */ p = iterator->list; for (i = 0; i < sizeof protocolNames / sizeof protocolNames[0]; i++) { if ((protocolNames[i].proto_mask & proto_mask) != 0 && protocolNames[i].proto_name != NULL) { int proto_len = strlen(protocolNames[i].proto_name); memcpy(p, protocolNames[i].proto_name, proto_len); p += proto_len; *p++ = ' '; } } if (supportDeviceProtocol) { int proto_len = strlen(DEVICE_PROTOCOL); memcpy(p, DEVICE_PROTOCOL, proto_len); p += proto_len; *p++ = ' '; } p--; *p = '\0'; /* replace last space with zero */ } else { /* No protocols were found for provided MIME type. Return 0 */ break; } mmapi_string_delete_duplicates(iterator->list); } while (0); /* freeing buffers */ if (mime != NULL && mime != stack_string_buffer) { MMP_FREE(mime); } if (string16 != NULL && string16 != stack_string16_buffer) { MMP_FREE(string16); } KNI_EndHandles(); KNI_ReturnInt((jint)iterator); }