|
|
@ -7,14 +7,14 @@ |
|
|
|
#include "AudioStream.h" |
|
|
|
#include "AudioStream.h" |
|
|
|
|
|
|
|
|
|
|
|
SafeQueue<RTMPPacket *> packets; |
|
|
|
SafeQueue<RTMPPacket *> packets; |
|
|
|
VideoStream *videoChannel = 0; |
|
|
|
VideoStream *videoStream = 0; |
|
|
|
int isStart = 0; |
|
|
|
int isStart = 0; |
|
|
|
pthread_t pid; |
|
|
|
pthread_t pid; |
|
|
|
|
|
|
|
|
|
|
|
int readyPushing = 0; |
|
|
|
int readyPushing = 0; |
|
|
|
uint32_t start_time; |
|
|
|
uint32_t start_time; |
|
|
|
|
|
|
|
|
|
|
|
AudioStream *audioChannel = 0; |
|
|
|
AudioStream *audioStream = 0; |
|
|
|
|
|
|
|
|
|
|
|
//子线程回调给Java需要用到JavaVM
|
|
|
|
//子线程回调给Java需要用到JavaVM
|
|
|
|
JavaVM *javaVM; |
|
|
|
JavaVM *javaVM; |
|
|
@ -73,10 +73,10 @@ void callback(RTMPPacket *packet) { |
|
|
|
extern "C" |
|
|
|
extern "C" |
|
|
|
JNIEXPORT void JNICALL |
|
|
|
JNIEXPORT void JNICALL |
|
|
|
Java_com_frank_live_LivePusherNew_native_1init(JNIEnv *env, jobject instance) { |
|
|
|
Java_com_frank_live_LivePusherNew_native_1init(JNIEnv *env, jobject instance) { |
|
|
|
videoChannel = new VideoStream; |
|
|
|
videoStream = new VideoStream; |
|
|
|
videoChannel->setVideoCallback(callback); |
|
|
|
videoStream->setVideoCallback(callback); |
|
|
|
audioChannel = new AudioStream; |
|
|
|
audioStream = new AudioStream; |
|
|
|
audioChannel->setAudioCallback(callback); |
|
|
|
audioStream->setAudioCallback(callback); |
|
|
|
packets.setReleaseCallback(releasePackets); |
|
|
|
packets.setReleaseCallback(releasePackets); |
|
|
|
jobject_error = env->NewGlobalRef(instance); |
|
|
|
jobject_error = env->NewGlobalRef(instance); |
|
|
|
} |
|
|
|
} |
|
|
@ -86,8 +86,8 @@ JNIEXPORT void JNICALL |
|
|
|
Java_com_frank_live_LivePusherNew_native_1setVideoCodecInfo(JNIEnv *env, jobject instance, |
|
|
|
Java_com_frank_live_LivePusherNew_native_1setVideoCodecInfo(JNIEnv *env, jobject instance, |
|
|
|
jint width, jint height, jint fps, |
|
|
|
jint width, jint height, jint fps, |
|
|
|
jint bitrate) { |
|
|
|
jint bitrate) { |
|
|
|
if (videoChannel) { |
|
|
|
if (videoStream) { |
|
|
|
videoChannel->setVideoEncInfo(width, height, fps, bitrate); |
|
|
|
videoStream->setVideoEncInfo(width, height, fps, bitrate); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -126,7 +126,7 @@ void *start(void *args) { |
|
|
|
//开始推流
|
|
|
|
//开始推流
|
|
|
|
readyPushing = 1; |
|
|
|
readyPushing = 1; |
|
|
|
packets.setWork(1); |
|
|
|
packets.setWork(1); |
|
|
|
callback(audioChannel->getAudioTag()); |
|
|
|
callback(audioStream->getAudioTag()); |
|
|
|
RTMPPacket *packet = 0; |
|
|
|
RTMPPacket *packet = 0; |
|
|
|
while (readyPushing) { |
|
|
|
while (readyPushing) { |
|
|
|
packets.pop(packet); |
|
|
|
packets.pop(packet); |
|
|
@ -179,11 +179,11 @@ extern "C" |
|
|
|
JNIEXPORT void JNICALL |
|
|
|
JNIEXPORT void JNICALL |
|
|
|
Java_com_frank_live_LivePusherNew_native_1pushVideo(JNIEnv *env, jobject instance, |
|
|
|
Java_com_frank_live_LivePusherNew_native_1pushVideo(JNIEnv *env, jobject instance, |
|
|
|
jbyteArray data_) { |
|
|
|
jbyteArray data_) { |
|
|
|
if (!videoChannel || !readyPushing) { |
|
|
|
if (!videoStream || !readyPushing) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
jbyte *data = env->GetByteArrayElements(data_, NULL); |
|
|
|
jbyte *data = env->GetByteArrayElements(data_, NULL); |
|
|
|
videoChannel->encodeData(data); |
|
|
|
videoStream->encodeData(data); |
|
|
|
env->ReleaseByteArrayElements(data_, data, 0); |
|
|
|
env->ReleaseByteArrayElements(data_, data, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -192,8 +192,8 @@ JNIEXPORT void JNICALL |
|
|
|
Java_com_frank_live_LivePusherNew_native_1setAudioCodecInfo(JNIEnv *env, jobject instance, |
|
|
|
Java_com_frank_live_LivePusherNew_native_1setAudioCodecInfo(JNIEnv *env, jobject instance, |
|
|
|
jint sampleRateInHz, |
|
|
|
jint sampleRateInHz, |
|
|
|
jint channels) { |
|
|
|
jint channels) { |
|
|
|
if (audioChannel) { |
|
|
|
if (audioStream) { |
|
|
|
audioChannel->setAudioEncInfo(sampleRateInHz, channels); |
|
|
|
audioStream->setAudioEncInfo(sampleRateInHz, channels); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -202,8 +202,8 @@ extern "C" |
|
|
|
JNIEXPORT jint JNICALL |
|
|
|
JNIEXPORT jint JNICALL |
|
|
|
Java_com_frank_live_LivePusherNew_getInputSamples(JNIEnv *env, jobject instance) { |
|
|
|
Java_com_frank_live_LivePusherNew_getInputSamples(JNIEnv *env, jobject instance) { |
|
|
|
|
|
|
|
|
|
|
|
if (audioChannel) { |
|
|
|
if (audioStream) { |
|
|
|
return audioChannel->getInputSamples(); |
|
|
|
return audioStream->getInputSamples(); |
|
|
|
} |
|
|
|
} |
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
@ -213,11 +213,11 @@ JNIEXPORT void JNICALL |
|
|
|
Java_com_frank_live_LivePusherNew_native_1pushAudio(JNIEnv *env, jobject instance, |
|
|
|
Java_com_frank_live_LivePusherNew_native_1pushAudio(JNIEnv *env, jobject instance, |
|
|
|
jbyteArray data_) { |
|
|
|
jbyteArray data_) { |
|
|
|
|
|
|
|
|
|
|
|
if (!audioChannel || !readyPushing) { |
|
|
|
if (!audioStream || !readyPushing) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
jbyte *data = env->GetByteArrayElements(data_, NULL); |
|
|
|
jbyte *data = env->GetByteArrayElements(data_, NULL); |
|
|
|
audioChannel->encodeData(data); |
|
|
|
audioStream->encodeData(data); |
|
|
|
env->ReleaseByteArrayElements(data_, data, 0); |
|
|
|
env->ReleaseByteArrayElements(data_, data, 0); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -234,6 +234,6 @@ extern "C" |
|
|
|
JNIEXPORT void JNICALL |
|
|
|
JNIEXPORT void JNICALL |
|
|
|
Java_com_frank_live_LivePusherNew_native_1release(JNIEnv *env, jobject instance) { |
|
|
|
Java_com_frank_live_LivePusherNew_native_1release(JNIEnv *env, jobject instance) { |
|
|
|
env->DeleteGlobalRef(jobject_error); |
|
|
|
env->DeleteGlobalRef(jobject_error); |
|
|
|
DELETE(videoChannel); |
|
|
|
DELETE(videoStream); |
|
|
|
DELETE(audioChannel); |
|
|
|
DELETE(audioStream); |
|
|
|
} |
|
|
|
} |