<commit_before>/* Copyright 2015 Samsung Electronics Co., LTD
 *
 * 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.
 */

package org.gearvrf.scene_objects;

import java.io.IOException;

import org.gearvrf.GVRContext;
import org.gearvrf.GVRDrawFrameListener;
import org.gearvrf.GVRExternalTexture;
import org.gearvrf.GVRMaterial;
import org.gearvrf.GVRMaterialShaderId;
import org.gearvrf.GVRMesh;
import org.gearvrf.GVRSceneObject;
import org.gearvrf.GVRMaterial.GVRShaderType;

import android.graphics.SurfaceTexture;
import android.media.MediaPlayer;
import android.view.Surface;

/**
 * A {@linkplain GVRSceneObject scene object} that shows video, using the
 * Android {@link MediaPlayer}.
 */
public class GVRVideoSceneObject extends GVRSceneObject {
    private GVRVideo mVideo;

    /** Video type constants, for use with {@link GVRVideoSceneObject} */
    public abstract class GVRVideoType {
        public static final int MONO = 0;
        public static final int HORIZONTAL_STEREO = 1;
        public static final int VERTICAL_STEREO = 2;
    };

    /**
     * Play a video on a {@linkplain GVRSceneObject scene object} with an
     * arbitrarily complex geometry, using the Android {@link MediaPlayer}
     * 
     * @param gvrContext
     *            current {@link GVRContext}
     * @param mesh
     *            a {@link GVRMesh} - see
     *            {@link GVRContext#loadMesh(org.gearvrf.GVRAndroidResource)}
     *            and {@link GVRContext#createQuad(float, float)}
     * @param mediaPlayer
     *            an Android {@link MediaPlayer}
     * @param videoType
     *            One of the {@linkplain GVRVideoType video type constants}
     * @throws IllegalArgumentException
     *             on an invalid {@code videoType} parameter
     */
    public GVRVideoSceneObject(final GVRContext gvrContext, GVRMesh mesh,
            final MediaPlayer mediaPlayer, int videoType) {
        super(gvrContext, mesh);
        final GVRExternalTexture texture = new GVRExternalTexture(gvrContext);

        GVRMaterialShaderId materialType;
        switch (videoType) {
        case GVRVideoType.MONO:
            materialType = GVRShaderType.OES.ID;
            break;
        case GVRVideoType.HORIZONTAL_STEREO:
            materialType = GVRShaderType.OESHorizontalStereo.ID;
            break;
        case GVRVideoType.VERTICAL_STEREO:
            materialType = GVRShaderType.OESVerticalStereo.ID;
            break;
        default:
            try {
                texture.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            throw new IllegalArgumentException();
        }
        GVRMaterial material = new GVRMaterial(gvrContext, materialType);
        material.setMainTexture(texture);
        getRenderData().setMaterial(material);

        gvrContext.runOnGlThread(new Runnable() {
            @Override
            public void run() {
                // Because texture.getId() is called, this needs to run in GL thread
                mVideo = new GVRVideo(mediaPlayer, texture);
                gvrContext.registerDrawFrameListener(mVideo);
            }
        });
    }

    /**
     * Play a video on a 2D, rectangular {@linkplain GVRSceneObject scene
     * object,} using the Android {@link MediaPlayer}
     * 
     * @param gvrContext
     *            current {@link GVRContext}
     * @param width
     *            the rectangle's width
     * @param height
     *            the rectangle's height
     * @param mediaPlayer
     *            an Android {@link MediaPlayer}
     * @param videoType
     *            One of the {@linkplain GVRVideoType video type constants}
     * @throws IllegalArgumentException
     *             on an invalid {@code videoType} parameter
     */
    public GVRVideoSceneObject(GVRContext gvrContext, float width,
            float height, MediaPlayer mediaPlayer, int videoType) {
        this(gvrContext, gvrContext.createQuad(width, height), mediaPlayer,
                videoType);
    }

    /**
     * Poll the {@link MediaPlayer} once per frame.<commit_msg>Support for GVRExternalTesture for GVRVideoSceneObject<commit_after>/* Copyright 2015 Samsung Electronics Co., LTD
 *
 * 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.
 */

package org.gearvrf.scene_objects;

import java.io.IOException;

import org.gearvrf.GVRContext;
import org.gearvrf.GVRDrawFrameListener;
import org.gearvrf.GVRExternalTexture;
import org.gearvrf.GVRMaterial;
import org.gearvrf.GVRMaterialShaderId;
import org.gearvrf.GVRMesh;
import org.gearvrf.GVRSceneObject;
import org.gearvrf.GVRMaterial.GVRShaderType;
import org.gearvrf.GVRTexture;

import android.graphics.SurfaceTexture;
import android.media.MediaPlayer;
import android.view.Surface;

/**
 * A {@linkplain GVRSceneObject scene object} that shows video, using the
 * Android {@link MediaPlayer}.
 */
public class GVRVideoSceneObject extends GVRSceneObject {
    private GVRVideo mVideo;

    /** Video type constants, for use with {@link GVRVideoSceneObject} */
    public abstract class GVRVideoType {
        public static final int MONO = 0;
        public static final int HORIZONTAL_STEREO = 1;
        public static final int VERTICAL_STEREO = 2;
    };

    /**
     * Play a video on a {@linkplain GVRSceneObject scene object} with an
     * arbitrarily complex geometry, using the Android {@link MediaPlayer}
     *
     * @param gvrContext
     *            current {@link GVRContext}
     * @param mesh
     *            a {@link GVRMesh} - see
     *            {@link GVRContext#loadMesh(org.gearvrf.GVRAndroidResource)}
     *            and {@link GVRContext#createQuad(float, float)}
     * @param mediaPlayer
     *            an Android {@link MediaPlayer}
     * @param texture
     *            a {@link GVRExternalTexture} to link with {@link MediaPlayer}
     * @param videoType
     *            One of the {@linkplain GVRVideoType video type constants}
     * @throws IllegalArgumentException
     *             on an invalid {@code videoType} parameter
     */
    public GVRVideoSceneObject(final GVRContext gvrContext, GVRMesh mesh,
                               final MediaPlayer mediaPlayer, final GVRExternalTexture texture,
                               int videoType) {
        super(gvrContext, mesh);
        GVRMaterialShaderId materialType;

        switch (videoType) {
            case GVRVideoType.MONO:
                materialType = GVRShaderType.OES.ID;
                break;
            case GVRVideoType.HORIZONTAL_STEREO:
                materialType = GVRShaderType.OESHorizontalStereo.ID;
                break;
            case GVRVideoType.VERTICAL_STEREO:
                materialType = GVRShaderType.OESVerticalStereo.ID;
                break;
            default:
                try {
                    texture.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                throw new IllegalArgumentException();
        }
        GVRMaterial material = new GVRMaterial(gvrContext, materialType);
        material.setMainTexture(texture);
        getRenderData().setMaterial(material);

        gvrContext.runOnGlThread(new Runnable() {
            @Override
            public void run() {
                // Because texture.getId() is called, this needs to run in GL thread
                mVideo = new GVRVideo(mediaPlayer, texture);
                gvrContext.registerDrawFrameListener(mVideo);
            }
        });
    }

    /**
     * Play a video on a {@linkplain GVRSceneObject scene object} with an
     * arbitrarily complex geometry, using the Android {@link MediaPlayer}
     * 
     * @param gvrContext
     *            current {@link GVRContext}
     * @param mesh
     *            a {@link GVRMesh} - see
     *            {@link GVRContext#loadMesh(org.gearvrf.GVRAndroidResource)}
     *            and {@link GVRContext#createQuad(float, float)}
     * @param mediaPlayer
     *            an Android {@link MediaPlayer}
     * @param videoType
     *            One of the {@linkplain GVRVideoType video type constants}
     * @throws IllegalArgumentException
     *             on an invalid {@code videoType} parameter
     */
    public GVRVideoSceneObject(final GVRContext gvrContext, GVRMesh mesh,
            final MediaPlayer mediaPlayer, int videoType) {
        this(gvrContext, mesh, mediaPlayer, new GVRExternalTexture(gvrContext), videoType);
    }

    /**
     * Play a video on a 2D, rectangular {@linkplain GVRSceneObject scene
     * object,} using the Android {@link MediaPlayer}
     * 
     * @param gvrContext
     *            current {@link GVRContext}
     * @param width
     *            the rectangle's width
     * @param height
     *            the rectangle's height
     * @param mediaPlayer
     *            an Android {@link MediaPlayer}
     * @param videoType
     *            One of the {@linkplain GVRVideoType video type constants}
     * @throws IllegalArgumentException
     *             on an invalid {@code videoType} parameter
     */
    public GVRVideoSceneObject(GVRContext gvrContext, float width,
            float height, MediaPlayer mediaPlayer, int videoType) {
        this(gvrContext, gvrContext.createQuad(width, height), mediaPlayer,
                videoType);
    }

    /**
     * Poll the {@link MediaPlayer} once per frame.
{'fraction_non_alphanumeric': 0.07719567091274782, 'fraction_numerical': 0.002298630399387032, 'mean_word_length': 2.348941629249519, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5836077', 'n_tokens_mistral': 2840, 'n_tokens_neox': 2750, 'n_words': 842}