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

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

Merge "GenericSource: fix sending time for text data"

parents 7374d018 992c5598
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#include <media/stagefright/DataSource.h>
#include <media/stagefright/FileSource.h>
#include <media/stagefright/MediaBuffer.h>
#include <media/stagefright/MediaClock.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaExtractor.h>
#include <media/stagefright/MediaSource.h>
@@ -51,7 +52,8 @@ static const int kHighWaterMarkKB = 200;
NuPlayer::GenericSource::GenericSource(
        const sp<AMessage> &notify,
        bool uidValid,
        uid_t uid)
        uid_t uid,
        const sp<MediaClock> &mediaClock)
    : Source(notify),
      mAudioTimeUs(0),
      mAudioLastDequeueTimeUs(0),
@@ -65,10 +67,12 @@ NuPlayer::GenericSource::GenericSource(
      mIsStreaming(false),
      mUIDValid(uidValid),
      mUID(uid),
      mMediaClock(mediaClock),
      mFd(-1),
      mBitrate(-1ll),
      mPendingReadBufferTypes(0) {
    ALOGV("GenericSource");
    CHECK(mediaClock != NULL);

    mBufferingMonitor = new BufferingMonitor(notify);
    resetDataSource();
@@ -729,17 +733,20 @@ void NuPlayer::GenericSource::fetchTextData(
    int64_t timeUs;
    CHECK(msg->findInt64("timeUs", &timeUs));

    int64_t subTimeUs;
    int64_t subTimeUs = 0;
    readBuffer(type, timeUs, MediaPlayerSeekMode::SEEK_PREVIOUS_SYNC /* mode */, &subTimeUs);

    int64_t delayUs = subTimeUs - timeUs;
    status_t eosResult;
    if (!packets->hasBufferAvailable(&eosResult)) {
        return;
    }

    if (msg->what() == kWhatFetchSubtitleData) {
        const int64_t oneSecUs = 1000000ll;
        delayUs -= oneSecUs;
        subTimeUs -= 1000000ll;  // send subtile data one second earlier
    }
    sp<AMessage> msg2 = new AMessage(sendWhat, this);
    msg2->setInt32("generation", msgGeneration);
    msg2->post(delayUs < 0 ? 0 : delayUs);
    mMediaClock->addTimer(msg2, subTimeUs);
}

void NuPlayer::GenericSource::sendTextData(
@@ -771,8 +778,10 @@ void NuPlayer::GenericSource::sendTextData(
        notify->setBuffer("buffer", buffer);
        notify->post();

        const int64_t delayUs = nextSubTimeUs - subTimeUs;
        msg->post(delayUs < 0 ? 0 : delayUs);
        if (msg->what() == kWhatSendSubtitleData) {
            nextSubTimeUs -= 1000000ll;  // send subtile data one second earlier
        }
        mMediaClock->addTimer(msg, nextSubTimeUs);
    }
}

+4 −1
Original line number Diff line number Diff line
@@ -35,12 +35,14 @@ class IDataSource;
struct IMediaHTTPService;
struct MediaSource;
class MediaBuffer;
struct MediaClock;
struct NuCachedSource2;

struct NuPlayer::GenericSource : public NuPlayer::Source,
                                 public MediaBufferObserver // Modular DRM
{
    GenericSource(const sp<AMessage> &notify, bool uidValid, uid_t uid);
    GenericSource(const sp<AMessage> &notify, bool uidValid, uid_t uid,
                  const sp<MediaClock> &mediaClock);

    status_t setDataSource(
            const sp<IMediaHTTPService> &httpService,
@@ -227,6 +229,7 @@ private:
    bool mIsStreaming;
    bool mUIDValid;
    uid_t mUID;
    const sp<MediaClock> mMediaClock;
    sp<IMediaHTTPService> mHTTPService;
    AString mUri;
    KeyedVector<String8, String8> mUriHeaders;
+3 −3
Original line number Diff line number Diff line
@@ -281,7 +281,7 @@ void NuPlayer::setDataSourceAsync(
        ALOGV("setDataSourceAsync GenericSource %s", url);

        sp<GenericSource> genericSource =
                new GenericSource(notify, mUIDValid, mUID);
                new GenericSource(notify, mUIDValid, mUID, mMediaClock);

        status_t err = genericSource->setDataSource(httpService, url, headers);

@@ -304,7 +304,7 @@ void NuPlayer::setDataSourceAsync(int fd, int64_t offset, int64_t length) {
    sp<AMessage> notify = new AMessage(kWhatSourceNotify, this);

    sp<GenericSource> source =
            new GenericSource(notify, mUIDValid, mUID);
            new GenericSource(notify, mUIDValid, mUID, mMediaClock);

    ALOGV("setDataSourceAsync fd %d/%lld/%lld source: %p",
            fd, (long long)offset, (long long)length, source.get());
@@ -325,7 +325,7 @@ void NuPlayer::setDataSourceAsync(const sp<DataSource> &dataSource) {
    sp<AMessage> msg = new AMessage(kWhatSetDataSource, this);
    sp<AMessage> notify = new AMessage(kWhatSourceNotify, this);

    sp<GenericSource> source = new GenericSource(notify, mUIDValid, mUID);
    sp<GenericSource> source = new GenericSource(notify, mUIDValid, mUID, mMediaClock);
    status_t err = source->setDataSource(dataSource);

    if (err != OK) {