Skip to content

Commit

Permalink
Add VSync.
Browse files Browse the repository at this point in the history
  • Loading branch information
rellla committed Jan 30, 2015
1 parent f232751 commit 042e014
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Most features of full VDPAU are missing, only decoding of h264, mpeg1 and
mpeg2 and output of software-decoded videos will work.
Output bypasses X video driver, hence don't try to use Xv
at the same time.
Only tested with mplayer, if other players need unimplemented functions
Only tested with mplayer and mpv, if other players need unimplemented functions
something will fail.

$ make
Expand All @@ -23,6 +23,9 @@ To enable OSD support for e.g. subtitles, set VDPAU_OSD environment
variable to 1:
$ export VDPAU_OSD=1

To enable experimental VSYNC support, set VDPAU_VSYNC environment variable to 1:
$ export VDPAU_VSYNC=1

This partly breaks X11 integration due to hardware limitations. The video
area can't be overlapped by other windows. For fullscreen use this is no
problem.
Expand Down
10 changes: 10 additions & 0 deletions device.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ VdpStatus vdp_imp_device_create_x11(Display *display,
return VDP_STATUS_ERROR;
}

// Get environment variables
char *env_vdpau_osd = getenv("VDPAU_OSD");
if (env_vdpau_osd && strncmp(env_vdpau_osd, "1", 1) == 0)
{
Expand All @@ -54,6 +55,15 @@ VdpStatus vdp_imp_device_create_x11(Display *display,
VDPAU_DBG("Failed to open /dev/g2d! OSD disabled.");
}

char *env_vdpau_vsync = getenv("VDPAU_VSYNC");
if (env_vdpau_vsync && strncmp(env_vdpau_vsync, "1", 1) == 0)
{
dev->vsync_enabled = 1;
VDPAU_DBG("VSync enabled.");
}
else
VDPAU_DBG("VSync disabled.");

*get_proc_address = &vdp_get_proc_address;

return VDP_STATUS_OK;
Expand Down
27 changes: 24 additions & 3 deletions presentation_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@
*
*/

#include "vdpau_private.h"
#include <time.h>
#include <fcntl.h>
#include <inttypes.h>
#include <linux/fb.h>
#include <pthread.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include "sunxi_disp_ioctl.h"
#include <time.h>

#include "queue.h"
#include "rgba.h"
#include "sunxi_disp_ioctl.h"
#include "vdpau_private.h"
#include "ve.h"

static pthread_t presentation_thread_id;
Expand Down Expand Up @@ -253,6 +256,16 @@ static VdpStatus do_presentation_queue_display(Task *task)

static void *presentation_thread(void *param)
{
queue_ctx_t *q = param;
int fd_fb = 0;

if (q->device->vsync_enabled)
{
fd_fb = open("/dev/fb0", O_RDWR);
if (!fd_fb)
VDPAU_DGB("Error opening framebuffer device /dev/fb0");
}

while (1) {
int64_t timeout;
Task *task = q_peek_head(queue);
Expand All @@ -261,6 +274,14 @@ static void *presentation_thread(void *param)
clock_gettime(CLOCK_REALTIME, &now);
// timeout is the difference between now and scheduled time
timeout = (task->when.tv_sec - now.tv_sec) * 1000 * 1000 + (task->when.tv_nsec - now.tv_nsec) / 1000;

// do the VSync
if (q->device->vsync_enabled)
{
if ((fd_fb) && (ioctl(fd_fb, FBIO_WAITFORVSYNC, 0)))
VDPAU_DBG("VSync failed");
}

if (timeout <= 0) { // task is ready to go
// run the task
do_presentation_queue_display(task);
Expand Down
1 change: 1 addition & 0 deletions vdpau_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef struct
int fd;
int g2d_fd;
int osd_enabled;
int vsync_enabled;
} device_ctx_t;

typedef struct
Expand Down

0 comments on commit 042e014

Please sign in to comment.