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

Commit 1f797c43 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 8909196 from 8c4e619c to tm-qpr1-release

Change-Id: I58a6b5d137701aef807d82c9b1dee049f5ea28d1
parents d134a68a 8c4e619c
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -191,8 +191,8 @@ NuPlayerDrm::CryptoInfo *NuPlayerDrm::makeCryptoInfo(
        uint8_t key[kBlockSize],
        uint8_t iv[kBlockSize],
        CryptoPlugin::Mode mode,
        size_t *clearbytes,
        size_t *encryptedbytes)
        uint32_t *clearbytes,
        uint32_t *encryptedbytes)
{
    // size needed to store all the crypto data
    size_t cryptosize;
@@ -236,7 +236,7 @@ NuPlayerDrm::CryptoInfo *NuPlayerDrm::getSampleCryptoInfo(MetaDataBase &meta)
    if (!meta.findData(kKeyEncryptedSizes, &type, &crypteddata, &cryptedsize)) {
        return NULL;
    }
    size_t numSubSamples = cryptedsize / sizeof(size_t);
    size_t numSubSamples = cryptedsize / sizeof(uint32_t);

    if (numSubSamples <= 0) {
        ALOGE("getSampleCryptoInfo INVALID numSubSamples: %zu", numSubSamples);
@@ -285,8 +285,8 @@ NuPlayerDrm::CryptoInfo *NuPlayerDrm::getSampleCryptoInfo(MetaDataBase &meta)
            (uint8_t*) key,
            (uint8_t*) iv,
            (CryptoPlugin::Mode)mode,
            (size_t*) cleardata,
            (size_t*) crypteddata);
            (uint32_t*) cleardata,
            (uint32_t*) crypteddata);
}

}   // namespace android
+2 −2
Original line number Diff line number Diff line
@@ -106,8 +106,8 @@ namespace android {
                uint8_t key[kBlockSize],
                uint8_t iv[kBlockSize],
                CryptoPlugin::Mode mode,
                size_t *clearbytes,
                size_t *encryptedbytes);
                uint32_t *clearbytes,
                uint32_t *encryptedbytes);

        static CryptoInfo *getSampleCryptoInfo(MetaDataBase &meta);

+52 −19
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
 * limitations under the License.
 */

