mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-20 02:00:05 -08:00
move static sources into dedicated package (#2616)
This commit is contained in:
parent
e9528c0917
commit
43d41c070b
58 changed files with 2271 additions and 2172 deletions
128
internal/staticsources/rpicamera/source.go
Normal file
128
internal/staticsources/rpicamera/source.go
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
// Package rpicamera contains the Raspberry Pi Camera static source.
|
||||
package rpicamera
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/description"
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
||||
|
||||
"github.com/bluenviron/mediamtx/internal/conf"
|
||||
"github.com/bluenviron/mediamtx/internal/defs"
|
||||
"github.com/bluenviron/mediamtx/internal/logger"
|
||||
"github.com/bluenviron/mediamtx/internal/protocols/rpicamera"
|
||||
"github.com/bluenviron/mediamtx/internal/stream"
|
||||
"github.com/bluenviron/mediamtx/internal/unit"
|
||||
)
|
||||
|
||||
func paramsFromConf(cnf *conf.Path) rpicamera.Params {
|
||||
return rpicamera.Params{
|
||||
CameraID: cnf.RPICameraCamID,
|
||||
Width: cnf.RPICameraWidth,
|
||||
Height: cnf.RPICameraHeight,
|
||||
HFlip: cnf.RPICameraHFlip,
|
||||
VFlip: cnf.RPICameraVFlip,
|
||||
Brightness: cnf.RPICameraBrightness,
|
||||
Contrast: cnf.RPICameraContrast,
|
||||
Saturation: cnf.RPICameraSaturation,
|
||||
Sharpness: cnf.RPICameraSharpness,
|
||||
Exposure: cnf.RPICameraExposure,
|
||||
AWB: cnf.RPICameraAWB,
|
||||
Denoise: cnf.RPICameraDenoise,
|
||||
Shutter: cnf.RPICameraShutter,
|
||||
Metering: cnf.RPICameraMetering,
|
||||
Gain: cnf.RPICameraGain,
|
||||
EV: cnf.RPICameraEV,
|
||||
ROI: cnf.RPICameraROI,
|
||||
HDR: cnf.RPICameraHDR,
|
||||
TuningFile: cnf.RPICameraTuningFile,
|
||||
Mode: cnf.RPICameraMode,
|
||||
FPS: cnf.RPICameraFPS,
|
||||
IDRPeriod: cnf.RPICameraIDRPeriod,
|
||||
Bitrate: cnf.RPICameraBitrate,
|
||||
Profile: cnf.RPICameraProfile,
|
||||
Level: cnf.RPICameraLevel,
|
||||
AfMode: cnf.RPICameraAfMode,
|
||||
AfRange: cnf.RPICameraAfRange,
|
||||
AfSpeed: cnf.RPICameraAfSpeed,
|
||||
LensPosition: cnf.RPICameraLensPosition,
|
||||
AfWindow: cnf.RPICameraAfWindow,
|
||||
TextOverlayEnable: cnf.RPICameraTextOverlayEnable,
|
||||
TextOverlay: cnf.RPICameraTextOverlay,
|
||||
}
|
||||
}
|
||||
|
||||
// Source is a Raspberry Pi Camera static source.
|
||||
type Source struct {
|
||||
Parent defs.StaticSourceParent
|
||||
}
|
||||
|
||||
// Log implements StaticSource.
|
||||
func (s *Source) Log(level logger.Level, format string, args ...interface{}) {
|
||||
s.Parent.Log(level, "[RPI Camera source] "+format, args...)
|
||||
}
|
||||
|
||||
// Run implements StaticSource.
|
||||
func (s *Source) Run(params defs.StaticSourceRunParams) error {
|
||||
medi := &description.Media{
|
||||
Type: description.MediaTypeVideo,
|
||||
Formats: []format.Format{&format.H264{
|
||||
PayloadTyp: 96,
|
||||
PacketizationMode: 1,
|
||||
}},
|
||||
}
|
||||
medias := []*description.Media{medi}
|
||||
var stream *stream.Stream
|
||||
|
||||
onData := func(dts time.Duration, au [][]byte) {
|
||||
if stream == nil {
|
||||
res := s.Parent.SetReady(defs.PathSourceStaticSetReadyReq{
|
||||
Desc: &description.Session{Medias: medias},
|
||||
GenerateRTPPackets: true,
|
||||
})
|
||||
if res.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
stream = res.Stream
|
||||
}
|
||||
|
||||
stream.WriteUnit(medi, medi.Formats[0], &unit.H264{
|
||||
Base: unit.Base{
|
||||
NTP: time.Now(),
|
||||
PTS: dts,
|
||||
},
|
||||
AU: au,
|
||||
})
|
||||
}
|
||||
|
||||
cam, err := rpicamera.New(paramsFromConf(params.Conf), onData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cam.Close()
|
||||
|
||||
defer func() {
|
||||
if stream != nil {
|
||||
s.Parent.SetNotReady(defs.PathSourceStaticSetNotReadyReq{})
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case cnf := <-params.ReloadConf:
|
||||
cam.ReloadParams(paramsFromConf(cnf))
|
||||
|
||||
case <-params.Context.Done():
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// APISourceDescribe implements StaticSource.
|
||||
func (*Source) APISourceDescribe() defs.APIPathSourceOrReader {
|
||||
return defs.APIPathSourceOrReader{
|
||||
Type: "rpiCameraSource",
|
||||
ID: "",
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue