Feature: check if encoder open success or not

pull/221/head
xufuji456 2 years ago
parent 80fabc2009
commit 9e62e6872a
  1. 8
      Live/src/main/cpp/AudioStream.cpp
  2. 2
      Live/src/main/cpp/AudioStream.h
  3. 18
      Live/src/main/cpp/PushInterface.h
  4. 28
      Live/src/main/cpp/RtmpPusher.cpp
  5. 18
      Live/src/main/cpp/VideoStream.cpp
  6. 2
      Live/src/main/cpp/VideoStream.h

@ -20,13 +20,14 @@ void AudioStream::setAudioCallback(AudioCallback callback) {
this->audioCallback = callback; this->audioCallback = callback;
} }
void AudioStream::setAudioEncInfo(int samplesInHZ, int channels) { int AudioStream::setAudioEncInfo(int samplesInHZ, int channels) {
mChannels = channels; mChannels = channels;
//open faac encoder //open faac encoder
audioCodec = faacEncOpen(static_cast<unsigned long>(samplesInHZ), audioCodec = faacEncOpen(static_cast<unsigned long>(samplesInHZ),
static_cast<unsigned int>(channels), static_cast<unsigned int>(channels),
&inputSamples, &inputSamples,
&maxOutputBytes); &maxOutputBytes);
buffer = new u_char[maxOutputBytes];
//set encoder params //set encoder params
faacEncConfigurationPtr config = faacEncGetCurrentConfiguration(audioCodec); faacEncConfigurationPtr config = faacEncGetCurrentConfiguration(audioCodec);
@ -34,10 +35,7 @@ void AudioStream::setAudioEncInfo(int samplesInHZ, int channels) {
config->aacObjectType = LOW; config->aacObjectType = LOW;
config->inputFormat = FAAC_INPUT_16BIT; config->inputFormat = FAAC_INPUT_16BIT;
config->outputFormat = 0; config->outputFormat = 0;
faacEncSetConfiguration(audioCodec, config); return faacEncSetConfiguration(audioCodec, config);
//output buffer
buffer = new u_char[maxOutputBytes];
} }
int AudioStream::getInputSamples() const { int AudioStream::getInputSamples() const {

@ -14,7 +14,7 @@ public:
~AudioStream(); ~AudioStream();
void setAudioEncInfo(int samplesInHZ, int channels); int setAudioEncInfo(int samplesInHZ, int channels);
void setAudioCallback(AudioCallback audioCallback); void setAudioCallback(AudioCallback audioCallback);

@ -7,4 +7,22 @@
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,"FrankLive",__VA_ARGS__) #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,"FrankLive",__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,"FrankLive",__VA_ARGS__) #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,"FrankLive",__VA_ARGS__)
/***************relative to Java**************/
//error code for opening video encoder
const int ERROR_VIDEO_ENCODER_OPEN = 0x01;
//error code for video encoding
const int ERROR_VIDEO_ENCODE = 0x02;
//error code for opening audio encoder
const int ERROR_AUDIO_ENCODER_OPEN = 0x03;
//error code for audio encoding
const int ERROR_AUDIO_ENCODE = 0x04;
//error code for RTMP connecting
const int ERROR_RTMP_CONNECT = 0x05;
//error code for connecting stream
const int ERROR_RTMP_CONNECT_STREAM = 0x06;
//error code for sending packet
const int ERROR_RTMP_SEND_PACKET = 0x07;
/***************relative to Java**************/
#endif #endif

@ -22,24 +22,6 @@ JavaVM *javaVM;
//callback object //callback object
jobject jobject_error; jobject jobject_error;
/***************relative to Java**************/
//error code for opening video encoder
const int ERROR_VIDEO_ENCODER_OPEN = 0x01;
//error code for video encoding
const int ERROR_VIDEO_ENCODE = 0x02;
//error code for opening audio encoder
const int ERROR_AUDIO_ENCODER_OPEN = 0x03;
//error code for audio encoding
const int ERROR_AUDIO_ENCODE = 0x04;
//error code for RTMP connecting
const int ERROR_RTMP_CONNECT = 0x05;
//error code for connecting stream
const int ERROR_RTMP_CONNECT_STREAM = 0x06;
//error code for sending packet
const int ERROR_RTMP_SEND_PACKET = 0x07;
/***************relative to Java**************/
//when calling System.loadLibrary, will callback it //when calling System.loadLibrary, will callback it
jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
javaVM = vm; javaVM = vm;
@ -152,7 +134,10 @@ RTMP_PUSHER_FUNC(void, native_1init) {
RTMP_PUSHER_FUNC(void, native_1setVideoCodecInfo, RTMP_PUSHER_FUNC(void, native_1setVideoCodecInfo,
jint width, jint height, jint fps, jint bitrate) { jint width, jint height, jint fps, jint bitrate) {
if (videoStream) { if (videoStream) {
videoStream->setVideoEncInfo(width, height, fps, bitrate); int ret = videoStream->setVideoEncInfo(width, height, fps, bitrate);
if (ret < 0) {
throwErrToJava(ERROR_VIDEO_ENCODER_OPEN);
}
} }
} }
@ -181,7 +166,10 @@ RTMP_PUSHER_FUNC(void, native_1pushVideo, jbyteArray yuv, jint camera_type) {
RTMP_PUSHER_FUNC(void, native_1setAudioCodecInfo, jint sampleRateInHz, jint channels) { RTMP_PUSHER_FUNC(void, native_1setAudioCodecInfo, jint sampleRateInHz, jint channels) {
if (audioStream) { if (audioStream) {
audioStream->setAudioEncInfo(sampleRateInHz, channels); int ret = audioStream->setAudioEncInfo(sampleRateInHz, channels);
if (ret < 0) {
throwErrToJava(ERROR_AUDIO_ENCODER_OPEN);
}
} }
} }

@ -23,7 +23,7 @@ VideoStream::~VideoStream() {
} }
} }
void VideoStream::setVideoEncInfo(int width, int height, int fps, int bitrate) { int VideoStream::setVideoEncInfo(int width, int height, int fps, int bitrate) {
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex);
m_frameLen = width * height; m_frameLen = width * height;
if (videoCodec) { if (videoCodec) {
@ -38,7 +38,10 @@ void VideoStream::setVideoEncInfo(int width, int height, int fps, int bitrate) {
//setting x264 params //setting x264 params
x264_param_t param; x264_param_t param;
x264_param_default_preset(&param, "ultrafast", "zerolatency"); int ret = x264_param_default_preset(&param, "ultrafast", "zerolatency");
if (ret < 0) {
goto end;
}
param.i_level_idc = 32; param.i_level_idc = 32;
//input format //input format
param.i_csp = X264_CSP_I420; param.i_csp = X264_CSP_I420;
@ -69,12 +72,21 @@ void VideoStream::setVideoEncInfo(int width, int height, int fps, int bitrate) {
//thread number //thread number
param.i_threads = 1; param.i_threads = 1;
x264_param_apply_profile(&param, "baseline"); ret = x264_param_apply_profile(&param, "baseline");
if (ret < 0) {
goto end;
}
//open encoder //open encoder
videoCodec = x264_encoder_open(&param); videoCodec = x264_encoder_open(&param);
if (!videoCodec) {
ret = -1;
goto end;
}
pic_in = new x264_picture_t(); pic_in = new x264_picture_t();
x264_picture_alloc(pic_in, X264_CSP_I420, width, height); x264_picture_alloc(pic_in, X264_CSP_I420, width, height);
end:
pthread_mutex_unlock(&mutex); pthread_mutex_unlock(&mutex);
return ret;
} }
void VideoStream::setVideoCallback(VideoCallback callback) { void VideoStream::setVideoCallback(VideoCallback callback) {

@ -15,7 +15,7 @@ public:
~VideoStream(); ~VideoStream();
void setVideoEncInfo(int width, int height, int fps, int bitrate); int setVideoEncInfo(int width, int height, int fps, int bitrate);
void encodeVideo(int8_t *data, int camera_type); void encodeVideo(int8_t *data, int camera_type);

Loading…
Cancel
Save