Skip to content

Commit

Permalink
rtsp audio stream info
Browse files Browse the repository at this point in the history
  • Loading branch information
serezhka committed Jun 8, 2022
1 parent a234248 commit 82ddaed
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 36 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
.gradle
gradlew
gradlew.bat
gradle/wrapper/*
!gradle/wrapper/gradle-wrapper.properties
gradle
build
out
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: java

before_install:
- wget https://services.gradle.org/distributions/gradle-6.1-bin.zip
- unzip -qq gradle-6.1-bin.zip
- export GRADLE_HOME=$PWD/gradle-6.1
- wget https://services.gradle.org/distributions/gradle-7.4-bin.zip
- unzip -qq gradle-7.4-bin.zip
- export GRADLE_HOME=$PWD/gradle-7.4
- export PATH=$GRADLE_HOME/bin:$PATH
- gradle -v
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# java-airplay-lib

[![Build Status](https://travis-ci.com/serezhka/java-airplay-lib.svg?branch=master)](https://travis-ci.com/serezhka/java-airplay-lib) [![Release](https://jitpack.io/v/serezhka/java-airplay-lib.svg)](https://jitpack.io/#serezhka/java-airplay-lib) [![HitCount](http://hits.dwyl.io/serezhka/java-airplay-lib.svg)](http://hits.dwyl.io/serezhka/java-airplay-lib)
[![Build Status](https://travis-ci.com/serezhka/java-airplay-lib.svg?branch=master)](https://travis-ci.com/serezhka/java-airplay-lib)
[![Release](https://jitpack.io/v/serezhka/java-airplay-lib.svg)](https://jitpack.io/#serezhka/java-airplay-lib)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT)

This library is intended to easily create AirPlay2 servers acting like Apple TV. Tested with iPhone X (iOS 14.0.1)
Expand Down
33 changes: 17 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
plugins {
id 'maven'
id 'java-library'
}

group 'com.github.serezhka'
version '1.0.4'

sourceCompatibility = JavaVersion.VERSION_1_9
version '1.0.5'

repositories {
mavenCentral()
}

dependencies {
implementation "org.jmdns:jmdns:3.5.5"
implementation "net.i2p.crypto:eddsa:0.3.0"
implementation "org.whispersystems:curve25519-java:0.5.0"
implementation "com.googlecode.plist:dd-plist:1.22"
implementation "org.slf4j:slf4j-api:1.7.30"
java {
sourceCompatibility = JavaVersion.VERSION_1_9
}

testImplementation "org.junit.jupiter:junit-jupiter-api:5.4.2"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.4.2"
testRuntimeOnly "org.slf4j:slf4j-simple:1.7.30"
dependencies {
implementation 'org.jmdns:jmdns:3.5.7'
implementation 'net.i2p.crypto:eddsa:0.3.0'
implementation 'org.whispersystems:curve25519-java:0.5.0'
implementation 'com.googlecode.plist:dd-plist:1.23'
implementation 'org.slf4j:slf4j-api:1.7.36'

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testRuntimeOnly 'org.slf4j:slf4j-simple:1.7.36'
}

test {
useJUnitPlatform()
}

wrapper {
gradleVersion = '6.1.1'
gradleVersion = '7.4'
distributionType = Wrapper.DistributionType.ALL
}

task fatJar(type: Jar) {
classifier = 'all'
archiveClassifier.set('all')
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}

task jarSources(type: Jar) {
classifier = 'sources'
archiveClassifier.set('sources')
from sourceSets.main.allSource
}

Expand Down
5 changes: 0 additions & 5 deletions gradle/wrapper/gradle-wrapper.properties

This file was deleted.

15 changes: 12 additions & 3 deletions src/main/java/com/github/serezhka/jap2lib/RTSP.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,23 @@ MediaStreamInfo getMediaStreamInfo(InputStream rtspSetupPayload) throws Exceptio

// audio
case 96:
AudioStreamInfo.AudioStreamInfoBuilder builder = new AudioStreamInfo.AudioStreamInfoBuilder();
if (stream.containsKey("ct")) {
int compressionType = (int) stream.get("ct");
builder.compressionType(AudioStreamInfo.CompressionType.fromCode(compressionType));
}
if (stream.containsKey("audioFormat")) {
long audioFormatCode = (int) stream.get("audioFormat"); // FIXME int or long ?!
return new AudioStreamInfo(audioFormatCode);
builder.audioFormat(AudioStreamInfo.AudioFormat.fromCode(audioFormatCode));
}
if (stream.containsKey("spf")) {
int samplesPerFrame = (int) stream.get("spf");
builder.samplesPerFrame(samplesPerFrame);
}
return new AudioStreamInfo();
return builder.build();

default:
log.warn("Unknown stream type: {}", type);
log.error("Unknown stream type: {}", type);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,56 @@

public class AudioStreamInfo implements MediaStreamInfo {

private final CompressionType compressionType;
private final AudioFormat audioFormat;
private final int samplesPerFrame;

public AudioStreamInfo() {
audioFormat = null;
}

public AudioStreamInfo(long audioFormatCode) {
this.audioFormat = AudioFormat.fromCode(audioFormatCode);
private AudioStreamInfo(CompressionType compressionType, AudioFormat audioFormat, int samplesPerFrame) {
this.compressionType = compressionType;
this.audioFormat = audioFormat;
this.samplesPerFrame = samplesPerFrame;
}

@Override
public StreamType getStreamType() {
return StreamType.AUDIO;
}

public CompressionType getCompressionType() {
return compressionType;
}

public AudioFormat getAudioFormat() {
return audioFormat;
}

public int getSamplesPerFrame() {
return samplesPerFrame;
}

public enum CompressionType {
LPCM(1),
ALAC(2),
AAC(4),
AAC_ELD(8),
OPUS(32);

private final int code;

CompressionType(int code) {
this.code = code;
}

public static CompressionType fromCode(long code) {
for (CompressionType type : CompressionType.values()) {
if (type.code == code) {
return type;
}
}
throw new IllegalArgumentException("Unknown compression type with code: " + code);
}
}

public enum AudioFormat {
PCM_8000_16_1(0x4),
PCM_8000_16_2(0x8),
Expand Down Expand Up @@ -69,4 +100,29 @@ public static AudioFormat fromCode(long code) {
throw new IllegalArgumentException("Unknown audio format with code: " + code);
}
}

public static final class AudioStreamInfoBuilder {
private AudioFormat audioFormat;
private CompressionType compressionType;
private int samplesPerFrame;

public AudioStreamInfoBuilder audioFormat(AudioFormat audioFormat) {
this.audioFormat = audioFormat;
return this;
}

public AudioStreamInfoBuilder compressionType(CompressionType compressionType) {
this.compressionType = compressionType;
return this;
}

public AudioStreamInfoBuilder samplesPerFrame(int samplesPerFrame) {
this.samplesPerFrame = samplesPerFrame;
return this;
}

public AudioStreamInfo build() {
return new AudioStreamInfo(compressionType, audioFormat, samplesPerFrame);
}
}
}

0 comments on commit 82ddaed

Please sign in to comment.