修正gradle文件

This commit is contained in:
Raymond Yang 2023-01-18 14:47:46 +08:00
parent ca3744f8be
commit 8288bc57c5
8 changed files with 107 additions and 85 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="16" />
<bytecodeTargetLevel target="11" />
</component>
</project>

View File

@ -7,7 +7,7 @@
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="semeru-16" />
<option name="gradleJvm" value="Embedded JDK" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

View File

@ -16,5 +16,5 @@
</option>
</component>
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" project-jdk-name="16" project-jdk-type="JavaSDK" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK" />
</project>

View File

@ -4,12 +4,12 @@ plugins {
apply plugin: 'kotlin-android'
android {
compileSdk 32
compileSdk 33
defaultConfig {
applicationId "com.ray650128.gstreamer_demo_app"
minSdk 26
targetSdk 32
targetSdk 33
versionCode 1
versionName "1.0"

View File

@ -4,6 +4,7 @@ import android.os.Bundle
import android.util.DisplayMetrics
import android.util.Log
import android.view.LayoutInflater
import android.view.SurfaceHolder
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
@ -15,7 +16,7 @@ import com.ray650128.gstreamer_demo_app.databinding.FragmentGridVideoBinding
import kotlin.math.sqrt
class GridVideoFragment : Fragment(), GstCallback {
class GridVideoFragment : Fragment(), GstCallback, SurfaceHolder.Callback {
private var mPageNum: Int = 0
private var splitMode = 0
@ -26,10 +27,12 @@ class GridVideoFragment : Fragment(), GstCallback {
private lateinit var binding: FragmentGridVideoBinding
private var gstPlayers: ArrayList<GstLibrary?> = ArrayList()
private var gstPlayers: ArrayList<GstLibrary> = ArrayList()
private var videoViews: ArrayList<VideoView> = ArrayList()
private var surfaceHolders: ArrayList<SurfaceHolder> = ArrayList()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -76,15 +79,14 @@ class GridVideoFragment : Fragment(), GstCallback {
}
override fun onDestroyView() {
for (i in gstPlayers.indices) {
gstPlayers[i].close()
}
Log.d("${TAG}_$mPageNum", "onDestroyView()")
super.onDestroyView()
}
override fun onDestroy() {
for (i in gstPlayers.indices) {
gstPlayers[i]?.release()
gstPlayers[i] = null
}
Log.d("${TAG}_$mPageNum", "onDestroy()")
super.onDestroy()
}
@ -112,63 +114,66 @@ class GridVideoFragment : Fragment(), GstCallback {
for (col in 0 until maxCol) {
for (row in 0 until maxRow) {
val videoView = VideoView(requireContext()).apply {
layoutParams = GridLayout.LayoutParams().apply {
height = cellHeight
width = cellWidth
val videoView = VideoView(requireContext())
val layoutParams = GridLayout.LayoutParams().apply {
height = cellHeight
width = cellWidth
topMargin = 0.dp
bottomMargin = 0.dp
marginEnd = 0.dp
marginStart = 0.dp
topMargin = 0.dp
bottomMargin = 0.dp
marginEnd = 0.dp
marginStart = 0.dp
// 調整間距
when (splitMode) {
4 -> {
when (col) {
0 -> bottomMargin = 2.dp
1 -> topMargin = 2.dp
}
when (row) {
0 -> marginEnd = 2.dp
1 -> marginStart = 2.dp
}
// 調整間距
when (splitMode) {
4 -> {
when (col) {
0 -> bottomMargin = 2.dp
1 -> topMargin = 2.dp
}
9 -> {
if (col == 1) {
topMargin = 4.dp
bottomMargin = 4.dp
}
if (row == 1) {
marginEnd = 4.dp
marginStart = 4.dp
}
when (row) {
0 -> marginEnd = 2.dp
1 -> marginStart = 2.dp
}
}
9 -> {
if (col == 1) {
topMargin = 4.dp
bottomMargin = 4.dp
}
if (row == 1) {
marginEnd = 4.dp
marginStart = 4.dp
}
}
}
}
baseView.addView(videoView)
baseView.addView(videoView, layoutParams)
videoViews.add(videoView)
videoView.videoView.holder.addCallback(this@GridVideoFragment)
surfaceHolders.add(videoView.videoView.holder)
}
}
}
for (index in videoViews.indices) {
gstPlayers.add(GstLibrary(requireContext(), data[index]))
gstPlayers[index]?.setSurfaceView(videoViews[index].videoView)
gstPlayers[index]?.setOnStatusChangeListener(this)
gstPlayers[index].setOnStatusChangeListener(this)
}
}
private fun playAll() {
for (index in data.indices) {
gstPlayers[index]?.play()
gstPlayers[index].play()
}
}
private fun stopAll() {
for (index in data.indices) {
gstPlayers[index]?.stop()
gstPlayers[index].stop()
gstPlayers[index].close()
}
}
@ -189,6 +194,23 @@ class GridVideoFragment : Fragment(), GstCallback {
Log.d("${TAG}_$mPageNum", "GstPlayer #$index: $message")
}
override fun surfaceCreated(holder: SurfaceHolder) {
val index = surfaceHolders.indexOf(holder)
gstPlayers[index].setSurfaceHolder(holder)
Log.d("GStreamer", "Surface created: " + holder.surface)
}
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
//val index = surfaceHolders.indexOf(holder)
Log.d("GStreamer", "Surface changed to format $format width $width height $height")
}
override fun surfaceDestroyed(holder: SurfaceHolder) {
val index = surfaceHolders.indexOf(holder)
gstPlayers[index].releaseSurface()
Log.d("GStreamer", "Surface destroyed")
}
companion object {
private val TAG = GridVideoFragment::class.java.simpleName
private const val ARG_PAGE_NUM = "page_number"

View File

@ -22,20 +22,31 @@ class MainActivity : AppCompatActivity() {
private lateinit var splitVideoViewAdapter: ViewPager2Adapter
/*@SuppressLint("AuthLeak")
@SuppressLint("AuthLeak")
private val defaultMediaUris = arrayListOf(
arrayListOf(
"rtsp://admin:admin@192.168.0.77:554/media/video2",
"rtsp://admin:1q2w3e4r!@192.168.0.79:554/media/video2",
"rtsp://admin:1q2w3e4r~@211.23.78.226:8588/media/video2",
"rtsp://admin:admin@211.23.78.226:8574/v02",
"rtsp://admin:admin@211.23.78.226:8575/v02",
"rtsp://admin:admin@192.168.0.77:554/media/video2",
"rtsp://admin:123456@192.168.0.80:554/profile2",
"rtsp://admin:123456@192.168.0.83:554/profile2",
"rtsp://admin:123456@192.168.0.84:554/profile2",
"rtsp://admin:admin@192.168.0.86:554/v2",
"rtsp://admin:admin@192.168.0.89:554/v02",
"rtsp://admin:1q2w3e4r!@60.249.32.50:554/unicast/c8/s1/live",
"rtsp://admin:1q2w3e4r!@192.168.0.79:554/media/video2",
"rtsp://admin:1q2w3e4r~@211.23.78.226:8588/media/video2",
"rtsp://admin:admin@211.23.78.226:8574/v02",
),
arrayListOf(
"",
"",
"",
"",
"",
"",
"",
"",
"",
),
/*arrayListOf(
"rtsp://admin:1q2w3e4r!@60.249.32.50:554/unicast/c1/s1/live",
"rtsp://admin:1q2w3e4r!@60.249.32.50:554/unicast/c2/s1/live",
"rtsp://admin:1q2w3e4r!@60.249.32.50:554/unicast/c3/s1/live",
@ -45,7 +56,7 @@ class MainActivity : AppCompatActivity() {
"rtsp://admin:1q2w3e4r!@60.249.32.50:554/unicast/c7/s1/live",
"rtsp://admin:1q2w3e4r!@60.249.32.50:554/unicast/c8/s1/live",
"rtsp://admin:1q2w3e4r!@60.249.32.50:554/unicast/c9/s1/live"
),
),*/
arrayListOf(
"",
"",
@ -57,9 +68,9 @@ class MainActivity : AppCompatActivity() {
"",
"",
)
)*/
)
@SuppressLint("AuthLeak")
/*@SuppressLint("AuthLeak")
private val defaultMediaUris = arrayListOf(
arrayListOf(
"rtsp://admin:admin@211.23.78.226:8574/v02"
@ -69,8 +80,11 @@ class MainActivity : AppCompatActivity() {
),
arrayListOf(
"rtsp://admin:admin@192.168.0.77:554/media/video2"
),
arrayListOf(
"http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_1080p_60fps_normal.mp4"
)
)
)*/
override fun onCreate(savedInstanceState: Bundle?) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)

View File

@ -1,11 +1,11 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 32
compileSdkVersion 33
defaultConfig {
minSdkVersion 15
targetSdkVersion 32
targetSdkVersion 33
versionCode 1
versionName "1.0"

View File

@ -10,16 +10,15 @@ import android.view.SurfaceView;
import org.freedesktop.gstreamer.GStreamer;
public class GstLibrary implements SurfaceHolder.Callback {
import java.io.Closeable;
import java.io.IOException;
public class GstLibrary implements Closeable {
final Context mAppContext;
private GstCallback gstCallback;
private GStreamerSurfaceView surfaceView;
private final Handler mainHandler = new Handler(Looper.getMainLooper());
private final String rtspUrl;
public GstLibrary(Context context, String rtspUrl) {
@ -61,18 +60,11 @@ public class GstLibrary implements SurfaceHolder.Callback {
nativeSurfaceFinalize();
}
public void release() {
nativeFinalize();
}
public void setOnStatusChangeListener(GstCallback callback) {
this.gstCallback = callback;
}
public void setSurfaceView(GStreamerSurfaceView surfaceView) {
this.surfaceView = surfaceView;
SurfaceHolder holder = this.surfaceView.getHolder();
holder.addCallback(this);
public void setSurfaceHolder(SurfaceHolder holder) {
nativeSurfaceInit(holder.getSurface());
}
@ -110,11 +102,11 @@ public class GstLibrary implements SurfaceHolder.Callback {
// Inform the video surface about the new size and recalculate the layout.
private void onMediaSizeChanged (int width, int height) {
Log.i ("GStreamer", "Media size changed to " + width + "x" + height);
mainHandler.post(() -> {
/*mainHandler.post(() -> {
surfaceView.media_width = width;
surfaceView.media_height = height;
surfaceView.requestLayout();
});
});*/
}
static {
@ -123,18 +115,12 @@ public class GstLibrary implements SurfaceHolder.Callback {
nativeClassInit();
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Log.d("GStreamer", "Surface changed to format " + format + " width " + width + " height " + height);
}
public void surfaceCreated(SurfaceHolder holder) {
Log.d("GStreamer", "Surface created: " + holder.getSurface());
nativeSurfaceInit (holder.getSurface());
}
public void surfaceDestroyed(SurfaceHolder holder) {
Log.d("GStreamer", "Surface destroyed");
nativePause();
nativeSurfaceFinalize();
@Override
public void close() throws IOException {
try {
nativeFinalize();
} catch (Exception e) {
e.printStackTrace();
}
}
}