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_INFO("Not 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;
	TSK_DEBUG_INFO("AudioUnit producer stoppped");
	return 0;	
}
static int tdav_consumer_audiounit_stop(tmedia_consumer_t* self)
{
	tdav_consumer_audiounit_t* consumer = (tdav_consumer_audiounit_t*)self;
	
    if(!consumer){
		TSK_DEBUG_ERROR("Invalid parameter");
		return -1;
	}
	if(!consumer->started){
		TSK_DEBUG_INFO("Not started");
		return 0;
	}
	else {
		int ret = tdav_audiounit_handle_stop(consumer->audioUnitHandle);
		if(ret){
			TSK_DEBUG_ERROR("tdav_audiounit_handle_stop failed with error code=%d", ret);
			return ret;
		}
	}
#if TARGET_OS_IPHONE
	//https://devforums.apple.com/thread/118595
	if(consumer->audioUnitHandle){
		tdav_audiounit_handle_destroy(&consumer->audioUnitHandle);
	}
#endif
	
	consumer->started = tsk_false;
	TSK_DEBUG_INFO("AudioUnit consumer stoppped");
	return 0;	
	
}
int tdav_consumer_audiounit_deinit(tmedia_consumer_t* self)
{
    tdav_consumer_audiounit_t* consumer = (tdav_consumer_audiounit_t*)self;
    if(!consumer) {
        TSK_DEBUG_ERROR("Invalid parameter");
        return -1;
    }
    // Stop
    if (consumer->started) {
        int ret = tdav_audiounit_handle_stop(consumer->audioUnitHandle);
        if (ret) {
            TSK_DEBUG_ERROR("tdav_audiounit_handle_stop failed with error code=%d", ret);
        }
        consumer->started = tsk_false;
    }
    // Destroy handle (will be re-created by the next start)
#if TARGET_OS_IPHONE
    //https://devforums.apple.com/thread/118595
    if (consumer->audioUnitHandle) {
        tdav_audiounit_handle_destroy(&consumer->audioUnitHandle);
    }
#endif
    consumer->ready = tsk_false;
    consumer->paused = tsk_false;
    
    TSK_DEBUG_INFO("AudioUnit consumer deinitialized");
    
    return 0;
}