µroar Manual Philipp ph3-der-loewe Schafft

Similar documents
Experiment 6 The Real World Interface

CSE 410: Systems Programming

Operating Systems. Lecture 06. System Calls (Exec, Open, Read, Write) Inter-process Communication in Unix/Linux (PIPE), Use of PIPE on command line

Processes often need to communicate. CSCB09: Software Tools and Systems Programming. Solution: Pipes. Recall: I/O mechanisms in C

File Descriptors and Piping

Maria Hybinette, UGA. ! One easy way to communicate is to use files. ! File descriptors. 3 Maria Hybinette, UGA. ! Simple example: who sort

CSE 333 SECTION 3. POSIX I/O Functions

CS240: Programming in C

Networked Applications: Sockets. End System: Computer on the Net

CSC209H Lecture 6. Dan Zingaro. February 11, 2015

Lecture 8 Dynamic Memory Allocation

Socket Programming. #In the name of Allah. Computer Engineering Department Sharif University of Technology CE443- Computer Networks

Networked Applications: Sockets. Goals of Todayʼs Lecture. End System: Computer on the ʻNet. Client-server paradigm End systems Clients and servers

Dotstack Porting Guide.

CSE 333 Section 8 - Client-Side Networking

Processes. Johan Montelius KTH

Dynamic memory. EECS 211 Winter 2019

A process. the stack

Hybrid of client-server and P2P. Pure P2P Architecture. App-layer Protocols. Communicating Processes. Transport Service Requirements

CSE 333 SECTION 3. POSIX I/O Functions

CMSC 216 Introduction to Computer Systems Lecture 17 Process Control and System-Level I/O

Section 3: File I/O, JSON, Generics. Meghan Cowan

Workshop on Inter Process Communication Solutions

System Call. Preview. System Call. System Call. System Call 9/7/2018

CSE 333 Midterm Exam 2/12/16. Name UW ID#

CSMC 412. Computer Networks Prof. Ashok K Agrawala Ashok Agrawala Set 2. September 15 CMSC417 Set 2 1

Files. Eric McCreath

COSC Operating Systems Design, Fall Lecture Note: Unnamed Pipe and Shared Memory. Unnamed Pipes

API Interlude: Process Creation (DRAFT)

Protecting Communication with SSL

Application Programming Interfaces

File and Directories. Advanced Programming in the UNIX Environment

Important Dates. October 27 th Homework 2 Due. October 29 th Midterm

libqsearch A library designed for fast multiple pattern matching

APSIN x000 API Description

#define PERLIO_NOT_STDIO 0 /* For co-existence with stdio only */ #include <perlio.h> /* Usually via #include <perl.h> */

Communication. Serial port programming

CS360 Midterm 2 Spring, 2016 James S. Plank March 10, 2016

CMPS 105 Systems Programming. Prof. Darrell Long E2.371

Application Note: AN00152 xscope - Bi-Directional Endpoint

Files and the Filesystems. Linux Files

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

MSc Integrated Electronics Networks Assignment. Investigation of TCP/IP Sockets and Ports. Gavin Cameron

CSE 333 Lecture 16 - network programming intro

User's Manual. USB 2.0 Audio PCA with 16 Bit I/O, 4 x 4 Audio Mixer

we are here Page 1 Recall: How do we Hide I/O Latency? I/O & Storage Layers Recall: C Low level I/O

CS307 Operating Systems Processes

Processes. Process Concept. The Process. The Process (Cont.) Process Control Block (PCB) Process State

Linux Device Drivers Interrupt Requests

CBLORB. The Program. Chapter 2

Processes. Operating System Concepts with Java. 4.1 Sana a University, Dr aimen

Today: Process Management. The Big Picture So Far. What's in a Process? Example Process State in Memory

Computer Networks Prof. Ashok K. Agrawala

Socket programming in C

CS , Spring Sample Exam 3

Socket Programming for TCP and UDP

The Big Picture So Far. Today: Process Management

NPTEL Course Jan K. Gopinath Indian Institute of Science

Operating systems. Lecture 7

Concurrent Programming. Concurrent Programming with Processes and Threads

The Big Picture So Far. Chapter 4: Processes

CIS 2107 Computer Systems and Low-Level Programming Fall 2011 Midterm

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430

LibSysCTr(3) System Call Tracing Library LibSysCTr(3)

Preview. Interprocess Communication with Pipe. Pipe from the Parent to the child Pipe from the child to the parent FIFO popen() with r Popen() with w

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

Fall 2017 :: CSE 306. File Systems Basics. Nima Honarmand

