-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e782970
commit 2b83977
Showing
37 changed files
with
36,509 additions
and
638 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# PythonPlugin | ||
This is a Python plugin project for Ant Media Server. You can use this project to interface with python program to modify Audio/Video data, apply AI | ||
With this plugin you can find: | ||
- Accessing the Ant Media Server ie. AntMediaApplicationAdaptor class | ||
- Registration of the plugin as the PacketListener and/or FrameListener | ||
- Consuming packets and/or frames | ||
- REST interface implementation | ||
|
||
# Prerequests | ||
- Install Ant Media Server | ||
- Install Maven | ||
|
||
# Quick Start | ||
|
||
- Clone the repository and go the Sample Plugin Directory | ||
```sh | ||
git clone https://github.com/ant-media/Plugins.git | ||
cd Plugins/PythonPlugin/ | ||
``` | ||
- Build the Sample Plugin | ||
```sh | ||
sudo ./redeploy.sh | ||
``` | ||
- Publish/unPublish a Live Stream to Ant Media Server with WebRTC/RTMP/RTSP | ||
- Check the logs on the server side | ||
``` | ||
tail -f /usr/local/antmedia/log/ant-media-server.log | ||
``` | ||
You would see the following logs | ||
``` | ||
... | ||
... | ||
... | ||
io.antmedia.plugin.PythonPlugin - *************** Stream Started: streamIdXXXXX *************** | ||
... | ||
... | ||
... | ||
io.antmedia.plugin.PythonPlugin - *************** Stream Finished: streamIdXXXXX *************** | ||
... | ||
... | ||
... | ||
``` | ||
|
||
For more information about the plugins, [visit this post](https://antmedia.io/plugins-will-make-ant-media-server-more-powerful/) | ||
|
||
-classpath jna.jar:. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ubuntu | ||
sudo apt install openjdk-17-jdk-headless | ||
sudo apt install maven | ||
sudo apt install python3-pip | ||
sudo apt-get install libavutil-dev libavfilter-dev libavformat-dev libsdl2-dev libavcodec-dev libx264-dev libxvidcore-dev libvdpau-dev libva-dev libxcb-shm0-dev libwavpack-dev libvpx-dev libvorbis-dev libogg-dev libvidstab-dev libspeex-dev libopus-dev libopencore-amrnb-dev libopencore-amrwb-dev libmp3lame-dev libfreetype6-dev libfdk-aac-dev libass-dev libbz2-dev libsoxr-dev | ||
sudo at install ffmpeg | ||
apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 libjson-glib-dev gstreamer1.0-nice gstreamer1.0-pulseaudio | ||
|
||
sudo apt-get install python3-dev | ||
sudo pip3 install cython numpy opencv-python |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/sh | ||
AMS_DIR=/home/usama/tem/ant-media-server/ | ||
mvn clean install -Dmaven.javadoc.skip=true -Dmaven.test.skip=true -Dgpg.skip=true | ||
OUT=$? | ||
|
||
if [ $OUT -ne 0 ]; then | ||
exit $OUT | ||
fi | ||
|
||
cd ./src/main/python/ | ||
python3 setup.py build_ext --inplace | ||
cd ../../../ | ||
|
||
cp ./src/main/python/libpythonWrapper.so $AMS_DIR/lib/native/ | ||
|
||
rm -r $AMS_DIR/plugins/PythonPlugin.jar | ||
cp ./target/PythonPlugin.jar $AMS_DIR/plugins/ | ||
|
||
OUT=$? | ||
|
||
if [ $OUT -ne 0 ]; then | ||
exit $OUT | ||
fi | ||
cd $AMS_DIR | ||
./start-debug.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.antmedia.app; | ||
|
||
import java.util.List; | ||
import com.sun.jna.Structure.*; | ||
import com.sun.jna.Structure; | ||
|
||
import java.util.Arrays; | ||
|
||
@FieldOrder({ "streamId", "pipeline_type", "pipeline", "protocol", "port_number", "hostname", "language" }) | ||
public class DataMaper extends Structure { | ||
public static class ByReference extends DataMaper implements Structure.ByReference { | ||
} | ||
|
||
public String streamId; | ||
public String pipeline_type; | ||
public String pipeline; | ||
public String protocol; | ||
public String port_number; | ||
public String hostname; | ||
public String language; | ||
|
||
@Override | ||
protected List<String> getFieldOrder() { | ||
return Arrays.asList( | ||
new String[] { "streamId", "pipeline_type", "pipeline", "protocol", "port_number", "hostname", "language" }); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
PythonPlugin/src/main/java/io/antmedia/app/NativeInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package io.antmedia.app; | ||
|
||
import com.sun.jna.Library; | ||
import com.sun.jna.Native; | ||
import com.sun.jna.Callback; | ||
|
||
public class NativeInterface { | ||
|
||
public static interface PY_WRAPPER extends Library { | ||
|
||
PY_WRAPPER INSTANCE = Native.load("./lib/native/libpythonWrapper.so", | ||
PY_WRAPPER.class); | ||
|
||
public boolean Py_IsInitialized(); | ||
|
||
void init_py_and_wrapperlib(); | ||
|
||
void init_python_plugin_state(); | ||
|
||
void PyImport_ImportModule(String moduletoimport); | ||
|
||
void pyimport_wrapperlib(); | ||
|
||
void aquirejil(); | ||
|
||
void releasejil(); | ||
|
||
void streamStarted(String streamid); | ||
|
||
void streamFinished(String streamid); | ||
|
||
void joinedTheRoom(String roomId, String streamId); | ||
|
||
void leftTheRoom(String roomId, String streamId); | ||
|
||
void onVideoFrame(String streamId, long pktPointer); | ||
|
||
void onAudioFrame(String streamId, long pktPointer); | ||
|
||
void onVideoPacket(String streamId, long pktPointer); | ||
|
||
void onAudioPacket(String streamId, long pktPointer); | ||
|
||
void setStreamInfo(String streamId, long codecPar, long rational, int isEnabled, int streamType); // pkt codecType | ||
// 0=video | ||
|
||
interface receiveDataCallback extends Callback { | ||
void C_Callback(String streamId, String roomId, String data); | ||
} | ||
|
||
void registerCallback(receiveDataCallback callback); | ||
|
||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
PythonPlugin/src/main/java/io/antmedia/app/PythonWrapFrameListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.antmedia.app; | ||
|
||
import org.bytedeco.ffmpeg.avutil.AVFrame; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.antmedia.plugin.PythonPlugin; | ||
import io.antmedia.plugin.api.IFrameListener; | ||
import io.antmedia.plugin.api.StreamParametersInfo; | ||
|
||
public class PythonWrapFrameListener implements IFrameListener { | ||
|
||
protected static Logger logger = LoggerFactory.getLogger(PythonWrapFrameListener.class); | ||
|
||
@Override | ||
public AVFrame onAudioFrame(String streamId, AVFrame audioFrame) { | ||
// NativeInterface.JNA_RTSP_SERVER.INSTANCE.aquirejil(); | ||
// NativeInterface.JNA_RTSP_SERVER.INSTANCE.onAudioFrame(streamId, | ||
// audioFrame.address()); | ||
// NativeInterface.JNA_RTSP_SERVER.INSTANCE.releasejil(); | ||
return null; | ||
} | ||
|
||
@Override | ||
public AVFrame onVideoFrame(String streamId, AVFrame videoFrame) { | ||
NativeInterface.PY_WRAPPER.INSTANCE.aquirejil(); | ||
NativeInterface.PY_WRAPPER.INSTANCE.onVideoFrame(streamId, videoFrame.address()); | ||
NativeInterface.PY_WRAPPER.INSTANCE.releasejil(); | ||
return null; | ||
} | ||
|
||
@Override | ||
public void writeTrailer(String streamId) { | ||
} | ||
|
||
@Override | ||
public void setVideoStreamInfo(String streamId, StreamParametersInfo videoStreamInfo) { | ||
} | ||
|
||
@Override | ||
public void setAudioStreamInfo(String streamId, StreamParametersInfo audioStreamInfo) { | ||
} | ||
|
||
@Override | ||
public void start() { | ||
logger.info("PythonFrameListener.start()"); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
PythonPlugin/src/main/java/io/antmedia/app/PythonWrapPacketListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.antmedia.app; | ||
|
||
import org.bytedeco.ffmpeg.avcodec.AVPacket; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.antmedia.plugin.api.IPacketListener; | ||
import io.antmedia.plugin.api.StreamParametersInfo; | ||
|
||
public class PythonWrapPacketListener implements IPacketListener { | ||
|
||
protected static Logger logger = LoggerFactory.getLogger(PythonWrapPacketListener.class); | ||
|
||
@Override | ||
public void writeTrailer(String streamId) { | ||
System.out.println("PythonPacketListener.writeTrailer()"); | ||
} | ||
|
||
@Override | ||
public AVPacket onVideoPacket(String streamId, AVPacket packet) { | ||
NativeInterface.PY_WRAPPER.INSTANCE.aquirejil(); | ||
NativeInterface.PY_WRAPPER.INSTANCE.onVideoPacket(streamId, packet.address()); | ||
NativeInterface.PY_WRAPPER.INSTANCE.releasejil(); | ||
return packet; | ||
} | ||
|
||
@Override | ||
public AVPacket onAudioPacket(String streamId, AVPacket packet) { | ||
NativeInterface.PY_WRAPPER.INSTANCE.aquirejil(); | ||
NativeInterface.PY_WRAPPER.INSTANCE.onAudioPacket(streamId, packet.address()); | ||
NativeInterface.PY_WRAPPER.INSTANCE.releasejil(); | ||
|
||
return packet; | ||
} | ||
|
||
@Override | ||
public void setVideoStreamInfo(String streamId, StreamParametersInfo videoStreamInfo) { | ||
} | ||
|
||
@Override | ||
public void setAudioStreamInfo(String streamId, StreamParametersInfo audioStreamInfo) { | ||
} | ||
|
||
} |
Oops, something went wrong.