Browse files

Installing pytee's modification of MPlayer

  • Loading branch information...
1 parent 7cffc58 commit 8d3731974c3188eabb1e4e9ea1485da35c2c654f @KonishchevDmitry committed Apr 6, 2012
Showing with 100 additions and 64 deletions.
  1. +50 −24 Makefile
  2. +50 −40 mplayer/process.py
View
74 Makefile
@@ -1,33 +1,54 @@
-.PHONY: all clean distclean install uninstall
-.PHONY: install-desktop install-icons
-.PHONY: uninstall-desktop uninstall-icons
+.PHONY: all build clean distclean install uninstall
+.PHONY: clean-mplayer distclean-mplayer mplayer
+.PHONY: install-desktop install-icons install-mplayer
+.PHONY: uninstall-desktop uninstall-icons uninstall-mplayer
+
+program_unix_name := pytee
PREFIX := /usr
bindir := $(PREFIX)/bin
datarootdir := $(PREFIX)/share
+libexecdir := $(PREFIX)/libexec
+datadir := $(datarootdir)/$(program_unix_name)
+
+mplayer_srcdir := mplayer/mplayer
+mplayer_dir := $(libexecdir)/$(program_unix_name)
system := $(shell uname -s)
-program_unix_name := pytee
-data_dir := $(datarootdir)/$(program_unix_name)
-all:
+all: build
ifeq ($(system),Darwin)
+build: mplayer
+clean: clean-mplayer
+distclean: distclean-mplayer
+install: install-mplayer
+uninstall: uninstall-mplayer
else
install: install-desktop install-icons
-install: uninstall-desktop uninstall-icons
+uninstall: uninstall-desktop uninstall-icons
endif
-install: all
+build:
+
+mplayer: $(mplayer_srcdir)/config.mak
+ make -C $(mplayer_srcdir) -j4
+
+$(mplayer_srcdir)/config.mak: Makefile
+ cd $(mplayer_srcdir) && ./configure --prefix=$(mplayer_dir) --bindir=$(mplayer_dir) \
+ --disable-mencoder --disable-dvdread --disable-dvdread-internal --disable-networking
+
+
+install: build
set -e; for file in mplayer/*.py $$(find pycl pysd pytee subtitles -name '*.py'; find icons -name '*.png' -o -name '*.svg'); do \
- install -d $(DESTDIR)$(data_dir)/$$(dirname $$file); \
- install -m 0644 $$file $(DESTDIR)$(data_dir)/$$file; \
+ install -d $(DESTDIR)$(datadir)/$$(dirname $$file); \
+ install -m 0644 $$file $(DESTDIR)$(datadir)/$$file; \
done
install -d $(DESTDIR)$(bindir)
- echo '#!/bin/sh\nexec $(data_dir)/$(program_unix_name)/main.py "$$@"' > $(DESTDIR)$(bindir)/$(program_unix_name)
- chmod a+x $(DESTDIR)$(data_dir)/$(program_unix_name)/main.py
+ echo '#!/bin/sh\nexec $(datadir)/$(program_unix_name)/main.py "$$@"' > $(DESTDIR)$(bindir)/$(program_unix_name)
+ chmod a+x $(DESTDIR)$(datadir)/$(program_unix_name)/main.py
chmod a+x $(DESTDIR)$(bindir)/$(program_unix_name)
install-desktop:
@@ -40,21 +61,16 @@ install-icons:
install -d $(DESTDIR)$(datarootdir)/applications
install -m 0644 $(program_unix_name).desktop $(DESTDIR)$(datarootdir)/applications/$(program_unix_name).desktop
+install-mplayer: mplayer
+ make -C $(mplayer_srcdir) install
+
uninstall:
set -e; for file in mplayer/*.py $$(find pycl pysd pytee subtitles -name '*.py'; find icons -name '*.png' -o -name '*.svg'); do \
- rm -f $(DESTDIR)$(data_dir)/$$file; \
+ rm -f $(DESTDIR)$(datadir)/$$file; \
done
- set -e; while true; do \
- if [ $${removed:-1} -eq 0 ]; then \
- break; \
- fi; \
- removed=0; \
- if [ -d $(DESTDIR)$(data_dir) ]; then \
- for dir in $$(find $(DESTDIR)$(data_dir) -type d -empty); do \
- rmdir $$dir; let removed+=1; \
- done; \
- fi; \
+ set -e; for dir in "$(DESTDIR)$(datadir)" "$(DESTDIR)$(mplayer_dir)"; do \
+ [ ! -d "$$dir" ] || rmdir -p "$$dir"; \
done
rm -f $(DESTDIR)$(bindir)/$(program_unix_name)
@@ -66,7 +82,17 @@ uninstall-icons:
rm -f $(DESTDIR)$(datarootdir)/icons/hicolor/$${file#*/}; \
done
+uninstall-mplayer:
+ make -C $(mplayer_srcdir) uninstall
+
clean:
-distclean: clean
+clean-mplayer:
+ make -C $(mplayer_srcdir) clean
+
+
+distclean:
+
+distclean-mplayer:
+ make -C $(mplayer_srcdir) distclean
View
90 mplayer/process.py
@@ -90,9 +90,6 @@ class MPlayer(QtCore.QObject):
__shm_name = None
"""MPlayer's shared memory name."""
- __shm_fd = -1
- """MPlayer's shared memory descriptor."""
-
__shm_memory = None
"""MPlayer's shared memory."""
@@ -141,39 +138,60 @@ def get_movie_image(self):
height = movie.get_height()
try:
- while self.__shm_fd < 0:
- self.__shm_fd = libc.shm_open(self.__shm_name, os.O_RDONLY)
- if self.__shm_fd < 0 and ctypes.get_errno() != errno.EINTR:
- (LOG.debug if ctypes.get_errno() == errno.ENOENT else LOG.error)(
- "Unable to open the MPlayer's shared memory buffer: %s.", os.strerror(ctypes.get_errno()))
- return QtGui.QImage(width, height, QtGui.QImage.Format_RGB888)
+ while True:
+ fd = libc.shm_open(self.__shm_name, os.O_RDONLY)
+
+ if fd < 0:
+ if ctypes.get_errno() != errno.EINTR:
+ (LOG.debug if ctypes.get_errno() == errno.ENOENT else LOG.error)(
+ "Unable to open the MPlayer's shared memory buffer: %s.", os.strerror(ctypes.get_errno()))
+ return QtGui.QImage(width, height, QtGui.QImage.Format_RGB888)
+ else:
+ break
+
+ try:
+ image_size = 3 * width * height
- image_size = 3 * width * height
+ if self.__shm_memory is None:
+ # TODO FIXME
+ memory_size = os.fstat(fd).st_size
+ memory_size = image_size
+ #if memory_size != image_size:
+ # raise Error("MPlayer created shared memory of invalid size ({0} vs {1}).", memory_size, image_size)
- if self.__shm_memory is None:
- memory_size = os.fstat(self.__shm_fd).st_size
- if memory_size != image_size:
- raise Error("MPlayer created shared memory of invalid size ({0} vs {1}).", memory_size, image_size)
+ self.__shm_memory = mmap.mmap(fd, memory_size, mmap.MAP_SHARED, mmap.PROT_READ)
+ finally:
+ try:
+ pycl.misc.syscall_wrapper(os.close, fd)
+ except Exception as e:
+ LOG.error("Unable to close the MPlayer's shared memory object: %s.", EE(e))
- self.__shm_memory = mmap.mmap(self.__shm_fd, memory_size, mmap.MAP_SHARED, mmap.PROT_READ)
+# TODO FIXME
+ #image_data = buffer(self.__shm_memory[:image_size], 0, image_size)
+ #image_data = buffer(, 0, image_size)
+ return QtGui.QImage(self.__shm_memory, width, height, 3 * width, QtGui.QImage.Format_RGB888)
- return QtGui.QImage(self.__shm_memory[:image_size], width, height, 3 * width, QtGui.QImage.Format_RGB888)
# TODO: remove
-# #image = QtGui.QPixmap().loadFromData(self.__shm_memory[0:image_size], QtGui.QImage.Format_RGB888).toImage()
-# bmp_header_fmt = "<ccIIIIiiHHIIiiII"
-# bmp_header_size = struct.calcsize(bmp_header_fmt)
-# bmp_header = struct.pack(bmp_header_fmt,
-# "B", "M", bmp_header_size + image_size, 0, bmp_header_size,
-# 40, movie.get_width(), -movie.get_height(), 1, 24, 0, 0, 2000, 2000, 0, 0)
-# bmp_image = bmp_header
-# for i in xrange(0, image_size / 3):
-# bmp_image += image_data[i * 3+2:i * 3 + 3]
-# bmp_image += image_data[i * 3+1:i * 3 + 2]
-# bmp_image += image_data[i * 3:i * 3 + 1]
-# #open("out.bmp", "w").write(bmp_image)
-# image.loadFromData(bmp_image)
+# import struct
+# image_data = self.__shm_memory[:image_size]
+# bmp_header_fmt = "<ccIIIIiiHHIIiiII"
+# bmp_header_size = struct.calcsize(bmp_header_fmt)
+# bmp_header = struct.pack(bmp_header_fmt,
+# "B", "M", bmp_header_size + image_size, 0, bmp_header_size,
+# 40, movie.get_width(), -movie.get_height(), 1, 24, 0, 0, 2000, 2000, 0, 0)
+# bmp_image = bmp_header
+# for i in xrange(0, image_size / 3):
+# bmp_image += image_data[i * 3+2:i * 3 + 3]
+# bmp_image += image_data[i * 3+1:i * 3 + 2]
+# bmp_image += image_data[i * 3:i * 3 + 1]
+# #open("out.bmp", "w").write(bmp_image)
+# image = QtGui.QImage(width, height, QtGui.QImage.Format_RGB888)
+# image.loadFromData(bmp_image)
+# return image
except Exception as e:
- LOG.error("Failed to get the movie image: %s", e)
+ # TODO FIXME
+ #LOG.error("Failed to get the movie image: %s", e)
+ LOG.exception("Failed to get the movie image: %s", e)
return QtGui.QImage(width, height, QtGui.QImage.Format_RGB888)
@@ -257,14 +275,6 @@ def terminate(self):
finally:
self.__shm_memory = None
- if self.__shm_fd >= 0:
- try:
- pycl.misc.syscall_wrapper(os.close, self.__shm_fd)
- except Exception as e:
- LOG.error("Unable to close the MPlayer's shared memory object: %s.", EE(e))
- finally:
- self.__shm_fd = -1
-
self.__shm_name = None
if prev_state == "running":
@@ -382,7 +392,7 @@ def __run(self, movie_path, video_output, start_from, paused):
args = [
# TODO
- os.path.expanduser("~/mplayer/bin/mplayer") if pycl.main.is_osx() else "/usr/bin/mplayer",
+ os.path.expanduser("~/pytee/libexec/pytee/mplayer") if pycl.main.is_osx() else "/usr/bin/mplayer",
"-framedrop",
"-slave", "-quiet",
@@ -397,7 +407,7 @@ def __run(self, movie_path, video_output, start_from, paused):
]
if pycl.main.is_osx():
- args += [ "-vo", "corevideo:shared_buffer:buffer_name=" + video_output ]
+ args += [ "-vo", "corevideo:shared_buffer:rgb_only:buffer_name=" + video_output ]
else:
args += [
# Forcing XV driver usage to disable VDPAU which may cause

0 comments on commit 8d37319

Please sign in to comment.