<commit_before>/*
 * Kurento Android Media: Android Media Library based on FFmpeg.
 * Copyright (C) 2011  <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

extern "C" {
#include <jni.h>

#include <util/log.h>
#include <init-log.h>
}

#include "MediaPortManager.h"

static char* LOG_TAG = "NDK-socket-manager";

extern "C" {
	JNIEXPORT jint JNICALL Java_com_kurento_kas_media_ports_MediaPortManager_takeAudioLocalPort(
				JNIEnv* env, jclass clazz, jint audioPort);
	JNIEXPORT jint JNICALL Java_com_kurento_kas_media_ports_MediaPortManager_releaseAudioLocalPort(
						JNIEnv* env, jclass clazz);

	JNIEXPORT jint JNICALL Java_com_kurento_kas_media_ports_MediaPortManager_takeVideoLocalPort(
				JNIEnv* env, jclass clazz, jint videoPort);
	JNIEXPORT jint JNICALL Java_com_kurento_kas_media_ports_MediaPortManager_releaseVideoLocalPort(
						JNIEnv* env, jclass clazz);
}

using namespace media;

MediaPort *audioMediaPort;
MediaPort *videoMediaPort;

JNIEXPORT jint JNICALL
Java_com_kurento_kas_media_ports_MediaPortManager_takeAudioLocalPort(
				JNIEnv* env, jclass clazz, jint audioPort) {
	if (init_log() != 0)
		media_log(MEDIA_LOG_WARN, LOG_TAG, "Couldn't init android log");

	if (audioPort < 0)
		audioMediaPort = MediaPortManager::createMediaPort();
	else
		audioMediaPort = MediaPortManager::createMediaPort(audioPort);

	return audioMediaPort->getPort();
}

JNIEXPORT jint JNICALL
Java_com_kurento_kas_media_ports_MediaPortManager_releaseAudioLocalPort(
						JNIEnv* env, jclass clazz) {
	int ret = 0;

	if (init_log() != 0)
		media_log(MEDIA_LOG_WARN, LOG_TAG, "Couldn't init android log");

	if (audioMediaPort) {
		ret = MediaPortManager::releaseMediaPort(audioMediaPort);
		audioMediaPort = NULL;
	}

	return ret;
}

JNIEXPORT jint JNICALL
Java_com_kurento_kas_media_ports_MediaPortManager_takeVideoLocalPort(
				JNIEnv* env, jclass clazz, jint videoPort) {
	if (init_log() != 0)
		media_log(MEDIA_LOG_WARN, LOG_TAG, "Couldn't init android log");

	if (videoPort < 0)
		videoMediaPort = MediaPortManager::createMediaPort();
	else
		videoMediaPort = MediaPortManager::createMediaPort(videoPort);

	return videoMediaPort->getPort();
}

JNIEXPORT jint JNICALL
Java_com_kurento_kas_media_ports_MediaPortManager_releaseVideoLocalPort(
						JNIEnv* env, jclass clazz) {
	int ret = 0;

	if (init_log() != 0)
		media_log(MEDIA_LOG_WARN, LOG_TAG, "Couldn't init android log");

	if (videoMediaPort) {
		ret = MediaPortManager::releaseMediaPort(videoMediaPort);
		videoMediaPort = NULL;
	}

	return ret;
}<commit_msg>Use takeMediaPort instead of createMediaPort.<commit_after>/*
 * Kurento Android Media: Android Media Library based on FFmpeg.
 * Copyright (C) 2011  <NAME>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

extern "C" {
#include <jni.h>

#include <util/log.h>
#include <init-log.h>
}

#include "MediaPortManager.h"

static char* LOG_TAG = "NDK-socket-manager";

extern "C" {
	JNIEXPORT jint JNICALL Java_com_kurento_kas_media_ports_MediaPortManager_takeAudioLocalPort(
				JNIEnv* env, jclass clazz, jint audioPort);
	JNIEXPORT jint JNICALL Java_com_kurento_kas_media_ports_MediaPortManager_releaseAudioLocalPort(
						JNIEnv* env, jclass clazz);

	JNIEXPORT jint JNICALL Java_com_kurento_kas_media_ports_MediaPortManager_takeVideoLocalPort(
				JNIEnv* env, jclass clazz, jint videoPort);
	JNIEXPORT jint JNICALL Java_com_kurento_kas_media_ports_MediaPortManager_releaseVideoLocalPort(
						JNIEnv* env, jclass clazz);
}

using namespace media;

MediaPort *audioMediaPort;
MediaPort *videoMediaPort;

JNIEXPORT jint JNICALL
Java_com_kurento_kas_media_ports_MediaPortManager_takeAudioLocalPort(
				JNIEnv* env, jclass clazz, jint audioPort) {
	if (init_log() != 0)
		media_log(MEDIA_LOG_WARN, LOG_TAG, "Couldn't init android log");

	if (audioPort < 0)
		audioMediaPort = MediaPortManager::takeMediaPort();
	else
		audioMediaPort = MediaPortManager::takeMediaPort(audioPort);

	return audioMediaPort->getPort();
}

JNIEXPORT jint JNICALL
Java_com_kurento_kas_media_ports_MediaPortManager_releaseAudioLocalPort(
						JNIEnv* env, jclass clazz) {
	int ret = 0;

	if (init_log() != 0)
		media_log(MEDIA_LOG_WARN, LOG_TAG, "Couldn't init android log");

	if (audioMediaPort) {
		ret = MediaPortManager::releaseMediaPort(audioMediaPort);
		audioMediaPort = NULL;
	}

	return ret;
}

JNIEXPORT jint JNICALL
Java_com_kurento_kas_media_ports_MediaPortManager_takeVideoLocalPort(
				JNIEnv* env, jclass clazz, jint videoPort) {
	if (init_log() != 0)
		media_log(MEDIA_LOG_WARN, LOG_TAG, "Couldn't init android log");

	if (videoPort < 0)
		videoMediaPort = MediaPortManager::takeMediaPort();
	else
		videoMediaPort = MediaPortManager::takeMediaPort(videoPort);

	return videoMediaPort->getPort();
}

JNIEXPORT jint JNICALL
Java_com_kurento_kas_media_ports_MediaPortManager_releaseVideoLocalPort(
						JNIEnv* env, jclass clazz) {
	int ret = 0;

	if (init_log() != 0)
		media_log(MEDIA_LOG_WARN, LOG_TAG, "Couldn't init android log");

	if (videoMediaPort) {
		ret = MediaPortManager::releaseMediaPort(videoMediaPort);
		videoMediaPort = NULL;
	}

	return ret;
}
{'fraction_non_alphanumeric': 0.08379254457050243, 'fraction_numerical': 0.004213938411669368, 'mean_word_length': 5.482142857142857, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '1349242', 'n_tokens_mistral': 2253, 'n_tokens_neox': 2067, 'n_words': 554}