/* Grab a free PCM frame */
static uint32_t * voice_buf_get(void)
{
    if (voice_unplayed_frames() >= VOICE_FRAMES)
    {
        /* Full */
        voice_start_playback();
        return NULL;
    }

    return voicebuf[cur_buf_in % VOICE_FRAMES];
}
/* Decode frames or stop if all have completed */
static enum voice_state voice_decode(struct voice_thread_data *td)
{
    if (!queue_empty(&voice_queue))
        return VOICE_STATE_MESSAGE;

    /* Decode the data */
    if (speex_decode_int(td->st, &td->bits, voice_output_buf) < 0)
    {
        /* End of stream or error - get next clip */
        td->vi.size = 0;

        if (td->vi.get_more != NULL)
            td->vi.get_more(&td->vi.start, &td->vi.size);

        if (td->vi.start != NULL && (ssize_t)td->vi.size > 0)
        {
            /* Make bit buffer use our own buffer */
            speex_bits_set_bit_buffer(&td->bits, td->vi.start, td->vi.size);
            /* Don't skip any samples when we're stringing clips together */
            td->lookahead = 0;
        }
        else
        {
            /* If all clips are done and not playing, force pcm playback. */
            voice_start_playback();
            return VOICE_STATE_MESSAGE;
        }
    }
    else
    {
        yield();

        /* Output the decoded frame */
        td->count = VOICE_FRAME_SIZE - td->lookahead;
        td->src[0] = (const char *)&voice_output_buf[td->lookahead];
        td->src[1] = NULL;
        td->lookahead -= MIN(VOICE_FRAME_SIZE, td->lookahead);

        if (td->count > 0)
            return VOICE_STATE_BUFFER_INSERT;
    }

