Skip to content

Commit

Permalink
Spec fixes, io_file fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanreg committed Dec 5, 2023
1 parent 682cf88 commit 9ea409b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 28 deletions.
12 changes: 6 additions & 6 deletions draft-avtransport-spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -2409,13 +2409,13 @@ The [=colorspace=] field must be interpreted in the following way:
: <dfn>CSP_ICTCP</dfn> = <i>0x5</i>
:: Video contains [[BT2100]] ICtCp color data.
: <dfn>CSP_BAYER_BGGR</dfn> = <i>0x6</i>
:: 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.
: <dfn>CSP_BAYER_RGGB</dfn> = <i>0x7</i>
:: Same as above, with a 'Red', 'Green', 'Green', 'Blue' order.
:: Same as above, with a ''Red'', ''Green'', ''Green'', ''Blue'' order.
: <dfn>CSP_BAYER_GBRG</dfn> = <i>0x8</i>
:: Same as above, with a 'Green', 'Blue', 'Red', 'Green' order.
:: Same as above, with a ''Green'', ''Blue'', ''Red'', ''Green'' order.
: <dfn>CSP_BAYER_GRBG</dfn> = <i>0x9</i>
:: Same as above, with a 'Green', 'Red', 'Blue', 'Green' order.
:: Same as above, with a ''Green'', ''Red'', ''Blue'', ''Green'' order.
</div>


Expand Down Expand Up @@ -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'' (<code>AV01</code>).

The [[#stream-configuration-packets]] payload MUST be the
codec's so-called ''uncompressed header''. For information on its syntax,
Expand Down
10 changes: 4 additions & 6 deletions libavtransport/io_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
45 changes: 35 additions & 10 deletions libavtransport/io_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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");
Expand All @@ -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)
Expand Down
22 changes: 19 additions & 3 deletions libavtransport/io_null.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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,
};
6 changes: 3 additions & 3 deletions libavtransport/protocol_noop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9ea409b

Please sign in to comment.