Exemple #1
0
int alsa_swtich_port(alsa_param_t *alsa_params, int card, int port)
{
    char dev[10] = {0};
    adec_print("card = %d, port = %d\n", card, port);
    sprintf(dev, "hw:%d,%d", (card >= 0) ? card : 0, (port >= 0) ? port : 0);
    pthread_mutex_lock(&alsa_params->playback_mutex);
    snd_pcm_drop(alsa_params->handle);
    snd_pcm_close(alsa_params->handle);
    alsa_params->handle = NULL;
    int err = snd_pcm_open(&alsa_params->handle, dev, SND_PCM_STREAM_PLAYBACK, 0);

    if (err < 0) {
        adec_print("audio open error: %s", snd_strerror(err));
        pthread_mutex_unlock(&alsa_params->playback_mutex);
        return -1;
    }

    set_params_raw(alsa_params);
    pthread_mutex_unlock(&alsa_params->playback_mutex);

    return 0;
}
Exemple #2
0
/**
 * \brief get current audio pcrscr
 * \param dsp_ops pointer to dsp operation struct
 * \return current audio pcrscr otherwise -1 if an error occurred
 */
unsigned long  audiodsp_get_pcrscr(dsp_operations_t *dsp_ops)
{
    unsigned long val;

    if (dsp_ops->dsp_file_fd < 0) {
        adec_print("read error!! audiodsp have not opened\n");
        return -1;
    }

    ioctl(dsp_ops->dsp_file_fd, AUDIODSP_SYNC_GET_PCRSCR, &val);

    return val;
}
/**
 * \brief start audio dec
 * \param handle pointer to player private data
 * \return 0 on success otherwise -1 if an error occurred
 */
int audio_decode_start(void *handle)
{
    int ret;
    adec_cmd_t *cmd;
    aml_audio_dec_t *audec = (aml_audio_dec_t *)handle;

    if (!handle) {
        adec_print("audio handle is NULL !\n");
        return -1;
    }

    cmd = adec_message_alloc();
    if (cmd) {
        cmd->ctrl_cmd = CMD_START;
        ret = adec_send_message(audec, cmd);
    } else {
        adec_print("message alloc failed, no memory!");
        ret = -1;
    }

    return ret;
}
/**
 * \brief stop output
 * \param audec pointer to audec
 * \return 0 on success otherwise negative error code
 */
extern "C" int android_stop(struct aml_audio_dec* audec)
{
    adec_print("android out stop");

    audio_out_operations_t *out_ops = &audec->aout_ops;
    AudioTrack *track = (AudioTrack *)out_ops->private_data;

    Mutex::Autolock _l(mLock);

    if (!track) {
        adec_print("No track instance!\n");
        return -1;
    }

    track->stop();

    /* release AudioTrack */
    delete track;
    out_ops->private_data = NULL;

    return 0;
}
static int audio_hardware_ctrl(hw_command_t cmd)
{
    int fd;

    fd = open(AUDIO_CTRL_DEVICE, O_RDONLY);
    if (fd < 0) {
        adec_print("Open Device %s Failed!", AUDIO_CTRL_DEVICE);
        return -1;
    }

    switch (cmd) {
    case HW_CHANNELS_SWAP:
        ioctl(fd, AMAUDIO_IOC_SET_CHANNEL_SWAP, 0);
        break;

    case HW_LEFT_CHANNEL_MONO:
        ioctl(fd, AMAUDIO_IOC_SET_LEFT_MONO, 0);
        break;

    case HW_RIGHT_CHANNEL_MONO:
        ioctl(fd, AMAUDIO_IOC_SET_RIGHT_MONO, 0);
        break;

    case HW_STEREO_MODE:
        ioctl(fd, AMAUDIO_IOC_SET_STEREO, 0);
        break;

    default:
        adec_print("Unknow Command %d!", cmd);
        break;

    };

    close(fd);

    return 0;

}
/**
 * \brief init audio dec
 * \param handle pointer to player private data
 * \return 0 on success otherwise -1 if an error occurred
 */
