playlist.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * DudelDu
  3. *
  4. * Copyright 2016 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the MIT
  7. * License, If a copy of the MIT License was not distributed with this
  8. * file, You can obtain one at https://opensource.org/licenses/MIT.
  9. */
  10. /*
  11. Package dudeldu is a simple audio streaming server using the SHOUTcast protocol.
  12. Server
  13. Server is the main server object which runs a shoutcast server instance.
  14. Using a WaitGroup a client can wait for the start and shutdown of the server.
  15. Incoming new connections are served with a ConnectionHandler method. The
  16. default implementation for this is the HandleRequest method of the
  17. DefaultRequestHandler object.
  18. DefaultRequestHandler
  19. DefaultRequestHandler is the default request handler implementation for the
  20. DudelDu server. DefaultRequestHandler has a customizable ServeRequest function.
  21. ServeRequest is called once a request was successfully decoded.
  22. The default implementation supports sending meta data while streaming audio. The
  23. metadata implementation is according to:
  24. http://www.smackfu.com/stuff/programming/shoutcast.html
  25. Playlists
  26. Playlists provide the data which is send to the client. A simple implementation
  27. will just read .mp3 files and send them in chunks (via the Frame() method) to
  28. the client.
  29. A request handler uses a PlaylistFactory to produce a Playlist for each new
  30. connection.
  31. */
  32. package dudeldu
  33. import "errors"
  34. /*
  35. FrameSize is the suggested size of a frame which should be send to the client
  36. at a time.
  37. The absolute theoretical maximum frame size for a MPEG audio is 2881 bytes:
  38. MPEG 2.5 Layer II, 8000 Hz @ 160 kbps, with a padding slot.
  39. Theoretical frame sizes for Layer III range from 24 to 1441 bytes
  40. there is a "soft" limit imposed by the standard of 960 bytes.
  41. see: http://www.mars.org/pipermail/mad-dev/2002-January/000425.html
  42. */
  43. const FrameSize = 3000
  44. /*
  45. ErrPlaylistEnd is a special error code which signals that the end of the playlist has been reached
  46. */
  47. var ErrPlaylistEnd = errors.New("End of playlist")
  48. /*
  49. Playlist is an object which provides a request handler with a
  50. constant stream of bytes and meta information about the current playing title.
  51. */
  52. type Playlist interface {
  53. /*
  54. Name is the name of the playlist.
  55. */
  56. Name() string
  57. /*
  58. ContentType returns the content type of this playlist e.g. audio/mpeg.
  59. */
  60. ContentType() string
  61. /*
  62. Artist returns the artist which is currently playing.
  63. */
  64. Artist() string
  65. /*
  66. Title returns the title which is currently playing.
  67. */
  68. Title() string
  69. /*
  70. Frame returns the current audio frame which is playing.
  71. */
  72. Frame() ([]byte, error)
  73. /*
  74. ReleaseFrame releases a frame which has been written to the client.
  75. */
  76. ReleaseFrame([]byte)
  77. /*
  78. Finished returns if the playlist has finished playing.
  79. */
  80. Finished() bool
  81. /*
  82. Close any open files by this playlist and reset the current pointer. After this
  83. call the playlist can be played again unless an error is returned.
  84. */
  85. Close() error
  86. }
  87. /*
  88. PlaylistFactory produces a Playlist for a given path.
  89. */
  90. type PlaylistFactory interface {
  91. /*
  92. Playlist returns a playlist for a given path.
  93. */
  94. Playlist(path string, shuffle bool) Playlist
  95. }