FishEyeVideoVC.mm 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. //
  2. // FishEyeVideoVC.m
  3. // 未来家庭
  4. //
  5. // Created by wujiangbo on 8/8/16.
  6. // Copyright © 2016 wujiangbo. All rights reserved.
  7. //
  8. #import "FishEyeVideoVC.h"
  9. #import "FunSDK/FunSDK.h"
  10. #import "FunSDK/XTypes.h"
  11. //#import "OpenGLView.h"
  12. //#import "SVProgressHUD.h"
  13. #import <QuartzCore/QuartzCore.h>
  14. #import <OpenGLES/ES2/glext.h>
  15. #import <GLKit/GLKit.h>
  16. #include <queue>
  17. #import "AppDelegate.h"
  18. #import "VRGLViewController.h"
  19. //#import "MacroDefinication.h"
  20. #import "Header.h"
  21. #define RAD_TO_DEG( rad ) ( (rad) * 57.29577951f )
  22. @interface FishEyeVideoVC ()
  23. {
  24. VRGLViewController *SoftVR;//软解Glkview视图
  25. FUN_HANDLE player; //播放器句柄
  26. // UI_HANDLE msgHandle;
  27. UIImageView *backGroundImage; // 背景图片
  28. int startTime; // 录像开始时间
  29. BOOL isPause; // 录像是否暂停
  30. UIView *_toolView; // 工具栏
  31. UIView *_narView; // 导航栏
  32. CGPoint _touchBegPoint;
  33. CGPoint _touchEndPoint;
  34. BOOL _touched;
  35. NSInteger numbers;
  36. BOOL isMove;//判断手指停留 惯性停止
  37. BOOL isTouchMove;
  38. int Hardandsofts;//4:软解 3:硬解
  39. int Hardmodels;//模式
  40. short centerOffsetX;
  41. short centerOffsetY;
  42. short imageWidth;
  43. short imageHeight;
  44. short imgradius;
  45. UIPinchGestureRecognizer *twoFingerPinch ;
  46. int talkHandle;
  47. }
  48. @property(nonatomic,strong)UIView *gView;//显示播放视频的试图
  49. @property (strong, nonatomic) EAGLContext *context;
  50. @property(nonatomic)NSUInteger orietation;
  51. @property (strong, nonatomic) NSDate *begDate;
  52. @property (strong,nonatomic) NSDate *endDate;
  53. @end
  54. @implementation FishEyeVideoVC
  55. - (void)viewDidLoad {
  56. [super viewDidLoad];
  57. startTime = 0;
  58. isPause = NO;
  59. // 1.0 创建视图
  60. [self createBaseView];
  61. // 2.0 创建底部工具视图
  62. [self createToolView];
  63. [[UIApplication sharedApplication] setStatusBarHidden:FALSE];
  64. // 3.0 默认横屏播放
  65. //[self homeButtonLeft];
  66. self.playBtn.selected =NO;
  67. [self playVideo];
  68. [self addDoubleTapGesture];
  69. }
  70. -(void)addDoubleTapGesture
  71. {
  72. UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapAction:)];
  73. doubleTap.numberOfTapsRequired = 2;
  74. doubleTap.numberOfTouchesRequired = 1;
  75. [self.view addGestureRecognizer:doubleTap];
  76. }
  77. -(void)doubleTapAction:(UITapGestureRecognizer*)recognizer
  78. {
  79. if (SoftVR) {
  80. [SoftVR DoubleTap:nil];
  81. }
  82. }
  83. -(void)tapGesture
  84. {
  85. [self hiddenNav];
  86. }
  87. //隐藏状态栏和工具栏
  88. -(void)hiddenNarViewAndToolView{
  89. _narView.hidden = YES;
  90. _toolView.hidden = YES;
  91. }
  92. //显示状态栏和工具栏
  93. -(void)showNarViewAndToolView{
  94. _narView.hidden = NO;
  95. if (self.fisheyephotoOrvideo ==2) {
  96. _toolView.hidden =YES;
  97. }else{
  98. _toolView.hidden = NO;
  99. }
  100. }
  101. -(void)switchNarViewAndToolView {
  102. if (_narView.hidden == YES) {
  103. [self showNarViewAndToolView];
  104. } else {
  105. [self hiddenNarViewAndToolView];
  106. }
  107. }
  108. - (void)viewWillDisappear:(BOOL)animated
  109. {
  110. FUN_MediaSetSound(player, 0, 0);
  111. FUN_MediaStop(player);
  112. [[UIApplication sharedApplication] setStatusBarHidden:FALSE];
  113. [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
  114. }
  115. -(void)viewWillAppear:(BOOL)animated
  116. {
  117. [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
  118. self.timeSlider.frame = CGRectMake(CGRectGetMaxX(self.playBtn.frame) + 20,20, ScreenWidth - CGRectGetMaxX(self.playBtn.frame) - 40 , 44);
  119. }
  120. #pragma mark - 创建基本视图
  121. - (void)createBaseView
  122. {
  123. self.view.backgroundColor = [UIColor whiteColor];
  124. backGroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenHeight, ScreenWidth)];
  125. backGroundImage.image = [UIImage imageNamed:@"fisheye_video_background"];
  126. [self.view addSubview:backGroundImage];
  127. SoftVR = [[VRGLViewController alloc]init];
  128. [self addChildViewController:SoftVR];
  129. SoftVR.view.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
  130. [self.view addSubview:SoftVR.view];
  131. SoftVR.VRShowMode = 1;
  132. SoftVR.view.hidden = YES;
  133. _narView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 64, ScreenWidth)];
  134. [self.view addSubview:_narView];
  135. UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 20, 44, 44)];
  136. [backButton setImage:[UIImage imageNamed:@"new_back.png"] forState:UIControlStateNormal];
  137. [backButton addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
  138. backButton.backgroundColor = [UIColor clearColor];
  139. [_narView addSubview:backButton];
  140. self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(backButton.frame) + 10, 20, ScreenHeight - (CGRectGetMaxX(backButton.frame) + 10), 44)];
  141. self.titleLabel.text = [self.fileName lastPathComponent];
  142. self.titleLabel.textColor = [UIColor whiteColor];
  143. self.titleLabel.backgroundColor = [UIColor clearColor];
  144. [_narView addSubview:self.titleLabel];
  145. }
  146. #pragma mark - createToolView
  147. - (void)createToolView
  148. {
  149. // _toolView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_WIDTH - 80, SCREEN_HEIGHT, 80)];
  150. // if (SCREEN_WIDTH < SCREEN_HEIGHT) {
  151. // _toolView.frame = CGRectMake(0, SCREEN_HEIGHT - 80, SCREEN_WIDTH, 80);
  152. // }
  153. // [self.view addSubview:_toolView];
  154. _toolView = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenWidth - 80, ScreenHeight, 80)];
  155. [self.view addSubview:_toolView];
  156. self.playBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 20, 44, 44)];
  157. [self.playBtn addTarget:self action:@selector(playBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
  158. [self.playBtn setImage:[UIImage imageNamed:@"fisheye_video_pouse"] forState:UIControlStateNormal];
  159. [self.playBtn setImage:[UIImage imageNamed:@"fisheye_video_play"] forState:UIControlStateSelected];
  160. [_toolView addSubview:self.playBtn];
  161. self.playTime = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.playBtn.frame) + 20, 0, 100, 40)];
  162. self.playTime.textColor = [UIColor whiteColor];
  163. self.playTime.text = @"00:00";
  164. self.playTime.font = [UIFont systemFontOfSize:12];
  165. [_toolView addSubview:self.playTime];
  166. self.totalTime = [[UILabel alloc] initWithFrame:CGRectMake(ScreenHeight - 120, 0, 100, 40)];
  167. self.totalTime.textColor = [UIColor whiteColor];
  168. self.totalTime.textAlignment = NSTextAlignmentRight;
  169. self.totalTime.text = @"00:00";
  170. self.totalTime.font = [UIFont systemFontOfSize:12];
  171. [_toolView addSubview:self.totalTime];
  172. self.timeSlider = [[UISlider alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.playBtn.frame) + 20,20, ScreenWidth - CGRectGetMaxX(self.playBtn.frame) - 40 , 44)];
  173. self.timeSlider.minimumTrackTintColor = [UIColor redColor];
  174. self.timeSlider.maximumTrackTintColor = [UIColor colorWithRed:68/255.0 green:71/255.0 blue:72/255.0 alpha:1];
  175. self.timeSlider.maximumValue = 30 * 60;
  176. [self.timeSlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
  177. [_toolView addSubview:self.timeSlider];
  178. if (self.fisheyephotoOrvideo ==2) {
  179. _toolView.hidden =YES;
  180. }else{
  181. _toolView.hidden = NO;
  182. }
  183. }
  184. -(BOOL)shouldAutorotate
  185. {
  186. return NO;
  187. }
  188. -(NSUInteger)supportedInterfaceOrientations{
  189. SoftVR.view.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
  190. if (SoftVR) {
  191. [SoftVR configSoftEAGLContext];
  192. }
  193. //[SoftVR reloadInitView:SoftVR.view.frame];
  194. return UIInterfaceOrientationMaskLandscapeRight;
  195. }
  196. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  197. {
  198. return YES;
  199. }
  200. #pragma mark - 全屏播放
  201. -(void)homeButtonLeft
  202. {
  203. CGFloat number = 0;
  204. number = number + 90.0;
  205. [UIView beginAnimations:nil context:nil];
  206. [UIView setAnimationDuration:0];
  207. CGAffineTransform rotate = CGAffineTransformMakeRotation(number / 180.0 * M_PI );
  208. [_gView setTransform:rotate];
  209. [_toolView setTransform:rotate];
  210. [_narView setTransform:rotate];
  211. [UIView commitAnimations];
  212. _narView.center = CGPointMake(ScreenWidth - 20, ScreenWidth / 2);
  213. _toolView.center = CGPointMake(30, ScreenHeight/2);
  214. _gView.bounds = CGRectMake(0, 0, ScreenHeight, ScreenWidth);
  215. _gView.center = CGPointMake(ScreenWidth * 0.5, ScreenHeight * 0.5);
  216. }
  217. #pragma mark - UIControlEventValueChanged
  218. - (void)sliderAction:(UISlider *)slider
  219. {
  220. int f = slider.value;
  221. self.playTime.text = [self changeSecToTimeText:f];
  222. FUN_MediaSeekToTime(player,f, 0, 0);
  223. //FUN_MediaSeekToPos(handle,f * 100 / 25, 0);
  224. }
  225. #pragma mark - 将秒转化成显示的时间
  226. - (NSString *)changeSecToTimeText:(int)second
  227. {
  228. NSString *timeStr = @"";
  229. int min = (int)second/60;
  230. NSString *minStr;
  231. if (min < 10) {
  232. minStr = [NSString stringWithFormat:@"0%d",min];
  233. }
  234. else{
  235. minStr = [NSString stringWithFormat:@"%d",min];
  236. }
  237. int sec = second- ((int)second/60) * 60;
  238. NSString *secStr;
  239. if (sec < 10) {
  240. secStr = [NSString stringWithFormat:@"0%d",sec];
  241. }
  242. else{
  243. secStr = [NSString stringWithFormat:@"%d",sec];
  244. }
  245. timeStr = [NSString stringWithFormat:@"%@:%@",minStr,secStr];
  246. return timeStr;
  247. }
  248. #pragma mark - 播放/暂停按钮点击事件
  249. - (void)playBtnClicked:(UIButton *)sender
  250. {
  251. sender.selected = !sender.selected;
  252. if (self.playBtn.selected == NO && isPause == NO) {
  253. [self playVideo];
  254. }
  255. else{
  256. [self stopPlay];
  257. }
  258. }
  259. #pragma mark - 返回按钮点击事件
  260. - (void)backAction:(UIButton *)sender
  261. {
  262. [SoftVR removeFromParentViewController];
  263. [self dismissViewControllerAnimated:YES completion:nil];
  264. [self.navigationController popViewControllerAnimated:YES];
  265. }
  266. #pragma mark - 开始播放
  267. - (void)playVideo{
  268. player = FUN_MediaLocRecordPlay(SELF, [self.fileName UTF8String] , (__bridge void*)_gView,0);
  269. FUN_MediaSetSound(player, 100, 0);
  270. }
  271. #pragma mark - 停止播放
  272. - (void)stopPlay
  273. {
  274. isPause = !isPause;
  275. FUN_MediaPause(player,-1);
  276. }
  277. #pragma mark - SDK 回调
  278. -(void)OnFunSDKResult:(NSNumber *) pParam
  279. {
  280. NSInteger nAddr = [pParam integerValue];
  281. MsgContent *msg = (MsgContent *)nAddr;
  282. NSLog(@"-------------请求数据回调(tatal)---------------------");
  283. switch (msg->id) {
  284. case EMSG_ON_FRAME_USR_DATA:
  285. {
  286. if (msg -> param2 == 3) {
  287. SDK_FishEyeFrameHW fishFrame = {0};
  288. memcpy(&fishFrame, msg->pObject + 8, sizeof(SDK_FishEyeFrameHW));
  289. if (fishFrame.secene == SDK_FISHEYE_SECENE_P360_FE) {
  290. Hardandsofts = 3;
  291. FUN_SetIntAttr(player, EOA_MEDIA_YUV_USER, SELF); // 返回Yuv数据
  292. FUN_SetIntAttr(player, EOA_SET_MEDIA_VIEW_VISUAL, 0); // 自己画画面
  293. }
  294. }else if ((msg->param2 == 4) && \
  295. (msg->param1 >= (8 + sizeof(SDK_FishEyeFrameSW))))
  296. {
  297. SDK_FishEyeFrameSW fishFrame = {0};
  298. Hardandsofts =4;
  299. memcpy(&fishFrame, msg->pObject + 8, sizeof(SDK_FishEyeFrameSW));
  300. //
  301. // FUN_SetIntAttr(player, EOA_MEDIA_YUV_USER, self.msgHandle);//返回Yuv数据
  302. // FUN_SetIntAttr(player, EOA_SET_MEDIA_VIEW_VISUAL, 0);//自己画画面
  303. // 圆心偏差横坐标 单位:像素点
  304. centerOffsetX = fishFrame.centerOffsetX;
  305. //圆心偏差纵坐标 单位:像素点
  306. centerOffsetY = fishFrame.centerOffsetY;
  307. //半径 单位:像素点
  308. imgradius = fishFrame.radius;
  309. //圆心校正时的图像宽度 单位:像素点
  310. imageWidth = fishFrame.imageWidth;
  311. //圆心校正时的图像高度 单位:像素点
  312. imageHeight = fishFrame.imageHeight;
  313. //视角 0:俯视 1:平视
  314. if (fishFrame.viewAngle == 0) {
  315. }
  316. //显示模式 0:360VR
  317. if (fishFrame.lensType == SDK_FISHEYE_LENS_360VR || fishFrame.lensType == SDK_FISHEYE_LENS_360LVR) {//360vr
  318. [SoftVR setVRType:XMVR_TYPE_360D];
  319. }else{//180Vr
  320. [SoftVR setVRType:XMVR_TYPE_180D];
  321. }
  322. //设置鱼眼软解参数
  323. [SoftVR setVRFecParams:centerOffsetX yCenter:centerOffsetY radius:imgradius Width:imageWidth Height:imageHeight];
  324. SoftVR.view.hidden = NO;
  325. }
  326. SoftVR.view.hidden = NO;
  327. break;
  328. }
  329. case EMSG_ON_YUV_DATA://鱼眼灯泡或小雨点 p360模式 YUV数据回调
  330. {
  331. [SoftVR PushData:msg->param2 height:msg->param3 YUVData:(unsigned char *)msg->pObject];
  332. }
  333. break;
  334. case EMSG_START_PLAY://开始播放回
  335. {
  336. int time = msg->param3 - msg->param2 + 1;
  337. startTime = msg->param2;
  338. self.totalTime.text = [NSString stringWithFormat:@"%@",[self changeSecToTimeText:time]];
  339. self.timeSlider.maximumValue = time;
  340. }
  341. break;
  342. case EMSG_ON_PLAY_INFO: //收到解码信息回调
  343. {
  344. int playTime = msg->param2 - msg->param1;
  345. [self.timeSlider setValue:playTime animated:NO];
  346. self.playTime.text = [self changeSecToTimeText:playTime];
  347. }
  348. break;
  349. case EMSG_ON_PLAY_BUFFER_BEGIN: // 正在缓存数据
  350. {
  351. NSLog(@"Buffer begin.....");
  352. }
  353. break;
  354. case EMSG_ON_PLAY_BUFFER_END:
  355. {
  356. }
  357. break;
  358. case EMSG_PAUSE_PLAY:
  359. {
  360. }
  361. break;
  362. case EMSG_ON_PLAY_END: // 录像播放结束
  363. {
  364. self.playBtn.selected = !self.playBtn.selected;
  365. self.playTime.text = @"00:00";
  366. [self.timeSlider setValue:0 animated:NO];
  367. }
  368. break;
  369. }
  370. }
  371. //- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
  372. //{
  373. // [SoftVR SoftTouchMoveBegan:touches Softevent:event];
  374. //
  375. //
  376. //}
  377. -(void)hiddenNav
  378. {
  379. _narView.hidden = !_narView.hidden;
  380. if (self.fisheyephotoOrvideo ==2) {
  381. }else{
  382. _toolView.hidden = !_toolView.hidden;
  383. }
  384. }
  385. - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  386. {
  387. [SoftVR SoftTouchMove:touches Softevent:event];
  388. }
  389. //- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
  390. //{
  391. // [SoftVR SoftTouchMoveEnd:touches Softevent:event];
  392. // for (UITouch *touch in touches) {
  393. // if (event.allTouches.count == 1 && touch.tapCount == 1)
  394. // {
  395. // [self hiddenNav];
  396. // }
  397. // }
  398. //
  399. //}
  400. //-(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  401. // [SoftVR SoftTouchMoveEnd:touches Softevent:event];
  402. // for (UITouch *touch in touches) {
  403. // if (event.allTouches.count == 1 && touch.tapCount == 1)
  404. // {
  405. // [self hiddenNav];
  406. // }
  407. // }
  408. //
  409. //}
  410. -(NSInteger)comparebegtime{
  411. NSUInteger unitFlags =
  412. NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear;
  413. NSCalendar *calendar = [NSCalendar currentCalendar];
  414. NSDateComponents *cps = [calendar components:unitFlags fromDate:self.begDate toDate:self.endDate options:0];
  415. return [cps second];
  416. }
  417. - (void) touchesPinch:(UIPinchGestureRecognizer *)recognizer
  418. {
  419. [SoftVR SoftTouchesPinch:recognizer.scale];
  420. return;
  421. }
  422. @end