mirror of
https://github.com/langhuihui/monibuca.git
synced 2025-09-27 09:52:06 +08:00
fix: writeTrailerTask never dispose
This commit is contained in:
14
api.go
14
api.go
@@ -160,9 +160,9 @@ func (s *Server) StreamInfo(ctx context.Context, req *pb.StreamSnapRequest) (res
|
||||
}
|
||||
|
||||
func (s *Server) TaskTree(context.Context, *emptypb.Empty) (res *pb.TaskTreeResponse, err error) {
|
||||
var fillData func(m task.ITask) *pb.TaskTreeResponse
|
||||
fillData = func(m task.ITask) (res *pb.TaskTreeResponse) {
|
||||
res = &pb.TaskTreeResponse{Id: m.GetTaskID(), State: uint32(m.GetState()), Type: uint32(m.GetTaskType()), Owner: m.GetOwnerType(), StartTime: timestamppb.New(m.GetTask().StartTime), Description: m.GetDescriptions()}
|
||||
var fillData func(m task.ITask) *pb.TaskTreeData
|
||||
fillData = func(m task.ITask) (res *pb.TaskTreeData) {
|
||||
res = &pb.TaskTreeData{Id: m.GetTaskID(), State: uint32(m.GetState()), Type: uint32(m.GetTaskType()), Owner: m.GetOwnerType(), StartTime: timestamppb.New(m.GetTask().StartTime), Description: m.GetDescriptions()}
|
||||
if job, ok := m.(task.IJob); ok {
|
||||
if blockedTask := job.Blocked(); blockedTask != nil {
|
||||
res.Blocked = fillData(blockedTask)
|
||||
@@ -173,7 +173,7 @@ func (s *Server) TaskTree(context.Context, *emptypb.Empty) (res *pb.TaskTreeResp
|
||||
}
|
||||
return
|
||||
}
|
||||
res = fillData(&Servers)
|
||||
res = &pb.TaskTreeResponse{Data: fillData(&Servers)}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -361,7 +361,7 @@ func (s *Server) Restart(ctx context.Context, req *pb.RequestWithId) (res *empty
|
||||
|
||||
func (s *Server) Shutdown(ctx context.Context, req *pb.RequestWithId) (res *emptypb.Empty, err error) {
|
||||
if s, ok := Servers.Get(req.Id); ok {
|
||||
s.Stop(pkg.ErrStopFromAPI)
|
||||
s.Stop(task.ErrStopByUser)
|
||||
} else {
|
||||
return nil, pkg.ErrNotFound
|
||||
}
|
||||
@@ -439,7 +439,7 @@ func (s *Server) SeekStream(ctx context.Context, req *pb.SeekStreamRequest) (res
|
||||
func (s *Server) StopPublish(ctx context.Context, req *pb.StreamSnapRequest) (res *pb.SuccessResponse, err error) {
|
||||
s.Streams.Call(func() error {
|
||||
if s, ok := s.Streams.Get(req.StreamPath); ok {
|
||||
s.Stop(pkg.ErrStopFromAPI)
|
||||
s.Stop(task.ErrStopByUser)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@@ -711,7 +711,7 @@ func (s *Server) RemoveDevice(ctx context.Context, req *pb.RequestWithId) (res *
|
||||
err = tx.Error
|
||||
s.Devices.Call(func() error {
|
||||
if device, ok := s.Devices.Get(uint(req.Id)); ok {
|
||||
device.Stop(pkg.ErrStopFromAPI)
|
||||
device.Stop(task.ErrStopByUser)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
@@ -7,8 +7,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"m7s.live/pro/pkg"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"m7s.live/pro/pkg/config"
|
||||
"m7s.live/pro/pkg/task"
|
||||
@@ -158,7 +156,7 @@ func (d *DeviceTask) Dispose() {
|
||||
d.TickTask.Dispose()
|
||||
d.Plugin.Server.Streams.Call(func() error {
|
||||
if stream, ok := d.Plugin.Server.Streams.Get(d.Device.GetStreamPath()); ok {
|
||||
stream.Stop(pkg.ErrStopFromAPI)
|
||||
stream.Stop(task.ErrStopByUser)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
1498
pb/global.pb.go
1498
pb/global.pb.go
File diff suppressed because it is too large
Load Diff
@@ -231,15 +231,21 @@ message SysInfoResponse {
|
||||
SysInfoData data = 3;
|
||||
}
|
||||
|
||||
message TaskTreeResponse {
|
||||
message TaskTreeData {
|
||||
uint32 id = 1;
|
||||
uint32 type = 2;
|
||||
string owner = 3;
|
||||
google.protobuf.Timestamp startTime = 4;
|
||||
map<string, string> description = 5;
|
||||
repeated TaskTreeResponse children = 6;
|
||||
repeated TaskTreeData children = 6;
|
||||
uint32 state = 7;
|
||||
TaskTreeResponse blocked = 8;
|
||||
TaskTreeData blocked = 8;
|
||||
}
|
||||
|
||||
message TaskTreeResponse {
|
||||
int32 code = 1;
|
||||
string message = 2;
|
||||
TaskTreeData data = 3;
|
||||
}
|
||||
|
||||
message StreamListRequest {
|
||||
|
@@ -4,7 +4,6 @@ import "errors"
|
||||
|
||||
var (
|
||||
ErrNotFound = errors.New("not found")
|
||||
ErrStopFromAPI = errors.New("stop from api")
|
||||
ErrStreamExist = errors.New("stream exist")
|
||||
ErrKick = errors.New("kick")
|
||||
ErrDiscard = errors.New("discard")
|
||||
|
@@ -7,7 +7,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"m7s.live/pro"
|
||||
m7s "m7s.live/pro"
|
||||
"m7s.live/pro/pkg"
|
||||
"m7s.live/pro/pkg/codec"
|
||||
"m7s.live/pro/pkg/task"
|
||||
@@ -30,42 +30,47 @@ func (task *writeTrailerTask) Start() (err error) {
|
||||
err = task.muxer.WriteTrailer()
|
||||
if err != nil {
|
||||
task.Error("write trailer", "err", err)
|
||||
return task.muxer.File.Close()
|
||||
} else {
|
||||
task.Info("write trailer")
|
||||
var temp *os.File
|
||||
temp, err = os.CreateTemp("", "*.mp4")
|
||||
if err != nil {
|
||||
task.Error("create temp file", "err", err)
|
||||
return
|
||||
}
|
||||
defer os.Remove(temp.Name())
|
||||
err = task.muxer.ReWriteWithMoov(temp)
|
||||
if err != nil {
|
||||
task.Error("rewrite with moov", "err", err)
|
||||
return
|
||||
}
|
||||
if _, err = task.muxer.File.Seek(0, io.SeekStart); err != nil {
|
||||
task.Error("seek file", "err", err)
|
||||
return
|
||||
}
|
||||
if _, err = temp.Seek(0, io.SeekStart); err != nil {
|
||||
task.Error("seek temp file", "err", err)
|
||||
return
|
||||
}
|
||||
if _, err = io.Copy(task.muxer.File, temp); err != nil {
|
||||
task.Error("copy file", "err", err)
|
||||
return
|
||||
}
|
||||
if err = task.muxer.File.Close(); err != nil {
|
||||
task.Error("close file", "err", err)
|
||||
return
|
||||
}
|
||||
if err = temp.Close(); err != nil {
|
||||
task.Error("close temp file", "err", err)
|
||||
if errClose := task.muxer.File.Close(); errClose != nil {
|
||||
return errClose
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (task *writeTrailerTask) Run() (err error) {
|
||||
task.Info("write trailer")
|
||||
var temp *os.File
|
||||
temp, err = os.CreateTemp("", "*.mp4")
|
||||
if err != nil {
|
||||
task.Error("create temp file", "err", err)
|
||||
return
|
||||
}
|
||||
defer os.Remove(temp.Name())
|
||||
err = task.muxer.ReWriteWithMoov(temp)
|
||||
if err != nil {
|
||||
task.Error("rewrite with moov", "err", err)
|
||||
return
|
||||
}
|
||||
if _, err = task.muxer.File.Seek(0, io.SeekStart); err != nil {
|
||||
task.Error("seek file", "err", err)
|
||||
return
|
||||
}
|
||||
if _, err = temp.Seek(0, io.SeekStart); err != nil {
|
||||
task.Error("seek temp file", "err", err)
|
||||
return
|
||||
}
|
||||
if _, err = io.Copy(task.muxer.File, temp); err != nil {
|
||||
task.Error("copy file", "err", err)
|
||||
return
|
||||
}
|
||||
if err = task.muxer.File.Close(); err != nil {
|
||||
task.Error("close file", "err", err)
|
||||
return
|
||||
}
|
||||
if err = temp.Close(); err != nil {
|
||||
task.Error("close temp file", "err", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@@ -250,6 +250,9 @@ func (c *NetConnection) ReadResponse() (res *util.Response, err error) {
|
||||
|
||||
func (c *NetConnection) Receive(sendMode bool, onReceive func(byte, []byte) error, onRTCP func(byte, []byte) error) (err error) {
|
||||
for err == nil {
|
||||
if err = c.StopReason(); err != nil {
|
||||
return
|
||||
}
|
||||
ts := time.Now()
|
||||
if err = c.conn.SetReadDeadline(ts.Add(util.Conditional(sendMode, time.Second*60, time.Second*15))); err != nil {
|
||||
return
|
||||
|
@@ -4,11 +4,11 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"m7s.live/pro/pkg/config"
|
||||
"m7s.live/pro/pkg/task"
|
||||
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
"m7s.live/pro"
|
||||
gpb "m7s.live/pro/pb"
|
||||
"m7s.live/pro/pkg"
|
||||
hdl "m7s.live/pro/plugin/flv/pkg"
|
||||
rtmp "m7s.live/pro/plugin/rtmp/pkg"
|
||||
rtsp "m7s.live/pro/plugin/rtsp/pkg"
|
||||
@@ -31,7 +31,7 @@ func (r *StressPlugin) pull(count int, format, url string, puller m7s.Puller) (e
|
||||
}
|
||||
} else if count < i {
|
||||
for j := i; j > count; j-- {
|
||||
r.pullers.Items[j-1].Stop(pkg.ErrStopFromAPI)
|
||||
r.pullers.Items[j-1].Stop(task.ErrStopByUser)
|
||||
r.pullers.Remove(r.pullers.Items[j-1])
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func (r *StressPlugin) push(count int, streamPath, format, remoteHost string, pu
|
||||
}
|
||||
} else if count < i {
|
||||
for j := i; j > count; j-- {
|
||||
r.pushers.Items[j-1].Stop(pkg.ErrStopFromAPI)
|
||||
r.pushers.Items[j-1].Stop(task.ErrStopByUser)
|
||||
r.pushers.Remove(r.pushers.Items[j-1])
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ func (r *StressPlugin) PullHDL(ctx context.Context, req *pb.PullRequest) (res *g
|
||||
|
||||
func (r *StressPlugin) StopPush(ctx context.Context, req *emptypb.Empty) (res *gpb.SuccessResponse, err error) {
|
||||
for pusher := range r.pushers.Range {
|
||||
pusher.Stop(pkg.ErrStopFromAPI)
|
||||
pusher.Stop(task.ErrStopByUser)
|
||||
}
|
||||
r.pushers.Clear()
|
||||
return &gpb.SuccessResponse{}, nil
|
||||
@@ -90,7 +90,7 @@ func (r *StressPlugin) StopPush(ctx context.Context, req *emptypb.Empty) (res *g
|
||||
|
||||
func (r *StressPlugin) StopPull(ctx context.Context, req *emptypb.Empty) (res *gpb.SuccessResponse, err error) {
|
||||
for puller := range r.pullers.Range {
|
||||
puller.Stop(pkg.ErrStopFromAPI)
|
||||
puller.Stop(task.ErrStopByUser)
|
||||
}
|
||||
r.pullers.Clear()
|
||||
return &gpb.SuccessResponse{}, nil
|
||||
|
@@ -128,8 +128,10 @@ func (p *PullJob) Publish() (err error) {
|
||||
p.Publisher.Type = PublishTypePull
|
||||
if err == nil && p.conf.MaxRetry != 0 {
|
||||
p.Publisher.OnDispose(func() {
|
||||
if p.Publisher.StopReasonIs(pkg.ErrPublishDelayCloseTimeout, pkg.ErrStopFromAPI) {
|
||||
if p.Publisher.StopReasonIs(pkg.ErrPublishDelayCloseTimeout, task.ErrStopByUser) {
|
||||
p.Stop(p.Publisher.StopReason())
|
||||
} else {
|
||||
p.puller.Stop(p.Publisher.StopReason())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@@ -80,8 +80,10 @@ func (p *TransformJob) Publish(streamPath string) (err error) {
|
||||
p.Publisher.Type = PublishTypeTransform
|
||||
if err == nil {
|
||||
p.Publisher.OnDispose(func() {
|
||||
if p.Publisher.StopReasonIs(pkg.ErrPublishDelayCloseTimeout, pkg.ErrStopFromAPI) {
|
||||
if p.Publisher.StopReasonIs(pkg.ErrPublishDelayCloseTimeout, task.ErrStopByUser) {
|
||||
p.Stop(p.Publisher.StopReason())
|
||||
} else {
|
||||
p.Transformer.Stop(p.Publisher.StopReason())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user