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

Commit 6ff9b812 authored by Glenn Kasten's avatar Glenn Kasten
Browse files

Bug 4599730 Get audio channel count on MediaPlayer

Related changes:
 - Fix bug in get/setParameter* to recycle Parcels when done with them.

Change-Id: Iaff05e91bbd99a14fccb79d816dd873359b6ae65
parent 72de151f
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -130,13 +130,22 @@ enum media_player_states {
    MEDIA_PLAYER_PLAYBACK_COMPLETE  = 1 << 7
};

enum media_set_parameter_keys {
    KEY_PARAMETER_TIMED_TEXT_TRACK_INDEX = 1000,
    KEY_PARAMETER_TIMED_TEXT_ADD_OUT_OF_BAND_SOURCE = 1001,
// Keep KEY_PARAMETER_* in sync with MediaPlayer.java.
// The same enum space is used for both set and get, in case there are future keys that
// can be both set and get.  But as of now, all parameters are either set only or get only.
enum media_parameter_keys {
    KEY_PARAMETER_TIMED_TEXT_TRACK_INDEX = 1000,                // set only
    KEY_PARAMETER_TIMED_TEXT_ADD_OUT_OF_BAND_SOURCE = 1001,     // set only

    // Streaming/buffering parameters
    KEY_PARAMETER_CACHE_STAT_COLLECT_FREQ_MS = 1100,
    KEY_PARAMETER_CACHE_STAT_COLLECT_FREQ_MS = 1100,            // set only

    // Return a Parcel containing a single int, which is the channel count of the
    // audio track, or zero for error (e.g. no audio track) or unknown.
    KEY_PARAMETER_AUDIO_CHANNEL_COUNT = 1200,                   // get only

};

// ----------------------------------------------------------------------------
// ref-counted object for callbacks
class MediaPlayerListener: virtual public RefBase
+17 −4
Original line number Diff line number Diff line
@@ -1333,6 +1333,10 @@ public class MediaPlayer
     */
    private static final int KEY_PARAMETER_TIMED_TEXT_ADD_OUT_OF_BAND_SOURCE = 1001;

    // There are currently no defined keys usable from Java with get*Parameter.
    // But if any keys are defined, the order must be kept in sync with include/media/mediaplayer.h.
    // private static final int KEY_PARAMETER_... = ...;

    /**
     * Sets the parameter indicated by key.
     * @param key key indicates the parameter to be set.
@@ -1352,7 +1356,9 @@ public class MediaPlayer
    public boolean setParameter(int key, String value) {
        Parcel p = Parcel.obtain();
        p.writeString(value);
        return setParameter(key, p);
        boolean ret = setParameter(key, p);
        p.recycle();
        return ret;
    }

    /**
@@ -1365,7 +1371,9 @@ public class MediaPlayer
    public boolean setParameter(int key, int value) {
        Parcel p = Parcel.obtain();
        p.writeInt(value);
        return setParameter(key, p);
        boolean ret = setParameter(key, p);
        p.recycle();
        return ret;
    }

    /**
@@ -1377,6 +1385,7 @@ public class MediaPlayer

    /**
     * Gets the value of the parameter indicated by key.
     * The caller is responsible for recycling the returned parcel.
     * @param key key indicates the parameter to get.
     * @return value of the parameter.
     * {@hide}
@@ -1396,7 +1405,9 @@ public class MediaPlayer
    public String getStringParameter(int key) {
        Parcel p = Parcel.obtain();
        getParameter(key, p);
        return p.readString();
        String ret = p.readString();
        p.recycle();
        return ret;
    }

    /**
@@ -1408,7 +1419,9 @@ public class MediaPlayer
    public int getIntParameter(int key) {
        Parcel p = Parcel.obtain();
        getParameter(key, p);
        return p.readInt();
        int ret = p.readInt();
        p.recycle();
        return ret;
    }

    /**
+16 −1
Original line number Diff line number Diff line
@@ -2238,7 +2238,22 @@ status_t AwesomePlayer::setCacheStatCollectFreq(const Parcel &request) {
}

status_t AwesomePlayer::getParameter(int key, Parcel *reply) {
    switch (key) {
    case KEY_PARAMETER_AUDIO_CHANNEL_COUNT:
        {
            int32_t channelCount;
            if (mAudioTrack == 0 ||
                    !mAudioTrack->getFormat()->findInt32(kKeyChannelCount, &channelCount)) {
                channelCount = 0;
            }
            reply->writeInt32(channelCount);
        }
        return OK;
    default:
        {
            return ERROR_UNSUPPORTED;
        }
    }
}

bool AwesomePlayer::isStreamingHTTP() const {