Ejemplo n.º 1
0
static long q6_aac_in_ioctl(struct file *file,
				 unsigned int cmd, unsigned long arg)
{
	struct aac *aac = file->private_data;
	int rc = 0;
	int i = 0;
	struct aac_fc *fc;
	int size = 0;

	mutex_lock(&aac->lock);
	switch (cmd) {
	case AUDIO_SET_VOLUME:
		break;
	case AUDIO_GET_STATS:
	{
		struct msm_audio_stats stats;
		pr_debug("[%s:%s] GET_STATS\n", __MM_FILE__, __func__);
		memset(&stats, 0, sizeof(stats));
		if (copy_to_user((void *) arg, &stats, sizeof(stats)))
			return -EFAULT;
		return 0;
	}
	case AUDIO_START:
	{
		uint32_t acdb_id;
		pr_debug("[%s:%s] AUDIO_START\n", __MM_FILE__, __func__);
		if (arg == 0) {
			acdb_id = 0;
		} else {
			if (copy_from_user(&acdb_id, (void *) arg,
					sizeof(acdb_id))) {
				rc = -EFAULT;
				break;
			}
		}
		if (aac->audio_client) {
			rc = -EBUSY;
			pr_err("[%s:%s] active session already existing\n",
				__MM_FILE__, __func__);
			break;
		} else {
			aac->audio_client = q6audio_open_aac(
					aac->str_cfg.buffer_size,
					aac->cfg.sample_rate,
					aac->cfg.channels,
					aac->cfg.bit_rate,
					aac->cfg.stream_format,
					aac->voicerec_mode.rec_mode, acdb_id);

			if (aac->audio_client < 0) {
				pr_err("[%s:%s] aac open session failed\n",
					__MM_FILE__, __func__);
				rc = -ENOMEM;
				break;
			}
		}

		/*allocate flow control buffers*/
		fc = aac->aac_fc;
		size = ((aac->str_cfg.buffer_size < 1543) ? 1543 :
				aac->str_cfg.buffer_size);
		for (i = 0; i < AAC_FC_BUFF_CNT; ++i) {
			mutex_init(&(fc->fc_buff[i].lock));
			fc->fc_buff[i].empty = 1;
			fc->fc_buff[i].data = kmalloc(size, GFP_KERNEL);
			if (fc->fc_buff[i].data == NULL) {
				pr_err("[%s:%s] No memory for FC buffers\n",
						__MM_FILE__, __func__);
				rc = -ENOMEM;
				goto fc_fail;
			}
			fc->fc_buff[i].size = size;
			fc->fc_buff[i].actual_size = 0;
		}

		/*create flow control thread*/
		fc->task = kthread_run(q6_aac_flowcontrol,
				aac, "aac_flowcontrol");
		if (IS_ERR(fc->task)) {
			rc = PTR_ERR(fc->task);
			pr_err("[%s:%s] error creating flow control thread\n",
					__MM_FILE__, __func__);
			goto fc_fail;
		}
		break;
fc_fail:
		/*free flow control buffers*/
		--i;
		for (; i >=  0; i--) {
			kfree(fc->fc_buff[i].data);
			fc->fc_buff[i].data = NULL;
		}
		break;
	}
	case AUDIO_STOP:
		pr_debug("[%s:%s] AUDIO_STOP\n", __MM_FILE__, __func__);
		break;
	case AUDIO_FLUSH:
		break;
	case AUDIO_SET_INCALL: {
		pr_debug("[%s:%s] SET_INCALL\n", __MM_FILE__, __func__);
		if (copy_from_user(&aac->voicerec_mode,
			(void *)arg, sizeof(struct msm_voicerec_mode)))
			rc = -EFAULT;

		if (aac->voicerec_mode.rec_mode != AUDIO_FLAG_READ
			&& aac->voicerec_mode.rec_mode !=
			AUDIO_FLAG_INCALL_MIXED) {
			aac->voicerec_mode.rec_mode = AUDIO_FLAG_READ;
			pr_err("[%s:%s] Invalid rec_mode\n", __MM_FILE__,
					__func__);
			rc = -EINVAL;
		}
		break;
	}
	case AUDIO_GET_STREAM_CONFIG:
		if (copy_to_user((void *)arg, &aac->str_cfg,
			sizeof(struct msm_audio_stream_config)))
			rc = -EFAULT;
		pr_debug("[%s:%s] GET_STREAM_CONFIG: buffsz=%d, buffcnt=%d\n",
			 __MM_FILE__, __func__, aac->str_cfg.buffer_size,
			aac->str_cfg.buffer_count);
		break;
	case AUDIO_SET_STREAM_CONFIG:
		if (copy_from_user(&aac->str_cfg, (void *)arg,
			sizeof(struct msm_audio_stream_config))) {
			rc = -EFAULT;
			break;
		}
		pr_debug("[%s:%s] SET_STREAM_CONFIG: buffsz=%d, buffcnt=%d\n",
			 __MM_FILE__, __func__, aac->str_cfg.buffer_size,
			aac->str_cfg.buffer_count);
		if (aac->str_cfg.buffer_size < 1543) {
			pr_err("[%s:%s] Buffer size too small\n", __MM_FILE__,
					__func__);
			rc = -EINVAL;
			break;
		}
		if (aac->str_cfg.buffer_count != 2)
			pr_info("[%s:%s] Buffer count set to 2\n", __MM_FILE__,
					__func__);

		break;
	case AUDIO_SET_AAC_ENC_CONFIG:
		if (copy_from_user(&aac->cfg, (void *) arg,
				 sizeof(struct msm_audio_aac_enc_config))) {
			rc = -EFAULT;
		}
		pr_debug("[%s:%s] SET_AAC_ENC_CONFIG: channels=%d, rate=%d\n",
			__MM_FILE__, __func__, aac->cfg.channels,
			aac->cfg.sample_rate);
		if (aac->cfg.channels < 1 || aac->cfg.channels > 2) {
			pr_err("[%s:%s]invalid number of channels\n",
				 __MM_FILE__, __func__);
			rc = -EINVAL;
		}
		if (aac->cfg.sample_rate != 48000) {
			pr_err("[%s:%s] only 48KHz is supported\n",
					__MM_FILE__, __func__);
			rc = -EINVAL;
		}
		if (aac->cfg.stream_format != AUDIO_AAC_FORMAT_RAW &&
			aac->cfg.stream_format != AUDIO_AAC_FORMAT_ADTS) {
			pr_err("[%s:%s] unsupported AAC format\n", __MM_FILE__,
					__func__);
			rc = -EINVAL;
		}
		break;
	case AUDIO_GET_AAC_ENC_CONFIG:
		if (copy_to_user((void *) arg, &aac->cfg,
				 sizeof(struct msm_audio_aac_enc_config))) {
			rc = -EFAULT;
		}
		pr_debug("[%s:%s] GET_AAC_ENC_CONFIG: channels=%d, rate=%d\n",
			__MM_FILE__, __func__, aac->cfg.channels,
			aac->cfg.sample_rate);
		break;
	default:
		rc = -EINVAL;
	}

	mutex_unlock(&aac->lock);
	pr_debug("[%s:%s] rc = %d\n", __MM_FILE__, __func__, rc);
	return rc;
}
Ejemplo n.º 2
0
static long q6_aac_in_ioctl(struct file *file,
				 unsigned int cmd, unsigned long arg)
{
	struct aac *aac = file->private_data;
	int rc = 0;

	mutex_lock(&aac->lock);
	switch (cmd) {
	case AUDIO_SET_VOLUME:
		break;
	case AUDIO_GET_STATS:
	{
		struct msm_audio_stats stats;
		memset(&stats, 0, sizeof(stats));
		if (copy_to_user((void *) arg, &stats, sizeof(stats)))
			return -EFAULT;
		return 0;
	}
	case AUDIO_START:
	{
		uint32_t acdb_id;
		if (arg == 0) {
			acdb_id = 0;
		} else {
			if (copy_from_user(&acdb_id, (void *) arg,
					sizeof(acdb_id))) {
				rc = -EFAULT;
				break;
			}
		}
		if (aac->audio_client) {
			rc = -EBUSY;
			break;
		} else {
			aac->audio_client = q6audio_open_aac(
					aac->str_cfg.buffer_size,
					aac->cfg.sample_rate,
					aac->cfg.channels,
					aac->cfg.bit_rate,
					aac->cfg.stream_format,
					aac->voicerec_mode.rec_mode, acdb_id);

			if (aac->audio_client < 0) {
				rc = -ENOMEM;
				break;
			}
		}
		break;
	}
	case AUDIO_STOP:
		break;
	case AUDIO_FLUSH:
		break;
	case AUDIO_SET_INCALL: {
		if (copy_from_user(&aac->voicerec_mode,
			(void *)arg, sizeof(struct msm_voicerec_mode)))
			rc = -EFAULT;

		if (aac->voicerec_mode.rec_mode != AUDIO_FLAG_READ
			&& aac->voicerec_mode.rec_mode !=
			AUDIO_FLAG_INCALL_MIXED) {
			aac->voicerec_mode.rec_mode = AUDIO_FLAG_READ;
			pr_err("[%s:%s] Invalid rec_mode\n", __MM_FILE__,
					__func__);
			rc = -EINVAL;
		}
		break;
	}
	case AUDIO_GET_STREAM_CONFIG:
		if (copy_to_user((void *)arg, &aac->str_cfg,
			sizeof(struct msm_audio_stream_config)))
			rc = -EFAULT;
		break;
	case AUDIO_SET_STREAM_CONFIG:
		if (copy_from_user(&aac->str_cfg, (void *)arg,
			sizeof(struct msm_audio_stream_config))) {
			rc = -EFAULT;
			break;
		}
		if (aac->str_cfg.buffer_size < 1543) {
			pr_err("[%s:%s] Buffer size too small\n", __MM_FILE__,
					__func__);
			rc = -EINVAL;
			break;
		}
		if (aac->str_cfg.buffer_count != 2)
			pr_info("[%s:%s] Buffer count set to 2\n", __MM_FILE__,
					__func__);

		break;
	case AUDIO_SET_AAC_ENC_CONFIG:
		if (copy_from_user(&aac->cfg, (void *) arg,
				 sizeof(struct msm_audio_aac_enc_config))) {
			rc = -EFAULT;
		}
		if (aac->cfg.channels < 1 || aac->cfg.channels > 2) {
			pr_err("[%s:%s]invalid number of channels\n",
				 __MM_FILE__, __func__);
			rc = -EINVAL;
		}
		if (aac->cfg.sample_rate != 48000) {
			pr_err("[%s:%s] only 48KHz is supported\n",
					__MM_FILE__, __func__);
			rc = -EINVAL;
		}
		if (aac->cfg.stream_format != AUDIO_AAC_FORMAT_RAW &&
			aac->cfg.stream_format != AUDIO_AAC_FORMAT_ADTS) {
			pr_err("[%s:%s] unsupported AAC format\n", __MM_FILE__,
					__func__);
			rc = -EINVAL;
		}
		break;
	case AUDIO_GET_AAC_ENC_CONFIG:
		if (copy_to_user((void *) arg, &aac->cfg,
				 sizeof(struct msm_audio_aac_enc_config))) {
			rc = -EFAULT;
		}
		break;
	default:
		rc = -EINVAL;
	}

	mutex_unlock(&aac->lock);
	return rc;
}