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 frameDuration attribute to OpusEncoderConfig #551

Merged

Conversation

bdrtc
Copy link
Contributor

@bdrtc bdrtc commented Sep 5, 2022

This fixes #371


Preview | Diff

@@ -131,6 +131,7 @@
<xmp>
dictionary OpusEncoderConfig {
OpusBitstreamFormat format = "opus";
[EnforceRange] unsigned long frameDuration;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably be "long long" and in microseconds like all other time fields in WebCodecs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we do find duration in audioData is in microseconds,
as described in #371 ,
frameSize = numberOfChannels*sampleRate * frameDuration / 1000
most audio encoder use millseconds as frame duration(opus ptime for example), we can change it to micoseconds, then ,the frameSize Calculation will be:
frameSize = numberOfChannels*sampleRate * frameDuration / 1000/1000

Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dalecurtis Do you see the new commit according to your comments? This is my first PR that need some modifications, I'm afraid of missing an important action.

Copy link
Member

Choose a reason for hiding this comment

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

We can see the new commits. This issue will be discussed at TPAC next week, so we might hold off on merging this PR until those discussions happen.

Copy link
Contributor

Choose a reason for hiding this comment

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

I defer to Thomas for the final decision, I was just driving by.

Copy link
Member

Choose a reason for hiding this comment

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

@aboba, @padenot: any thoughts on microseconds vs milliseconds?

IIUC, the valid frameDurations in milliseconds are {2.5, 5, 10, 20, 40, 60} according to the spec. Leaving it in microseconds might give the impression of finer grain support.

Copy link
Collaborator

@aboba aboba Oct 4, 2022

Choose a reason for hiding this comment

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

As you say, Opus ptimes have a limited set of values, are expressed in ms and are rounded up. So if you're willing to make the lowest frameDuration 3 instead of 2.5, you don't really need microseconds.

@tguilbert-google
Copy link
Member

@aboba, @padenot : does this need editor's approval? If so, please take a look.

@padenot
Copy link
Collaborator

padenot commented Sep 19, 2022

We probably want to have something to do the error checking/validation/rounding to nearest here. Only a very small set of numbers is valid. What happens if you pass something that Opus can't work with?

@bdrtc
Copy link
Contributor Author

bdrtc commented Sep 20, 2022

if we want add error checking, it should be run in audioencoder configure method, by checking the validation of AudioEncodeConfig, Add one more check step like this:
2. if codec is opus and frameDuration exist, frameDuration is not in {2.5, 5, 10, 20, 40, 60}, return false.
what's more, frameDuration type should be changed to double.
@tguilbert-google @padenot any more sugguestion about this ? thanks.

@aboba
Copy link
Collaborator

aboba commented Sep 20, 2022

I think the allowable values are a bit broader. From RFC 7587 Section 6.1:

" ptime: the preferred duration of media represented by a packet
(according to Section 6 of [RFC4566]) that a decoder wants to
receive, in milliseconds rounded up to the next full integer
value. Possible values are 3, 5, 10, 20, 40, 60, or an arbitrary
multiple of an Opus frame size rounded up to the next full integer
value, up to a maximum value of 120, as defined in Section 4. If
no value is specified, the default is 20."

@tguilbert-google
Copy link
Member

tguilbert-google commented Sep 20, 2022

  1. if codec is opus and frameDuration exist, frameDuration is not in {2.5, 5, 10, 20, 40, 60}, return false.

I think we are trying to avoid codec-specific steps in the main spec. We could instead add a generic validation step referring to the registries, along the lines of "If the current codec's registry defines a codec-specific Additional configuration validation steps, run the algorithm defined in the registry. If the return value is ...", and add a section validating OpusEncoderConfig.

There is probably better wording though.

@padenot
Copy link
Collaborator

padenot commented Sep 20, 2022

I agree with @tguilbert-google.

@bdrtc
Copy link
Contributor Author

bdrtc commented Sep 21, 2022

We add a new commit according to the disscussion above, please take a review. @tguilbert-google

Copy link
Member

@tguilbert-google tguilbert-google left a comment

Choose a reason for hiding this comment

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

Latest commit looks good % comments.

FYI, I will be generally unavailable in the next week and a half.

index.src.html Outdated
2. Return `true`.
2. If the current codec's registry defines a codec-specific additional configuration
validation steps, run the algorithm defined in the registry. If the return
value is `false`, return it.
Copy link
Member

Choose a reason for hiding this comment

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

How about:

2. If the {{AudioEncoderConfig}} has a codec-specific extension and the corresponding 
 registration in the [[WEBCODECS-CODEC-REGISTRY]] defines steps to check whether the
 the extension is a valid extension, return the result of running those steps.
3. Return `true`.

To check if an {{OpusEncoderConfig}} is a valid OpusEncoderConfig,
run these steps:
1. If {{OpusEncoderConfig/frameDuration}} is not a valid ptime value,
which is described in section 6.1 of [[RFC6381]], return `false`.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is the right RFC/section. Should this be Section 6.1 of rfc7587?

Defer to @aboba.

I also don't know if there's a way to directly link to a section from the [[RFC...]]

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, It's a wrong reference. It should be rfc7587.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will fix it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, RFC 7587 Section 6.1 makes more sense. We typically link to the RFC and include the Section # but not link to it.

};
</xmp>
</pre>

