[0] | 1 | //sources.c: |
---|
| 2 | |
---|
| 3 | #include "roard.h" |
---|
| 4 | |
---|
| 5 | int sources_init (void) { |
---|
| 6 | g_source_client = -1; |
---|
| 7 | return 0; |
---|
| 8 | } |
---|
| 9 | |
---|
[64] | 10 | int sources_set_client (int client) { |
---|
| 11 | if ( client >= 0 ) { |
---|
| 12 | g_source_client = client; |
---|
| 13 | return 0; |
---|
| 14 | } else { |
---|
| 15 | return -1; |
---|
| 16 | } |
---|
| 17 | } |
---|
[0] | 18 | |
---|
| 19 | int sources_free (void) { |
---|
| 20 | return 0; |
---|
| 21 | } |
---|
| 22 | |
---|
[65] | 23 | int sources_add (char * driver, char * device, char * container, char * options, int primary) { |
---|
[67] | 24 | if ( strcmp(driver, "raw") == 0 ) { |
---|
[65] | 25 | return sources_add_raw(driver, device, container, options, primary); |
---|
[67] | 26 | } else if ( strcmp(driver, "wav") == 0 ) { |
---|
| 27 | return sources_add_wav(driver, device, container, options, primary); |
---|
[542] | 28 | } else if ( strcmp(driver, "cf") == 0 ) { |
---|
| 29 | return sources_add_cf(driver, device, container, options, primary); |
---|
[67] | 30 | } |
---|
[65] | 31 | |
---|
[0] | 32 | return -1; |
---|
| 33 | } |
---|
| 34 | |
---|
[65] | 35 | int sources_add_raw (char * driver, char * device, char * container, char * options, int primary) { |
---|
| 36 | int stream; |
---|
| 37 | int fh; |
---|
| 38 | struct roar_stream * s; |
---|
| 39 | |
---|
[566] | 40 | ROAR_WARN("sources_add_raw(*): The raw source is obsolete, use source 'cf' (default)!"); |
---|
| 41 | |
---|
[65] | 42 | if ( (fh = open(device, O_RDONLY, 0644)) == -1 ) { |
---|
| 43 | return -1; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | if ( (stream = streams_new()) == -1 ) { |
---|
| 47 | close(fh); |
---|
| 48 | return -1; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | streams_get(stream, (struct roar_stream_server **)&s); |
---|
| 52 | |
---|
| 53 | memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info)); |
---|
| 54 | |
---|
| 55 | s->dir = ROAR_DIR_PLAY; |
---|
| 56 | s->pos_rel_id = -1; |
---|
| 57 | |
---|
| 58 | streams_set_fh(stream, fh); |
---|
| 59 | |
---|
| 60 | client_stream_add(g_source_client, stream); |
---|
| 61 | |
---|
| 62 | return 0; |
---|
| 63 | } |
---|
| 64 | |
---|
[67] | 65 | int sources_add_wav (char * driver, char * device, char * container, char * options, int primary) { |
---|
| 66 | int stream; |
---|
| 67 | int fh; |
---|
| 68 | char buf[44]; |
---|
| 69 | struct roar_stream * s; |
---|
| 70 | |
---|
[566] | 71 | ROAR_WARN("sources_add_raw(*): The wav(e) source is obsolete, use source 'cf' (default)!"); |
---|
| 72 | |
---|
[67] | 73 | if ( (fh = open(device, O_RDONLY, 0644)) == -1 ) { |
---|
| 74 | return -1; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | if (read(fh, buf, 44) != 44) { |
---|
| 78 | close(fh); |
---|
| 79 | return -1; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | if ( (stream = streams_new()) == -1 ) { |
---|
| 83 | close(fh); |
---|
| 84 | return -1; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | streams_get(stream, (struct roar_stream_server **)&s); |
---|
| 88 | |
---|
| 89 | memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info)); |
---|
| 90 | |
---|
| 91 | memcpy(&(s->info.rate ), buf+24, 4); |
---|
| 92 | memcpy(&(s->info.channels), buf+22, 2); |
---|
| 93 | memcpy(&(s->info.bits ), buf+34, 2); |
---|
| 94 | |
---|
| 95 | s->dir = ROAR_DIR_PLAY; |
---|
| 96 | s->pos_rel_id = -1; |
---|
| 97 | |
---|
| 98 | streams_set_fh(stream, fh); |
---|
| 99 | |
---|
| 100 | client_stream_add(g_source_client, stream); |
---|
| 101 | |
---|
| 102 | return 0; |
---|
| 103 | } |
---|
[542] | 104 | |
---|
| 105 | int sources_add_cf (char * driver, char * device, char * container, char * options, int primary) { |
---|
[555] | 106 | int stream; |
---|
| 107 | int fh; |
---|
| 108 | int codec; |
---|
| 109 | int len; |
---|
| 110 | char buf[64]; |
---|
[542] | 111 | struct roar_stream * s; |
---|
| 112 | |
---|
| 113 | if ( (fh = open(device, O_RDONLY, 0644)) == -1 ) { |
---|
| 114 | return -1; |
---|
| 115 | } |
---|
| 116 | |
---|
[556] | 117 | // TODO: finy out a better way of doing auto detetion without need for seek! |
---|
[555] | 118 | if ( !options ) { |
---|
| 119 | if ( (len = read(fh, buf, 64)) < 1 ) { |
---|
| 120 | close(fh); |
---|
| 121 | return -1; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | if ( lseek(fh, -len, SEEK_CUR) == (off_t)-1 ) { |
---|
| 125 | close(fh); |
---|
| 126 | return -1; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | if ( (codec = roar_file_codecdetect(buf, len)) == -1 ) { |
---|
| 130 | close(fh); |
---|
| 131 | return -1; |
---|
| 132 | } |
---|
| 133 | } else { |
---|
| 134 | if ( (codec = roar_str2codec(options)) == -1 ) { |
---|
| 135 | close(fh); |
---|
| 136 | return -1; |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | |
---|
[542] | 140 | if ( (stream = streams_new()) == -1 ) { |
---|
| 141 | close(fh); |
---|
| 142 | return -1; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | streams_get(stream, (struct roar_stream_server **)&s); |
---|
| 146 | |
---|
| 147 | memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info)); |
---|
| 148 | |
---|
| 149 | s->dir = ROAR_DIR_PLAY; |
---|
| 150 | s->pos_rel_id = -1; |
---|
| 151 | s->info.codec = codec; |
---|
| 152 | |
---|
[566] | 153 | ROAR_STREAM_SERVER(s)->codec_orgi = codec; |
---|
| 154 | |
---|
[542] | 155 | streams_set_fh(stream, fh); |
---|
| 156 | |
---|
| 157 | client_stream_add(g_source_client, stream); |
---|
| 158 | |
---|
| 159 | return 0; |
---|
| 160 | } |
---|
| 161 | |
---|
[0] | 162 | //ll |
---|