change rest-like api to grpc

This commit is contained in:
garionion 2020-12-29 17:34:34 +01:00
parent e57d4c191d
commit 7f793dc75c
9 changed files with 610 additions and 153 deletions

292
api/PlayoutService.pb.go Normal file
View file

@ -0,0 +1,292 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.25.0
// protoc v3.12.4
// source: api/PlayoutService.proto
package api
import (
proto "github.com/golang/protobuf/proto"
timestamp "github.com/golang/protobuf/ptypes/timestamp"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// This is a compile-time assertion that a sufficiently up-to-date version
// of the legacy proto package is being used.
const _ = proto.ProtoPackageIsVersion4
type Job struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
StartAt *timestamp.Timestamp `protobuf:"bytes,1,opt,name=StartAt,proto3" json:"StartAt,omitempty"`
StopAt *timestamp.Timestamp `protobuf:"bytes,2,opt,name=StopAt,proto3" json:"StopAt,omitempty"`
Source string `protobuf:"bytes,3,opt,name=Source,proto3" json:"Source,omitempty"`
ID int64 `protobuf:"varint,4,opt,name=ID,proto3" json:"ID,omitempty"`
Version string `protobuf:"bytes,5,opt,name=Version,proto3" json:"Version,omitempty"`
}
func (x *Job) Reset() {
*x = Job{}
if protoimpl.UnsafeEnabled {
mi := &file_api_PlayoutService_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Job) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Job) ProtoMessage() {}
func (x *Job) ProtoReflect() protoreflect.Message {
mi := &file_api_PlayoutService_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Job.ProtoReflect.Descriptor instead.
func (*Job) Descriptor() ([]byte, []int) {
return file_api_PlayoutService_proto_rawDescGZIP(), []int{0}
}
func (x *Job) GetStartAt() *timestamp.Timestamp {
if x != nil {
return x.StartAt
}
return nil
}
func (x *Job) GetStopAt() *timestamp.Timestamp {
if x != nil {
return x.StopAt
}
return nil
}
func (x *Job) GetSource() string {
if x != nil {
return x.Source
}
return ""
}
func (x *Job) GetID() int64 {
if x != nil {
return x.ID
}
return 0
}
func (x *Job) GetVersion() string {
if x != nil {
return x.Version
}
return ""
}
type ScheduledJob struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
ID int64 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"`
Port string `protobuf:"bytes,2,opt,name=Port,proto3" json:"Port,omitempty"`
Room string `protobuf:"bytes,3,opt,name=Room,proto3" json:"Room,omitempty"`
Version string `protobuf:"bytes,4,opt,name=Version,proto3" json:"Version,omitempty"`
}
func (x *ScheduledJob) Reset() {
*x = ScheduledJob{}
if protoimpl.UnsafeEnabled {
mi := &file_api_PlayoutService_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ScheduledJob) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ScheduledJob) ProtoMessage() {}
func (x *ScheduledJob) ProtoReflect() protoreflect.Message {
mi := &file_api_PlayoutService_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ScheduledJob.ProtoReflect.Descriptor instead.
func (*ScheduledJob) Descriptor() ([]byte, []int) {
return file_api_PlayoutService_proto_rawDescGZIP(), []int{1}
}
func (x *ScheduledJob) GetID() int64 {
if x != nil {
return x.ID
}
return 0
}
func (x *ScheduledJob) GetPort() string {
if x != nil {
return x.Port
}
return ""
}
func (x *ScheduledJob) GetRoom() string {
if x != nil {
return x.Room
}
return ""
}
func (x *ScheduledJob) GetVersion() string {
if x != nil {
return x.Version
}
return ""
}
var File_api_PlayoutService_proto protoreflect.FileDescriptor
var file_api_PlayoutService_proto_rawDesc = []byte{
0x0a, 0x18, 0x61, 0x70, 0x69, 0x2f, 0x50, 0x6c, 0x61, 0x79, 0x6f, 0x75, 0x74, 0x53, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x61, 0x70, 0x69, 0x1a,
0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66,
0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x22, 0xb1, 0x01, 0x0a, 0x03, 0x4a, 0x6f, 0x62, 0x12, 0x34, 0x0a, 0x07, 0x53, 0x74, 0x61, 0x72,
0x74, 0x41, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67,
0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65,
0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x07, 0x53, 0x74, 0x61, 0x72, 0x74, 0x41, 0x74, 0x12, 0x32,
0x0a, 0x06, 0x53, 0x74, 0x6f, 0x70, 0x41, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a,
0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66,
0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x06, 0x53, 0x74, 0x6f, 0x70,
0x41, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01,
0x28, 0x09, 0x52, 0x06, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x44,
0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x49, 0x44, 0x12, 0x18, 0x0a, 0x07, 0x56, 0x65,
0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x56, 0x65, 0x72,
0x73, 0x69, 0x6f, 0x6e, 0x22, 0x60, 0x0a, 0x0c, 0x53, 0x63, 0x68, 0x65, 0x64, 0x75, 0x6c, 0x65,
0x64, 0x4a, 0x6f, 0x62, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03,
0x52, 0x02, 0x49, 0x44, 0x12, 0x12, 0x0a, 0x04, 0x50, 0x6f, 0x72, 0x74, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x04, 0x50, 0x6f, 0x72, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x52, 0x6f, 0x6f, 0x6d,
0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x52, 0x6f, 0x6f, 0x6d, 0x12, 0x18, 0x0a, 0x07,
0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x56,
0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x32, 0x3b, 0x0a, 0x07, 0x50, 0x6c, 0x61, 0x79, 0x6f, 0x75,
0x74, 0x12, 0x30, 0x0a, 0x0f, 0x53, 0x63, 0x68, 0x65, 0x64, 0x75, 0x6c, 0x65, 0x50, 0x6c, 0x61,
0x79, 0x6f, 0x75, 0x74, 0x12, 0x08, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4a, 0x6f, 0x62, 0x1a, 0x11,
0x2e, 0x61, 0x70, 0x69, 0x2e, 0x53, 0x63, 0x68, 0x65, 0x64, 0x75, 0x6c, 0x65, 0x64, 0x4a, 0x6f,
0x62, 0x22, 0x00, 0x42, 0x29, 0x5a, 0x27, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f,
0x6d, 0x2f, 0x47, 0x61, 0x72, 0x69, 0x6f, 0x6e, 0x69, 0x6f, 0x6e, 0x2f, 0x66, 0x66, 0x6d, 0x70,
0x65, 0x67, 0x2d, 0x70, 0x6c, 0x61, 0x79, 0x6f, 0x75, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_api_PlayoutService_proto_rawDescOnce sync.Once
file_api_PlayoutService_proto_rawDescData = file_api_PlayoutService_proto_rawDesc
)
func file_api_PlayoutService_proto_rawDescGZIP() []byte {
file_api_PlayoutService_proto_rawDescOnce.Do(func() {
file_api_PlayoutService_proto_rawDescData = protoimpl.X.CompressGZIP(file_api_PlayoutService_proto_rawDescData)
})
return file_api_PlayoutService_proto_rawDescData
}
var file_api_PlayoutService_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_api_PlayoutService_proto_goTypes = []interface{}{
(*Job)(nil), // 0: api.Job
(*ScheduledJob)(nil), // 1: api.ScheduledJob
(*timestamp.Timestamp)(nil), // 2: google.protobuf.Timestamp
}
var file_api_PlayoutService_proto_depIdxs = []int32{
2, // 0: api.Job.StartAt:type_name -> google.protobuf.Timestamp
2, // 1: api.Job.StopAt:type_name -> google.protobuf.Timestamp
0, // 2: api.Playout.SchedulePlayout:input_type -> api.Job
1, // 3: api.Playout.SchedulePlayout:output_type -> api.ScheduledJob
3, // [3:4] is the sub-list for method output_type
2, // [2:3] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name
2, // [2:2] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name
}
func init() { file_api_PlayoutService_proto_init() }
func file_api_PlayoutService_proto_init() {
if File_api_PlayoutService_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_api_PlayoutService_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Job); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_api_PlayoutService_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ScheduledJob); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_api_PlayoutService_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_api_PlayoutService_proto_goTypes,
DependencyIndexes: file_api_PlayoutService_proto_depIdxs,
MessageInfos: file_api_PlayoutService_proto_msgTypes,
}.Build()
File_api_PlayoutService_proto = out.File
file_api_PlayoutService_proto_rawDesc = nil
file_api_PlayoutService_proto_goTypes = nil
file_api_PlayoutService_proto_depIdxs = nil
}

