IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> android FM的流程 -> 正文阅读

[移动开发]android FM的流程

FM framework:

1、适配层调用的最外面接口是Radiomanager


frameworks/base/core/java/android/hardware/radio/RadioManager.java
frameworks/base/core/java/android/hardware/radio/TunerCallbackAdapter.java
下面是向上外层适配层回调的主要是三个接口, 都在TunerCallbackAdapter.java
onTuneFailed, onCurrentProgramInfoChanged, onProgramListUpdated

RadioManager.java→构造函数里获取radioservice

public?RadioManager(@NonNull?Context context)?throws?ServiceNotFoundException {
mService?= IRadioService.Stub.asInterface(
ServiceManager.getServiceOrThrow(Context.RADIO_SERVICE));
}

frameworks/base/core/java/android/hardware/radio/RadioManager.java

打开tuner设备,并设置callback

public RadioTuner openTuner(int moduleId){
    TunerCallbackAdapter halCallback = new TunerCallbackAdapter(callback, handler);
    ITuner tuner = mService.openTuner(moduleId, config, withAudio, halCallback);
    return new TunerAdapter(tuner, halCallback, config != null ? config.getType() : BAND_INVALID);
}
接下来在frameworks/base/core/java/android/hardware/radio/TunerAdapter.java里做接口调用,比如

scan, step, tune, startBackgroundScan(没用到)

在frameworks/base/core/java/android/hardware/radio/TunerCallbackAdapter.java接收回调

2、再往下, 是hal service的代码,分为hal和hal2


frameworks/base/services/core/java/com/android/server/broadcastradio
注意一下, hal1和hal2是而选一的
hal1会调用native函数, native函数是在frameworks/base/services/core/jni/BroadcastRadio, 但是android11并不走hal1,
所以也不通过native访问radio hal层

hal是直接通过IServiceManager manager = IServiceManager.getService();

frameworks/base/services/core/java/com/android/server/broadcastradio/BroadcastRadioService.java

public class BroadcastRadioService extends SystemService
public void onStart() {
    publishBinderService(Context.RADIO_SERVICE, mServiceImpl);
}

frameworks/base/services/core/java/com/android/server/broadcastradio/hal2/BroadcastRadioService.java

private IServiceNotification.Stub mServiceListener = new IServiceNotification.Stub() {
    @Override
    public void onRegistration(String fqName, String serviceName, boolean preexisting) {
        //这个会生成一个module
        RadioModule module = RadioModule.tryLoadingModule(moduleId, serviceName);
    }
};

frameworks/base/services/core/java/com/android/server/broadcastradio/hal2/RadioModule.java
这里是获取IBroadcastRadio service对象, 以便于直接调用到hal层

public static @Nullable RadioModule tryLoadingModule(int idx, @NonNull String fqName) {
     IBroadcastRadio service = IBroadcastRadio.getService(fqName);
     return new RadioModule(service, prop);
}


这里直接操作hal层的openSession函数, 在回调里返回hal的操作对象session

public @NonNull TunerSession openSession(@NonNull android.hardware.radio.ITunerCallback userCb)
        throws RemoteException {
    synchronized (mLock) {
            mService.openSession(mHalTunerCallback, (result, session) -> {
                Convert.throwOnError("openSession", result);
                hwSession.value = session;
            });
        TunerSession tunerSession = new TunerSession(this, mHalTunerSession, userCb);
        mAidlTunerSessions.add(tunerSession);

        return tunerSession;
    }
}

frameworks/base/services/core/java/com/android/server/broadcastradio/hal2/TunerSession.java
在这里会向hal层调用tune、scan等接口

3、hal层


vendor/qisi/proprietary/interfaces/broadcastradio/2.0/BroadcastRadio.cpp
这里是将hal层的session操作对象返回到framework层

Return<void> BroadcastRadio::openSession(const sp<ITunerCallback>& callback,
                                         openSession_cb _hidl_cb) {
    sp<TunerSession> newSession = new TunerSession(*this, callback);

    mSession = newSession;

    _hidl_cb(Result::OK, newSession);
    return {};
}

