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

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

Merge "BufferingSettings: define internal BufferingSettings API."

parents e0255950 d399e7e6
Loading
Loading
Loading
Loading
+73 −0
Original line number Diff line number Diff line
/*
 * Copyright 2016 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 ANDROID_BUFFERING_SETTINGS_H
#define ANDROID_BUFFERING_SETTINGS_H

#include <binder/Parcelable.h>

namespace android {

enum BufferingMode : int {
    // Do not support buffering.
    BUFFERING_MODE_NONE             = 0,
    // Support only time based buffering.
    BUFFERING_MODE_TIME_ONLY        = 1,
    // Support only size based buffering.
    BUFFERING_MODE_SIZE_ONLY        = 2,
    // Support both time and size based buffering, time based calculation precedes size based.
    // Size based calculation will be used only when time information is not available for
    // the stream.
    BUFFERING_MODE_TIME_THEN_SIZE   = 3,
    // Number of modes.
    BUFFERING_MODE_COUNT            = 4,
};

struct BufferingSettings : public Parcelable {
    static const int kNoWatermark = -1;

    static bool IsValidBufferingMode(int mode);

    BufferingMode mInitialBufferingMode;  // for prepare
    BufferingMode mRebufferingMode;  // for playback

    int mInitialWatermarkMs;  // time based
    int mInitialWatermarkKB;  // size based

    // When cached data is below this mark, playback will be paused for buffering
    // till data reach |mRebufferingWatermarkHighMs| or end of stream.
    int mRebufferingWatermarkLowMs;
    // When cached data is above this mark, buffering will be paused.
    int mRebufferingWatermarkHighMs;

    // When cached data is below this mark, playback will be paused for buffering
    // till data reach |mRebufferingWatermarkHighKB| or end of stream.
    int mRebufferingWatermarkLowKB;
    // When cached data is above this mark, buffering will be paused.
    int mRebufferingWatermarkHighKB;

    BufferingSettings();

    status_t writeToParcel(Parcel* parcel) const override;
    status_t readFromParcel(const Parcel* parcel) override;

};

} // namespace android

// ---------------------------------------------------------------------------

#endif // ANDROID_BUFFERING_SETTINGS_H
+4 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ class IGraphicBufferProducer;
struct IMediaHTTPService;
struct AudioPlaybackRate;
struct AVSyncSettings;
struct BufferingSettings;

typedef IMediaSource::ReadOptions::SeekMode MediaPlayerSeekMode;

@@ -59,6 +60,9 @@ public:
    virtual status_t        setDataSource(const sp<IDataSource>& source) = 0;
    virtual status_t        setVideoSurfaceTexture(
                                    const sp<IGraphicBufferProducer>& bufferProducer) = 0;
    virtual status_t        getDefaultBufferingSettings(
                                    BufferingSettings* buffering /* nonnull */) = 0;
    virtual status_t        setBufferingSettings(const BufferingSettings& buffering) = 0;
    virtual status_t        prepareAsync() = 0;
    virtual status_t        start() = 0;
    virtual status_t        stop() = 0;
+10 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include <media/AudioSystem.h>
#include <media/AudioTimestamp.h>
#include <media/AVSyncSettings.h>
#include <media/BufferingSettings.h>
#include <media/Metadata.h>

// Fwd decl to make sure everyone agrees that the scope of struct sockaddr_in is
@@ -174,6 +175,15 @@ public:
    virtual status_t    setVideoSurfaceTexture(
                                const sp<IGraphicBufferProducer>& bufferProducer) = 0;

    virtual status_t    getDefaultBufferingSettings(
                                BufferingSettings* buffering /* nonnull */) {
        *buffering = BufferingSettings();
        return OK;
    }
    virtual status_t    setBufferingSettings(const BufferingSettings& /* buffering */) {
        return OK;
    }

    virtual status_t    prepare() = 0;
    virtual status_t    prepareAsync() = 0;
    virtual status_t    start() = 0;
+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ LOCAL_SRC_FILES:= \
LOCAL_SRC_FILES += \
    IDataSource.cpp \
    IHDCP.cpp \
    BufferingSettings.cpp \
    mediaplayer.cpp \
    IMediaCodecList.cpp \
    IMediaCodecService.cpp \
+73 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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_TAG "BufferingSettings"
//#define LOG_NDEBUG 0

#include <binder/Parcel.h>

#include <media/BufferingSettings.h>

namespace android {

// static
bool BufferingSettings::IsValidBufferingMode(int mode) {
    return (mode >= BUFFERING_MODE_NONE && mode < BUFFERING_MODE_COUNT);
}

BufferingSettings::BufferingSettings()
        : mInitialBufferingMode(BUFFERING_MODE_NONE),
          mRebufferingMode(BUFFERING_MODE_NONE),
          mInitialWatermarkMs(kNoWatermark),
          mInitialWatermarkKB(kNoWatermark),
          mRebufferingWatermarkLowMs(kNoWatermark),
          mRebufferingWatermarkHighMs(kNoWatermark),
          mRebufferingWatermarkLowKB(kNoWatermark),
          mRebufferingWatermarkHighKB(kNoWatermark) { }

status_t BufferingSettings::readFromParcel(const Parcel* parcel) {
    if (parcel == nullptr) {
        return BAD_VALUE;
    }
    mInitialBufferingMode = (BufferingMode)parcel->readInt32();
    mRebufferingMode = (BufferingMode)parcel->readInt32();
    mInitialWatermarkMs = parcel->readInt32();
    mInitialWatermarkKB = parcel->readInt32();
    mRebufferingWatermarkLowMs = parcel->readInt32();
    mRebufferingWatermarkHighMs = parcel->readInt32();
    mRebufferingWatermarkLowKB = parcel->readInt32();
    mRebufferingWatermarkHighKB = parcel->readInt32();

    return OK;
}

status_t BufferingSettings::writeToParcel(Parcel* parcel) const {
    if (parcel == nullptr) {
        return BAD_VALUE;
    }
    parcel->writeInt32(mInitialBufferingMode);
    parcel->writeInt32(mRebufferingMode);
    parcel->writeInt32(mInitialWatermarkMs);
    parcel->writeInt32(mInitialWatermarkKB);
    parcel->writeInt32(mRebufferingWatermarkLowMs);
    parcel->writeInt32(mRebufferingWatermarkHighMs);
    parcel->writeInt32(mRebufferingWatermarkLowKB);
    parcel->writeInt32(mRebufferingWatermarkHighKB);

    return OK;
}

} // namespace android
Loading