quatanium / foscam-ios-sdk

Foscam iOS SDK for H.264 IP Cameras (FI9821W/P/HD816W/P)
MIT License
26 stars 19 forks source link

EXC_BAD_ACCESS #1

Open brandtdaniels opened 10 years ago

brandtdaniels commented 10 years ago

I'm getting a crash on this line:

        usrLogIn(_m_iDeviceType, _m_CtrlParam.ip, _m_CtrlParam.username, _m_CtrlParam.passwd, _m_CtrlParam.streamType, _m_CtrlParam.port, _m_CtrlParam.webPort, m_Uid, _m_iChid);

in FoscamCamera.m on Thread 1.

Do you have an example project with this sdk running on iOS 7?

taiyangc commented 10 years ago

The official sdk with sample is here: http://foscam.us/forum/cgi-sdk-for-hd-camera-t6045.html

I am unable to provide you with a sample project but I can help you with debugging. We have tested it with target set to iOS6 but it also works on iOS7. Do you have a stack trace on this exception?

brandtdaniels commented 10 years ago

crashes right after usleep(50) in MessageThreadWork of FoscamCamera.m and right before the line above.

Incident Identifier: 277D249C-6C0F-4AAC-9C2C-329C14AD8FE1 CrashReporter Key: 252bf933926a28270ec1b8b4aee126fddbf108b7 Hardware Model: iPhone5,2 Process:
Path: /var/mobile/Applications/ Identifier: com. Version: 225 (1.7.9) Code Type: ARM (Native) Parent Process: launchd [1]

Date/Time: 2014-06-04 16:43:19.079 -0700 OS Version: iOS 7.1.1 (11D201) Report Version: 104

Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x00000000 Triggered by Thread: 0

Thread 0 Crashed: 0 IFH 0x00bcdba0 0x46000 + 12090272 1 IFH 0x0073ba90 0x46000 + 7297680 2 IFH 0x0073b41e 0x46000 + 7296030 3 IFH 0x00086cc0 0x46000 + 265408 4 UIKit 0x32b23d1e -[UIViewController _setViewAppearState:isAnimating:] + 434 5 UIKit 0x32b241bc -[UIViewController _endAppearanceTransition:] + 260 6 UIKit 0x32bcf4ee -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 866 7 UIKit 0x32c9b1a4 49-[UINavigationController _startCustomTransition:]_block_invoke + 156 8 UIKit 0x32c20ee8 -[_UIViewControllerTransitionContext completeTransition:] + 72 9 UIKit 0x32d7db08 53-[_UINavigationParallaxTransition animateTransition:]_block_invoke103 + 448 10 UIKit 0x32b4178a -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 282 11 UIKit 0x32b413d2 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 174 12 UIKit 0x32b412ea -[UIViewAnimationState animationDidStop:finished:] + 62 13 QuartzCore 0x3278be06 CA::Layer::run_animation_callbacks(void*) + 230 14 libdispatch.dylib 0x3af59d3c _dispatch_client_callout + 20 15 libdispatch.dylib 0x3af5c6be _dispatch_main_queue_callback_4CF + 274 16 CoreFoundation 0x302a467c CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 4 17 CoreFoundation 0x302a2f48 __CFRunLoopRun + 1304 18 CoreFoundation 0x3020d764 CFRunLoopRunSpecific + 520 19 CoreFoundation 0x3020d546 CFRunLoopRunInMode + 102 20 GraphicsServices 0x3517a6ce GSEventRunModal + 134 21 UIKit 0x32b6c88c UIApplicationMain + 1132 22 IFH 0x00600e6c 0x46000 + 6008428 23 IFH 0x0004a9bc 0x46000 + 18876

Thread 1: 0 libsystem_kernel.dylib 0x3b012804 kevent64 + 24 1 libdispatch.dylib 0x3af61050 _dispatch_mgr_invoke + 228 2 libdispatch.dylib 0x3af5b2de _dispatch_mgr_thread + 34

