From 95d2f0bb5e73c1969345ad714f265b462f4fd4c2 Mon Sep 17 00:00:00 2001 From: yomguy Date: Tue, 10 Jan 2012 19:41:51 +0100 Subject: [PATCH] add a webm streaming test (with stream-m) --- tests.py | 23 ---------------- tests/push_webm.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 23 deletions(-) delete mode 100644 tests.py create mode 100755 tests/push_webm.py diff --git a/tests.py b/tests.py deleted file mode 100644 index 2247054..0000000 --- a/tests.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -This file demonstrates two different styles of tests (one doctest and one -unittest). These will both pass when you run "manage.py test". - -Replace these with more appropriate tests for your application. -""" - -from django.test import TestCase - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.failUnlessEqual(1 + 1, 2) - -__test__ = {"doctest": """ -Another way to test that 1 + 1 is equal to 2. - ->>> 1 + 1 == 2 -True -"""} - diff --git a/tests/push_webm.py b/tests/push_webm.py new file mode 100755 index 0000000..9ecd90c --- /dev/null +++ b/tests/push_webm.py @@ -0,0 +1,68 @@ + +import httplib +import os +import pycurl +import urllib + +class FileReader: + def __init__(self, fp): + self.fp = fp + + def read_callback(self, size): + return self.fp.read(size) + +class RelayReader: + def __init__(self, relay): + self.relay = urllib.urlopen(relay) + + def read_callback(self, size): + return self.relay.read(size) + + +class Streamer(object): + + BUFFER_SIZE = 0x10000 + + def __init__(self, host, port, mount_point, media, relay): + self.host = host + self.port = port + self.mount_point = mount_point + self.media = media + self.relay = relay + + self.file = open(self.media, 'r') + self.url='http://'+self.host+':'+self.port+self.mount_point + + def read(self): + while True: + buf = self.file.read(self.BUFFER_SIZE) + if not len(buf): + break + yield buf + + def stream(self): + feed = self.read() + h = httplib.HTTPConnection(self.host,self.port) + for buf in feed: + h.request('POST',self.mount_point) + h.send(buf) + response = h.getresponse() + #print response + #print response.status, response.reason, response.read() + + def stream2(self): + c = pycurl.Curl() + c.setopt(pycurl.URL, self.url) + c.setopt(pycurl.UPLOAD, 1) + #c.setopt(pycurl.READFUNCTION, FileReader(self.file).read_callback) + c.setopt(pycurl.READFUNCTION, RelayReader(self.relay).read_callback) + #c.setopt(pycurl.READFUNCTION, self.file.read) + filesize = os.path.getsize(self.media) + c.setopt(pycurl.INFILESIZE, filesize) + c.perform() + c.close() + +s = Streamer('127.0.0.1','9080','/publish/first?password=secret','/home/momo/Downloads/test.webm','http://192.168.0.14:9000/') +s.stream2() + + -- 2.39.5