    return VOICE_STATE_DECODE;
}
예제 #3
0
int msm_reset_all_device(void)
{
	int rc = 0;
	int dev_id = 0;
	struct msm_snddev_info *dev_info = NULL;

	for (dev_id = 0; dev_id < audio_dev_ctrl.num_dev; dev_id++) {
		dev_info = audio_dev_ctrl_find_dev(dev_id);
		if (IS_ERR(dev_info)) {
			pr_err("%s:pass invalid dev_id\n", __func__);
			rc = PTR_ERR(dev_info);
			return rc;
		}
		if (!dev_info->opened)
			continue;
		pr_debug("%s:Resetting device %d active on COPP %d"
			"with  %lld as routing\n", __func__,
				dev_id, dev_info->copp_id, dev_info->sessions);
		broadcast_event(AUDDEV_EVT_REL_PENDING,
					dev_id,
					SESSION_IGNORE);
		rc = dev_info->dev_ops.close(dev_info);
		if (rc < 0) {
			pr_err("%s:Snd device failed close!\n", __func__);
			return rc;
		} else {
			dev_info->opened = 0;
			broadcast_event(AUDDEV_EVT_DEV_RLS,
				dev_id,
				SESSION_IGNORE);

			if (dev_info->copp_id == VOICE_PLAYBACK_TX)
				voice_start_playback(0);
		}
		dev_info->sessions = 0;
	}
	msm_clear_all_session();
	return 0;
}
예제 #4
0
int msm_snddev_set_dec(int popp_id, int copp_id, int set,
					int rate, int mode)
{
	int rc = 0, i = 0;
	int rc2 = 0;

	if ((popp_id >= MAX_SESSIONS) || (popp_id <= 0)) {
		pr_err("%s: Invalid session id %d\n", __func__, popp_id);
		return 0;
	}

	mutex_lock(&routing_info.adm_mutex);
	if (set) {
		rc = adm_open(copp_id, PLAYBACK, rate, mode,
			DEFAULT_COPP_TOPOLOGY);
		if (rc < 0) {
			pr_err("%s: adm open fail rc[%d]\n", __func__, rc);
			rc = -EINVAL;
			mutex_unlock(&routing_info.adm_mutex);
			return rc;
		}
		msm_set_copp_id(popp_id, copp_id);
		pr_debug("%s:Session id=%d copp_id=%d\n",
			__func__, popp_id, copp_id);
		rc = msm_check_multicopp_per_stream(popp_id);
		pr_err("rc = %d\n", rc);
		rc2 = msm_check_multistream_per_copp(copp_id);
		pr_err("rc2 = %d\n", rc2);

		if (rc == 1 && rc2 == 1) {
			pr_debug("Calling one to one routing\n");
			rc = adm_matrix_map(popp_id, PLAYBACK, 1, &copp_id);
			if (rc < 0) {
				pr_err("%s: matrix map failed rc[%d]\n",
					 __func__, rc);
				adm_close(copp_id);
				rc = -EINVAL;
				mutex_unlock(&routing_info.adm_mutex);
				return rc;
			}
		} else {
			if (rc > 1) {
				pr_debug("Calling one to many routing rc =%d\n",
					rc);
				pr_debug("No of copps = %d\n",
					payload.num_copps);
				rc = adm_route_mcopp(popp_id, (void *)&payload,
							PLAYBACK, ONE_TO_MANY);
				if (rc < 0) {
					pr_err("%s: adm_route_mcopp fail"
					"rc[%d]\n", __func__, rc);
					rc = -EINVAL;
					mutex_unlock(&routing_info.adm_mutex);
					return rc;
				}
			} else if (rc2 > 1) {
				pr_debug("Calling many to one routing rc2=%d\n",
					rc2);
				pr_debug("No of sessions = %d\n",
					payload.num_sessions);
				rc = adm_route_mcopp(popp_id, (void *)&payload,
							PLAYBACK, MANY_TO_ONE);
				if (rc < 0) {
					pr_err("%s: adm_route_mcopp fail"
					"rc[%d]\n", __func__, rc);
					rc = -EINVAL;
					mutex_unlock(&routing_info.adm_mutex);
					return rc;
				}
			}
		}
	} else {
		for (i = 0; i < AFE_MAX_PORTS; i++) {
			if (routing_info.copp_list[popp_id][i] == copp_id) {
				rc = adm_close(copp_id);
				if (rc < 0) {
					pr_err("%s: adm close fail copp[%d]"
						"rc[%d]\n",
						__func__, copp_id, rc);
					rc = -EINVAL;
					mutex_unlock(&routing_info.adm_mutex);
					return rc;
				}
				msm_clear_copp_id(popp_id, copp_id);
				break;
			}
		}
	}

	if (copp_id == VOICE_PLAYBACK_TX) {
		/* Signal uplink playback. */
		rc = voice_start_playback(set);
	}
	mutex_unlock(&routing_info.adm_mutex);
	return rc;
}
예제 #5
0
int msm_snddev_set_dec(int popp_id, int copp_id, int set,
					int rate, int mode)
{
	int rc = 0, i = 0, num_copps;
	struct route_payload payload;

	if ((popp_id >= MAX_SESSIONS) || (popp_id <= 0)) {
		pr_err("%s: Invalid session id %d\n", __func__, popp_id);
		return 0;
	}

	mutex_lock(&routing_info.adm_mutex);
	if (set) {
		rc = adm_open(copp_id, ADM_PATH_PLAYBACK, rate, mode,
			DEFAULT_COPP_TOPOLOGY);
		if (rc < 0) {
			pr_err("%s: adm open fail rc[%d]\n", __func__, rc);
			rc = -EINVAL;
			mutex_unlock(&routing_info.adm_mutex);
			return rc;
		}
		msm_set_copp_id(popp_id, copp_id);
		pr_debug("%s:Session id=%d copp_id=%d\n",
			__func__, popp_id, copp_id);
		memset(payload.copp_ids, COPP_IGNORE,
				(sizeof(unsigned int) * AFE_MAX_PORTS));
		num_copps = msm_check_multicopp_per_stream(popp_id, &payload);
		
		rc = adm_matrix_map(popp_id, ADM_PATH_PLAYBACK, num_copps,
					payload.copp_ids, copp_id);
		if (rc < 0) {
			pr_err("%s: matrix map failed rc[%d]\n",
				__func__, rc);
			adm_close(copp_id);
			rc = -EINVAL;
			mutex_unlock(&routing_info.adm_mutex);
			return rc;
		}
#ifdef CONFIG_MSM8X60_RTAC
		for (i = 0; i < num_copps; i++)
			rtac_add_adm_device(payload.copp_ids[i], popp_id);
#endif
	} else {
		for (i = 0; i < AFE_MAX_PORTS; i++) {
			if (routing_info.copp_list[popp_id][i] == copp_id) {
				rc = adm_close(copp_id);
				if (rc < 0) {
					pr_err("%s: adm close fail copp[%d]"
						"rc[%d]\n",
						__func__, copp_id, rc);
					rc = -EINVAL;
					mutex_unlock(&routing_info.adm_mutex);
					return rc;
				}
				msm_clear_copp_id(popp_id, copp_id);
				break;
			}
		}
	}

	if (copp_id == VOICE_PLAYBACK_TX) {
		
		rc = voice_start_playback(set);
	}
	mutex_unlock(&routing_info.adm_mutex);
	return rc;
}
예제 #6
0
int msm_snddev_set_dec(int popp_id, int copp_id, int set,
					int rate, int mode)
{
	int rc = 0, i = 0, num_copps;
	struct route_payload payload;

	if ((popp_id >= MAX_SESSIONS) || (popp_id <= 0)) {
		pr_err("%s: Invalid session id %d\n", __func__, popp_id);
		return 0;
	}

	mutex_lock(&routing_info.adm_mutex);
	if (set) {
		rc = adm_open(copp_id, ADM_PATH_PLAYBACK, rate, mode,
			DEFAULT_COPP_TOPOLOGY);
		if (rc < 0) {
			pr_err("%s: adm open fail rc[%d]\n", __func__, rc);
			rc = -EINVAL;
			goto fail_cmd;
		}

	 rc = adm_matrix_map(popp_id, PLAYBACK, 1, &copp_id);
	 if (rc < 0) {
	 pr_err("%s: matrix map failed rc[%d]\n", __func__, rc);
	 adm_close(copp_id);
	 rc = -EINVAL;
	 goto fail_cmd;
		msm_set_copp_id(popp_id, copp_id);
		pr_debug("%s:Session id=%d copp_id=%d\n",
			__func__, popp_id, copp_id);
		memset(payload.copp_ids, COPP_IGNORE,
				(sizeof(unsigned int) * AFE_MAX_PORTS));
		num_copps = msm_check_multicopp_per_stream(popp_id, &payload);
		/* Multiple streams per copp is handled, one stream at a time */
		rc = adm_matrix_map(popp_id, ADM_PATH_PLAYBACK, num_copps,
					payload.copp_ids, copp_id);
		if (rc < 0) {
			pr_err("%s: matrix map failed rc[%d]\n",
				__func__, rc);
			adm_close(copp_id);
			rc = -EINVAL;
			mutex_unlock(&routing_info.adm_mutex);
			return rc;
		}
#ifdef CONFIG_MSM8X60_RTAC
		for (i = 0; i < num_copps; i++)
			rtac_add_adm_device(payload.copp_ids[i], popp_id);
#endif
	} else {
		for (i = 0; i < AFE_MAX_PORTS; i++) {
			if (routing_info.copp_list[popp_id][i] == copp_id) {
				rc = adm_close(copp_id);
				if (rc < 0) {
					pr_err("%s: adm close fail copp[%d]"
						"rc[%d]\n",
						__func__, copp_id, rc);
					rc = -EINVAL;
					mutex_unlock(&routing_info.adm_mutex);
					return rc;
				}
				msm_clear_copp_id(popp_id, copp_id);
				break;
			}
		}
	}

	if (copp_id == VOICE_PLAYBACK_TX) {
		/* Signal uplink playback. */
		rc = voice_start_playback(set);
	}
	mutex_unlock(&routing_info.adm_mutex);
	return rc;
}
EXPORT_SYMBOL(msm_snddev_set_dec);


static int check_tx_copp_topology(int session_id)
{
	int cnt;
	int ret_val = -ENOENT;

	cnt = adm_tx_topology_tbl.session_cnt;
	if (cnt) {
		do {
			if (adm_tx_topology_tbl.session_id[cnt-1]
				== session_id)
				ret_val = cnt-1;
		} while (--cnt);
	}

	return ret_val;
}
int msm_snddev_set_dec(int popp_id, int copp_id, int set,
					int rate, int mode)
{
	int rc = 0, i = 0;
	struct route_payload payload;
	int topology = DEFAULT_COPP_TOPOLOGY;

	if ((popp_id >= MAX_SESSIONS) || (popp_id <= 0)) {
		pr_aud_err("%s: Invalid session id %d\n", __func__, popp_id);
		return 0;
	}

	mutex_lock(&routing_info.adm_mutex);
	if (set) {
		if (ctrl_ops->support_opendsp) {
			if (ctrl_ops->support_opendsp())
				topology = HTC_COPP_TOPOLOGY;
		}
		pr_aud_info("%s, topology = 0x%x\n", __func__, topology);
		rc = adm_open(copp_id, PLAYBACK, rate, mode,
			topology);
		if (rc < 0) {
			pr_aud_err("%s: adm open fail rc[%d]\n", __func__, rc);
			rc = -EINVAL;
			mutex_unlock(&routing_info.adm_mutex);
			return rc;
		}
		msm_set_copp_id(popp_id, copp_id);
		pr_debug("%s:Session id=%d copp_id=%d\n",
			__func__, popp_id, copp_id);
		memset(payload.copp_ids, DEVICE_IGNORE,
				(sizeof(unsigned int) * AFE_MAX_PORTS));
		rc = msm_check_multicopp_per_stream(popp_id, &payload);
		/* Multiple streams per copp is handled, one stream at a time */
		rc = adm_matrix_map(popp_id, PLAYBACK, rc,
					payload.copp_ids, copp_id);
		if (rc < 0) {
			pr_aud_err("%s: matrix map failed rc[%d]\n",
				__func__, rc);
			adm_close(copp_id);
			rc = -EINVAL;
			mutex_unlock(&routing_info.adm_mutex);
			return rc;
		}
	} else {
		for (i = 0; i < AFE_MAX_PORTS; i++) {
			if (routing_info.copp_list[popp_id][i] == copp_id) {
				rc = adm_close(copp_id);
				if (rc < 0) {
					pr_aud_err("%s: adm close fail copp[%d]"
						"rc[%d]\n",
						__func__, copp_id, rc);
					rc = -EINVAL;
					mutex_unlock(&routing_info.adm_mutex);
					return rc;
				}
				msm_clear_copp_id(popp_id, copp_id);
				break;
			}
		}
	}

	if (copp_id == VOICE_PLAYBACK_TX) {
		/* Signal uplink playback. */
		rc = voice_start_playback(set);
	}
	mutex_unlock(&routing_info.adm_mutex);
	return rc;
}