Skip to content

Commit

Permalink
Output mostly working
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanreg committed Nov 16, 2023
1 parent 3937bf7 commit b36328e
Show file tree
Hide file tree
Showing 36 changed files with 2,317 additions and 840 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# AVTransport
This repository hosts the AVTransport container/media transmission protocol, and the reference implementation code.

Expand Down Expand Up @@ -32,7 +31,7 @@ If `transport` is not specified, the *udp* transport method shall be assumed. `t
Alternatively, for UDP-only, the `udp://<address>:<port>` URI scheme can be used, at the risk of conflict with other protocols (`MPEG-TS`).

### File extension
The `.at` or `.avt` file extensions shall be used.
The `.avt` file extensions should be used.

## Links
You can talk about the project and get in touch with developers on:
Expand Down
142 changes: 80 additions & 62 deletions draft-avtransport-spec.bs

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions libavtransport/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# libavtransport

The reference code for the implementation of the AVTransport protocol can be found here.

The code is a fully usable and optimized library, rather than simply being a reference,
and contains tools for manipulating AVTransport streams and files.
The library is also embeddable into different projects.

The output graph is as follows:

External API -> output.c -> encode.c -> avtransport.c -> connection.c -> protocol_noop.c -> io_file.c
116 changes: 3 additions & 113 deletions libavtransport/avtransport.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
#include <stdlib.h>
#include <string.h>

#include <arpa/inet.h>
#include <netdb.h>

#include <libavtransport/avtransport.h>
#include <avtransport/avtransport.h>

#include "common.h"

Expand Down Expand Up @@ -59,113 +56,6 @@ void avt_close(AVTContext **ctx)
}
}

int avt_parse_address(const char *path, enum AVTProtocolType *proto,
uint8_t dst_ip[16], uint16_t *dst_port)
{
int native_uri = 0;

/* Zero out output */
*proto = AVT_UNKNOWN;
dst_ip = (uint8_t [16]){ 0 };
*dst_port = 0;

char *dup = strdup(path);
if (!dup)
return AVT_ERROR(ENOMEM);

char *tmp = NULL;
char *scheme = strtok_r(dup, ":", &tmp);
if (!strcmp(scheme, "avt")) {
native_uri = 1;
} else if (!strcmp(scheme, "udp")) { /* Unofficial and conflicting, but let's accept it */
*proto = AVT_UDP;
} else if (!strcmp(scheme, "quic")) { /* Unofficial, but let's accept it */
*proto = AVT_QUIC;
} else {
free(dup);
return AVT_ERROR(ENOTSUP);
}

char *addr_pre = strtok_r(scheme, ":", &tmp);
if (!strcmp(addr_pre, "//") && (addr_pre[2])) {
addr_pre += 2;
} else { /* Error out if there's no :// */
free(dup);
return AVT_ERROR(ENOTSUP);
}

if (native_uri) {
char *transport = strtok_r(addr_pre, "@", &tmp);
char *serv = strtok_r(transport, "@", &tmp);
if (!serv)
addr_pre = transport;
}

if (addr_pre[0]) {
} else if (addr_pre[0] == '[') {
tmp = NULL;
char *endb = strtok_r(addr_pre, "]", &tmp);

struct in6_addr dst_6 = { 0 };
int ret = inet_pton(AF_INET6, endb, &dst_6);
if (!ret)
endb = strtok_r(addr_pre, "]", &tmp);

if (ret || !endb) {
free(dup);
return AVT_ERROR(EINVAL);
}

memcpy(dst_ip, dst_6.s6_addr, 16);

if (addr_pre[0] == ':') {
char *res = NULL;
*dst_port = strtol(addr_pre + 1, &res, 10);
if (res) {
free(dup);
return AVT_ERROR(EINVAL);
}
}

free(dup);
return 0;
}

/* Attempt to convert and parse the IP address as IPv4 in IPv6 */
char *addr = strtok_r(addr_pre, ":", &tmp);
char addr_temp[32] = { "::FFFF:" };
memcpy(addr_temp + strlen(addr_temp), addr, strlen(addr));
addr_temp[31] = '\0';

struct in6_addr dst_4 = { 0 };
int ret = inet_pton(AF_INET6, addr_temp, &dst_4);
if (ret) {
int error;
struct addrinfo hints = { 0 }, *res = NULL;
const char *service = "0";

char *sport = strtok_r(addr_pre, ":", &tmp);
if (sport[0])
sport += 1; /* Skip : */

hints.ai_socktype = SOCK_DGRAM;
hints.ai_family = AF_INET6;
hints.ai_flags = 0;
if ((error = getaddrinfo(addr, service, &hints, &res))) {
free(dup);
return AVT_ERROR(EINVAL);
}

memcpy(dst_ip, res->ai_addr, res->ai_addrlen);
} else {
memcpy(dst_ip, dst_4.s6_addr, 16);
}

free(dup);

return 0;
}

