Feature: change to c++ thread

pull/221/head
xufuji456 2 years ago
parent f48e4c2332
commit 705f9ba572
  1. 4
      Live/src/main/cpp/AudioStream.cpp
  2. 13
      Live/src/main/cpp/RtmpPusher.cpp
  3. 6
      Live/src/main/cpp/VideoStream.cpp

@ -49,7 +49,7 @@ RTMPPacket *AudioStream::getAudioTag() {
u_long len;
faacEncGetDecoderSpecificInfo(audioCodec, &buf, &len);
int bodySize = static_cast<int>(2 + len);
auto *packet = new RTMPPacket;
auto *packet = new RTMPPacket();
RTMPPacket_Alloc(packet, bodySize);
//channel layout: stereo
packet->m_body[0] = 0xAF;
@ -76,7 +76,7 @@ void AudioStream::encodeData(int8_t *data) {
static_cast<unsigned int>(maxOutputBytes));
if (byteLen > 0) {
int bodySize = 2 + byteLen;
auto *packet = new RTMPPacket;
auto *packet = new RTMPPacket();
RTMPPacket_Alloc(packet, bodySize);
//stereo
packet->m_body[0] = 0xAF;

@ -12,13 +12,11 @@
PacketQueue<RTMPPacket *> packets;
VideoStream *videoStream = nullptr;
pthread_t pid;
AudioStream *audioStream = nullptr;
std::atomic<bool> isPushing;
uint32_t start_time;
AudioStream *audioStream = nullptr;
//use to get thread's JNIEnv
JavaVM *javaVM;
//callback object
@ -143,9 +141,9 @@ void *start(void *args) {
RTMP_PUSHER_FUNC(void, native_1init) {
LOGI("native init...");
videoStream = new VideoStream;
videoStream = new VideoStream();
videoStream->setVideoCallback(callback);
audioStream = new AudioStream;
audioStream = new AudioStream();
audioStream->setAudioCallback(callback);
packets.setReleaseCallback(releasePackets);
jobject_error = env->NewGlobalRef(instance);
@ -166,7 +164,9 @@ RTMP_PUSHER_FUNC(void, native_1start, jstring path_) {
const char *path = env->GetStringUTFChars(path_, nullptr);
char *url = new char[strlen(path) + 1];
strcpy(url, path);
pthread_create(&pid, nullptr, start, url);
std::thread pushThread(start, url);
pushThread.detach();
env->ReleaseStringUTFChars(path_, path);
}
@ -205,7 +205,6 @@ RTMP_PUSHER_FUNC(void, native_1stop) {
LOGI("native stop...");
isPushing = false;
packets.setRunning(false);
pthread_join(pid, nullptr);
}
RTMP_PUSHER_FUNC(void, native_1release) {

@ -72,7 +72,7 @@ void VideoStream::setVideoEncInfo(int width, int height, int fps, int bitrate) {
x264_param_apply_profile(&param, "baseline");
//open encoder
videoCodec = x264_encoder_open(&param);
pic_in = new x264_picture_t;
pic_in = new x264_picture_t();
x264_picture_alloc(pic_in, X264_CSP_I420, width, height);
pthread_mutex_unlock(&mutex);
}
@ -128,7 +128,7 @@ void VideoStream::encodeVideo(int8_t *data, int camera_type) {
void VideoStream::sendSpsPps(uint8_t *sps, uint8_t *pps, int sps_len, int pps_len) {
int bodySize = 13 + sps_len + 3 + pps_len;
auto *packet = new RTMPPacket;
auto *packet = new RTMPPacket();
RTMPPacket_Alloc(packet, bodySize);
int i = 0;
//start code
@ -181,7 +181,7 @@ void VideoStream::sendFrame(int type, uint8_t *payload, int i_payload) {
payload += 3;
}
int bodySize = 9 + i_payload;
auto *packet = new RTMPPacket;
auto *packet = new RTMPPacket();
RTMPPacket_Alloc(packet, bodySize);
packet->m_body[0] = 0x27;

Loading…
Cancel
Save