Thread 2: 0 libsystem_kernel.dylib 0x3b025c70 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x3b08ac1e _pthread_wqthread + 306 2 libsystem_pthread.dylib 0x3b08aad8 start_wqthread + 4

Thread 3: 0 libsystem_kernel.dylib 0x3b012a50 mach_msg_trap + 20 1 libsystem_kernel.dylib 0x3b012848 mach_msg + 36 2 CoreFoundation 0x302a4624 CFRunLoopServiceMachPort + 152 3 CoreFoundation 0x302a2d44 CFRunLoopRun + 788 4 CoreFoundation 0x3020d764 CFRunLoopRunSpecific + 520 5 CoreFoundation 0x3020d546 CFRunLoopRunInMode + 102 6 Foundation 0x30c00492 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 250 7 Foundation 0x30c51254 -[NSRunLoop(NSRunLoop) run] + 76 8 INSTEON for Hub 0x0081f1bc 0x46000 + 8229308 9 Foundation 0x30cc2a0a NSThread__main + 1058 10 libsystem_pthread.dylib 0x3b08c956 _pthread_body + 138 11 libsystem_pthread.dylib 0x3b08c8c6 _pthread_start + 98 12 libsystem_pthread.dylib 0x3b08aae4 thread_start + 4

Thread 4: 0 libsystem_kernel.dylib 0x3b025c70 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x3b08ac1e _pthread_wqthread + 306 2 libsystem_pthread.dylib 0x3b08aad8 start_wqthread + 4

Thread 5: 0 libsystem_kernel.dylib 0x3b025c70 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x3b08ac1e _pthread_wqthread + 306 2 libsystem_pthread.dylib 0x3b08aad8 start_wqthread + 4

Thread 6: 0 libsystem_kernel.dylib 0x3b012a50 mach_msg_trap + 20 1 libsystem_kernel.dylib 0x3b012848 mach_msg + 36 2 CoreFoundation 0x302a4624 CFRunLoopServiceMachPort + 152 3 CoreFoundation 0x302a2d44 CFRunLoopRun + 788 4 CoreFoundation 0x3020d764 CFRunLoopRunSpecific + 520 5 CoreFoundation 0x3020d546 CFRunLoopRunInMode + 102 6 Foundation 0x30c00492 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 250 7 INSTEON for Hub 0x00181a74 0x46000 + 1292916 8 INSTEON for Hub 0x00413880 0x46000 + 3987584 9 libdispatch.dylib 0x3af59d50 _dispatch_call_block_and_release + 8 10 libdispatch.dylib 0x3af5f684 _dispatch_root_queue_drain + 224 11 libdispatch.dylib 0x3af5f8d8 _dispatch_worker_thread2 + 52 12 libsystem_pthread.dylib 0x3b08ac14 _pthread_wqthread + 296 13 libsystem_pthread.dylib 0x3b08aad8 start_wqthread + 4

Thread 7 name: com.apple.NSURLConnectionLoader Thread 7: 0 libsystem_kernel.dylib 0x3b012a50 mach_msg_trap + 20 1 libsystem_kernel.dylib 0x3b012848 mach_msg + 36 2 CoreFoundation 0x302a4624 CFRunLoopServiceMachPort + 152 3 CoreFoundation 0x302a2d44 __CFRunLoopRun + 788 4 CoreFoundation 0x3020d764 CFRunLoopRunSpecific + 520 5 CoreFoundation 0x3020d546 CFRunLoopRunInMode + 102 6 Foundation 0x30c4d23c +[NSURLConnection(Loader) _resourceLoadLoop:] + 316 7 Foundation 0x30cc2a0a NSThreadmain + 1058 8 libsystem_pthread.dylib 0x3b08c956 _pthread_body + 138 9 libsystem_pthread.dylib 0x3b08c8c6 _pthread_start + 98 10 libsystem_pthread.dylib 0x3b08aae4 thread_start + 4