AVTStream *avt_alloc_stream(AVTContext *ctx, uint16_t id)
{
if (!ctx->output.ctx)
Expand All @@ -181,8 +71,8 @@ AVTStream *avt_alloc_stream(AVTContext *ctx, uint16_t id)
if (!ret)
return NULL;

ret->private = calloc(1, sizeof(*ret->private));
if (!ret->private) {
ret->priv = calloc(1, sizeof(*ret->priv));
if (!ret->priv) {
free(ret);
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion libavtransport/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#include <stdatomic.h>

#include <libavtransport/utils.h>
#include <avtransport/utils.h>

struct AVTBuffer {
uint8_t *data;
Expand Down
16 changes: 8 additions & 8 deletions libavtransport/bytestream.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef LIBAVTRANSPORT_BYTESTREAM
#define LIBAVTRANSPORT_BYTESTREAM
#ifndef AVTRANSPORT_BYTESTREAM
#define AVTRANSPORT_BYTESTREAM

#include <stdint.h>
#include <string.h>

#include <libavtransport/utils.h>
#include <libavtransport/rational.h>
#include <avtransport/utils.h>
#include <avtransport/rational.h>
#include "utils.h"

#ifndef AVT_RB8
Expand Down Expand Up @@ -180,7 +180,7 @@
} while(0)
#endif

#if CONFIG_BIG_ENDIAN
#ifdef CONFIG_BIG_ENDIAN
#define AVT_RN(p, l) AVT_RB##l(p)
#define AVT_WN(p, l, v) AVT_WB##l(p, v)
#else
Expand All @@ -195,7 +195,7 @@ typedef struct AVTBytestream {
} AVTBytestream;

/* Initialize bytestream for reading or writing */
AVTBytestream inline avt_bs_init(uint8_t *buf, size_t len)
static AVTBytestream inline avt_bs_init(uint8_t *buf, size_t len)
{
return (AVTBytestream) {
.start = buf,
Expand Down Expand Up @@ -270,7 +270,7 @@ static void inline avt_bsw_sbuf(AVTBytestream *bs, char8_t *buf, const size_t le
/* Write fixed-length zero-terminated string to bytestream */
static void inline avt_bsw_fstr(AVTBytestream *bs, const char *str, const size_t fixed_len)
{
size_t lens = AVT_MIN(strlen(str), fixed_len - 1);
size_t lens = AVT_MIN(strlen(str), fixed_len);
avt_assert1(((bs->ptr) + fixed_len) <= bs->end);
memcpy(bs->ptr, str, lens);
memset(bs->ptr, 0, fixed_len - lens);
Expand All @@ -291,7 +291,7 @@ static size_t inline avt_bs_offs(AVTBytestream *bs)
#define AVT_RDR(base_read, e, len, s) \
static inline uint ##len## _t avt_bsr_##e##len(AVTBytestream *bs) \
{ \
uint ##len## _t v; \
uint ##len## _t v = 0; \
if ((bs)->ptr + (len >> 3) <= (bs)->end) { \
v = base_read##len((bs)->ptr); \
(bs)->ptr += len >> 3; \
Expand Down
21 changes: 3 additions & 18 deletions libavtransport/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,15 @@

#include <stdatomic.h>

#include <libavtransport/avtransport.h>

enum AVTProtocolType {
AVT_UNKNOWN,
AVT_UDP,
AVT_QUIC,
};
#include <avtransport/avtransport.h>

typedef struct AVTStreamPriv {
enum AVTCodecID codec_id;
} AVTStreamPriv;

struct AVTContext {
struct AVTOutput *out;

struct {
AVTConnection **conn;
int nb_conn;
Expand All @@ -65,18 +61,7 @@ struct AVTContext {
AVTContextOptions opts;
};

int avt_parse_address(const char *path, enum AVTProtocolType *proto,
uint8_t dst_ip[16], uint16_t *dst_port);

AVTStream *avt_alloc_stream(AVTContext *ctx, uint16_t id);
AVTStream *avt_find_stream(AVTContext *ctx, uint16_t id);

#if defined(__GNUC__) || defined(__clang__)
#define avt_printf_format(fmtpos, attrpos) __attribute__((__format__(__printf__, fmtpos, attrpos)))
#else
#define avt_printf_format(fmtpos, attrpos)
#endif

void avt_log(void *ctx, enum AVTLogLevel level, const char *fmt, ...) avt_printf_format(3, 4);

#endif
Loading

0 comments on commit b36328e

Please sign in to comment.