mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-09-26 20:31:11 +08:00
33 lines
652 B
Go
33 lines
652 B
Go
package mpegts
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/AlexxIT/go2rtc/internal/api"
|
|
"github.com/AlexxIT/go2rtc/internal/streams"
|
|
"github.com/AlexxIT/go2rtc/pkg/aac"
|
|
)
|
|
|
|
func apiStreamAAC(w http.ResponseWriter, r *http.Request) {
|
|
src := r.URL.Query().Get("src")
|
|
stream := streams.Get(src)
|
|
if stream == nil {
|
|
http.Error(w, api.StreamNotFound, http.StatusNotFound)
|
|
return
|
|
}
|
|
|
|
cons := aac.NewConsumer()
|
|
cons.WithRequest(r)
|
|
|
|
if err := stream.AddConsumer(cons); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
w.Header().Add("Content-Type", "audio/aac")
|
|
|
|
_, _ = cons.WriteTo(w)
|
|
|
|
stream.RemoveConsumer(cons)
|
|
}
|