Update of /cvsroot/freevo/freevo/src/video/plugins
In directory sc8-pr-cvs1:/tmp/cvs-serv13722
Modified Files:
mplayer.py
Added Files:
bmovl.py
Log Message:
Removed the unstable bmovl part from mplayer.py and made it a plugin.
Even if we are in a code freeze, this is a major cleanup to put the
unstable stuff in a plugin to prevent mplayer from crashing because of
bmovl.
--- NEW FILE: bmovl.py ---
#if 0 /*
# -----------------------------------------------------------------------
# bmovl.py - bmovl plugin for Freevo MPlayer module for video
# -----------------------------------------------------------------------
# $Id: bmovl.py,v 1.1 2003/11/04 17:53:23 dischi Exp $
#
# Notes:
# Todo:
#
# -----------------------------------------------------------------------
# $Log: bmovl.py,v $
# Revision 1.1 2003/11/04 17:53:23 dischi
# Removed the unstable bmovl part from mplayer.py and made it a plugin.
# Even if we are in a code freeze, this is a major cleanup to put the
# unstable stuff in a plugin to prevent mplayer from crashing because of
# bmovl.
#
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002 Krister Lagerstrom, et al.
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# 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 MER-
# CHANTABILITY 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, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------- */
#endif
import os
import time
import config
import plugin
import osd
import skin
import pygame
from osd import OSD
from event import *
osd = osd.get_singleton()
class OSDbmovl(OSD):
"""
an OSD class for bmovl
"""
def __init__(self, width, height):
self.width = width
self.height = height
self.depth = 32
self.screen = pygame.Surface((width, height), SRCALPHA)
# clear surface
self.screen.fill((0,0,0,0))
self.bmovl = os.open('/tmp/bmovl', os.O_WRONLY)
def close(self):
os.close(self.bmovl)
def show(self):
os.write(self.bmovl, 'SHOW\n')
def hide(self):
os.write(self.bmovl, 'HIDE\n')
def clearscreen(self, color=None):
self.screen.fill((0,0,0,0))
os.write(self.bmovl, 'CLEAR %s %s %s %s' % (self.width, self.height, 0, 0))
def update(self, rect):
_debug_('update bmovl')
update = self.screen.subsurface(rect)
os.write(self.bmovl, 'RGBA32 %d %d %d %d %d %d\n' % \
(update.get_width(), update.get_height(), rect[0], rect[1], 0, 0))
os.write(self.bmovl, pygame.image.tostring(update, 'RGBA'))
class PluginInterface(plugin.Plugin):
def __init__(self):
plugin.Plugin.__init__(self)
self._type = 'mplayer_video'
def play(self, command, player):
self.item = player.item
self.player = player
self.osd_visible = False
self.bmovl = None
if os.path.exists('/tmp/bmovl'):
return command + [ '-vf', 'bmovl=1:0:/tmp/bmovl' ]
return command
def show_osd(self):
"""
bmovl: init bmovl osd and show it
"""
_debug_('show osd')
height = config.OVERSCAN_Y + 60
if not skin.get_singleton().settings.images.has_key('background'):
_debug_('no background')
return
bg = self.bmovl.loadbitmap(skin.get_singleton().settings.images['background'])
bg = pygame.transform.scale(bg, (self.bmovl.width, self.bmovl.height))
self.bmovl.screen.blit(bg, (0,0))
# bar at the top:
self.bmovl.drawbox(0, height-1, osd.width, height-1, width=1, color=0x000000)
clock = time.strftime('%a %I:%M %P')
clock_font = skin.get_singleton().GetFont('clock')
clock_width = clock_font.font.stringsize(clock)
self.bmovl.drawstringframed(clock,
self.bmovl.width-config.OVERSCAN_X-10-clock_width,
config.OVERSCAN_Y+10, clock_width, -1,
clock_font.font, clock_font.color)
self.bmovl.update((0, 0, self.bmovl.width, height))
# bar at the bottom
height += 40
x0 = config.OVERSCAN_X+10
y0 = self.bmovl.height + 5 - height
width = self.bmovl.width - 2 * config.OVERSCAN_X
self.bmovl.drawbox(0, self.bmovl.height + 1 - height, self.bmovl.width,
self.bmovl.height + 1 - height, width=1, color=0x000000)
if self.item.image:
image = pygame.transform.scale(self.bmovl.loadbitmap(self.item.image),
(65, 90))
self.bmovl.screen.blit(image, (x0, y0))
x0 += image.get_width() + 10
width -= image.get_width() + 10
title = self.item.name
tagline = self.item.getattr('tagline')
if self.item.tv_show:
show = config.TV_SHOW_REGEXP_SPLIT(self.item.name)
title = show[0] + " " + show[1] + "x" + show[2]
tagline = show[3]
title_font = skin.get_singleton().GetFont('title')
tagline_font = skin.get_singleton().GetFont('info tagline')
pos = self.bmovl.drawstringframed(title, x0, y0, width, -1, title_font.font,
title_font.color)
if tagline:
self.bmovl.drawstringframed(tagline, x0, pos[1][3]+5, width, -1,
tagline_font.font, tagline_font.color)
self.bmovl.update((0, self.bmovl.height-height, self.bmovl.width, height))
# and show it
self.bmovl.show()
def hide_osd(self):
"""
bmovl: hide osd
"""
_debug_('hide')
self.player.thread.app.refresh = None
self.bmovl.clearscreen()
self.bmovl.hide()
def stop(self):
if self.bmovl:
self.bmovl.close()
self.bmovl = None
def eventhandler(self, event):
if event == TOGGLE_OSD and self.bmovl:
if self.osd_visible:
self.player.thread.app.write('osd 1\n')
self.hide_osd()
else:
self.show_osd()
self.player.thread.app.write('osd 3\n')
self.osd_visible = not self.osd_visible
return True
def stdout(self, line):
if self.bmovl:
return
try:
if line.find('SwScaler:') ==0 and line.find(' -> ') > 0 and \
line[line.find(' -> '):].find('x') > 0:
width, height = line[line.find(' -> ')+4:].split('x')
self.bmovl = OSDbmovl(int(width), int(height))
if line.find('Expand: ') == 0:
width, height = line[7:line.find(',')].split('x')
self.bmovl = OSDbmovl(int(width), int(height))
except:
pass
Index: mplayer.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/video/plugins/mplayer.py,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** mplayer.py 1 Nov 2003 20:51:49 -0000 1.37
--- mplayer.py 4 Nov 2003 17:53:23 -0000 1.38
***************
*** 6,24 ****
#
# Notes:
- # Perhaps we should move the filetype specific stuff (like the one for vob)
- # into the config files...
- #
- # i.e.
- #
- # MP_CUSTOM = {
- # '.vob' = '-ac hwac3 ...',
- # '.rm' = '-forceidx',
- # ...
- # }
- #
# Todo:
#
# -----------------------------------------------------------------------
# $Log$
# Revision 1.37 2003/11/01 20:51:49 dischi
# fix bug in delay
--- 6,19 ----
#
# Notes:
# Todo:
#
# -----------------------------------------------------------------------
# $Log$
+ # Revision 1.38 2003/11/04 17:53:23 dischi
+ # Removed the unstable bmovl part from mplayer.py and made it a plugin.
+ # Even if we are in a code freeze, this is a major cleanup to put the
+ # unstable stuff in a plugin to prevent mplayer from crashing because of
+ # bmovl.
+ #
# Revision 1.37 2003/11/01 20:51:49 dischi
# fix bug in delay
***************
*** 50,82 ****
# enable it. You need mmpython > 0.2 to make it work.
#
- # Revision 1.29 2003/10/02 10:24:33 dischi
- # bmovl update
- #
- # Revision 1.28 2003/10/01 22:30:10 dischi
- # some bmovl fixes, you must use software scale with expand to make it work
- #
- # Revision 1.27 2003/10/01 20:39:34 dischi
- # bmovl support
- #
- # Revision 1.24 2003/09/20 17:03:20 dischi
- # draw status while connecting and caching for network files
- #
- # Revision 1.23 2003/09/19 22:09:15 dischi
- # use new childapp thread function
- #
- # Revision 1.22 2003/09/18 17:09:54 gsbarbieri
- # Faster version detection + handle for CVS versions.
- #
- # Revision 1.21 2003/09/14 20:09:37 dischi
- # removed some TRUE=1 and FALSE=0 add changed some debugs to _debug_
- #
- # Revision 1.20 2003/09/03 17:54:38 dischi
- # Put logfiles into LOGDIR not $FREEVO_STARTDIR because this variable
- # doesn't exist anymore.
- #
- # Revision 1.19 2003/09/02 19:10:22 dischi
- # Basic mplayer version detection. Convert -vop to -vf if cvs or 1.0pre1
- # is used
- #
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
--- 45,48 ----
***************
*** 118,127 ****
import osd
- from osd import OSD
osd = osd.get_singleton()
- import skin
- import pygame
-
class PluginInterface(plugin.Plugin):
"""
--- 84,89 ----
***************
*** 158,203 ****
- class OSDbmovl(OSD):
- """
- an OSD class for bmovl
- """
- def __init__(self, width, height):
- self.width = width
- self.height = height
- self.depth = 32
- self.screen = pygame.Surface((width, height), SRCALPHA)
-
- # clear surface
- self.screen.fill((0,0,0,0))
-
- self.bmovl = os.open('/tmp/bmovl', os.O_WRONLY)
-
-
- def close(self):
- os.close(self.bmovl)
-
-
- def show(self):
- os.write(self.bmovl, 'SHOW\n')
-
-
- def hide(self):
- os.write(self.bmovl, 'HIDE\n')
-
-
- def clearscreen(self, color=None):
- self.screen.fill((0,0,0,0))
- os.write(self.bmovl, 'CLEAR %s %s %s %s' % (self.width, self.height, 0, 0))
-
-
- def update(self, rect):
- _debug_('update bmovl')
- update = self.screen.subsurface(rect)
- os.write(self.bmovl, 'RGBA32 %d %d %d %d %d %d\n' % \
- (update.get_width(), update.get_height(), rect[0], rect[1], 0, 0))
- os.write(self.bmovl, pygame.image.tostring(update, 'RGBA'))
-
-
-
class MPlayer:
"""
--- 120,123 ----
***************
*** 235,240 ****
self.filename = filename
!
! self.mode = mode # setting global var to mode.
_debug_('MPlayer.play(): mode=%s, filename=%s' % (mode, filename))
--- 155,159 ----
self.filename = filename
! self.mode = mode
_debug_('MPlayer.play(): mode=%s, filename=%s' % (mode, filename))
***************
*** 298,301 ****
--- 217,221 ----
' ' + config.MPLAYER_ARGS[mode])
+ # make the options a list
mpl = mpl.split(' ') + [ filename ] + additional_args.split(' ')
***************
*** 308,315 ****
elif not '-framedrop' in mpl:
mpl += config.MPLAYER_SOFTWARE_SCALER.split(' ')
-
- if os.path.exists('/tmp/bmovl') and config.MPLAYER_SOFTWARE_SCALER:
- mpl += ('-vf', 'bmovl=1:0:/tmp/bmovl')
if config.MPLAYER_SET_AUDIO_DELAY and item.info.has_key('delay') and \
item.info['delay'] > 0:
--- 228,233 ----
elif not '-framedrop' in mpl:
mpl += config.MPLAYER_SOFTWARE_SCALER.split(' ')
+ # correct avi delay based on mmpython settings
if config.MPLAYER_SET_AUDIO_DELAY and item.info.has_key('delay') and \
item.info['delay'] > 0:
***************
*** 322,325 ****
--- 240,244 ----
command.remove('')
+ # autocrop
if config.MPLAYER_AUTOCROP and str(' ').join(command).find('crop=') == -1:
_debug_('starting autocrop')
***************
*** 345,348 ****
--- 264,275 ----
child.wait()
+ self.file = item
+ self.item = item
+
+ self.plugins = plugin.get('mplayer_video')
+
+ for p in self.plugins:
+ command = p.play(command, self)
+
command=self.vop_append(command)
***************
*** 350,358 ****
plugin.getbyname('MIXER').reset()
- self.file = item
- self.osd_visible = False
- self.item = item
- self.bmovl = None
-
rc.app(self)
--- 277,280 ----
***************
*** 363,443 ****
- def show_osd(self):
- """
- bmovl: init bmovl osd and show it
- """
- _debug_('show osd')
-
- height = config.OVERSCAN_Y + 60
- if not skin.get_singleton().settings.images.has_key('background'):
- _debug_('no background')
- return
-
- bg =
self.bmovl.loadbitmap(skin.get_singleton().settings.images['background'])
- bg = pygame.transform.scale(bg, (self.bmovl.width, self.bmovl.height))
-
- self.bmovl.screen.blit(bg, (0,0))
-
- # bar at the top:
- self.bmovl.drawbox(0, height-1, osd.width, height-1, width=1, color=0x000000)
-
- clock = time.strftime('%a %I:%M %P')
- clock_font = skin.get_singleton().GetFont('clock')
- clock_width = clock_font.font.stringsize(clock)
-
- self.bmovl.drawstringframed(clock,
self.bmovl.width-config.OVERSCAN_X-10-clock_width,
- config.OVERSCAN_Y+10, clock_width, -1,
- clock_font.font, clock_font.color)
-
- self.bmovl.update((0, 0, self.bmovl.width, height))
-
- # bar at the bottom
- height += 40
- x0 = config.OVERSCAN_X+10
- y0 = self.bmovl.height + 5 - height
- width = self.bmovl.width - 2 * config.OVERSCAN_X
-
- self.bmovl.drawbox(0, self.bmovl.height + 1 - height, self.bmovl.width,
- self.bmovl.height + 1 - height, width=1, color=0x000000)
-
- if self.item.image:
- image = pygame.transform.scale(self.bmovl.loadbitmap(self.item.image),
(65, 90))
- self.bmovl.screen.blit(image, (x0, y0))
- x0 += image.get_width() + 10
- width -= image.get_width() + 10
-
- title = self.item.name
- tagline = self.item.getattr('tagline')
-
- if self.item.tv_show:
- show = config.TV_SHOW_REGEXP_SPLIT(self.item.name)
- title = show[0] + " " + show[1] + "x" + show[2]
- tagline = show[3]
-
- title_font = skin.get_singleton().GetFont('title')
- tagline_font = skin.get_singleton().GetFont('info tagline')
-
- pos = self.bmovl.drawstringframed(title, x0, y0, width, -1, title_font.font,
- title_font.color)
- if tagline:
- self.bmovl.drawstringframed(tagline, x0, pos[1][3]+5, width, -1,
- tagline_font.font, tagline_font.color)
-
- self.bmovl.update((0, self.bmovl.height-height, self.bmovl.width, height))
-
- # and show it
- self.bmovl.show()
-
-
- def hide_osd(self):
- """
- bmovl: hide osd
- """
- _debug_('hide')
- self.thread.app.refresh = None
- self.bmovl.clearscreen()
- self.bmovl.hide()
-
-
def stop(self):
"""
--- 285,288 ----
***************
*** 446,452 ****
self.thread.stop('quit\n')
rc.app(None)
! if self.bmovl:
! self.bmovl.close()
! self.bmovl = None
--- 291,296 ----
self.thread.stop('quit\n')
rc.app(None)
! for p in self.plugins:
! command = p.stop()
***************
*** 457,460 ****
--- 301,308 ----
"""
+ for p in self.plugins:
+ if p.eventhandler(event):
+ return True
+
if event == VIDEO_MANUAL_SEEK:
self.seek = 0
***************
*** 498,511 ****
return self.item.eventhandler(event)
- if event == TOGGLE_OSD and self.bmovl:
- if self.osd_visible:
- self.thread.app.write('osd 1\n')
- self.hide_osd()
- else:
- self.show_osd()
- self.thread.app.write('osd 3\n')
- self.osd_visible = not self.osd_visible
- return True
-
try:
if event == VIDEO_SEND_MPLAYER_CMD:
--- 346,349 ----
***************
*** 537,540 ****
--- 375,379 ----
self.seek = 0
rc.set_context('video')
+
def reset_seek_timeout(self):
***************
*** 542,545 ****
--- 381,385 ----
self.seek_timer = threading.Timer(config.MPLAYER_SEEK_TIMEOUT,
self.reset_seek)
self.seek_timer.start()
+
def vop_append(self, command):
***************
*** 605,626 ****
self.item = item
self.mplayer = mplayer
self.osdfont = osd.getfont(config.OSD_DEFAULT_FONTNAME,
config.OSD_DEFAULT_FONTSIZE)
childapp.ChildApp.__init__(self, app)
- self.exit_type = None
! self.use_bmovl = False
! pos = 0
! if '-vop' in app:
! pos = app.index('-vop')
! if '-vf' in app:
! pos = app.index('-vf')
! if pos and app[pos+1].find('/tmp/bmovl') > 0:
! print 'Found /tmp/bmovl, activating experimental bmovl support'
! self.use_bmovl = True
!
!
def kill(self):
# Use SIGINT instead of SIGKILL to make sure MPlayer shuts
--- 445,466 ----
self.item = item
self.mplayer = mplayer
+ self.exit_type = None
self.osdfont = osd.getfont(config.OSD_DEFAULT_FONTNAME,
config.OSD_DEFAULT_FONTSIZE)
+ # check for mplayer plugins
+ self.stdout_plugins = []
+ self.elapsed_plugins = []
+ for p in plugin.get('mplayer_video'):
+ if hasattr(p, 'stdout'):
+ self.stdout_plugins.append(p)
+ if hasattr(p, 'elapsed'):
+ self.elapsed_plugins.append(p)
+
+ # init the child (== start the threads)
childapp.ChildApp.__init__(self, app)
!
def kill(self):
# Use SIGINT instead of SIGKILL to make sure MPlayer shuts
***************
*** 646,655 ****
def stdout_cb(self, line):
if config.MPLAYER_DEBUG:
try:
self.log_stdout.write(line + '\n')
except ValueError:
! pass # File closed
if self.network_play:
if line.find('Opening audio decoder') == 0:
--- 486,499 ----
def stdout_cb(self, line):
+ """
+ parse the stdout of the mplayer process
+ """
if config.MPLAYER_DEBUG:
try:
self.log_stdout.write(line + '\n')
except ValueError:
! pass
+ # show connection status for network play
if self.network_play:
if line.find('Opening audio decoder') == 0:
***************
*** 662,689 ****
line = 'Connecting to server'
osd.clearscreen(osd.COL_BLACK)
! osd.drawstringframed(line, config.OVERSCAN_X, config.OVERSCAN_Y,
! osd.width - 2 * config.OVERSCAN_X, -1,
self.osdfont,
! osd.COL_WHITE)
osd.update()
! # experimental for bmovl, may crash
! try:
! if line.find('SwScaler:') ==0 and line.find(' -> ') > 0 and \
! line[line.find(' -> '):].find('x') > 0 and self.use_bmovl:
! width, height = line[line.find(' -> ')+4:].split('x')
! self.mplayer.bmovl = OSDbmovl(int(width), int(height))
! self.use_bmovl = False
! if line.find('Expand: ') == 0 and self.use_bmovl:
! width, height = line[7:line.find(',')].split('x')
! self.mplayer.bmovl = OSDbmovl(int(width), int(height))
! self.use_bmovl = False
! except:
! pass
!
if line.find("A:") == 0:
! m = self.RE_TIME(line) # Convert decimal
if hasattr(m,'group'):
self.item.elapsed = int(m.group(1))+1
!
elif line.find("Exiting...") == 0:
m = self.RE_EXIT(line)
--- 506,525 ----
line = 'Connecting to server'
osd.clearscreen(osd.COL_BLACK)
! osd.drawstringframed(line, config.OVERSCAN_X+10,
config.OVERSCAN_Y+10,
! osd.width - 2 * (config.OVERSCAN_X+10), -1,
! self.osdfont, osd.COL_WHITE)
osd.update()
!
! # current elapsed time
if line.find("A:") == 0:
! m = self.RE_TIME(line)
if hasattr(m,'group'):
self.item.elapsed = int(m.group(1))+1
! for p in self.elapsed_plugins:
! p.elapsed(self.item.elapsed)
!
!
! # exit status
elif line.find("Exiting...") == 0:
m = self.RE_EXIT(line)
***************
*** 691,696 ****
--- 527,536 ----
self.exit_type = m.group(1)
+
# this is the first start of the movie, parse infos
elif not self.item.elapsed:
+ for p in self.stdout_plugins:
+ p.stdout(line)
+
if self.check_audio:
if line.find('MPEG: No audio stream found -> no sound') == 0:
***************
*** 707,711 ****
--- 547,555 ----
+
def stderr_cb(self, line):
+ """
+ parse the stderr of the mplayer process
+ """
if config.MPLAYER_DEBUG:
try:
***************
*** 713,714 ****
--- 557,561 ----
except ValueError:
pass # File closed
+
+ for p in self.stdout_plugins:
+ p.stdout(line)
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog