Example #1
0
 void JackNetMasterInterface::FatalRecvError()
 {
     // fatal connection issue, exit
     jack_error("Recv connection lost error = %s, '%s' exiting", StrError(NET_ERROR_CODE), fParams.fName);
     // ask to the manager to properly remove the master
     Exit();
     // UGLY temporary way to be sure the thread does not call code possibly causing a deadlock in JackEngine.
     ThreadExit();
 }
int JackPortAudioDriver::SetBufferSize(jack_nframes_t buffer_size)
{
    PaError err;

    if ((err = Pa_CloseStream(fStream)) != paNoError) {
        jack_error("Pa_CloseStream error = %s", Pa_GetErrorText(err));
        return -1;
    }

    err = OpenStream(buffer_size);
    if (err != paNoError) {
        jack_error("Pa_OpenStream error %d = %s", err, Pa_GetErrorText(err));
        return -1;
    } else {
        JackAudioDriver::SetBufferSize(buffer_size); // Generic change, never fails
        return 0;
    }
}
Example #3
0
int JackLoopbackDriver::ProcessWriteSync()
{
    // Suspend on connected clients in the graph
    if (SuspendRefNum() < 0) {
        jack_error("JackLoopbackDriver::ProcessWriteSync - SuspendRefNum error");
        return -1;
    }
    return 0;
}
Example #4
0
 //utility *********************************************************************************************************
 SERVER_EXPORT int GetHostName(char * name, int size)
 {
     if (gethostname(name, size) == SOCKET_ERROR) {
         jack_error("Can't get 'hostname' : %s", strerror(NET_ERROR_CODE));
         strcpy(name, "default");
         return -1;
     }
     return 0;
 }
int JackSocketServerChannel::Start()
{
    if (fThread.Start() != 0) {
        jack_error("Cannot start Jack server listener");
        return -1;
    } else {
        return 0;
    }
}
    bool JackBasePosixMutex::Lock()
    {
        pthread_t current_thread = pthread_self();

        if (!pthread_equal(current_thread, fOwner)) {
            int res = pthread_mutex_lock(&fMutex);
            if (res == 0) {
                fOwner = current_thread;
                return true;
            } else {
                jack_error("JackBasePosixMutex::Lock res = %d", res);
                return false;
            }
        } else {
            jack_error("JackBasePosixMutex::Lock mutex already locked by thread = %d", current_thread);
            return false;
        }
    }
