From 9ea409bed03a40cb0ae140c90a037a72ffc28e06 Mon Sep 17 00:00:00 2001 From: Lynne Date: Tue, 5 Dec 2023 15:39:35 +0100 Subject: [PATCH] Spec fixes, io_file fixes --- draft-avtransport-spec.bs | 12 ++++----- libavtransport/io_common.h | 10 +++----- libavtransport/io_file.c | 45 ++++++++++++++++++++++++++-------- libavtransport/io_null.c | 22 ++++++++++++++--- libavtransport/protocol_noop.c | 6 ++--- 5 files changed, 67 insertions(+), 28 deletions(-) diff --git a/draft-avtransport-spec.bs b/draft-avtransport-spec.bs index 8217344..fe31286 100644 --- a/draft-avtransport-spec.bs +++ b/draft-avtransport-spec.bs @@ -6,7 +6,7 @@ Shortname: avtransport URL: https://cyanreg.github.io/avtransport/ Repository: https://github.com/cyanreg/avtransport Inline Github Issues: no -Date: 2023-11-17 +Date: now Status: LD Group: FFmpeg Abstract: The AVTransport protocol is a new standardized mechanism for multimedia transport and storage. @@ -2409,13 +2409,13 @@ The [=colorspace=] field must be interpreted in the following way: : CSP_ICTCP = 0x5 :: Video contains [[BT2100]] ICtCp color data. : CSP_BAYER_BGGR = 0x6 - :: Video contains raw CMOS voltages, from 4x4 cells with a pattern 'Blue', 'Green', 'Green', 'Red', in raster-order. + :: Video contains raw CMOS voltages, from 4x4 cells with a pattern ''Blue'', ''Green'', ''Green'', ''Red'', in raster-order. : CSP_BAYER_RGGB = 0x7 - :: Same as above, with a 'Red', 'Green', 'Green', 'Blue' order. + :: Same as above, with a ''Red'', ''Green'', ''Green'', ''Blue'' order. : CSP_BAYER_GBRG = 0x8 - :: Same as above, with a 'Green', 'Blue', 'Red', 'Green' order. + :: Same as above, with a ''Green'', ''Blue'', ''Red'', ''Green'' order. : CSP_BAYER_GRBG = 0x9 - :: Same as above, with a 'Green', 'Red', 'Blue', 'Green' order. + :: Same as above, with a ''Green'', ''Red'', ''Blue'', ''Green'' order. @@ -3263,7 +3263,7 @@ The `packet_data` must contain raw FLAC frames, with their frame header untouche For [[AV1]] encapsulation, the [=codec_id=] in [[#stream-registration-packets]] -must be ''0x41563031'' (''AV01''). +must be ''0x41563031'' (AV01). The [[#stream-configuration-packets]] payload MUST be the codec's so-called ''uncompressed header''. For information on its syntax, diff --git a/libavtransport/io_common.h b/libavtransport/io_common.h index c8e4e0a..aa4e335 100644 --- a/libavtransport/io_common.h +++ b/libavtransport/io_common.h @@ -46,13 +46,13 @@ typedef struct AVTIO { int (*init)(AVTContext *ctx, AVTIOCtx **io, AVTAddress *addr); + uint32_t (*get_max_pkt_len)(AVTContext *ctx, struct AVTIOCtx *io); + /* Attempt to add a secondary destination, NULL if unsupported */ int (*add_dst)(AVTContext *ctx, AVTIOCtx *io, AVTAddress *addr); /* Removes a secondary destination, NULL if unsupported */ - int (*rm_dst)(AVTContext *ctx, AVTIOCtx *io, AVTAddress *addr); - - uint32_t (*get_max_pkt_len)(AVTContext *ctx, struct AVTIOCtx *io); + int (*del_dst)(AVTContext *ctx, AVTIOCtx *io, AVTAddress *addr); /* Write. Returns positive offset on success, otherwise negative error */ int64_t (*write_output)(AVTContext *ctx, AVTIOCtx *io, @@ -69,9 +69,7 @@ typedef struct AVTIO { /* If only off is set, get the first packet at/after that offset. * If pts is set, get the stream data packet at/after the pts time * If seq is set, the get first packet at/after that seq */ - int64_t (*seek)(AVTContext *ctx, AVTIOCtx *io, - int64_t off, uint32_t seq, - int64_t ts, bool ts_is_dts); + int64_t (*seek)(AVTContext *ctx, AVTIOCtx *io, int64_t off); /* Flush data written */ int (*flush)(AVTContext *ctx, AVTIOCtx *io); diff --git a/libavtransport/io_file.c b/libavtransport/io_file.c index 344234d..59aae74 100644 --- a/libavtransport/io_file.c +++ b/libavtransport/io_file.c @@ -34,6 +34,9 @@ struct AVTIOCtx { FILE *f; + off_t rpos; + off_t wpos; + int is_write; }; static int handle_error(AVTIOCtx *io, const char *msg) @@ -71,27 +74,36 @@ static uint32_t file_max_pkt_len(AVTContext *ctx, AVTIOCtx *io) static int64_t file_read_input(AVTContext *ctx, AVTIOCtx *io, AVTBuffer **_buf, size_t len) { - int err; + int ret; uint8_t *data; size_t buf_len, off = 0; AVTBuffer *buf = *_buf; + if (io->is_write) { + ret = fseeko(io->f, io->rpos, SEEK_SET); + if (ret < 0) { + ret = handle_error(io, "Error seeking: %s\n"); + return ret; + } + io->is_write = 0; + } + if (!buf) { buf = avt_buffer_alloc(len); if (!buf) return AVT_ERROR(ENOMEM); } else { off = avt_buffer_get_data_len(buf); - err = avt_buffer_realloc(buf, len); - if (err < 0) - return err; + ret = avt_buffer_realloc(buf, len); + if (ret < 0) + return ret; } data = avt_buffer_get_data(buf, &buf_len); len = AVT_MIN(len, buf_len - off); fread(data + off, 1, len, io->f); - return (int64_t)ftello(io->f); + return (int64_t)(io->rpos = ftello(io->f)); } static int64_t file_write_output(AVTContext *ctx, AVTIOCtx *io, @@ -102,6 +114,15 @@ static int64_t file_write_output(AVTContext *ctx, AVTIOCtx *io, size_t len; uint8_t *data = avt_buffer_get_data(payload, &len); + if (!io->is_write) { + ret = fseeko(io->f, io->wpos, SEEK_SET); + if (ret < 0) { + ret = handle_error(io, "Error seeking: %s\n"); + return ret; + } + io->is_write = 1; + } + size_t out = fwrite(hdr, 1, hdr_len, io->f); if (out != hdr_len) { ret = handle_error(io, "Error writing: %s\n"); @@ -117,14 +138,18 @@ static int64_t file_write_output(AVTContext *ctx, AVTIOCtx *io, } fflush(io->f); - return (int64_t)ftello(io->f); + return (int64_t)(io->wpos = ftello(io->f)); } -static int64_t file_seek(AVTContext *ctx, AVTIOCtx *io, - int64_t off, uint32_t seq, - int64_t ts, bool ts_is_dts) +static int64_t file_seek(AVTContext *ctx, AVTIOCtx *io, int64_t off) { - return (int64_t)ftello(io->f); + int ret = fseeko(io->f, (off_t)off, SEEK_SET); + if (ret < 0) { + ret = handle_error(io, "Error seeking: %s\n"); + return ret; + } + io->is_write = 0; + return (int64_t)(io->rpos = ftello(io->f)); } static int file_flush(AVTContext *ctx, AVTIOCtx *io) diff --git a/libavtransport/io_null.c b/libavtransport/io_null.c index 058a523..f4931cb 100644 --- a/libavtransport/io_null.c +++ b/libavtransport/io_null.c @@ -59,6 +59,16 @@ static uint32_t null_max_pkt_len(AVTContext *ctx, AVTIOCtx *io) return UINT32_MAX; } +static int null_add_dst(AVTContext *ctx, AVTIOCtx *io, AVTAddress *addr) +{ + return 0; +} + +static int null_del_dst(AVTContext *ctx, AVTIOCtx *io, AVTAddress *addr) +{ + return 0; +} + static int64_t null_input(AVTContext *ctx, AVTIOCtx *io, AVTBuffer **buf, size_t len) { @@ -93,13 +103,16 @@ static int64_t null_output(AVTContext *ctx, AVTIOCtx *io, return atomic_fetch_add(&io->pos_w, hdr_len + avt_buffer_get_data_len(payload)); } -static int64_t null_seek(AVTContext *ctx, AVTIOCtx *io, - int64_t off, uint32_t seq, - int64_t ts, bool ts_is_dts) +static int64_t null_seek(AVTContext *ctx, AVTIOCtx *io, int64_t off) { return atomic_load(&io->pos_r); } +static int null_flush(AVTContext *ctx, AVTIOCtx *io) +{ + return 0; +} + static int null_close(AVTContext *ctx, AVTIOCtx **_io) { AVTIOCtx *io = *_io; @@ -113,8 +126,11 @@ const AVTIO avt_io_null = { .type = AVT_IO_NULL, .init = null_init, .get_max_pkt_len = null_max_pkt_len, + .add_dst = null_add_dst, + .del_dst = null_del_dst, .read_input = null_input, .write_output = null_output, .seek = null_seek, + .flush = null_flush, .close = null_close, }; diff --git a/libavtransport/protocol_noop.c b/libavtransport/protocol_noop.c index e46ce41..ff82094 100644 --- a/libavtransport/protocol_noop.c +++ b/libavtransport/protocol_noop.c @@ -60,9 +60,9 @@ static int noop_add_dst(AVTContext *ctx, AVTProtocolCtx *p, AVTAddress *addr) static int noop_rm_dst(AVTContext *ctx, AVTProtocolCtx *p, AVTAddress *addr) { - if (!p->io->rm_dst) + if (!p->io->del_dst) return AVT_ERROR(ENOTSUP); - return p->io->rm_dst(ctx, p->io_ctx, addr); + return p->io->del_dst(ctx, p->io_ctx, addr); } static int64_t noop_send_packet(AVTContext *ctx, AVTProtocolCtx *p, @@ -109,7 +109,7 @@ static int64_t noop_seek(AVTContext *ctx, AVTProtocolCtx *p, int64_t off, uint32_t seq, int64_t ts, bool ts_is_dts) { - return p->io->seek(ctx, p->io_ctx, off, seq, ts, ts_is_dts); + return p->io->seek(ctx, p->io_ctx, off); } static int noop_flush(AVTContext *ctx, AVTProtocolCtx *p)