PictureFileDownloadConfig.mm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // PictureFileDownloadConfig.m
  3. // FunSDKDemo
  4. //
  5. // Created by XM on 2018/11/16.
  6. // Copyright © 2018年 XM. All rights reserved.
  7. //
  8. #import "PictureFileDownloadConfig.h"
  9. @implementation PictureFileDownloadConfig
  10. #pragma mark - 根据传入的图片信息开始下载小缩略图片
  11. - (void)downloadSmallPicture:(PictureInfo*)pictureInfo{
  12. //获取通道
  13. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  14. //存储路径
  15. NSString *directoryPath = [NSString thumbnailPath];
  16. //开始时间
  17. XM_SYSTEM_TIME timeBegin = pictureInfo.timeBegin;
  18. NSString *timeString = [NSString stringWithFormat:@"%04d-%02d-%02d %02d:%02d:%02d",timeBegin.year,timeBegin.month,timeBegin.day,timeBegin.hour,timeBegin.minute,timeBegin.second];
  19. NSString *thumbPath = [directoryPath stringByAppendingFormat:@"/%@.jpg",timeString];
  20. char pInparm[512] = {0};
  21. sprintf(pInparm, "{\"Name\" : \"OPCompressPic\", \"OPCompressPic\": {\"Width\" : 160,\"Height\" :100, \"IsGeo\" :1, \"PicName\" :\"%s\"},\"SessionID\" : \"0x00000002\"}",SZSTR(pictureInfo.fileName));
  22. FUN_DevSearchPic(self.msgHandle, SZSTR(channel.deviceMac), 1448, 30000, 2000, pInparm, (int)strlen(pInparm), 10, -1, SZSTR(thumbPath), 0);
  23. }
  24. #pragma mark - 根据传入的图片信息下载图片
  25. - (void)downloadPicture:(PictureInfo*)pictureInfo {
  26. //获取通道
  27. ChannelObject *channel = [[DeviceControl getInstance] getSelectChannel];
  28. //下载原图
  29. H264_DVR_FILE_DATA fileData = {0};
  30. fileData.ch = (int)pictureInfo.channelNo;
  31. fileData.size = (int)pictureInfo.fileSize;
  32. strncpy(fileData.sFileName, SZSTR(pictureInfo.fileName), 108);
  33. //开始时间
  34. XM_SYSTEM_TIME timeBegin = pictureInfo.timeBegin;
  35. fileData.stBeginTime.year = (int)timeBegin.year;
  36. fileData.stBeginTime.month = (int)timeBegin.month;
  37. fileData.stBeginTime.day = (int)timeBegin.day;
  38. fileData.stBeginTime.hour = ((int)timeBegin.hour);
  39. fileData.stBeginTime.minute = (int)timeBegin.minute;
  40. fileData.stBeginTime.second = (int)timeBegin.second;
  41. //结束时间
  42. XM_SYSTEM_TIME timeEnd = pictureInfo.timeEnd;
  43. fileData.stEndTime.year = (int)timeEnd.year;
  44. fileData.stEndTime.month = (int)timeEnd.month;
  45. fileData.stEndTime.day = (int)timeEnd.day;
  46. fileData.stEndTime.hour = ((int)timeEnd.hour);
  47. fileData.stEndTime.minute = (int)timeEnd.minute;
  48. fileData.stEndTime.second = (int)timeEnd.second;
  49. //下载路径
  50. NSString *directoryPath = [NSString getPhotoPath];
  51. NSString *timeString = [NSString stringWithFormat:@"%04d-%02d-%02d %02d:%02d:%02d",timeBegin.year,timeBegin.month,timeBegin.day,timeBegin.hour,timeBegin.minute,timeBegin.second];
  52. NSString *pictureFilePath = [directoryPath stringByAppendingFormat:@"/%@.jpg",timeString];
  53. //开始下载
  54. FUN_DevDowonLoadByFile(self.msgHandle, SZSTR(channel.deviceMac), &fileData, SZSTR(pictureFilePath), 0);
  55. }
  56. #pragma mark - SDK回调
  57. -(void)OnFunSDKResult:(NSNumber *) pParam{
  58. NSInteger nAddr = [pParam integerValue];
  59. MsgContent *msg = (MsgContent *)nAddr;
  60. NSLog(@"msg->id = %d",msg->id);
  61. switch (msg->id) {
  62. #pragma mark 缩略图下载成功回调
  63. case EMSG_DEV_SEARCH_PIC:{
  64. if ( [self.delegate respondsToSelector:@selector(thumbDownloadResult: path:)]) {
  65. [self.delegate thumbDownloadResult:msg->param1 path:NSSTR(msg->szStr)];
  66. }
  67. }
  68. break;
  69. #pragma mark 原图开始下载回调
  70. case EMSG_ON_FILE_DOWNLOAD:{ //原图开始下载回调
  71. if ([self.delegate respondsToSelector:@selector(pictureDownloadStartResult:)]) {
  72. [self.delegate pictureDownloadStartResult:msg->param1];
  73. }
  74. }
  75. break;
  76. #pragma mark 原图下载进度回调
  77. case EMSG_ON_FILE_DLD_POS:{ //原图下载进度
  78. if ([self.delegate respondsToSelector:@selector(pictureDownloadProgressResult:)]) {
  79. if (msg->param1 < 0) {
  80. }else {
  81. [self.delegate pictureDownloadProgressResult:(CGFloat)msg->param2 / (CGFloat)msg->param1];
  82. }
  83. }
  84. }
  85. break;
  86. #pragma mark 原图下载成功回调
  87. case EMSG_ON_FILE_DLD_COMPLETE: { //原图下载成功
  88. if ([self.delegate respondsToSelector:@selector(pictureDownloadEndResultPath:)]) {
  89. [self.delegate pictureDownloadEndResultPath:NSSTR(msg->szStr)];
  90. }
  91. }
  92. }
  93. }
  94. @end