int audio_decode_init(void **handle, arm_audio_info *a_ainfo)
{
    int ret;
    aml_audio_dec_t *audec;

    if (*handle) {
        adec_print("Existing an audio dec instance!Need not to create it !");
        return -1;
    }

    audec = (aml_audio_dec_t *)malloc(sizeof(aml_audio_dec_t));
    if (audec == NULL) {
        adec_print("malloc failed! not enough memory !");
        return -1;
    }
    //set param for arm audio decoder
    memset(audec, 0, sizeof(aml_audio_dec_t));
    audec->channels=a_ainfo->channels;
    audec->samplerate=a_ainfo->sample_rate;
    audec->format=a_ainfo->format;
    audec->adsp_ops.dsp_file_fd=a_ainfo->handle;
    audec->extradata_size=a_ainfo->extradata_size;
	audec->SessionID=a_ainfo->SessionID;
	audec->dspdec_not_supported = a_ainfo->dspdec_not_supported;
    if(a_ainfo->extradata_size>0&&a_ainfo->extradata_size<=AUDIO_EXTRA_DATA_SIZE)
        memcpy((char*)audec->extradata,(char*)a_ainfo->extradata,a_ainfo->extradata_size);
   
//	adec_print("audio_decode_init  pcodec = %d, pcodec->ctxCodec = %d!\n", pcodec, pcodec->ctxCodec);
    ret = audiodec_init(audec);
    if (ret) {
        adec_print("adec init failed!");
        return -1;
    }

    *handle = (void *)audec;

    return 0;
}
Exemple #7
0
/**
 * \brief init feeder
 * \param audec pointer to audec
 * \return 0 on success otherwise -1 if an error occurred
 */
int feeder_init(aml_audio_dec_t *audec)
{
    int ret;
    dsp_operations_t *dsp_ops;

    dsp_ops = &audec->adsp_ops;

    audec->format = get_audio_format();
    if (audec->format == ADEC_AUDIO_FORMAT_UNKNOWN) {
        adec_print("Unknown audio format!");
        return -1;
    }

    ret = audiodsp_init(dsp_ops);
    if (ret) {
        adec_print("audio dsp init failed!");
        return -1;
    }
		
    ret = audiodsp_start(audec);
    if (ret == 0) {
        dsp_ops->dsp_on = 1;
        dsp_ops->dsp_read = audiodsp_stream_read;
        dsp_ops->get_cur_pts = audiodsp_get_pts;
        dsp_ops->get_cur_pcrscr = audiodsp_get_pcrscr;
	      dsp_ops->set_cur_apts    = audiodsp_set_apts;	
    } else {
        audiodsp_release(dsp_ops);
        dsp_ops->dsp_on = 0;
        dsp_ops->dsp_read = NULL;
        dsp_ops->get_cur_pts = NULL;
        dsp_ops->get_cur_pcrscr = NULL;

        /* TODO: amport init */
    }

    return ret;
}
int audio_get_soundtrack(void *handle, int* strack )
{
    int ret =0;
    aml_audio_dec_t *audec = (aml_audio_dec_t *)handle;

    if (!handle) {
        adec_print("audio handle is NULL !\n");
        return -1;
    }

    *strack= audec->soundtrack;

    return ret;    
}
/**
 * \brief output left and right channels
 * \param handle pointer to player private data
 * \return 0 on success otherwise -1 if an error occurred
 */
