├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── streye │ │ └── androidrestreamer │ │ ├── MainActivity.kt │ │ └── plugin │ │ ├── VLCReStreamerBase.kt │ │ ├── VLCReStreamerRtmp.kt │ │ └── VLCReStreamerRtsp.kt │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ └── activity_main.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/ 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedroSG94/AndroidReStreamer/9bc6557824370d4d6bc2f78f947976200281f1cf/README.md -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion 28 7 | defaultConfig { 8 | applicationId "com.streye.androidrestreamer" 9 | minSdkVersion 21 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 25 | implementation 'com.android.support:appcompat-v7:28.0.0' 26 | 27 | implementation 'com.github.pedroSG94.vlc-example-streamplayer:pedrovlc:2.5.14v3' 28 | implementation 'com.github.pedroSG94.rtmp-rtsp-stream-client-java:rtplibrary:1.5.8' 29 | } 30 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/streye/androidrestreamer/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.streye.androidrestreamer 2 | 3 | import android.os.Bundle 4 | import android.support.v7.app.AppCompatActivity 5 | import android.view.SurfaceHolder 6 | import android.widget.Toast 7 | import com.streye.androidrestreamer.plugin.VLCReStreamerRtmp 8 | import kotlinx.android.synthetic.main.activity_main.* 9 | import net.ossrs.rtmp.ConnectCheckerRtmp 10 | 11 | class MainActivity : AppCompatActivity(), SurfaceHolder.Callback, ConnectCheckerRtmp { 12 | 13 | private val streamURL = "rtmp://10.7.12.62/live/pedro" 14 | private val vlcURL = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov" 15 | 16 | private lateinit var vlcReStreamerRtmp: VLCReStreamerRtmp 17 | 18 | override fun onCreate(savedInstanceState: Bundle?) { 19 | super.onCreate(savedInstanceState) 20 | setContentView(R.layout.activity_main) 21 | vlcReStreamerRtmp = VLCReStreamerRtmp(surfaceView, this) 22 | surfaceView.holder.addCallback(this) 23 | } 24 | 25 | override fun onConnectionSuccessRtmp() { 26 | runOnUiThread { 27 | Toast.makeText(this@MainActivity, "Connection success", Toast.LENGTH_SHORT).show() 28 | } 29 | } 30 | 31 | override fun onConnectionFailedRtmp(reason: String) { 32 | runOnUiThread { 33 | Toast.makeText(this@MainActivity, "Connection failed. $reason", Toast.LENGTH_SHORT).show() 34 | vlcReStreamerRtmp.stopStream() 35 | } 36 | } 37 | 38 | override fun onDisconnectRtmp() { 39 | runOnUiThread { Toast.makeText(this@MainActivity, "Disconnected", Toast.LENGTH_SHORT).show() } 40 | } 41 | 42 | override fun onAuthErrorRtmp() { 43 | runOnUiThread { Toast.makeText(this@MainActivity, "Auth error", Toast.LENGTH_SHORT).show() } 44 | } 45 | 46 | override fun onAuthSuccessRtmp() { 47 | runOnUiThread { Toast.makeText(this@MainActivity, "Auth success", Toast.LENGTH_SHORT).show() } 48 | } 49 | 50 | override fun surfaceChanged(p0: SurfaceHolder?, p1: Int, p2: Int, p3: Int) { 51 | if (!vlcReStreamerRtmp.isStreaming()) { 52 | if (vlcReStreamerRtmp.isRecording() || vlcReStreamerRtmp.prepareAudio() && vlcReStreamerRtmp.prepareVideo()) { 53 | vlcReStreamerRtmp.startStream(streamURL, vlcURL) 54 | } 55 | } 56 | } 57 | 58 | override fun surfaceDestroyed(p0: SurfaceHolder?) { 59 | if (vlcReStreamerRtmp.isStreaming()) vlcReStreamerRtmp.stopStream() 60 | if (vlcReStreamerRtmp.isOnPreview()) vlcReStreamerRtmp.stopPreview() 61 | } 62 | 63 | override fun surfaceCreated(p0: SurfaceHolder?) { 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /app/src/main/java/com/streye/androidrestreamer/plugin/VLCReStreamerBase.kt: -------------------------------------------------------------------------------- 1 | package com.streye.androidrestreamer.plugin 2 | 3 | import android.content.Context 4 | import android.media.MediaCodec 5 | import android.media.MediaFormat 6 | import android.os.Build 7 | import android.support.annotation.RequiresApi 8 | import android.util.Log 9 | import com.pedro.encoder.audio.AudioEncoder 10 | import com.pedro.encoder.audio.GetAacData 11 | import com.pedro.encoder.input.audio.GetMicrophoneData 12 | import com.pedro.encoder.input.audio.MicrophoneManager 13 | import com.pedro.encoder.input.video.CameraHelper 14 | import com.pedro.encoder.utils.CodecUtil 15 | import com.pedro.encoder.video.FormatVideoEncoder 16 | import com.pedro.encoder.video.GetVideoData 17 | import com.pedro.encoder.video.VideoEncoder 18 | import com.pedro.rtplibrary.base.RecordController 19 | import com.pedro.rtplibrary.view.GlInterface 20 | import com.pedro.rtplibrary.view.LightOpenGlView 21 | import com.pedro.rtplibrary.view.OffScreenGlThread 22 | import com.pedro.rtplibrary.view.OpenGlView 23 | import com.pedro.vlc.VlcListener 24 | import com.pedro.vlc.VlcVideoLibrary 25 | import java.io.IOException 26 | import java.nio.ByteBuffer 27 | 28 | 29 | /** 30 | * Created by pedro on 29/03/19. 31 | */ 32 | 33 | abstract class VLCReStreamerBase : GetAacData, GetVideoData, GetMicrophoneData, VlcListener { 34 | 35 | private val TAG = "VLCReStreamerBase" 36 | 37 | private var context: Context? = null 38 | private var vlcVideoLibrary: VlcVideoLibrary? = null 39 | protected lateinit var videoEncoder: VideoEncoder 40 | private lateinit var microphoneManager: MicrophoneManager 41 | private lateinit var audioEncoder: AudioEncoder 42 | private var glInterface: GlInterface? = null 43 | private var streaming = false 44 | private var videoEnabled = true 45 | private var onPreview = false 46 | private lateinit var recordController: RecordController 47 | 48 | private val options = arrayListOf(":fullscreen") 49 | 50 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) 51 | constructor(openGlView: OpenGlView) { 52 | context = openGlView.context 53 | this.glInterface = openGlView 54 | glInterface?.init() 55 | init() 56 | } 57 | 58 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) 59 | constructor(lightOpenGlView: LightOpenGlView) { 60 | context = lightOpenGlView.context 61 | this.glInterface = lightOpenGlView 62 | this.glInterface?.init() 63 | init() 64 | } 65 | 66 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) 67 | constructor(context: Context) { 68 | this.context = context 69 | glInterface = OffScreenGlThread(context) 70 | glInterface?.init() 71 | init() 72 | } 73 | 74 | private fun init() { 75 | videoEncoder = VideoEncoder(this) 76 | microphoneManager = MicrophoneManager(this) 77 | audioEncoder = AudioEncoder(this) 78 | recordController = RecordController() 79 | vlcVideoLibrary = VlcVideoLibrary(context, this, glInterface?.surfaceTexture) 80 | vlcVideoLibrary?.setOptions(options) 81 | } 82 | 83 | /** 84 | * Basic auth developed to work with Wowza. No tested with other server 85 | * 86 | * @param user auth. 87 | * @param password auth. 88 | */ 89 | abstract fun setAuthorization(user: String, password: String) 90 | 91 | /** 92 | * Call this method before use @startStream. If not you will do a stream without video. NOTE: 93 | * Rotation with encoder is silence ignored in some devices. 94 | * 95 | * @param width resolution in px. 96 | * @param height resolution in px. 97 | * @param fps frames per second of the stream. 98 | * @param bitrate H264 in kb. 99 | * @param hardwareRotation true if you want rotate using encoder, false if you want rotate with 100 | * software if you are using a SurfaceView or TextureView or with OpenGl if you are using 101 | * OpenGlView. 102 | * @param rotation could be 90, 180, 270 or 0. You should use CameraHelper.getCameraOrientation 103 | * with SurfaceView or TextureView and 0 with OpenGlView or LightOpenGlView. NOTE: Rotation with 104 | * encoder is silence ignored in some devices. 105 | * @return true if success, false if you get a error (Normally because the encoder selected 106 | * doesn't support any configuration seated or your device hasn't a H264 encoder). 107 | */ 108 | fun prepareVideo(width: Int, height: Int, fps: Int, bitrate: Int, hardwareRotation: Boolean, 109 | iFrameInterval: Int, rotation: Int): Boolean { 110 | if (onPreview) { 111 | stopPreview() 112 | onPreview = true 113 | } 114 | val formatVideoEncoder = FormatVideoEncoder.SURFACE 115 | return videoEncoder.prepareVideoEncoder(width, height, fps, bitrate, rotation, hardwareRotation, 116 | iFrameInterval, formatVideoEncoder) 117 | } 118 | 119 | /** 120 | * backward compatibility reason 121 | */ 122 | fun prepareVideo(width: Int, height: Int, fps: Int, bitrate: Int, hardwareRotation: Boolean, 123 | rotation: Int): Boolean { 124 | return prepareVideo(width, height, fps, bitrate, hardwareRotation, 2, rotation) 125 | } 126 | 127 | protected abstract fun prepareAudioRtp(isStereo: Boolean, sampleRate: Int) 128 | 129 | /** 130 | * Call this method before use @startStream. If not you will do a stream without audio. 131 | * 132 | * @param bitrate AAC in kb. 133 | * @param sampleRate of audio in hz. Can be 8000, 16000, 22500, 32000, 44100. 134 | * @param isStereo true if you want Stereo audio (2 audio channels), false if you want Mono audio 135 | * (1 audio channel). 136 | * @param echoCanceler true enable echo canceler, false disable. 137 | * @param noiseSuppressor true enable noise suppressor, false disable. 138 | * @return true if success, false if you get a error (Normally because the encoder selected 139 | * doesn't support any configuration seated or your device hasn't a AAC encoder). 140 | */ 141 | fun prepareAudio(bitrate: Int, sampleRate: Int, isStereo: Boolean, echoCanceler: Boolean, 142 | noiseSuppressor: Boolean): Boolean { 143 | microphoneManager.createMicrophone(sampleRate, isStereo, echoCanceler, noiseSuppressor) 144 | prepareAudioRtp(isStereo, sampleRate) 145 | return audioEncoder.prepareAudioEncoder(bitrate, sampleRate, isStereo) 146 | } 147 | 148 | /** 149 | * Same to call: rotation = 0; if (Portrait) rotation = 90; prepareVideo(640, 480, 30, 1200 * 150 | * 1024, false, rotation); 151 | * 152 | * @return true if success, false if you get a error (Normally because the encoder selected 153 | * doesn't support any configuration seated or your device hasn't a H264 encoder). 154 | */ 155 | fun prepareVideo(): Boolean { 156 | val rotation = CameraHelper.getCameraOrientation(context) 157 | return prepareVideo(640, 480, 30, 1200 * 1024, false, rotation) 158 | } 159 | 160 | /** 161 | * Same to call: prepareAudio(64 * 1024, 32000, true, false, false); 162 | * 163 | * @return true if success, false if you get a error (Normally because the encoder selected 164 | * doesn't support any configuration seated or your device hasn't a AAC encoder). 165 | */ 166 | fun prepareAudio(): Boolean { 167 | return prepareAudio(64 * 1024, 32000, true, false, false) 168 | } 169 | 170 | /** 171 | * @param forceVideo force type codec used. FIRST_COMPATIBLE_FOUND, SOFTWARE, HARDWARE 172 | * @param forceAudio force type codec used. FIRST_COMPATIBLE_FOUND, SOFTWARE, HARDWARE 173 | */ 174 | fun setForce(forceVideo: CodecUtil.Force, forceAudio: CodecUtil.Force) { 175 | videoEncoder.setForce(forceVideo) 176 | audioEncoder.setForce(forceAudio) 177 | } 178 | 179 | /** 180 | * Start record a MP4 video. Need be called while stream. 181 | * 182 | * @param path where file will be saved. 183 | * @throws IOException If you init it before start stream. 184 | */ 185 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) 186 | @Throws(IOException::class) 187 | fun startRecord(path: String, listener: RecordController.Listener?) { 188 | recordController.startRecord(path, listener) 189 | if (!streaming) { 190 | startEncoders() 191 | } else if (videoEncoder.isRunning) { 192 | resetVideoEncoder() 193 | } 194 | } 195 | 196 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) 197 | @Throws(IOException::class) 198 | fun startRecord(path: String) { 199 | startRecord(path, null) 200 | } 201 | 202 | /** 203 | * Stop record MP4 video started with @startRecord. If you don't call it file will be unreadable. 204 | */ 205 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) 206 | fun stopRecord() { 207 | recordController.stopRecord() 208 | if (!streaming) stopStream() 209 | } 210 | 211 | /** 212 | * Stop camera preview. Ignored if streaming or already stopped. You need call it after 213 | * 214 | * @stopStream to release camera properly if you will close activity. 215 | */ 216 | fun stopPreview() { 217 | if (!isStreaming() && onPreview && glInterface !is OffScreenGlThread) { 218 | glInterface?.stop() 219 | vlcVideoLibrary?.stop() 220 | onPreview = false 221 | } else { 222 | Log.e(TAG, "Streaming or preview stopped, ignored") 223 | } 224 | } 225 | 226 | protected abstract fun startStreamRtp(url: String) 227 | 228 | /** 229 | * Need be called after @prepareVideo or/and @prepareAudio. This method override resolution of 230 | * 231 | * @param url of the stream like: protocol://ip:port/application/streamName 232 | * 233 | * RTSP: rtsp://192.168.1.1:1935/live/pedroSG94 RTSPS: rtsps://192.168.1.1:1935/live/pedroSG94 234 | * RTMP: rtmp://192.168.1.1:1935/live/pedroSG94 RTMPS: rtmps://192.168.1.1:1935/live/pedroSG94 235 | * @startPreview to resolution seated in @prepareVideo. If you never startPreview this method 236 | * startPreview for you to resolution seated in @prepareVideo. 237 | */ 238 | fun startStream(url: String, vlcUrl: String) { 239 | streaming = true 240 | if (!recordController.isRecording) { 241 | startEncoders() 242 | } else { 243 | resetVideoEncoder() 244 | } 245 | startStreamRtp(url) 246 | onPreview = true 247 | vlcVideoLibrary?.play(vlcUrl) 248 | } 249 | 250 | private fun startEncoders() { 251 | videoEncoder.start() 252 | audioEncoder.start() 253 | prepareGlView() 254 | microphoneManager.start() 255 | onPreview = true 256 | } 257 | 258 | private fun resetVideoEncoder() { 259 | glInterface?.removeMediaCodecSurface() 260 | videoEncoder.reset() 261 | glInterface?.addMediaCodecSurface(videoEncoder.inputSurface) 262 | } 263 | 264 | private fun prepareGlView() { 265 | if (glInterface is OffScreenGlThread) { 266 | glInterface = OffScreenGlThread(context) 267 | glInterface?.init() 268 | (glInterface as OffScreenGlThread).setFps(videoEncoder.fps) 269 | } 270 | if (videoEncoder.rotation == 90 || videoEncoder.rotation == 270) { 271 | glInterface?.setEncoderSize(videoEncoder.height, videoEncoder.width) 272 | } else { 273 | glInterface?.setEncoderSize(videoEncoder.width, videoEncoder.height) 274 | } 275 | glInterface?.setRotation(0) 276 | glInterface?.start() 277 | if (videoEncoder.inputSurface != null) { 278 | glInterface?.addMediaCodecSurface(videoEncoder.inputSurface) 279 | } 280 | vlcVideoLibrary = VlcVideoLibrary(context, this, glInterface?.surfaceTexture) 281 | vlcVideoLibrary?.setOptions(options) 282 | } 283 | 284 | protected abstract fun stopStreamRtp() 285 | 286 | /** 287 | * Stop stream started with @startStream. 288 | */ 289 | fun stopStream() { 290 | if (streaming) { 291 | streaming = false 292 | stopStreamRtp() 293 | } 294 | if (!recordController.isRecording) { 295 | microphoneManager.stop() 296 | glInterface?.removeMediaCodecSurface() 297 | if (glInterface is OffScreenGlThread) { 298 | glInterface?.stop() 299 | vlcVideoLibrary?.stop() 300 | } 301 | videoEncoder.stop() 302 | audioEncoder.stop() 303 | recordController.resetFormats() 304 | } 305 | } 306 | 307 | //cache control 308 | @Throws(RuntimeException::class) 309 | abstract fun resizeCache(newSize: Int) 310 | 311 | abstract fun getCacheSize(): Int 312 | 313 | abstract fun getSentAudioFrames(): Long 314 | 315 | abstract fun getSentVideoFrames(): Long 316 | 317 | abstract fun getDroppedAudioFrames(): Long 318 | 319 | abstract fun getDroppedVideoFrames(): Long 320 | 321 | abstract fun resetSentAudioFrames() 322 | 323 | abstract fun resetSentVideoFrames() 324 | 325 | abstract fun resetDroppedAudioFrames() 326 | 327 | abstract fun resetDroppedVideoFrames() 328 | 329 | /** 330 | * Mute microphone, can be called before, while and after stream. 331 | */ 332 | fun disableAudio() { 333 | microphoneManager.mute() 334 | } 335 | 336 | /** 337 | * Enable a muted microphone, can be called before, while and after stream. 338 | */ 339 | fun enableAudio() { 340 | microphoneManager.unMute() 341 | } 342 | 343 | /** 344 | * Get mute state of microphone. 345 | * 346 | * @return true if muted, false if enabled 347 | */ 348 | fun isAudioMuted(): Boolean { 349 | return microphoneManager.isMuted 350 | } 351 | 352 | /** 353 | * Get video camera state 354 | * 355 | * @return true if disabled, false if enabled 356 | */ 357 | fun isVideoEnabled(): Boolean { 358 | return videoEnabled 359 | } 360 | 361 | /** 362 | * Disable send camera frames and send a black image with low bitrate(to reduce bandwith used) 363 | * instance it. 364 | */ 365 | fun disableVideo() { 366 | videoEncoder.startSendBlackImage() 367 | videoEnabled = false 368 | } 369 | 370 | /** 371 | * Enable send camera frames. 372 | */ 373 | fun enableVideo() { 374 | videoEncoder.stopSendBlackImage() 375 | videoEnabled = true 376 | } 377 | 378 | fun getBitrate(): Int { 379 | return videoEncoder.bitRate 380 | } 381 | 382 | fun getResolutionValue(): Int { 383 | return videoEncoder.width * videoEncoder.height 384 | } 385 | 386 | fun getStreamWidth(): Int { 387 | return videoEncoder.width 388 | } 389 | 390 | fun getStreamHeight(): Int { 391 | return videoEncoder.height 392 | } 393 | 394 | fun getGlInterface(): GlInterface { 395 | return glInterface!! 396 | } 397 | 398 | /** 399 | * Set video bitrate of H264 in kb while stream. 400 | * 401 | * @param bitrate H264 in kb. 402 | */ 403 | @RequiresApi(api = Build.VERSION_CODES.KITKAT) 404 | fun setVideoBitrateOnFly(bitrate: Int) { 405 | videoEncoder.setVideoBitrateOnFly(bitrate) 406 | } 407 | 408 | /** 409 | * Set limit FPS while stream. This will be override when you call to prepareVideo method. This 410 | * could produce a change in iFrameInterval. 411 | * 412 | * @param fps frames per second 413 | */ 414 | fun setLimitFPSOnFly(fps: Int) { 415 | videoEncoder.fps = fps 416 | } 417 | 418 | /** 419 | * Get stream state. 420 | * 421 | * @return true if streaming, false if not streaming. 422 | */ 423 | fun isStreaming(): Boolean { 424 | return streaming 425 | } 426 | 427 | /** 428 | * Get preview state. 429 | * 430 | * @return true if enabled, false if disabled. 431 | */ 432 | fun isOnPreview(): Boolean { 433 | return onPreview 434 | } 435 | 436 | /** 437 | * Get record state. 438 | * 439 | * @return true if recording, false if not recoding. 440 | */ 441 | fun isRecording(): Boolean { 442 | return recordController.isRecording 443 | } 444 | 445 | fun pauseRecord() { 446 | recordController.pauseRecord() 447 | } 448 | 449 | fun resumeRecord() { 450 | recordController.resumeRecord() 451 | } 452 | 453 | fun getRecordStatus(): RecordController.Status { 454 | return recordController.status 455 | } 456 | 457 | override fun onComplete() { 458 | glInterface?.surfaceTexture?.setDefaultBufferSize(240, 160) //This is original stream size. 459 | } 460 | 461 | override fun onError() { 462 | 463 | } 464 | 465 | protected abstract fun getAacDataRtp(aacBuffer: ByteBuffer, info: MediaCodec.BufferInfo) 466 | 467 | override fun getAacData(aacBuffer: ByteBuffer, info: MediaCodec.BufferInfo) { 468 | recordController.recordAudio(aacBuffer, info) 469 | if (streaming) getAacDataRtp(aacBuffer, info) 470 | } 471 | 472 | protected abstract fun onSpsPpsVpsRtp(sps: ByteBuffer, pps: ByteBuffer, vps: ByteBuffer?) 473 | 474 | override fun onSpsPps(sps: ByteBuffer, pps: ByteBuffer) { 475 | if (streaming) onSpsPpsVpsRtp(sps, pps, null) 476 | } 477 | 478 | override fun onSpsPpsVps(sps: ByteBuffer, pps: ByteBuffer, vps: ByteBuffer) { 479 | if (streaming) onSpsPpsVpsRtp(sps, pps, vps) 480 | } 481 | 482 | protected abstract fun getH264DataRtp(h264Buffer: ByteBuffer, info: MediaCodec.BufferInfo) 483 | 484 | override fun getVideoData(h264Buffer: ByteBuffer, info: MediaCodec.BufferInfo) { 485 | recordController.recordVideo(h264Buffer, info) 486 | if (streaming) getH264DataRtp(h264Buffer, info) 487 | } 488 | 489 | override fun inputPCMData(buffer: ByteArray, size: Int) { 490 | audioEncoder.inputPCMData(buffer, size) 491 | } 492 | 493 | override fun onVideoFormat(mediaFormat: MediaFormat) { 494 | recordController.setVideoFormat(mediaFormat) 495 | } 496 | 497 | override fun onAudioFormat(mediaFormat: MediaFormat) { 498 | recordController.setAudioFormat(mediaFormat) 499 | } 500 | } -------------------------------------------------------------------------------- /app/src/main/java/com/streye/androidrestreamer/plugin/VLCReStreamerRtmp.kt: -------------------------------------------------------------------------------- 1 | package com.streye.androidrestreamer.plugin 2 | 3 | import android.content.Context 4 | import android.media.MediaCodec 5 | import android.os.Build 6 | import android.support.annotation.RequiresApi 7 | import com.pedro.rtplibrary.view.LightOpenGlView 8 | import com.pedro.rtplibrary.view.OpenGlView 9 | import net.ossrs.rtmp.ConnectCheckerRtmp 10 | import net.ossrs.rtmp.SrsFlvMuxer 11 | import java.nio.ByteBuffer 12 | 13 | 14 | /** 15 | * Created by pedro on 29/03/19. 16 | */ 17 | 18 | class VLCReStreamerRtmp : VLCReStreamerBase { 19 | 20 | private val srsFlvMuxer: SrsFlvMuxer 21 | 22 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) 23 | constructor(openGlView: OpenGlView, connectChecker: ConnectCheckerRtmp) : super(openGlView) { 24 | srsFlvMuxer = SrsFlvMuxer(connectChecker) 25 | } 26 | 27 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) 28 | constructor(lightOpenGlView: LightOpenGlView, connectChecker: ConnectCheckerRtmp) : 29 | super(lightOpenGlView) { 30 | srsFlvMuxer = SrsFlvMuxer(connectChecker) 31 | } 32 | 33 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) 34 | constructor(context: Context, connectChecker: ConnectCheckerRtmp) : super(context) { 35 | srsFlvMuxer = SrsFlvMuxer(connectChecker) 36 | } 37 | 38 | /** 39 | * H264 profile. 40 | * 41 | * @param profileIop Could be ProfileIop.BASELINE or ProfileIop.CONSTRAINED 42 | */ 43 | fun setProfileIop(profileIop: Byte) { 44 | srsFlvMuxer.setProfileIop(profileIop) 45 | } 46 | 47 | @Throws(RuntimeException::class) 48 | override fun resizeCache(newSize: Int) { 49 | srsFlvMuxer.resizeFlvTagCache(newSize) 50 | } 51 | 52 | override fun getCacheSize(): Int { 53 | return srsFlvMuxer.flvTagCacheSize 54 | } 55 | 56 | override fun getSentAudioFrames(): Long { 57 | return srsFlvMuxer.sentAudioFrames 58 | } 59 | 60 | override fun getSentVideoFrames(): Long { 61 | return srsFlvMuxer.sentVideoFrames 62 | } 63 | 64 | override fun getDroppedAudioFrames(): Long { 65 | return srsFlvMuxer.droppedAudioFrames 66 | } 67 | 68 | override fun getDroppedVideoFrames(): Long { 69 | return srsFlvMuxer.droppedVideoFrames 70 | } 71 | 72 | override fun resetSentAudioFrames() { 73 | srsFlvMuxer.resetSentAudioFrames() 74 | } 75 | 76 | override fun resetSentVideoFrames() { 77 | srsFlvMuxer.resetSentVideoFrames() 78 | } 79 | 80 | override fun resetDroppedAudioFrames() { 81 | srsFlvMuxer.resetDroppedAudioFrames() 82 | } 83 | 84 | override fun resetDroppedVideoFrames() { 85 | srsFlvMuxer.resetDroppedVideoFrames() 86 | } 87 | 88 | override fun setAuthorization(user: String, password: String) { 89 | srsFlvMuxer.setAuthorization(user, password) 90 | } 91 | 92 | override fun prepareAudioRtp(isStereo: Boolean, sampleRate: Int) { 93 | srsFlvMuxer.setIsStereo(isStereo) 94 | srsFlvMuxer.setSampleRate(sampleRate) 95 | } 96 | 97 | override fun startStreamRtp(url: String) { 98 | if (videoEncoder.rotation == 90 || videoEncoder.rotation == 270) { 99 | srsFlvMuxer.setVideoResolution(videoEncoder.height, videoEncoder.width) 100 | } else { 101 | srsFlvMuxer.setVideoResolution(videoEncoder.width, videoEncoder.height) 102 | } 103 | srsFlvMuxer.start(url) 104 | } 105 | 106 | override fun stopStreamRtp() { 107 | srsFlvMuxer.stop() 108 | } 109 | 110 | override fun getAacDataRtp(aacBuffer: ByteBuffer, info: MediaCodec.BufferInfo) { 111 | srsFlvMuxer.sendAudio(aacBuffer, info) 112 | } 113 | 114 | override fun onSpsPpsVpsRtp(sps: ByteBuffer, pps: ByteBuffer, vps: ByteBuffer?) { 115 | srsFlvMuxer.setSpsPPs(sps, pps) 116 | } 117 | 118 | override fun getH264DataRtp(h264Buffer: ByteBuffer, info: MediaCodec.BufferInfo) { 119 | srsFlvMuxer.sendVideo(h264Buffer, info) 120 | } 121 | } -------------------------------------------------------------------------------- /app/src/main/java/com/streye/androidrestreamer/plugin/VLCReStreamerRtsp.kt: -------------------------------------------------------------------------------- 1 | package com.streye.androidrestreamer.plugin 2 | 3 | import android.content.Context 4 | import android.media.MediaCodec 5 | import android.os.Build 6 | import android.support.annotation.RequiresApi 7 | import com.pedro.encoder.utils.CodecUtil 8 | import com.pedro.rtplibrary.view.LightOpenGlView 9 | import com.pedro.rtplibrary.view.OpenGlView 10 | import com.pedro.rtsp.rtsp.Protocol 11 | import com.pedro.rtsp.rtsp.RtspClient 12 | import com.pedro.rtsp.rtsp.VideoCodec 13 | import com.pedro.rtsp.utils.ConnectCheckerRtsp 14 | import java.nio.ByteBuffer 15 | 16 | /** 17 | * Created by pedro on 29/03/19. 18 | */ 19 | 20 | class VLCReStreamerRtsp: VLCReStreamerBase { 21 | 22 | private val rtspClient: RtspClient 23 | 24 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) 25 | constructor(openGlView: OpenGlView, connectChecker: ConnectCheckerRtsp) : super(openGlView) { 26 | rtspClient = RtspClient(connectChecker) 27 | } 28 | 29 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) 30 | constructor(lightOpenGlView: LightOpenGlView, connectChecker: ConnectCheckerRtsp) : 31 | super(lightOpenGlView) { 32 | rtspClient = RtspClient(connectChecker) 33 | } 34 | 35 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) 36 | constructor(context: Context, connectChecker: ConnectCheckerRtsp) : super(context) { 37 | rtspClient = RtspClient(connectChecker) 38 | } 39 | 40 | /** 41 | * Internet protocol used. 42 | * 43 | * @param protocol Could be Protocol.TCP or Protocol.UDP. 44 | */ 45 | fun setProtocol(protocol: Protocol) { 46 | rtspClient.setProtocol(protocol) 47 | } 48 | 49 | @Throws(RuntimeException::class) 50 | override fun resizeCache(newSize: Int) { 51 | rtspClient.resizeCache(newSize) 52 | } 53 | 54 | override fun getCacheSize(): Int { 55 | return rtspClient.cacheSize 56 | } 57 | 58 | override fun getSentAudioFrames(): Long { 59 | return rtspClient.sentAudioFrames 60 | } 61 | 62 | override fun getSentVideoFrames(): Long { 63 | return rtspClient.sentVideoFrames 64 | } 65 | 66 | override fun getDroppedAudioFrames(): Long { 67 | return rtspClient.droppedAudioFrames 68 | } 69 | 70 | override fun getDroppedVideoFrames(): Long { 71 | return rtspClient.droppedVideoFrames 72 | } 73 | 74 | override fun resetSentAudioFrames() { 75 | rtspClient.resetSentAudioFrames() 76 | } 77 | 78 | override fun resetSentVideoFrames() { 79 | rtspClient.resetSentVideoFrames() 80 | } 81 | 82 | override fun resetDroppedAudioFrames() { 83 | rtspClient.resetDroppedAudioFrames() 84 | } 85 | 86 | override fun resetDroppedVideoFrames() { 87 | rtspClient.resetDroppedVideoFrames() 88 | } 89 | 90 | fun setVideoCodec(videoCodec: VideoCodec) { 91 | videoEncoder.type = 92 | if (videoCodec == VideoCodec.H265) CodecUtil.H265_MIME else CodecUtil.H264_MIME 93 | } 94 | 95 | override fun setAuthorization(user: String, password: String) { 96 | rtspClient.setAuthorization(user, password) 97 | } 98 | 99 | override fun prepareAudioRtp(isStereo: Boolean, sampleRate: Int) { 100 | rtspClient.setIsStereo(isStereo) 101 | rtspClient.setSampleRate(sampleRate) 102 | } 103 | 104 | override fun startStreamRtp(url: String) { 105 | rtspClient.setUrl(url) 106 | } 107 | 108 | override fun stopStreamRtp() { 109 | rtspClient.disconnect() 110 | } 111 | 112 | override fun getAacDataRtp(aacBuffer: ByteBuffer, info: MediaCodec.BufferInfo) { 113 | rtspClient.sendAudio(aacBuffer, info) 114 | } 115 | 116 | override fun onSpsPpsVpsRtp(sps: ByteBuffer, pps: ByteBuffer, vps: ByteBuffer?) { 117 | rtspClient.setSPSandPPS(sps, pps, vps) 118 | rtspClient.connect() 119 | } 120 | 121 | override fun getH264DataRtp(h264Buffer: ByteBuffer, info: MediaCodec.BufferInfo) { 122 | rtspClient.sendVideo(h264Buffer, info) 123 | } 124 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedroSG94/AndroidReStreamer/9bc6557824370d4d6bc2f78f947976200281f1cf/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedroSG94/AndroidReStreamer/9bc6557824370d4d6bc2f78f947976200281f1cf/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedroSG94/AndroidReStreamer/9bc6557824370d4d6bc2f78f947976200281f1cf/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedroSG94/AndroidReStreamer/9bc6557824370d4d6bc2f78f947976200281f1cf/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedroSG94/AndroidReStreamer/9bc6557824370d4d6bc2f78f947976200281f1cf/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedroSG94/AndroidReStreamer/9bc6557824370d4d6bc2f78f947976200281f1cf/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedroSG94/AndroidReStreamer/9bc6557824370d4d6bc2f78f947976200281f1cf/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedroSG94/AndroidReStreamer/9bc6557824370d4d6bc2f78f947976200281f1cf/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedroSG94/AndroidReStreamer/9bc6557824370d4d6bc2f78f947976200281f1cf/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedroSG94/AndroidReStreamer/9bc6557824370d4d6bc2f78f947976200281f1cf/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Android ReStreamer 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.3.21' 5 | repositories { 6 | google() 7 | jcenter() 8 | maven { url 'https://jitpack.io' } 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.3.2' 12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | maven { url 'https://jitpack.io' } 23 | } 24 | } 25 | 26 | task clean(type: Delete) { 27 | delete rootProject.buildDir 28 | } 29 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # Kotlin code style for this project: "official" or "obsolete": 15 | kotlin.code.style=official 16 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pedroSG94/AndroidReStreamer/9bc6557824370d4d6bc2f78f947976200281f1cf/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Mar 29 13:56:39 CET 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------