Thread 8 name: com.apple.CFSocket.private Thread 8: 0 libsystem_kernel.dylib 0x3b025434 select + 20 1 CoreFoundation 0x302a851e CFSocketManager + 482 2 libsystem_pthread.dylib 0x3b08c956 _pthread_body + 138 3 libsystem_pthread.dylib 0x3b08c8c6 _pthread_start + 98 4 libsystem_pthread.dylib 0x3b08aae4 thread_start + 4

Thread 9: 0 libsystem_kernel.dylib 0x3b025c70 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x3b08ac1e _pthread_wqthread + 306 2 libsystem_pthread.dylib 0x3b08aad8 start_wqthread + 4

Thread 10: 0 libsystem_kernel.dylib 0x3b012a50 mach_msg_trap + 20 1 libsystem_kernel.dylib 0x3b012848 mach_msg + 36 2 CoreFoundation 0x302a4624 CFRunLoopServiceMachPort + 152 3 CoreFoundation 0x302a2d44 CFRunLoopRun + 788 4 CoreFoundation 0x3020d764 CFRunLoopRunSpecific + 520 5 CoreFoundation 0x3020d546 CFRunLoopRunInMode + 102 6 INSTEON for Hub 0x0019bb38 0x46000 + 1399608 7 Foundation 0x30cc2a0a NSThread__main + 1058 8 libsystem_pthread.dylib 0x3b08c956 _pthread_body + 138 9 libsystem_pthread.dylib 0x3b08c8c6 _pthread_start + 98 10 libsystem_pthread.dylib 0x3b08aae4 thread_start + 4

Thread 11: 0 libsystem_kernel.dylib 0x3b025c70 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x3b08ac1e _pthread_wqthread + 306 2 libsystem_pthread.dylib 0x3b08aad8 start_wqthread + 4

Thread 12: 0 libsystem_kernel.dylib 0x3b012a50 mach_msg_trap + 20 1 libsystem_kernel.dylib 0x3b012848 mach_msg + 36 2 CoreFoundation 0x302a4624 CFRunLoopServiceMachPort + 152 3 CoreFoundation 0x302a2d44 CFRunLoopRun + 788 4 CoreFoundation 0x3020d764 CFRunLoopRunSpecific + 520 5 CoreFoundation 0x3020d546 CFRunLoopRunInMode + 102 6 Foundation 0x30c00492 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 250 7 INSTEON for Hub 0x00181a74 0x46000 + 1292916 8 INSTEON for Hub 0x00413880 0x46000 + 3987584 9 libdispatch.dylib 0x3af59d50 _dispatch_call_block_and_release + 8 10 libdispatch.dylib 0x3af5f684 _dispatch_root_queue_drain + 224 11 libdispatch.dylib 0x3af5f8d8 _dispatch_worker_thread2 + 52 12 libsystem_pthread.dylib 0x3b08ac14 _pthread_wqthread + 296 13 libsystem_pthread.dylib 0x3b08aad8 start_wqthread + 4

Thread 13: 0 libsystem_kernel.dylib 0x3b025c70 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x3b08ac1e _pthread_wqthread + 306 2 libsystem_pthread.dylib 0x3b08aad8 start_wqthread + 4

Thread 14: 0 libsystem_kernel.dylib 0x3b025c70 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x3b08ac1e _pthread_wqthread + 306 2 libsystem_pthread.dylib 0x3b08aad8 start_wqthread + 4

Thread 15: 0 libsystem_kernel.dylib 0x3b025c70 __workq_kernreturn + 8 1 libsystem_pthread.dylib 0x3b08ac1e _pthread_wqthread + 306 2 libsystem_pthread.dylib 0x3b08aad8 start_wqthread + 4

Thread 16: 0 libsystem_kernel.dylib 0x3b025544 __semwait_signal + 24 1 libsystem_c.dylib 0x3af96744 nanosleep + 168 2 libsystem_c.dylib 0x3af96694 usleep + 48 3 INSTEON for Hub 0x0073c0c0 0x46000 + 7299264 4 INSTEON for Hub 0x0073bbb2 0x46000 + 7297970 5 libsystem_pthread.dylib 0x3b08c956 _pthread_body + 138 6 libsystem_pthread.dylib 0x3b08c8c6 _pthread_start + 98 7 libsystem_pthread.dylib 0x3b08aae4 thread_start + 4