Example #7
0
static
struct jackctl_parameter *
jackctl_add_parameter(
    JSList ** parameters_list_ptr_ptr,
    char id,
    const char * name,
    const char * short_description,
    const char * long_description,
    jackctl_param_type_t type,
    union jackctl_parameter_value * value_ptr,
    union jackctl_parameter_value * default_value_ptr,
    union jackctl_parameter_value value,
    jack_driver_param_constraint_desc_t * constraint_ptr)
{
    struct jackctl_parameter * parameter_ptr;

    parameter_ptr = (struct jackctl_parameter *)malloc(sizeof(struct jackctl_parameter));
    if (parameter_ptr == NULL)
    {
        jack_error("Cannot allocate memory for jackctl_parameter structure.");
        goto fail;
    }

    parameter_ptr->name = name;
    parameter_ptr->short_description = short_description;
    parameter_ptr->long_description = long_description;
    parameter_ptr->type = type;
    parameter_ptr->is_set = false;

    if (value_ptr == NULL)
    {
        value_ptr = &parameter_ptr->value;
    }

    if (default_value_ptr == NULL)
    {
        default_value_ptr = &parameter_ptr->default_value;
    }

    parameter_ptr->value_ptr = value_ptr;
    parameter_ptr->default_value_ptr = default_value_ptr;

    *value_ptr = *default_value_ptr = value;

    parameter_ptr->driver_ptr = NULL;
    parameter_ptr->driver_parameter_ptr = NULL;
    parameter_ptr->id = id;
    parameter_ptr->constraint_ptr = constraint_ptr;

    *parameters_list_ptr_ptr = jack_slist_append(*parameters_list_ptr_ptr, parameter_ptr);

    return parameter_ptr;

fail:
    return NULL;
}
Example #8
0
void *
jack_port_get_buffer (jack_port_t *port, jack_nframes_t nframes)
{
	JSList *node, *next;

	/* Output port.  The buffer was assigned by the engine
	   when the port was registered.
	*/
	if (port->shared->flags & JackPortIsOutput) {
		if (port->tied) {
			return jack_port_get_buffer (port->tied, nframes);
		}
                
                if (port->client_segment_base == NULL || *port->client_segment_base == MAP_FAILED) {
                        return NULL;
                }

		return jack_output_port_buffer (port);
	}

	/* Input port.  Since this can only be called from the
	   process() callback, and since no connections can be
	   made/broken during this phase (enforced by the jack
	   server), there is no need to take the connection lock here
	*/
	if ((node = port->connections) == NULL) {
		
                if (port->client_segment_base == NULL || *port->client_segment_base == MAP_FAILED) {
                        return NULL;
                }

		/* no connections; return a zero-filled buffer */
		return (void *) (*(port->client_segment_base) + port->type_info->zero_buffer_offset);
	}

	if ((next = jack_slist_next (node)) == NULL) {

		/* one connection: use zero-copy mode - just pass
		   the buffer of the connected (output) port.
		*/
		return jack_port_get_buffer (((jack_port_t *) node->data),
					     nframes);
	}

	/* Multiple connections.  Use a local buffer and mix the
	   incoming data into that buffer.  We have already
	   established the existence of a mixdown function during the
	   connection process.
	*/
	if (port->mix_buffer == NULL) {
		jack_error( "internal jack error: mix_buffer not allocated" );
		return NULL;
	}
	port->fptr.mixdown (port, nframes);
	return (void *) port->mix_buffer;
}
Example #9
0
static inline void
log_result (char *msg, int res)
{
	char outbuf[500];

	snprintf (outbuf, sizeof(outbuf),
		  "jack_client_create_thread: error %d %s: %s",
		  res, msg, strerror (res));
	jack_error (outbuf);
}
Example #10
0
bool jack_tls_free_key(jack_tls_key key)
{
    if (!TlsFree(key))
    {
        jack_error("TlsFree() failed. Error is %d", (unsigned int)GetLastError());
        return false;
    }

    return true;
}
Example #11
0
int JackMidiDriver::ProcessReadSync()
{
    int res = 0;
    
    jack_log("JackMidiDriver::ProcessReadSync");

    // Read input buffers for the current cycle
    if (Read() < 0) {
        jack_error("JackMidiDriver::ProcessReadSync: read error");
        res = -1;
    }

    if (ResumeRefNum() < 0) {
        jack_error("JackMidiDriver::ProcessReadSync: ResumeRefNum error");
        res = -1;
    }

    return res;
}
Example #12
0
int JackMidiDriver::ProcessWriteSync()
{
    int res = 0;
    
    jack_log("JackMidiDriver::ProcessWriteSync");

    if (SuspendRefNum() < 0) {
        jack_error("JackMidiDriver::ProcessWriteSync: SuspendRefNum error");
        res = -1;
    }

    // Write output buffers from the current cycle
    if (Write() < 0) {
        jack_error("JackMidiDriver::ProcessWriteSync: write error");
        res = -1;
    }

    return res;
}
Example #13
0
    int Shm::attach_shm_read (jack_shm_info_t* si) {
        jack_shm_registry_t *registry = &jack_shm_registry[si->index];

        if((si->ptr.attached_at = shm_addr(registry->fd)) == NULL) {
            jack_error ("Cannot mmap shm segment %s", registry->id);
            close (si->fd);
            return -1;
        }
        return 0;
    }
