<commit_before>/*
 *			GPAC - Multimedia Framework C SDK
 *
 *			Authors: <NAME>
 *			Copyright (c) 2010-20XX Telecom ParisTech
 *			All rights reserved
 *
 *  This file is part of GPAC / AVI Recorder demo module
 *
 *  GPAC 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, or (at your option)
 *  any later version.
 *
 *  GPAC 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 this library; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */
#include <stdlib.h>
#if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(__MINGW32__)

#define EMULATE_INTTYPES
#define EMULATE_FAST_INT
#ifndef inline
#define inline __inline
#endif

#if defined(__SYMBIAN32__)
#define EMULATE_INTTYPES
#endif


#ifndef __MINGW32__
#define __attribute__(s)
#endif

#endif
#include "ts_muxer.h"

#define USE_GPAC_MPEG2TS
#undef USE_GPAC_MPEG2TS

#ifdef USE_GPAC_MPEG2TS
#include "gpac_ts_muxer.c"
#else
#include "ffmpeg_ts_muxer.c"
#endif /* USE_GPAC_MPEG2TS */

#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
#include <libavutil/avutil.h>

/* This number * 188 should be lower than the UDP packet size */
#define TS_PACKETS_PER_UDP_PACKET 1

#define audioCodecBitrate 96000
#include <unistd.h>

static const u32 maxFPS = 25;

static const char * moduleName = "AVRedirect";

static const char * AVR_VIDEO_CODEC_OPTION = "VideoCodec";


#define AVR_TIMERS_LENGHT 25

#define U32_ABS( a, b ) (a > b ? a - b : b - a)

#define DUMP_MP3
#undef DUMP_MP3

/**
 * This thread sends the frame to TS mux
 * \param Parameter The GF_AVRedirect pointer
 */
