<commit_before>/*
 *    Copyright (C) 2014 <NAME>
 *
 *    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 com.h6ah4i.android.media.opensl;

import android.content.Context;
import android.media.MediaPlayer;
import android.media.audiofx.Equalizer;

import com.h6ah4i.android.media.IBasicMediaPlayer;
import com.h6ah4i.android.media.IMediaPlayerFactory;
import com.h6ah4i.android.media.audiofx.IBassBoost;
import com.h6ah4i.android.media.audiofx.IEnvironmentalReverb;
import com.h6ah4i.android.media.audiofx.IEqualizer;
import com.h6ah4i.android.media.audiofx.IHQVisualizer;
import com.h6ah4i.android.media.audiofx.ILoudnessEnhancer;
import com.h6ah4i.android.media.audiofx.IPreAmp;
import com.h6ah4i.android.media.audiofx.IPresetReverb;
import com.h6ah4i.android.media.audiofx.IVirtualizer;
import com.h6ah4i.android.media.audiofx.IVisualizer;
import com.h6ah4i.android.media.opensl.OpenSLMediaPlayerContext.Parameters;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLBassBoost;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLEnvironmentalReverb;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLEqualizer;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLHQEqualizer;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLHQVisualizer;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLPreAmp;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLPresetReverb;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLVirtualizer;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLVisualizer;

public class OpenSLMediaPlayerFactory implements IMediaPlayerFactory {
    private OpenSLMediaPlayerContext mMediaPlayerContext;

    public OpenSLMediaPlayerFactory(Context context) {
        mMediaPlayerContext = new OpenSLMediaPlayerContext(context, getDefaultContextParams());
    }

    public OpenSLMediaPlayerFactory(Context context, OpenSLMediaPlayerContext.Parameters params) {
        mMediaPlayerContext = new OpenSLMediaPlayerContext(context, params);
    }

    public OpenSLMediaPlayerContext getOpenSLMediaPlayerContext() {
        return mMediaPlayerContext;
    }

    @Override
    public void release() throws IllegalStateException, UnsupportedOperationException {
        if (mMediaPlayerContext != null) {
            mMediaPlayerContext.release();
            mMediaPlayerContext = null;
        }
    }

    @Override
    protected void finalize() throws Throwable {
        release();
    }

    @Override
    public IBasicMediaPlayer createMediaPlayer()
            throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException {
        return new OpenSLMediaPlayer(getMediaPlayerContext(), getMediaPlayerOptions());
    }

    @Override
    public IBassBoost createBassBoost(int audioSession)
            throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException {
        return onCreateBassBoost(audioSession);
    }

    @Override<commit_msg>Fix Android Studio lint warning of "Finalization issues"<commit_after>/*
 *    Copyright (C) 2014 <NAME>
 *
 *    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 com.h6ah4i.android.media.opensl;

import android.content.Context;
import android.media.MediaPlayer;
import android.media.audiofx.Equalizer;

import com.h6ah4i.android.media.IBasicMediaPlayer;
import com.h6ah4i.android.media.IMediaPlayerFactory;
import com.h6ah4i.android.media.audiofx.IBassBoost;
import com.h6ah4i.android.media.audiofx.IEnvironmentalReverb;
import com.h6ah4i.android.media.audiofx.IEqualizer;
import com.h6ah4i.android.media.audiofx.IHQVisualizer;
import com.h6ah4i.android.media.audiofx.ILoudnessEnhancer;
import com.h6ah4i.android.media.audiofx.IPreAmp;
import com.h6ah4i.android.media.audiofx.IPresetReverb;
import com.h6ah4i.android.media.audiofx.IVirtualizer;
import com.h6ah4i.android.media.audiofx.IVisualizer;
import com.h6ah4i.android.media.opensl.OpenSLMediaPlayerContext.Parameters;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLBassBoost;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLEnvironmentalReverb;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLEqualizer;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLHQEqualizer;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLHQVisualizer;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLPreAmp;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLPresetReverb;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLVirtualizer;
import com.h6ah4i.android.media.opensl.audiofx.OpenSLVisualizer;

public class OpenSLMediaPlayerFactory implements IMediaPlayerFactory {
    private OpenSLMediaPlayerContext mMediaPlayerContext;

    public OpenSLMediaPlayerFactory(Context context) {
        mMediaPlayerContext = new OpenSLMediaPlayerContext(context, getDefaultContextParams());
    }

    public OpenSLMediaPlayerFactory(Context context, OpenSLMediaPlayerContext.Parameters params) {
        mMediaPlayerContext = new OpenSLMediaPlayerContext(context, params);
    }

    public OpenSLMediaPlayerContext getOpenSLMediaPlayerContext() {
        return mMediaPlayerContext;
    }

    @Override
    public void release() throws IllegalStateException, UnsupportedOperationException {
        if (mMediaPlayerContext != null) {
            mMediaPlayerContext.release();
            mMediaPlayerContext = null;
        }
    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        release();
    }

    @Override
    public IBasicMediaPlayer createMediaPlayer()
            throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException {
        return new OpenSLMediaPlayer(getMediaPlayerContext(), getMediaPlayerOptions());
    }

    @Override
    public IBassBoost createBassBoost(int audioSession)
            throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException {
        return onCreateBassBoost(audioSession);
    }

    @Override
{'fraction_non_alphanumeric': 0.0799544743206715, 'fraction_numerical': 0.014795845781761274, 'mean_word_length': 4.475077881619938, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4443467', 'n_tokens_mistral': 2123, 'n_tokens_neox': 2090, 'n_words': 419}