Signal Example 1. Signal Example 2

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.

Final Exam. Fall Semester 2016 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

Process Management! Goals of this Lecture!

UNIT III - APPLICATION DEVELOPMENT. TCP Echo Server

CSC209H Lecture 3. Dan Zingaro. January 21, 2015

Operating Systems 2010/2011

The Big Picture So Far. Chapter 4: Processes

CSC 271 Software I: Utilities and Internals

Embedded System Design

EECS 3221 Operating System Fundamentals

EECS 3221 Operating System Fundamentals

CS Operating Systems Lab 3: UNIX Processes

#include <tobii/tobii.h> char const* tobii_error_message( tobii_error_t error );

Final Exam. Fall Semester 2016 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

Inter-process communication (IPC)

Computer 2 App1. App3 API Library. App3. API Library. Local Clipboard

TCP: Three-way handshake

UNIX System Programming

Chapter 3: Processes. Operating System Concepts 9 th Edition

Problem 1: Concepts (Please be concise)

Slide Set 8. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Memory management. Johan Montelius KTH

Unix-Linux 2. Unix is supposed to leave room in the process table for a superuser process that could be used to kill errant processes.

10. I/O System Library

UDP CONNECT TO A SERVER

Interprocess Communication. Originally multiple approaches Today more standard some differences between distributions still exist

Cuckoo Monitor Documentation

Systems Programming. 08. Standard I/O Library. Alexander Holupirek

Standards / Extensions C or C++ Dependencies POSIX.1 XPG4 XPG4.2 Single UNIX Specification, Version 3

OS COMPONENTS OVERVIEW OF UNIX FILE I/O. CS124 Operating Systems Fall , Lecture 2

Linked data structures. EECS 211 Winter 2019

Transcription:

µroar Manual Philipp ph3-der-loewe Schafft April 26, 2010

Contents Contens 1 1 Programming with libmuroar 2 1.1 Connecting to sever and creation of streams............ 2 1.2 Portable IO with extended IO functions.............. 3 1.3 Checking if a server exists...................... 3 1.4 Sending a notify beep........................ 4 2 Quick reference 7 2.1 Constants and Magics........................ 7 2.1.1 Directions and Stream Types................ 7 2.1.2 Codecs............................. 8 2.1.3 Network Constants...................... 8 2.1.4 Command Constants..................... 8 2.2 Basic functions............................ 9 2.3 Extended IO functions........................ 10 1

