Ticket #43: ffmpeg-jack-osx.patch

File ffmpeg-jack-osx.patch, 3.5 KB (added by Hanspeter Niederstrasser, 15 years ago)

provides semaphore_* when HAVE_MACH_SEMAPHORE_H is set

  • configure

    diff --git a/configure b/configure
    index 3fceb31..a0317d4 100755
    a b HAVE_LIST="  
    10851085    lrint
    10861086    lrintf
    10871087    lzo1x_999_compress
     1088    mach_semaphore_h
    10881089    machine_ioctl_bt848_h
    10891090    machine_ioctl_meteor_h
    10901091    malloc_h
    ffserver_extralibs='$ldl'  
    15001501
    15011502doc_deps="texi2html"
    15021503
     1504mach_semaphore_deps="mach_semaphore_h"
     1505
    15031506# tests
    15041507
    15051508test_deps(){
    check_header soundcard.h  
    29512954
    29522955enabled_any alsa_indev alsa_outdev && check_lib2 alsa/asoundlib.h snd_pcm_htimestamp -lasound
    29532956
     2957check_header mach/semaphore.h
     2958
    29542959enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack
    29552960
    29562961enabled_any sndio_indev sndio_outdev && check_lib2 sndio.h sio_open -lsndio
  • libavdevice/jack_audio.c

    diff --git a/libavdevice/jack_audio.c b/libavdevice/jack_audio.c
    index 9062e7f..274380d 100644
    a b  
    2121 */
    2222
    2323#include "config.h"
     24#ifdef HAVE_MACH_SEMAPHORE_H
     25#include <mach/task.h>
     26#include <mach/semaphore.h>
     27#endif
    2428#include <semaphore.h>
     29
    2530#include <jack/jack.h>
    2631
    2732#include "libavutil/log.h"
     
    3843typedef struct {
    3944    jack_client_t * client;
    4045    int             activated;
     46#ifdef HAVE_MACH_SEMAPHORE_H
     47    semaphore_t     packet_count;
     48#else
    4149    sem_t           packet_count;
     50#endif
    4251    jack_nframes_t  sample_rate;
    4352    jack_nframes_t  buffer_size;
    4453    jack_port_t **  ports;
    static int process_callback(jack_nframes_t nframes, void *arg)  
    99108
    100109    /* Send the now filled packet back, and increase packet counter */
    101110    av_fifo_generic_write(self->filled_pkts, &pkt, sizeof(pkt), NULL);
     111#ifdef HAVE_MACH_SEMAPHORE_H
     112    semaphore_signal(self->packet_count);
     113#else
    102114    sem_post(&self->packet_count);
     115#endif
    103116
    104117    return 0;
    105118}
    static int start_jack(AVFormatContext *context, AVFormatParameters *params)  
    150163        return AVERROR(EIO);
    151164    }
    152165
     166#ifdef HAVE_MACH_SEMAPHORE_H
     167    semaphore_create(TASK_NULL, &self->packet_count, 0, 0);
     168#else
    153169    sem_init(&self->packet_count, 0, 0);
     170#endif
    154171
    155172    self->sample_rate = jack_get_sample_rate(self->client);
    156173    self->nports      = params->channels;
    static void stop_jack(JackData *self)  
    212229            jack_deactivate(self->client);
    213230        jack_client_close(self->client);
    214231    }
     232#ifdef HAVE_MACH_SEMAPHORE_H
     233    semaphore_destroy(TASK_NULL, self->packet_count);
     234#else
    215235    sem_destroy(&self->packet_count);
     236#endif
    216237    free_pkt_fifo(self->new_pkts);
    217238    free_pkt_fifo(self->filled_pkts);
    218239    av_freep(&self->ports);
    static int audio_read_header(AVFormatContext *context, AVFormatParameters *param  
    253274static int audio_read_packet(AVFormatContext *context, AVPacket *pkt)
    254275{
    255276    JackData *self = context->priv_data;
     277#ifdef HAVE_MACH_SEMAPHORE_H
     278    mach_timespec_t timeout = {0, 0};
     279#else
    256280    struct timespec timeout = {0, 0};
     281#endif
    257282    int test;
    258283
    259284    /* Activate the JACK client on first packet read. Activating the JACK client
    static int audio_read_packet(AVFormatContext *context, AVPacket *pkt)  
    274299
    275300    /* Wait for a packet comming back from process_callback(), if one isn't available yet */
    276301    timeout.tv_sec = av_gettime() / 1000000 + 2;
     302#ifdef HAVE_MACH_SEMAPHORE_H
     303    if (semaphore_timedwait(self->packet_count, timeout)) {
     304#else
    277305    if (sem_timedwait(&self->packet_count, &timeout)) {
     306#endif
    278307        if (errno == ETIMEDOUT) {
    279308            av_log(context, AV_LOG_ERROR,
    280309                   "Input error: timed out when waiting for JACK process callback output\n");