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

Commit 6ea551fa authored by Andreas Huber's avatar Andreas Huber
Browse files

Remove obsolete miracast sink code and friends.

Change-Id: I8bbb22fb0cfe2d73881d9f05bf8112ae86d8040b
related-to-bug: 11047222
parent f05e50eb
Loading
Loading
Loading
Loading
+0 −70
Original line number Diff line number Diff line
@@ -3,16 +3,9 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
        MediaReceiver.cpp               \
        MediaSender.cpp                 \
        Parameters.cpp                  \
        rtp/RTPAssembler.cpp            \
        rtp/RTPReceiver.cpp             \
        rtp/RTPSender.cpp               \
        sink/DirectRenderer.cpp         \
        sink/WifiDisplaySink.cpp        \
        SNTPClient.cpp                  \
        TimeSyncer.cpp                  \
        source/Converter.cpp            \
        source/MediaPuller.cpp          \
        source/PlaybackSession.cpp      \
@@ -63,66 +56,3 @@ LOCAL_SHARED_LIBRARIES:= \
LOCAL_MODULE:= wfd

include $(BUILD_EXECUTABLE)

################################################################################

include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
        udptest.cpp                 \

LOCAL_SHARED_LIBRARIES:= \
        libbinder                       \
        libgui                          \
        libmedia                        \
        libstagefright                  \
        libstagefright_foundation       \
        libstagefright_wfd              \
        libutils                        \
        liblog                          \

LOCAL_MODULE:= udptest

include $(BUILD_EXECUTABLE)

################################################################################

include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
        rtptest.cpp                 \

LOCAL_SHARED_LIBRARIES:= \
        libbinder                       \
        libgui                          \
        libmedia                        \
        libstagefright                  \
        libstagefright_foundation       \
        libstagefright_wfd              \
        libutils                        \
        liblog                          \

LOCAL_MODULE:= rtptest

include $(BUILD_EXECUTABLE)

################################################################################

include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
        nettest.cpp                     \

LOCAL_SHARED_LIBRARIES:= \
        libbinder                       \
        libgui                          \
        libmedia                        \
        libstagefright                  \
        libstagefright_foundation       \
        libstagefright_wfd              \
        libutils                        \
        liblog                          \

LOCAL_MODULE:= nettest

