summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorrr- <mkurczew@gmail.com>2015-11-07 21:11:04 +0100
committerwm4 <wm4@nowhere>2015-11-08 15:00:15 +0100
commit62f261a7b82922bce32eeaff9d1ab1b6c660598c (patch)
tree5c989f20e4b951bc92f58fdb745f2c40885d00ae /video
parentc3f2ef5491dc28d1f2f68d024b4be01c27b029e7 (diff)
downloadmpv-62f261a7b82922bce32eeaff9d1ab1b6c660598c.tar.bz2
mpv-62f261a7b82922bce32eeaff9d1ab1b6c660598c.tar.xz
vo_drm: use bool rather than integer return values
Since the errors weren't used for anything other than simple success/fail checks, I simplified things a bit.
Diffstat (limited to 'video')
-rw-r--r--video/out/drm_common.c69
-rw-r--r--video/out/drm_common.h5
-rw-r--r--video/out/opengl/drm_egl.c5
-rw-r--r--video/out/vo_drm.c59
4 files changed, 60 insertions, 78 deletions
diff --git a/video/out/drm_common.c b/video/out/drm_common.c
index 5e695f8dc4..697cb61c6d 100644
--- a/video/out/drm_common.c
+++ b/video/out/drm_common.c
@@ -70,7 +70,7 @@ static bool is_connector_valid(struct kms *kms, int connector_id,
return true;
}
-static int setup_connector(
+static bool setup_connector(
struct kms *kms, const drmModeRes *res, int connector_id)
{
drmModeConnector *connector = NULL;
@@ -89,26 +89,25 @@ static int setup_connector(
}
if (connector_id == -1) {
MP_ERR(kms, "No connected connectors found\n");
- return -ENODEV;
+ return false;
}
}
if (connector_id < 0 || connector_id >= res->count_connectors) {
MP_ERR(kms, "Bad connector ID. Max valid connector ID = %u\n",
res->count_connectors);
- return -ENODEV;
+ return false;
}
connector = drmModeGetConnector(kms->fd, res->connectors[connector_id]);
- if (!is_connector_valid(kms, connector_id, connector, false)) {
- return -ENODEV;
- }
+ if (!is_connector_valid(kms, connector_id, connector, false))
+ return false;
kms->connector = connector;
- return 0;
+ return true;
}
-static int setup_crtc(struct kms *kms, const drmModeRes *res)
+static bool setup_crtc(struct kms *kms, const drmModeRes *res)
{
for (unsigned int i = 0; i < kms->connector->count_encoders; ++i) {
drmModeEncoder *encoder
@@ -127,7 +126,7 @@ static int setup_crtc(struct kms *kms, const drmModeRes *res)
kms->encoder = encoder;
kms->crtc_id = encoder->crtc_id;
- return 0;
+ return true;
}
drmModeFreeEncoder(encoder);
@@ -136,10 +135,10 @@ static int setup_crtc(struct kms *kms, const drmModeRes *res)
MP_ERR(kms,
"Connector %u has no suitable CRTC\n",
kms->connector->connector_id);
- return -ENODEV;
+ return false;
}
-static int setup_mode(struct kms *kms, int mode_id)
+static bool setup_mode(struct kms *kms, int mode_id)
{
if (mode_id < 0 || mode_id >= kms->connector->count_modes) {
MP_ERR(
@@ -156,11 +155,11 @@ static int setup_mode(struct kms *kms, int mode_id)
kms->connector->modes[i].hdisplay,
kms->connector->modes[i].vdisplay);
}
- return -EINVAL;
+ return false;
}
kms->mode = kms->connector->modes[mode_id];
- return 0;
+ return true;
}
@@ -178,32 +177,28 @@ struct kms *kms_create(struct mp_log *log)
return ret;
}
-int kms_setup(struct kms *kms, const char *device_path, int connector_id, int mode_id)
+bool kms_setup(struct kms *kms, const char *device_path, int connector_id, int mode_id)
{
- int ret = 0;
kms->fd = open(device_path, O_RDWR | O_CLOEXEC);
if (kms->fd < 0) {
MP_ERR(kms, "Cannot open \"%s\": %s.\n", device_path, mp_strerror(errno));
- ret = -errno;
- goto end;
+ return false;
}
drmModeRes *res = drmModeGetResources(kms->fd);
if (!res) {
MP_ERR(kms, "Cannot retrieve DRM resources: %s\n", mp_strerror(errno));
- ret = -errno;
- goto end;
+ return false;
}
- if (setup_connector(kms, res, mode_id))
- goto end;
- if (setup_crtc(kms, res))
- goto end;
- if (setup_mode(kms, mode_id))
- goto end;
+ if (!setup_connector(kms, res, mode_id))
+ return false;
+ if (!setup_crtc(kms, res))
+ return false;
+ if (!setup_mode(kms, mode_id))
+ return false;
-end:
- return ret;
+ return true;
}
void kms_destroy(struct kms *kms)
@@ -249,7 +244,7 @@ static int install_signal(int signo, void (*handler)(int))
}
-int vt_switcher_init(struct vt_switcher *s, struct mp_log *log)
+bool vt_switcher_init(struct vt_switcher *s, struct mp_log *log)
{
s->log = log;
s->tty_fd = -1;
@@ -258,37 +253,37 @@ int vt_switcher_init(struct vt_switcher *s, struct mp_log *log)
if (mp_make_cloexec_pipe(vt_switcher_pipe)) {
MP_ERR(s, "Creating pipe failed: %s\n", mp_strerror(errno));
- return -1;
+ return false;
}
s->tty_fd = open("/dev/tty", O_RDWR | O_CLOEXEC);
if (s->tty_fd < 0) {
MP_ERR(s, "Can't open TTY for VT control: %s\n", mp_strerror(errno));
- return -1;
+ return false;
}
if (has_signal_installed(RELEASE_SIGNAL)) {
MP_ERR(s, "Can't handle VT release - signal already used\n");
- return -1;
+ return false;
}
if (has_signal_installed(ACQUIRE_SIGNAL)) {
MP_ERR(s, "Can't handle VT acquire - signal already used\n");
- return -1;
+ return false;
}
if (install_signal(RELEASE_SIGNAL, vt_switcher_sighandler)) {
MP_ERR(s, "Failed to install release signal: %s\n", mp_strerror(errno));
- return -1;
+ return false;
}
if (install_signal(ACQUIRE_SIGNAL, vt_switcher_sighandler)) {
MP_ERR(s, "Failed to install acquire signal: %s\n", mp_strerror(errno));
- return -1;
+ return false;
}
struct vt_mode vt_mode;
if (ioctl(s->tty_fd, VT_GETMODE, &vt_mode) < 0) {
MP_ERR(s, "VT_GETMODE failed: %s\n", mp_strerror(errno));
- return -1;
+ return false;
}
vt_mode.mode = VT_PROCESS;
@@ -296,10 +291,10 @@ int vt_switcher_init(struct vt_switcher *s, struct mp_log *log)
vt_mode.acqsig = ACQUIRE_SIGNAL;
if (ioctl(s->tty_fd, VT_SETMODE, &vt_mode) < 0) {
MP_ERR(s, "VT_SETMODE failed: %s\n", mp_strerror(errno));
- return -1;
+ return false;
}
- return 0;
+ return true;
}
void vt_switcher_acquire(struct vt_switcher *s,
diff --git a/video/out/drm_common.h b/video/out/drm_common.h
index da26af7f97..98a4bad04d 100644
--- a/video/out/drm_common.h
+++ b/video/out/drm_common.h
@@ -18,6 +18,7 @@
#ifndef MP_VT_SWITCHER_H
#define MP_VT_SWITCHER_H
+#include <stdbool.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
@@ -37,7 +38,7 @@ struct vt_switcher {
void *handler_data[2];
};
-int vt_switcher_init(struct vt_switcher *s, struct mp_log *log);
+bool vt_switcher_init(struct vt_switcher *s, struct mp_log *log);
void vt_switcher_destroy(struct vt_switcher *s);
void vt_switcher_poll(struct vt_switcher *s, int timeout_ms);
void vt_switcher_interrupt_poll(struct vt_switcher *s);
@@ -46,7 +47,7 @@ void vt_switcher_acquire(struct vt_switcher *s, void (*handler)(void*), void *us
void vt_switcher_release(struct vt_switcher *s, void (*handler)(void*), void *user_data);
struct kms *kms_create(struct mp_log *log);
-int kms_setup(struct kms *kms, const char *device_path, int conn_id, int mode_id);
+bool kms_setup(struct kms *kms, const char *device_path, int conn_id, int mode_id);
void kms_destroy(struct kms *kms);
#endif
diff --git a/video/out/opengl/drm_egl.c b/video/out/opengl/drm_egl.c
index 696785d975..a54467e235 100644
--- a/video/out/opengl/drm_egl.c
+++ b/video/out/opengl/drm_egl.c
@@ -313,7 +313,7 @@ static int drm_egl_init(struct MPGLContext *ctx, int flags)
p->ev.version = DRM_EVENT_CONTEXT_VERSION;
p->ev.page_flip_handler = page_flipped;
- p->vt_switcher_active = vt_switcher_init(&p->vt_switcher, ctx->vo->log) == 0;
+ p->vt_switcher_active = vt_switcher_init(&p->vt_switcher, ctx->vo->log);
if (p->vt_switcher_active) {
vt_switcher_acquire(&p->vt_switcher, acquire_vt, ctx);
vt_switcher_release(&p->vt_switcher, release_vt, ctx);
@@ -329,8 +329,7 @@ static int drm_egl_init(struct MPGLContext *ctx, int flags)
}
// TODO: arguments should be configurable
- int ret = kms_setup(p->kms, "/dev/dri/card0", -1, 0);
- if (ret) {
+ if (!kms_setup(p->kms, "/dev/dri/card0", -1, 0)) {
MP_ERR(ctx->vo, "Failed to configure KMS.\n");
return -1;
}
diff --git a/video/out/vo_drm.c b/video/out/vo_drm.c
index 467d9bc82c..7b1ff0b6c2 100644
--- a/video/out/vo_drm.c
+++ b/video/out/vo_drm.c
@@ -100,10 +100,8 @@ static void fb_destroy(int fd, struct framebuffer *buf)
}
}
-static int fb_setup_single(struct vo *vo, int fd, struct framebuffer *buf)
+static bool fb_setup_single(struct vo *vo, int fd, struct framebuffer *buf)
{
- int ret = 0;
-
buf->handle = 0;
// create dumb buffer
@@ -112,34 +110,28 @@ static int fb_setup_single(struct vo *vo, int fd, struct framebuffer *buf)
.height = buf->height,
.bpp = BITS_PER_PIXEL,
};
- ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &creq);
- if (ret < 0) {
+ if (drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &creq) < 0) {
MP_ERR(vo, "Cannot create dumb buffer: %s\n", mp_strerror(errno));
- ret = -errno;
- goto end;
+ goto err;
}
buf->stride = creq.pitch;
buf->size = creq.size;
buf->handle = creq.handle;
// create framebuffer object for the dumb-buffer
- ret = drmModeAddFB(fd, buf->width, buf->height, 24, creq.bpp, buf->stride,
- buf->handle, &buf->fb);
- if (ret) {
+ if (drmModeAddFB(fd, buf->width, buf->height, 24, creq.bpp, buf->stride,
+ buf->handle, &buf->fb)) {
MP_ERR(vo, "Cannot create framebuffer: %s\n", mp_strerror(errno));
- ret = -errno;
- goto end;
+ goto err;
}
// prepare buffer for memory mapping
struct drm_mode_map_dumb mreq = {
.handle = buf->handle,
};
- ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &mreq);
- if (ret) {
+ if (drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &mreq)) {
MP_ERR(vo, "Cannot map dumb buffer: %s\n", mp_strerror(errno));
- ret = -errno;
- goto end;
+ goto err;
}
// perform actual memory mapping
@@ -147,22 +139,18 @@ static int fb_setup_single(struct vo *vo, int fd, struct framebuffer *buf)
fd, mreq.offset);
if (buf->map == MAP_FAILED) {
MP_ERR(vo, "Cannot map dumb buffer: %s\n", mp_strerror(errno));
- ret = -errno;
- goto end;
+ goto err;
}
memset(buf->map, 0, buf->size);
+ return true;
-end:
- if (ret == 0) {
- return 0;
- }
-
+err:
fb_destroy(fd, buf);
- return ret;
+ return false;
}
-static int fb_setup_double_buffering(struct vo *vo)
+static bool fb_setup_double_buffering(struct vo *vo)
{
struct priv *p = vo->priv;
@@ -173,18 +161,17 @@ static int fb_setup_double_buffering(struct vo *vo)
}
for (unsigned int i = 0; i < BUF_COUNT; i++) {
- int ret = fb_setup_single(vo, p->kms->fd, &p->bufs[i]);
- if (ret) {
+ if (!fb_setup_single(vo, p->kms->fd, &p->bufs[i])) {
MP_ERR(vo, "Cannot create framebuffer for connector %d\n",
p->kms->connector->connector_id);
for (unsigned int j = 0; j < i; j++) {
fb_destroy(p->kms->fd, &p->bufs[j]);
}
- return ret;
+ return false;
}
}
- return 0;
+ return true;
}
static void page_flipped(int fd, unsigned int frame, unsigned int sec,
@@ -194,11 +181,11 @@ static void page_flipped(int fd, unsigned int frame, unsigned int sec,
p->pflip_happening = false;
}
-static int crtc_setup(struct vo *vo)
+static bool crtc_setup(struct vo *vo)
{
struct priv *p = vo->priv;
if (p->active)
- return 0;
+ return true;
p->old_crtc = drmModeGetCrtc(p->kms->fd, p->kms->crtc_id);
int ret = drmModeSetCrtc(p->kms->fd, p->kms->crtc_id,
p->bufs[p->front_buf + BUF_COUNT - 1].fb,
@@ -208,7 +195,7 @@ static int crtc_setup(struct vo *vo)
1,
&p->kms->mode);
p->active = true;
- return ret;
+ return ret == 0;
}
static void crtc_release(struct vo *vo)
@@ -434,7 +421,7 @@ static int preinit(struct vo *vo)
p->ev.version = DRM_EVENT_CONTEXT_VERSION;
p->ev.page_flip_handler = page_flipped;
- p->vt_switcher_active = vt_switcher_init(&p->vt_switcher, vo->log) == 0;
+ p->vt_switcher_active = vt_switcher_init(&p->vt_switcher, vo->log);
if (p->vt_switcher_active) {
vt_switcher_acquire(&p->vt_switcher, acquire_vt, vo);
vt_switcher_release(&p->vt_switcher, release_vt, vo);
@@ -448,12 +435,12 @@ static int preinit(struct vo *vo)
goto err;
}
- if (kms_setup(p->kms, p->device_path, p->connector_id, p->mode_id)) {
+ if (!kms_setup(p->kms, p->device_path, p->connector_id, p->mode_id)) {
MP_ERR(vo, "Failed to configure KMS.\n");
goto err;
}
- if (fb_setup_double_buffering(vo)) {
+ if (!fb_setup_double_buffering(vo)) {
MP_ERR(vo, "Failed to set up double buffering.\n");
goto err;
}
@@ -467,7 +454,7 @@ static int preinit(struct vo *vo)
p->device_w = p->bufs[0].width;
p->device_h = p->bufs[0].height;
- if (crtc_setup(vo)) {
+ if (!crtc_setup(vo)) {
MP_ERR(vo,
"Cannot set CRTC for connector %u: %s\n",
p->kms->connector->connector_id,