Blame view

src/decoder/dvpp/DvppDataMemory.hpp 3.12 KB
6fdcb6a5   Hu Chunming   初次提交,代码大体完成编写,完善中
1
2
3
4
5
6
7
8
  #ifndef __DVPP_DATA_MEMORY_HPP__
  #define __DVPP_DATA_MEMORY_HPP__
  
  #include<string>
  
  #include "depend_headers.h"
  #include "dvpp_headers.h"
  
4061a3c3   Hu Chunming   更换decoder
9
10
  #include <memory>
  
6fdcb6a5   Hu Chunming   初次提交,代码大体完成编写,完善中
11
12
13
14
15
16
17
18
  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)
4061a3c3   Hu Chunming   更换decoder
19
20
       :DeviceMemory(_channel, _width, _width_stride, _height, _height_stride, _size, _id, _dev_id, _key_frame, frame_nb, false){
          data_type = 0;
6fdcb6a5   Hu Chunming   初次提交,代码大体完成编写,完善中
21
22
23
24
25
26
27
          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)
4061a3c3   Hu Chunming   更换decoder
28
29
       :DeviceMemory(3, _width, _width_stride, _height, _height_stride, _size, _id, _dev_id, _key_frame, frame_nb, false){
          data_type = 0;
6fdcb6a5   Hu Chunming   初次提交,代码大体完成编写,完善中
30
31
32
          pHwRgb = pHwData;
      }
  
4061a3c3   Hu Chunming   更换decoder
33
      DvppDataMemory(DvppDataMemory* pSrc):DeviceMemory(3, pSrc->getWidth(), pSrc->getWidthStride(), pSrc->getHeight(),  pSrc->getHeightStride(), pSrc->getSize(), pSrc->getId(), pSrc->getDeviceId(), pSrc->isKeyFrame(), pSrc->getFrameNb(), false){
6fdcb6a5   Hu Chunming   初次提交,代码大体完成编写,完善中
34
35
36
37
38
          if(pSrc == nullptr) {
              LOG_ERROR("[{}]- pSrc is nullptr", pSrc->getId());
              return;
          }
  
6fdcb6a5   Hu Chunming   初次提交,代码大体完成编写,完善中
39
40
41
42
43
44
45
46
47
48
49
50
51
          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;
          }
  
4061a3c3   Hu Chunming   更换decoder
52
          data_type = 0;
6fdcb6a5   Hu Chunming   初次提交,代码大体完成编写,完善中
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
          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;
          }
      }
  
4061a3c3   Hu Chunming   更换decoder
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
      HostData* memCpy2Host() {
          HostData* hostData = new HostData(getWidth(), getWidthStride(), getHeight(), getHeightStride(), getSize(), getId());
          int _size = getSize();
          int ret = aclrtMemcpy(hostData->pData, getSize(), getMem(), getSize(), ACL_MEMCPY_DEVICE_TO_HOST);
          if(ret != ACL_ERROR_NONE){
              LOG_ERROR("[{}]- aclrtMemcpy failed", getId());
              return nullptr;
          }
  
          return hostData;
      }
  
      virtual DeviceMemory* clone() {
          DvppDataMemory* pData = new DvppDataMemory(this);
          return pData;
      }
  
6fdcb6a5   Hu Chunming   初次提交,代码大体完成编写,完善中
88
89
90
91
92
  public:
      int data_type;  // 0: rgb , 1: NV12
  };
  
  
4061a3c3   Hu Chunming   更换decoder
93
94
  // typedef std::shared_ptr<DvppDataMemory> DvppDataMemoryPtr;
  
6fdcb6a5   Hu Chunming   初次提交,代码大体完成编写,完善中
95
  #endif      // __DVPP_DATA_MEMORY_HPP__