Skip to content

Commit ea0656e

Browse files
committed
New stream preferences
1 parent 75fa77f commit ea0656e

18 files changed

+427
-148
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</activity>
5252

5353
<service
54-
android:name=".StreamingService"
54+
android:name=".streaming.StreamingService"
5555
android:foregroundServiceType="mediaProjection" />
5656

5757
<meta-data

app/src/main/java/com/fpvout/digiview/MainActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import androidx.core.content.res.ResourcesCompat;
3737
import androidx.preference.PreferenceManager;
3838

39+
import com.fpvout.digiview.streaming.StreamingService;
3940
import com.google.android.material.floatingactionbutton.FloatingActionButton;
4041

4142
import net.ossrs.rtmp.ConnectCheckerRtmp;
@@ -187,7 +188,7 @@ protected void onCreate(Bundle savedInstanceState) {
187188
liveButton = findViewById(R.id.liveButton);
188189
liveButton.setOnClickListener(v -> {
189190
if (!StreamingService.isStreaming()) {
190-
if (sharedPreferences.getString("RtmpUrl", "").isEmpty() || sharedPreferences.getString("RtmpKey", "").isEmpty()) {
191+
if (sharedPreferences.getString("StreamRtmpUrl", "").isEmpty() || sharedPreferences.getString("StreamRtmpKey", "").isEmpty()) {
191192
Toast.makeText(this, getString(R.string.rtmp_settings_empty), Toast.LENGTH_LONG).show();
192193
Intent intent = new Intent(v.getContext(), SettingsActivity.class);
193194
v.getContext().startActivity(intent);

app/src/main/java/com/fpvout/digiview/SettingsActivity.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import androidx.preference.ListPreference;
1111
import androidx.preference.PreferenceFragmentCompat;
1212

13+
import com.fpvout.digiview.streaming.StreamAudioSource;
14+
1315
import java.util.ArrayList;
1416
import java.util.Arrays;
1517

@@ -48,13 +50,16 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
4850
setPreferencesFromResource(R.xml.root_preferences, rootKey);
4951

5052
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
51-
ListPreference audioSourcePreference = findPreference("AudioSource");
53+
ListPreference audioSourcePreference = findPreference("StreamAudioSource");
5254

5355
ArrayList<CharSequence> entries = new ArrayList<>(Arrays.asList(audioSourcePreference.getEntries()));
5456
ArrayList<CharSequence> entryValues = new ArrayList<>(Arrays.asList(audioSourcePreference.getEntryValues()));
5557

56-
entries.add(getString(R.string.audio_source_internal));
57-
entryValues.add("internal");
58+
entries.add(getString(R.string.stream_audio_source_performance));
59+
entryValues.add(StreamAudioSource.PERFORMANCE);
60+
61+
entries.add(getString(R.string.stream_audio_source_internal));
62+
entryValues.add(StreamAudioSource.INTERNAL);
5863

5964
audioSourcePreference.setEntries(entries.toArray(new CharSequence[0]));
6065
audioSourcePreference.setEntryValues(entryValues.toArray(new CharSequence[0]));
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.fpvout.digiview.streaming;
2+
3+
public class StreamAudioBitrate {
4+
public static final String DEFAULT = "128";
5+
6+
public static int getBitrate(String value) {
7+
return Integer.parseInt(value) * 1024;
8+
}
9+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.fpvout.digiview.streaming;
2+
3+
public class StreamAudioSampleRate {
4+
public static final String DEFAULT = "44100hz";
5+
6+
public static int getSampleRate(String value) {
7+
switch (value) {
8+
case "8khz":
9+
return 8000;
10+
case "11025hz":
11+
return 11025;
12+
case "16khz":
13+
return 16000;
14+
case "22050hz":
15+
return 22050;
16+
case "32000hz":
17+
return 32000;
18+
case DEFAULT:
19+
return 44100;
20+
case "48khz":
21+
return 48000;
22+
case "96khz":
23+
return 96000;
24+
}
25+
26+
return -1;
27+
}
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fpvout.digiview.streaming;
2+
3+
import android.media.MediaRecorder;
4+
5+
public class StreamAudioSource {
6+
public static final String DEFAULT = "default";
7+
public static final String INTERNAL = "internal";
8+
public static final String PERFORMANCE = "performance";
9+
10+
public static int getAudioSource(String value) {
11+
switch (value) {
12+
case DEFAULT:
13+
return MediaRecorder.AudioSource.DEFAULT;
14+
case "mic":
15+
return MediaRecorder.AudioSource.MIC;
16+
case "cam":
17+
return MediaRecorder.AudioSource.CAMCORDER;
18+
case "communication":
19+
return MediaRecorder.AudioSource.VOICE_COMMUNICATION;
20+
case PERFORMANCE:
21+
return MediaRecorder.AudioSource.VOICE_PERFORMANCE;
22+
}
23+
24+
return -1;
25+
}
26+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.fpvout.digiview.streaming;
2+
3+
public class StreamBitrate {
4+
public static final String DEFAULT = "2500";
5+
6+
public static int getBitrate(String value) {
7+
return Integer.parseInt(value) * 1024;
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.fpvout.digiview.streaming;
2+
3+
public class StreamFramerate {
4+
public static final String DEFAULT = "60";
5+
6+
public static int getFramerate(String value) {
7+
return Integer.parseInt(value);
8+
}
9+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.fpvout.digiview.streaming;
2+
3+
public class StreamResolution {
4+
public static final String DEFAULT = "720p";
5+
private final int width;
6+
private final int height;
7+
8+
private StreamResolution(int width, int height) {
9+
this.width = width;
10+
this.height = height;
11+
}
12+
13+
public static StreamResolution getResolution(String value) {
14+
switch (value) {
15+
case "240p":
16+
return new StreamResolution(426, 240);
17+
case "360p":
18+
return new StreamResolution(640, 360);
19+
case "480p":
20+
return new StreamResolution(854, 480);
21+
case DEFAULT:
22+
return new StreamResolution(1280, 720);
23+
case "1080p":
24+
return new StreamResolution(1920, 1080);
25+
}
26+
27+
return null;
28+
}
29+
30+
public int getWidth() {
31+
return width;
32+
}
33+
34+
public int getHeight() {
35+
return height;
36+
}
37+
}

0 commit comments

Comments
 (0)