Beispiel #1
0
static void acodec_info_init(play_para_t *p_para, codec_para_t *a_codec)
{
    AVCodecContext  *pCodecCtx;
    a_stream_info_t *ainfo = &p_para->astream_info;

    a_codec->has_audio      = 1;
    a_codec->audio_type     = ainfo->audio_format;
    a_codec->audio_pid      = ainfo->audio_pid;
    a_codec->audio_channels = ainfo->audio_channel;
    a_codec->audio_samplerate = ainfo->audio_samplerate;
    a_codec->noblock = !!p_para->buffering_enable;
    a_codec->avsync_threshold = p_para->start_param->avsync_threshold;
    a_codec->stream_type = stream_type_convert(p_para->stream_type, 0, a_codec->has_audio);
	a_codec->switch_audio_flag = 0;
    if( p_para->astream_info.has_audio==1 && 
        p_para->vstream_info.has_video==0 && 
        (a_codec->audio_type ==AFORMAT_COOK ||a_codec->audio_type ==AFORMAT_SIPR))
    {  
        log_print("[%s %d]Pure RA audio Stream/%d, Covert audio_type to AFORMAT_PCM_S16LE\n",__FUNCTION__,__LINE__,a_codec->audio_type);
        a_codec->audio_type=AFORMAT_PCM_S16LE;
    }
    log_print("[%s:%d]audio stream_type=%d afmt=%d apid=%d asample_rate=%d achannel=%d\n",
              __FUNCTION__, __LINE__, a_codec->stream_type, a_codec->audio_type, a_codec->audio_pid,
              a_codec->audio_samplerate, a_codec->audio_channels);
	pCodecCtx = p_para->pFormatCtx->streams[p_para->astream_info.audio_index]->codec;

    /*if ((a_codec->audio_type == AFORMAT_ADPCM) || (a_codec->audio_type == AFORMAT_WMA) || (a_codec->audio_type == AFORMAT_WMAPRO) || (a_codec->audio_type == AFORMAT_PCM_S16BE) || (a_codec->audio_type == AFORMAT_PCM_S16LE) || (a_codec->audio_type == AFORMAT_PCM_U8) \
        ||(a_codec->audio_type == AFORMAT_AMR)) {*/
    if (IS_AUIDO_NEED_EXT_INFO(a_codec->audio_type)) {
        if ((a_codec->audio_type == AFORMAT_ADPCM) || (a_codec->audio_type == AFORMAT_ALAC)) {
            a_codec->audio_info.bitrate = pCodecCtx->sample_fmt;
        } else if (a_codec->audio_type == AFORMAT_APE) {
            a_codec->audio_info.bitrate = pCodecCtx->bits_per_coded_sample;
        } else {
            a_codec->audio_info.bitrate = pCodecCtx->bit_rate;
        }
        a_codec->audio_info.sample_rate = pCodecCtx->sample_rate;
        a_codec->audio_info.channels = pCodecCtx->channels;
        a_codec->audio_info.codec_id = pCodecCtx->codec_id;
        a_codec->audio_info.block_align = pCodecCtx->block_align;
        a_codec->audio_info.extradata_size = pCodecCtx->extradata_size;
        if (a_codec->audio_info.extradata_size > 0) {
            if (a_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__);
                a_codec->audio_info.extradata_size =    AUDIO_EXTRA_DATA_SIZE;
            }
            memcpy((char*)a_codec->audio_info.extradata, pCodecCtx->extradata, a_codec->audio_info.extradata_size);
        }
        a_codec->audio_info.valid = 1;
        log_print("[%s]fmt=%d srate=%d chanels=%d extrasize=%d,block align %d,codec id 0x%x\n", __FUNCTION__, a_codec->audio_type, \
                  a_codec->audio_info.sample_rate, a_codec->audio_info.channels, a_codec->audio_info.extradata_size, a_codec->audio_info.block_align, a_codec->audio_info.codec_id);

    }
	a_codec->SessionID = p_para->start_param->SessionID;		
	if(IS_AUDIO_NOT_SUPPORTED_BY_AUDIODSP(a_codec->audio_type,pCodecCtx)){
			a_codec->dspdec_not_supported = 1;
			log_print("main profile aac not supported by dsp decoder,so set dspdec_not_supported flag\n");
	}	
}
Beispiel #2
0
bool CTsPlayer::StartPlay()
{
	int ret;
	memset(pcodec,0,sizeof(*pcodec));
	pcodec->stream_type=STREAM_TYPE_TS;
	pcodec->video_type = vPara.vFmt;
	pcodec->has_video=1;
	pcodec->audio_type= aPara.aFmt;
	pcodec->has_audio=1;
	pcodec->video_pid=(int)vPara.pid;
	pcodec->audio_pid=(int)aPara.pid;
	//pcodec->audio_channels = 1;
	//pcodec->audio_samplerate = 48000;
	// 解决AC3无声的问题
    if(IS_AUIDO_NEED_EXT_INFO(pcodec->audio_type)){
        pcodec->audio_info.valid = 1;
		LOGI("set audio_info.valid to 1");
    }
    if (pcodec->video_type == VFORMAT_H264) {
         pcodec->am_sysinfo.format = VIDEO_DEC_FORMAT_H264;
         pcodec->am_sysinfo.param = (void *)(0);
    }
    else if(pcodec->video_type ==VFORMAT_MPEG12){
        pcodec->am_sysinfo.param = (void *)(0);
    }
	printf("set %d,%d,%d,%d\n",vPara.vFmt,aPara.aFmt,vPara.pid,aPara.pid);
	pcodec->noblock = 0;
	/*other setting*/
	ret=codec_init(pcodec);

 #if DUMP_TSPACKET1	
	 m_fStream = fopen("/data/data/novel.supertv.dvb/new_1.ts","wb");
 #endif 
	
	return !ret;
}
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;
        } else if (codec->video_type == VFORMAT_VC1) {
            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;
		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;

        }
	 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;
    }

    p_para->codec = codec;
    return PLAYER_SUCCESS;
