Exemple #1
0
static gboolean
gst_set_vstream_info(GstAmlVdec *amlvdec, GstCaps * caps)
{
	GstStructure *structure;
	const char *name;
	gint32 ret = CODEC_ERROR_NONE;
	AmlStreamInfo *videoinfo = NULL;
	int coordinate[4] = {0, 0, 0, 0};
	structure = gst_caps_get_structure(caps, 0);
	name = gst_structure_get_name(structure);

	videoinfo = amlVstreamInfoInterface(name);
	if (NULL == name) {
		return FALSE;
	}
	amlvdec->info = videoinfo;
	videoinfo->init(videoinfo, amlvdec->pcodec, structure);
	if (amlvdec->pcodec && amlvdec->pcodec->stream_type == STREAM_TYPE_ES_VIDEO) {
		if (!amlvdec->codec_init_ok) {
			ret = codec_init(amlvdec->pcodec);
			if (ret != CODEC_ERROR_NONE) {
				GST_ERROR("codec init failed, ret=-0x%x", -ret);
				return FALSE;
			}
			set_fb0_blank(1);
			set_fb1_blank(1);
			set_tsync_enable(1);
			set_display_axis(coordinate);
			//set_video_axis(coordinate);
			amlvdec->codec_init_ok = 1;
			if (amlvdec->trickRate > 0) {
				if (amlvdec->pcodec && amlvdec->pcodec->cntl_handle) {
//T					codec_set_video_playrate(amlvdec->pcodec, (int) (amlvdec->trickRate * (1 << 16)));
				}
			}
			GST_DEBUG_OBJECT(amlvdec, "video codec_init ok");
		}

	}
	return TRUE;
}
Exemple #2
0
int tvplay_adapter_play(IN U16 vpid,IN U8 vstype,IN U16 apid,IN U8 astype)
{
    LOGI("tvplay_adapter_play(vpid=%d,stype=%d,apid=%d,stype=%d).\n",vpid,vstype,apid,astype);

#if DUMP_TSPACKET0
    gfStream = fopen("/data/test_0.ts","wb");
#endif
#if 0
    if(player != NULL)
    {
        player_sign = 0;
        LOGI("erooraaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
        player->Stop();
        player->VideoHide();
        delete player;
        player = NULL;
    }
#endif
    int videopid = vpid;
    int audiopid = apid;
    int videotype = vstype;
    int audiotype= astype;
    pthread_t  playerthread;
    if(player == NULL)
    {
        player=new CTsPlayer();
        player->SetColorKey(1,0);

    }
    set_tsync_enable(1);
//	player->VideoShow();
    VIDEO_PARA_T VideoPara;
    AUDIO_PARA_T AudioPara;
    memset(&AudioPara,0,sizeof(AudioPara));

    VideoPara.pid = vpid;
    AudioPara.pid = apid;
    switch(vstype)
    {
    case 1:
    case 2:
        VideoPara.vFmt=VFORMAT_MPEG12;
        break;
    case 16:
        VideoPara.vFmt=VFORMAT_MPEG4;
        break;
    case 27:
        VideoPara.vFmt=VFORMAT_H264;
        break;
    case 234:
        VideoPara.vFmt=VFORMAT_VC1;
        break;
    default:
        VideoPara.vFmt=VFORMAT_MPEG12;
        break;

    }

    switch(astype)
    {
    case 3:
    case 4:
        AudioPara.aFmt=AFORMAT_MPEG;
        break;
    case 15:
        AudioPara.aFmt=AFORMAT_AAC;
        break;
    case 0x7B:
    case 0x8A:
        AudioPara.aFmt=AFORMAT_DTS;
        break;
    case 0x81:
    case 0x6a:
    case 0x7A:
    case 6:
        AudioPara.aFmt=AFORMAT_AC3;
        break;

    default:
        AudioPara.aFmt=AFORMAT_MPEG;
        break;

    }

    //LOGI("videopid=%d,vfat=%d,audiopid=%d,afat=%d",videopid,VideoPara.vFmt,audiopid,AudioPara.aFmt);
    player->InitVideo(&VideoPara);
    player->InitAudio(&AudioPara);

#if 1
    player_sign = 1;
    if(pthread_create(&playerthread, NULL, player_thread, NULL) != 0) {
        LOGE("pthread_create error!");
    }
#endif
    //loop_buffer->ClrBuffer();
    if(!player->StartPlay()) {
        LOGI("Player start failed\n");
        player_sign = 0;
        delete player;
        player = NULL;
        return -1;
    }
    LOGI("AudioPara.aFmt=%d,VideoPara.vFmt=%d",AudioPara.aFmt,VideoPara.vFmt);



    LOGE("after player->StartPlay !");
    //player->SetVideoWindow(0,0,1920,1080);
    //player->SetScreenMode(3);
    //osd_blank("/sys/class/graphics/fb0/blank",1);
    //osd_blank("/sys/class/graphics/fb1/blank",1);
    //set_tsync_enable(1);

    LOGE("before pthread_create !");

    return 0;
}
Exemple #3
0
static int player_mate_thread_cmd_proxy(play_para_t *player, struct player_mate *mate)
{
    player_cmd_t *cmd = NULL;
    int ret;
    play_para_t *p_para=player;
    /*
    check the cmd & do for main thread;
    */
      if (p_para->oldcmd.ctrl_cmd == CMD_SEARCH &&
        nextcmd_is_cmd(p_para, CMD_SEARCH) &&
        ((p_para->oldcmdtime >= player_get_systemtime_ms() - 400)) && /*lastcmd is not too old.*/
        ((p_para->stream_type == STREAM_ES && p_para->vcodec != NULL) || /*ES*/
         (p_para->stream_type != STREAM_ES  && p_para->codec && p_para->vstream_info.has_video))) { /*PS,RM,TS*/
        /*if latest cmd and next cmd are all search,we must wait the frame show.*/
        if (p_para->vcodec) {
            ret = codec_get_cntl_state(p_para->vcodec);    /*es*/
        } else {
            ret = codec_get_cntl_state(p_para->codec);    /*not es*/
        }
        if(p_para->avsynctmpchanged == 0) {
            p_para->oldavsyncstate = get_tsync_enable();
        }
        if (p_para->oldavsyncstate == 1) {
            set_tsync_enable(0);
            p_para->avsynctmpchanged = 1;
        }
        if (ret <= 0) {
            return NONO_FLAG;
        }
    }	
    cmd = get_message(player);
    if (!cmd) {
        return 0;    /*no cmds*/
    }

    p_para->oldcmd = *cmd;
    p_para->oldcmdtime = player_get_systemtime_ms();
    log_print("pid[%d]:: [check_flag:%d]cmd=%x set_mode=%x info=%x param=%d fparam=%f\n", p_para->player_id, __LINE__, cmd->ctrl_cmd, cmd->set_mode, cmd->info_cmd, cmd->param, cmd->f_param);
    if (cmd->ctrl_cmd != CMD_SEARCH && p_para->avsynctmpchanged > 0) {
		/*not search now,resore the sync states...*/
		set_tsync_enable(p_para->oldavsyncstate);
		p_para->avsynctmpchanged = 0;
    }	
    check_msg(player,cmd);
    message_free(cmd);
    if(player->playctrl_info.search_flag && !(p_para->pFormatCtx->iformat->flags & AVFMT_NOFILE) && p_para->pFormatCtx->pb!=NULL && p_para->pFormatCtx->pb->local_playback == 0){
        /*in mate thread seek,and interrupt the read thread.
              so we need to ignore the first ffmpeg erros. */
        player->playctrl_info.ignore_ffmpeg_errors=1;	
        player->playctrl_info.temp_interrupt_ffmpeg=1;
        log_print("ffmpeg_interrupt tmped by player mate!\n");
        ffmpeg_interrupt_light(player->thread_mgt.pthread_id);
        codec_resume(player->codec);  /*auto resume on*/
    }
    if (p_para->playctrl_info.search_flag) {
        set_black_policy(0);
    }
    if (p_para->playctrl_info.end_flag) {
        log_print("player_mate: end_flag! \n");
        update_playing_info(p_para);
        update_player_states(p_para, 1);
        return 0;
    }
    if (p_para->playctrl_info.pause_flag) {
        if (get_player_state(p_para) != PLAYER_PAUSE) {
            ret = codec_pause(p_para->codec);
            if (ret != 0) {
                log_error("[%s:%d]pause failed!ret=%d\n", __FUNCTION__, __LINE__, ret);
            }
            set_player_state(p_para, PLAYER_PAUSE);
            update_playing_info(p_para);
            update_player_states(p_para, 1);
        }
        return CONTINUE_FLAG;
    } else {
        if ((get_player_state(p_para) == PLAYER_PAUSE) || (get_player_state(p_para) == PLAYER_SEARCHOK)) {
            ret = codec_resume(p_para->codec);
            if (ret != 0) {
                log_error("[%s:%d]resume failed!ret=%d\n", __FUNCTION__, __LINE__, ret);
            }
            set_player_state(p_para, PLAYER_RUNNING);
            update_playing_info(p_para);
            update_player_states(p_para, 1);
        }
    }
    return 0;
}
Exemple #4
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;
}
Exemple #5
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: psplay <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);

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

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