Skip to content

Commit

Permalink
feat: add getWrappedMimeType, update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
eshaz committed Nov 14, 2024
1 parent 0879bc8 commit ca512f9
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 22 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@
--mdat [audio data]
```

## Methods
## API

### `MSEAudioWrapper`

_Default export_

`const wrapper = new MSEAudioWrapper("audio/mpeg", {minFramesPerSegment: 2, minBytesPerSegment: 576, preferredContainer: "webm"});`
* `constructor`
Expand Down Expand Up @@ -133,6 +137,20 @@
* OPUS (ISOBMFF) - `audio/mp4;codecs="opus"`
* OPUS (WEBM) - `audio/webm;codecs="opus"`
* Vorbis - `audio/webm;codecs="vorbis"`

### `getWrappedMimeType(codec, container = WEBM)`

_Named export_

Returns the mime-type that MSEAudioWrapper will produce given a passed in codec and container type.

* `codec` *required*
* Codec of the audio data to wrap
* Accepts `aac`, `flac`, `mpeg`, `opus`, `vorbis`
* `container` *optional*
* Accepts `"webm"`, `"fmp4"`
* Defaults to `"webm"`

---


Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mse-audio-wrapper",
"version": "1.4.14",
"version": "1.4.15",
"description": "Library to enable Media Source Extensions API playback for unsupported audio containers and raw codecs",
"main": "src/MSEAudioWrapper.js",
"type": "module",
Expand Down Expand Up @@ -44,9 +44,9 @@
"url": "https://github.com/sponsors/eshaz"
},
"dependencies": {
"codec-parser": "2.4.3"
"codec-parser": "2.5.0"
},
"devDependencies": {
"prettier": "^3.0.1"
"prettier": "^3.3.3"
}
}
27 changes: 19 additions & 8 deletions src/MSEAudioWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ import WEBMContainer from "./containers/webm/WEBMContainer.js";

const noOp = () => {};

export const getWrappedMimeType = (codec, container = WEBM) => {
switch (codec) {
case "mpeg":
return `${AUDIO_MP4}"${MP3}"`;
case "aac":
return `${AUDIO_MP4}"${MP4A_40_2}"`;
case "flac":
return `${AUDIO_MP4}"${FLAC}"`;
case "vorbis":
return `${AUDIO_WEBM}"${VORBIS}"`;
case "opus":
return container === WEBM
? `${AUDIO_WEBM}"${OPUS}"`
: `${AUDIO_MP4}"${OPUS}"`;
}
};

export default class MSEAudioWrapper {
/**
* @description Wraps audio data into media source API compatible containers
Expand Down Expand Up @@ -166,29 +183,23 @@ export default class MSEAudioWrapper {
* @private
*/
_getContainer(codec) {
this._mimeType = getWrappedMimeType(codec, this.PREFERRED_CONTAINER);

switch (codec) {
case "mpeg":
this._mimeType = `${AUDIO_MP4}"${MP3}"`;
return new ISOBMFFContainer(MP3);
case "aac":
this._mimeType = `${AUDIO_MP4}"${MP4A_40_2}"`;
return new ISOBMFFContainer(MP4A_40_2);
case "flac":
this._mimeType = `${AUDIO_MP4}"${FLAC}"`;
return new ISOBMFFContainer(FLAC);
case "vorbis":
this._mimeType = `${AUDIO_WEBM}"${VORBIS}"`;

this.MAX_SAMPLES_PER_SEGMENT = 32767;
return new WEBMContainer(VORBIS);
case "opus":
if (this.PREFERRED_CONTAINER === WEBM) {
this._mimeType = `${AUDIO_WEBM}"${OPUS}"`;

this.MAX_SAMPLES_PER_SEGMENT = 32767;
return new WEBMContainer(OPUS);
}
this._mimeType = `${AUDIO_MP4}"${OPUS}"`;
return new ISOBMFFContainer(OPUS);
}
}
Expand Down

0 comments on commit ca512f9

Please sign in to comment.