Revision record

Version recorder date judges Review content
0.9 吴刚 2018 first draft
1.0 方一鸣 2018 Update how SDK is imported
1.1 吴刚 2019.3.13 Callback interface for updating audio and video dataAdded BJCastV2 release note. Description of new service release and service discovery

[TOC]

1 Overview

1.1 Aim

It is used to guide the development and testing of the developers who use the Bijie BJCast receiver SDK.

1.2 Target

This document is applicable to developers who develop the BJCast receiving end of the Android platform.

1.3 Abbreviations definition

abbreviations definition
BJCast BiJie wireless screen cast protocol

2 Scope

2.1 Function

This SDK can accept a screen request form Mac , Windows , and Android.

All four emitters use BJCast projection protocol. BJCast protocol is currently divided into BJCastV1, BJCastV2 versions.

Windows/Android sender uses BJCastV1, Mac sender uses BJCastV2.

The external interface of BJCastV1 and BJCastV2 at the receiver is consistent.

2.2 SDK frame

BJCast Receiver SDK is generally divided into two layers.

1) cast_base_lib-1.0.17-release.aar:it is an Android Module,it defines the basic interface of MediaChannel,Module.

2) bj_cast_lib-1.0.18-release.aar: it is an Android Module,which defines BJCastModule,and related JNI interface.

App is developed based on bj_cast_lib-1.0.18-release.aar. Applications should not, in principle, modify what is in cast_base_lib-1.0.17-release.aar, bj_cast_lib-1.0.18-release.aar.

img

The above figure is the core class diagram,customers need to implement the ModuleImpItf interface and the functional interface of the MediaChannel.

2.3 The DEMO use of DSK

BJCastReceiverSDKDemo is a reference implementation of receiver,which is based on bj_cast_lib-1.0.15-release.aar, and realizes function of BJCast receiver. In which BJCastModuleImp realizes ModuleImpItf interface,GLScreenRenderChannel realizes MediaChannelinterface.

2.4 SDK delivery

  • Dynamic depot
  • DEMO source code
  • SDK interface document

3 Interface

3.1 Description

Interfaces are mainly in BJCastModule and MediaChannel.Users can implement their own related interfaces, You can also refer to the DEMO source code implementation provided by our company.

3.2 Set up a custom implementation class interface

public void setImp(ModuleImpItf imp)

3.3 Initialization interface

public native boolean init(Properties props);

In which name means the name of receiver,The name that searched by BJCast sender is passed through this parameter; pwd is the password to be inputted when beginning screen casting , can be null.

BJCastModule calss Init way to Initialize the BJCast receiver module. Called when App is initializing,The BJCastModule object should be designed to be only one.

Where Properties supports the setting of the following properties:

PARA_NAME_DEVICE_NAME:the name of receiver, also the name searched by the discovery protocol(If the customer does not need to use our discovery protocol,they may not have to care about this attribute)。

PARA_NAME_SERVICE_PORTBJCastV1 service interface,BJCastV1 service interface default is 8188BJCastV2 service interface is BJCastV1 service interface +2,default is 8190. User can set it.

PARA_NAME_MDNS_DEAMON_ENABLE:Whether internal MDNSD is enabled to publish Airplay services,value rang is 0,1. The default is 1.

Notice:If the receiver runs BJAirplay and BJCast at the same time,then need to set PARA_NAME_MDNS_DEAMON_ENABLE to 1 in one of the modules, and the other must be 0;If both modules initialize, the parameter is 1,it will lead to one of the two release fail.

3.4 Deinitialize the interface

public native void fini();

Use BJCastModule class’s fini way to deinitialize BJCast module. Called when App destroys the BJCast receiver service.

3.5 Session access interface

public MediaChannel reqMediaChannel(MediaChannelInfo info) ;

Iput:session information,describe its business type.

Output: The MediaChannel object that be created.

This is a callback interface, when the BJCast protocol stack finds session access, JNI lay will call this interface actively,the application layer needs to implement the relevant logic,customer need to implement this logic in the customer’s own ModuleItf implementation class.

Specific implementation can refer to DEMO source code.

3.6 Session end interface

public void relMediaChannel(MediaChannel channel)

Call back interface, called when the underlying receiving session ends. Realize related logic in Application layer.

Specific implementation can refer to DEMO source code.

3.7 Application layer end interface

public void kickOut(MediaChannel channel)

The application layer actively ends the session interface.

3.8 Session processing interface

When the session is established successfully,The protocol stack calls the corresponding interface in the MediaChannel class to spit back data or get the status. The following interfaces need to be implemented in the MediaChannel subclass,customers need to implement the following interfaces according to their own actual situation.

Important interfaces in MediaChannel subclass are as follows, the BJCast receiver needs to focus on the following interfaces.

3.8.1 Set window handle

public void setSurface(Surface surface)

​ Configure a window handle for render output.

3.8.2 Audio data return interface

public abstract void onAudioFrame(byte[] buffer,int len,long ts);

Where buffer is an array of audio data. ,len is the length of data,ts is a timestamp。

