instrumentation: add next-share/
[cs-p2p-next.git] / instrumentation / next-share / BaseLib / Core / Video / MovieTransport.py
1 # Written by Jan David Mol, Arno Bakker
2 # see LICENSE.txt for license information
3
4
5 import os,sys
6
7 from BaseLib.Core.osutils import *
8
9 DEBUG = False
10
11 class MovieTransport:
12     
13     def __init__(self):
14         pass
15         
16     def start( self, bytepos = 0 ):
17         pass
18     
19     def size(self ):
20         pass
21
22     def read(self):
23         pass
24         
25     def stop(self):
26         pass
27
28     def done(self):
29         pass
30     
31     def get_mimetype(self):
32         pass
33  
34     def set_mimetype(self,mimetype):
35         pass
36
37     def available(self):
38         pass
39     
40  
41 class MovieTransportStreamWrapper:
42     """ Provide a file-like interface """
43     def __init__(self,mt):
44         self.mt = mt
45         self.started = False
46
47     def read(self,numbytes=None):
48         if DEBUG:
49             print >>sys.stderr,"MovieTransportStreamWrapper: read",numbytes
50
51         if not self.started:
52             self.mt.start(0)
53             self.started = True
54         if self.mt.done():
55             return ''
56         data = self.mt.read(numbytes)
57         if data is None:
58             print >>sys.stderr,"MovieTransportStreamWrapper: mt read returns None"
59             data = ''
60         return data
61
62     def seek(self,pos,whence=os.SEEK_SET):
63         # TODO: shift play_pos in PiecePicking + interpret whence
64         if DEBUG:
65             print >>sys.stderr,"MovieTransportStreamWrapper: seek:",pos,"whence",whence
66         self.mt.seek(pos,whence=whence)
67         # Arno, 2010-01-08: seek also means we've started.
68         self.started = True
69     
70     def close(self):
71         if DEBUG:
72             print >>sys.stderr,"MovieTransportStreamWrapper: close"
73         self.mt.stop()
74
75     def available(self):
76         return self.mt.available()
77     
78     def get_generation_time(self):
79         # Overrriden by AuthStreamWrapper normally. Added to give sane warning
80         # when playing unauthenticated stream as if it had auth.
81         raise ValueError("This is an unauthenticated stream that provides no timestamp")