#include <charconv>
#include <inttypes.h>
#include <mutex>
#include <set>
@@ -324,29 +325,61 @@ void CodecHandler::onMessageReceived(const sp<AMessage> &msg) {
            }

            AMessage::Type type;
            int64_t mediaTimeUs, systemNano;
            size_t index = 0;

            // TODO. This code has dependency with MediaCodec::CreateFramesRenderedMessage.
            for (size_t ix = 0; ix < data->countEntries(); ix++) {
                AString name = data->getEntryNameAt(ix, &type);
                if (name.startsWith(AStringPrintf("%zu-media-time-us", index).c_str())) {
                    AMessage::ItemData data = msg->getEntryAt(index);
                    data.find(&mediaTimeUs);
                } else if (name.startsWith(AStringPrintf("%zu-system-nano", index).c_str())) {
                    AMessage::ItemData data = msg->getEntryAt(index);
                    data.find(&systemNano);
            size_t n = data->countEntries();

            thread_local std::vector<std::optional<int64_t>> mediaTimesInUs;
            thread_local std::vector<std::optional<int64_t>> systemTimesInNs;
            mediaTimesInUs.resize(n);
            systemTimesInNs.resize(n);
            std::fill_n(mediaTimesInUs.begin(), n, std::nullopt);
            std::fill_n(systemTimesInNs.begin(), n, std::nullopt);
            for (size_t i = 0; i < n; i++) {
                AString name = data->getEntryNameAt(i, &type);
                if (name.endsWith("-media-time-us")) {
                    int64_t mediaTimeUs;
                    AMessage::ItemData itemData = data->getEntryAt(i);
                    itemData.find(&mediaTimeUs);

                    int index = -1;
                    std::from_chars_result result = std::from_chars(
                            name.c_str(), name.c_str() + name.find("-"), index);
                    if (result.ec == std::errc() && 0 <= index && index < n) {
                        mediaTimesInUs[index] = mediaTimeUs;
                    } else {
                        std::error_code ec = std::make_error_code(result.ec);
                        ALOGE("Unexpected media time index: #%d with value %lldus (err=%d %s)",
                              index, (long long)mediaTimeUs, ec.value(), ec.message().c_str());
                    }
                } else if (name.endsWith("-system-nano")) {
                    int64_t systemNano;
                    AMessage::ItemData itemData = data->getEntryAt(i);
                    itemData.find(&systemNano);

                    int index = -1;
                    std::from_chars_result result = std::from_chars(
                            name.c_str(), name.c_str() + name.find("-"), index);
                    if (result.ec == std::errc() && 0 <= index && index < n) {
                        systemTimesInNs[index] = systemNano;
                    } else {
                        std::error_code ec = std::make_error_code(result.ec);
                        ALOGE("Unexpected system time index: #%d with value %lldns (err=%d %s)",
                              index, (long long)systemNano, ec.value(), ec.message().c_str());
                    }
                }
            }

            Mutex::Autolock _l(mCodec->mFrameRenderedCallbackLock);
            if (mCodec->mFrameRenderedCallback != NULL) {
                for (size_t i = 0; i < n; ++i) {
                    if (mediaTimesInUs[i] && systemTimesInNs[i]) {
                        mCodec->mFrameRenderedCallback(
                                mCodec,
                                mCodec->mFrameRenderedCallbackUserData,
                                mediaTimeUs,
                                systemNano);
                                mediaTimesInUs[i].value(),
                                systemTimesInNs[i].value());
                    } else {
                        break;
                    }

                    index++;
                }
            }
            break;
+2 −1
Original line number Diff line number Diff line
@@ -1172,7 +1172,7 @@ protected:
    volatile int32_t                mSuspended;

    int64_t                         mBytesWritten;
    int64_t                         mFramesWritten; // not reset on standby
    std::atomic<int64_t>            mFramesWritten; // not reset on standby
    int64_t                         mLastFramesWritten = -1; // track changes in timestamp
                                                             // server frames written.
    int64_t                         mSuspendedFrames; // not reset on standby
@@ -1386,6 +1386,7 @@ public:
    virtual     bool        hasFastMixer() const = 0;
    virtual     FastTrackUnderruns getFastTrackUnderruns(size_t fastIndex __unused) const
                                { FastTrackUnderruns dummy; return dummy; }
                const std::atomic<int64_t>& framesWritten() const { return mFramesWritten; }

protected:
                // accessed by both binder threads and within threadLoop(), lock on mutex needed
+13 −3
Original line number Diff line number Diff line
@@ -1094,12 +1094,22 @@ status_t AudioFlinger::PlaybackThread::Track::start(AudioSystem::sync_event_t ev
                    __func__, mId, (int)mThreadIoHandle);
        }

        // states to reset position info for non-offloaded/direct tracks
        if (!isOffloaded() && !isDirect()
        PlaybackThread *playbackThread = (PlaybackThread *)thread.get();

        // states to reset position info for pcm tracks
        if (audio_is_linear_pcm(mFormat)
                && (state == IDLE || state == STOPPED || state == FLUSHED)) {
            mFrameMap.reset();

            if (!isFastTrack() && (isDirect() || isOffloaded())) {
                // Start point of track -> sink frame map. If the HAL returns a
                // frame position smaller than the first written frame in
                // updateTrackFrameInfo, the timestamp can be interpolated
                // instead of using a larger value.
                mFrameMap.push(mAudioTrackServerProxy->framesReleased(),
                               playbackThread->framesWritten());
            }
        }
        PlaybackThread *playbackThread = (PlaybackThread *)thread.get();
        if (isFastTrack()) {
            // refresh fast track underruns on start because that field is never cleared
            // by the fast mixer; furthermore, the same track can be recycled, i.e. start