From ed3e3e046840d5bf1ca84a8c0cc097425e89d6d6 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Mon, 26 Mar 2012 11:13:27 -0700 Subject: Provisional support for secure decryption of media streams. Change-Id: Ib3982a9c960bfdb0cb7e1b174440b141b194cfbe --- cmds/stagefright/codec.cpp | 58 +++++++++++++++++++++++++++++++++++++++------- cmds/stagefright/sf2.cpp | 5 ++++ 2 files changed, 55 insertions(+), 8 deletions(-) (limited to 'cmds') diff --git a/cmds/stagefright/codec.cpp b/cmds/stagefright/codec.cpp index fea62cc..cf2909e 100644 --- a/cmds/stagefright/codec.cpp +++ b/cmds/stagefright/codec.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -36,7 +37,9 @@ static void usage(const char *me) { fprintf(stderr, "usage: %s [-a] use audio\n" "\t\t[-v] use video\n" "\t\t[-p] playback\n" - "\t\t[-S] allocate buffers from a surface\n", me); + "\t\t[-S] allocate buffers from a surface\n" + "\t\t[-D] decrypt input buffers\n", + me); exit(1); } @@ -63,7 +66,8 @@ static int decode( const char *path, bool useAudio, bool useVideo, - const android::sp &surface) { + const android::sp &surface, + bool decryptInputBuffers) { using namespace android; static int64_t kTimeout = 500ll; @@ -109,13 +113,31 @@ static int decode( state->mNumBuffersDecoded = 0; state->mIsAudio = isAudio; - state->mCodec = MediaCodec::CreateByType( - looper, mime.c_str(), false /* encoder */); + if (decryptInputBuffers && !isAudio) { + static const MediaCodecList *list = MediaCodecList::getInstance(); + + ssize_t index = + list->findCodecByType(mime.c_str(), false /* encoder */); + + CHECK_GE(index, 0); + + const char *componentName = list->getCodecName(index); + + AString fullName = componentName; + fullName.append(".secure"); + + state->mCodec = MediaCodec::CreateByComponentName( + looper, fullName.c_str()); + } else { + state->mCodec = MediaCodec::CreateByType( + looper, mime.c_str(), false /* encoder */); + } CHECK(state->mCodec != NULL); err = state->mCodec->configure( - format, isVideo ? surface : NULL, 0 /* flags */); + format, isVideo ? surface : NULL, + decryptInputBuffers ? MediaCodec::CONFIGURE_FLAG_SECURE : 0); CHECK_EQ(err, (status_t)OK); @@ -202,12 +224,24 @@ static int decode( err = extractor->getSampleTime(&timeUs); CHECK_EQ(err, (status_t)OK); + uint32_t bufferFlags = 0; + + uint32_t sampleFlags; + err = extractor->getSampleFlags(&sampleFlags); + CHECK_EQ(err, (status_t)OK); + + if (sampleFlags & NuMediaExtractor::SAMPLE_FLAG_ENCRYPTED) { + CHECK(decryptInputBuffers); + + bufferFlags |= MediaCodec::BUFFER_FLAG_ENCRYPTED; + } + err = state->mCodec->queueInputBuffer( index, 0 /* offset */, buffer->size(), timeUs, - 0 /* flags */); + bufferFlags); CHECK_EQ(err, (status_t)OK); @@ -341,9 +375,10 @@ int main(int argc, char **argv) { bool useVideo = false; bool playback = false; bool useSurface = false; + bool decryptInputBuffers = false; int res; - while ((res = getopt(argc, argv, "havpS")) >= 0) { + while ((res = getopt(argc, argv, "havpSD")) >= 0) { switch (res) { case 'a': { @@ -369,6 +404,12 @@ int main(int argc, char **argv) { break; } + case 'D': + { + decryptInputBuffers = true; + break; + } + case '?': case 'h': default: @@ -440,7 +481,8 @@ int main(int argc, char **argv) { player->stop(); player->reset(); } else { - decode(looper, argv[0], useAudio, useVideo, surface); + decode(looper, argv[0], + useAudio, useVideo, surface, decryptInputBuffers); } if (playback || (useSurface && useVideo)) { diff --git a/cmds/stagefright/sf2.cpp b/cmds/stagefright/sf2.cpp index 64df5d1..3bbfbdc 100644 --- a/cmds/stagefright/sf2.cpp +++ b/cmds/stagefright/sf2.cpp @@ -287,6 +287,11 @@ private: msg->setInt32("channel-count", numChannels); msg->setInt32("sample-rate", sampleRate); + + int32_t isADTS; + if (meta->findInt32(kKeyIsADTS, &isADTS) && isADTS != 0) { + msg->setInt32("is-adts", true); + } } uint32_t type; -- cgit v1.1