Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lxbndr committed Dec 18, 2024
0 parents commit 48bb006
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Test package

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:

jobs:
test:

runs-on: macos-latest

steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Build
run: swift build
- name: Run tests
run: |
set -e
echo "::group::Run BitwiseTests"
.build/debug/BitwiseTests
echo "::endgroup::"
echo "::group::Run FramingTests"
.build/debug/FramingTests
echo "::endgroup::"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.build/
.swiftpm/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ogg"]
path = Sources/COgg/ogg
url = https://github.com/xiph/ogg.git
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Readdle Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
43 changes: 43 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// swift-tools-version: 5.4
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "swift-ogg",
products: [
.library(
name: "Ogg",
targets: ["COgg"]
),
],
targets: [
.target(
name: "COgg",
sources: [
"./ogg/src/bitwise.c",
"./ogg/src/framing.c",
]
),
.executableTarget(
name: "BitwiseTests",
path: "Tests/BitwiseTests",
cSettings: [
.headerSearchPath("../../Sources/COgg/ogg/include"),
.headerSearchPath("../../Sources/COgg/ogg/src"),
.define("_V_SELFTEST"),
.unsafeFlags(["-Wno-shorten-64-to-32"]),
]
),
.executableTarget(
name: "FramingTests",
path: "Tests/FramingTests",
cSettings: [
.headerSearchPath("../../Sources/COgg/ogg/include"),
.headerSearchPath("../../Sources/COgg/ogg/src"),
.define("_V_SELFTEST"),
.unsafeFlags(["-Wno-shorten-64-to-32"]),
]
),
]
)
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# swift-ogg
A basic Swift Package wrapper for `libogg` from [xiph/ogg](https://github.com/xiph/ogg).

# Usage
Add a dependency to your Swift Package definition.
The example below is in `swift-tools-version: 5.4` syntax:
```swift
let package = Package(
name: "MyPackage",
products: [.library(name: "MyLib", targets: ["MyLib"])],
dependencies: [
.package(url: "https://github.com/readdle/swift-ogg.git", .upToNextMinor(from: "1.3.5")),
],
targets: [
.target(
name: "MyLib",
dependencies: [
.product(name: "Ogg", package: "swift-ogg"),
],
```
Import C module in your code and use [ogg API](https://www.xiph.org/ogg/doc/libogg/reference.html):
```swift
import COgg

var streamState = ogg_stream_state()
var headerPacket = ogg_packet()
var oggPage = ogg_page()

ogg_stream_init(&streamState, Int32(Date().timeIntervalSince1970))

// Prepare required header packets

ogg_stream_packetin(&streamState, &headerPacket)

while ogg_stream_flush(&streamState, &oggPage) != 0 {
// Process page data, e.g. write to file
}
```

# Versioning
As it is only a wrapper, versioning strictly follows the original.
Version `1.3.5` would correspond to official [v1.3.5](https://github.com/xiph/ogg/releases/tag/v1.3.5) release
and so on.

# Licenses
This project is under MIT license. `libogg` sources are
from [xiph/ogg repository](https://github.com/xiph/ogg) and are licensed under
the [BSD-3-Clause license](https://github.com/xiph/ogg?tab=BSD-3-Clause-1-ov-file#BSD-3-Clause-1-ov-file).
4 changes: 4 additions & 0 deletions Sources/COgg/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module COgg [system] {
umbrella header "ogg/ogg.h"
export *
}
1 change: 1 addition & 0 deletions Sources/COgg/include/ogg/ogg.h
1 change: 1 addition & 0 deletions Sources/COgg/include/ogg/os_types.h
1 change: 1 addition & 0 deletions Sources/COgg/ogg
Submodule ogg added at e1774c
1 change: 1 addition & 0 deletions Tests/BitwiseTests/bitwise.c
1 change: 1 addition & 0 deletions Tests/FramingTests/framing.c

0 comments on commit 48bb006

Please sign in to comment.