Code Analysis

 

This section describes how to develop the sample application to help developers create DAB/DMB applications.

 

The sample application consists of the following files:

 

  Files   Description
src/com/example/dabsampleapp/MainActivity.java Developing main operation of the sample application
src/com/example/dabsampleapp/ChManagerDb.java Converting received data from Framework to string or integer
src/com/example/dabsampleapp/EBUChar.java Definition of Char code value to process subtitles
src/com/example/dabsampleapp/Utils.java Definition of integer value such as event number and frequency number

MainActivity

The start point of sample app is MainActivity.

 

Define DmbManager for Dmb class.

public static Dmb DmbManager = null; 

 

Call Dmb.open() to start DAB/DMB service.

openDMB();
}
...
public void openDMB(){
      ...
      DmbManager = Dmb.open();
}

 

Develop to broadcast DAB or DMB channel depending on op_mode.

if(opMode == Utils.OP_MODE_DAB){
      setCurrentRadioChannel(position);
}
else{
      setCurrentTVChannel(position);
}

 

Call APIs which are needed to broadcast radio or TV in consecutive order after selecting DAB or DMB mode. First, registerEventCallback to receive event from DAB/DMB service by calling init(). EventCallback receives events regarding channel setting errors and working status of the service. When you call init(), includes op_mode and liveFlag to broadcast the on-air value.

public void initDMB(int opMode, int liveFlag){
      if(DmbManager != null){
            if(opMode == Utils.OP_MODE_ENSQUERY){
            DmbManager.exit();
            }
      DmbManager.init(opMode, liveFlag, 1, mInitEventCallback);
      }
}

 

Search channels by calling find(), and register SignalCallback to send whether channel is locked or not.

public void findDMB(int freg){
      if(DmbManager != null){
      DmbManager.find(freg, mFindSignalCallback);
      }
}

 

Set a channel to show your user by calling select(). At this time, ensemble block number and channel ID are sent to framework.

public void selectDMB(int opmode, int freq, int subChId, int dscty, int subChSize, int fec_scheme){
      if(DmbManager != null){
            if(dscty == -1){
                DmbManager.select(opmode, freq, subChId, mVideoCallback, mAudioCallback);
            } else {
                DmbManager.select(opmode, freq, subChId, dscty, subChSize, fec_scheme, mVideoCallback, mAudioCallback);
            }
      }
}

 

Register DataCallback function by calling data(), and send data such as FIC and SLS/DLS to the application. onData() must be implemented in case a DataCallback is received from the application. Decode SLS/DLS data and make a channel list in the sample application.

 

public void dataDMB(int dataType, int onOff) {
      if (DmbManager != null){
            DmbManager.data(dataType, onOff, mDataCallback);
      }
}
...
private final class DataCallback implements com.lge.broadcast.tdmb.Dmb.DataCallback{
      public void onData(int type, int size, byte[] data, Dmb mDmb){
         if(type == Utils.DMB_CHANNEL_SI_RECEIVED) {
            processChannelSiReceived(size, data);
         }
         else if (type == Utils.DMB_DLS_RECEIVED) {
            processDLSReceiveDone(data);
         }
         else if (type == Utils.DMB_SLS_RECEIVED) {
            processSSTriggeringMode(data);
         }
         ...
      }
}

 

In case of a TV broadcast, size, position, and rotation of the video displayed on the device can be set usingDmb.setVideoDimension().

To use SurfaceView, SurfaceHolder is necessary.

public void setDimensionDMB(int left, int top, int width, int height, int degree, SurfaceHolder holder){
      if (DmbManager != null) {
            DmbManager.setVideoDimension(left, top, width, height, degree, holder);
      }
}

 

The code for SurfaceView is as follows.

mPreview = (SurfaceView)findViewById(R.id.surface);
mHolder = mPreview.getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mPreview.setVisibility(View.VISIBLE);

 

If you want to end DAB/DMB service, call exit() and release() to return the resource.

exitDMB();
releaseDMB();
}
...
public static void releasdDMB(){
      if(DmbManager != null){
         DmbManager.release();
      }
      DmbManager = null;
}
public static void exitDMB(){
      if(DmbManager != null){
         DmbManager.exit();
      }
}
Navigation