gmyth-stream/main.py
author renatofilho
Mon Apr 02 16:57:57 2007 +0100 (2007-04-02)
branchtrunk
changeset 477 88bf59e8da5f
parent 474 07c12d2ceddf
permissions -rwxr-xr-x
[svn r482] dont make seek for push mode
morphbr@453
     1
#!/usr/bin/python
morphbr@453
     2
morphbr@470
     3
import os
morphbr@470
     4
import lib
morphbr@453
     5
import sys
morphbr@453
     6
import ConfigParser
morphbr@453
     7
morphbr@453
     8
config = ConfigParser.ConfigParser()
morphbr@453
     9
config.read("stream.conf")
morphbr@453
    10
morphbr@453
    11
media_plugin = config.get("Media", "engine")
morphbr@453
    12
exec("from plugins.media.%s import *" % media_plugin)
morphbr@453
    13
morphbr@453
    14
media = Media(config)
morphbr@453
    15
morphbr@453
    16
comm_plugin = config.get("Comm", "engine")
morphbr@453
    17
exec("from plugins.comm.%s import *" % comm_plugin)
morphbr@453
    18
morphbr@453
    19
# Start Our Server:
morphbr@453
    20
server = Server(config)
morphbr@453
    21
morphbr@470
    22
lib.log("Starting GMyth-Stream server")
morphbr@453
    23
morphbr@453
    24
while (server.finish == 0):
morphbr@453
    25
    con, client = server.getRequest()
morphbr@453
    26
morphbr@453
    27
    while True:
morphbr@453
    28
        msg = server.getMsg(1024).strip()
morphbr@453
    29
morphbr@453
    30
        if not msg: break
morphbr@453
    31
morphbr@470
    32
        lib.log("Received %s from: %s" % (msg, client) )
morphbr@470
    33
morphbr@470
    34
        if (msg == "SETUP"):
morphbr@453
    35
            setup = server.getMsg(1024).strip().split(" ")
morphbr@475
    36
            size = len(setup)
morphbr@475
    37
            options = []
morphbr@475
    38
morphbr@475
    39
            if ( size < 10 ):
morphbr@475
    40
                server.sendMsg(lib.log("Wrong SETUP command from: %s" % client[0]))
morphbr@475
    41
morphbr@475
    42
            else:
morphbr@475
    43
morphbr@475
    44
                if ( size > 10 ):
morphbr@475
    45
                    i = 10
morphbr@475
    46
                    while (i < size):
morphbr@475
    47
                        options.append(setup[i])
morphbr@475
    48
                        i += 1
morphbr@475
    49
morphbr@474
    50
                ret = media.setup(setup[0], setup[1], setup[2], \
morphbr@474
    51
                                  setup[3], setup[4], setup[5],
morphbr@474
    52
                                  setup[6], setup[7], setup[8],
morphbr@475
    53
                                  setup[9], options)
morphbr@470
    54
morphbr@474
    55
                if (ret == 0):
morphbr@474
    56
                    server.Ack("SETUP")
morphbr@474
    57
                else:
morphbr@475
    58
                    server.sendMsg(lib.log(ret))
morphbr@470
    59
morphbr@453
    60
morphbr@453
    61
        elif (msg == "PLAY"):
morphbr@453
    62
            media.play()
morphbr@470
    63
            server.Ack("PLAY")
morphbr@453
    64
morphbr@453
    65
        elif (msg == "STOP"):
morphbr@453
    66
            media.stop()
morphbr@470
    67
            server.Ack("STOP")
morphbr@453
    68
morphbr@453
    69
        elif (msg == "CLOSE"):
morphbr@453
    70
            server.finish = 1
morphbr@453
    71
            media.stop()
morphbr@470
    72
            server.Ack("CLOSE")
morphbr@453
    73
            break
morphbr@453
    74
morphbr@470
    75
    lib.log("Closing connection with %s" % client[0])
morphbr@453
    76
    server.disconnect_client(con)
morphbr@453
    77
morphbr@453
    78
server.stop()
morphbr@466
    79
del(server)
morphbr@470
    80
lib.log("Server stopped. Closing...")
morphbr@470
    81