4、回调的数据
hardware/interfaces/broadcastradio/2.0/types.hal
/**
* A set of identifiers necessary to tune to a given station.
*
* This can hold a combination of various identifiers, like:
* - AM/FM frequency,
* - HD Radio subchannel,
* - DAB service ID.
*
* The type of radio technology is determined by the primary identifier - if the
* primary identifier is for DAB, the program is DAB. However, a program of a
* specific radio technology may have additional secondary identifiers for other
* technologies, i.e. a satellite program may have FM fallback frequency,
* if a station broadcasts both via satellite and FM.
*
* The identifiers from VENDOR_START..VENDOR_END range have limited
* serialization capabilities: they are serialized locally, but ignored by the
* cloud services. If a program has primary id from vendor range, it's not
* synchronized with other devices at all.
*/
struct?ProgramSelector?{
/**
* Primary program identifier.
*
* This identifier uniquely identifies a station and can be used for
* equality check.
*
* It can hold only a subset of identifier types, one per each
* radio technology:
* - analogue AM/FM: AMFM_FREQUENCY;
* - FM RDS: RDS_PI;
* - HD Radio: HD_STATION_ID_EXT;
* - DAB: DAB_SID_EXT;
* - Digital Radio Mondiale: DRMO_SERVICE_ID;
* - SiriusXM: SXM_SERVICE_ID;
* - vendor-specific: VENDOR_START..VENDOR_END.
*
* The list may change in future versions, so the implementation must obey,
* but not rely on it.
*/
ProgramIdentifier primaryId;

/**
* Secondary program identifiers.
*
* These identifiers are supplementary and can speed up tuning process,
* but the primary ID must be sufficient (i.e. RDS PI is enough to select
* a station from the list after a full band scan).
*
* Two selectors with different secondary IDs, but the same primary ID are
* considered equal. In particular, secondary IDs vector may get updated for
* an entry on the program list (ie. when a better frequency for a given
* station is found).
*/
vec<ProgramIdentifier> secondaryIds;
};



/**
* Program (channel, station) information.
*
* Carries both user-visible information (like station name) and technical
* details (tuning selector).
*/
struct?ProgramInfo?{
/**
* An identifier used to point at the program (primarily to tune to it).
*
* This field is required - its type field must not be set to
* IdentifierType::INVALID.
*/
ProgramSelector selector;

/**
* Identifier currently used for program selection.
*
* It allows to determine which technology is currently used for reception.
*
* Some program selectors contain tuning information for different radio
* technologies (i.e. FM RDS and DAB). For example, user may tune using
* a ProgramSelector with RDS_PI primary identifier, but the tuner hardware
* may choose to use DAB technology to make actual tuning. This identifier
* must reflect that.
*
* This field is required for currently tuned program only.
* For all other items on the program list, its type field must be
* initialized to IdentifierType::INVALID.
*
* Only primary identifiers for a given radio technology are valid:
* - AMFM_FREQUENCY for analog AM/FM;
* - RDS_PI for FM RDS;
* - HD_STATION_ID_EXT;
* - DAB_SID_EXT;
* - DRMO_SERVICE_ID;
* - SXM_SERVICE_ID;
* - VENDOR_*;
* - more might come in next minor versions of this HAL.
*/
ProgramIdentifier logicallyTunedTo;

/**
* Identifier currently used by hardware to physically tune to a channel.
*
* Some radio technologies broadcast the same program on multiple channels,
* i.e. with RDS AF the same program may be broadcasted on multiple
* alternative frequencies; the same DAB program may be broadcast on
* multiple ensembles. This identifier points to the channel to which the
* radio hardware is physically tuned to.
*
* This field is required for currently tuned program only.
* For all other items on the program list, its type field must be
* initialized to IdentifierType::INVALID.
*
* Only physical identifiers are valid:
* - AMFM_FREQUENCY;
* - DAB_ENSEMBLE;
* - DRMO_FREQUENCY;
* - SXM_CHANNEL;
* - VENDOR_*;
* - more might come in next minor versions of this HAL.
*/
ProgramIdentifier physicallyTunedTo;

/**
* Primary identifiers of related contents.
*
* Some radio technologies provide pointers to other programs that carry
* related content (i.e. DAB soft-links). This field is a list of pointers
* to other programs on the program list.
*
* This is not a list of programs that carry the same content (i.e.
* DAB hard-links, RDS AF). Switching to programs from this list usually
* require user action.
*
* Please note, that these identifiers do not have to exist on the program
* list - i.e. DAB tuner may provide information on FM RDS alternatives
* despite not supporting FM RDS. If the system has multiple tuners, another
* one may have it on its list.
*
* This field is optional (can be empty).
*/
vec<ProgramIdentifier> relatedContent;

bitfield<ProgramInfoFlags> infoFlags;

/**
* Signal quality measured in 0% to 100% range to be shown in the UI.
*
* The purpose of this field is primarily informative, must not be used to
* determine to which frequency should it tune to.
*/
uint32_t signalQuality;

/**
* Program metadata (station name, PTY, song title).
*/
vec<Metadata> metadata;

/**
* Vendor-specific information.
*
* It may be used for extra features, not supported by the platform,
* for example: paid-service=true; bitrate=320kbps.
*/
vec<VendorKeyValue> vendorInfo;
};

  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2022-08-06 10:55:38  更:2022-08-06 10:58:49 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/25 4:50:55-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码