![]() |
![]() Prof Nail Glue French False Tips Acrylic Nail Art 10 pc $2.49 Time Remaining: 18d 3h 6m Buy It Now for only: $2.49 |
![]() FULL Nail Art Acrylic Powder Liquid Brush Glitter Glue Block False Tip Kit Set 2 $0.99 Time Remaining: 9h 26m |
![]() BYB Nail Glue with brush 10g X 2 For False Nails $4.09 Time Remaining: 8h 33m Buy It Now for only: $5.74 |
![]() False French Acrylic Nail Full Tips Flower + Glue ED $2.90 Time Remaining: 27d 19h 10m Buy It Now for only: $2.90 |
![]() 20PCS False Nails Tips French manicure Fake Vivid GREEN Color Acrylic Free Glue $5.29 Time Remaining: 2d 19h 44m |
![]() 5pcs 10g Nail Art with Brush Nail Glue False Tip Decoration Acrylic UV DIY $3.25 Time Remaining: 8d 1h 42m Buy It Now for only: $3.25 |
![]() 20PCS False Nails Tips French manicure Fake Vivid GREEN Color Acrylic Free Glue $5.29 Time Remaining: 3d 17h 43m |
![]() 12pc White Zebra Stripe UV Acrylic Art French False Nail Tips Decoration Glue $0.99 Time Remaining: 10h 39m |
![]() 10 x 2g Blue Nail Glue False Tips Acrylic Nail Art $3.19 Time Remaining: 19d 19h 49m Buy It Now for only: $3.19 |
![]() BYB Nail Glue with brush 10g X 2 For False Nails $4.09 Time Remaining: 2d 9h 27m Buy It Now for only: $5.74 |
![]() PRE GLUE KIDS GIRLS FALSE NAIL TIPS CHILDREN SIZE FAKE NAILS BOW PINK HEART $4.70 Time Remaining: 20d 5h 21m Buy It Now for only: $4.70 |
![]() 20PCS False Nails Tips French manicure Fake Vivid GREEN Color Acrylic Free Glue $5.29 Time Remaining: 4d 19h 42m |
![]() 10 x Nail Glue 2 gram For False Nails $3.77 Time Remaining: 1d 10h 24m Buy It Now for only: $5.30 |
![]() 5pcs 10g Nail Art with Brush Nail Glue False Tip Decoration Acrylic UV DIY $2.89 Time Remaining: 27d 22h 53m Buy It Now for only: $2.89 |
![]() 24 Glitter Butterfly False Nail Art Tips + Glue S223 $0.99 Time Remaining: 1d 9h 15m |
![]() 5x 10g False Nail Art Glitter GLUE ACRYLIC with Brush $3.28 Time Remaining: 15d 7h 7m Buy It Now for only: $3.28 |
![]() KT018 3g PRO Acrylic Nail Glue Art False Tips x 5 $0.99 Time Remaining: 1d 22h 7m |
![]() New 24 pcs Nail Art French False Tips + Glue S218 $0.99 Time Remaining: 1d 10h 5m |
![]() 5x 10g False Nail Art Glitter GLUE ACRYLIC with Brush $3.92 Time Remaining: 1d 8h 17m Buy It Now for only: $3.92 |
![]() 24 x Black lace Logo False Nail Art Tips + Glue S225 $0.99 Time Remaining: 1d 9h 5m |
![]() 3g acrylic nail glue nail art false tips S126 1 $0.99 Time Remaining: 26d 21h 40m Buy It Now for only: $0.99 |
![]() 50 x Nail Glue 2 gram For False Nails $8.96 Time Remaining: 2d 2h 57m Buy It Now for only: $12.56 |
![]() False nails French manicure acrylic prosthesis 20PC Color Natural Free Glue $4.99 Time Remaining: 17h 27m |
![]() 5 Tube PINK GEL NAIL GLUE 2g False Fake tips Nails Art $3.13 Time Remaining: 25d 14h 25m Buy It Now for only: $3.13 |
![]() False nails manicure acrylic prosthesis 20PC Color CLEAR Free Glue $4.99 Time Remaining: 17h 27m |
![]() 100Pcs Acrylic French False Nail Half Tips Natural Cream + Nail Glue + Box 736 $3.59 Time Remaining: 2d 10m Buy It Now for only: $3.59 |
![]() KT073 5 x Pro Nail Glue French False Tips Nail Art $0.99 Time Remaining: 17h 12m |
![]() 10pcs 10g Professional False Nail Tips Glue Adhesive Nail Art with Brush New $2.25 (13 Bids) Time Remaining: 1d 22h 48m |
![]() 100pcs Rainbow Chrome French False Nail Tips with Glue 9 styles to choose $4.99 Time Remaining: 16d 1h 9m Buy It Now for only: $4.99 |
![]() FAKE FALSE NAILS PACK OF 24 UNION JACK DESIGN INCLUDES GLUE $2.58 (3 Bids) Time Remaining: 5d 6h 23m |
![]() 100 Pcs Acrylic Rainbow French Half False Nail Art Tips Box Package 228 W Glue $4.99 Time Remaining: 2d 11h 31m Buy It Now for only: $4.99 |
![]() 5pcs Acrylic Nail Art Glue for false nail tips Rhinestone pearl decoration D04 $0.99 Time Remaining: 23h 16m |
![]() City Chick Floral Art False Nails With Glue New $1.56 Time Remaining: 1d 3h 12m |
![]() 1 10 100 x 3g grams Nail Glue For Acrylic False French Art Decoration Nail Tips $25.88 Time Remaining: 22d 2h 5m Buy It Now for only: $25.88 |
![]() EYE GLUE FOR FAKE FALSE EYELASH EYELASHES DOUBLE EYELID $0.01 (2 Bids) Time Remaining: 20h 42m |
![]() 24 pcs 3D Design False Nails Art Tips Fake Nail with Glue Great for Party A112 $5.00 Time Remaining: 16d 9h 13m Buy It Now for only: $5.00 |
![]() 20PCS False Nails French manicure Fake BLUE Zebra Print Art Tips Free Glue $5.29 Time Remaining: 2d 6h 55m |
![]() 4x Nail Glue fr Acrylic False Fake Gel French Nail Tips $0.99 Time Remaining: 3d 20h 58m |
![]() False Acrylic Nail Glitter Black Full Tips + GLUE EV $2.90 Time Remaining: 20d 20h 8m Buy It Now for only: $2.90 |
![]() False Fake French Acrylic Nail Tips Glue Remover Debonder 54188 $2.99 Time Remaining: 3d 20h 58m |
![]() Pro Glue For False Eyelash Double Eyelid Adhesive 3g $1.36 Time Remaining: 7d 13h 54m Buy It Now for only: $1.36 |
![]() 6x Nail Glue fr Acrylic False Fake Gel French Nail Tips $0.99 Time Remaining: 3d 21h 3m |
![]() False nails manicure acrylic prosthesis 20PC Color CLEAR Free Glue $4.99 Time Remaining: 2d 19h 32m |
![]() LARGE CLEAR BRUSH ON NAIL GLUE 7g False Nails Fake tips $2.34 Time Remaining: 5d 1h 21m Buy It Now for only: $2.34 |
![]() 20PCS False Nails French manicure Fake BLUE Zebra Print Art Tips Free Glue $5.29 Time Remaining: 2d 19h 44m |
![]() 10g Nail Art with Brush Nail Glue False Tip Acrylic UV $0.99 Time Remaining: 21d 22h 8m Buy It Now for only: $0.99 |
![]() 20PCS False Nails French manicure Fake BLUE Zebra Print Art Tips Free Glue $5.29 Time Remaining: 2d 19h 51m |
![]() False nails manicure acrylic prosthesis 20PC Color CLEAR Free Glue $4.99 Time Remaining: 2d 20h 51m |
![]() 6 Pcs False Nail Art Glue Tips Glitter Acrylic Decoration Rhinestones with Brush $3.67 Time Remaining: 22d 8h 6m Buy It Now for only: $3.67 |
![]() 10 x 3g PRO Acrylic Nail Glue French Art False Tips nail art decoration kit $0.01 (1 Bid) Time Remaining: 2d 2h 38m |
![]() New Makeup Glue For False Eyelash Double Eyelid Gel 3g $1.56 Time Remaining: 22h 6m Buy It Now for only: $1.56 |
![]() 20PCS False Nails Tips French manicure Fake Vivid Fushia Color Acrylic Free Glue $5.29 Time Remaining: 3d 7h 14m |
![]() False nails French manicure acrylic prosthesis 20PC Color Natural Free Glue $4.99 Time Remaining: 3d 7h 14m |
![]() 10 x 2g Nail Art False Tips Acrylic Glue $1.99 Time Remaining: 5d 18h 24m Buy It Now for only: $1.99 |
![]() 20PCS False Nails Tips French manicure Fake Vivid Fushia Color Acrylic Free Glue $5.29 Time Remaining: 3d 13h 41m |
![]() 10g False Nail Art Glitter GLUE ACRYLIC with Brush $0.99 Time Remaining: 7d 2h 34m Buy It Now for only: $0.99 |
![]() 20PCS False Nails French manicure Fake Leopard Print Nail Art Tips Free Glue $5.29 Time Remaining: 3d 18h 30m |
![]() 20PCS False Nails Tips French manicure Fake Vivid Fushia Color Acrylic Free Glue $5.29 Time Remaining: 3d 17h 34m |
![]() 5x 10g False Nail Art Glitter GLUE ACRYLIC with Brush $3.29 Time Remaining: 13d 21h 58m Buy It Now for only: $3.29 |
![]() 10 x New 3g PRO Acrylic Nail Glue French Art False Tips $3.59 Time Remaining: 19h 32m Buy It Now for only: $4.59 |
![]() 10 X 3g Acrylic Nail Art Glue French False Tip Manicure $2.85 Time Remaining: 19d 18h 52m Buy It Now for only: $2.85 |
![]() 20PCS False Nails Tips French manicure Fake Vivid GREEN Color Acrylic Free Glue $5.29 Time Remaining: 3d 22h 28m |
![]() 20PCS False Nails Tips French manicure Fake Vivid Fushia Color Acrylic Free Glue $5.29 Time Remaining: 4d 11h 39m |
![]() 10 x 2g Mini ProfessionaL Acrylic Glue Beauty Pink Nail False Art Decorate Tips $1.75 Time Remaining: 2d 19h 43m Buy It Now for only: $1.75 |
![]() 20PCS False Nails Tips French manicure Fake Vivid AQUA Color Acrylic Free Glue $5.29 Time Remaining: 4d 11h 39m |
![]() 10 x 2g Pink Nail Art False Tips Acrylic Glue $1.99 Time Remaining: 20h 54m Buy It Now for only: $1.99 |
![]() 10 x New 3g PRO Acrylic Nail Glue French Art False Tips $2.00 (14 Bids) Time Remaining: 1d 22h 48m |
![]() 20PCS False Nails Tips French manicure Fake Vivid Fushia Color Acrylic Free Glue $5.29 Time Remaining: 4d 16h 57m |
![]() 5 X 3g Acrylic Nail Art Glue French False Tips Manicure $2.94 Time Remaining: 23d 22h 48m Buy It Now for only: $2.94 |
![]() A02 20PCS False Nails French manicure Fake Leopard Print Nail Art Tips Free Glue $5.29 Time Remaining: 4d 20h 27m |
![]() 10pcs 10g Nail Art with Brush Nail Glue False Tip Decoration Acrylic UV DIY $6.25 Time Remaining: 8d 1h 54m Buy It Now for only: $6.25 |
![]() 15 ml Base Coat UV Gel for False Nail Art Glitter Glue Polish Soak Off Color $6.99 Time Remaining: 2d 12h 53m |
![]() False nails manicure acrylic prosthesis 20PC Color CLEAR Free Glue $4.99 Time Remaining: 4d 19h 42m |
![]() 24 Tips Nail Art Fashion Metallic 3D False Full Cover Nails Art Tips + Glue Box $2.99 Time Remaining: 9d 7h 52m Buy It Now for only: $2.99 |
![]() 20PCS False Nails Tips French manicure Fake Vivid Fushia Color Acrylic Free Glue $5.29 Time Remaining: 4d 19h 51m |
![]() 1 10 100 x 3g grams Nail Glue For Acrylic False French Art Decoration Nail Tips $25.88 Time Remaining: 14d 2h 47m Buy It Now for only: $25.88 |
![]() False nails French manicure acrylic prosthesis 20PC Color Natural Free Glue $4.99 Time Remaining: 4d 19h 51m |
![]() Professional Pro Glue For French False Tips Acrylic Nail Art 3g $0.01 Time Remaining: 1d 20h 57m |
![]() 10 x 2g Superior Grade A+++ PINK Nail Glue False Tips Acrylic Nail Art $4.00 Time Remaining: 21d 23h 52m Buy It Now for only: $4.00 |
![]() New Hot 15 ml Base Coat UV Gel False Nail Art Glitter Glue Polish Soak Off Color $6.89 Time Remaining: 3d 20h 45m |
![]() Nail Glue for Acrylic False Fake Gel French Nail Tips $4.99 Time Remaining: 23d 22h 22m Buy It Now for only: $4.99 |
![]() 20PCS False Nails French manicure Fake Leopard Print Nail Art Tips Free Glue $5.29 Time Remaining: 5d 15h 46m |
![]() 20PCS False Nails French manicure Fake Leopard Print Nail Art Tips Free Glue $5.29 Time Remaining: 5d 18h 7m |
![]() 5pcs Acrylic Nail Art Glue for false nail tips Rhinestone pearl decoration D04 $4.40 Time Remaining: 8d 1h 55m Buy It Now for only: $4.40 |
![]() 100pcs New False Nail Tips Adhesive Glue Sticky Tape Easy Fast Nail Art $0.99 Time Remaining: 6d 17h 56m |
![]() 2 X 2g Pink Nail Glue False Tips Acrylic for Nail Art $0.99 Time Remaining: 15d 18h 39m Buy It Now for only: $0.99 |
![]() 20PCS False Nails French manicure Fake BLUE Zebra Print Art Tips Free Glue $5.29 Time Remaining: 6d 4h 1m |
![]() 20PCS False Nails French manicure Fake BLUE Zebra Print Art Tips Free Glue $5.29 Time Remaining: 6d 4h 16m |
![]() NICE 4 X Pink Clear White UV Builder Gel Acrylic Nail Art False Tips Kit Glue $4.27 Time Remaining: 7d 19h 38m Buy It Now for only: $4.27 |
![]() 20PCS False Nails French manicure Fake Leopard Print Nail Art Tips Free Glue $5.29 Time Remaining: 6d 16h 1m |
![]() False Fake Arcylic French Nail Tips Glue Remover Debonder 54188 $4.99 Time Remaining: 28d 23h 13m Buy It Now for only: $4.99 |
![]() 20PCS False Nails French manicure Fake BLUE Zebra Print Art Tips Free Glue $5.29 Time Remaining: 6d 16h 49m |
![]() 12p Pre Design French False Nails Tips Glue Free $2.49 Time Remaining: 6d 2h 5m |
![]() 12pc 3D Pre Designer French False Nail Art Deco Acrylic UV Gel Glue Sticker Tips $2.59 Time Remaining: 5d 1h 44m Buy It Now for only: $2.59 |
![]() 10 x 10g False Nail Art Glitter GLUE ACRYLIC W Brush $7.98 Time Remaining: 5d 8h 33m Buy It Now for only: $8.98 |
![]() 6 Nail Art Glue for Acrylic False Tips Rhinestones 3D $1.00 Time Remaining: 21d 9h 41m Buy It Now for only: $1.00 |
![]() 10 x 10g False Nail Art Glitter GLUE ACRYLIC W Brush $7.98 Time Remaining: 5d 20h 31m Buy It Now for only: $8.98 |
![]() 10 x 10g False Nail Art Glitter GLUE ACRYLIC W Brush $7.98 Time Remaining: 6d 10h 21m Buy It Now for only: $8.98 |
![]() 24 PRE GLUE KIDS GIRLS FALSE NAIL TIPS CHILDREN SIZE FAKE NAILS PURPLE ZEBRA $4.70 Time Remaining: 20d 5h 14m Buy It Now for only: $4.70 |
![]() New 24 Nail Art Rose False Acrylic Tips + Glue F325 $0.99 Time Remaining: 1d 1h 55m |
Glue False
Build a mobile video chat framework with Nex Gen Media Server (NGMS) API by Hung
This tutorial shows how to build the framework to allow real-time video streaming between two mobile clients using NGMS-Embedded API.
IntroductionÂ
Nex Gen Media Server is best known as a multi-purpose media streaming server to deliver live and stored video to a variety of devices. The same media server can be embedded into a mobile application to facilitate real time video communication. Here we will use the NGMS API to facilitate building a video chat client for Android devices using the Android Software Developer Kit (SDK) and Google Android Native Developer Kit (NDK).
We will use NGMS to provide all of the network transport RTP services, video frame compression and decompression. NGMS will run as a natively compiled shared object used by our Android app. We will use a Java Native Interface (JNI) bridging layer to invoke native methods from Java application code.
Pre-requisistes
This article assumes that you have a basic understanding and at least an intermediate level of experience building Android apps. I will not go over the details of setting up and Android project in an iDE such as Eclipse. If you have previously created Android apps, or at least went through some example tutorials you should be able to utilize this tutorial to create a real-time video streaming client.
If you haven't already done so, you will need to download the Google Android SDK (Software Developer Kit). In this example I used Revision 15 on a Linux 32bit machine. The java application layer is used to create the actual Android app. The app code will interface with a JNI layer to invoke the NGMS API routines.
You will also need to download the Google Android NDK (Native Developer Kit). In this example I used Revision 6b on a Linux 32bit machine. The NDK will be used for creating the native interface layer which serves as the glue between the native code and Java application code. You should also have a basic understand of the C programming language.
You should first begin by creating a skeleton Android application using an IDE such as Eclipse. In this example, the application will be called ngmsclient. The Java package name will be called com.example.ngmsclient and will target Android OS 2.3 or higher. The root project directory should contain a folder called "jni" which will contain the native sources used to interface with the Java application code. The example below assumes that you have a skeleton Android app working and will show you how to integrate an ExampleChat class into your Android project.
The Native Layer
The NGMS core embedded library is written in C and is packaged as a shared object file. Since the Android OS is based on Linux, the NGMS core library will run natively within your Android application space. You will need to obtain the NGMS core library for Android OS from the ngmsvid.com website. The essential components are the library files libngms.so, libxcode.so, and the header file ngmslib.h. The ngms bundled .so files will be packaged along with your ngmsclient.apk to provide video chat services.
The JNI Layer
We will build a shared library called ngmsglue.so which will serve as the glue between the ngms API and our Java application code. The structure of the Java Native Interface (JNI) directory within your ngmsclient project directory should look like this.
jni/Android.mk
jni/ngmsglue.c
jni/ngms/include/ngmslib.h
jni/ngms/lib/libngms.so
jni/ngms/lib/libxcode.so
ngmsglue.c will contain the code to control NGMS output and input features. The code will maintain two seperate NGMS API contexts, one for stream output parameters and one for stream input parameters. You should notice that the naming convention of each function should match the Java package and class name from where you are invoking the native code.
ngmsStartReceiver is called to initialize the NGMS capture input API to listen on port 5004 for a network video stream encapsulated over MPEG-2 TS. Each successive video frame will be automatically demuxed and decoded into RGB565 pixel format. The complete frame can then be read by calling ngmsReceiveFrame.
ngmsStartSender is called to initialize the NGMS stream output API to output encoded video frames to a remote host over port 5004. ngmsTransmitFrame is called to encode and transmit a single raw frame in NV21 pixel format.
/*
* ngmsglue.c
*
* JNI layer to access the NGMS streaming and capture API
*
*/
#include <string.h>
#include <stdio.h>
#include <jni.h>
#include <android/log.h>
#include "ngmslib.h"
/**
* Holds the configuration for the NGMS RTP receiver and decoder
*/
static NGMSLIB_STREAM_PARAMS_T ngmsReceiver;
/**
* Holds the configuration for the NGMS RTP sender and encoder
*/
static NGMSLIB_STREAM_PARAMS_T ngmsSender;
/**
* Starts the NGMS capture service
*/
jint Java_com_example_ngmsclient_ExampleChat_ngmsStartReceiver (JNIEnv* _env, jobject _thiz)
{
char xcoderConfig[512];
char sdpConfig[512];
int i;
/*
* Before doing anything call ngmslib_open to open the NGMS service
*/
i = ngmslib_open(&ngmsReceiver);
if (i != NGMS_RC_OK)
{
__android_log_print(ANDROID_LOG_ERROR, "ngms", "ngmslib_open failed with error %d", i);
return -1;
}
/*
* Construct an xcoder configuration key value string
*/
sprintf(xcoderConfig, "vc=rgb565,vx=320,vy=240");
/*
* Construct an SDP configuration for the RTP receiver
* Here we setup NGMS to read data over a MPEG-2 Transport Stream.
*/
sprintf(sdpConfig, "sdp://"
"m=video 5004 RTP/AVP 33n"
"a=rtpmap:33 MP2T/90000n"
"a=fmtp:33n");
/*
* Customize the capture configuration parameters
*/
ngmsReceiver.inputs[0] = sdpConfig;
ngmsReceiver.strxcode = xcoderConfig;
ngmsReceiver.islive = 1;
ngmsReceiver.noaud = 1;
/*
* Start the RTP receiver
*/
i = ngmslib_stream(&ngmsReceiver);
if (i != NGMS_RC_OK)
{
__android_log_print(ANDROID_LOG_ERROR, "ngms", "ngmslib_stream failed with error %d", i);
ngmslib_close(&ngmsReceiver);
return -1;
}
return 0;
}
/**
* Stops the NGMS RTP capture service
*/
jint Java_com_example_ngmsclient_ExampleChat_ngmsStopReceiver (JNIEnv* _env, jobject _thiz)
{
/*
* Stop the RTP receiver
*/
ngmslib_close(&ngmsReceiver);
return 0;
}
/**
* NGMS Callback operation which blocks until a complete video frame has been received and decoded
*/
jint Java_com_example_ngmsclient_ExampleChat_ngmsReceiveFrame (JNIEnv* _env, jobject _thiz, jbyteArray frameBytes)
{
jstring str;
jboolean copy;
jbyte* buffer = (*_env)->GetByteArrayElements(_env, frameBytes, ©);
jsize max = (*_env)->GetArrayLength(_env, frameBytes);
int frameSize;
frameSize = ngmslib_readVidFrame(&ngmsReceiver, buffer, max, NULL);
(*_env)->ReleaseByteArrayElements(_env, frameBytes, buffer, JNI_ABORT);
return frameSize;
}
/**
* Starts the NGMS streaming service
*/
jint Java_com_example_ngmsclient_ExampleChat_ngmsStartSender (JNIEnv* _env, jobject _thiz, jstring remoteAddress)
{
char xcoderConfig[512];
char filter[512];
char destination[512];
const char *p;
int i;
/*
* Before doing anything call ngmslib_open to open the NGMS service
*/
i = ngmslib_open(&ngmsSender);
if (i != NGMS_RC_OK)
{
__android_log_print(ANDROID_LOG_ERROR, "ngms", "ngmslib_open failed with error %d", i);
return -1;
}
/*
* Get the destination host string
*/
p = (*_env)->GetStringUTFChars(_env, remoteAddress, 0);
sprintf(destination, "rtp://%s:5004", p);
(*_env)->ReleaseStringUTFChars(_env, remoteAddress, p);
/*
* Customize the stream configuration parameters
*/
ngmsSender.output = destination;
sprintf(xcoderConfig, "vc=h264,vp=66,vb=250,vx=320,vy=240,vgmax=2000,vgmin=1500,vfr=15,vcfrout=-1,vth=1,vl=1,vsc=1,vf=2");
ngmsSender.strxcode = xcoderConfig;
sprintf(filter, "type=yuv420sp,size=320x240");
ngmsSender.strfilters[0] = filter;
ngmsSender.inputs[0]= "/dev/dummyvideo";
ngmsSender.noaud = 1;
/*
* Start the RTP sender
*/
i = ngmslib_stream(&ngmsSender);
if (i != NGMS_RC_OK)
{
__android_log_print(ANDROID_LOG_ERROR, "ngms", "ngmslib_stream failed with error %d", i);
ngmslib_close(&ngmsSender);
return -1;
}
return 0;
}
/**
* Stops the NGMS streaming service
*/
jint Java_com_example_ngmsclient_ExampleChat_ngmsStopSender (JNIEnv* _env, jobject _thiz)
{
/*
* Stop the RTP sender
*/
ngmslib_close(&ngmsSender);
return 0;
}
/**
* Encodes and transmits a single video frame using local RTP transport
*/
jint Java_com_example_ngmsclient_ExampleChat_ngmsTransmitFrame (JNIEnv* _env, jobject _thiz, jbyteArray frameBytes)
{
jboolean copy;
jbyte* buffer = (*_env)->GetByteArrayElements(_env, frameBytes, ©);
jsize size = (*_env)->GetArrayLength(_env, frameBytes);
int i;
i = ngmslib_onVidFrame(&ngmsSender, buffer, size);
(*_env)->ReleaseByteArrayElements(_env, frameBytes, buffer, JNI_ABORT);
return i;
}
We will create the makefile Android.mk which is used by the Android NDK to build our ngmsglue library.
#Example Android.mk Makefile
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ngmsglue
LOCAL_SRC_FILES := ngmsglue.c
LOCAL_C_INCLUDES := ngms/include
LOCAL_LDFLAGS := -Lngms/lib
LOCAL_LDLIBS := -llog -lm -lngms -lxcode
include $(BUILD_SHARED_LIBRARY)
To build the ngmsglue.so shared library simply do the following.
cd [YOUR NGMSCLIENT PROJECT DIR]/jni
${ANDROID_NDK_HOME}/ndk-build
This should produce the output file [YOUR NGMSCLIENT PROJECT DIR]/libs/armeabi/ibngmsglue.so
You may need to manually copy the libraries ngms/lib/libngms.so and ngms/lib/libxcode.so into the libs/armeabi output directory because the contents of this directory will be automatically packaged into the project .apk application.
The Java Application Layer
The java application layer consists of the application level logic for the Android app we are building. To be able to utilize the native code from the previous section we will need to create a simple application using the Android SDK. This example demonstrates using the ExampleChat class which can be used by your own application to provide real-time interactive video streaming. It does not show all the steps necessary to create a complete Android video streaming application. An intermediate level Android developer should be able to complete the task by building upon and including the ExampleChat class in their full-blown application.
The ExampleChat class shown below is used to control the NGMS stream sender and the NGMS stream receiver. The method startSender can be called to begin streaming video from the native camera using the camera preview mechanism. Each video frame output by the camera is handed down to the NGMS API where it will be encoded and transmitted to the remote party using native RTP encapsulation. The method starReceiver can be called to begin receiving video from a remote instance of the same app. startReceiver launches a thread which performs a blocking poll for the next available received and decoded video frame. Together, these two methods can be used to establish a bi-directional video stream between two remote instances of the same app across a network.
/*
* ExampleChat.java
*
*/
package com.example.ngmsclient;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.PreviewCallback;
import android.graphics.ImageFormat;
public class ExampleChat
{
private boolean myReceiverRunning;
private Camera myCamera;
private PreviewCallback myCameraCallback;
/**
* Change this value to the destination where the video will be streamed
*/
private static final DESTINATION = "10.0.0.1";
/**
* method to initialize and start sending video from the local camera
*/
public void startSender () throws Exception
{
myCamera = Camera.open();
Parameters parameters = myCamera.getParameters();
parameters.setPreviewFormat(ImageFormat.NV21);
parameters.setPreviewFrameRate(15);
parameters.setPreviewSize(320, 240);
myCamera.setParameters(parameters);
/**
* Call the NGMS native method to perform streaming initialization
*/
ngmsStartSender(DESTINATION);
myCameraCallback = new PreviewCallback()
{
public void onPreviewFrame(byte[] frameBytes, Camera camera)
{
/**
* Call the NGMS native routine to encode and transmit the video frame
* to the remote destination using RTP transport.
*/
ngmsTransmitFrame(frameBytes);
}
}
myCamera.startPreview();
myCamera.setPreviewCallback(myCameraCallback);
}
/**
* method to stop sending video
*/
public void stopSender () throws Exception
{
ngmsStopSender();
}
/**
* method to start receiving remote video
*/
public void startReceiver () throws Exception
{
/**
* Call the NGMS native method to perform input initialization
*/
ngmsStartReceiver();
/**
* Start the thread which will poll for received video frames
*/
new Thread(myVideoFrameReceiver).start();
}
/**
* method to stop receiving remote video
*/
public void stopReceiver () throws Exception
{
myReceiverRunning = false;
ngmsStopReceiver();
}
/**
* Thread used to check for decoded video frames
* received by the NGMS native layer
*/
private Runnable myVideoFrameReceiver = new Runnable()
{
public void run()
{
/**
* Allocate a buffer to hold a video frame 320 x 240 pixels
* in RGB565 format, taking 16 bits (2 bytes) per pixel.
*/
byte[] frameBytes = new byte[ 320 * 240 * 2 ];
int size;
myReceiverRunning = true;
while(myReceiverRunning)
{
/**
* Block until a frame has been received and decoded by the native layer
*/
size = ngmsReceiveFrame(frameBytes);
if(size > 0)
{
/**
* The frameBytes array represents a video frame in RGB565 format.
* These bytes can be converted into a Bitmap object for display
* on the screen.
*/
}
}
}
}
/**
* Static initialization to load native libraries into address space
*/
static
{
System.loadLibrary("xcode");
System.loadLibrary("ngms");
System.loadLibrary("ngmsglue");
}
/**
* Define native method prototypes
*/
public native int ngmsStartReceiver ();
public native int ngmsStopReceiver ();
public native int ngmsReceiveFrame (byte[] frameBytes);
public native int ngmsStartSender (String remoteAddress);
public native int ngmsStopSender ();
public native int ngmsTransmitFrame (byte[] frameBytes);
}
Once you have integrated the ExampleChat class into your own Android project ensure that all three of the native libraries exist in the project /libs directory so that they will be included into your .apk output.
libs/armeabi/libngms.so
libs/armeabi/libxcode.so
libs/armeabi/libngmsglue.so
This example produces video output to the destination IP address 10.0.0.1. To successfully enable two clients to stream video bi-directionally you will need to change this IP address to match your remote client.
ConclusionÂ
The above example demonstrates how to stream live video from the camera object in real-time and how to receive a remote live stream and extract each decoded video frame for display. The same process flow can be applied to add audio streaming in-order to create a complete video chat application. â




































































































