コード例 #1
0
static float _get_system_prop(SysPropType type){
    float value = 0.0;
    float ret = -1;    
    switch(type){
        case PROP_DEBUG_LEVEL:
            ret = am_getconfig_float("libplayer.hls.debug",&value);
            if(ret<0){
                ret = 0;
                value = 0;
            }            
            break;
        case PROP_CMF_SUPPORT:
            ret = am_getconfig_bool("libplayer.hls.cmf");
            if(ret<0){
                value = -1;
            }else{
                value= ret;
            }
            break;
        default:
            RLOG("Never see this line,type:%d\n",type);
            break;
    }
    if(ret < 0 || value <0){
        ret = -1;
    }else{
        ret = value;
    }

    return ret;
    
}
コード例 #2
0
ファイル: aml_resample.c プロジェクト: Owersun/c2_aml_libs
void af_resample_set_SampsNumRatio(af_resampe_ctl_t *paf_resampe_ctl)
{  
    int resample_type=af_get_resample_type();
	int default_DELTA_NUMSAMPS=RESAMPLE_DELTA_NUMSAMPS;
	if (am_getconfig_bool("media.libplayer.wfd"))
	{
       default_DELTA_NUMSAMPS=2;
	}
	audiodsp_set_pcm_resample_delta(default_DELTA_NUMSAMPS);
	paf_resampe_ctl->LastResamType=resample_type;
	adec_print("ReSample Coef Init: type/%d DELTA_NUMSAMPS/%d ",resample_type,default_DELTA_NUMSAMPS);
    //memset(paf_resampe_ctl,0,sizeof(af_resampe_ctl_t));
    if(resample_type==RESAMPLE_TYPE_NONE){
         paf_resampe_ctl->SampNumIn=DEFALT_NUMSAMPS_PERCH;
         paf_resampe_ctl->SampNumOut=DEFALT_NUMSAMPS_PERCH;
    }
    else if(resample_type==RESAMPLE_TYPE_DOWN)
    {
         paf_resampe_ctl->SampNumIn=DEFALT_NUMSAMPS_PERCH + default_DELTA_NUMSAMPS;
         paf_resampe_ctl->SampNumOut=DEFALT_NUMSAMPS_PERCH ;
    }
    else if(resample_type==RESAMPLE_TYPE_UP)
    {
         paf_resampe_ctl->SampNumIn=DEFALT_NUMSAMPS_PERCH - default_DELTA_NUMSAMPS;
         paf_resampe_ctl->SampNumOut=DEFALT_NUMSAMPS_PERCH;
    }
    af_resample_linear_coef_get(paf_resampe_ctl);
    paf_resampe_ctl->ResevedSampsValid=0;
    paf_resampe_ctl->OutSampReserveLen=0;
    paf_resampe_ctl->InitFlag=1;

}
コード例 #3
0
/*=======================================================================================*/
int url_is_file_list(ByteIOContext *s, const char *filename)
{
    int ret;
    list_demux_t *demux;
    ByteIOContext *lio = s;
    int64_t    *oldpos = 0;
    if (am_getconfig_bool("media.amplayer.usedm3udemux")) {
        return 0;    /*if used m3u demux,always failed;*/
    }
    if (!lio) {
        ret = url_fopen(&lio, filename, AVIO_FLAG_READ | URL_MINI_BUFFER|URL_NO_LP_BUFFER);
        if (ret != 0) {
            return AVERROR(EIO);
        }
    } else {
        oldpos = url_ftell(lio);
    }
    demux = probe_demux(lio, filename);
    if (lio != s) {
        url_fclose(lio);
    } else {
        url_fseek(lio, oldpos, SEEK_SET);
    }
    return demux != NULL ? 100 : 0;
}
コード例 #4
0
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 (am_getconfig_bool("media.libplayer.wfd")) {
	    ret = ioctl(dsp_ops->dsp_file_fd, AUDIODSP_GET_PCM_LEVEL, &val);
            if (ret == 0) {
                //adec_print("pcm level == 0x%x\n", val);
                if ((val < 0x1000) && (1==audiodsp_get_pcm_resample_enable())) {
                //    adec_print("disable pcm down resample");
                //    audiodsp_set_pcm_resample_enable(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;
}
コード例 #5
0
ファイル: udp.c プロジェクト: Aldwych/buildroot-linux
static int udp_set_url(struct sockaddr_storage *addr,
                       const char *hostname, int port)
{
    struct addrinfo *res0;
    int addr_len;
    int family = AF_UNSPEC;
    if(am_getconfig_bool("media.libplayer.ipv4only"))	
		family = AF_INET;
    res0 = udp_resolve_host(hostname, port, SOCK_DGRAM, family, 0);
    if (res0 == 0) return AVERROR(EIO);
    memcpy(addr, res0->ai_addr, res0->ai_addrlen);
    addr_len = res0->ai_addrlen;
    freeaddrinfo(res0);

    return addr_len;
}
コード例 #6
0
ファイル: adec-internal-mgt.c プロジェクト: vitmod/libp
int audiodec_init(aml_audio_dec_t *audec)
{
    int ret = 0;
    pthread_t    tid;
    char value[PROPERTY_VALUE_MAX]={0};
    unsigned wfd = 0;	
    adec_print("audiodec_init!");
    adec_message_pool_init(audec);
    get_output_func(audec);
    int nCodecType=audec->format;
    set_audio_decoder(audec);
    audec->format_changed_flag=0;
    audec->audio_decoder_enabled  = -1;//default set a invalid value
    audec->mix_lr_channel_enable  = -1;
    audec->VersionNum=-1;
    if(am_getconfig_bool("media.libplayer.wfd"))  {
  	wfd = 1;
   }		
    if (get_audio_decoder() == AUDIO_ARC_DECODER) {
    		audec->adsp_ops.dsp_file_fd = -1;
		ret = amthreadpool_pthread_create(&tid, NULL, (void *)adec_message_loop, (void *)audec);
		pthread_setname_np(tid,"AmadecMsgloop");
    }
    else if(wfd && (nCodecType == ACODEC_FMT_AAC ||nCodecType ==  ACODEC_FMT_WIFIDISPLAY)){
		adec_print("using wfd audio decoder \n");
		ret = amthreadpool_pthread_create(&tid, NULL, (void *)adec_wfddec_msg_loop, (void *)audec);
		audec->audio_decoder_enabled = 0x1;
		pthread_setname_np(tid,"AmadecWFDMsgloop");
    }
    else 
    {
		int codec_type=get_audio_decoder();
		RegisterDecode(audec,codec_type);
		ret = amthreadpool_pthread_create(&tid, NULL, (void *)adec_armdec_loop, (void *)audec);
		pthread_mutex_init(&audec->thread_mgt.pthread_mutex, NULL);
		pthread_cond_init(&audec->thread_mgt.pthread_cond, NULL);
		audec->thread_mgt.pthread_id = tid;
		pthread_setname_np(tid,"AmadecArmdecLP");
    }
    if (ret != 0) {
        adec_print("Create adec main thread failed!\n");
        return ret;
    }
    adec_print("Create adec main thread success! tid = %d\n", tid);
    audec->thread_pid = tid;
    return ret;
}
コード例 #7
0
ファイル: udp.c プロジェクト: Aldwych/buildroot-linux
static int udp_socket_create(UDPContext *s,
                             struct sockaddr_storage *addr, int *addr_len)
{
    int udp_fd = -1;
    struct addrinfo *res0 = NULL, *res = NULL;
    int family = AF_UNSPEC;
    if(am_getconfig_bool("media.libplayer.ipv4only"))	
		family = AF_INET;
    if (((struct sockaddr *) &s->dest_addr)->sa_family)
        family = ((struct sockaddr *) &s->dest_addr)->sa_family;
    res0 = udp_resolve_host(0, s->local_port, SOCK_DGRAM, family, AI_PASSIVE);
    if (res0 == 0)
        goto fail;
    for (res = res0; res; res=res->ai_next) {
        udp_fd = socket(res->ai_family, SOCK_DGRAM, 0);
        if (udp_fd > 0) break;
        av_log(NULL, AV_LOG_ERROR, "socket: %s\n", strerror(errno));
    }

    if (udp_fd < 0)
        goto fail;

    memcpy(addr, res->ai_addr, res->ai_addrlen);
    *addr_len = res->ai_addrlen;

    freeaddrinfo(res0);

    return udp_fd;

 fail:
    if (udp_fd >= 0)
        closesocket(udp_fd);
    if(res0)
        freeaddrinfo(res0);
    return -1;
}
コード例 #8
0
ファイル: audiodsp-ctl.c プロジェクト: vitmod/libp
int audiodsp_start(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) {
        return -1;
    }

    if (am_getconfig_bool("media.libplayer.wfd")) {
        ioctl(dsp_ops->dsp_file_fd, AUDIODSP_SET_PCM_BUF_SIZE, 8*1024);
    } else {
        ioctl(dsp_ops->dsp_file_fd, AUDIODSP_SET_PCM_BUF_SIZE, 32*1024);
    }
    
    m_fmt = switch_audiodsp(audec->format);
    adec_print("[%s:%d]  audio_fmt=%d\n", __FUNCTION__, __LINE__, m_fmt);

    if (find_firmware_by_fmt(m_fmt) == NULL) {
        return -2;
    }

    ioctl(dsp_ops->dsp_file_fd, AUDIODSP_SET_FMT, m_fmt);

    ret = ioctl(dsp_ops->dsp_file_fd, AUDIODSP_START, 0);
    if (ret != 0) {
        return -3;
    }

    if(audec->need_stop){ //in case  stop command comes now  
        ioctl(dsp_ops->dsp_file_fd, AUDIODSP_STOP, 0);
        return -5;
    }

    ret = ioctl(dsp_ops->dsp_file_fd, AUDIODSP_DECODE_START, 0);
    err_count = 0;
    if(ret==0){
        do{
            ret = ioctl(dsp_ops->dsp_file_fd, AUDIODSP_WAIT_FORMAT, 0);
	    if(ret!=0 && !audec->need_stop){
                err_count++;			
                amthreadpool_thread_usleep(1000*20);
                if (err_count > PARSER_WAIT_MAX){ 
	             ioctl(dsp_ops->dsp_file_fd, AUDIODSP_STOP, 0);//audiodsp_start failed,should stop audiodsp 								
	             adec_print("[%s:%d] audio dsp not ready for decode PCM in 2s\n", __FUNCTION__, __LINE__);
                    return -4;	
                    }				
	    }
        }while(!audec->need_stop && (ret!=0));
    }

    if (ret != 0) {
	 ioctl(dsp_ops->dsp_file_fd, AUDIODSP_STOP, 0);//audiodsp_start failed,should stop audiodsp 					
        return -4;
    }

    ioctl(dsp_ops->dsp_file_fd, AUDIODSP_GET_CHANNELS_NUM, &val);
    if (val != (unsigned long) - 1) {
        audec->channels = val;
    }

    ioctl(dsp_ops->dsp_file_fd, AUDIODSP_GET_SAMPLERATE, &val);
    if (val != (unsigned long) - 1) {
        audec->samplerate = val;
    }

    ioctl(dsp_ops->dsp_file_fd, AUDIODSP_GET_BITS_PER_SAMPLE, &val);
    if (val != (unsigned long) - 1) {
        audec->data_width = val;
    }
    adec_print("channels == %d, samplerate == %d\n", audec->channels, audec->samplerate);
    return ret;
}
コード例 #9
0
ファイル: player_ts.c プロジェクト: anonbeat/libamplayer-m3
static int stream_ts_init(play_para_t *p_para)
{
    v_stream_info_t *vinfo = &p_para->vstream_info;
    a_stream_info_t *ainfo = &p_para->astream_info;
    s_stream_info_t *sinfo = &p_para->sstream_info;
    AVCodecContext  *pCodecCtx;
    codec_para_t *codec ;
    int ret = CODEC_ERROR_NONE;

    codec = codec_alloc();
    if (!codec) {
        return PLAYER_EMPTY_P;
    }
    MEMSET(codec, 0, sizeof(codec_para_t));

    codec->noblock = !!p_para->buffering_enable;
    if (vinfo->has_video) {
        codec->has_video = 1;
        codec->video_type = vinfo->video_format;
        codec->video_pid = vinfo->video_pid;
        if ((codec->video_type == VFORMAT_H264) || (codec->video_type == VFORMAT_H264MVC)) {
            codec->am_sysinfo.format = vinfo->video_codec_type;
            codec->am_sysinfo.width = vinfo->video_width;
            codec->am_sysinfo.height = vinfo->video_height;
            codec->am_sysinfo.rate = vinfo->video_rate;
            if (p_para->pFormatCtx->pb && p_para->pFormatCtx->pb->is_slowmedia) {
                /* ts slow media, use idr framerate */
                log_print("[%s:%d]Slow media detected for ts\n", __FUNCTION__, __LINE__);
                codec->am_sysinfo.param = USE_IDR_FRAMERATE;
            }
        } else if (codec->video_type == VFORMAT_VC1 || codec->video_type == VFORMAT_AVS) {
            codec->am_sysinfo.format = vinfo->video_codec_type;
            codec->am_sysinfo.width = vinfo->video_width;
            codec->am_sysinfo.height = vinfo->video_height;
            codec->am_sysinfo.rate = vinfo->video_rate;
        }
    }
    if (ainfo->has_audio) {
        codec->has_audio = 1;
        codec->audio_type = ainfo->audio_format;
        codec->audio_pid = ainfo->audio_pid;
        codec->audio_channels = ainfo->audio_channel;
        codec->audio_samplerate = ainfo->audio_samplerate;
		codec->switch_audio_flag = 0;
        pCodecCtx = p_para->pFormatCtx->streams[p_para->astream_info.audio_index]->codec;
        /*if ((codec->audio_type == AFORMAT_ADPCM) || (codec->audio_type == AFORMAT_WMA)
            || (codec->audio_type == AFORMAT_WMAPRO) || (codec->audio_type == AFORMAT_PCM_S16BE)
            || (codec->audio_type == AFORMAT_PCM_S16LE) || (codec->audio_type == AFORMAT_PCM_U8)
            || (codec->audio_type == AFORMAT_PCM_BLURAY)||(codec->audio_type == AFORMAT_AMR)) {*/
        if (IS_AUIDO_NEED_EXT_INFO(codec->audio_type)) {
            codec->audio_info.bitrate = pCodecCtx->sample_fmt;
            codec->audio_info.sample_rate = pCodecCtx->sample_rate;
            codec->audio_info.channels = pCodecCtx->channels;
            codec->audio_info.codec_id = pCodecCtx->codec_id;
            codec->audio_info.block_align = pCodecCtx->block_align;
            codec->audio_info.extradata_size = pCodecCtx->extradata_size;
            if (codec->audio_info.extradata_size > 0) {
                if (codec->audio_info.extradata_size >  AUDIO_EXTRA_DATA_SIZE) {
                    log_print("[%s:%d],extra data size exceed max  extra data buffer,cut it to max buffer size ", __FUNCTION__, __LINE__);
                    codec->audio_info.extradata_size =  AUDIO_EXTRA_DATA_SIZE;
                }
                memcpy((char*)codec->audio_info.extradata, pCodecCtx->extradata, codec->audio_info.extradata_size);
            }
            codec->audio_info.valid = 1;

        }
		if(IS_AUDIO_NOT_SUPPORTED_BY_AUDIODSP(codec->audio_type,pCodecCtx)){
				codec->dspdec_not_supported = 1;
				log_print("main profile aac not supported by dsp decoder,so set dspdec_not_supported flag\n");
		}	
        codec->avsync_threshold = p_para->start_param->avsync_threshold;
        log_print("[%s:%d]audio bitrate=%d sample_rate=%d channels=%d codec_id=%x block_align=%d,extra size\n",
                  __FUNCTION__, __LINE__, codec->audio_info.bitrate, codec->audio_info.sample_rate, codec->audio_info.channels,
                  codec->audio_info.codec_id, codec->audio_info.block_align, codec->audio_info.extradata_size);
    }
    if (sinfo->has_sub) {
        codec->has_sub = 1;
        codec->sub_pid = sinfo->sub_pid;
        codec->sub_type = sinfo->sub_type;
    }

    codec->stream_type = stream_type_convert(p_para->stream_type, codec->has_video, codec->has_audio);
    codec->packet_size = p_para->pFormatCtx->orig_packet_size;
    ret = codec_init(codec);
    if (ret != CODEC_ERROR_NONE) {
        if (ret != CODEC_OPEN_HANDLE_FAILED) {
            codec_close(codec);
        }
        goto error1;
    }
    
    if(am_getconfig_bool("media.libplayer.wfd")) {
        ret = codec_init_audio_utils(codec);
        if (ret != CODEC_ERROR_NONE) {
            codec_close(codec);
            goto error1;
        }
    }    

    p_para->codec = codec;
    return PLAYER_SUCCESS;
error1:
    log_print("[ts]codec_init failed!\n");
    codec_free(codec);
    return DECODER_INIT_FAILED;
}
コード例 #10
0
/* return non zero if error */
static int tcp_open(URLContext *h, const char *uri, int flags)
{
    struct addrinfo hints, *ai, *cur_ai;
    int port, fd = -1;
    TCPContext *s = NULL;
    int listen_socket = 0;
    const char *p;
    char buf[256];
    int ret;
    socklen_t optlen;
    int timeout = 500, listen_timeout = -1;
    char hostname[1024],proto[1024],path[1024];
    char portstr[10];

    av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname),
        &port, path, sizeof(path), uri);
    if (strcmp(proto, "tcp"))
        return AVERROR(EINVAL);
    if (port <= 0 || port >= 65536) {
        av_log(h, AV_LOG_ERROR, "Port missing in uri\n");
        return AVERROR(EINVAL);
    }
    p = strchr(uri, '?');
    if (p) {
        if (av_find_info_tag(buf, sizeof(buf), "listen", p))
            listen_socket = 1;
        if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) {
            timeout = strtol(buf, NULL, 10);
        }
        if (av_find_info_tag(buf, sizeof(buf), "listen_timeout", p)) {
            listen_timeout = strtol(buf, NULL, 10);

        }
    }
    memset(&hints, 0, sizeof(hints));
    if(am_getconfig_bool("media.libplayer.ipv4only"))	
    		hints.ai_family = AF_INET;
    else
		hints.ai_family = AF_UNSPEC;	
    hints.ai_socktype = SOCK_STREAM;
    snprintf(portstr, sizeof(portstr), "%d", port);
	av_log(h, AV_LOG_INFO,"tcp will get address from dns!\n");	
    if (listen_socket)
        hints.ai_flags |= AI_PASSIVE;
    if (!hostname[0])
        ret = getaddrinfo(NULL, portstr, &hints, &ai);
    else
    ret = getaddrinfo(hostname, portstr, &hints, &ai);
    if (ret) {
        av_log(h, AV_LOG_ERROR,
               "Failed to resolve hostname %s: %s\n",
               hostname, gai_strerror(ret));
        return AVERROR(EIO);
    }
    av_log(h, AV_LOG_INFO,"resolved %s's  ipaddress \n",hostname);
    cur_ai = ai;

 restart:
    ret = AVERROR(EIO);
    fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol);
    if (fd < 0)
        goto fail;

    if (listen_socket) {
        int fd1;
        int reuse = 1;
        struct pollfd lp = { fd, POLLIN, 0 };
        setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
        ret = bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
        if (ret) {
            ret = ff_neterrno();
            goto fail1;
        }
        ret = listen(fd, 1);
        if (ret) {
            ret = ff_neterrno();
            goto fail1;
        }
        ret = poll(&lp, 1, listen_timeout >= 0 ? listen_timeout : -1);
        if (ret <= 0) {
            ret = AVERROR(ETIMEDOUT);
            goto fail1;
        }
        fd1 = accept(fd, NULL, NULL);
        if (fd1 < 0) {
            ret = ff_neterrno();
            goto fail1;
        }
        closesocket(fd);
        fd = fd1;
        ff_socket_nonblock(fd, 1);
    } else {
 redo:
        ff_socket_nonblock(fd, 1);
        ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
    }

    if (ret < 0) {
        struct pollfd p = {fd, POLLOUT, 0};
        ret = ff_neterrno();
        if (ret == AVERROR(EINTR)) {
            if (url_interrupt_cb()) {
                ret = AVERROR_EXIT;
                goto fail1;
            }
            goto redo;
        }
        if (ret != AVERROR(EINPROGRESS) &&
            ret != AVERROR(EAGAIN))
            goto fail;

        /* wait until we are connected or until abort */
        while(timeout--) {
            if (url_interrupt_cb()) {
                ret = AVERROR_EXIT;
                goto fail1;
            }
            ret = poll(&p, 1, 100);
            if (ret > 0)
                break;
        }
        if (ret <= 0) {
			 av_log(h, AV_LOG_ERROR,
                   "TCP connection to %s:%d timeout failed!\n",
                   hostname, port);
            ret = AVERROR(ETIMEDOUT);
            goto fail;
        }
        /* test error */
        optlen = sizeof(ret);
        if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen))
            ret = AVUNERROR(ff_neterrno());
        if (ret != 0) {
            char errbuf[100];
            ret = AVERROR(ret);
            av_strerror(ret, errbuf, sizeof(errbuf));
            av_log(h, AV_LOG_ERROR,
                   "TCP connection to %s:%d failed: %s\n",
                   hostname, port, errbuf);
            ret = AVERROR(ret);
            goto fail;
        }
    }
    av_log(h, AV_LOG_INFO,"tcp  connect %s ok!\n",hostname);	
    s = av_malloc(sizeof(TCPContext));
    if (!s) {
        freeaddrinfo(ai);
        return AVERROR(ENOMEM);
    }
    h->priv_data = s;
    h->is_streamed = 1;
    s->fd = fd;
    freeaddrinfo(ai);
    return 0;

 fail:
    if (cur_ai->ai_next) {
        /* Retry with the next sockaddr */
        cur_ai = cur_ai->ai_next;
        if (fd >= 0)
            closesocket(fd);
        goto restart;
    }
 fail1:
    if (fd >= 0)
        closesocket(fd);
    freeaddrinfo(ai);
    return ret;
}
コード例 #11
0
ファイル: adec-pts-mgt.c プロジェクト: mdrjr/c2_aml_libs
/**
 * \brief start pts manager
 * \param audec pointer to audec
 * \return 0 on success otherwise -1
 */
