OSDN Git Service

Panasonicのライブビュー、縦横の変化をさせても継続するように見直す。
authorMRSa <mrsa@myad.jp>
Mon, 22 Jul 2019 15:15:32 +0000 (00:15 +0900)
committerMRSa <mrsa@myad.jp>
Mon, 22 Jul 2019 15:15:32 +0000 (00:15 +0900)
app/src/main/java/net/osdn/gokigen/a01d/camera/panasonic/wrapper/PanasonicCameraWrapper.java
app/src/main/java/net/osdn/gokigen/a01d/camera/panasonic/wrapper/PanasonicLiveViewControl.java
app/src/main/java/net/osdn/gokigen/a01d/liveview/LiveViewFragment.java

index 16cfa72..bf73062 100644 (file)
@@ -43,6 +43,7 @@ public class PanasonicCameraWrapper implements IPanasonicCameraHolder, IPanasoni
     private PanasonicCameraFocusControl focusControl = null;
     private PanasonicCameraCaptureControl captureControl = null;
     private PanasonicCameraZoomLensControl zoomControl = null;
+    private PanasonicCameraConnection cameraConnection = null;
 
     public PanasonicCameraWrapper(final Activity context, final ICameraStatusReceiver statusReceiver , final @NonNull ICameraChangeListener listener)
     {
@@ -58,9 +59,14 @@ public class PanasonicCameraWrapper implements IPanasonicCameraHolder, IPanasoni
         try
         {
             //this.panasonicCameraApi = PanasonicCameraApi.newInstance(panasonicCamera);
-            eventObserver = CameraEventObserver.newInstance(context, panasonicCamera);
-            liveViewControl = new PanasonicLiveViewControl(panasonicCamera);
-
+            if (eventObserver == null)
+            {
+                eventObserver = CameraEventObserver.newInstance(context, panasonicCamera);
+            }
+            if (liveViewControl == null)
+            {
+                liveViewControl = new PanasonicLiveViewControl(panasonicCamera);
+            }
             focusControl.setCamera(panasonicCamera);
             captureControl.setCamera(panasonicCamera);
             zoomControl.setCamera(panasonicCamera);
@@ -110,10 +116,14 @@ public class PanasonicCameraWrapper implements IPanasonicCameraHolder, IPanasoni
                 eventObserver.activate();
                 eventObserver.start();
                 ICameraStatusHolder holder = eventObserver.getCameraStatusHolder();
-                holder.getLiveviewStatus();
+                if (holder != null)
+                {
+                    holder.getLiveviewStatus();
+                }
             }
         }
-        catch (Exception e) {
+        catch (Exception e)
+        {
             e.printStackTrace();
         }
     }
@@ -128,7 +138,12 @@ public class PanasonicCameraWrapper implements IPanasonicCameraHolder, IPanasoni
     @Override
     public ICameraConnection getPanasonicCameraConnection()
     {
-        return (new PanasonicCameraConnection(context, provider, this, listener));
+        // PanasonicCameraConnectionは複数生成しない。
+        if (cameraConnection == null)
+        {
+            cameraConnection = new PanasonicCameraConnection(context, provider, this, listener);
+        }
+        return (cameraConnection);
     }
 
     @Override
index 105664b..f8ec285 100644 (file)
@@ -123,14 +123,15 @@ public class PanasonicLiveViewControl implements ILiveViewControl
                         String reply = SimpleHttpClient.httpGet(camera.getCmdUrl() + LIVEVIEW_STOP_REQUEST, TIMEOUT_MS);
                         if (!reply.contains("<result>ok</result>"))
                         {
-                            Log.v(TAG, "stopLiveview() reply is fail... ");
+                            Log.v(TAG, "stopLiveview() reply is fail... " + reply);
                         }
                         else
                         {
-                            //  ライブビューウォッチャーを止める
-                            whileStreamReceive = false;
                             Log.v(TAG, "stopLiveview() is issued.");
                         }
+                        //  ライブビューウォッチャーを止める
+                        whileStreamReceive = false;
+                        closeReceiveSocket();
                     }
                     catch (Exception e)
                     {
@@ -291,10 +292,24 @@ public class PanasonicLiveViewControl implements ILiveViewControl
                 }
             }
         }
+        closeReceiveSocket();
+        Log.v(TAG, "  ----- startReceiveStream() : Finished.");
+        System.gc();
+    }
+
+    public ILiveViewListener getLiveViewListener()
+    {
+        return (liveViewListener);
+    }
+
+    private void closeReceiveSocket()
+    {
+        Log.v(TAG, "closeReceiveSocket()");
         try
         {
             if (receiveSocket != null)
             {
+                Log.v(TAG, "  ----- SOCKET CLOSE -----  ");
                 receiveSocket.close();
                 receiveSocket = null;
             }
@@ -303,12 +318,5 @@ public class PanasonicLiveViewControl implements ILiveViewControl
         {
             e.printStackTrace();
         }
-        Log.v(TAG, "  ----- startReceiveStream() : Finished.");
-        System.gc();
-    }
-
-    public ILiveViewListener getLiveViewListener()
-    {
-        return (liveViewListener);
     }
 }
index 10b84a5..8b38cc5 100644 (file)
@@ -587,10 +587,13 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
         super.onPause();
         Log.v(TAG, "onPause() Start");
 
-        // ライブビューの停止
         try
         {
-            liveViewControl.stopLiveView();
+            // ライブビューの停止
+            if (liveViewControl != null)
+            {
+                liveViewControl.stopLiveView();
+            }
         }
         catch (Exception e)
         {