import android.os.SystemProperties;
String prop_name = "persist.car.system_type"
if ("0".equals(SystemProperties.get( prop_name))) //比對prop_name值 == 0
{
//比對prop_name值 == 0
}else
{
//比對prop_name值 != 0(不等於0)
}
關於我 : Kun-hsien(KH)
研究&開發是一段艱難的旅程:享受在資料字串與信號間遊走。
從VB->HTML->PHP->MySQL->Fedora->MCSE->JAVA->XML->Android->Embeded C->C ->C# ->Python-> Arduino -> IoT ->MQTT ->Spark ->CAN ->I2C->無人機....
這裡除了紀錄開發Apps遇到問題的Solution並分享給大家外,各種開發技術的文章也在此探討!希望大家都能順利解決自己遇到的問題!
import android.os.SystemProperties;
String prop_name = "persist.car.system_type"
if ("0".equals(SystemProperties.get( prop_name))) //比對prop_name值 == 0
{
//比對prop_name值 == 0
}else
{
//比對prop_name值 != 0(不等於0)
}
RAW pixels viewer(免安裝的網路資源) : https://rawpixels.net/
7yuv(需下載安裝於電腦中) : http://datahammer.de/
類似RGB的概念 : YUV也是三種色彩元素代稱, Y=明亮度, U=色度, V=濃度
YUV為視訊影像的編碼格式 目前專案僅用到N21與N12兩種格式的驗證應用
YUV文獻 : https://www.itread01.com/content/1542704886.html
N21與N12根據定義為YUV中 UV順序相反,
N21為Y填完再用UV交替填完,例 : YYYYVUVUVU
YUV格式中又分為YUV444,YUV422,YUV420
1.YUV 4:4:4取樣,每一個Y對應一組UV分量,一個YUV佔8+8+8 = 24bits 3個位元組。
2.YUV 4:2:2取樣,每兩個Y共用一組UV分量,一個YUV佔8+4+4 = 16bits 2個位元組。
3.YUV 4:2:0取樣,每四個Y共用一組UV分量,一個YUV佔8+2+2 = 12bits 1.5個位元組。
YUV420中又分為,YUV420SP與YUV420P
在camera相關案子得應用中有平台影響推流的問題待釐清,就順勢追了一下code
private final Timer timer = new Timer();
private final TimerTask tickTask = new TimerTask() {
public void run() {
VirtualCameraCapturer.this.tick();
}};
private void tick() {
// Log.d("CAM_AntiPushEngine", "VirtualCameraCapturer frame=" + frame + " buffersize=" + frame.getBuffer().getHeight());
capturerObserver.onFrameCaptured(frame);
}
其中frame由另一函式放張圖片來更新再透過tick作推送
try {
Log.d(TAG, "VirtualCameraCapturer...1");
inputStream = context.getAssets().open("clip_480x360_Format-0.yuv");
int size = 480 * 360 * 3 / 2;
byte[] data = new byte[size];
inputStream.read(data, 0, size);
Log.v("NV12","KH123");
VideoFrame.Buffer frameBuffer = new NV12Buffer(480, 360, 480, 360, ByteBuffer.wrap(data), new Runnable() {
//VideoFrame.Buffer frameBuffer = new NV21Buffer(data, 480, 360, new Runnable() {
@Override
public void run() {
Log.d("lhq", "NV21Buffer release");
}
});
Log.v("NV12","KH456");
long captureTimeNs = TimeUnit.MILLISECONDS.toNanos(SystemClock.elapsedRealtime());
frame = new VideoFrame(frameBuffer, 0, captureTimeNs);
Log.v(TAG, "VirtualCameraCapturer...2");
} catch (IOException e) {
e.printStackTrace();
}
由上述程式碼可看到 應用程式新增一個timer tick去定期將camera擷取到的影像frame推送到onFrameCaptured裡面。
此時我們追到另一個code base使用Find in path看誰會去呼叫onFrameCaptured函式。
在webrtc中的Camera1Session.javad查詢到
private void listenForTextureFrames() {
private void listenForBytebufferFrames() {
會使用到onFrameCaptured
在 listenForTextureFrames()中可在以下程式碼段前後擷取出raw data看其格式及圖片檢查是否正確
inal VideoFrame modifiedFrame = new VideoFrame(
CameraSession.createTextureBufferWithModifiedTransformMatrix(
(TextureBufferImpl) frame.getBuffer(),
/* mirror= */ info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT,
/* rotation= */ 0),
/* rotation= */ getFrameOrientation(), frame.getTimestampNs());
Log.v(TAG, "Modified frame");


public Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight) { int width = bm.getWidth(); int height = bm.getHeight(); float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // CREATE A MATRIX FOR THE MANIPULATION Matrix matrix = new Matrix(); // RESIZE THE BIT MAP matrix.postScale(scaleWidth, scaleHeight); // "RECREATE" THE NEW BITMAP Bitmap resizedBitmap = Bitmap.createBitmap( bm, 0, 0, width, height, matrix, false); //bm.recycle(); return resizedBitmap;}
import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent; public class BootBroadcastReceiver extends BroadcastReceiver { static final String ACTION = "android.intent.action.BOOT_COMPLETED"; @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ACTION)) { Intent mainActivityIntent = new Intent(context, MainActivity.class); // 要啟動的Activity mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(mainActivityIntent); } } }
android:name=".BootBroadcastReceiver"/>android:name=".MainActivity" android:screenOrientation="landscape">
android:name="android.intent.action.QUICKBOOT_POWERON" />
android:name="android.permission.RECEIVE_BOOT_COMPLETED">
1
|
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED
|
1
|
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n package_name/class_name
|
android:name="android.intent.category.LAUNCHER" />android:name="android.intent.category.HOME" />
if (getSupportActionBar() != null){
getSupportActionBar().hide();
}
Camera.Paramenters params = mCamera.getParameters();
params.setZoom(zoomLevel);
mCamera.setParameters(params);
final int zoomScale = 200;
captureBuilder.set(CaptureRequest.SCALER_CROP_REGION, new
Rect(zoomScale * mZoomLevel, zoomScale * mZoomLevel, mStartBounds.right
- (zoomScale * mZoomLevel), mStartBounds.bottom - (zoomScale * mZoomLevel)));
mCameraTextureView.setRotationX(180.0f);
package com.example.multiscreencameratest; import android.Manifest;import android.app.Service;import android.content.ComponentName;import android.content.Intent;import android.content.ServiceConnection;import android.content.pm.PackageManager;import android.graphics.Bitmap;import android.graphics.Matrix;import android.graphics.SurfaceTexture;import android.hardware.camera2.CameraAccessException;import android.hardware.camera2.CameraCaptureSession;import android.hardware.camera2.CameraCharacteristics;import android.hardware.camera2.CameraDevice;import android.hardware.camera2.CameraManager;import android.hardware.camera2.CameraMetadata;import android.hardware.camera2.CaptureRequest;import android.hardware.camera2.params.StreamConfigurationMap;import android.media.MediaPlayer;import android.os.Bundle; import android.app.Activity;import android.app.AlertDialog;import android.app.Presentation;import android.content.Context;import android.content.DialogInterface;import android.content.res.Resources;import android.hardware.display.DisplayManager;import android.os.Handler;import android.os.HandlerThread;import android.os.IBinder;import android.os.Message;import android.support.annotation.NonNull;import android.support.v4.app.ActivityCompat;import android.support.v7.app.AppCompatActivity;import android.util.Log;import android.util.Size;import android.util.SparseArray;import android.view.Display;import android.view.Surface;import android.view.SurfaceHolder;import android.view.SurfaceView;import android.view.TextureView;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;import android.widget.AdapterView;import android.widget.AdapterView.OnItemSelectedListener;import android.widget.ArrayAdapter;import android.widget.Button;import android.widget.ListView;import android.widget.Spinner;import android.widget.TextView;import android.widget.Toast; import java.io.File;import java.io.IOException;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList; import java.util.Arrays;import java.util.HashMap;import java.util.Map; public class MainActivity extends AppCompatActivity implements View.OnClickListener, AdapterView.OnItemClickListener { private final String LOG_TAG = "MultiScreenCameraTest"; private static final int MESG_UPDATE_DISPLAY = 100; private static final int MESG_SHOW_SCRENN = 101; private static final int MESG_SHOW_ALL_SCRENN = 102; private static final int MESG_HIDE_SCRENN = 103; private static final int MESG_HIDE_ALL_SCRENN = 104; private static final int MESG_SCAN_CAMERA = 200; private Context mContext = null; private MsgHandler mMsgHandler = null; private DisplayManager mDisplayManager; private DisplayListAdapter mDisplayListAdapter; private TextureView mCameraTextureView; private boolean mIsTextureViewAvailable = false; private CameraManager mCameraManager = null; private CameraDevice mCameraDevice = null; private Size mImageDimension = null; protected CameraCaptureSession mCameraCaptureSession = null; protected CaptureRequest.Builder mCaptureRequestBuilder = null; private Handler mBackgroundHandler; private HandlerThread mBackgroundThread; private Display[] mDisplays; private boolean mShowAllDisplays = true; private HashMapMultiScreen> mMultiScreenMap = null;,