core.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package core
  2. import (
  3. "os"
  4. "path"
  5. "path/filepath"
  6. log "github.com/sirupsen/logrus"
  7. "github.com/owncast/owncast/core/chat"
  8. "github.com/owncast/owncast/models"
  9. "github.com/owncast/owncast/services/config"
  10. "github.com/owncast/owncast/services/notifications"
  11. "github.com/owncast/owncast/services/status"
  12. "github.com/owncast/owncast/services/webhooks"
  13. "github.com/owncast/owncast/services/yp"
  14. "github.com/owncast/owncast/storage/configrepository"
  15. "github.com/owncast/owncast/storage/data"
  16. "github.com/owncast/owncast/utils"
  17. "github.com/owncast/owncast/video/rtmp"
  18. "github.com/owncast/owncast/video/transcoder"
  19. )
  20. var (
  21. _stats *models.Stats
  22. _storage models.StorageProvider
  23. _transcoder *transcoder.Transcoder
  24. _yp *yp.YP
  25. _broadcaster *models.Broadcaster
  26. handler transcoder.HLSHandler
  27. fileWriter = transcoder.FileWriterReceiverService{}
  28. )
  29. // Start starts up the core processing.
  30. func Start() error {
  31. resetDirectories()
  32. configRepository := configrepository.Get()
  33. configRepository.PopulateDefaults()
  34. if err := configRepository.VerifySettings(); err != nil {
  35. log.Error(err)
  36. return err
  37. }
  38. if err := setupStats(); err != nil {
  39. log.Error("failed to setup the stats")
  40. return err
  41. }
  42. // The HLS handler takes the written HLS playlists and segments
  43. // and makes storage decisions. It's rather simple right now
  44. // but will play more useful when recordings come into play.
  45. handler = transcoder.HLSHandler{}
  46. if err := setupStorage(); err != nil {
  47. log.Errorln("storage error", err)
  48. }
  49. // user.SetupUsers()
  50. // auth.Setup(data.GetDatastore())
  51. fileWriter.SetupFileWriterReceiverService(&handler)
  52. if err := createInitialOfflineState(); err != nil {
  53. log.Error("failed to create the initial offline state")
  54. return err
  55. }
  56. s := status.Get()
  57. gsf := func() *models.Status {
  58. s := status.Get()
  59. return &s.Status
  60. }
  61. _yp = yp.NewYP(gsf)
  62. if err := chat.Start(gsf); err != nil {
  63. log.Errorln(err)
  64. }
  65. // start the rtmp server
  66. go rtmp.Start(setStreamAsConnected, s.SetBroadcaster)
  67. rtmpPort := configRepository.GetRTMPPortNumber()
  68. if rtmpPort != 1935 {
  69. log.Infof("RTMP is accepting inbound streams on port %d.", rtmpPort)
  70. }
  71. webhooks.InitTemporarySingleton(gsf)
  72. notifications.Setup(data.GetDatastore())
  73. return nil
  74. }