Runt
2025-04-14 d0aec90013f06ed4b258235bcabe02e50550271a
app/src/main/java/com/runt/live/cpp/LiveMiniView.java
@@ -1,10 +1,17 @@
package com.runt.live.cpp;
import android.media.AudioFormat;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.Log;
import android.view.Surface;
import com.runt.live.R;
import com.runt.live.data.StreamWindow;
import com.runt.live.ui.stream.LiveLayoutView;
import com.runt.live.util.AudioUtil;
import com.runt.live.util.BitmapUtils;
import com.runt.open.mvi.OpenApplication;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@@ -18,6 +25,7 @@
    static final String TAG = "LiveMiniView";
    public static AudioUtil audioUtil = new AudioUtil();
    static HashMap<String,PcmData> pcmdatas = new HashMap<>();
    static HashMap<String,Bitmap> textBitmaps = new HashMap<>();
    private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
    public static int mainStreamCode = 0 ;
    public static final int FRAME_WIDTH = 1080,FRAME_HEIGHT = 1920,FRAME_PS = 30;
@@ -41,7 +49,38 @@
    public static native void native_push_pcm(byte[] bytes);
    public static native void native_set_main_surface(Surface surface);
    public static native void native_release_main_surface();
    public static native byte[] native_convert_nv21_to_rgba(byte[] bytes,int width,int height);
    public static byte[] drawText(byte[] rgba,int streamCode,int width,int height){
        int length = rgba.length;
        byte[] argb = new byte[length];
        StreamWindow streamWindow = LiveLayoutView.Companion.getLiveStreamsState().getValue().getStream(streamCode);
        String key = streamWindow.getId()+"";
        if(!textBitmaps.containsKey(key)){
            Bitmap bitmap = BitmapUtils.Companion.getInstance().textToBitmap(streamWindow.getRemark(),130f , OpenApplication.Companion.getApplication().getResources().getColor(R.color.white),
                    OpenApplication.Companion.getApplication().getResources().getColor(R.color.transparent));
            textBitmaps.put(key,bitmap);
        }
        Bitmap bitmap = textBitmaps.get(key);
        Bitmap mainBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        //Log.e(TAG , "updateText: ${width}x${cutHeight} ${streamWindow.sizeState.value} ${( streamWindow.sizeState.value.x * 1.0 /  streamWindow.sizeState.value.y )}", )
        ByteBuffer buffer = ByteBuffer.wrap(rgba);
        mainBitmap.copyPixelsFromBuffer(buffer);
        Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap,width,height, true);
        Canvas canvas = new Canvas(mainBitmap);
        // 构建目标区域
        Rect destRect = new Rect(0,0,width,height);
        // 绘制小图到大图
        canvas.drawBitmap(scaledBitmap, null, destRect, null);
        ByteBuffer buffer2 = ByteBuffer.allocate(mainBitmap.getByteCount());
        mainBitmap.copyPixelsToBuffer(buffer2);
        argb = buffer2.array();
        return argb;
    }
    /*    external fun native_update_mini_sn(code : Int ,streamCode : Int, sn : Int)
        external fun native_update_mini_live(code : Int ,streamCode : Int, isLive:Boolean)