error1:
    log_print("[ts]codec_init failed!\n");
    codec_free(codec);
    return DECODER_INIT_FAILED;
}
static int stream_audio_init(play_para_t *p_para)
{
    int ret = CODEC_ERROR_NONE;
    a_stream_info_t *ainfo = &p_para->astream_info;
    codec_para_t *codec ;
    AVCodecContext  *pCodecCtx;	
    codec = codec_alloc();
    if (!codec) {
        return PLAYER_EMPTY_P;
    }
    MEMSET(codec, 0, sizeof(codec_para_t));
    codec->noblock = !!p_para->buffering_enable;
    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;
    }
    codec->stream_type = stream_type_convert(p_para->stream_type, codec->has_video, codec->has_audio);
	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_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;
        log_print("[%s:%d]block_align=%d,,sample_rate=%d,,channels=%d,,bitrate=%d,,codec_id=%d,extra size %d,SessionID=%d\n", __FUNCTION__, __LINE__, codec->audio_info.block_align,
                  codec->audio_info.sample_rate, codec->audio_info.channels , codec->audio_info.extradata_size, codec->audio_info.codec_id, codec->audio_info.extradata_size, codec->SessionID);
    }
	codec->SessionID = p_para->start_param->SessionID;	
	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");
	}	
    ret = codec_init(codec);
    if (ret != CODEC_ERROR_NONE) {
        if (ret != CODEC_OPEN_HANDLE_FAILED) {
            codec_close(codec);
        }
        goto error1;
    }
    log_print("[%s:%d]codec init finished! mute_on:%d\n", __FUNCTION__, __LINE__, p_para->playctrl_info.audio_mute);
    /*ret = codec_set_mute(codec, p_para->playctrl_info.audio_mute);
    if (ret != CODEC_ERROR_NONE) {
        codec_close(codec);
        goto error1;
    }*/
    p_para->acodec = codec;
    return PLAYER_SUCCESS;

error1:
    log_print("[audio]codec_init failed!ret=%x stream_type=%d\n", ret, codec->stream_type);
    codec_free(codec);
    return DECODER_INIT_FAILED;
}