<commit_before>/*
 * Copyright (C) 2009 Nokia Corporation.
 *
 * Authors: <NAME> <<EMAIL>>
 *                      <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "gupnp-dlna-private.h"

static const char *
guess_jpeg_profile (GUPnPDIDLLiteResource *resource)
{
        if (resource->width < 0 || resource->height < 0) {
                return "JPEG_MED";
        } else if (resource->width <= 48 && resource->height <= 48) {
                return "JPEG_SM_ICO";
        } else if (resource->width <= 120 && resource->height <= 120) {
                return "JPEG_LRG_ICO";
        } else if (resource->width <= 160 && resource->height <= 160) {
                return "JPEG_TN"; /* Thumbnail */
        } else if (resource->width <= 640 && resource->height <= 480) {
                return "JPEG_SM";
        } else if (resource->width <= 1024 && resource->height <= 768) {
                return "JPEG_MED";
        } else if (resource->width <= 4096 && resource->height <= 4096) {
                return "JPEG_LRG";
        } else {
                return NULL;
        }
}

static const char *
guess_png_profile (GUPnPDIDLLiteResource *resource)
{
        if (resource->width < 0 || resource->height < 0) {
                return "PNG_MED";
        } else if (resource->width <= 48 && resource->height <= 48) {
                return "PNG_SM_ICO";
        } else if (resource->width <= 120 && resource->height <= 120) {
                return "PNG_LRG_ICO";
        } else if (resource->width <= 160 && resource->height <= 160) {
                return "PNG_TN"; /* Thumbnail */
        } else if (resource->width <= 640 && resource->height <= 480) {
                return "PNG_SM";
        } else if (resource->width <= 1024 && resource->height <= 768) {
                return "PNG_MED";
        } else if (resource->width <= 4096 && resource->height <= 4096) {
                return "PNG_LRG";
        } else {
                return NULL;
        }
}

static void
check_int_allowed (int         value,
                   const char *value_name,
                   const int  *allowed_values,
                   const char *profile)
{
        if (value > 0) {
                const int *allowed_value;
                gboolean not_allowed = TRUE;

            for (allowed_value = allowed_values;
                 *allowed_value != -1;
                 allowed_value++) {
                if (value == *allowed_value) {
                        not_allowed = FALSE;
                        break;
                }
            }

            if (not_allowed) {
                g_warning ("DLNA specs do not allow %d as %s for %s profile",
                           value,
                           value_name,
                           profile);
            }
        }
}

static void
check_frequency (GUPnPDIDLLiteResource *resource,
                 const int             *allowed_freq,
                 const char            *profile)
{
        check_int_allowed (resource->sample_freq,
                           "frequency",
                           allowed_freq,
                           profile);
}

static void
check_bitrate (GUPnPDIDLLiteResource *resource,
               const int             *allowed_bitrates,
               const char            *profile)
{
        check_int_allowed (resource->bitrate,
                           "bitrate",
                           allowed_bitrates,
                           profile);
}

static void
check_sample_size (GUPnPDIDLLiteResource *resource,
                   const int             *allowed_sample_size,
                   const char            *profile)
{
        check_int_allowed (resource->bits_per_sample,
                           "bitsPerSample",
                           allowed_sample_size,
                           profile);
}

static void
check_num_channels (GUPnPDIDLLiteResource *resource,
                    const int             *allowed_num_channels,
                    const char            *profile)
{
        check_int_allowed (resource->n_audio_channels,
                           "nrAudioChannels",
                           allowed_num_channels,
                           profile);
}

static const char *
guess_ac3_profile (GUPnPDIDLLiteResource *resource)
{
        const int allowed_freq[] = { 32000, 41000, 4800, -1 };

        check_frequency (resource, allowed_freq, "AC3");

        return "AC3";
}

static const char *
guess_lpcm_profile (GUPnPDIDLLiteResource *resource)
{
        const int allowed_freq[] = { 41000, 4800, -1 };
        const int allowed_num_channels[] = { 1, 2, -1 };
        const int allowed_sample_size [] = { 16, -1 };

        check_frequency (resource, allowed_freq, "LPCM");
        check_num_channels (resource, allowed_num_channels, "LPCM");
        check_sample_size (resource, allowed_sample_size, "LPCM");

        return "LPCM";
}

