Permalink
Browse files

Use MPlayer as a display surface (untested!)

  • Loading branch information...
1 parent 70c0e56 commit 6ba940eba2d245ac381e35671de92ea7b55ddc32 @asquared asquared committed Feb 1, 2012
@@ -17,4 +17,5 @@
* along with openreplay. If not, see <http://www.gnu.org/licenses/>.
*/
+%include "mplayer_display_surface.i"
%include "framebuffer_display_surface.i"
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2011 Exavideo LLC.
+ *
+ * This file is part of openreplay.
+ *
+ * openreplay 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * openreplay 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 openreplay. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "mplayer_display_surface.h"
+
+#include <unistd.h>
+#include "posix_util.h"
+
+MplayerDisplaySurface::MplayerDisplaySurface(const char *cmd) {
+ _w = 1920;
+ _h = 1080;
+ _pixel_format = BGRAn8;
+ _pitch = minpitch( );
+ alloc( );
+ make_ops( );
+
+ _fd = fork_mplayer(cmd);
+
+ if (_fd == -1) {
+ throw std::runtime_error("Failed to fork mplayer!");
+ }
+}
+
+MplayerDisplaySurface::~MplayerDisplaySurface( ) {
+ close(_fd);
+}
+
+void MplayerDisplaySurface::flip( ) {
+ write_to_fd(_fd);
+}
+
+int MplayerDisplaySurface::fork_mplayer(const char *cmd) {
+ int pipefd[2];
+
+ if (pipe(pipefd) != 0) {
+ throw POSIXError("pipe");
+ }
+
+ pid_t child = fork( );
+
+ if (child == -1) {
+ throw POSIXError("fork");
+ } else if (child == 0) {
+ close(pipefd[1]);
+ dup2(pipefd[0], STDIN_FILENO);
+
+ execl("/bin/sh", "/bin/sh", "-c", cmd, NULL);
+ perror("execl");
+ _exit(1);
+ } else {
+ close(pipefd[0]);
+ return pipefd[1];
+ }
+}
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2011 Exavideo LLC.
+ *
+ * This file is part of openreplay.
+ *
+ * openreplay 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * openreplay 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 openreplay. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _MPLAYER_DISPLAY_SURFACE_H
+#define _MPLAYER_DISPLAY_SURFACE_H
+
+#include "display_surface.h"
+
+class MplayerDisplaySurface : public DisplaySurface {
+ public:
+ MplayerDisplaySurface(const char *cmd = "mplayer -demuxer rawvideo -rawvideo bgra:w=1920:h=1080 -");
+ ~MplayerDisplaySurface( );
+ virtual void flip( );
+ protected:
+ int _fd;
+ int fork_mplayer(const char *cmd);
+};
+
+
+#endif
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2011 Exavideo LLC.
+ *
+ * This file is part of openreplay.
+ *
+ * openreplay 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * openreplay 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 openreplay. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+%{
+ #include "mplayer_display_surface.h"
+%}
+
+class MplayerDisplaySurface : public DisplaySurface {
+ public:
+ MplayerDisplaySurface(const char * = "mplayer -demuxer rawvideo -rawvideo bgra:w=1920:h=1080 -");
+ ~MplayerDisplaySurface( );
+};
@@ -1,2 +1,4 @@
display_surface_OBJECTS = \
- display_surface/framebuffer_display_surface.o
+ display_surface/framebuffer_display_surface.o \
+ display_surface/mplayer_display_surface.o
+

0 comments on commit 6ba940e

Please sign in to comment.