/* 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; }
/* destructor */ static tsk_object_t* tdav_producer_audioqueue_dtor(tsk_object_t * self) { tdav_producer_audioqueue_t *producer = self; if(producer){ // Stop the producer if not done if(producer->started){ tdav_producer_audioqueue_stop(self); } // Free all buffers and dispose the queue if (producer->queue) { tsk_size_t i; for(i=0; i<CoreAudioRecordBuffers; i++){ AudioQueueFreeBuffer(producer->queue, producer->buffers[i]); } AudioQueueDispose(producer->queue, true); } /* deinit base */ tdav_producer_audio_deinit(TDAV_PRODUCER_AUDIO(producer)); } return self; }
/* destructor */ static tsk_object_t* tdav_producer_dsound_dtor(tsk_object_t * self) { tdav_producer_dsound_t *dsound = self; if(dsound){ tsk_size_t i; /* stop */ if(dsound->started){ tdav_producer_dsound_stop(self); } /* deinit base */ tdav_producer_audio_deinit(TDAV_PRODUCER_AUDIO(dsound)); /* deinit self */ if(dsound->captureBuffer){ IDirectSoundCaptureBuffer_Release(dsound->captureBuffer); } if(dsound->device){ IDirectSoundCapture_Release(dsound->device); } for(i = 0; i<sizeof(dsound->notifEvents)/sizeof(HANDLE); i++){ if(dsound->notifEvents[i]){ CloseHandle(dsound->notifEvents[i]); } } } return self; }
/* destructor */ static tsk_object_t* tdav_producer_waveapi_dtor(tsk_object_t * self) { tdav_producer_waveapi_t *producer = self; if(producer){ tsk_size_t i; /* stop */ if(producer->started){ tdav_producer_waveapi_stop(self); } /* deinit base */ tdav_producer_audio_deinit(TDAV_PRODUCER_AUDIO(producer)); /* deinit self */ for(i = 0; i< sizeof(producer->hWaveHeaders)/sizeof(LPWAVEHDR); i++){ free_wavehdr(producer, i); } if(producer->hWaveIn){ waveInClose(producer->hWaveIn); } if(producer->events[0]){ CloseHandle(producer->events[0]); } if(producer->events[1]){ CloseHandle(producer->events[1]); } DeleteCriticalSection(&producer->cs); } return self; }
/* 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; }
/* constructor */ static tsk_object_t* tdav_producer_audiounit_ctor(tsk_object_t * self, va_list * app) { tdav_producer_audiounit_t *producer = self; if(producer){ /* init base */ tdav_producer_audio_init(TDAV_PRODUCER_AUDIO(producer)); /* init self */ } return self; }
/* constructor */ static tsk_object_t* tdav_producer_waveapi_ctor(tsk_object_t * self, va_list * app) { tdav_producer_waveapi_t *producer = self; if(producer){ /* init base */ tdav_producer_audio_init(TDAV_PRODUCER_AUDIO(producer)); /* init self */ InitializeCriticalSection(&producer->cs); } return self; }
/* ============ Media Producer Interface ================= */ int tdav_producer_audiounit_set(tmedia_producer_t* self, const tmedia_param_t* param) { if(param->plugin_type == tmedia_ppt_producer){ if(param->value_type == tmedia_pvt_int32){ if(tsk_striequals(param->key, "mute")){ int32_t mute = TSK_TO_INT32((uint8_t*)param->value); return tdav_audiounit_handle_mute(((tdav_producer_audiounit_t*)self)->audioUnitHandle, mute ? tsk_true : tsk_false); } } } return tdav_producer_audio_set(TDAV_PRODUCER_AUDIO(self), param); }
/* ============ Media Producer Interface ================= */ int tdav_producer_waveapi_prepare(tmedia_producer_t* self, const tmedia_codec_t* codec) { tdav_producer_waveapi_t* producer = (tdav_producer_waveapi_t*)self; tsk_size_t i; if(!producer || !codec && codec->plugin){ TSK_DEBUG_ERROR("Invalid parameter"); return -1; } TDAV_PRODUCER_AUDIO(producer)->channels = codec->plugin->audio.channels; TDAV_PRODUCER_AUDIO(producer)->rate = codec->plugin->rate; /* codec should have ptime */ /* Format */ ZeroMemory(&producer->wfx, sizeof(WAVEFORMATEX)); producer->wfx.wFormatTag = WAVE_FORMAT_PCM; producer->wfx.nChannels = TDAV_PRODUCER_AUDIO(producer)->channels; producer->wfx.nSamplesPerSec = TDAV_PRODUCER_AUDIO(producer)->rate; producer->wfx.wBitsPerSample = TDAV_PRODUCER_AUDIO(producer)->bits_per_sample; producer->wfx.nBlockAlign = (producer->wfx.nChannels * producer->wfx.wBitsPerSample/8); producer->wfx.nAvgBytesPerSec = (producer->wfx.nSamplesPerSec * producer->wfx.nBlockAlign); /* Average bytes (count) for each notification */ producer->bytes_per_notif = ((producer->wfx.nAvgBytesPerSec * TDAV_PRODUCER_AUDIO(producer)->ptime)/1000); /* create buffers */ for(i = 0; i< sizeof(producer->hWaveHeaders)/sizeof(LPWAVEHDR); i++){ create_wavehdr(producer, i); } return 0; }
//#define tdav_producer_audioqueue_set tsk_null int tdav_producer_audioqueue_set(tmedia_producer_t* self, const tmedia_param_t* param) { tdav_producer_audioqueue_t* producer = (tdav_producer_audioqueue_t*)self; if(param->plugin_type == tmedia_ppt_producer){ if(param->value_type == tmedia_pvt_int32){ if(tsk_striequals(param->key, "mute")){ producer->muted = TSK_TO_INT32((uint8_t*)param->value); return 1; } } } return tdav_producer_audio_set(TDAV_PRODUCER_AUDIO(self), param); }
/* ============ Media Producer Interface ================= */ int tdav_producer_audiounit_set(tmedia_producer_t* self, const tmedia_param_t* param) { tdav_producer_audiounit_t* producer = (tdav_producer_audiounit_t*)self; if(param->plugin_type == tmedia_ppt_producer){ if(param->value_type == tmedia_pvt_int32){ if (tsk_striequals(param->key, "mute")) { producer->muted = TSK_TO_INT32((uint8_t*)param->value); return tdav_audiounit_handle_mute(((tdav_producer_audiounit_t*)self)->audioUnitHandle, producer->muted); } else if (tsk_striequals(param->key, "interrupt")) { int32_t interrupt = *((uint8_t*)param->value) ? 1 : 0; return tdav_audiounit_handle_interrupt(producer->audioUnitHandle, interrupt); } } } return tdav_producer_audio_set(TDAV_PRODUCER_AUDIO(self), param); }
/* ============ Media Producer Interface ================= */ int tdav_producer_dsound_prepare(tmedia_producer_t* self, const tmedia_codec_t* codec) { HRESULT hr; WAVEFORMATEX wfx = {0}; DSCBUFFERDESC dsbd = {0}; tdav_producer_dsound_t* dsound = (tdav_producer_dsound_t*)self; if(!dsound || !codec){ TSK_DEBUG_ERROR("Invalid parameter"); return -1; } if(dsound->device || dsound->captureBuffer){ TSK_DEBUG_ERROR("Producer already prepared"); return -2; } TDAV_PRODUCER_AUDIO(dsound)->channels = codec->plugin->audio.channels; TDAV_PRODUCER_AUDIO(dsound)->rate = codec->plugin->rate; /* Create capture device */ if((hr = DirectSoundCaptureCreate(NULL, &dsound->device, NULL) != DS_OK)){ tdav_win32_print_error("DirectSoundCaptureCreate", hr); return -3; } /* Creates the capture buffer */ wfx.wFormatTag = WAVE_FORMAT_PCM; wfx.nChannels = TDAV_PRODUCER_AUDIO(dsound)->channels; wfx.nSamplesPerSec = TDAV_PRODUCER_AUDIO(dsound)->rate; wfx.wBitsPerSample = TDAV_PRODUCER_AUDIO(dsound)->bits_per_sample; wfx.nBlockAlign = (wfx.nChannels * wfx.wBitsPerSample/8); wfx.nAvgBytesPerSec = (wfx.nSamplesPerSec * wfx.nBlockAlign); /* Average bytes (count) for each notification */ dsound->bytes_per_notif = ((wfx.nAvgBytesPerSec * TDAV_PRODUCER_AUDIO(dsound)->ptime)/1000); dsbd.dwSize = sizeof(DSCBUFFERDESC); dsbd.dwBufferBytes = (TDAV_DSOUNS_PRODUCER_NOTIF_POS_COUNT * dsound->bytes_per_notif); dsbd.lpwfxFormat = &wfx; if((hr = IDirectSoundCapture_CreateCaptureBuffer(dsound->device, &dsbd, &dsound->captureBuffer, NULL)) != DS_OK){ tdav_win32_print_error("IDirectSoundCapture_CreateCaptureBuffer", hr); return -4; } return 0; }
/** * Generic function to compare two producers. * @param producer1 The first producer to compare. * @param producer2 The second producer to compare. * @retval Returns an integral value indicating the relationship between the two producers: * <0 : @a producer1 less than @a producer2.<br> * 0 : @a producer1 identical to @a producer2.<br> * >0 : @a producer1 greater than @a producer2.<br> */ int tdav_producer_audio_cmp(const tsk_object_t* producer1, const tsk_object_t* producer2) { return (TDAV_PRODUCER_AUDIO(producer1) - TDAV_PRODUCER_AUDIO(producer2)); }