8. Streaming Media Transfer Interface
StreamingTransferImpl
8.1. IStreamingTransfer
public interface IStreamingTransfer {
/**
* Whether the streaming media transfer function is supported
*
* @return boolean Result
*/
boolean isSupportStreamTransfer();
/**
* Whether streaming media is being transferred
*
* @return boolean Result
*/
boolean isTransferring();
/**
* Add streaming state callback
*
* @param callback Streaming state callback
*/
void addOnStreamingStateCallback(OnStreamingStateCallback callback);
/**
* Remove streaming state callback
*
* @param callback Streaming state callback
*/
void removeOnStreamingStateCallback(OnStreamingStateCallback callback);
/**
* Get cached peripheral information
*
* @return List<PeripheralInfo> Peripheral information
*/
List<PeripheralInfo> getPeripheralInfos();
/**
* Get the streaming parameters currently being transferred by the specified peripheral
*
* @param info PeripheralInfo Peripheral information
* <p>
* If null is passed in, returns the parameters of all streaming media being transferred<br/>
* If not null, returns the streaming parameters being transferred by the specified peripheral
* </p>
* @return List<PeripheralParam> Streaming parameters being transferred
*/
List<PeripheralParam> getPeripheralParams(PeripheralInfo info);
/**
* Find the corresponding peripheral information by session ID
*
* @param index int Session ID
* @return PeripheralInfo Peripheral information
*/
PeripheralInfo findPeripheralInfo(int index);
/**
* Read peripheral information
*
* @param callback Result callback
*/
void readPeripheralInfos(OnOperationCallback<List<PeripheralInfo>> callback);
/**
* Start media stream transfer (request streaming media from the device)
*
* @param params Peripheral request parameters
* @param callback Operation callback<br/>
* After the operation succeeds, the streaming state will be called back
* via {@link OnStreamingStateCallback}
*/
void startStreamingTransfer(List<PeripheralParam> params, OnOperationCallback<List<PeripheralResult>> callback);
/**
* Start media stream transfer
*
* @param way Transfer method
* @param params Peripheral request parameters
* @param callback Operation callback<br/>
* After the operation succeeds, the streaming state will be called back
* via {@link OnStreamingStateCallback}
*/
void startStreamingTransfer(int way, List<PeripheralParam> params, OnOperationCallback<List<PeripheralResult>> callback);
/**
* Stop media stream transfer
*
* @param params Peripheral request parameters
* @param callback Operation callback<br/>
* After the operation succeeds, the streaming state will be called back
* via {@link OnStreamingStateCallback#onStopTransfer(int, boolean, List)}
*/
void stopStreamingTransfer(List<PeripheralParam> params, OnOperationCallback<Boolean> callback);
/**
* Write frame data
*
* @param frameData Frame data
* @param callback Operation callback
*/
void writeFrameData(FrameData frameData, OnOperationCallback<Boolean> callback);
}
8.2. IStreamingDataProxy
Streaming data proxy, implemented by the application layer, used to bind the actual streaming data channel (BLE or an independent SPP channel).
public interface IStreamingDataProxy {
/**
* Get the operating device object
*/
BluetoothDevice getDevice();
/**
* Set the data listener
*/
void setOnStreamingDataListener(OnStreamingDataListener listener);
/**
* Write data to the device
*
* @param device Bluetooth device
* @param data Raw data
* @param callback Operation result
*/
void writeStreamingData(BluetoothDevice device, byte[] data, OnOperationCallback<Boolean> callback);
}
8.3. OnStreamingDataListener
public interface OnStreamingDataListener {
/**
* Callback for received streaming data
*
* @param device Bluetooth device
* @param data Streaming data
*/
void onStreamingData(BluetoothDevice device, byte[] data);
}
8.4. OnStreamingStateCallback
public interface OnStreamingStateCallback {
/**
* SDK-initiated operation
*/
int REASON_SDK = 0;
/**
* Remote device request
*/
int REASON_REMOTE = 1;
/**
* Callback for peripheral information change
*/
void onPeripheralInfoChange(List<PeripheralInfo> peripheralInfos);
/**
* Callback for starting streaming media transfer
*
* @param reason Reason code
* @param params Peripheral parameters
*/
void onStartTransfer(int reason, List<PeripheralParam> params);
/**
* Callback for received frame data
*
* @param frameData Frame data
*/
void onReceiveFrame(FrameData frameData);
/**
* Callback for lost frame information
*
* @param reason Reason code
* @param frameError Frame error information
*/
void onFrameLost(int reason, FrameError frameError);
/**
* Callback for stopping streaming media transfer
*
* @param reason Reason code
* @param isFinish Whether the transfer is completely stopped
* @param results Results of stopping peripherals
*/
void onStopTransfer(int reason, boolean isFinish, List<PeripheralResult> results);
}
Note
onReceiveFrameis called back on a sub-thread; do not perform time-consuming operations hereonFrameLostis called back only once for the same frame; when the device continuously sends abnormal frames, the SDK limits the frequency of exception reportingFor transfer methods and reason codes, refer to Transfer Method and Reason Code Reference Table
8.5. Commands and Constants
public class StreamingCtrlCmd {
/**
* Read online peripheral information
*/
public static final int OP_READ_ONLINE_PERIPHERALS = 0x00;
/**
* Start streaming media transfer
*/
public static final int OP_START_TRANSFER_STREAMING = 0x01;
/**
* Stop streaming media transfer
*/
public static final int OP_STOP_TRANSFER_STREAMING = 0x02;
/**
* Report streaming media error
*/
public static final int OP_REPORT_STREAMING_ERROR = 0x03;
/**
* SDK requests streaming media data from the remote device (DEVICE --> SDK)
*/
public static final int WAY_REQUEST_DATA = 0;
/**
* SDK requests pushing streaming media data to the device (SDK --> DEVICE)
*/
public static final int WAY_PUSH_DATA = 1;
/**
* Operation succeeded
*/
public static final int ERR_NONE = 0;
/**
* Device busy/start failed
*/
public static final int ERR_DEVICE_BUSY = 1;
/**
* Invalid parameter
*/
public static final int ERR_INVALID_PARAM = 2;
/**
* Missing header data
*/
public static final int REASON_MISSING_HEADER_DATA = 1;
/**
* Data corruption
*/
public static final int REASON_DATA_CORRUPTION = 2;
/**
* CRC check failed
*/
public static final int REASON_CRC_ERROR = 3;
/**
* Convert the result code to an SDK error code
*/
public static int code2Error(int code);
}
8.6. FrameData
FrameData data structure, refer to Frame Data.
Frame data types refer to StreamingData.DATA_TYPE_*:
Constant |
Value |
Description |
|---|---|---|
StreamingData.DATA_TYPE_HEAD |
0x01 |
Streaming media header information |
StreamingData.DATA_TYPE_RAW |
0x02 |
Streaming media raw data |
StreamingData.DATA_TYPE_FRAME |
0x03 |
Streaming media frame data |
8.6.1. FrameError
public class FrameError implements Parcelable {
/**
* Get frame information
*/
public FrameData getFrameData();
/**
* Get the error reason
*
* <p>Refer to StreamingCtrlCmd.REASON_*</p>
*/
public int getReason();
}
8.7. Peripheral Information and Transfer Parameters
For the data structures of PeripheralInfo / PeripheralParam / PeripheralResult, refer to:
For the configuration of the independent SPP channel, refer to Independent SPP Channel for Streaming Media.