replace NULL with nullptr,using auto instead of concrete type

dev
xufuji456 3 years ago
parent ba919de3b4
commit 1a2e8a55b7
  1. 6
      Live/src/main/cpp/AudioStream.cpp
  2. 30
      Live/src/main/cpp/RtmpPusher.cpp
  3. 10
      Live/src/main/cpp/VideoStream.cpp

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

@ -11,14 +11,14 @@
(JNIEnv *env, jobject instance, ##__VA_ARGS__)\ (JNIEnv *env, jobject instance, ##__VA_ARGS__)\
SafeQueue<RTMPPacket *> packets; SafeQueue<RTMPPacket *> packets;
VideoStream *videoStream = 0; VideoStream *videoStream = nullptr;
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 *audioStream = 0; AudioStream *audioStream = nullptr;
//use to get thread's JNIEnv //use to get thread's JNIEnv
JavaVM *javaVM; JavaVM *javaVM;
@ -52,7 +52,7 @@ jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
//callback error to java //callback error to java
void throwErrToJava(int error_code) { void throwErrToJava(int error_code) {
JNIEnv *env; JNIEnv *env;
javaVM->AttachCurrentThread(&env, NULL); javaVM->AttachCurrentThread(&env, nullptr);
jclass classErr = env->GetObjectClass(jobject_error); jclass classErr = env->GetObjectClass(jobject_error);
jmethodID methodErr = env->GetMethodID(classErr, "errorFromNative", "(I)V"); jmethodID methodErr = env->GetMethodID(classErr, "errorFromNative", "(I)V");
env->CallVoidMethod(jobject_error, methodErr, error_code); env->CallVoidMethod(jobject_error, methodErr, error_code);
@ -76,7 +76,7 @@ void releasePackets(RTMPPacket *&packet) {
void *start(void *args) { void *start(void *args) {
char *url = static_cast<char *>(args); char *url = static_cast<char *>(args);
RTMP *rtmp = 0; RTMP *rtmp = nullptr;
do { do {
rtmp = RTMP_Alloc(); rtmp = RTMP_Alloc();
if (!rtmp) { if (!rtmp) {
@ -92,7 +92,7 @@ void *start(void *args) {
//timeout //timeout
rtmp->Link.timeout = 5; rtmp->Link.timeout = 5;
RTMP_EnableWrite(rtmp); RTMP_EnableWrite(rtmp);
ret = RTMP_Connect(rtmp, 0); ret = RTMP_Connect(rtmp, nullptr);
if (!ret) { if (!ret) {
LOGE("RTMP_Connect:%s", url); LOGE("RTMP_Connect:%s", url);
throwErrToJava(ERROR_RTMP_CONNECT); throwErrToJava(ERROR_RTMP_CONNECT);
@ -110,7 +110,7 @@ void *start(void *args) {
readyPushing = 1; readyPushing = 1;
packets.setWork(1); packets.setWork(1);
callback(audioStream->getAudioTag()); callback(audioStream->getAudioTag());
RTMPPacket *packet = 0; RTMPPacket *packet = nullptr;
while (readyPushing) { while (readyPushing) {
packets.pop(packet); packets.pop(packet);
if (!readyPushing) { if (!readyPushing) {
@ -140,7 +140,7 @@ void *start(void *args) {
RTMP_Free(rtmp); RTMP_Free(rtmp);
} }
delete (url); delete (url);
return 0; return nullptr;
} }
RTMP_PUSHER_FUNC(void, native_1init) { RTMP_PUSHER_FUNC(void, native_1init) {
@ -166,10 +166,10 @@ RTMP_PUSHER_FUNC(void, native_1start, jstring path_) {
return; return;
} }
isStart = 1; isStart = 1;
const char *path = env->GetStringUTFChars(path_, 0); const char *path = env->GetStringUTFChars(path_, nullptr);
char *url = new char[strlen(path) + 1]; char *url = new char[strlen(path) + 1];
strcpy(url, path); strcpy(url, path);
pthread_create(&pid, 0, start, url); pthread_create(&pid, nullptr, start, url);
env->ReleaseStringUTFChars(path_, path); env->ReleaseStringUTFChars(path_, path);
} }
@ -177,7 +177,7 @@ RTMP_PUSHER_FUNC(void, native_1pushVideo, jbyteArray data_) {
if (!videoStream || !readyPushing) { if (!videoStream || !readyPushing) {
return; return;
} }
jbyte *data = env->GetByteArrayElements(data_, NULL); jbyte *data = env->GetByteArrayElements(data_, nullptr);
videoStream->encodeData(data); videoStream->encodeData(data);
env->ReleaseByteArrayElements(data_, data, 0); env->ReleaseByteArrayElements(data_, data, 0);
} }
@ -186,9 +186,9 @@ RTMP_PUSHER_FUNC(void, native_1pushVideoNew, jbyteArray y, jbyteArray u, jbyteAr
if (!videoStream || !readyPushing) { if (!videoStream || !readyPushing) {
return; return;
} }
jbyte *y_plane = env->GetByteArrayElements(y, NULL); jbyte *y_plane = env->GetByteArrayElements(y, nullptr);
jbyte *u_plane = env->GetByteArrayElements(u, NULL); jbyte *u_plane = env->GetByteArrayElements(u, nullptr);
jbyte *v_plane = env->GetByteArrayElements(v, NULL); jbyte *v_plane = env->GetByteArrayElements(v, nullptr);
videoStream->encodeDataNew(y_plane, u_plane, v_plane); videoStream->encodeDataNew(y_plane, u_plane, v_plane);
env->ReleaseByteArrayElements(y, y_plane, 0); env->ReleaseByteArrayElements(y, y_plane, 0);
env->ReleaseByteArrayElements(u, u_plane, 0); env->ReleaseByteArrayElements(u, u_plane, 0);
@ -212,7 +212,7 @@ RTMP_PUSHER_FUNC(void, native_1pushAudio, jbyteArray data_) {
if (!audioStream || !readyPushing) { if (!audioStream || !readyPushing) {
return; return;
} }
jbyte *data = env->GetByteArrayElements(data_, NULL); jbyte *data = env->GetByteArrayElements(data_, nullptr);
audioStream->encodeData(data); audioStream->encodeData(data);
env->ReleaseByteArrayElements(data_, data, 0); env->ReleaseByteArrayElements(data_, data, 0);
} }
@ -221,7 +221,7 @@ RTMP_PUSHER_FUNC(void, native_1stop) {
LOGI("native stop..."); LOGI("native stop...");
readyPushing = 0; readyPushing = 0;
packets.setWork(0); packets.setWork(0);
pthread_join(pid, 0); pthread_join(pid, nullptr);
} }
RTMP_PUSHER_FUNC(void, native_1release) { RTMP_PUSHER_FUNC(void, native_1release) {

@ -5,14 +5,14 @@
#include "PushInterface.h" #include "PushInterface.h"
VideoStream::VideoStream() { VideoStream::VideoStream() {
pthread_mutex_init(&mutex, 0); pthread_mutex_init(&mutex, nullptr);
} }
VideoStream::~VideoStream() { VideoStream::~VideoStream() {
pthread_mutex_destroy(&mutex); pthread_mutex_destroy(&mutex);
if (videoCodec) { if (videoCodec) {
x264_encoder_close(videoCodec); x264_encoder_close(videoCodec);
videoCodec = 0; videoCodec = nullptr;
} }
if (pic_in) { if (pic_in) {
x264_picture_clean(pic_in); x264_picture_clean(pic_in);
@ -30,7 +30,7 @@ void VideoStream::setVideoEncInfo(int width, int height, int fps, int bitrate) {
uvSize = ySize / 4; uvSize = ySize / 4;
if (videoCodec) { if (videoCodec) {
x264_encoder_close(videoCodec); x264_encoder_close(videoCodec);
videoCodec = 0; videoCodec = nullptr;
} }
if (pic_in) { if (pic_in) {
x264_picture_clean(pic_in); x264_picture_clean(pic_in);
@ -147,7 +147,7 @@ void VideoStream::encodeDataNew(int8_t *y_plane, int8_t *u_plane, int8_t *v_plan
void VideoStream::sendSpsPps(uint8_t *sps, uint8_t *pps, int sps_len, int pps_len) { void VideoStream::sendSpsPps(uint8_t *sps, uint8_t *pps, int sps_len, int pps_len) {
int bodySize = 13 + sps_len + 3 + pps_len; int bodySize = 13 + sps_len + 3 + pps_len;
RTMPPacket *packet = new RTMPPacket; auto *packet = new RTMPPacket;
RTMPPacket_Alloc(packet, bodySize); RTMPPacket_Alloc(packet, bodySize);
int i = 0; int i = 0;
//start code //start code
@ -200,7 +200,7 @@ void VideoStream::sendFrame(int type, uint8_t *payload, int i_payload) {
payload += 3; payload += 3;
} }
int bodySize = 9 + i_payload; int bodySize = 9 + i_payload;
RTMPPacket *packet = new RTMPPacket; auto *packet = new RTMPPacket;
RTMPPacket_Alloc(packet, bodySize); RTMPPacket_Alloc(packet, bodySize);
packet->m_body[0] = 0x27; packet->m_body[0] = 0x27;

Loading…
Cancel
Save