static BOOL tsmf_stream_process_ack(void* arg, BOOL force) { TSMF_STREAM* stream = arg; TSMF_SAMPLE* sample; UINT64 ack_time; BOOL rc = FALSE; if (!stream) return FALSE; Queue_Lock(stream->sample_ack_list); sample = (TSMF_SAMPLE*) Queue_Peek(stream->sample_ack_list); if (!sample) goto finally; if (!force) { ack_time = get_current_time(); if (sample->ack_time > ack_time) goto finally; } sample = Queue_Dequeue(stream->sample_ack_list); tsmf_sample_ack(sample); tsmf_sample_free(sample); finally: Queue_Unlock(stream->sample_ack_list); return rc; }
RPC_PDU* rpc_recv_dequeue_pdu(rdpRpc* rpc) { RPC_PDU* pdu; DWORD dwMilliseconds; pdu = NULL; dwMilliseconds = rpc->client->SynchronousReceive ? INFINITE : 0; if (WaitForSingleObject(Queue_Event(rpc->client->ReceiveQueue), dwMilliseconds) == WAIT_OBJECT_0) { pdu = (RPC_PDU*) Queue_Dequeue(rpc->client->ReceiveQueue); #ifdef WITH_DEBUG_TSG if (pdu) { fprintf(stderr, "Receiving PDU (length: %d, CallId: %d)\n", pdu->s->length, pdu->CallId); winpr_HexDump(Stream_Buffer(pdu->s), Stream_Length(pdu->s)); fprintf(stderr, "\n"); } #endif return pdu; } return pdu; }
// close the android audio device void android_CloseRecDevice(OPENSL_STREAM *p) { DEBUG_DVC("p=%p", p); if (p == NULL) return; if (p->queue) { while (Queue_Count(p->queue) > 0) { queue_element *e = Queue_Dequeue(p->queue); free(e->data); free(e); } Queue_Free(p->queue); } if (p->next) { free(p->next->data); free(p->next); } if (p->prep) { free(p->prep->data); free(p->prep); } openSLDestroyEngine(p); free(p); }
RPC_PDU* rpc_client_receive_pool_take(rdpRpc* rpc) { RPC_PDU* pdu = NULL; if (WaitForSingleObject(Queue_Event(rpc->client->ReceivePool), 0) == WAIT_OBJECT_0) pdu = Queue_Dequeue(rpc->client->ReceivePool); if (!pdu) { pdu = (RPC_PDU*)malloc(sizeof(RPC_PDU)); if (!pdu) return NULL; pdu->s = Stream_New(NULL, rpc->max_recv_frag); if (!pdu->s) { free(pdu); return NULL; } } pdu->CallId = 0; pdu->Flags = 0; Stream_Length(pdu->s) = 0; Stream_SetPosition(pdu->s, 0); return pdu; }
static void* serial_thread_func(void* arg) { IRP* irp; DWORD status; SERIAL_DEVICE* serial = (SERIAL_DEVICE*)arg; HANDLE ev[] = {serial->stopEvent, Queue_Event(serial->queue)}; while (1) { status = WaitForMultipleObjects(2, ev, FALSE, 1); if (WAIT_OBJECT_0 == status) break; serial->nfds = 1; FD_ZERO(&serial->read_fds); FD_ZERO(&serial->write_fds); serial->tv.tv_sec = 0; serial->tv.tv_usec = 0; serial->select_timeout = 0; if (status == WAIT_OBJECT_0 + 1) { if ((irp = (IRP*) Queue_Dequeue(serial->queue))) serial_process_irp(serial, irp); continue; } serial_check_fds(serial); } return NULL; }
RPC_PDU* rpc_recv_dequeue_pdu(rdpRpc* rpc) { RPC_PDU* pdu; DWORD dwMilliseconds; DWORD result; dwMilliseconds = rpc->client->SynchronousReceive ? SYNCHRONOUS_TIMEOUT * 4 : 0; result = WaitForSingleObject(Queue_Event(rpc->client->ReceiveQueue), dwMilliseconds); if (result == WAIT_TIMEOUT) { WLog_ERR(TAG, "timed out waiting for receive event"); return NULL; } if (result != WAIT_OBJECT_0) return NULL; pdu = (RPC_PDU*)Queue_Dequeue(rpc->client->ReceiveQueue); #ifdef WITH_DEBUG_TSG if (pdu) { WLog_DBG(TAG, "Receiving PDU (length: %d, CallId: %d)", pdu->s->length, pdu->CallId); winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(pdu->s), Stream_Length(pdu->s)); } else { WLog_DBG(TAG, "Receiving a NULL PDU"); } #endif return pdu; }
int TestQueue(int argc, char* argv[]) { int item; int index; int count; wQueue* queue; queue = Queue_New(TRUE, -1, -1); for (index = 1; index <= 10; index++) { Queue_Enqueue(queue, (void*) (size_t) index); } count = Queue_Count(queue); printf("queue count: %d\n", count); for (index = 1; index <= 10; index++) { item = (int) (size_t) Queue_Dequeue(queue); if (item != index) return -1; } Queue_Clear(queue); Queue_Free(queue); return 0; }
static void pbrpc_main_loop(pbRPCContext* context) { int status; DWORD nCount; HANDLE events[32]; rdsServer* server = g_Server; pbrpc_connect(context); while (context->isConnected) { nCount = 0; events[nCount++] = context->stopEvent; events[nCount++] = Queue_Event(context->writeQueue); events[nCount++] = context->hPipe; status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); if (status == WAIT_FAILED) { break; } if (WaitForSingleObject(context->stopEvent, 0) == WAIT_OBJECT_0) { break; } if (WaitForSingleObject(context->hPipe, 0) == WAIT_OBJECT_0) { status = pbrpc_process_message_in(server); if (status < 0) { fprintf(stderr, "Transport problem reconnecting..\n"); pbrpc_reconnect(context); continue; } } if (WaitForSingleObject(Queue_Event(context->writeQueue), 0) == WAIT_OBJECT_0) { FDSAPI_MSG_PACKET* msg = NULL; while ((msg = Queue_Dequeue(context->writeQueue))) { status = pbrpc_process_message_out(server, msg); pbrpc_message_free(msg, FALSE); } if (status < 0) { fprintf(stderr, "Transport problem reconnecting..\n"); pbrpc_reconnect(context); continue; } } } }
// this callback handler is called every time a buffer finishes playing static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void* context) { OPENSL_STREAM* p = (OPENSL_STREAM*) context; assert(p); assert(p->queue); void* data = Queue_Dequeue(p->queue); free(data); }
wStream* rpc_client_fragment_pool_take(rdpRpc* rpc) { wStream* fragment = NULL; if (WaitForSingleObject(Queue_Event(rpc->client->FragmentPool), 0) == WAIT_OBJECT_0) fragment = Queue_Dequeue(rpc->client->FragmentPool); if (!fragment) fragment = Stream_New(NULL, rpc->max_recv_frag); return fragment; }
void queueTest() { uint32_t i; char text[20]; for (i = 0; i < 30; i++) { Queue_Enqueue(&queue, sprintf(text, "Entry [%d]", i), text); Queue_Enqueue(&queue2, sprintf(text, "Entry [%d]", i), text); } printf("First queue[%d][%d]:\n", Queue_MaxQueueSize(&queue), Queue_MaxStrSize(&queue)); while (Queue_HasNext(&queue)) printf("%s\n", Queue_Dequeue(&queue)); printf("Second queue[%d][%d]:\n", Queue_MaxQueueSize(&queue2), Queue_MaxStrSize(&queue2)); while (Queue_HasNext(&queue2)) printf("%s\n", Queue_Dequeue(&queue2)); }
int d(int mat[], int i, int j, int n, int m) { int mn = m * n; int iter; int ans = 0; int c; if (mat[i * m + j] == 1) { return 0; } int mark[34225]; for (iter = 0; iter < 34225; iter++) { mark[iter] = 0; } struct Queue* Q = Queue_Create(); Queue_Enqueue(Q, i * m + j); Queue_Enqueue(Q, -1); mark[i * m + j] += 1; while (1) { c = Queue_Dequeue(Q); if (c == -1) { Queue_Enqueue(Q, -1); ans += 1; continue; } if ((c % m) && (!mark[c - 1])) { if (mat[c - 1] == 1) { return ans + 1; } Queue_Enqueue(Q, c - 1); mark[c - 1] += 1; } if (((c + 1) % m) && (!mark[c + 1])) { if (mat[c + 1] == 1) { return ans + 1; } Queue_Enqueue(Q, c + 1); mark[c + 1] += 1; } if (((0 <= (c + m)) && ((c + m) < mn)) && (!mark[c + m])) { if (mat[c + m] == 1) { return ans + 1; } Queue_Enqueue(Q, c + m); mark[c + m] += 1; } if (((0 <= (c - m)) && ((c - m) < mn)) && (!mark[c - m])) { if (mat[c - m] == 1) { return ans + 1; } Queue_Enqueue(Q, c - m); mark[c - m] += 1; } } }
/* Returns TRUE if no more samples are currently available * Returns FALSE otherwise */ static BOOL tsmf_stream_process_ack(void* arg, BOOL force) { TSMF_STREAM* stream = arg; TSMF_SAMPLE* sample; UINT64 ack_time; BOOL rc = FALSE; if (!stream) return TRUE; Queue_Lock(stream->sample_ack_list); sample = (TSMF_SAMPLE*) Queue_Peek(stream->sample_ack_list); if (!sample) { rc = TRUE; goto finally; } if (!force) { /* Do some min/max ack limiting if we have access to Buffer level information */ if (stream->decoder && stream->decoder->BufferLevel) { /* Try to keep buffer level below max by withholding acks */ if (stream->currentBufferLevel > stream->maxBufferLevel) goto finally; /* Try to keep buffer level above min by pushing acks through quickly */ else if (stream->currentBufferLevel < stream->minBufferLevel) goto dequeue; } /* Time based acks only */ ack_time = get_current_time(); if (sample->ack_time > ack_time) goto finally; } dequeue: sample = Queue_Dequeue(stream->sample_ack_list); if (sample) { tsmf_sample_ack(sample); tsmf_sample_free(sample); } finally: Queue_Unlock(stream->sample_ack_list); return rc; }
STREAM* transport_receive_pool_take(rdpTransport* transport) { STREAM* pdu = NULL; if (WaitForSingleObject(Queue_Event(transport->ReceivePool), 0) == WAIT_OBJECT_0) pdu = Queue_Dequeue(transport->ReceivePool); if (!pdu) pdu = stream_new(BUFFER_SIZE); pdu->p = pdu->data; return pdu; }
// gets a buffer of size samples from the device int android_RecIn(OPENSL_STREAM *p,short *buffer,int size) { queue_element *e; int rc; assert(p); assert(buffer); assert(size > 0); /* Initial trigger for the queue. */ if (!p->prep) { p->prep = calloc(1, sizeof(queue_element)); p->prep->data = calloc(p->buffersize, p->bits_per_sample / 8); p->prep->size = p->buffersize * p->bits_per_sample / 8; p->next = calloc(1, sizeof(queue_element)); p->next->data = calloc(p->buffersize, p->bits_per_sample / 8); p->next->size = p->buffersize * p->bits_per_sample / 8; (*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue, p->next->data, p->next->size); (*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue, p->prep->data, p->prep->size); (*p->recorderRecord)->SetRecordState(p->recorderRecord, SL_RECORDSTATE_RECORDING); } /* Wait for queue to be filled... */ if (!Queue_Count(p->queue)) WaitForSingleObject(p->queue->event, INFINITE); e = Queue_Dequeue(p->queue); if (!e) { WLog_ERR(TAG, "[ERROR] got e=%p from queue", e); return -1; } rc = (e->size < size) ? e->size : size; assert(size == e->size); assert(p->buffersize * p->bits_per_sample / 8 == size); memcpy(buffer, e->data, rc); free(e->data); free(e); return rc; }
RPC_PDU* rpc_recv_dequeue_pdu(rdpRpc* rpc) { RPC_PDU* pdu; DWORD dwMilliseconds; pdu = NULL; dwMilliseconds = rpc->client->SynchronousReceive ? INFINITE : 0; if (WaitForSingleObject(Queue_Event(rpc->client->ReceiveQueue), dwMilliseconds) == WAIT_OBJECT_0) { pdu = (RPC_PDU*) Queue_Dequeue(rpc->client->ReceiveQueue); return pdu; } return pdu; }
void *ContextManager_Producer(void *_self) { ContextManager *self = (ContextManager*)_self; Queue *q = self->outgoing_queue; while(true) { while(Queue_Empty(q)) pthread_yield(); void *data = Queue_Dequeue(q); if(data == NULL) break; printf("%s\n", (char*)data); } printf("Producer queue shut down\n"); return NULL; }
int main() { queue_t *q = (queue_t*)malloc(sizeof(queue_t)); Queue_Init(q); int i, t; for (i = 0; i < 20; i++) { Queue_Enqueue(q, i); printf("Enqueue: %d\n", i); } for (i = 0; i < 10; i++) { Queue_Dequeue(q, &t); printf("Dequeue: %d\n", t); } return 0; }
RFX_TILE* rfx_tile_pool_take(RFX_CONTEXT* context) { RFX_TILE* tile = NULL; if (WaitForSingleObject(Queue_Event(context->priv->TilePool), 0) == WAIT_OBJECT_0) tile = Queue_Dequeue(context->priv->TilePool); if (!tile) { tile = (RFX_TILE*) malloc(sizeof(RFX_TILE)); tile->x = tile->y = 0; tile->data = (BYTE*) malloc(4096 * 4); /* 64x64 * 4 */ } return tile; }
void *ContextManager_Consumer(void *_self) { ContextManager *self = (ContextManager*)_self; Queue *q = self->incoming_queue; while(true) { while(Queue_Empty(q)) pthread_yield(); void *data = Queue_Dequeue(q); if(data == NULL) break; printf("Enqueueing data!\n"); Queue_Enqueue(self->outgoing_queue, data); } printf("Consumer queue shut down\n"); return NULL; }
int rpc_send_dequeue_pdu(rdpRpc* rpc) { int status; RPC_PDU* pdu; RpcClientCall* clientCall; rpcconn_common_hdr_t* header; pdu = (RPC_PDU*) Queue_Dequeue(rpc->client->SendQueue); if (!pdu) return 0; WaitForSingleObject(rpc->VirtualConnection->DefaultInChannel->Mutex, INFINITE); status = rpc_in_write(rpc, Stream_Buffer(pdu->s), Stream_Length(pdu->s)); header = (rpcconn_common_hdr_t*) Stream_Buffer(pdu->s); clientCall = rpc_client_call_find_by_id(rpc, header->call_id); clientCall->State = RPC_CLIENT_CALL_STATE_DISPATCHED; ReleaseMutex(rpc->VirtualConnection->DefaultInChannel->Mutex); /* * This protocol specifies that only RPC PDUs are subject to the flow control abstract * data model. RTS PDUs and the HTTP request and response headers are not subject to flow control. * Implementations of this protocol MUST NOT include them when computing any of the variables * specified by this abstract data model. */ if (header->ptype == PTYPE_REQUEST) { rpc->VirtualConnection->DefaultInChannel->BytesSent += status; rpc->VirtualConnection->DefaultInChannel->SenderAvailableWindow -= status; } Stream_Free(pdu->s, TRUE); free(pdu); if (rpc->client->SynchronousSend) SetEvent(rpc->client->PduSentEvent); return status; }
void rdpsnd_count_frames(rdpsndIOSPlugin* p) { int targetFrames; waveItem* peek; peek = Queue_Peek(p->waveQ); if (!peek) { printf("empty waveQ!\n"); return; } targetFrames = peek->numFrames; //printf("count %d/%d frames\n", p->frameCnt, targetFrames); if (p->frameCnt >= targetFrames) { UINT16 tB; UINT16 diff; tB = (UINT16)GetTickCount(); diff = tB - peek->localTimeStampA; //frameCnt = frameCnt - peek->numFrames; p->frameCnt = 0; peek = Queue_Dequeue(p->waveQ); rdpsnd_send_wave_confirm_pdu(p->device.rdpsnd, peek->remoteTimeStampA + diff, peek->ID); //printf("confirm with latency:%d\n", diff); printf("\tConfirm %02X timeStamp A:%d B:%d diff %d (qCount=%d)\n" , peek->ID, peek->remoteTimeStampA, peek->remoteTimeStampA + diff, diff, Queue_Count(p->waveQ)); free(peek); } }
static void tsmf_stream_process_ack(TSMF_STREAM* stream) { TSMF_SAMPLE* sample; UINT64 ack_time; ack_time = get_current_time(); while ((Queue_Count(stream->sample_ack_list) > 0) && !(WaitForSingleObject(stream->stopEvent, 0) == WAIT_OBJECT_0)) { sample = (TSMF_SAMPLE*) Queue_Peek(stream->sample_ack_list); if (!sample || (sample->ack_time > ack_time)) break; sample = Queue_Dequeue(stream->sample_ack_list); tsmf_sample_ack(sample); tsmf_sample_free(sample); } }
static void VideoClientContextPriv_free(VideoClientContextPriv *priv) { EnterCriticalSection(&priv->framesLock); while (Queue_Count(priv->frames)) { VideoFrame *frame = Queue_Dequeue(priv->frames); if (frame) VideoFrame_free(&frame); } Queue_Free(priv->frames); LeaveCriticalSection(&priv->framesLock); DeleteCriticalSection(&priv->framesLock); if (priv->currentPresentation) PresentationContext_unref(priv->currentPresentation); BufferPool_Free(priv->surfacePool); free(priv); }
static void* serial_thread_func(void* arg) { IRP* irp; DWORD status; SERIAL_DEVICE* serial = (SERIAL_DEVICE*)arg; while (1) { if (WaitForSingleObject(serial->stopEvent, 0) == WAIT_OBJECT_0) break; if (WaitForSingleObject(Queue_Event(serial->queue), 10) == WAIT_OBJECT_0) break; serial->nfds = 1; FD_ZERO(&serial->read_fds); FD_ZERO(&serial->write_fds); serial->tv.tv_sec = 1; serial->tv.tv_usec = 0; serial->select_timeout = 0; irp = (IRP*) Queue_Dequeue(serial->queue); if (irp) serial_process_irp(serial, irp); status = WaitForSingleObject(serial->in_event, 0); if ((status == WAIT_OBJECT_0) || (status == WAIT_TIMEOUT)) { if (serial_check_fds(serial)) ResetEvent(serial->in_event); } } return NULL; }
static void* thread_pool_work_func(void* arg) { DWORD status; PTP_POOL pool; PTP_WORK work; HANDLE events[2]; PTP_CALLBACK_INSTANCE callbackInstance; pool = (PTP_POOL) arg; events[0] = pool->TerminateEvent; events[1] = Queue_Event(pool->PendingQueue); while (1) { status = WaitForMultipleObjects(2, events, FALSE, INFINITE); if (status == WAIT_OBJECT_0) break; if (status != (WAIT_OBJECT_0 + 1)) break; callbackInstance = (PTP_CALLBACK_INSTANCE) Queue_Dequeue(pool->PendingQueue); if (callbackInstance) { work = callbackInstance->Work; work->WorkCallback(callbackInstance, work->CallbackParameter, work); CountdownEvent_Signal(pool->WorkComplete, 1); free(callbackInstance); } } ExitThread(0); return NULL; }
static void* serial_thread_func(void* arg) { IRP* irp; DWORD status; SERIAL_DEVICE* serial = (SERIAL_DEVICE*)arg; HANDLE ev[] = {serial->stopEvent, Queue_Event(serial->queue), serial->newEvent}; assert(NULL != serial); while (1) { status = WaitForMultipleObjects(3, ev, FALSE, INFINITE); if (WAIT_OBJECT_0 == status) break; else if (status == WAIT_OBJECT_0 + 1) { FD_ZERO(&serial->read_fds); FD_ZERO(&serial->write_fds); serial->tv.tv_sec = 0; serial->tv.tv_usec = 0; serial->select_timeout = 0; if ((irp = (IRP*) Queue_Dequeue(serial->queue))) serial_process_irp(serial, irp); } else if (status == WAIT_OBJECT_0 + 2) ResetEvent(serial->newEvent); if(serial->tty) serial_check_fds(serial); } ExitThread(0); return NULL; }
int rpc_client_on_fragment_received_event(rdpRpc* rpc) { BYTE* buffer; UINT32 StubOffset; UINT32 StubLength; wStream* fragment; rpcconn_hdr_t* header; freerdp* instance; instance = (freerdp*) rpc->transport->settings->instance; if (!rpc->client->pdu) rpc->client->pdu = rpc_client_receive_pool_take(rpc); fragment = Queue_Dequeue(rpc->client->FragmentQueue); buffer = (BYTE*) Stream_Buffer(fragment); header = (rpcconn_hdr_t*) Stream_Buffer(fragment); if (rpc->State < RPC_CLIENT_STATE_CONTEXT_NEGOTIATED) { rpc->client->pdu->Flags = 0; rpc->client->pdu->CallId = header->common.call_id; Stream_EnsureCapacity(rpc->client->pdu->s, Stream_Length(fragment)); Stream_Write(rpc->client->pdu->s, buffer, Stream_Length(fragment)); Stream_Length(rpc->client->pdu->s) = Stream_GetPosition(rpc->client->pdu->s); rpc_client_fragment_pool_return(rpc, fragment); Queue_Enqueue(rpc->client->ReceiveQueue, rpc->client->pdu); SetEvent(rpc->transport->ReceiveEvent); rpc->client->pdu = NULL; return 0; } if (header->common.ptype == PTYPE_RTS) { if (rpc->VirtualConnection->State >= VIRTUAL_CONNECTION_STATE_OPENED) { //fprintf(stderr, "Receiving Out-of-Sequence RTS PDU\n"); rts_recv_out_of_sequence_pdu(rpc, buffer, header->common.frag_length); rpc_client_fragment_pool_return(rpc, fragment); } else { fprintf(stderr, "warning: unhandled RTS PDU\n"); } return 0; } else if (header->common.ptype == PTYPE_FAULT) { rpc_recv_fault_pdu(header); return -1; } if (header->common.ptype != PTYPE_RESPONSE) { fprintf(stderr, "Unexpected RPC PDU type: %d\n", header->common.ptype); return -1; } rpc->VirtualConnection->DefaultOutChannel->BytesReceived += header->common.frag_length; rpc->VirtualConnection->DefaultOutChannel->ReceiverAvailableWindow -= header->common.frag_length; if (!rpc_get_stub_data_info(rpc, buffer, &StubOffset, &StubLength)) { fprintf(stderr, "rpc_recv_pdu_fragment: expected stub\n"); return -1; } if (StubLength == 4) { //fprintf(stderr, "Ignoring TsProxySendToServer Response\n"); printf("Got stub length 4 with flags %d and callid %d\n", header->common.pfc_flags, header->common.call_id); /* received a disconnect request from the server? */ if ((header->common.call_id == rpc->PipeCallId) && (header->common.pfc_flags & PFC_LAST_FRAG)) { TerminateEventArgs e; instance->context->rdp->disconnect = TRUE; rpc->transport->tsg->state = TSG_STATE_TUNNEL_CLOSE_PENDING; EventArgsInit(&e, "freerdp"); e.code = 0; PubSub_OnTerminate(instance->context->pubSub, instance->context, &e); } rpc_client_fragment_pool_return(rpc, fragment); return 0; } Stream_EnsureCapacity(rpc->client->pdu->s, header->response.alloc_hint); buffer = (BYTE*) Stream_Buffer(fragment); header = (rpcconn_hdr_t*) Stream_Buffer(fragment); if (rpc->StubFragCount == 0) rpc->StubCallId = header->common.call_id; if (rpc->StubCallId != header->common.call_id) { fprintf(stderr, "invalid call_id: actual: %d, expected: %d, frag_count: %d\n", rpc->StubCallId, header->common.call_id, rpc->StubFragCount); } Stream_Write(rpc->client->pdu->s, &buffer[StubOffset], StubLength); rpc->StubFragCount++; rpc_client_fragment_pool_return(rpc, fragment); if (rpc->VirtualConnection->DefaultOutChannel->ReceiverAvailableWindow < (rpc->ReceiveWindow / 2)) { //fprintf(stderr, "Sending Flow Control Ack PDU\n"); rts_send_flow_control_ack_pdu(rpc); } /** * If alloc_hint is set to a nonzero value and a request or a response is fragmented into multiple * PDUs, implementations of these extensions SHOULD set the alloc_hint field in every PDU to be the * combined stub data length of all remaining fragment PDUs. */ if (header->response.alloc_hint == StubLength) { rpc->client->pdu->Flags = RPC_PDU_FLAG_STUB; rpc->client->pdu->CallId = rpc->StubCallId; Stream_Length(rpc->client->pdu->s) = Stream_GetPosition(rpc->client->pdu->s); rpc->StubFragCount = 0; rpc->StubCallId = 0; Queue_Enqueue(rpc->client->ReceiveQueue, rpc->client->pdu); rpc->client->pdu = NULL; return 0; } return 0; }
static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync) { TSMF_STREAM* s; LIST_ITEM* item; TSMF_SAMPLE* sample; BOOL pending = FALSE; TSMF_PRESENTATION* presentation = stream->presentation; if (Queue_Count(stream->sample_list) < 1) return NULL; if (sync) { if (stream->decoder) { if (stream->decoder->GetDecodedData) { if (stream->major_type == TSMF_MAJOR_TYPE_AUDIO) { /* Check if some other stream has earlier sample that needs to be played first */ if (stream->last_end_time > AUDIO_TOLERANCE) { WaitForSingleObject(presentation->mutex, INFINITE); for (item = presentation->stream_list->head; item; item = item->next) { s = (TSMF_STREAM*) item->data; if (s != stream && !s->eos && s->last_end_time && s->last_end_time < stream->last_end_time - AUDIO_TOLERANCE) { pending = TRUE; break; } } ReleaseMutex(presentation->mutex); } } else { if (stream->last_end_time > presentation->audio_end_time) { pending = TRUE; } } } } } if (pending) return NULL; sample = (TSMF_SAMPLE*) Queue_Dequeue(stream->sample_list); if (sample && (sample->end_time > stream->last_end_time)) stream->last_end_time = sample->end_time; return sample; }
static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync) { UINT32 index; UINT32 count; TSMF_STREAM *s; TSMF_SAMPLE* sample; BOOL pending = FALSE; TSMF_PRESENTATION* presentation = stream->presentation; if (!stream) return NULL; if (Queue_Count(stream->sample_list) < 1) return NULL; if (sync) { if (stream->decoder) { if (stream->decoder->GetDecodedData) { if (stream->major_type == TSMF_MAJOR_TYPE_AUDIO) { /* Check if some other stream has earlier sample that needs to be played first */ /* Start time is more reliable than end time as some stream types seem to have incorrect * end times from the server */ if (stream->last_start_time > AUDIO_TOLERANCE) { ArrayList_Lock(presentation->stream_list); count = ArrayList_Count(presentation->stream_list); for (index = 0; index < count; index++) { s = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index); /* Start time is more reliable than end time as some stream types seem to have incorrect * end times from the server */ if (s != stream && !s->eos && s->last_start_time && s->last_start_time < stream->last_start_time - AUDIO_TOLERANCE) { DEBUG_TSMF("Pending due to audio tolerance"); pending = TRUE; break; } } ArrayList_Unlock(presentation->stream_list); } } else { /* Start time is more reliable than end time as some stream types seem to have incorrect * end times from the server */ if (stream->last_start_time > presentation->audio_start_time) { DEBUG_TSMF("Pending due to stream start time > audio start time"); pending = TRUE; } } } } } if (pending) return NULL; sample = (TSMF_SAMPLE *) Queue_Dequeue(stream->sample_list); /* Only update stream last end time if the sample end time is valid and greater than the current stream end time */ if (sample && (sample->end_time > stream->last_end_time) && (!sample->invalidTimestamps)) stream->last_end_time = sample->end_time; /* Only update stream last start time if the sample start time is valid and greater than the current stream start time */ if (sample && (sample->start_time > stream->last_start_time) && (!sample->invalidTimestamps)) stream->last_start_time = sample->start_time; return sample; }