int audio_channel_stereo(void *handle)
{
    int ret;
    adec_cmd_t *cmd;
    aml_audio_dec_t *audec = (aml_audio_dec_t *)handle;

    if (!handle) {
        adec_print("audio handle is NULL !\n");
        return -1;
    }

    cmd = adec_message_alloc();
    if (cmd) {
	 audec->soundtrack = HW_STEREO_MODE;
        cmd->ctrl_cmd = CMD_STEREO;
        ret = adec_send_message(audec, cmd);
    } else {
        adec_print("message alloc failed, no memory!");
        ret = -1;
    }

    return ret;
}
int pcmenc_init()
{
	buffer_size = 0;
	read_offset = 0;
	map_buf = 0xffffffff;
	dev_fd = -1;
    dev_fd = open(AUDIODSP_PCMENC_DEV_NAME, O_RDONLY);
    if(dev_fd < 0){
        //printf("can not open %s\n", AUDIODSP_PCMENC_DEV_NAME);
        adec_print("can not open %s\n", AUDIODSP_PCMENC_DEV_NAME);
        return -1;
    }
    ioctl(dev_fd, AUDIODSP_PCMENC_GET_RING_BUF_SIZE, &buffer_size); 
/* mapping the kernel buffer to user space to acess */    
    map_buf= mmap(0,buffer_size, PROT_READ , MAP_PRIVATE, dev_fd, 0);
    if((unsigned)map_buf == -1){
    	//printf("pcmenc:mmap failed,err id %d \n",errno);
    	adec_print("pcmenc:mmap failed,err id %d \n",errno);
    	close(dev_fd);
    	return -1;
    }
	return 0;	
}
Exemple #11
0
/**
 * \brief init audiodsp
 * \param dsp_ops pointer to dsp operation struct
 * \return 0 on success otherwise -1 if an error occurred
 */
int audiodsp_init(dsp_operations_t *dsp_ops)
{
    int i;
    int fd = -1;
    int num;
    int ret;
    firmware_s_t *f;

    num = ARRAY_SIZE(firmware_list);

    if (dsp_ops->dsp_file_fd < 0) {
        fd = open(DSP_DEV_NOD, O_RDONLY, 0644);
    }

    if (fd < 0) {
        adec_print("unable to open audio dsp  %s,err: %s", DSP_DEV_NOD, strerror(errno));
        return -1;
    }
    ioctl(fd, AUDIODSP_UNREGISTER_ALLFIRMWARE, 0);
    for (i = 0; i < num; i++) {
        f = &firmware_list[i];
        ret = register_firmware(fd, f->fmt, f->name);
        if (ret != 0) {
            adec_print("register firmware error=%d,fmt:%d,name:%s\n", ret, f->fmt, f->name);
        }
    }
    if(i>0)
		ret=0;//ignore the some fmt register error,for compatible some old kernel.can't support muti filename,
    if (ret != 0) {
        close(fd);

    }

    dsp_ops->dsp_file_fd = fd;

    return ret;
}
int audiodsp_format_update(aml_audio_dec_t *audec)
{
    int m_fmt;
    int ret = -1;
    unsigned long val;
    dsp_operations_t *dsp_ops = &audec->adsp_ops;
	
    if (dsp_ops->dsp_file_fd < 0 || get_audio_decoder()!=AUDIO_ARC_DECODER) {
        return ret;
    }
	
	ret=0;
	if(1/*audiodsp_get_format_changed_flag()*/)
	{
         ioctl(dsp_ops->dsp_file_fd, AUDIODSP_GET_CHANNELS_NUM, &val);
         if (val != (unsigned long) - 1) {
		    if( audec->channels != val){
			   //adec_print("dsp_format_update: pre_channels=%d  cur_channels=%d\n", audec->channels,val);
               audec->channels = val;
		       ret=1;
		    }
         }

         ioctl(dsp_ops->dsp_file_fd, AUDIODSP_GET_SAMPLERATE, &val);
         if (val != (unsigned long) - 1) {
		     if(audec->samplerate != val){
			    //adec_print("dsp_format_update: pre_samplerate=%d  cur_samplerate=%d\n", audec->samplerate,val);
                audec->samplerate = val;
		        ret=2;
		     }
         }
         #if 1
         ioctl(dsp_ops->dsp_file_fd, AUDIODSP_GET_BITS_PER_SAMPLE, &val);
         if (val != (unsigned long) - 1) {
		     if(audec->data_width != val){
		        //adec_print("dsp_format_update: pre_data_width=%d  cur_data_width=%d\n", audec->data_width,val);
                audec->data_width = val;
		        ret=3;
		     }
         }
		 #endif
		//audiodsp_set_format_changed_flag(0);
	}
	if(ret>0){
	    audec->format_changed_flag=ret;
	    adec_print("dsp_format_update: audec->format_changed_flag = %d \n", audec->format_changed_flag); 
	}
    return ret;
}
/**
 * \brief check audiodec ready or not
 * \param handle pointer to player private data
 * \return 1 = audiodec is ready, 0 = audiodec not ready
 */
