fea: transcode add http api

This commit is contained in:
banshan
2024-10-11 18:00:43 +08:00
parent 1da97f8a43
commit 7ff3279bf3
6 changed files with 436 additions and 60 deletions

View File

@@ -5,7 +5,7 @@ FROM golang:1.23.1-bullseye AS builder
LABEL stage=gobuilder LABEL stage=gobuilder
# Env # Env
ENV CGO_ENABLE 0 ENV CGO_ENABLED 0
ENV GOOS linux ENV GOOS linux
ENV GOARCH amd64 ENV GOARCH amd64
#ENV GOPROXY https://goproxy.cn,direct #ENV GOPROXY https://goproxy.cn,direct

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"google.golang.org/protobuf/types/known/emptypb"
"net/url" "net/url"
"os" "os"
"path" "path"
@@ -292,10 +293,47 @@ func (t *TranscodePlugin) Launch(ctx context.Context, transReq *pb.TransRequest)
return 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{} response = &globalPB.SuccessResponse{}
if item, ok := t.Server.Transforms.Get(closeReq.DstStream); ok { if item, ok := t.Server.Transforms.Get(closeReq.DstStream); ok {
item.TransformJob.Stop(fmt.Errorf("manual closed")) item.TransformJob.Stop(fmt.Errorf("manual closed"))
} }
return 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
}

View File

