Skip to content

Commit

Permalink
Merge pull request #1414 from pedroSG94/feature/samples-refactor
Browse files Browse the repository at this point in the history
Feature/samples refactor
  • Loading branch information
pedroSG94 committed Mar 2, 2024
2 parents 23aacf9 + afad9d9 commit 6c3cde4
Show file tree
Hide file tree
Showing 136 changed files with 3,090 additions and 8,728 deletions.
87 changes: 16 additions & 71 deletions README.md
Expand Up @@ -25,7 +25,7 @@ https://github.com/pedroSG94/vlc-example-streamplayer

## iOS version (under develop):

https://github.com/pedroSG94/rtmp-rtsp-stream-client-swift
https://github.com/pedroSG94/RootEncoder-iOS

## Wiki

Expand All @@ -37,11 +37,6 @@ https://github.com/pedroSG94/RootEncoder/wiki
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<!--Only for record video/audio-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--Optional for play store-->
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
```

## Compile
Expand Down Expand Up @@ -70,7 +65,7 @@ allprojects {
}
}
dependencies {
implementation 'com.github.pedroSG94.RootEncoder:library:2.3.6'
implementation 'com.github.pedroSG94.RootEncoder:library:2.3.7'
}
```
Expand Down Expand Up @@ -154,75 +149,25 @@ This library need sponsors to get new devices or pay platforms to test and debug
If you are interested. You can contact me by email or donate directly on [Github](https://github.com/sponsors/pedroSG94) or [Paypal](https://www.paypal.com/paypalme/pedroSG94)
Thank you!

## Use example:
## Use examples:

This code is a basic example.
I recommend you go to Activities in app module and see all examples.
### Rotation example

### RTMP:

```java
This is the recommend way to use the library.
This example support screen rotation, stream orientation (vertical, horizontal) filters and change video/audio sources on fly:
https://github.com/pedroSG94/RootEncoder/tree/master/app/src/main/java/com/pedro/streamer/rotation

//default
### Screen example

//create builder
RtmpCamera1 rtmpCamera1 = new RtmpCamera1(openGlView, connectCheckerRtmp);
//start stream
if (rtmpCamera1.prepareAudio() && rtmpCamera1.prepareVideo()) {
rtmpCamera1.startStream("rtmp://yourEndPoint");
} else {
/**This device cant init encoders, this could be for 2 reasons: The encoder selected doesnt support any configuration setted or your device hasnt a H264 or AAC encoder (in this case you can see log error valid encoder not found)*/
}
//stop stream
rtmpCamera1.stopStream();

//with params

//create builder
RtmpCamera1 rtmpCamera1 = new RtmpCamera1(openGlView, connectCheckerRtmp);
//start stream
if (rtmpCamera1.prepareAudio(int bitrate, int sampleRate, boolean isStereo, boolean echoCanceler,
boolean noiseSuppressor) && rtmpCamera1.prepareVideo(int width, int height, int fps, int bitrate, int rotation)) {
rtmpCamera1.startStream("rtmp://yourEndPoint");
} else {
/**This device cant init encoders, this could be for 2 reasons: The encoder selected doesnt support any configuration setted or your device hasnt a H264 or AAC encoder (in this case you can see log error valid encoder not found)*/
}
//stop stream
rtmpCamera1.stopStream();
Example to stream using Screen as video source using a service to stream in background:
https://github.com/pedroSG94/RootEncoder/tree/master/app/src/main/java/com/pedro/streamer/screen

```
### From file example

### RTSP:
Code example to stream using a video file as video/audio source:
https://github.com/pedroSG94/RootEncoder/tree/master/app/src/main/java/com/pedro/streamer/file

```java
### Old Api example

//default

//create builder
//by default TCP protocol.
RtspCamera1 rtspCamera1 = new RtspCamera1(openGlView, connectCheckerRtsp);
//start stream
if (rtspCamera1.prepareAudio() && rtspCamera1.prepareVideo()) {
rtspCamera1.startStream("rtsp://yourEndPoint");
} else {
/**This device cant init encoders, this could be for 2 reasons: The encoder selected doesnt support any configuration setted or your device hasnt a H264 or AAC encoder (in this case you can see log error valid encoder not found)*/
}
//stop stream
rtspCamera1.stopStream();

//with params

//create builder
RtspCamera1 rtspCamera1 = new RtspCamera1(openGlView, connectCheckerRtsp);
rtspCamera1.setProtocol(protocol);
//start stream
if (rtspCamera1.prepareAudio(int bitrate, int sampleRate, boolean isStereo, boolean echoCanceler,
boolean noiseSuppressor) && rtspCamera1.prepareVideo(int width, int height, int fps, int bitrate, int rotation)) {
rtspCamera1.startStream("rtsp://yourEndPoint");
} else {
/**This device cant init encoders, this could be for 2 reasons: The encoder selected doesnt support any configuration setted or your device hasnt a H264 or AAC encoder (in this case you can see log error valid encoder not found)*/
}
//stop stream
rtspCamera1.stopStream();

```
Code example for low API devices (Android API 16+):
https://github.com/pedroSG94/RootEncoder/tree/master/app/src/main/java/com/pedro/streamer/oldapi
1 change: 0 additions & 1 deletion app/build.gradle.kts
Expand Up @@ -32,7 +32,6 @@ android {
jvmTarget = "17"
}
buildFeatures {
viewBinding = true
buildConfig = true
}
}
Expand Down
77 changes: 12 additions & 65 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -2,10 +2,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!--some devices need read permission to create folders or files-->
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.CAMERA"/>
Expand Down Expand Up @@ -33,7 +29,6 @@
<activity
android:name="com.pedro.streamer.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
Expand All @@ -42,77 +37,29 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<activity
android:name="com.pedro.streamer.customexample.RtmpActivity"
android:label="@string/rtmp_streamer"
android:screenOrientation="portrait"
/>
<activity
android:name="com.pedro.streamer.customexample.RtspActivity"
android:label="@string/rtsp_streamer"
android:screenOrientation="portrait"
/>
<activity
android:name="com.pedro.streamer.defaultexample.ExampleRtspActivity"
android:label="@string/default_rtsp"
/>
<activity
android:name="com.pedro.streamer.defaultexample.ExampleRtmpActivity"
android:label="@string/default_rtmp"
/>
<activity
android:name="com.pedro.streamer.defaultexample.ExampleSrtActivity"
android:label="@string/default_srt"
/>
<activity
android:name="com.pedro.streamer.filestreamexample.RtspFromFileActivity"
android:label="@string/from_file_rtsp"
android:screenOrientation="portrait"
/>
<activity
android:name="com.pedro.streamer.filestreamexample.RtmpFromFileActivity"
android:label="@string/from_file_rtmp"
android:screenOrientation="portrait"
/>
<activity
android:name="com.pedro.streamer.openglexample.OpenGlRtmpActivity"
android:label="@string/opengl_rtmp"
/>
<activity
android:name="com.pedro.streamer.openglexample.OpenGlRtspActivity"
android:label="@string/opengl_rtsp"
android:name="com.pedro.streamer.oldapi.OldApiActivity"
android:label="@string/old_api"
/>

