- Brief introduction
- Flow Display
- 1. Decide to establish a connection to the camera and initialize the corresponding object in some way, for example, most commonly via the Internet.
- 2. Create session, initialize the session
- 3. Get an instance of the interface that provides the Streaming fucntion. Currently, there are two Streaming interfaces.
- 4. Decide which rendering method to use
- 5. Open stream
- 6. Close stream
- 7. Release Session Resources
- 8. Release the resources corresponding to the connection object
- Several different rendering modes
- Sample code
Brief introduction
As mentioned in the previous document, The two major SDKs provided by the SDK that can be used independently. This article describes how to use the Streaming SDK to develop corresponding functions. Such as Opening or closing the video stream, fetching frames, rendering frames and other operations.
Flow Display
1. Decide to establish a connection to the camera and initialize the corresponding object in some way, for example, most commonly via the Internet.
transport = new ICatchINETTransport("192.168.1.1");try {transport.prepareTransport();} catch (IchTransportException e) {e.printStackTrace();System.exit(1);}
2. Create session, initialize the session
DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();ICatchGLDisplayPPI displayPPI = new ICatchGLDisplayPPI(displayMetrics.xdpi, displayMetrics.ydpi);/* create session, prepare session, and get the preview client */try {this.pancamSession = ICatchPancamSession.createSession();this.pancamSession.prepareSession(this.transport, ICatchGLColor.BLACK, displayPPI);} catch (IchTransportException e) {e.printStackTrace();System.exit(-1);}this.preview = this.pancamSession.getPreview();if (this.preview == null) {System.exit(-1);}
3. Get an instance of the interface that provides the Streaming fucntion. Currently, there are two Streaming interfaces.
- Real-time preview, the interface is ICatchIPancamPview, the acquisition method is as follows:
this.preview = this.pancamSession.getPreview();if (this.preview == null) {System.exit(-1);}
In subsequent documents, we sill use ICatchIPancamPreview as an interface to show the use of related methods
- Camera video playback, the interface is ICatchPancamVideoPlayback, the acquisition method is as follows:
this.videoPlayback = this.pancamSession.getVideoPlayback();if (this.videoPlayback == null) {System.exit(-1);}
4. Decide which rendering method to use
try {/* disable render, create streaming provider(app instance) */ICatchIStreamProvider streamProvider = this.preview.disableRender();this.streamingHandler = new StreamingHandler(streamProvider);/* must assign a surface view to stream handler to act as render surface */SurfaceView surfaceView = findViewById(R.id.surfaceView1);this.streamingHandler.setSurfaceView(surfaceView);}catch(Exception ex){ex.printStackTrace();System.exit(-1);}
In the above example, we want to use App rendering, So we created a class named StreamingHandler (encapsulating the ICatchIStreamProvider interface) for a series of operations such as fetching, decoding, and rendering.
For more information:
- Please refer to the implementation code of the class, in order to demonstrate the main function, I believe its implementation is simple enough
- There is also a document for reference, here
5. Open stream
/* create stream parameter & use it as parameter to start stream */try {ICatchStreamParam param = new ICatchH264StreamParam();boolean retVal = preview.start(param);if (!retVal) {return;}}catch(Exception ex) {ex.printStackTrace();return;}streamingHandler.start();
Here is an extra line of code, streamingHandler.start ();, which is used to start frame fetching, decoding, and rendering related operations on the App side.
6. Close stream
/* stop grab frame & render process */streamingHandler.stop();try {preview.stop();}catch (Exception ex) {ex.printStackTrace();}
7. Release Session Resources
try {pancamSession.destroySession();} catch (IchInvalidSessionException e) {e.printStackTrace();System.exit(-1);}
8. Release the resources corresponding to the connection object
try {this.transport.destroyTransport();} catch (IchTransportException e) {e.printStackTrace();}
Several different rendering modes
According to whether The SDK rendering is required, The streaming app development is divided into three main modes.
1. Rendering frames without The SDK
Since the SDK is not sued to render video streams, App developers need to manually take frames, decode(if needed), and then render frames(including both audio and video frames).
It should be noted that if audio is turned on, the SDK will have audio and video synchronization processing(video frames refer to audio frames). At this time, you need to set the aduio frame delay appropriately.
2. Use SDK to render normal video stream:
SurfaceView surfaceView = findViewById(R.id.surfaceView1);ICatchISurfaceContext surfaceContext = new ICatchSurfaceContext(surfaceView.getHolder().getSurface());boolean retVal = this.preview.enableRender(surfaceContext);if (!retVal) {System.exit(-1);}
This is probably the easiest and fastest way to see frames on your phone.
3. Use SDK to render panoramic video stream:
4. Get frames by the app, but still use the SDK rendering(With the help of ICatchIPancamImage interface)
This may be useful in some cases. Imagine a situation where the App wants to get frames to do some special things (such as face recognition, AI classification, etc.), and wants to use the SDK rendering.
- See
SDKRenderActivity2file in the sample project. - The
SDKRenderRGBAclass will also provide some help.
Sample code
We also provide a project based on Android studio, which is used to show some of the operations mentioned above. Now we will explain some contents in the project:
You can download the source code from github
1. Mainly entry file
- icatchtek.com.streamingalone.ui.apprender.AppRenderActivity
It is used to display rendering using App. There is another tool class provided by App under the same package path. It is also an entry for frame fetching, decoding, and rendering. Customers can refer to the main sample Flow and related classes, interfaces, and API usage to write their own code to achieve the unique functions of the client app. - icatchtek.com.streamingalone.ui.sdkrender.mode1.SDKRenderActivity1
Used to demonstrate rendering with SDK icatchtek.com.streamingalone.ui.sdkrender.mode2.SDKRenderActivity2
It is used to display using the SDK to render, but the frame is still taken by the app. After the customer performs the additional processing on the frame, the SDK will render it on the screen.2. Some tips
The main process, the code will have the following comments:
/* ------step x------------------------*//* description *//* ------step x------------------------*/
After the user analyzes several different Activity entry files, it will be found that there are 6 steps in total, except for Step 3, the other steps are completely the same. Step3 will lead to different operation results due to different rendering methods, such as:
- With SDK rendering, the app does not need to create new classes to do anything. The SDK will do all the frame-related work.
- With App rendering, the App needs to create additional threads to obtain stream information and frames. Of course, this way provides sufficient flexibility for App development.
