Beispiel #1
0
void RTSPSource::onTrackDataAvailable(size_t trackIndex)
{
    nsCString data;
    sp<ABuffer> accessUnit;
    TrackInfo *info = &mTracks.editItemAt(trackIndex);

    if (mState != PLAYING) {
        return;
    }

    status_t err = dequeueAccessUnit(info->mIsAudio, &accessUnit);

    if (err == -EWOULDBLOCK || err == ERROR_END_OF_STREAM) {
        return;
    } else if (err == INFO_DISCONTINUITY) {
        nsRefPtr<nsIStreamingProtocolMetaData> meta;

        meta = new mozilla::net::RtspMetaData();
        meta->SetFrameType(MEDIASTREAM_FRAMETYPE_DISCONTINUITY);

        data.AssignLiteral("DISCONTINUITY");
        if (mListener) {
            mListener->OnMediaDataAvailable(trackIndex, data, data.Length(), 0, meta.get());
        }
        LOGV("err trackIndex[%d]:INFO_DISCONTINUITY", trackIndex);
        return;
    }

    nsRefPtr<nsIStreamingProtocolMetaData> meta;
    int64_t int64Value;

    meta = new mozilla::net::RtspMetaData();

    MOZ_ASSERT(accessUnit != NULL);
    DebugOnly<bool> success = accessUnit->meta()->findInt64("timeUs", &int64Value);
    MOZ_ASSERT(success);
    meta->SetTimeStamp(int64Value);

    meta->SetFrameType(MEDIASTREAM_FRAMETYPE_NORMAL);
    data.Assign((const char *) accessUnit->data(), accessUnit->size());

    if (mListener) {
        mListener->OnMediaDataAvailable(trackIndex, data, data.Length(), 0, meta.get());
    }
}
status_t NuPlayer::DecoderPassThrough::fetchInputData(sp<AMessage> &reply) {
    sp<ABuffer> accessUnit;

    do {
        status_t err = dequeueAccessUnit(&accessUnit);

        if (err == -EWOULDBLOCK) {
            return err;
        } else if (err != OK) {
            if (err == INFO_DISCONTINUITY) {
                int32_t type;
                CHECK(accessUnit->meta()->findInt32("discontinuity", &type));

                bool formatChange =
                        (type & ATSParser::DISCONTINUITY_AUDIO_FORMAT) != 0;

                bool timeChange =
                        (type & ATSParser::DISCONTINUITY_TIME) != 0;

                ALOGI("audio discontinuity (formatChange=%d, time=%d)",
                        formatChange, timeChange);

                if (formatChange || timeChange) {
                    sp<AMessage> msg = mNotify->dup();
                    msg->setInt32("what", kWhatInputDiscontinuity);
                    // will perform seamless format change,
                    // only notify NuPlayer to scan sources
                    msg->setInt32("formatChange", false);
                    msg->post();
                }

                if (timeChange) {
                    doFlush(false /* notifyComplete */);
                    err = OK;
                } else if (formatChange) {
                    // do seamless format change
                    err = OK;
                } else {
                    // This stream is unaffected by the discontinuity
                    return -EWOULDBLOCK;
                }
            }

            reply->setInt32("err", err);
            return OK;
        }

        accessUnit = aggregateBuffer(accessUnit);
    } while (accessUnit == NULL);

#if 0
    int64_t mediaTimeUs;
    CHECK(accessUnit->meta()->findInt64("timeUs", &mediaTimeUs));
    ALOGV("feeding audio input buffer at media time %.2f secs",
         mediaTimeUs / 1E6);
#endif

    reply->setBuffer("buffer", accessUnit);

    return OK;
}