<activity
android:name="com.pedro.streamer.openglexample.OpenGlSrtActivity"
android:label="@string/opengl_srt"
android:name="com.pedro.streamer.file.FromFileActivity"
android:label="@string/from_file"
/>

<activity
android:name="com.pedro.streamer.openglexample.OpenGlGenericActivity"
android:label="@string/opengl_generic"
android:name="com.pedro.streamer.screen.ScreenActivity"
android:label="@string/display"
/>
<activity
android:name="com.pedro.streamer.displayexample.DisplayActivity"
android:label="@string/display_rtmp"
android:screenOrientation="portrait" />
<activity
android:name="com.pedro.streamer.backgroundexample.BackgroundActivity"
android:label="@string/service_rtp"
android:screenOrientation="portrait" />

<activity android:name="com.pedro.streamer.rotation.RotationExampleActivity"
<activity android:name="com.pedro.streamer.rotation.RotationActivity"
android:label="@string/rotation_rtmp"
android:screenOrientation="fullSensor"
android:configChanges="orientation|screenSize"
/>

<service android:name="com.pedro.streamer.rotation.StreamService"
android:foregroundServiceType="mediaProjection|camera|microphone"
/>

<service android:name="com.pedro.streamer.backgroundexample.RtpService"
android:foregroundServiceType="camera|microphone"
/>

<service android:name="com.pedro.streamer.displayexample.DisplayService"
<service android:name="com.pedro.streamer.screen.ScreenService"
android:foregroundServiceType="mediaProjection"
/>
</application>
Expand Down

0 comments on commit 6c3cde4

Please sign in to comment.