ricohapi / theta-client

A library to control RICOH THETA
MIT License
15 stars 11 forks source link

Connection issue with ios demo project #38

Closed yuehengshiCarmedia2p0 closed 10 months ago

yuehengshiCarmedia2p0 commented 1 year ago

Hi there, I'm running the ios demo and sometimes it won't connect to the camera after the first connection and I got the logs below. I guess it might be because too many connection requests. Is there a way like disconnecting from the camera or stop the current session so that there won't be an issue with the next connection request.

https://github.com/ricohapi/theta-client/assets/107428314/fa1459ec-59c0-480a-9d60-5ddc62b75f9e

HttpClient: REQUEST: http://192.168.1.1/osc/info
METHOD: HttpMethod(value=GET)
COMMON HEADERS
-> Accept: application/json
-> Accept-Charset: UTF-8
CONTENT HEADERS
-> Content-Length: 0
BODY Content-Type: null
BODY START

BODY END
HttpClient: REQUEST http://192.168.1.1/osc/info failed with exception: kotlin.IllegalStateException: Failed to connect to InetSocketAddress(hostname=192.168.1.1, port=80).
HttpClient: REQUEST http://192.168.1.1/osc/info failed with exception: io.ktor.utils.io.errors.PosixException.TimeoutIOException: ETIMEDOUT (60): Operation timed out
https://github.com/ricohapi/theta-client/assets/107428314/bea8758c-7463-4175-a7ff-c250393933ea

Also, I’m using theta sc2, firm version 06.41. I got image decode errors when getting the live frames. It looks like it only successfully decoded some live frames, the rest was failed to be decoded, so the live view is kind of stuck.

09a421edcc908c15da21fd9fe07ce9df55ded0ef_2_1380x892

yuehengshiCarmedia2p0 commented 1 year ago

Also sometimes I got this error when running function func livePreview(frameHandler: @escaping ThetaFrameHandler) in file ThetaSdk, not sure what is this error about

Error Domain=KotlinException Code=0 "kotlin.NullPointerException" UserInfo={NSLocalizedDescription=kotlin.NullPointerException, KotlinException=com.ricoh360.thetaclient.ThetaRepository.NotConnectedException: kotlin.NullPointerException, KotlinExceptionOrigin=} Error Domain=KotlinException Code=0 "Selector closed." UserInfo={NSLocalizedDescription=Selector closed., KotlinException=com.ricoh360.thetaclient.ThetaRepository.NotConnectedException: Selector closed., KotlinExceptionOrigin=}

simago commented 1 year ago

@yuehengshiCarmedia2p0 Thank you for reporting the issue. We are investigating the problems.

simago commented 1 year ago

@yuehengshiCarmedia2p0 We have found two problems in iOS demo.

(1) In ThetaSdk.swift: Function Theta.livePreview() has wrong callback function invoke().

(2) In TakePhotoView.swift: When back button is tapped, getThetaInfo() is called before finishing getLivePreview().

To fix the first problem, please replace the 76th line through the 93th line of ThetaSdk.swift with following codes:

            func invoke(p1: Any?) async throws -> Any? {
                let now = CACurrentMediaTime()
                if (now - last > Self.FrameInterval) {
                    var result = false
                    autoreleasepool {
                        if let frameData = p1 as? KotlinPair<KotlinByteArray, KotlinInt> {
                            let nsData = PlatformKt.frameFrom(
                                packet: frameData
                            )
                            result = handler(nsData)
                        }
                    }
                    last = now
                    return result
                } else {
                    return true
                }
            }

To fix the second problem, please replace the 59th line through 61th line of TakePhotoView.swift with following codes:

                    Button(action: {
                        previewing = false
                        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
                            self.presentation.wrappedValue.dismiss()
                        }
                    },

We will include these changes to the next release.

yuehengshiCarmedia2p0 commented 1 year ago

@simago Thanks for the help! I think the it did fix the connection issue, but I still have 2 questions:

  1. Still having Picture decode failed problem with SC2 (SC doesn't have this issue)
  2. Could you please have a look at the video? So the issue happens when switching wifi, and then there will be an error with livePreview. Since there is a demand of switching wifi in our app, I wonder how to handle with switching wifi.

Thanks!

simago commented 1 year ago

@yuehengshiCarmedia2p0 We recognize Picture decode failed problem with SC2. Each JPEG frame received from Theta has no problem, but an error may occur on decoding JPEG frame. We do not have a solution yet.

simago commented 1 year ago

@yuehengshiCarmedia2p0 Thank you for reporting the issue on switching WiFi. We will investigate it.

By the way, we will take summer holidays from tomorrow, so we can not respond a while.

simago commented 1 year ago

@yuehengshiCarmedia2p0 I saw your video and tried to display live preview with Theta SC after WiFi switching, but I do not get an exception yet.

Theta SC and SC2 sometimes don't send chunk data of live preview, so Theta Client perform a retry of preview request ( see the source code). In the case of the video, Theta SC may not send chunk data within the retries.

I will improve the PreviewClientException message in the next release, so that you will get the cause of the exception.

yuehengshiCarmedia2p0 commented 1 year ago

@simago I just tested many times with SC they all got the exception and recorded a new video Whereas SC2 won't throw an exception, it will be failed to show live preview the first time after switching wifi but then it will be working, please see the video for SC2

simago commented 1 year ago

@yuehengshiCarmedia2p0 Thank you for valuable tests with SC and SC2.

SC implements both of Web API v2.0 and Web API v2.1, they are incompatible with each other. When turning on SC and losing WiFi connection with SC, Web API v2.0 gets effective.

Theta Client targets Web API 2.1, so if SC is found on initialization, make SC change to Web API 2.1. But we did not consider losing WiFi connection, so Theta Client sends a request for Web API 2.1 to SC with Web API 2.0 and gets an error response.

We will provide a solution to this problem.

simago commented 10 months ago

1.4.0 has fixed this issue.