2023-02-08 18:12:00 +01:00
|
|
|
/* AVB support */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2022 Wim Taymans */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2022-04-05 18:10:27 +02:00
|
|
|
|
|
|
|
|
#ifndef AVB_STREAM_H
|
|
|
|
|
#define AVB_STREAM_H
|
|
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <linux/if_packet.h>
|
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
|
|
#include <spa/utils/ringbuffer.h>
|
|
|
|
|
#include <spa/param/audio/format.h>
|
2026-05-31 15:06:14 +02:00
|
|
|
#include <spa/node/io.h>
|
|
|
|
|
|
|
|
|
|
#include "mc-recover.h"
|
|
|
|
|
#include "play-loop.h"
|
2022-04-05 18:10:27 +02:00
|
|
|
|
|
|
|
|
#include <pipewire/pipewire.h>
|
|
|
|
|
|
|
|
|
|
#define BUFFER_SIZE (1u<<16)
|
|
|
|
|
#define BUFFER_MASK (BUFFER_SIZE-1)
|
|
|
|
|
|
|
|
|
|
struct stream {
|
|
|
|
|
struct spa_list link;
|
|
|
|
|
|
|
|
|
|
struct server *server;
|
|
|
|
|
|
|
|
|
|
uint16_t direction;
|
2026-04-25 07:31:15 +02:00
|
|
|
uint16_t index;
|
2022-04-05 18:10:27 +02:00
|
|
|
uint64_t id;
|
|
|
|
|
|
|
|
|
|
struct pw_stream *stream;
|
|
|
|
|
struct spa_hook stream_listener;
|
|
|
|
|
|
2026-03-15 10:21:03 +01:00
|
|
|
uint64_t peer_id;
|
2022-04-05 18:10:27 +02:00
|
|
|
uint8_t addr[6];
|
2026-03-15 10:21:03 +01:00
|
|
|
int vlan_id;
|
|
|
|
|
|
2022-04-05 18:10:27 +02:00
|
|
|
struct spa_source *source;
|
2026-04-26 16:19:29 +02:00
|
|
|
struct spa_source *flush_timer;
|
|
|
|
|
uint64_t flush_last_ns;
|
2026-05-28 11:45:00 +00:00
|
|
|
bool is_crf;
|
2026-05-31 15:06:14 +02:00
|
|
|
uint64_t next_txtime;
|
2022-04-05 18:10:27 +02:00
|
|
|
int prio;
|
|
|
|
|
int mtt;
|
|
|
|
|
int t_uncertainty;
|
|
|
|
|
uint32_t frames_per_pdu;
|
|
|
|
|
int ptime_tolerance;
|
|
|
|
|
|
|
|
|
|
uint8_t pdu[2048];
|
|
|
|
|
size_t hdr_size;
|
|
|
|
|
size_t payload_size;
|
|
|
|
|
size_t pdu_size;
|
|
|
|
|
int64_t pdu_period;
|
|
|
|
|
uint8_t pdu_seq;
|
|
|
|
|
uint8_t prev_seq;
|
2022-04-08 10:34:23 +02:00
|
|
|
uint8_t dbc;
|
2022-04-05 18:10:27 +02:00
|
|
|
|
|
|
|
|
struct iovec iov[3];
|
|
|
|
|
struct sockaddr_ll sock_addr;
|
|
|
|
|
struct msghdr msg;
|
|
|
|
|
char control[CMSG_SPACE(sizeof(uint64_t))];
|
|
|
|
|
struct cmsghdr *cmsg;
|
|
|
|
|
|
|
|
|
|
struct spa_ringbuffer ring;
|
|
|
|
|
void *buffer_data;
|
|
|
|
|
size_t buffer_size;
|
|
|
|
|
|
|
|
|
|
uint64_t format;
|
|
|
|
|
uint32_t stride;
|
|
|
|
|
struct spa_audio_info info;
|
2026-05-31 15:06:14 +02:00
|
|
|
|
|
|
|
|
/* milan-avb: AAF media-clock recovery (listener / STREAM_INPUT only).
|
|
|
|
|
* Active only while the CLOCK_DOMAIN selects the AAF (INPUT_STREAM)
|
|
|
|
|
* clock source whose location points at this stream. Estimator state in
|
|
|
|
|
* struct mc_recover (mc-recover.h); recovered from avtp_timestamp deltas. */
|
|
|
|
|
bool mc_aaf_active;
|
|
|
|
|
struct mc_recover mc;
|
|
|
|
|
|
|
|
|
|
/* milan-avb: actuator I/O areas (set via .io_changed). io_rate_match is the
|
|
|
|
|
* resampler knob — NULL unless the adapter inserted a resampler. */
|
|
|
|
|
struct spa_io_rate_match *io_rate_match;
|
|
|
|
|
struct spa_io_position *io_position;
|
|
|
|
|
|
|
|
|
|
/* milan-avb: previous 1 Hz sample for the local consume-rate log. */
|
|
|
|
|
uint64_t play_last_consume_tai;
|
|
|
|
|
uint64_t play_last_ticks;
|
|
|
|
|
uint64_t play_log_last_ns;
|
|
|
|
|
bool play_primed;
|
|
|
|
|
|
|
|
|
|
/* milan-avb: actuator state; servos the ring to play_target (play-loop.h). */
|
|
|
|
|
struct play_loop play;
|
|
|
|
|
int32_t play_target;
|
|
|
|
|
|
|
|
|
|
/* milan-avb: optional raw PCM dump for offline analysis (THDN, waveform). */
|
|
|
|
|
FILE *raw_dump_fp;
|
|
|
|
|
size_t raw_dump_bytes;
|
2022-04-05 18:10:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#include "msrp.h"
|
|
|
|
|
#include "mvrp.h"
|
2022-04-06 12:58:47 +02:00
|
|
|
#include "maap.h"
|
2022-04-05 18:10:27 +02:00
|
|
|
|
2025-11-27 09:37:37 +01:00
|
|
|
struct stream *server_create_stream(struct server *server, struct stream *stream,
|
2022-04-05 18:10:27 +02:00
|
|
|
enum spa_direction direction, uint16_t index);
|
|
|
|
|
|
|
|
|
|
void stream_destroy(struct stream *stream);
|
|
|
|
|
|
2025-11-27 09:37:37 +01:00
|
|
|
int stream_activate(struct stream *stream, uint16_t index, uint64_t now);
|
2022-04-05 18:10:27 +02:00
|
|
|
int stream_deactivate(struct stream *stream, uint64_t now);
|
2026-04-07 17:39:04 -04:00
|
|
|
int stream_activate_virtual(struct stream *stream, uint16_t index);
|
2022-04-05 18:10:27 +02:00
|
|
|
|
2026-05-31 15:06:14 +02:00
|
|
|
/* milan-avb: re-evaluate each input stream's media-clock recovery against the
|
|
|
|
|
* current CLOCK_DOMAIN selection. Call after SET_CLOCK_SOURCE for on-the-fly
|
|
|
|
|
* clock-source switching. */
|
|
|
|
|
void avb_stream_update_clock_source(struct server *server);
|
|
|
|
|
|
2022-04-05 18:10:27 +02:00
|
|
|
#endif /* AVB_STREAM_H */
|