Blame view

src/decoder/dvpp/DvppDataMemory.hpp 2.53 KB
6fdcb6a5   Hu Chunming   初次提交,代码大体完成编写,完善中
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  #ifndef __DVPP_DATA_MEMORY_HPP__
  #define __DVPP_DATA_MEMORY_HPP__
  
  #include<string>
  
  #include "depend_headers.h"
  #include "dvpp_headers.h"
  
  using namespace std;
  
  // static int snap_free = 0;
  
  class DvppDataMemory : public DeviceMemory
  {
  public:
      DvppDataMemory(int _channel, int _width, int _width_stride, int _height, int _height_stride, int _size, string _id, string _dev_id, bool _key_frame, unsigned long long frame_nb)
       :DeviceMemory(_channel, _width, _width_stride, _height, _height_stride, _id, _dev_id, _key_frame, frame_nb, false){
          data_size = _size;
          data_type = 1;
          int ret = acldvppMalloc((void **)&pHwRgb, data_size);
          if(ret != ACL_ERROR_NONE){
              LOG_ERROR("[{}]- acldvppMalloc failed", id);
          }
      }
  
      DvppDataMemory( int _width, int _width_stride, int _height, int _height_stride, int _size, string _id, string _dev_id, bool _key_frame, unsigned long long frame_nb, unsigned char * pHwData)
       :DeviceMemory(-1, _width, _width_stride, _height, _height_stride, _id, _dev_id, _key_frame, frame_nb, false){
          data_size = _size;
          data_type = 1;
          pHwRgb = pHwData;
      }
  
      DvppDataMemory(DvppDataMemory* pSrc):DeviceMemory(-1, pSrc->getWidth(), pSrc->getWidthStride(), pSrc->getHeight(),  pSrc->getHeightStride(), pSrc->getId(), pSrc->getDeviceId(), pSrc->isKeyFrame(), pSrc->getFrameNb(), false){
          if(pSrc == nullptr) {
              LOG_ERROR("[{}]- pSrc is nullptr", pSrc->getId());
              return;
          }
  
          data_size = pSrc->getSize();
          int ret = acldvppMalloc((void **)&pHwRgb, data_size);
          if(ret != ACL_ERROR_NONE){
              LOG_ERROR("[{}]- acldvppMalloc failed", pSrc->getId());
              return;
          }
  
          ret = aclrtMemcpy(pHwRgb, data_size, pSrc->getMem(), pSrc->getSize(), ACL_MEMCPY_DEVICE_TO_DEVICE);
          if(ret != ACL_ERROR_NONE){
              acldvppFree(pHwRgb);
              LOG_ERROR("[{}]- aclrtMemcpy failed", pSrc->getId());
              return;
          }
  
          data_type = 2;
          timestamp = UtilTools::get_cur_time_ms();
      }
  
      ~DvppDataMemory(){
          // if (data_type == 2)
          // {
          //     snap_free++;
          //     LOG_INFO("[{}]- snap_free: {}", getId(), snap_free);
          // }
          if (pHwRgb) {
              int ret = acldvppFree(pHwRgb);
              if(ret != ACL_ERROR_NONE){
                  LOG_ERROR("[{}]- acldvppFree failed", id);
              }
              pHwRgb = nullptr;
          }
      }
  
  public:
      int data_type;  // 0: rgb , 1: NV12
  };
  
  
  #endif      // __DVPP_DATA_MEMORY_HPP__