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

Commit d80d6f6b authored by Wei Jia's avatar Wei Jia
Browse files

MediaSync: clean up configureAudioTrack and configureSurface.

Bug: 19666434

Change-Id: I8b112843d430c0730a879abc9aa25f143bdcf09d
parent 5551aca2
Loading
Loading
Loading
Loading
+9 −13
Original line number Original line Diff line number Diff line
@@ -312,13 +312,13 @@ final public class MediaSync {
     * @throws IllegalArgumentException if the surface has been released, is invalid,
     * @throws IllegalArgumentException if the surface has been released, is invalid,
     *     or can not be connected.
     *     or can not be connected.
     * @throws IllegalStateException if setting the surface is not supported, e.g.
     * @throws IllegalStateException if setting the surface is not supported, e.g.
     *     not in the Initialized state, or another surface has already been configured.
     *     not in the Initialized state, or another surface has already been set.
     */
     */
    public void setSurface(@Nullable Surface surface) {
    public void setSurface(@Nullable Surface surface) {
        native_configureSurface(surface);
        native_setSurface(surface);
    }
    }


    private native final void native_configureSurface(@Nullable Surface surface);
    private native final void native_setSurface(@Nullable Surface surface);


    /**
    /**
     * Sets the audio track for MediaSync.
     * Sets the audio track for MediaSync.
@@ -328,21 +328,17 @@ final public class MediaSync {
     * @param audioTrack Specify an AudioTrack through which to render the audio data.
     * @param audioTrack Specify an AudioTrack through which to render the audio data.
     * @throws IllegalArgumentException if the audioTrack has been released, or is invalid.
     * @throws IllegalArgumentException if the audioTrack has been released, or is invalid.
     * @throws IllegalStateException if setting the audio track is not supported, e.g.
     * @throws IllegalStateException if setting the audio track is not supported, e.g.
     *     not in the Initialized state, or another audio track has already been configured.
     *     not in the Initialized state, or another audio track has already been set.
     */
     */
    public void setAudioTrack(@Nullable AudioTrack audioTrack) {
    public void setAudioTrack(@Nullable AudioTrack audioTrack) {
        // AudioTrack has sanity check for configured sample rate.
        native_setAudioTrack(audioTrack);
        int nativeSampleRateInHz = (audioTrack == null ? 0 : audioTrack.getSampleRate());

        native_configureAudioTrack(audioTrack, nativeSampleRateInHz);
        mAudioTrack = audioTrack;
        mAudioTrack = audioTrack;
        if (audioTrack != null && mAudioThread == null) {
        if (audioTrack != null && mAudioThread == null) {
            createAudioThread();
            createAudioThread();
        }
        }
    }
    }


    private native final void native_configureAudioTrack(
    private native final void native_setAudioTrack(@Nullable AudioTrack audioTrack);
            @Nullable AudioTrack audioTrack, int nativeSampleRateInHz);


    /**
    /**
     * Requests a Surface to use as the input. This may only be called after
     * Requests a Surface to use as the input. This may only be called after
@@ -350,7 +346,7 @@ final public class MediaSync {
     * <p>
     * <p>
     * The application is responsible for calling release() on the Surface when
     * The application is responsible for calling release() on the Surface when
     * done.
     * done.
     * @throws IllegalStateException if not configured, or another input surface has
     * @throws IllegalStateException if not set, or another input surface has
     *     already been created.
     *     already been created.
     */
     */
    @NonNull
    @NonNull
@@ -574,7 +570,7 @@ final public class MediaSync {
     * @param sizeInBytes number of bytes to queue.
     * @param sizeInBytes number of bytes to queue.
     * @param presentationTimeUs the presentation timestamp in microseconds for the first frame
     * @param presentationTimeUs the presentation timestamp in microseconds for the first frame
     *     in the buffer.
     *     in the buffer.
     * @throws IllegalStateException if audio track is not configured or internal configureation
     * @throws IllegalStateException if audio track is not set or internal configureation
     *     has not been done correctly.
     *     has not been done correctly.
     */
     */
    public void queueAudio(
    public void queueAudio(
@@ -582,7 +578,7 @@ final public class MediaSync {
            long presentationTimeUs) {
            long presentationTimeUs) {
        if (mAudioTrack == null || mAudioThread == null) {
        if (mAudioTrack == null || mAudioThread == null) {
            throw new IllegalStateException(
            throw new IllegalStateException(
                    "AudioTrack is NOT configured or audio thread is not created");
                    "AudioTrack is NOT set or audio thread is not created");
        }
        }


        synchronized(mAudioLock) {
        synchronized(mAudioLock) {
+15 −15
Original line number Original line Diff line number Diff line
@@ -61,12 +61,12 @@ JMediaSync::JMediaSync() {
JMediaSync::~JMediaSync() {
JMediaSync::~JMediaSync() {
}
}


status_t JMediaSync::configureSurface(const sp<IGraphicBufferProducer> &bufferProducer) {
status_t JMediaSync::setSurface(const sp<IGraphicBufferProducer> &bufferProducer) {
    return mSync->configureSurface(bufferProducer);
    return mSync->setSurface(bufferProducer);
}
}


status_t JMediaSync::configureAudioTrack(const sp<AudioTrack> &audioTrack) {
status_t JMediaSync::setAudioTrack(const sp<AudioTrack> &audioTrack) {
    return mSync->configureAudioTrack(audioTrack);
    return mSync->setAudioTrack(audioTrack);
}
}


status_t JMediaSync::createInputSurface(
status_t JMediaSync::createInputSurface(
@@ -163,9 +163,9 @@ static void throwExceptionAsNecessary(
    }
    }
}
}


static void android_media_MediaSync_native_configureSurface(
static void android_media_MediaSync_native_setSurface(
        JNIEnv *env, jobject thiz, jobject jsurface) {
        JNIEnv *env, jobject thiz, jobject jsurface) {
    ALOGV("android_media_MediaSync_configureSurface");
    ALOGV("android_media_MediaSync_setSurface");


    sp<JMediaSync> sync = getMediaSync(env, thiz);
    sp<JMediaSync> sync = getMediaSync(env, thiz);
    if (sync == NULL) {
    if (sync == NULL) {
@@ -184,7 +184,7 @@ static void android_media_MediaSync_native_configureSurface(
        }
        }
    }
    }


    status_t err = sync->configureSurface(bufferProducer);
    status_t err = sync->setSurface(bufferProducer);


    if (err == INVALID_OPERATION) {
    if (err == INVALID_OPERATION) {
        throwExceptionAsNecessary(
        throwExceptionAsNecessary(
@@ -196,9 +196,9 @@ static void android_media_MediaSync_native_configureSurface(
    }
    }
}
}


static void android_media_MediaSync_native_configureAudioTrack(
static void android_media_MediaSync_native_setAudioTrack(
        JNIEnv *env, jobject thiz, jobject jaudioTrack) {
        JNIEnv *env, jobject thiz, jobject jaudioTrack) {
    ALOGV("android_media_MediaSync_configureAudioTrack");
    ALOGV("android_media_MediaSync_setAudioTrack");


    sp<JMediaSync> sync = getMediaSync(env, thiz);
    sp<JMediaSync> sync = getMediaSync(env, thiz);
    if (sync == NULL) {
    if (sync == NULL) {
@@ -215,7 +215,7 @@ static void android_media_MediaSync_native_configureAudioTrack(
        }
        }
    }
    }


    status_t err = sync->configureAudioTrack(audioTrack);
    status_t err = sync->setAudioTrack(audioTrack);


    if (err == INVALID_OPERATION) {
    if (err == INVALID_OPERATION) {
        throwExceptionAsNecessary(
        throwExceptionAsNecessary(
@@ -501,13 +501,13 @@ static void android_media_MediaSync_native_finalize(JNIEnv *env, jobject thiz) {
}
}


static JNINativeMethod gMethods[] = {
static JNINativeMethod gMethods[] = {
    { "native_configureSurface",
    { "native_setSurface",
      "(Landroid/view/Surface;)V",
      "(Landroid/view/Surface;)V",
      (void *)android_media_MediaSync_native_configureSurface },
      (void *)android_media_MediaSync_native_setSurface },


    { "native_configureAudioTrack",
    { "native_setAudioTrack",
      "(Landroid/media/AudioTrack;I)V",
      "(Landroid/media/AudioTrack;)V",
      (void *)android_media_MediaSync_native_configureAudioTrack },
      (void *)android_media_MediaSync_native_setAudioTrack },


    { "createInputSurface", "()Landroid/view/Surface;",
    { "createInputSurface", "()Landroid/view/Surface;",
      (void *)android_media_MediaSync_createInputSurface },
      (void *)android_media_MediaSync_createInputSurface },
+2 −2
Original line number Original line Diff line number Diff line
@@ -33,8 +33,8 @@ class MediaSync;
struct JMediaSync : public RefBase {
struct JMediaSync : public RefBase {
    JMediaSync();
    JMediaSync();


    status_t configureSurface(const sp<IGraphicBufferProducer> &bufferProducer);
    status_t setSurface(const sp<IGraphicBufferProducer> &bufferProducer);
    status_t configureAudioTrack(const sp<AudioTrack> &audioTrack);
    status_t setAudioTrack(const sp<AudioTrack> &audioTrack);


    status_t createInputSurface(sp<IGraphicBufferProducer>* bufferProducer);
    status_t createInputSurface(sp<IGraphicBufferProducer>* bufferProducer);