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

Add WAV content filter #982

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open

Conversation

torusrxxx
Copy link
Contributor

WAV PCM audio is such a simple and safe format. RIFF format is supported so why not WAV files?

@Bombe
Copy link
Contributor

Bombe commented Sep 26, 2024

That test needs to be at least a dozen tests, and none of them should be green if you remove all the code from the filter! 😄

Comment on lines 758 to 760
addMIMEType((short)623, "image/avif", "avif");
addMIMEType((short)624, "image/heic", "heic");
addMIMEType((short)625, "image/heif", "heif");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These change appear to be unrelated to this PR.

@@ -123,6 +124,11 @@ false, false, new M3UFilter(), false, false, false, false, false, false,
register(new FilterMIMEType("audio/mpeg", "mp3", new String[] {"audio/mp3", "audio/x-mp3", "audio/x-mpeg", "audio/mpeg3", "audio/x-mpeg3", "audio/mpg", "audio/x-mpg", "audio/mpegaudio"},
new String[0], true, false, new MP3Filter(), true, true, false, true, false, false,
l10n("audioMP3ReadAdvice"), false, null, null, false));

// WAV - has a filter
register(new FilterMIMEType("audio/vnd.wave", "mp3", new String[] {"audio/vnd.wave", "audio/x-wav", "audio/wav", "audio/wave"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mentions "mp3" even though it is about WAV.

return new byte[] {'W', 'A', 'V', 'E'};
}

class WAVFilterContext {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is not used elsewhere, please make it private.

Additionally, the fields in this class should not be declared public as they are not effectively accessible outside this class.
Either make them private, or of you prefer a more compact look, make them package-private (by just omitting public).

Comment on lines 85 to 88
}
}
return output;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off in various places in this class. Please either use 4 spaces or 1 tab for indentation, and don't mix both styles.

Comment on lines 91 to 92
if((size & 1) != 0) // Add padding if necessary
output.writeByte(input.readByte());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use braces around if/then/else blocks, even if they are otherwise one single line.

if(ctx.hasfmt) {
throw new DataFilterException(l10n("invalidTitle"), l10n("invalidTitle"), "Unexpected fmt chunk was encountered");
}
if(size != 16 && size != 18 && size != 40) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do these magic numbers represent? (please introduce constants with descriptive names)

throw new DataFilterException(l10n("invalidTitle"), l10n("invalidTitle"), "Unexpected header chunk was encountered, instead of fmt chunk");
}
if(ID[0] == 'd' && ID[1] == 'a' && ID[2] == 't' && ID[3] == 'a') {
if(ctx.format == WAVE_FORMAT_PCM || ctx.format == WAVE_FORMAT_IEEE_FLOAT || ctx.format == WAVE_FORMAT_ALAW || ctx.format == WAVE_FORMAT_MULAW) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition will always evaluate to true (ctx.format is only written in line 51 and checked immediately after)

@ArneBab
Copy link
Contributor

ArneBab commented Oct 21, 2024

@Bombe @bertm can you check whether your comments are addressed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants