int tnet_transport_stop(tnet_transport_t *transport)
{
    int ret;
    transport_context_t *context;

    if(!transport) {
        return -1;
    }

    context = transport->context;

    if((ret = tsk_runnable_stop(TSK_RUNNABLE(transport)))) {
        return ret;
    }

    if(context) {
        static char c = '\0';

        // signal
        tsk_safeobj_lock(context); // =>MUST
        if(tnet_transport_have_socket(transport, context->pipeR)) { // to avoid SIGPIPE=> check that there is at least one reader
            write(context->pipeW, &c, 1);
        }
        tsk_safeobj_unlock(context);
    }

    if(transport->mainThreadId[0]) {
        return tsk_thread_join(transport->mainThreadId);
    }
    else {
        /* already soppped */
        return 0;
    }
}
int tnet_transport_stop(tnet_transport_t *transport)
{	
	int ret;
	transport_context_t *context;
    
	if (!transport) {
		return -1;
	}
	
	context = transport->context;
	
	if ((ret = tsk_runnable_stop(TSK_RUNNABLE(transport)))) {
		return ret;
	}
	
	if(transport->mainThreadId[0]){
		if (context && context->cf_run_loop) {
			// Signal the run-loop
			CFRunLoopWakeUp(context->cf_run_loop);
		}
		return tsk_thread_join(transport->mainThreadId);
	}
	else { // already stopped
		return 0;
	}
}
Exemplo n.º 3
0
int tdav_producer_waveapi_stop(tmedia_producer_t* self)
{
	tdav_producer_waveapi_t* producer = (tdav_producer_waveapi_t*)self;
	MMRESULT result;

	if(!self){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}

	if(!producer->started){
		TSK_DEBUG_WARN("Producer not started");
		return 0;
	}

	/* stop thread */
	if(producer->tid[0]){
		SetEvent(producer->events[1]);
		tsk_thread_join(&(producer->tid[0]));
	}

	/* should be done here */
	producer->started = tsk_false;

	if(producer->hWaveIn && (((result = waveInReset(producer->hWaveIn)) != MMSYSERR_NOERROR) || ((result = waveInClose(producer->hWaveIn)) != MMSYSERR_NOERROR))){
		print_last_error(result, "waveInReset/waveInClose");
	}

	return 0;
}
Exemplo n.º 4
0
int tdav_consumer_dsound_stop(tmedia_consumer_t* self)
{
	tdav_consumer_dsound_t* dsound = (tdav_consumer_dsound_t*)self;

	HRESULT hr;

	if(!self){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}

	if(!dsound->started){
		TSK_DEBUG_WARN("Consumer not started");
		return 0;
	}

	/* should be done here */
	dsound->started = tsk_false;

	/* stop thread */
	if(dsound->tid[0]){
		tsk_thread_join(&(dsound->tid[0]));
	}

	if((hr = IDirectSoundBuffer_Stop(dsound->secondaryBuffer)) != DS_OK){
		tdav_win32_print_error("IDirectSoundBuffer_Stop", hr);
	}
	if((hr = IDirectSoundBuffer_SetCurrentPosition(dsound->secondaryBuffer, 0)) != DS_OK){
		tdav_win32_print_error("IDirectSoundBuffer_SetCurrentPosition", hr);
	}

	return 0;
}
Exemplo n.º 5
0
int tdav_producer_dsound_stop(tmedia_producer_t* self)
{
	tdav_producer_dsound_t* dsound = (tdav_producer_dsound_t*)self;

	HRESULT hr;

	if(!self){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}

	if(!dsound->started){
		TSK_DEBUG_WARN("Producer not started");
		return 0;
	}

	/* should be done here */
	dsound->started = tsk_false;

	/* stop thread */
	if(dsound->tid[0]){
		tsk_thread_join(&(dsound->tid[0]));
	}

	if((hr = IDirectSoundCaptureBuffer_Stop(dsound->captureBuffer)) != DS_OK){
		tdav_win32_print_error("IDirectSoundCaptureBuffer_Stop", hr);
	}

	return 0;
}
Exemplo n.º 6
0
/*=== stop all threads */
int tnet_transport_stop(tnet_transport_t *transport)
{
    int ret;

    if ((ret = tsk_runnable_stop(TSK_RUNNABLE(transport)))) {
        return ret;
    }

    if (transport->mainThreadId[0]) {
        WSASetEvent(((transport_context_t*)(transport->context))->events[0]);
        return tsk_thread_join(transport->mainThreadId);
    }
    else {
        /* already stoppped */
        return 0;
    }
}
Exemplo n.º 7
0
static int tdav_producer_audiounit_stop(tmedia_producer_t* self)
{
    tdav_producer_audiounit_t* producer = (tdav_producer_audiounit_t*)self;
	
    if(!producer){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}
	if(!producer->started){
		TSK_DEBUG_WARN("Not started started");
		return 0;
	}
	else {
		int ret = tdav_audiounit_handle_stop(producer->audioUnitHandle);
		if(ret){
			TSK_DEBUG_ERROR("tdav_audiounit_handle_stop failed with error code=%d", ret);
			// do not return even if failed => we MUST stop the thread!
		}
#if TARGET_OS_IPHONE
		//https://devforums.apple.com/thread/118595
		if(producer->audioUnitHandle){
			tdav_audiounit_handle_destroy(&producer->audioUnitHandle);
		}
#endif
	}	
	producer->started = tsk_false;
	// signal
	if(producer->senderCondWait){
		tsk_condwait_broadcast(producer->senderCondWait);
	}
	// stop thread
	if(producer->senderThreadId[0]){
		tsk_thread_join(&(producer->senderThreadId[0]));
	}
	TSK_DEBUG_INFO("AudioUnit producer stoppped");
	return 0;	
}