static int thread_process_message_wave_info(rdpsndPlugin * plugin, char * data, int data_size) { int wFormatNo; int error; if (plugin->device_plugin) error = plugin->device_plugin->open(plugin->device_plugin); else error = 1; plugin->wTimeStamp = GET_UINT16(data, 0); /* time in ms */ plugin->local_time_stamp = get_mstime(); /* time in ms */ wFormatNo = GET_UINT16(data, 2); LLOGLN(10, ("thread_process_message_wave_info: data_size %d " "wFormatNo %d", data_size, wFormatNo)); plugin->cBlockNo = GET_UINT8(data, 4); plugin->waveDataSize = data_size - 8; memcpy(plugin->waveData, data + 8, 4); if (wFormatNo != plugin->current_format && !error) { plugin->current_format = wFormatNo; set_format(plugin); } plugin->expectingWave = 1; return error; }
static int process_CAPABILITY_REQUEST_PDU(drdynvcPlugin * plugin, int Sp, int cbChId, char * data, int data_size) { int error; int size; char * out_data; LLOGLN(10, ("process_CAPABILITY_REQUEST_PDU:")); plugin->version = GET_UINT16(data, 2); if (plugin->version == 2) { plugin->PriorityCharge0 = GET_UINT16(data, 4); plugin->PriorityCharge1 = GET_UINT16(data, 6); plugin->PriorityCharge2 = GET_UINT16(data, 8); plugin->PriorityCharge3 = GET_UINT16(data, 10); } size = 4; out_data = (char *) malloc(size); SET_UINT16(out_data, 0, 0x0050); /* Cmd+Sp+cbChId+Pad. Note: MSTSC sends 0x005c */ SET_UINT16(out_data, 2, plugin->version); hexdump(out_data, 4); error = plugin->ep.pVirtualChannelWrite(plugin->open_handle, out_data, size, out_data); if (error != CHANNEL_RC_OK) { LLOGLN(0, ("process_CAPABILITY_REQUEST_PDU: " "VirtualChannelWrite " "failed %d", error)); return 1; } return 0; }
XdgMimeCache * _xdg_mime_cache_new_from_file (const char *file_name) { XdgMimeCache *cache = NULL; #ifdef HAVE_MMAP int fd = -1; struct stat st; char *buffer = NULL; int minor; /* Open the file and map it into memory */ do fd = open (file_name, O_RDONLY|_O_BINARY, 0); while (fd == -1 && errno == EINTR); if (fd < 0) return NULL; if (fstat (fd, &st) < 0 || st.st_size < 4) goto done; buffer = (char *) mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); if (buffer == MAP_FAILED) goto done; minor = GET_UINT16 (buffer, 2); /* Verify version */ if (GET_UINT16 (buffer, 0) != MAJOR_VERSION || (minor < MINOR_VERSION_MIN || minor > MINOR_VERSION_MAX)) { munmap (buffer, st.st_size); goto done; } cache = (XdgMimeCache *) malloc (sizeof (XdgMimeCache)); cache->minor = minor; cache->ref_count = 1; cache->buffer = buffer; cache->size = st.st_size; done: if (fd != -1) close (fd); #else /* HAVE_MMAP */ cache = (XdgMimeCache *) malloc (sizeof (XdgMimeCache)); cache->minor = 0; cache->ref_count = 1; cache->buffer = NULL; cache->size = 0; #endif /* HAVE_MMAP */ return cache; }
static int rdpsnd_pulse_format_supported(rdpsndDevicePlugin * devplugin, char * snd_format, int size) { struct pulse_device_data * pulse_data; int nChannels; int wBitsPerSample; int nSamplesPerSec; int cbSize; int wFormatTag; pulse_data = (struct pulse_device_data *) devplugin->device_data; if (!pulse_data->context) return 0; wFormatTag = GET_UINT16(snd_format, 0); nChannels = GET_UINT16(snd_format, 2); nSamplesPerSec = GET_UINT32(snd_format, 4); wBitsPerSample = GET_UINT16(snd_format, 14); cbSize = GET_UINT16(snd_format, 16); LLOGLN(10, ("rdpsnd_pulse_format_supported: wFormatTag=%d " "nChannels=%d nSamplesPerSec=%d wBitsPerSample=%d cbSize=%d", wFormatTag, nChannels, nSamplesPerSec, wBitsPerSample, cbSize)); switch (wFormatTag) { case 1: /* PCM */ if (cbSize == 0 && (nSamplesPerSec <= PA_RATE_MAX) && (wBitsPerSample == 8 || wBitsPerSample == 16) && (nChannels >= 1 && nChannels <= PA_CHANNELS_MAX)) { LLOGLN(0, ("rdpsnd_pulse_format_supported: ok")); return 1; } break; case 6: /* A-LAW */ case 7: /* U-LAW */ if (cbSize == 0 && (nSamplesPerSec <= PA_RATE_MAX) && (wBitsPerSample == 8) && (nChannels >= 1 && nChannels <= PA_CHANNELS_MAX)) { LLOGLN(0, ("rdpsnd_pulse_format_supported: ok")); return 1; } break; case 0x11: /* IMA ADPCM */ if ((nSamplesPerSec <= PA_RATE_MAX) && (wBitsPerSample == 4) && (nChannels == 1 || nChannels == 2)) { LLOGLN(0, ("rdpsnd_pulse_format_supported: ok")); return 1; } break; } return 0; }
static int rdpsnd_alsa_set_format(rdpsndDevicePlugin * devplugin, char * snd_format, int size) { struct alsa_device_data * alsa_data; int nChannels; int wBitsPerSample; int nSamplesPerSec; int wFormatTag; int nBlockAlign; alsa_data = (struct alsa_device_data *) devplugin->device_data; wFormatTag = GET_UINT16(snd_format, 0); nChannels = GET_UINT16(snd_format, 2); nSamplesPerSec = GET_UINT32(snd_format, 4); nBlockAlign = GET_UINT16(snd_format, 12); wBitsPerSample = GET_UINT16(snd_format, 14); LLOGLN(0, ("rdpsnd_alsa_set_format: wFormatTag=%d nChannels=%d " "nSamplesPerSec=%d wBitsPerSample=%d nBlockAlign=%d", wFormatTag, nChannels, nSamplesPerSec, wBitsPerSample, nBlockAlign)); alsa_data->source_rate = nSamplesPerSec; alsa_data->actual_rate = nSamplesPerSec; alsa_data->source_channels = nChannels; alsa_data->actual_channels = nChannels; switch (wFormatTag) { case 1: /* PCM */ switch (wBitsPerSample) { case 8: alsa_data->format = SND_PCM_FORMAT_S8; alsa_data->bytes_per_channel = 1; break; case 16: alsa_data->format = SND_PCM_FORMAT_S16_LE; alsa_data->bytes_per_channel = 2; break; } break; case 0x11: /* IMA ADPCM */ alsa_data->format = SND_PCM_FORMAT_S16_LE; alsa_data->bytes_per_channel = 2; break; } alsa_data->wformat = wFormatTag; alsa_data->block_size = nBlockAlign; set_params(alsa_data); return 0; }
static int thread_process_message(cliprdrPlugin * plugin, char * data, int data_size) { uint16 type; uint32 flag; uint32 length; uint32 format; type = GET_UINT16(data, 0); flag = GET_UINT16(data, 2); length = GET_UINT32(data, 4); LLOGLN(10, ("cliprdr: thread_process_message: type=%d flag=%d length=%d", type, flag, length)); switch (type) { case CB_MONITOR_READY: clipboard_sync(plugin->device_data); break; case CB_FORMAT_LIST: clipboard_format_list(plugin->device_data, flag, data + 8, length); cliprdr_send_packet(plugin, CB_FORMAT_LIST_RESPONSE, CB_RESPONSE_OK, NULL, 0); break; case CB_FORMAT_LIST_RESPONSE: clipboard_format_list_response(plugin->device_data, flag); break; case CB_FORMAT_DATA_REQUEST: format = GET_UINT32(data, 8); clipboard_request_data(plugin->device_data, format); break; case CB_FORMAT_DATA_RESPONSE: clipboard_handle_data(plugin->device_data, flag, data + 8, length); break; case CB_CLIP_CAPS: clipboard_handle_caps(plugin->device_data, flag, data + 8, length); break; default: LLOGLN(0, ("thread_process_message: type %d not supported", type)); break; } return 0; }
static int audin_process_format_change(IWTSVirtualChannelCallback * pChannelCallback, char * data, uint32 data_size) { AUDIN_CHANNEL_CALLBACK * callback = (AUDIN_CHANNEL_CALLBACK *) pChannelCallback; uint32 NewFormat; char * format; int size; NewFormat = GET_UINT32(data, 0); LLOGLN(10, ("audin_process_format_change: NewFormat=%d", NewFormat)); if (NewFormat >= callback->formats_count) { LLOGLN(0, ("audin_process_format_change: invalid format index %d (total %d)", NewFormat, callback->formats_count)); return 1; } wave_in_close(callback->device_data); format = callback->formats_data[NewFormat]; size = 18 + GET_UINT16(format, 16); wave_in_set_format(callback->device_data, 0, format, size); audin_send_format_change_pdu(pChannelCallback, NewFormat); wave_in_open(callback->device_data, audin_receive_wave_data, callback); return 0; }
static int audin_process_open(IWTSVirtualChannelCallback * pChannelCallback, char * data, uint32 data_size) { AUDIN_CHANNEL_CALLBACK * callback = (AUDIN_CHANNEL_CALLBACK *) pChannelCallback; uint32 FramesPerPacket; uint32 initialFormat; char * format; int size; int result; FramesPerPacket = GET_UINT32(data, 0); initialFormat = GET_UINT32(data, 4); LLOGLN(10, ("audin_process_open: FramesPerPacket=%d initialFormat=%d", FramesPerPacket, initialFormat)); if (initialFormat >= callback->formats_count) { LLOGLN(0, ("audin_process_open: invalid format index %d (total %d)", initialFormat, callback->formats_count)); return 1; } format = callback->formats_data[initialFormat]; size = 18 + GET_UINT16(format, 16); wave_in_set_format(callback->device_data, FramesPerPacket, format, size); result = wave_in_open(callback->device_data, audin_receive_wave_data, callback); if (result == 0) { audin_send_format_change_pdu(pChannelCallback, initialFormat); } audin_send_open_reply_pdu(pChannelCallback, result); return 0; }
XdgMimeCache * _xdg_mime_cache_new_from_file (G_GNUC_UNUSED const char *file_name) { XdgMimeCache *cache = NULL; #ifdef HAVE_MMAP int fd = -1; struct stat st; char *buffer = NULL; /* Open the file and map it into memory */ fd = open (file_name, O_RDONLY|_O_BINARY, 0); if (fd < 0) return NULL; if (XDG_MIME_FSTAT (fd, &st) < 0 || st.st_size < 4) goto done; buffer = (char *) mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); if (buffer == MAP_FAILED) goto done; /* Verify version */ if (GET_UINT16 (buffer, 0) != MAJOR_VERSION || GET_UINT16 (buffer, 2) != MINOR_VERSION) { munmap (buffer, st.st_size); goto done; } cache = (XdgMimeCache *) malloc (sizeof (XdgMimeCache)); cache->ref_count = 1; cache->buffer = buffer; cache->size = st.st_size; done: if (fd != -1) close (fd); #endif /* HAVE_MMAP */ return cache; }
static gint find_image_offset (GtkIconCache *cache, const gchar *icon_name, gint directory_index) { guint32 hash_offset; guint32 n_buckets; guint32 chain_offset; int hash; guint32 image_list_offset, n_images; int i; chain_offset = cache->last_chain_offset; if (chain_offset) { guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4); gchar *name = cache->buffer + name_offset; if (strcmp (name, icon_name) == 0) goto find_dir; } hash_offset = GET_UINT32 (cache->buffer, 4); n_buckets = GET_UINT32 (cache->buffer, hash_offset); hash = icon_name_hash (icon_name) % n_buckets; chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * hash); while (chain_offset != 0xffffffff) { guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4); gchar *name = cache->buffer + name_offset; if (strcmp (name, icon_name) == 0) { cache->last_chain_offset = chain_offset; goto find_dir; } chain_offset = GET_UINT32 (cache->buffer, chain_offset); } cache->last_chain_offset = 0; return 0; find_dir: /* We've found an icon list, now check if we have the right icon in it */ image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8); n_images = GET_UINT32 (cache->buffer, image_list_offset); for (i = 0; i < n_images; i++) { if (GET_UINT16 (cache->buffer, image_list_offset + 4 + 8 * i) == directory_index) return image_list_offset + 4 + 8 * i; } return 0; }
/* returns boolean */ static int rdpsnd_alsa_format_supported(rdpsndDevicePlugin * devplugin, char * snd_format, int size) { struct alsa_device_data * alsa_data; int nChannels; int wBitsPerSample; int nSamplesPerSec; int cbSize; int wFormatTag; alsa_data = (struct alsa_device_data *) devplugin->device_data; wFormatTag = GET_UINT16(snd_format, 0); nChannels = GET_UINT16(snd_format, 2); nSamplesPerSec = GET_UINT32(snd_format, 4); wBitsPerSample = GET_UINT16(snd_format, 14); cbSize = GET_UINT16(snd_format, 16); LLOGLN(10, ("rdpsnd_alsa_format_supported: wFormatTag=%d " "nChannels=%d nSamplesPerSec=%d wBitsPerSample=%d cbSize=%d", wFormatTag, nChannels, nSamplesPerSec, wBitsPerSample, cbSize)); switch (wFormatTag) { case 1: /* PCM */ if (cbSize == 0 && (nSamplesPerSec <= 48000) && (wBitsPerSample == 8 || wBitsPerSample == 16) && (nChannels == 1 || nChannels == 2)) { LLOGLN(0, ("rdpsnd_alsa_format_supported: ok")); return 1; } break; case 0x11: /* IMA ADPCM */ if ((nSamplesPerSec <= 48000) && (wBitsPerSample == 4) && (nChannels == 1 || nChannels == 2)) { LLOGLN(0, ("rdpsnd_alsa_format_supported: ok")); return 1; } break; } return 0; }
void rdpdr_process_capabilities(char* data, int size) { int i; int offset; uint16 numCapabilities; uint16 capabilityType; numCapabilities = GET_UINT16(data, 0); /* numCapabilities */ /* pad (2 bytes) */ offset = 4; for(i = 0; i < numCapabilities; i++) { capabilityType = GET_UINT16(data, offset); switch (capabilityType) { case CAP_GENERAL_TYPE: offset += rdpdr_process_general_capset(&data[offset], size - offset); break; case CAP_PRINTER_TYPE: offset += rdpdr_process_printer_capset(&data[offset], size - offset); break; case CAP_PORT_TYPE: offset += rdpdr_process_port_capset(&data[offset], size - offset); break; case CAP_DRIVE_TYPE: offset += rdpdr_process_drive_capset(&data[offset], size - offset); break; case CAP_SMARTCARD_TYPE: offset += rdpdr_process_smartcard_capset(&data[offset], size - offset); break; default: //fprintf(stderr, "unimpl: Device redirection capability set type %d\n", capabilityType); break; } } }
gboolean gtk_icon_cache_has_icon_in_directory (GtkIconCache *cache, const gchar *icon_name, const gchar *directory) { guint32 hash_offset; guint32 n_buckets; guint32 chain_offset; gint hash; gboolean found_icon = FALSE; gint directory_index; directory_index = get_directory_index (cache, directory); if (directory_index == -1) return FALSE; hash_offset = GET_UINT32 (cache->buffer, 4); n_buckets = GET_UINT32 (cache->buffer, hash_offset); hash = icon_name_hash (icon_name) % n_buckets; chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * hash); while (chain_offset != 0xffffffff) { guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4); gchar *name = cache->buffer + name_offset; if (strcmp (name, icon_name) == 0) { found_icon = TRUE; break; } chain_offset = GET_UINT32 (cache->buffer, chain_offset); } if (found_icon) { guint32 image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8); guint32 n_images = GET_UINT32 (cache->buffer, image_list_offset); guint32 image_offset = image_list_offset + 4; gint i; for (i = 0; i < n_images; i++) { guint16 index = GET_UINT16 (cache->buffer, image_offset); if (index == directory_index) return TRUE; image_offset += 8; } } return FALSE; }
/* Process smartcard redirection capability set */ int rdpdr_process_smartcard_capset(char* data, int size) { uint16 capabilityLength; uint32 version; capabilityLength = GET_UINT16(data, 0); /* capabilityLength */ version = GET_UINT32(data, 2); /* version */ return (int)capabilityLength; }
static int set_format(rdpsndPlugin * plugin) { char * snd_format; int size; int index; LLOGLN(10, ("set_format:")); snd_format = plugin->supported_formats; size = 18 + GET_UINT16(snd_format, 16); index = 0; while (index < plugin->current_format) { snd_format += size; size = 18 + GET_UINT16(snd_format, 16); index++; } if (plugin->device_plugin) plugin->device_plugin->set_format(plugin->device_plugin, snd_format, size); return 0; }
static gint find_image_offset (GtkIconCache *cache, const gchar *icon_name, const gchar *directory) { guint32 hash_offset; guint32 n_buckets; guint32 chain_offset; int hash, directory_index; guint32 image_list_offset, n_images; gboolean found = FALSE; int i; hash_offset = GET_UINT32 (cache->buffer, 4); n_buckets = GET_UINT32 (cache->buffer, hash_offset); hash = icon_name_hash (icon_name) % n_buckets; chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * hash); while (chain_offset != 0xffffffff) { guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4); gchar *name = cache->buffer + name_offset; if (strcmp (name, icon_name) == 0) { found = TRUE; break; } chain_offset = GET_UINT32 (cache->buffer, chain_offset); } if (!found) { return 0; } /* We've found an icon list, now check if we have the right icon in it */ directory_index = get_directory_index (cache, directory); image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8); n_images = GET_UINT32 (cache->buffer, image_list_offset); for (i = 0; i < n_images; i++) { if (GET_UINT16 (cache->buffer, image_list_offset + 4 + 8 * i) == directory_index) return image_list_offset + 4 + 8 * i; } return 0; }
/* called by worker thread server is getting a feel of the round trip time */ static int thread_process_message_training(rdpsndPlugin * plugin, char * data, int data_size) { int wTimeStamp; int wPackSize; int size; char * out_data; uint32 error; wTimeStamp = GET_UINT16(data, 0); wPackSize = GET_UINT16(data, 2); if (wPackSize != 0) { if ((wPackSize - 4) != data_size) { LLOGLN(0, ("thread_process_message_training: size error " "wPackSize %d data_size %d", wPackSize, data_size)); return 1; } } size = 8; out_data = (char *) malloc(size); SET_UINT8(out_data, 0, SNDC_TRAINING); SET_UINT8(out_data, 1, 0); SET_UINT16(out_data, 2, size - 4); SET_UINT16(out_data, 4, wTimeStamp); SET_UINT16(out_data, 6, wPackSize); error = plugin->ep.pVirtualChannelWrite(plugin->open_handle, out_data, size, out_data); if (error != CHANNEL_RC_OK) { LLOGLN(0, ("thread_process_message_training: VirtualChannelWrite " "failed %d", error)); return 1; } return 0; }
gint gtk_icon_cache_get_icon_flags (GtkIconCache *cache, const gchar *icon_name, gint directory_index) { guint32 image_offset; image_offset = find_image_offset (cache, icon_name, directory_index); if (!image_offset) return 0; return GET_UINT16 (cache->buffer, image_offset + 2); }
/* Process device direction general capability set */ int rdpdr_process_general_capset(char* data, int size) { uint16 capabilityLength; uint32 version; uint16 protocolMinorVersion; uint32 ioCode1; uint32 extendedPDU; uint32 extraFlags1; capabilityLength = GET_UINT16(data, 0); /* capabilityLength */ version = GET_UINT32(data, 2); /* version */ /* osType, ignored on receipt (4 bytes) */ /* osVersion, unused and must be set to zero (4 bytes) */ /* protocolMajorVersion, must be set to 1 (2 bytes) */ protocolMinorVersion = GET_UINT16(data, 16); /* protocolMinorVersion */ ioCode1 = GET_UINT32(data, 18); /* ioCode1 */ /* ioCode2, must be set to zero, reserved for future use (4 bytes) */ extendedPDU = GET_UINT32(data, 26); /* extendedPDU */ extraFlags1 = GET_UINT32(data, 30); /* extraFlags1 */ /* extraFlags2, must be set to zero, reserved for future use (4 bytes) */ /* * SpecialTypeDeviceCap (4 bytes): * present when GENERAL_CAPABILITY_VERSION_02 is used */ if (version == GENERAL_CAPABILITY_VERSION_02) { uint32 specialTypeDeviceCap; specialTypeDeviceCap = GET_UINT32(data, 34); } return (int)capabilityLength; }
void xf_decode_data(xfInfo * xfi, uint8 * data, int data_size) { uint16 cmdType; uint32 bitmapDataLength; int destLeft; int destTop; int size; while (data_size > 0) { cmdType = GET_UINT16(data, 0); switch (cmdType) { case CMDTYPE_SET_SURFACE_BITS: case CMDTYPE_STREAM_SURFACE_BITS: destLeft = GET_UINT16(data, 2); destTop = GET_UINT16(data, 4); bitmapDataLength = GET_UINT32(data, 18); xf_decode_frame(xfi, destLeft, destTop, data + 22, bitmapDataLength); size = 22 + bitmapDataLength; break; case CMDTYPE_FRAME_MARKER: size = 8; break; default: printf("xf_decode_data: unknown cmdType %d\n", cmdType); size = 2; break; } data_size -= size; data += size; } }
static int thread_process_message(rdpsndPlugin * plugin, char * data, int data_size) { int opcode; int size; static int wave_error = 0; if (plugin->expectingWave) { if (!wave_error) thread_process_message_wave(plugin, data, data_size); plugin->expectingWave = 0; return 0; } opcode = GET_UINT8(data, 0); size = GET_UINT16(data, 2); LLOGLN(10, ("thread_process_message: data_size %d opcode %d size %d", data_size, opcode, size)); switch (opcode) { case SNDC_FORMATS: thread_process_message_formats(plugin, data + 4, size); break; case SNDC_TRAINING: thread_process_message_training(plugin, data + 4, size); break; case SNDC_WAVE: if (!wave_error) wave_error = thread_process_message_wave_info(plugin, data + 4, size); break; case SNDC_CLOSE: thread_process_message_close(plugin, data + 4, size); wave_error = 0; break; case SNDC_SETVOLUME: thread_process_message_setvolume(plugin, data + 4, size); break; case 0: /* wave PDU: ignoring it since it is received only if wave_error == 1*/ break; default: LLOGLN(0, ("thread_process_message: unknown opcode")); break; } return 0; }
void gtk_icon_cache_add_icons (GtkIconCache *cache, const gchar *directory, GHashTable *hash_table) { int directory_index; guint32 hash_offset, n_buckets; guint32 chain_offset; guint32 image_list_offset, n_images; int i, j; directory_index = get_directory_index (cache, directory); if (directory_index == -1) return; hash_offset = GET_UINT32 (cache->buffer, 4); n_buckets = GET_UINT32 (cache->buffer, hash_offset); for (i = 0; i < n_buckets; i++) { chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * i); while (chain_offset != 0xffffffff) { guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4); gchar *name = cache->buffer + name_offset; image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8); n_images = GET_UINT32 (cache->buffer, image_list_offset); for (j = 0; j < n_images; j++) { if (GET_UINT16 (cache->buffer, image_list_offset + 4 + 8 * j) == directory_index) g_hash_table_insert (hash_table, name, NULL); } chain_offset = GET_UINT32 (cache->buffer, chain_offset); } } }
gboolean gtk_icon_cache_has_icons (GtkIconCache *cache, const gchar *directory) { int directory_index; guint32 hash_offset, n_buckets; guint32 chain_offset; guint32 image_list_offset, n_images; int i, j; directory_index = get_directory_index (cache, directory); if (directory_index == -1) return FALSE; hash_offset = GET_UINT32 (cache->buffer, 4); n_buckets = GET_UINT32 (cache->buffer, hash_offset); for (i = 0; i < n_buckets; i++) { chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * i); while (chain_offset != 0xffffffff) { image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8); n_images = GET_UINT32 (cache->buffer, image_list_offset); for (j = 0; j < n_images; j++) { if (GET_UINT16 (cache->buffer, image_list_offset + 4 + 8 * j) == directory_index) return TRUE; } chain_offset = GET_UINT32 (cache->buffer, chain_offset); } } return FALSE; }
static uint32 get_variable_uint(int cbLen, char * data, int * pos) { uint32 val; switch (cbLen) { case 0: val = (uint32) GET_UINT8(data, *pos); *pos += 1; break; case 1: val = (uint32) GET_UINT16(data, *pos); *pos += 2; break; default: val = (uint32) GET_UINT32(data, *pos); *pos += 4; break; } return val; }
GtkIconData * _gtk_icon_cache_get_icon_data (GtkIconCache *cache, const gchar *icon_name, gint directory_index) { guint32 offset, image_data_offset, meta_data_offset; GtkIconData *data; int i; offset = find_image_offset (cache, icon_name, directory_index); if (!offset) return NULL; image_data_offset = GET_UINT32 (cache->buffer, offset + 4); if (!image_data_offset) return NULL; meta_data_offset = GET_UINT32 (cache->buffer, image_data_offset + 4); if (!meta_data_offset) return NULL; data = g_slice_new0 (GtkIconData); data->ref = 1; offset = GET_UINT32 (cache->buffer, meta_data_offset); if (offset) { data->has_embedded_rect = TRUE; data->x0 = GET_UINT16 (cache->buffer, offset); data->y0 = GET_UINT16 (cache->buffer, offset + 2); data->x1 = GET_UINT16 (cache->buffer, offset + 4); data->y1 = GET_UINT16 (cache->buffer, offset + 6); } offset = GET_UINT32 (cache->buffer, meta_data_offset + 4); if (offset) { data->n_attach_points = GET_UINT32 (cache->buffer, offset); data->attach_points = g_new (GdkPoint, data->n_attach_points); for (i = 0; i < data->n_attach_points; i++) { data->attach_points[i].x = GET_UINT16 (cache->buffer, offset + 4 + 4 * i); data->attach_points[i].y = GET_UINT16 (cache->buffer, offset + 4 + 4 * i + 2); } } offset = GET_UINT32 (cache->buffer, meta_data_offset + 8); if (offset) { gint n_names; gchar *lang, *name; gchar **langs; GHashTable *table = g_hash_table_new (g_str_hash, g_str_equal); n_names = GET_UINT32 (cache->buffer, offset); for (i = 0; i < n_names; i++) { lang = cache->buffer + GET_UINT32 (cache->buffer, offset + 4 + 8 * i); name = cache->buffer + GET_UINT32 (cache->buffer, offset + 4 + 8 * i + 4); g_hash_table_insert (table, lang, name); } langs = (gchar **)g_get_language_names (); for (i = 0; langs[i]; i++) { name = g_hash_table_lookup (table, langs[i]); if (name) { data->display_name = g_strdup (name); break; } } g_hash_table_destroy (table); } return data; }
int tsmf_codec_parse_media_type(TS_AM_MEDIA_TYPE * mediatype, const uint8 * pMediaType) { uint32 cbFormat; const uint8 * pFormat; int i; int ret = 0; memset(mediatype, 0, sizeof(TS_AM_MEDIA_TYPE)); LLOG(0, ("MajorType: ")); tsmf_print_guid(pMediaType); for (i = 0; tsmf_major_type_map[i].type != TSMF_MAJOR_TYPE_UNKNOWN; i++) { if (memcmp(tsmf_major_type_map[i].guid, pMediaType, 16) == 0) break; } mediatype->MajorType = tsmf_major_type_map[i].type; if (mediatype->MajorType == TSMF_MAJOR_TYPE_UNKNOWN) ret = 1; LLOGLN(0, (" (%s)", tsmf_major_type_map[i].name)); LLOG(0, ("SubType: ")); tsmf_print_guid(pMediaType + 16); for (i = 0; tsmf_sub_type_map[i].type != TSMF_SUB_TYPE_UNKNOWN; i++) { if (memcmp(tsmf_sub_type_map[i].guid, pMediaType + 16, 16) == 0) break; } mediatype->SubType = tsmf_sub_type_map[i].type; if (mediatype->SubType == TSMF_SUB_TYPE_UNKNOWN) ret = 1; LLOGLN(0, (" (%s)", tsmf_sub_type_map[i].name)); LLOG(0, ("FormatType: ")); tsmf_print_guid(pMediaType + 44); for (i = 0; tsmf_format_type_map[i].type != TSMF_FORMAT_TYPE_UNKNOWN; i++) { if (memcmp(tsmf_format_type_map[i].guid, pMediaType + 44, 16) == 0) break; } mediatype->FormatType = tsmf_format_type_map[i].type; if (mediatype->FormatType == TSMF_FORMAT_TYPE_UNKNOWN) ret = 1; LLOGLN(0, (" (%s)", tsmf_format_type_map[i].name)); cbFormat = GET_UINT32(pMediaType, 60); LLOGLN(0, ("tsmf_stream_set_format: cbFormat %d", cbFormat)); pFormat = pMediaType + 64; for (i = 0; i < cbFormat; i++) { LLOG(0, ("%02X ", pFormat[i])); if (i % 16 == 15) LLOG(0, ("\n")); } LLOG(0, ("\n")); switch (mediatype->FormatType) { case TSMF_FORMAT_TYPE_MFVIDEOFORMAT: /* http://msdn.microsoft.com/en-us/library/aa473808.aspx */ /* MFVIDEOFORMAT.videoInfo.dwWidth */ mediatype->Width = GET_UINT32(pFormat, 8); /* MFVIDEOFORMAT.videoInfo.dwHeight */ mediatype->Height = GET_UINT32(pFormat, 12); /* MFVIDEOFORMAT.compressedInfo.AvgBitrate */ mediatype->BitRate = GET_UINT32(pFormat, 136); /* MFVIDEOFORMAT.videoInfo.FramesPerSecond */ mediatype->SamplesPerSecond.Numerator = GET_UINT32(pFormat, 48); mediatype->SamplesPerSecond.Denominator = GET_UINT32(pFormat, 52); if (cbFormat > 176) { mediatype->ExtraDataSize = cbFormat - 176; mediatype->ExtraData = pFormat + 176; } break; case TSMF_FORMAT_TYPE_WAVEFORMATEX: /* http://msdn.microsoft.com/en-us/library/dd757720.aspx */ mediatype->Channels = GET_UINT16(pFormat, 2); mediatype->SamplesPerSecond.Numerator = GET_UINT32(pFormat, 4); mediatype->SamplesPerSecond.Denominator = 1; mediatype->BitRate = GET_UINT32(pFormat, 8) * 8; mediatype->BlockAlign = GET_UINT16(pFormat, 12); mediatype->BitsPerSample = GET_UINT16(pFormat, 14); mediatype->ExtraDataSize = GET_UINT16(pFormat, 16); if (mediatype->ExtraDataSize > 0) mediatype->ExtraData = pFormat + 18; break; case TSMF_FORMAT_TYPE_MPEG2VIDEOINFO: /* http://msdn.microsoft.com/en-us/library/dd390707.aspx */ i = tsmf_codec_parse_VIDEOINFOHEADER2(mediatype, pFormat); i += tsmf_codec_parse_BITMAPINFOHEADER(mediatype, pFormat + i); if (cbFormat > i) { mediatype->ExtraDataSize = cbFormat - i; mediatype->ExtraData = pFormat + i; } break; case TSMF_FORMAT_TYPE_VIDEOINFO2: i = tsmf_codec_parse_VIDEOINFOHEADER2(mediatype, pFormat); tsmf_codec_parse_BITMAPINFOHEADER(mediatype, pFormat + i); i += 40; /* Skip only BITMAPINFOHEADER */ if (cbFormat > i) { mediatype->ExtraDataSize = cbFormat - i; mediatype->ExtraData = pFormat + i; } break; default: break; } if (mediatype->SamplesPerSecond.Numerator == 0) mediatype->SamplesPerSecond.Numerator = 1; if (mediatype->SamplesPerSecond.Denominator == 0) mediatype->SamplesPerSecond.Denominator = 1; return ret; }
static int audin_process_formats(IWTSVirtualChannelCallback * pChannelCallback, char * data, uint32 data_size) { AUDIN_CHANNEL_CALLBACK * callback = (AUDIN_CHANNEL_CALLBACK *) pChannelCallback; uint32 NumFormats; uint32 i; int size; int out_size; char * ldata; char * out_data; char * lout_formats; int out_format_count; int error; NumFormats = GET_UINT32(data, 0); if ((NumFormats < 1) || (NumFormats > 1000)) { LLOGLN(0, ("audin_process_formats: bad NumFormats %d", NumFormats)); return 1; } /* Ignore cbSizeFormatsPacket */ size = sizeof(char *) * (NumFormats + 1); callback->formats_data = (char **) malloc(size); memset(callback->formats_data, 0, size); out_size = data_size + 1; out_data = (char *) malloc(out_size); memset(out_data, 0, out_size); lout_formats = out_data + 9; /* remainder is sndFormats (variable) */ ldata = data + 8; out_format_count = 0; for (i = 0; i < NumFormats; i++) { size = 18 + GET_UINT16(ldata, 16); if (wave_in_format_supported(callback->device_data, ldata, size)) { /* Store the agreed format in the corresponding index */ callback->formats_data[out_format_count] = (char *) malloc(size); memcpy(callback->formats_data[out_format_count], ldata, size); /* Put the format to output buffer */ memcpy(lout_formats, ldata, size); lout_formats += size; out_format_count++; } ldata += size; } callback->formats_count = out_format_count; audin_send_incoming_data_pdu(pChannelCallback); /* cbSizeFormatsPacket: the size of the entire PDU minus the size of ExtraData */ size = lout_formats - out_data; SET_UINT8(out_data, 0, MSG_SNDIN_FORMATS); SET_UINT32(out_data, 1, out_format_count); SET_UINT32(out_data, 5, size); error = callback->channel->Write(callback->channel, size, out_data, NULL); free(out_data); return error; }
int s3g_command_read_ext(s3g_context_t *ctx, s3g_command_t *cmd, unsigned char *buf, size_t maxbuf, size_t *buflen) { unsigned char *buf0 = buf; ssize_t bytes_expected, bytes_read; s3g_command_info_t *ct; s3g_command_t dummy; foo_16_t f16; foo_32_t f32; int iret; uint8_t ui8arg; iret = -1; if (buflen) *buflen = 0; // We have to have a read context // We don't need a command context to return the command in if (!ctx || !buf || maxbuf == 0) { fprintf(stderr, "s3g_command_get(%d): Invalid call; ctx=%p, buf=%p, " "maxbuf=%lu\n", __LINE__, (void *)ctx, (void *)buf, maxbuf); errno = EINVAL; return(-1); } else if (!ctx->read) { fprintf(stderr, "s3g_command_get(%d): Invalid context; " "ctx->read=NULL\n", __LINE__); errno = EINVAL; return(-1); } else if (!buf || maxbuf == 0) { fprintf(stderr, "s3g_command_get(%d): Invalid context; " "ctx->read=NULL\n", __LINE__); errno = EINVAL; return(-1); } // Initialize command table s3g_init(); if (1 != (bytes_expected = (*ctx->read)(ctx->r_ctx, buf0, maxbuf, 1))) { // End of file condition? if (bytes_expected == 0) return(1); // EOF fprintf(stderr, "s3g_command_get(%d): Error while reading from the s3g file; " "%s (%d)\n", __LINE__, strerror(errno), errno); return(-1); } ct = command_table + buf0[0]; // &command_table[buf0[0]] buf += 1; maxbuf -= 1; if (!cmd) cmd = &dummy; cmd->cmd_id = ct->cmd_id; cmd->cmd_desc = ct->cmd_desc; cmd->cmd_len = ct->cmd_len; cmd->cmd_raw_len = 0; if (ct->cmd_desc == NULL) { fprintf(stderr, "s3g_command_get(%d): Unrecognized command, %d\n", __LINE__, buf0[0]); goto done; } #define GET_INT32(v) \ if (maxbuf < 4) goto trunc; \ if (4 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 4))) \ goto io_error; \ memcpy(&f32.u.c, buf, 4); \ buf += bytes_read; \ maxbuf -= bytes_read; \ cmd->t.v = f32.u.i #define GET_UINT32(v) \ if (maxbuf < 4) goto trunc; \ if (4 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 4))) \ goto io_error; \ memcpy(&f32.u.c, buf, 4); \ buf += bytes_read; \ maxbuf -= bytes_read; \ cmd->t.v = f32.u.u #define GET_FLOAT32(v) \ if (maxbuf < 4) goto trunc; \ if (4 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 4))) \ goto io_error; \ memcpy(&f32.u.c, buf, 4); \ buf += bytes_read; \ maxbuf -= bytes_read; \ cmd->t.v = f32.u.f; #define GET_UINT8(v) \ if (maxbuf < 1) goto trunc; \ if (1 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 1))) \ goto io_error; \ ui8arg = buf[0]; \ buf += bytes_read; \ maxbuf -= bytes_read; \ cmd->t.v = ui8arg #define GET_INT16(v) \ if (maxbuf < 2) goto trunc; \ if (2 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 2))) \ goto io_error; \ memcpy(&f16.u.c, buf, 2); \ buf += bytes_read; \ maxbuf -= bytes_read; \ cmd->t.v = f16.u.i #define GET_UINT16(v) \ if (maxbuf < 2) goto trunc; \ if (2 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 2))) \ goto io_error; \ memcpy(&f16.u.c, buf, 2); \ buf += bytes_read; \ maxbuf -= bytes_read; \ cmd->t.v = f16.u.u #define ZERO(v,c) cmd->t.v = (c)0 switch(cmd->cmd_id) { case HOST_CMD_DELAY : GET_UINT32(delay.millis); break; case HOST_CMD_FIND_AXES_MINIMUM : case HOST_CMD_FIND_AXES_MAXIMUM : GET_UINT8(find_axes_minmax.flags); GET_UINT32(find_axes_minmax.feedrate); GET_UINT16(find_axes_minmax.timeout); break; case HOST_CMD_WAIT_FOR_TOOL : GET_UINT8(wait_for_tool.index); GET_UINT16(wait_for_tool.ping_delay); GET_UINT16(wait_for_tool.timeout); break; case HOST_CMD_WAIT_FOR_PLATFORM : GET_UINT8(wait_for_platform.index); GET_UINT16(wait_for_platform.ping_delay); GET_UINT16(wait_for_platform.timeout); break; case HOST_CMD_STORE_HOME_POSITION : GET_UINT8(store_home_position.axes); break; case HOST_CMD_RECALL_HOME_POSITION : GET_UINT8(recall_home_position.axes); break; default : // Just read the data bytes_expected = (ssize_t)(ct->cmd_len & 0x7fffffff); if ((bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, ct->cmd_len)) != bytes_expected) goto io_error; buf += bytes_read; maxbuf -= bytes_read; break; case HOST_CMD_TOOL_COMMAND : // This command is VERY MBI specific if ((ssize_t)3 != (*ctx->read)(ctx->r_ctx, buf, maxbuf, 3)) goto io_error; if (cmd) cmd->cmd_len = (size_t)buf[2]; cmd->t.tool.subcmd_id = buf[1]; cmd->t.tool.index = buf[0]; cmd->t.tool.subcmd_len = bytes_expected = (ssize_t)buf[2]; if ((bytes_read = (*ctx->read)(ctx->r_ctx, buf + 3, maxbuf - 3, (size_t)buf[2])) != bytes_expected) goto io_error; if (cmd->t.tool.subcmd_len == 1) cmd->t.tool.subcmd_value = (uint16_t)buf[3]; else if (cmd->t.tool.subcmd_len > 1) memcpy((void *)&cmd->t.tool.subcmd_value, buf + 3, sizeof(uint16_t)); else cmd->t.tool.subcmd_value = 0; maxbuf -= 3 + bytes_read; buf += 3 + bytes_read; cmd->t.tool.subcmd_desc = tool_command_table[cmd->t.tool.subcmd_id].cmd_desc; if (cmd->t.tool.subcmd_desc == NULL) cmd->t.tool.subcmd_desc = "unknown tool subcommand"; break; case HOST_CMD_SET_POSITION_EXT : // x4, y4, z4, a4, b4 = 20 bytes GET_INT32(set_position_ext.x); GET_INT32(set_position_ext.y); GET_INT32(set_position_ext.z); GET_INT32(set_position_ext.a); GET_INT32(set_position_ext.b); break; case HOST_CMD_QUEUE_POINT_EXT : // x4, y4, z4, a4, b4, dda4 = 24 bytes GET_INT32(queue_point_ext.x); GET_INT32(queue_point_ext.y); GET_INT32(queue_point_ext.z); GET_INT32(queue_point_ext.a); GET_INT32(queue_point_ext.b); GET_INT32(queue_point_ext.dda); ZERO(queue_point_ext.dummy_rel, uint8_t); ZERO(queue_point_ext.dummy_distance, float); ZERO(queue_point_ext.dummy_feedrate_mult_64, uint16_t); break; case HOST_CMD_QUEUE_POINT_NEW : // x4, y4, z4, a4, b4, us4, relative = 25 bytes GET_INT32(queue_point_new.x); GET_INT32(queue_point_new.y); GET_INT32(queue_point_new.z); GET_INT32(queue_point_new.a); GET_INT32(queue_point_new.b); GET_INT32(queue_point_new.us); GET_UINT8(queue_point_new.rel); ZERO(queue_point_ext.dummy_distance, float); ZERO(queue_point_ext.dummy_feedrate_mult_64, uint16_t); break; case HOST_CMD_QUEUE_POINT_NEW_EXT : // x4, y4, z4, a4, b4, dda_rate4, relative, distance 4, feedrate_mult64 2 = 31 bytes GET_INT32(queue_point_new_ext.x); GET_INT32(queue_point_new_ext.y); GET_INT32(queue_point_new_ext.z); GET_INT32(queue_point_new_ext.a); GET_INT32(queue_point_new_ext.b); GET_INT32(queue_point_new_ext.dda_rate); GET_UINT8(queue_point_new_ext.rel); GET_FLOAT32(queue_point_new_ext.distance); GET_INT16(queue_point_new_ext.feedrate_mult_64); break; case HOST_CMD_SET_POT_VALUE : GET_UINT8(digi_pot.axis); GET_UINT8(digi_pot.value); break; case HOST_CMD_SET_RGB_LED : GET_UINT8(rgb_led.red); GET_UINT8(rgb_led.green); GET_UINT8(rgb_led.blue); GET_UINT8(rgb_led.blink_rate); GET_UINT8(rgb_led.effect); break; case HOST_CMD_SET_BEEP : GET_UINT16(beep.frequency); GET_UINT16(beep.duration); GET_UINT8(beep.effect); break; case HOST_CMD_PAUSE_FOR_BUTTON : GET_UINT8(button_pause.mask); GET_UINT16(button_pause.timeout); GET_UINT8(button_pause.timeout_behavior); break; case HOST_CMD_DISPLAY_MESSAGE : GET_UINT8(display_message.options); GET_UINT8(display_message.x); GET_UINT8(display_message.y); GET_UINT8(display_message.timeout); cmd->t.display_message.message_len = 0; if (maxbuf < 1) goto trunc; for (;;) { unsigned char uc; if (1 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 1))) goto io_error; uc = buf[0]; ++buf; --maxbuf; if (uc == '\0') break; if (cmd->t.display_message.message_len < (sizeof(cmd->t.display_message.message) - 1)) cmd->t.display_message.message[cmd->t.display_message.message_len++] = uc; if (maxbuf < 1) goto trunc; } cmd->t.display_message.message[cmd->t.display_message.message_len] = '\0'; break; case HOST_CMD_SET_BUILD_PERCENT : GET_UINT8(build_percentage.percentage); GET_UINT8(build_percentage.reserved); break; case HOST_CMD_QUEUE_SONG : GET_UINT8(queue_song.song_id); break; case HOST_CMD_RESET_TO_FACTORY : GET_UINT8(factory_reset.options); break; case HOST_CMD_BUILD_START_NOTIFICATION : GET_INT32(build_start.steps); cmd->t.build_start.message_len = 0; if (maxbuf < 1) goto trunc; for (;;) { unsigned char uc; if (1 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 1))) goto io_error; uc = buf[0]; ++buf; --maxbuf; if (uc == '\0') break; if (cmd->t.build_start.message_len < (sizeof(cmd->t.build_start.message) - 1)) cmd->t.build_start.message[cmd->t.build_start.message_len++] = uc; } cmd->t.build_start.message[cmd->t.build_start.message_len] = '\0'; break; case HOST_CMD_BUILD_END_NOTIFICATION : GET_UINT8(build_end.flags); break; case HOST_CMD_CHANGE_TOOL : GET_UINT8(change_tool.index); break; case HOST_CMD_ENABLE_AXES : GET_UINT8(enable_axes.axes); break; case HOST_CMD_SET_ACCELERATION_TOGGLE: GET_UINT8(set_segment_acceleration.s); break; case HOST_CMD_STREAM_VERSION: GET_UINT8(x3g_version.version_high); GET_UINT8(x3g_version.version_low); GET_UINT8(x3g_version.reserved1); GET_UINT32(x3g_version.reserved2); GET_UINT16(x3g_version.bot_type); GET_UINT16(x3g_version.reserved3); GET_UINT32(x3g_version.reserved4); GET_UINT32(x3g_version.reserved5); GET_UINT8(x3g_version.reserved6); break; } #undef ZERO #undef GET_UINT8 #undef GET_INT32 iret = 0; goto done; io_error: fprintf(stderr, "s3g_command_get(%d): Error while reading from the s3g file; " "%s (%d)\n", __LINE__, strerror(errno), errno); iret = -1; goto done; trunc: fprintf(stderr, "s3g_command_get(%d): Caller supplied read buffer is too small", __LINE__); iret = -1; done: cmd->cmd_raw_len = (size_t)(buf - buf0); if (buflen) *buflen = cmd->cmd_raw_len; return(iret); }
static int rdpsnd_pulse_set_format(rdpsndDevicePlugin * devplugin, char * snd_format, int size) { struct pulse_device_data * pulse_data; pa_sample_spec sample_spec = { 0 }; int nChannels; int wBitsPerSample; int nSamplesPerSec; int wFormatTag; int nBlockAlign; pulse_data = (struct pulse_device_data *) devplugin->device_data; if (!pulse_data->context) return 1; wFormatTag = GET_UINT16(snd_format, 0); nChannels = GET_UINT16(snd_format, 2); nSamplesPerSec = GET_UINT32(snd_format, 4); nBlockAlign = GET_UINT16(snd_format, 12); wBitsPerSample = GET_UINT16(snd_format, 14); LLOGLN(0, ("rdpsnd_pulse_set_format: wFormatTag=%d nChannels=%d " "nSamplesPerSec=%d wBitsPerSample=%d nBlockAlign=%d", wFormatTag, nChannels, nSamplesPerSec, wBitsPerSample, nBlockAlign)); sample_spec.rate = nSamplesPerSec; sample_spec.channels = nChannels; switch (wFormatTag) { case 1: /* PCM */ switch (wBitsPerSample) { case 8: sample_spec.format = PA_SAMPLE_U8; break; case 16: sample_spec.format = PA_SAMPLE_S16LE; break; } break; case 6: /* A-LAW */ sample_spec.format = PA_SAMPLE_ALAW; break; case 7: /* U-LAW */ sample_spec.format = PA_SAMPLE_ULAW; break; case 0x11: /* IMA ADPCM */ sample_spec.format = PA_SAMPLE_S16LE; break; } pulse_data->sample_spec = sample_spec; pulse_data->format = wFormatTag; pulse_data->block_size = nBlockAlign; if (pulse_data->stream) { pa_threaded_mainloop_lock(pulse_data->mainloop); pa_stream_disconnect(pulse_data->stream); pa_stream_unref(pulse_data->stream); pulse_data->stream = NULL; pa_threaded_mainloop_unlock(pulse_data->mainloop); } rdpsnd_pulse_open(devplugin); return 0; }
/* called by worker thread receives a list of server supported formats and returns a list of client supported formats */ static int thread_process_message_formats(rdpsndPlugin * plugin, char * data, int data_size) { int index; int format_count; int out_format_count; int out_format_size; int size; int flags; int version; char * ldata; char * out_data; char * out_formats; char * lout_formats; uint32 error; /* skip: dwFlags (4 bytes), dwVolume (4 bytes), dwPitch (4 bytes), wDGramPort (2 bytes) */ format_count = GET_UINT16(data, 14); /* wNumberOfFormats */ if ((format_count < 1) || (format_count > 1000)) { LLOGLN(0, ("thread_process_message_formats: bad format_count %d", format_count)); return 1; } plugin->cBlockNo = GET_UINT8(data, 16); /* cLastBlockConfirmed */ version = GET_UINT16(data, 17); /* wVersion */ if (version < 2) { LLOGLN(0, ("thread_process_message_formats: warning, old server")); } LLOGLN(0, ("thread_process_message_formats: version %d", version)); /* skip: bPad (1 byte) */ /* setup output buffer */ size = 32 + data_size; out_data = (char *) malloc(size); out_formats = out_data + 24; lout_formats = out_formats; /* remainder is sndFormats (variable) */ ldata = data + 20; out_format_count = 0; for (index = 0; index < format_count; index++) { size = 18 + GET_UINT16(ldata, 16); if (plugin->device_plugin && plugin->device_plugin->format_supported(plugin->device_plugin, ldata, size)) { memcpy(lout_formats, ldata, size); lout_formats += size; out_format_count++; } ldata += size; } out_format_size = (int) (lout_formats - out_formats); if ((out_format_size > 0) && (out_format_count > 0)) { plugin->supported_formats = (char *) malloc(out_format_size); memcpy(plugin->supported_formats, out_formats, out_format_size); plugin->supported_formats_size = out_format_size; } else { LLOGLN(0, ("thread_process_message_formats: error, " "no formats supported")); } size = 24 + out_format_size; SET_UINT8(out_data, 0, SNDC_FORMATS); /* Header (4 bytes) */ SET_UINT8(out_data, 1, 0); SET_UINT16(out_data, 2, size - 4); flags = TSSNDCAPS_ALIVE | TSSNDCAPS_VOLUME; SET_UINT32(out_data, 4, flags); /* dwFlags */ SET_UINT32(out_data, 8, 0xffffffff); /* dwVolume */ SET_UINT32(out_data, 12, 0); /* dwPitch */ SET_UINT16(out_data, 16, 0); /* wDGramPort */ SET_UINT16(out_data, 18, out_format_count); /* wNumberOfFormats */ SET_UINT8(out_data, 20, 0); /* cLastBlockConfirmed */ SET_UINT16(out_data, 21, 2); /* wVersion */ SET_UINT8(out_data, 23, 0); /* bPad */ error = plugin->ep.pVirtualChannelWrite(plugin->open_handle, out_data, size, out_data); if (error != CHANNEL_RC_OK) { LLOGLN(0, ("thread_process_message_formats: " "VirtualChannelWrite " "failed %d", error)); return 1; } if (version >= 6) { size = 8; out_data = (char *) malloc(size); SET_UINT8(out_data, 0, SNDC_QUALITYMODE); /* Header (4 bytes) */ SET_UINT8(out_data, 1, 0); SET_UINT16(out_data, 2, size - 4); SET_UINT16(out_data, 4, 2); /* HIGH_QUALITY */ SET_UINT16(out_data, 6, 0); /* Reserved (2 bytes) */ error = plugin->ep.pVirtualChannelWrite(plugin->open_handle, out_data, size, out_data); if (error != CHANNEL_RC_OK) { LLOGLN(0, ("thread_process_message_formats: " "VirtualChannelWrite " "failed %d", error)); return 1; } } return 0; }