include $(BUILD_EXECUTABLE)
+0 −328
Original line number Diff line number Diff line
/*
 * Copyright 2013, 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 "MediaReceiver"
#include <utils/Log.h>

#include "MediaReceiver.h"

#include "AnotherPacketSource.h"
#include "rtp/RTPReceiver.h"

#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/ANetworkSession.h>
#include <media/stagefright/MetaData.h>
#include <media/stagefright/Utils.h>

namespace android {

MediaReceiver::MediaReceiver(
        const sp<ANetworkSession> &netSession,
        const sp<AMessage> &notify)
    : mNetSession(netSession),
      mNotify(notify),
      mMode(MODE_UNDEFINED),
      mGeneration(0),
      mInitStatus(OK),
      mInitDoneCount(0) {
}

MediaReceiver::~MediaReceiver() {
}

ssize_t MediaReceiver::addTrack(
        RTPReceiver::TransportMode rtpMode,
        RTPReceiver::TransportMode rtcpMode,
        int32_t *localRTPPort) {
    if (mMode != MODE_UNDEFINED) {
        return INVALID_OPERATION;
    }

    size_t trackIndex = mTrackInfos.size();

    TrackInfo info;

    sp<AMessage> notify = new AMessage(kWhatReceiverNotify, id());
    notify->setInt32("generation", mGeneration);
    notify->setSize("trackIndex", trackIndex);

    info.mReceiver = new RTPReceiver(mNetSession, notify);
    looper()->registerHandler(info.mReceiver);

    info.mReceiver->registerPacketType(
            33, RTPReceiver::PACKETIZATION_TRANSPORT_STREAM);

    info.mReceiver->registerPacketType(
            96, RTPReceiver::PACKETIZATION_AAC);

    info.mReceiver->registerPacketType(
            97, RTPReceiver::PACKETIZATION_H264);

    status_t err = info.mReceiver->initAsync(
            rtpMode,
            rtcpMode,
            localRTPPort);

    if (err != OK) {
        looper()->unregisterHandler(info.mReceiver->id());
        info.mReceiver.clear();

        return err;
    }

    mTrackInfos.push_back(info);

    return trackIndex;
}

status_t MediaReceiver::connectTrack(
        size_t trackIndex,
        const char *remoteHost,
        int32_t remoteRTPPort,
        int32_t remoteRTCPPort) {
    if (trackIndex >= mTrackInfos.size()) {
        return -ERANGE;
    }

    TrackInfo *info = &mTrackInfos.editItemAt(trackIndex);
    return info->mReceiver->connect(remoteHost, remoteRTPPort, remoteRTCPPort);
}

status_t MediaReceiver::initAsync(Mode mode) {
    if ((mode == MODE_TRANSPORT_STREAM || mode == MODE_TRANSPORT_STREAM_RAW)
            && mTrackInfos.size() > 1) {
        return INVALID_OPERATION;
    }

    sp<AMessage> msg = new AMessage(kWhatInit, id());
    msg->setInt32("mode", mode);
    msg->post();

    return OK;
}

void MediaReceiver::onMessageReceived(const sp<AMessage> &msg) {
    switch (msg->what()) {
        case kWhatInit:
        {
            int32_t mode;
            CHECK(msg->findInt32("mode", &mode));

            CHECK_EQ(mMode, MODE_UNDEFINED);
            mMode = (Mode)mode;

            if (mInitStatus != OK || mInitDoneCount == mTrackInfos.size()) {
                notifyInitDone(mInitStatus);
            }

            mTSParser = new ATSParser(
                    ATSParser::ALIGNED_VIDEO_DATA
                        | ATSParser::TS_TIMESTAMPS_ARE_ABSOLUTE);

            mFormatKnownMask = 0;
            break;
        }

        case kWhatReceiverNotify:
        {
            int32_t generation;
            CHECK(msg->findInt32("generation", &generation));
            if (generation != mGeneration) {
                break;
            }

            onReceiverNotify(msg);
            break;
        }

        default:
            TRESPASS();
    }
}

void MediaReceiver::onReceiverNotify(const sp<AMessage> &msg) {
    int32_t what;
    CHECK(msg->findInt32("what", &what));

    switch (what) {
        case RTPReceiver::kWhatInitDone:
        {
            ++mInitDoneCount;

            int32_t err;
            CHECK(msg->findInt32("err", &err));

            if (err != OK) {
                mInitStatus = err;
                ++mGeneration;
            }

            if (mMode != MODE_UNDEFINED) {
                if (mInitStatus != OK || mInitDoneCount == mTrackInfos.size()) {
                    notifyInitDone(mInitStatus);
                }
            }
            break;
        }

        case RTPReceiver::kWhatError:
        {
            int32_t err;
            CHECK(msg->findInt32("err", &err));

            notifyError(err);
            break;
        }

        case RTPReceiver::kWhatAccessUnit:
        {
            size_t trackIndex;
            CHECK(msg->findSize("trackIndex", &trackIndex));

            sp<ABuffer> accessUnit;
            CHECK(msg->findBuffer("accessUnit", &accessUnit));

            int32_t followsDiscontinuity;
            if (!msg->findInt32(
                        "followsDiscontinuity", &followsDiscontinuity)) {
                followsDiscontinuity = 0;
            }

            if (mMode == MODE_TRANSPORT_STREAM) {
                if (followsDiscontinuity) {
                    mTSParser->signalDiscontinuity(
                            ATSParser::DISCONTINUITY_TIME, NULL /* extra */);
                }

                for (size_t offset = 0;
                        offset < accessUnit->size(); offset += 188) {
                    status_t err = mTSParser->feedTSPacket(
                             accessUnit->data() + offset, 188);

                    if (err != OK) {
                        notifyError(err);
                        break;
                    }
                }

                drainPackets(0 /* trackIndex */, ATSParser::VIDEO);
                drainPackets(1 /* trackIndex */, ATSParser::AUDIO);
            } else {
                postAccessUnit(trackIndex, accessUnit, NULL);
            }
            break;
        }

        case RTPReceiver::kWhatPacketLost:
        {
            notifyPacketLost();
            break;
        }

        default:
            TRESPASS();
    }
}

