Skip to content

Commit

Permalink
Update to 0.2 (#40)
Browse files Browse the repository at this point in the history
* Update to 0.2

* Add quick start section to README
  • Loading branch information
gavv authored Feb 19, 2023
1 parent 435d94c commit 8d398f8
Show file tree
Hide file tree
Showing 27 changed files with 1,701 additions and 550 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: build

on:
workflow_dispatch:
repository_dispatch:

pull_request:
branches:
- master
- main
- v*

push:
branches:
- master
- main
- v*
tags:
- v*

repository_dispatch:
workflow_dispatch:

schedule:
- cron: '0 0 * * 1'

Expand Down Expand Up @@ -62,8 +62,8 @@ jobs:
- name: Install system dependencies
run: >
sudo apt-get -y install g++ pkg-config scons ragel gengetopt \
libuv1-dev libunwind-dev libpulse-dev libsox-dev libcpputest-dev libtool \
intltool autoconf automake make cmake
libuv1-dev libunwind-dev libspeexdsp-dev libsox-dev libpulse-dev \
libtool intltool autoconf automake make cmake meson
- name: Install Go
uses: actions/setup-go@v3
Expand All @@ -88,6 +88,12 @@ jobs:
cd roc
go test -covermode=count -coverprofile=coverage.out
- name: Run tests with cgocheck
if: ${{ matrix.test == 'yes' }}
run: |
cd roc
GODEBUG=cgocheck=2 go test -count=1 .
- name: Run tests under race detector
if: ${{ matrix.test == 'yes' }}
run: |
Expand Down Expand Up @@ -123,7 +129,8 @@ jobs:
uses: actions/checkout@v3

- name: Install system dependencies
run: brew install scons ragel gengetopt libuv speexdsp sox cpputest
run: |
brew install scons ragel gengetopt libuv speexdsp sox cpputest
- name: Install Go
uses: actions/setup-go@v3
Expand All @@ -146,6 +153,11 @@ jobs:
cd roc
go test
- name: Run tests with cgocheck
run: |
cd roc
GODEBUG=cgocheck=2 go test -count=1 .
- name: Run tests under race detector
run: |
cd roc
Expand Down
10 changes: 10 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ linters:
- govet
- revive
- staticcheck
- exhaustruct
- exportloopref
- lll
- misspell
Expand All @@ -12,5 +13,14 @@ linters:
- unused

linters-settings:
exhaustruct:
include:
- 'roc_.*'
lll:
line-length: 100

issues:
exclude-rules:
- text: '_ is missing'
linters:
- exhaustruct
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019 Roc authors
Copyright (c) 2019 Roc Streaming authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
GO111MODULE := on
export GO111MODULE

all: check test race
all: build lint test

.PHONY: check
check:
build:
cd roc && go build .
cd roc && go test . -run xxx

lint:
cd roc && golangci-lint run .

.PHONY: test
test:
cd roc && go test .

.PHONY: race
race:
cd roc && GODEBUG=cgocheck=2 go test -count=1 .
cd roc && go test -race .

.PHONY: fmt
clean:
cd roc && go clean -cache -testcache

tidy:
cd roc && go mod tidy

fmt:
cd roc && gofmt -s -w .
134 changes: 127 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

This library provides Go (golang) bindings for [Roc Toolkit](https://github.com/roc-streaming/roc-toolkit), a toolkit for real-time audio streaming over the network.

_Work in progress!_

## About Roc

Compatible senders and receivers include:
Expand All @@ -31,6 +29,121 @@ Documentation for the bindings is availabe on [pkg.go.dev](https://pkg.go.dev/gi

Documentation for the underlying C API can be found [here](https://roc-streaming.org/toolkit/docs/api.html).

## Quick start

#### Sender

```go
import (
"github.com/roc-streaming/roc-go/roc"
)

context, err := roc.OpenContext(roc.ContextConfig{})
if err != nil {
panic(err)
}
defer context.Close()

sender, err := roc.OpenSender(roc.SenderConfig{
FrameSampleRate: 44100,
FrameChannels: roc.ChannelSetStereo,
FrameEncoding: roc.FrameEncodingPcmFloat,
FecEncoding: roc.FecEncodingRs8m,
ClockSource: roc.ClockInternal,
})
if err != nil {
panic(err)
}
defer sender.Close()

sourceEndpoint, err := roc.ParseEndpoint("rtp+rs8m://192.168.0.1:10001")
if err != nil {
panic(err)
}

repairEndpoint, err := roc.ParseEndpoint("rs8m://192.168.0.1:10002")
if err != nil {
panic(err)
}

err = sender.Connect(roc.SlotDefault, roc.InterfaceAudioSource, sourceEndpoint)
if err != nil {
panic(err)
}

err = sender.Connect(roc.SlotDefault, roc.InterfaceAudioRepair, repairEndpoint)
if err != nil {
panic(err)
}

for {
samples := make([]float32, 320)

/* fill samples */

err = sender.WriteFloats(samples)
if err != nil {
panic(err)
}
}
```

#### Receiver

```go
import (
"github.com/roc-streaming/roc-go/roc"
)

context, err := roc.OpenContext(roc.ContextConfig{})
if err != nil {
panic(err)
}
defer context.Close()

receiver, err := roc.OpenReceiver(roc.ReceiverConfig{
FrameSampleRate: 44100,
FrameChannels: roc.ChannelSetStereo,
FrameEncoding: roc.FrameEncodingPcmFloat,
ClockSource: roc.ClockInternal,
})
if err != nil {
panic(err)
}
defer receiver.Close()

sourceEndpoint, err := roc.ParseEndpoint("rtp+rs8m://0.0.0.0:10001")
if err != nil {
panic(err)
}

repairEndpoint, err := roc.ParseEndpoint("rs8m://0.0.0.0:10002")
if err != nil {
panic(err)
}

err = receiver.Bind(roc.SlotDefault, roc.InterfaceAudioSource, sourceEndpoint)
if err != nil {
panic(err)
}

err = receiver.Bind(roc.SlotDefault, roc.InterfaceAudioRepair, repairEndpoint)
if err != nil {
panic(err)
}

for {
samples := make([]float32, 320)

err = receiver.ReadFloats(samples)
if err != nil {
panic(err)
}

/* process samples */
}
```

## Versioning

Go bindings and the C library both use [semantic versioning](https://semver.org/).
Expand All @@ -49,7 +162,7 @@ Rules starting from 1.0.0 release:

## Installation

You will need to have Roc Toolkit library and headers installed system-wide. Refer to official build [instructions](https://roc-streaming.org/toolkit/docs/building.html) on how to install libroc. There is no official distribution for any OS as of now, you will need to install from source.
You will need to have Roc Toolkit library and headers installed system-wide. Refer to official build [instructions](https://roc-streaming.org/toolkit/docs/building.html) on how to install libroc from source.

After installing libroc, you can install bindings using regular `go get`:

Expand All @@ -59,17 +172,24 @@ go get github.com/roc-streaming/roc-go/roc

## Development

Check for compilation and linter errors:
Run all checks:

```
make check
make
```

Run tests:
Only run specific checks:

```
make build
make lint
make test
make race # run tests under race detector
```

Update modules:

```
make tidy
```

Format code:
Expand Down
Loading

0 comments on commit 8d398f8

Please sign in to comment.