Skip to content

Commit 82ddaed

Browse files
committed
rtsp audio stream info
1 parent a234248 commit 82ddaed

File tree

7 files changed

+97
-36
lines changed

7 files changed

+97
-36
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
.gradle
33
gradlew
44
gradlew.bat
5-
gradle/wrapper/*
6-
!gradle/wrapper/gradle-wrapper.properties
5+
gradle
76
build
87
out

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
language: java
22

33
before_install:
4-
- wget https://services.gradle.org/distributions/gradle-6.1-bin.zip
5-
- unzip -qq gradle-6.1-bin.zip
6-
- export GRADLE_HOME=$PWD/gradle-6.1
4+
- wget https://services.gradle.org/distributions/gradle-7.4-bin.zip
5+
- unzip -qq gradle-7.4-bin.zip
6+
- export GRADLE_HOME=$PWD/gradle-7.4
77
- export PATH=$GRADLE_HOME/bin:$PATH
88
- gradle -v

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# java-airplay-lib
22

3-
[![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)
3+
[![Build Status](https://travis-ci.com/serezhka/java-airplay-lib.svg?branch=master)](https://travis-ci.com/serezhka/java-airplay-lib)
4+
[![Release](https://jitpack.io/v/serezhka/java-airplay-lib.svg)](https://jitpack.io/#serezhka/java-airplay-lib)
45
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT)
56

67
This library is intended to easily create AirPlay2 servers acting like Apple TV. Tested with iPhone X (iOS 14.0.1)

build.gradle

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,47 @@
11
plugins {
2-
id 'maven'
32
id 'java-library'
43
}
54

65
group 'com.github.serezhka'
7-
version '1.0.4'
8-
9-
sourceCompatibility = JavaVersion.VERSION_1_9
6+
version '1.0.5'
107

118
repositories {
129
mavenCentral()
1310
}
1411

15-
dependencies {
16-
implementation "org.jmdns:jmdns:3.5.5"
17-
implementation "net.i2p.crypto:eddsa:0.3.0"
18-
implementation "org.whispersystems:curve25519-java:0.5.0"
19-
implementation "com.googlecode.plist:dd-plist:1.22"
20-
implementation "org.slf4j:slf4j-api:1.7.30"
12+
java {
13+
sourceCompatibility = JavaVersion.VERSION_1_9
14+
}
2115

22-
testImplementation "org.junit.jupiter:junit-jupiter-api:5.4.2"
23-
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.4.2"
24-
testRuntimeOnly "org.slf4j:slf4j-simple:1.7.30"
16+
dependencies {
17+
implementation 'org.jmdns:jmdns:3.5.7'
18+
implementation 'net.i2p.crypto:eddsa:0.3.0'
19+
implementation 'org.whispersystems:curve25519-java:0.5.0'
20+
implementation 'com.googlecode.plist:dd-plist:1.23'
21+
implementation 'org.slf4j:slf4j-api:1.7.36'
22+
23+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
24+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
25+
testRuntimeOnly 'org.slf4j:slf4j-simple:1.7.36'
2526
}
2627

2728
test {
2829
useJUnitPlatform()
2930
}
3031

3132
wrapper {
32-
gradleVersion = '6.1.1'
33+
gradleVersion = '7.4'
3334
distributionType = Wrapper.DistributionType.ALL
3435
}
3536

3637
task fatJar(type: Jar) {
37-
classifier = 'all'
38+
archiveClassifier.set('all')
3839
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
3940
with jar
4041
}
4142

4243
task jarSources(type: Jar) {
43-
classifier = 'sources'
44+
archiveClassifier.set('sources')
4445
from sourceSets.main.allSource
4546
}
4647

gradle/wrapper/gradle-wrapper.properties

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/main/java/com/github/serezhka/jap2lib/RTSP.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,23 @@ MediaStreamInfo getMediaStreamInfo(InputStream rtspSetupPayload) throws Exceptio
4444

4545
// audio
4646
case 96:
47+
AudioStreamInfo.AudioStreamInfoBuilder builder = new AudioStreamInfo.AudioStreamInfoBuilder();
48+
if (stream.containsKey("ct")) {
49+
int compressionType = (int) stream.get("ct");
50+
builder.compressionType(AudioStreamInfo.CompressionType.fromCode(compressionType));
51+
}
4752
if (stream.containsKey("audioFormat")) {
4853
long audioFormatCode = (int) stream.get("audioFormat"); // FIXME int or long ?!
49-
return new AudioStreamInfo(audioFormatCode);
54+
builder.audioFormat(AudioStreamInfo.AudioFormat.fromCode(audioFormatCode));
55+
}
56+
if (stream.containsKey("spf")) {
57+
int samplesPerFrame = (int) stream.get("spf");
58+
builder.samplesPerFrame(samplesPerFrame);
5059
}
51-
return new AudioStreamInfo();
60+
return builder.build();
5261

5362
default:
54-
log.warn("Unknown stream type: {}", type);
63+
log.error("Unknown stream type: {}", type);
5564
}
5665
}
5766
return null;

src/main/java/com/github/serezhka/jap2lib/rtsp/AudioStreamInfo.java

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,56 @@
22

33
public class AudioStreamInfo implements MediaStreamInfo {
44

5+
private final CompressionType compressionType;
56
private final AudioFormat audioFormat;
7+
private final int samplesPerFrame;
68

7-
public AudioStreamInfo() {
8-
audioFormat = null;
9-
}
10-
11-
public AudioStreamInfo(long audioFormatCode) {
12-
this.audioFormat = AudioFormat.fromCode(audioFormatCode);
9+
private AudioStreamInfo(CompressionType compressionType, AudioFormat audioFormat, int samplesPerFrame) {
10+
this.compressionType = compressionType;
11+
this.audioFormat = audioFormat;
12+
this.samplesPerFrame = samplesPerFrame;
1313
}
1414

1515
@Override
1616
public StreamType getStreamType() {
1717
return StreamType.AUDIO;
1818
}
1919

20+
public CompressionType getCompressionType() {
21+
return compressionType;
22+
}
23+
2024
public AudioFormat getAudioFormat() {
2125
return audioFormat;
2226
}
2327

28+
public int getSamplesPerFrame() {
29+
return samplesPerFrame;
30+
}
31+
32+
public enum CompressionType {
33+
LPCM(1),
34+
ALAC(2),
35+
AAC(4),
36+
AAC_ELD(8),
37+
OPUS(32);
38+
39+
private final int code;
40+
41+
CompressionType(int code) {
42+
this.code = code;
43+
}
44+
45+
public static CompressionType fromCode(long code) {
46+
for (CompressionType type : CompressionType.values()) {
47+
if (type.code == code) {
48+
return type;
49+
}
50+
}
51+
throw new IllegalArgumentException("Unknown compression type with code: " + code);
52+
}
53+
}
54+
2455
public enum AudioFormat {
2556
PCM_8000_16_1(0x4),
2657
PCM_8000_16_2(0x8),
@@ -69,4 +100,29 @@ public static AudioFormat fromCode(long code) {
69100
throw new IllegalArgumentException("Unknown audio format with code: " + code);
70101
}
71102
}
103+
104+
public static final class AudioStreamInfoBuilder {
105+
private AudioFormat audioFormat;
106+
private CompressionType compressionType;
107+
private int samplesPerFrame;
108+
109+
public AudioStreamInfoBuilder audioFormat(AudioFormat audioFormat) {
110+
this.audioFormat = audioFormat;
111+
return this;
112+
}
113+
114+
public AudioStreamInfoBuilder compressionType(CompressionType compressionType) {
115+
this.compressionType = compressionType;
116+
return this;
117+
}
118+
119+
public AudioStreamInfoBuilder samplesPerFrame(int samplesPerFrame) {
120+
this.samplesPerFrame = samplesPerFrame;
121+
return this;
122+
}
123+
124+
public AudioStreamInfo build() {
125+
return new AudioStreamInfo(compressionType, audioFormat, samplesPerFrame);
126+
}
127+
}
72128
}

0 commit comments

Comments
 (0)