void MediaReceiver::drainPackets(
        size_t trackIndex, ATSParser::SourceType type) {
    sp<AnotherPacketSource> source =
        static_cast<AnotherPacketSource *>(
                mTSParser->getSource(type).get());

    if (source == NULL) {
        return;
    }

    sp<AMessage> format;
    if (!(mFormatKnownMask & (1ul << trackIndex))) {
        sp<MetaData> meta = source->getFormat();
        CHECK(meta != NULL);

        CHECK_EQ((status_t)OK, convertMetaDataToMessage(meta, &format));

        mFormatKnownMask |= 1ul << trackIndex;
    }

    status_t finalResult;
    while (source->hasBufferAvailable(&finalResult)) {
        sp<ABuffer> accessUnit;
        status_t err = source->dequeueAccessUnit(&accessUnit);
        if (err == OK) {
            postAccessUnit(trackIndex, accessUnit, format);
            format.clear();
        } else if (err != INFO_DISCONTINUITY) {
            notifyError(err);
        }
    }

    if (finalResult != OK) {
        notifyError(finalResult);
    }
}

void MediaReceiver::notifyInitDone(status_t err) {
    sp<AMessage> notify = mNotify->dup();
    notify->setInt32("what", kWhatInitDone);
    notify->setInt32("err", err);
    notify->post();
}

void MediaReceiver::notifyError(status_t err) {
    sp<AMessage> notify = mNotify->dup();
    notify->setInt32("what", kWhatError);
    notify->setInt32("err", err);
    notify->post();
}

void MediaReceiver::notifyPacketLost() {
    sp<AMessage> notify = mNotify->dup();
    notify->setInt32("what", kWhatPacketLost);
    notify->post();
}

void MediaReceiver::postAccessUnit(
        size_t trackIndex,
        const sp<ABuffer> &accessUnit,
        const sp<AMessage> &format) {
    sp<AMessage> notify = mNotify->dup();
    notify->setInt32("what", kWhatAccessUnit);
    notify->setSize("trackIndex", trackIndex);
    notify->setBuffer("accessUnit", accessUnit);

    if (format != NULL) {
        notify->setMessage("format", format);
    }

    notify->post();
}

status_t MediaReceiver::informSender(
        size_t trackIndex, const sp<AMessage> &params) {
    if (trackIndex >= mTrackInfos.size()) {
        return -ERANGE;
    }

    TrackInfo *info = &mTrackInfos.editItemAt(trackIndex);
    return info->mReceiver->informSender(params);
}

}  // namespace android

+0 −111
Original line number Diff line number Diff line
/*
 * Copyright 2013, 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.
 */

#include <media/stagefright/foundation/AHandler.h>

#include "ATSParser.h"
#include "rtp/RTPReceiver.h"

namespace android {

struct ABuffer;
struct ANetworkSession;
struct AMessage;
struct ATSParser;

// This class facilitates receiving of media data for one or more tracks
// over RTP. Either a 1:1 track to RTP channel mapping is used or a single
// RTP channel provides the data for a transport stream that is consequently
// demuxed and its track's data provided to the observer.
struct MediaReceiver : public AHandler {
    enum {
        kWhatInitDone,
        kWhatError,
        kWhatAccessUnit,
        kWhatPacketLost,
    };

    MediaReceiver(
            const sp<ANetworkSession> &netSession,
            const sp<AMessage> &notify);

    ssize_t addTrack(
            RTPReceiver::TransportMode rtpMode,
            RTPReceiver::TransportMode rtcpMode,
            int32_t *localRTPPort);

    status_t connectTrack(
            size_t trackIndex,
            const char *remoteHost,
            int32_t remoteRTPPort,
            int32_t remoteRTCPPort);

