@@ -126,6 +126,21 @@ status_t JMediaCodec::queueInputBuffer(
126126 return mCodec ->queueInputBuffer (index, offset, size, timeUs, flags);
127127}
128128
129+ status_t JMediaCodec::queueSecureInputBuffer (
130+ size_t index,
131+ size_t offset,
132+ const CryptoPlugin::SubSample *subSamples,
133+ size_t numSubSamples,
134+ const uint8_t key[16 ],
135+ const uint8_t iv[16 ],
136+ CryptoPlugin::Mode mode,
137+ int64_t presentationTimeUs,
138+ uint32_t flags) {
139+ return mCodec ->queueSecureInputBuffer (
140+ index, offset, subSamples, numSubSamples, key, iv, mode,
141+ presentationTimeUs, flags);
142+ }
143+
129144status_t JMediaCodec::dequeueInputBuffer (size_t *index, int64_t timeoutUs) {
130145 return mCodec ->dequeueInputBuffer (index, timeoutUs);
131146}
@@ -367,6 +382,125 @@ static void android_media_MediaCodec_queueInputBuffer(
367382 throwExceptionAsNecessary (env, err);
368383}
369384
385+ static void android_media_MediaCodec_queueSecureInputBuffer (
386+ JNIEnv *env,
387+ jobject thiz,
388+ jint index,
389+ jint offset,
390+ jintArray numBytesOfClearDataObj,
391+ jintArray numBytesOfEncryptedDataObj,
392+ jint numSubSamples,
393+ jbyteArray keyObj,
394+ jbyteArray ivObj,
395+ jint mode,
396+ jlong timestampUs,
397+ jint flags) {
398+ ALOGV (" android_media_MediaCodec_queueSecureInputBuffer" );
399+
400+ sp<JMediaCodec> codec = getMediaCodec (env, thiz);
401+
402+ if (codec == NULL ) {
403+ jniThrowException (env, " java/lang/IllegalStateException" , NULL );
404+ return ;
405+ }
406+
407+ status_t err = OK;
408+
409+ CryptoPlugin::SubSample *subSamples = NULL ;
410+ jbyte *key = NULL ;
411+ jbyte *iv = NULL ;
412+
413+ if (numSubSamples <= 0 ) {
414+ err = -EINVAL;
415+ } else if (numBytesOfClearDataObj == NULL
416+ && numBytesOfEncryptedDataObj == NULL ) {
417+ err = -EINVAL;
418+ } else if (numBytesOfEncryptedDataObj != NULL
419+ && env->GetArrayLength (numBytesOfEncryptedDataObj) < numSubSamples) {
420+ err = -ERANGE;
421+ } else if (numBytesOfClearDataObj != NULL
422+ && env->GetArrayLength (numBytesOfClearDataObj) < numSubSamples) {
423+ err = -ERANGE;
424+ } else {
425+ jboolean isCopy;
426+
427+ jint *numBytesOfClearData =
428+ (numBytesOfClearDataObj == NULL )
429+ ? NULL
430+ : env->GetIntArrayElements (numBytesOfClearDataObj, &isCopy);
431+
432+ jint *numBytesOfEncryptedData =
433+ (numBytesOfEncryptedDataObj == NULL )
434+ ? NULL
435+ : env->GetIntArrayElements (numBytesOfEncryptedDataObj, &isCopy);
436+
437+ subSamples = new CryptoPlugin::SubSample[numSubSamples];
438+
439+ for (jint i = 0 ; i < numSubSamples; ++i) {
440+ subSamples[i].mNumBytesOfClearData =
441+ (numBytesOfClearData == NULL ) ? 0 : numBytesOfClearData[i];
442+
443+ subSamples[i].mNumBytesOfEncryptedData =
444+ (numBytesOfEncryptedData == NULL )
445+ ? 0 : numBytesOfEncryptedData[i];
446+ }
447+
448+ if (numBytesOfEncryptedData != NULL ) {
449+ env->ReleaseIntArrayElements (
450+ numBytesOfEncryptedDataObj, numBytesOfEncryptedData, 0 );
451+ numBytesOfEncryptedData = NULL ;
452+ }
453+
454+ if (numBytesOfClearData != NULL ) {
455+ env->ReleaseIntArrayElements (
456+ numBytesOfClearDataObj, numBytesOfClearData, 0 );
457+ numBytesOfClearData = NULL ;
458+ }
459+ }
460+
461+ if (err == OK && keyObj != NULL ) {
462+ if (env->GetArrayLength (keyObj) != 16 ) {
463+ err = -EINVAL;
464+ } else {
465+ jboolean isCopy;
466+ key = env->GetByteArrayElements (keyObj, &isCopy);
467+ }
468+ }
469+
470+ if (err == OK && ivObj != NULL ) {
471+ if (env->GetArrayLength (ivObj) != 16 ) {
472+ err = -EINVAL;
473+ } else {
474+ jboolean isCopy;
475+ iv = env->GetByteArrayElements (ivObj, &isCopy);
476+ }
477+ }
478+
479+ if (err == OK) {
480+ err = codec->queueSecureInputBuffer (
481+ index, offset,
482+ subSamples, numSubSamples,
483+ (const uint8_t *)key, (const uint8_t *)iv,
484+ (CryptoPlugin::Mode)mode,
485+ timestampUs, flags);
486+ }
487+
488+ if (iv != NULL ) {
489+ env->ReleaseByteArrayElements (ivObj, iv, 0 );
490+ iv = NULL ;
491+ }
492+
493+ if (key != NULL ) {
494+ env->ReleaseByteArrayElements (keyObj, key, 0 );
495+ key = NULL ;
496+ }
497+
498+ delete[] subSamples;
499+ subSamples = NULL ;
500+
501+ throwExceptionAsNecessary (env, err);
502+ }
503+
370504static jint android_media_MediaCodec_dequeueInputBuffer (
371505 JNIEnv *env, jobject thiz, jlong timeoutUs) {
372506 ALOGV (" android_media_MediaCodec_dequeueInputBuffer" );
@@ -532,6 +666,9 @@ static JNINativeMethod gMethods[] = {
532666 { " queueInputBuffer" , " (IIIJI)V" ,
533667 (void *)android_media_MediaCodec_queueInputBuffer },
534668
669+ { " queueSecureInputBuffer" , " (II[I[II[B[BIJI)V" ,
670+ (void *)android_media_MediaCodec_queueSecureInputBuffer },
671+
535672 { " dequeueInputBuffer" , " (J)I" ,
536673 (void *)android_media_MediaCodec_dequeueInputBuffer },
537674
0 commit comments