[xiph-commits] r11797 - trunk/souffleur

daraku at svn.xiph.org daraku at svn.xiph.org
Mon Aug 21 12:11:27 PDT 2006


Author: daraku
Date: 2006-08-21 12:11:06 -0700 (Mon, 21 Aug 2006)
New Revision: 11797

Modified:
   trunk/souffleur/GPlayer.py
   trunk/souffleur/SouffleurXML.py
   trunk/souffleur/Subtitles.py
   trunk/souffleur/streams.py
Log:
Code clean and coments add for Subtitles.py
Coments add to the streams.py
Coments add to the SouffleurXML.py
Coments add to the GPlayer.py


Modified: trunk/souffleur/GPlayer.py
===================================================================
--- trunk/souffleur/GPlayer.py	2006-08-21 02:55:45 UTC (rev 11796)
+++ trunk/souffleur/GPlayer.py	2006-08-21 19:11:06 UTC (rev 11797)
@@ -15,8 +15,6 @@
 import pygtk
 pygtk.require('2.0')
 
-#import sys
-
 import gobject
 gobject.threads_init()
 
@@ -26,7 +24,16 @@
 import gst.interfaces
 import gtk
 
+## \file GPlayer.py
+# Documentation for GPlayer module of Souffleur project.
+# \todo Add better seeking.
+
+
+## GstPlayer class.
+# Class for playing media in GStreamer.
 class GstPlayer:
+    ## Construstor
+    # \param videowidget - VideoWidget class.
     def __init__(self, videowidget):
         self.playing = False
         self.player = gst.element_factory_make("playbin", "player")
@@ -38,33 +45,48 @@
         bus.connect('sync-message::element', self.on_sync_message)
         bus.connect('message', self.on_message)
 
+    ## \var playing
+    # Bool variable, TRUE - if media is playing.
+    
+    ## \var player
+    # GStreamer playerbin element.
+    
+    ## \var videowidget
+    # GTK+ widget for video render.
+    
+#==============================================================================
     def on_sync_message(self, bus, message):
         if message.structure is None:
             return
         if message.structure.get_name() == 'prepare-xwindow-id':
             self.videowidget.set_sink(message.src)
             message.src.set_property('force-aspect-ratio', True)
-            
+
+#==============================================================================
     def on_message(self, bus, message):
         t = message.type
         if t == gst.MESSAGE_ERROR:
             err, debug = message.parse_error()
             print "Error: %s" % err, debug
-            #if self.on_eos:
-            #    self.on_eos()
             self.playing = False
         elif t == gst.MESSAGE_EOS:
-            #if self.on_eos:
-            #    self.on_eos()
             self.playing = False
 
+#==============================================================================
+    ## Set location.
+    # Set location of the source.
+    # \param location - URI of the source.
     def set_location(self, location):
         self.player.set_state(gst.STATE_NULL)
         self.player.set_property('uri', location)
 
+#==============================================================================
+    ## Get location.
+    # Get location of the source.
     def get_location(self):
         return self.player.get_property('uri')
 
+#==============================================================================
     def query_position(self):
         "Returns a (position, duration) tuple"
         try:
@@ -79,10 +101,11 @@
 
         return (position, duration)
 
+#==============================================================================
+    ## Seek.
+    # Seek media.
+    # \param location - location to the seek.
     def seek(self, location):
-        """
-        @param location: time to seek to, in nanoseconds
-        """
         gst.debug("seeking to %r" % location)
         event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
             gst.SEEK_FLAG_FLUSH,
@@ -96,33 +119,61 @@
         else:
             gst.error("seek to %r failed" % location)
 
+#==============================================================================
+    ## Pause.
+    # Media pause.
     def pause(self):
         gst.info("pausing player")
         self.player.set_state(gst.STATE_PAUSED)
         self.playing = False
 
+#==============================================================================
+    ## Play.
+    # Media play.
     def play(self):
         gst.info("playing player")
         self.player.set_state(gst.STATE_PLAYING)
         self.playing = True
-        
+
+#==============================================================================
+    ## Stop
+    # Media stop.
     def stop(self):
         self.player.set_state(gst.STATE_NULL)
         self.playing = False
         gst.info("stopped player")
 
+#==============================================================================
+    ## Get state.
+    # Get current state of the media.
+    # \param timeout - time out of the operation.
+    # \raturn state of the media.
     def get_state(self, timeout=1):
         return self.player.get_state(timeout=timeout)
 
+#==============================================================================
+    ## Is playing
+    # \return TRUE if media is playing.
     def is_playing(self):
         return self.playing
 
