summaryrefslogtreecommitdiffstats
path: root/mobile/android/base/java/org/mozilla/gecko/media/GeckoMediaDrmBridgeV23.java
blob: 74144f28edc50aeae96fc2fa7f306e5863ee0cf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.gecko.media;

import android.annotation.TargetApi;
import static android.os.Build.VERSION_CODES.M;
import android.media.MediaDrm;
import android.util.Log;
import java.util.List;

public class GeckoMediaDrmBridgeV23 extends GeckoMediaDrmBridgeV21 {

    private static final String LOGTAG = "GeckoMediaDrmBridgeV23";
    private static final boolean DEBUG = false;

    GeckoMediaDrmBridgeV23(String keySystem) throws Exception {
        super(keySystem);
        if (DEBUG) Log.d(LOGTAG, "GeckoMediaDrmBridgeV23 ctor");
        mDrm.setOnKeyStatusChangeListener(new KeyStatusChangeListener(), null);
    }

    @TargetApi(M)
    private class KeyStatusChangeListener implements MediaDrm.OnKeyStatusChangeListener {
        @Override
        public void onKeyStatusChange(MediaDrm mediaDrm,
                                      byte[] sessionId,
                                      List<MediaDrm.KeyStatus> keyInformation,
                                      boolean hasNewUsableKey) {
            if (DEBUG) Log.d(LOGTAG, "[onKeyStatusChange] hasNewUsableKey = " + hasNewUsableKey);
            if (keyInformation.size() == 0) {
                return;
            }
            SessionKeyInfo[] keyInfos = new SessionKeyInfo[keyInformation.size()];
            for (int i = 0; i < keyInformation.size(); i++) {
                MediaDrm.KeyStatus keyStatus = keyInformation.get(i);
                keyInfos[i] = new SessionKeyInfo(keyStatus.getKeyId(),
                                                 keyStatus.getStatusCode());
            }
            onSessionBatchedKeyChanged(sessionId, keyInfos);
        }
    }
}