Skip to content

Commit

Permalink
Ensure native libraries are loaded properly if running on OSGi
Browse files Browse the repository at this point in the history
System.loadLibrary works properly in a real OSGi context in
combination with Bundle-NativeCode manifest headers. The hacky
JNIUtils with reflection and absolute paths is broken on newer
Java versions unless add-opens is added. We don't need that.
  • Loading branch information
ibauersachs committed Jun 11, 2022
1 parent 70dbb5c commit de8f41c
Show file tree
Hide file tree
Showing 19 changed files with 47 additions and 187 deletions.
23 changes: 0 additions & 23 deletions src/main/java/org/jitsi/impl/neomedia/MediaUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,6 @@ public class MediaUtils
AudioFormat.ULAW_RTP,
8000);

/*
* Some codecs depend on JMF native libraries which are only available
* on 32-bit Linux and 32-bit Windows.
*/
if (OSUtils.IS_LINUX32 || OSUtils.IS_WINDOWS32)
{
Map<String, String> g723FormatParams = new HashMap<>();
g723FormatParams.put("annexa", "no");
g723FormatParams.put("bitrate", "6.3");
addMediaFormats(
(byte) SdpConstants.G723,
"G723",
MediaType.AUDIO,
AudioFormat.G723_RTP,
g723FormatParams,
null,
8000);
}