+#==============================================================================
+## VideoWidget class.
+# VideoWidget class for render video stream on GTK+ widget.
 class VideoWidget:
+    ## Constructor.
+    # \param TArea - GTK+ drowing area widget.
     def __init__(self, TArea):
         self.Area=TArea
         self.imagesink = None
         self.Area.unset_flags(gtk.DOUBLE_BUFFERED)
 
+    ## \var Area
+    # GTK+ drowing area widget.
+    
+    ## \var imagesink
+    # Sink element for 
+
     def do_expose_event(self, event):
         if self.imagesink:
             self.imagesink.expose()

Modified: trunk/souffleur/SouffleurXML.py
===================================================================
--- trunk/souffleur/SouffleurXML.py	2006-08-21 02:55:45 UTC (rev 11796)
+++ trunk/souffleur/SouffleurXML.py	2006-08-21 19:11:06 UTC (rev 11797)
@@ -1,3 +1,7 @@
+## \file SouffleurXML.py
+# Documentation for subtitles module of Souffleur project.
+# \author Maxim Litvinov (aka DarakuTenshi) <otaky at ukr.net>
+
 import xml.dom.minidom
 
 from streams import Media
@@ -6,7 +10,10 @@
 from Subtitles import Sub
 from Subtitles import Subtitles
 
+## ProjectXML class.
+# Class for working whith XML formated project file.
 class ProjectXML:
+    ## Constructor
     def __init__(self):
         self.impl = xml.dom.minidom.getDOMImplementation()
         self.doc = self.impl.createDocument(None, "souffleur", None)
@@ -26,6 +33,29 @@
         self.body = None
         self.version = 0
 
+    ## \var impl
+    # DOMImplementation for XML parsing.
+    
+    ## \var doc
+    # Document XML object.
+    
+    ## \var root
+    # Root element ("souffleur" section) in the object.
+    
+    ## \var head
+    # Object of the "head" section in the XML.
+    
+    ## \var body 
+    # Object of the "body" section in the XML.
+    
+    ## \var version
+    # Version of the pfoject file format.
+
+#==============================================================================
+    ## Load XML file.
+    # Load XML tree from the file.
+    # \param fileName - name of the XML project file.
+    # \return self object or None.
     def load(self, fileName):
         self.root = None
         self.head = None
@@ -44,11 +74,20 @@
                 self.version = i.childNodes[0].nodeValue
         return self
 
+#==============================================================================
+    ## Write XML.
+    # Write XML data to the file.
+    # \param fileName - name of file to store data.
     def write(self, fileName):
         HDLR=file(fileName, "w")
         self.doc.writexml(HDLR)
         HDLR.close()
 
+#==============================================================================
+    ## Add variable head.
+    # Add some variable to the head section.
+    # \param attrName - name of the attribute.
+    # \param attrValue - value of the attribute.
     def addHeadInfo(self, attrName, attrValue):
         if not self.head:
             self.head=self.doc.createElement("head")
@@ -62,6 +101,10 @@
         attrEl.appendChild(attrTxt)
         self.head.appendChild(attrEl)
 
+#==============================================================================
+    ## Add media.
+    # Add media info to the body section.
+    # \param media - Media class instance.
     def addMedia(self, media):
         if not media:
             return
@@ -112,7 +155,10 @@
                 tmpEl.appendChild(tmpTxt)
                 attrs.appendChild(tmpEl)
 
-
+#==============================================================================
+    ## Add subtitles.
+    # Add subtitles to the body section.
+    # \param subtitle - Subtitles class instance.
     def addSubtitle(self, subtitle):
         if not subtitle:
             return
@@ -146,6 +192,10 @@
             sub.appendChild(tmpEl)
             data.appendChild(sub)
 
+#==============================================================================
+    ##Get head
+    # Get list of the head section attributes.
+    # \return list of the attrName => attrValue
     def getHead(self):
         if not self.head:
             return None
@@ -154,6 +204,10 @@
             ret[i.nodeName]=i.childNodes[0].nodeValue
         return ret
 
+#==============================================================================
+    ## Get media.
+    # Get media info from XML.
+    # \return List of the Media class.
     def getMedia(self):
         if not self.body:
             return None
@@ -185,6 +239,10 @@
                 ret.append(tMedia)
         return ret
 
+#==============================================================================
+    ##Get subtitles.
+    # Get subtitles from XML project file.
+    # \raturn Array of the Subtitles.
     def getSubtitle(self):
         if not self.body:
             return None

