From 1bd139a2a68690e80398b70b27ca59550fea0e65 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Tue, 3 Apr 2012 14:19:20 -0700 Subject: New Crypto services talking to the new crypto "HAL". Change-Id: I69ed31e7a8b4d69d1209d2d516f94d258f072566 related-to-bug: 6275919 --- cmds/stagefright/SimplePlayer.cpp | 5 ++- cmds/stagefright/codec.cpp | 69 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 70 insertions(+), 4 deletions(-) (limited to 'cmds/stagefright') diff --git a/cmds/stagefright/SimplePlayer.cpp b/cmds/stagefright/SimplePlayer.cpp index 0cfeb3e..7636906 100644 --- a/cmds/stagefright/SimplePlayer.cpp +++ b/cmds/stagefright/SimplePlayer.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -318,7 +319,9 @@ status_t SimplePlayer::onPrepare() { CHECK(state->mCodec != NULL); err = state->mCodec->configure( - format, mNativeWindow->getSurfaceTextureClient(), + format, + mNativeWindow->getSurfaceTextureClient(), + NULL /* crypto */, 0 /* flags */); CHECK_EQ(err, (status_t)OK); diff --git a/cmds/stagefright/codec.cpp b/cmds/stagefright/codec.cpp index cf2909e..5cbfbfe 100644 --- a/cmds/stagefright/codec.cpp +++ b/cmds/stagefright/codec.cpp @@ -20,8 +20,10 @@ #include "SimplePlayer.h" +#include #include - +#include +#include #include #include #include @@ -59,6 +61,33 @@ struct CodecState { bool mIsAudio; }; +static sp makeCrypto( + const uint8_t uuid[16], const void *data, size_t size) { + sp sm = defaultServiceManager(); + + sp binder = + sm->getService(String16("media.player")); + + sp service = + interface_cast(binder); + + CHECK(service != NULL); + + sp crypto = service->makeCrypto(); + + if (crypto == NULL || crypto->initCheck() != OK) { + return NULL; + } + + status_t err = crypto->createPlugin(uuid, data, size); + + if (err != OK) { + return NULL; + } + + return crypto; +} + } // namespace android static int decode( @@ -78,6 +107,8 @@ static int decode( return 1; } + sp crypto; + KeyedVector stateByTrack; bool haveAudio = false; @@ -113,7 +144,38 @@ static int decode( state->mNumBuffersDecoded = 0; state->mIsAudio = isAudio; - if (decryptInputBuffers && !isAudio) { + if (decryptInputBuffers && crypto == NULL) { + sp emm; + CHECK(format->findBuffer("emm", &emm)); + + sp ecm; + CHECK(format->findBuffer("ecm", &ecm)); + + struct WVOpaqueInitData { + uint8_t mEMM[16]; + uint8_t mECM[32]; + + } opaque; + + CHECK_EQ(emm->size(), sizeof(opaque.mEMM)); + memcpy(opaque.mEMM, emm->data(), emm->size()); + + CHECK_EQ(ecm->size(), 80u); + // bytes 16..47 of the original ecm stream data. + memcpy(opaque.mECM, ecm->data() + 16, 32); + + static const uint8_t kUUIDWidevine[16] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 + }; + + crypto = makeCrypto(kUUIDWidevine, &opaque, sizeof(opaque)); + CHECK(crypto != NULL); + CHECK_EQ(crypto->initCheck(), (status_t)OK); + } + + if (decryptInputBuffers + && crypto->requiresSecureDecoderComponent(mime.c_str())) { static const MediaCodecList *list = MediaCodecList::getInstance(); ssize_t index = @@ -137,7 +199,8 @@ static int decode( err = state->mCodec->configure( format, isVideo ? surface : NULL, - decryptInputBuffers ? MediaCodec::CONFIGURE_FLAG_SECURE : 0); + crypto, + 0 /* flags */); CHECK_EQ(err, (status_t)OK); -- cgit v1.1