addMediaFormats(
(byte) SdpConstants.GSM,
"GSM",
Expand Down Expand Up @@ -1041,10 +1022,6 @@ else if (jmfEncoding.equals(AudioFormat.GSM))
{
return SdpConstants.GSM;
}
else if (jmfEncoding.equals(AudioFormat.GSM_RTP))
{
return SdpConstants.GSM;
}
else if (jmfEncoding.equals(AudioFormat.G728_RTP))
{
return SdpConstants.G728;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.jitsi.impl.neomedia.codec.audio.opus;

import org.jitsi.utils.*;
import org.jitsi.util.*;

/**
* Defines the API of the native opus library to be utilized by the libjitsi
Expand Down Expand Up @@ -78,7 +78,7 @@ public class Opus
*/
static
{
JNIUtils.loadLibrary("jnopus", Opus.class);
OSUtils.loadLibrary("jnopus", Opus.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.jitsi.impl.neomedia.codec.audio.speex;

import org.jitsi.utils.*;
import org.jitsi.util.*;

/**
* Provides the interface to the native Speex library.
Expand All @@ -42,7 +42,7 @@ public final class Speex

static
{
JNIUtils.loadLibrary("jnspeex", Speex.class);
OSUtils.loadLibrary("jnspeex", Speex.class);
}

public static void assertSpeexIsFunctional()
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jitsi/impl/neomedia/codec/video/VPX.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.jitsi.impl.neomedia.codec.video;

import org.jitsi.utils.*;
import org.jitsi.util.*;

/**
* A wrapper for the libvpx native library.
Expand Down Expand Up @@ -902,7 +902,7 @@ public static String codec_err_to_string(int err)

static
{
JNIUtils.loadLibrary("jnvpx", VPX.class);
OSUtils.loadLibrary("jnvpx", VPX.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ else if (OSUtils.IS_WINDOWS)
}
if (libname != null)
{
JNIUtils.loadLibrary(libname, CoreAudioDevice.class);
OSUtils.loadLibrary(libname, CoreAudioDevice.class);
isLoaded = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,52 +238,6 @@ private static void fixRenderers()
PlugInManager.removePlugIn(
"com.sun.media.renderer.audio.JavaSoundRenderer",
PlugInManager.RENDERER);

if (OSUtils.IS_WINDOWS)
{
if (OSUtils.IS_WINDOWS32)
{
/*
* DDRenderer will cause 32-bit Windows Vista/7 to switch its
* theme from Aero to Vista Basic so try to pick up a different
* Renderer.
*/
if (renderers.contains(
"com.sun.media.renderer.video.GDIRenderer"))
{
PlugInManager.removePlugIn(
"com.sun.media.renderer.video.DDRenderer",
PlugInManager.RENDERER);
}
}
else if (OSUtils.IS_WINDOWS64)
{
/*
* Remove the native Renderers for 64-bit Windows because native
* JMF libs are not available for 64-bit machines.
*/
PlugInManager.removePlugIn(
"com.sun.media.renderer.video.GDIRenderer",
PlugInManager.RENDERER);
PlugInManager.removePlugIn(
"com.sun.media.renderer.video.DDRenderer",
PlugInManager.RENDERER);
}
}
else if (!OSUtils.IS_LINUX32)
{
if (renderers.contains(
"com.sun.media.renderer.video.LightWeightRenderer")
|| renderers.contains(
"com.sun.media.renderer.video.AWTRenderer"))
{
// Remove XLibRenderer because it is native and JMF is supported
// on 32-bit machines only.
PlugInManager.removePlugIn(
"com.sun.media.renderer.video.XLibRenderer",
PlugInManager.RENDERER);
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.jitsi.impl.neomedia.imgstreaming;

import org.jitsi.utils.*;
import org.jitsi.util.*;
import org.jitsi.utils.logging.*;

/**
Expand All @@ -36,7 +36,7 @@ public class ScreenCapture

try
{
JNIUtils.loadLibrary(lib, ScreenCapture.class);
OSUtils.loadLibrary(lib, ScreenCapture.class);
}
catch (Throwable t)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.jitsi.impl.neomedia.jmfext.media.protocol.directshow;

import javax.media.*;
import org.jitsi.utils.*;
import org.jitsi.util.*;

/**
* DirectShow video format.
Expand Down Expand Up @@ -79,7 +79,7 @@ public class DSFormat

static
{
JNIUtils.loadLibrary("jndirectshow", DSFormat.class);
OSUtils.loadLibrary("jndirectshow", DSFormat.class);

ARGB32 = ARGB32();
I420 = I420();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.jitsi.impl.neomedia.jmfext.media.protocol.directshow;

import org.jitsi.utils.*;
import org.jitsi.util.*;

/**
* DirectShow capture device manager.
Expand Down Expand Up @@ -44,7 +44,7 @@ public class DSManager

static
{
JNIUtils.loadLibrary("jndirectshow", DSManager.class);
OSUtils.loadLibrary("jndirectshow", DSManager.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.jitsi.impl.neomedia.jmfext.media.protocol.video4linux2;

import org.jitsi.utils.*;
import org.jitsi.util.*;

/**
* Provides the interface to the native Video for Linux Two API Specification
Expand Down Expand Up @@ -95,7 +95,7 @@ public class Video4Linux2

static
{
JNIUtils.loadLibrary("jnvideo4linux2", Video4Linux2.class);
OSUtils.loadLibrary("jnvideo4linux2", Video4Linux2.class);

VIDIOC_DQBUF = VIDIOC_DQBUF();
VIDIOC_G_FMT = VIDIOC_G_FMT();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.jitsi.impl.neomedia.jmfext.media.protocol.wasapi;

import org.jitsi.utils.*;
import org.jitsi.util.*;
import org.jitsi.utils.logging.*;

/**
Expand Down Expand Up @@ -122,7 +122,7 @@ public class WASAPI

static
{
JNIUtils.loadLibrary("jnwasapi", WASAPI.class);
OSUtils.loadLibrary("jnwasapi", WASAPI.class);

AUDCLNT_E_NOT_STOPPED
= MAKE_HRESULT(SEVERITY_ERROR, FACILIY_AUDCLNT, 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.jitsi.impl.neomedia.codec.video.*;
import org.jitsi.impl.neomedia.jmfext.media.renderer.*;
import org.jitsi.util.OSUtils;
import org.jitsi.utils.*;
import org.jitsi.util.swing.*;
import org.jitsi.utils.logging.*;

Expand Down Expand Up @@ -98,7 +97,7 @@ public class JAWTRenderer

static
{
JNIUtils.loadLibrary("jnawtrenderer", JAWTRenderer.class);
OSUtils.loadLibrary("jnawtrenderer", JAWTRenderer.class);
}

static native void addNotify(long handle, Component component);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jitsi/impl/neomedia/portaudio/Pa.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.jitsi.service.configuration.*;
import org.jitsi.service.libjitsi.*;
import org.jitsi.util.OSUtils;
import org.jitsi.utils.*;
import org.jitsi.utils.logging.*;

/**
Expand Down Expand Up @@ -246,7 +245,7 @@ public String getApiName()

static
{
JNIUtils.loadLibrary("jnportaudio", Pa.class);
OSUtils.loadLibrary("jnportaudio", Pa.class);

try
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jitsi/impl/neomedia/pulseaudio/PA.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.jitsi.impl.neomedia.pulseaudio;

import org.jitsi.utils.*;
import org.jitsi.util.*;

/**
* Declares the functions, structures and constants of the native
Expand Down Expand Up @@ -122,7 +122,7 @@ public interface stream_success_cb_t

static
{
JNIUtils.loadLibrary("jnpulseaudio", PA.class);
OSUtils.loadLibrary("jnpulseaudio", PA.class);
}

public static native void buffer_attr_free(long attr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.jitsi.impl.neomedia.quicktime;

import org.jitsi.utils.*;
import org.jitsi.util.*;

/**
* Represents a CoreVideo <tt>CVImageBufferRef</tt>.
Expand All @@ -26,7 +26,7 @@ public class CVImageBuffer
{
static
{
JNIUtils.loadLibrary("jnquicktime", CVImageBuffer.class);
OSUtils.loadLibrary("jnquicktime", CVImageBuffer.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.jitsi.impl.neomedia.quicktime;

import org.jitsi.utils.*;
import org.jitsi.util.*;

/**
* @author Lyubomir Marinov
Expand All @@ -30,7 +30,7 @@ public final class CVPixelBufferAttributeKey

static
{
JNIUtils.loadLibrary("jnquicktime", CVPixelBufferAttributeKey.class);
OSUtils.loadLibrary("jnquicktime", CVPixelBufferAttributeKey.class);

kCVPixelBufferHeightKey = kCVPixelBufferHeightKey();
kCVPixelBufferPixelFormatTypeKey = kCVPixelBufferPixelFormatTypeKey();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jitsi/impl/neomedia/quicktime/NSObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.jitsi.impl.neomedia.quicktime;

import org.jitsi.utils.*;
import org.jitsi.util.*;

/**
* Represents the root of most Objective-C class hierarchies which which objects
Expand All @@ -28,7 +28,7 @@ public class NSObject
{
static
{
JNIUtils.loadLibrary("jnquicktime", NSObject.class);
OSUtils.loadLibrary("jnquicktime", NSObject.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
package org.jitsi.impl.neomedia.recording;

import java.io.*;
import org.jitsi.utils.*;
import org.jitsi.util.*;

public class WebmWriter
{
static
{
JNIUtils.loadLibrary("jnvpx", WebmWriter.class);
OSUtils.loadLibrary("jnvpx", WebmWriter.class);
}

/**
Expand Down
Loading

0 comments on commit de8f41c

Please sign in to comment.