Lines Matching refs:handle
106 void (*thermal_client_unregister_callback)(int handle);
124 static struct speaker_prot_session handle; variable
131 handle.spkr_in_use = true; in spkr_prot_set_spkrstatus()
133 handle.spkr_in_use = false; in spkr_prot_set_spkrstatus()
134 clock_gettime(CLOCK_BOOTTIME, &handle.spkr_last_time_used); in spkr_prot_set_spkrstatus()
145 if (pthread_equal(handle.speaker_prot_threadid, threadid) || !adev) { in audio_extn_spkr_prot_calib_cancel()
151 pthread_mutex_lock(&handle.mutex_spkr_prot); in audio_extn_spkr_prot_calib_cancel()
152 pthread_mutex_lock(&handle.spkr_calib_cancelack_mutex); in audio_extn_spkr_prot_calib_cancel()
153 handle.cancel_spkr_calib = 1; in audio_extn_spkr_prot_calib_cancel()
154 pthread_cond_signal(&handle.spkr_calib_cancel); in audio_extn_spkr_prot_calib_cancel()
155 pthread_mutex_unlock(&handle.mutex_spkr_prot); in audio_extn_spkr_prot_calib_cancel()
156 pthread_cond_wait(&handle.spkr_calibcancel_ack, in audio_extn_spkr_prot_calib_cancel()
157 &handle.spkr_calib_cancelack_mutex); in audio_extn_spkr_prot_calib_cancel()
158 pthread_mutex_unlock(&handle.spkr_calib_cancelack_mutex); in audio_extn_spkr_prot_calib_cancel()
170 if (handle.spkr_in_use) { in is_speaker_in_use()
175 *sec = temp.tv_sec - handle.spkr_last_time_used.tv_sec; in is_speaker_in_use()
298 struct audio_device *adev = handle.adev_handle; in spkr_calibrate()
355 handle.pcm_rx = handle.pcm_tx = NULL; in spkr_calibrate()
356 handle.pcm_rx = pcm_open(adev->snd_card, in spkr_calibrate()
359 if (handle.pcm_rx && !pcm_is_ready(handle.pcm_rx)) { in spkr_calibrate()
360 ALOGE("%s: %s", __func__, pcm_get_error(handle.pcm_rx)); in spkr_calibrate()
387 handle.pcm_tx = pcm_open(adev->snd_card, in spkr_calibrate()
390 if (handle.pcm_tx && !pcm_is_ready(handle.pcm_tx)) { in spkr_calibrate()
391 ALOGE("%s: %s", __func__, pcm_get_error(handle.pcm_tx)); in spkr_calibrate()
395 if (pcm_start(handle.pcm_rx) < 0) { in spkr_calibrate()
400 if (pcm_start(handle.pcm_tx) < 0) { in spkr_calibrate()
409 pthread_mutex_lock(&handle.mutex_spkr_prot); in spkr_calibrate()
412 (void)pthread_cond_timedwait(&handle.spkr_calib_cancel, in spkr_calibrate()
413 &handle.mutex_spkr_prot, &ts); in spkr_calibrate()
415 pthread_mutex_lock(&handle.spkr_calib_cancelack_mutex); in spkr_calibrate()
416 if (handle.cancel_spkr_calib) { in spkr_calibrate()
467 if (handle.pcm_rx) in spkr_calibrate()
468 pcm_close(handle.pcm_rx); in spkr_calibrate()
469 handle.pcm_rx = NULL; in spkr_calibrate()
471 if (handle.pcm_tx) in spkr_calibrate()
472 pcm_close(handle.pcm_tx); in spkr_calibrate()
473 handle.pcm_tx = NULL; in spkr_calibrate()
497 handle.spkr_prot_mode = MSM_SPKR_PROT_CALIBRATED; in spkr_calibrate()
500 handle.spkr_prot_mode = MSM_SPKR_PROT_NOT_CALIBRATED; in spkr_calibrate()
507 if (!handle.cancel_spkr_calib && cleanup) { in spkr_calibrate()
508 pthread_mutex_unlock(&handle.spkr_calib_cancelack_mutex); in spkr_calibrate()
509 pthread_cond_wait(&handle.spkr_calib_cancel, &handle.mutex_spkr_prot); in spkr_calibrate()
510 pthread_mutex_lock(&handle.spkr_calib_cancelack_mutex); in spkr_calibrate()
525 if (handle.cancel_spkr_calib) in spkr_calibrate()
526 pthread_cond_signal(&handle.spkr_calibcancel_ack); in spkr_calibrate()
527 handle.cancel_spkr_calib = 0; in spkr_calibrate()
528 pthread_mutex_unlock(&handle.spkr_calib_cancelack_mutex); in spkr_calibrate()
529 pthread_mutex_unlock(&handle.mutex_spkr_prot); in spkr_calibrate()
544 struct audio_device *adev = handle.adev_handle; in spkr_calibration_thread()
556 handle.speaker_prot_threadid = pthread_self(); in spkr_calibration_thread()
564 handle.spkr_prot_mode = MSM_SPKR_PROT_DISABLED; in spkr_calibration_thread()
567 handle.spkr_prot_mode = MSM_SPKR_PROT_NOT_CALIBRATED; in spkr_calibration_thread()
569 handle.spkr_prot_mode = MSM_SPKR_PROT_DISABLED; in spkr_calibration_thread()
572 if (handle.spkr_prot_mode == MSM_SPKR_PROT_DISABLED) { in spkr_calibration_thread()
614 handle.spkr_prot_mode = MSM_SPKR_PROT_DISABLED; in spkr_calibration_thread()
616 handle.spkr_prot_mode = MSM_SPKR_PROT_CALIBRATED; in spkr_calibration_thread()
626 if (!handle.thermal_client_request("spkr",1)) { in spkr_calibration_thread()
628 pthread_mutex_lock(&handle.spkr_prot_thermalsync_mutex); in spkr_calibration_thread()
629 pthread_cond_wait(&handle.spkr_prot_thermalsync, in spkr_calibration_thread()
630 &handle.spkr_prot_thermalsync_mutex); in spkr_calibration_thread()
632 t0 = (handle.spkr_prot_t0 * (1 << 6)); in spkr_calibration_thread()
633 pthread_mutex_unlock(&handle.spkr_prot_thermalsync_mutex); in spkr_calibration_thread()
636 handle.spkr_prot_t0); in spkr_calibration_thread()
640 handle.spkr_prot_t0); in spkr_calibration_thread()
681 if (handle.thermal_client_handle) in spkr_calibration_thread()
682 handle.thermal_client_unregister_callback(handle.thermal_client_handle); in spkr_calibration_thread()
683 handle.thermal_client_handle = 0; in spkr_calibration_thread()
684 if (handle.thermal_handle) in spkr_calibration_thread()
685 dlclose(handle.thermal_handle); in spkr_calibration_thread()
686 handle.thermal_handle = NULL; in spkr_calibration_thread()
693 pthread_mutex_lock(&handle.spkr_prot_thermalsync_mutex); in thermal_client_callback()
695 if (handle.spkr_prot_mode == MSM_SPKR_PROT_NOT_CALIBRATED) in thermal_client_callback()
696 handle.spkr_prot_t0 = temp; in thermal_client_callback()
697 pthread_cond_signal(&handle.spkr_prot_thermalsync); in thermal_client_callback()
698 pthread_mutex_unlock(&handle.spkr_prot_thermalsync_mutex); in thermal_client_callback()
706 memset(&handle, 0, sizeof(handle)); in audio_extn_spkr_prot_init()
712 handle.spkr_prot_enable = false; in audio_extn_spkr_prot_init()
714 handle.spkr_prot_enable = true; in audio_extn_spkr_prot_init()
715 if (!handle.spkr_prot_enable) { in audio_extn_spkr_prot_init()
719 handle.adev_handle = adev; in audio_extn_spkr_prot_init()
720 handle.spkr_prot_mode = MSM_SPKR_PROT_DISABLED; in audio_extn_spkr_prot_init()
721 handle.spkr_processing_state = SPKR_PROCESSING_IN_IDLE; in audio_extn_spkr_prot_init()
722 handle.spkr_prot_t0 = -1; in audio_extn_spkr_prot_init()
723 pthread_cond_init(&handle.spkr_prot_thermalsync, NULL); in audio_extn_spkr_prot_init()
724 pthread_cond_init(&handle.spkr_calib_cancel, NULL); in audio_extn_spkr_prot_init()
725 pthread_cond_init(&handle.spkr_calibcancel_ack, NULL); in audio_extn_spkr_prot_init()
726 pthread_mutex_init(&handle.mutex_spkr_prot, NULL); in audio_extn_spkr_prot_init()
727 pthread_mutex_init(&handle.spkr_calib_cancelack_mutex, NULL); in audio_extn_spkr_prot_init()
728 pthread_mutex_init(&handle.spkr_prot_thermalsync_mutex, NULL); in audio_extn_spkr_prot_init()
729 handle.thermal_handle = dlopen(THERMAL_CLIENT_LIBRARY_PATH, in audio_extn_spkr_prot_init()
731 if (!handle.thermal_handle) { in audio_extn_spkr_prot_init()
735 handle.thermal_client_register_callback = in audio_extn_spkr_prot_init()
737 dlsym(handle.thermal_handle, "thermal_client_register_callback"); in audio_extn_spkr_prot_init()
738 handle.thermal_client_unregister_callback = in audio_extn_spkr_prot_init()
740 dlsym(handle.thermal_handle, "thermal_client_unregister_callback"); in audio_extn_spkr_prot_init()
741 if (!handle.thermal_client_register_callback || in audio_extn_spkr_prot_init()
742 !handle.thermal_client_unregister_callback) { in audio_extn_spkr_prot_init()
746 handle.thermal_client_handle = in audio_extn_spkr_prot_init()
747 handle.thermal_client_register_callback("spkr", thermal_client_callback, NULL); in audio_extn_spkr_prot_init()
748 if (!handle.thermal_client_handle) { in audio_extn_spkr_prot_init()
752 handle.thermal_client_request = (int (*)(char *, int)) in audio_extn_spkr_prot_init()
753 dlsym(handle.thermal_handle, "thermal_client_request"); in audio_extn_spkr_prot_init()
757 if (handle.thermal_client_request) { in audio_extn_spkr_prot_init()
759 (void)pthread_create(&handle.spkr_calibration_thread, in audio_extn_spkr_prot_init()
760 (const pthread_attr_t *) NULL, spkr_calibration_thread, &handle); in audio_extn_spkr_prot_init()
763 if (handle.thermal_client_handle && in audio_extn_spkr_prot_init()
764 handle.thermal_client_unregister_callback) in audio_extn_spkr_prot_init()
765 handle.thermal_client_unregister_callback(handle.thermal_client_handle); in audio_extn_spkr_prot_init()
766 if (handle.thermal_handle) in audio_extn_spkr_prot_init()
767 dlclose(handle.thermal_handle); in audio_extn_spkr_prot_init()
768 handle.thermal_handle = NULL; in audio_extn_spkr_prot_init()
769 handle.spkr_prot_enable = false; in audio_extn_spkr_prot_init()
772 if (handle.spkr_prot_enable) { in audio_extn_spkr_prot_init()
790 if (!handle.spkr_prot_enable) in audio_extn_get_spkr_prot_snd_device()
806 struct audio_device *adev = handle.adev_handle; in audio_extn_spkr_prot_start_processing()
826 pthread_mutex_lock(&handle.mutex_spkr_prot); in audio_extn_spkr_prot_start_processing()
827 if (handle.spkr_processing_state == SPKR_PROCESSING_IN_IDLE) { in audio_extn_spkr_prot_start_processing()
832 handle.pcm_tx = NULL; in audio_extn_spkr_prot_start_processing()
844 handle.pcm_tx = pcm_open(adev->snd_card, in audio_extn_spkr_prot_start_processing()
847 if (handle.pcm_tx && !pcm_is_ready(handle.pcm_tx)) { in audio_extn_spkr_prot_start_processing()
848 ALOGE("%s: %s", __func__, pcm_get_error(handle.pcm_tx)); in audio_extn_spkr_prot_start_processing()
852 if (pcm_start(handle.pcm_tx) < 0) { in audio_extn_spkr_prot_start_processing()
875 if (handle.pcm_tx) in audio_extn_spkr_prot_start_processing()
876 pcm_close(handle.pcm_tx); in audio_extn_spkr_prot_start_processing()
877 handle.pcm_tx = NULL; in audio_extn_spkr_prot_start_processing()
883 handle.spkr_processing_state = SPKR_PROCESSING_IN_PROGRESS; in audio_extn_spkr_prot_start_processing()
884 pthread_mutex_unlock(&handle.mutex_spkr_prot); in audio_extn_spkr_prot_start_processing()
892 struct audio_device *adev = handle.adev_handle; in audio_extn_spkr_prot_stop_processing()
897 pthread_mutex_lock(&handle.mutex_spkr_prot); in audio_extn_spkr_prot_stop_processing()
898 if (adev && handle.spkr_processing_state == SPKR_PROCESSING_IN_PROGRESS) { in audio_extn_spkr_prot_stop_processing()
900 if (handle.pcm_tx) in audio_extn_spkr_prot_stop_processing()
901 pcm_close(handle.pcm_tx); in audio_extn_spkr_prot_stop_processing()
902 handle.pcm_tx = NULL; in audio_extn_spkr_prot_stop_processing()
910 handle.spkr_processing_state = SPKR_PROCESSING_IN_IDLE; in audio_extn_spkr_prot_stop_processing()
911 pthread_mutex_unlock(&handle.mutex_spkr_prot); in audio_extn_spkr_prot_stop_processing()
920 return handle.spkr_prot_enable; in audio_extn_spkr_prot_is_enabled()