My Project
TelemetryDisplay.h
1 // Copyright 2023 DreamWorks Animation LLC
2 // SPDX-License-Identifier: Apache-2.0
3 #pragma once
4 
5 #include "TelemetryLayout.h"
6 #include "TelemetryOverlay.h"
7 
8 #include <mcrt_dataio/engine/merger/GlobalNodeInfo.h>
9 #include <mcrt_dataio/share/util/FloatValueTracker.h>
10 #include <mcrt_messages/BaseFrame.h>
11 #include <scene_rdl2/common/grid_util/Parser.h>
12 #include <scene_rdl2/common/rec_time/RecTime.h>
13 
14 #include <memory>
15 #include <unordered_map>
16 
17 namespace mcrt_dataio {
18 namespace telemetry {
19 
21 {
22 public:
23  unsigned mOverlayWidth {0};
24  unsigned mOverlayHeight {0};
25 
26  unsigned mImageWidth {0};
27  unsigned mImageHeight {0};
28 
29  size_t mViewId {0};
30  uint32_t mFrameId {0};
31  mcrt::BaseFrame::Status mStatus {mcrt::BaseFrame::FINISHED};
32  float mRenderPrepProgress {0.0f};
33  float mProgress {0.0f};
34  unsigned mFbActivityCounter {0};
35  unsigned mDecodeProgressiveFrameCounter {0};
36  bool mIsCoarsePass {true};
37  float mCurrentLatencySec {0.0f};
38  float mReceiveImageDataFps {0.0f};
39 
40  const GlobalNodeInfo* mGlobalNodeInfo {nullptr};
41 
42  //------------------------------
43 
44  std::string show() const;
45 };
46 
47 class Display
48 {
49 public:
50  using Arg = scene_rdl2::grid_util::Arg;
51  using Parser = scene_rdl2::grid_util::Parser;
52  using Align = Overlay::Align;
53 
54  Display() { parserConfigure(); };
55 
56  void setActive(bool sw) { mActive = sw; }
57  bool getActive() const { return mActive; }
58 
59  void bakeOverlayRgb888(std::vector<unsigned char>& rgbFrame,
60  const bool top2bottomFlag,
61  const DisplayInfo& info,
62  bool bakeWithPrevArchive);
63 
64  void switchLayoutNext() { switchLayoutToNextOnTheList(); }
65 
66  Parser& getParser() { return mParser; }
67 
68  std::string show() const;
69 
70 private:
71 
72  void setupLayout();
73  bool setupFont();
74  bool setupTestFont();
75  unsigned calcFontSize() const;
76 
77  void testBakeOverlayRgb888(const DisplayInfo& info,
78  std::vector<unsigned char>& rgbFrame,
79  const bool top2bottomFlag,
80  bool bakeWithPrevArchive);
81  bool stdBakeOverlayRgb888(const DisplayInfo& info,
82  std::vector<unsigned char>& rgbFrame,
83  const bool top2bottomFlag,
84  bool bakeWithPrevArchive);
85 
86  void drawOverlay(const DisplayInfo& info);
87 
88  void finalizeOverlayRgb888(const DisplayInfo& info,
89  std::vector<unsigned char>& rgbFrame,
90  const bool top2bottomFlag,
91  Align hAlign,
92  Align vAlign,
93  bool bakeWithPrevArchive);
94  void copyArchive(std::vector<unsigned char>& rgbFrame) const;
95  void clearBgArchive();
96 
97  void switchLayoutByName(const std::string& name,
98  const std::function<void(const std::string& msg)>);
99  void switchLayoutToNextOnTheList();
100 
101  void parserConfigure();
102 
103  std::string showTestInfo() const;
104  std::string showAlign(Align align) const;
105  std::string showLayoutNameList() const;
106  std::string showCurrentLayoutName() const;
107  std::string showTimingProfile() const;
108  void resetTimingProfile();
109 
110  //------------------------------
111 
112  bool mActive {false};
113  bool mDoParallel {true};
114  bool mTimingProfile {false};
115  bool mTestMode {false};
116 
117  unsigned mOverwriteWidth {0}; // telemetry overlay size overwrite value
118  unsigned mOverwriteHeight {0}; // telemetry overlay size overwrite value
119 
120  std::shared_ptr<Overlay> mOverlay;
121  std::shared_ptr<Font> mFont;
122 
123  std::vector<unsigned char> mBgArchive; // initially empty
124 
125  std::string mError;
126 
127  //
128  // overlay data layout
129  //
130  std::shared_ptr<LayoutBase> mCurrLayout;
131  std::unordered_map<std::string, std::shared_ptr<LayoutBase>> mLayoutMap;
132 
133  //
134  // test parameters
135  //
136  std::unique_ptr<Font> mTestFont;
137  unsigned mTestStrX {0};
138  unsigned mTestStrY {0};
139  unsigned mTestStrCol[3] {255, 255, 255};
140  unsigned mTestBgCol[4] {0, 0, 0, 0};
141  std::string mTestMsg {"This is a test"};
142  std::string mTestFontTTFFileName {"/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf"};
143  int mTestFontPoint {12};
144  Align mTestHAlign {Align::MIDDLE};
145  Align mTestVAlign {Align::MIDDLE};
146 
147  //
148  // for timing profile
149  //
150  scene_rdl2::rec_time::RecTime mRecTime;
151  FloatValueTracker mOverlayClear {64}; // sec : keep 64 events total
152  FloatValueTracker mDrawStrTime {64}; // sec : keep 64 events total
153  FloatValueTracker mCopyArchiveTime {64}; // sec : keep 64 events total
154  FloatValueTracker mFinalizeRgb888Time {64}; // sec : keep 64 events total
155 
156  Parser mParser;
157 };
158 
159 } // namespace telemetry
160 } // namespace mcrt_dataio
Definition: TelemetryDisplay.h:20
Definition: TelemetryDisplay.h:47
Definition: ClientReceiverConsoleDriver.cc:9