| 1 |
#include "avm_fourcc.h" |
| 2 |
#include "avm_cpuinfo.h" |
| 3 |
#include "avm_except.h" |
| 4 |
#include "avm_creators.h" |
| 5 |
#include "avm_output.h" |
| 6 |
#include "utils.h" |
| 7 |
|
| 8 |
#include <unistd.h> // geteuid |
| 9 |
#include <string.h> // memcpy |
| 10 |
#include <stdlib.h> // getenv, free() |
| 11 |
#include <stdio.h> |
| 12 |
|
| 13 |
#include "fullscreen_renderer.h" |
| 14 |
|
| 15 |
|
| 16 |
AVM_BEGIN_NAMESPACE; |
| 17 |
|
| 18 |
#define __MODULE__ "AvicapRenderer" |
| 19 |
|
| 20 |
AvicapRenderer::AvicapRenderer(void *dpy){ |
| 21 |
m_pPW=this; |
| 22 |
m_pDpy=dpy; |
| 23 |
// m_bQuit=false; |
| 24 |
|
| 25 |
zx = zy = zw = zh = 0; |
| 26 |
|
| 27 |
} |
| 28 |
|
| 29 |
void AvicapRenderer::setSize(int w,int h){ |
| 30 |
m_iWidth=w; |
| 31 |
m_iHeight=h; |
| 32 |
} |
| 33 |
|
| 34 |
AvicapRenderer::~AvicapRenderer(){ |
| 35 |
|
| 36 |
while (m_VideoRenderers.size() > 0) |
| 37 |
{ |
| 38 |
delete m_VideoRenderers.back(); |
| 39 |
m_VideoRenderers.pop_back(); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
void AvicapRenderer::setCaption(avm::string capstr){ |
| 46 |
for(uint i=0;i<m_VideoRenderers.size();i++){ |
| 47 |
m_VideoRenderers[i]->SetCaption(capstr.c_str(),NULL); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
void AvicapRenderer::setRecordingColorSpace(Colorspaces colorspace) |
| 52 |
{ |
| 53 |
recording_csp=colorspace; |
| 54 |
} |
| 55 |
|
| 56 |
bool AvicapRenderer::checkColorSpace(fourcc_t csp) |
| 57 |
{ |
| 58 |
if(csp==fccYUY2 && recording_csp==cspYUY2){ |
| 59 |
return true; |
| 60 |
} |
| 61 |
else if(csp==fccYV12 && recording_csp==cspYV12){ |
| 62 |
return true; |
| 63 |
} |
| 64 |
|
| 65 |
return false; |
| 66 |
} |
| 67 |
|
| 68 |
// used when we are in pause mode or the player is not playing |
| 69 |
int AvicapRenderer::drawFrame(CImage *im) |
| 70 |
{ |
| 71 |
#if 1 |
| 72 |
// printf("c1\n"); |
| 73 |
if (true) |
| 74 |
{ |
| 75 |
//printf("c2\n"); |
| 76 |
//CImage* im = m_pVideostream->GetFrame(true); // ReadFrame |
| 77 |
// m_fLastDiff = 0.0; |
| 78 |
// setQuality(); |
| 79 |
// printf("c2.1\n"); |
| 80 |
if (im) |
| 81 |
{ |
| 82 |
// printf("c3\n"); |
| 83 |
//const subtitle_line_t* sl = GetCurrentSubtitles(); |
| 84 |
for (unsigned i = 0; i < m_VideoRenderers.size(); i++) |
| 85 |
{ |
| 86 |
// printf("drawing on vr %d\n",i); |
| 87 |
m_VideoRenderers[i]->Draw(im); |
| 88 |
//if (HasSubtitles()) |
| 89 |
// m_VideoRenderers[i]->DrawSubtitles(sl); |
| 90 |
|
| 91 |
m_VideoRenderers[i]->Sync(); |
| 92 |
} |
| 93 |
//printf("c4\n"); |
| 94 |
// m_Quality.insert(im->GetQuality() * 100.0); |
| 95 |
im->Release(); |
| 96 |
// m_iFramesVideo++; |
| 97 |
} |
| 98 |
return 0; |
| 99 |
} |
| 100 |
#endif |
| 101 |
return -1; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
//from aviplay2 |
| 106 |
|
| 107 |
int AvicapRenderer::Refresh() |
| 108 |
{ |
| 109 |
printf("avicaprenderer-refresh\n"); |
| 110 |
for (unsigned i = 0; i < m_VideoRenderers.size(); i++){ |
| 111 |
printf("avicaprenderer-refresh %d\n",i); |
| 112 |
m_VideoRenderers[i]->Refresh(); |
| 113 |
} |
| 114 |
return 0; |
| 115 |
} |
| 116 |
|
| 117 |
// should be redesigned - only first one will get resize event for now |
| 118 |
int AvicapRenderer::Resize(int& new_w, int& new_h) |
| 119 |
{ |
| 120 |
printf("resize %d %d\n",new_w,new_h); |
| 121 |
if (m_VideoRenderers.size() > 0) |
| 122 |
{ |
| 123 |
bool pres; |
| 124 |
//Get(VIDEO_PRESERVE_ASPECT, &pres, 0); |
| 125 |
pres=false; |
| 126 |
if (pres) |
| 127 |
{ |
| 128 |
//StreamInfo* si = m_pVideostream->GetStreamInfo(); |
| 129 |
//float a = si->GetAspectRatio(); |
| 130 |
float a=0.0; |
| 131 |
//delete si; |
| 132 |
if (a == 0) |
| 133 |
a = GetWidth() / (float) GetHeight(); |
| 134 |
new_w = (int) (new_h * a + 0.5); |
| 135 |
if (zw) |
| 136 |
new_w = new_h * zw / zh; |
| 137 |
} |
| 138 |
printf("new w/h %d %d\n",new_w,new_h); |
| 139 |
return m_VideoRenderers.front()->Resize(new_w, new_h); |
| 140 |
} |
| 141 |
return 0; |
| 142 |
} |
| 143 |
|
| 144 |
int AvicapRenderer::Zoom(int x, int y, int w, int h) |
| 145 |
{ |
| 146 |
zx = zy = zw = zh = 0; |
| 147 |
for (unsigned i = 0; i < m_VideoRenderers.size(); i++) |
| 148 |
if (m_VideoRenderers[i]->Zoom(x, y, w, h) == 0) |
| 149 |
{ |
| 150 |
zx = x; zy = y; zw = w; zh = h; |
| 151 |
} |
| 152 |
return 0; |
| 153 |
} |
| 154 |
|
| 155 |
int AvicapRenderer::ToggleFullscreen(bool maximize) |
| 156 |
//int AvicapRenderer::ToggleFullscreen(bool maximize=false) |
| 157 |
{ |
| 158 |
for (unsigned i = 0; i < m_VideoRenderers.size(); i++) |
| 159 |
if (m_VideoRenderers[i]->ToggleFullscreen(maximize) != 0) |
| 160 |
return -1; |
| 161 |
return 0; |
| 162 |
} |
| 163 |
|
| 164 |
#if 0 |
| 165 |
void AvicapRenderer::updateResize() |
| 166 |
{ |
| 167 |
int w, h; |
| 168 |
switch(m_iResizeCount % 3) |
| 169 |
{ |
| 170 |
case 0: |
| 171 |
w=GetWidth()/2; h=GetHeight()/2; |
| 172 |
break; |
| 173 |
case 1: |
| 174 |
w=GetWidth(); h=GetHeight(); |
| 175 |
break; |
| 176 |
case 2: |
| 177 |
w=GetWidth()*2; h=GetHeight()*2; |
| 178 |
break; |
| 179 |
} |
| 180 |
Resize(w, h); |
| 181 |
} |
| 182 |
#endif |
| 183 |
void AvicapRenderer::createVideoRenderer() |
| 184 |
{ |
| 185 |
int pos = -1, wx, wy, ww, wh; |
| 186 |
while (m_VideoRenderers.size() > 0) |
| 187 |
{ |
| 188 |
if (pos < 0) |
| 189 |
pos = m_VideoRenderers.back()->GetPosition(wx, wy); |
| 190 |
if (pos == 0) |
| 191 |
pos = m_VideoRenderers.back()->GetSize(ww, wh); |
| 192 |
delete m_VideoRenderers.back(); |
| 193 |
m_VideoRenderers.pop_back(); |
| 194 |
} |
| 195 |
|
| 196 |
printf("WX %d WY %d WW %d WH %d\n", wx, wy, ww, wh); |
| 197 |
#ifndef X_DISPLAY_MISSING |
| 198 |
if (m_pDpy && GetWidth() > 0 && GetHeight() > 0) |
| 199 |
{ |
| 200 |
bool sub = false; |
| 201 |
IVideoRenderer* renderer = 0; |
| 202 |
|
| 203 |
bool useyuv; |
| 204 |
// Get(USE_YUV, &useyuv, 0); |
| 205 |
|
| 206 |
useyuv=my_useyuv; |
| 207 |
|
| 208 |
if (useyuv && !renderer) |
| 209 |
{ |
| 210 |
// checking for YUY2 first |
| 211 |
static const fourcc_t tryFcc[] = { |
| 212 |
fccYUY2, // looks like YV12 is not supported for Color changes |
| 213 |
//fccYUY2, |
| 214 |
fccYV12, // fastest |
| 215 |
fccUYVY, |
| 216 |
fccI420, |
| 217 |
// forced |
| 218 |
//fccYUY2, |
| 219 |
fccYV12, |
| 220 |
//fccUYVY, |
| 221 |
0 |
| 222 |
}; |
| 223 |
int i = 0; |
| 224 |
|
| 225 |
while (!renderer && tryFcc[i]) |
| 226 |
{ |
| 227 |
try |
| 228 |
{ |
| 229 |
// we always allow to use last entry when HW acceleration |
| 230 |
// is requested - it is giving hw scalable picture |
| 231 |
m_CSP = tryFcc[i]; |
| 232 |
if (!tryFcc[i + 1] || checkColorSpace(m_CSP) == true) |
| 233 |
{ |
| 234 |
printf("yuvrenderer %d\n",m_CSP); |
| 235 |
renderer = CreateYUVRenderer(m_pPW, m_pDpy, |
| 236 |
GetWidth(), GetHeight(), |
| 237 |
m_CSP, sub); |
| 238 |
} |
| 239 |
} |
| 240 |
catch (FatalError& e) |
| 241 |
{ |
| 242 |
e.PrintAll(); |
| 243 |
delete renderer; |
| 244 |
renderer=0; |
| 245 |
} |
| 246 |
i++; |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
if (!renderer) |
| 251 |
{ |
| 252 |
printf("creating rgb renderer\n"); |
| 253 |
renderer = CreateFullscreenRenderer(m_pPW, m_pDpy, GetWidth(), GetHeight(), sub); |
| 254 |
//m_CSP = m_iDepth; |
| 255 |
//int result = m_pVideostream->GetVideoDecoder()->SetDestFmt(m_iDepth); |
| 256 |
} |
| 257 |
|
| 258 |
if (renderer) |
| 259 |
{ |
| 260 |
//StreamInfo* si = m_pVideostream->GetStreamInfo(); |
| 261 |
//float a = si->GetAspectRatio(); |
| 262 |
float a = 0.1f; |
| 263 |
if (a > 1.f) |
| 264 |
{ |
| 265 |
int w = (int) (GetHeight() * a + 0.5f); |
| 266 |
int h = GetHeight(); |
| 267 |
renderer->Resize(w, h); |
| 268 |
} |
| 269 |
//delete si; |
| 270 |
#if 0 |
| 271 |
if (pos == 0) |
| 272 |
{ |
| 273 |
renderer->Resize(ww, wh); |
| 274 |
renderer->SetPosition(wx, wy); |
| 275 |
} |
| 276 |
#endif |
| 277 |
renderer->SetCaption("avicap: unknown", 0); |
| 278 |
|
| 279 |
m_VideoRenderers.push_back(renderer); |
| 280 |
printf("pushback renderer\n"); |
| 281 |
//char* fs; |
| 282 |
//Get(SUBTITLE_FONT, &fs, 0); |
| 283 |
//renderer->SetFont(sub ? fs : 0); |
| 284 |
//if (fs) free(fs); |
| 285 |
} |
| 286 |
//setVideoBuffering(); |
| 287 |
//SetColorSpace(IMG_FMT_I420, false); |
| 288 |
//m_pVideostream->GetVideoDecoder()->SetDestFmt(IMG_FMT_I420); |
| 289 |
} |
| 290 |
#endif |
| 291 |
} |
| 292 |
|
| 293 |
AVM_END_NAMESPACE; |
| 294 |
|
| 295 |
|