Exemplo n.º 1
0
static void coreaudio_free(void *data)
{
   coreaudio_t *dev = (coreaudio_t*)data;

   if (!dev)
      return;

   if (dev->dev_alive)
   {
      AudioOutputUnitStop(dev->dev);
#ifdef OSX_PPC
      CloseComponent(dev->dev);
#else
      AudioComponentInstanceDispose(dev->dev);
#endif
   }

   if (dev->buffer)
      fifo_free(dev->buffer);

   slock_free(dev->lock);
   scond_free(dev->cond);

   free(dev);
}
Exemplo n.º 2
0
CoreAudioOutput::~CoreAudioOutput()
{
	OSSpinLockLock(_spinlockAU);
	
	if(_au != NULL)
	{
		AudioOutputUnitStop(_au);
		AudioUnitUninitialize(_au);
#if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
		if (IsOSXVersionSupported(10, 6, 0))
		{
			AudioComponentInstanceDispose(_au);
		}
		else
		{
			CloseComponent(_au);
		}
#else
		CloseComponent(_au);
#endif
		_au = NULL;
	}
	
	OSSpinLockUnlock(_spinlockAU);
	
	delete _buffer;
	_buffer = NULL;
	
	free(_spinlockAU);
	_spinlockAU = NULL;
}
Exemplo n.º 3
0
void CoreAudioDriver::disconnect()
{
	OSStatus err = noErr;
	err = AudioOutputUnitStop( m_outputUnit );
	err = AudioUnitUninitialize( m_outputUnit );
	err = AudioComponentInstanceDispose( m_outputUnit );
}
AudioDestinationIOS::~AudioDestinationIOS()
{
    audioDestinations().remove(this);

    if (m_outputUnit)
        AudioComponentInstanceDispose(m_outputUnit);
}
Exemplo n.º 5
0
static void coreaudio_free(void *data)
{
   coreaudio_t *dev = (coreaudio_t*)data;

   if (!dev)
      return;

   if (dev->dev_alive)
   {
      AudioOutputUnitStop(dev->dev);
#if (defined(__MACH__) && (defined(__ppc__) || defined(__ppc64__)))
      CloseComponent(dev->dev);
#else
      AudioComponentInstanceDispose(dev->dev);
#endif
   }

   if (dev->buffer)
      fifo_free(dev->buffer);

   slock_free(dev->lock);
   scond_free(dev->cond);

   free(dev);
}
Exemplo n.º 6
0
static int close_coreaudio(audio_output_t *ao)
{
    mpg123_coreaudio_t* ca = (mpg123_coreaudio_t*)ao->userptr;

    if (ca) {
        ca->decode_done = 1;
        while(!ca->play_done && ca->play) usleep(10000);

        /* No matter the error code, we want to close it
           (by brute force if necessary) */
        AudioConverterDispose(ca->converter);
        AudioOutputUnitStop(ca->outputUnit);
        AudioUnitUninitialize(ca->outputUnit);
        AudioComponentInstanceDispose(ca->outputUnit);

        /* Free the ring buffer */
        sfifo_close( &ca->fifo );

        /* Free the conversion buffer */
        if (ca->buffer) {
            free( ca->buffer );
            ca->buffer = NULL;
        }

    }

    return 0;
}
Exemplo n.º 7
0
gboolean
gst_core_audio_close (GstCoreAudio * core_audio)
{
  AudioComponentInstanceDispose (core_audio->audiounit);
  core_audio->audiounit = NULL;
  return TRUE;
}
Exemplo n.º 8
0
gboolean
gst_core_audio_open (GstCoreAudio * core_audio)
{

  if (!gst_core_audio_open_impl (core_audio))
    return FALSE;

  if (core_audio->is_src) {
    AudioStreamBasicDescription asbd_in;
    UInt32 propertySize;
    OSStatus status;

    GstOsxAudioSrc *src =
        GST_OSX_AUDIO_SRC (GST_OBJECT_PARENT (core_audio->osxbuf));

    propertySize = sizeof (asbd_in);
    status = AudioUnitGetProperty (core_audio->audiounit,
        kAudioUnitProperty_StreamFormat,
        kAudioUnitScope_Input, 1, &asbd_in, &propertySize);

    if (status) {
      AudioComponentInstanceDispose (core_audio->audiounit);
      core_audio->audiounit = NULL;
      GST_WARNING_OBJECT (core_audio,
          "Unable to obtain device properties: %d", (int) status);
      return FALSE;
    } else {
      src->deviceChannels = asbd_in.mChannelsPerFrame;
    }
  }

  return TRUE;
}
Exemplo n.º 9
0
gboolean
gst_core_audio_close (GstCoreAudio * core_audio)
{
  OSStatus status;

  /* Uninitialize the AudioUnit */
  status = AudioUnitUninitialize (core_audio->audiounit);
  if (status) {
    GST_ERROR_OBJECT (core_audio, "Failed to uninitialize AudioUnit: %d",
        (int) status);
    return FALSE;
  }

  AudioUnitRemovePropertyListenerWithUserData (core_audio->audiounit,
      kAudioUnitProperty_AudioChannelLayout, _audio_unit_property_listener,
      core_audio);
  AudioUnitRemovePropertyListenerWithUserData (core_audio->audiounit,
      kAudioUnitProperty_StreamFormat, _audio_unit_property_listener,
      core_audio);

  /* core_audio->osxbuf is already locked at this point */
  core_audio->cached_caps_valid = FALSE;
  gst_caps_replace (&core_audio->cached_caps, NULL);

  AudioComponentInstanceDispose (core_audio->audiounit);
  core_audio->audiounit = NULL;
  return TRUE;
}
Exemplo n.º 10
0
AudioDestinationMac::~AudioDestinationMac()
{
    if (m_outputUnit)
        AudioComponentInstanceDispose(m_outputUnit);
    
    delete m_input; // LabSound
}
Exemplo n.º 11
0
static void au_unconfigure(AUData *d) {
	if (d->write_started==FALSE && d->read_started==FALSE) {
		AudioUnitUninitialize(d->io_unit);
		AudioOutputUnitStop(d->io_unit);
		AudioComponentInstanceDispose (d->io_unit);
		d->started=FALSE;
	}
}
Exemplo n.º 12
0
void iOSCoreAudioShutdown()
{
    if (audioInstance) {
        AudioOutputUnitStop(audioInstance);
        AudioUnitUninitialize(audioInstance);
        AudioComponentInstanceDispose(audioInstance);
        audioInstance = nil;
    }
}
void AudioLoopImplCocoa::shutdown()
{
    if (initialized)
    {
        AudioOutputUnitStop(audioUnit);
        AudioUnitUninitialize(audioUnit);
        AudioComponentInstanceDispose(audioUnit);
        audioUnit = NULL;
    }
}
Exemplo n.º 14
0
void AudioDriverCoreAudio::finish() {
	capture_finish();

	if (audio_unit) {
		OSStatus result;

		lock();

		AURenderCallbackStruct callback;
		zeromem(&callback, sizeof(AURenderCallbackStruct));
		result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, kOutputBus, &callback, sizeof(callback));
		if (result != noErr) {
			ERR_PRINT("AudioUnitSetProperty failed");
		}

		if (active) {
			result = AudioOutputUnitStop(audio_unit);
			if (result != noErr) {
				ERR_PRINT("AudioOutputUnitStop failed");
			}

			active = false;
		}

		result = AudioUnitUninitialize(audio_unit);
		if (result != noErr) {
			ERR_PRINT("AudioUnitUninitialize failed");
		}

#ifdef OSX_ENABLED
		AudioObjectPropertyAddress prop;
		prop.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
		prop.mScope = kAudioObjectPropertyScopeGlobal;
		prop.mElement = kAudioObjectPropertyElementMaster;

		result = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &prop, &output_device_address_cb, this);
		if (result != noErr) {
			ERR_PRINT("AudioObjectRemovePropertyListener failed");
		}
