188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber/*
288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber * Copyright 2012, The Android Open Source Project
388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber *
488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber * you may not use this file except in compliance with the License.
688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber * You may obtain a copy of the License at
788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber *
888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber *     http://www.apache.org/licenses/LICENSE-2.0
988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber *
1088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber * Unless required by applicable law or agreed to in writing, software
1188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
1288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber * See the License for the specific language governing permissions and
1488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber * limitations under the License.
1588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber */
1688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
1788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber//#define LOG_NDEBUG 0
1888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber#define LOG_TAG "MediaExtractor-JNI"
1988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber#include <utils/Log.h>
2088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
2188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber#include "android_media_MediaExtractor.h"
22ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick#include "android_media_MediaMetricsJNI.h"
2388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
2488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber#include "android_media_Utils.h"
2588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber#include "android_runtime/AndroidRuntime.h"
2687eac99a21772ae56018cb81db6966557b459554Ruben Brunk#include "android_runtime/Log.h"
2788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber#include "jni.h"
2888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber#include "JNIHelp.h"
294eaa2938084353a54dc259466172909329a048ccChris Watkins#include "android_media_MediaDataSource.h"
3088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
31d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber#include <media/IMediaHTTPService.h>
32ab57d03bdb3010d4957fb88c8acb30575ca02ec9Andreas Huber#include <media/hardware/CryptoAPI.h>
3388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber#include <media/stagefright/foundation/ABuffer.h>
3488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber#include <media/stagefright/foundation/ADebug.h>
3588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber#include <media/stagefright/foundation/AMessage.h>
3688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber#include <media/stagefright/DataSource.h>
3788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber#include <media/stagefright/MediaErrors.h>
3891befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber#include <media/stagefright/MetaData.h>
3988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber#include <media/stagefright/NuMediaExtractor.h>
40d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang#include <android/media/ICas.h>
4188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
427be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar#include <nativehelper/ScopedLocalRef.h>
437be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar
44d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber#include "android_util_Binder.h"
45d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber
4688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Hubernamespace android {
4788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
4888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstruct fields_t {
4988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    jfieldID context;
5091befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
5191befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    jmethodID cryptoInfoSetID;
5288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber};
5388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
5488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatic fields_t gFields;
5588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
5688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas HuberJMediaExtractor::JMediaExtractor(JNIEnv *env, jobject thiz)
5788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    : mClass(NULL),
5888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber      mObject(NULL) {
5988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    jclass clazz = env->GetObjectClass(thiz);
6088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    CHECK(clazz != NULL);
6188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
6288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    mClass = (jclass)env->NewGlobalRef(clazz);
6388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    mObject = env->NewWeakGlobalRef(thiz);
6488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
6588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    mImpl = new NuMediaExtractor;
6688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
6788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
6888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas HuberJMediaExtractor::~JMediaExtractor() {
6988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    JNIEnv *env = AndroidRuntime::getJNIEnv();
7088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
7188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    env->DeleteWeakGlobalRef(mObject);
7288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    mObject = NULL;
7388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    env->DeleteGlobalRef(mClass);
7488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    mClass = NULL;
7588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
7688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
7707ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huberstatus_t JMediaExtractor::setDataSource(
78d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber        const sp<IMediaHTTPService> &httpService,
79d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber        const char *path,
80d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber        const KeyedVector<String8, String8> *headers) {
81d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber    return mImpl->setDataSource(httpService, path, headers);
8207ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber}
8307ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber
8407ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huberstatus_t JMediaExtractor::setDataSource(int fd, off64_t offset, off64_t size) {
8507ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    return mImpl->setDataSource(fd, offset, size);
8688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
8788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
88c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissenstatus_t JMediaExtractor::setDataSource(const sp<DataSource> &datasource) {
89c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen    return mImpl->setDataSource(datasource);
90c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen}
91c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen
92d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhangstatus_t JMediaExtractor::setMediaCas(const sp<ICas> &cas) {
93d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang    return mImpl->setMediaCas(cas);
94d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang}
95d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang
9688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Hubersize_t JMediaExtractor::countTracks() const {
9788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    return mImpl->countTracks();
9888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
9988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
10088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatus_t JMediaExtractor::getTrackFormat(size_t index, jobject *format) const {
10188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    sp<AMessage> msg;
10288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    status_t err;
10388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if ((err = mImpl->getTrackFormat(index, &msg)) != OK) {
10488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return err;
10588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
10688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
10788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    JNIEnv *env = AndroidRuntime::getJNIEnv();
10888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
10988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    return ConvertMessageToMap(env, msg, format);
11088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
11188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
112e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissenstatus_t JMediaExtractor::getFileFormat(jobject *format) const {
113e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen    sp<AMessage> msg;
114e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen    status_t err;
115e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen    if ((err = mImpl->getFileFormat(&msg)) != OK) {
116e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen        return err;
117e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen    }
118e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen
119e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen    JNIEnv *env = AndroidRuntime::getJNIEnv();
120e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen
121e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen    return ConvertMessageToMap(env, msg, format);
122e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen}
123e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen
12488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatus_t JMediaExtractor::selectTrack(size_t index) {
12588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    return mImpl->selectTrack(index);
12688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
12788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
128f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huberstatus_t JMediaExtractor::unselectTrack(size_t index) {
129f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber    return mImpl->unselectTrack(index);
130f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber}
131f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber
132f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huberstatus_t JMediaExtractor::seekTo(
133f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber        int64_t timeUs, MediaSource::ReadOptions::SeekMode mode) {
134f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber    return mImpl->seekTo(timeUs, mode);
13588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
13688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
13788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatus_t JMediaExtractor::advance() {
13888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    return mImpl->advance();
13988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
14088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
14188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatus_t JMediaExtractor::readSampleData(
14288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jobject byteBuf, size_t offset, size_t *sampleSize) {
14388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    JNIEnv *env = AndroidRuntime::getJNIEnv();
14488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
14588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    void *dst = env->GetDirectBufferAddress(byteBuf);
14688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
147075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat    size_t dstSize;
148c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber    jbyteArray byteArray = NULL;
149c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber
1507be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar    ScopedLocalRef<jclass> byteBufClass(env, env->FindClass("java/nio/ByteBuffer"));
1517be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar    CHECK(byteBufClass.get() != NULL);
152c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber
1537be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar    if (dst == NULL) {
154c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber        jmethodID arrayID =
1557be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar            env->GetMethodID(byteBufClass.get(), "array", "()[B");
156c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber        CHECK(arrayID != NULL);
157c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber
158c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber        byteArray =
159c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber            (jbyteArray)env->CallObjectMethod(byteBuf, arrayID);
160c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber
161c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber        if (byteArray == NULL) {
162c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber            return INVALID_OPERATION;
163c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber        }
16488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
165c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber        jboolean isCopy;
166c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber        dst = env->GetByteArrayElements(byteArray, &isCopy);
167c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber
168075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        dstSize = (size_t) env->GetArrayLength(byteArray);
169c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber    } else {
170075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        dstSize = (size_t) env->GetDirectBufferCapacity(byteBuf);
171c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber    }
17288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
17388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (dstSize < offset) {
174c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber        if (byteArray != NULL) {
175c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber            env->ReleaseByteArrayElements(byteArray, (jbyte *)dst, 0);
176c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber        }
177c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber
17888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return -ERANGE;
17988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
18088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
18188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    sp<ABuffer> buffer = new ABuffer((char *)dst + offset, dstSize - offset);
18288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
18388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    status_t err = mImpl->readSampleData(buffer);
18488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
185c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber    if (byteArray != NULL) {
186c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber        env->ReleaseByteArrayElements(byteArray, (jbyte *)dst, 0);
187c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber    }
188c52b980277f08aee7981b1fdbca7a89464cf66d9Andreas Huber
18988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (err != OK) {
19088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return err;
19188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
19288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
19388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    *sampleSize = buffer->size();
19488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
1957be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar    jmethodID positionID = env->GetMethodID(
1967be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar            byteBufClass.get(), "position", "(I)Ljava/nio/Buffer;");
1977be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar
1987be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar    CHECK(positionID != NULL);
1997be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar
2007be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar    jmethodID limitID = env->GetMethodID(
2017be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar            byteBufClass.get(), "limit", "(I)Ljava/nio/Buffer;");
2027be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar
2037be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar    CHECK(limitID != NULL);
2047be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar
2057be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar    jobject me = env->CallObjectMethod(
2067be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar            byteBuf, limitID, offset + *sampleSize);
2077be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar    env->DeleteLocalRef(me);
2087be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar    me = env->CallObjectMethod(
2097be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar            byteBuf, positionID, offset);
2107be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar    env->DeleteLocalRef(me);
2117be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar    me = NULL;
2127be24522ce2e1821ad45e7ada7c3f91e6814889aLajos Molnar
21388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    return OK;
21488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
21588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
21688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatus_t JMediaExtractor::getSampleTrackIndex(size_t *trackIndex) {
21788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    return mImpl->getSampleTrackIndex(trackIndex);
21888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
21988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
22088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatus_t JMediaExtractor::getSampleTime(int64_t *sampleTimeUs) {
22188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    return mImpl->getSampleTime(sampleTimeUs);
22288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
22388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
2249b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huberstatus_t JMediaExtractor::getSampleFlags(uint32_t *sampleFlags) {
22591befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    *sampleFlags = 0;
22691befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
22791befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    sp<MetaData> meta;
22891befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    status_t err = mImpl->getSampleMeta(&meta);
22991befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
23091befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    if (err != OK) {
23191befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        return err;
23291befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    }
23391befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
23491befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    int32_t val;
23591befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    if (meta->findInt32(kKeyIsSyncFrame, &val) && val != 0) {
23691befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        (*sampleFlags) |= NuMediaExtractor::SAMPLE_FLAG_SYNC;
23791befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    }
23891befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
23991befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    uint32_t type;
24091befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    const void *data;
24191befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    size_t size;
24291befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    if (meta->findData(kKeyEncryptedSizes, &type, &data, &size)) {
24391befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        (*sampleFlags) |= NuMediaExtractor::SAMPLE_FLAG_ENCRYPTED;
24491befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    }
24591befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
24691befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    return OK;
24791befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber}
24891befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
249ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essickstatus_t JMediaExtractor::getMetrics(Parcel *reply) const {
250ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick
251ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    status_t status = mImpl->getMetrics(reply);
252ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    return status;
253ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick}
254ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick
255ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick
25691befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huberstatus_t JMediaExtractor::getSampleMeta(sp<MetaData> *sampleMeta) {
25791befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    return mImpl->getSampleMeta(sampleMeta);
2589b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber}
2599b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber
26074a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huberbool JMediaExtractor::getCachedDuration(int64_t *durationUs, bool *eos) const {
26174a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    return mImpl->getCachedDuration(durationUs, eos);
26274a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber}
26374a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber
26488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}  // namespace android
26588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
26688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber////////////////////////////////////////////////////////////////////////////////
26788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
26888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberusing namespace android;
26988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
27088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatic sp<JMediaExtractor> setMediaExtractor(
27188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        JNIEnv *env, jobject thiz, const sp<JMediaExtractor> &extractor) {
27288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    sp<JMediaExtractor> old =
273075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        (JMediaExtractor *)env->GetLongField(thiz, gFields.context);
27488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
27588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (extractor != NULL) {
27688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        extractor->incStrong(thiz);
27788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
27888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (old != NULL) {
27988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        old->decStrong(thiz);
28088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
281075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat    env->SetLongField(thiz, gFields.context, (jlong)extractor.get());
28288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
28388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    return old;
28488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
28588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
28688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatic sp<JMediaExtractor> getMediaExtractor(JNIEnv *env, jobject thiz) {
287075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat    return (JMediaExtractor *)env->GetLongField(thiz, gFields.context);
28888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
28988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
29088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatic void android_media_MediaExtractor_release(JNIEnv *env, jobject thiz) {
29188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    setMediaExtractor(env, thiz, NULL);
29288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
29388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
29460d610bf103379277a4b29a7ead4f013f6128e4eAndreas Huberstatic jint android_media_MediaExtractor_getTrackCount(
29588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        JNIEnv *env, jobject thiz) {
29688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
29788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
29888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (extractor == NULL) {
29988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jniThrowException(env, "java/lang/IllegalStateException", NULL);
30007ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber        return -1;
30188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
30288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
303075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat    return (jint) extractor->countTracks();
30488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
30588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
30660d610bf103379277a4b29a7ead4f013f6128e4eAndreas Huberstatic jobject android_media_MediaExtractor_getTrackFormatNative(
30788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        JNIEnv *env, jobject thiz, jint index) {
30888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
30988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
31088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (extractor == NULL) {
31188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jniThrowException(env, "java/lang/IllegalStateException", NULL);
31288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return NULL;
31388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
31488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
31588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    jobject format;
31688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    status_t err = extractor->getTrackFormat(index, &format);
31788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
31888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (err != OK) {
31988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
32088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return NULL;
32188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
32288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
32388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    return format;
32488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
32588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
326e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissenstatic jobject android_media_MediaExtractor_getFileFormatNative(
327e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen        JNIEnv *env, jobject thiz) {
328e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
329e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen
330e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen    if (extractor == NULL) {
331e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen        jniThrowException(env, "java/lang/IllegalStateException", NULL);
332e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen        return NULL;
333e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen    }
334e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen
335e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen    jobject format;
336e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen    status_t err = extractor->getFileFormat(&format);
337e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen
338e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen    if (err != OK) {
339e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
340e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen        return NULL;
341e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen    }
342e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen
343e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen    return format;
344e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen}
345e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen
34688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatic void android_media_MediaExtractor_selectTrack(
34788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        JNIEnv *env, jobject thiz, jint index) {
34888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
34988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
35088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (extractor == NULL) {
35188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jniThrowException(env, "java/lang/IllegalStateException", NULL);
35288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return;
35388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
35488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
35588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    status_t err = extractor->selectTrack(index);
35688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
35788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (err != OK) {
35888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
35988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return;
36088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
36188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
36288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
363f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huberstatic void android_media_MediaExtractor_unselectTrack(
364f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber        JNIEnv *env, jobject thiz, jint index) {
365f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
366f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber
367f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber    if (extractor == NULL) {
368f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber        jniThrowException(env, "java/lang/IllegalStateException", NULL);
369f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber        return;
370f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber    }
371f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber
372f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber    status_t err = extractor->unselectTrack(index);
373f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber
374f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber    if (err != OK) {
375f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
376f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber        return;
377f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber    }
378f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber}
379f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber
38088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatic void android_media_MediaExtractor_seekTo(
381f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber        JNIEnv *env, jobject thiz, jlong timeUs, jint mode) {
38288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
38388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
38488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (extractor == NULL) {
38588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jniThrowException(env, "java/lang/IllegalStateException", NULL);
38688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return;
38788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
38888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
389f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber    if (mode < MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC
390f86374adec8bd77af7b012f788ea59575296facbAndreas Huber            || mode >= MediaSource::ReadOptions::SEEK_CLOSEST) {
391f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
392f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber        return;
393f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber    }
394f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber
395f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber    extractor->seekTo(timeUs, (MediaSource::ReadOptions::SeekMode)mode);
39688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
39788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
39888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatic jboolean android_media_MediaExtractor_advance(
39988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        JNIEnv *env, jobject thiz) {
40088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
40188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
40288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (extractor == NULL) {
40388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jniThrowException(env, "java/lang/IllegalStateException", NULL);
404075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        return JNI_FALSE;
40588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
40688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
40788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    status_t err = extractor->advance();
40888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
40988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (err == ERROR_END_OF_STREAM) {
410075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        return JNI_FALSE;
41188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    } else if (err != OK) {
41288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
413075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        return JNI_FALSE;
41488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
41588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
416075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat    return JNI_TRUE;
41788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
41888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
41988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatic jint android_media_MediaExtractor_readSampleData(
42088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        JNIEnv *env, jobject thiz, jobject byteBuf, jint offset) {
42188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
42288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
42388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (extractor == NULL) {
42488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jniThrowException(env, "java/lang/IllegalStateException", NULL);
42588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return -1;
42688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
42788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
42888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    size_t sampleSize;
42988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    status_t err = extractor->readSampleData(byteBuf, offset, &sampleSize);
43088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
43188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (err == ERROR_END_OF_STREAM) {
43288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return -1;
43388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    } else if (err != OK) {
43488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
435075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        return -1;
43688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
43788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
438075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat    return (jint) sampleSize;
43988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
44088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
44188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatic jint android_media_MediaExtractor_getSampleTrackIndex(
44288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        JNIEnv *env, jobject thiz) {
44388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
44488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
44588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (extractor == NULL) {
44688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jniThrowException(env, "java/lang/IllegalStateException", NULL);
44788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return -1;
44888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
44988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
45088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    size_t trackIndex;
45188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    status_t err = extractor->getSampleTrackIndex(&trackIndex);
45288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
45388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (err == ERROR_END_OF_STREAM) {
45488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return -1;
45588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    } else if (err != OK) {
45688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
457075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        return -1;
45888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
45988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
460075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat    return (jint) trackIndex;
46188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
46288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
46388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatic jlong android_media_MediaExtractor_getSampleTime(
46488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        JNIEnv *env, jobject thiz) {
46588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
46688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
46788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (extractor == NULL) {
46888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jniThrowException(env, "java/lang/IllegalStateException", NULL);
46988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return -1ll;
47088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
47188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
47288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    int64_t sampleTimeUs;
47388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    status_t err = extractor->getSampleTime(&sampleTimeUs);
47488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
47588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (err == ERROR_END_OF_STREAM) {
47688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return -1ll;
47788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    } else if (err != OK) {
47888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
479075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        return -1ll;
48088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
48188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
482075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat    return (jlong) sampleTimeUs;
48388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
48488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
4859b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huberstatic jint android_media_MediaExtractor_getSampleFlags(
4869b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber        JNIEnv *env, jobject thiz) {
4879b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
4889b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber
4899b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber    if (extractor == NULL) {
4909b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber        jniThrowException(env, "java/lang/IllegalStateException", NULL);
491075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        return -1;
4929b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber    }
4939b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber
4949b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber    uint32_t sampleFlags;
4959b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber    status_t err = extractor->getSampleFlags(&sampleFlags);
4969b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber
4979b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber    if (err == ERROR_END_OF_STREAM) {
498075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        return -1;
4999b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber    } else if (err != OK) {
5009b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
501075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        return -1;
5029b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber    }
5039b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber
504075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat    return (jint) sampleFlags;
5059b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber}
5069b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber
50791befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huberstatic jboolean android_media_MediaExtractor_getSampleCryptoInfo(
50891befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        JNIEnv *env, jobject thiz, jobject cryptoInfoObj) {
50991befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
51091befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
51191befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    if (extractor == NULL) {
51291befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        jniThrowException(env, "java/lang/IllegalStateException", NULL);
513075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        return JNI_FALSE;
51491befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    }
51591befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
51691befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    sp<MetaData> meta;
51791befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    status_t err = extractor->getSampleMeta(&meta);
51891befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
51991befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    if (err != OK) {
520075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        return JNI_FALSE;
52191befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    }
52291befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
52391befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    uint32_t type;
52491befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    const void *data;
52591befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    size_t size;
52691befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    if (!meta->findData(kKeyEncryptedSizes, &type, &data, &size)) {
527075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        return JNI_FALSE;
52891befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    }
52991befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
530e92416dfeb115939231819c5edb593b8bb81cc6dAshok Bhat    size_t numSubSamples = size / sizeof(int32_t);
53191befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
53291befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    if (numSubSamples == 0) {
533075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        return JNI_FALSE;
53491befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    }
53591befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
53691befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    jintArray numBytesOfEncryptedDataObj = env->NewIntArray(numSubSamples);
53791befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    jboolean isCopy;
53891befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    jint *dst = env->GetIntArrayElements(numBytesOfEncryptedDataObj, &isCopy);
53991befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    for (size_t i = 0; i < numSubSamples; ++i) {
540e92416dfeb115939231819c5edb593b8bb81cc6dAshok Bhat        dst[i] = ((const int32_t *)data)[i];
54191befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    }
54291befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    env->ReleaseIntArrayElements(numBytesOfEncryptedDataObj, dst, 0);
54391befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    dst = NULL;
54491befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
54591befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    size_t encSize = size;
54691befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    jintArray numBytesOfPlainDataObj = NULL;
547ab57d03bdb3010d4957fb88c8acb30575ca02ec9Andreas Huber    if (meta->findData(kKeyPlainSizes, &type, &data, &size)) {
54891befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        if (size != encSize) {
54991befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber            // The two must be of the same length.
550075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat            return JNI_FALSE;
55191befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        }
55291befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
55391befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        numBytesOfPlainDataObj = env->NewIntArray(numSubSamples);
55491befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        jboolean isCopy;
55591befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        jint *dst = env->GetIntArrayElements(numBytesOfPlainDataObj, &isCopy);
55691befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        for (size_t i = 0; i < numSubSamples; ++i) {
557e92416dfeb115939231819c5edb593b8bb81cc6dAshok Bhat            dst[i] = ((const int32_t *)data)[i];
55891befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        }
55991befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        env->ReleaseIntArrayElements(numBytesOfPlainDataObj, dst, 0);
56091befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        dst = NULL;
56191befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    }
56291befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
56391befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    jbyteArray keyObj = NULL;
56491befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    if (meta->findData(kKeyCryptoKey, &type, &data, &size)) {
56591befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        if (size != 16) {
56691befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber            // Keys must be 16 bytes in length.
567075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat            return JNI_FALSE;
56891befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        }
56991befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
57091befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        keyObj = env->NewByteArray(size);
57191befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        jboolean isCopy;
57291befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        jbyte *dst = env->GetByteArrayElements(keyObj, &isCopy);
57391befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        memcpy(dst, data, size);
57491befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        env->ReleaseByteArrayElements(keyObj, dst, 0);
57591befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        dst = NULL;
57691befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    }
57791befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
57891befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    jbyteArray ivObj = NULL;
57991befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    if (meta->findData(kKeyCryptoIV, &type, &data, &size)) {
58091befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        if (size != 16) {
58191befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber            // IVs must be 16 bytes in length.
582075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat            return JNI_FALSE;
58391befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        }
58491befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
58591befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        ivObj = env->NewByteArray(size);
58691befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        jboolean isCopy;
58791befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        jbyte *dst = env->GetByteArrayElements(ivObj, &isCopy);
58891befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        memcpy(dst, data, size);
58991befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        env->ReleaseByteArrayElements(ivObj, dst, 0);
59091befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        dst = NULL;
59191befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    }
59291befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
59391befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    int32_t mode;
59491befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    if (!meta->findInt32(kKeyCryptoMode, &mode)) {
595ab57d03bdb3010d4957fb88c8acb30575ca02ec9Andreas Huber        mode = CryptoPlugin::kMode_AES_CTR;
59691befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    }
59791befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
59891befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    env->CallVoidMethod(
59991befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber            cryptoInfoObj,
60091befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber            gFields.cryptoInfoSetID,
601136c08a7d3678e9fcf22667e75b0904a94add6bbAshok Bhat            (jint)numSubSamples,
60291befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber            numBytesOfPlainDataObj,
60391befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber            numBytesOfEncryptedDataObj,
60491befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber            keyObj,
60591befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber            ivObj,
60691befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber            mode);
60791befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
608075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat    return JNI_TRUE;
60991befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber}
61091befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
61188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatic void android_media_MediaExtractor_native_init(JNIEnv *env) {
61288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    jclass clazz = env->FindClass("android/media/MediaExtractor");
61388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    CHECK(clazz != NULL);
61488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
615075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat    gFields.context = env->GetFieldID(clazz, "mNativeContext", "J");
61688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    CHECK(gFields.context != NULL);
61788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
61891befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    clazz = env->FindClass("android/media/MediaCodec$CryptoInfo");
61991befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    CHECK(clazz != NULL);
62091befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
62191befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    gFields.cryptoInfoSetID =
62291befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        env->GetMethodID(clazz, "set", "(I[I[I[B[BI)V");
62388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
62488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
62588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatic void android_media_MediaExtractor_native_setup(
62607ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber        JNIEnv *env, jobject thiz) {
62788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    sp<JMediaExtractor> extractor = new JMediaExtractor(env, thiz);
62807ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    setMediaExtractor(env,thiz, extractor);
62907ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber}
63088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
63107ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huberstatic void android_media_MediaExtractor_setDataSource(
63207ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber        JNIEnv *env, jobject thiz,
633d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber        jobject httpServiceBinderObj,
634d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber        jstring pathObj,
635d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber        jobjectArray keysArray,
636d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber        jobjectArray valuesArray) {
63707ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
63807ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber
63907ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    if (extractor == NULL) {
64007ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber        jniThrowException(env, "java/lang/IllegalStateException", NULL);
64107ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber        return;
64207ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    }
64307ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber
64407ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    if (pathObj == NULL) {
64588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
64688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return;
64788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
64888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
64907ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    KeyedVector<String8, String8> headers;
65007ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    if (!ConvertKeyValueArraysToKeyedVector(
65107ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber                env, keysArray, valuesArray, &headers)) {
65207ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber        return;
65307ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    }
65488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
65507ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    const char *path = env->GetStringUTFChars(pathObj, NULL);
65607ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber
65707ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    if (path == NULL) {
65888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return;
65988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
66088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
661d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber    sp<IMediaHTTPService> httpService;
662d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber    if (httpServiceBinderObj != NULL) {
663d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber        sp<IBinder> binder = ibinderForJavaObject(env, httpServiceBinderObj);
664d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber        httpService = interface_cast<IMediaHTTPService>(binder);
665d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber    }
666d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber
667d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber    status_t err = extractor->setDataSource(httpService, path, &headers);
66888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
66907ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    env->ReleaseStringUTFChars(pathObj, path);
67007ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    path = NULL;
67188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
67288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    if (err != OK) {
67388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        jniThrowException(
67488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber                env,
67588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber                "java/io/IOException",
67688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber                "Failed to instantiate extractor.");
67788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        return;
67888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    }
67907ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber}
68088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
68107ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huberstatic void android_media_MediaExtractor_setDataSourceFd(
68207ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber        JNIEnv *env, jobject thiz,
68307ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber        jobject fileDescObj, jlong offset, jlong length) {
68407ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
68507ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber
68607ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    if (extractor == NULL) {
68707ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber        jniThrowException(env, "java/lang/IllegalStateException", NULL);
68807ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber        return;
68907ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    }
69007ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber
69107ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    if (fileDescObj == NULL) {
69207ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
69307ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber        return;
69407ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    }
69507ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber
69607ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    int fd = jniGetFDFromFileDescriptor(env, fileDescObj);
69707ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber
69807ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    status_t err = extractor->setDataSource(fd, offset, length);
69907ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber
70007ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    if (err != OK) {
70107ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber        jniThrowException(
70207ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber                env,
70307ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber                "java/io/IOException",
70407ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber                "Failed to instantiate extractor.");
70507ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber        return;
70607ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    }
70788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
70888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
709c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissenstatic void android_media_MediaExtractor_setDataSourceCallback(
710c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen        JNIEnv *env, jobject thiz,
711c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen        jobject callbackObj) {
712c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
713c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen
714c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen    if (extractor == NULL) {
715c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen        jniThrowException(env, "java/lang/IllegalStateException", NULL);
716c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen        return;
717c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen    }
718c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen
719c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen    if (callbackObj == NULL) {
720c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
721c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen        return;
722c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen    }
723c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen
7244eaa2938084353a54dc259466172909329a048ccChris Watkins    sp<DataSource> bridge =
7254eaa2938084353a54dc259466172909329a048ccChris Watkins        DataSource::CreateFromIDataSource(new JMediaDataSource(env, callbackObj));
726c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen    status_t err = extractor->setDataSource(bridge);
727c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen
728c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen    if (err != OK) {
729bc10185fa1669a151568feb72277785d323fc344Chong Zhang        // Clear bridge so that JMediaDataSource::close() is called _before_
730bc10185fa1669a151568feb72277785d323fc344Chong Zhang        // we throw the IOException.
731bc10185fa1669a151568feb72277785d323fc344Chong Zhang        // Otherwise close() gets called when we go out of scope, it calls
732bc10185fa1669a151568feb72277785d323fc344Chong Zhang        // Java with a pending exception and crashes the process.
733bc10185fa1669a151568feb72277785d323fc344Chong Zhang        bridge.clear();
734c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen        jniThrowException(
735c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen                env,
736c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen                "java/io/IOException",
737c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen                "Failed to instantiate extractor.");
738c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen        return;
739c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen    }
740c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen}
741c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen
742d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhangstatic void android_media_MediaExtractor_setMediaCas(
743d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang        JNIEnv *env, jobject thiz, jobject casBinderObj) {
744d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
745d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang
746d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang    if (extractor == NULL) {
747d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang        jniThrowException(env, "java/lang/IllegalStateException", NULL);
748d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang        return;
749d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang    }
750d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang
751d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang    if (casBinderObj == NULL) {
752d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
753d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang        return;
754d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang    }
755d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang
756d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang    sp<ICas> cas;
757d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang    if (casBinderObj != NULL) {
758d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang        sp<IBinder> binder = ibinderForJavaObject(env, casBinderObj);
759d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang        cas = interface_cast<ICas>(binder);
760d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang    }
761d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang    status_t err = extractor->setMediaCas(cas);
762d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang
763d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang    if (err != OK) {
764d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang        cas.clear();
765d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang        jniThrowException(
766d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang                env,
767d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang                "java/io/IllegalArgumentException",
768d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang                "Failed to set MediaCas on extractor.");
769d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang    }
770d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang}
771d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang
77274a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huberstatic jlong android_media_MediaExtractor_getCachedDurationUs(
77374a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber        JNIEnv *env, jobject thiz) {
77474a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
77574a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber
77674a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    if (extractor == NULL) {
77774a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber        jniThrowException(env, "java/lang/IllegalStateException", NULL);
77874a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber        return -1ll;
77974a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    }
78074a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber
78174a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    int64_t cachedDurationUs;
78274a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    bool eos;
78374a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    if (!extractor->getCachedDuration(&cachedDurationUs, &eos)) {
78474a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber        return -1ll;
78574a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    }
78674a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber
787075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat    return (jlong) cachedDurationUs;
78874a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber}
78974a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber
79074a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huberstatic jboolean android_media_MediaExtractor_hasCacheReachedEOS(
79174a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber        JNIEnv *env, jobject thiz) {
79274a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
79374a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber
79474a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    if (extractor == NULL) {
79574a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber        jniThrowException(env, "java/lang/IllegalStateException", NULL);
796075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        return JNI_TRUE;
79774a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    }
79874a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber
79974a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    int64_t cachedDurationUs;
80074a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    bool eos;
80174a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    if (!extractor->getCachedDuration(&cachedDurationUs, &eos)) {
802075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat        return JNI_TRUE;
80374a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    }
80474a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber
805075e9a19ce645752f8282bc19c91b25978a7dc52Ashok Bhat    return eos ? JNI_TRUE : JNI_FALSE;
80674a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber}
80774a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber
80888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberstatic void android_media_MediaExtractor_native_finalize(
80988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        JNIEnv *env, jobject thiz) {
81088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    android_media_MediaExtractor_release(env, thiz);
81188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
81288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
813ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essickstatic jobject
814f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essickandroid_media_MediaExtractor_native_getMetrics(JNIEnv * env, jobject thiz)
815ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick{
816f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick    ALOGV("android_media_MediaExtractor_native_getMetrics");
817ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick
818ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    sp<JMediaExtractor> extractor = getMediaExtractor(env, thiz);
819ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    if (extractor == NULL ) {
820ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick        jniThrowException(env, "java/lang/IllegalStateException", NULL);
821ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick        return NULL;
822ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    }
823ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick
824ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    // get what we have for the metrics from the codec
825ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    Parcel reply;
826ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    status_t err = extractor->getMetrics(&reply);
827ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    if (err != OK) {
828ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick        ALOGE("getMetrics failed");
829ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick        return (jobject) NULL;
830ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    }
831ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick
832ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    // build and return the Bundle
833ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    MediaAnalyticsItem *item = new MediaAnalyticsItem;
834ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    item->readFromParcel(reply);
835ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    jobject mybundle = MediaMetricsJNI::writeMetricsToBundle(env, item, NULL);
836ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick
837ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    // housekeeping
838ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    delete item;
839ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    item = NULL;
840ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick
841ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick    return mybundle;
842ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick}
843ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick
844ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick
84576f6a86de25e1bf74717e047e55fd44b089673f3Daniel Micaystatic const JNINativeMethod gMethods[] = {
84688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    { "release", "()V", (void *)android_media_MediaExtractor_release },
84788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
84860d610bf103379277a4b29a7ead4f013f6128e4eAndreas Huber    { "getTrackCount", "()I", (void *)android_media_MediaExtractor_getTrackCount },
84988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
850e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen    { "getFileFormatNative", "()Ljava/util/Map;",
851e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen        (void *)android_media_MediaExtractor_getFileFormatNative },
852e20a6d5c479909f37af748a81a6e5a5deb7b6e2cMarco Nelissen
85360d610bf103379277a4b29a7ead4f013f6128e4eAndreas Huber    { "getTrackFormatNative", "(I)Ljava/util/Map;",
85460d610bf103379277a4b29a7ead4f013f6128e4eAndreas Huber        (void *)android_media_MediaExtractor_getTrackFormatNative },
85588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
85688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    { "selectTrack", "(I)V", (void *)android_media_MediaExtractor_selectTrack },
85788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
858f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber    { "unselectTrack", "(I)V",
859f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber        (void *)android_media_MediaExtractor_unselectTrack },
860f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber
861f2855b3df5994e165b29025c4c49d8e7d634c034Andreas Huber    { "seekTo", "(JI)V", (void *)android_media_MediaExtractor_seekTo },
86288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
86388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    { "advance", "()Z", (void *)android_media_MediaExtractor_advance },
86488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
86588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    { "readSampleData", "(Ljava/nio/ByteBuffer;I)I",
86688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        (void *)android_media_MediaExtractor_readSampleData },
86788572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
86888572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    { "getSampleTrackIndex", "()I",
86988572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        (void *)android_media_MediaExtractor_getSampleTrackIndex },
87088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
87188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    { "getSampleTime", "()J",
87288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber        (void *)android_media_MediaExtractor_getSampleTime },
87388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
8749b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber    { "getSampleFlags", "()I",
8759b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber        (void *)android_media_MediaExtractor_getSampleFlags },
8769b8e496f4d143280deff137c5f30ca8907bc28dbAndreas Huber
87791befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber    { "getSampleCryptoInfo", "(Landroid/media/MediaCodec$CryptoInfo;)Z",
87891befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber        (void *)android_media_MediaExtractor_getSampleCryptoInfo },
87991befdc0c4710234840cdfd853e7d30e8f9de62cAndreas Huber
88088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    { "native_init", "()V", (void *)android_media_MediaExtractor_native_init },
88188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
88207ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    { "native_setup", "()V",
88388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber      (void *)android_media_MediaExtractor_native_setup },
88488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
88588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    { "native_finalize", "()V",
88688572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber      (void *)android_media_MediaExtractor_native_finalize },
88707ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber
888d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber    { "nativeSetDataSource",
889d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber        "(Landroid/os/IBinder;Ljava/lang/String;[Ljava/lang/String;"
890d2506a506303ed94fd1991cf986b825b870a67c5Andreas Huber        "[Ljava/lang/String;)V",
89107ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber      (void *)android_media_MediaExtractor_setDataSource },
89207ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber
89307ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber    { "setDataSource", "(Ljava/io/FileDescriptor;JJ)V",
89407ea426e3ae8915ca6bf67135f523f42cd920af0Andreas Huber      (void *)android_media_MediaExtractor_setDataSourceFd },
89574a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber
8964eaa2938084353a54dc259466172909329a048ccChris Watkins    { "setDataSource", "(Landroid/media/MediaDataSource;)V",
897c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen      (void *)android_media_MediaExtractor_setDataSourceCallback },
898c209a06cfdcf633f12a299245312e3ac32bff27cMarco Nelissen
899d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang    { "nativeSetMediaCas", "(Landroid/os/IBinder;)V",
900d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang      (void *)android_media_MediaExtractor_setMediaCas },
901d5927ae8833780395f8fc5070d0a0a4f8f668292Chong Zhang
90274a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    { "getCachedDuration", "()J",
90374a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber      (void *)android_media_MediaExtractor_getCachedDurationUs },
90474a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber
90574a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber    { "hasCacheReachedEndOfStream", "()Z",
90674a78b0f6e8c07cfc7da8f043987f6de0648bc05Andreas Huber      (void *)android_media_MediaExtractor_hasCacheReachedEOS },
907ba5ce2c0f8c8b7349225d7367a422cf505ff419eRay Essick
90810353e36018224b86ef2918d1d68107459d445cfRay Essick    {"native_getMetrics",          "()Landroid/os/PersistableBundle;",
909f2d0e40bf01fa133dd6b36f3716005d53fa9776cRay Essick      (void *)android_media_MediaExtractor_native_getMetrics},
91088572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber};
91188572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber
91288572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huberint register_android_media_MediaExtractor(JNIEnv *env) {
91388572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber    return AndroidRuntime::registerNativeMethods(env,
91488572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber                "android/media/MediaExtractor", gMethods, NELEM(gMethods));
91588572f7a3e9d7ef85c26865a0150f3c2041561c2Andreas Huber}
916