Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f0941797 authored by Robert Shih's avatar Robert Shih Committed by Android (Google) Code Review
Browse files

Merge "Introduce AMediaDataSource_newUri API"

parents b3d9c5f2 2568eb97
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ cc_library_shared {
        "libgui",
        "libui",
        "libmedia2_jni_core",
        "libmediandk_utils",
    ],

    export_include_dirs: ["include"],
@@ -99,3 +100,44 @@ llndk_library {
    symbol_file: "libmediandk.map.txt",
    export_include_dirs: ["include"],
}

cc_library {
    name: "libmediandk_utils",

    srcs: [
        "NdkMediaDataSourceCallbacks.cpp",
    ],

    include_dirs: [
        "frameworks/av/media/libstagefright/include",
        "frameworks/av/media/ndk/include",
    ],

    export_include_dirs: [
        "include",
    ],

    cflags: [
        "-Werror",
        "-Wno-error=deprecated-declarations",
        "-Wall",
    ],

    shared_libs: [
        "libstagefright_foundation",
        "liblog",
        "libutils",
        "libcutils",
    ],

    sanitize: {
        misc_undefined: [
            "unsigned-integer-overflow",
            "signed-integer-overflow",
        ],
        cfi: true,
        diag: {
            cfi: true,
        },
    },
}
+20 −0
Original line number Diff line number Diff line
@@ -32,12 +32,14 @@
#include <media/IMediaHTTPService.h>
#include <media/NdkMediaError.h>
#include <media/NdkMediaDataSource.h>
#include <media/stagefright/DataSourceFactory.h>
#include <media/stagefright/InterfaceUtils.h>
#include <mediaplayer2/JavaVMHelper.h>
#include <mediaplayer2/JMedia2HTTPService.h>

#include "../../libstagefright/include/HTTPBase.h"
#include "../../libstagefright/include/NuCachedSource2.h"
#include "NdkMediaDataSourceCallbacksPriv.h"

using namespace android;

@@ -187,6 +189,24 @@ AMediaDataSource* AMediaDataSource_new() {
    return mSource;
}

EXPORT
AMediaDataSource* AMediaDataSource_newUri(
        const char *uri,
        int numheaders,
        const char * const *key_values) {

    sp<MediaHTTPService> service = createMediaHttpService(uri, /* version = */ 1);
    KeyedVector<String8, String8> headers;
    for (int i = 0; i < numheaders; ++i) {
        String8 key8(key_values[i * 2]);
        String8 value8(key_values[i * 2 + 1]);
        headers.add(key8, value8);
    }

    sp<DataSource> source = DataSourceFactory::CreateFromURI(service, uri, &headers);
    return convertDataSourceToAMediaDataSource(source);
}

EXPORT
void AMediaDataSource_delete(AMediaDataSource *mSource) {
    ALOGV("dtor");
+42 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

//#define LOG_NDEBUG 0
#define LOG_TAG "NdkMediaDataSourceCallbacks"

#include "NdkMediaDataSourceCallbacksPriv.h"
#include <media/DataSource.h>

namespace android {

ssize_t DataSource_getSize(void *userdata) {
    DataSource *source = static_cast<DataSource *>(userdata);
    off64_t size = -1;
    source->getSize(&size);
    return size;
}

ssize_t DataSource_readAt(void *userdata, off64_t offset, void * buf, size_t size) {
    DataSource *source = static_cast<DataSource *>(userdata);
    return source->readAt(offset, buf, size);
}

void DataSource_close(void *userdata) {
    DataSource *source = static_cast<DataSource *>(userdata);
    source->close();
}

}  // namespace android
+48 −0
Original line number Diff line number Diff line
/*
 * Copyright 2018, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef A_MEDIA_DATA_SOURCE_CALLBACKS_H

#define A_MEDIA_DATA_SOURCE_CALLBACKS_H

#include <media/DataSource.h>
#include <media/NdkMediaDataSource.h>
#include <media/NdkMediaError.h>
#include <sys/types.h>

namespace android {

ssize_t DataSource_getSize(void *userdata);

ssize_t DataSource_readAt(void *userdata, off64_t offset, void * buf, size_t size);

void DataSource_close(void *userdata);

static inline AMediaDataSource* convertDataSourceToAMediaDataSource(const sp<DataSource> &source) {
    if (source == NULL) {
        return NULL;
    }
    AMediaDataSource *mSource = AMediaDataSource_new();
    AMediaDataSource_setUserdata(mSource, source.get());
    AMediaDataSource_setReadAt(mSource, DataSource_readAt);
    AMediaDataSource_setGetSize(mSource, DataSource_getSize);
    AMediaDataSource_setClose(mSource, DataSource_close);
    return mSource;
}

}  // namespace android

#endif  // A_MEDIA_DATA_SOURCE_CALLBACKS_H
+24 −0
Original line number Diff line number Diff line
@@ -86,6 +86,30 @@ typedef void (*AMediaDataSourceClose)(void *userdata);
 */
AMediaDataSource* AMediaDataSource_new() __INTRODUCED_IN(28);

#if __ANDROID_API__ >= 29

/**
 * Create new media data source. Returns NULL if memory allocation
 * for the new data source object fails.
 *
 * Set the |uri| from which the data source will read,
 * plus additional http headers when initiating the request.
 *
 * Headers will contain corresponding items from |key_values|
 * in the following fashion:
 *
 * key_values[0]:key_values[1]
 * key_values[2]:key_values[3]
 * ...
 * key_values[(numheaders - 1) * 2]:key_values[(numheaders - 1) * 2 + 1]
 *
 */
AMediaDataSource* AMediaDataSource_newUri(const char *uri,
        int numheaders,
        const char * const *key_values) __INTRODUCED_IN(29);

#endif  /*__ANDROID_API__ >= 29 */

/**
 * Delete a previously created media data source.
 */
Loading