Modified: trunk/souffleur/Subtitles.py
===================================================================
--- trunk/souffleur/Subtitles.py	2006-08-21 02:55:45 UTC (rev 11796)
+++ trunk/souffleur/Subtitles.py	2006-08-21 19:11:06 UTC (rev 11797)
@@ -1,3 +1,8 @@
+## \file Subtitles.py
+# Documentation for subtitles module of Souffleur project.
+# \author Maxim Litvinov (aka DarakuTenshi) <otaky at ukr.net>
+# \todo Add support of different subtitles format.
+
 import os
 import string
 
@@ -4,29 +9,57 @@
 SUB_NONE=0
 SUB_SRT=1
 
+## Sub class.
+# The Sub class, tha handle subtitle
 class Sub:
+
+    ## Constructor
     def __init__(self):
         self.text=""
         self.start_time=None
         self.end_time=None
-        self.subType=SUB_NONE
         self.Attributes=None
+
 #==============================================================================
+    ## Check subtitle time.
+    # This function check if subtitle visibility in given time.
+    # \param[in] time - time to check
+    # \return 1 - if visibility in time, 0 - otherwise
     def isInTime(self, time):
         if( (time>=self.start_time) and (time<=self.end_time) ):
             return 1
         else:
             return 0
 
+    ## \var text
+    # A variable to store subtitle text
+    
+    ## \var start_time
+    # A variable to store a start time of visibility of subtitle (in ns).
+    
+    ## \var end_time
+    # A variable to store a end time of visibility of subtitle (in ns).
+    
+    ## \var Attributes
+    # A array of attributes of subtitle. (NOT USED YET)
+
 #==============================================================================
-#==============================================================================
+
+## Subtitles calss
+# Class for subtitles stuff (load, save, get...)
 class Subtitles:
+    
+    ## Constructor
     def __init__(self):
         self.subs={}
         self.subSource=None
-        self.subType=SUB_NONE
         self.subKeys=[]
+
 #==============================================================================
+    ## Load subtitles.
+    # Load subtitles from file whith associated stream ID.
+    # \param fileName - name of subtitles file.
+    # \param ID - stream ID.
     def subLoad(self, fileName, ID):
         FILE=os.open(fileName, os.O_RDONLY)
         FS=os.fstat(FILE)
@@ -36,7 +69,12 @@
         self._subSRTLoadFromString(DATA)
 
         self.subSource=ID
-#==============================================================================    
+
+#==============================================================================
+    ## Save subtitles.
+    # Save subtitles to the file.
+    # \param FN - file name.
+    # \param format - the store format of subtitles. (NOT USED YET)
     def subSave(self, FN, format):
         if (self.subSource!=None):
             FUN=os.open(FN,os.O_WRONLY|os.O_CREAT|os.O_TRUNC)
@@ -45,11 +83,9 @@
                 SUB = self.subs[int(i)]
                 Text=str(N)+"\r\n"
                 Hour, Min, Sec, MSec = self._subTime2SRTtime(SUB.start_time)
-                #Text+=str(Hour)+":"+str(Min)+":"+str(Sec)+","+str(MSec)
                 Text+="%02d:%02d:%02d,%03d"%(Hour, Min, Sec, MSec)
                 Text+=" --> "
                 Hour, Min, Sec, MSec = self._subTime2SRTtime(SUB.end_time)
-                #Text+=str(Hour)+":"+str(Min)+":"+str(Sec)+","+str(MSec)+"\n"
                 Text+="%02d:%02d:%02d,%03d"%(Hour, Min, Sec, MSec)+"\r\n"
                 Text+=SUB.text+"\r\n"
                 if (SUB.text[-2]!="\r\n"):
@@ -57,7 +93,12 @@
                 os.write(FUN, Text)
                 N+=1
             os.close(FUN)
+
 #==============================================================================
+    ## Convert subtitle time to SRT format.
+    # Convert subtitle time for saving in SRT subtitles file.
+    # \param time - subtitle time.
+    # \return list of: hour, minute, second and milisecond
     def _subTime2SRTtime(self, time):
         tTime = time
         MSec = tTime%1000
@@ -67,16 +108,18 @@
         Min = tTime%60
         Hour = tTime/60
         return Hour, Min, Sec, MSec
+
 #==============================================================================
+    ## Load SRT formated subtitles.
+    # Load SRT formated subtitles from given string.
+    # \param DATA - string of SRT subtitles.
     def _subSRTLoadFromString(self, DATA):
-        self.subType=SUB_SRT
         if (string.find(DATA, "\r\n")==-1):
             DATA=string.split(DATA,"\n")
         else:
             DATA=string.split(DATA,"\r\n")
         i=0
         while(i<len(DATA)):