26
api/PlayoutService.proto Normal file
View file

@ -0,0 +1,26 @@
syntax = "proto3";
option go_package = "github.com/Garionion/ffmpeg-playout/api";
package api;
import "google/protobuf/timestamp.proto";
service Playout {
rpc SchedulePlayout (Job) returns (ScheduledJob) {}
}
message Job {
google.protobuf.Timestamp StartAt = 1;
google.protobuf.Timestamp StopAt = 2;
string Source = 3;
int64 ID = 4;
string Version = 5;
}
message ScheduledJob {
int64 ID = 1;
string Port = 2;
string Room = 3;
string Version = 4;
}

View file

@ -0,0 +1,97 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
package api
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion7
// PlayoutClient is the client API for Playout service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type PlayoutClient interface {
SchedulePlayout(ctx context.Context, in *Job, opts ...grpc.CallOption) (*ScheduledJob, error)
}
type playoutClient struct {
cc grpc.ClientConnInterface
}
func NewPlayoutClient(cc grpc.ClientConnInterface) PlayoutClient {
return &playoutClient{cc}
}
func (c *playoutClient) SchedulePlayout(ctx context.Context, in *Job, opts ...grpc.CallOption) (*ScheduledJob, error) {
out := new(ScheduledJob)
err := c.cc.Invoke(ctx, "/api.Playout/SchedulePlayout", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// PlayoutServer is the server API for Playout service.
// All implementations must embed UnimplementedPlayoutServer
// for forward compatibility
type PlayoutServer interface {
SchedulePlayout(context.Context, *Job) (*ScheduledJob, error)
mustEmbedUnimplementedPlayoutServer()
}
// UnimplementedPlayoutServer must be embedded to have forward compatible implementations.
type UnimplementedPlayoutServer struct {
}
func (UnimplementedPlayoutServer) SchedulePlayout(context.Context, *Job) (*ScheduledJob, error) {
return nil, status.Errorf(codes.Unimplemented, "method SchedulePlayout not implemented")
}
func (UnimplementedPlayoutServer) mustEmbedUnimplementedPlayoutServer() {}
// UnsafePlayoutServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to PlayoutServer will
// result in compilation errors.
type UnsafePlayoutServer interface {
mustEmbedUnimplementedPlayoutServer()
}
func RegisterPlayoutServer(s grpc.ServiceRegistrar, srv PlayoutServer) {
s.RegisterService(&_Playout_serviceDesc, srv)
}
func _Playout_SchedulePlayout_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Job)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PlayoutServer).SchedulePlayout(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/api.Playout/SchedulePlayout",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PlayoutServer).SchedulePlayout(ctx, req.(*Job))
}
return interceptor(ctx, in, info, handler)
}
var _Playout_serviceDesc = grpc.ServiceDesc{
ServiceName: "api.Playout",
HandlerType: (*PlayoutServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "SchedulePlayout",
Handler: _Playout_SchedulePlayout_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "api/PlayoutService.proto",
}

1
api/api.go Normal file
View file

@ -0,0 +1 @@
package api

14
go.mod
View file

@ -3,13 +3,17 @@ module github.com/Garionion/ffmpeg-playout
go 1.15
require (
github.com/andybalholm/brotli v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.4.9
github.com/gofiber/fiber/v2 v2.1.3
github.com/golang/protobuf v1.4.3
github.com/grafov/bcast v0.0.0-20190217190352-1447f067e08d
github.com/ilyakaznacheev/cleanenv v1.2.5
github.com/json-iterator/go v1.1.10
github.com/klauspost/compress v1.11.2 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
golang.org/x/sys v0.0.0-20201223074533-0d417f636930 // indirect
golang.org/x/text v0.3.4 // indirect
google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d // indirect
google.golang.org/grpc v1.34.0
google.golang.org/protobuf v1.25.0
gopkg.in/fatih/set.v0 v0.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect
)

127
go.sum
View file

@ -1,59 +1,118 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/andybalholm/brotli v1.0.0 h1:7UCwP93aiSfvWpapti8g88vVVGp2qqtGyePsSuDafo4=
github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
github.com/andybalholm/brotli v1.0.1 h1:KqhlKozYbRtJvsPrrEeXcO+N2l6NYT5A2QAFmSULpEc=
github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/gofiber/fiber/v2 v2.1.3 h1:d2fkRf6fkLa1uXgzXqN5iqAydjytoocS83hm1o00Ocg=
github.com/gofiber/fiber/v2 v2.1.3/go.mod h1:MMiSv1HrDkN8Pv7NeVDYK+T/lwXOEKAvPBbLvJPCEfA=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grafov/bcast v0.0.0-20190217190352-1447f067e08d h1:Q2+KsA/1GLC9xyLsDun3/EOJ+83rY/IHRsO1DToPrdo=
github.com/grafov/bcast v0.0.0-20190217190352-1447f067e08d/go.mod h1:RInr+B3/Tx70hYm0rpNPMTD7vH0pBG5ny/JsHAs2KcQ=
github.com/ilyakaznacheev/cleanenv v1.2.5 h1:/SlcF9GaIvefWqFJzsccGG/NJdoaAwb7Mm7ImzhO3DM=
github.com/ilyakaznacheev/cleanenv v1.2.5/go.mod h1:/i3yhzwZ3s7hacNERGFwvlhwXMDcaqwIzmayEhbRplk=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/klauspost/compress v1.10.7 h1:7rix8v8GpI3ZBb0nSozFRgbtXKv+hOe+qfEpZqybrAg=
github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.11.2 h1:MiK62aErc3gIiVEtyzKfeOHgW7atJb5g/KNX5m3c2nQ=
github.com/klauspost/compress v1.11.2/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.16.0 h1:9zAqOYLl8Tuy3E5R6ckzGDJ1g8+pw15oQp2iL9Jl6gQ=
github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a h1:0R4NLDRDZX6JcmhJgXi5E4b8Wg84ihbmUKp/GvSPEzc=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw=
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201101102859-da207088b7d1 h1:a/mKvvZr9Jcc8oKfcmgzyp7OwF73JPWsQLvH1z2Kxck=
golang.org/x/sys v0.0.0-20201101102859-da207088b7d1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201223074533-0d417f636930 h1:vRgIt+nup/B/BwIS0g2oC0haq0iqbV3ZA+u6+0TlNCo=
golang.org/x/sys v0.0.0-20201223074533-0d417f636930/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d h1:HV9Z9qMhQEsdlvxNFELgQ11RkMzO3CMkjEySjCtuLes=
google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.34.0 h1:raiipEjMOIC/TO2AvyTxP25XFdLxNIBwzDh3FM3XztI=
google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fatih/set.v0 v0.2.1 h1:Xvyyp7LXu34P0ROhCyfXkmQCAoOUKb1E2JS9I7SE5CY=
gopkg.in/fatih/set.v0 v0.2.1/go.mod h1:5eLWEndGL4zGGemXWrKuts+wTJR0y+w+auqUJZbmyBg=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
olympos.io/encoding/edn v0.0.0-20200308123125-93e3b8dd0e24 h1:sreVOrDp0/ezb0CHKVek/l7YwpxPJqv+jT3izfSphA4=
olympos.io/encoding/edn v0.0.0-20200308123125-93e3b8dd0e24/go.mod h1:oVgVk4OWVDi43qWBEyGhXgYxt7+ED4iYNpTngSLX2Iw=
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 h1:slmdOY3vp8a7KQbHkL+FLbvbkgMqmXojpFUO/jENuqQ=

192
main.go
View file

@ -1,20 +1,24 @@
package main
import (
"context"
"errors"
"fmt"
"github.com/Garionion/ffmpeg-playout/api"
"github.com/Garionion/ffmpeg-playout/playout"
"github.com/Garionion/ffmpeg-playout/store"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/golang/protobuf/ptypes"
"github.com/ilyakaznacheev/cleanenv"
jsoniter "github.com/json-iterator/go"
"google.golang.org/grpc"
"log"
"net"
"time"
)
var json = jsoniter.ConfigCompatibleWithStandardLibrary
type server struct {
api.UnimplementedPlayoutServer
*store.Store
}
type Config struct {
Outputs []string `yaml:"outputs"`
@ -27,102 +31,78 @@ type Config struct {
PrometheusPushGateway string `yaml:"prometheusPushGateway"`
}
type Job struct {
StartAt time.Time `json:"startAt,omitempty"`
StopAt time.Time `json:"stopAt,omitempty"`
Source string `json:"source"`
ID int `json:"id"`
Version string `json:"version"`
}
func (g *server) schedulePlayout(ctx context.Context, job *api.Job) (*api.ScheduledJob, error) {
var p *playout.Job
var err error
type ScheduledJob struct {
ID int `json:"id"`
Port string `json:"port"`
Room string `json:"room"`
Version string `json:"version"`
}
func schedulePlayout(s *store.Store) fiber.Handler {
// TODO return custom error
return func(c *fiber.Ctx) error {
var p *playout.Job
job := new(Job)
jsonErr := json.Unmarshal(c.Body(), job)
if jsonErr != nil {
log.Println("got defective request: ", jsonErr)
c.SendStatus(400)
return jsonErr
}
if job.Source == "" {
c.SendStatus(400)
return errors.New("Got Empty Source. I can't play »Nothing«")
}
var output string
newPlayoutJob := new(playout.Job)
s.RLock()
olPlayoutJob, playoutExists := s.Playouts[job.ID]
s.RUnlock()
if playoutExists {
p = olPlayoutJob
} else {
p = newPlayoutJob
p.ControlChannel = make(chan string)
}
p.ID = job.ID
p.Source = job.Source
p.Version = job.Version
p.StartAt = job.StartAt
if job.StopAt.IsZero() {
p.StopAt = p.StartAt.Add(s.DefaultDuration)
} else {
p.StopAt = job.StopAt
}
if playoutExists {
p.ControlChannel <- "reschedule"
output = p.Output
} else {
var err error
s.Lock()
output, err = s.AddPlayout(p)
s.Unlock()
if err != nil {
c.SendStatus(500)
return fmt.Errorf("can not schedule playout: %s", err)
}
}
c.JSON(ScheduledJob{
ID: p.ID,
Port: output,
Version: p.Version,
})
if !playoutExists {
go func() {
log.Printf("Start Scheduling %v", p.ID)
Waiting:
for {
select {
case ctrlMsg := <-p.ControlChannel:
log.Printf("%d Control Message: %s", p.ID, ctrlMsg)
continue
case <-time.After(time.Until(p.StartAt)):
break Waiting
}
}
p.Playout(s.Config)
s.DeletePlayout(p.ID)
}()
}
// staus 409 when no schedule possible
return nil
if job.Source == "" {
return nil, errors.New("Got Empty Source. I can't play »Nothing«")
}
var output string
newPlayoutJob := new(playout.Job)
g.Store.RLock()
olPlayoutJob, playoutExists := g.Store.Playouts[job.ID]
g.Store.RUnlock()
if playoutExists {
p = olPlayoutJob
} else {
p = newPlayoutJob
p.ControlChannel = make(chan string)
}
p.ID = job.ID
p.Source = job.Source
p.Version = job.Version
p.StartAt, err = ptypes.Timestamp(job.StartAt)
if err != nil {
return nil, err
}
if p.StopAt.IsZero() {
p.StopAt = p.StartAt.Add(g.Store.DefaultDuration)
} else {
p.StopAt, err = ptypes.Timestamp(job.StartAt)
}
if playoutExists {
p.ControlChannel <- "reschedule"
output = p.Output
} else {
var err error
g.Store.Lock()
output, err = g.Store.AddPlayout(p)
g.Store.Unlock()
if err != nil {
return nil, fmt.Errorf("can not schedule playout: %s", err)
}
}
scheduledJob := &api.ScheduledJob{
ID: p.ID,
Port: output,
Version: p.Version,
}
if !playoutExists {
go func() {
log.Printf("Start Scheduling %v", p.ID)
Waiting:
for {
select {
case ctrlMsg := <-p.ControlChannel:
log.Printf("%d Control Message: %s", p.ID, ctrlMsg)
continue
case <-time.After(time.Until(p.StartAt)):
break Waiting
}
}
p.Playout(g.Store.Config)
g.Store.DeletePlayout(p.ID)
}()
}
return scheduledJob, nil
}
var cfg Config
@ -137,18 +117,16 @@ func main() {
if err != nil {
log.Fatal("Failed to init Store: ", err.Error())
}
app := fiber.New()
app.Use(cors.New())
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
})
app.Post("/schedulePlayout", schedulePlayout(s))
server := &server{
Store: s,
}
ln, err := net.Listen("tcp", cfg.Address)
if err != nil {
log.Fatal(err)
}
log.Fatal(app.Listener(ln))
g := grpc.NewServer()
api.RegisterPlayoutServer(g, server)
log.Fatalf("failed to serve: %v", g.Serve(ln))
}

View file

@ -17,7 +17,7 @@ import (
)
type Job struct {
ID int
ID int64
Version string
StartAt time.Time
StopAt time.Time
@ -79,7 +79,7 @@ func monitorFFmpeg(cfg *Config, progressPath string, f *bcast.Member, output str
f.Close()
}
func killProcess(cmd *exec.Cmd, id int) {
func killProcess(cmd *exec.Cmd, id int64) {
log.Printf("Kill %v", cmd.Process.Pid)
err := syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
if err != nil {
@ -91,7 +91,7 @@ func killProcess(cmd *exec.Cmd, id int) {
//nolint:funlen
func (p *Job) Playout(cfg *Config) {
progressPath := path.Join(cfg.ProgressDir, strconv.Itoa(p.ID))
progressPath := path.Join(cfg.ProgressDir, strconv.FormatInt(p.ID, 10))
playoutScript := path.Join(cfg.PlayoutScriptPath, cfg.PlayoutScript)
for {
log.Printf("Start Playout for %v", p.ID)

View file

@ -2,14 +2,14 @@ package store
import (
"errors"
"ffmpeg-playout/playout"
"github.com/Garionion/ffmpeg-playout/playout"
"log"
"sync"
"time"
)
type Store struct {
Playouts map[int]*playout.Job
Playouts map[int64]*playout.Job
DefaultDuration time.Duration
Outputs []string
*playout.Config
@ -17,7 +17,7 @@ type Store struct {
}
func NewStore(o []string, defaultDuration string, playoutScriptPath string, playoutScript string, tmpDir string, prometheus string, format string) (*Store, error) {
playouts := make(map[int]*playout.Job)
playouts := make(map[int64]*playout.Job)
var d time.Duration
var err error
@ -61,7 +61,7 @@ func (s *Store) AddPlayout(p *playout.Job) (string, error) {
return output, nil
}
func (s *Store) DeletePlayout(id int) {
func (s *Store) DeletePlayout(id int64) {
s.Lock()
delete(s.Playouts, id)
s.Unlock()