int audio_dec_ready(void *handle)
{
    aml_audio_dec_t *audec = (aml_audio_dec_t *)handle;

    if (!handle) {
        adec_print("audio handle is NULL !\n");
        return -1;
    }

    if (audec->state > INITTED) {
        return 1;
    } else {
        return 0;
    }
}
/**
 * \brief set audio volume
 * \param handle pointer to player private data
 * \param vol volume value
 * \return 0 on success otherwise -1 if an error occurred
 */
int audio_decode_get_volume(void *handle, float *vol)
{
    int ret = 0;
    adec_cmd_t *cmd;
    aml_audio_dec_t *audec = (aml_audio_dec_t *)handle;

    if (!handle) {
        adec_print("audio handle is NULL !\n");
        return -1;
    }

    *vol = audec->volume;

    return ret;
}
/**
 * \brief mute audio output
 * \param handle pointer to player private data
 * \param en 1 = mute output, 0 = unmute output
 * \return 0 on success otherwise -1 if an error occurred
 */
int audio_decode_set_mute(void *handle, int en)
{
    int ret;
    adec_cmd_t *cmd;
    aml_audio_dec_t *audec = (aml_audio_dec_t *)handle;

    if (!handle) {
        adec_print("audio handle is NULL !\n");
        return -1;
    }

    cmd = adec_message_alloc();
    if (cmd) {
        cmd->ctrl_cmd = CMD_MUTE;
        cmd->value.en = en;
        cmd->has_arg = 1;
        ret = adec_send_message(audec, cmd);
    } else {
        adec_print("message alloc failed, no memory!");
        ret = -1;
    }

    return ret;
}
Exemple #16
0
static int get_hdmi_switch_state()
{
	int state = 0;
    int fd = -1;
    char  bcmd[16] = {0};
    fd = open(HDMI_SWITCH_STATE_PATH, O_RDONLY);
    if (fd >= 0) {
        read(fd, bcmd, sizeof(bcmd));
        state = strtol(bcmd, NULL, 10);
        close(fd);
    }else {
        adec_print("unable to open file %s,err: %s", HDMI_SWITCH_STATE_PATH, strerror(errno));
    }
	return state;
}
void adec_reset_track(aml_audio_dec_t *audec)
{
	if(audec->format_changed_flag){
		adec_print("reset audio_track: samplerate=%d channels=%d\n", audec->samplerate,audec->channels);
        audio_out_operations_t *out_ops = &audec->aout_ops;
		out_ops->mute(audec, 1);
		out_ops->pause(audec);
        out_ops->stop(audec);
		//audec->SessionID +=1;
        out_ops->init(audec);
		if(audec->state == ACTIVE)
        	out_ops->start(audec);
	    audec->format_changed_flag=0;
	}
}
int dtsenc_init()
{
    return 0;
    int ret;
    memset(&dtsenc_info,0,sizeof(dtsenc_info_t));
    dtsenc_info.dts_flag = get_dts_format();
    if(!dtsenc_info.dts_flag)
        return -1;
    dtsenc_info.raw_mode=get_dts_mode();
    //dtsenc_info.raw_mode=1;//default open
    if(!dtsenc_info.raw_mode)
        return -1;
    if(!get_cpu_type()) //if cpu !=m6 ,skip
        return -1;
    
   //adec_print("====dts_flag:%d raw_mode:%d \n",dtsenc_info.dts_flag,dtsenc_info.raw_mode);
    
    ret=dts_transenc_init();
    if(ret!=1)
    {
        adec_print("====dts_trancenc init failed \n");
        return -1;
    }
    dtsenc_info.state=INITTED;

   pthread_t    tid;
       ret = pthread_create(&tid, NULL, (void *)dts_enc_loop, NULL);
        if (ret != 0) {
           dtsenc_release();
           return -1;
       }
	pthread_setname_np(tid,"AmadecDtsEncLP");	
       dtsenc_info.thread_pid = tid;
    adec_print("====dts_enc init success \n");
    return 0;
}
Exemple #19
0
/**
 * \brief release feeder
 * \param audec pointer to audec
 * \return 0 on success otherwise -1 if an error occurred
 */
