From 40a1a9a046a90db4d9d5a99ea7ba0427bbf277bf Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sat, 13 Oct 2012 11:57:14 +0200 Subject: [PATCH] Add automatic video mode change at startup, remove background layer, restore console fb after exit --- osdopenvg.cc | 16 ++--- osdopenvg.h | 4 +- videoomx.cc | 164 +++++++++++++++++++++++++++++---------------------- videoomx.h | 2 +- 4 files changed, 106 insertions(+), 80 deletions(-) diff --git a/osdopenvg.cc b/osdopenvg.cc index 4d8c419..0f892fa 100644 --- a/osdopenvg.cc +++ b/osdopenvg.cc @@ -153,13 +153,13 @@ int OsdOpenVG::init(void* device) Log::getInstance()->log("OSD", Log::NOTICE, "Displaysize is %d x %d ",display_width, display_height); VC_RECT_T dst_rect ={0,0,display_width,display_height}; VC_RECT_T src_rect={0,0,BACKBUFFER_WIDTH <<16,BACKBUFFER_HEIGHT<<16}; - VC_RECT_T src_rect_bg={0,0,1<<16,1<<16}; - VC_RECT_T src_rect_im={0,0,1,1}; + // VC_RECT_T src_rect_bg={0,0,1<<16,1<<16}; + // VC_RECT_T src_rect_im={0,0,1,1}; - uint32_t back_image_ptr; + /* uint32_t back_image_ptr; bcm_backres=vc_dispmanx_resource_create(VC_IMAGE_RGB888,1,1,&back_image_ptr); unsigned int color=0x00FF0000; - vc_dispmanx_resource_write_data(bcm_backres,VC_IMAGE_RGB888,4,&color,&src_rect_im); + vc_dispmanx_resource_write_data(bcm_backres,VC_IMAGE_RGB888,4,&color,&src_rect_im);*/ DISPMANX_UPDATE_HANDLE_T bcm_update; bcm_display=vc_dispmanx_display_open(0); @@ -169,9 +169,9 @@ int OsdOpenVG::init(void* device) &src_rect,DISPMANX_PROTECTION_NONE,0, 0, (DISPMANX_TRANSFORM_T) 0); - bcm_background=vc_dispmanx_element_add(bcm_update,bcm_display, + /* bcm_background=vc_dispmanx_element_add(bcm_update,bcm_display, 0,&dst_rect,bcm_backres , - &src_rect_bg,DISPMANX_PROTECTION_NONE,0, 0, (DISPMANX_TRANSFORM_T) 0); + &src_rect_bg,DISPMANX_PROTECTION_NONE,0, 0, (DISPMANX_TRANSFORM_T) 0);*/ vc_dispmanx_update_submit_sync(bcm_update); @@ -326,9 +326,9 @@ int OsdOpenVG::shutdown() bcm_update=vc_dispmanx_update_start(0); vc_dispmanx_element_remove(bcm_update,bcm_element); - vc_dispmanx_element_remove(bcm_update,bcm_background); +// vc_dispmanx_element_remove(bcm_update,bcm_background); vc_dispmanx_update_submit_sync(bcm_update); - vc_dispmanx_resource_delete(bcm_backres); +// vc_dispmanx_resource_delete(bcm_backres); vc_dispmanx_display_close(bcm_display); diff --git a/osdopenvg.h b/osdopenvg.h index 29bcfe5..57d7f08 100644 --- a/osdopenvg.h +++ b/osdopenvg.h @@ -139,8 +139,8 @@ protected: uint32_t display_width; DISPMANX_DISPLAY_HANDLE_T bcm_display; DISPMANX_ELEMENT_HANDLE_T bcm_element; - DISPMANX_ELEMENT_HANDLE_T bcm_background; - DISPMANX_RESOURCE_HANDLE_T bcm_backres; +// DISPMANX_ELEMENT_HANDLE_T bcm_background; +// DISPMANX_RESOURCE_HANDLE_T bcm_backres; uint32_t mode; diff --git a/videoomx.cc b/videoomx.cc index 39527ac..b737bf3 100644 --- a/videoomx.cc +++ b/videoomx.cc @@ -26,6 +26,7 @@ #include "woptionpane.h" #include "osdopenvg.h" +#include // temp #include "log.h" @@ -75,6 +76,7 @@ int VideoOMX::init(UCHAR tformat) if (!attachFrameBuffer()) { shutdown(); return 0; } setTVsize(ASPECT4X3); + selectVideoMode(0); @@ -165,10 +167,33 @@ int VideoOMX::shutdown() { if (!initted) return 0; initted = 0; + Log::getInstance()->log("Video", Log::NOTICE, "Shutdown video module"); DeAllocateCodecsOMX(); OMX_Deinit(); - vc_tv_show_info(0); // back to console + //vc_tv_show_info(0); // back to console + // Restore console + int fd_fbset=0; + struct fb_var_screeninfo screeninfo; + fd_fbset=open("/dev/fb0",O_RDONLY); + if (fd_fbset<0) { + Log::getInstance()->log("Video", Log::CRIT, "Could not open frame buffer device %d", fd_fbset); + return 0; + } + if (ioctl(fd_fbset, FBIOGET_VSCREENINFO, &screeninfo)){ + close(fd_fbset); + Log::getInstance()->log("Video", Log::CRIT, "Could not FBIOGET_VSCREENINFO frame buffer device"); + return 0; + } + screeninfo.bits_per_pixel=8; + if (ioctl(fd_fbset, FBIOPUT_VSCREENINFO, &screeninfo)){ + Log::getInstance()->log("Video", Log::CRIT, "Could not FBIOPUT_VSCREENINFO frame buffer device"); + } + screeninfo.bits_per_pixel=16; + if (ioctl(fd_fbset, FBIOPUT_VSCREENINFO, &screeninfo)){ + Log::getInstance()->log("Video", Log::CRIT, "Could not FBIOPUT_VSCREENINFO frame buffer device"); + } + close(fd_fbset); return 1; } @@ -313,74 +338,75 @@ int VideoOMX::setFormat(UCHAR tformat) return 1; } -//void VideoOMX::selectVideoMode(int interlaced) -//{ -// if (/*hdmi*/ true) { -// TV_SUPPORTED_MODE_T all_supp_modes[TV_MAX_SUPPORTED_MODES]; -// HDMI_RES_GROUP_T pref_group; -// TV_SUPPORTED_MODE_T *mymode=NULL; -// TV_SUPPORTED_MODE_T *mymode_second_best=NULL; -// bool got_optimum=false; -// uint32_t pref_mode; -// int all_my_modes=vc_tv_hdmi_get_supported_modes(HDMI_RES_GROUP_CEA, -// all_supp_modes,TV_MAX_SUPPORTED_MODES, -// &pref_group,&pref_mode); -// int target_fps=50; -// if (format==PAL)target_fps=50; -// else if (format==NTSC) target_fps=60; -// if (all_my_modes<=0) { -// Log::getInstance()->log("Video", Log::NOTICE, "No CEA modes found abort"); -// return; -// } -// -// //Now first determine native resolution -// int native_width=1920; -// int native_height=1080; -// for (int i=0;ilog("Video", Log::NOTICE, "Found native mode %dx%d %d Hz i: %d", -// mymode->width,mymode->height,mymode->frame_rate,mymode->scan_mode); -// } -// -// } -// //Now find the mode which matches best -// for (int i=0;iwidth==native_width && -// curmode->height==native_height && -// curmode->frame_rate==target_fps) { -// if(curmode->scan_mode==interlaced) { -// got_optimum=true; -// mymode=curmode; -// Log::getInstance()->log("Video", Log::NOTICE, "Found optimum mode %dx%d %d Hz i: %d", -// mymode->width,mymode->height,mymode->frame_rate,mymode->scan_mode); -// } else { -// mymode_second_best=curmode; -// Log::getInstance()->log("Video", Log::NOTICE, "Found close to optimum mode %dx%d %d Hz i: %d", -// mymode_second_best->width,mymode_second_best->height, -// mymode_second_best->frame_rate,mymode_second_best->scan_mode); -// } -// -// } -// } -// if (mymode) { -// Log::getInstance()->log("Video", Log::NOTICE, "Switch to optimum mode"); -// vc_tv_hdmi_power_on_explicit(HDMI_MODE_HDMI,HDMI_RES_GROUP_CEA,mymode->code); -// } else if (mymode_second_best) { -// Log::getInstance()->log("Video", Log::NOTICE, "Switch to close to optimum mode"); -// vc_tv_hdmi_power_on_explicit(HDMI_MODE_HDMI,HDMI_RES_GROUP_CEA,mymode_second_best->code); -// } else { -// Log::getInstance()->log("Video", Log::NOTICE, "Switch to prefered mode"); -// vc_tv_hdmi_power_on_best(1920,1080,target_fps,interlaced?HDMI_INTERLACED:HDMI_NONINTERLACED, -// (EDID_MODE_MATCH_FLAG_T)(HDMI_MODE_MATCH_FRAMERATE|HDMI_MODE_MATCH_RESOLUTION|HDMI_MODE_MATCH_SCANMODE)); -// } -// -// } -// -// -// -//} +void VideoOMX::selectVideoMode(int interlaced) +{ + if (/*hdmi*/ true) { + TV_SUPPORTED_MODE_T all_supp_modes[TV_MAX_SUPPORTED_MODES]; + HDMI_RES_GROUP_T pref_group; + TV_SUPPORTED_MODE_T *mymode=NULL; + TV_SUPPORTED_MODE_T *mymode_second_best=NULL; + bool got_optimum=false; + uint32_t pref_mode; + int all_my_modes=vc_tv_hdmi_get_supported_modes(HDMI_RES_GROUP_CEA, + all_supp_modes,TV_MAX_SUPPORTED_MODES, + &pref_group,&pref_mode); + int target_fps=50; + if (format==PAL)target_fps=50; + else if (format==NTSC) target_fps=60; + if (all_my_modes<=0) { + Log::getInstance()->log("Video", Log::NOTICE, "No CEA modes found abort"); + return; + } + + //Now first determine native resolution + int native_width=1920; + int native_height=1080; + for (int i=0;ilog("Video", Log::NOTICE, "Found native mode %dx%d %d Hz i: %d", + mymode->width,mymode->height,mymode->frame_rate,mymode->scan_mode); + } + + } + //Now find the mode which matches best + for (int i=0;iwidth==native_width && + curmode->height==native_height && + curmode->frame_rate==target_fps) { + if(curmode->scan_mode==interlaced) { + got_optimum=true; + mymode=curmode; + Log::getInstance()->log("Video", Log::NOTICE, "Found optimum mode %dx%d %d Hz i: %d", + mymode->width,mymode->height,mymode->frame_rate,mymode->scan_mode); + } else { + mymode_second_best=curmode; + Log::getInstance()->log("Video", Log::NOTICE, "Found close to optimum mode %dx%d %d Hz i: %d", + mymode_second_best->width,mymode_second_best->height, + mymode_second_best->frame_rate,mymode_second_best->scan_mode); + } + + } + } + vc_tv_power_off(); + if (mymode) { + Log::getInstance()->log("Video", Log::NOTICE, "Switch to optimum mode"); + vc_tv_hdmi_power_on_explicit(HDMI_MODE_HDMI,HDMI_RES_GROUP_CEA,mymode->code); + } else if (mymode_second_best) { + Log::getInstance()->log("Video", Log::NOTICE, "Switch to close to optimum mode"); + vc_tv_hdmi_power_on_explicit(HDMI_MODE_HDMI,HDMI_RES_GROUP_CEA,mymode_second_best->code); + } else { + Log::getInstance()->log("Video", Log::NOTICE, "Switch to prefered mode"); + vc_tv_hdmi_power_on_best(1920,1080,target_fps,interlaced?HDMI_INTERLACED:HDMI_NONINTERLACED, + (EDID_MODE_MATCH_FLAG_T)(HDMI_MODE_MATCH_FRAMERATE|HDMI_MODE_MATCH_RESOLUTION|HDMI_MODE_MATCH_SCANMODE)); + } + + } + + + +} int VideoOMX::setConnection(UCHAR tconnection) diff --git a/videoomx.h b/videoomx.h index 9fd9caf..cdc0c13 100644 --- a/videoomx.h +++ b/videoomx.h @@ -257,7 +257,7 @@ class VideoOMX : public Video, public Thread_TYPE float xpos,ypos; int deinterlace; void updateMode();//called internally to adjust for different parameters - // void selectVideoMode(int interlaced); + void selectVideoMode(int interlaced); UCHAR tvsystem; -- 2.39.5