Example #14
0
bool jack_tls_set(jack_tls_key key, void *data_ptr)
{
    if (!TlsSetValue(key, data_ptr))
    {
        jack_error("TlsSetValue() failed. Error is %d", (unsigned int)GetLastError());
        return false;
    }

    return true;
}
Example #15
0
    int Shm::access_registry (jack_shm_info_t * ri) {
        jack_d("access_registry\n");
        /* registry must be locked */
		sp<IAndroidShm> service = getShmService();
		if(service == NULL){
			jack_error("shm service is null");
			return EINVAL;
		}
        int shm_fd = service->getRegistryIndex();

        strncpy (registry_id, JACK_REGISTRY_NAME, sizeof (registry_id) - 1);
        registry_id[sizeof (registry_id) - 1] = '\0';

        if(service->isAllocated(shm_fd) == FALSE) {
            //jack_error ("Cannot mmap shm registry segment (%s)",
            //        strerror (errno));
            jack_error ("Cannot mmap shm registry segment");
            //close (shm_fd);
            ri->ptr.attached_at = NULL;
            registry_fd = JACK_SHM_REGISTRY_FD;
            return EINVAL;
        }

        ri->fd = shm_fd;
        registry_fd = shm_fd;
        ri->ptr.attached_at = shm_addr(shm_fd);

        if(ri->ptr.attached_at == NULL) {
            ALOGE("attached pointer is null !");
            jack_shm_header = NULL;
            jack_shm_registry = NULL;
            return 0;
        }

        /* set up global pointers */
        ri->index = JACK_SHM_REGISTRY_INDEX;
        jack_shm_header = (jack_shm_header_t*)(ri->ptr.attached_at);
        jack_shm_registry = (jack_shm_registry_t *) (jack_shm_header + 1);

        jack_d("jack_shm_header[%p],jack_shm_registry[%p]", jack_shm_header, jack_shm_registry);
        //close (shm_fd); // steph
        return 0;
    }
Example #16
0
int
jack_port_untie (jack_port_t *port)
{
	if (port->tied == NULL) {
		jack_error ("port \"%s\" is not tied", port->shared->name);
		return -1;
	}
	port->tied = NULL;
	return 0;
}
Example #17
0
inline bool JackClient::WaitSync()
{
    // Suspend itself: wait on the input synchro
    if (GetGraphManager()->SuspendRefNum(GetClientControl(), fSynchroTable, 0x7FFFFFFF) < 0) {
        jack_error("SuspendRefNum error");
        return false;
    } else {
        return true;
    }
}
Example #18
0
 void JackNetInterface::SetRcvTimeOut()
 {
     if (!fSetTimeOut) {
         if (fSocket.SetTimeOut(fPacketTimeOut) == SOCKET_ERROR) {
             jack_error("Can't set rx timeout : %s", StrError(NET_ERROR_CODE));
             return;
         }
         fSetTimeOut = true;
     }
 }
Example #19
0
 void JackNetSlaveInterface::InitAPI()
 {
     // open Socket API with the first slave
     if (fSlaveCounter++ == 0) {
         if (SocketAPIInit() < 0) {
             jack_error("Can't init Socket API, exiting...");
             throw std::bad_alloc();
         }
     }
 }
Example #20
0
    char* Shm::shm_addr (unsigned int fd) {
        if(fd >= JACK_SHM_HEAP_ENOUGH_COUNT) {
            jack_error("ignore to get memory buffer : index[%d] is too big", fd);
            return NULL;
        }

		sp<IAndroidShm> service = Shm::getShmService();
		if(service == NULL){
			jack_error("shm service is null");
			return NULL;
		}
        mShmMemBase[fd] = service->getBuffer(fd);
        if(mShmMemBase[fd] == NULL) {
            jack_error("fail to get memory buffer");
            return NULL;
        }

        return ((char *) mShmMemBase[fd]->getBase());
    }
