<commit_before>/* *
 * This file is part of Feng
 *
 * Copyright (C) 2009 by LScube team <<EMAIL>>
 * See AUTHORS for more details
 *
 * feng is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * feng 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with feng; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * */

#include <config.h>

#include <stdbool.h>
#include <time.h>
#include <mqueue.h>
#include <fcntl.h> /* for mq_open's O_* options */
#include <errno.h>
#include <unistd.h> /* for usleep() */
#include <string.h>
#include <math.h>
#include <ctype.h> /* for tolower */

#include "feng.h"
#include "fnc_log.h"

#include "media/demuxer.h"
#include "media/mediaparser.h"

#define REQUIRED_FLUX_PROTOCOL_VERSION 4

typedef struct sd_private_data {
    char *mrl;
    mqd_t queue;
} sd_private_data;

/**
 * @brief Uninitialisation function for the demuxer_sd fake parser
 *
 * This function simply frees the slice in Track::private_data as a
 * mqd_t object.
 */
static void demuxer_sd_fake_mediaparser_uninit(Track *tr) {
    sd_private_data *priv = tr->private_data;
    g_free(priv->mrl);
    g_free(priv);
}

/**
 * @brief Fake parser description for demuxer_sd tracks
 *
 * This object is used to free the slice in Track::private_data as a
 * mqd_t object.
 */
static const MediaParser demuxer_sd_fake_mediaparser = {
    .info = NULL,
    .init = NULL,
    .parse = NULL,
    .uninit = demuxer_sd_fake_mediaparser_uninit
};

/*
 * Struct for automatic probing of live media sources
 */
typedef struct RTP_static_payload {
        int PldType;
        char const *EncName;
        int ClockRate;      // In Hz
        short Channels;
        int BitPerSample;
        float PktLen;       // In msec
} RTP_static_payload;

static const RTP_static_payload RTP_payload[] ={
        // Audio
        { 0 ,"PCMU"   ,8000 ,1 ,8 ,20 },
        {-1 ,""       ,-1   ,-1,-1,-1 },
        { 2 ,"G726_32",8000 ,1 ,4 ,20 },
        { 3 ,"GSM"    ,8000 ,1 ,-1,20 },
        { 4 ,"G723"   ,8000 ,1 ,-1,30 },
        { 5 ,"DVI4"   ,8000 ,1 ,4 ,20 },
        { 6 ,"DVI4"   ,16000,1 ,4 ,20 },
        { 7 ,"LPC"    ,8000 ,1 ,-1,20 },
        { 8 ,"PCMA"   ,8000 ,1 ,8 ,20 },
        { 9 ,"G722"   ,8000 ,1 ,8 ,20 },
        { 10,"L16"    ,44100,2 ,16,20 },
        { 11,"L16"    ,44100,1 ,16,20 },
        { 12,"QCELP"  ,8000 ,1 ,-1,20 },
        { -1,""       ,  -1 ,-1,-1,-1 },
        { 14,"MPA"    ,90000,1 ,-1,-1 },
        { 15,"G728"   ,8000 ,1 ,-1,20 },
        { 16,"DVI4"   ,11025,1 ,4 ,20 },
        { 17,"DVI4"   ,22050,1 ,4 ,20 },
        { 18,"G729"   ,8000 ,1 ,-1,20 },
        { -1,""       ,-1   ,-1,-1,-1 },
        { -1,""       ,-1   ,-1,-1,-1 },
        { -1,""       ,-1   ,-1,-1,-1 },
        { -1,""       ,-1   ,-1,-1,-1 },
        { -1,""       ,-1   ,-1,-1,-1 },
        // Video: 24-95 - Pkt_len in milliseconds is not specified and will be calculated in such a way
        // that each RTP packet contains a video frame (but no more than 536 byte, for UDP limitations)
        { -1,""       ,-1   ,-1,-1,-1 },
        { 25,"CelB"   ,90000,0 ,-1,-1 },
        { 26,"JPEG"   ,90000,0 ,-1,-1 },
        { -1,""       ,-1   ,-1,-1,-1 },
        { 28,"nv"     ,90000,0 ,-1,-1 },
        { -1,""       ,-1   ,-1,-1,-1 },
        { -1,""       ,-1   ,-1,-1,-1 },
        { 31,"H261"   ,90000,0 ,-1,-1 },
        { 32,"MPV"    ,90000,0 ,-1,-1 },
        { 33,"MP2T"   ,90000,0 ,-1,-1 },
        { 34,"H263"   ,90000,0 ,-1,-1 },
        { -1,""       ,-1   ,-1,-1,-1 },
        // Dynamic: 96-127
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 },
        { -1, "", -1, -1, -1, -1 }, { -1, "", -1, -1, -1, -1 }
};

/*! SD common tags */
#define SD_STREAM           "stream"
#define SD_STREAM_END       "stream_end"
#define SD_FILENAME         "file_name"
#define SD_CLOCK_RATE       "clock_rate"
#define SD_PAYLOAD_TYPE     "payload_type"
#define SD_ENCODING_NAME    "encoding_name"
#define SD_MEDIA_TYPE       "media_type"
#define SD_AUDIO_CHANNELS   "audio_channels"
#define SD_FMTP             "fmtp"
/*! Creative commons specific tags */
#define SD_LICENSE          "license"
#define SD_RDF              "verify"
#define SD_TITLE            "title"
#define SD_CREATOR          "creator"

