osx_write: kill superfluous semaphore code
[paraslash.git] / osx_writer.c
index c4a97e4b5ae9c0f2575f8239bb79c43dab45a8f7..b0d672c963443b7225ef2053871c3fb614b9df67 100644 (file)
@@ -32,7 +32,6 @@
 #include <CoreAudio/CoreAudio.h>
 #include <AudioUnit/AudioUnit.h>
 #include <AudioToolbox/DefaultAudioOutput.h>
-#include <semaphore.h>
 struct osx_buffer {
        float *buffer;
        long size;
@@ -47,10 +46,10 @@ struct private_osx_writer_data {
        short *ptr;
        AudioUnit output;
        char play;
-       sem_t *semaphore;
        osx_buffer *from; /* Current buffers */
        osx_buffer *to;
        unsigned samplerate;
+       unsigned channels;
 };
 
 
@@ -91,7 +90,6 @@ static void init_buffers(struct private_osx_writer_data *powd)
                (*ptrptr)->buffer = NULL;
                ptrptr = &(*ptrptr)->next;
                /* This buffer is ready for filling (of course, it is empty!) */
-               sem_post(powd->semaphore);
        }
        *ptrptr = powd->from = powd->to;
 }
@@ -145,6 +143,7 @@ static OSStatus osx_callback(void * inClientData,
                dest = outOutputData->mBuffers[i].mData;
                while (m > 0) {
                        if ((n = powd->from->remaining) <= 0) {
+                               PARA_INFO_LOG("%s", "buffer underrun\n");
                                /* no more bytes in the current read buffer! */
                                while ((n = powd->from->remaining) <= 0)
                                        /* wait for the results */
@@ -162,11 +161,8 @@ static OSStatus osx_callback(void * inClientData,
                        /* remember all done work */
                        m -= n;
                        powd->from->ptr += n;
-                       if ((powd->from->remaining -= n) <= 0) {
-                               /* tell that there's a buffer to fill */
-                               sem_post(powd->semaphore);
+                       if ((powd->from->remaining -= n) <= 0)
                                powd->from = powd->from->next;
-                       }
                }
        }
        return 0;
@@ -180,8 +176,7 @@ static int osx_writer_open(struct writer_node *wn)
        Component comp;
        AURenderCallbackStruct inputCallback = {osx_callback, powd};
        AudioStreamBasicDescription format;
-       char s[10];
-       int m, ret;
+       int ret;
        struct writer_node_group *wng = wn->wng;
        struct osx_write_args_info *conf = wn->conf;
 
@@ -223,12 +218,12 @@ static int osx_writer_open(struct writer_node *wn)
        format.mFormatFlags = kLinearPCMFormatFlagIsFloat
                | kLinearPCMFormatFlagIsPacked
                | kLinearPCMFormatFlagIsBigEndian;
-       /*
-        * We produce 2-channel audio. Now if we have a mega-super-hyper card for our
-        * audio, it is its problem to convert it to 8-, 16-, 32- or 1024-channel data.
-        */
+       if (!conf->channels_given && wng->channels)
+               powd->channels = *wng->channels;
+       else
+               powd->channels = conf->channels_arg;
+       format.mChannelsPerFrame = powd->channels;
        format.mFramesPerPacket = 1;
-       format.mChannelsPerFrame = 2;
        format.mBytesPerPacket = format.mChannelsPerFrame * sizeof(float);
        format.mBytesPerFrame = format.mFramesPerPacket * format.mBytesPerPacket;
        /* one of the most constant constants of the whole computer history */
@@ -238,16 +233,6 @@ static int osx_writer_open(struct writer_node *wn)
                        kAudioUnitScope_Input, 0, &format,
                        sizeof(AudioStreamBasicDescription)))
                goto e2;
-       /* init the semaphore */
-       strcpy(s, "/mpg123-0000");
-       do {
-               for (m = 10;; m--)
-                       if( (s[m]++) <= '9')
-                               break;
-                       else
-                               s[m] = '0';
-       } while ((powd->semaphore = sem_open(s, O_CREAT | O_EXCL, 0644, 0))
-               == (sem_t *)SEM_FAILED);
        init_buffers(powd);
        ret = -E_ADD_CALLBACK;
        if (AudioUnitSetProperty(powd->output, kAudioUnitProperty_SetRenderCallback,
@@ -289,7 +274,6 @@ static void osx_writer_close(struct writer_node *wn)
        AudioUnitUninitialize(powd->output);
        CloseComponent(powd->output);
        destroy_buffers(powd);
-       sem_close(powd->semaphore);
        free(powd);
 }