1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HOS_BUFFER_TRACKING_H 17 #define HOS_BUFFER_TRACKING_H 18 19 #include "buffer_trace.h" 20 #include <memory> 21 22 #define PIPELINE_REPORT_BUFFER_LOCATION(I, F, N) TRACKING_REPORT_BUFFER_LOCATION(I, F, N, false); 23 24 #define POOL_REPORT_BUFFER_LOCATION(I, F) TRACKING_REPORT_BUFFER_LOCATION(I, F, "", true); 25 26 #define TRACKING_REPORT_BUFFER_LOCATION(I, F, N, R) \ 27 do { \ 28 auto m = std::make_shared<BufferTrackingMessage>(); \ 29 m->trackingId = I; \ 30 m->frameNumber = F; \ 31 m->nodeName = N; \ 32 m->isReturnBack = R; \ 33 BufferTracking::ReportBufferLocation(m); \ 34 } while (0); 35 36 namespace OHOS::Camera { 37 class BufferTracking { 38 public: 39 // begin to track a stream, call AddTrackingNode to add node after this function. 40 // trackingId can be steam id, poolId is id of buffer pool which in SinkNode. 41 static void AddTrackingStreamBegin(const int32_t trackingId, const int64_t poolId); 42 43 // add node complete, call this before StartTracking, after AddTrackingNode. 44 static void AddTrackingStreamEnd(const int32_t trackingId); 45 46 // disable tracking a stream 47 static void DeleteTrackingStream(const int32_t trackingId); 48 49 // append node to tracking list, call this before AddTrackingStreamEnd, after AddTrackingStreamBegin. 50 static void AddTrackingNode(const int32_t trackingId, const std::string node); 51 52 /* report location of a buffer, after this buffer has been delivered to a node or pool. 53 * report report report report report report 54 * | | | | | | 55 * BUFFERPOOL---->SOURCENODE----->NODE----->NODE----->NODE---->SINKNODE---->BUFFERPOOL 56 */ 57 static void ReportBufferLocation(const std::shared_ptr<BufferTrackingMessage>& message); 58 59 // start a thread to tracking buffers of a stream. 60 static void StartTracking(); 61 62 // stop stacking 63 static void StopTracking(); 64 65 // check if there are buffers in a specific node. 66 static int32_t IsNodeEmpty(const int32_t id, const std::string node); 67 68 // check if there are buffers from beginNode to endNode. 69 static int32_t IsNodeEmpty(const int32_t id, const std::string beginNode, const std::string endNode); 70 71 static void DumpBufferTrace(const int32_t id, BufferTraceGraph& graph); 72 }; 73 } // namespace OHOS::Camera 74 #endif 75