| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of the Falcon Player (FPP) and is Copyright (C) | ||
| 3 | * 2013-2022 by the Falcon Player Developers. | ||
| 4 | * | ||
| 5 | * The Falcon Player (FPP) is free software, and is covered under | ||
| 6 | * multiple Open Source licenses. Please see the included 'LICENSES' | ||
| 7 | * file for descriptions of what files are covered by each license. | ||
| 8 | * | ||
| 9 | * This source file is covered under the GPL v2 as described in the | ||
| 10 | * included LICENSE.GPL file. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "fpp-pch.h" | ||
| 14 | |||
| 15 | #include "fpp-json.h" | ||
| 16 | |||
| 17 | #include "../common.h" | ||
| 18 | #include "../log.h" | ||
| 19 | |||
| 20 | #include "FBMatrix.h" | ||
| 21 | #include "ChannelOutputSetup.h" | ||
| 22 | #include "overlays/PixelOverlay.h" | ||
| 23 | #include "overlays/PixelOverlayModelSub.h" | ||
| 24 | |||
| 25 | #include "../Plugin.h" | ||
| 26 | |||
| 27 | class FBMatrixPlugin : public FPPPlugins::Plugin, public FPPPlugins::ChannelOutputPlugin { | ||
| 28 | public: | ||
| 29 | 18 | FBMatrixPlugin() : | |
| 30 |
2/4✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
|
54 | FPPPlugins::Plugin("FBMatrix") { |
| 31 | 18 | } | |
| 32 | 27 | virtual ChannelOutput* createChannelOutput(unsigned int startChannel, unsigned int channelCount) override { | |
| 33 |
2/6✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 27 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
54 | return new FBMatrixOutput(startChannel, channelCount); |
| 34 | } | ||
| 35 | }; | ||
| 36 | |||
| 37 | extern "C" { | ||
| 38 | 18 | FPPPlugins::Plugin* createPlugin() { | |
| 39 |
2/6✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
36 | return new FBMatrixPlugin(); |
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | /* | ||
| 44 | * | ||
| 45 | */ | ||
| 46 | 27 | FBMatrixOutput::FBMatrixOutput(unsigned int startChannel, | |
| 47 | 27 | unsigned int channelCount) : | |
| 48 | 27 | ChannelOutput(startChannel, channelCount) { | |
| 49 |
1/2✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
|
27 | LogDebug(VB_CHANNELOUT, "FBMatrixOutput::FBMatrixOutput(%u, %u)\n", |
| 50 | startChannel, channelCount); | ||
| 51 | 27 | } | |
| 52 | |||
| 53 | /* | ||
| 54 | * | ||
| 55 | */ | ||
| 56 | 108 | FBMatrixOutput::~FBMatrixOutput() { | |
| 57 | 54 | LogDebug(VB_CHANNELOUT, "FBMatrixOutput::~FBMatrixOutput()\n"); | |
| 58 | |||
| 59 | // Close() normally does this, but Init() can return failure after the | ||
| 60 | // listener is registered, and a failed output is deleted without a Close(). | ||
| 61 | // A listener left pointing at a freed FBMatrixOutput is the very bug this | ||
| 62 | // is here to prevent, one level up. | ||
| 63 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 24 times.
|
54 | if (!m_modelListenerName.empty()) { |
| 64 | 6 | PixelOverlayManager::INSTANCE.removeModelListener(modelName, m_modelListenerName); | |
| 65 | 6 | m_modelListenerName.clear(); | |
| 66 | } | ||
| 67 | |||
| 68 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 3 times.
|
54 | if (buffer) |
| 69 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
48 | delete[] buffer; |
| 70 | 108 | } | |
| 71 | |||
| 72 | 27 | int FBMatrixOutput::Init(Json::Value config) { | |
| 73 | 27 | LogDebug(VB_CHANNELOUT, "FBMatrixOutput::Init()\n"); | |
| 74 | |||
| 75 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 20 times.
|
27 | if (config.isMember("modelName")) |
| 76 |
2/4✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
7 | modelName = config["modelName"].asString(); |
| 77 | |||
| 78 | 27 | LogDebug(VB_CHANNELOUT, "FBMatrix::Init: modelName='%s', empty=%d\n", modelName.c_str(), modelName == ""); | |
| 79 | |||
| 80 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 7 times.
|
27 | if (modelName == "") { |
| 81 | 20 | int width = 0; | |
| 82 | 20 | int height = 0; | |
| 83 | 20 | std::string device; | |
| 84 | |||
| 85 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | if ((config.isMember("width")) && |
| 86 |
4/8✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
|
40 | (config.isMember("height")) && |
| 87 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | (config.isMember("device"))) { |
| 88 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | width = config["width"].asInt(); |
| 89 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | height = config["height"].asInt(); |
| 90 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | device = config["device"].asString(); |
| 91 | |||
| 92 |
3/6✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
60 | replaceStart(device, "/dev/"); |
| 93 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | modelName = "FB - "; |
| 94 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | modelName += device; |
| 95 | |||
| 96 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | LogDebug(VB_CHANNELOUT, "FBMatrix: Checking for existing model '%s', hasModel=%d\n", |
| 97 | modelName.c_str(), PixelOverlayManager::INSTANCE.getModel(modelName) != nullptr); | ||
| 98 | |||
| 99 | // Delete existing model if it exists, so we can recreate with PixelSize | ||
| 100 |
3/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 18 times.
|
20 | if (PixelOverlayManager::INSTANCE.getModel(modelName)) { |
| 101 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | LogDebug(VB_CHANNELOUT, "FBMatrix: Removing existing model '%s' to recreate with PixelSize\n", modelName.c_str()); |
| 102 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | PixelOverlayManager::INSTANCE.removeAutoOverlayModel(modelName); |
| 103 | } | ||
| 104 | |||
| 105 |
5/10✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 20 times.
✗ Branch 9 not taken.
|
20 | if (width && height && (device != "")) { |
| 106 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | Json::Value val; |
| 107 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | val["Name"] = modelName; |
| 108 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | val["Type"] = "FB"; |
| 109 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | val["Width"] = width; |
| 110 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | val["Height"] = height; |
| 111 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | val["Device"] = device; |
| 112 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | val["autoCreated"] = true; |
| 113 | |||
| 114 | // Pass through pixelSize if specified in config | ||
| 115 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
|
20 | if (config.isMember("pixelSize")) { |
| 116 | ✗ | int ps = config["pixelSize"].asInt(); | |
| 117 | ✗ | val["PixelSize"] = ps; | |
| 118 | ✗ | LogDebug(VB_CHANNELOUT, "FBMatrix: Setting PixelSize=%d for model '%s'\n", ps, modelName.c_str()); | |
| 119 | } else { | ||
| 120 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | LogDebug(VB_CHANNELOUT, "FBMatrix: No pixelSize in config for model '%s'\n", modelName.c_str()); |
| 121 | } | ||
| 122 | |||
| 123 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | PixelOverlayManager::INSTANCE.addModel(val); |
| 124 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | m_autoCreatedFBModelName = modelName; |
| 125 | 20 | } else { | |
| 126 | ✗ | LogErr(VB_CHANNELOUT, "Empty Pixel Overlay Model name\n"); | |
| 127 | ✗ | AddOutputConfigWarning(35, "VirtualMatrix: Empty Pixel Overlay Model name"); | |
| 128 | ✗ | return 0; | |
| 129 | } | ||
| 130 | } else { | ||
| 131 | ✗ | LogErr(VB_CHANNELOUT, "Empty Pixel Overlay Model name\n"); | |
| 132 | ✗ | AddOutputConfigWarning(35, "VirtualMatrix: Empty Pixel Overlay Model name"); | |
| 133 | ✗ | return 0; | |
| 134 | } | ||
| 135 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | } |
| 136 | |||
| 137 | // Track the model rather than caching a bare pointer: an auto-created FB | ||
| 138 | // model is destroyed by removeAutoOverlayModel() whenever the outputs are | ||
| 139 | // reloaded, and the channel output thread can be inside PrepData()/ | ||
| 140 | // SendData() at that moment. | ||
| 141 |
2/4✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✗ Branch 3 not taken.
|
27 | m_modelListenerName = "FBMatrix" + std::to_string((uintptr_t)this); |
| 142 |
1/2✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
|
27 | PixelOverlayManager::INSTANCE.addModelListener(modelName, m_modelListenerName, |
| 143 | 27 | [this](PixelOverlayModel* m) { | |
| 144 |
1/2✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
|
14 | std::lock_guard<std::mutex> lock(m_modelLock); |
| 145 | // buffer is sized for the model we saw in Init(), and SendData() | ||
| 146 | // hands it to model->setData(), which copies the *model's* | ||
| 147 | // width * height worth of bytes out of it. A model re-created | ||
| 148 | // under the same name with other dimensions (a second | ||
| 149 | // VirtualMatrix on the same device, whose Init() replaces | ||
| 150 | // "FB - <device>") would turn that into a heap over-read, so only | ||
| 151 | // follow a replacement that still matches this output. | ||
| 152 |
7/8✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 13 times.
|
14 | if (m && (m->getWidth() != width || m->getHeight() != height)) { |
| 153 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogWarn(VB_CHANNELOUT, "FBMatrix: model '%s' is now %dx%d, this output is %dx%d; detaching\n", |
| 154 | modelName.c_str(), m->getWidth(), m->getHeight(), width, height); | ||
| 155 | 1 | m = nullptr; | |
| 156 | } | ||
| 157 | 14 | model = m; | |
| 158 | 14 | }); | |
| 159 | 27 | model = PixelOverlayManager::INSTANCE.getModel(modelName); | |
| 160 | |||
| 161 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 26 times.
|
27 | if (!model) { |
| 162 | 1 | LogErr(VB_CHANNELOUT, "Invalid Pixel Overlay Model: '%s'\n", modelName.c_str()); | |
| 163 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | AddOutputConfigWarning(35, "VirtualMatrix: Invalid Pixel Overlay Model: " + modelName); |
| 164 | 1 | return 0; | |
| 165 | } | ||
| 166 | |||
| 167 | // A submodel draws through its parent, and only a framebuffer draws from | ||
| 168 | // SendData(): any other parent, or a grid submodel (which scatters to | ||
| 169 | // channels), would write sequence channels after the outputs ahead of | ||
| 170 | // this one had sent them. A parent not loaded yet is checked when it | ||
| 171 | // arrives (PixelOverlayModelSub::readyForPassThrough()). | ||
| 172 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 22 times.
|
26 | if (model->getType() == "Sub") { |
| 173 | 4 | std::string why; | |
| 174 | 4 | PixelOverlayModel* root = model; | |
| 175 |
6/8✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 4 times.
|
8 | for (int depth = 0; root && root->getType() == "Sub"; depth++) { |
| 176 | 4 | PixelOverlayModelSub* s = static_cast<PixelOverlayModelSub*>(root); | |
| 177 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (s->isGridMode()) { |
| 178 | ✗ | why = "is an xLights submodel, which a Virtual Matrix cannot draw"; | |
| 179 | ✗ | break; | |
| 180 | } | ||
| 181 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (depth >= 16) { |
| 182 | ✗ | why = "has a parent chain that leads back to it"; | |
| 183 | ✗ | break; | |
| 184 | } | ||
| 185 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | root = PixelOverlayManager::INSTANCE.getModel(s->getParentName()); |
| 186 | } | ||
| 187 |
7/10✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 3 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 3 times.
|
4 | if (why.empty() && root && root->getType() != "FB") { |
| 188 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | why = "is a submodel of '" + root->getName() + "', which is not a framebuffer"; |
| 189 | } | ||
| 190 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | if (!why.empty()) { |
| 191 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogErr(VB_CHANNELOUT, "Pixel Overlay Model '%s' %s\n", modelName.c_str(), why.c_str()); |
| 192 |
4/8✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
1 | AddOutputConfigWarning(35, "VirtualMatrix: model " + modelName + " " + why); |
| 193 | 1 | model = nullptr; | |
| 194 | 1 | return 0; | |
| 195 | } | ||
| 196 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | } |
| 197 | |||
| 198 | // buffer is 3 byte RGB and SendData() hands it to setData(), which reads | ||
| 199 | // the model's own bytes per pixel (4 for an RGBW submodel) | ||
| 200 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 24 times.
|
25 | if (model->getBytesPerPixel() != 3) { |
| 201 | 1 | LogErr(VB_CHANNELOUT, "Pixel Overlay Model '%s' is not RGB\n", modelName.c_str()); | |
| 202 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | AddOutputConfigWarning(35, "VirtualMatrix: model " + modelName + " is not an RGB model"); |
| 203 | 1 | model = nullptr; | |
| 204 | 1 | return 0; | |
| 205 | } | ||
| 206 | |||
| 207 | 24 | width = model->getWidth(); | |
| 208 | 24 | height = model->getHeight(); | |
| 209 | |||
| 210 | // Calculate channel count from the model size | ||
| 211 | 24 | m_channelCount = width * height * 3; | |
| 212 | |||
| 213 | 24 | inverted = config["invert"].asInt(); | |
| 214 | 24 | flipHorizontal = config["flipHorizontal"].asInt(); | |
| 215 | |||
| 216 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | if (m_channelCount != (width * height * 3)) { |
| 217 | ✗ | LogErr(VB_CHANNELOUT, "Error, channel count is incorrect\n"); | |
| 218 | ✗ | AddOutputConfigWarning(35, "VirtualMatrix: Invalid Pixel Overlay Model: " + modelName); | |
| 219 | ✗ | return 0; | |
| 220 | } | ||
| 221 | |||
| 222 | 24 | buffer = new unsigned char[width * height * 3]; | |
| 223 | |||
| 224 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 5 times.
|
24 | if (PixelOverlayManager::INSTANCE.isAutoCreatePixelOverlayModels()) { |
| 225 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | std::string dd = "VirtualMatrix"; |
| 226 |
3/4✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 15 times.
|
19 | if (config.isMember("description")) { |
| 227 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | dd = config["description"].asString(); |
| 228 | } | ||
| 229 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | std::string desc = dd; |
| 230 | 19 | int count = 0; | |
| 231 |
3/4✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 19 times.
|
23 | while (PixelOverlayManager::INSTANCE.getModel(desc) != nullptr) { |
| 232 | 4 | count++; | |
| 233 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | desc = dd + "-" + std::to_string(count); |
| 234 | } | ||
| 235 |
4/8✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 19 times.
✗ Branch 7 not taken.
|
95 | PixelOverlayManager::INSTANCE.addAutoOverlayModel(desc, |
| 236 | m_startChannel, m_channelCount, 3, | ||
| 237 | "H", "TL", | ||
| 238 | 19 | height, 1); | |
| 239 |
1/2✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
|
19 | m_autoCreatedModelName = desc; |
| 240 | 19 | } | |
| 241 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | return ChannelOutput::Init(config); |
| 242 | } | ||
| 243 | |||
| 244 | /* | ||
| 245 | * | ||
| 246 | */ | ||
| 247 | 24 | int FBMatrixOutput::Close(void) { | |
| 248 | 24 | LogDebug(VB_CHANNELOUT, "FBMatrixOutput::Close()\n"); | |
| 249 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (!m_modelListenerName.empty()) { |
| 250 | 24 | PixelOverlayManager::INSTANCE.removeModelListener(modelName, m_modelListenerName); | |
| 251 | 24 | m_modelListenerName.clear(); | |
| 252 | } | ||
| 253 | { | ||
| 254 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | std::lock_guard<std::mutex> lock(m_modelLock); |
| 255 | 24 | model = nullptr; | |
| 256 | 24 | } | |
| 257 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 5 times.
|
24 | if (!m_autoCreatedModelName.empty()) { |
| 258 | 19 | PixelOverlayManager::INSTANCE.removeAutoOverlayModel(m_autoCreatedModelName); | |
| 259 | } | ||
| 260 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 4 times.
|
24 | if (!m_autoCreatedFBModelName.empty()) { |
| 261 | 20 | PixelOverlayManager::INSTANCE.removeAutoOverlayModel(m_autoCreatedFBModelName); | |
| 262 | } | ||
| 263 | 24 | return ChannelOutput::Close(); | |
| 264 | } | ||
| 265 | |||
| 266 | 2421 | void FBMatrixOutput::PrepData(unsigned char* channelData) { | |
| 267 |
1/2✓ Branch 0 taken 2421 times.
✗ Branch 1 not taken.
|
2421 | std::lock_guard<std::mutex> lock(m_modelLock); |
| 268 |
3/4✓ Branch 0 taken 2354 times.
✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2354 times.
|
2421 | if (!model || !buffer) { |
| 269 | 67 | return; | |
| 270 | } | ||
| 271 | 2354 | channelData += m_startChannel; | |
| 272 | |||
| 273 |
1/2✓ Branch 0 taken 2354 times.
✗ Branch 1 not taken.
|
2354 | LogExcess(VB_CHANNELOUT, "FBMatrixOutput::SendData(%p)\n", |
| 274 | channelData); | ||
| 275 | |||
| 276 | 2354 | int stride = width * 3; | |
| 277 | |||
| 278 |
2/2✓ Branch 0 taken 80120 times.
✓ Branch 1 taken 2354 times.
|
82474 | for (int y = 0; y < height; y++) { |
| 279 | 80120 | unsigned char* src = channelData + (y * stride); | |
| 280 | // Vertical flip: write source row y into the mirrored destination row | ||
| 281 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 80120 times.
|
80120 | int dstRow = inverted ? (height - 1 - y) : y; |
| 282 | 80120 | unsigned char* dst = buffer + (dstRow * stride); | |
| 283 | |||
| 284 |
2/2✓ Branch 0 taken 608 times.
✓ Branch 1 taken 79512 times.
|
80120 | if (flipHorizontal) { |
| 285 | // Horizontal flip: reverse the pixel order within the row | ||
| 286 | 608 | unsigned char* sp = src; | |
| 287 | 608 | unsigned char* dp = dst + ((width - 1) * 3); | |
| 288 |
2/2✓ Branch 0 taken 38912 times.
✓ Branch 1 taken 608 times.
|
39520 | for (int x = 0; x < width; x++) { |
| 289 | 38912 | dp[0] = sp[0]; | |
| 290 | 38912 | dp[1] = sp[1]; | |
| 291 | 38912 | dp[2] = sp[2]; | |
| 292 | 38912 | sp += 3; | |
| 293 | 38912 | dp -= 3; | |
| 294 | } | ||
| 295 | } else { | ||
| 296 | 79512 | memcpy(dst, src, stride); | |
| 297 | } | ||
| 298 | } | ||
| 299 |
2/2✓ Branch 0 taken 2354 times.
✓ Branch 1 taken 67 times.
|
2421 | } |
| 300 | |||
| 301 | 2390 | int FBMatrixOutput::SendData(unsigned char* channelData) { | |
| 302 |
1/2✓ Branch 0 taken 2390 times.
✗ Branch 1 not taken.
|
2390 | std::lock_guard<std::mutex> lock(m_modelLock); |
| 303 |
3/4✓ Branch 0 taken 2325 times.
✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2325 times.
|
2390 | if (!model || !buffer) { |
| 304 | 65 | return m_channelCount; | |
| 305 | } | ||
| 306 |
2/4✓ Branch 0 taken 2325 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2325 times.
✗ Branch 3 not taken.
|
2325 | if (model->getState() == 0) { |
| 307 | // Pass-through mode: the model isn't being driven by an active | ||
| 308 | // overlay/effect, so push the current sequence channels into it | ||
| 309 | // and draw to the framebuffer right here. | ||
| 310 |
1/2✓ Branch 0 taken 2325 times.
✗ Branch 1 not taken.
|
2325 | model->setData(buffer); |
| 311 | // doOverlay() takes the whole sequence buffer: a submodel's parent | ||
| 312 | // writes at its own absolute channels, and channelData here is this | ||
| 313 | // output's slice, starting m_startChannel in. (A framebuffer model | ||
| 314 | // ignores the argument and draws its own data.) A submodel only | ||
| 315 | // once its parent, found since Init() or re-created, is a framebuffer. | ||
| 316 |
1/2✓ Branch 0 taken 2325 times.
✗ Branch 1 not taken.
|
2325 | PixelOverlayModelSub* sub = dynamic_cast<PixelOverlayModelSub*>(model); |
| 317 |
5/8✓ Branch 0 taken 16 times.
✓ Branch 1 taken 2309 times.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2325 times.
✗ Branch 7 not taken.
|
2325 | if (!sub || sub->readyForPassThrough()) { |
| 318 |
1/2✓ Branch 0 taken 2325 times.
✗ Branch 1 not taken.
|
2325 | model->doOverlay(channelData - m_startChannel); |
| 319 | } | ||
| 320 | } | ||
| 321 | // else: the model is acting as an overlay (e.g., a Pixel Overlay | ||
| 322 | // effect is writing into channelData via flushOverlayBuffer). Don't | ||
| 323 | // call setData here — that would overwrite the effect's data with | ||
| 324 | // m_seqData every frame and leave the framebuffer mostly black. | ||
| 325 | // doOverlays() in ProcessSequenceData() drives the framebuffer in | ||
| 326 | // that case via PixelOverlayModelFB::doOverlay(). | ||
| 327 | 2325 | return m_channelCount; | |
| 328 | 2390 | } | |
| 329 | |||
| 330 | 52 | void FBMatrixOutput::GetRequiredChannelRanges(const std::function<void(int, int)>& addRange) { | |
| 331 | 52 | addRange(m_startChannel, m_startChannel + (width * height * 3) - 1); | |
| 332 | 52 | } | |
| 333 | |||
| 334 | /* | ||
| 335 | * | ||
| 336 | */ | ||
| 337 | 24 | void FBMatrixOutput::DumpConfig(void) { | |
| 338 | 24 | LogDebug(VB_CHANNELOUT, "VirtualMatrixOutput::DumpConfig()\n"); | |
| 339 | 24 | LogDebug(VB_CHANNELOUT, " model : %s\n", modelName.c_str()); | |
| 340 | 24 | LogDebug(VB_CHANNELOUT, " width : %d\n", width); | |
| 341 | 24 | LogDebug(VB_CHANNELOUT, " height : %d\n", height); | |
| 342 | 24 | LogDebug(VB_CHANNELOUT, " flipV : %d\n", inverted); | |
| 343 | 24 | LogDebug(VB_CHANNELOUT, " flipH : %d\n", flipHorizontal); | |
| 344 | 24 | } | |
| 345 |