static const char *
guess_mp3_profile (GUPnPDIDLLiteResource *resource)
{<commit_msg>Fix allowed frequencies in AC-3 and LPCM profiles<commit_after>/*
 * Copyright (C) 2009 Nokia Corporation.
 *
 * Authors: <NAME> <<EMAIL>>
 *                      <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "gupnp-dlna-private.h"

static const char *
guess_jpeg_profile (GUPnPDIDLLiteResource *resource)
{
        if (resource->width < 0 || resource->height < 0) {
                return "JPEG_MED";
        } else if (resource->width <= 48 && resource->height <= 48) {
                return "JPEG_SM_ICO";
        } else if (resource->width <= 120 && resource->height <= 120) {
                return "JPEG_LRG_ICO";
        } else if (resource->width <= 160 && resource->height <= 160) {
                return "JPEG_TN"; /* Thumbnail */
        } else if (resource->width <= 640 && resource->height <= 480) {
                return "JPEG_SM";
        } else if (resource->width <= 1024 && resource->height <= 768) {
                return "JPEG_MED";
        } else if (resource->width <= 4096 && resource->height <= 4096) {
                return "JPEG_LRG";
        } else {
                return NULL;
        }
}

static const char *
guess_png_profile (GUPnPDIDLLiteResource *resource)
{
        if (resource->width < 0 || resource->height < 0) {
                return "PNG_MED";
        } else if (resource->width <= 48 && resource->height <= 48) {
                return "PNG_SM_ICO";
        } else if (resource->width <= 120 && resource->height <= 120) {
                return "PNG_LRG_ICO";
        } else if (resource->width <= 160 && resource->height <= 160) {
                return "PNG_TN"; /* Thumbnail */
        } else if (resource->width <= 640 && resource->height <= 480) {
                return "PNG_SM";
        } else if (resource->width <= 1024 && resource->height <= 768) {
                return "PNG_MED";
        } else if (resource->width <= 4096 && resource->height <= 4096) {
                return "PNG_LRG";
        } else {
                return NULL;
        }
}

static void
check_int_allowed (int         value,
                   const char *value_name,
                   const int  *allowed_values,
                   const char *profile)
{
        if (value > 0) {
                const int *allowed_value;
                gboolean not_allowed = TRUE;

            for (allowed_value = allowed_values;
                 *allowed_value != -1;
                 allowed_value++) {
                if (value == *allowed_value) {
                        not_allowed = FALSE;
                        break;
                }
            }

            if (not_allowed) {
                g_warning ("DLNA specs do not allow %d as %s for %s profile",
                           value,
                           value_name,
                           profile);
            }
        }
}

static void
check_frequency (GUPnPDIDLLiteResource *resource,
                 const int             *allowed_freq,
                 const char            *profile)
{
        check_int_allowed (resource->sample_freq,
                           "frequency",
                           allowed_freq,
                           profile);
}

static void
check_bitrate (GUPnPDIDLLiteResource *resource,
               const int             *allowed_bitrates,
               const char            *profile)
{
        check_int_allowed (resource->bitrate,
                           "bitrate",
                           allowed_bitrates,
                           profile);
}

static void
check_sample_size (GUPnPDIDLLiteResource *resource,
                   const int             *allowed_sample_size,
                   const char            *profile)
{
        check_int_allowed (resource->bits_per_sample,
                           "bitsPerSample",
                           allowed_sample_size,
                           profile);
}

static void
check_num_channels (GUPnPDIDLLiteResource *resource,
                    const int             *allowed_num_channels,
                    const char            *profile)
{
        check_int_allowed (resource->n_audio_channels,
                           "nrAudioChannels",
                           allowed_num_channels,
                           profile);
}

static const char *
guess_ac3_profile (GUPnPDIDLLiteResource *resource)
{
        const int allowed_freq[] = { 32000, 44100, 48000, -1 };

        check_frequency (resource, allowed_freq, "AC3");

        return "AC3";
}

static const char *
guess_lpcm_profile (GUPnPDIDLLiteResource *resource)
{
        const int allowed_freq[] = { 44100, 48000, -1 };
        const int allowed_num_channels[] = { 1, 2, -1 };
        const int allowed_sample_size [] = { 16, -1 };

        check_frequency (resource, allowed_freq, "LPCM");
        check_num_channels (resource, allowed_num_channels, "LPCM");
        check_sample_size (resource, allowed_sample_size, "LPCM");

        return "LPCM";
}

static const char *
guess_mp3_profile (GUPnPDIDLLiteResource *resource)
{
{'fraction_non_alphanumeric': 0.09612688398177358, 'fraction_numerical': 0.023746933052926744, 'mean_word_length': 1.6585138597717215, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '84946', 'n_tokens_mistral': 3301, 'n_tokens_neox': 2978, 'n_words': 879}