Webm newbie
Vasileios Anagnostopoulos
fithis2001 at gmail.com
Thu Jan 2 09:40:55 PST 2014
Hi,
I have tried to create a goloang http server (based on a node.js sample)
that receives a webm file through a tcp port in order to serve through
http get the file to the browser.
The pipeline I use is
gst-launch-1.0 webmmux name=mux ! tcpclientsink port=3005 videotestsrc
pattern=snow num-buffers=250 ! video/x-raw,framerate=25/1 ! videoconvert !
vp8enc ! queue ! mux.video_0
the idea behind the golang application is that it listens on http port 9001
for path
http://localhost:9001/stream.webm
As soon s the browser connects, it sends the headers
t := time.Now().UTC()
w.Header().Set("Date", t.Format(layoutee))
w.Header().Set("Connection", "Close")
w.Header().Set("Cache-Control", "private")
w.Header().Set("Content-Type", "video/webm")
and begins to listen on port 3005
Then I start the pipeline and the server copies what it receives through
port 3005 to the response body
But after some bytes and without showing anything, either chromium or
firefox closes the connection.
I am on Windows 7 x86, gstreamer-1.0-x86-1.2.2, golang 1.2
Is the rationale sane?
I put the golang code in case someone wants to test
package main
import (
"fmt"
"html"
"log"
"net"
"net/http"
"net/http/httputil"
"os"
"time"
)
const (
RECV_BUF_LEN = 1024
layoutee = http.TimeFormat
)
type myHandler struct {
}
func (v *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Println("Hello World!")
g1, _ := httputil.DumpRequest(r, true)
fmt.Println(string(g1))
t := time.Now().UTC()
w.Header().Set("Date", t.Format(layoutee))
w.Header().Set("Connection", "Close")
w.Header().Set("Cache-Control", "private")
w.Header().Set("Content-Type", "video/webm")
w.Header().Set("Server", "CustomStreamer/0.0.1")
listener, err := net.Listen("tcp", "0.0.0.0:3005")
if err != nil {
fmt.Fprintf(w, "error listening: %q", html.EscapeString(err.Error()))
println("error listening:", err.Error())
w.(http.Flusher).Flush()
return
}
conn, err := listener.Accept()
if err != nil {
fmt.Fprintf(w, "Error accept: %q", html.EscapeString(err.Error()))
println("Error accept:", err.Error())
w.(http.Flusher).Flush()
return
}
c := make(chan []byte)
q := make(chan bool)
go gstreamerFunc(conn, c, q)
for buf := range c {
writelen := len(buf)
println("got ", writelen, " bytes of data =")
_, err2 := w.Write(buf)
if err2 != nil {
println("Error 2 writing data:", err2.Error())
close(q)
listener.Close()
return
}
w.(http.Flusher).Flush()
}
close(q)
listener.Close()
w.(http.Flusher).Flush()
}
func main() {
g := new(myHandler)
http.Handle("/stream.webm", g)
err := http.ListenAndServe(":9001", nil)
if err != nil {
fmt.Println("Fucked")
log.Fatal(err)
}
}
func gstreamerFunc(conn net.Conn, c chan []byte, q chan bool) {
buf := make([]byte, RECV_BUF_LEN)
for {
fmt.Println("Inside")
n, err := conn.Read(buf)
if err != nil {
println("Error reading:", err.Error())
conn.Close()
close(c)
os.Exit(1)
return
}
//println("received ", n, " bytes of data =", string(buf))
select {
case c <- buf[0:n]:
println("received ", n, " bytes of data =")
case <-q:
println("closed normally")
conn.Close()
close(c)
os.Exit(0)
return
}
}
}
--
Dr. Vasileios Anagnostopoulos (MSc,PhD)
Researcher/Developer
ICCS/NTUA 9 Heroon Polytechneiou Str., Zografou 15773 Athens,Greece
T (+30) 2107723404 M (+30) 6936935388
E vanag at mail.ntua.gr<mailto:vanag at mail.ntua.gr> www.ntua.gr<
http://www.ntua.gr/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20140102/b284124a/attachment-0001.html>
More information about the gstreamer-devel
mailing list