1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884 |
- //
- // PCSBaseViewController.m
- // PanoramicCameraSDK
- //
- // Created by 王昭威 on 2023/1/14.
- //
- #import "PCSBaseViewController.h"
- #import <AVFoundation/AVFoundation.h>
- #import "Masonry.h"
- #import "CameraManager.h"
- #import "AVCapturePhotoOutput+VersionAdaptor.h"
- #import "PCSRoundButton.h"
- #import "PCSModeList.h"
- #import "UIImage+ext.h"
- #import "PCSTools.h"
- #import "OperationNodeProtocol.h"
- #import "OperationNodeSingle.h"
- #import "OperationNodeMultiple.h"
- #import "OperationNodePanorama.h"
- #import "QuitMultipleModeAlertViewController.h"
- #import <CoreMotion/CoreMotion.h>
- #import "OperationNodeMovie.h"
- #import "SDKParameters.h"
- #import "PhotoListViewController.h"
- #import "CustomModalViewTransition.h"
- #import "MovieListViewController.h"
- #import "TimerLabel.h"
- #import "MoviePlayerViewController.h"
- #import "PanoramaOrientationView.h"
- #import "PanoramaGuideView.h"
- #import "Renderer.h"
- #import "CameraTextureRenderPass.h"
- #import "LenzSDKConstant.h"
- #import "TensorFlowWrapper.h"
- #import "DBManager.h"
- #import <Photos/Photos.h>
- #import "BaseViewTapGestureDelegate.h"
- #import "MovieListCellModel.h"
- #import "PreviewSingleViewController.h"
- #import "OperationNodeAIPanorama.h"
- #import "PhotoAlbumListViewController.h"
- #import "PhotoAlbumModel.h"
- //#import "LenStitcher.h"
- //#import <LenzStitchSDK/LenzStitchSDK.h>
- #import "LenzDataManager.h"
- #import "LenzHeader.h"
- #import "LenzCachedResourceModel.h"
- #import "LenzDataManager.h"
- #import "PCSPreviewViewController.h"
- #import "SVProgressHUD.h"
- #import "PCSAutherView.h"
- #import <LenzTensorFlowSDK/LenzTensorFlow.h>
- #define MODE_LIST_INDEX_2_MODE_ENUM(x) ((x))
- // PCS means panoramic camera sdk
- @interface PCSBaseViewController ()<AVCapturePhotoCaptureDelegate,
- AVCaptureFileOutputRecordingDelegate,
- AVCaptureAudioDataOutputSampleBufferDelegate,
- UIViewControllerTransitioningDelegate,
- AVCaptureVideoDataOutputSampleBufferDelegate,
- PhotoListViewControllerDelegate,
- PanoramaOrientationViewDelegate>
- @property (nonatomic, assign) CGFloat accX;
- @property (nonatomic, nullable, readonly) AVCaptureDevice* currentCamera;
- @property (nonatomic, nullable, readonly) AVCaptureDeviceInput* currentCameraInput;
- @property (nonatomic, strong) AVCaptureSession* captureSession;
- @property (nonatomic, strong) AVCaptureVideoDataOutput* videoDataOutput;
- @property (nonatomic, strong) AVCaptureMovieFileOutput* movieFileOutput;
- @property (nonatomic, strong) AVCapturePhotoOutput* photoOutput;
- @property (nonatomic, strong) AVCapturePhotoSettings* outputSettings;
- @property (nonatomic, copy) dispatch_queue_t videoDataQueue;
- @property (nonatomic, strong) AVAssetWriter* videoWriter;
- @property (nonatomic, strong) AVAssetWriterInput* videoWriterInput;
- @property (nonatomic, assign) BOOL cameraPrepared;
- @property (nonatomic, assign) BOOL flag;
- @property (nonatomic, assign) BOOL hasCache;
- @property (nonatomic, strong) UIView* focusView;
- @property (nonatomic, strong, nullable) NSTimer* recordTimer;
- @property (nonatomic) dispatch_source_t touchSourceTimer;
- @property (nonatomic) CGFloat touchTime;
- @property (nonatomic, strong, nullable) NSTimer* motionTimer;
- @property (nonatomic, strong) BaseViewTapGestureDelegate* tapDelegate;
- /**
- key: PhotographModeEnum
- value: subclass of OperationNodeProtocol
- */
- @property (nonatomic, strong) NSDictionary<NSNumber*, id<OperationNodeProtocol>>* operationNodes;
- @property (nonatomic, strong) NSArray<id<OperationNodeProtocol>>* operationNodesArray;
- @property (nonatomic) dispatch_semaphore_t videoStitchSemaphore;
- @property (nonatomic) LenzCachedResourceModel *resourceModel;
- @property (nonatomic) UIView *stitchView;
- @property (nonatomic) UIImageView *stitchImageView;
- @property (nonatomic) UILabel *stitchLabel;
- @property (nonatomic) CABasicAnimation *loadingAnimation;
- @property (nonatomic) BOOL isStitchBigImage;
- @property (nonatomic) CGFloat brightnessValue;
- @property (nonatomic) CMMotionManager *motionManager;
- @property (nonatomic) BOOL isTakePhoto;
- @property (nonatomic) NSLock *stitchkLock;
- @property (nonatomic) LenVideoStitchResult stitchResult;
- @property (nonatomic) NSNumber *startPitchX;
- @property (nonatomic) NSNumber *startRollY;
- @property (nonatomic) LenzTensorFlow *tensorFlow;
- @property (nonatomic) BOOL isContainSingleInReatinMode;
- @property (nonatomic) UILabel *aiPanPromtLabel;
- @property (nonatomic) PCSAutherView *authView;
- @end
- @implementation PCSBaseViewController
- #pragma mark - Life Circle
- - (void)dealloc{
- [self stopAllSensors];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- [[LenzDBManager shared] close];
- }
- - (void)awakeFromNib{
- [super awakeFromNib];
- [self setup];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [SVProgressHUD setDefaultStyle:SVProgressHUDStyleLight];
- [SVProgressHUD setMinimumDismissTimeInterval:1.5];
- [SVProgressHUD setMaximumDismissTimeInterval:3];
- [SVProgressHUD setFont:[UIFont systemFontOfSize:14]];
- self.tensorFlow = [[LenzTensorFlow alloc]initWithFileName:@"moire_mobilenetv2_79"];
- self.stitchkLock = [[NSLock alloc]init];
-
- self.totalArray = [[NSMutableArray alloc]init];
- self.cachesArray = [[NSMutableArray alloc]init];
- self.typeArray = [[NSMutableArray alloc]init];
- self.isContainSingleInReatinMode = NO;
- self.resourceModel = [[LenzCachedResourceModel alloc]init];
- self.motionManager = [[CMMotionManager alloc]init];
- self.motionManager.deviceMotionUpdateInterval = 1/5;
-
- [self.view addSubview:self.panoramaGuideView];
- [self panoramaOrientationViewslt:(PanoramaOrientationViewLeft)];
- self.panoramaGuideView.hidden = YES;
-
- [self.view addSubview:self.aiPanPromtLabel];
- [self.aiPanPromtLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.view);
- make.top.mas_equalTo(self.modeLabel.mas_bottom).mas_offset(20);
- make.width.mas_offset(240);
- make.height.mas_offset(20);
- }];
- [self.view addSubview:self.authView];
- [self.authView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_offset(0);
- }];
- if (!JK_IS_IPHONE_X) {
- self.safeBottom.constant = 25;
- self.safeTop.constant = 15;
- }else{
- self.safeBottom.constant = 0;
- }
-
- [self.timerLabel updateWith:100];
-
- self.albumButton.layer.cornerRadius = 6;
- self.albumButton.clipsToBounds = YES;
- [self updateFlashButton];
-
- [PCSMotionManager shared];
-
- __weak typeof(self) weakself = self;
- [self.modeList reloadWith:self.operationNodesArray];
- self.modeList.indexChangedHandler = ^BOOL(NSUInteger newMode, NSUInteger oldMode, NSUInteger newIndex) {
- __strong typeof(weakself) strongSelf = weakself;
-
- if ([SDKParameters shared].retainedMode == SDK_DATA_RETAINED_CLEAR) {
- BOOL needAlert = NO;
- switch (self.mode) {
- case SDK_CAPTURE_MODE_CONTINUOUS:
- needAlert = self.resourceModel.continousArray.count;
- break;
- case SDK_CAPTURE_MODE_SINGLE:
- needAlert = self.resourceModel.singleArray.count;
- break;
- case SDK_CAPTURE_MODE_MOVIE:
- needAlert = self.resourceModel.movieArray.count;
- break;
- case SDK_CAPTURE_MODE_PANORAMA:
- needAlert = self.resourceModel.panoramArray.count;
- break;
- case SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA:
- needAlert = self.resourceModel.aiPanoramArray.count;
- break;
-
- default:
- break;
- }
- if (needAlert) {
- [QuitMultipleModeAlertViewController show:self title:@"确认提醒" text:@"切换模式会清除已拍摄数据,请确认" leftBtnTitle:@"取消" rightBtnTitle:@"确定" withLeftButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) {
- [alertController dismissViewControllerAnimated:NO completion:^{}];
- } rightButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) {
- switch (self.mode) {
- case SDK_CAPTURE_MODE_CONTINUOUS: {
-
- [self.resourceModel.continousArray removeAllObjects];
- [self updateViewStatus];
- }
- break;
- case SDK_CAPTURE_MODE_SINGLE: {
- [self.resourceModel.singleArray removeAllObjects];
- [self updateViewStatus];
- }
- break;
- case SDK_CAPTURE_MODE_MOVIE:
- {
- [self.resourceModel.movieArray removeAllObjects];
- [self updateViewStatus];
- }
- break;
- case SDK_CAPTURE_MODE_PANORAMA:
- {
- [self.resourceModel.panoramArray removeAllObjects];
- [self updateViewStatus];
- }
- break;
- case SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA:
- {
- [self.resourceModel.aiPanoramArray removeAllObjects];
- [self updateViewStatus];
- }
- break;
-
- default:
- break;
- }
- self.modeList.index = newIndex;
- [self.modeList updateItemsConstraints];
- [strongSelf modeWillChange:newMode oldIndex:oldMode];
-
- id<OperationNodeProtocol> oldModelNode = strongSelf.currentOperationNode;
- PhotographModeEnum mode = (PhotographModeEnum)MODE_LIST_INDEX_2_MODE_ENUM(newMode);
- strongSelf.mode = mode;
- // self.ai_fullView.hidden = !(mode == SDK_CAPTURE_MODE_PANORAMA);
- self.ai_fullView.hidden = YES;
- [strongSelf modeDidChange:newMode oldIndex:oldMode];
- [strongSelf updateCaptureSessionWith:oldMode];
- if([oldModelNode respondsToSelector:@selector(didQuit)]){
- [oldModelNode didQuit];
- }
-
- [alertController dismissViewControllerAnimated:NO completion:^{}];
- }];
- return NO;
- }
- }
-
- [strongSelf modeWillChange:newMode oldIndex:oldMode];
-
- id<OperationNodeProtocol> oldModelNode = strongSelf.currentOperationNode;
- PhotographModeEnum mode = (PhotographModeEnum)MODE_LIST_INDEX_2_MODE_ENUM(newMode);
- strongSelf.mode = mode;
- // self.ai_fullView.hidden = !(mode == SDK_CAPTURE_MODE_PANORAMA);
- self.ai_fullView.hidden = YES;
- [strongSelf modeDidChange:newMode oldIndex:oldMode];
- [strongSelf updateCaptureSessionWith:oldMode];
- if([oldModelNode respondsToSelector:@selector(didQuit)]){
- [oldModelNode didQuit];
- }
- return YES;
- };
-
- [self modeWillChange:[SDKParameters shared].modeIndex oldIndex:0lu];
- self.modeList.mode = [SDKParameters shared].modeIndex;
- self.mode = [SDKParameters shared].modeIndex;
- [self modeDidChange:[SDKParameters shared].modeIndex oldIndex:0lu];
-
- UIVisualEffectView* effectView = [[UIVisualEffectView alloc] initWithEffect: [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
- effectView.alpha = 0.8;
- effectView.effect = nil;
- self.effectView = effectView;
- [self.view insertSubview:self.effectView belowSubview:self.backButton];
- [self.effectView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.view);
- }];
-
- if(!self.cameraPrepared){
- [self prepareCamera];
- }
-
- [self modeDidChange:[SDKParameters shared].modeIndex oldIndex:0lu];
- [self updateCaptureSessionWith:0];
-
- self.panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureHandler:)];
- [self.view addGestureRecognizer:self.panGesture];
-
-
- UIImageView* loadingImageView = [[UIImageView alloc] initWithImage:[UIImage sdkImageNamed:@"loading"]];
- self.loadingIndicator = loadingImageView;
- self.loadingIndicator.hidden = YES;
- [self.view addSubview:self.loadingIndicator];
- [loadingImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(self.view);
- }];
-
- self.savePhotoButton.titleLabel.textColor = [UIColor whiteColor];
- self.discardPhotoButton.titleLabel.textColor = [UIColor whiteColor];
-
-
- // [self.takePhotoButton mas_remakeConstraints:^(MASConstraintMaker *make) {
- // make.centerX.equalTo(self.view);
- // make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
- // }];
-
- [self updateUIByMode];
-
- self.panoramOrientationGuideView.delegate = self;
-
- self.ablumImageView = [[UIImageView alloc]init];
- [self.view addSubview:self.ablumImageView];
- self.ablumImageView.layer.cornerRadius = 6;
- self.ablumImageView.layer.masksToBounds = YES;
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showPreview:)];
- [self.ablumImageView addGestureRecognizer:tap];
- self.ablumImageView.userInteractionEnabled = YES;
- self.ablumImageView.hidden = YES;
- // self.ablumImageView.backgroundColor = [UIColor redColor];
- self.ablumImageView.contentMode = UIViewContentModeScaleAspectFill;
- [self.ablumImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.mas_equalTo(self.takePhotoButton);
- make.left.mas_equalTo(20);
- make.width.height.mas_equalTo(60);
- // make.top.left.mas_equalTo(50);
- // make.width.height.mas_equalTo(300);
- }];
-
- UILongPressGestureRecognizer *ges = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressGes:)];
- // ges.numberOfTapsRequired = 1;
- ges.minimumPressDuration = 1;
- [self.takePhotoButton addGestureRecognizer:ges];
-
- self.timerLabel.layer.cornerRadius = 6;
- self.timerLabel.layer.masksToBounds = YES;
-
- [self.ai_fullView addTarget:self action:@selector(alFullViewAction:) forControlEvents:UIControlEventTouchUpInside];
-
- [self.view addSubview:self.stitchView];
- [self.stitchView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.mas_equalTo(self.view);
- make.centerX.mas_equalTo(self.view);
- make.width.mas_offset(200);
- make.height.mas_offset(200);
- }];
- }
- - (PCSAutherView *)authView {
- if (!_authView) {
- _authView = [[PCSAutherView alloc]init];
- _authView.hidden = YES;
- }
- return _authView;
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- self.panGesture.enabled = YES;
- if([self.currentOperationNode respondsToSelector:@selector(updateUI)])
- [self.currentOperationNode updateUI];
- }
- - (void)viewDidAppear:(BOOL)animated{
- [super viewDidAppear:animated];
- if(self.cameraPrepared){
- switch ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]) {
- case AVAuthorizationStatusAuthorized:
- [self startCaptureSession];
- [[PCSMotionManager shared] startAccelerometerUpdates];
- break;
- case AVAuthorizationStatusNotDetermined:{
- [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
- if(granted){
- [self startCaptureSession];
- [[PCSMotionManager shared] startAccelerometerUpdates];
- }
- else{
- [self showAuthorCamerIfNeed];
- [[NSNotificationCenter defaultCenter] postNotificationName:CameraNotificationNotPermission object:self];
- }
- }];
- break;
- }
- case AVAuthorizationStatusDenied:{
- [[NSNotificationCenter defaultCenter] postNotificationName:CameraNotificationNotPermission object:self];
- break;
- }
- case AVAuthorizationStatusRestricted:
- break;
- default:
- break;
- }
-
- switch ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]) {
- case AVAuthorizationStatusAuthorized:
- [self setupMicrophone];
- break;
- case AVAuthorizationStatusNotDetermined:{
- [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
- if(granted){
- [self setupMicrophone];
- }
- else{
- [self showAudioCamerIfNeed];
- [[NSNotificationCenter defaultCenter] postNotificationName:MicrophoneNotificationNotPermission object:self];
- }
- }];
- break;
- }
- case AVAuthorizationStatusDenied:{
- [[NSNotificationCenter defaultCenter] postNotificationName:MicrophoneNotificationNotPermission object:self];
- break;
- }
- case AVAuthorizationStatusRestricted:
- break;
- default:
- break;
- }
- }
- // [self showAuthorCamerIfNeed];
- }
- - (void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
- [self stopCaptureSession];
- [[PCSMotionManager shared] stopAccelerometerUpdates];
- }
- - (void)updateFlashButton {
- __block SDKFlashModeIndex flashModel = SDK_FLASH_MODE_AUTO;
- [[SDKParameters shared].items enumerateObjectsUsingBlock:^(SDKParametersItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.model == self.mode) {
- flashModel = obj.flashMode;
- }
- }];
- switch (flashModel) {
- case SDK_FLASH_MODE_AUTO:{
- self.outputSettings.flashMode = AVCaptureFlashModeAuto;
- [self.flashButton setImage:[UIImage sdkImageNamed:@"flash-auto-btn"] forState:UIControlStateNormal];
- break;
- }
- case SDK_FLASH_MODE_ON:{
- self.outputSettings.flashMode = AVCaptureFlashModeOn;
- [self.flashButton setImage:[UIImage sdkImageNamed:@"flash-btn"] forState:UIControlStateNormal];
- break;
- }
- case SDK_FLASH_MODE_OFF:{
- self.outputSettings.flashMode = AVCaptureFlashModeOff;
- [self.flashButton setImage:[UIImage sdkImageNamed:@"flash-disable-btn"] forState:UIControlStateNormal];
- break;
- }
- default:
- break;
- }
- }
- - (UIView *)stitchView {
- if (!_stitchView) {
- _stitchView = [[UIView alloc]init];
- [_stitchView addSubview:self.stitchImageView];
- [self.stitchImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(_stitchView);
- make.top.mas_equalTo(0);
- make.width.height.mas_equalTo(68);
- }];
- [_stitchView addSubview:self.stitchLabel];
- [self.stitchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.stitchImageView.mas_bottom).mas_offset(20);
- make.centerX.mas_equalTo(self.stitchImageView);
- }];
- _stitchView.hidden = YES;
- }
- return _stitchView;
- }
- - (UIImageView *)stitchImageView {
- if (!_stitchImageView) {
- _stitchImageView = [[UIImageView alloc]init];
- _stitchImageView.image = [UIImage loadNamed:@"loading"];
- }
- return _stitchImageView;
- }
- - (CABasicAnimation *)loadingAnimation {
- if (!_loadingAnimation) {
- _loadingAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
- _loadingAnimation.fromValue = [NSNumber numberWithFloat:0.f];
- _loadingAnimation.toValue = [NSNumber numberWithFloat: M_PI *2];
- _loadingAnimation.duration = 3;
- _loadingAnimation.autoreverses = NO;
- _loadingAnimation.fillMode = kCAFillModeForwards;
- _loadingAnimation.repeatCount = MAXFLOAT;
- }
- return _loadingAnimation;
- }
- - (UILabel *)aiPanPromtLabel {
- if (!_aiPanPromtLabel) {
- _aiPanPromtLabel = [[UILabel alloc]init];
- _aiPanPromtLabel.backgroundColor = [UIColor colorWithRed:33/255.0 green:33/255.0 blue:33/255.0 alpha:.2];
- _aiPanPromtLabel.layer.cornerRadius = 6;
- _aiPanPromtLabel.layer.masksToBounds = YES;
- _aiPanPromtLabel.textColor = [UIColor whiteColor];
- _aiPanPromtLabel.font = [UIFont systemFontOfSize:14];
- _aiPanPromtLabel.text = @"请保持手机与拍摄物平行,匀速拍摄";
- _aiPanPromtLabel.hidden = YES;
- _aiPanPromtLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _aiPanPromtLabel;
- }
- - (UILabel *)stitchLabel {
- if (!_stitchLabel) {
- _stitchLabel = [[UILabel alloc]init];
- _stitchLabel.text = @"正在拼接中,请稍等";
- _stitchLabel.font = [UIFont systemFontOfSize:12];
- _stitchLabel.textColor = [UIColor whiteColor];
- }
- return _stitchLabel;
- }
- #pragma mark - Private Method
- - (void)alFullViewAction:(UIButton *)button {
- if (self.mode == SDK_CAPTURE_MODE_PANORAMA) {
- OperationNodePanorama *pan = nil;
- if ([self.currentOperationNode isKindOfClass:[OperationNodePanorama class]]) {
- pan = self.currentOperationNode;
- pan.needHiddenDir = !pan.needHiddenDir;
- }
- self.panoramOrientationGuideView.hidden = pan.needHiddenDir;
- } else if (self.mode == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
- OperationNodeAIPanorama *aiPan = nil;
- if ([self.currentOperationNode isKindOfClass:[OperationNodeAIPanorama class]]) {
- aiPan = self.currentOperationNode;
- aiPan.needHiddenDir = !aiPan.needHiddenDir;
- }
- self.panoramOrientationGuideView.hidden = aiPan.needHiddenDir;
- }
- }
- - (void)showPreview:(UITapGestureRecognizer *)tap {
- if (self.ablumImageView.hidden) {
- return;
- }
- if(self.mode != SDK_CAPTURE_MODE_SINGLE) {
- PCSPreviewViewController *vc = [[PCSPreviewViewController alloc]init];
- vc.modalPresentationStyle = UIModalPresentationFullScreen;
- vc.model = self.resourceModel;
- vc.selectIndex = self.mode;
- vc.dataChangeBlock = ^{
- [self updateViewStatus];
- };
- [self presentViewController:vc animated:YES completion:nil];
- } else {
- PreviewSingleViewController* dst = [[PreviewSingleViewController alloc]init];
- dst.modalPresentationStyle = UIModalPresentationFullScreen;
- dst.singleModeNode = self.currentOperationNode;
- if (self.resourceModel.singleArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.singleArray.firstObject;
- dst.image = model.image;
- }
- [self presentViewController:dst animated:YES completion:nil];
- }
- }
- + (instancetype)initWithParams:(NSDictionary *)params complete:(PCSBaseVCCompleteBLock)complete {
- [self parser:params];
-
- UIStoryboard* sb = [UIStoryboard storyboardWithName:[PCSTools shared].mainStoryboardName bundle:[PCSTools sdkBundle]];
- PCSBaseViewController *vc = (PCSBaseViewController *)[sb instantiateViewControllerWithIdentifier:@"sample"];
- vc.completeBlock = complete;
- return vc;
- }
- #pragma mark - Config param
- + (void)parser: (NSDictionary*)params{
- SDKParameters* sdkParams = [SDKParameters shared];
- NSString* retainedMode = params[@"dataRetainedMode"];
- if(retainedMode != nil){
- if([retainedMode isEqual:@"retain"]){
- sdkParams.retainedMode = SDK_DATA_RETAINED_RETAIN;
- }
- else if([retainedMode isEqual:@"clear"]){
- sdkParams.retainedMode = SDK_DATA_RETAINED_CLEAR;
- }
- }
- NSArray* arr = params[@"cameraMode"];
- NSDictionary<NSString*, NSNumber*>* table = @{
- @"continuous": @(SDK_CAPTURE_MODE_CONTINUOUS),
- @"single" : @(SDK_CAPTURE_MODE_SINGLE),
- @"video" : @(SDK_CAPTURE_MODE_MOVIE),
- @"panorama" : @(SDK_CAPTURE_MODE_PANORAMA),
- @"panoramaPlus" : @(SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA)
- };
- NSMutableArray<NSNumber*>* modeIndiciesTable = [NSMutableArray array];
-
- NSMutableArray *mutabArray = [NSMutableArray array];
- [arr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if ([obj isKindOfClass:[NSDictionary class]]) {
- NSDictionary *dict = (NSDictionary *)obj;
- NSString *mode = dict[@"mode"];
- if (!table[mode]) {
- return;
- }
- if (idx == 0) {
- sdkParams.modeIndex = (SDKCaptureModeIndex)table[mode].integerValue;
- }
- [modeIndiciesTable addObject:table[mode]];
- SDKParametersItem *item = [[SDKParametersItem alloc]init];
- NSString* cameraPosition = dict[@"type"];
- item.model = (SDKCaptureModeIndex)table[mode].integerValue;
- if(cameraPosition != nil){
- if([cameraPosition isEqual:@"back"]){
- item.cameraPosition = SDK_CAMERA_PISITION_BACK;
- item.cameraPositionString = cameraPosition;
- }
- else if([cameraPosition isEqual:@"front"]){
- item.cameraPosition = SDK_CAMERA_PISITION_FRONT;
- item.cameraPositionString = cameraPosition;
- }
- }
-
-
- NSNumber* recTime = dict[@"recTime"];
- if(recTime != nil){
- item.limitRecordTime = [recTime integerValue];
- }
-
- item.keyFrame = dict[@"keyframe"];
- item.isRemake = [dict[@"isRemake"] boolValue];
- NSNumber *quantity = dict[@"quantity"];
- if (quantity) {
- item.quantity = [quantity integerValue];
- }
- NSNumber *quality = dict[@"quality"];
- if (quality) {
- item.quality = [quality floatValue];
- }
-
- NSString* flashMode = dict[@"flashMode"];
- if(flashMode != nil){
- item.flashModeString = flashMode;
- if([flashMode isEqualToString:@"auto"]){
- item.flashMode = SDK_FLASH_MODE_AUTO;
- }
- else if([flashMode isEqualToString:@"on"]){
- item.flashMode = SDK_FLASH_MODE_ON;
- }
- else if([flashMode isEqualToString:@"off"]){
- item.flashMode = SDK_FLASH_MODE_OFF;
- }
- }
-
- NSNumber* videoQualityNum = dict[@"videoQuality"];
- if(videoQualityNum != nil){
- NSInteger videoQuality = [videoQualityNum integerValue];
- if(videoQuality == 480){
- item.videoQuality = SDK_VIDEO_QUALITY_480;
- }
- else if(videoQuality == 720){
- item.videoQuality = SDK_VIDEO_QUALITY_720;
- }
- else if(videoQuality == 1080){
- item.videoQuality = SDK_VIDEO_QUALITY_1080;
- }
- else if(videoQuality == 2160){
- item.videoQuality = SDK_VIDEO_QUALITY_2160;
- }
- }
-
- NSNumber* showPreviewForPanorama = dict[@"showPreview"];
- if(showPreviewForPanorama != nil){
- item.showPreviewForPanorama = [showPreviewForPanorama boolValue];
- }
- [mutabArray addObject:item];
- }
- }];
- sdkParams.modeIndices = [modeIndiciesTable copy];
- [SDKParameters shared].items = mutabArray;
-
-
- }
- // 拍照界面
- - (void)showPreviewView: (BOOL)show{
- self.previewLayer.hidden = !show;
- self.takePhotoButton.enabled = show;
- self.resultImageView.hidden = show;
- self.backButton.hidden = !show;
- self.flashButton.hidden = !show;
- self.switchButton.hidden = !show;
-
- self.discardPhotoButton.hidden = show;
- self.savePhotoButton.hidden = show;
-
- }
- - (void)setup{
-
- // 打开数据库
- [[LenzDBManager shared] openSqlDataBase];
- [LenzDataManager creatDirectory];
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- [[PCSTools shared] cleanDiskCache];
- });
-
- _mode = SDK_CAPTURE_MODE_CONTINUOUS;
-
- _captureSession = [[AVCaptureSession alloc] init];
- _captureSession.sessionPreset = AVCaptureSessionPresetInputPriority;
-
- _movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
- // _movieFileOutput.maxRecordedDuration = CMTimeMake(self.parameters.limitRecordTime, 1);
-
- // setup video data output for panoramic
- _videoDataQueue = dispatch_queue_create("video data", DISPATCH_QUEUE_SERIAL);
- _videoDataOutput = [[AVCaptureVideoDataOutput alloc] init];
- _videoDataOutput.alwaysDiscardsLateVideoFrames = YES;
- _videoDataOutput.videoSettings = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA]
- forKey:(id)kCVPixelBufferPixelFormatTypeKey];
-
- _photoOutput = [[AVCapturePhotoOutput alloc] init];
- NSDictionary *setDic = @{AVVideoCodecKey:AVVideoCodecTypeJPEG};
- _outputSettings = [AVCapturePhotoSettings photoSettingsWithFormat:setDic];
- [_photoOutput setPhotoSettingsForSceneMonitoring:_outputSettings];
-
- _previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession];
- _previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
- NSMutableArray* nodesArr = [NSMutableArray array];
- NSMutableDictionary* nodesDic = [NSMutableDictionary dictionary];
- __block SDKCaptureModeIndex defaultModeIndex = SDK_CAPTURE_MODE_CONTINUOUS;
- NSDictionary<NSNumber*, Class>* nodeClsTable = @{
- @(SDK_CAPTURE_MODE_CONTINUOUS): [OperationNodeMultiple class],
- @(SDK_CAPTURE_MODE_SINGLE): [OperationNodeSingle class],
- @(SDK_CAPTURE_MODE_MOVIE): [OperationNodeMovie class],
- @(SDK_CAPTURE_MODE_PANORAMA): [OperationNodePanorama class],
- @(SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA): [OperationNodeAIPanorama class],
- };
-
- [[SDKParameters shared].modeIndices enumerateObjectsUsingBlock:^(NSNumber * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (idx == 0) {
- defaultModeIndex = (SDKCaptureModeIndex)obj.integerValue;
- }
- if(nodeClsTable[obj] != nil){
- if ([SDKParameters shared].retainedMode == SDK_DATA_RETAINED_RETAIN && obj.intValue == SDK_CAPTURE_MODE_SINGLE) {
- self.isContainSingleInReatinMode = YES;
- return;
- } else {
- id node = [[nodeClsTable[obj] alloc] initWithController: self];
- if ([node isKindOfClass:[OperationNodeVideoBase class]]) {
- OperationNodeVideoBase *base = (OperationNodeVideoBase *)node;
- [[SDKParameters shared].items enumerateObjectsUsingBlock:^(SDKParametersItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.model == self.mode) {
- base.recTime = obj.limitRecordTime;
- }
- }];
-
- }
- [nodesArr addObject: node];
- nodesDic[obj] = node;
- }
- }
- }];
- if ([SDKParameters shared].retainedMode == SDK_DATA_RETAINED_RETAIN && nodesArr.count == 0 && self.isContainSingleInReatinMode) {
- // reatin模式下只有single
- id node = [[OperationNodeSingle alloc] initWithController: self];
- [nodesArr addObject: node];
- nodesDic[@(SDK_CAPTURE_MODE_SINGLE)] = node;
- defaultModeIndex = SDK_CAPTURE_MODE_SINGLE;
- }
- [SDKParameters shared].modeIndex = defaultModeIndex;
- _operationNodesArray = [nodesArr copy];
- _operationNodes = [nodesDic copy];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationWillChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
- }
- - (void)startMotion {
-
-
- if (self.motionManager.deviceMotionAvailable) {
- __weak typeof(self)wearSelf = self;
-
- [self.motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMDeviceMotion * _Nullable motion, NSError * _Nullable error) {
- if (!self.startPitchX && !self.startRollY) {
- self.startPitchX = @(motion.attitude.pitch * 100);
- self.startRollY = @(motion.attitude.roll *100);
- }
-
- double x = self.startPitchX.doubleValue - motion.attitude.pitch * 100;
- double y = self.startRollY.doubleValue - motion.attitude.roll * 100;
- LenVideoStitchDirction dir = (LenVideoStitchDirction)wearSelf.panoramOrientationGuideView.selectedItemIndex;
- if (dir == LenVideoStitchDirctionLeft || dir == LenVideoStitchDirctionRight) {
- if (fabs(x) < 3) {
- // NSLog(@"~~~~~~~~~~水平");
- [wearSelf.panoramaGuideView updateArrowWith:PanoramaArrowDirCenter dir:dir];
- } else {
- if (x > 0) {
- // NSLog(@"~~~~~~~~~~向下");
- [wearSelf.panoramaGuideView updateArrowWith:PanoramaArrowDirDown dir:dir];
- } else {
- // NSLog(@"~~~~~~~~~~向上");
- [wearSelf.panoramaGuideView updateArrowWith:PanoramaArrowDirUp dir:dir];
- }
- }
- } else if (dir == LenVideoStitchDirctionUp || dir == LenVideoStitchDirctionDown) {
-
- if (fabs(y) < 3) {
- [wearSelf.panoramaGuideView updateArrowWith:PanoramaArrowDirCenter dir:dir];
- } else {
- if (y > 0) {
- [wearSelf.panoramaGuideView updateArrowWith:PanoramaArrowDirLeft dir:dir];
- } else {
- [wearSelf.panoramaGuideView updateArrowWith:PanoramaArrowDirRight dir:dir];
- }
- }
- }
-
- }];
- }
- }
- - (void)stopMotion {
- [self.motionManager stopDeviceMotionUpdates];
- self.startPitchX = nil;
- self.startRollY = nil;
- LenVideoStitchDirction dir = (LenVideoStitchDirction)self.panoramOrientationGuideView.selectedItemIndex;
- [self.panoramaGuideView updateArrowWith:PanoramaArrowDirCenter dir:dir];
- }
- #pragma mark - Lazy Load
- - (BaseViewTapGestureDelegate *)tapDelegate{
- if(_tapDelegate == nil){
- _tapDelegate = [[BaseViewTapGestureDelegate alloc] init];
- _tapDelegate.controller = self;
- }
-
- return _tapDelegate;
- }
- - (AVCaptureDevice *)currentCamera{
- __block AVCaptureDevice* camera = nil;
- [self.captureSession.inputs enumerateObjectsUsingBlock:^(__kindof AVCaptureInput * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- AVCaptureDeviceInput* inputDevice = obj;
- if([inputDevice.device hasMediaType:AVMediaTypeVideo]){
- camera = inputDevice.device;
- *stop = YES;
- }
- }];
- return self.currentCameraInput.device;
- }
- - (AVCaptureDeviceInput*)currentCameraInput{
- __block AVCaptureDeviceInput* cameraInput = nil;
- [self.captureSession.inputs enumerateObjectsUsingBlock:^(__kindof AVCaptureInput * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- AVCaptureDeviceInput* inputDevice = obj;
- if([inputDevice.device hasMediaType:AVMediaTypeVideo]){
- cameraInput = inputDevice;
- *stop = YES;
- }
- }];
- return cameraInput;
- }
- - (SDKParameters *)parameters{
- return [SDKParameters shared];
- }
- #pragma mark - Action
- - (void)focusOn: (CGPoint)point{
- CGPoint pt = [self.previewLayer captureDevicePointOfInterestForPoint:point];
- AVCaptureDevice* curr = self.currentCamera;
- [[CameraManager shared] focusOn:pt device:curr];
- [self showFocusViewAt:point];
- }
- - (void)showFocusViewAt: (CGPoint)point{
- [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(hideFocusView) object:nil];
- if(self.focusView == nil){
- UIImageView* imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 42, 42)];
- imgView.image = [UIImage sdkImageNamed:@"focus"];
- imgView.contentMode = UIViewContentModeScaleAspectFit;
- self.focusView = imgView;
- [self.view addSubview:self.focusView];
- }
- self.focusView.hidden = NO;
- CABasicAnimation* flash = [CABasicAnimation animationWithKeyPath:@"opacity"];
- flash.duration = 0.2;
- flash.fromValue = @(1);
- flash.toValue = @(0.1);
- flash.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- flash.autoreverses = YES;
- flash.repeatCount = 3;
- [self.focusView.layer removeAnimationForKey:@"flash"];
-
- [self.focusView.layer addAnimation:flash forKey:@"flash"];
- self.focusView.frame = CGRectMake(point.x - 21, point.y - 21, 42, 42);
- [self performSelector:@selector(hideFocusView) withObject:nil afterDelay:3];
- }
- - (void)hideFocusView{
- [self.focusView.layer removeAnimationForKey:@"flash"];
- self.focusView.hidden = YES;
- }
- - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
- if(error != nil){
- return;
- }
- if(self.mode == SDK_CAPTURE_MODE_SINGLE){
- [self dismissViewControllerAnimated:YES completion:^{}];
- }
- else{
- [self startCaptureSession];
- [self showPreviewView:YES];
- }
- }
- - (AVCaptureVideoOrientation)videoOrientation{
- UIDeviceOrientation curr = UIDeviceOrientationUnknown;
- return [self videoOrientation:&curr];
- }
- - (AVCaptureVideoOrientation)videoOrientation:(UIDeviceOrientation*)currentDeviceOrientation{
- return [[PCSMotionManager shared] videoOrientation:currentDeviceOrientation];;
- }
- - (void)takeStillPhoto:(AVCaptureVideoPreviewLayer*)previewLayer {
- if ([self showAuthorCamerIfNeed]) {
- return;
- }
- AVCaptureConnection *connection = [self.photoOutput connectionWithMediaType:AVMediaTypeVideo];
- if ([connection isVideoStabilizationSupported]) {
- connection.preferredVideoStabilizationMode = AVCaptureVideoStabilizationModeAuto;
- }
- if(connection == nil){
- // [self showAlertForAuthorization];
- return;
- }
- if (connection.supportsVideoOrientation) {
- // 根据motion设置照片方向
- AVCaptureVideoOrientation videoOrientation = [self videoOrientation];
- connection.videoMirrored = self.currentCamera == [CameraManager shared].front;
- connection.videoOrientation = videoOrientation;
- }
- // 创建 AVCapturePhotoSettings
- AVCapturePhotoSettings *photoSettings = [AVCapturePhotoSettings photoSettings];
- if ([self.photoOutput.availablePhotoCodecTypes containsObject:AVVideoCodecTypeJPEG]) {
- NSDictionary *format = @{AVVideoCodecKey: AVVideoCodecTypeJPEG};
- photoSettings = [AVCapturePhotoSettings photoSettingsWithFormat:format];
- // NSLog(@"-----:%ld",(long)self.currentCameraInput.device.position);
- if (self.currentCameraInput.device.position == SDK_CAMERA_PISITION_BACK) {
- photoSettings.flashMode = self.outputSettings.flashMode;
-
- }
- photoSettings.previewPhotoFormat = @{
- (NSString*)kCVPixelBufferPixelFormatTypeKey : photoSettings.availablePreviewPhotoPixelFormatTypes.firstObject,
- (NSString*)kCVPixelBufferWidthKey: @(160),
- (NSString*)kCVPixelBufferHeightKey: @(160),
- };
- }
- photoSettings.autoStillImageStabilizationEnabled = YES;
- // 拍照
-
- [self.photoOutput capturePhotoWithSettings:photoSettings delegate:self];
- }
- #pragma mark - Notification
- - (void)orientationWillChange: (NSNotification*)noti{
- NSLog(@"orientationWillChange");
- }
- - (void)willEnterForeground: (NSNotification*)noti{
- // if(self.broken){
- // [self.player play];
- // self.broken = NO;
- // }
- }
- //UIBackgroundTaskIdentifier _bgTaskToken;
- - (void)willEnterBackground: (NSNotification*)noti{
-
- if([self.currentOperationNode conformsToProtocol:@protocol(OperationNodeBackgroundProtocol)]){
- id<OperationNodeBackgroundProtocol> obj = self.currentOperationNode;
- if ([obj respondsToSelector:@selector(willEnterBackground:)]) {
- [obj willEnterBackground:noti];
- }
- }
- }
- - (void)orientationDidChange: (NSNotification*)noti{
- NSLog(@"orientationDidChange");
- if([self.currentOperationNode respondsToSelector:@selector(stop)])
- [self.currentOperationNode stop];
- }
- #pragma mark - alert
- - (void)showAlertForAuthorizationWithText: (NSString*)text{
- [QuitMultipleModeAlertViewController show:self title:@"" text:text leftBtnTitle:@"取消" rightBtnTitle:@"确认" withLeftButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) {
-
- [alertController dismissViewControllerAnimated:YES completion:^{
- // [self dismissViewControllerAnimated:YES completion:^{
- //
- // }];
- }];
- } rightButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) {
- [alertController dismissViewControllerAnimated:YES completion:^{
- NSURL* url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
- if(url != nil){
- [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
- // NSLog(succ)
- }];
- }
-
- }];
- }];
- }
- - (void)showAlertForAuthorization{
- [self showAlertForAuthorizationWithText:@"请在系统设置里打开摄像机访问权限后重试"];
- }
- - (BOOL)showAuthBoth {
- __block BOOL showVideoAlert = NO;
- AVAuthorizationStatus staus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
- switch (staus) {
- case AVAuthorizationStatusDenied:{
- showVideoAlert = YES;
- break;
- }
- default:
- showVideoAlert = NO;
- break;
- }
-
- __block BOOL showAlert = NO;
-
- switch ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]) {
- case AVAuthorizationStatusDenied:{
- showAlert = YES;
- break;
- }
- default:
- showAlert = NO;
- break;
- }
- if (showVideoAlert && showAlert) {
- [self.authView showAutherWith:PCSAuthPhoneAndMir];
- return YES;
- }
- return NO;
-
- }
-
- - (BOOL)showAuthorCamerIfNeed {
- __block BOOL showAlert = NO;
- AVAuthorizationStatus staus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
- switch (staus) {
- case AVAuthorizationStatusDenied:{
- [self.authView showAutherWith:PCSAuthPhone];
- // [self showAlertForAuthorizationWithText:@"请在系统设置里打开摄像机访问权限后重试"];
- showAlert = YES;
- break;
- }
- default:
- showAlert = NO;
- break;
- }
- return showAlert;
- }
-
- - (BOOL)showAudioCamerIfNeed {
- __block BOOL showAlert = NO;
-
- switch ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]) {
- case AVAuthorizationStatusDenied:{
- [self.authView showAutherWith:PCSAuthMir];
- // [self showAlertForAuthorizationWithText:@"请在系统设置里打开麦克风访问权限后重试"];
- showAlert = YES;
- break;
- }
- default:
- showAlert = NO;
- break;
- }
-
- return showAlert;
- }
- #pragma mark - Capture
- - (void)takeStillPhoto{
- [self takeStillPhoto:self.previewLayer];
- }
- - (BOOL)startRecording{
- if (![self showAuthBoth]) {
- if ([self showAuthorCamerIfNeed] || [self showAudioCamerIfNeed]) {
- return NO;
- }
- } else {
- return NO;
- }
-
- if(self.movieFileOutput.isRecording){
- return NO;
- }
-
-
- [[SDKParameters shared].items enumerateObjectsUsingBlock:^(SDKParametersItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.model == self.mode) {
- self.movieFileOutput.maxRecordedDuration = CMTimeMake(obj.limitRecordTime, 1);
- }
- }];
-
- [self.recordTimer invalidate];
- dispatch_async(dispatch_get_main_queue(), ^{
- self.recordTimer = [NSTimer timerWithTimeInterval:0.2 repeats:YES block:^(NSTimer * _Nonnull timer) {
- [self.timerLabel updateWith:self.movieFileOutput.recordedDuration.value / self.movieFileOutput.recordedDuration.timescale];
- }];
- [[NSRunLoop currentRunLoop] addTimer:self.recordTimer forMode:NSDefaultRunLoopMode];
- });
-
- NSURL* tmpMovieFileUrl = [NSURL fileURLWithPath:[LenzDataManager moviePath]];
- AVCaptureConnection* connection = [self.movieFileOutput connectionWithMediaType:AVMediaTypeVideo];
- if ([connection isVideoStabilizationSupported]) {
- connection.preferredVideoStabilizationMode = AVCaptureVideoStabilizationModeAuto;
- }
- if(connection == nil){
- // [self showAlertForAuthorization];
- return NO;
- }
-
- UIDeviceOrientation currOrientation = UIDeviceOrientationUnknown;
- connection.videoOrientation = [self videoOrientation:&currOrientation];
- AVCaptureDevice* camera = self.currentCamera;
- [camera lockForConfiguration:nil];
- if ([camera hasFlash] && self.currentCameraInput.device.position == SDK_CAMERA_PISITION_BACK) {
- if (self.outputSettings.flashMode == AVCaptureFlashModeOff) {
- [camera setTorchMode:AVCaptureTorchModeOff];
- } else if (self.outputSettings.flashMode == AVCaptureFlashModeOn) {
- [camera setTorchMode:AVCaptureTorchModeOn];
- } else {
- [camera setTorchMode:AVCaptureTorchModeAuto];
- }
- }
- [camera unlockForConfiguration];
- self.thumbnailOritaionByCurrentVideoOrientation = [UIImage imageOrientationByDeviceOrientation:currOrientation isFrontCamera:camera == [CameraManager shared].front];
- [self.movieFileOutput startRecordingToOutputFileURL: tmpMovieFileUrl recordingDelegate:self];
- return YES;
- }
- - (void)stopRecording{
- [self.movieFileOutput stopRecording];
- AVCaptureDevice* camera = self.currentCamera;
- [camera lockForConfiguration:nil];
- if ([camera hasFlash] && self.currentCameraInput.device.position == SDK_CAMERA_PISITION_BACK) {
- [camera setTorchMode:AVCaptureTorchModeOff];
- }
- [camera unlockForConfiguration];
- [self.recordTimer invalidate];
- self.recordTimer = nil;
- }
- - (BOOL)startVideoDataOutputing{
-
- [[NSNotificationCenter defaultCenter] removeObserver:self name:PCS_NotificationNameOrientationDidChange object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:PCS_NotificationNameOrientationDidChange object:nil];
- UIDeviceOrientation deviceOrientation = UIDeviceOrientationPortrait;
- AVCaptureVideoOrientation orientation = [self videoOrientation:&deviceOrientation];
- CGFloat degree = 0;
- AVCaptureDevice* camera = self.currentCamera;
-
- CameraManager* cameraMgr = [CameraManager shared];
- BOOL isFront = camera == cameraMgr.front;
- BOOL isLandscape = NO;
- // 前摄像头需要镜像一下
- switch (deviceOrientation) {
- case UIDeviceOrientationPortrait:
- degree = 0;
- break;
- case UIDeviceOrientationLandscapeRight:
- degree = isFront ? 90 : -90;
- isLandscape = YES;
- break;
- case UIDeviceOrientationPortraitUpsideDown:
- degree = 180;
- break;
- case UIDeviceOrientationLandscapeLeft:
- degree = isFront ? -90 : 90;
- isLandscape = YES;
- break;
- default:
- break;
- }
-
- __block BOOL ret = NO;
- dispatch_sync(self.videoDataQueue, ^{
- if(self.videoDataOutput.sampleBufferDelegate != nil){
- return;
- }
- if([self configureVideoWritter]){
- AVCaptureConnection *connection = [self.videoDataOutput connectionWithMediaType:AVMediaTypeVideo];
- if ([connection isVideoStabilizationSupported]) {
- connection.preferredVideoStabilizationMode = AVCaptureVideoStabilizationModeAuto;
- }
- if(connection == nil){
- // [self showAlertForAuthorization];
- return;
- }
- [connection setVideoOrientation:orientation];
- CGFloat aspect = isFront ? cameraMgr.frontAspect : cameraMgr.backAspect;
- aspect = isLandscape ? 1.0 / aspect : aspect;
- [self.videoDataOutput setSampleBufferDelegate:self queue:self.videoDataQueue];
- ret = YES;
- }
- });
-
- return ret;
- }
- - (PanoramaGuideView *)panoramaGuideView{
- if (_panoramaGuideView == nil) {
- _panoramaGuideView = [[PanoramaGuideView alloc]init];
- _panoramaGuideView.hidden = YES;
- }
- return _panoramaGuideView;;
- }
- - (void)stopVideoDataOutputing{
- [self.motionTimer invalidate];
- self.motionTimer = nil;
- [[NSNotificationCenter defaultCenter] removeObserver:self name:PCS_NotificationNameOrientationDidChange object:nil];
- dispatch_async(self.videoDataQueue, ^{
- [self.videoDataOutput setSampleBufferDelegate:nil queue:nil];
- [Renderer shared].cameraPass.texture = nil;
- });
- [self stopMotion];
- [self.panoramaGuideView showImageWith:nil dir:self.panoramOrientationGuideView.selectedItemIndex];
- [self updateViewStatus];
- }
- - (void)updateViewStatusWhenStitchSave:(BOOL)isSaveIng {
- dispatch_async(dispatch_get_main_queue(), ^{
- self.stitchView.hidden = !isSaveIng;
- if (self.stitchView.hidden) {
- [self.stitchImageView.layer removeAnimationForKey:@"loadingAnimation"];
- } else {
- [self.stitchImageView.layer addAnimation:self.loadingAnimation forKey:@"loadingAnimation"];
- }
- self.flashButton.hidden = isSaveIng;
- if (self.mode == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
- self.panoramOrientationGuideView.hidden = YES;
- self.ai_fullView.hidden = YES;
- self.panoramaGuideView.hidden = YES;
- } else {
- self.panoramOrientationGuideView.hidden = isSaveIng;
- // self.ai_fullView.hidden = isSaveIng;
- self.ai_fullView.hidden = YES;
- self.panoramaGuideView.hidden = isSaveIng;
- }
- self.modeList.hidden = isSaveIng;
- self.savePhotoButton.hidden = isSaveIng;
- self.takePhotoButton.hidden = isSaveIng;
- // self.switchButton.hidden = isSaveIng;
- self.discardPhotoButton.hidden = isSaveIng;
- self.backButton.hidden = !isSaveIng;
- self.ablumImageView.hidden = isSaveIng;
- // self.timerLabel.hidden = isSaveIng;
-
- });
- }
- - (void)updateViewStatusWhenStitchFail {
- dispatch_async(dispatch_get_main_queue(), ^{
- self.stitchView.hidden = YES;
- self.flashButton.hidden = NO;
- self.modeList.hidden = NO;
- self.savePhotoButton.hidden = NO;
- self.takePhotoButton.hidden = NO;
- if (self.mode == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
- self.ai_fullView.hidden = YES;
- self.panoramOrientationGuideView.hidden = YES;
- self.panoramaGuideView.hidden = YES;
- } else {
- // self.ai_fullView.hidden = NO;
- self.ai_fullView.hidden = YES;
- self.panoramOrientationGuideView.hidden = NO;
- self.panoramaGuideView.hidden = NO;
- }
- // self.switchButton.hidden = isSaveIng;
- self.discardPhotoButton.hidden = NO;
- self.backButton.hidden = YES;
- self.ablumImageView.hidden = NO;
- [self.takePhotoButton setImage:[UIImage loadNamed:@"take-photo-btn"] forState:UIControlStateNormal];
- // self.timerLabel.hidden = isSaveIng;
-
- });
- }
- - (BOOL)getStitchBigImageIfNeed {
- BOOL isSuccess = NO;
- NSString *s = [LenStitcher getCurrentPanoramaShow];
- if (s.length) {
- isSuccess = YES;
- }
- return isSuccess;
- }
- - (BOOL)configureVideoWritter{
- // setup asset writter for the video data output
- NSURL* tmpMovieFileUrl = [NSURL fileURLWithPath:[[PCSTools shared].tmpPath stringByAppendingPathComponent:@"video-data-tmp-file.mov"] isDirectory:NO];
- NSError* err = nil;
- [[NSFileManager defaultManager] removeItemAtURL:tmpMovieFileUrl error:nil];
- self.videoWriter = [[AVAssetWriter alloc] initWithURL:tmpMovieFileUrl fileType:AVFileTypeQuickTimeMovie error:&err];
- if(err != nil){
- NSLog(@"%@", err);
- self.videoWriter = nil;
- return NO;
- }
-
- [[SDKParameters shared].items enumerateObjectsUsingBlock:^(SDKParametersItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.model == self.mode) {
- NSDictionary* settings = [NSDictionary dictionaryWithObjectsAndKeys:
- AVVideoCodecTypeH264, AVVideoCodecKey,
- [NSNumber numberWithInteger: obj.resolution.width], AVVideoWidthKey,
- [NSNumber numberWithInteger: obj.resolution.height], AVVideoHeightKey,
- nil];
- self.videoWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:settings];
- }
- }];
-
- self.videoWriterInput.expectsMediaDataInRealTime = YES;
-
- [self.videoWriter addInput:self.videoWriterInput];
-
- return YES;
- }
- - (void)prepareCamera{
- if (self.cameraPrepared) {
- return;
- }
- __block AVCaptureDevice* device = nil;
- [[SDKParameters shared].items enumerateObjectsUsingBlock:^(SDKParametersItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.model == self.mode) {
- device = obj.cameraPosition == SDK_CAMERA_PISITION_BACK ? [CameraManager shared].back : [CameraManager shared].front;
- }
- }];
-
- if (device == nil) {
- self.cameraPrepared = false;
- return;
- }
-
- NSError* error;
- AVCaptureDeviceInput* input = [[AVCaptureDeviceInput alloc] initWithDevice:device error:&error];
- if(error != nil){
- self.cameraPrepared = false;
- return;
- }
- [self.captureSession beginConfiguration];
- if([self.captureSession canAddInput:input]){
- [self.captureSession addInput:input];
- }
- else{
- return;
- }
-
- self.previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.captureSession];
- self.previewLayer.frame = self.view.layer.bounds;
- self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
- [self.view.layer insertSublayer:self.previewLayer atIndex:0u];
-
- if([self.captureSession canAddOutput:self.photoOutput]){
- [self.captureSession addOutput:self.photoOutput];
- }
-
- if([self.captureSession canAddOutput:self.movieFileOutput]){
- [self.captureSession addOutput:self.movieFileOutput];
- }
-
- [self.captureSession commitConfiguration];
- self.cameraPrepared = YES;
- [[SDKParameters shared].items enumerateObjectsUsingBlock:^(SDKParametersItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.model == self.mode) {
- [[CameraManager shared] setResolutionFor:AVCaptureDevicePositionBack with:obj.resolution.height];
- [[CameraManager shared] setResolutionFor:AVCaptureDevicePositionFront with:obj.resolution.height];
- }
- }];
-
- [self updatePreViewLayer];
- }
- #pragma mark - Gesture
- - (void)tapGestureHandler: (UITapGestureRecognizer*)gesture{
- switch(gesture.state){
- case UIGestureRecognizerStateBegan:{
- break;
- }
- case UIGestureRecognizerStateChanged:{
- break;
- }
- case UIGestureRecognizerStateEnded:{
- CGPoint pt = [gesture locationInView:self.view];
- [self focusOn:pt];
- break;
- }
- case UIGestureRecognizerStateCancelled:{
- break;
- }
- default:
- break;
- }
- }
- - (void)panGestureHandler: (UIPanGestureRecognizer*)gesture{
- switch(gesture.state){
- case UIGestureRecognizerStateBegan:{
- break;
- }
- case UIGestureRecognizerStateChanged:{
- if(self.flag){
- return;
- }
- self.flag = YES;
- CGPoint translation = [gesture translationInView:self.view];
- [self.modeList updateIndexByTanslation:translation];
- break;
- }
- case UIGestureRecognizerStateEnded:{
- self.flag = NO;
- break;
- }
- case UIGestureRecognizerStateCancelled:{
- self.flag = NO;
- break;
- }
- default:
- self.flag = NO;
- break;
- }
- }
- #pragma mark - orientation
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations{
- return UIInterfaceOrientationMaskPortrait;
- }
- - (void)updateUIByMode{
- self.albumButton.hidden = YES;
- self.numberOfImagesLabel.hidden = YES;
- self.modeLabel.text = self.currentOperationNode.modeTitleString;
- // self.ai_fullView.hidden = !(self.mode == SDK_CAPTURE_MODE_PANORAMA);
- self.ai_fullView.hidden = YES;
- self.panGesture.enabled = YES;
-
- // self.controller.savePhotoButton.hidden = !self.hasCache;
- // self.controller.discardPhotoButton.hidden = !self.hasCache;
- //
- // self.controller.albumButton.hidden = !self.hasCache;
- // self.controller.backButton.hidden = self.hasCache;
-
-
- if([self.currentOperationNode respondsToSelector:@selector(updateUI)]){
- [self.currentOperationNode updateUI];
- }
- [self updatePreViewLayer];
- }
- - (void)updatePreViewLayer {
- CGFloat width = [UIScreen mainScreen].bounds.size.width;
- CGFloat height = [UIScreen mainScreen].bounds.size.height;
- switch (self.mode) {
- case SDK_CAPTURE_MODE_CONTINUOUS: {
- self.switchButton.hidden = NO;
- self.panoramaGuideView.hidden = YES;
- self.panoramOrientationGuideView.hidden = YES;
- self.previewLayer.frame = CGRectMake(0, (height - width*4/3)/2, width, width*4/3);
- [self showAuthorCamerIfNeed];
- }
-
- break;
- case SDK_CAPTURE_MODE_SINGLE: {
- self.switchButton.hidden = NO;
- self.panoramaGuideView.hidden = YES;
- self.panoramOrientationGuideView.hidden = YES;
- self.previewLayer.frame = CGRectMake(0, (height - width*4/3)/2, width, width*4/3);
- [self showAuthorCamerIfNeed];
- }
-
- break;
- case SDK_CAPTURE_MODE_MOVIE: {
- self.switchButton.hidden = NO;
- self.panoramaGuideView.hidden = YES;
- self.panoramOrientationGuideView.hidden = YES;
- self.previewLayer.frame = self.view.layer.bounds;
- if (![self showAuthBoth]) {
- [self showAudioCamerIfNeed];
- }
- }
-
- break;
- case SDK_CAPTURE_MODE_PANORAMA: {
- self.switchButton.hidden = YES;
- self.panoramaGuideView.hidden = NO;
- self.panoramOrientationGuideView.hidden = NO;
- self.previewLayer.frame = self.view.layer.bounds;
- [self showAuthorCamerIfNeed];
- }
-
- break;
- case SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA: {
- self.switchButton.hidden = YES;
- self.panoramaGuideView.hidden = YES;
- self.panoramOrientationGuideView.hidden = YES;
- self.previewLayer.frame = self.view.layer.bounds;
- [self showAuthorCamerIfNeed];
- }
-
- break;
-
- default:
- break;
- }
- }
- - (void)modeWillChange: (NSUInteger)newIndex oldIndex: (NSUInteger)oldIndex{
- if(newIndex >= INT_MAX){
- return;
- }
-
- [self.currentOperationNode willQuitOnCompletion:^() {}];
- }
- - (void)modeDidChange: (NSUInteger)newIndex oldIndex: (NSUInteger)oldIndex{
-
- if(newIndex >= INT_MAX){
- return;
- }
-
- // self.modeList.userInteractionEnabled = NO;
- // [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]
- if(self.effectView.superview != nil){
- // self.effectView.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
- [UIView animateWithDuration:0.5 animations:^{
- self.effectView.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
- }];
- }
- // dispatch_async(dispatch_get_global_queue(0, 0), ^{
- if(newIndex != SDK_CAPTURE_MODE_MOVIE){
- [[SDKParameters shared].items enumerateObjectsUsingBlock:^(SDKParametersItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.model == self.mode) {
- [[CameraManager shared] setResolutionFor:AVCaptureDevicePositionBack with:obj.resolution.height];
- [[CameraManager shared] setResolutionFor:AVCaptureDevicePositionFront with:obj.resolution.height];
- }
- }];
-
- }
- else{
- [[SDKParameters shared].items enumerateObjectsUsingBlock:^(SDKParametersItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.model == self.mode) {
- [[CameraManager shared] setResolutionFor:AVCaptureDevicePositionBack with:obj.videoResolution.height];
- [[CameraManager shared] setResolutionFor:AVCaptureDevicePositionFront with:obj.videoResolution.height];
- }
- }];
- }
-
-
- // dispatch_sync(dispatch_get_main_queue(), ^{
- // self.modeList.userInteractionEnabled = YES;
- self.effectView.effect = nil;
- // });
- // });
- [self updateUIByMode];
- [self switchDevicePositionBack];
- [self updateNumberLabel];
- }
- - (void)updateCaptureSessionWith:(NSInteger)oldIndex {
- PhotographModeEnum oldModeEnum = (PhotographModeEnum)(oldIndex);
- if((self.mode == SDK_CAPTURE_MODE_PANORAMA || self.mode == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA)
- && oldModeEnum != SDK_CAPTURE_MODE_PANORAMA
- && oldModeEnum != SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA){
-
- if([self.captureSession canAddOutput:self.videoDataOutput]){
- [self.captureSession addOutput:self.videoDataOutput];
- [self.captureSession removeOutput:self.movieFileOutput];
- }
- }
- else if((self.mode == SDK_CAPTURE_MODE_MOVIE)
- && (oldModeEnum == SDK_CAPTURE_MODE_PANORAMA
- || oldModeEnum == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA)){
-
- if([self.captureSession canAddOutput:self.movieFileOutput]){
- [self.captureSession addOutput:self.movieFileOutput];
- [self.captureSession removeOutput:self.videoDataOutput];
- }
- }
- }
- - (void)setupMicrophone{
- NSError* audioError = nil;
- AVCaptureDevice* audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
- AVCaptureDeviceInput* audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&audioError];
- if(audioError == nil){
- AVCaptureAudioDataOutput* audioOutput = [[AVCaptureAudioDataOutput alloc] init];
- [audioOutput setSampleBufferDelegate:self queue:dispatch_get_global_queue(0, 0)];
-
- if([self.captureSession canAddInput:audioInput]){
- [self.captureSession addInput:audioInput];
- }
- if([self.captureSession canAddOutput:audioOutput]){
- [self.captureSession addOutput:audioOutput];
- }
- }
- }
- - (UIStatusBarStyle)preferredStatusBarStyle{
- return UIStatusBarStyleLightContent;
- }
- #pragma mark 方向调用的代理
- - (void)panoramaOrientationViewslt:(PanoramaOrientationViewDirectionEnum)direction{
- // NSLog(@"方向%ld",direction);
- self.panoramaGuideView.hidden = NO;
- // self.ai_fullView.hidden = NO;
-
- // [LenStitcher videoResetPath];
- [UIView animateWithDuration:0.25 animations:^{
- [self.panoramaGuideView mas_remakeConstraints:^(MASConstraintMaker *make) {
- switch (direction) {
- case PanoramaOrientationViewLeft:
- case PanoramaOrientationViewRight:
- {
- make.left.right.offset(0);
- make.centerY.mas_equalTo(self.view);
- make.height.mas_equalTo(PanoramaGuideViewWOrH);
- }
- break;
- case PanoramaOrientationViewUp:
- case PanoramaOrientationViewDown:
- {
- make.centerX.mas_equalTo(self.view);
- make.width.mas_equalTo(PanoramaGuideViewWOrH);
- make.bottom.mas_equalTo(self.panoramOrientationGuideView.mas_top).offset(-25);
- make.top.mas_equalTo(self.timerLabel.mas_bottom).offset(15);
- }
- break;
- case PanoramaOrientationViewAny: {
- self.panoramaGuideView.hidden = YES;
- // self.ai_fullView.hidden = YES;
- }
- break;
- default:
- break;
- }
- }];
- if (self.mode != SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
- [self.panoramaGuideView setNeedsLayout];
- [self.panoramaGuideView layoutIfNeeded];
- }
- } completion:^(BOOL finished) {
- [self.panoramaGuideView direction:direction];
- }];
- }
- - (void)stopAllSensors{
- [self.captureSession stopRunning];
- [[PCSMotionManager shared] stopAccelerometerUpdates];
- }
- #pragma mark - session
- - (void)turnTorchOff{
- AVCaptureDevice* currentDevice = self.currentCamera;
- if(currentDevice == nil || !currentDevice.hasTorch){
- return;
- }
- NSError* error;
- if(error == nil){
- [currentDevice lockForConfiguration:&error];
- currentDevice.torchMode = AVCaptureTorchModeOff;
- [currentDevice unlockForConfiguration];
- }
- }
- - (void)stopCaptureSession{
- [self turnTorchOff];
-
- if (self.captureSession.isRunning) {
- [self.captureSession stopRunning];
- }
- }
- - (void)startCaptureSession{
- if (!self.cameraPrepared) {
- [self prepareCamera];
- }
-
- if (self.cameraPrepared && (!self.captureSession.isRunning)) {
- [self.captureSession startRunning];
- }
- }
- #pragma mark - Btn call back
- -(IBAction)switchCameraTapped:(id)sender
- {
- if(self.captureSession == nil){
- return;
- }
-
- AVCaptureDeviceInput* currInput = self.currentCameraInput;
- if(currInput == nil){
- return;
- }
- AVCaptureDevice* currentDevice = currInput.device;
- AVCaptureDevice *newCamera = nil;
- if(currentDevice.position == AVCaptureDevicePositionBack){
- newCamera = [CameraManager shared].front;
- }
- else if(currentDevice.position == AVCaptureDevicePositionFront){
- newCamera = [CameraManager shared].back;
- }
- else{
- return;
- }
-
- [self.captureSession beginConfiguration];
- if(currentDevice.hasTorch){
- NSError* error;
- [currentDevice lockForConfiguration:&error];
- currentDevice.torchMode = AVCaptureTorchModeOff;
- [currentDevice unlockForConfiguration];
- }
- [self.captureSession removeInput:currInput];
- self.flashButton.hidden = !newCamera.hasFlash;
- NSError *err = nil;
- AVCaptureDeviceInput *newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:newCamera error:&err];
- if(newVideoInput == nil || err != nil){
- NSLog(@"Error creating capture device input: %@", err.localizedDescription);
- }
- else if([self.captureSession canAddInput:newVideoInput]){
- [self.captureSession addInput:newVideoInput];
- }
- [self.captureSession commitConfiguration];
- }
- - (void)switchDevicePositionBack {
- if(self.captureSession == nil ||
- (self.mode != SDK_CAPTURE_MODE_PANORAMA && self.mode != SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA)){
- return;
- }
-
- AVCaptureDeviceInput* currInput = self.currentCameraInput;
- if(currInput == nil){
- return;
- }
- AVCaptureDevice* currentDevice = currInput.device;
- AVCaptureDevice *newCamera = nil;
- if(currentDevice.position == AVCaptureDevicePositionBack){
- return;
- }
- if(currentDevice.position == AVCaptureDevicePositionFront){
- newCamera = [CameraManager shared].back;
- }
-
- [self.captureSession beginConfiguration];
- if(currentDevice.hasTorch){
- NSError* error;
- [currentDevice lockForConfiguration:&error];
- currentDevice.torchMode = AVCaptureTorchModeOff;
- [currentDevice unlockForConfiguration];
- }
- [self.captureSession removeInput:currInput];
- NSError *err = nil;
- AVCaptureDeviceInput *newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:newCamera error:&err];
- if(newVideoInput == nil || err != nil){
- NSLog(@"Error creating capture device input: %@", err.localizedDescription);
- } else if([self.captureSession canAddInput:newVideoInput]){
- [self.captureSession addInput:newVideoInput];
- }
- [self.captureSession commitConfiguration];
- }
- - (void)takePhotoButtonTouchUpInside:(id)sender{
- self.takePhotoButton.enabled = NO;
- if (self.outputSettings.flashMode == AVCaptureFlashModeOn && (self.mode == SDK_CAPTURE_MODE_SINGLE || self.mode == SDK_CAPTURE_MODE_CONTINUOUS || self.mode == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA)) {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- self.takePhotoButton.enabled = YES;
- });
- } else {
- dispatch_async(dispatch_get_main_queue(), ^{
- self.takePhotoButton.enabled = YES;
- });
- }
- if(![self.currentOperationNode respondsToSelector:@selector(enable)] || self.currentOperationNode.enable){
-
- if (self.mode == SDK_CAPTURE_MODE_MOVIE) {
- __block SDKParametersItem *videoItems = nil;
- [[SDKParameters shared].items enumerateObjectsUsingBlock:^(SDKParametersItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.model == self.mode) {
- videoItems = obj;
- }
- }];
- if (videoItems.quantity > 0 && self.resourceModel.movieArray.count >= videoItems.quantity) {
- [SVProgressHUD showImage:[UIImage imageNamed:@""] status:[NSString stringWithFormat:@"最多录制%ld条视频", videoItems.quantity]];
- return;
- }
- }
-
- if (self.mode == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
-
- OperationNodeAIPanorama *aiPan = nil;
- if ([self.currentOperationNode isKindOfClass:[OperationNodeAIPanorama class]]) {
- aiPan = self.currentOperationNode;
- if (!aiPan.isRecording) {
- aiPan.AIType = OperationAITypeTap;
- }
- }
- }
-
- [self.currentOperationNode takePhotoButtonTouched];
- if (self.mode == SDK_CAPTURE_MODE_PANORAMA && !self.isVideoStitchStopedWhenRecording) {
- [LenStitcher videoResetPath];
- LenzResourceItemModel *itemModel = [[LenzResourceItemModel alloc]init];
- [self.resourceModel.panoramArray addObject:itemModel];
- [self startMotion];
- }
- }
- }
- - (void)longPressGes:(UILongPressGestureRecognizer *)ges {
- switch (ges.state) {
- case UIGestureRecognizerStateBegan:
- {
- if (self.mode == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
- OperationNodeAIPanorama *aiPan = nil;
- if ([self.currentOperationNode isKindOfClass:[OperationNodeAIPanorama class]]) {
- // self.videoStitchSemaphore = dispatch_semaphore_create(1);
- [LenStitcher videoResetPath];
- LenzResourceItemModel *itemModel = [[LenzResourceItemModel alloc]init];
- [self.resourceModel.aiPanoramArray addObject:itemModel];
- [self startMotion];
- aiPan = self.currentOperationNode;
- // self.touchTime = 0;
- aiPan.AIType = OperationAITypeLongPress;
- [self.currentOperationNode takePhotoButtonTouched];
- }
- }
- }
-
- break;
- case UIGestureRecognizerStateEnded:
-
- break;
- default:
- break;
- }
- }
- - (void)takePhotoButtonTouchDownInside:(id)sender{
- }
- - (void)flashButtonTouchUpInside:(id)sender{
- AVCaptureDevice* currentDevice = self.currentCamera;
- if(currentDevice == nil || !currentDevice.hasFlash){
- return;
- }
- NSError* error = nil;
- [currentDevice lockForConfiguration:&error];
- if(error != nil){
- return;
- }
- if(self.outputSettings.flashMode == AVCaptureFlashModeOn){
- self.outputSettings.flashMode = AVCaptureFlashModeAuto;
- [self.flashButton setImage:[UIImage sdkImageNamed:@"flash-auto-btn"] forState:UIControlStateNormal];
- }
- else if(self.outputSettings.flashMode == AVCaptureFlashModeAuto){
- self.outputSettings.flashMode = AVCaptureFlashModeOff;
- [self.flashButton setImage:[UIImage sdkImageNamed:@"flash-disable-btn"] forState:UIControlStateNormal];
- }
- else{
- self.outputSettings.flashMode = AVCaptureFlashModeOn;
- [self.flashButton setImage:[UIImage sdkImageNamed:@"flash-btn"] forState:UIControlStateNormal];
- }
- [currentDevice unlockForConfiguration];
- }
- - (void)backButtonTouchUpInside:(id)sender{
-
- if (!self.stitchView.hidden) {
-
- [QuitMultipleModeAlertViewController show:self title:@"确认提醒" text:@"图片拼接中,返回会清空正在拼接的数据" leftBtnTitle:@"取消" rightBtnTitle:@"确定" withLeftButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) {
-
- [alertController dismissViewControllerAnimated:NO completion:^{}];
- } rightButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) {
- [self updateViewStatusWhenStitchSave:NO];
- [alertController dismissViewControllerAnimated:NO completion:^{
- // [self dismissViewControllerAnimated:YES completion:^{}];
- }];
- }];
- } else {
- [self dismissViewControllerAnimated:YES completion:^{}];
- }
-
- }
- - (void)makeResData:(NSMutableArray <LenzResourceItemModel *> *)array {
- [array enumerateObjectsUsingBlock:^(LenzResourceItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
-
- }];
- }
- - (void)savePhotoButtonTouchUpInside:(id)sender{
- //待优化
- NSMutableArray *res = [NSMutableArray array];
- __block NSInteger idIndex = 1;
- [self.resourceModel.singleArray enumerateObjectsUsingBlock:^(LenzResourceItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- idIndex += idx;
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- dict[@"id"] = [NSString stringWithFormat:@"%ld", idIndex];
- dict[@"path"] = obj.path;
- dict[@"cameraMode"] = obj.cameraMode;
- dict[@"cameraType"] = obj.cameraType;
- dict[@"isRemake"] = @(obj.isRemake);
- [res addObject:dict];
- }];
-
- [self.resourceModel.continousArray enumerateObjectsUsingBlock:^(LenzResourceItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- idIndex += idx;
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- dict[@"id"] = [NSString stringWithFormat:@"%ld", idIndex];
- dict[@"path"] = obj.path;
- dict[@"cameraMode"] = obj.cameraMode;
- dict[@"cameraType"] = obj.cameraType;
- dict[@"isRemake"] = @(obj.isRemake);
- [res addObject:dict];
- }];
-
- [self.resourceModel.movieArray enumerateObjectsUsingBlock:^(LenzResourceItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- idIndex += idx;
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- dict[@"id"] = [NSString stringWithFormat:@"%ld", idIndex];
- dict[@"path"] = obj.path;
- dict[@"cameraMode"] = obj.cameraMode;
- dict[@"cameraType"] = obj.cameraType;
- dict[@"isRemake"] = @(obj.isRemake);
- [res addObject:dict];
- }];
- [self.resourceModel.panoramArray enumerateObjectsUsingBlock:^(LenzResourceItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.path.length) {
- idIndex += idx;
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- dict[@"id"] = [NSString stringWithFormat:@"%ld", idIndex];
- dict[@"path"] = obj.path;
- dict[@"cameraMode"] = obj.cameraMode;
- dict[@"cameraType"] = obj.cameraType;
- dict[@"isRemake"] = @(obj.isRemake);
- NSMutableArray *keyFrame = [NSMutableArray array];
- [obj.keyFrame enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- [keyFrame addObject:obj];
- }];
- dict[@"keyFrame"] = keyFrame;
- [res addObject:dict];
- }
- }];
- [self.resourceModel.aiPanoramArray enumerateObjectsUsingBlock:^(LenzResourceItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.path.length) {
- idIndex += idx;
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- dict[@"id"] = [NSString stringWithFormat:@"%ld", idIndex];
- dict[@"path"] = obj.path;
- dict[@"cameraMode"] = obj.cameraMode;
- dict[@"cameraType"] = obj.cameraType;
- dict[@"isRemake"] = @(obj.isRemake);
- NSMutableArray *keyFrame = [NSMutableArray array];
- [obj.keyFrame enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- [keyFrame addObject:obj];
- }];
- dict[@"keyFrame"] = keyFrame;
- [res addObject:dict];
- }
- }];
- if (self.completeBlock) {
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- dict[@"code"] = @(200);
- dict[@"message"] = @"成功";
- dict[@"data"] = res;
- self.completeBlock(dict);
- [self dismissViewControllerAnimated:YES completion:^{
-
- }];
- }
- // self.panGesture.enabled = YES;
- // // Access has not been determined.
- // [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- // if (status == PHAuthorizationStatusAuthorized) {
- // // Access has been granted.
- // [self.currentOperationNode save];
- // }
- // else {
- // // Access has been denied.
- // [self showAlertForAuthorizationWithText:@"请设置相册权限后重试"];
- // }
- // });
- // }];
- }
- - (void)discardPhotoResultButtonTouchUpInside:(id)sender{
- self.panGesture.enabled = YES;
- // if([self.currentOperationNode respondsToSelector:@selector(discardPhotoResultButtonTouchUpInside)]){
- // [self.currentOperationNode discardPhotoResultButtonTouchUpInside];
- // }
- NSString *title = @"返回会清空已拍摄数据,请确认!";
- // if (self.mode == SDK_CAPTURE_MODE_MOVIE) {
- // title = @"返回会清空已拍摄视频,请确认!";
- // } else if (self.mode == SDK_CAPTURE_MODE_PANORAMA || self.mode == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
- // title = @"返回会清空已拼接图片,请确认!";
- // }
- [QuitMultipleModeAlertViewController show:self title:@"确认提醒" text:title leftBtnTitle:@"取消" rightBtnTitle:@"确定" withLeftButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) {
- [alertController dismissViewControllerAnimated:NO completion:^{}];
- } rightButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) {
- // if (self.mode == SDK_CAPTURE_MODE_CONTINUOUS) {
- [self.resourceModel.continousArray removeAllObjects];
- // } else if (self.mode == SDK_CAPTURE_MODE_MOVIE) {
- [self.resourceModel.movieArray removeAllObjects];
- // } else if (self.mode == SDK_CAPTURE_MODE_PANORAMA) {
- [self.resourceModel.panoramArray removeAllObjects];
- // } else if (self.mode == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
- [self.resourceModel.aiPanoramArray removeAllObjects];
- // }
- [self updateViewStatus];
- [alertController dismissViewControllerAnimated:NO completion:^{
- }];
- }];
- }
- - (void)albumButtonTouchUpInside:(id)sender{
- [self performSegueWithIdentifier:@"show-photoalbum" sender:nil];
- // if([self.currentOperationNode respondsToSelector:@selector(segueForAlbum)]){
- // [self performSegueWithIdentifier:self.currentOperationNode.segueForAlbum sender:nil];
- // }
- }
- - (__kindof id<OperationNodeProtocol>)currentOperationNode{
- // NSLog(@"======:%u",self.mode);
- // NSLog(@"------:%@",self.operationNodes);
- return self.operationNodes[@(self.mode)];
- }
- - (void)updateNumberLabel {
- self.aiPanPromtLabel.hidden = YES;
- switch (self.mode) {
- case SDK_CAPTURE_MODE_CONTINUOUS: {
- if (self.resourceModel.continousArray.count > 0) {
- self.numberOfImagesLabel.hidden = NO;
- self.numberOfImagesLabel.text = [NSString stringWithFormat:@"已连拍%ld张", self.resourceModel.continousArray.count];
- } else {
- self.numberOfImagesLabel.hidden = YES;
- }
- }
-
- break;
- case SDK_CAPTURE_MODE_MOVIE:{
- if (self.resourceModel.movieArray.count > 0) {
- self.numberOfImagesLabel.hidden = NO;
- self.numberOfImagesLabel.text = [NSString stringWithFormat:@"已拍视频%ld条", self.resourceModel.movieArray.count];
- } else {
- self.numberOfImagesLabel.hidden = YES;
- }
- }
-
- break;
- case SDK_CAPTURE_MODE_PANORAMA:
- {
- if (self.resourceModel.panoramArray.count > 0) {
- self.numberOfImagesLabel.hidden = NO;
- self.numberOfImagesLabel.text = [NSString stringWithFormat:@"已拼接%ld张", self.resourceModel.panoramArray.count];
- } else {
- self.numberOfImagesLabel.hidden = YES;
- }
- }
-
- break;
- case SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA:
- {
- self.aiPanPromtLabel.hidden = NO;
- if (self.resourceModel.aiPanoramArray.count > 0) {
- self.numberOfImagesLabel.hidden = NO;
- self.numberOfImagesLabel.text = [NSString stringWithFormat:@"已拍摄%ld张", self.resourceModel.aiPanoramArray.count];
- } else {
- self.numberOfImagesLabel.text = @"轻点拍照,长按录制";
- self.numberOfImagesLabel.hidden = NO;
- }
- }
- break;
-
- default:
- self.numberOfImagesLabel.hidden = YES;
- break;
- }
- }
- - (void)savePhotoWith:(NSData *)data isRemake:(BOOL)isRemake{
- UIImage *image = [[UIImage alloc] initWithData:data];
- NSString *path = [LenzDataManager saveImageWith:data mode:self.mode];
- LenzResourceItemModel *itemModel = [[LenzResourceItemModel alloc]init];
- itemModel.path = path;
- [[SDKParameters shared].items enumerateObjectsUsingBlock:^(SDKParametersItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.model == self.mode) {
- itemModel.cameraType = obj.cameraPositionString;
- }
- }];
-
- itemModel.mode = self.mode;
-
-
- itemModel.image = image;
- itemModel.isRemake = isRemake;
- switch (self.mode) {
- case SDK_CAPTURE_MODE_CONTINUOUS:{
-
- [self.resourceModel.continousArray addObject:itemModel];
- }
- break;
- case SDK_CAPTURE_MODE_SINGLE: {
- [self.resourceModel.singleArray addObject:itemModel];
- }
-
- break;
- case SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA: {
- [self.resourceModel.aiPanoramArray addObject:itemModel];
- }
-
- break;
-
- default:
- break;
- }
- self.resourceModel.lastIndex = self.mode;
- [self updateViewStatus];
- // [self.cachesArray addObject:image];
- //
- // [self.typeArray addObject:@"photo"];
- //
- // [self.totalArray addObject:image];
- //
- // self.capturedImage = image;
-
-
-
- [self.currentOperationNode triggered];
- if(self.mode == SDK_CAPTURE_MODE_SINGLE){
- // self.panGesture.enabled = NO;
- [self stopCaptureSession];
- [self performSegueWithIdentifier:@"preview_single" sender:nil];
- // [self showPreviewView:NO];
- }
- else if(self.mode == SDK_CAPTURE_MODE_CONTINUOUS){
- self.discardPhotoButton.hidden = NO;
- self.savePhotoButton.hidden = NO;
- }
-
- self.resultImageView.image = image;
- }
- #pragma mark 相机单拍,和连拍的代理
- - (void)captureOutput:(AVCapturePhotoOutput *)output didFinishProcessingPhoto:(AVCapturePhoto *)photo error:(NSError *)error{
- NSData* imageData = [photo fileDataRepresentation];
- if (imageData == nil){
- NSLog(@"%s", "unable to create image data");
- return;
- }
- UIImage *image = [[UIImage alloc] initWithData:imageData];
- BOOL isRemake = [self.tensorFlow remake:image];
- __block BOOL needCheckRemake = NO;
- [[SDKParameters shared].items enumerateObjectsUsingBlock:^(SDKParametersItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.model == self.mode) {
- needCheckRemake = obj.isRemake;
- }
- }];
- if (isRemake && needCheckRemake) {
- [QuitMultipleModeAlertViewController show:self title:@"确认提醒" text:@"检测到该图片为翻拍,是否继续使用?" leftBtnTitle:@"取消" rightBtnTitle:@"确定" withLeftButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) {
- [alertController dismissViewControllerAnimated:YES completion:nil];
- } rightButtonCallBack:^(QuitMultipleModeAlertViewController * _Nonnull alertController) {
- [alertController dismissViewControllerAnimated:YES completion:nil];
- [self savePhotoWith:imageData isRemake:isRemake];
-
- }];
- } else {
- [self savePhotoWith:imageData isRemake:isRemake];
- }
-
- }
- - (void)updateViewStatus {
- dispatch_async(dispatch_get_main_queue(), ^{
- UIImage *image = nil;
- NSMutableArray *continousMutArray = [NSMutableArray array];
- [self.resourceModel.continousArray enumerateObjectsUsingBlock:^(LenzResourceItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.path && obj.image) {
- [continousMutArray addObject:obj];
- }
- }];
- self.resourceModel.continousArray = continousMutArray;
-
- NSMutableArray *singleMutArray = [NSMutableArray array];
- [self.resourceModel.singleArray enumerateObjectsUsingBlock:^(LenzResourceItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.path && obj.image) {
- [singleMutArray addObject:obj];
- }
- }];
- self.resourceModel.singleArray = singleMutArray;
-
- NSMutableArray *movieMutArray = [NSMutableArray array];
- [self.resourceModel.movieArray enumerateObjectsUsingBlock:^(LenzResourceItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.path && obj.image) {
- [movieMutArray addObject:obj];
- }
- }];
- self.resourceModel.movieArray = movieMutArray;
-
- NSMutableArray *panoramMutArray = [NSMutableArray array];
- [self.resourceModel.panoramArray enumerateObjectsUsingBlock:^(LenzResourceItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.path && obj.image) {
- [panoramMutArray addObject:obj];
- }
- }];
- self.resourceModel.panoramArray = panoramMutArray;
-
- NSMutableArray *aiPanoramMutArray = [NSMutableArray array];
- [self.resourceModel.aiPanoramArray enumerateObjectsUsingBlock:^(LenzResourceItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.path && obj.image) {
- [aiPanoramMutArray addObject:obj];
- }
- }];
- self.resourceModel.aiPanoramArray = aiPanoramMutArray;
-
- switch (self.resourceModel.lastIndex) {
- case SDK_CAPTURE_MODE_CONTINUOUS: {
- if (self.resourceModel.continousArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.continousArray.lastObject;
- image = model.image;
- } else {
- if (self.resourceModel.singleArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.singleArray.lastObject;
- image = model.image;
- } else if (self.resourceModel.movieArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.movieArray.lastObject;
- image = model.image;
- } else if (self.resourceModel.panoramArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.panoramArray.lastObject;
- image = model.image;
- } else if (self.resourceModel.aiPanoramArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.aiPanoramArray.lastObject;
- image = model.image;
- }
- }
- }
-
- break;
- case SDK_CAPTURE_MODE_SINGLE:{
- if (self.resourceModel.singleArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.singleArray.lastObject;
- image = model.image;
- } else {
- if (self.resourceModel.continousArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.continousArray.lastObject;
- image = model.image;
- } else if (self.resourceModel.movieArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.movieArray.lastObject;
- image = model.image;
- } else if (self.resourceModel.panoramArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.panoramArray.lastObject;
- image = model.image;
- } else if (self.resourceModel.aiPanoramArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.aiPanoramArray.lastObject;
- image = model.image;
- }
- }
- }
-
- break;
- case SDK_CAPTURE_MODE_MOVIE:{
- if (self.resourceModel.movieArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.movieArray.lastObject;
- image = model.image;
- } else {
- if (self.resourceModel.singleArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.singleArray.lastObject;
- image = model.image;
- } else if (self.resourceModel.continousArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.continousArray.lastObject;
- image = model.image;
- } else if (self.resourceModel.panoramArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.panoramArray.lastObject;
- image = model.image;
- } else if (self.resourceModel.aiPanoramArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.aiPanoramArray.lastObject;
- image = model.image;
- }
- }
- }
-
- break;
- case SDK_CAPTURE_MODE_PANORAMA:{
- if (self.resourceModel.panoramArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.panoramArray.lastObject;
- image = model.image;
- } else {
- if (self.resourceModel.singleArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.singleArray.lastObject;
- image = model.image;
- } else if (self.resourceModel.movieArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.movieArray.lastObject;
- image = model.image;
- } else if (self.resourceModel.continousArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.continousArray.lastObject;
- image = model.image;
- } else if (self.resourceModel.aiPanoramArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.aiPanoramArray.lastObject;
- image = model.image;
- }
- }
- }
-
- break;
- case SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA:{
- if (self.resourceModel.aiPanoramArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.aiPanoramArray.lastObject;
- image = model.image;
- } else {
- if (self.resourceModel.singleArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.singleArray.lastObject;
- image = model.image;
- } else if (self.resourceModel.movieArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.movieArray.lastObject;
- image = model.image;
- } else if (self.resourceModel.panoramArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.panoramArray.lastObject;
- image = model.image;
- } else if (self.resourceModel.continousArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.continousArray.lastObject;
- image = model.image;
- }
- }
- }
-
- break;
-
- default:
- break;
- }
- if (image) {
- self.ablumImageView.image = image;
- self.ablumImageView.hidden = NO;
- self.discardPhotoButton.hidden = NO;
- self.savePhotoButton.hidden = NO;
- self.backButton.hidden = YES;
- } else {
- self.ablumImageView.image = nil;
- self.ablumImageView.hidden = YES;
- self.discardPhotoButton.hidden = YES;
- self.savePhotoButton.hidden = YES;
- self.backButton.hidden = NO;
- }
- [self updateNumberLabel];
- });
-
- }
- #pragma mark - AVCaptureFileOutputRecordingDelegate
- - (void)captureOutput:(AVCaptureFileOutput *)output didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray<AVCaptureConnection *> *)connections error:(NSError *)error{
- //视频录制
- BOOL recordedSuccessfully = YES;
- // A problem occurred: Find out if the recording was successful.
- if(error.code == AVErrorMaximumDurationReached){
- NSLog(@"%@", [error localizedDescription]);
- }
- else if (error.code == AVErrorDiskFull){
- NSLog(@"%@", [error localizedDescription]);
- dispatch_async(dispatch_get_main_queue(), ^{
- [[NSNotificationCenter defaultCenter] postNotificationName:LenzSDKNotificationDiskIsFull object:error];
- });
- }
- else if (error.code == AVErrorSessionWasInterrupted){
- NSLog(@"%@", [error localizedDescription]);
- }
- id value = [[error userInfo] objectForKey:AVErrorRecordingSuccessfullyFinishedKey];
- if (value) {
- recordedSuccessfully = [value boolValue];
-
- [self.recordTimer invalidate];
- self.recordTimer = nil;
- }
- if(!recordedSuccessfully){
- return;
- }
-
- OperationNodeMovie *node = nil;
- if ([self.currentOperationNode isKindOfClass:[OperationNodeMovie class]]) {
- node = (OperationNodeMovie *)self.currentOperationNode;
- if (node.isRecording) {
- [self.currentOperationNode takePhotoButtonTouched];
- }
- }
- // NSString *path = [LenzDataManager saveVideoUrl:outputFileURL model:self.mode];
- LenzResourceItemModel *itemModel = [[LenzResourceItemModel alloc]init];
- itemModel.path = outputFileURL.absoluteString;
- [[SDKParameters shared].items enumerateObjectsUsingBlock:^(SDKParametersItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.model == self.mode) {
- itemModel.cameraType = obj.cameraPositionString;
- }
- }];
-
- itemModel.mode = self.mode;
- itemModel.image = [self videoFrameImageWith:outputFileURL];
- [self.resourceModel.movieArray addObject:itemModel];
- self.resourceModel.lastIndex = self.mode;
-
- // self.recordedFileUrl = outputFileURL;
-
- // [self.typeArray addObject:@"movie"];
- [self updateViewStatus];
- [self.timerLabel updateWith:0];
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.currentOperationNode triggered];
- self.thumbnailOritaionByCurrentVideoOrientation = UIImageOrientationUp;
- });
- }
- - (BOOL)encodeFrame:(CMSampleBufferRef) sampleBuffer{
-
- if (CMSampleBufferDataIsReady(sampleBuffer)) {
-
- if (self.videoWriter.status == AVAssetWriterStatusUnknown) {
-
- CMTime startTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
-
- [self.videoWriter startWriting];
- [self.videoWriter startSessionAtSourceTime:startTime];
- }
-
- if (self.videoWriter.status == AVAssetWriterStatusFailed) {
- NSLog(@"writer error %@", self.videoWriter.error.localizedDescription);
- return NO;
- }
-
- if (self.videoWriterInput.readyForMoreMediaData) {
- [self.videoWriterInput appendSampleBuffer:sampleBuffer];
- return YES;
- }
- }
- return NO;
- }
- #pragma mark - AVCaptureAudioDataOutputSampleBufferDelegate
- #pragma mark - UIViewControllerTransitioningDelegate
- - (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{
- return [[CustomModalViewTransitionPresent alloc] init];
- }
- - (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{
- return [[CustomModalViewTransitionDismiss alloc] init];
- }
- #pragma mark - PhotoListViewControllerDelegate
- //删除视频
- - (void)deleteMovie: (MovieListCellModel*)model completion: (DeleteImageCompletionCallBackType)completion{
- for (int i = 0; i < self.totalArray.count; i ++) {
- UIImage *image = self.totalArray[i];
- if (image == (UIImage *)model.movieModel.thumbnail) {
- [self.totalArray removeObjectAtIndex:i];
- [self.typeArray removeObjectAtIndex:i];
- break;;
- }
-
- }
- // id<OperationNodeProtocol> curr = self.currentOperationNode;
- id<OperationNodeProtocol> curr = (__kindof id<OperationNodeProtocol>)self.operationNodes[@(2)];
- if([curr respondsToSelector:@selector(deleteCacheForKey:completion:)]){
- [curr deleteCacheForKey:model.movieModel.fileUrl.path completion:completion];
- }
- }
- //连拍删除
- - (void)deleteImage:(UIImage *)image completion:(nonnull DeleteImageCompletionCallBackType)completion{
-
- // id<OperationNodeProtocol> curr = self.currentOperationNode;
- for (int i = 0; i < self.totalArray.count; i ++) {
- UIImage *img = self.totalArray[i];
- if (img == image) {
- [self.totalArray removeObjectAtIndex:i];
- [self.typeArray removeObjectAtIndex:i];
- break;;
- }
-
- }
-
- id<OperationNodeProtocol> curr = (__kindof id<OperationNodeProtocol>)self.operationNodes[@(0)];
- if([curr respondsToSelector:@selector(deleteCacheForImage:completion:)]){
- [curr deleteCacheForImage:image completion:completion];
- }
- }
- - (void)deleteImageWithName:(NSString *)name completion:(nonnull DeleteImageCompletionCallBackType)completion{
-
- id<OperationNodeProtocol> curr = self.currentOperationNode;
- if([curr respondsToSelector:@selector(deleteCacheForKey:completion:)]){
- [curr deleteCacheForKey:name completion:completion];
- }
- }
- #pragma mark - AVCaptureVideoDataOutputSampleBufferDelegate
- - (void)captureOutput:(AVCaptureOutput *)output didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
- @autoreleasepool {
- if (connection == [self.videoDataOutput connectionWithMediaType:AVMediaTypeVideo]) {
-
- [self.stitchkLock lock];
- // dispatch_semaphore_wait(self.videoStitchSemaphore, DISPATCH_TIME_FOREVER);
- OperationNodeVideoBase *base = nil;
- if ([self.currentOperationNode isKindOfClass:[OperationNodeVideoBase class]]) {
- base = (OperationNodeVideoBase *)self.currentOperationNode;
- }
-
- if (self.isVideoStitchStopedWhenRecording &&
- (self.stitchResult != LenVideoStitchResultFail && self.stitchResult != LenVideoStitchResultStitchFail)) {
- [self updateViewStatusWhenStitchSave:YES];
- self.isStitchBigImage = YES;
- }
- [LenStitcher videoStitchWith:sampleBuffer
- dirction:(LenVideoStitchDirction)self.panoramOrientationGuideView.selectedItemIndex
- isStop:self.isVideoStitchStopedWhenRecording
- complete:^(LenVideoStitchResult result, LenVideoStitchNeedSave needSave) {
- self.stitchResult = result;
-
- self.isVideoStitchStopedWhenRecording = NO;
- UIImage *image = [LenStitcher getCurrentPanoramaShowImage];
- LenzResourceItemModel *model = nil;
- if (self.mode == SDK_CAPTURE_MODE_PANORAMA) {
- model = self.resourceModel.panoramArray.lastObject;
- } else if (self.mode == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
- model = self.resourceModel.aiPanoramArray.lastObject;
- }
- if (!image || !model) {
- [self.stitchkLock unlock];
- return;
- }
-
- if (result == LenVideoStitchResultSuccess) {
- dispatch_async(dispatch_get_main_queue(), ^{
-
- if (self.isStitchBigImage) {
- //保存大图拼接路径
- [[SDKParameters shared].items enumerateObjectsUsingBlock:^(SDKParametersItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.model == self.mode) {
- model.cameraType = obj.cameraPositionString;
- }
- }];
- model.mode = self.mode;
- if ([LenStitcher getCurrentPanoramaShow]) {
- model.image = image;
- model.path = [LenStitcher getCurrentPanoramaShow];
- }
- [self updateViewStatusWhenStitchSave:NO];
- self.isStitchBigImage = NO;
- [self.panoramaGuideView clearImage];
- [self updateViewStatus];
- [self.panoramaGuideView showImageWith:nil dir:self.panoramOrientationGuideView.selectedItemIndex];
- } else {
- if (base.isRecording) {
- __block BOOL keyFrame = NO;
- [[SDKParameters shared].items enumerateObjectsUsingBlock:^(SDKParametersItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.model == self.mode) {
- keyFrame = obj.keyFrame;
- }
- }];
-
- if (needSave && keyFrame) {
- NSString *path = [LenzDataManager saveImageWith:UIImageJPEGRepresentation(image, .6) mode:self.mode];
- // itemModel.path = path;
- if (path) {
- [model.keyFrame addObject:path];
- }
- }
- if (self.panoramOrientationGuideView.selectedItemIndex != PanoramaOrientationViewAny) {
- [self.panoramaGuideView showImageWith:image dir:self.panoramOrientationGuideView.selectedItemIndex];
- } else {
- self.ablumImageView.hidden = NO;
- self.ablumImageView.image = image;
- }
- }
- }
- self.resourceModel.lastIndex = self.mode;
- });
- } else {
-
- if (!base.isRecording) {
- // [self removeLastStich];
- //停止拼接,移除保存中 非success数据
- if (self.mode == SDK_CAPTURE_MODE_PANORAMA) {
- NSMutableArray *array = [NSMutableArray array];
- [self.resourceModel.panoramArray enumerateObjectsUsingBlock:^(LenzResourceItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.path.length) {
- [array addObject:obj];
- }
- }];
- self.resourceModel.panoramArray = array;
- } else if (self.mode == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
- NSMutableArray *array = [NSMutableArray array];
- [self.resourceModel.aiPanoramArray enumerateObjectsUsingBlock:^(LenzResourceItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if (obj.path.length) {
- [array addObject:obj];
- }
- }];
- self.resourceModel.aiPanoramArray = array;
- }
- [self updateViewStatus];
- [self.stitchkLock unlock];
- return;
- }
- if (result == LenVideoStitchResultFail || result == LenVideoStitchResultStitchFail) {
- if (result == LenVideoStitchResultFail) {
- [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"拼接失败,流程结束"];
- } else {
- [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"拼接大图失败,流程结束"];
- }
-
- self.isVideoStitchStopedWhenRecording = NO;
- // base.isRecording = NO;
- dispatch_async(dispatch_get_main_queue(), ^{
- [base takePhotoButtonTouched];
- [self stopMotion];
- // [self takePhotoButtonTouchUpInside:[NSObject new]];
- [self removeLastStich];
- [self updateViewStatusWhenStitchFail];
- [self.panoramaGuideView clearImage];
- [self updateViewStatus];
- [self.panoramaGuideView showImageWith:nil dir:self.panoramOrientationGuideView.selectedItemIndex];
- });
-
- [SVProgressHUD dismissWithDelay:3 completion:^{
- }];
- } else if(result == LenVideoStitchResultSlowMore) {
- [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"目标物较少,请对准目标物低速且匀速拍摄"];
- } else if (result == LenVideoStitchResultSlow) {
- [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"目标物较少,请对准目标物低速且匀速拍摄"];
- } else {
- // [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"请勿往反方向移动"];
- }
- }
-
- [self.stitchkLock unlock];
- // dispatch_semaphore_signal(self.videoStitchSemaphore);
- }];
-
- }
- }
- }
- - (void)removeLastStich {
- if (self.mode == SDK_CAPTURE_MODE_PANORAMA) {
- if (self.resourceModel.panoramArray.count > 0) {
- [self.resourceModel.panoramArray removeLastObject];
- }
- } else if (self.mode == SDK_CAPTURE_MODE_INTELLEGENCE_PANORAMA) {
- if (self.resourceModel.aiPanoramArray.count > 0) {
- [self.resourceModel.aiPanoramArray removeLastObject];
- }
- }
- }
- //*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- if([segue.identifier isEqualToString:@"show-photos"]){
- if([segue.destinationViewController isKindOfClass:[PhotoListViewController class]]){
- PhotoListViewController* dst = segue.destinationViewController;
- OperationNodeMultiple* node = self.currentOperationNode;
- dst.transitioningDelegate = self;
- [dst setImagesInMemory:node.cachesInMemory andImageNamesOnDisk:node.cachesOnDisk];
- dst.delegate = self;
- }
- }
- else if([segue.identifier isEqualToString:@"show-movies"]){
- if([segue.destinationViewController isKindOfClass:[MovieListViewController class]]){
- MovieListViewController* dst = segue.destinationViewController;
- OperationNodeMovie* node = self.currentOperationNode;
- dst.transitioningDelegate = self;
- dst.movieModels = node.cachedMovies;
- dst.delegate = self;
- }
- }
- else if([segue.identifier isEqualToString:@"preview_single"]){
- PreviewSingleViewController* dst = segue.destinationViewController;
- dst.singleModeNode = self.currentOperationNode;
- if (self.resourceModel.singleArray.count > 0) {
- LenzResourceItemModel *model = self.resourceModel.singleArray.firstObject;
- dst.image = model.image;
- }
- // dst.image = self.capturedImage;
- }else if ([segue.identifier isEqualToString:@"show-photoalbum"]){
-
- PhotoAlbumListViewController *dst = segue.destinationViewController;
- dst.typeArray = self.typeArray;
-
- //图片数据
- NSString *typeStr = self.typeArray.lastObject;
- // if ([typeStr isEqualToString:@"photo"]) {
- OperationNodeMultiple* node = (__kindof id<OperationNodeProtocol>)self.operationNodes[@(0)];
- // OperationNodeMultiple* node = self.currentOperationNode;
- dst.node = node;
- dst.photoListVC.transitioningDelegate = self;
- [dst.photoListVC setImagesInMemory:node.cachesInMemory andImageNamesOnDisk:node.cachesOnDisk];
- dst.photoListVC.delegate = self;
-
- // }else if ([typeStr isEqualToString:@"movie"]) {
- OperationNodeMovie* movieNode = (__kindof id<OperationNodeProtocol>)self.operationNodes[@(2)];
- dst.movieListVC.transitioningDelegate = self;
- dst.movieListVC.movieModels = movieNode.cachedMovies;
- dst.movieListVC.delegate = self;
- // }
-
- //视频数据
-
-
-
-
- }
-
- }
- //*/
- - (void)clearSingleData {
- [self.resourceModel.singleArray removeAllObjects];
- [self updateViewStatus];
- }
- - (UIImage *)videoFrameImageWith:(NSURL *)url {
- AVURLAsset* asset = [[AVURLAsset alloc] initWithURL:url options:nil];
- AVAssetImageGenerator *generateImg = [[AVAssetImageGenerator alloc] initWithAsset:asset];
- NSError *err = NULL;
- CMTime time = CMTimeMake(1, 65);
- CGImageRef refImg = [generateImg copyCGImageAtTime:time actualTime:NULL error:&err];
- UIImage *frameImage= [[UIImage alloc] initWithCGImage:refImg scale:1.0 orientation:self.thumbnailOritaionByCurrentVideoOrientation];
- return frameImage;
- }
- @end
|