To check if an {{OpusEncoderConfig}} is a valid OpusEncoderConfig,
Copy link
Member

Choose a reason for hiding this comment

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

NIT: <dfn>valid OpusEncoderConfig</dfn>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cause there is not a more detail dfn about "valid OpusEncoderConfig", maybe a clever desc is:
To check if an {{OpusEncoderConfig}} is valid,
......

@helaozhao
Copy link
Contributor

another commit, please review it.

@tguilbert-google
Copy link
Member

Looks good to me!

I'm leaving editors @aboba and @padenot to do the final approval and merge.

Thanks for the patch!

};
</xmp>
</pre>

To check if an {{OpusEncoderConfig}} is valid, run these steps:
1. If {{OpusEncoderConfig/frameDuration}} is not a valid ptime value,
Copy link
Member

Choose a reason for hiding this comment

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

NIT: should ptime be ptime? (wrapped with backticks?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it should be.

@bdrtc
Copy link
Contributor Author

bdrtc commented Sep 29, 2022

@aboba @padenot any thoughts about new commit?

@tguilbert-google
Copy link
Member

Assuming no objections from @padenot, I am merging this change.

Chromium implementation work will be tracked in crbug.com/1372152

@tguilbert-google
Copy link
Member

Thanks for the PR!

@tguilbert-google tguilbert-google merged commit eab6c4d into w3c:main Oct 6, 2022
github-actions bot added a commit that referenced this pull request Oct 6, 2022
…der-config

SHA: eab6c4d
Reason: push, by @tguilbert-google

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Oct 6, 2022
…der-config

SHA: eab6c4d
Reason: push, by @tguilbert-google

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Oct 6, 2022
…der-config

SHA: eab6c4d
Reason: push, by @tguilbert-google

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Oct 6, 2022
…der-config

SHA: eab6c4d
Reason: push, by @tguilbert-google

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Oct 6, 2022
…der-config

SHA: eab6c4d
Reason: push, by @tguilbert-google

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Oct 6, 2022
…der-config

SHA: eab6c4d
Reason: push, by @tguilbert-google

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Oct 6, 2022
…der-config

SHA: eab6c4d
Reason: push, by @tguilbert-google

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Oct 6, 2022
…der-config

SHA: eab6c4d
Reason: push, by @tguilbert-google

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Oct 6, 2022
…der-config

SHA: eab6c4d
Reason: push, by @tguilbert-google

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Oct 6, 2022
…der-config

SHA: eab6c4d
Reason: push, by @tguilbert-google

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Oct 6, 2022
…der-config

SHA: eab6c4d
Reason: push, by @tguilbert-google

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Oct 6, 2022
…der-config

SHA: eab6c4d
Reason: push, by @tguilbert-google

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Oct 6, 2022
…der-config

SHA: eab6c4d
Reason: push, by @tguilbert-google

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Oct 6, 2022
…der-config

SHA: eab6c4d
Reason: push, by @tguilbert-google

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Oct 6, 2022
…der-config

SHA: eab6c4d
Reason: push, by @tguilbert-google

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@bdrtc bdrtc deleted the 371-add-frameduration-to-opus-encoder-config branch October 8, 2022 02:36
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.

AudioEncoderConfig.latencyMode (or similar)
6 participants