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 individual rate adjustment per substream for Opus #11

Merged
merged 5 commits into from
Aug 16, 2024

Conversation

thirv
Copy link
Contributor

@thirv thirv commented Aug 8, 2024

This is an experimental tool that is useful for sound quality optimization. Open to suggestions about the UI etc. Also, not sure if this would somehow be a hindrance and is better left out.

Usage example in a .textproto config file:

codec_config_metadata {
  codec_config_id: 200
  codec_config {
    codec_id: CODEC_ID_OPUS
    num_samples_per_frame: 960
    audio_roll_distance: -4
    decoder_config_opus {
      version: 1
      pre_skip: 312
      input_sample_rate: 48000
      opus_encoder_metadata {
        target_bitrate_per_channel: 16000
        application: APPLICATION_AUDIO
        use_float_api: false
        use_substream_rate_override: true
        substream_rate_overrides: [64000, 57000, 30000, 9000]
      }
    }
  }
}

@thirv thirv changed the title Add individual rate adjustment per substram for Opus Add individual rate adjustment per substream for Opus Aug 8, 2024
@thirv thirv marked this pull request as ready for review August 8, 2024 22:06
@jwcullen jwcullen self-requested a review August 14, 2024 14:25
@@ -41,6 +41,9 @@ message OpusEncoderMetadata {
optional OpusApplicationFlag application = 2;
optional bool use_float_api = 3 [default = true];
optional float coupling_rate_adjustment = 4 [default = 1.0];
optional bool use_substream_rate_override = 5 [default = false];
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the proto may be better as

map<uint32, int32> substream_id_to_bitrate_override = 5;

In textproto it would look like.

# Substream ID 123 has a bitrate of 1000.
substream_id_to_bitrate_override {
key: 123
value: 1000 
}

This would be more reasonable if large substream IDs are used - which are generally supported elsewhere in the encoder.

I think in this case it makes sense to check presence of the substream in the map, and there does not need to be a use_substream_rate_override. When the substream is not present that implies it is not being overrided - using the "default" calculation would be reasonable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the help, was considering it but was not sure how maps worked here.

0.5f)));
opus_rate =
encoder_metadata_.use_substream_rate_override()
? encoder_metadata_.substream_rate_overrides()[substream_id_]
Copy link
Collaborator

@jwcullen jwcullen Aug 14, 2024

Choose a reason for hiding this comment

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

This introduces an error if encoder_metadata_.substream_rate_overrides()[substream_id_] goes out of bounds.

Before performing the lookup validate that it does not go out of bounds. At review time check against the size of the array. But if you take the "map"-based suggestion in another comment check that the substream_id is present.

I think if it would go out of bounds it is OK to fallback to the calculation based on target_bitrate_per_channels.

Same in the else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the help, was considering it but was not sure how maps worked here.

@@ -41,6 +41,9 @@ message OpusEncoderMetadata {
optional OpusApplicationFlag application = 2;
Copy link
Collaborator

@jwcullen jwcullen Aug 14, 2024

Choose a reason for hiding this comment

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

Do you imagine any use cases where application should vary per substream (or per audio element)?

I'm thinking of a use case where one audio element is music (best encoded as APPLICATION_AUDIO) and a second audio element is voice chat (best encoded as APPLICATION_VOIP).

If you think this would be useful, we may want to consider how we would handle this - even if it does not get implemented in this PR.

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 personally don't see this as a critical addition right now; I'd think separate audio elements would be used in that case. But yeah, the need may materialize suddenly at some point.

@@ -59,7 +59,7 @@ namespace {
absl::Status InitializeEncoder(
const iamf_tools_cli_proto::CodecConfig& codec_config_metadata,
const CodecConfigObu& codec_config, int num_channels,
std::unique_ptr<EncoderBase>& encoder) {
std::unique_ptr<EncoderBase>& encoder, int substream_id = NULL) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
std::unique_ptr<EncoderBase>& encoder, int substream_id = NULL) {
std::unique_ptr<EncoderBase>& encoder, int substream_id = 0) {

@jwcullen jwcullen merged commit 4025a37 into AOMediaCodec:main Aug 16, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants