codecs.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * @file - codecs.js - Handles tasks regarding codec strings such as translating them to
  3. * codec strings, or translating codec strings into objects that can be examined.
  4. */
  5. /**
  6. * Parses a codec string to retrieve the number of codecs specified,
  7. * the video codec and object type indicator, and the audio profile.
  8. */
  9. 'use strict';
  10. Object.defineProperty(exports, '__esModule', {
  11. value: true
  12. });
  13. var parseCodecs = function parseCodecs() {
  14. var codecs = arguments.length <= 0 || arguments[0] === undefined ? '' : arguments[0];
  15. var result = {
  16. codecCount: 0
  17. };
  18. var parsed = undefined;
  19. result.codecCount = codecs.split(',').length;
  20. result.codecCount = result.codecCount || 2;
  21. // parse the video codec
  22. parsed = /(^|\s|,)+(avc1)([^ ,]*)/i.exec(codecs);
  23. if (parsed) {
  24. result.videoCodec = parsed[2];
  25. result.videoObjectTypeIndicator = parsed[3];
  26. }
  27. // parse the last field of the audio codec
  28. result.audioProfile = /(^|\s|,)+mp4a.[0-9A-Fa-f]+\.([0-9A-Fa-f]+)/i.exec(codecs);
  29. result.audioProfile = result.audioProfile && result.audioProfile[2];
  30. return result;
  31. };
  32. exports.parseCodecs = parseCodecs;