Thread 0 crashed with ARM Thread State (32-bit): r0: 0x00000000 r1: 0x0131b414 r2: 0x00000000 r3: 0x27dbc94c r4: 0x00006270 r5: 0x00000000 r6: 0x00000001 r7: 0x27dbc86c r8: 0x181cf632 r9: 0x00006270 r10: 0x00000001 r11: 0x181cf646 ip: 0x00006270 sp: 0x27dbc830 lr: 0x0073ba95 pc: 0x00bcdba0

brandtdaniels commented 10 years ago

I think it's a threading issue in FoscamCamera.m

taiyangc commented 10 years ago

I agree there are some threading issues here and there. But most problems lie within the lower-level sdk (which I do not have access to).

The solution, though not elegant, is the following:

1) Modify main.m like this:

#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#if !(TARGET_IPHONE_SIMULATOR)
#import "FSApi.h"
#endif

int main(int argc, char *argv[])
{
    @autoreleasepool {
#if !(TARGET_IPHONE_SIMULATOR)
        Init();
#endif
        int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
#if !(TARGET_IPHONE_SIMULATOR)
        Uninit();
#endif
        return retVal;
    }
}

2) Use Singleton pattern for FoscamCamera everywhere. Basically, do not de-allocate once created. Foscam lib is terrible at memory allocation. If you need multiple cameras at the same time, allocate four FoscamCameras (which is the max concurrent limit on these models), and use a pool to manage these singletons.

+ (FoscamCamera *)sharedFoscam
{
    static dispatch_once_t once;
    static FoscamCamera *sharedInstance;

    dispatch_once(&once, ^{
        sharedInstance = [[FoscamCamera alloc] init];
    });

    return sharedInstance;
}

Hope this helps.

brandtdaniels commented 10 years ago

Sorry not working, now getting a crash in main.m instead

taiyangc commented 10 years ago

We will release a demo project in the coming week.

brandtdaniels commented 10 years ago

I've created a pull request with an updated ffmpeg. Also I've put the autorelease pools back in the thread methods:

- (void)MessageThreadWork
{
    @autoreleasepool {
- (void)ThreadWork
{
    @autoreleasepool {

It seems to help, as I've gotten a bit further. Now i'm encountering this issue:

Save frame to buffer, isKey:0, len:1540, width:1280, height:720, mShmSize/2:524288
Read frame from buffer, DataLen:1540, Pos:451434, IsKeyFram:0, Width:1280, Height:720
Jun 11 10:47:47 iPhone IFH[4782] <Error>: CGImageCreate: invalid image bits/pixel or bytes/row.
Save frame to buffer, isKey:0, len:8084, width:1280, height:720, mShmSize/2:524288
Read frame from buffer, DataLen:8084, Pos:452974, IsKeyFram:0, Width:1280, Height:720
taiyangc commented 10 years ago

The Foscam SDK is incompatible with ffmpeg higher than the 0.7 branch (we traced it all the way back). Your original issue should become clear when the demo project is released. Sorry about not doing so earlier.

brandtdaniels commented 10 years ago

Is LibFsNetLib their only static library? Otherwise why can't we interface with ffmpeg without using their conversion code? I'm trying to get Foscam to recompile their library to support more architectures such as the simulator.

-Brandt

Sent from my iPhone

On Jun 11, 2014, at 12:26 PM, Eric Chen notifications@github.com wrote:

The Foscam SDK is incompatible with ffmpeg higher than the 0.7 branch (we traced it all the way back). Your original issue should become clear when the demo project is released. Sorry about not doing so earlier.

— Reply to this email directly or view it on GitHub.

taiyangc commented 10 years ago

It's possible to interface directly with ffmpeg but I doubt it would be a short task, given that the Foscam apis are all private. They told us only armv7 would be built for now.