Skip to content

Commit 491e496

Browse files
committed
move preview new classes outside of GlInterface and add access to new methods to StreamBase
1 parent 173d1f6 commit 491e496

File tree

4 files changed

+104
-34
lines changed

4 files changed

+104
-34
lines changed

library/src/main/java/com/pedro/library/base/StreamBase.kt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import com.pedro.library.util.FpsListener
5151
import com.pedro.library.util.PreviewCallback
5252
import com.pedro.library.util.streamclient.StreamBaseClient
5353
import com.pedro.library.view.GlStreamInterface
54+
import com.pedro.library.view.preview.MultiPreviewConfig
5455
import java.nio.ByteBuffer
5556
import kotlin.math.max
5657

@@ -366,15 +367,30 @@ abstract class StreamBase(
366367
if (removeCallbacks) previewCallback.removeCallbacks()
367368
}
368369

369-
fun addPreviewSurface(
370-
surface: Surface,
371-
config: GlStreamInterface.MultiPreviewConfig
372-
) {
370+
fun addPreviewSurface(surface: Surface, config: MultiPreviewConfig) {
373371
if (!surface.isValid) throw IllegalArgumentException("Make sure the Surface is valid")
374372
if (!isOnPreview) throw IllegalStateException("Preview must be started before adding surfaces")
375373
glInterface.addMultiPreviewSurface(surface, config)
376374
}
377375

376+
fun removeMultiPreviewSurface(surface: Surface) {
377+
glInterface.removeMultiPreviewSurface(surface)
378+
}
379+
380+
fun removeAllMultiPreviewSurfaces() {
381+
glInterface.removeAllMultiPreviewSurfaces()
382+
}
383+
384+
fun updateMultiPreviewConfig(surface: Surface, config: MultiPreviewConfig): Boolean {
385+
return glInterface.updateMultiPreviewConfig(surface, config)
386+
}
387+
388+
fun hasMultiPreviewSurface(surface: Surface): Boolean {
389+
return glInterface.hasMultiPreviewSurface(surface)
390+
}
391+
392+
fun getMultiPreviewSurfaceCount(): Int = glInterface.getMultiPreviewSurfaceCount()
393+
378394
/**
379395
* Change video source to Camera1 or Camera2.
380396
* Must be called after prepareVideo.

library/src/main/java/com/pedro/library/view/GlStreamInterface.kt

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import com.pedro.encoder.utils.gl.AspectRatioMode
3939
import com.pedro.encoder.utils.gl.GlUtil
4040
import com.pedro.library.util.Filter
4141
import com.pedro.library.util.SensorRotationManager
42+
import com.pedro.library.view.preview.MultiPreviewConfig
43+
import com.pedro.library.view.preview.PreviewSurfaceInfo
4244
import java.util.concurrent.BlockingQueue
4345
import java.util.concurrent.ConcurrentHashMap
4446
import java.util.concurrent.ExecutorService
@@ -63,32 +65,6 @@ class GlStreamInterface(private val context: Context): OnFrameAvailableListener,
6365
private val multiPreviewSurfaceManagers = ConcurrentHashMap<Surface, PreviewSurfaceInfo>()
6466
private val mainRender = MainRender()
6567

66-
/**
67-
* User-facing configuration for a multi-preview surface.
68-
* All configuration fields are mutable to support dynamic updates.
69-
*
70-
* @param width the width of the preview. 0 to use preview or encoder resolution
71-
* @param height the height of the preview. 0 to use preview or encoder resolution
72-
* @param horizontalFlip true to flip horizontally
73-
* @param verticalFlip true to flip vertically
74-
* @param aspectRatioMode aspect ratio mode for this surface
75-
* @param isPortrait true for portrait orientation, false for landscape
76-
* @param viewPort viewport for this surface. null for full screen
77-
*/
78-
data class MultiPreviewConfig(
79-
var width: Int = 0,
80-
var height: Int = 0,
81-
var horizontalFlip: Boolean = false,
82-
var verticalFlip: Boolean = false,
83-
var aspectRatioMode: AspectRatioMode = AspectRatioMode.Adjust,
84-
var isPortrait: Boolean = false,
85-
var viewPort: ViewPort? = null
86-
)
87-
88-
data class PreviewSurfaceInfo(
89-
val surfaceManager: SurfaceManager,
90-
val config: MultiPreviewConfig
91-
)
9268
private var encoderWidth = 0
9369
private var encoderHeight = 0
9470
private var encoderRecordWidth = 0
@@ -419,10 +395,18 @@ class GlStreamInterface(private val context: Context): OnFrameAvailableListener,
419395
val w = if (config.width > 0) config.width else if (previewWidth == 0) encoderWidth else previewWidth
420396
val h = if (config.height > 0) config.height else if (previewHeight == 0) encoderHeight else previewHeight
421397

422-
val surfaceMgr = SurfaceManager()
423-
surfaceMgr.eglSetup(surface, surfaceManager)
424-
val finalConfig = MultiPreviewConfig(w, h, config.horizontalFlip, config.verticalFlip, config.aspectRatioMode, config.isPortrait, config.viewPort)
425-
multiPreviewSurfaceManagers[surface] = PreviewSurfaceInfo(surfaceMgr, finalConfig)
398+
val surfaceManager = SurfaceManager()
399+
surfaceManager.eglSetup(surface, this@GlStreamInterface.surfaceManager)
400+
val finalConfig = MultiPreviewConfig(
401+
w,
402+
h,
403+
config.horizontalFlip,
404+
config.verticalFlip,
405+
config.aspectRatioMode,
406+
config.isPortrait,
407+
config.viewPort
408+
)
409+
multiPreviewSurfaceManagers[surface] = PreviewSurfaceInfo(surfaceManager, finalConfig)
426410
}
427411
}
428412

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
*
3+
* * Copyright (C) 2024 pedroSG94.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * http://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package com.pedro.library.view.preview
20+
21+
import com.pedro.encoder.utils.ViewPort
22+
import com.pedro.encoder.utils.gl.AspectRatioMode
23+
24+
/**
25+
* User-facing configuration for a multi-preview surface.
26+
* All configuration fields are mutable to support dynamic updates.
27+
*
28+
* @param width the width of the preview. 0 to use preview or encoder resolution
29+
* @param height the height of the preview. 0 to use preview or encoder resolution
30+
* @param horizontalFlip true to flip horizontally
31+
* @param verticalFlip true to flip vertically
32+
* @param aspectRatioMode aspect ratio mode for this surface
33+
* @param isPortrait true for portrait orientation, false for landscape
34+
* @param viewPort viewport for this surface. null for full screen
35+
*/
36+
data class MultiPreviewConfig(
37+
var width: Int = 0,
38+
var height: Int = 0,
39+
var horizontalFlip: Boolean = false,
40+
var verticalFlip: Boolean = false,
41+
var aspectRatioMode: AspectRatioMode = AspectRatioMode.Adjust,
42+
var isPortrait: Boolean = false,
43+
var viewPort: ViewPort? = null
44+
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
*
3+
* * Copyright (C) 2024 pedroSG94.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * http://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package com.pedro.library.view.preview
20+
21+
import com.pedro.encoder.input.gl.SurfaceManager
22+
23+
internal data class PreviewSurfaceInfo(
24+
val surfaceManager: SurfaceManager,
25+
val config: MultiPreviewConfig
26+
)

0 commit comments

Comments
 (0)