PUBLIC HAL_USB_INTERFACE_DESCRIPTOR_T* hal_UsbDescriptorCopyInterfaceDescriptor(CONST HAL_USB_INTERFACE_DESCRIPTOR_T* interface) { UINT32 nbEp; UINT32 i; HAL_USB_INTERFACE_DESCRIPTOR_T* newInterface; newInterface = (HAL_USB_INTERFACE_DESCRIPTOR_T*) sxr_Malloc(sizeof(HAL_USB_INTERFACE_DESCRIPTOR_T)); memcpy(newInterface, interface, sizeof(HAL_USB_INTERFACE_DESCRIPTOR_T)); for(nbEp = 0; interface->epList[nbEp]; ++nbEp); newInterface->epList = (HAL_USB_EP_DESCRIPTOR_T**) sxr_Malloc((nbEp+1)*sizeof(HAL_USB_EP_DESCRIPTOR_T*)); newInterface->epList[nbEp] = 0; for(i = 0; i < nbEp; ++i) { newInterface->epList[i] = (HAL_USB_EP_DESCRIPTOR_T*) sxr_Malloc(sizeof(HAL_USB_EP_DESCRIPTOR_T)); memcpy(newInterface->epList[i], interface->epList[i], sizeof(HAL_USB_EP_DESCRIPTOR_T)); } return newInterface; }
VOID* xvid_myMalloc(UINT32 size) { VOID* addr; MALLOC_CHUNK_T** currentChunk; UINT32 i; addr = sxr_Malloc(size); if(addr == 0) { return 0; } currentChunk = &firstChunk; while(*currentChunk) { for(i = 0; i < MALLOC_CHUNK_SIZE; ++i) { if((*currentChunk)->addr[i] == 0) { break; } } if(i != MALLOC_CHUNK_SIZE) { break; } currentChunk = &(*currentChunk)->next; } if(*currentChunk == 0) { *currentChunk = (MALLOC_CHUNK_T*)sxr_Malloc(sizeof(MALLOC_CHUNK_T)); if(*currentChunk == 0) { sxr_Free(addr); return 0; } memset(*currentChunk, 0, sizeof(MALLOC_CHUNK_T)); i = 0; } (*currentChunk)->addr[i] = addr; return addr; }
PUBLIC HAL_USB_DEVICE_DESCRIPTOR_T* hal_UsbDescriptorNewDeviceDescriptor(UINT8 usbClass, UINT8 usbSubClass, UINT8 usbProto, UINT16 vendor, UINT16 product, UINT16 version, HAL_USB_CONFIG_DESCRIPTOR_T* configList[], UINT8* serialnumber, UINT8* description) { HAL_USB_DEVICE_DESCRIPTOR_T* device_desc; device_desc = (HAL_USB_DEVICE_DESCRIPTOR_T*) sxr_Malloc(sizeof(HAL_USB_DEVICE_DESCRIPTOR_T)); device_desc->usbClass = usbClass; device_desc->usbSubClass = usbSubClass; device_desc->usbProto = usbProto; device_desc->vendor = vendor; device_desc->product = product; device_desc->version = version; device_desc->configList = configList; device_desc->description = description; device_desc->serialNumber = serialnumber; device_desc->usbMode = 0; return device_desc; }
PRIVATE VOID* mps_openPcm8kmono(MPS_HANDLE_T handle) { // PCM8KMONO MPS_TRACE("mps_openPcm8kmono"); handle->videoLength = 0; handle->videoBuffer = 0; handle->audioLength = 1024*8; handle->audioBuffer = (UINT8*) sxr_Malloc(handle->audioLength); handle->stream.audioMode = AVPS_PLAY_AUDIO_MODE_PCM; handle->stream.audioSampleRate = 8000; handle->stream.channelNb = 1; handle->stream.voiceQuality = TRUE; return (VOID*)1; }
PUBLIC HAL_USB_CONFIG_DESCRIPTOR_T* hal_UsbDescriptorNewConfigDescriptor(UINT8 maxPower, UINT8 attributes, HAL_USB_INTERFACE_DESCRIPTOR_T** interfaceList, UINT8* description) { HAL_USB_CONFIG_DESCRIPTOR_T* config_desc; config_desc = (HAL_USB_CONFIG_DESCRIPTOR_T*) sxr_Malloc(sizeof(HAL_USB_CONFIG_DESCRIPTOR_T)); config_desc->attrib = attributes; config_desc->maxPower = maxPower; config_desc->interfaceList = interfaceList; config_desc->description = description; return config_desc; }
PUBLIC HAL_USB_CS_INTERFACE_DESCRIPTOR_T* hal_UsbDescriptorNewCSInterfaceDescriptor(HAL_USB_CS_CONSTRUCTOR_T constructor, HAL_USB_CALLBACK_T callback) { HAL_USB_CS_INTERFACE_DESCRIPTOR_T* interface_desc; interface_desc = (HAL_USB_CS_INTERFACE_DESCRIPTOR_T*) sxr_Malloc(sizeof(HAL_USB_INTERFACE_DESCRIPTOR_T)); interface_desc->reserved[0] = 0; interface_desc->reserved[1] = 0; interface_desc->constructor = constructor; interface_desc->interfaceIdx = 0xFF; interface_desc->callback = callback; return interface_desc; }
PUBLIC HAL_USB_EP_DESCRIPTOR_T* hal_UsbDescriptorNewBulkEpDescriptor(UINT8 ep, HAL_USB_CALLBACK_T callback) { UINT8 epNum; HAL_USB_EP_DESCRIPTOR_T* ep_desc; epNum = HAL_USB_EP_NUM(ep); if(epNum >= 16 || epNum == 0) { return 0; } ep_desc = (HAL_USB_EP_DESCRIPTOR_T*) sxr_Malloc(sizeof(HAL_USB_EP_DESCRIPTOR_T)); ep_desc->ep = ep; ep_desc->interval = 0; ep_desc->callback = callback; ep_desc->type = HAL_USB_EP_TYPE_BULK; return ep_desc; }
PUBLIC HAL_USB_INTERFACE_DESCRIPTOR_T* hal_UsbDescriptorNewInterfaceDescriptor(UINT8 usbClass, UINT8 usbSubClass, UINT8 usbProto, UINT8 interfaceIdx, HAL_USB_EP_DESCRIPTOR_T** epList, UINT8* description, HAL_USB_CALLBACK_T callback) { HAL_USB_INTERFACE_DESCRIPTOR_T* interface_desc; interface_desc = (HAL_USB_INTERFACE_DESCRIPTOR_T*) sxr_Malloc(sizeof(HAL_USB_INTERFACE_DESCRIPTOR_T)); interface_desc->usbClass = usbClass; interface_desc->usbSubClass = usbSubClass; interface_desc->usbProto = usbProto; interface_desc->interfaceIdx = interfaceIdx; interface_desc->epList = epList; interface_desc->description = description; interface_desc->callback = callback; return interface_desc; }
// ============================================================================= // mrs_AmrOpen // ----------------------------------------------------------------------------- /// Open the AMR codec to record an AMR file, and complete the handle to use /// to access the file. The handle's medium information must have been /// set previoulsy by calling the #mrs_OpenFile function. /// /// @param handle Handle filled with the file information. /// @param mode File opening mode: creation, appending, etc ... /// @param data Pointer to a private codec structure.. (unused) /// @return #MRS_ERR_NO when the opening is successful, #MRS_ERR_FILE_ERROR when it failed /// to create or access the file, #MRS_ERR_INCOMPATIBLE_AUDIO_CODEC when /// the audio format is incompatible. /// @todo Densify the return value. // ============================================================================= PRIVATE MRS_ERR_T mrs_AmrOpen(MRS_HANDLE_T handle, MRS_FILE_MODE_T mode, VOID** data) { // Header plus a silence frame UINT8 buffer[6+32]; #ifndef MRS_USES_AVRS // FIXME g_mrsAmrHandle = handle; #endif // FIXME Useful data ? *data = NULL; // Write the file header if the file is created // and add a silence frame at the beginning so that // the file is never 'empty'. if (mode == MRS_FILE_MODE_CREATE) { // File creation. buffer[0] = '#'; buffer[1] = '!'; buffer[2] = 'A'; buffer[3] = 'M'; buffer[4] = 'R'; buffer[5] = '\n'; buffer[6] = 0x3c; buffer[7] = 0x55; buffer[8] = 0x00; buffer[9] = 0x88; buffer[10] = 0xb6; buffer[11] = 0x66; buffer[12] = 0x79; buffer[13] = 0xe1; buffer[14] = 0xe0; buffer[15] = 0x01; buffer[16] = 0xe7; buffer[17] = 0xcf; buffer[18] = 0xf0; buffer[19] = 0x00; buffer[20] = 0x00; buffer[21] = 0x00; buffer[22] = 0x80; buffer[23] = 0x00; buffer[24] = 0x00; buffer[25] = 0x00; buffer[26] = 0x00; buffer[27] = 0x00; buffer[28] = 0x00; buffer[29] = 0x00; buffer[30] = 0x00; buffer[31] = 0x00; buffer[32] = 0x00; buffer[33] = 0x00; buffer[34] = 0x00; buffer[35] = 0x00; buffer[36] = 0x00; buffer[37] = 0x00; if (mrs_MediumWrite(&handle->mediumAudio, buffer, sizeof(buffer))>=0) { MRS_TRACE(MRS_INFO_TRC, 0, "mrs_OpenFile: AMR header written."); } else { return MRS_ERR_FILE_ERROR; } } else { // File appending. MRS_TRACE(MRS_INFO_TRC, 0, "mrs_OpenFile: AMR appending data."); // Check the validity of the file format if (mrs_MediumSeek(&handle->mediumAudio, 0, FS_SEEK_SET)>=0) { if (mrs_MediumRead(&handle->mediumAudio, buffer, sizeof(buffer))>=0) { MRS_TRACE(MRS_INFO_TRC, 0, "mrs_OpenFile: AMR header read (?)."); if (buffer[0] != '#' || buffer[1] != '!' || buffer[2] != 'A' || buffer[3] != 'M' || buffer[4] != 'R' || buffer[5] != '\n') { MRS_TRACE(MRS_INFO_TRC, 0, "mrs_OpenFile: AMR header read: BAD CODEC !"); return MRS_ERR_INCOMPATIBLE_AUDIO_CODEC; } else { MRS_TRACE(MRS_INFO_TRC, 0, "mrs_OpenFile: AMR header read (OK)."); } } else { MRS_TRACE(MRS_INFO_TRC, 0, "mrs_OpenFile: AMR header read FAILED !"); return MRS_ERR_FILE_ERROR; } } else { MRS_TRACE(MRS_INFO_TRC, 0, "mrs_OpenFile: AMR header seek failed."); return MRS_ERR_FILE_ERROR; } // Reset pointer at the end of the file to add new data // with the codec following calls. (record, etc) if (mrs_MediumSeek(&handle->mediumAudio, 0, FS_SEEK_END) <0) { MRS_TRACE(MRS_INFO_TRC, 0, "mrs_OpenFile: AMR ."); return MRS_ERR_FILE_ERROR; } } handle->videoLength = 0; handle->videoBuffer = 0; handle->audioLength = 1600; //1024*8; // Half a buffer is worth half a second of data. handle->audioBuffer = (UINT8*) sxr_Malloc(handle->audioLength); handle->audioStream.mode = AVRS_REC_AUDIO_MODE_AMR_RING; handle->audioStream.sampleRate = HAL_AIF_FREQ_8000HZ; handle->audioStream.channelNb = HAL_AIF_MONO; handle->audioStream.voiceQuality = TRUE; return MRS_ERR_NO; }
// ============================================================================= // mrs_PcmOpen // ----------------------------------------------------------------------------- /// Open the PCM codec to record an PCM file, and complete the handle to use /// to access the file. The handle's medium information must have been /// set previoulsy by calling the #mrs_OpenFile function. /// /// @param handle Handle filled with the file information. /// @param mode File opening mode: creation, appending, etc ... /// @param data Pointer to a private codec structure.. (unused) /// @return #MRS_ERR_NO when the opening is successful, #MRS_ERR_FILE_ERROR when it failed /// to create or access the file, #MRS_ERR_INCOMPATIBLE_AUDIO_CODEC when /// the audio format is incompatible. /// @todo Densify the return value. // ============================================================================= PRIVATE MRS_ERR_T mrs_PcmOpen(MRS_HANDLE_T handle, MRS_FILE_MODE_T mode, VOID** data) { // 'Blank' wave file header. UINT8 waveHeader[MRS_CODEC_PCM_WAVE_FILE_HEADER_SIZE]={0}; // Variable to receive the file header when appending, // for check. MRS_CODEC_PCM_WAVE_HEADER_T waveFormatHeader; #ifndef MRS_USES_AVRS // FIXME g_mrsPcmHandle = handle; #endif // FIXME Useful data ? *data = NULL; // Write the file header if the file is created if (mode == MRS_FILE_MODE_CREATE) { // File creation: The header will be written // at the end of the record as the file lenght // needs to be known. We write '0' in the header // place instead. if (mrs_MediumWrite(&handle->mediumAudio, waveHeader, MRS_CODEC_PCM_WAVE_FILE_HEADER_SIZE)>=0) // FIXME == MRS_CODEC_PCM_WAVE_FILE_HEADER_SIZE ? { MRS_TRACE(MRS_INFO_TRC, 0, "mrs_OpenFile: PCM header written."); } else { return MRS_ERR_FILE_ERROR; } } else { // File appending. MRS_TRACE(MRS_INFO_TRC, 0, "mrs_OpenFile: PCM appending data."); // Check the validity of the file format if (mrs_MediumSeek(&handle->mediumAudio, 0, FS_SEEK_SET)>=0) { if (mrs_MediumRead(&handle->mediumAudio, &waveFormatHeader, sizeof(waveFormatHeader))>=0) { MRS_TRACE(MRS_INFO_TRC, 0, "mrs_OpenFile: PCM header read (?)."); if (waveFormatHeader.szRiff != MPS_RIFF_ID('R', 'I', 'F', 'F') || waveFormatHeader.szWaveFmt[0] != MPS_RIFF_ID('W', 'A', 'V', 'E') || waveFormatHeader.dwFmtSize != 16 || waveFormatHeader.wFormatTag != 1 || waveFormatHeader.nChannels != HAL_AIF_MONO || waveFormatHeader.nSamplesPerSec != HAL_AIF_FREQ_8000HZ || waveFormatHeader.wBitsPerSample != 16) { MRS_TRACE(MRS_INFO_TRC, 0, "mrs_OpenFile: PCM header read: BAD CODEC !"); return MRS_ERR_INCOMPATIBLE_AUDIO_CODEC; } else { MRS_TRACE(MRS_INFO_TRC, 0, "mrs_OpenFile: PCM header read (OK)."); } } else { MRS_TRACE(MRS_INFO_TRC, 0, "mrs_OpenFile: PCM header read FAILED !"); return MRS_ERR_FILE_ERROR; } } else { MRS_TRACE(MRS_INFO_TRC, 0, "mrs_OpenFile: PCM header seek failed."); return MRS_ERR_FILE_ERROR; } // Reset pointer at the end of the file to add new data // with the codec following calls. (record, etc) if (mrs_MediumSeek(&handle->mediumAudio, 0, FS_SEEK_END) <0) { MRS_TRACE(MRS_INFO_TRC, 0, "mrs_OpenFile: PCM ."); return MRS_ERR_FILE_ERROR; } } handle->videoLength = 0; handle->videoBuffer = 0; handle->audioLength = 16000; // Half a buffer is worth half a second of data. handle->audioBuffer = (UINT8*) sxr_Malloc(handle->audioLength); handle->audioStream.mode = AVRS_REC_AUDIO_MODE_PCM; handle->audioStream.sampleRate = HAL_AIF_FREQ_8000HZ; handle->audioStream.channelNb = HAL_AIF_MONO; handle->audioStream.voiceQuality = TRUE; return MRS_ERR_NO; }