#endif

		result = AudioComponentInstanceDispose(audio_unit);
		if (result != noErr) {
			ERR_PRINT("AudioComponentInstanceDispose failed");
		}

		audio_unit = NULL;
		unlock();
	}

	if (mutex) {
		memdelete(mutex);
		mutex = NULL;
	}
}
Exemplo n.º 15
0
    ~Input()
    {
        if (m_inputUnit)
            AudioComponentInstanceDispose(m_inputUnit);
        
        free(m_buffers);

        if (m_audioBus)
            delete m_audioBus;
        
    }
Exemplo n.º 16
0
void
coreaudio_object_close(struct audio_object *object)
{
	struct coreaudio_object *self = to_coreaudio_object(object);
	if(self->initialized) {
		AudioUnitUninitialize(self->outputUnit);
		AudioComponentInstanceDispose(self->outputUnit);
		TPCircularBufferCleanup(&(self->circularBuffer));
		self->initialized = FALSE;
	}

}
Exemplo n.º 17
0
void CloseDefaultAU () {
	OSStatus err = noErr;

	err = AudioOutputUnitStop (gOutputUnit);
	if (err) { printf ("AudioOutputUnitStop=%ld\n", (long int)err); }

	err = AudioUnitUninitialize (gOutputUnit);
	if (err) { printf ("AudioUnitUninitialize=%ld\n", (long int)err); }

	AudioComponentInstanceDispose (gOutputUnit);

	if (inputBuffer) deallocAudioBufferList(inputBuffer);
}
Exemplo n.º 18
0
bool coreAudioDevice::localStop(void) 
{
    if (_inUse)
    {
        verify_noerr(AudioOutputUnitStop(theOutputUnit));
        // Clean up
        verify_noerr(AudioUnitUninitialize(theOutputUnit));
        verify_noerr(AudioComponentInstanceDispose(theOutputUnit));
    }
	_inUse=0;
        ADM_usleep(10*1000);
	return 1;
}
Exemplo n.º 19
0
    void close()
    {
        if (isRunning)
        {
            isRunning = false;
            AudioSessionSetActive (false);

            if (audioUnit != 0)
            {
                AudioComponentInstanceDispose (audioUnit);
                audioUnit = 0;
            }
        }
    }
    void close()
    {
        if (isRunning)
        {
            isRunning = false;
            AudioSessionRemovePropertyListenerWithUserData (kAudioSessionProperty_AudioRouteChange, routingChangedStatic, this);
            AudioSessionSetActive (false);

            if (audioUnit != 0)
            {
                AudioComponentInstanceDispose (audioUnit);
                audioUnit = 0;
            }
        }
    }