int adec_pts_start(aml_audio_dec_t *audec)
{
    unsigned long pts = 0;
    char *file;
    char buf[64];
    dsp_operations_t *dsp_ops;
	char value[PROPERTY_VALUE_MAX]={0};

    adec_print("adec_pts_start");
    dsp_ops = &audec->adsp_ops;
    memset(buf, 0, sizeof(buf));

    if (audec->avsync_threshold <= 0) {
        if (am_getconfig_bool("media.libplayer.wfd")) {
            audec->avsync_threshold = SYSTIME_CORRECTION_THRESHOLD * 2 / 3;
            adec_print("use 2/3 default av sync threshold!\n");
        } else {
            audec->avsync_threshold = SYSTIME_CORRECTION_THRESHOLD;
            adec_print("use default av sync threshold!\n");
        }
    }
    adec_print("av sync threshold is %d , no_first_apts=%d,\n", audec->avsync_threshold, audec->no_first_apts);

    dsp_ops->last_pts_valid = 0;
    if(property_get("sys.amplayer.drop_pcm",value,NULL) > 0)
    	if(!strcmp(value,"1"))
    	     adec_pts_droppcm(audec);
    // before audio start or pts start
    if(amsysfs_set_sysfs_str(TSYNC_EVENT, "AUDIO_PRE_START") == -1)
    {
        return -1;
    }

    usleep(1000);

	if (audec->no_first_apts) {
		if (amsysfs_get_sysfs_str(TSYNC_APTS, buf, sizeof(buf)) == -1) {
			adec_print("unable to open file %s,err: %s", TSYNC_APTS, strerror(errno));
			return -1;
		}

		if (sscanf(buf, "0x%lx", &pts) < 1) {
			adec_print("unable to get vpts from: %s", buf);
			return -1;
		}

	} else {
	    pts = adec_calc_pts(audec);

	    if (pts == -1) {

	        adec_print("pts==-1");

    		if (amsysfs_get_sysfs_str(TSYNC_APTS, buf, sizeof(buf)) == -1) {
    			adec_print("unable to open file %s,err: %s", TSYNC_APTS, strerror(errno));
    			return -1;
    		}

	        if (sscanf(buf, "0x%lx", &pts) < 1) {
	            adec_print("unable to get apts from: %s", buf);
	            return -1;
	        }
	    }
	}

    adec_print("audio pts start from 0x%lx", pts);

    sprintf(buf, "AUDIO_START:0x%lx", pts);

    if(amsysfs_set_sysfs_str(TSYNC_EVENT, buf) == -1)
    {
        return -1;
    }

    return 0;
}
コード例 #12
0
ファイル: adec-pts-mgt.c プロジェクト: mdrjr/c2_aml_libs
int adec_pts_droppcm(aml_audio_dec_t *audec)
{
    unsigned long vpts, apts;
    int drop_size;
    int ret;
    char buf[32];
    char buffer[8*1024];
    char value[PROPERTY_VALUE_MAX]={0};

    if (amsysfs_get_sysfs_str(TSYNC_VPTS, buf, sizeof(buf)) == -1) {
    	adec_print("unable to open file %s,err: %s", TSYNC_APTS, strerror(errno));
    	return -1;
    }
    if (sscanf(buf, "0x%lx", &vpts) < 1) {
        adec_print("unable to get vpts from: %s", buf);
        return -1;
    }

    apts = adec_calc_pts(audec);
    int diff = (apts > vpts)?(apts-vpts):(vpts-apts);
    adec_print("before drop --apts 0x%x,vpts 0x%x,apts %s, diff 0x%x\n",apts,vpts,(apts>vpts)?"big":"small",diff);
    if(apts>=vpts) //no need to drop pcm
        return 0;
    int audio_ahead = 0;
    unsigned pts_ahead_val = SYSTIME_CORRECTION_THRESHOLD;

    if (am_getconfig_bool("media.libplayer.wfd")) {
        pts_ahead_val = pts_ahead_val * 2 / 3;
    }

    if(property_get("media.amplayer.apts",value,NULL) > 0){
    	if(!strcmp(value,"slow")){
    		audio_ahead = -1;
    	}
    	else if(!strcmp(value,"fast")){
    		audio_ahead = 1;
    	}
    }
    memset(value,0,sizeof(value));
    if(property_get("media.amplayer.apts_val",value,NULL) > 0){
    	pts_ahead_val = atoi(value);
    }
    adec_print("audio ahead %d,ahead pts value %d \n",	audio_ahead,pts_ahead_val);

    struct timeval  new_time,old_time;
    long new_time_mseconds;
    long old_time_mseconds;
    //old time
    gettimeofday(&old_time, NULL);
    old_time_mseconds = (old_time.tv_usec / 1000 + old_time.tv_sec * 1000);

#define DROP_PCM_DURATION_THRESHHOLD 4 //unit:s
    drop_size = ((vpts - apts+pts_ahead_val*audio_ahead)/90) * (audec->samplerate/1000) * audec->channels *2;
    int drop_duration=drop_size/audec->channels/2/audec->samplerate;
    int nDropCount=0;
    adec_print("==drop_size=%d, nDropCount:%d -----------------\n",drop_size, nDropCount);
    while(drop_size > 0 && drop_duration <DROP_PCM_DURATION_THRESHHOLD){
    	ret = audec->adsp_ops.dsp_read(&audec->adsp_ops, buffer, MIN(drop_size, 8192));
    	//apts = adec_calc_pts(audec);
    	//adec_print("==drop_size=%d, ret=%d, nDropCount:%d apts=0x%x,-----------------\n",drop_size, ret, nDropCount,apts);
    	if(ret==0)//no data in pcm buf
    	{
    		if(nDropCount>=5)
    			break;
    		else
    			nDropCount++;
    		adec_print("==ret:0 no pcm nDropCount:%d \n",nDropCount);
    	}
    	else
    	{
    		nDropCount=0;
    		drop_size -= ret;
    	}
    }

    //new time
    gettimeofday(&new_time, NULL);
    new_time_mseconds = (new_time.tv_usec / 1000 + new_time.tv_sec * 1000);
    adec_print("==old time  sec :%d usec:%d \n", old_time.tv_sec  ,old_time.tv_usec );
    adec_print("==new time  sec:%d usec:%d \n", new_time.tv_sec  ,new_time.tv_usec  );
    adec_print("==old time ms is :%d  new time ms is:%d   diff:%d  \n",old_time_mseconds ,new_time_mseconds ,new_time_mseconds- old_time_mseconds);

    if (amsysfs_get_sysfs_str(TSYNC_VPTS, buf, sizeof(buf)) == -1) {
    	adec_print("unable to open file %s,err: %s", TSYNC_APTS, strerror(errno));
    	return -1;
    }
    if (sscanf(buf, "0x%lx", &vpts) < 1) {
        adec_print("unable to get vpts from: %s", buf);
        return -1;
    }

    apts = adec_calc_pts(audec);
    diff = (apts > vpts)?(apts-vpts):(vpts-apts);
    adec_print("after drop pcm:--apts 0x%x,vpts 0x%x,apts %s, diff 0x%x\n",apts,vpts,(apts>vpts)?"big":"small",diff);
    return 0;
}
コード例 #13
0
ファイル: adec-internal-mgt.c プロジェクト: vitmod/libp
static int set_audio_decoder(aml_audio_dec_t *audec)
{
	int audio_id;
	int i;	
    int num;
	int ret;
    audio_type_t *t;
	char value[PROPERTY_VALUE_MAX];
	

	audio_id = audec->format;

    num = ARRAY_SIZE(audio_type);
    for (i = 0; i < num; i++) {
        t = &audio_type[i];
        if (t->audio_id == audio_id) {
            break;
        }
    }

    if(match_types(t->type, "thd")||match_types(t->type, "wmavoi")){
        adec_print("audio format is %s, so chose AUDIO_ARM_DECODER",t->type);
        audio_decoder = AUDIO_ARM_DECODER;
        goto exit;
    }


	ret = property_get("media.arm.audio.decoder",value,NULL);
	adec_print("media.amplayer.audiocodec = %s, t->type = %s\n", value, t->type);
	if (ret>0 && match_types(t->type,value))
	{	
		char type_value[] = "ac3,eac3";
		set_multichs_prop();
		if(match_types(t->type,type_value))
		{   
            #ifdef DOLBY_USE_ARMDEC
            adec_print("DOLBY_USE_ARMDEC=%d",DOLBY_USE_ARMDEC);
            audio_decoder = AUDIO_ARM_DECODER;
            #else
            audio_decoder = AUDIO_ARC_DECODER;
            adec_print("<DOLBY_USE_ARMDEC> is not DEFINED,use ARC_Decoder\n!");
            #endif
        }
        #ifndef USE_ARM_AUDIO_DEC
        else if(match_types(t->type, "dts")){
            if(access("/system/etc/firmware/audiodsp_codec_dtshd.bin",F_OK)){
                adec_print("using no license dts component");
                audio_decoder = AUDIO_ARM_DECODER;
            }else{
                adec_print("using audiodsp dts decoder");
                audio_decoder = AUDIO_ARC_DECODER;
            }
        }
        #endif
        else{
            audio_decoder = AUDIO_ARM_DECODER;
        }
        goto exit;
    }
	
	ret = property_get("media.arc.audio.decoder",value,NULL);
	adec_print("media.amplayer.audiocodec = %s, t->type = %s\n", value, t->type);
	if (ret>0 && match_types(t->type,value))
	{	
		if(audec->dspdec_not_supported == 0)
			audio_decoder = AUDIO_ARC_DECODER;
		else{
			audio_decoder = AUDIO_ARM_DECODER;	
			adec_print("[%s:%d]arc decoder not support this audio yet,switch to ARM decoder \n",__FUNCTION__, __LINE__);
		}
		goto exit;
	} 
	
	ret = property_get("media.ffmpeg.audio.decoder",value,NULL);
	adec_print("media.amplayer.audiocodec = %s, t->type = %s\n", value, t->type);
	if (ret>0 && match_types(t->type,value))
	{	
		audio_decoder = AUDIO_FFMPEG_DECODER;
		goto exit;
	} 
	
	audio_decoder = AUDIO_ARC_DECODER; //set arc decoder as default
	if(audec->dspdec_not_supported == 1){
		audio_decoder = AUDIO_ARM_DECODER;	
		adec_print("[%s:%d]arc decoder not support this audio yet,switch to ARM decoder \n",__FUNCTION__, __LINE__);
	}
exit:
	if(am_getconfig_bool("media.libplayer.wfd") && (audio_id ==ACODEC_FMT_WIFIDISPLAY ||audio_id==ACODEC_FMT_AAC)){
		adec_print("wfd use arm decoder \n");
		audio_decoder = AUDIO_ARMWFD_DECODER;
	}	
	return 0;
}