chromium/media/midi/midi_manager_alsa.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/midi/midi_manager_alsa.h"

#include <errno.h>
#include <poll.h>
#include <stddef.h>
#include <stdlib.h>

#include <string>
#include <utility>

#include "base/functional/bind.h"
#include "base/json/json_string_value_serializer.h"
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
#include "base/posix/safe_strerror.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "crypto/sha2.h"
#include "media/midi/midi_service.h"
#include "media/midi/midi_service.mojom.h"
#include "media/midi/task_service.h"

namespace midi {

namespace {

PortState;
Result;

enum {};

// Per-output buffer. This can be smaller, but then large sysex messages
// will be (harmlessly) split across multiple seq events. This should
// not have any real practical effect, except perhaps to slightly reorder
// realtime messages with respect to sysex.
constexpr size_t kSendBufferSize =;

// Minimum client id for which we will have ALSA card devices for. When we
// are searching for card devices (used to get the path, id, and manufacturer),
// we don't want to get confused by kernel clients that do not have a card.
// See seq_clientmgr.c in the ALSA code for this.
// TODO(agoode): Add proper client -> card export from the kernel to avoid
//               hardcoding.
constexpr int kMinimumClientIdForCards =;

// ALSA constants.
const char kAlsaHw[] =;

// udev constants.
const char kUdev[] =;
const char kUdevSubsystemSound[] =;
const char kUdevPropertySoundInitialized[] =;
const char kUdevActionChange[] =;
const char kUdevActionRemove[] =;

const char kUdevIdVendor[] =;
const char kUdevIdVendorEnc[] =;
const char kUdevIdVendorFromDatabase[] =;
const char kUdevIdVendorId[] =;
const char kUdevIdModelId[] =;
const char kUdevIdBus[] =;
const char kUdevIdPath[] =;
const char kUdevIdUsbInterfaceNum[] =;
const char kUdevIdSerialShort[] =;

const char kSysattrVendorName[] =;
const char kSysattrVendor[] =;
const char kSysattrModel[] =;
const char kSysattrGuid[] =;

const char kCardSyspath[] =;

// Constants for the capabilities we search for in inputs and outputs.
// See http://www.alsa-project.org/alsa-doc/alsa-lib/seq.html.
constexpr unsigned int kRequiredInputPortCaps =;
constexpr unsigned int kRequiredOutputPortCaps =;

constexpr unsigned int kCreateOutputPortCaps =;
constexpr unsigned int kCreateInputPortCaps =;
constexpr unsigned int kCreatePortType =;

int AddrToInt(int client, int port) {}

// Returns true if this client has an ALSA card associated with it.
bool IsCardClient(snd_seq_client_type_t type, int client_id) {}

// TODO(agoode): Move this to device/udev_linux.
const std::string UdevDeviceGetPropertyOrSysattr(
    struct udev_device* udev_device,
    const char* property_key,
    const char* sysattr_key) {}

int GetCardNumber(udev_device* dev) {}

std::string GetVendor(udev_device* dev) {}

void SetStringIfNonEmpty(base::Value::Dict* value,
                         const std::string& path,
                         const std::string& in_value) {}

}  // namespace

MidiManagerAlsa::MidiManagerAlsa(MidiService* service) :{}

MidiManagerAlsa::~MidiManagerAlsa() {}

void MidiManagerAlsa::StartInitialization() {}

void MidiManagerAlsa::DispatchSendMidiData(MidiManagerClient* client,
                                           uint32_t port_index,
                                           const std::vector<uint8_t>& data,
                                           base::TimeTicks timestamp) {}

MidiManagerAlsa::MidiPort::Id::Id() = default;

MidiManagerAlsa::MidiPort::Id::Id(const std::string& bus,
                                  const std::string& vendor_id,
                                  const std::string& model_id,
                                  const std::string& usb_interface_num,
                                  const std::string& serial)
    :{}

MidiManagerAlsa::MidiPort::Id::Id(const Id&) = default;

MidiManagerAlsa::MidiPort::Id::~Id() = default;

bool MidiManagerAlsa::MidiPort::Id::operator==(const Id& rhs) const {}

bool MidiManagerAlsa::MidiPort::Id::empty() const {}

MidiManagerAlsa::MidiPort::MidiPort(const std::string& path,
                                    const Id& id,
                                    int client_id,
                                    int port_id,
                                    int midi_device,
                                    const std::string& client_name,
                                    const std::string& port_name,
                                    const std::string& manufacturer,
                                    const std::string& version,
                                    Type type)
    :{}

MidiManagerAlsa::MidiPort::~MidiPort() = default;

// Note: keep synchronized with the MidiPort::Match* methods.
std::unique_ptr<base::Value::Dict> MidiManagerAlsa::MidiPort::Value() const {}

std::string MidiManagerAlsa::MidiPort::JSONValue() const {}

// TODO(agoode): Do not use SHA256 here. Instead store a persistent
//               mapping and just use a UUID or other random string.
//               http://crbug.com/465320
std::string MidiManagerAlsa::MidiPort::OpaqueKey() const {}

bool MidiManagerAlsa::MidiPort::MatchConnected(const MidiPort& query) const {}

bool MidiManagerAlsa::MidiPort::MatchCardPass1(const MidiPort& query) const {}

bool MidiManagerAlsa::MidiPort::MatchCardPass2(const MidiPort& query) const {}

bool MidiManagerAlsa::MidiPort::MatchNoCardPass1(const MidiPort& query) const {}

bool MidiManagerAlsa::MidiPort::MatchNoCardPass2(const MidiPort& query) const {}

MidiManagerAlsa::MidiPortStateBase::~MidiPortStateBase() = default;

MidiManagerAlsa::MidiPortStateBase::iterator
MidiManagerAlsa::MidiPortStateBase::Find(
    const MidiManagerAlsa::MidiPort& port) {}

MidiManagerAlsa::MidiPortStateBase::iterator
MidiManagerAlsa::MidiPortStateBase::FindConnected(
    const MidiManagerAlsa::MidiPort& port) {}

MidiManagerAlsa::MidiPortStateBase::iterator
MidiManagerAlsa::MidiPortStateBase::FindDisconnected(
    const MidiManagerAlsa::MidiPort& port) {}

MidiManagerAlsa::MidiPortStateBase::MidiPortStateBase() = default;

MidiManagerAlsa::MidiPortState::MidiPortState() = default;

uint32_t MidiManagerAlsa::MidiPortState::push_back(
    std::unique_ptr<MidiPort> port) {}

MidiManagerAlsa::AlsaSeqState::AlsaSeqState() = default;

MidiManagerAlsa::AlsaSeqState::~AlsaSeqState() = default;

void MidiManagerAlsa::AlsaSeqState::ClientStart(int client_id,
                                                const std::string& client_name,
                                                snd_seq_client_type_t type) {}

bool MidiManagerAlsa::AlsaSeqState::ClientStarted(int client_id) {}

void MidiManagerAlsa::AlsaSeqState::ClientExit(int client_id) {}

void MidiManagerAlsa::AlsaSeqState::PortStart(
    int client_id,
    int port_id,
    const std::string& port_name,
    MidiManagerAlsa::AlsaSeqState::PortDirection direction,
    bool midi) {}

void MidiManagerAlsa::AlsaSeqState::PortExit(int client_id, int port_id) {}

snd_seq_client_type_t MidiManagerAlsa::AlsaSeqState::ClientType(
    int client_id) const {}

std::unique_ptr<MidiManagerAlsa::TemporaryMidiPortState>
MidiManagerAlsa::AlsaSeqState::ToMidiPortState(const AlsaCardMap& alsa_cards) {}

MidiManagerAlsa::AlsaSeqState::Port::Port(
    const std::string& name,
    MidiManagerAlsa::AlsaSeqState::PortDirection direction,
    bool midi)
    :{}

MidiManagerAlsa::AlsaSeqState::Port::~Port() = default;

MidiManagerAlsa::AlsaSeqState::Client::Client(const std::string& name,
                                              snd_seq_client_type_t type)
    :{}

MidiManagerAlsa::AlsaSeqState::Client::~Client() = default;

void MidiManagerAlsa::AlsaSeqState::Client::AddPort(
    int addr,
    std::unique_ptr<Port> port) {}

void MidiManagerAlsa::AlsaSeqState::Client::RemovePort(int addr) {}

MidiManagerAlsa::AlsaSeqState::Client::PortMap::const_iterator
MidiManagerAlsa::AlsaSeqState::Client::begin() const {}

MidiManagerAlsa::AlsaSeqState::Client::PortMap::const_iterator
MidiManagerAlsa::AlsaSeqState::Client::end() const {}

MidiManagerAlsa::AlsaCard::AlsaCard(udev_device* dev,
                                    const std::string& name,
                                    const std::string& longname,
                                    const std::string& driver,
                                    int midi_device_count)
    :{}

MidiManagerAlsa::AlsaCard::~AlsaCard() = default;

// static
std::string MidiManagerAlsa::AlsaCard::ExtractManufacturerString(
    const std::string& udev_id_vendor,
    const std::string& udev_id_vendor_id,
    const std::string& udev_id_vendor_from_database,
    const std::string& alsa_name,
    const std::string& alsa_longname) {}

void MidiManagerAlsa::SendMidiData(MidiManagerClient* client,
                                   uint32_t port_index,
                                   const std::vector<uint8_t>& data) {}

void MidiManagerAlsa::EventLoop() {}

void MidiManagerAlsa::ProcessSingleEvent(snd_seq_event_t* event,
                                         base::TimeTicks timestamp) {}

void MidiManagerAlsa::ProcessClientStartEvent(int client_id) {}

void MidiManagerAlsa::ProcessPortStartEvent(const snd_seq_addr_t& addr) {}

void MidiManagerAlsa::ProcessClientExitEvent(const snd_seq_addr_t& addr) {}

void MidiManagerAlsa::ProcessPortExitEvent(const snd_seq_addr_t& addr) {}

void MidiManagerAlsa::ProcessUdevEvent(udev_device* dev) {}

void MidiManagerAlsa::AddCard(udev_device* dev) {}

void MidiManagerAlsa::RemoveCard(int number) {}

void MidiManagerAlsa::UpdatePortStateAndGenerateEvents() {}

// TODO(agoode): return false on failure.
void MidiManagerAlsa::EnumerateAlsaPorts() {}

bool MidiManagerAlsa::EnumerateUdevCards() {}

bool MidiManagerAlsa::CreateAlsaOutputPort(uint32_t port_index,
                                           int client_id,
                                           int port_id) {}

void MidiManagerAlsa::DeleteAlsaOutputPort(uint32_t port_index) {}

bool MidiManagerAlsa::Subscribe(uint32_t port_index,
                                int client_id,
                                int port_id) {}

MidiManagerAlsa::ScopedSndMidiEventPtr
MidiManagerAlsa::CreateScopedSndMidiEventPtr(size_t size) {}

MidiManager* MidiManager::Create(MidiService* service) {}

}  // namespace midi