Tv Develop of Android TIF Study

The article is mainly recording the following skills
–>Android TIF code Structure and flow
–>How to use TIF in Tv App
References:
http://blog.csdn.net/wangmxe/article/details/50528682
http://blog.csdn.net/zhudaozhuan/article/details/50849542

1: TIF architecture

1.1: TIF OverView

The Android TV Input Framework (TIF) simplifies the delivery of content to Android TV. The TIF provides a standard API for manufacturers to use in constructing input modules for controlling
Android TV.
这里写图片描述
The Android TV Input Framework includes a TV Input Manager and an example TV App that works with a special remote control to access builtin and IP tuner channels.

In all, the TV Input Framework consists of:
● TV Provider (com.android.providers.tv.TvProvider) a database of channels, programs and associated permissions
● TV Input Manager (android.media.tv.TvInputManager) brokers
communication between the TV Inputs and TV App
● TV Input an application provided by the OEM, Google or third parties to route content
● TV App (com.android.tv.TvActivity) the application provided by the OEM or Google for user interaction
● HDMICEC the technology to allow remote control of various devices over HDMI

1.2: TIF Directory Structure

这里写图片描述

1.3: TIF Main Class

  • TvView: Displays TV contents. The TvView class provides a high level interface for applications to show TV programs from various TV sources that implement {@link TvInputService}
    这里写图片描述
    –>TvInputCallback: Callback used to receive various status updates on the {@link TvView}
  • TvInputManager: Central system API to the overall TV input framework (TIF) architecture, which arbitrates interaction between applications and the selected TV inputs.
    这里写图片描述
    –>SessionCallback: Interface used to receive the created session,
    –>TvInputCallback: Callback used to monitor status of the TV input
    –>Session: The Session provides the per-session functionality of TV inputs
  • TvInputManagerService: This class provides a system service that manages television inputs.
    这里写图片描述
  • TvInputService: all of the input device must inherit the class.The TvInputService class represents a TV input or source such as HDMI or built-in tuner which provides pass-through video or broadcast TV programs.

1.4: TIS init flow

这里写图片描述

2: how to use TIF

2.1: create session

           {
                mTvInputManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE);
                if (mTvInputManager != null) {
                    observerCallback = new ObserverSessionCallback();
                    List inputlist = mTvInputManager.getTvInputList();
                    if (inputlist != null) {
                        for (int i = 0; i < inputlist.size(); i++) {
                            TvInputInfo tinfo = (TvInputInfo) inputlist.get(i);
                            if ((tinfo.getType() == TvInputInfo.TYPE_TUNER) &&
                                (tinfo.getComponent().getPackageName().equals(ITVSessionContext.TUNERSERVICE_PKG_ID))) {
                                tunerServiceId = tinfo.getId();
                                Log.d(tag, "TunerService ID = " + tunerServiceId);
                                break;
                            }
                        }
                    }
                    if (mTvInputManager.getInputState(tunerServiceId) == TvInputManager.INPUT_STATE_CONNECTED) {
                        Log.d(tag, "creating the session,waiting for call back");
                        mTvInputManager.createSession(tunerServiceId, observerCallback, mSessionHandler);
                    } else {
                        Log.d(tag, "input tuner not added yet,waiting for call back");
                    }
                } else {
                    Log.d(tag, "Could not get system service TV_INPUT_SERVICE!!");
                }
            }

2.2: inherit SessionCallback

    public class ObserverSessionCallback extends SessionCallback {
        Session mySession = null;

        public void onSessionCreated(Session session) {
            Log.d(tag, "onSessionCreated ");
            if (session != null) {
                Log.d(tag, "Session creation successful");
                mySession = session;
                String action = ITVSessionContext.APP_PRIVATE_COMMAND_SESSION_TYPE;
                Bundle bundle = new Bundle();
                bundle.putString(ITVSessionContext.KEY_SESSION_TYPE, ITVSessionContext.SESSION_TYPE_MAIN_OBSERVER);
                mySession.sendAppPrivateCommand(action, bundle);
            } else {
                Log.d(tag, "Session creation failed");
            }
        }

        public void onSessionReleased(Session session) {
            Log.d(tag, "onSessionReleased called");
            mySession = null;
            mObserverSessionContext = null;
        }

        public void onChannelRetuned(Session session, Uri channelUri) {
        }

        public void onVideoUnavailable(Session session, int reason) {
        }

        public void onSessionEvent(Session session, String eventType, Bundle eventArgs) {
            Log.i(tag, "onSessionEvent " + this);
            if (eventType.equals(ITVSessionContext.EVENT_SESSION_CONTEXT_CREATED)) {
                IBinder binder = eventArgs.getBinder(ITVSessionContext.SESSION_CONTEXT);
                mObserverSessionContext = ITVSessionContext.instance.asInterface(binder);
                ObserverSessionContextCallbacks mainSessionContextCallbacks = new ObserverSessionContextCallbacks();
                mObserverSessionContext.registerSessionContextCallbacks(mainSessionContextCallbacks);
            }
        }
    }

commit id: 98c0c6e7d5ffcefd0e939f6a5f2b40e30ee69cb2

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值