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 support in mediacodecaudiorenderer for 24bit pcm to float #3635

Merged
merged 3 commits into from
Jan 24, 2018

Conversation

drhill
Copy link
Contributor

@drhill drhill commented Dec 23, 2017

Kept FloatResampleAudioProcessor it's own class in case it can be leveraged/upgraded in the future. This has to be explicitly enabled for use.

Copy link
Collaborator

@andrewlewis andrewlewis left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

  • Would it make sense for FloatResamplingAudioProcessor to support 32-bit PCM to float conversion (in addition to 24-bit)?
  • I think we should try to move the resampling step into DefaultAudioSink and leave MediaCodecAudioRenderer unmodified, so that other audio renderers could also benefit from this functionality. This would also remove the need to input/output/drain the audio processor in the renderer. I suggest we add a constructor argument enableResamplingToFloat in DefaultAudioSink and apply the FloatResamplingAudioProcessor as a special case. This may be a bit tricky as we will need to disable the int PCM processors under the right circumstances. If that sounds reasonable I can take a look at doing that part of the change.

@drhill
Copy link
Contributor Author

drhill commented Jan 6, 2018

lol... isn't that what I had a few months ago? Both 32-bit pcm to float conversion (I removed as I have no media of that type but it is certainly a good idea) and the floatresample code in the AudioSink (much older code now). I'll try to give it a look this weekend. Thanks!

…n defaultaudiosync to use that resample when audio input is 24/32bit pcm and the new flag is enabled
@drhill
Copy link
Contributor Author

drhill commented Jan 6, 2018

Ok, got it started though tt looks a little sloppy having the hiResProcessors and the regular ones. 24bit pcm audio converts to 32 float fine. DTS, DTS-HD, DD, TrueHD, and 16 bit PCM all seem unchanged. Didn't test 32bit int to 32bit float as I don't have video samples of that.

@andrewlewis
Copy link
Collaborator

Yes, this is doing float to integer conversion in the audio sink as you had a while back. I thought before that it wasn't worth the complexity to convert 24-bit and 32-bit integer input to float, but actually it is needed to make this complete. Sorry for having to split this up and iterate.

I don't think it's so bad having the int -> float processor separate from the other ones. Does it ever make sense to use the processors together? Going via 16-bit makes it not worth doing float output.

Had a quick look and this looks good. I will take a proper look next week and hopefully we can get it submitted soon. Thanks!

@drhill
Copy link
Contributor Author

drhill commented Jan 6, 2018

No problem.

I think the separate processors makes sense. Maybe add a layer of extraction for each processor which encapsulates the current 16 bit processor with any float processor and have the encapsulating class direct the inputs to the proper processor or just do nothing if the input isn't supported?

........./ 16BitResampler
Resampler
.........\ FloatResampler

....................../ 16bitChannelMapperProcessor
ChannelMapperProcessor
......................\ pass through untouched non-16bit data

....................../ 16bitTrimmingAudioProcessor
TrimmingAudioProcessor
......................\ pass through untouched non-16bit data

etcetera
Editing formatting

Copy link
Collaborator

@andrewlewis andrewlewis left a comment

Choose a reason for hiding this comment

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

Looks good. Just some minor things to fix up then we can merge this. Thanks again!

@@ -0,0 +1,182 @@
package com.google.android.exoplayer2.audio;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please could you add an AOSP header? (Just copy from another file and replace the year with 2018.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check

}
@C.Encoding int encoding = inputEncoding;
boolean processingEnabled = isInputPcm && inputEncoding != C.ENCODING_PCM_FLOAT;
if (processingEnabled) {
AudioProcessor[] activeAudioProcessors = shouldUpResPCMAudio ?
Copy link
Collaborator

Choose a reason for hiding this comment

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

The "active" part of the name may be misleading because these audio processors won't necessarily all end up being active (in the terminology of AudioProcessor.isActive()).

How about renaming the final fields to something like toIntPcmAvailableAudioProcessors and toFloatPcmAvailableAudioProcessors? The names are a bit long but hopefully clearer. Or, if not doing that rename, this line could be AudioProcessor[] availableAudioProcessors = shouldUpResPCMAudio ? hiResAvailableAudioProcessors : this.availableAudioProcessors. Same applies for other occurrence of activeAudioProcessors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did the rename and changed the local activeAudioProcessors line to availableAudioProcessors

if (isInputPcm) {
pcmFrameSize = Util.getPcmFrameSize(inputEncoding, channelCount);
pcmFrameSize = Util.getPcmFrameSize(shouldUpResPCMAudio
Copy link
Collaborator

Choose a reason for hiding this comment

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

pcmFrameSize is used to calculate the number of submitted frames (not the number of output frames), so shouldn't this be left as it was?

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, I think that was a mixing of changes that got left in and caused discontinuity errors. Fixed.

buffer.put((byte) (bits & 0xff));
buffer.put((byte) ((bits >> 8) & 0xff));
buffer.put((byte) ((bits >> 16) & 0xff));
buffer.put((byte) ((bits >> 24) & 0xff));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does buffer.putLong(bits) work here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

putInt works

if (isInputPcm) {
pcmFrameSize = Util.getPcmFrameSize(inputEncoding, channelCount);
pcmFrameSize = Util.getPcmFrameSize(shouldUpResPCMAudio
? C.ENCODING_PCM_FLOAT : inputEncoding, channelCount);
}
@C.Encoding int encoding = inputEncoding;
boolean processingEnabled = isInputPcm && inputEncoding != C.ENCODING_PCM_FLOAT;
Copy link
Collaborator

Choose a reason for hiding this comment

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

For the 24-bit integer PCM -> float path we can't apply playback parameters, but processingEnabled gets set to true so setPlaybackParameters will try to apply the playback parameters. For now shall we just add another flag canApplyPlaybackParams which is processingEnabled && !shouldUpResPCMAudio and change the check in setPlaybackParameters to use that?

@andrewlewis
Copy link
Collaborator

I suggest we go with separate available audio processors references for this change as it isn't much code, and have a think about doing #3635 (comment) later on.

@drhill
Copy link
Contributor Author

drhill commented Jan 14, 2018

Changes made. Thanks!

@ojw28 ojw28 merged commit 4d2e0bf into google:dev-v2 Jan 24, 2018
@drhill drhill deleted the dev-v2_24bitpcm branch January 24, 2018 22:31
@google google locked and limited conversation to collaborators Jun 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants