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

Commit 3a474aa6 authored by Lajos Molnar's avatar Lajos Molnar
Browse files

stagefright: support setting/getting playback/sync config in MediaSync

Bug: 18249558
Bug: 19666434
Bug: 20057497
Change-Id: I5868b17423d7c20cfaf4a399f3eb67bfba440605
parent a8df0b71
Loading
Loading
Loading
Loading
+61 −0
Original line number Diff line number Diff line
/*
 * Copyright 2015 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_AV_SYNC_SETTINGS_H
#define ANDROID_AV_SYNC_SETTINGS_H

namespace android {

enum AVSyncSource : unsigned {
    // let the system decide the best sync source
    AVSYNC_SOURCE_DEFAULT = 0,
    // sync to the system clock
    AVSYNC_SOURCE_SYSTEM_CLOCK = 1,
    // sync to the audio track
    AVSYNC_SOURCE_AUDIO = 2,
    // sync to the display vsync
    AVSYNC_SOURCE_VSYNC = 3,
    AVSYNC_SOURCE_MAX,
};

enum AVSyncAudioAdjustMode : unsigned {
    // let the system decide the best audio adjust mode
    AVSYNC_AUDIO_ADJUST_MODE_DEFAULT = 0,
    // adjust audio by time stretching
    AVSYNC_AUDIO_ADJUST_MODE_STRETCH = 1,
    // adjust audio by resampling
    AVSYNC_AUDIO_ADJUST_MODE_RESAMPLE = 2,
    AVSYNC_AUDIO_ADJUST_MODE_MAX,
};

// max tolerance when adjusting playback speed to desired playback speed
#define AVSYNC_TOLERANCE_MAX 1.0f

struct AVSyncSettings {
    AVSyncSource mSource;
    AVSyncAudioAdjustMode mAudioAdjustMode;
    float mTolerance;
    AVSyncSettings()
        : mSource(AVSYNC_SOURCE_DEFAULT),
          mAudioAdjustMode(AVSYNC_AUDIO_ADJUST_MODE_DEFAULT),
          mTolerance(.044f) { }
};

} // namespace android

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

#endif // ANDROID_AV_SYNC_SETTINGS_H
+6 −0
Original line number Diff line number Diff line
@@ -360,6 +360,11 @@ public:
    /* Return current source sample rate in Hz */
            uint32_t    getSampleRate() const;

    /* Return the original source sample rate in Hz. This corresponds to the sample rate
     * if playback rate had normal speed and pitch.
     */
            uint32_t    getOriginalSampleRate() const;

    /* Set source playback rate for timestretch
     * 1.0 is normal speed: < 1.0 is slower, > 1.0 is faster
     * 1.0 is normal pitch: < 1.0 is lower pitch, > 1.0 is higher pitch
@@ -749,6 +754,7 @@ protected:
    float                   mVolume[2];
    float                   mSendLevel;
    mutable uint32_t        mSampleRate;            // mutable because getSampleRate() can update it
    uint32_t                mOriginalSampleRate;
    AudioPlaybackRate       mPlaybackRate;
    size_t                  mFrameCount;            // corresponds to current IAudioTrack, value is
                                                    // reported back by AudioFlinger to the client
+7 −1
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ class IDataSource;
struct IStreamSource;
class IGraphicBufferProducer;
struct IMediaHTTPService;
struct AudioPlaybackRate;
struct AVSyncSettings;

class IMediaPlayer: public IInterface
{
@@ -58,7 +60,11 @@ public:
    virtual status_t        stop() = 0;
    virtual status_t        pause() = 0;
    virtual status_t        isPlaying(bool* state) = 0;
    virtual status_t        setPlaybackRate(float rate) = 0;
    virtual status_t        setPlaybackSettings(const AudioPlaybackRate& rate) = 0;
    virtual status_t        getPlaybackSettings(AudioPlaybackRate* rate /* nonnull */) = 0;
    virtual status_t        setSyncSettings(const AVSyncSettings& sync, float videoFpsHint) = 0;
    virtual status_t        getSyncSettings(AVSyncSettings* sync /* nonnull */,
                                            float* videoFps /* nonnull */) = 0;
    virtual status_t        seekTo(int msec) = 0;
    virtual status_t        getCurrentPosition(int* msec) = 0;
    virtual status_t        getDuration(int* msec) = 0;
