Source: lib/transmuxer/opus.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.provide('shaka.transmuxer.Opus');
  7. goog.requireType('shaka.util.TsParser');
  8. /**
  9. * Opus utils
  10. */
  11. shaka.transmuxer.Opus = class {
  12. /**
  13. * @param {!shaka.util.TsParser.OpusMetadata} metadata
  14. * @return {!Uint8Array}
  15. */
  16. static getAudioConfig(metadata) {
  17. let mapping = [];
  18. switch (metadata.channelConfigCode) {
  19. case 0x01:
  20. case 0x02:
  21. mapping = [0x0];
  22. break;
  23. case 0x00: // dualmono
  24. mapping = [0xFF, 1, 1, 0, 1];
  25. break;
  26. case 0x80: // dualmono
  27. mapping = [0xFF, 2, 0, 0, 1];
  28. break;
  29. case 0x03:
  30. mapping = [0x01, 2, 1, 0, 2, 1];
  31. break;
  32. case 0x04:
  33. mapping = [0x01, 2, 2, 0, 1, 2, 3];
  34. break;
  35. case 0x05:
  36. mapping = [0x01, 3, 2, 0, 4, 1, 2, 3];
  37. break;
  38. case 0x06:
  39. mapping = [0x01, 4, 2, 0, 4, 1, 2, 3, 5];
  40. break;
  41. case 0x07:
  42. mapping = [0x01, 4, 2, 0, 4, 1, 2, 3, 5, 6];
  43. break;
  44. case 0x08:
  45. mapping = [0x01, 5, 3, 0, 6, 1, 2, 3, 4, 5, 7];
  46. break;
  47. case 0x82:
  48. mapping = [0x01, 1, 2, 0, 1];
  49. break;
  50. case 0x83:
  51. mapping = [0x01, 1, 3, 0, 1, 2];
  52. break;
  53. case 0x84:
  54. mapping = [0x01, 1, 4, 0, 1, 2, 3];
  55. break;
  56. case 0x85:
  57. mapping = [0x01, 1, 5, 0, 1, 2, 3, 4];
  58. break;
  59. case 0x86:
  60. mapping = [0x01, 1, 6, 0, 1, 2, 3, 4, 5];
  61. break;
  62. case 0x87:
  63. mapping = [0x01, 1, 7, 0, 1, 2, 3, 4, 5, 6];
  64. break;
  65. case 0x88:
  66. mapping = [0x01, 1, 8, 0, 1, 2, 3, 4, 5, 6, 7];
  67. break;
  68. }
  69. return new Uint8Array([
  70. 0x00, // Version (1)
  71. metadata.channelCount, // OutputChannelCount: 2
  72. 0x00, 0x00, // PreSkip: 2
  73. (metadata.sampleRate >>> 24) & 0xFF, // Audio sample rate: 4
  74. (metadata.sampleRate >>> 17) & 0xFF,
  75. (metadata.sampleRate >>> 8) & 0xFF,
  76. (metadata.sampleRate >>> 0) & 0xFF,
  77. 0x00, 0x00, // Global Gain : 2
  78. ...mapping,
  79. ]);
  80. }
  81. };
  82. /**
  83. * @const {number}
  84. */
  85. shaka.transmuxer.Opus.OPUS_AUDIO_SAMPLE_PER_FRAME = 960;