diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-01-26 18:32:32 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-01-26 18:32:32 +1100 |
| commit | 7b60f5f864997e94895305f23ed2716ad7d9acaa (patch) | |
| tree | dc1a6d0f366bcbf8ee05070765fa91ffef7720eb /src/audio/stream_info.cpp | |
| parent | 3696512b387ceefd25c00830fb24ddd073c06e2c (diff) | |
| download | tangara-fw-7b60f5f864997e94895305f23ed2716ad7d9acaa.tar.gz | |
Make StreamInfo a PDO
Diffstat (limited to 'src/audio/stream_info.cpp')
| -rw-r--r-- | src/audio/stream_info.cpp | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/src/audio/stream_info.cpp b/src/audio/stream_info.cpp deleted file mode 100644 index 8f217b79..00000000 --- a/src/audio/stream_info.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "stream_info.hpp" - -#include <cstdint> -#include <string> - -#include "cbor.h" - -#include "stream_message.hpp" - -namespace audio { - -static const std::string kKeyPath = "p"; -static const std::string kKeyChannels = "c"; -static const std::string kKeyBitsPerSample = "b"; -static const std::string kKeySampleRate = "r"; - -auto StreamInfo::Parse(CborValue& container) - -> cpp::result<StreamInfo, CborError> { - CborValue map; - cbor_value_enter_container(&container, &map); - - CborValue entry; - StreamInfo ret; - - cbor_value_map_find_value(&map, kKeyPath.c_str(), &entry); - if (cbor_value_get_type(&entry) != CborInvalidType) { - char* val; - size_t len; - cbor_value_dup_text_string(&entry, &val, &len, NULL); - ret.path_ = std::string(val, len); - free(val); - } - cbor_value_map_find_value(&map, kKeyChannels.c_str(), &entry); - if (cbor_value_get_type(&entry) != CborInvalidType) { - uint64_t val; - cbor_value_get_uint64(&entry, &val); - ret.channels_ = val; - } - cbor_value_map_find_value(&map, kKeyBitsPerSample.c_str(), &entry); - if (cbor_value_get_type(&entry) != CborInvalidType) { - uint64_t val; - cbor_value_get_uint64(&entry, &val); - ret.bits_per_sample_ = val; - } - cbor_value_map_find_value(&map, kKeySampleRate.c_str(), &entry); - if (cbor_value_get_type(&entry) != CborInvalidType) { - uint64_t val; - cbor_value_get_uint64(&entry, &val); - ret.sample_rate_ = val; - } - - return ret; -} - -auto StreamInfo::Encode(CborEncoder& enc) -> std::optional<CborError> { - CborEncoder map; - size_t num_items = 0 + channels_.has_value() + bits_per_sample_.has_value() + - sample_rate_.has_value() + path_.has_value(); - cbor_encoder_create_map(&enc, &map, num_items); - - if (channels_) { - cbor_encode_text_string(&map, kKeyChannels.c_str(), kKeyChannels.size()); - cbor_encode_uint(&map, channels_.value()); - } - if (bits_per_sample_) { - cbor_encode_text_string(&map, kKeyBitsPerSample.c_str(), - kKeyBitsPerSample.size()); - cbor_encode_uint(&map, bits_per_sample_.value()); - } - if (sample_rate_) { - cbor_encode_text_string(&map, kKeySampleRate.c_str(), - kKeySampleRate.size()); - cbor_encode_uint(&map, sample_rate_.value()); - } - if (path_) { - cbor_encode_text_string(&map, kKeyPath.c_str(), kKeyPath.size()); - cbor_encode_text_string(&map, path_.value().c_str(), path_.value().size()); - } - - cbor_encoder_close_container(&enc, &map); - - return std::nullopt; -} - -} // namespace audio |
