2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef DESCRAMBLER_API_H_
18 #define DESCRAMBLER_API_H_
20 #include <media/stagefright/MediaErrors.h>
21 #include <media/cas/CasAPI.h>
26 struct DescramblerPlugin;
28 struct DescramblerFactory {
29 DescramblerFactory() {}
30 virtual ~DescramblerFactory() {}
32 // Determine if the plugin can handle the CA scheme identified by CA_system_id.
33 virtual bool isSystemIdSupported(
34 int32_t CA_system_id) const = 0;
36 // Construct a new instance of a DescramblerPlugin given a CA_system_id
37 virtual status_t createPlugin(
38 int32_t CA_system_id, DescramblerPlugin **plugin) = 0;
41 DescramblerFactory(const DescramblerFactory &);
42 DescramblerFactory &operator=(const DescramblerFactory &);
45 struct DescramblerPlugin {
46 enum ScramblingControl {
47 kScrambling_Unscrambled = 0,
48 kScrambling_Reserved = 1,
49 kScrambling_EvenKey = 2,
50 kScrambling_OddKey = 3,
54 uint32_t mNumBytesOfClearData;
55 uint32_t mNumBytesOfEncryptedData;
58 DescramblerPlugin() {}
59 virtual ~DescramblerPlugin() {}
61 // If this method returns false, a non-secure decoder will be used to
62 // decode the data after decryption. The decrypt API below will have
63 // to support insecure decryption of the data (secure = false) for
64 // media data of the given mime type.
65 virtual bool requiresSecureDecoderComponent(const char *mime) const = 0;
67 // A MediaCas session may be associated with a MediaCrypto session. The
68 // associated MediaCas session is used to load decryption keys
69 // into the crypto/cas plugin. The keys are then referenced by key-id
70 // in the 'key' parameter to the decrypt() method.
71 // Should return NO_ERROR on success, ERROR_DRM_SESSION_NOT_OPENED if
72 // the session is not opened and a code from MediaErrors.h otherwise.
73 virtual status_t setMediaCasSession(const CasSessionId& sessionId) = 0;
75 // If the error returned falls into the range
76 // ERROR_DRM_VENDOR_MIN..ERROR_DRM_VENDOR_MAX, errorDetailMsg should be
77 // filled in with an appropriate string.
78 // At the java level these special errors will then trigger a
79 // MediaCodec.CryptoException that gives clients access to both
80 // the error code and the errorDetailMsg.
81 // Returns a non-negative result to indicate the number of bytes written
82 // to the dstPtr, or a negative result to indicate an error.
83 virtual ssize_t descramble(
85 ScramblingControl scramblingControl,
87 const SubSample *subSamples,
92 AString *errorDetailMsg) = 0;
95 DescramblerPlugin(const DescramblerPlugin &);
96 DescramblerPlugin &operator=(const DescramblerPlugin &);
99 } // namespace android
102 extern android::DescramblerFactory *createDescramblerFactory();
105 #endif // DESCRAMBLER_API_H_