int feeder_release(aml_audio_dec_t *audec)
{
    int ret;
    dsp_operations_t *dsp_ops;

    dsp_ops = &audec->adsp_ops;

    ret = audiodsp_stop(dsp_ops);
    if (ret) {
        adec_print("audiodsp stop failed!");
        return -1;
    }

    ret = audiodsp_release(dsp_ops);
    if (ret) {
        adec_print("audiodsp release failed!");
        return -1;
    }

    dsp_ops->dsp_on = 0;
    dsp_ops->dsp_read = NULL;

    return ret;
}
static void *dts_enc_loop()
{
    return 0;
    int ret;
    while(1)
    {
        switch(dtsenc_info.state)
        {
            case INITTED:
               usleep(10000);
               continue;
            case ACTIVE:
                break;
            case PAUSED:
				iec958buf_fill_zero();
                usleep(100000);
                continue;
            case STOPPED:
                goto quit_loop;
            default:
                goto err;
          }
          //shaoshuai --non_block
          ret=dts_transenc_process_frame();
          //usleep(100000);
          //adec_print("====dts_enc thread is running \n");
    }
 quit_loop:
    adec_print("====dts_enc thread exit success \n");
    pthread_exit(NULL);
    return 0;
 err:
 adec_print("====dts_enc thread exit success err\n");
    pthread_exit(NULL);
    return -1;
}
Exemple #21
0
/**
 * \brief pause output
 * \param audec pointer to audec
 * \return 0 on success otherwise negative error code
 */
int alsa_pause_raw(struct aml_audio_dec* audec)
{

    int res = 0;
    alsa_param_t *alsa_params;

    if(audec->aout_ops.private_data_raw) {
        alsa_params = (alsa_param_t *)audec->aout_ops.private_data_raw;
    } else {
        adec_print("OUT SETTING::PCM\n");
        return -1;
    }
    if(1 == alsa_params->pause_flag) {
        adec_print("[%s::%d]--[already in pause(%d) status]\n",__FUNCTION__, __LINE__,alsa_params->pause_flag);
        return 0;
    }

    alsa_params->pause_flag = 1;
    while ((res = snd_pcm_pause(alsa_params->handle, 1)) == -EAGAIN) {
        sleep(1);
    }

    return res;
}
Exemple #22
0
int alsa_get_aml_card()
{
    int card = -1, err = 0;
    int fd = -1;
    unsigned fileSize = 512;
    char *read_buf = NULL, *pd = NULL;
    static const char *const SOUND_CARDS_PATH = "/proc/asound/cards";
    fd = open(SOUND_CARDS_PATH, O_RDONLY);
    if (fd < 0) {
        adec_print("ERROR: failed to open config file %s error: %d\n", SOUND_CARDS_PATH, errno);
        close(fd);
        return -1;
    }

    read_buf = (char *)malloc(fileSize);
    if (!read_buf) {
        adec_print("Failed to malloc read_buf");
        close(fd);
        return -1;
    }
    memset(read_buf, 0x0, fileSize);
    err = read(fd, read_buf, fileSize);
    if (fd < 0) {
        adec_print("ERROR: failed to read config file %s error: %d\n", SOUND_CARDS_PATH, errno);
        free(read_buf);
        close(fd);
        return -1;
    }
    pd = strstr(read_buf, "AML");
    card = *(pd - 3) - '0';

OUT:
    free(read_buf);
    close(fd);
    return card;
}
static int audiodsp_set_pcm_resample_enable(unsigned long enable)
{
    int utils_fd, ret;

    utils_fd = open("/dev/amaudio_utils", O_RDWR);
    if (utils_fd >= 0) {
        ret = ioctl(utils_fd, AMAUDIO_IOC_SET_RESAMPLE_ENA, enable);
        if (ret < 0) {
            adec_print("AMAUDIO_IOC_SET_RESAMPLE_ENA failed\n");
            close(utils_fd);
            return -1;
        }
        close(utils_fd);
        return 0;
    }
    return -1;
}
/**
 * \brief output right channel
 * \param handle pointer to player private data
 * \return 0 on success otherwise -1 if an error occurred
 */
