static int stream_video_init(play_para_t *p_para)
{
    int ret = CODEC_ERROR_NONE;
    v_stream_info_t *vinfo = &p_para->vstream_info;

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

    if (vinfo->has_video) {
        codec->has_video = 1;
        codec->video_type = vinfo->video_format;
        codec->video_pid = vinfo->video_pid;
    }
    codec->stream_type = stream_type_convert(p_para->stream_type, codec->has_video, codec->has_audio);
    codec->noblock = !!p_para->buffering_enable;
    ret = codec_init(codec);
    if (ret != CODEC_ERROR_NONE) {
        if (ret != CODEC_OPEN_HANDLE_FAILED) {
            codec_close(codec);
        }
        goto error1;
    }

    p_para->vcodec = codec;
    return PLAYER_SUCCESS;
error1:
    log_print("[video]codec_init failed!ret=%x stream_type=%d\n", ret, codec->stream_type);
    codec_free(codec);
    return DECODER_INIT_FAILED;
}
示例#2
0
static int stream_ps_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;
    codec_para_t *codec ;
    AVCodecContext  *pCodecCtx;

    int ret = CODEC_ERROR_NONE;

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

    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;
        }
        if (codec->video_type == VFORMAT_VC1) {
            codec->video_pid = codec->video_pid >> 8; // vc1 is extension id, from 0xfd55 to 0xfd5f according to ffmpeg
            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;
            codec->am_sysinfo.ratio = vinfo->video_ratio;
        }
static int stream_video_init(play_para_t *p_para)
{
    int ret = -1;
	v_stream_info_t *vinfo=&p_para->vstream_info;
	
	codec_para_t *codec ;		
	codec=codec_alloc();
	if(!codec)
		return PLAYER_EMPTY_P;
	MEMSET(codec, 0, sizeof(codec_para_t));
    if (codec_init_cntl(codec) != 0)
        goto error1;
	if(vinfo->has_video)
	{
		codec->has_video = 1;
		codec->video_type = vinfo->video_format;
		codec->video_pid = vinfo->video_pid;		
	}	
	codec->stream_type= stream_type_convert(p_para->stream_type, codec->has_video, codec->has_audio);
    ret = codec_init(codec);
	if(ret != 0)
		goto error1;
	
	p_para->vcodec = codec;	   
	return PLAYER_SUCCESS;
error1:
	log_print("[video]codec_init failed!ret=%x stream_type=%d\n",ret,codec->stream_type);
	codec_free(codec);	
	return DECODER_INIT_FAILED;
}
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;
}
示例#6
0
文件: player_es.c 项目: vitmod/libp
static int stream_es_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;
    codec_para_t *v_codec = NULL, *a_codec = NULL, *s_codec = NULL;
    int ret = CODEC_ERROR_NONE;

    if (vinfo->has_video) {
        v_codec = codec_alloc();
        if (!v_codec) {
            return PLAYER_EMPTY_P;
        }
        MEMSET(v_codec, 0, sizeof(codec_para_t));

        vcodec_info_init(p_para, v_codec);

        ret = codec_init(v_codec);
        if (ret != CODEC_ERROR_NONE) {
            if (ret != CODEC_OPEN_HANDLE_FAILED) {
                codec_close(v_codec);
            }
            goto error1;
        }
        p_para->vcodec = v_codec;
    }

    if (ainfo->has_audio) {
        a_codec = codec_alloc();
        if (!a_codec) {
            if (vinfo->has_video && v_codec) {
                codec_release(v_codec);
            }
            return PLAYER_EMPTY_P;
        }
        MEMSET(a_codec, 0, sizeof(codec_para_t));

        acodec_info_init(p_para, a_codec);

        ret = codec_init(a_codec);
        if (ret != CODEC_ERROR_NONE) {
            if (ret != CODEC_OPEN_HANDLE_FAILED) {
                codec_close(a_codec);
            }
            goto error2;
        }
        p_para->acodec = a_codec;
    }
    if (!p_para->vcodec && !p_para->acodec) {
        log_print("[stream_es_init] no audio and no video codec init!\n");
        return DECODER_INIT_FAILED;
    }
    if (sinfo->has_sub) {
        s_codec = codec_alloc();
        if (!s_codec) {
            if (vinfo->has_video && v_codec) {
                codec_release(v_codec);
            }
            if (ainfo->has_audio && a_codec) {
                codec_release(a_codec);
            }
            return PLAYER_EMPTY_P;
        }

        MEMSET(s_codec, 0, sizeof(codec_para_t));
        scodec_info_init(p_para, s_codec);
        if (codec_init(s_codec) != 0) {
            goto error3;
        }
        p_para->scodec = s_codec;
    }

    if (v_codec) {
        codec_set_freerun_mode(v_codec, p_para->playctrl_info.freerun_mode);
        codec_set_vsync_upint(v_codec, p_para->playctrl_info.vsync_upint);
    }
    
    return PLAYER_SUCCESS;

error1:
    codec_free(v_codec);
    return DECODER_INIT_FAILED;

error2:
    if (vinfo->has_video && v_codec) {
        codec_release(v_codec);
    }
    codec_free(a_codec);
    return DECODER_INIT_FAILED;

error3:
    if (vinfo->has_video && v_codec) {
        codec_release(v_codec);
    }
    if (ainfo->has_audio && a_codec) {
        codec_release(a_codec);
    }
    codec_free(s_codec);
    return DECODER_INIT_FAILED;
}