mirror of
https://github.com/tuxbox-neutrino/libstb-hal.git
synced 2025-08-26 15:02:58 +02:00
- formatting code using astyle
Conflicts: libarmbox/dmx.cpp libgeneric-pc/video_lib.h libspark/dmx.cpp Signed-off-by: Thilo Graf <dbt@novatux.de>
This commit is contained in:
@@ -1,25 +1,25 @@
|
||||
/*
|
||||
Copyright 2010 Carsten Juttner <carjay@gmx.net>
|
||||
Copyright 2012,2013 Stefan Seyfried <seife@tuxboxcvs.slipkontur.de>
|
||||
Copyright 2010 Carsten Juttner <carjay@gmx.net>
|
||||
Copyright 2012,2013 Stefan Seyfried <seife@tuxboxcvs.slipkontur.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
openGL based framebuffer implementation
|
||||
based on Carjay's neutrino-hd-dvbapi work, see
|
||||
http://gitorious.org/neutrino-hd/neutrino-hd-dvbapi
|
||||
openGL based framebuffer implementation
|
||||
based on Carjay's neutrino-hd-dvbapi work, see
|
||||
http://gitorious.org/neutrino-hd/neutrino-hd-dvbapi
|
||||
|
||||
TODO: AV-Sync code is "experimental" at best
|
||||
TODO: AV-Sync code is "experimental" at best
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
@@ -90,8 +90,8 @@ GLFbPC::GLFbPC(int x, int y, std::vector<unsigned char> &buf): mReInit(true), mS
|
||||
*mX = x;
|
||||
*mY = y;
|
||||
av_reduce(&mOA.num, &mOA.den, x, y, INT_MAX);
|
||||
mVA = mOA; /* initial aspect ratios are from the FB resolution, those */
|
||||
_mVA = mVA; /* will be updated by the videoDecoder functions anyway */
|
||||
mVA = mOA; /* initial aspect ratios are from the FB resolution, those */
|
||||
_mVA = mVA; /* will be updated by the videoDecoder functions anyway */
|
||||
mVAchanged = true;
|
||||
mCrop = DISPLAY_AR_MODE_PANSCAN;
|
||||
zoom = 1.0;
|
||||
@@ -119,7 +119,7 @@ GLFbPC::GLFbPC(int x, int y, std::vector<unsigned char> &buf): mReInit(true), mS
|
||||
|
||||
unlink("/tmp/neutrino.input");
|
||||
mkfifo("/tmp/neutrino.input", 0600);
|
||||
input_fd = open("/tmp/neutrino.input", O_RDWR|O_CLOEXEC|O_NONBLOCK);
|
||||
input_fd = open("/tmp/neutrino.input", O_RDWR | O_CLOEXEC | O_NONBLOCK);
|
||||
if (input_fd < 0)
|
||||
hal_info("%s: could not open /tmp/neutrino.input FIFO: %m\n", __func__);
|
||||
initKeys();
|
||||
@@ -221,12 +221,12 @@ void GLFramebuffer::run()
|
||||
|
||||
/* init the good stuff */
|
||||
GLenum err = glewInit();
|
||||
if(err == GLEW_OK)
|
||||
if (err == GLEW_OK)
|
||||
{
|
||||
if((!GLEW_VERSION_1_5)||(!GLEW_EXT_pixel_buffer_object)||(!GLEW_ARB_texture_non_power_of_two))
|
||||
if ((!GLEW_VERSION_1_5) || (!GLEW_EXT_pixel_buffer_object) || (!GLEW_ARB_texture_non_power_of_two))
|
||||
{
|
||||
hal_info("GLFB: Sorry, your graphics card is not supported. "
|
||||
"Needs at least OpenGL 1.5, pixel buffer objects and NPOT textures.\n");
|
||||
"Needs at least OpenGL 1.5, pixel buffer objects and NPOT textures.\n");
|
||||
hal_info("incompatible graphics card: %m");
|
||||
_exit(1); /* Life is hard */
|
||||
}
|
||||
@@ -262,7 +262,8 @@ void GLFbPC::setupCtx()
|
||||
}
|
||||
|
||||
void GLFbPC::setupOSDBuffer()
|
||||
{ /* the OSD buffer size can be decoupled from the actual
|
||||
{
|
||||
/* the OSD buffer size can be decoupled from the actual
|
||||
window size since the GL can blit-stretch with no
|
||||
trouble at all, ah, the luxury of ignorance... */
|
||||
// mMutex.lock();
|
||||
@@ -325,7 +326,7 @@ void GLFbPC::releaseGLObjects()
|
||||
struct input_event ev;
|
||||
if (key == 'f')
|
||||
{
|
||||
hal_info_c("GLFB::%s: toggle fullscreen %s\n", __func__, glfb_priv->mFullscreen?"off":"on");
|
||||
hal_info_c("GLFB::%s: toggle fullscreen %s\n", __func__, glfb_priv->mFullscreen ? "off" : "on");
|
||||
glfb_priv->mFullscreen = !(glfb_priv->mFullscreen);
|
||||
glfb_priv->mReInit = true;
|
||||
return;
|
||||
@@ -364,7 +365,7 @@ int sleep_us = 30000;
|
||||
|
||||
void GLFbPC::render()
|
||||
{
|
||||
if(mShutDown)
|
||||
if (mShutDown)
|
||||
glutLeaveMainLoop();
|
||||
|
||||
mReInitLock.lock();
|
||||
@@ -376,7 +377,8 @@ void GLFbPC::render()
|
||||
mReInit = false;
|
||||
mX = &_mX[mFullscreen];
|
||||
mY = &_mY[mFullscreen];
|
||||
if (mFullscreen) {
|
||||
if (mFullscreen)
|
||||
{
|
||||
int x = glutGet(GLUT_SCREEN_WIDTH);
|
||||
int y = glutGet(GLUT_SCREEN_HEIGHT);
|
||||
*mX = x;
|
||||
@@ -389,17 +391,18 @@ void GLFbPC::render()
|
||||
xoff = (x - *mX) / 2;
|
||||
yoff = (y - *mY) / 2;
|
||||
glutFullScreen();
|
||||
} else
|
||||
}
|
||||
else
|
||||
*mX = *mY * mOA.num / mOA.den;
|
||||
hal_info("%s: reinit mX:%d mY:%d xoff:%d yoff:%d fs %d\n",
|
||||
__func__, *mX, *mY, xoff, yoff, mFullscreen);
|
||||
__func__, *mX, *mY, xoff, yoff, mFullscreen);
|
||||
glViewport(xoff, yoff, *mX, *mY);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
float aspect = static_cast<float>(*mX)/ *mY;
|
||||
float aspect = static_cast<float>(*mX) / *mY;
|
||||
float osdaspect = static_cast<float>(mOA.den) / mOA.num;
|
||||
|
||||
glOrtho(aspect*-osdaspect, aspect*osdaspect, -1.0, 1.0, -1.0, 1.0 );
|
||||
glOrtho(aspect * -osdaspect, aspect * osdaspect, -1.0, 1.0, -1.0, 1.0);
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
@@ -414,7 +417,8 @@ void GLFbPC::render()
|
||||
glutReshapeWindow(*mX, *mY);
|
||||
|
||||
bltDisplayBuffer(); /* decoded video stream */
|
||||
if (mState.blit) {
|
||||
if (mState.blit)
|
||||
{
|
||||
/* only blit manually after fb->blit(), this helps to find missed blit() calls */
|
||||
mState.blit = false;
|
||||
hal_debug("GLFB::%s blit!\n", __func__);
|
||||
@@ -431,16 +435,18 @@ void GLFbPC::render()
|
||||
xscale = 1.0;
|
||||
int cmp = (mCrop == DISPLAY_AR_MODE_NONE) ? 0 : av_cmp_q(mVA, mOA);
|
||||
const AVRational a149 = { 14, 9 };
|
||||
switch (cmp) {
|
||||
switch (cmp)
|
||||
{
|
||||
default:
|
||||
case INT_MIN: /* invalid */
|
||||
case 0: /* identical */
|
||||
case INT_MIN: /* invalid */
|
||||
case 0: /* identical */
|
||||
hal_debug("%s: mVA == mOA (or fullscreen mode :-)\n", __func__);
|
||||
break;
|
||||
case 1: /* mVA > mOA -- video is wider than display */
|
||||
case 1: /* mVA > mOA -- video is wider than display */
|
||||
hal_debug("%s: mVA > mOA\n", __func__);
|
||||
xscale = av_q2d(mVA) / av_q2d(mOA);
|
||||
switch (mCrop) {
|
||||
switch (mCrop)
|
||||
{
|
||||
case DISPLAY_AR_MODE_PANSCAN:
|
||||
break;
|
||||
case DISPLAY_AR_MODE_LETTERBOX:
|
||||
@@ -453,18 +459,20 @@ void GLFbPC::render()
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case -1: /* mVA < mOA -- video is taller than display */
|
||||
case -1: /* mVA < mOA -- video is taller than display */
|
||||
hal_debug("%s: mVA < mOA\n", __func__);
|
||||
xscale = av_q2d(mVA) / av_q2d(mOA);
|
||||
switch (mCrop) {
|
||||
switch (mCrop)
|
||||
{
|
||||
case DISPLAY_AR_MODE_LETTERBOX:
|
||||
break;
|
||||
case DISPLAY_AR_MODE_PANSCAN2:
|
||||
if (av_cmp_q(a149, mOA) < 0) {
|
||||
if (av_cmp_q(a149, mOA) < 0)
|
||||
{
|
||||
zoom = av_q2d(mVA) * av_q2d(a149) / av_q2d(mOA);
|
||||
break;
|
||||
}
|
||||
/* fallthrough for output format 14:9 */
|
||||
/* fallthrough for output format 14:9 */
|
||||
case DISPLAY_AR_MODE_PANSCAN:
|
||||
zoom = av_q2d(mOA) / av_q2d(mVA);
|
||||
break;
|
||||
@@ -500,11 +508,15 @@ void GLFbPC::checkReinit(int x, int y)
|
||||
static int last_x = 0, last_y = 0;
|
||||
|
||||
mReInitLock.lock();
|
||||
if (!mFullscreen && !mReInit && (x != *mX || y != *mY)) {
|
||||
if (x != *mX && abs(x - last_x) > 2) {
|
||||
if (!mFullscreen && !mReInit && (x != *mX || y != *mY))
|
||||
{
|
||||
if (x != *mX && abs(x - last_x) > 2)
|
||||
{
|
||||
*mX = x;
|
||||
*mY = *mX * mOA.den / mOA.num;
|
||||
} else if (y != *mY && abs(y - last_y) > 2) {
|
||||
}
|
||||
else if (y != *mY && abs(y - last_y) > 2)
|
||||
{
|
||||
*mY = y;
|
||||
*mX = *mY * mOA.num / mOA.den;
|
||||
}
|
||||
@@ -517,25 +529,29 @@ void GLFbPC::checkReinit(int x, int y)
|
||||
|
||||
void GLFbPC::drawSquare(float size, float x_factor)
|
||||
{
|
||||
GLfloat vertices[] = {
|
||||
1.0f, 1.0f,
|
||||
GLfloat vertices[] =
|
||||
{
|
||||
1.0f, 1.0f,
|
||||
-1.0f, 1.0f,
|
||||
-1.0f, -1.0f,
|
||||
1.0f, -1.0f,
|
||||
1.0f, -1.0f,
|
||||
};
|
||||
|
||||
GLubyte indices[] = { 0, 1, 2, 3 };
|
||||
|
||||
GLfloat texcoords[] = {
|
||||
1.0, 0.0,
|
||||
0.0, 0.0,
|
||||
0.0, 1.0,
|
||||
1.0, 1.0,
|
||||
GLfloat texcoords[] =
|
||||
{
|
||||
1.0, 0.0,
|
||||
0.0, 0.0,
|
||||
0.0, 1.0,
|
||||
1.0, 1.0,
|
||||
};
|
||||
if (x_factor > -99.0) { /* x_factor == -100 => OSD */
|
||||
if (x_factor > -99.0) /* x_factor == -100 => OSD */
|
||||
{
|
||||
if (videoDecoder &&
|
||||
videoDecoder->pig_x > 0 && videoDecoder->pig_y > 0 &&
|
||||
videoDecoder->pig_w > 0 && videoDecoder->pig_h > 0) {
|
||||
videoDecoder->pig_w > 0 && videoDecoder->pig_h > 0)
|
||||
{
|
||||
/* these calculations even consider cropping and panscan mode
|
||||
* maybe this could be done with some clever opengl tricks? */
|
||||
double w2 = (double)mState.width * 0.5l;
|
||||
@@ -546,16 +562,17 @@ void GLFbPC::drawSquare(float size, float x_factor)
|
||||
double h = (double)videoDecoder->pig_h / h2;
|
||||
x += ((1.0l - x_factor * size) / 2.0l) * w / x_factor / size;
|
||||
y += ((size - 1.0l) / 2.0l) * h / size;
|
||||
vertices[0] = x + w; /* top right x */
|
||||
vertices[1] = y; /* top right y */
|
||||
vertices[2] = x; /* top left x */
|
||||
vertices[3] = y; /* top left y */
|
||||
vertices[4] = x; /* bottom left x */
|
||||
vertices[5] = y - h; /* bottom left y */
|
||||
vertices[6] = vertices[0]; /* bottom right x */
|
||||
vertices[7] = vertices[5]; /* bottom right y */
|
||||
vertices[0] = x + w; /* top right x */
|
||||
vertices[1] = y; /* top right y */
|
||||
vertices[2] = x; /* top left x */
|
||||
vertices[3] = y; /* top left y */
|
||||
vertices[4] = x; /* bottom left x */
|
||||
vertices[5] = y - h; /* bottom left y */
|
||||
vertices[6] = vertices[0]; /* bottom right x */
|
||||
vertices[7] = vertices[5]; /* bottom right y */
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
x_factor = 1.0; /* OSD */
|
||||
|
||||
glPushMatrix();
|
||||
@@ -589,7 +606,8 @@ void GLFbPC::bltDisplayBuffer()
|
||||
return;
|
||||
static bool warn = true;
|
||||
cVideo::SWFramebuffer *buf = videoDecoder->getDecBuf();
|
||||
if (!buf) {
|
||||
if (!buf)
|
||||
{
|
||||
if (warn)
|
||||
hal_info("GLFB::%s did not get a buffer...\n", __func__);
|
||||
warn = false;
|
||||
@@ -601,7 +619,8 @@ void GLFbPC::bltDisplayBuffer()
|
||||
return;
|
||||
|
||||
AVRational a = buf->AR();
|
||||
if (a.den != 0 && a.num != 0 && av_cmp_q(a, _mVA)) {
|
||||
if (a.den != 0 && a.num != 0 && av_cmp_q(a, _mVA))
|
||||
{
|
||||
_mVA = a;
|
||||
/* _mVA is the raw buffer's aspect, mVA is the real scaled output aspect */
|
||||
av_reduce(&mVA.num, &mVA.den, w * a.num, h * a.den, INT_MAX);
|
||||
@@ -624,10 +643,11 @@ void GLFbPC::bltDisplayBuffer()
|
||||
int64_t vpts = buf->pts() + 18000;
|
||||
if (audioDecoder)
|
||||
apts = audioDecoder->getPts();
|
||||
if (apts != last_apts) {
|
||||
if (apts != last_apts)
|
||||
{
|
||||
int rate, dummy1, dummy2;
|
||||
if (apts < vpts)
|
||||
sleep_us = (sleep_us * 2 + (vpts - apts)*10/9) / 3;
|
||||
sleep_us = (sleep_us * 2 + (vpts - apts) * 10 / 9) / 3;
|
||||
else if (sleep_us > 1000)
|
||||
sleep_us -= 1000;
|
||||
last_apts = apts;
|
||||
@@ -642,5 +662,5 @@ void GLFbPC::bltDisplayBuffer()
|
||||
sleep_us = 1;
|
||||
}
|
||||
hal_debug("vpts: 0x%" PRIx64 " apts: 0x%" PRIx64 " diff: %6.3f sleep_us %d buf %d\n",
|
||||
buf->pts(), apts, (buf->pts() - apts)/90000.0, sleep_us, videoDecoder->buf_num);
|
||||
buf->pts(), apts, (buf->pts() - apts) / 90000.0, sleep_us, videoDecoder->buf_num);
|
||||
}
|
||||
|
Reference in New Issue
Block a user