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

Commit 48072cfe authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "MediaPlayer2: clean up libstagefright_player2"

parents e6d56684 42437ad0
Loading
Loading
Loading
Loading
+0 −23
Original line number Diff line number Diff line
@@ -239,52 +239,29 @@ cc_library_static {
    name: "libstagefright_player2",

    srcs: [
        "CallbackDataSource.cpp",
        "CallbackMediaSource.cpp",
        "ClearDataSourceFactory.cpp",
        "ClearFileSource.cpp",
        "DataURISource.cpp",
        "HTTPBase.cpp",
        "HevcUtils.cpp",
        "InterfaceUtils.cpp",
        "MediaClock.cpp",
        "MediaExtractor.cpp",
        "MediaExtractorFactory.cpp",
        "NdkUtils.cpp",
        "NuCachedSource2.cpp",
        "RemoteMediaExtractor.cpp",
        "RemoteMediaSource.cpp",
        "Utils.cpp",
        "VideoFrameScheduler.cpp",
        "http/ClearMediaHTTP.cpp",
    ],

    shared_libs: [
        "libbinder",
        "libcutils",
        "libgui",
        "liblog",
        "libaudioclient",
        "libmediaextractor",
        "libmediametrics",
        "libmediautils",
        "libnetd_client",
        "libui",
        "libutils",
        "libmedia_helper",
        "libstagefright_foundation",
        "libziparchive",
    ],

    static_libs: [
        "libstagefright_esds",
        "libmedia_player2_util",
    ],

    header_libs:[
        "media_plugin_headers",
    ],

    export_include_dirs: [
        "include",
    ],
+0 −117
Original line number Diff line number Diff line
/*
 * Copyright (C) 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 "ClearDataSourceFactory"

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

#include <media/MediaHTTPConnection.h>
#include <media/MediaHTTPService.h>
#include <media/stagefright/ClearFileSource.h>
#include <media/stagefright/ClearMediaHTTP.h>
#include <media/stagefright/ClearDataSourceFactory.h>
#include <media/stagefright/DataURISource.h>
#include <utils/String8.h>

namespace android {

// static
sp<DataSource> ClearDataSourceFactory::CreateFromURI(
        const sp<MediaHTTPService> &httpService,
        const char *uri,
        const KeyedVector<String8, String8> *headers,
        String8 *contentType,
        HTTPBase *httpSource) {
    if (contentType != NULL) {
        *contentType = "";
    }

    sp<DataSource> source;
    if (!strncasecmp("file://", uri, 7)) {
        source = new ClearFileSource(uri + 7);
    } else if (!strncasecmp("http://", uri, 7) || !strncasecmp("https://", uri, 8)) {
        if (httpService == NULL) {
            ALOGE("Invalid http service!");
            return NULL;
        }

        if (httpSource == NULL) {
            sp<MediaHTTPConnection> conn = httpService->makeHTTPConnection();
            if (conn == NULL) {
                ALOGE("Failed to make http connection from http service!");
                return NULL;
            }
            httpSource = new ClearMediaHTTP(conn);
        }

        String8 cacheConfig;
        bool disconnectAtHighwatermark = false;
        KeyedVector<String8, String8> nonCacheSpecificHeaders;
        if (headers != NULL) {
            nonCacheSpecificHeaders = *headers;
            NuCachedSource2::RemoveCacheSpecificHeaders(
                    &nonCacheSpecificHeaders,
                    &cacheConfig,
                    &disconnectAtHighwatermark);
        }

        if (httpSource->connect(uri, &nonCacheSpecificHeaders) != OK) {
            ALOGE("Failed to connect http source!");
            return NULL;
        }

        if (contentType != NULL) {
            *contentType = httpSource->getMIMEType();
        }

        source = NuCachedSource2::Create(
                httpSource,
                cacheConfig.isEmpty() ? NULL : cacheConfig.string(),
                disconnectAtHighwatermark);
    } else if (!strncasecmp("data:", uri, 5)) {
        source = DataURISource::Create(uri);
    } else {
        // Assume it's a filename.
        source = new ClearFileSource(uri);
    }

    if (source == NULL || source->initCheck() != OK) {
        return NULL;
    }

    return source;
}

sp<DataSource> ClearDataSourceFactory::CreateFromFd(int fd, int64_t offset, int64_t length) {
    sp<ClearFileSource> source = new ClearFileSource(fd, offset, length);
    return source->initCheck() != OK ? nullptr : source;
}

sp<DataSource> ClearDataSourceFactory::CreateMediaHTTP(const sp<MediaHTTPService> &httpService) {
    if (httpService == NULL) {
        return NULL;
    }

    sp<MediaHTTPConnection> conn = httpService->makeHTTPConnection();
    if (conn == NULL) {
        return NULL;
    } else {
        return new ClearMediaHTTP(conn);
    }
}

}  // namespace android
+0 −45
Original line number Diff line number Diff line
/*
 * Copyright (C) 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 DATA_SOURCE_FACTORY2_H_

#define DATA_SOURCE_FACTORY2_H_

#include <sys/types.h>
#include <utils/RefBase.h>

namespace android {

struct MediaHTTPService;
class String8;
struct HTTPBase;

class ClearDataSourceFactory {
public:
    static sp<DataSource> CreateFromURI(
            const sp<MediaHTTPService> &httpService,
            const char *uri,
            const KeyedVector<String8, String8> *headers = NULL,
            String8 *contentType = NULL,
            HTTPBase *httpSource = NULL);

    static sp<DataSource> CreateMediaHTTP(const sp<MediaHTTPService> &httpService);
    static sp<DataSource> CreateFromFd(int fd, int64_t offset, int64_t length);
};

}  // namespace android

#endif  // DATA_SOURCE_FACTORY2_H_