Exemplo n.º 21
0
static tsk_object_t* tdav_audiounit_instance_dtor(tsk_object_t * self)
{ 
	tdav_audiounit_instance_t* inst = self;
	if(inst){
        tsk_safeobj_lock(inst);
		if(inst->audioUnit){
            AudioUnitUninitialize(inst->audioUnit);
            AudioComponentInstanceDispose(inst->audioUnit);
            inst->audioUnit = tsk_null;
		}
        tsk_safeobj_unlock(inst);
        
		tsk_safeobj_deinit(inst);
	}
	return self;
}
Exemplo n.º 22
0
    void close() override
    {
        if (isRunning)
        {
            isRunning = false;

            setSessionUInt32Property (kAudioSessionProperty_AudioCategory, kAudioSessionCategory_MediaPlayback);

            AudioSessionRemovePropertyListenerWithUserData (kAudioSessionProperty_AudioRouteChange, routingChangedStatic, this);
            AudioSessionSetActive (false);

            if (audioUnit != 0)
            {
                AudioComponentInstanceDispose (audioUnit);
                audioUnit = 0;
            }
        }
    }
Exemplo n.º 23
0
InputImplAudioUnit::~InputImplAudioUnit()
{
	if( mIsCapturing ) {
		stop();
	}
	
	if( mInputUnit ) {
		AudioComponentInstanceDispose( mInputUnit );
	}
	
	for( int i = 0; i < mCircularBuffers.size(); i++ ) {
		delete mCircularBuffers[i];
	}
	
	if( mInputBuffer )
		free( mInputBuffer );
	if( mInputBufferData )
		free( mInputBufferData );
}
Exemplo n.º 24
0
void CAPlayThrough::Cleanup()
{
	//clean up
	Stop();
									
	delete mBuffer;
	mBuffer = 0;
	if(mInputBuffer){
		for(UInt32 i = 0; i<mInputBuffer->mNumberBuffers; i++)
			free(mInputBuffer->mBuffers[i].mData);
		free(mInputBuffer);
		mInputBuffer = 0;
	}
	
	AudioUnitUninitialize(mInputUnit);
	AUGraphClose(mGraph);
	DisposeAUGraph(mGraph);
    AudioComponentInstanceDispose(mInputUnit);
}
Exemplo n.º 25
0
static void coreaudio_free(void *data)
{
   coreaudio_t *dev = (coreaudio_t*)data;
   if (!dev)
      return;

   if (dev->dev_alive)
   {
      AudioOutputUnitStop(dev->dev);
      AudioComponentInstanceDispose(dev->dev);
   }

   if (dev->buffer)
      fifo_free(dev->buffer);

   pthread_mutex_destroy(&dev->lock);
   pthread_cond_destroy(&dev->cond);

   free(dev);
}
Exemplo n.º 26
0
/*
 *This function handles a change in the audio's route. 
 *(TODO) this needs some work, should be a member of the class and call setupIO in place of SetupRemoteIO;
 *(TODO) make sure we don't crash when input becomes unavailable on an iPod Touch.
 */