int audio_channel_right_mono(void *handle)
{
    int ret;
    adec_cmd_t *cmd;
    aml_audio_dec_t *audec = (aml_audio_dec_t *)handle;

    cmd = adec_message_alloc();
    if (cmd) {
        cmd->ctrl_cmd = CMD_RIGHT_MONO;
        ret = adec_send_message(audec, cmd);
    } else {
        adec_print("message alloc failed, no memory!");
        ret = -1;
    }

    return ret;
}
/**
 * \brief pause audio dec
 * \param handle pointer to player private data
 * \return 0 on success otherwise -1 if an error occurred
 */
int audio_decode_pause(void *handle)
{
    int ret;
    adec_cmd_t *cmd;
    aml_audio_dec_t *audec = (aml_audio_dec_t *)handle;

    cmd = adec_message_alloc();
    if (cmd) {
        cmd->ctrl_cmd = CMD_PAUSE;
        ret = adec_send_message(audec, cmd);
    } else {
        adec_print("message alloc failed, no memory!");
        ret = -1;
    }

    return ret;
}
/**
 * \brief get audio dsp decoded frame number
 * \param handle pointer to player private data
 * \return n = audiodec frame number, -1 = error
 */
int audio_get_decoded_nb_frames(void *handle)
{
    aml_audio_dec_t *audec = (aml_audio_dec_t *)handle;

    if (!handle) {
        adec_print("audio handle is NULL !\n");
        return -1;
    }

    audec->decoded_nb_frames = audiodsp_get_decoded_nb_frames(&audec->adsp_ops);
    //adec_print("audio_get_decoded_nb_frames:  %d!", audec->decoded_nb_frames);
    if (audec->decoded_nb_frames >= 0) {
        return audec->decoded_nb_frames;
    } else {
        return -2;
    }
}
/**
 * \brief pause pts manager
 * \return 0 on success otherwise -1
 */
int adec_pts_pause(void)
{
    int fd;
    char buf[32];

    fd = open(TSYNC_EVENT, O_WRONLY);
    if (fd < 0) {
        adec_print("unable to open file %s,err: %s", TSYNC_EVENT, strerror(errno));
        return -1;
    }

    sprintf(buf, "AUDIO_PAUSE");
    write(fd, buf, strlen(buf));
    close(fd);

    return 0;
}
int audio_set_av_delay(void *handle, int delay)
{
    aml_audio_dec_t *audec = (aml_audio_dec_t *)handle;
    if (!handle) {
        adec_print("audio handle is NULL !\n");
        return -1;
    }

    if (delay > 500)
        delay = 500;
    else if (delay < -500)
        delay = -500;

    audec->audio_delay = delay;

    return 0;
}
int dtsenc_stop()
{
    return 0;
    if(dtsenc_info.state<INITTED)
           return -1;
    dtsenc_info.state=STOPPED;
    //jone the thread
    if(dtsenc_info.thread_pid<=0)
        return -1;
    int ret = pthread_join(dtsenc_info.thread_pid, NULL);
    dtsenc_info.thread_pid=0;
    if(dtsenc_info.state!=STOPPED)
            return -1;
    dts_transenc_deinit();
    adec_print("====dts_enc stop ok\n");
    return 0;
}
/**
 * \brief swap audio left and right channels
 * \param handle pointer to player private data
 * \return 0 on success otherwise -1 if an error occurred
 */
int audio_channels_swap(void *handle)
{
    int ret;
    adec_cmd_t *cmd;
    aml_audio_dec_t *audec = (aml_audio_dec_t *)handle;

    cmd = adec_message_alloc();
    if (cmd) {
        cmd->ctrl_cmd = CMD_CHANL_SWAP;
        ret = adec_send_message(audec, cmd);
    } else {
        adec_print("message alloc failed, no memory!");
        ret = -1;
    }

    return ret;
}