diff --git a/Dockerfile b/Dockerfile index 2f6747b..50c6ff7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ FROM golang:1.23.1-bullseye AS builder LABEL stage=gobuilder # Env -ENV CGO_ENABLE 0 +ENV CGO_ENABLED 0 ENV GOOS linux ENV GOARCH amd64 #ENV GOPROXY https://goproxy.cn,direct diff --git a/plugin/transcode/api.go b/plugin/transcode/api.go index cb0797b..86ca5fa 100755 --- a/plugin/transcode/api.go +++ b/plugin/transcode/api.go @@ -4,6 +4,7 @@ import ( "context" "encoding/base64" "fmt" + "google.golang.org/protobuf/types/known/emptypb" "net/url" "os" "path" @@ -292,10 +293,47 @@ func (t *TranscodePlugin) Launch(ctx context.Context, transReq *pb.TransRequest) return } -func (t *TranscodePlugin) Close(ctx context.Context, closeReq *pb.CloseRequest) (response *globalPB.SuccessResponse, err error) { +type TranscodeingStream struct { + SrcStream string + DestStream string +} + +func (t *TranscodePlugin) Close(ctx context.Context, closeReq *pb.TransTwin) (response *globalPB.SuccessResponse, err error) { response = &globalPB.SuccessResponse{} if item, ok := t.Server.Transforms.Get(closeReq.DstStream); ok { item.TransformJob.Stop(fmt.Errorf("manual closed")) } return } + +func (t *TranscodePlugin) List(context.Context, *emptypb.Empty) (*pb.TransListResponse, error) { + data := make([]*pb.TransTwin, 0) + t.Server.Transforms.Call(func() error { + for transformedMap := range t.Server.Transforms.Range { + if _, ok := transformedMap.TransformJob.Transformer.(*transcode.Transformer); ok { + data = append(data, &pb.TransTwin{ + SrcStream: transformedMap.TransformJob.StreamPath, + DstStream: transformedMap.Target, + }) + } + } + return nil + }) + return &pb.TransListResponse{ + Code: 0, + Message: "success", + Data: data, + }, nil +} + +func (t *TranscodePlugin) Exist(ctx context.Context, req *pb.TransTwin) (*globalPB.SuccessResponse, error) { + response := &globalPB.SuccessResponse{} + if _, ok := t.Server.Transforms.Get(req.DstStream); ok { + response.Code = 0 + response.Message = "success" + } else { + response.Code = 1 + response.Message = "fail" + } + return response, nil +} diff --git a/plugin/transcode/pb/transcode.pb.go b/plugin/transcode/pb/transcode.pb.go index bfb24ff..8019a20 100644 --- a/plugin/transcode/pb/transcode.pb.go +++ b/plugin/transcode/pb/transcode.pb.go @@ -10,7 +10,7 @@ import ( _ "google.golang.org/genproto/googleapis/api/annotations" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - _ "google.golang.org/protobuf/types/known/emptypb" + emptypb "google.golang.org/protobuf/types/known/emptypb" pb "m7s.live/m7s/v5/pb" reflect "reflect" sync "sync" @@ -249,29 +249,29 @@ func (x *TransRequest) GetOverlayConfigs() []*OverlayConfig { return nil } -type CloseRequest struct { +type TransTwin struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - SrcStream string `protobuf:"bytes,1,opt,name=src_stream,json=srcStream,proto3" json:"src_stream,omitempty"` // 原始流 - DstStream string `protobuf:"bytes,2,opt,name=dst_stream,json=dstStream,proto3" json:"dst_stream,omitempty"` // 输出流 + SrcStream string `protobuf:"bytes,1,opt,name=src_stream,proto3" json:"src_stream,omitempty"` // 原始流 + DstStream string `protobuf:"bytes,2,opt,name=dst_stream,proto3" json:"dst_stream,omitempty"` // 输出流 } -func (x *CloseRequest) Reset() { - *x = CloseRequest{} +func (x *TransTwin) Reset() { + *x = TransTwin{} mi := &file_transcode_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *CloseRequest) String() string { +func (x *TransTwin) String() string { return protoimpl.X.MessageStringOf(x) } -func (*CloseRequest) ProtoMessage() {} +func (*TransTwin) ProtoMessage() {} -func (x *CloseRequest) ProtoReflect() protoreflect.Message { +func (x *TransTwin) ProtoReflect() protoreflect.Message { mi := &file_transcode_proto_msgTypes[2] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -283,25 +283,86 @@ func (x *CloseRequest) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use CloseRequest.ProtoReflect.Descriptor instead. -func (*CloseRequest) Descriptor() ([]byte, []int) { +// Deprecated: Use TransTwin.ProtoReflect.Descriptor instead. +func (*TransTwin) Descriptor() ([]byte, []int) { return file_transcode_proto_rawDescGZIP(), []int{2} } -func (x *CloseRequest) GetSrcStream() string { +func (x *TransTwin) GetSrcStream() string { if x != nil { return x.SrcStream } return "" } -func (x *CloseRequest) GetDstStream() string { +func (x *TransTwin) GetDstStream() string { if x != nil { return x.DstStream } return "" } +type TransListResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` + Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` + Data []*TransTwin `protobuf:"bytes,3,rep,name=data,proto3" json:"data,omitempty"` +} + +func (x *TransListResponse) Reset() { + *x = TransListResponse{} + mi := &file_transcode_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *TransListResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TransListResponse) ProtoMessage() {} + +func (x *TransListResponse) ProtoReflect() protoreflect.Message { + mi := &file_transcode_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TransListResponse.ProtoReflect.Descriptor instead. +func (*TransListResponse) Descriptor() ([]byte, []int) { + return file_transcode_proto_rawDescGZIP(), []int{3} +} + +func (x *TransListResponse) GetCode() int32 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *TransListResponse) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +func (x *TransListResponse) GetData() []*TransTwin { + if x != nil { + return x.Data + } + return nil +} + var File_transcode_proto protoreflect.FileDescriptor var file_transcode_proto_rawDesc = []byte{ @@ -354,26 +415,44 @@ var file_transcode_proto_rawDesc = []byte{ 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x4f, 0x76, 0x65, 0x72, 0x6c, 0x61, 0x79, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x0e, 0x6f, 0x76, 0x65, 0x72, 0x6c, 0x61, 0x79, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x73, 0x22, - 0x4c, 0x0a, 0x0c, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, - 0x1d, 0x0a, 0x0a, 0x73, 0x72, 0x63, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x72, 0x63, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x1d, - 0x0a, 0x0a, 0x64, 0x73, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x09, 0x64, 0x73, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x32, 0xbf, 0x01, - 0x0a, 0x03, 0x61, 0x70, 0x69, 0x12, 0x5c, 0x0a, 0x06, 0x6c, 0x61, 0x75, 0x6e, 0x63, 0x68, 0x12, - 0x17, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, - 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, - 0x6c, 0x2e, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x22, 0x20, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1a, 0x3a, 0x01, 0x2a, 0x22, 0x15, 0x2f, 0x74, - 0x72, 0x61, 0x6e, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6c, 0x61, 0x75, - 0x6e, 0x63, 0x68, 0x12, 0x5a, 0x0a, 0x05, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x12, 0x17, 0x2e, 0x74, - 0x72, 0x61, 0x6e, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x2e, 0x53, - 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1f, - 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, 0x01, 0x2a, 0x22, 0x14, 0x2f, 0x74, 0x72, 0x61, 0x6e, - 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x42, - 0x25, 0x5a, 0x23, 0x6d, 0x37, 0x73, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x2f, 0x6d, 0x37, 0x73, 0x2f, - 0x76, 0x35, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x63, - 0x6f, 0x64, 0x65, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x4b, 0x0a, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x77, 0x69, 0x6e, 0x12, 0x1e, 0x0a, 0x0a, + 0x73, 0x72, 0x63, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x73, 0x72, 0x63, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x1e, 0x0a, 0x0a, + 0x64, 0x73, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x64, 0x73, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x22, 0x6b, 0x0a, 0x11, + 0x54, 0x72, 0x61, 0x6e, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, + 0x28, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, + 0x74, 0x72, 0x61, 0x6e, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, + 0x77, 0x69, 0x6e, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x32, 0xed, 0x02, 0x0a, 0x03, 0x61, 0x70, + 0x69, 0x12, 0x5c, 0x0a, 0x06, 0x6c, 0x61, 0x75, 0x6e, 0x63, 0x68, 0x12, 0x17, 0x2e, 0x74, 0x72, + 0x61, 0x6e, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x2e, 0x53, 0x75, + 0x63, 0x63, 0x65, 0x73, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x20, 0x82, + 0xd3, 0xe4, 0x93, 0x02, 0x1a, 0x3a, 0x01, 0x2a, 0x22, 0x15, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, + 0x63, 0x6f, 0x64, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6c, 0x61, 0x75, 0x6e, 0x63, 0x68, 0x12, + 0x57, 0x0a, 0x05, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x12, 0x14, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, + 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x77, 0x69, 0x6e, 0x1a, 0x17, + 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x2e, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, + 0x01, 0x2a, 0x22, 0x14, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2f, 0x61, + 0x70, 0x69, 0x2f, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x12, 0x59, 0x0a, 0x04, 0x6c, 0x69, 0x73, 0x74, + 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1c, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, + 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x15, 0x12, 0x13, + 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6c, + 0x69, 0x73, 0x74, 0x12, 0x54, 0x0a, 0x05, 0x65, 0x78, 0x69, 0x73, 0x74, 0x12, 0x14, 0x2e, 0x74, + 0x72, 0x61, 0x6e, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x77, + 0x69, 0x6e, 0x1a, 0x17, 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x2e, 0x53, 0x75, 0x63, 0x63, + 0x65, 0x73, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1c, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x16, 0x12, 0x14, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2f, + 0x61, 0x70, 0x69, 0x2f, 0x65, 0x78, 0x69, 0x73, 0x74, 0x42, 0x25, 0x5a, 0x23, 0x6d, 0x37, 0x73, + 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x2f, 0x6d, 0x37, 0x73, 0x2f, 0x76, 0x35, 0x2f, 0x70, 0x6c, 0x75, + 0x67, 0x69, 0x6e, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2f, 0x70, 0x62, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -388,24 +467,31 @@ func file_transcode_proto_rawDescGZIP() []byte { return file_transcode_proto_rawDescData } -var file_transcode_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_transcode_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_transcode_proto_goTypes = []any{ (*OverlayConfig)(nil), // 0: transcode.OverlayConfig (*TransRequest)(nil), // 1: transcode.TransRequest - (*CloseRequest)(nil), // 2: transcode.CloseRequest - (*pb.SuccessResponse)(nil), // 3: global.SuccessResponse + (*TransTwin)(nil), // 2: transcode.TransTwin + (*TransListResponse)(nil), // 3: transcode.TransListResponse + (*emptypb.Empty)(nil), // 4: google.protobuf.Empty + (*pb.SuccessResponse)(nil), // 5: global.SuccessResponse } var file_transcode_proto_depIdxs = []int32{ 0, // 0: transcode.TransRequest.overlay_configs:type_name -> transcode.OverlayConfig - 1, // 1: transcode.api.launch:input_type -> transcode.TransRequest - 2, // 2: transcode.api.close:input_type -> transcode.CloseRequest - 3, // 3: transcode.api.launch:output_type -> global.SuccessResponse - 3, // 4: transcode.api.close:output_type -> global.SuccessResponse - 3, // [3:5] is the sub-list for method output_type - 1, // [1:3] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name + 2, // 1: transcode.TransListResponse.data:type_name -> transcode.TransTwin + 1, // 2: transcode.api.launch:input_type -> transcode.TransRequest + 2, // 3: transcode.api.close:input_type -> transcode.TransTwin + 4, // 4: transcode.api.list:input_type -> google.protobuf.Empty + 2, // 5: transcode.api.exist:input_type -> transcode.TransTwin + 5, // 6: transcode.api.launch:output_type -> global.SuccessResponse + 5, // 7: transcode.api.close:output_type -> global.SuccessResponse + 3, // 8: transcode.api.list:output_type -> transcode.TransListResponse + 5, // 9: transcode.api.exist:output_type -> global.SuccessResponse + 6, // [6:10] is the sub-list for method output_type + 2, // [2:6] 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_transcode_proto_init() } @@ -419,7 +505,7 @@ func file_transcode_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_transcode_proto_rawDesc, NumEnums: 0, - NumMessages: 3, + NumMessages: 4, NumExtensions: 0, NumServices: 1, }, diff --git a/plugin/transcode/pb/transcode.pb.gw.go b/plugin/transcode/pb/transcode.pb.gw.go index 3f6d465..229e448 100644 --- a/plugin/transcode/pb/transcode.pb.gw.go +++ b/plugin/transcode/pb/transcode.pb.gw.go @@ -21,6 +21,7 @@ import ( "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/emptypb" ) // Suppress "imported and not used" errors @@ -58,7 +59,7 @@ func local_request_Api_Launch_0(ctx context.Context, marshaler runtime.Marshaler } func request_Api_Close_0(ctx context.Context, marshaler runtime.Marshaler, client ApiClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq CloseRequest + var protoReq TransTwin var metadata runtime.ServerMetadata if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { @@ -71,7 +72,7 @@ func request_Api_Close_0(ctx context.Context, marshaler runtime.Marshaler, clien } func local_request_Api_Close_0(ctx context.Context, marshaler runtime.Marshaler, server ApiServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq CloseRequest + var protoReq TransTwin var metadata runtime.ServerMetadata if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { @@ -83,6 +84,60 @@ func local_request_Api_Close_0(ctx context.Context, marshaler runtime.Marshaler, } +func request_Api_List_0(ctx context.Context, marshaler runtime.Marshaler, client ApiClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq emptypb.Empty + var metadata runtime.ServerMetadata + + msg, err := client.List(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Api_List_0(ctx context.Context, marshaler runtime.Marshaler, server ApiServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq emptypb.Empty + var metadata runtime.ServerMetadata + + msg, err := server.List(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Api_Exist_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Api_Exist_0(ctx context.Context, marshaler runtime.Marshaler, client ApiClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq TransTwin + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Api_Exist_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Exist(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Api_Exist_0(ctx context.Context, marshaler runtime.Marshaler, server ApiServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq TransTwin + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Api_Exist_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Exist(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterApiHandlerServer registers the http handlers for service Api to "mux". // UnaryRPC :call ApiServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -140,6 +195,56 @@ func RegisterApiHandlerServer(ctx context.Context, mux *runtime.ServeMux, server }) + mux.Handle("GET", pattern_Api_List_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/transcode.Api/List", runtime.WithHTTPPathPattern("/transcode/api/list")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Api_List_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Api_List_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Api_Exist_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/transcode.Api/Exist", runtime.WithHTTPPathPattern("/transcode/api/exist")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Api_Exist_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Api_Exist_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -225,6 +330,50 @@ func RegisterApiHandlerClient(ctx context.Context, mux *runtime.ServeMux, client }) + mux.Handle("GET", pattern_Api_List_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/transcode.Api/List", runtime.WithHTTPPathPattern("/transcode/api/list")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Api_List_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Api_List_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Api_Exist_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/transcode.Api/Exist", runtime.WithHTTPPathPattern("/transcode/api/exist")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Api_Exist_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Api_Exist_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -232,10 +381,18 @@ var ( pattern_Api_Launch_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"transcode", "api", "launch"}, "")) pattern_Api_Close_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"transcode", "api", "close"}, "")) + + pattern_Api_List_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"transcode", "api", "list"}, "")) + + pattern_Api_Exist_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"transcode", "api", "exist"}, "")) ) var ( forward_Api_Launch_0 = runtime.ForwardResponseMessage forward_Api_Close_0 = runtime.ForwardResponseMessage + + forward_Api_List_0 = runtime.ForwardResponseMessage + + forward_Api_Exist_0 = runtime.ForwardResponseMessage ) diff --git a/plugin/transcode/pb/transcode.proto b/plugin/transcode/pb/transcode.proto index 86efef3..3f9e120 100644 --- a/plugin/transcode/pb/transcode.proto +++ b/plugin/transcode/pb/transcode.proto @@ -13,12 +13,24 @@ service api { body: "*" }; } - rpc close (CloseRequest) returns (global.SuccessResponse) { + rpc close (TransTwin) returns (global.SuccessResponse) { option (google.api.http) = { post: "/transcode/api/close" body: "*" }; } + + rpc list (google.protobuf.Empty) returns (TransListResponse) { + option (google.api.http) = { + get: "/transcode/api/list" + }; + } + + rpc exist (TransTwin) returns (global.SuccessResponse) { + option (google.api.http) = { + get: "/transcode/api/exist" + }; + } } message OverlayConfig { @@ -46,7 +58,13 @@ message TransRequest { repeated OverlayConfig overlay_configs = 8; } -message CloseRequest { - string src_stream = 1; // 原始流 - string dst_stream = 2; // 输出流 +message TransTwin { + string src_stream = 1 [json_name = "src_stream"]; // 原始流 + string dst_stream = 2 [json_name = "dst_stream"]; // 输出流 +} + +message TransListResponse { + int32 code = 1; + string message = 2; + repeated TransTwin data = 3; } \ No newline at end of file diff --git a/plugin/transcode/pb/transcode_grpc.pb.go b/plugin/transcode/pb/transcode_grpc.pb.go index cd69bff..6082534 100644 --- a/plugin/transcode/pb/transcode_grpc.pb.go +++ b/plugin/transcode/pb/transcode_grpc.pb.go @@ -11,6 +11,7 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + emptypb "google.golang.org/protobuf/types/known/emptypb" pb "m7s.live/m7s/v5/pb" ) @@ -22,6 +23,8 @@ const _ = grpc.SupportPackageIsVersion9 const ( Api_Launch_FullMethodName = "/transcode.api/launch" Api_Close_FullMethodName = "/transcode.api/close" + Api_List_FullMethodName = "/transcode.api/list" + Api_Exist_FullMethodName = "/transcode.api/exist" ) // ApiClient is the client API for Api service. @@ -29,7 +32,9 @@ const ( // 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 ApiClient interface { Launch(ctx context.Context, in *TransRequest, opts ...grpc.CallOption) (*pb.SuccessResponse, error) - Close(ctx context.Context, in *CloseRequest, opts ...grpc.CallOption) (*pb.SuccessResponse, error) + Close(ctx context.Context, in *TransTwin, opts ...grpc.CallOption) (*pb.SuccessResponse, error) + List(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*TransListResponse, error) + Exist(ctx context.Context, in *TransTwin, opts ...grpc.CallOption) (*pb.SuccessResponse, error) } type apiClient struct { @@ -50,7 +55,7 @@ func (c *apiClient) Launch(ctx context.Context, in *TransRequest, opts ...grpc.C return out, nil } -func (c *apiClient) Close(ctx context.Context, in *CloseRequest, opts ...grpc.CallOption) (*pb.SuccessResponse, error) { +func (c *apiClient) Close(ctx context.Context, in *TransTwin, opts ...grpc.CallOption) (*pb.SuccessResponse, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(pb.SuccessResponse) err := c.cc.Invoke(ctx, Api_Close_FullMethodName, in, out, cOpts...) @@ -60,12 +65,34 @@ func (c *apiClient) Close(ctx context.Context, in *CloseRequest, opts ...grpc.Ca return out, nil } +func (c *apiClient) List(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*TransListResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(TransListResponse) + err := c.cc.Invoke(ctx, Api_List_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *apiClient) Exist(ctx context.Context, in *TransTwin, opts ...grpc.CallOption) (*pb.SuccessResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(pb.SuccessResponse) + err := c.cc.Invoke(ctx, Api_Exist_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // ApiServer is the server API for Api service. // All implementations must embed UnimplementedApiServer // for forward compatibility. type ApiServer interface { Launch(context.Context, *TransRequest) (*pb.SuccessResponse, error) - Close(context.Context, *CloseRequest) (*pb.SuccessResponse, error) + Close(context.Context, *TransTwin) (*pb.SuccessResponse, error) + List(context.Context, *emptypb.Empty) (*TransListResponse, error) + Exist(context.Context, *TransTwin) (*pb.SuccessResponse, error) mustEmbedUnimplementedApiServer() } @@ -79,9 +106,15 @@ type UnimplementedApiServer struct{} func (UnimplementedApiServer) Launch(context.Context, *TransRequest) (*pb.SuccessResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Launch not implemented") } -func (UnimplementedApiServer) Close(context.Context, *CloseRequest) (*pb.SuccessResponse, error) { +func (UnimplementedApiServer) Close(context.Context, *TransTwin) (*pb.SuccessResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Close not implemented") } +func (UnimplementedApiServer) List(context.Context, *emptypb.Empty) (*TransListResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method List not implemented") +} +func (UnimplementedApiServer) Exist(context.Context, *TransTwin) (*pb.SuccessResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Exist not implemented") +} func (UnimplementedApiServer) mustEmbedUnimplementedApiServer() {} func (UnimplementedApiServer) testEmbeddedByValue() {} @@ -122,7 +155,7 @@ func _Api_Launch_Handler(srv interface{}, ctx context.Context, dec func(interfac } func _Api_Close_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(CloseRequest) + in := new(TransTwin) if err := dec(in); err != nil { return nil, err } @@ -134,7 +167,43 @@ func _Api_Close_Handler(srv interface{}, ctx context.Context, dec func(interface FullMethod: Api_Close_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ApiServer).Close(ctx, req.(*CloseRequest)) + return srv.(ApiServer).Close(ctx, req.(*TransTwin)) + } + return interceptor(ctx, in, info, handler) +} + +func _Api_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(emptypb.Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ApiServer).List(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Api_List_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ApiServer).List(ctx, req.(*emptypb.Empty)) + } + return interceptor(ctx, in, info, handler) +} + +func _Api_Exist_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(TransTwin) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ApiServer).Exist(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Api_Exist_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ApiServer).Exist(ctx, req.(*TransTwin)) } return interceptor(ctx, in, info, handler) } @@ -154,6 +223,14 @@ var Api_ServiceDesc = grpc.ServiceDesc{ MethodName: "close", Handler: _Api_Close_Handler, }, + { + MethodName: "list", + Handler: _Api_List_Handler, + }, + { + MethodName: "exist", + Handler: _Api_Exist_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "transcode.proto",