<commit_before>/*
 * Copyright (c) 2016 <NAME> <<EMAIL>>
 *
 * 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 ie.macinnes.tvheadend.tvinput;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.media.tv.TvTrackInfo;
import android.net.Uri;
import android.os.Handler;
import android.util.Log;
import android.view.Surface;

import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.MediaPlayer;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import ie.macinnes.tvheadend.Constants;
import ie.macinnes.tvheadend.account.AccountUtils;
import ie.macinnes.tvheadend.client.ClientUtils;
import ie.macinnes.tvheadend.model.Channel;

public class VlcSession extends BaseSession {
    private static final String TAG = VlcSession.class.getName();

    private LibVLC mLibVLC;
    private MediaPlayer mMediaPlayer;

    /**
     * Creates a new Session.
     *
     * @param context The context of the application
     */
    public VlcSession(Context context, Handler serviceHandler) {
        super(context, serviceHandler);
        Log.d(TAG, "Session created (" + mSessionNumber + ")");

        ArrayList<String> options = new ArrayList<>();
        options.add("--http-reconnect");
        options.add("--network-caching=2000");
        options.add("--deinterlace=-1");
        options.add("--deinterlace-mode=blend"); // discard,blend,mean,bob,linear,x,yadif,yadif2x,phosphor,ivtc
        options.add("--video-filter=deinterlace");

        mLibVLC = new LibVLC(options);
    }

    @Override
    public boolean onSetSurface(Surface surface) {
        Log.d(TAG, "Session onSetSurfaces (" + mSessionNumber + ")");

        mSurface = surface;

        if (mMediaPlayer != null && mSurface != null) {<commit_msg>VLC: Explicitly set user agent<commit_after>/*
 * Copyright (c) 2016 <NAME> <<EMAIL>>
 *
 * 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 ie.macinnes.tvheadend.tvinput;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.media.tv.TvTrackInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.util.Log;
import android.view.Surface;

import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
import org.videolan.libvlc.MediaPlayer;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import ie.macinnes.tvheadend.Constants;
import ie.macinnes.tvheadend.account.AccountUtils;
import ie.macinnes.tvheadend.client.ClientUtils;
import ie.macinnes.tvheadend.model.Channel;

public class VlcSession extends BaseSession {
    private static final String TAG = VlcSession.class.getName();

    private LibVLC mLibVLC;
    private MediaPlayer mMediaPlayer;

    /**
     * Creates a new Session.
     *
     * @param context The context of the application
     */
    public VlcSession(Context context, Handler serviceHandler) {
        super(context, serviceHandler);
        Log.d(TAG, "Session created (" + mSessionNumber + ")");

        ArrayList<String> options = new ArrayList<>();
        options.add("--http-reconnect");
        options.add("--network-caching=2000");
        options.add("--deinterlace=-1");
        options.add("--deinterlace-mode=blend"); // discard,blend,mean,bob,linear,x,yadif,yadif2x,phosphor,ivtc
        options.add("--video-filter=deinterlace");

        mLibVLC = new LibVLC(options);

        String userAgent = getUserAgent(mContext);
        mLibVLC.setUserAgent(userAgent, userAgent);
    }

    public String getUserAgent(Context context) {
        String versionName;

        try {
            String packageName = context.getPackageName();
            PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
            versionName = info.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            versionName = "?";
        }

        return "android-tvheadend/" + versionName + " (Linux;Android " + Build.VERSION.RELEASE
                + ") VLC/" + mLibVLC.version();
    }

    @Override
    public boolean onSetSurface(Surface surface) {
        Log.d(TAG, "Session onSetSurfaces (" + mSessionNumber + ")");

        mSurface = surface;

        if (mMediaPlayer != null && mSurface != null) {
{'fraction_non_alphanumeric': 0.10999451854558744, 'fraction_numerical': 0.005298739265485109, 'mean_word_length': 3.535211267605634, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '6613679', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1572, 'n_words': 422}