Exemplo n.º 1
0
static int stream_es_release(play_para_t *p_para)
{
    int r = -1;
    if (p_para->acodec) {
        r = codec_close(p_para->acodec);
        if (r < 0) {
            log_error("[stream_es_release]close acodec failed, r= %x\n", r);
            return r;
        }
        codec_free(p_para->acodec);
        p_para->acodec = NULL;
    }
    if (p_para->vcodec) {
        r = codec_close(p_para->vcodec);
        if (r < 0) {
            log_error("[stream_es_release]close vcodec failed, r= %x\n", r);
            return r;
        }
        codec_free(p_para->vcodec);
        p_para->vcodec = NULL;
    }
    if (p_para->scodec) {
        r = codec_close(p_para->scodec);
        if (r < 0) {
            log_error("[stream_es_release]close scodec failed, r= %x\n", r);
            return r;
        }
        codec_free(p_para->scodec);
        p_para->scodec = NULL;
    }
    p_para->codec = NULL;
    return 0;
}
Exemplo n.º 2
0
static void signal_handler(int signum)
{
    printf("Get signum=%x\n",signum);
    codec_close(apcodec);
    codec_close(vpcodec);
    fclose(fp);
    set_display_axis(1);
    signal(signum, SIG_DFL);
    raise (signum);
}
Exemplo n.º 3
0
void ES_PlayDeinit()
{
	if( apcodec != NULL )
	{
		codec_close(apcodec);
	//	apcodec = NULL;
	}
	
	if( vpcodec != NULL )
	{
		codec_close(vpcodec);
		vpcodec = NULL;
	}
		
}
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;
}
static int stream_ts_release(play_para_t *p_para)
{
    if (p_para->codec) {
        codec_close(p_para->codec);
        codec_free(p_para->codec);
    }
    p_para->codec = NULL;
    return 0;
}
static int stream_audio_release(play_para_t *p_para)
{
    if (p_para->acodec) {
        codec_close(p_para->acodec);
        codec_free(p_para->acodec);
    }
    p_para->acodec = NULL;
    p_para->codec = NULL;
    return PLAYER_SUCCESS;
}
Exemplo n.º 7
0
bool CTsPlayer::Stop()
{
#if DUMP_TSPACKET1
	if(m_fStream){
		fclose(m_fStream);
	}
#endif 
	codec_close(pcodec);
	return true;
}
Exemplo n.º 8
0
/*
======================
S_StopBackgroundTrack
======================
*/
void SOrig_StopBackgroundTrack( void )
{
	if ( !s_backgroundStream )
	{
		return;
	}

	codec_close( s_backgroundStream );
	s_backgroundStream = NULL;
	s_rawend = 0;
}
static int stream_video_release(play_para_t *p_para)
{
	if(p_para->vcodec)
	{
        codec_close_cntl(p_para->vcodec);
        codec_close(p_para->vcodec);
        codec_free(p_para->vcodec);
	}
	p_para->vcodec=NULL;
	return 0;
}
Exemplo n.º 10
0
static int stream_ts_release(play_para_t *p_para)
{
    if (p_para->codec) {
        if (p_para->codec->audio_utils_handle >= 0) {
            codec_set_audio_resample_ena(p_para->codec, 0); 
        }

        codec_close(p_para->codec);
        codec_free(p_para->codec);
    }
    p_para->codec = NULL;
    return 0;
}
Exemplo n.º 11
0
static int codec_release(codec_para_t *codec)
{
    int r = CODEC_ERROR_NONE;
    if (codec) {
        r = codec_close(codec);
        if (r < 0) {
            log_error("[stream_es_init]close codec failed, r= %x\n", r);
            return r;
        }
        codec_free(codec);
        codec = NULL;
    }
    return r;
}
Exemplo n.º 12
0
static gboolean
gst_aml_vdec_close(GstVideoDecoder * dec)
{
	GstAmlVdec *amlvdec = GST_AMLVDEC(dec);
	gint ret=0;
	GST_ERROR("%s,%d\n",__FUNCTION__,__LINE__);
	stop_eos_task (amlvdec);
	if (amlvdec->codec_init_ok) {
		amlvdec->codec_init_ok = 0;
		if (amlvdec->is_paused == TRUE) {
			ret = codec_resume(amlvdec->pcodec);
			if (ret != 0) {
				GST_ERROR("[%s:%d]resume failed!ret=%d", __FUNCTION__, __LINE__, ret);
			} else
				amlvdec->is_paused = FALSE;
		}
		set_black_policy(1);
		codec_close(amlvdec->pcodec);

		amlvdec->is_headerfeed = FALSE;
		if (amlvdec->input_state) {
			gst_video_codec_state_unref(amlvdec->input_state);
			amlvdec->input_state = NULL;
		}
		
		set_fb0_blank(0);
		set_fb1_blank(0);
//T?		set_display_axis(1);
	}
	if (amlvdec->info) {
			amlvdec->info->finalize(amlvdec->info);
			amlvdec->info = NULL;
		}
#if DEBUG_DUMP
	if (amlvdec->dump_fd > 0) {
		codec_set_dump_fd(NULL, 0);
		close(amlvdec->dump_fd);
	}
#endif
	if (amlvdec->pcodec) {
		g_free(amlvdec->pcodec);
		amlvdec->pcodec = NULL;
	}
	return TRUE;
}
Exemplo n.º 13
0
/*
======================
S_StartBackgroundTrack
======================
*/
void SOrig_StartBackgroundTrack( const char *intro, const char *loop )
{
	if ( !intro )
	{
		intro = "";
	}

	if ( !loop || !loop[ 0 ] )
	{
		loop = intro;
	}

	Com_DPrintf( "S_StartBackgroundTrack( %s, %s )\n", intro, loop );

	if ( !intro[ 0 ] )
	{
		return;
	}

	Q_strncpyz( s_backgroundLoop, loop, sizeof( s_backgroundLoop ) );

	// close the background track, but DON'T reset s_rawend
	// if restarting the same back ground track
	if ( s_backgroundStream )
	{
		codec_close( s_backgroundStream );
		s_backgroundStream = NULL;
	}

	// Open stream
	s_backgroundStream = codec_open( intro );

	if ( !s_backgroundStream )
	{
		Com_DPrintf( S_COLOR_YELLOW  "WARNING: couldn't open music file %s\n", intro );
		return;
	}

	if ( s_backgroundStream->info.channels != 2 || s_backgroundStream->info.rate != 22050 )
	{
		Com_DPrintf( S_COLOR_YELLOW  "WARNING: music file %s is not 22k stereo\n", intro );
	}
}
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;
}
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;
}
Exemplo n.º 16
0
/* Handle Q_CODEC_UNLOAD */
static void unload_codec(void)
{
    /* Tell codec to clean up */
    codec_type = AFMT_UNKNOWN;
    codec_close();
}
Exemplo n.º 17
0
int main(int argc,char *argv[])
{
    int ret = CODEC_ERROR_NONE;
    char buffer[READ_SIZE];
    unsigned int vformat = 0, aformat = 0;

    int len = 0;
    int size = READ_SIZE;
    uint32_t Readlen;
    uint32_t isize;
    struct buf_status vbuf;

    if (argc < 8) {
        printf("Corret command: tsplay <filename> <vid> <vformat(1 for mpeg2, 2 for h264)> <aid> <aformat(1 for mp3)> <channel> <samplerate>\n");
        return -1;
    }
    osd_blank("/sys/class/graphics/fb0/blank",1);
    osd_blank("/sys/class/graphics/fb1/blank",0);
    set_display_axis(0);
    set_stb_source_hiu();
    set_stb_demux_source_hiu();

    pcodec = &codec_para;
    memset(pcodec, 0, sizeof(codec_para_t ));

    pcodec->noblock = 0;
    pcodec->has_video = 1;
    pcodec->video_pid = atoi(argv[2]);
    vformat = atoi(argv[3]);
    if (vformat == 1)
        pcodec->video_type = VFORMAT_MPEG12;
    else if (vformat == 2)
        pcodec->video_type = VFORMAT_H264;
    else
        pcodec->video_type = VFORMAT_MPEG12;

    pcodec->has_audio = 1;
    pcodec->audio_pid = atoi(argv[4]);
    aformat = atoi(argv[5]);
    pcodec->audio_type = AFORMAT_MPEG; // take mp for example
    pcodec->audio_channels = atoi(argv[6]);
    pcodec->audio_samplerate = atoi(argv[7]);
    pcodec->audio_info.channels = 2;
    pcodec->audio_info.sample_rate = pcodec->audio_samplerate;
    pcodec->audio_info.valid = 1;

    pcodec->stream_type = STREAM_TYPE_TS;
    pcodec->packet_size = 188; // standard ts packet size

    printf("\n*********CODEC PLAYER DEMO************\n\n");
    filename = argv[1];
    printf("file %s to be played\n", filename);

    if((fp = fopen(filename,"rb")) == NULL)
    {
       printf("open file error!\n");
       return -1;
    }

    ret = codec_init(pcodec);
    if(ret != CODEC_ERROR_NONE)
    {
        printf("codec init failed, ret=-0x%x", -ret);
        return -1;
    }

    printf("ps codec ok!\n");

    //codec_set_cntl_avthresh(vpcodec, AV_SYNC_THRESH);
    //codec_set_cntl_syncthresh(vpcodec, 0);

    set_avsync_enable(1);

    while(!feof(fp))
    {
        Readlen = fread(buffer, 1, READ_SIZE,fp);
        //printf("Readlen %d\n", Readlen);
        if(Readlen <= 0)
        {
            printf("read file error!\n");
            rewind(fp);
        }

        isize = 0;
        do{
            ret = codec_write(pcodec, buffer+isize, Readlen);
            if (ret < 0) {
                if (errno != EAGAIN) {
                    printf("write data failed, errno %d\n", errno);
                    goto error;
                }
                else {
                    continue;
                }
            }
            else {
                isize += ret;
            }
            //printf("ret %d, isize %d\n", ret, isize);
        }while(isize < Readlen);	 

        signal(SIGCHLD, SIG_IGN);
        signal(SIGTSTP, SIG_IGN);
        signal(SIGTTOU, SIG_IGN);
        signal(SIGTTIN, SIG_IGN);
        signal(SIGHUP, signal_handler);
        signal(SIGTERM, signal_handler);
        signal(SIGSEGV, signal_handler);
        signal(SIGINT, signal_handler);
        signal(SIGQUIT, signal_handler);
    }	

    do {
        ret = codec_get_vbuf_state(pcodec, &vbuf);
        if (ret != 0) {
            printf("codec_get_vbuf_state error: %x\n", -ret);
            goto error;
        }        
    } while (vbuf.data_len > 0x100);
    
error:
    codec_close(pcodec);
    fclose(fp);
    set_display_axis(1);
    
    return 0;
}
Exemplo n.º 18
0
/*
======================
S_UpdateBackgroundTrack
======================
*/
void S_UpdateBackgroundTrack( void )
{
	int           bufferSamples;
	int           fileSamples;
	byte          raw[ 30000 ]; // just enough to fit in a mac stack frame
	int           fileBytes;
	int           r;
	static  float musicVolume = 0.5f;

	if ( !s_backgroundStream )
	{
		return;
	}

	// graeme see if this is OK
	musicVolume = ( musicVolume + ( s_musicVolume->value * 2 ) ) / 4.0f;

	// don't bother playing anything if musicvolume is 0
	if ( musicVolume <= 0 )
	{
		return;
	}

	// see how many samples should be copied into the raw buffer
	if ( s_rawend < s_soundtime )
	{
		s_rawend = s_soundtime;
	}

	while ( s_rawend < s_soundtime + MAX_RAW_SAMPLES )
	{
		bufferSamples = MAX_RAW_SAMPLES - ( s_rawend - s_soundtime );

		// decide how much data needs to be read from the file
		fileSamples = bufferSamples * s_backgroundStream->info.rate / dma.speed;

		// our max buffer size
		fileBytes = fileSamples * ( s_backgroundStream->info.width * s_backgroundStream->info.channels );

		if ( fileBytes > sizeof( raw ) )
		{
			fileBytes = sizeof( raw );
			fileSamples = fileBytes / ( s_backgroundStream->info.width * s_backgroundStream->info.channels );
		}

		// Read
		r = codec_read( s_backgroundStream, fileBytes, raw );

		if ( r < fileBytes )
		{
			fileBytes = r;
			fileSamples = r / ( s_backgroundStream->info.width * s_backgroundStream->info.channels );
		}

		if ( r > 0 )
		{
			// add to raw buffer
			SOrig_RawSamples( 0, fileSamples, s_backgroundStream->info.rate,
			                  s_backgroundStream->info.width, s_backgroundStream->info.channels, raw, s_musicVolume->value, -1 );
		}
		else
		{
			// loop
			if ( s_backgroundLoop[ 0 ] )
			{
				codec_close( s_backgroundStream );
				s_backgroundStream = NULL;
				SOrig_StartBackgroundTrack( s_backgroundLoop, s_backgroundLoop );

				if ( !s_backgroundStream )
				{
					return;
				}
			}
			else
			{
				SOrig_StopBackgroundTrack();
				return;
			}
		}
	}
}
Exemplo n.º 19
0
int main(int argc,char *argv[])
{
    int ret = CODEC_ERROR_NONE;
    char buffer[READ_SIZE];

    int len = 0;
    int size = READ_SIZE;
    uint32_t Readlen;
    uint32_t isize;
    struct buf_status vbuf;

    if (argc < 6) {
        printf("Corret command: esplayer <filename> <width> <height> <fps> <format(1:mpeg4 2:h264 6:vc1)> [subformat for mpeg4/vc1]\n");
        return -1;
    }
    osd_blank("/sys/class/graphics/fb0/blank",1);
    osd_blank("/sys/class/graphics/fb1/blank",0);
    set_display_axis(0);
#ifdef AUDIO_ES
    apcodec = &a_codec_para;
    memset(apcodec, 0, sizeof(codec_para_t ));
#endif

    vpcodec = &v_codec_para;
    memset(vpcodec, 0, sizeof(codec_para_t ));

    vpcodec->has_video = 1;
    vpcodec->video_type = atoi(argv[5]);
    if (vpcodec->video_type == VFORMAT_H264) {
        vpcodec->am_sysinfo.format = VIDEO_DEC_FORMAT_H264;
        vpcodec->am_sysinfo.param = (void *)(EXTERNAL_PTS | SYNC_OUTSIDE);
    }
    else if (vpcodec->video_type == VFORMAT_VC1) {
        if (argc < 7) {
            printf("No subformat for vc1, take the default VIDEO_DEC_FORMAT_WVC1\n");
            vpcodec->am_sysinfo.format = VIDEO_DEC_FORMAT_WVC1;
        }
        else {
            vpcodec->am_sysinfo.format = atoi(argv[6]);
        }
    }
    else if (vpcodec->video_type == VFORMAT_MPEG4) {
        if (argc < 7) {
            printf("No subformat for mpeg4, take the default VIDEO_DEC_FORMAT_MPEG4_5\n");
            vpcodec->am_sysinfo.format = VIDEO_DEC_FORMAT_MPEG4_5;
        }
        else {
            vpcodec->am_sysinfo.format = atoi(argv[6]);
        }
    }

    vpcodec->stream_type = STREAM_TYPE_ES_VIDEO;
    vpcodec->am_sysinfo.rate = 96000 / atoi(argv[4]);
    vpcodec->am_sysinfo.height = atoi(argv[3]);
    vpcodec->am_sysinfo.width = atoi(argv[2]);
    vpcodec->has_audio = 0;
    vpcodec->noblock = 0;

#ifdef AUDIO_ES
    apcodec->audio_type = AFORMAT_MPEG;
    apcodec->stream_type = STREAM_TYPE_ES_AUDIO;
    apcodec->audio_pid = 0x1023;
    apcodec->has_audio = 1;
    apcodec->audio_channels = 2;
    apcodec->audio_samplerate = 48000;
    apcodec->noblock = 0;
    apcodec->audio_info.channels = 2;
    apcodec->audio_info.sample_rate = 48000;
#endif

    printf("\n*********CODEC PLAYER DEMO************\n\n");
    filename = argv[1];
    printf("file %s to be played\n", filename);

    if((fp = fopen(filename,"rb")) == NULL)
    {
        printf("open file error!\n");
        return -1;
    }

#ifdef AUDIO_ES
    ret = codec_init(apcodec);
    if(ret != CODEC_ERROR_NONE)
    {
        printf("codec init failed, ret=-0x%x", -ret);
        return -1;
    }
#endif

    ret = codec_init(vpcodec);
    if(ret != CODEC_ERROR_NONE)
    {
        printf("codec init failed, ret=-0x%x", -ret);
        return -1;
    }
    printf("video codec ok!\n");

    //codec_set_cntl_avthresh(vpcodec, AV_SYNC_THRESH);
    //codec_set_cntl_syncthresh(vpcodec, 0);

    set_tsync_enable(0);

    pcodec = vpcodec;
    while(!feof(fp))
    {
        Readlen = fread(buffer, 1, READ_SIZE,fp);
        //printf("Readlen %d\n", Readlen);
        if(Readlen <= 0)
        {
            printf("read file error!\n");
            rewind(fp);
        }

        isize = 0;
        do {
            ret = codec_write(pcodec, buffer+isize, Readlen);
            if (ret < 0) {
                if (errno != EAGAIN) {
                    printf("write data failed, errno %d\n", errno);
                    goto error;
                }
                else {
                    continue;
                }
            }
            else {
                isize += ret;
            }
            //printf("ret %d, isize %d\n", ret, isize);
        } while(isize < Readlen);

        signal(SIGCHLD, SIG_IGN);
        signal(SIGTSTP, SIG_IGN);
        signal(SIGTTOU, SIG_IGN);
        signal(SIGTTIN, SIG_IGN);
        signal(SIGHUP, signal_handler);
        signal(SIGTERM, signal_handler);
        signal(SIGSEGV, signal_handler);
        signal(SIGINT, signal_handler);
        signal(SIGQUIT, signal_handler);
    }

    do {
        ret = codec_get_vbuf_state(pcodec, &vbuf);
        if (ret != 0) {
            printf("codec_get_vbuf_state error: %x\n", -ret);
            goto error;
        }
    } while (vbuf.data_len > 0x100);

error:
#ifdef AUDIO_ES
    codec_close(apcodec);
#endif
    codec_close(vpcodec);
    fclose(fp);
    set_display_axis(1);

    return 0;
}
Exemplo n.º 20
0
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;
}
Exemplo n.º 21
0
int main(int argc, char * const argv[])
{
	int ret = CODEC_ERROR_NONE;
  std::string input_filename;

  if (argc > 1) {
    for (int i = 1; i < argc; i++) {
      if (strncasecmp(argv[i], "--input", 7) == 0) {
        // check the next arg with the proper value.
        int next = i + 1;
        if (next < argc) {
          input_filename = argv[next];
          i++;
        }
      } else if (strncasecmp(argv[i], "-h", 2) == 0 || strncasecmp(argv[i], "--help", 6) == 0) {
        printf("Usage: %s [OPTIONS]...\n", argv[0]);
        printf("Arguments:\n");
        printf("  --input <filename> \tInput video filename\n");
        exit(0);
      }
    }
  }
  if (input_filename.empty()) {
    printf("no input file specified\n");
    exit(0);
  }

  // install signal handlers
  signal(SIGINT, signal_handler);
  signal(SIGTERM, signal_handler);

  // initialize App contex.
  AVPacket avpkt;
  AppContext ctx;
  memset(&ctx, 0, sizeof(ctx));

  player_para_init(&ctx);
  am_packet_init(&ctx.am_pkt);

  ctx.am_pkt.avpkt = &avpkt;
  av_init_packet(ctx.am_pkt.avpkt);

  // create the ffmepg file reader/demuxer
  ctx.demuxer = new FFmpegFileReader(input_filename.c_str());
  if (!ctx.demuxer->Initialize()) {
    fprintf(stderr, "ERROR: Can't initialize FFmpegFileReader\n");
    goto fail;
  }
  
  ctx.codec_context = ctx.demuxer->GetCodecContext();
  ctx.format_context = ctx.demuxer->GetFormatContext();
  if (!ctx.codec_context) {
    fprintf(stderr, "ERROR: Invalid FFmpegFileReader Codec Context\n");
    goto fail;
  }

  dump_extradata(&ctx);

  printf("video width(%d), height(%d), extradata_size(%d)\n",
    (int)ctx.codec_context->width, (int)ctx.codec_context->height, ctx.codec_context->extradata_size);

  AVStream *pStream;
  pStream = ctx.format_context->streams[ctx.demuxer->GetVideoIndex()];
  //ctx.vstream_info.video_pid = (unsigned short)ctx.codec_context->id;
  if (pStream->time_base.den) {
    ctx.vstream_info.start_time     = pStream->start_time * pStream->time_base.num * PTS_FREQ / pStream->time_base.den;
    ctx.vstream_info.video_duration = ((float)pStream->time_base.num / pStream->time_base.den) * UNIT_FREQ;
    ctx.vstream_info.video_pts      = ((float)pStream->time_base.num / pStream->time_base.den) * PTS_FREQ;
  }
  ctx.vstream_info.video_width  = ctx.codec_context->width;
  ctx.vstream_info.video_height = ctx.codec_context->height;
  ctx.vstream_info.video_ratio  = (float)pStream->sample_aspect_ratio.num / pStream->sample_aspect_ratio.den;
  if (ctx.codec_context->time_base.den) {
    ctx.vstream_info.video_codec_rate = (int64_t)UNIT_FREQ * ctx.codec_context->time_base.num / ctx.codec_context->time_base.den;
  }
  if (pStream->r_frame_rate.num) {
    ctx.vstream_info.video_rate = (int64_t)UNIT_FREQ * pStream->r_frame_rate.den / pStream->r_frame_rate.num;
  }


  log_print("time_base.num(%d), pStream->time_base.den(%d)\n",
    pStream->time_base.num, pStream->time_base.den);
    ctx.vstream_info.video_duration = ((float)pStream->time_base.num / pStream->time_base.den) * UNIT_FREQ;
    ctx.vstream_info.video_pts      = ((float)pStream->time_base.num / pStream->time_base.den) * PTS_FREQ;

  printf("\n*********AMLOGIC CODEC PLAYER DEMO************\n\n");
	osd_blank("/sys/class/graphics/fb0/blank", 1);
	osd_blank("/sys/class/graphics/fb1/blank", 1);
	//osd_blank("/sys/class/tsync/enable", 1);
  osd_blank("/sys/class/tsync/enable", 0);

  switch(ctx.codec_context->codec_id)
  {
    case CODEC_ID_H264:
      printf("CODEC_ID_H264\n");

      ctx.vcodec.has_video = 1;
      ctx.vcodec.has_audio = 0;
      ctx.stream_type = STREAM_ES;
      //ctx.vcodec.video_pid = ctx.demuxer->GetVideoIndex();
      ctx.vcodec.video_type = VFORMAT_H264;
      ctx.vcodec.stream_type = STREAM_TYPE_ES_VIDEO;
      //ctx.vcodec.noblock = !!p_para->buffering_enable;
      ctx.vcodec.am_sysinfo.format = VIDEO_DEC_FORMAT_H264;
      ctx.vcodec.am_sysinfo.width  = ctx.vstream_info.video_width;
      ctx.vcodec.am_sysinfo.height = ctx.vstream_info.video_height;
      ctx.vcodec.am_sysinfo.rate   = ctx.vstream_info.video_rate;
      ctx.vcodec.am_sysinfo.ratio  = ctx.vstream_info.video_ratio;
      ctx.vcodec.am_sysinfo.param = (void*)(EXTERNAL_PTS | SYNC_OUTSIDE);

    break;
    case CODEC_ID_MPEG4:
      printf("CODEC_ID_MPEG4\n");
      ctx.vcodec.video_type = VFORMAT_MPEG4;
    break;
    case CODEC_ID_MPEG2VIDEO:
      printf("CODEC_ID_MPEG2VIDEO\n");
      ctx.vcodec.video_type = VFORMAT_MPEG12;
    break;
    default:
      fprintf(stderr, "ERROR: Invalid FFmpegFileReader Codec Format (not h264/mpeg4) = %d\n",
        ctx.codec_context->codec_id);
      goto fail;
    break;
  }

	ret = codec_init(&ctx.vcodec);
	if(ret != CODEC_ERROR_NONE)
	{
		printf("codec init failed, ret=-0x%x", -ret);
		return -1;
	}
	printf("video codec ok!\n");


	ret = codec_init_cntl(&ctx.vcodec);
	if( ret != CODEC_ERROR_NONE )
	{
		printf("codec_init_cntl error\n");
		return -1;
	}

	codec_set_cntl_avthresh(&ctx.vcodec, AV_SYNC_THRESH);
	codec_set_cntl_syncthresh(&ctx.vcodec, ctx.vcodec.has_audio);

  {
    int frame_count, total = 0;
    int64_t bgn_us, end_us;

    ctx.am_pkt.codec = &ctx.vcodec;

    pre_header_feeding(&ctx, &ctx.am_pkt);

    ctx.demuxer->Read(ctx.am_pkt.avpkt);
    printf("byte_count(%d), dts(%llu), pts(%llu)\n",
      ctx.am_pkt.avpkt->size, ctx.am_pkt.avpkt->dts, ctx.am_pkt.avpkt->pts);
    if (!ctx.am_pkt.avpkt->size) {
      fprintf(stderr, "ERROR: Zero bytes read from input\n");
      //goto fail;
    }
    ctx.am_pkt.type = CODEC_VIDEO;
    ctx.am_pkt.data = ctx.am_pkt.avpkt->data;
    ctx.am_pkt.data_size = ctx.am_pkt.avpkt->size;
    ctx.am_pkt.avpkt_newflag = 1;
    ctx.am_pkt.avpkt_isvalid = 1;

    frame_count = 0;
    bool done = false;
    struct buf_status vbuf;
    struct vdec_status vdec;
    float  vlevel;
    while (!g_signal_abort && !done && (frame_count < 5000)) {
      h264_update_frame_header(&ctx.am_pkt);
      
      bgn_us = CurrentHostCounter() * 1000 / CurrentHostFrequency();

      log_print("avpts(%lld), avdts(%lld)\n",
        ctx.am_pkt.avpkt->pts, ctx.am_pkt.avpkt->dts);

      ret = write_av_packet(&ctx, &ctx.am_pkt);

      end_us = CurrentHostCounter() * 1000 / CurrentHostFrequency();

      frame_count++;
      //fprintf(stdout, "decode time(%llu) us\n", end_us-bgn_us);
      check_vcodec_state(&ctx.vcodec, &vdec, &vbuf);
      vlevel = 100.0 * (float)vbuf.data_len / vbuf.size;
      //log_print("buffering_states,vlevel=%d,vsize=%d,level=%f\n", vbuf.data_len, vbuf.size, vlevel);
      usleep(vlevel * 5000);

      ctx.demuxer->Read(ctx.am_pkt.avpkt);
      ctx.am_pkt.type = CODEC_VIDEO;
      ctx.am_pkt.data = ctx.am_pkt.avpkt->data;
      ctx.am_pkt.data_size = ctx.am_pkt.avpkt->size;
      ctx.am_pkt.avpkt_newflag = 1;
      ctx.am_pkt.avpkt_isvalid = 1;

      if (!ctx.am_pkt.data_size) done = true;
      total += ctx.am_pkt.data_size;
    }
  }

fail:
	codec_close_cntl(&ctx.vcodec);
	codec_close(&ctx.vcodec);

  return 0;
}
Exemplo n.º 22
0
void aml_cleanup() {
  codec_close(&codecParam);
}