static void rdpsnd_process_message_wave_info(rdpsndPlugin* rdpsnd, STREAM* data_in, uint16 BodySize) { uint16 wFormatNo; stream_read_uint16(data_in, rdpsnd->wTimeStamp); stream_read_uint16(data_in, wFormatNo); stream_read_uint8(data_in, rdpsnd->cBlockNo); stream_seek(data_in, 3); /* bPad */ stream_read(data_in, rdpsnd->waveData, 4); rdpsnd->waveDataSize = BodySize - 8; rdpsnd->wave_timestamp = get_mstime(); rdpsnd->expectingWave = true; DEBUG_SVC("waveDataSize %d wFormatNo %d", rdpsnd->waveDataSize, wFormatNo); rdpsnd->close_timestamp = 0; if (!rdpsnd->is_open) { rdpsnd->current_format = wFormatNo; rdpsnd->is_open = true; if (rdpsnd->device) IFCALL(rdpsnd->device->Open, rdpsnd->device, &rdpsnd->supported_formats[wFormatNo], rdpsnd->latency); } else if (wFormatNo != rdpsnd->current_format) { rdpsnd->current_format = wFormatNo; if (rdpsnd->device) IFCALL(rdpsnd->device->SetFormat, rdpsnd->device, &rdpsnd->supported_formats[wFormatNo], rdpsnd->latency); } }
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; }
void PlayVideo::play() { MediaPacket *pkt; int now_time; int sleep_time; int last_display_time; last_display_time = 0; while (1) { sendMutex->lock(); if (videoQueue->isEmpty()) { sendMutex->unlock(); usleep(10 * 1000); continue; } pkt = videoQueue->dequeue(); send_video_pkt(channel, stream_id, pkt->av_pkt); sendMutex->unlock(); now_time = get_mstime(); sleep_time = now_time - last_display_time; if (sleep_time > (1000 / fps)) { sleep_time = (1000 / fps); } if (sleep_time > 0) { usleep(sleep_time * 1000); } last_display_time = now_time; delete pkt; } }
static void rdpsnd_process_message_close(rdpsndPlugin* rdpsnd) { DEBUG_SVC("server closes."); if (rdpsnd->device) IFCALL(rdpsnd->device->Start, rdpsnd->device); rdpsnd->close_timestamp = get_mstime() + 2000; rdpsnd->plugin.interval_ms = 10; }
/* process the linked list of data that has queued to be sent */ static void rdpsnd_process_interval(rdpSvcPlugin* plugin) { rdpsndPlugin* rdpsnd = (rdpsndPlugin*)plugin; struct data_out_item* item; uint32 cur_time; while (list_size(rdpsnd->data_out_list) > 0) { item = (struct data_out_item*)list_peek(rdpsnd->data_out_list) ; cur_time = get_mstime(); if (!item || cur_time <= item->out_timestamp) break; item = (struct data_out_item*)list_dequeue(rdpsnd->data_out_list); svc_plugin_send(plugin, item->data_out); xfree(item); DEBUG_SVC("processed data_out"); } if (rdpsnd->is_open && rdpsnd->close_timestamp > 0) { cur_time = get_mstime(); if (cur_time > rdpsnd->close_timestamp) { if (rdpsnd->device) IFCALL(rdpsnd->device->Close, rdpsnd->device); rdpsnd->is_open = false; rdpsnd->close_timestamp = 0; DEBUG_SVC("processed close"); } } if (list_size(rdpsnd->data_out_list) == 0 && !rdpsnd->is_open) { rdpsnd->plugin.interval_ms = 0; } }
/* process the linked list of data that has queued to be sent */ static int thread_process_data_out(rdpsndPlugin * plugin) { char * data; int data_size; struct data_out_item * item; uint32 cur_time; uint32 error; LLOGLN(10, ("thread_process_data_out: ")); while (1) { if (wait_obj_is_set(plugin->term_event)) { break; } if (plugin->out_list_head == 0) { break; } cur_time = get_mstime(); if (cur_time <= plugin->out_list_head->out_time_stamp) { break; } data = plugin->out_list_head->data; data_size = plugin->out_list_head->data_size; item = plugin->out_list_head; plugin->out_list_head = plugin->out_list_head->next; if (plugin->out_list_head == 0) { plugin->out_list_tail = 0; } error = plugin->ep.pVirtualChannelWrite(plugin->open_handle, data, data_size, data); if (error != CHANNEL_RC_OK) { LLOGLN(0, ("thread_process_data_out: " "VirtualChannelWrite " "failed %d", error)); } LLOGLN(10, ("thread_process_data_out: confirm sent")); if (item != 0) { free(item); } } return 0; }
/* header is not removed from data in this function */ static void rdpsnd_process_message_wave(rdpsndPlugin* rdpsnd, STREAM* data_in) { uint16 wTimeStamp; uint32 delay_ms; uint32 process_ms; struct data_out_item* item; rdpsnd->expectingWave = 0; memcpy(stream_get_head(data_in), rdpsnd->waveData, 4); if (stream_get_size(data_in) != rdpsnd->waveDataSize) { DEBUG_WARN("size error"); return; } if (rdpsnd->device) IFCALL(rdpsnd->device->Play, rdpsnd->device, stream_get_head(data_in), stream_get_size(data_in)); process_ms = get_mstime() - rdpsnd->wave_timestamp; delay_ms = 250; wTimeStamp = rdpsnd->wTimeStamp + delay_ms; DEBUG_SVC("data_size %d delay_ms %u process_ms %u", stream_get_size(data_in), delay_ms, process_ms); item = xnew(struct data_out_item); item->data_out = stream_new(8); stream_write_uint8(item->data_out, SNDC_WAVECONFIRM); stream_write_uint8(item->data_out, 0); stream_write_uint16(item->data_out, 4); stream_write_uint16(item->data_out, wTimeStamp); stream_write_uint8(item->data_out, rdpsnd->cBlockNo); /* cConfirmedBlockNo */ stream_write_uint8(item->data_out, 0); /* bPad */ item->out_timestamp = rdpsnd->wave_timestamp + delay_ms; list_enqueue(rdpsnd->data_out_list, item); rdpsnd->plugin.interval_ms = 10; }
/* header is not removed from data in this function */ static int thread_process_message_wave(rdpsndPlugin * plugin, char * data, int data_size) { int size; int wTimeStamp; char * out_data; uint32 process_ms; plugin->expectingWave = 0; memcpy(data, plugin->waveData, 4); if (data_size != plugin->waveDataSize) { LLOGLN(0, ("thread_process_message_wave: " "size error")); } if (plugin->device_plugin) plugin->device_plugin->play(plugin->device_plugin, data, data_size); size = 8; out_data = (char *) malloc(size); SET_UINT8(out_data, 0, SNDC_WAVECONFIRM); SET_UINT8(out_data, 1, 0); SET_UINT16(out_data, 2, size - 4); process_ms = get_mstime() - plugin->local_time_stamp; plugin->delay_ms = 250; LLOGLN(10, ("thread_process_message_wave: " "data_size %d delay_ms %d process_ms %u", data_size, plugin->delay_ms, process_ms)); wTimeStamp = plugin->wTimeStamp + plugin->delay_ms; SET_UINT16(out_data, 4, wTimeStamp); SET_UINT8(out_data, 6, plugin->cBlockNo); SET_UINT8(out_data, 7, 0); plugin->data_out = out_data; plugin->data_out_size = size; queue_data_out(plugin); return 0; }