| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of the Falcon Player (FPP) and is Copyright (C) | ||
| 3 | * 2013-2026 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 LGPL v2.1 as described in the | ||
| 10 | * included LICENSE.LGPL file. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "fpp-pch.h" | ||
| 14 | |||
| 15 | #include "fpp-json.h" | ||
| 16 | #include "log.h" | ||
| 17 | |||
| 18 | #include "AudioSourceRegistry.h" | ||
| 19 | |||
| 20 | AudioSourceRegistry AudioSourceRegistry::INSTANCE; | ||
| 21 | |||
| 22 | 3 | void AudioSourceRegistry::registerSource(const AudioSource& src) { | |
| 23 |
5/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
|
3 | if (src.id.empty() || src.nodeName.empty()) { |
| 24 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogWarn(VB_MEDIAOUT, "AudioSourceRegistry: ignoring source with empty id or nodeName (plugin: %s)\n", |
| 25 | src.plugin.c_str()); | ||
| 26 | 2 | return; | |
| 27 | } | ||
| 28 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | std::unique_lock<std::mutex> lock(m_mutex); |
| 29 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | for (auto& s : m_sources) { |
| 30 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (s.id == src.id) { |
| 31 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | s = src; |
| 32 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogDebug(VB_MEDIAOUT, "AudioSourceRegistry: updated source '%s' (node: %s)\n", |
| 33 | src.id.c_str(), src.nodeName.c_str()); | ||
| 34 | 1 | return; | |
| 35 | } | ||
| 36 | } | ||
| 37 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | m_sources.push_back(src); |
| 38 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogInfo(VB_MEDIAOUT, "AudioSourceRegistry: registered source '%s' (node: %s, plugin: %s)\n", |
| 39 | src.id.c_str(), src.nodeName.c_str(), src.plugin.c_str()); | ||
| 40 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | } |
| 41 | |||
| 42 | ✗ | void AudioSourceRegistry::unregisterSource(const std::string& id) { | |
| 43 | ✗ | std::unique_lock<std::mutex> lock(m_mutex); | |
| 44 | ✗ | for (auto it = m_sources.begin(); it != m_sources.end(); ++it) { | |
| 45 | ✗ | if (it->id == id) { | |
| 46 | ✗ | LogInfo(VB_MEDIAOUT, "AudioSourceRegistry: unregistered source '%s'\n", id.c_str()); | |
| 47 | ✗ | m_sources.erase(it); | |
| 48 | ✗ | return; | |
| 49 | } | ||
| 50 | } | ||
| 51 | ✗ | } | |
| 52 | |||
| 53 | 1 | void AudioSourceRegistry::unregisterPluginSources(const std::string& plugin) { | |
| 54 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::unique_lock<std::mutex> lock(m_mutex); |
| 55 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | m_sources.erase(std::remove_if(m_sources.begin(), m_sources.end(), |
| 56 | 1 | [&plugin](const AudioSource& s) { return s.plugin == plugin; }), | |
| 57 | 1 | m_sources.end()); | |
| 58 | 1 | } | |
| 59 | |||
| 60 | 2 | Json::Value AudioSourceRegistry::toJson() const { | |
| 61 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | std::unique_lock<std::mutex> lock(m_mutex); |
| 62 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | Json::Value result; |
| 63 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | result["sources"] = Json::Value(Json::arrayValue); |
| 64 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | for (const auto& s : m_sources) { |
| 65 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | Json::Value j; |
| 66 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | j["id"] = s.id; |
| 67 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | j["name"] = s.name; |
| 68 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | j["nodeName"] = s.nodeName; |
| 69 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | j["plugin"] = s.plugin; |
| 70 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | j["channels"] = s.channels; |
| 71 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | j["sampleRate"] = s.sampleRate; |
| 72 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | result["sources"].append(j); |
| 73 | 2 | } | |
| 74 | 2 | return result; | |
| 75 | 2 | } | |
| 76 |