void osd_show_newchannel(struct osd_t* osd, int channel) { char str[128]; if ((osd->osd_state != OSD_NONE) && (osd->osd_state != OSD_NEWCHANNEL)) { osd_clear(osd); } osd->osd_state = OSD_NEWCHANNEL; snprintf(str,sizeof(str),"%d",channel); if (channel < 1000) { str[4] = 0; str[3] = '-'; if (channel < 100) { str[2] = '-'; if (channel < 10) { str[1] = '-'; } } } fprintf(stderr,"New channel = %s\n",str); pthread_mutex_lock(&osd->osd_mutex); osd_show_channelname(osd,str); graphics_update_displayed_resource(osd->img, 0, 0, 0, 0); pthread_mutex_unlock(&osd->osd_mutex); }
void osd_alert(struct osd_t* osd, char* text) { uint32_t text_length; uint32_t width,height; uint32_t y_offset; uint32_t x_offset; uint32_t text_size = 40; pthread_mutex_lock(&osd->osd_mutex); /* TODO: Only clear alert area */ graphics_resource_fill(osd->img, 0, 0, osd->display_width, osd->display_height, GRAPHICS_RGBA32(0,0,0,0)); if (text) { fprintf(stderr,"[OSD ALERT]: %s\n",text); text_length = strlen(text); graphics_resource_text_dimensions_ext(osd->img, text, text_length, &width, &height, text_size); x_offset = ((1920 - width) / 2); y_offset = (1080 - height) / 2; osd_draw_window(osd,x_offset,y_offset,width+100,height+50); graphics_resource_render_text_ext(osd->img, x_offset+50, y_offset+25, width, height, GRAPHICS_RGBA32(0xff,0xff,0xff,0xff), /* fg */ GRAPHICS_RGBA32(0,0,0,0x80), /* bg */ text, text_length, text_size); } graphics_update_displayed_resource(osd->img, 0, 0, 0, 0); pthread_mutex_unlock(&osd->osd_mutex); }
void osd_clear_newchannel(struct osd_t* osd) { /* TODO: Only clear channel area */ pthread_mutex_lock(&osd->osd_mutex); graphics_resource_fill(osd->img, 0, 0, osd->display_width, osd->display_height, GRAPHICS_RGBA32(0,0,0,0)); graphics_update_displayed_resource(osd->img, 0, 0, 0, 0); pthread_mutex_unlock(&osd->osd_mutex); fprintf(stderr,"Clearing OSD...\n"); }
void osd_clear(struct osd_t* osd) { pthread_mutex_lock(&osd->osd_mutex); graphics_resource_fill(osd->img, 0, 0, osd->display_width, osd->display_height, GRAPHICS_RGBA32(0,0,0,0)); graphics_update_displayed_resource(osd->img, 0, 0, 0, 0); pthread_mutex_unlock(&osd->osd_mutex); fprintf(stderr,"Clearing OSD...\n"); osd->osd_state = OSD_NONE; osd->osd_cleartime = 0; }
/* * Periodic updates of OSD */ void osd_update(struct osd_t* osd, int channel_id) { int osd_update = 0; uint32_t event; int server; time_t now; if ((osd->osd_cleartime) && (get_time() > osd->osd_cleartime)) { osd_clear(osd); return; } now = time(NULL); if (now < osd->last_now + 1) { // Update every second return; } osd->last_now = now; switch (osd->osd_state) { case OSD_INFO: channels_geteventid(channel_id, &event, &server); now = time(NULL); if (now >= osd->last_now + 1) { osd_show_time(osd); osd_update = 1; } if (osd->event != event) { osd_show_info(osd, channel_id, 0); osd_update = 1; } break; case OSD_CHANNELLIST: channels_geteventid(osd->model_channellist.channel[osd->model_channellist_current.selectedIndex].id, &event, &server); if (osd->model_now_next_current.event[0] != event) { osd_channellist_event_init(osd, osd->model_channellist.channel[osd->model_channellist_current.selectedIndex].id); osd_view(osd, OSD_CHANNELLIST); // make the new model the current osd_model_channellist_copy(&osd->model_channellist_current, &osd->model_channellist); osd_model_nownext_copy(&osd->model_now_next_current, &osd->model_now_next); } break; case OSD_MENU: snprintf(osd->model_menu.bitrate, sizeof(osd->model_menu.bitrate), "Bitrate = %.3fMbps", vcodec_bitrate / 1000000); osd_view(osd, OSD_MENU); break; } if (osd_update) { graphics_update_displayed_resource(osd->img, 0, 0, 0, 0); } }
/* * view dispatcher */ void osd_view(struct osd_t* osd, int view) { pthread_mutex_lock(&osd->osd_mutex); switch (view) { case OSD_CHANNELLIST: osd_channellist_view(osd); break; case OSD_MENU: osd_menu_view(osd); break; } osd->osd_state = view; graphics_update_displayed_resource(osd->img, 0, 0, 0, 0); pthread_mutex_unlock(&osd->osd_mutex); }
int main(void) { GRAPHICS_RESOURCE_HANDLE img; uint32_t width, height; int LAYER=1; bcm_host_init(); int s; s = gx_graphics_init("."); assert(s == 0); s = graphics_get_display_size(0, &width, &height); assert(s == 0); s = gx_create_window(0, width, height, GRAPHICS_RESOURCE_RGBA32, &img); assert(s == 0); // transparent before display to avoid screen flash graphics_resource_fill(img, 0, 0, width, height, GRAPHICS_RGBA32(0,0,0,0x00)); graphics_display_resource(img, 0, LAYER, 0, 0, GRAPHICS_RESOURCE_WIDTH, GRAPHICS_RESOURCE_HEIGHT, VC_DISPMAN_ROT0, 1); uint32_t text_size = 10; while (1) { const char *text = "The quick brown fox jumps over the lazy dog"; uint32_t y_offset = height-60+text_size/2; graphics_resource_fill(img, 0, 0, width, height, GRAPHICS_RGBA32(0,0,0,0x00)); // blue, at the top (y=40) graphics_resource_fill(img, 0, 40, width, 1, GRAPHICS_RGBA32(0,0,0xff,0xff)); // green, at the bottom (y=height-40) graphics_resource_fill(img, 0, height-40, width, 1, GRAPHICS_RGBA32(0,0xff,0,0xff)); // draw the subtitle text render_subtitle(img, text, 0, text_size, y_offset); graphics_update_displayed_resource(img, 0, 0, 0, 0); text_size += 1; if (text_size > 50) text_size = 10; } graphics_display_resource(img, 0, LAYER, 0, 0, GRAPHICS_RESOURCE_WIDTH, GRAPHICS_RESOURCE_HEIGHT, VC_DISPMAN_ROT0, 0); graphics_delete_resource(img); return 0; }
void osd_show_info(struct osd_t* osd, int channel_id, int timeout) { char str[128]; int server; channels_geteventid(channel_id,&osd->event,&server); channels_getnexteventid(channel_id,&osd->nextEvent,&server); struct event_t* event = event_copy(osd->event,server); struct event_t* nextEvent = event_copy(osd->nextEvent,server); fprintf(stderr,"***OSD: event=%d\n",(event ? event->eventId : -1)); event_dump(event); fprintf(stderr,"***OSD: nextEvent=%d\n",(nextEvent ? nextEvent->eventId : -1)); event_dump(nextEvent); fprintf(stderr,"******\n"); snprintf(str,sizeof(str),"%03d - %s",channels_getlcn(channel_id),channels_getname(channel_id)); char* iso_text = malloc(strlen(str)+1); utf8decode(str,iso_text); pthread_mutex_lock(&osd->osd_mutex); osd_show_channelname(osd,iso_text); osd_show_time(osd); osd_show_eventinfo(osd,event,nextEvent); graphics_update_displayed_resource(osd->img, 0, 0, 0, 0); pthread_mutex_unlock(&osd->osd_mutex); free(iso_text); osd->osd_state = OSD_INFO; if (timeout) { osd->osd_cleartime = get_time() + timeout; } event_free(event); event_free(nextEvent); }