1<!-- 2 Copyright (C) 2022 The Android Open Source Project 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 http://www.apache.org/licenses/LICENSE-2.0 7 Unless required by applicable law or agreed to in writing, software 8 distributed under the License is distributed on an "AS IS" BASIS, 9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 See the License for the specific language governing permissions and 11 limitations under the License 12 --> 13# car-evs-helper-lib 14This directory contains two modules that are used by other apps to process 15CarEvsBufferDescriptor and render its contents to the display with EGL. 16* `car-evs-helper-lib:` This library contains `CarEvsGLSurfaceView` and 17 `CarEvsBufferRenderer` classes. 18* `libcarevsglrenderer_jni`: This is a JNI library `CarEvsBufferRenderer` uses 19 to render the contents of `CarEvsBufferDescriptor` with EGL. 20## How to use 21Please follow below instructions to delegate a `CarEvsBufferDescriptor` rendering 22to this library. A reference implementation is also available at 23`packages/services/Car/tests/CarEvsCameraPreviewApp`. 241. Make the application refer to `car-evs-helper-lib` and 25 `libcarevsglrenderer_jni` libraries by adding below lines to `Android.bp`. 26``` 27static_libs: ["car-evs-helper-lib"], 28jni_libs: ["libcarevsglrenderer_jni"], 29``` 302. Implement `CarEvsGLSurfaceView.Callback` interface. For example, 31``` 32/** 33 * This method is called by the renderer to fetch a new frame to draw. 34 */ 35@Override 36public CarEvsBufferDescriptor getNewFrame() { 37 synchronized(mLock) { 38 // Return a buffer to render. 39 return mBufferToRender; 40 } 41} 42/** 43 * This method is called by the renderer when it is done with a passed 44 * CarEvsBufferDescriptor object. 45 */ 46@Override 47public void returnBuffer(CarEvsBufferDescriptor buffer) { 48 // Return a buffer to CarEvsService. 49 try { 50 mEvsManager.returnFrameBuffer(buffer); 51 } catch (Exception e) { 52 ... 53 } 54 ... 55} 56``` 573. Create `CarEvsGLSurfaceView` with the application context, 58 `CarEvsGLSurfaceView.Callback` object, and, optionally, a desired in-plane 59 rotation angle. 60``` 61private CarEvsGLSurfaceView mView; 62@Override 63protected void onCreate(Bundle savedInstanceState) { 64 ... 65 mView = CarEvsGLSurfaceView(getAppliation(), this, /* angleInDegree= */ 0); 66 ... 67} 68``` 694. Start a video stream and update wheneven new frame buffer arrives. For 70 example, 71``` 72private final CarEvsManager.CarEvsStreamCallback mStreamHandler = 73 new CarEvsManager.CarEvsStreamCallback() { 74 ... 75 @Override 76 public void onNewFrame(CarEvsBufferDescriptor buffer) { 77 synchronized(mLock) { 78 mBufferToRender = buffer; 79 } 80 } 81} 82``` 83