mirror of https://github.com/q191201771/lal.git
[feat] 支持rtsp pub h265 (lalserver支持接收rtsp h265的推流)
parent
bb9cbb9481
commit
d7df4d9623
File diff suppressed because one or more lines are too long
@ -0,0 +1,123 @@
|
||||
// Copyright 2020, Chef. All rights reserved.
|
||||
// https://github.com/q191201771/lal
|
||||
//
|
||||
// Use of this source code is governed by a MIT-style license
|
||||
// that can be found in the License file.
|
||||
//
|
||||
// Author: Chef (191201771@qq.com)
|
||||
|
||||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/q191201771/lal/pkg/base"
|
||||
"github.com/q191201771/naza/pkg/bininfo"
|
||||
"github.com/q191201771/naza/pkg/nazalog"
|
||||
)
|
||||
|
||||
const httpAPIVersion = "v0.0.1"
|
||||
const CodeSucc = 0
|
||||
const DespSucc = "succ"
|
||||
|
||||
var startTime string
|
||||
|
||||
type HTTPAPIServer struct {
|
||||
addr string
|
||||
ln net.Listener
|
||||
}
|
||||
|
||||
type HTTPResponseBasic struct {
|
||||
Code int `json:"code"`
|
||||
Desp string `json:"desp"`
|
||||
}
|
||||
|
||||
type APILalInfo struct {
|
||||
HTTPResponseBasic
|
||||
BinInfo string `json:"bin_info"`
|
||||
LalVersion string `json:"lal_version"`
|
||||
APIVersion string `json:"api_version"`
|
||||
StartTime string `json:"start_time"`
|
||||
}
|
||||
|
||||
type APIStatAllGroup struct {
|
||||
HTTPResponseBasic
|
||||
Groups []StatGroupItem `json:"groups"`
|
||||
}
|
||||
|
||||
type StatGroupItem struct {
|
||||
StreamName string `json:"stream_name"`
|
||||
AudioCodec string `json:"audio_codec"`
|
||||
VideoCodec string `json:"video_codec"`
|
||||
VideoWidth string `json:"video_width"`
|
||||
VideoHeight string `json:"video_height"`
|
||||
}
|
||||
|
||||
type StatPub struct {
|
||||
StatSession
|
||||
}
|
||||
|
||||
type StatSub struct {
|
||||
StatSession
|
||||
}
|
||||
|
||||
type StatSession struct {
|
||||
Protocol string `json:"protocol"`
|
||||
StartTime string `json:"start_time"`
|
||||
RemoteAddr string `json:"remote_addr"`
|
||||
Bitrate string `json:"bitrate"`
|
||||
}
|
||||
|
||||
func NewHTTPAPIServer(addr string) *HTTPAPIServer {
|
||||
return &HTTPAPIServer{
|
||||
addr: addr,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *HTTPAPIServer) Listen() (err error) {
|
||||
if h.ln, err = net.Listen("tcp", h.addr); err != nil {
|
||||
return
|
||||
}
|
||||
nazalog.Infof("start httpapi server listen. addr=%s", h.addr)
|
||||
return
|
||||
}
|
||||
|
||||
func (h *HTTPAPIServer) Runloop() error {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.HandleFunc("/api/lal_info", h.lalInfo)
|
||||
mux.HandleFunc("/api/stat/group", h.statGroup)
|
||||
mux.HandleFunc("/api/stat/all_group", h.statAllGroup)
|
||||
|
||||
var srv http.Server
|
||||
srv.Handler = mux
|
||||
return srv.Serve(h.ln)
|
||||
}
|
||||
|
||||
func (h *HTTPAPIServer) lalInfo(w http.ResponseWriter, req *http.Request) {
|
||||
var v APILalInfo
|
||||
v.Code = CodeSucc
|
||||
v.Desp = DespSucc
|
||||
v.BinInfo = bininfo.StringifySingleLine()
|
||||
v.LalVersion = base.LALVersion
|
||||
v.APIVersion = httpAPIVersion
|
||||
v.StartTime = startTime
|
||||
resp, _ := json.Marshal(v)
|
||||
w.Header().Add("Server", base.LALHTTPAPIServer)
|
||||
_, _ = w.Write(resp)
|
||||
}
|
||||
|
||||
func (h *HTTPAPIServer) statGroup(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
func (h *HTTPAPIServer) statAllGroup(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
func init() {
|
||||
startTime = time.Now().String()
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
// Copyright 2020, Chef. All rights reserved.
|
||||
// https://github.com/q191201771/lal
|
||||
//
|
||||
// Use of this source code is governed by a MIT-style license
|
||||
// that can be found in the License file.
|
||||
//
|
||||
// Author: Chef (191201771@qq.com)
|
||||
|
||||
package logic_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHTTPAPIServer(t *testing.T) {
|
||||
//s := logic.NewHTTPAPIServer(":8083")
|
||||
//if err := s.Listen(); err != nil {
|
||||
// nazalog.Error(err)
|
||||
// return
|
||||
//}
|
||||
//err := s.Runloop()
|
||||
//nazalog.Error(err)
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
// Copyright 2020, Chef. All rights reserved.
|
||||
// https://github.com/q191201771/lal
|
||||
//
|
||||
// Use of this source code is governed by a MIT-style license
|
||||
// that can be found in the License file.
|
||||
//
|
||||
// Author: Chef (191201771@qq.com)
|
||||
|
||||
package rtprtcp
|
||||
|
||||
import (
|
||||
"github.com/q191201771/lal/pkg/hevc"
|
||||
"github.com/q191201771/naza/pkg/nazalog"
|
||||
)
|
||||
|
||||
func calcPositionIfNeededHEVC(pkt *RTPPacket) {
|
||||
b := pkt.Raw[pkt.Header.payloadOffset:]
|
||||
|
||||
// +---------------+---------------+
|
||||
// |0|1|2|3|4|5|6|7|0|1|2|3|4|5|6|7|
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// |F| Type | LayerId | TID |
|
||||
// +-------------+-----------------+
|
||||
|
||||
outerNALUType := hevc.ParseNALUType(b[0])
|
||||
|
||||
switch outerNALUType {
|
||||
case hevc.NALUTypeSliceIDRNLP:
|
||||
fallthrough
|
||||
case hevc.NALUTypeSliceTrailR:
|
||||
pkt.positionType = PositionTypeSingle
|
||||
return
|
||||
case NALUTypeHEVCFUA:
|
||||
// Figure 1: The Structure of the HEVC NAL Unit Header
|
||||
|
||||
// 0 1 2 3
|
||||
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | PayloadHdr (Type=49) | FU header | DONL (cond) |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
|
||||
// | DONL (cond) | |
|
||||
// |-+-+-+-+-+-+-+-+ |
|
||||
// | FU payload |
|
||||
// | |
|
||||
// | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | :...OPTIONAL RTP padding |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
|
||||
// Figure 9: The Structure of an FU
|
||||
|
||||
// +---------------+
|
||||
// |0|1|2|3|4|5|6|7|
|
||||
// +-+-+-+-+-+-+-+-+
|
||||
// |S|E| FuType |
|
||||
// +---------------+
|
||||
|
||||
// Figure 10: The Structure of FU Header
|
||||
|
||||
startCode := (b[2] & 0x80) != 0
|
||||
endCode := (b[2] & 0x40) != 0
|
||||
|
||||
if startCode {
|
||||
pkt.positionType = PositionTypeFUAStart
|
||||
return
|
||||
}
|
||||
|
||||
if endCode {
|
||||
pkt.positionType = PositionTypeFUAEnd
|
||||
return
|
||||
}
|
||||
|
||||
pkt.positionType = PositionTypeFUAMiddle
|
||||
return
|
||||
default:
|
||||
// TODO chef: 没有实现 AP 48
|
||||
nazalog.Errorf("unknown nalu type. outerNALUType=%d", outerNALUType)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// hevc rtp包合帧部分见func unpackOneAVCOrHEVC
|
Loading…
Reference in New Issue