thanks to your replies .here is what i am doing.
i am capture and serve a (usb connected video camera) video streaming using
gstreamer at port :3000
here is the gstreamer command i issue
~$ gst-launch-0.10 v4l2src !
video/x-raw-yuv,width=320,height=240,framerate=\(fraction\)5/1 !
ffmpegcolorspace ! jpegenc ! multipartmux ! tcpserversink host=192.168.2.1
port=3000
here is my go http server will pull the binary content from port :3000 and
stream to browser http client at port :8080
/////////code////////////////
package main
import (
"fmt"
"html"
"log"
"net"
"net/http"
"net/http/httputil"
"os"
"time"
)
const (
RECV_BUF_LEN = 1024
layoutee = http.TimeFormat
)
func main() {
g := new(streamHandler)
http.Handle("/stream.webm", g)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal(err)
}
}
type streamHandler struct {
}
func (v *streamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Println("start streaming!!!")
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:3000")
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 streamer(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 streamer(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
}
}
}
///////////////code end///////////
when i start browser at "http://192.168.2.1:8080/stream.webm" i am not able
to receive any video output.
i am sure that gstreamer capturing my camera stream and serve streaming at
:3000
~$ vlc tcp://192.168.2.1:3000
because vlc is pulling the stream content and can show on vlc player
window.
Thanks
Thani
On Wednesday, 13 August 2014 14:42:44 UTC+5:30, Ingo Oeser wrote:
If you can move freely in the generated stream, just use
http.ServeContent.
If you have a byte slice of the content,wrap it in a bytes.Reader and pass
it to http.ServeContent.
If you have a real stream, which generated partially and is expensive to
implement seeking for, just use do io.Copy to the passed http.ResposeWriter
in your handler.
If this doesn't answer your question, please provide a bit sample code
describing how you generate the stream, how this stream generation relates
to the request. E.g. can it be reused to respond to a different request?
How big is it?
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.