/* destructor */
static tsk_object_t* tdav_consumer_audiounit_dtor(tsk_object_t * self)
{ 
	tdav_consumer_audiounit_t *consumer = self;
	if(consumer){
		/* deinit self */
		// Stop the consumer if not done
		if(consumer->started){
			tdav_consumer_audiounit_stop(self);
		}
		// destroy handle
		if(consumer->audioUnitHandle){
			tdav_audiounit_handle_destroy(&consumer->audioUnitHandle);
		}
		TSK_FREE(consumer->ring.chunck.buffer);
		if(consumer->ring.buffer){
			speex_buffer_destroy(consumer->ring.buffer);
		}
		if(consumer->ring.mutex){
			tsk_mutex_destroy(&consumer->ring.mutex);
		}
        
		/* deinit base */
		tdav_consumer_audio_deinit(TDAV_CONSUMER_AUDIO(consumer));
	}
	
	return self;
}
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;	
	
}
Ejemplo n.º 3
0
/* destructor */
static tsk_object_t* tdav_producer_audiounit_dtor(tsk_object_t * self)
{ 
	tdav_producer_audiounit_t *producer = self;
	if(producer){
		// Stop the producer if not done
		if(producer->started){
			tdav_producer_audiounit_stop(self);
		}
		
		// Free all buffers and dispose the queue
        if (producer->audioUnitHandle) {
			tdav_audiounit_handle_destroy(&producer->audioUnitHandle);
        }
		if(producer->ring.mutex){
			tsk_mutex_destroy(&producer->ring.mutex);
		}
        TSK_FREE(producer->ring.chunck.buffer);
		if(producer->ring.buffer){
			speex_buffer_destroy(producer->ring.buffer);
		}
		if(producer->senderCondWait){
			tsk_condwait_destroy(&producer->senderCondWait);
		}
		/* deinit base */
		tdav_producer_audio_deinit(TDAV_PRODUCER_AUDIO(producer));
	}
	
	return self;
}
Ejemplo n.º 4
0
/* destructor */
static tsk_object_t* tdav_producer_audiounit_dtor(tsk_object_t * self)
{ 
	tdav_producer_audiounit_t *producer = self;
	if(producer){
		// Stop the producer if not done
		if(producer->started){
			tdav_producer_audiounit_stop(self);
		}
		
		// Free all buffers and dispose the queue
        if (producer->audioUnitHandle) {
			tdav_audiounit_handle_destroy(&producer->audioUnitHandle);
        }
        TSK_FREE(producer->ring.chunck.buffer);
		if(producer->ring.buffer){
			speex_buffer_destroy(producer->ring.buffer);
		}
		/* deinit base */
		tdav_producer_audio_deinit(TDAV_PRODUCER_AUDIO(producer));
        
        TSK_DEBUG_INFO("*** AudioUnit Producer destroyed ***");
	}
	
	return self;
}
Ejemplo n.º 5
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_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;	
}
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;
}