    enum Mode {
        MODE_UNDEFINED,
        MODE_TRANSPORT_STREAM,
        MODE_TRANSPORT_STREAM_RAW,
        MODE_ELEMENTARY_STREAMS,
    };
    status_t initAsync(Mode mode);

    status_t informSender(size_t trackIndex, const sp<AMessage> &params);

protected:
    virtual void onMessageReceived(const sp<AMessage> &msg);
    virtual ~MediaReceiver();

private:
    enum {
        kWhatInit,
        kWhatReceiverNotify,
    };

    struct TrackInfo {
        sp<RTPReceiver> mReceiver;
    };

    sp<ANetworkSession> mNetSession;
    sp<AMessage> mNotify;

    Mode mMode;
    int32_t mGeneration;

    Vector<TrackInfo> mTrackInfos;

    status_t mInitStatus;
    size_t mInitDoneCount;

    sp<ATSParser> mTSParser;
    uint32_t mFormatKnownMask;

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

    void drainPackets(size_t trackIndex, ATSParser::SourceType type);

    void notifyInitDone(status_t err);
    void notifyError(status_t err);
    void notifyPacketLost();

    void postAccessUnit(
            size_t trackIndex,
            const sp<ABuffer> &accessUnit,
            const sp<AMessage> &format);

    DISALLOW_EVIL_CONSTRUCTORS(MediaReceiver);
};

}  // namespace android
+0 −174
Original line number Diff line number Diff line
/*
 * Copyright 2013, 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.
 */

#include "SNTPClient.h"

#include <media/stagefright/foundation/ALooper.h>
#include <media/stagefright/Utils.h>

#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>