@@ -10,7 +10,7 @@ import (
_ "google.golang.org/genproto/googleapis/api/annotations" _ "google.golang.org/genproto/googleapis/api/annotations"
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" 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" pb "m7s.live/m7s/v5/pb"
reflect "reflect" reflect "reflect"
sync "sync" sync "sync"
@@ -249,29 +249,29 @@ func (x *TransRequest) GetOverlayConfigs() []*OverlayConfig {
return nil return nil
} }
type CloseRequest struct { type TransTwin struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
SrcStream string `protobuf:"bytes,1,opt,name=src_stream,json=srcStream,proto3" json:"src_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,json=dstStream,proto3" json:"dst_stream,omitempty"` // 输出流 DstStream string `protobuf:"bytes,2,opt,name=dst_stream,proto3" json:"dst_stream,omitempty"` // 输出流
} }
func (x *CloseRequest) Reset() { func (x *TransTwin) Reset() {
*x = CloseRequest{} *x = TransTwin{}
mi := &file_transcode_proto_msgTypes[2] mi := &file_transcode_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
func (x *CloseRequest) String() string { func (x *TransTwin) String() string {
return protoimpl.X.MessageStringOf(x) 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] mi := &file_transcode_proto_msgTypes[2]
if x != nil { if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@@ -283,25 +283,86 @@ func (x *CloseRequest) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x) return mi.MessageOf(x)
} }
// Deprecated: Use CloseRequest.ProtoReflect.Descriptor instead. // Deprecated: Use TransTwin.ProtoReflect.Descriptor instead.
func (*CloseRequest) Descriptor() ([]byte, []int) { func (*TransTwin) Descriptor() ([]byte, []int) {
return file_transcode_proto_rawDescGZIP(), []int{2} return file_transcode_proto_rawDescGZIP(), []int{2}
} }
func (x *CloseRequest) GetSrcStream() string { func (x *TransTwin) GetSrcStream() string {
if x != nil { if x != nil {
return x.SrcStream return x.SrcStream
} }
return "" return ""
} }
func (x *CloseRequest) GetDstStream() string { func (x *TransTwin) GetDstStream() string {
if x != nil { if x != nil {
return x.DstStream return x.DstStream
} }
return "" 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 protoreflect.FileDescriptor
var file_transcode_proto_rawDesc = []byte{ 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, 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, 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, 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, 0x4b, 0x0a, 0x09, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54, 0x77, 0x69, 0x6e, 0x12, 0x1e, 0x0a, 0x0a,
0x1d, 0x0a, 0x0a, 0x73, 0x72, 0x63, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x01, 0x20, 0x73, 0x72, 0x63, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x72, 0x63, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x1d, 0x52, 0x0a, 0x73, 0x72, 0x63, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x1e, 0x0a, 0x0a,
0x0a, 0x0a, 0x64, 0x73, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x64, 0x73, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x28, 0x09, 0x52, 0x09, 0x64, 0x73, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x32, 0xbf, 0x01, 0x52, 0x0a, 0x64, 0x73, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x22, 0x6b, 0x0a, 0x11,
0x0a, 0x03, 0x61, 0x70, 0x69, 0x12, 0x5c, 0x0a, 0x06, 0x6c, 0x61, 0x75, 0x6e, 0x63, 0x68, 0x12, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x17, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52,
0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
0x6c, 0x2e, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12,
0x65, 0x22, 0x20, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1a, 0x3a, 0x01, 0x2a, 0x22, 0x15, 0x2f, 0x74, 0x28, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e,
0x72, 0x61, 0x6e, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6c, 0x61, 0x75, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x54,
0x6e, 0x63, 0x68, 0x12, 0x5a, 0x0a, 0x05, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x12, 0x17, 0x2e, 0x74, 0x77, 0x69, 0x6e, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x32, 0xed, 0x02, 0x0a, 0x03, 0x61, 0x70,
0x72, 0x61, 0x6e, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x65, 0x69, 0x12, 0x5c, 0x0a, 0x06, 0x6c, 0x61, 0x75, 0x6e, 0x63, 0x68, 0x12, 0x17, 0x2e, 0x74, 0x72,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x2e, 0x53, 0x61, 0x6e, 0x73, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x52, 0x65, 0x71,
0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1f, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x67, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x2e, 0x53, 0x75,
0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x3a, 0x01, 0x2a, 0x22, 0x14, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x63, 0x63, 0x65, 0x73, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x20, 0x82,
0x73, 0x63, 0x6f, 0x64, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x42, 0xd3, 0xe4, 0x93, 0x02, 0x1a, 0x3a, 0x01, 0x2a, 0x22, 0x15, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73,
0x25, 0x5a, 0x23, 0x6d, 0x37, 0x73, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x2f, 0x6d, 0x37, 0x73, 0x2f, 0x63, 0x6f, 0x64, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x6c, 0x61, 0x75, 0x6e, 0x63, 0x68, 0x12,
0x76, 0x35, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x63, 0x57, 0x0a, 0x05, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x12, 0x14, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73,
0x6f, 0x64, 0x65, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 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 ( var (
@@ -388,24 +467,31 @@ func file_transcode_proto_rawDescGZIP() []byte {
return file_transcode_proto_rawDescData 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{ var file_transcode_proto_goTypes = []any{
(*OverlayConfig)(nil), // 0: transcode.OverlayConfig (*OverlayConfig)(nil), // 0: transcode.OverlayConfig
(*TransRequest)(nil), // 1: transcode.TransRequest (*TransRequest)(nil), // 1: transcode.TransRequest
(*CloseRequest)(nil), // 2: transcode.CloseRequest (*TransTwin)(nil), // 2: transcode.TransTwin
(*pb.SuccessResponse)(nil), // 3: global.SuccessResponse (*TransListResponse)(nil), // 3: transcode.TransListResponse
(*emptypb.Empty)(nil), // 4: google.protobuf.Empty
(*pb.SuccessResponse)(nil), // 5: global.SuccessResponse
} }
var file_transcode_proto_depIdxs = []int32{ var file_transcode_proto_depIdxs = []int32{
0, // 0: transcode.TransRequest.overlay_configs:type_name -> transcode.OverlayConfig 0, // 0: transcode.TransRequest.overlay_configs:type_name -> transcode.OverlayConfig
1, // 1: transcode.api.launch:input_type -> transcode.TransRequest 2, // 1: transcode.TransListResponse.data:type_name -> transcode.TransTwin
2, // 2: transcode.api.close:input_type -> transcode.CloseRequest 1, // 2: transcode.api.launch:input_type -> transcode.TransRequest
3, // 3: transcode.api.launch:output_type -> global.SuccessResponse 2, // 3: transcode.api.close:input_type -> transcode.TransTwin
3, // 4: transcode.api.close:output_type -> global.SuccessResponse 4, // 4: transcode.api.list:input_type -> google.protobuf.Empty
3, // [3:5] is the sub-list for method output_type 2, // 5: transcode.api.exist:input_type -> transcode.TransTwin
1, // [1:3] is the sub-list for method input_type 5, // 6: transcode.api.launch:output_type -> global.SuccessResponse
1, // [1:1] is the sub-list for extension type_name 5, // 7: transcode.api.close:output_type -> global.SuccessResponse
1, // [1:1] is the sub-list for extension extendee 3, // 8: transcode.api.list:output_type -> transcode.TransListResponse
0, // [0:1] is the sub-list for field type_name 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() } func init() { file_transcode_proto_init() }
@@ -419,7 +505,7 @@ func file_transcode_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_transcode_proto_rawDesc, RawDescriptor: file_transcode_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 3, NumMessages: 4,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },

View File

@@ -21,6 +21,7 @@ import (
"google.golang.org/grpc/metadata" "google.golang.org/grpc/metadata"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/emptypb"
) )
// Suppress "imported and not used" errors // 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) { 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 var metadata runtime.ServerMetadata
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { 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) { 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 var metadata runtime.ServerMetadata
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { 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". // RegisterApiHandlerServer registers the http handlers for service Api to "mux".
// UnaryRPC :call ApiServer directly. // UnaryRPC :call ApiServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. // 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 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 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_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_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 ( var (
forward_Api_Launch_0 = runtime.ForwardResponseMessage forward_Api_Launch_0 = runtime.ForwardResponseMessage
forward_Api_Close_0 = runtime.ForwardResponseMessage forward_Api_Close_0 = runtime.ForwardResponseMessage
forward_Api_List_0 = runtime.ForwardResponseMessage
forward_Api_Exist_0 = runtime.ForwardResponseMessage
) )

View File

@@ -13,12 +13,24 @@ service api {
body: "*" body: "*"
}; };
} }
rpc close (CloseRequest) returns (global.SuccessResponse) { rpc close (TransTwin) returns (global.SuccessResponse) {
option (google.api.http) = { option (google.api.http) = {
post: "/transcode/api/close" post: "/transcode/api/close"
body: "*" 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 { message OverlayConfig {
@@ -46,7 +58,13 @@ message TransRequest {
repeated OverlayConfig overlay_configs = 8; repeated OverlayConfig overlay_configs = 8;
} }
message CloseRequest { message TransTwin {
string src_stream = 1; // 原始流 string src_stream = 1 [json_name = "src_stream"]; // 原始流
string dst_stream = 2; // 输出流 string dst_stream = 2 [json_name = "dst_stream"]; // 输出流
}
message TransListResponse {
int32 code = 1;
string message = 2;
repeated TransTwin data = 3;
} }

View File

@@ -11,6 +11,7 @@ import (
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes" codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status" status "google.golang.org/grpc/status"
emptypb "google.golang.org/protobuf/types/known/emptypb"
pb "m7s.live/m7s/v5/pb" pb "m7s.live/m7s/v5/pb"
) )
@@ -22,6 +23,8 @@ const _ = grpc.SupportPackageIsVersion9
const ( const (
Api_Launch_FullMethodName = "/transcode.api/launch" Api_Launch_FullMethodName = "/transcode.api/launch"
Api_Close_FullMethodName = "/transcode.api/close" 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. // 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. // 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 { type ApiClient interface {
Launch(ctx context.Context, in *TransRequest, opts ...grpc.CallOption) (*pb.SuccessResponse, error) 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 { type apiClient struct {
@@ -50,7 +55,7 @@ func (c *apiClient) Launch(ctx context.Context, in *TransRequest, opts ...grpc.C
return out, nil 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...) cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(pb.SuccessResponse) out := new(pb.SuccessResponse)
err := c.cc.Invoke(ctx, Api_Close_FullMethodName, in, out, cOpts...) 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 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. // ApiServer is the server API for Api service.
// All implementations must embed UnimplementedApiServer // All implementations must embed UnimplementedApiServer
// for forward compatibility. // for forward compatibility.
type ApiServer interface { type ApiServer interface {
Launch(context.Context, *TransRequest) (*pb.SuccessResponse, error) 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() mustEmbedUnimplementedApiServer()
} }
@@ -79,9 +106,15 @@ type UnimplementedApiServer struct{}
func (UnimplementedApiServer) Launch(context.Context, *TransRequest) (*pb.SuccessResponse, error) { func (UnimplementedApiServer) Launch(context.Context, *TransRequest) (*pb.SuccessResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Launch not implemented") 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") 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) mustEmbedUnimplementedApiServer() {}
func (UnimplementedApiServer) testEmbeddedByValue() {} 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) { 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 { if err := dec(in); err != nil {
return nil, err return nil, err
} }
@@ -134,7 +167,43 @@ func _Api_Close_Handler(srv interface{}, ctx context.Context, dec func(interface
FullMethod: Api_Close_FullMethodName, FullMethod: Api_Close_FullMethodName,
} }
handler := func(ctx context.Context, req interface{}) (interface{}, error) { 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) return interceptor(ctx, in, info, handler)
} }
@@ -154,6 +223,14 @@ var Api_ServiceDesc = grpc.ServiceDesc{
MethodName: "close", MethodName: "close",
Handler: _Api_Close_Handler, Handler: _Api_Close_Handler,
}, },
{
MethodName: "list",
Handler: _Api_List_Handler,
},
{
MethodName: "exist",
Handler: _Api_Exist_Handler,
},
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},
Metadata: "transcode.proto", Metadata: "transcode.proto",