OSDN Git Service

MediaExtractor: add getDrmInitData API
[android-x86/frameworks-base.git] / media / java / android / media / DrmInitData.java
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package android.media;
17
18 import android.media.MediaDrm;
19
20 import java.util.Arrays;
21 import java.util.HashMap;
22 import java.util.Map;
23 import java.util.UUID;
24
25 /**
26  * Encapsulates initialization data required by a {@link MediaDrm} instance.
27  */
28 public abstract class DrmInitData {
29
30     /**
31      * Retrieves initialization data for a given DRM scheme, specified by its UUID.
32      *
33      * @param schemeUuid The DRM scheme's UUID.
34      * @return The initialization data for the scheme, or null if the scheme is not supported.
35      */
36     public abstract SchemeInitData get(UUID schemeUuid);
37
38     /**
39      * Scheme initialization data.
40      */
41     public static final class SchemeInitData {
42
43         /**
44          * The mimeType of {@link #data}.
45          */
46         public final String mimeType;
47         /**
48          * The initialization data.
49          */
50         public final byte[] data;
51
52         /**
53          * @param mimeType The mimeType of the initialization data.
54          * @param data The initialization data.
55          *
56          * @hide
57          */
58         public SchemeInitData(String mimeType, byte[] data) {
59             this.mimeType = mimeType;
60             this.data = data;
61         }
62
63         @Override
64         public boolean equals(Object obj) {
65             if (!(obj instanceof SchemeInitData)) {
66                 return false;
67             }
68             if (obj == this) {
69                 return true;
70             }
71
72             SchemeInitData other = (SchemeInitData) obj;
73             return mimeType.equals(other.mimeType) && Arrays.equals(data, other.data);
74         }
75
76         @Override
77         public int hashCode() {
78             return mimeType.hashCode() + 31 * Arrays.hashCode(data);
79         }
80
81     }
82
83 }