From b294b6e4f9a3dc24bcdce28f0a9c45eda8755f1f Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 23 May 2023 02:13:08 +0200 Subject: GLMediaPlayer: Add setAudioChannelLimit(..), correlating with AudioSink.setChannelLimit() .. May be utilized to enforce 1 channel (mono) downsampling in combination with JOAL/OpenAL to experience spatial 3D position effects. --- src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java | 7 +++++++ .../classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src/jogl/classes/jogamp/opengl/util/av') diff --git a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java index 9e390319a..eb4ef5713 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java +++ b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java @@ -96,6 +96,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { private int textureInternalFormat; private int textureType; private int texUnit; + private int userMaxChannels = -1; // not set private int textureFragmentShaderHashCode; @@ -247,6 +248,12 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { @Override public final int[] getTextureWrapST() { return texWrapST; } + @Override + public final void setAudioChannelLimit(final int cc) { + userMaxChannels = Math.min(8, Math.max(1, cc)); + } + protected int getAudioChannelLimit() { return userMaxChannels; } + @Override public String getRequiredExtensionsShaderStub() { if(GLES2.GL_TEXTURE_EXTERNAL_OES == textureTarget) { diff --git a/src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java b/src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java index d6bbbdc5d..7b86b012d 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java +++ b/src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java @@ -346,6 +346,12 @@ public class FFMPEGMediaPlayer extends GLMediaPlayerImpl { } else { audioSink = AudioSinkFactory.createDefault(FFMPEGMediaPlayer.class.getClassLoader()); } + { + final int audioChannelLimit = getAudioChannelLimit(); + if( audioChannelLimit >= 1 ) { + audioSink.setChannelLimit(audioChannelLimit); + } + } final AudioFormat preferredAudioFormat = audioSink.getPreferredFormat(); if(DEBUG) { System.err.println("initStream: p2 aid "+aid+", preferred "+preferredAudioFormat+" on "+audioSink+", "+this); @@ -385,7 +391,7 @@ public class FFMPEGMediaPlayer extends GLMediaPlayerImpl { } else { resStreamLocS = streamLocS; } - final int aMaxChannelCount = audioSink.getMaxSupportedChannels(); + final int aMaxChannelCount = preferredAudioFormat.channelCount; final int aPrefSampleRate = preferredAudioFormat.sampleRate; // setStream(..) issues updateAttributes*(..), and defines avChosenAudioFormat, vid, aid, .. etc if(DEBUG) { -- cgit v1.2.3