Page 1 of 4 123 ... LastLast
Results 1 to 20 of 64

Your favorite Apple, iPhone, iPad, iOS, Jailbreak, and Cydia site.


Thread: CameraController, 3GS and 3.0

  1. #1
    Default CameraController, 3GS and 3.0
    Hi all,

    New member here

    I hope you can help with this:

    On my old iPhone, I'd written a small app for time-lapse photography. I class-dumped the PhotoLibrary framework and was using the CameraController interface to take photos programmatically without any user input. The app had a configurable delay setting, producing time-lapse sets of photos that were really quite cool.

    However, I've so far failed in porting the app to 3.0. I've run class-dump against the new framework and have produced the header fine... but after instantiating the CameraController class, calling startPreview and capturePhoto apparently does nothing. My cameraController callback never gets fired.

    Has anyone managed to get this working?

    Many thanks,
    Chris

  2. #2
    Default Auto Focus
    Is it possible for me to get a copy of that class dump? The auto focus works really well, however sometimes when shooting something close you might have to touch the screen multiple times to get a really clear picture and even then while auto focusing you will see the lens pass through the most optimal focus. I would like to write an app that will allow you to control the focus manually but see no references in the 3.0 SDK to the camera class and it's api's.

    -David

  3. #3
    Thanks for the reply!

    I've attached the PLCameraController header. I used the info here to help me generate the dumped headers.

    Good luck -- and let me know if you hit upon something that might help with my problem :)

    (I'm wondering if the delegate method signatures have changed. Unfortunately, the class dumps do not describe the PLCameraControllerDelegate protocol, so I don't know exactly what methods I need to implement in my delegate. There's some interesting stuff in PLCameraView.h (also attached) which seems to indicate that the delegate is indeed different for 3.0 -- see - (void)cameraController:(id)fp8 addedVideoAtPath:.. (etc) for example)

    Hopefully someone will figure this out - I knew I was out of my depth when I started using writing stuff like:

    Code:
    	id prot = objc_getProtocol("PLCameraControllerDelegate");
    	
    	uint propCount;
    	objc_property_t *properties = protocol_copyPropertyList(prot, &propCount);
    ...to try to figure out what the delegate needed to do ;) I'm still quite an objc newbie.
    Attached Files Attached Files

  4. #4
    Another update...

    I think my delegate implementation's actually OK... I invoked [camera _setCameraMode:0 force:TRUE]; and my cameraController:modeDidChange delegate method got called in return... so that's one thing crossed off the list!

    However, try what I can, I can't get [camera isReady] to return YES.

    So far, I'm just frantically calling methods and crossing my fingers! Before I call startPreview, I'm doing:

    [camera setFocusDisabled:TRUE];
    [camera setCaptureAtFullResolution:TRUE];
    [camera _setCameraMode:0 force:TRUE];
    [camera setDontShowFocus:TRUE];

    Just guessing for some of those values

    Perhaps I could subclass PLCameraController and try NSLogging some internal states?

    (so out of my comfort-zone here... but hey, it's fun in a masochistic way!)

  5. #5
    Wow! Thanks. Yeah this is a bit out of my comfort zone too. Apple's idea of an any to follow api structure and mine differ a lot! Keep us posted on what you get working, I think I might need your help.

    -David

  6. #6
    Quote Originally Posted by Kaos2800 View Post
    Wow! Thanks. Yeah this is a bit out of my comfort zone too. Apple's idea of an any to follow api structure and mine differ a lot! Keep us posted on what you get working, I think I might need your help.

    -David
    To be fair, we're digging around here in private frameworks ... so these interfaces weren't designed for direct use by developers and therefore official documentation is non-existent.

    I've still had no luck yet. Is anyone else out there looking at using the PLCameraController private library in 3.0 on the 3GS? Any tinkerers hit on anything useful-looking?

    Cheers,
    Chris

  7. #7
    Hi,

    I'm having the same issues...

    So far, I have used the PLCameraViewController class, and I call the loadView method, this will display the camera view (same as the old startPreview on 2.2.1)

    Regarding the capturePhoto method also not working on 3.0, I added the 7 delegate methods on my code (I have not tested removing the ones not needed), and now when calling capturePhoto, my cameraController:tookPicture:... delegate is called . But the display remains with what it appears to be a preview of the picture. Because I don't need that preview I'm trying to take the picture and not display it, but I had not luck for now. Working on this.

    Hope this help you, and any other info is welcome.

    Thanks!

  8. #8
    Quote Originally Posted by rilocr View Post
    Hi,

    I'm having the same issues...

    So far, I have used the PLCameraViewController class, and I call the loadView method, this will display the camera view (same as the old startPreview on 2.2.1)

    Regarding the capturePhoto method also not working on 3.0, I added the 7 delegate methods on my code (I have not tested removing the ones not needed), and now when calling capturePhoto, my cameraController:tookPicture:... delegate is called . But the display remains with what it appears to be a preview of the picture. Because I don't need that preview I'm trying to take the picture and not display it, but I had not luck for now. Working on this.

    Hope this help you, and any other info is welcome.

    Thanks!
    as I can see you have some luck with camera preview on 3.0

    My app was using following camera initialization on 2.2.1 and working perfectly. Please help me out with code transition to 3.0, I just need to initialize camera stream. That's it.

    declarations in .h:
    Code:
    @interface PLCameraController : NSObject 
    { 
    	CALayer *_cameraLayer; 
    	struct CameraDevice *_camera; 
    	struct CameraImageQueueHelper *_cameraHelper; 
    	id _delegate; 
    	UIView *_previewView; 
    	BOOL _isPreviewing; 
    	BOOL _isLocked; 
    	BOOL _wasPreviewingBeforeDeviceLock; 
    } 
    
    + (id)sharedInstance; 
    - (id)init; 
    - (void)dealloc; 
    - (void)_setIsReady; 
    - (BOOL)isReady; 
    - (void)_applicationSuspended; 
    - (void)_applicationResumed; 
    - (void)_tookPicture:(struct __CoreSurfaceBuffer *)fp8; 
    - (void)_tookPicture:(struct CGImage *)fp8 jpegData:(struct __CFData *)fp12 imageProperties:(struct __CFDictionary *)fp16; 
    - (struct CameraImageQueueHelper *)_cameraHelper; 
    - (BOOL)_setupCamera; 
    - (void)_tearDownCamera; 
    - (void)setDelegate:(id)fp8; 
    - (id)delegate; 
    - (struct CGRect)_cameraFrame; 
    - (id)previewView; 
    - (void)startPreview; 
    - (void)stopPreview; 
    - (void)capturePhoto; 
    
    @end
    and implementation:
    Code:
    PLCameraController *cam = [PLCameraController sharedInstance]; 
    	camView = [cam previewView];
    	[cam startPreview]; 
    	[self addSubview:camView];

  9. #9
    On 2.2.1, I had a class that contained the PLCameraContoller and PLCameraView instance, and that class inherited from UIViewController. Now, on 3.0, I just inherited my class from PLCameraViewController found on the private API (you can have it by making a class dump).

    On 2.2.1:
    Code:
    @interface MyClass : UIViewController {
         PLCameraController *cameraController;
         PLCameraView *cameraView;
    }
    On 3.0:
    Code:
    @interface MyClass:  PLCameraViewController {
         PLCameraController *cameraController;
    }
    And instead of calling the startPreview method, I just call the method loadView on PLCameraViewController, that made the camera display appear again.

    On 2.2.1:
    Code:
    [cameraController startPreview];
    On 3.0:
    Code:
    [self loadView];

  10. #10
    Ok - I think it've got it:

    Basically, I'm bypassing the header file entirely instead instantiating the camera controller using objc_getClass.

    My init code is thus:

    Code:
    self.cameraController = [(id)objc_getClass("PLCameraController") performSelector:@selector(sharedInstance)];
    		[cameraController setDelegate:self];
    		[cameraController setFocusDisabled:NO];
    		[cameraController setCaptureAtFullResolution:YES];
    		[cameraController setDontShowFocus:YES];
    		
    		UIView *previewView = [cameraController performSelector:@selector(previewView)];
    		[containerView addSubview:previewView];
    		[cameraController performSelector:@selector(startPreview)];
    		sleep(2);
    Note that cameraController is declared as (id), not as a class. Notice that I've been tinkering with some of the methods described in the header on the 3GS. They seem to be working and the log file doesn't indicate any unknown selectors. Also, I've found it necessary to sleep for a couple of seconds to allow the camera to initialise correctly (I suppose I should be handling this in the ReadyStateChanged delegate!)

    I'm then taking the snapshot with a simple call:

    Code:
    	[cameraController capturePhoto:TRUE];
    My delegate routines are:

    Code:
    - (void)cameraControllerReadyStateChanged:(NSNotification *)aNotification
    {
        NSLog(@"cameraControllerReadyStateChanged: %@", aNotification);	
    }
    
    -(void)cameraController:(id)sender
    			tookPicture:(UIImage*)picture
    			withPreview:(UIImage*)preview
    			   jpegData:(NSData*)rawData
    		imageProperties:(struct __CFDictionary *)imageProperties
    {
    	
    	NSLog(@"Saving and re-initing...");
    	UIImageWriteToSavedPhotosAlbum(picture, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil);  
    	[cameraController performSelector:@selector(stopPreview)];
    	[cameraController performSelector:@selector(startPreview)];
    }
    
    -(void)cameraController:(id)sender
    		addedVideoAtPath:(NSString *)path
    	  withPreviewSurface:(id)surface
    				metadata:(id)meta
    		  wasInterrupted:(BOOL)interrupt
    {
    	
    }
    
    -(void)cameraController:(id)sender
    		  modeDidChange:(int)mode {
    	NSLog(@"cameraController:modeDidChange");
    }
    
    -(void)cameraControllerVideoCaptureDidStart:(id)sender {
    	NSLog(@"cameraControllerVideoCaptureDidStart");
    }
    
    -(void)cameraControllerVideoCaptureDidStop:(id)sender {
    	NSLog(@"cameraControllerVideoCaptureDidStop");
    }
    
    -(void)cameraControllerFocusFinished:(id)sender {
    	NSLog(@"cameraControllerFocusFinished");
    }
    This works correctly - the tookPicture callback fires and the image is successfully saved to the 'Camera Roll' photo album. I managed to get the camera to re-init by stopping and starting the preview after the image is saved.

    Some of those callback routines relating to video capture look intriguing. But what I've got so far has put me well on the way to getting my time-lapse photography app back and working!

    Hope this helps you guys!

    Cheers,
    Chris

  11. #11
    I think there's no need to reinit the camera when calling the capturePhoto method with NO as a value for the parameter. It appears that parameter is something like : (BOOL) showPreview

    Code:
    [cameraController capturePhoto:NO];
    At least, that worked for me.

  12. #12
    My iPhone is a Part of Me IvanPK's Avatar
    Join Date
    Apr 2008
    Location
    USA
    Posts
    612
    Thanks
    56
    Thanked 47 Times in 44 Posts

    If you get the time lapse application working, could you post it? I'd love to try out something of the sort.

  13. #13
    Quote Originally Posted by rilocr View Post
    I think there's no need to reinit the camera when calling the capturePhoto method with NO as a value for the parameter. It appears that parameter is something like : (BOOL) showPreview

    Code:
    [cameraController capturePhoto:NO];
    Good spot! Behaves the same for me, too.

    Quote Originally Posted by IvanPK View Post
    If you get the time lapse application working, could you post it? I'd love to try out something of the sort.
    Will do! It's basically what I've already posted... just a bit of UI to set the capture interval in seconds and use that value in a call to performSelector:afterDelay. At least, that's the idea (it's not written yet!)

    Cheers,
    Chris

  14. #14
    2rilocr:

    dont know how to make your approach to work. The point is that 'MyClass' is already inherited some methods from UIView, so I dont know how to organize double inheritance.

    I'm trying simplest way to create an instance, like this, but app crashes immediately before start:
    Code:
    /*PLCameraViewController *cameraStream = [[PLCameraController alloc] init];
    	[cameraStream loadView];
    	[self addSubview:(UIView *)cameraStream];*/
    2displaced

    this approach seems working for me, but I have 11 warnings during compilation!

    Check it out if I did it correct way:

    I declare id *cameraController;
    then describe
    Code:
    @class PLCameraView;
    
    @interface PLCameraViewController : UIViewController 
    {
        PLCameraView *_cameraView;
    }
    
    
    - (BOOL)_displaysFullScreen;
    - (void)dealloc;
    - (void)loadView;
    - (void)viewWillDisappear:(BOOL)arg1;
    - (void)viewDidAppear:(BOOL)arg1;
    
    @end
    then I used your code for camera init. Most of the warnings concerning ID pointer type. I did synthesize it and set @property (nonatomic, retain) id *cameraController;

    What did I forget?

    PS For some bloody reason I have imported PhotoLibrary.framework from 2.2.1 And either way I'm trying to add it from 3.0 SDK, I will eventually have 2.2.1 reference after "Reveal in Finder" command.

  15. #15
    Ok, just create a new project on XCode, and then add a new UIViewController subclass, let's call it MyClass. So, in the applicationDidFinishLaunching add:

    Code:
    MyClassView = [[MyClass alloc] initWithNibName:nil bundle:nil];
    [window addSubview:[MyClassView view]];
    And the MyClass.h should be like:

    Code:
    @interface MyClass : PLCameraViewController {
    
    	PLCameraController	*cameraController;
    }
    @end
    When MyClass was created, it inherited from UIViewController, I just changed it to PLCameraViewController. Also, I added the PLCameraController instance to this class, and inside the initWithNibName method I just called:

    Code:
    cameraController = [PLCameraController sharedInstance];
    [cameraController setDelegate:self];
    With only that code you should be able to see camera display on the device, next just add the 7 delegates and start taking pictures or capturing video.

    Any other question just ask me,

  16. #16
    Default SurfaceBuffer Hacks?
    Um... Does anyone try to fix this callback on iPhone 3.0? We are so close to the solution to getting the raw frame once again in 2.2 ...

    Here is what we have used in 2.2


    Code:
    static int __camera_callbackHook(CameraDeviceRef cameraDevice,int a,CoreSurfaceBufferRef coreSurfaceBuffer,int b) {
    
    ..
    
    }
    Code:
    - (void)install_camera_callbackHook {
    	char *p = NULL;
    	object_getInstanceVariable(cameraController,"_camera",(void**)&p);
    	if (!p) return;
    	
    	if (!original_camera_callback) {
    		FUNC_camera_callback *funcP = (FUNC_camera_callback*)p;
    		original_camera_callback = *(funcP+37);
    		(funcP+37)[0] = __camera_callbackHook;
    	}
    }

  17. #17
    That's my next step...

  18. #18
    Default Full screen camera preview
    Can someone help here help me up something?
    I m now creating a camera app on os 3.0,
    i was able to preview the camera,
    but i cant resize the camera view,
    can someone give me some sample code?

  19. #19
    Default cannot preview using cameraController
    Hi,

    I'm having the problem.
    I cannot preview the camera on 3.0

    I created the project using Window-Based-Application template,
    and i added the code in appDelegate.h/m file.

    In camAppDelegate.h, if i write "id <PLCameraControllerDelegate> _delegate;",
    gcc said "error: cannot find protocol declaration for PLCameraControllerDelegate".
    So, i wrote "id _delegate;". Is this wrong?


    camAppDelegate.h
    Code:
    #import <UIKit/UIKit.h>
    
    @class AVCapture, PLPreviewView;
    
    @interface PLCameraController : NSObject
    {
        AVCapture *_avCapture;
        PLPreviewView *_previewView;
        BOOL _isPreviewing;
        BOOL _isLocked;
        int _cameraMode;
        int _captureOrientation;
        int _focusCount;
        int _autofocusCount;
        unsigned int _previousSimpleRemotePriority;
        id /*<PLCameraControllerDelegate>*/ _delegate;
        double _startTime;
        struct {
            unsigned int supportsVideo:1;
            unsigned int supportsAccurateStillCapture:1;
            unsigned int supportsFocus:1;
            unsigned int capturingVideo:1;
            unsigned int deferStopPreview:1;
            unsigned int deferStartVideoCapture:1;
            unsigned int inCall:1;
            unsigned int continuousAutofocusDuringCapture:1;
            unsigned int focusDisabled:1;
            unsigned int focusedAtPoint:1;
            unsigned int wasInterrupted:1;
            unsigned int resumePreviewing:1;
            unsigned int isReady:1;
            unsigned int didSetPreviewLayer:1;
            unsigned int didNotifyCaptureEnded:1;
            unsigned int dontShowFocus:1;
            unsigned int isChangingMode:1;
            unsigned int lowResolutionCapture:1;
            unsigned int delegateModeDidChange:1;
            unsigned int delegateTookPicture:1;
            unsigned int delegateReadyStateChanged:1;
            unsigned int delegateVideoCaptureDidStart:1;
            unsigned int delegateVideoCaptureDidStop:1;
            unsigned int delegateVideoAdded:1;
            unsigned int delegateFocusFinished:1;
        } _cameraFlags;
    }
    
    + (id)sharedInstance;
    - (id)init;
    - (void)dealloc;
    - (void)_inCallStatusChanged:(BOOL)fp8;
    - (BOOL)inCall;
    - (void)_setIsReady;
    - (BOOL)isReady;
    - (BOOL)canCaptureVideo;
    - (int)cameraMode;
    - (void)_setCameraMode:(int)fp8 force:(BOOL)fp12;
    - (void)setCameraMode:(int)fp8;
    - (void)_applicationSuspended;
    - (void)_applicationResumed;
    - (void)_tookPicture:(struct CGImage *)fp8 jpegData:(struct __CFData *)fp12 imageProperties:(struct __CFDictionary *)fp16;
    - (void)_tookPhoto:(id)fp8;
    - (void)_previewStarted:(id)fp8;
    - (void)_previewStopped:(id)fp8;
    - (void)_setVideoPreviewLayer;
    - (BOOL)_setupCamera;
    - (void)viewDidAppear;
    - (void)_tearDownCamera;
    - (void)setDelegate:(id)fp8;
    - (id)delegate;
    - (id)previewView;
    - (void)startPreview;
    - (void)_destroyAVCapture;
    - (void)stopPreview;
    - (void)resumePreview;
    - (BOOL)supportsAccurateStillCapture;
    - (void)capturePhoto:(BOOL)fp8;
    - (BOOL)isCapturingVideo;
    - (void)_captureStarted:(id)fp8;
    - (id)_createPreviewImage;
    - (void *)_createPreviewIOSurface;
    - (void)_captureCompleted:(id)fp8;
    - (void)_didStopCapture;
    - (void)_wasInterrupted:(id)fp8;
    - (void)_interruptionEnded:(id)fp8;
    - (BOOL)canStartVideoCapture;
    - (BOOL)startVideoCaptureAtPath:(id)fp8;
    - (void)_stopVideoCaptureAndPausePreview:(id)fp8;
    - (void)stopVideoCaptureAndPausePreview:(BOOL)fp8;
    - (id)videoCapturePath;
    - (BOOL)focusAtPoint:(struct CGPoint)fp8;
    - (void)restartAutoFocus;
    - (void)autofocus;
    - (void)lockFocus;
    - (BOOL)isFocusing;
    - (void)setDontShowFocus:(BOOL)fp8;
    - (void)setFocusDisabled:(BOOL)fp8;
    - (void)setCaptureAtFullResolution:(BOOL)fp8;
    - (void)_commonFocusFinished;
    - (void)_focusOperationFinished;
    - (void)_autofocusOperationFinished;
    - (void)_focusCompleted:(id)fp8;
    - (void)_focusWasCancelled:(id)fp8;
    - (void)_focusStarted:(id)fp8;
    - (void)_focusHasChanged:(id)fp8;
    - (int)videoCaptureOrientation;
    - (void)irisWillClose;
    - (void)_serverDied:(id)fp8;
    
    @end
    
    
    @interface camAppDelegate : NSObject <UIApplicationDelegate> {
        UIWindow *window;
    	PLCameraController *cameraController;
    }
    
    @property (nonatomic, retain) IBOutlet UIWindow *window;
    
    @end
    camAppDelegate.m
    Code:
    #import "camAppDelegate.h"
    
    @implementation camAppDelegate
    
    @synthesize window;
    
    - (void)cameraControllerReadyStateChanged:(NSNotification *)aNotification
    {
        NSLog(@"cameraControllerReadyStateChanged: %@", aNotification);	
    }
    
    -(void)cameraController:(id)sender
    			tookPicture:(UIImage*)picture
    			withPreview:(UIImage*)preview
    			   jpegData:(NSData*)rawData
    		imageProperties:(struct __CFDictionary *)imageProperties
    {
    	
    	NSLog(@"Saving and re-initing...");
    	UIImageWriteToSavedPhotosAlbum(picture, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil);  
    	[cameraController performSelector:@selector(stopPreview)];
    	[cameraController performSelector:@selector(startPreview)];
    }
    
    -(void)cameraController:(id)sender
    	   addedVideoAtPath:(NSString *)path
    	 withPreviewSurface:(id)surface
    			   metadata:(id)meta
    		 wasInterrupted:(BOOL)interrupt
    {
    	
    }
    
    -(void)cameraController:(id)sender
    		  modeDidChange:(int)mode {
    	NSLog(@"cameraController:modeDidChange");
    }
    
    -(void)cameraControllerVideoCaptureDidStart:(id)sender {
    	NSLog(@"cameraControllerVideoCaptureDidStart");
    }
    
    -(void)cameraControllerVideoCaptureDidStop:(id)sender {
    	NSLog(@"cameraControllerVideoCaptureDidStop");
    }
    
    -(void)cameraControllerFocusFinished:(id)sender {
    	NSLog(@"cameraControllerFocusFinished");
    }
    
    - (void)applicationDidFinishLaunching:(UIApplication *)application {    
    	cameraController = [(id)objc_getClass("PLCameraController") performSelector:@selector(sharedInstance)];
    	[cameraController setDelegate:self];
    	[cameraController setFocusDisabled:NO];
    	[cameraController setCaptureAtFullResolution:YES];
    	[cameraController setDontShowFocus:YES];
    	
    	UIView *previewView = [cameraController performSelector:@selector(previewView)];
    	[window addSubview:previewView];
    	[cameraController performSelector:@selector(startPreview)];
    	sleep(2);
    	
           // Override point for customization after application launch
        [window makeKeyAndVisible];
    }
    
    
    - (void)dealloc {
        [window release];
        [super dealloc];
    }
    @end

  20. #20
    What if you write:

    Code:
    @class AVCapture, PLPreviewView;
    @protocol PLCameraControllerDelegate;

Page 1 of 4 123 ... LastLast
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •