Example #1
0
void ES_PlayGetESBufferStatus ( int *audio_rate,int *vid_rate )
{
	
	int ret;
	struct buf_status vbuf;
	
	if( vpcodec == NULL)
	{
		*vid_rate=0;
	}
	else
	{
		ret = codec_get_vbuf_state( vpcodec, &vbuf);

		*vid_rate = ( vbuf.data_len * 100 )/vbuf.size ;
	}
	
	
	if( apcodec == NULL )
	{
		*audio_rate=0;
	}
	else
	{
		ret = codec_get_abuf_state( apcodec, &vbuf);

		*audio_rate = ( vbuf.data_len * 100 )/vbuf.size ;
	}
	
	
}
Example #2
0
static gboolean gst_amlvdec_polling_eos (GstAmlVdec *amlvdec)
{
    unsigned rp_move_count = 40,count=0;
    struct buf_status vbuf;
    unsigned last_rp = 0;
    gint ret = 1;	
    do {
	  if(count>2000)//avoid infinite loop
	      break;	
        ret = codec_get_vbuf_state(amlvdec->pcodec, &vbuf);
        if (ret != 0) {
            GST_ERROR("codec_get_vbuf_state error: %x\n", -ret);
            break;
        }
        if(last_rp != vbuf.read_pointer){
            last_rp = vbuf.read_pointer;
            rp_move_count = 200;
        }else
            rp_move_count--;        
        usleep(1000*30);
        count++;	

       /* if(amlvdec->passthrough) {
          break;
        }*/
    } while (vbuf.data_len > 0x100 && rp_move_count > 0);

    return TRUE;
}
Example #3
0
static void gst_amlvdec_polling_eos (GstAmlVdec *amlvdec)
{
    unsigned rp_move_count = 40,count=0;
    struct buf_status vbuf;
    unsigned last_rp = 0;
    int ret=1;	
    do {
	  if(count>2000)//avoid infinite loop
	      break;	
        ret = codec_get_vbuf_state(amlvdec->pcodec, &vbuf);
        if (ret != 0) {
            GST_ERROR("codec_get_vbuf_state error: %x\n", -ret);
            break;
        }
        if(last_rp != vbuf.read_pointer){
            last_rp = vbuf.read_pointer;
            rp_move_count = 200;
        }else
            rp_move_count--;        
        usleep(1000*30);
        count++;	

     /*   if(amlvdec->passthrough) {
          break;
        }*/
    } while (vbuf.data_len > 0x100 && rp_move_count > 0);
   // amlvdec->passthrough = FALSE;
    //gst_pad_push_event (amlvdec->srcpad, gst_event_new_eos ());
    gst_task_pause (amlvdec->eos_task);

}
static int check_vcodec_state(codec_para_t *codec, struct vdec_status *dec, struct buf_status *buf)
{
    int ret;

    ret = codec_get_vbuf_state(codec,  buf);
    if (ret != 0) {
        log_error("codec_get_vbuf_state error: %x\n", -ret);
    }

    ret = codec_get_vdec_state(codec, dec);
    if (ret != 0) {
        log_error("codec_get_vdec_state error: %x\n", -ret);
        ret = PLAYER_CHECK_CODEC_ERROR;
    }

    return ret;
}
Example #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: 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;
}
Example #6
0
static GstFlowReturn
gst_aml_vdec_decode (GstAmlVdec *amlvdec, GstBuffer * buf)
{
	GstFlowReturn ret = GST_FLOW_OK;
	guint8 *data;
	guint size;
	gint written;
	GstClockTime timestamp, pts;

	struct buf_status vbuf;
	GstMapInfo map;

	if (!amlvdec->info) {
		return GST_FLOW_OK;
	}
	if (amlvdec->pcodec && amlvdec->codec_init_ok) {
		while (codec_get_vbuf_state(amlvdec->pcodec, &vbuf) == 0) {
			if (vbuf.data_len * 10 < vbuf.size * 7) {
				break;
			}
			if (amlvdec->is_paused) {
				break;
			}
			usleep(20000);
		}
		timestamp = GST_BUFFER_TIMESTAMP (buf);
		pts = timestamp * 9LL / 100000LL + 1L;

		if (timestamp != GST_CLOCK_TIME_NONE) {
			GST_INFO_OBJECT(amlvdec, " video pts = %x", (unsigned long) pts);
			if (codec_checkin_pts(amlvdec->pcodec, (unsigned long) pts) != 0)
				GST_ERROR_OBJECT(amlvdec, "pts checkin flied maybe lose sync");

		}

		if (!amlvdec->is_headerfeed) {
			if (amlvdec->info->writeheader) {
				amlvdec->info->writeheader(amlvdec->info, amlvdec->pcodec);
			}
			amlvdec->is_headerfeed = TRUE;
		}
		if (amlvdec->info->add_startcode) {
			amlvdec->info->add_startcode(amlvdec->info, amlvdec->pcodec, buf);
		}
		gst_buffer_map(buf, &map, GST_MAP_READ);
		data = map.data;
		size = map.size;
		while (size > 0) {
			written = codec_write(amlvdec->pcodec, data, size);
			if (written >= 0) {
				size -= written;
				data += written;
			} else if (errno == EAGAIN || errno == EINTR) {
				GST_WARNING_OBJECT(amlvdec, "codec_write busy");
				if (amlvdec->is_paused) {
					break;
				}
				usleep(20000);
			} else {
				GST_ERROR_OBJECT(amlvdec, "codec_write failed");
				ret = GST_FLOW_ERROR;
				break;
			}
		}
		gst_buffer_unmap(buf, &map);
	}
	return ret;
}
Example #7
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;
}