static Bool audio_encoding_thread_run(void *param)
{
    u8 * inBuff;
    u8 * outBuff;
    u32 inBuffSize, outBuffSize, samplesReaden, toRead;
    u64 myTime = 0;
    u32 frameCountSinceReset = 0;
    u32 lastCurrentTime;
    outBuffSize = FF_MIN_BUFFER_SIZE;

    outBuff = malloc(outBuffSize* sizeof(u8));
    inBuff = NULL;
#ifdef DUMP_MP3
    FILE * mp3 = fopen("/tmp/dump.mp3", "w");
#endif /* DUMP_MP3 */
    Bool sendPts = 1;
    GF_AVRedirect * avr = (GF_AVRedirect*) param;
    AVCodecContext * ctx = NULL;
    assert( avr );
    gf_sc_add_audio_listener ( avr->term->compositor, &avr->audio_listen );
    while (avr->is_running && !ctx) {
        ctx = ts_get_audio_codec_context(avr->ts_implementation);
        gf_sleep(16);
    }
    if (!ctx) {
        goto exit;
    }

    printf("******* Audio Codec Context = %d/%d, start="LLU", frame_size=%u\n", ctx->time_base.num, ctx->time_base.den, ctx->timecode_frame_start, ctx->frame_size);
    samplesReaden = ctx->frame_size * ctx->channels;

    //printf("SETUP input sample size=%u, output samplesize=%u, buffsize=%u, samplesReaden=%u\n", ctx->input_sample_size, ctx->frame_size, sizeof(outbuf), samplesReaden);
    // 2 chars are needed for each short
    toRead = samplesReaden * 2;
    inBuffSize = toRead;
    inBuff = malloc(inBuffSize * sizeof(u8));
    while (avr->is_running && !avr->audioCurrentTime) {
        gf_sleep(16);
    }
    myTime = lastCurrentTime = avr->audioCurrentTime;
    frameCountSinceReset = 0;
    while (avr->is_running) {
        u32 readen;
        if (U32_ABS(avr->audioCurrentTime, myTime) > 25000) {
            //GF_LOG( GF_LOG_ERROR, GF_LOG_MODULE, ("[AVRedirect] Drift in audio : audioCurrentTime = %u, myTime=%u, resync...\n", avr->audioCurrentTime, myTime));<commit_msg>Fixed MSVC compilation<commit_after>/*
 *			GPAC - Multimedia Framework C SDK
 *
 *			Authors: <NAME>
 *			Copyright (c) 2010-20XX Telecom ParisTech
 *			All rights reserved
 *
 *  This file is part of GPAC / AVI Recorder demo module
 *
 *  GPAC 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, or (at your option)
 *  any later version.
 *
 *  GPAC 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 this library; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */
#include <stdlib.h>
#if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(__MINGW32__)

#define EMULATE_INTTYPES
#define EMULATE_FAST_INT
#ifndef inline
#define inline __inline
#endif

#if defined(__SYMBIAN32__)
#define EMULATE_INTTYPES
#endif


#ifndef __MINGW32__
#define __attribute__(s)
#endif

#endif
#include "ts_muxer.h"

#define USE_GPAC_MPEG2TS
#undef USE_GPAC_MPEG2TS

#ifdef USE_GPAC_MPEG2TS
#include "gpac_ts_muxer.c"
#else
#include "ffmpeg_ts_muxer.c"
#endif /* USE_GPAC_MPEG2TS */

#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
#include <libavutil/avutil.h>

/* This number * 188 should be lower than the UDP packet size */
#define TS_PACKETS_PER_UDP_PACKET 1

#define audioCodecBitrate 96000

#ifndef WIN32
#include <unistd.h>
#endif

static const u32 maxFPS = 25;

static const char * moduleName = "AVRedirect";

static const char * AVR_VIDEO_CODEC_OPTION = "VideoCodec";


#define AVR_TIMERS_LENGHT 25

#define U32_ABS( a, b ) (a > b ? a - b : b - a)

#define DUMP_MP3
#undef DUMP_MP3

/**
 * This thread sends the frame to TS mux
 * \param Parameter The GF_AVRedirect pointer
 */
static Bool audio_encoding_thread_run(void *param)
{
    u8 * inBuff;
    u8 * outBuff;
    u32 inBuffSize, outBuffSize, samplesReaden, toRead;
    u64 myTime = 0;
    u32 frameCountSinceReset = 0;
    u32 lastCurrentTime;
    Bool sendPts = 1;
    GF_AVRedirect * avr = (GF_AVRedirect*) param;
    AVCodecContext * ctx = NULL;
    assert( avr );

	outBuffSize = FF_MIN_BUFFER_SIZE;

    outBuff = malloc(outBuffSize* sizeof(u8));
    inBuff = NULL;
#ifdef DUMP_MP3
    FILE * mp3 = fopen("/tmp/dump.mp3", "w");
#endif /* DUMP_MP3 */
    sendPts = 1;
    gf_sc_add_audio_listener ( avr->term->compositor, &avr->audio_listen );
    while (avr->is_running && !ctx) {
        ctx = ts_get_audio_codec_context(avr->ts_implementation);
        gf_sleep(16);
    }
    if (!ctx) {
        goto exit;
    }

    printf("******* Audio Codec Context = %d/%d, start="LLU", frame_size=%u\n", ctx->time_base.num, ctx->time_base.den, ctx->timecode_frame_start, ctx->frame_size);
    samplesReaden = ctx->frame_size * ctx->channels;

    //printf("SETUP input sample size=%u, output samplesize=%u, buffsize=%u, samplesReaden=%u\n", ctx->input_sample_size, ctx->frame_size, sizeof(outbuf), samplesReaden);
    // 2 chars are needed for each short
    toRead = samplesReaden * 2;
    inBuffSize = toRead;
    inBuff = malloc(inBuffSize * sizeof(u8));
    while (avr->is_running && !avr->audioCurrentTime) {
        gf_sleep(16);
    }
    myTime = lastCurrentTime = avr->audioCurrentTime;
    frameCountSinceReset = 0;
    while (avr->is_running) {
        u32 readen;
        if (U32_ABS(avr->audioCurrentTime, myTime) > 25000) {
            //GF_LOG( GF_LOG_ERROR, GF_LOG_MODULE, ("[AVRedirect] Drift in audio : audioCurrentTime = %u, myTime=%u, resync...\n", avr->audioCurrentTime, myTime));
{'fraction_non_alphanumeric': 0.1098643006263048, 'fraction_numerical': 0.02205114822546973, 'mean_word_length': 3.772727272727273, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1190703', 'n_tokens_mistral': 2820, 'n_tokens_neox': 2664, 'n_words': 770}