main.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // The MIT License (MIT)
  2. //
  3. // # Copyright (c) 2021 Winlin
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. // this software and associated documentation files (the "Software"), to deal in
  7. // the Software without restriction, including without limitation the rights to
  8. // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. // the Software, and to permit persons to whom the Software is furnished to do so,
  10. // subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in all
  13. // copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  17. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  18. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  19. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. package main
  22. import (
  23. "context"
  24. "flag"
  25. "fmt"
  26. "github.com/ossrs/go-oryx-lib/logger"
  27. "github.com/ossrs/srs-bench/gb28181"
  28. "github.com/ossrs/srs-bench/janus"
  29. "github.com/ossrs/srs-bench/srs"
  30. "io/ioutil"
  31. "os"
  32. "os/signal"
  33. "syscall"
  34. )
  35. func main() {
  36. var sfu string
  37. fl := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
  38. fl.SetOutput(ioutil.Discard)
  39. fl.StringVar(&sfu, "sfu", "srs", "The SFU server, srs or gb28181 or janus")
  40. _ = fl.Parse(os.Args[1:])
  41. ctx := context.Background()
  42. var conf interface{}
  43. if sfu == "srs" {
  44. srs.Parse(ctx)
  45. } else if sfu == "gb28181" {
  46. conf = gb28181.Parse(ctx)
  47. } else if sfu == "janus" {
  48. janus.Parse(ctx)
  49. } else {
  50. fmt.Println(fmt.Sprintf("Usage: %v [Options]", os.Args[0]))
  51. fmt.Println(fmt.Sprintf("Options:"))
  52. fmt.Println(fmt.Sprintf(" -sfu The target SFU, srs or gb28181 or janus. Default: srs"))
  53. os.Exit(-1)
  54. }
  55. ctx, cancel := context.WithCancel(ctx)
  56. go func() {
  57. sigs := make(chan os.Signal, 1)
  58. signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT)
  59. for sig := range sigs {
  60. logger.Wf(ctx, "Quit for signal %v", sig)
  61. cancel()
  62. }
  63. }()
  64. var err error
  65. if sfu == "srs" {
  66. err = srs.Run(ctx)
  67. } else if sfu == "gb28181" {
  68. err = gb28181.Run(ctx, conf)
  69. } else if sfu == "janus" {
  70. err = janus.Run(ctx)
  71. }
  72. if err != nil {
  73. logger.Wf(ctx, "srs err %+v", err)
  74. return
  75. }
  76. logger.Tf(ctx, "Done")
  77. }