//Probe informations from RTPPTDEFS table form codec_name
static const RTP_static_payload * probe_stream_info(char const *codec_name)
{
    int i;
    for (i=0; i<96; ++i) {<commit_msg>Remove dynamic payload from the table (reduces size of table).<commit_after>/* *
 * This file is part of Feng
 *
 * Copyright (C) 2009 by LScube team <<EMAIL>>
 * See AUTHORS for more details
 *
 * feng is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * feng 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with feng; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * */

#include <config.h>

#include <stdbool.h>
#include <time.h>
#include <mqueue.h>
#include <fcntl.h> /* for mq_open's O_* options */
#include <errno.h>
#include <unistd.h> /* for usleep() */
#include <string.h>
#include <math.h>
#include <ctype.h> /* for tolower */

#include "feng.h"
#include "fnc_log.h"

#include "media/demuxer.h"
#include "media/mediaparser.h"

#define REQUIRED_FLUX_PROTOCOL_VERSION 4

typedef struct sd_private_data {
    char *mrl;
    mqd_t queue;
} sd_private_data;

/**
 * @brief Uninitialisation function for the demuxer_sd fake parser
 *
 * This function simply frees the slice in Track::private_data as a
 * mqd_t object.
 */
static void demuxer_sd_fake_mediaparser_uninit(Track *tr) {
    sd_private_data *priv = tr->private_data;
    g_free(priv->mrl);
    g_free(priv);
}

/**
 * @brief Fake parser description for demuxer_sd tracks
 *
 * This object is used to free the slice in Track::private_data as a
 * mqd_t object.
 */
static const MediaParser demuxer_sd_fake_mediaparser = {
    .info = NULL,
    .init = NULL,
    .parse = NULL,
    .uninit = demuxer_sd_fake_mediaparser_uninit
};

/*
 * Struct for automatic probing of live media sources
 */
typedef struct RTP_static_payload {
        int PldType;
        char const *EncName;
        int ClockRate;      // In Hz
        short Channels;
        int BitPerSample;
        float PktLen;       // In msec
} RTP_static_payload;

static const RTP_static_payload RTP_payload[96] ={
        // Audio
        { 0 ,"PCMU"   ,8000 ,1 ,8 ,20 },
        {-1 ,""       ,-1   ,-1,-1,-1 },
        { 2 ,"G726_32",8000 ,1 ,4 ,20 },
        { 3 ,"GSM"    ,8000 ,1 ,-1,20 },
        { 4 ,"G723"   ,8000 ,1 ,-1,30 },
        { 5 ,"DVI4"   ,8000 ,1 ,4 ,20 },
        { 6 ,"DVI4"   ,16000,1 ,4 ,20 },
        { 7 ,"LPC"    ,8000 ,1 ,-1,20 },
        { 8 ,"PCMA"   ,8000 ,1 ,8 ,20 },
        { 9 ,"G722"   ,8000 ,1 ,8 ,20 },
        { 10,"L16"    ,44100,2 ,16,20 },
        { 11,"L16"    ,44100,1 ,16,20 },
        { 12,"QCELP"  ,8000 ,1 ,-1,20 },
        { -1,""       ,  -1 ,-1,-1,-1 },
        { 14,"MPA"    ,90000,1 ,-1,-1 },
        { 15,"G728"   ,8000 ,1 ,-1,20 },
        { 16,"DVI4"   ,11025,1 ,4 ,20 },
        { 17,"DVI4"   ,22050,1 ,4 ,20 },
        { 18,"G729"   ,8000 ,1 ,-1,20 },
        { -1,""       ,-1   ,-1,-1,-1 },
        { -1,""       ,-1   ,-1,-1,-1 },
        { -1,""       ,-1   ,-1,-1,-1 },
        { -1,""       ,-1   ,-1,-1,-1 },
        { -1,""       ,-1   ,-1,-1,-1 },
        // Video: 24-95 - Pkt_len in milliseconds is not specified and will be calculated in such a way
        // that each RTP packet contains a video frame (but no more than 536 byte, for UDP limitations)
        { -1,""       ,-1   ,-1,-1,-1 },
        { 25,"CelB"   ,90000,0 ,-1,-1 },
        { 26,"JPEG"   ,90000,0 ,-1,-1 },
        { -1,""       ,-1   ,-1,-1,-1 },
        { 28,"nv"     ,90000,0 ,-1,-1 },
        { -1,""       ,-1   ,-1,-1,-1 },
        { -1,""       ,-1   ,-1,-1,-1 },
        { 31,"H261"   ,90000,0 ,-1,-1 },
        { 32,"MPV"    ,90000,0 ,-1,-1 },
        { 33,"MP2T"   ,90000,0 ,-1,-1 },
        { 34,"H263"   ,90000,0 ,-1,-1 },
        { -1,""       ,-1   ,-1,-1,-1 }
};

/*! SD common tags */
#define SD_STREAM           "stream"
#define SD_STREAM_END       "stream_end"
#define SD_FILENAME         "file_name"
#define SD_CLOCK_RATE       "clock_rate"
#define SD_PAYLOAD_TYPE     "payload_type"
#define SD_ENCODING_NAME    "encoding_name"
#define SD_MEDIA_TYPE       "media_type"
#define SD_AUDIO_CHANNELS   "audio_channels"
#define SD_FMTP             "fmtp"
/*! Creative commons specific tags */
#define SD_LICENSE          "license"
#define SD_RDF              "verify"
#define SD_TITLE            "title"
#define SD_CREATOR          "creator"

//Probe informations from RTPPTDEFS table form codec_name
static const RTP_static_payload * probe_stream_info(char const *codec_name)
{
    int i;
    for (i=0; i<96; ++i) {
{'fraction_non_alphanumeric': 0.22727272727272727, 'fraction_numerical': 0.0938442011740441, 'mean_word_length': 1.742440722210137, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 92, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3197750', 'n_tokens_mistral': 5597, 'n_tokens_neox': 5145, 'n_words': 1487}