視頻App如何使用無線傳輸服務獲得更好的播放體驗

1 前言

華爲公司經過多年的發展,在網絡連接,固網,有線,無線等部分積累了深厚的經驗。無線傳輸服務就是將這些經驗轉化爲能力體現在手機側,更好的展現華爲手機的優勢。
網絡最重要的就是穩定,快速,低時延。視頻App重要的也是保證用戶更好的觀看體驗,對網絡的要求也就更高。

本文將以視頻播放App爲例,介紹基本的應用場景和實現方式,以幫助用戶快速瞭解如何使用無線傳輸服務的相關功能。

2 名詞介紹

在下面的介紹中可能會用到一些網絡側常用的參數,含義如下:

QoE:Quality of Experience,用戶體驗質量。用戶對業務使用的最終感受。在這裏主要指體現網絡情況的抖動,時延等指標。

WiFi切片:對設備上不同的服務設置不同優先級,並按優先級進行相關數據分組。

3 業務背景介紹

現在各大運營商都開通了針對各種視頻軟件(如騰訊視頻,優酷視頻,抖音等)的大流量套餐,因此很多人都會在上班,旅遊的過程中通過它們觀看視頻。而觀看視頻過程中最擔心的就是網絡不穩定造成的卡頓,分辨率降低等情況,嚴重影響觀賞體驗。如果手機能夠最大限度保障視頻的流暢度,並且及時選擇更優的網絡,就能夠讓用戶有更好的觀賞體驗。如果能提前知道網絡的變化,豈不是能更好的應對可能的問題嘛。

4 關鍵流程

4.1 集成無線傳輸服務

集成無線傳輸服務的基本操作可以參考如下文檔進行操作:
https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides-V5/dev-process-0000001051069902-V5?ha_source=hms1

4.2 如何保障視頻質量

視頻軟件的訴求是什麼樣的?

首先,網絡速度越快越好,速度越快,視頻質量越高。

網絡要保持穩定,保證持續的觀影效果。

當網絡狀態有波動時,可以通過緩存功能對網絡進行平滑。

當網絡不允許時,降低分辨率優先保障連續性。

下面我們看一下,無線傳輸服務如何從各個角度提升視頻軟件的效果。

4.2.1 網絡優選

首先確認一點,無線傳輸服務並不能對您的網絡進行加速。但是它可以在網絡狀態不穩定,不足以支撐應用要求時,將網絡切換到可以滿足要求的網絡中(如果存在)。

比如用戶當前使用WIFI網絡,當遠離WIFI區域時,網絡質量逐漸下降。但是如果用戶WIFI沒有中斷,系統會繼續使用該網絡,導致視頻播放出現異常。

如果可以分析當前網絡狀態,並且及時切換到蜂窩網絡,則可以更好的進行觀影。

無線傳輸服務提供了基於QoE的網絡優選功能。通過主動反饋的方式,向App提供網絡狀態的回調。App可以通過當前的QoE狀態進行相應操作(切換網絡,增加緩存等)。

在這裏插入圖片描述

  1. 註冊服務
public class NetworkPredictActivity extends AppCompatActivity {
    private NetworkQoeClient networkQoeClient;
    private IQoeService qoeService;
    private ServiceConnection mSrcConn = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            qoeService = IQoeService.Stub.asInterface(service);
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            qoeService = null; 
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        networkQoeClient = WirelessClient.getNetworkQoeClient(NetworkPredictActivity.this);
        if (networkQoeClient != null) {
            networkQoeClient.getNetworkQoeServiceIntent()
                .addOnSuccessListener(new OnSuccessListener<Wirele***esult>() {
                    @Override            
                    public void onSuccess(Wirele***esult wirele***esult) {
                        Intent intent = wirele***esult.getIntent();
                        if (intent == null) {
                            return; 
                        }

                        NetworkPredictActivity.this.bindService(intent, mSrcConn, Context.BIND_AUTO_CREATE); 
                    }        
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override 
                    public void onFailure(Exception e) {
                        if (e instanceof ApiException) {
                            ApiException ex = (ApiException) e;
                            int errCode = ex.getStatusCode();
                        }            
                    }
                 });
         }
    }
}
  1. 註冊回調
    註冊回調後,系統會通過callback函數返回網絡信息。反饋頻率爲每秒一次。
