2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
22 #if defined(TARGET_RASPBERRY_PI)
24 #include "utils/log.h"
26 #include "cores/omxplayer/OMXImage.h"
30 m_initialized = false;
31 m_omx_initialized = false;
32 m_DllBcmHost = new DllBcmHost();
33 m_OMX = new COMXCore();
43 bool CRBP::Initialize()
45 CSingleLock lock (m_critSection);
49 m_initialized = m_DllBcmHost->Load();
53 m_DllBcmHost->bcm_host_init();
55 m_omx_initialized = m_OMX->Initialize();
56 if(!m_omx_initialized)
59 char response[80] = "";
62 m_codec_mpg2_enabled = false;
63 m_codec_wvc1_enabled = false;
65 if (vc_gencmd(response, sizeof response, "get_mem arm") == 0)
66 vc_gencmd_number_property(response, "arm", &m_arm_mem);
67 if (vc_gencmd(response, sizeof response, "get_mem gpu") == 0)
68 vc_gencmd_number_property(response, "gpu", &m_gpu_mem);
70 if (vc_gencmd(response, sizeof response, "codec_enabled MPG2") == 0)
71 m_codec_mpg2_enabled = strcmp("MPG2=enabled", response) == 0;
72 if (vc_gencmd(response, sizeof response, "codec_enabled WVC1") == 0)
73 m_codec_wvc1_enabled = strcmp("WVC1=enabled", response) == 0;
75 g_OMXImage.Initialize();
76 m_omx_image_init = true;
80 void CRBP::LogFirmwareVerison()
83 m_DllBcmHost->vc_gencmd(response, sizeof response, "version");
84 response[sizeof(response) - 1] = '\0';
85 CLog::Log(LOGNOTICE, "Raspberry PI firmware version: %s", response);
86 CLog::Log(LOGNOTICE, "ARM mem: %dMB GPU mem: %dMB MPG2:%d WVC1:%d", m_arm_mem, m_gpu_mem, m_codec_mpg2_enabled, m_codec_wvc1_enabled);
89 void CRBP::GetDisplaySize(int &width, int &height)
91 DISPMANX_DISPLAY_HANDLE_T display;
92 DISPMANX_MODEINFO_T info;
94 display = vc_dispmanx_display_open( 0 /*screen*/ );
95 if (vc_dispmanx_display_get_info(display, &info) == 0)
105 vc_dispmanx_display_close(display );
108 unsigned char *CRBP::CaptureDisplay(int width, int height, int *pstride, bool swap_red_blue, bool video_only)
110 DISPMANX_DISPLAY_HANDLE_T display;
111 DISPMANX_RESOURCE_HANDLE_T resource;
113 unsigned char *image = NULL;
114 uint32_t vc_image_ptr;
119 flags |= DISPMANX_SNAPSHOT_NO_RGB|DISPMANX_SNAPSHOT_FILL;
121 flags |= DISPMANX_SNAPSHOT_SWAP_RED_BLUE;
123 flags |= DISPMANX_SNAPSHOT_PACK;
125 display = vc_dispmanx_display_open( 0 /*screen*/ );
126 stride = ((width + 15) & ~15) * 4;
127 image = new unsigned char [height * stride];
131 resource = vc_dispmanx_resource_create( VC_IMAGE_RGBA32, width, height, &vc_image_ptr );
133 vc_dispmanx_snapshot(display, resource, (DISPMANX_TRANSFORM_T)flags);
135 vc_dispmanx_rect_set(&rect, 0, 0, width, height);
136 vc_dispmanx_resource_read_data(resource, &rect, image, stride);
137 vc_dispmanx_resource_delete( resource );
138 vc_dispmanx_display_close(display );
145 void CRBP::Deinitialize()
147 if (m_omx_image_init)
148 g_OMXImage.Deinitialize();
150 if(m_omx_initialized)
151 m_OMX->Deinitialize();
153 m_DllBcmHost->bcm_host_deinit();
156 m_DllBcmHost->Unload();
158 m_omx_image_init = false;
159 m_initialized = false;
160 m_omx_initialized = false;