+29 −2
Original line number Diff line number Diff line
@@ -26,8 +26,10 @@
#include <utils/RefBase.h>

#include <media/mediaplayer.h>
#include <media/AudioResamplerPublic.h>
#include <media/AudioSystem.h>
#include <media/AudioTimestamp.h>
#include <media/AVSyncSettings.h>
#include <media/Metadata.h>

// Fwd decl to make sure everyone agrees that the scope of struct sockaddr_in is
@@ -132,7 +134,8 @@ public:
        virtual void        pause() = 0;
        virtual void        close() = 0;

        virtual status_t    setPlaybackRatePermille(int32_t /* rate */) { return INVALID_OPERATION;}
        virtual status_t    setPlaybackRate(const AudioPlaybackRate& rate) = 0;
        virtual status_t    getPlaybackRate(AudioPlaybackRate* rate /* nonnull */) = 0;
        virtual bool        needsTrailingPadding() { return true; }

        virtual status_t    setParameters(const String8& /* keyValuePairs */) { return NO_ERROR; }
@@ -173,7 +176,31 @@ public:
    virtual status_t    stop() = 0;
    virtual status_t    pause() = 0;
    virtual bool        isPlaying() = 0;
    virtual status_t    setPlaybackRate(float /* rate */) { return INVALID_OPERATION; }
    virtual status_t    setPlaybackSettings(const AudioPlaybackRate& rate) {
        // by default, players only support setting rate to the default
        if (!isAudioPlaybackRateEqual(rate, AUDIO_PLAYBACK_RATE_DEFAULT)) {
            return BAD_VALUE;
        }
        return OK;
    }
    virtual status_t    getPlaybackSettings(AudioPlaybackRate* rate /* nonnull */) {
        *rate = AUDIO_PLAYBACK_RATE_DEFAULT;
        return OK;
    }
    virtual status_t    setSyncSettings(const AVSyncSettings& sync, float /* videoFps */) {
        // By default, players only support setting sync source to default; all other sync
        // settings are ignored. There is no requirement for getters to return set values.
        if (sync.mSource != AVSYNC_SOURCE_DEFAULT) {
            return BAD_VALUE;
        }
        return OK;
    }
    virtual status_t    getSyncSettings(
                                AVSyncSettings* sync /* nonnull */, float* videoFps /* nonnull */) {
        *sync = AVSyncSettings();
        *videoFps = -1.f;
        return OK;
    }
    virtual status_t    seekTo(int msec) = 0;
    virtual status_t    getCurrentPosition(int *msec) = 0;
    virtual status_t    getDuration(int *msec) = 0;
+10 −3
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@
#include <arpa/inet.h>

#include <binder/IMemory.h>

#include <media/AudioResamplerPublic.h>
#include <media/IMediaPlayerClient.h>
#include <media/IMediaPlayer.h>
#include <media/IMediaDeathNotifier.h>
@@ -32,8 +34,9 @@ class ANativeWindow;

namespace android {

class Surface;
struct AVSyncSettings;
class IGraphicBufferProducer;
class Surface;

enum media_event_type {
    MEDIA_NOP               = 0, // interface test message
@@ -223,7 +226,12 @@ public:
            status_t        stop();
            status_t        pause();
            bool            isPlaying();
            status_t        setPlaybackRate(float rate);
            status_t        setPlaybackSettings(const AudioPlaybackRate& rate);
            status_t        getPlaybackSettings(AudioPlaybackRate* rate /* nonnull */);
            status_t        setSyncSettings(const AVSyncSettings& sync, float videoFpsHint);
            status_t        getSyncSettings(
                                    AVSyncSettings* sync /* nonnull */,
                                    float* videoFps /* nonnull */);
            status_t        getVideoWidth(int *w);
            status_t        getVideoHeight(int *h);
            status_t        seekTo(int msec);
@@ -278,7 +286,6 @@ private:
    int                         mVideoWidth;
    int                         mVideoHeight;
    int                         mAudioSessionId;
    float                       mPlaybackRate;
    float                       mSendLevel;
    struct sockaddr_in          mRetransmitEndpoint;
    bool                        mRetransmitEndpointValid;
Loading