clean the code, and fix bug service stopped when back pressed
[rtmpclient.git] / app / src / main / jni / FfmpegHelper.cpp
index 3bd2f10..71d7064 100644 (file)
@@ -157,7 +157,7 @@ int FfmpegHelper::processFrame(uint8_t* data)
 {
     if(!isEncoderReady){
         FLOGE("processFrame - isEncoderReady is false.");
-        return 0;
+        return -1;
     }
     int ret = 0;
     int y_length = pWidth * pHeight;
@@ -236,11 +236,15 @@ int FfmpegHelper::processFrame(uint8_t* data)
 
 int FfmpegHelper::close()
 {
-    if(vStream)
+    if(vStream){
         avcodec_close(vStream->codec);
+        vStream = NULL;
+    }
+
     if (formatCtx){
         avio_close(formatCtx->pb);
         avformat_free_context(formatCtx);
+        formatCtx = NULL;
     }
     FLOGE("<----------- FfmpegHelper::close ");
     isEncoderReady = false;