JNI return audio data, Audio is AAC encoded data, Users need to implement audio decoding and play in this function. DEMO source code in SDK can be referred to for specific implementation.

3.8.3 Video data return interface

public void onVideoFrame(byte[] buffer,int len,long ts)

​ BJCast Mirror Video data Interface,what is returned by this interface is H.264 video data.,user needs to decode and play.

Buffer is an array of video data, len is data length and ts is timestamp. The specific implementation can refer to the DEMO source code in SDK.

3.8.4 Notify mouse shape interface

public void updateCursorShape(byte[] pngData)

When the shape of the mouse changes, the new mouse shape interface is notified and the input is PNG data. The PNG data can be decoded as a Bitmap with reference to the implementation in demo.

BJCast uses a separate channel to transmit mouse information, and the maximum frame rate of the mouse can reach 100fps.

3.8.5 Mouse location update notification interface

public void updateCursorPos(short x,short y)

the interface informs the update of the mouse position x, y, The upper-left coordinates of the screen are (0,0). Note that the player needs to convert coordinates based on the actual image size and the current screen size. For example, the video image transmitted by the transmitter is 720p,coordinate position (1280,720), the view corresponding to the currently displayed player is 1080p screen, it is obvious that the actual display position needs to be converted to (1920, 1080), which can be converted by referring to the actual position calculation method in demo.

3.8.6 Hide the mouse notification interface

public void hindCursor()

The interface notifies the application that it needs to hide the mouse (for example, when the sender plays the video with the full screen , the mouse automatically disappears, and the receiver is notified to hide the mouse)

4 Service discovery

When the sender initiates the projection session to the receiver, it is first necessary to determine the communication IP and communication port at the receiver. The discovery protocol is used to automatically discover the receiver device in the wireless screen shooting system. Customers should choose the projection protocol according to the needs of their own business system. If the customer needs to manage the receiver device through the cloud platform, it is necessary to consider the custom wireless screen shooting protocol. At present, two kinds of discovery protocols are predefined in BJCast SDK, which can be used to discover BJCast receiver in the same LAN. The BJCastV1 supports the discovery of the service discovery and the Zerosponf by the discovery protocol ; and the BJCastV2 uniformly uses the Zerocarf to realize the service release and service discovery.

4.1 BJCastV1 custom service discovery protocol

SDK internally supports a custom service discovery protocol, such as the WINDOWS/Android launcher SDK, which already provides an interface, which is not detailed here.

4.2 Zeroconf

At present, the BJCast receiver uses zeroconf to realize service publishing and service discovery based on mdns.

Customers can use the standard ns-sd interface to discover services.

4.2.1 BJCastV1 service release

ServiceName: BJCastReceiver@Name@DeviceID, ServiceName is divided into three parts,each part is separated by the @ symbol,the first is BJCastReceiver,the second is receiver name,the third is device ID(used to uniquely identify a device that currently acquires the MAC address of the receiver by default)

ServiceType: “_bjcast._tcp”

4.2.2 BJCastV2 service release

ServiceName: BJCastReceiver@Name@DeviceID, ServiceName is divided into tree parts,each part is separated by the @ symbol,the first is BJCastReceiver,the second is receiver name,the third is device ID(used to uniquely identify a device that currently acquires the MAC address of the receiver by default)

ServiceType: “_ bjcast2._tcp”

4.2.3 method for realizing zercoonf service discovery

The current Android, IOS/ MAC platform has standard API interfaces to support NSD-based service discovery. Windows can use the Apple open source mDNSResponder to implement service discovery. Android platform can use NsdManager related interface to realize service discovery, can refer to https://developer.android.com/reference/android/net/nsd/NsdManager.html

IOS/MAC platform can use Bonjour related interface to realize service discovery.

The windows platform can use Bonjour related interface to implement the service, and can refer to the windows version of mDNSResponder to realize the service discovery function. Can refer to https://opensource.apple.com/tarballs/mDNSResponder/

5 Demo Description

BJCastModuleImp implements ModuleImpItf interface in Demo,The method of the relay channel is realized , Here you can control whether to access the logical control of a session. Where GLScreenRenderChannel is created in reqMediaChannel,and start the playing related View, create the Surface for playback. The GLSrenRenderChannel implements the MediaChannel-related functional interface and uses the MediaCodec interface to decode and play audio and video data.

6 How to use SDK

  1. Import aar, create a new libs directory in the app directory and place the aar file in that directory,Then add the following code above and inside the dependencies in the build.gralle(app). :repositories{ flatDir { dirs ’libs ’} },compile (name: ‘bjcast_lib-1.0.18-release.aar’, ext: ‘aar’) compile (name: ‘cast_base_lib-1.0.17-release.aar’, ext: ‘aar’),can refer to the Demo
  2. To implement the ModuleImpItf interface, refer to the BJCastModuleImp. reqMediaChannel interface to return an instance of a custom MediaChannel implementation class and start the playback interface.
  3. To implement the MediaChannel-related functional interface, refer to the GLScreenRenderChannel.
  4. To realize its own playback interface, we can refer to the implementation of view in view package, and set the Surface of playback interface to MediaChannel.