-            #i=i+1
             if(i>=len(DATA)):
                 break
             N = DATA[i]
@@ -100,34 +143,55 @@
             TS.text=Text
             TS.start_time=ST
             TS.end_time=ET
-            TS.subType=self.subType
             self.subs[int(ST)]=TS
         self.updateKeys()
+
 #==============================================================================    
+    ## Delete subtitle.
+    # Delete subtitle from subtitles array.
+    # \param time - key of subtitle in "subs" list.
     def subDel(self, time):
         del self.subs[time]
         self.updateKeys()
- #==============================================================================   
+        
+#==============================================================================
+    ## Add subtitle.
+    # Add subtitle to the "subs" list.
+    # \param STime - start time of the subtitle.
+    # \param ETime - end time of the subtitle.
+    # \param Attrs - attributes of the subtitle.
+    # \param isUpdate - to update (or not) keys array of "subs" list.
     def subAdd(self, STime, ETime, Text, Attrs, isUpdate=0):
         TS=Sub()
         TS.text=Text
         TS.start_time=STime
         TS.end_time=ETime
-        TS.subType=self.subType
         TS.Attributes=Attrs
         self.subs[int(STime)]=TS
         if isUpdate==1:
             self.updateKeys()
+
 #==============================================================================    
+    ## Update keys array.
+    # Update array of "subs" keys.
     def updateKeys(self):
         self.subKeys=self.subs.keys()
         self.subKeys.sort()
+
 #==============================================================================
+    ## Update subtitle.
+    # Update subtitle key.
+    # \param upSubKey - subtitle to update.
     def subUpdate(self, upSubKey):
         Sub = self.subs[upSubKey]
         self.subDel(upSubKey)
         self.subAdd(Sub.start_time, Sub.end_time, Sub.text, Sub.Attributes, 1)
+
 #==============================================================================
+    ## Get subtitle.
+    # Get subtitle with given time of visibility.
+    # \param time - time of requested subtitle.
+    # \return subtitle or "None".
     def getSub(self, time):
         i=0
         for i in self.subKeys:
@@ -137,3 +201,12 @@
             else:
                 return None
         return None
+
+    ## \var subs
+    # List of loaded subtitles.
+    
+    ## \var subSource
+    # The source of subtitle 
+    
+    ## \var subKeys
+    # Array of "subs" keys (hashs)

Modified: trunk/souffleur/streams.py
===================================================================
--- trunk/souffleur/streams.py	2006-08-21 02:55:45 UTC (rev 11796)
+++ trunk/souffleur/streams.py	2006-08-21 19:11:06 UTC (rev 11797)
@@ -1,17 +1,44 @@
+## \file streams.py
+# Documentation for streams module of Souffleur project.
+# \author Maxim Litvinov (aka DarakuTenshi) <otaky at ukr.net>
+
+## Stream class
+# Class for geting info on stream
 class Stream:
+    ## Constructor
     def __init__(self):
         self.MIME=None
         self.Name=None
         self.attrs={}
         self.ID=None
     
+    ## Add attribute.
+    # Add attribute on the stream.
+    # \param attrName - name of the attribute.
+    # \param attrValue - value of the attribute.
     def addAttr(self, attrName, attrValue):
         if not attrName or not attrValue:
             return
 
         self.attrs[attrName]=attrValue
 
+    ## \var MIME
+    # MIME type of the stream.
+    
+    ## \var Name
+    # Stream name in the GStreamer.
+    
+    ## \var attrs
+    # List of the attributes.
+    
+    ## \var ID
+    # ID of the stream in Souffleur current project.
+
+
+## Media class.
+# Class for geting info on media.
 class Media:
+    ## Constructor
     def __init__(self):
         self.MIME=None
         self.source=None
@@ -19,6 +46,9 @@
         self.Streams=[]
         self.lastID=0
 
+    ## Add stream.
+    # Add stream to the media.
+    # \param stream - the stream to add.
     def addStream(self, stream):
         if type(stream)!=type(Stream()):
             return
@@ -26,3 +56,18 @@
             return
         self.Streams.append(stream)
         self.lastID=stream.ID
+
+    ## \var MIME
+    # MIME type of the media.
+    
+    ## \var source
+    # Source file name of the media.
+    
+    ## \var sourceURI
+    # Source URO of the media.
+    
+    ## \var Streams
+    # List of the stream of media.
+    
+    ## \var lastID
+    # Last used ID number in the media.



More information about the commits mailing list