int osd_show_progress_bar(u32 percent) { static u32 progress; u32 step = 1; /* wait_queue_head_t wait_head; */ struct osd_fb_dev_s *fb_dev; struct ge2d_context_s *context = progress_bar.ge2d_context; struct src_dst_info_s *op_info = &progress_bar.op_info; if (NULL == context) { /* osd_init_progress_bar(); */ pr_debug("context is NULL\n"); return -1; } fb_dev = gp_fbdev_list[1]; if (NULL == fb_dev) { pr_debug("fb1 should exit!!!"); return -EFAULT; } while (progress < percent) { pr_debug("progress is %d, x: [%d], y: [%d], w: [%d], h: [%d]\n", progress, op_info->dst_rect.x, op_info->dst_rect.y, op_info->dst_rect.w, op_info->dst_rect.h); fillrect(context, op_info->dst_rect.x, op_info->dst_rect.y, op_info->dst_rect.w, op_info->dst_rect.h, op_info->color); /* wait_event_interruptible_timeout(wait_head,0,4); */ progress += step; op_info->dst_rect.x += op_info->dst_rect.w; op_info->color -= (0xff*step/100) << 16; } if (100 == percent) { progress = 0; osd_blank(1, fb_dev->fb_info); destroy_ge2d_work_queue(progress_bar.ge2d_context); } return 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; }
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; }
int osd_init_progress_bar(void) { struct src_dst_info_s *op_info = &progress_bar.op_info; const struct vinfo_s *vinfo = progress_bar.vinfo; struct osd_fb_dev_s *fb_dev; struct canvas_s cs; struct config_para_s *cfg = &ge2d_config; struct ge2d_context_s *context = ge2d_context; u32 step = 1; memset(&progress_bar, 0, sizeof(struct osd_progress_bar_s)); vinfo = get_current_vinfo(); progress_bar.bar_border = (((vinfo->field_height ? vinfo->field_height : vinfo->height) * 4 / 720)>>2)<<2; progress_bar.bar_width = (((vinfo->width * 200 / 1280)>>2)<<2) + progress_bar.bar_border; progress_bar.bar_height = (((vinfo->field_height ? vinfo->field_height : vinfo->height) * 32 / 720) >> 2) << 2; if (0 == init_fb1_first(vinfo)) { fb_dev = gp_fbdev_list[1]; if (NULL == fb_dev) { pr_debug("fb1 should exit!!!"); return -EFAULT; } canvas_read(OSD2_CANVAS_INDEX, &cs); context = create_ge2d_work_queue(); if (!context) { pr_debug("create work queue error\n"); return -EFAULT; } memset(cfg, 0, sizeof(struct config_para_s)); cfg->src_dst_type = OSD1_OSD1; cfg->src_format = GE2D_FORMAT_S32_ARGB; cfg->src_planes[0].addr = cs.addr; cfg->src_planes[0].w = cs.width / 4; cfg->src_planes[0].h = cs.height; cfg->dst_planes[0].addr = cs.addr; cfg->dst_planes[0].w = cs.width / 4; cfg->dst_planes[0].h = cs.height; if (ge2d_context_config(context, cfg) < 0) { pr_debug("ge2d config error.\n"); return -EFAULT; } if (NULL == context) { pr_debug("ge2d_context is NULL!!!!!!\n"); return -EFAULT; } progress_bar.ge2d_context = context; pr_debug("progress bar setup ge2d device OK\n"); /* clear dst rect */ op_info->color = 0x000000bf; op_info->dst_rect.x = 0; op_info->dst_rect.y = 0; op_info->dst_rect.w = vinfo->width; op_info->dst_rect.h = vinfo->field_height ? vinfo->field_height : vinfo->height; fillrect(context, op_info->dst_rect.x, op_info->dst_rect.y, op_info->dst_rect.w, op_info->dst_rect.h, op_info->color); pr_debug("clear dstrect is - (%d, %d)-(%d, %d) -\n", op_info->dst_rect.x, op_info->dst_rect.y, op_info->dst_rect.w, op_info->dst_rect.h); /* show fb1 */ console_lock(); osd_blank(0, fb_dev->fb_info); console_unlock(); op_info->color = 0x555555ff; op_info->dst_rect.x = (vinfo->width / 2) - progress_bar.bar_width; op_info->dst_rect.y = ((vinfo->field_height ? vinfo->field_height : vinfo->height) * 9) / 10; op_info->dst_rect.w = progress_bar.bar_width * 2; op_info->dst_rect.h = progress_bar.bar_height; pr_debug("fill==dst:%d-%d-%d-%d\n", op_info->dst_rect.x, op_info->dst_rect.y, op_info->dst_rect.w, op_info->dst_rect.h); fillrect(context, op_info->dst_rect.x, op_info->dst_rect.y, op_info->dst_rect.w, op_info->dst_rect.h, op_info->color); } else { pr_debug("fb1 init failed, exit!!!"); return -EFAULT; } /* initial op info before draw actrualy */ op_info->dst_rect.x += progress_bar.bar_border; op_info->dst_rect.y += progress_bar.bar_border; op_info->dst_rect.w = (progress_bar.bar_width - progress_bar.bar_border) * 2 * step/100; op_info->dst_rect.h = progress_bar.bar_height - progress_bar.bar_border * 2; op_info->color = 0xffffff; return 0; }
bool CWinSystemGLES::Show(bool raise) { osd_blank("/sys/class/graphics/fb0/blank", 0); return true; }
bool CWinSystemGLES::Hide() { osd_blank("/sys/class/graphics/fb0/blank", 1); return true; }
int osd_notify_callback(struct notifier_block *block, unsigned long cmd , void *para) { const vinfo_t *vinfo; myfb_dev_t *fb_dev; int i,blank; disp_rect_t *disp_rect; vinfo = get_current_vinfo(); amlog_mask_level(LOG_MASK_PARA,LOG_LEVEL_LOW,"tv_server:vmode=%s\r\n", vinfo->name); switch(cmd) { case VOUT_EVENT_MODE_CHANGE: amlog_mask_level(LOG_MASK_PARA,LOG_LEVEL_LOW,"recevie change mode message \r\n"); for(i=0;i<OSD_COUNT;i++) { if(NULL==(fb_dev=gp_fbdev_list[i])) continue; set_default_display_axis(&fb_dev->fb_info->var,&fb_dev->osd_ctl,vinfo); console_lock(); osddev_update_disp_axis(fb_dev,1); console_unlock(); } break; case VOUT_EVENT_OSD_BLANK: blank=*(int*)para ; for(i=0;i<OSD_COUNT;i++) { if(NULL==(fb_dev=gp_fbdev_list[i])) continue; console_lock(); osd_blank(blank,fb_dev->fb_info); console_unlock(); } break; case VOUT_EVENT_OSD_DISP_AXIS: disp_rect=(disp_rect_t*)para; for(i=0;i<OSD_COUNT;i++) { if(!disp_rect) break; fb_dev=gp_fbdev_list[i]; if(fb_dev->preblend_enable) break; //if osd layer preblend ,it's position is controled by vpp. fb_dev->osd_ctl.disp_start_x=disp_rect->x ; fb_dev->osd_ctl.disp_start_y=disp_rect->y ; amlog_mask_level(LOG_MASK_PARA,LOG_LEVEL_LOW,"set disp axis: x:%d y:%d w:%d h:%d\r\n" , \ disp_rect->x, disp_rect->y,\ disp_rect->w, disp_rect->h ); if(disp_rect->x+disp_rect->w > vinfo->width) { fb_dev->osd_ctl.disp_end_x=vinfo->width - 1; } else { fb_dev->osd_ctl.disp_end_x=fb_dev->osd_ctl.disp_start_x+disp_rect->w -1 ; } if(disp_rect->y+ disp_rect->h>vinfo->height) { fb_dev->osd_ctl.disp_end_y=vinfo->height- 1; } else { fb_dev->osd_ctl.disp_end_y=fb_dev->osd_ctl.disp_start_y + disp_rect->h - 1 ; } disp_rect ++; amlog_mask_level(LOG_MASK_PARA,LOG_LEVEL_LOW,"new disp axis: startx:%d starty:%d endx:%d endy:%d\r\n" , \ fb_dev->osd_ctl.disp_start_x, fb_dev->osd_ctl.disp_start_y,\ fb_dev->osd_ctl.disp_end_x,fb_dev->osd_ctl.disp_end_y); console_lock(); osddev_update_disp_axis(fb_dev,0); console_unlock(); } break; } return 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; }