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

Commit 81dd60e0 authored by Oscar Rydhé's avatar Oscar Rydhé Committed by Andreas Huber
Browse files

Added HTTP support for SDP files.

Added support for playing SDP files from http links. Previously,
SDP files only worked when started from rtsp links
(rtsp://a.b.c/abc.sdp), but they are just as common in http links.

patch provided by "Oscar Rydhé <oscar.rydhe@sonyericsson.com>"

Change-Id: Ic73af3a9a002009dbe8b04c267a4621bf7fe2f46
parent 5ab368af
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -215,6 +215,10 @@ class NuPlayerFactory : public MediaPlayerFactory::IFactory {
            if (strstr(url,"m3u8")) {
                return kOurScore;
            }

            if ((len >= 4 && !strcasecmp(".sdp", &url[len - 4])) || strstr(url, ".sdp?")) {
                return kOurScore;
            }
        }

        if (!strncasecmp("rtsp://", url, 7)) {
+6 −0
Original line number Diff line number Diff line
@@ -177,6 +177,7 @@ static bool IsHTTPLiveURL(const char *url) {
void NuPlayer::setDataSource(
        const char *url, const KeyedVector<String8, String8> *headers) {
    sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
    size_t len = strlen(url);

    sp<AMessage> notify = new AMessage(kWhatSourceNotify, id());

@@ -185,6 +186,11 @@ void NuPlayer::setDataSource(
        source = new HTTPLiveSource(notify, url, headers, mUIDValid, mUID);
    } else if (!strncasecmp(url, "rtsp://", 7)) {
        source = new RTSPSource(notify, url, headers, mUIDValid, mUID);
    } else if ((!strncasecmp(url, "http://", 7)
                || !strncasecmp(url, "https://", 8))
                    && ((len >= 4 && !strcasecmp(".sdp", &url[len - 4]))
                    || strstr(url, ".sdp?"))) {
        source = new RTSPSource(notify, url, headers, mUIDValid, mUID, true);
    } else {
        source = new GenericSource(notify, url, headers, mUIDValid, mUID);
    }
+68 −6
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@

#include "AnotherPacketSource.h"
#include "MyHandler.h"
#include "SDPLoader.h"

#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MetaData.h>
@@ -33,12 +34,14 @@ NuPlayer::RTSPSource::RTSPSource(
        const char *url,
        const KeyedVector<String8, String8> *headers,
        bool uidValid,
        uid_t uid)
        uid_t uid,
        bool isSDP)
    : Source(notify),
      mURL(url),
      mUIDValid(uidValid),
      mUID(uid),
      mFlags(0),
      mIsSDP(isSDP),
      mState(DISCONNECTED),
      mFinalResult(OK),
      mDisconnectReplyID(0),
@@ -73,17 +76,26 @@ void NuPlayer::RTSPSource::start() {
    }

    CHECK(mHandler == NULL);
    CHECK(mSDPLoader == NULL);

    sp<AMessage> notify = new AMessage(kWhatNotify, mReflector->id());

    mHandler = new MyHandler(mURL.c_str(), notify, mUIDValid, mUID);
    mLooper->registerHandler(mHandler);

    CHECK_EQ(mState, (int)DISCONNECTED);
    mState = CONNECTING;

    if (mIsSDP) {
        mSDPLoader = new SDPLoader(notify,
                (mFlags & kFlagIncognito) ? SDPLoader::kFlagIncognito : 0,
                mUIDValid, mUID);

        mSDPLoader->load(mURL.c_str(), mExtraHeaders.isEmpty() ? NULL : &mExtraHeaders);
    } else {
        mHandler = new MyHandler(mURL.c_str(), notify, mUIDValid, mUID);
        mLooper->registerHandler(mHandler);

        mHandler->connect();
    }
}

void NuPlayer::RTSPSource::stop() {
    if (mLooper == NULL) {
@@ -408,6 +420,12 @@ void NuPlayer::RTSPSource::onMessageReceived(const sp<AMessage> &msg) {
            break;
        }

        case SDPLoader::kWhatSDPLoaded:
        {
            onSDPLoaded(msg);
            break;
        }

        default:
            TRESPASS();
    }
@@ -461,6 +479,46 @@ void NuPlayer::RTSPSource::onConnected() {
    mState = CONNECTED;
}

void NuPlayer::RTSPSource::onSDPLoaded(const sp<AMessage> &msg) {
    status_t err;
    CHECK(msg->findInt32("result", &err));

    mSDPLoader.clear();

    if (mDisconnectReplyID != 0) {
        err = UNKNOWN_ERROR;
    }

    if (err == OK) {
        sp<ASessionDescription> desc;
        sp<RefBase> obj;
        CHECK(msg->findObject("description", &obj));
        desc = static_cast<ASessionDescription *>(obj.get());

        AString rtspUri;
        if (!desc->findAttribute(0, "a=control", &rtspUri)) {
            ALOGE("Unable to find url in SDP");
            err = UNKNOWN_ERROR;
        } else {
            sp<AMessage> notify = new AMessage(kWhatNotify, mReflector->id());

            mHandler = new MyHandler(rtspUri.c_str(), notify, mUIDValid, mUID);
            mLooper->registerHandler(mHandler);

            mHandler->loadSDP(desc);
        }
    }

    if (err != OK) {
        mState = DISCONNECTED;
        mFinalResult = err;

        if (mDisconnectReplyID != 0) {
            finishDisconnectIfPossible();
        }
    }
}

void NuPlayer::RTSPSource::onDisconnected(const sp<AMessage> &msg) {
    status_t err;
    CHECK(msg->findInt32("result", &err));
@@ -479,7 +537,11 @@ void NuPlayer::RTSPSource::onDisconnected(const sp<AMessage> &msg) {

void NuPlayer::RTSPSource::finishDisconnectIfPossible() {
    if (mState != DISCONNECTED) {
        if (mHandler != NULL) {
            mHandler->disconnect();
        } else if (mSDPLoader != NULL) {
            mSDPLoader->cancel();
        }
        return;
    }

+6 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ namespace android {
struct ALooper;
struct AnotherPacketSource;
struct MyHandler;
struct SDPLoader;

struct NuPlayer::RTSPSource : public NuPlayer::Source {
    RTSPSource(
@@ -36,7 +37,8 @@ struct NuPlayer::RTSPSource : public NuPlayer::Source {
            const char *url,
            const KeyedVector<String8, String8> *headers,
            bool uidValid = false,
            uid_t uid = 0);
            uid_t uid = 0,
            bool isSDP = false);

    virtual void start();
    virtual void stop();
@@ -90,6 +92,7 @@ private:
    bool mUIDValid;
    uid_t mUID;
    uint32_t mFlags;
    bool mIsSDP;
    State mState;
    status_t mFinalResult;
    uint32_t mDisconnectReplyID;
@@ -98,6 +101,7 @@ private:
    sp<ALooper> mLooper;
    sp<AHandlerReflector<RTSPSource> > mReflector;
    sp<MyHandler> mHandler;
    sp<SDPLoader> mSDPLoader;

    Vector<TrackInfo> mTracks;
    sp<AnotherPacketSource> mAudioTrack;
@@ -110,6 +114,7 @@ private:
    sp<AnotherPacketSource> getSource(bool audio);

    void onConnected();
    void onSDPLoaded(const sp<AMessage> &msg);
    void onDisconnected(const sp<AMessage> &msg);
    void finishDisconnectIfPossible();

+70 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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 SDP_LOADER_H_

#define SDP_LOADER_H_

#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/AHandler.h>
#include <utils/String8.h>

namespace android {

struct HTTPBase;

struct SDPLoader : public AHandler {
    enum Flags {
        // Don't log any URLs.
        kFlagIncognito = 1,
    };
    enum {
        kWhatSDPLoaded = 'sdpl'
    };
    SDPLoader(const sp<AMessage> &notify, uint32_t flags = 0, bool uidValid = false, uid_t uid = 0);

    void load(const char* url, const KeyedVector<String8, String8> *headers);

    void cancel();

protected:
    virtual ~SDPLoader() {}

    virtual void onMessageReceived(const sp<AMessage> &msg);

private:
    enum {
        kWhatLoad = 'load',
    };

    void onLoad(const sp<AMessage> &msg);

    sp<AMessage> mNotify;
    const char* mUrl;
    uint32_t mFlags;
    bool mUIDValid;
    uid_t mUID;
    sp<ALooper> mNetLooper;
    bool mCancelled;

    sp<HTTPBase> mHTTPDataSource;

    DISALLOW_EVIL_CONSTRUCTORS(SDPLoader);
};

}  // namespace android

#endif  // SDP_LOADER_H_
Loading