You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
3.7 KiB

  1. # Multiple Alternative Audio Tracks
  2. ## General
  3. m3u8 manifests with multiple audio streams will have those streams added to `video.js` in an `AudioTrackList`. The `AudioTrackList` can be accessed using `player.audioTracks()` or `tech.audioTracks()`.
  4. ## Mapping m3u8 metadata to AudioTracks
  5. The mapping between `AudioTrack` and the parsed m3u8 file is fairly straight forward. The table below shows the mapping
  6. | m3u8 | AudioTrack |
  7. |---------|------------|
  8. | label | label |
  9. | lang | language |
  10. | default | enabled |
  11. | ??? | kind |
  12. | ??? | id |
  13. As you can see m3u8's do not have a property for `AudioTrack.id`, which means that we let `video.js` randomly generate the id for `AudioTrack`s. This will have no real impact on any part of the system as we do not use the `id` anywhere.
  14. The other property that does not have a mapping in the m3u8 is `AudioTrack.kind`. It was decided that we would set the `kind` to `main` when `default` is set to `true` and in all other cases we set it to `alternative`
  15. Below is a basic example of a mapping
  16. m3u8 layout
  17. ``` JavaScript
  18. {
  19. 'media-group-1': [{
  20. 'audio-track-1': {
  21. default: true,
  22. lang: 'eng'
  23. },
  24. 'audio-track-2': {
  25. default: true,
  26. lang: 'fr'
  27. }
  28. }]
  29. }
  30. ```
  31. Corresponding AudioTrackList when media-group-1 is used (before any tracks have been changed)
  32. ``` JavaScript
  33. [{
  34. label: 'audio-tracks-1',
  35. enabled: true,
  36. language: 'eng',
  37. kind: 'main',
  38. id: 'random'
  39. }, {
  40. label: 'audio-tracks-2',
  41. enabled: false,
  42. language: 'fr',
  43. kind: 'alternative',
  44. id: 'random'
  45. }]
  46. ```
  47. ## Startup (how tracks are added and used)
  48. > AudioTrack & AudioTrackList live in video.js
  49. 1. `HLS` creates a `MasterPlaylistController` and watches for the `loadedmetadata` event
  50. 1. `HLS` parses the m3u8 using the `MasterPlaylistController`
  51. 1. `MasterPlaylistController` creates a `PlaylistLoader` for the master m3u8
  52. 1. `MasterPlaylistController` creates `PlaylistLoader`s for every audio playlist
  53. 1. `MasterPlaylistController` creates a `SegmentLoader` for the main m3u8
  54. 1. `MasterPlaylistController` creates a `SegmentLoader` for a potential audio playlist
  55. 1. `HLS` sees the `loadedmetadata` and finds the currently selected MediaGroup and all the metadata
  56. 1. `HLS` removes all `AudioTrack`s from the `AudioTrackList`
  57. 1. `HLS` created `AudioTrack`s for the MediaGroup and adds them to the `AudioTrackList`
  58. 1. `HLS` calls `MasterPlaylistController`s `useAudio` with no arguments (causes it to use the currently enabled audio)
  59. 1. `MasterPlaylistController` turns off the current audio `PlaylistLoader` if it is on
  60. 1. `MasterPlaylistController` maps the `label` to the `PlaylistLoader` containing the audio
  61. 1. `MasterPlaylistController` turns on that `PlaylistLoader` and the Corresponding `SegmentLoader` (master or audio only)
  62. 1. `MediaSource`/`mux.js` determine how to mux
  63. ## How tracks are switched
  64. > AudioTrack & AudioTrackList live in video.js
  65. 1. `HLS` is setup to watch for the `changed` event on the `AudioTrackList`
  66. 1. User selects a new `AudioTrack` from a menu (where only one track can be enabled)
  67. 1. `AudioTrackList` enables the new `Audiotrack` and disables all others
  68. 1. `AudioTrackList` triggers a `changed` event
  69. 1. `HLS` sees the `changed` event and finds the newly enabled `AudioTrack`
  70. 1. `HLS` sends the `label` for the new `AudioTrack` to `MasterPlaylistController`s `useAudio` function
  71. 1. `MasterPlaylistController` turns off the current audio `PlaylistLoader` if it is on
  72. 1. `MasterPlaylistController` maps the `label` to the `PlaylistLoader` containing the audio
  73. 1. `MasterPlaylistController` maps the `label` to the `PlaylistLoader` containing the audio
  74. 1. `MasterPlaylistController` turns on that `PlaylistLoader` and the Corresponding `SegmentLoader` (master or audio only)
  75. 1. `MediaSource`/`mux.js` determine how to mux