namespace android {

SNTPClient::SNTPClient() {
}

status_t SNTPClient::requestTime(const char *host) {
    struct hostent *ent;
    int64_t requestTimeNTP, requestTimeUs;
    ssize_t n;
    int64_t responseTimeUs, responseTimeNTP;
    int64_t originateTimeNTP, receiveTimeNTP, transmitTimeNTP;
    int64_t roundTripTimeNTP, clockOffsetNTP;

    status_t err = UNKNOWN_ERROR;

    int s = socket(AF_INET, SOCK_DGRAM, 0);

    if (s < 0) {
        err = -errno;

        goto bail;
    }

    ent = gethostbyname(host);

    if (ent == NULL) {
        err = -ENOENT;
        goto bail2;
    }

    struct sockaddr_in hostAddr;
    memset(hostAddr.sin_zero, 0, sizeof(hostAddr.sin_zero));
    hostAddr.sin_family = AF_INET;
    hostAddr.sin_port = htons(kNTPPort);
    hostAddr.sin_addr.s_addr = *(in_addr_t *)ent->h_addr;

    uint8_t packet[kNTPPacketSize];
    memset(packet, 0, sizeof(packet));

    packet[0] = kNTPModeClient | (kNTPVersion << 3);

    requestTimeNTP = getNowNTP();
    requestTimeUs = ALooper::GetNowUs();
    writeTimeStamp(&packet[kNTPTransmitTimeOffset], requestTimeNTP);

    n = sendto(
            s, packet, sizeof(packet), 0,
            (const struct sockaddr *)&hostAddr, sizeof(hostAddr));

    if (n < 0) {
        err = -errno;
        goto bail2;
    }

    memset(packet, 0, sizeof(packet));

    do {
        n = recv(s, packet, sizeof(packet), 0);
    } while (n < 0 && errno == EINTR);

    if (n < 0) {
        err = -errno;
        goto bail2;
    }

    responseTimeUs = ALooper::GetNowUs();

    responseTimeNTP = requestTimeNTP + makeNTP(responseTimeUs - requestTimeUs);

    originateTimeNTP = readTimeStamp(&packet[kNTPOriginateTimeOffset]);
    receiveTimeNTP = readTimeStamp(&packet[kNTPReceiveTimeOffset]);
    transmitTimeNTP = readTimeStamp(&packet[kNTPTransmitTimeOffset]);

    roundTripTimeNTP =
        makeNTP(responseTimeUs - requestTimeUs)
            - (transmitTimeNTP - receiveTimeNTP);

    clockOffsetNTP =
        ((receiveTimeNTP - originateTimeNTP)
            + (transmitTimeNTP - responseTimeNTP)) / 2;

    mTimeReferenceNTP = responseTimeNTP + clockOffsetNTP;
    mTimeReferenceUs = responseTimeUs;
    mRoundTripTimeNTP = roundTripTimeNTP;

    err = OK;

bail2:
    close(s);
    s = -1;

bail:
    return err;
}

int64_t SNTPClient::adjustTimeUs(int64_t timeUs) const {
    uint64_t nowNTP =
        mTimeReferenceNTP + makeNTP(timeUs - mTimeReferenceUs);

    int64_t nowUs =
        (nowNTP >> 32) * 1000000ll
        + ((nowNTP & 0xffffffff) * 1000000ll) / (1ll << 32);

    nowUs -= ((70ll * 365 + 17) * 24) * 60 * 60 * 1000000ll;

    return nowUs;
}

// static
void SNTPClient::writeTimeStamp(uint8_t *dst, uint64_t ntpTime) {
    *dst++ = (ntpTime >> 56) & 0xff;
    *dst++ = (ntpTime >> 48) & 0xff;
    *dst++ = (ntpTime >> 40) & 0xff;
    *dst++ = (ntpTime >> 32) & 0xff;
    *dst++ = (ntpTime >> 24) & 0xff;
    *dst++ = (ntpTime >> 16) & 0xff;
    *dst++ = (ntpTime >> 8) & 0xff;
    *dst++ = ntpTime & 0xff;
}

// static
uint64_t SNTPClient::readTimeStamp(const uint8_t *dst) {
    return U64_AT(dst);
}

// static
uint64_t SNTPClient::getNowNTP() {
    struct timeval tv;
    gettimeofday(&tv, NULL /* time zone */);

    uint64_t nowUs = tv.tv_sec * 1000000ll + tv.tv_usec;

    nowUs += ((70ll * 365 + 17) * 24) * 60 * 60 * 1000000ll;

    return makeNTP(nowUs);
}

// static
uint64_t SNTPClient::makeNTP(uint64_t deltaUs) {
    uint64_t hi = deltaUs / 1000000ll;
    uint64_t lo = ((1ll << 32) * (deltaUs % 1000000ll)) / 1000000ll;

    return (hi << 32) | lo;
}

}  // namespace android
+0 −62
Original line number Diff line number Diff line
/*
 * Copyright 2013, 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 SNTP_CLIENT_H_

#define SNTP_CLIENT_H_

#include <media/stagefright/foundation/ABase.h>
#include <utils/Errors.h>

namespace android {

// Implementation of the SNTP (Simple Network Time Protocol)
struct SNTPClient {
    SNTPClient();

    status_t requestTime(const char *host);

    // given a time obtained from ALooper::GetNowUs()
    // return the number of us elapsed since Jan 1 1970 00:00:00 (UTC).
    int64_t adjustTimeUs(int64_t timeUs) const;

private:
    enum {
        kNTPPort = 123,
        kNTPPacketSize = 48,
        kNTPModeClient = 3,
        kNTPVersion = 3,
        kNTPTransmitTimeOffset = 40,
        kNTPOriginateTimeOffset = 24,
        kNTPReceiveTimeOffset = 32,
    };

    uint64_t mTimeReferenceNTP;
    int64_t mTimeReferenceUs;
    int64_t mRoundTripTimeNTP;

    static void writeTimeStamp(uint8_t *dst, uint64_t ntpTime);
    static uint64_t readTimeStamp(const uint8_t *dst);

    static uint64_t getNowNTP();
    static uint64_t makeNTP(uint64_t deltaUs);

    DISALLOW_EVIL_CONSTRUCTORS(SNTPClient);
};

}  // namespace android

#endif  // SNTP_CLIENT_H_
Loading