public class NetworkQoeActivity extends AppCompatActivity {
    private int[] channelIndex = new int[4];
    private int[] uLRtt = new int[4];
    private int[] dLRtt = new int[4];
    private int[] uLBandwidth = new int[4];
    private int[] dLBandwidth = new int[4];
    private int[] uLRate = new int[4];
    private int[] dLRate = new int[4];
    private int[] netQoeLevel = new int[4];
    private int[] uLPkgLo***ate = new int[4];
    private IQoeService qoeService;
    private IQoeCallBack callBack = new IQoeCallBack.Stub() {
        @Override
        public void callBack(int type, Bundle qoeInfo) throws RemoteException {
            if (qoeInfo == null || type != 0) {
                return;
            }

            int channelNum = 0;
            if (qoeInfo.containsKey("channelNum")) {
                channelNum = qoeInfo.getInt("channelNum");
            }

            String channelQoe = String.valueOf(channelNum);
            for (int i = 0; i < channelNum; i++) {
                uLRtt[i] = qoeInfo.getInt("uLRtt" + i);
                dLRtt[i] = qoeInfo.getInt("dLRtt" + i);
                uLBandwidth[i] = qoeInfo.getInt("uLBandwidth" + i);
                dLBandwidth[i] = qoeInfo.getInt("dLBandwidth" + i);
                uLRate[i] = qoeInfo.getInt("uLRate" + i);
                dLRate[i] = qoeInfo.getInt("dLRate" + i);
                netQoeLevel[i] = qoeInfo.getInt("netQoeLevel" + i);
                uLPkgLo***ate[i] = qoeInfo.getInt("uLPkgLo***ate" + i);
                channelIndex[i] = qoeInfo.getInt("channelIndex" + i); 
                channelQoe += "," + channelIndex[i] + "," + uLRtt[i] + "," + dLRtt[i] + "," + uLBandwidth[i] + "," 
                    + dLBandwidth[i] + "," + uLRate[i] + "," + dLRate[i] + "," + netQoeLevel[i] + ","
                    + uLPkgLo***ate[i];
            }

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (qoeService != null) {
            try {
                int ret = qoeService.registerNetQoeCallBack("com.huawei.hms.wirelessdemo",callBack);
            } catch (RemoteException ex) { 
            }
        }
    }
}
  1. 主動獲取狀態
    App可以主動獲取網絡狀態(需要首先註冊回調)。
Bundle qoeInfo = qoeService.queryRealTimeQoe("com.huawei.hms.wirelessdemo");
        if (qoeInfo == null) {
                 return;
        }
  1. 上報網絡狀態
    當App發現網絡狀態異常時,可以主動採取降低分辨率的方式,保障視頻順利播放。也可以向無線傳輸服務上報網絡狀態,它將分析當前網絡狀態,切換到更優的網絡中。
data.putInt("eventId", 1);
        data.putString("netReason", "2");
        data.putString("pkgName", "com.huawei.hms.wirelessdemo");
        data.putInt("direction", 1);
        data.putString("version", "5.0.1.300");
        long currentTime = System.currentTimeMillis();
        String timeNow = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(currentTime);
        data.putString("errorTime", timeNow);
        if (qoeService != null) {
            try {
                int ret = qoeService.reportAppQuality(data);
            } catch (RemoteException ex) {
            }
        }

4.2.2 網絡狀態預測

對於視頻App來說,一個很大的應用場景就是上下班。在這種情況下,用戶的路徑相同,而網絡的變化趨勢通常也是很類似。針對這種場景,無線傳輸服務提供了基於學習的預測能力,根據用戶的位置變化,主動預知網絡變化趨勢,以便App提前做出應對(比如提升視頻緩存時長)。

  1. 註冊弱信號接收廣播
    無線傳輸服務提供基於廣播的弱信號預測。
final IntentFilter filter = new IntentFilter();
        filter.addAction(NETWORK_PREDICTION_ACTION);
        registerReceiver(receiver, filter);
  1. 接收弱信號廣播
receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                int enteringTime = intent.getIntExtra("enteringTime", 0);
                int leavingTime = intent.getIntExtra("leavingTime", 0);
                int type =intent.getIntExtra("type",0);
            }
        };

當Type爲1時,在enteringTime後將進入弱信號區間,在進入弱信號區間後,將在leavingTime後離開弱信號區間。

Type爲0時表示取消前一次預測。

信號預測的時間範圍爲30s到60s。

4.2.3 高優先級WIFI發包

當在帶寬有限的WIFI環境下,有多個不同App爭搶帶寬時,有更高優先級的App將可以更好的保障使用效果。

無線傳輸服務提供了Wifi增強功能,可以保障高優先級上行發包(如果使用華爲路由器,可實現下行高優先級)。

  1. 綁定服務
WifiEnhanceClient wifiEnhanceClient = WirelessClient.getWifiEnhanceClient(WifiEnhanceActivity.this);
        wifiEnhanceClient.getWifiEnhanceServiceIntent()
                .addOnSuccessListener(new OnSuccessListener<Wirele***esult>() {
                    @Override
                    public void onSuccess(Wirele***esult wirele***esult) {
                        Intent intent = wirele***esult.getIntent();
                        if (intent == null) {
                            return;
                        }
                        WifiEnhanceActivity.this.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(Exception exception) {
                        if (exception instanceof ApiException) {
                            ApiException ex = (ApiException) exception;
                            int errCode = ex.getStatusCode();
                        }
                    }
                });
  1. 設置Wi-Fi高優先級發包
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (mWifiEnhanceService != null) {
            try {
                mWifiEnhanceService.setHighPriority("com.huawei.hms.wirlesstestdemo", 6, 1);
            } catch (RemoteException exception) {
                // 這裏可以添加打印
            }
        }
    }

對視頻應用來說下行帶寬更加重要,因此該功能在華爲WIFI的情況下更加有效。

綜合以上三種場景,可以讓視頻應用在千變萬化的網絡情況下,給用戶最好的視頻使用感受。

5 其他

無線傳輸服務中的功能使用到了很多硬件能力,因此部分功能需要有硬件的支持。

欲瞭解更多詳情,請參閱:
華爲開發者聯盟官網:https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides-V5/introduction-0000001050749815-V5#ZH-CN_TOPIC_0000001050749815__section10966112614216?ha_source=hms1

參與開發者討論請到Reddit社區:https://www.reddit.com/r/HuaweiDevelopers/

下載demo和示例代碼請到Github:https://github.com/HMS-Core

解決集成問題請到Stack Overflow:https://stackoverflow.com/questions/tagged/huawei-mobile-services?tab=Newest


原文鏈接:https://developer.huawei.com/consumer/cn/forum/topic/0202442899177200495?fid=18

原作者:胡椒

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章