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

Commit 0224bf17 authored by Andreas Huber's avatar Andreas Huber
Browse files

Various improvements of wifi display code

- manually prepend SPS/PPS if encoder doesn't support it
- latency improvements
- support for "our" method of optional RTP retransmission
- improvements to the wfd commandline tool for testing
- make it easier to turn on/off suspension of the video pipeline on idle
- fixes an issue where an error during encryption would cause a SEGV
- add HDCP descriptor if necessary

Squashed commit of the following:

commit 1115be0ebb3b885b4f1b7dba56761ca013d0ec4a
Author: Andreas Huber <andih@google.com>
Date:   Fri Nov 9 11:32:23 2012 -0800

    Better shutdown of wfd -l sessions.

    Change-Id: Id898a14ae21efd3b065b00a729830063d39195a7

commit 0e7d106dfe4eb6e2640b0b66c65deaba265f7ff0
Author: Andreas Huber <andih@google.com>
Date:   Thu Nov 8 16:38:55 2012 -0800

    No more sending delay, create rtp packets upfront.

    Change-Id: I809a225f664fdb485c7d9a49a27886601a6a26b2

commit d399e8571b77353d59afb57508dfd2a82c1ef93a
Author: Andreas Huber <andih@google.com>
Date:   Thu Nov 8 14:19:43 2012 -0800

    Restore AudioSource buffer size, factor out TimeSeries, make

    suspending video optional.

    Change-Id: Ifdfe4d447b901e714abf52856b4641d1d55a5d41

commit f8b649f0b8f917d59f4b8a2e8e6d7db61a684a78
Author: Andreas Huber <andih@google.com>
Date:   Thu Nov 8 09:34:06 2012 -0800

    Pull 480 frames at a time from AudioSource/AudioRecord

    Change-Id: I1e215abd329faec3da026631122c0f4c800c0ac4

commit 1bc13452eb35eebbba00f5da93fa86535be5db59
Author: Andreas Huber <andih@google.com>
Date:   Thu Nov 8 08:50:30 2012 -0800

    fixed bitrate traffic simulation

    Change-Id: Ic5efb7cbb0b5d3b4917bc77b8ba73d447249e695

commit 016cdff18e74bdc631a5679e97192645ed095aa2
Author: Andreas Huber <andih@google.com>
Date:   Wed Nov 7 14:00:03 2012 -0800

    resurrected "our" style of retransmission.

    Change-Id: I34d757aba67428437cb39b8293a9651750ad20d9

commit 384cf1a3c8fb4ec410bdf8fa5722c298e6028f3e
Author: Andreas Huber <andih@google.com>
Date:   Tue Nov 6 09:38:55 2012 -0800

    Changes to make wfd work on manta.

    Change-Id: I7a4e00cf16581fe2146edd1b359af195774090e4

commit 9628f24b22b35f28630d99dda3614babf51bc07e
Author: Andreas Huber <andih@google.com>
Date:   Wed Nov 7 09:15:44 2012 -0800

    Patch up rtp timestamps to more accurately measure network jitter.

    Change-Id: I9502a4615575f97f98a215a13131a89a6ae93c6d

commit 7c891a1a24f08bbd50f55be13f7d05f43e807eb8
Author: Andreas Huber <andih@google.com>
Date:   Tue Nov 6 09:37:24 2012 -0800

    Additions to the "wfd" tool to create a local wfd source.

    Change-Id: I99558653a70fdc703f9d13990b3ce1c4d3ae227a