Chapter 1 Programming with libmuroar 1.1 Connecting to sever and creation of streams In order to create a stream on a server you first need to open the connection to the server. After the connection has been successfully established you can connect the stream to the server. To connect you have to call the function muroar connect() like this: int fh; if ( (fh = muroar_connect(server_address, "myapp")) == -1 ) { // handle errors here After the connection has been established you now can connect the stream to the server. To do this you need to call the function muroar stream() like this: if ( muroar_stream(fh, MUROAR_PLAY_WAVE, NULL, MUROAR_CODEC_PCM, rate, channels, bits) == -1 ) { // handle errors here Now the stream is ready to write audio data to it. In case you want to write MIDI or Light Control data you need to change the direction parameter. See section 2.1.1 for a list of possible values. In case you want to use non native signed PCM data you need to change the codec to the correct value. See section 2.1.2 for symbolic codec constants. At end of stream you need to close the socket. This need to be done by calling muroar close() like this: 2

CHAPTER 1. PROGRAMMING WITH LIBMUROAR 3 if ( muroar_close(fh) == -1 ) { // handle errors here On how to do portable IO on your stream see the next section. 1.2 Portable IO with extended IO functions As different Operating Systems need different functions to read and write to sockets you should consider using µroar s portable IO functions for reading and writing. They will handle all the Operating System depending stuff. Those functions work basically like the read() and write() function on a POSIX system. They will return the number of bytes actually read or written or 1 on error. If they do not return the same number of bytes as requested you should wait before calling them another time. Calling them again with the rest of the buffer is not needed as they will loop internally until really no data can be read or written at the moment any more. Example of reading some data and writing them to another socket: ssize_t ret_read, ret_write; ret_read = muroar_read(fh, buffer, buffer_len); if ( ret_read == -1 ) { // handle errors here else if ( ret_read == 0 ) { // nothing left or EOF else { ret_write = muroar_write(fh, buffer, ret_read); if ( ret_write == -1 ) { // handle errors here else if ( ret_write < ret_read ) { // not all bytes have been written else { // all bytes have been written, no error 1.3 Checking if a server exists In order to check the presence of a server you can simply call muroar connect() and check the return value. If the function returns -1 the server is not existing at the given address or does not respond.

CHAPTER 1. PROGRAMMING WITH LIBMUROAR 4 If the connection can be established you need to call muroar quit() to disconnect from the server. The socket is closed and all used buffers are freed by using this function. You must not call muroar close() after this call returned. A complete example of a testing function may look like this: // return a true value in case a server is found: int test_server(char * server) { int fh; if ( (fh = muroar_connect(server, "myapp")) == -1 ) return 0; if ( muroar_quit(fh) == -1 ) return 0; return 1; 1.4 Sending a notify beep To send a notify beep you first need to connect to the server using muroar connect(). After you have connect you can send a notify beep using muroar beep(). The function takes a open file handle to the server that is not connected to a stream. You must not call muroar stream() on the file handle before calling muroar beep(). After you are done you can disconnect using muroar quit(). The beep will end as soon as it finises (the playback time of the beep is over) or you close the connection to the server. This means that you need to keep the connection up as long as the beep is still playing. If your application uses beeps regularly you should keep the connection to the server open and close it at program termination. A simple example: #include <muroar.h> #include <unistd.h> int main (void) { int fh; if ( (fh = muroar_connect(null, "muroarbeep")) == -1 ) return 1; muroar_beep(fh); // may return -1 on error. // real world applications need to check this! sleep(1);

CHAPTER 1. PROGRAMMING WITH LIBMUROAR 5 muroar_quit(fh); // we ignore errors here, too, as above. return 0; A more complex example using a global connection. #include <muroar.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> void do_something(int i); int roar_connection = -1; static void roar_exit_callback (void) { if ( roar_connection!= -1 ) muroar_quit(roar_connection); int main (void) { int i; roar_connection = muroar_connect(null, "muroarbeep"); if ( roar_connection == -1 ) { fpirntf(stderr, "Can not connect to RoarAudio Server!\n"); return 1; atexit(roar_exit_callback); for (i = 0; ; i++) do_something(i); return 1; void do_something(int i) { printf("%i...\n", i); if ( i % 2 ) muroar_beep(roar_connection); // we ignore errors here, // real world applications // need to check! sleep(1); if ( i == 8 ) exit(0);

CHAPTER 1. PROGRAMMING WITH LIBMUROAR 6 This example program counts from zero to eight beeping every odd number. The output with <beep> being a beep via RoarAudio looks like this: 0... 1... <beep> 2... 3... <beep> 4... 5... <beep> 6... 7... <beep> 8... The function roar exit callback() in the given example will disconnect the connection to the server as soon as the program terminates normally using return from main() or exit().

Chapter 2 Quick reference 2.1 Constants and Magics 2.1.1 Directions and Stream Types #define MUROAR_PLAY_WAVE 1 #define MUROAR_PLAY_MIDI 12 #define MUROAR_PLAY_LIGHT 14 #define MUROAR_RECORD_WAVE 2 #define MUROAR_MONITOR_WAVE 3 #define MUROAR_MONITOR_MIDI 13 #define MUROAR_MONITOR_LIGHT 15 #define MUROAR_FILTER_WAVE 4 Those constants are the symbolic names for the direction parameter of the muroar stream() function. The name consists of two important part: the real direction and the subsystem the stream should use. The direction can be PLAY for a playback stream (a stream that sends data to the sound server) or MON- ITOR for monitoring streams which are used to read the mixed signal from the sound server. In addition there is RECORD and FILTER which are currently only supported by the Waveform Subsystem. A record stream is a stream that reads the audio data from one stream before it is mixed. This is similar to using a thru stream. The only difference is that a record stream supports transcoding. As this is not needed by other subsystems you may simply use thru streams. The filter stream is a stream that can be used to filter audio data. You need to read data from it, filter it, and write it back to the stream. You need to use exactly the same values for the stream as the server s mixer has. Filter streams are currently only supported by the Waveform Subsystem. The last part of the name is the name of the subsystem to use. WAVE for the Waveform Subsystem used by PCM or PCM like data, MIDI for MIDI music and LIGHT for the Light Control Subsystem which may be used to control a light setup. For Audio playback you normally want to use the Waveform Subsystem. 7

CHAPTER 2. QUICK REFERENCE 8 2.1.2 Codecs Constant codecs: #define MUROAR_CODEC_PCM_S_LE 0x01 #define MUROAR_CODEC_PCM_S_BE 0x02 #define MUROAR_CODEC_PCM_S_PDP 0x03 #define MUROAR_CODEC_PCM_U_LE 0x05 #define MUROAR_CODEC_PCM_U_BE 0x06 #define MUROAR_CODEC_PCM_U_PDP 0x07 #define MUROAR_CODEC_OGG_VORBIS 0x10 #define MUROAR_CODEC_RIFF_WAVE 0x20 #define MUROAR_CODEC_ALAW 0x30 #define MUROAR_CODEC_MULAW 0x34 #define MUROAR_CODEC_MIDI 0x60 #define MUROAR_CODEC_DMX512 0x70 #define MUROAR_CODEC_ROARDMX 0x71 Those constants are the symbolic names for the used codecs. For default and native byte order constants see the next section. Magical codecs: #define MUROAR_CODEC_PCM_S #define MUROAR_CODEC_PCM_U #define MUROAR_CODEC_PCM MUROAR_CODEC_PCM_S_* MUROAR_CODEC_PCM_U_* MUROAR_CODEC_PCM_S Those constants are aliases for the similar named constants for the native byte order. For example on a big endian system MUROAR CODEC PCM S will be an alias for MUROAR CODEC PCM S BE. MUROAR CODEC PCM is an alias for MUROAR CODEC PCM S. Those constants are to be used as default codecs for the waveform subsystem. 2.1.3 Network Constants #define MUROAR_PORT 16002 The constant MUROAR PORT defines the default TCP port for the RoarAudio protocol. 2.1.4 Command Constants #define MUROAR_CMD_NOOP 0 #define MUROAR_CMD_IDENTIFY 1 #define MUROAR_CMD_AUTH 2 #define MUROAR_CMD_NEW_STREAM 3 #define MUROAR_CMD_SET_META 4 #define MUROAR_CMD_EXEC_STREAM 5 #define MUROAR_CMD_QUIT 6 #define MUROAR_CMD_GET_STANDBY 7 #define MUROAR_CMD_SET_STANDBY 8

CHAPTER 2. QUICK REFERENCE 9 #define MUROAR_CMD_SERVER_INFO 9 #define MUROAR_CMD_SERVER_STATS 10 #define MUROAR_CMD_SERVER_OINFO 11 #define MUROAR_CMD_ADD_DATA 12 #define MUROAR_CMD_EXIT 13 #define MUROAR_CMD_LIST_STREAMS 14 #define MUROAR_CMD_LIST_CLIENTS 15 #define MUROAR_CMD_GET_CLIENT 16 #define MUROAR_CMD_GET_STREAM 17 #define MUROAR_CMD_KICK 18 #define MUROAR_CMD_SET_VOL 19 #define MUROAR_CMD_GET_VOL 20 #define MUROAR_CMD_CON_STREAM 21 #define MUROAR_CMD_GET_META 22 #define MUROAR_CMD_LIST_META 23 #define MUROAR_CMD_BEEP 24 #define MUROAR_CMD_GET_STREAM_PARA 27 #define MUROAR_CMD_SET_STREAM_PARA 28 #define MUROAR_CMD_ATTACH 29 #define MUROAR_CMD_PASSFH 30 #define MUROAR_CMD_GETTIMEOFDAY 31 #define MUROAR_CMD_WHOAMI 32 #define MUROAR_CMD_OK 254 /* return value OK */ #define MUROAR_CMD_ERROR 255 /* return value ERROR */ The above constants define the values for the command parameter used in the messages on the wire. They are of no intrest for most developers. For there meaning please see the complet RoarAudio Manual. 2.2 Basic functions int muroar_connect(char * server, char * name); This function connects to a RoarAudio server. It opens a control connection. int muroar_quit (int fh); This function closes a control connection opened with muroar connect(). int muroar_stream (int fh, int dir, int * stream, int codec, int rate, int channels, int bits); This function creates, connects and execs a stream on the already connected control connection converting the connection into a data connection. int muroar_close (int fh); This function closes a data connection created with muroar stream(). int muroar_beep (int fh);

CHAPTER 2. QUICK REFERENCE 10 This function asks the server to do a simple beep. You can use this on file handles opened with muroar connect() which are not used with muroar stream() nor closed with muroar close(). 2.3 Extended IO functions ssize_t muroar_write (int fh, const void * buf, size_t len); ssize_t muroar_read (int fh, void * buf, size_t len); Those both functions behave mostly like the POSIX functions read(2) and write(2) expect that they will retry reading or writing until a final error happens. This is done to avoid different maximum write sizes on different operating systems so the application does not need to care about them.