diff --git a/Live/src/main/cpp/AudioStream.cpp b/Live/src/main/cpp/AudioStream.cpp index f986b4f..edfd904 100644 --- a/Live/src/main/cpp/AudioStream.cpp +++ b/Live/src/main/cpp/AudioStream.cpp @@ -8,7 +8,8 @@ AudioStream::AudioStream() { } AudioStream::~AudioStream() { - DELETE(buffer); + delete buffer; + buffer = nullptr; if (audioCodec) { faacEncClose(audioCodec); audioCodec = nullptr; @@ -39,7 +40,7 @@ void AudioStream::setAudioEncInfo(int samplesInHZ, int channels) { buffer = new u_char[maxOutputBytes]; } -int AudioStream::getInputSamples() { +int AudioStream::getInputSamples() const { return static_cast(inputSamples); } diff --git a/Live/src/main/cpp/AudioStream.h b/Live/src/main/cpp/AudioStream.h index f37d9d2..c246ddb 100644 --- a/Live/src/main/cpp/AudioStream.h +++ b/Live/src/main/cpp/AudioStream.h @@ -18,7 +18,7 @@ public: void setAudioCallback(AudioCallback audioCallback); - int getInputSamples(); + int getInputSamples() const; void encodeData(int8_t *data); diff --git a/Live/src/main/cpp/PacketQueue.h b/Live/src/main/cpp/PacketQueue.h index 1010924..b2c3ac5 100644 --- a/Live/src/main/cpp/PacketQueue.h +++ b/Live/src/main/cpp/PacketQueue.h @@ -12,7 +12,7 @@ class PacketQueue { public: void push(T new_value) { - std::lock_guard lk(m_mutex); + std::lock_guard lock(m_mutex); if (m_running) { m_queue.push(new_value); m_cond.notify_one(); @@ -21,7 +21,7 @@ public: int pop(T &value) { int ret = 0; - std::unique_lock lk(m_mutex); + std::unique_lock lock(m_mutex); if (!m_running) { return ret; } @@ -34,22 +34,22 @@ public: } void setRunning(bool run) { - std::lock_guard lk(m_mutex); + std::lock_guard lock(m_mutex); m_running = run; } int empty() { - std::lock_guard lk(m_mutex); + std::lock_guard lock(m_mutex); return m_queue.empty(); } int size() { - std::lock_guard lk(m_mutex); + std::lock_guard lock(m_mutex); return static_cast(m_queue.size()); } void clear() { - std::lock_guard lk(m_mutex); + std::lock_guard lock(m_mutex); int size = m_queue.size(); for (int i = 0; i < size; ++i) { T value = m_queue.front(); diff --git a/Live/src/main/cpp/PushInterface.h b/Live/src/main/cpp/PushInterface.h index 9058608..f930545 100644 --- a/Live/src/main/cpp/PushInterface.h +++ b/Live/src/main/cpp/PushInterface.h @@ -7,6 +7,4 @@ #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,"FrankLive",__VA_ARGS__) #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,"FrankLive",__VA_ARGS__) -#define DELETE(obj) if(obj){ delete obj; obj = 0; } - #endif diff --git a/Live/src/main/cpp/RtmpPusher.cpp b/Live/src/main/cpp/RtmpPusher.cpp index 1ac9cee..13416e8 100644 --- a/Live/src/main/cpp/RtmpPusher.cpp +++ b/Live/src/main/cpp/RtmpPusher.cpp @@ -12,7 +12,6 @@ PacketQueue packets; VideoStream *videoStream = nullptr; -int isStart = 0; pthread_t pid; std::atomic isPushing; @@ -76,7 +75,7 @@ void releasePackets(RTMPPacket *&packet) { void *start(void *args) { char *url = static_cast(args); - RTMP *rtmp = nullptr; + RTMP *rtmp; do { rtmp = RTMP_Alloc(); if (!rtmp) { @@ -131,7 +130,6 @@ void *start(void *args) { } releasePackets(packet); } while (0); - isStart = 0; isPushing = false; packets.setRunning(false); packets.clear(); @@ -162,10 +160,9 @@ RTMP_PUSHER_FUNC(void, native_1setVideoCodecInfo, RTMP_PUSHER_FUNC(void, native_1start, jstring path_) { LOGI("native start..."); - if (isStart) { + if (isPushing) { return; } - isStart = 1; const char *path = env->GetStringUTFChars(path_, nullptr); char *url = new char[strlen(path) + 1]; strcpy(url, path); @@ -214,6 +211,8 @@ RTMP_PUSHER_FUNC(void, native_1stop) { RTMP_PUSHER_FUNC(void, native_1release) { LOGI("native release..."); env->DeleteGlobalRef(jobject_error); - DELETE(videoStream); - DELETE(audioStream); + delete videoStream; + videoStream = nullptr; + delete audioStream; + audioStream = nullptr; } \ No newline at end of file diff --git a/Live/src/main/cpp/VideoStream.cpp b/Live/src/main/cpp/VideoStream.cpp index a681520..dade40a 100644 --- a/Live/src/main/cpp/VideoStream.cpp +++ b/Live/src/main/cpp/VideoStream.cpp @@ -18,7 +18,8 @@ VideoStream::~VideoStream() { } if (pic_in) { x264_picture_clean(pic_in); - DELETE(pic_in); + delete pic_in; + pic_in = nullptr; } } @@ -31,7 +32,8 @@ void VideoStream::setVideoEncInfo(int width, int height, int fps, int bitrate) { } if (pic_in) { x264_picture_clean(pic_in); - DELETE(pic_in); + delete pic_in; + pic_in = nullptr; } //setting x264 params @@ -79,9 +81,12 @@ void VideoStream::setVideoCallback(VideoCallback callback) { this->videoCallback = callback; } -void VideoStream::encodeVideo(int8_t *data, int8_t camera_type) { +void VideoStream::encodeVideo(int8_t *data, int camera_type) { pthread_mutex_lock(&mutex); + if (!pic_in) + return; + if (camera_type == 1) { memcpy(pic_in->img.plane[0], data, m_frameLen); // y for (int i = 0; i < m_frameLen/4; ++i) { diff --git a/Live/src/main/cpp/VideoStream.h b/Live/src/main/cpp/VideoStream.h index 00f8df3..80aad3d 100644 --- a/Live/src/main/cpp/VideoStream.h +++ b/Live/src/main/cpp/VideoStream.h @@ -17,7 +17,7 @@ public: void setVideoEncInfo(int width, int height, int fps, int bitrate); - void encodeVideo(int8_t *data, int8_t camera_type); + void encodeVideo(int8_t *data, int camera_type); void setVideoCallback(VideoCallback videoCallback);