// Server side : publish the semaphore in the global namespace
bool JackMachSemaphore::Allocate(const char* name, const char* server_name, int value)
{
    BuildName(name, server_name, fName, sizeof(fName));
    mach_port_t task = mach_task_self();
    kern_return_t res;

    if (fBootPort == 0) {
        if ((res = task_get_bootstrap_port(task, &fBootPort)) != KERN_SUCCESS) {
            jack_error("Allocate: Can't find bootstrap mach port err = %s", mach_error_string(res));
            return false;
        }
    }

    if ((res = semaphore_create(task, &fSemaphore, SYNC_POLICY_FIFO, value)) != KERN_SUCCESS) {
        jack_error("Allocate: can create semaphore err = %s", mach_error_string(res));
        return false;
    }

    if ((res = bootstrap_register(fBootPort, fName, fSemaphore)) != KERN_SUCCESS) {
        jack_error("Allocate: can't check in mach semaphore name = %s err = %s", fName, mach_error_string(res));

        switch (res) {
            case BOOTSTRAP_SUCCESS :
                /* service not currently registered, "a good thing" (tm) */
                break;
            case BOOTSTRAP_NOT_PRIVILEGED :
                jack_log("bootstrap_register(): bootstrap not privileged");
                break;
            case BOOTSTRAP_SERVICE_ACTIVE :
                jack_log("bootstrap_register(): bootstrap service active");
                break;
            default :
                jack_log("bootstrap_register() err = %s", mach_error_string(res));
                break;
        }

        return false;
    }

    jack_log("JackMachSemaphore::Allocate name = %s", fName);
    return true;
}
bool JackPosixSemaphore::Wait()
{
    int res;

    while ((res = sem_wait(fSemaphore) < 0)) {
        jack_error("JackPosixSemaphore::Wait name = %s err = %s", fName, strerror(errno));
        if (errno != EINTR)
            break;
    }
    return (res == 0);
}
void JackSocketServerChannel::ClientCreate()
{
    jack_log("JackSocketServerChannel::ClientCreate socket");
    JackClientSocket* socket = fRequestListenSocket.Accept();
    if (socket) {
        fSocketTable[socket->GetFd()] = make_pair(-1, socket);
        fRebuild = true;
    } else {
        jack_error("Client socket cannot be created");
    }
}
int JackSocketServerNotifyChannel::Open(const char* server_name)
{
    if (fRequestSocket.Connect(jack_server_dir, server_name, 0) < 0) {
        jack_error("Cannot connect to server socket");
        return -1;
    } else {
        fRequestSocket.SetNonBlocking(true);
        JackServerGlobals::fRTNotificationSocket = fRequestSocket.GetFd();
        return 0;
    }
}
// Client side : get the published semaphore from server
bool JackMachSemaphore::ConnectInput(const char* name, const char* server_name)
{
    BuildName(name, server_name, fName, sizeof(fName));
    kern_return_t res;

    if (fBootPort == 0) {
        if ((res = task_get_bootstrap_port(mach_task_self(), &fBootPort)) != KERN_SUCCESS) {
            jack_error("Connect: can't find bootstrap port err = %s", mach_error_string(res));
            return false;
        }
    }

    if ((res = bootstrap_look_up(fBootPort, fName, &fSemaphore)) != KERN_SUCCESS) {
        jack_error("Connect: can't find mach semaphore name = %s err = %s", fName, mach_error_string(res));
        return false;
    }

    jack_log("JackMachSemaphore::Connect name = %s ", fName);
    return true;
}
Example #26
0
inline void JackClient::Error()
{
    jack_error("JackClient::Execute error name = %s", GetClientControl()->fName);
    // Hum... not sure about this, the following "close" code is called in the RT thread...
    int result;
    fThread.DropSelfRealTime();
    GetClientControl()->fActive = false;
    fChannel->ClientDeactivate(GetClientControl()->fRefNum, &result);
    ShutDown(jack_status_t(JackFailure | JackServerError), JACK_SERVER_FAILURE);
    fThread.Terminate();
}
bool JackSocketClientChannel::Init()
{
    jack_log("JackSocketClientChannel::Init");
    fNotificationSocket = fNotificationListenSocket.Accept();
    
    // No more needed
    fNotificationListenSocket.Close();
    
    // Setup context
    if (!jack_tls_set(JackGlobals::fNotificationThread, this)) {
        jack_error("Failed to set thread notification key");
    }

    if (!fNotificationSocket) {
        jack_error("JackSocketClientChannel: cannot establish notication socket");
        return false;
    } else {
        return true;
    }
}
Example #28
0
int
jack_attach_shm_read (jack_shm_info_t* si)
{
	if ((si->ptr.attached_at = shmat (jack_shm_registry[si->index].id, 0, SHM_RDONLY)) < 0) {
		jack_error ("Cannot attach shm segment (%s)",
			    strerror (errno));
		jack_release_shm_info (si->index);
		return -1;
	}
	return 0;
}
Example #29
0
void JackClient::OnInfoShutdown(JackInfoShutdownCallback callback, void *arg)
{
    if (IsActive()) {
        jack_error("You cannot set callbacks on an active client");
    } else {
        // Shutdown callback will either be an old API version or the new version (with info)
        GetClientControl()->fCallback[kShutDownCallback] = (callback != NULL);
        fInfoShutdownArg = arg;
        fInfoShutdown = callback;
    }
}
Example #30
0
static int get_fragment (int fd)
{
	int fragsize;

	if (ioctl (fd, SNDCTL_DSP_GETBLKSIZE, &fragsize) < 0) {
		jack_error ("OSS: failed to get fragment size: %s@%i, errno=%d",
			    __FILE__, __LINE__, errno);
		return 0;
	}
	return fragsize;
}