void propListener( void * inClientData, AudioSessionPropertyID	inID, UInt32 inDataSize, const void *inData )
{
	//NSLog(@"propListener");
	MUEAudioIO *THIS = (MUEAudioIO*)inClientData;
	if (inID == kAudioSessionProperty_AudioRouteChange)
	{
			// if there was a route change, we need to dispose the current rio unit and create a new one
			AudioComponentInstanceDispose(THIS->rioUnit);		
			
			//SetupRemoteIO(THIS->rioUnit, THIS->inputProc, THIS->thruFormat);
            THIS->setupIO(); //(TODO) will this work?
			
			UInt32 size = sizeof(THIS->hwSampleRate);
			AudioSessionGetProperty(kAudioSessionProperty_CurrentHardwareSampleRate, &size, &THIS->hwSampleRate);
			
			AudioOutputUnitStart(THIS->rioUnit);
			
			//See what the new routing is, and take dependent action...
			CFStringRef newRoute;
			size = sizeof(CFStringRef);
			AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &size, &newRoute);
			if (newRoute)
			{	
				CFShow(newRoute);
				if (CFStringCompare(newRoute, CFSTR("Headset"), NULL) == kCFCompareEqualTo) // headset plugged in
				{
					//Do something if you'd like
				}
				else if (CFStringCompare(newRoute, CFSTR("Receiver"), NULL) == kCFCompareEqualTo) // headset plugged in
				{
					//Do something if you'd like	
				}			
				else		//Something else must be plugged in...Third party?
				{
					//Do something if you'd like
				}
			}
		
	}
}
Exemplo n.º 27
0
static void
audiounit_stream_destroy(cubeb_stream * stm)
{
  int r;

  stm->shutdown = 1;

  if (stm->unit) {
    AudioOutputUnitStop(stm->unit);
    AudioUnitUninitialize(stm->unit);
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
    CloseComponent(stm->unit);
#else
    AudioComponentInstanceDispose(stm->unit);
#endif
  }

  r = pthread_mutex_destroy(&stm->mutex);
  assert(r == 0);

  free(stm);
}
Exemplo n.º 28
0
static void
COREAUDIO_CloseDevice(_THIS)
{
    if (this->hidden != NULL) {
        if (this->hidden->audioUnitOpened) {
            OSStatus result = noErr;
            AURenderCallbackStruct callback;
            const AudioUnitElement output_bus = 0;
            const AudioUnitElement input_bus = 1;
            const int iscapture = this->iscapture;
            const AudioUnitElement bus =
                ((iscapture) ? input_bus : output_bus);
            const AudioUnitScope scope =
                ((iscapture) ? kAudioUnitScope_Output :
                 kAudioUnitScope_Input);

            /* stop processing the audio unit */
            result = AudioOutputUnitStop(this->hidden->audioUnit);

            /* Remove the input callback */
            SDL_memset(&callback, 0, sizeof(AURenderCallbackStruct));
            result = AudioUnitSetProperty(this->hidden->audioUnit,
                                          kAudioUnitProperty_SetRenderCallback,
                                          scope, bus, &callback,
                                          sizeof(callback));

#if MACOSX_COREAUDIO
            CloseComponent(this->hidden->audioUnit);
#else
            AudioComponentInstanceDispose(this->hidden->audioUnit);
#endif

            this->hidden->audioUnitOpened = 0;
        }
        SDL_free(this->hidden->buffer);
        SDL_free(this->hidden);
        this->hidden = NULL;
    }
}
Exemplo n.º 29
0
void AudioDriverCoreAudio::capture_finish() {
	if (input_unit) {
		lock();

		AURenderCallbackStruct callback;
		zeromem(&callback, sizeof(AURenderCallbackStruct));
		OSStatus result = AudioUnitSetProperty(input_unit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0, &callback, sizeof(callback));
		if (result != noErr) {
			ERR_PRINT("AudioUnitSetProperty failed");
		}

		result = AudioUnitUninitialize(input_unit);
		if (result != noErr) {
			ERR_PRINT("AudioUnitUninitialize failed");
		}

#ifdef OSX_ENABLED
		AudioObjectPropertyAddress prop;
		prop.mSelector = kAudioHardwarePropertyDefaultInputDevice;
		prop.mScope = kAudioObjectPropertyScopeGlobal;
		prop.mElement = kAudioObjectPropertyElementMaster;

		result = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &prop, &input_device_address_cb, this);
		if (result != noErr) {
			ERR_PRINT("AudioObjectRemovePropertyListener failed");
		}
#endif

		result = AudioComponentInstanceDispose(input_unit);
		if (result != noErr) {
			ERR_PRINT("AudioComponentInstanceDispose failed");
		}

		input_unit = NULL;
		unlock();
	}
}
Exemplo n.º 30
0
static void
COREAUDIO_CloseDevice(_THIS)
{
    if (this->hidden != NULL) {
        if (this->hidden->audioUnitOpened) {
            #if MACOSX_COREAUDIO
            /* Unregister our disconnect callback. */
            AudioObjectRemovePropertyListener(this->hidden->deviceID, &alive_address, device_unplugged, this);
            #endif

            AURenderCallbackStruct callback;
            const AudioUnitElement output_bus = 0;
            const AudioUnitElement input_bus = 1;
            const int iscapture = this->iscapture;
            const AudioUnitElement bus =
                ((iscapture) ? input_bus : output_bus);
            const AudioUnitScope scope =
                ((iscapture) ? kAudioUnitScope_Output :
                 kAudioUnitScope_Input);

            /* stop processing the audio unit */
            AudioOutputUnitStop(this->hidden->audioUnit);

            /* Remove the input callback */
            SDL_memset(&callback, 0, sizeof(AURenderCallbackStruct));
            AudioUnitSetProperty(this->hidden->audioUnit,
                                 kAudioUnitProperty_SetRenderCallback,
                                 scope, bus, &callback, sizeof(callback));
            AudioComponentInstanceDispose(this->hidden->audioUnit);
            this->hidden->audioUnitOpened = 0;
        }
        SDL_free(this->hidden->buffer);
        SDL_free(this->hidden);
        this->hidden = NULL;
    }
}