api.proto 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // 定义项目 API 的 proto 文件 可以同时描述 gRPC 和 HTTP API
  2. // protobuf 文件参考:
  3. // - https://developers.google.com/protocol-buffers/
  4. // - http://info.bilibili.co/display/documentation/gRPC+Proto
  5. // protobuf 生成 HTTP 工具:
  6. // - http://git.bilibili.co/platform/go-common/tree/master/app/tool/protoc-gen-bm
  7. syntax = "proto3";
  8. // package 命名使用 {discovery_id}.{version} 的方式, version 形如 v1, v2, v1beta ..
  9. // NOTE: 不知道的 discovery_id 请询问大佬, 新项目找大佬申请 discovery_id,先到先得抢注
  10. // e.g. account.service.v1
  11. package live.rtc.v1;
  12. //option go_package = "v1";
  13. import "github.com/gogo/protobuf/gogoproto/gogo.proto";
  14. // NOTE: 最后请删除这些无用的注释 (゜-゜)つロ
  15. // 呵呵 我特么偏不删(゜-゜)つロ
  16. option go_package = "v1";
  17. service Rtc {
  18. // `method:"POST"`
  19. rpc JoinChannel(JoinChannelRequest) returns (JoinChannelResponse);
  20. // `method:"POST"`
  21. rpc LeaveChannel(LeaveChannelRequest) returns (LeaveChannelResponse);
  22. // `method:"POST"`
  23. rpc PublishStream(PublishStreamRequest) returns (PublishStreamResponse);
  24. // `method:"POST"`
  25. rpc TerminateStream(TerminateStreamRequest) returns (TerminateStreamResponse);
  26. // `method:"GET"`
  27. rpc Channel(ChannelRequest) returns (ChannelResponse);
  28. // `method:"GET"`
  29. rpc Stream(StreamRequest) returns (StreamResponse);
  30. // `method:"POST"`
  31. rpc SetRtcConfig(SetRtcConfigRequest) returns (SetRtcConfigResponse);
  32. // `method:"GET"`
  33. rpc VerifyToken(VerifyTokenRequest) returns (VerifyTokenResponse);
  34. }
  35. message MediaSource {
  36. enum MediaType{
  37. OTHER = 0;
  38. VIDEO = 1;
  39. AUDIO = 2;
  40. DATA = 3;
  41. SMALL_VIDEO = 4;
  42. }
  43. MediaType type = 1 [(gogoproto.jsontag) = "type"];
  44. string codec = 2 [(gogoproto.jsontag) = "codec"];
  45. string media_specific = 3 [(gogoproto.jsontag) = "media_specific"];
  46. uint32 ssrc = 4 [(gogoproto.jsontag) = "ssrc"];
  47. uint64 user_id = 5 [(gogoproto.jsontag) = "user_id"];
  48. }
  49. message EncoderConfig {
  50. uint32 width = 1 [(gogoproto.jsontag) = "width"];
  51. uint32 height = 2 [(gogoproto.jsontag) = "height"];
  52. uint32 bitrate = 3 [(gogoproto.jsontag) = "bitrate"];
  53. uint32 frame_rate = 4 [(gogoproto.jsontag) = "frame_rate"];
  54. string video_codec = 5 [(gogoproto.jsontag) = "video_codec"];
  55. string video_profile = 6 [(gogoproto.jsontag) = "video_profile"];
  56. reserved 7 to 18;
  57. uint32 channel = 19 [(gogoproto.jsontag) = "channel"];
  58. uint32 sample_rate = 20 [(gogoproto.jsontag) = "sample_rate"];
  59. string audio_codec = 21 [(gogoproto.jsontag) = "audio_codec"];
  60. }
  61. message JoinChannelRequest {
  62. uint64 channel_id = 1 [(gogoproto.jsontag) = "channel_id"];
  63. uint64 user_id = 2 [(gogoproto.jsontag) = "user_id"];
  64. uint32 proto_version = 3 [(gogoproto.jsontag) = "proto_version"];
  65. repeated MediaSource source = 4 [(gogoproto.jsontag) = "source"];
  66. }
  67. message JoinChannelResponse {
  68. uint32 call_id = 1 [(gogoproto.jsontag) = "call_id"];
  69. string token = 2 [(gogoproto.jsontag) = "token"];
  70. repeated MediaSource source = 3 [(gogoproto.jsontag) = "source"];
  71. }
  72. message LeaveChannelRequest {
  73. uint64 channel_id = 1 [(gogoproto.jsontag) = "channel_id"];
  74. uint64 user_id = 2 [(gogoproto.jsontag) = "user_id"];
  75. uint32 call_id = 3 [(gogoproto.jsontag) = "call_id"];
  76. }
  77. message LeaveChannelResponse {
  78. }
  79. message PublishStreamRequest{
  80. uint64 channel_id = 1 [(gogoproto.jsontag) = "channel_id"];
  81. uint64 user_id = 2 [(gogoproto.jsontag) = "user_id"];
  82. uint32 call_id = 3 [(gogoproto.jsontag) = "call_id"];
  83. EncoderConfig encoder_config = 4 [(gogoproto.jsontag) = "encoder_config"];
  84. string mix_config = 5 [(gogoproto.jsontag) = "mix_config"];
  85. }
  86. message PublishStreamResponse{
  87. }
  88. message TerminateStreamRequest{
  89. uint64 channel_id = 1 [(gogoproto.jsontag) = "channel_id"];
  90. uint64 user_id = 2 [(gogoproto.jsontag) = "user_id"];
  91. uint32 call_id = 3 [(gogoproto.jsontag) = "call_id"];
  92. }
  93. message TerminateStreamResponse{
  94. }
  95. message ChannelRequest{
  96. uint64 channel_id = 1 [(gogoproto.jsontag) = "channel_id"];
  97. }
  98. message ChannelResponse{
  99. repeated MediaSource media_source = 1 [(gogoproto.jsontag) = "media_source"];
  100. string server = 2 [(gogoproto.jsontag) = "server"];
  101. uint32 tcp_port = 3 [(gogoproto.jsontag) = "tcp_port"];
  102. uint32 udp_port = 4 [(gogoproto.jsontag) = "udp_port"];
  103. }
  104. message StreamRequest {
  105. uint64 channel_id = 1 [(gogoproto.jsontag) = "channel_id"];
  106. uint64 user_id = 2 [(gogoproto.jsontag) = "user_id"];
  107. uint32 call_id = 3 [(gogoproto.jsontag) = "call_id"];
  108. }
  109. message StreamResponse {
  110. EncoderConfig encoder_config = 1 [(gogoproto.jsontag) = "encoder_config"];
  111. string mix_config = 2 [(gogoproto.jsontag) = "mix_config"];
  112. }
  113. message SetRtcConfigRequest {
  114. uint64 channel_id = 1 [(gogoproto.jsontag) = "channel_id"];
  115. uint64 user_id = 2 [(gogoproto.jsontag) = "user_id"];
  116. uint32 call_id = 3 [(gogoproto.jsontag) = "call_id"];
  117. string config = 4 [(gogoproto.jsontag) = "config"];
  118. }
  119. message SetRtcConfigResponse {
  120. }
  121. message VerifyTokenRequest {
  122. uint64 channel_id = 1 [(gogoproto.jsontag) = "channel_id"];
  123. uint32 call_id = 2 [(gogoproto.jsontag) = "call_id"];
  124. string token = 3 [(gogoproto.jsontag) = "token"];
  125. }
  126. message VerifyTokenResponse {
  127. bool pass = 1 [(gogoproto.jsontag) = "pass"];
  128. }