Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix: parse unknown codecs as audio or video (#15)" #18

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions src/codecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,44 +91,23 @@ export const mapLegacyAvcCodecs = function(codecString) {
export const parseCodecs = function(codecString = '') {
const codecs = codecString.split(',');
const result = {};
const unknown = [];

codecs.forEach(function(codec) {
codec = codec.trim();
let codecType;

['video', 'audio'].forEach(function(name) {
const match = regexs[name].exec(codec.toLowerCase());

if (!match || match.length <= 1) {
return;
}
codecType = name;

// maintain codec case
const type = codec.substring(0, match[1].length);
const details = codec.replace(type, '');

result[name] = {type, details};
});

// codec type is not audio or video
// try to deremine its type after all the other codecs
if (!codecType) {
unknown.push(codec);
}
});

// TODO: Report that a codec could not be identified somehow
// Set unknown codecs to either the "missing" audio or video codec.
// If we have all unknown codecs the first one will always be
// video and the second one will always be audio.
unknown.forEach(function(codec) {
if (!result.video) {
result.video = {type: codec, details: ''};
} else if (!result.audio) {
result.audio = {type: codec, details: ''};
}
});

return result;
Expand Down
33 changes: 0 additions & 33 deletions test/codecs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,39 +160,6 @@ QUnit.test('parses video and audio codec with mixed case', function(assert) {
);
});

QUnit.test('parses two unknown codec', function(assert) {
assert.deepEqual(
parseCodecs('fake.codec, other-fake'),
{
video: {type: 'fake.codec', details: ''},
audio: {type: 'other-fake', details: ''}
},
'parsed faked codecs as video/audio'
);
});

QUnit.test('parses on unknown video codec with a known audio', function(assert) {
assert.deepEqual(
parseCodecs('fake.codec, mp4a.40.2'),
{
video: {type: 'fake.codec', details: ''},
audio: {type: 'mp4a', details: '.40.2'}
},
'parsed faked video codec'
);
});

QUnit.test('parses on unknown audio codec with a known video', function(assert) {
assert.deepEqual(
parseCodecs('avc1.42001e, other-fake'),
{
video: {type: 'avc1', details: '.42001e'},
audio: {type: 'other-fake', details: ''}
},
'parsed faked audio codec'
);
});

QUnit.module('codecsFromDefault');

QUnit.test('returns falsey when no audio group ID', function(assert) {
Expand Down