Change-Id: Ia94c63fc390f597014531073485f0cfc53b3418a
parent 78b012f5
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -407,6 +407,24 @@ status_t ANetworkSession::Session::writeMore() {
        do {
            const sp<ABuffer> &datagram = *mOutDatagrams.begin();

            uint8_t *data = datagram->data();
            if (data[0] == 0x80 && (data[1] & 0x7f) == 33) {
                int64_t nowUs = ALooper::GetNowUs();

                uint32_t prevRtpTime = U32_AT(&data[4]);

                // 90kHz time scale
                uint32_t rtpTime = (nowUs * 9ll) / 100ll;
                int32_t diffTime = (int32_t)rtpTime - (int32_t)prevRtpTime;

                ALOGV("correcting rtpTime by %.0f ms", diffTime / 90.0);

                data[4] = rtpTime >> 24;
                data[5] = (rtpTime >> 16) & 0xff;
                data[6] = (rtpTime >> 8) & 0xff;
                data[7] = rtpTime & 0xff;
            }

            int n;
            do {
                n = send(mSocket, datagram->data(), datagram->size(), 0);
@@ -424,6 +442,9 @@ status_t ANetworkSession::Session::writeMore() {
        } while (err == OK && !mOutDatagrams.empty());

        if (err == -EAGAIN) {
            if (!mOutDatagrams.empty()) {
                ALOGI("%d datagrams remain queued.", mOutDatagrams.size());
            }
            err = OK;
        }

+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ LOCAL_SRC_FILES:= \
        source/Sender.cpp               \
        source/TSPacketizer.cpp         \
        source/WifiDisplaySource.cpp    \
        TimeSeries.cpp                  \

LOCAL_C_INCLUDES:= \
        $(TOP)/frameworks/av/media/libstagefright \
+67 −0
Original line number Diff line number Diff line
/*
 * Copyright 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.
 */

#include "TimeSeries.h"

#include <math.h>
#include <string.h>

namespace android {

TimeSeries::TimeSeries()
    : mCount(0),
      mSum(0.0) {
}

void TimeSeries::add(double val) {
    if (mCount < kHistorySize) {
        mValues[mCount++] = val;
        mSum += val;
    } else {
        mSum -= mValues[0];
        memmove(&mValues[0], &mValues[1], (kHistorySize - 1) * sizeof(double));
        mValues[kHistorySize - 1] = val;
        mSum += val;
    }
}

double TimeSeries::mean() const {
    if (mCount < 1) {
        return 0.0;
    }

    return mSum / mCount;
}

double TimeSeries::sdev() const {
    if (mCount < 1) {
        return 0.0;
    }

    double m = mean();

    double sum = 0.0;
    for (size_t i = 0; i < mCount; ++i) {
        double tmp = mValues[i] - m;
        tmp *= tmp;

        sum += tmp;
    }

    return sqrt(sum / mCount);
}

}  // namespace android
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright 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 TIME_SERIES_H_

#define TIME_SERIES_H_

#include <sys/types.h>

namespace android {

struct TimeSeries {
    TimeSeries();

    void add(double val);

    double mean() const;
    double sdev() const;

private:
    enum {
        kHistorySize = 20
    };
    double mValues[kHistorySize];

    size_t mCount;
    double mSum;
};

}  // namespace android

#endif  // TIME_SERIES_H_
+40 −6
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ Converter::Converter(
      mInputFormat(format),
      mIsVideo(false),
      mIsPCMAudio(usePCMAudio),
      mNeedToManuallyPrependSPSPPS(false),
      mDoMoreWorkPending(false)
#if ENABLE_SILENCE_DETECTION
      ,mFirstSilentFrameUs(-1ll)
@@ -94,6 +95,10 @@ sp<AMessage> Converter::getOutputFormat() const {
    return mOutputFormat;
}

bool Converter::needToManuallyPrependSPSPPS() const {
    return mNeedToManuallyPrependSPSPPS;
}

static int32_t getBitrate(const char *propName, int32_t defaultValue) {
    char val[PROPERTY_VALUE_MAX];
    if (property_get(propName, val, NULL)) {
@@ -157,16 +162,45 @@ status_t Converter::initEncoder() {
        mOutputFormat->setInt32("bitrate-mode", OMX_Video_ControlRateConstant);
        mOutputFormat->setInt32("frame-rate", 30);
        mOutputFormat->setInt32("i-frame-interval", 1);  // Iframes every 1 secs
        mOutputFormat->setInt32("prepend-sps-pps-to-idr-frames", 1);
    }

    ALOGV("output format is '%s'", mOutputFormat->debugString(0).c_str());

    status_t err = mEncoder->configure(
    mNeedToManuallyPrependSPSPPS = false;

    status_t err = NO_INIT;

    if (!isAudio) {
        sp<AMessage> tmp = mOutputFormat->dup();
        tmp->setInt32("prepend-sps-pps-to-idr-frames", 1);

        err = mEncoder->configure(
                tmp,
                NULL /* nativeWindow */,
                NULL /* crypto */,
                MediaCodec::CONFIGURE_FLAG_ENCODE);

        if (err == OK) {
            // Encoder supported prepending SPS/PPS, we don't need to emulate
            // it.
            mOutputFormat = tmp;
        } else {
            mNeedToManuallyPrependSPSPPS = true;

            ALOGI("We going to manually prepend SPS and PPS to IDR frames.");
        }
    }

    if (err != OK) {
        // We'll get here for audio or if we failed to configure the encoder
        // to automatically prepend SPS/PPS in the case of video.

        err = mEncoder->configure(
                    mOutputFormat,
                    NULL /* nativeWindow */,
                    NULL /* crypto */,
                    MediaCodec::CONFIGURE_FLAG_ENCODE);
    }

    if (err != OK) {
        return err;
Loading