source: roaraudio/libroar/stream.c @ 0:2a41d2f42394

Last change on this file since 0:2a41d2f42394 was 0:2a41d2f42394, checked in by phi, 16 years ago

Initial revision

File size: 2.9 KB
Line 
1//stream.c:
2
3#include "libroar.h"
4
5int roar_stream_connect (struct roar_connection * con, struct roar_stream * s, int dir) {
6 struct roar_message m;
7
8 s->dir = dir;
9
10 m.cmd     = ROAR_CMD_NEW_STREAM;
11 m.stream  = -1;
12 m.pos     = 0;
13
14 roar_stream_s2m(s, &m);
15
16 if ( roar_req(con, &m, NULL) != 0 )
17  return -1;
18
19 if ( m.cmd == ROAR_CMD_OK ) {
20  s->id = m.stream;
21
22  ROAR_DBG("roar_stream_connect(*) = 0");
23  return 0;
24 }
25
26 ROAR_ERR("roar_stream_connect(*): Connecting new stream faild!");
27 ROAR_DBG("roar_stream_connect(*) = -1");
28 return -1;
29}
30
31int roar_stream_new (struct roar_stream * s, unsigned int rate,
32                     unsigned int channels, unsigned int bits, unsigned int codec) {
33
34
35 s->fh         = -1;
36 s->id         = -1;
37 s->pos        = 0;
38 s->pos_rel_id = -1;
39
40 s->dir        = ROAR_DIR_DEFAULT;
41
42 s->datalen    = 0;
43 s->offset     = 0;
44
45 s->database   = NULL;
46 s->dataoff    = NULL;
47
48 s->info.rate     = rate;
49 s->info.channels = channels;
50 s->info.bits     = bits;
51 s->info.codec    = codec;
52
53 if ( bits > ROAR_BITS_MAX )
54  return -1;
55
56 return 0;
57}
58
59int roar_stream_exec    (struct roar_connection * con, struct roar_stream * s) {
60 struct roar_message m;
61
62 m.cmd     = ROAR_CMD_EXEC_STREAM;
63 m.stream  = s->id;
64 m.datalen = 0;
65 m.pos     = 0;
66
67 if ( roar_req(con, &m, NULL) == -1 )
68  return -1;
69
70 if ( m.cmd == ROAR_CMD_OK )
71  return 0;
72 return -1;
73}
74
75
76int roar_stream_add_data (struct roar_connection * con, struct roar_stream * s, char * data, size_t len) {
77 struct roar_message m;
78
79 m.cmd     = ROAR_CMD_ADD_DATA;
80 m.stream  = s->id;
81 m.datalen = len;
82
83// if ( roar_req(con, &m, (void**)&data) == -1 )
84//  return -1;
85 if ( roar_send_message(con, &m, data) != 0 )
86  return -1;
87
88 if ( roar_recv_message(con, &m, NULL) == -1 )
89  return -1;
90
91 if ( m.cmd == ROAR_CMD_OK )
92  return 0;
93 return -1;
94}
95
96
97#define _ROAR_STREAM_MESSAGE_LEN ((5+1)*4)
98
99int roar_stream_s2m     (struct roar_stream * s, struct roar_message * m) {
100 uint32_t * data;
101 int i;
102
103 if ( !(s && m) )
104  return -1;
105
106 m->datalen = _ROAR_STREAM_MESSAGE_LEN;
107 data = (uint32_t*) m->data;
108
109 data[0] = s->dir;
110 data[1] = s->pos_rel_id;
111 data[2] = s->info.rate;
112 data[3] = s->info.bits;
113 data[4] = s->info.channels;
114 data[5] = s->info.codec;
115
116 for (i = 0; i < _ROAR_STREAM_MESSAGE_LEN/4; i++)
117  data[i] = ROAR_HOST2NET32(data[i]);
118
119 ROAR_DBG("roar_stream_s2m(*): s->info:");
120 roar_debug_audio_info_print(&s->info);
121
122 return 0;
123}
124int roar_stream_m2s     (struct roar_stream * s, struct roar_message * m) {
125 uint32_t * data;
126 int i;
127
128 if ( !(s && m) )
129  return -1;
130
131 if ( m->datalen != _ROAR_STREAM_MESSAGE_LEN )
132  return -1;
133
134 data = (uint32_t*) m->data;
135
136 for (i = 0; i < _ROAR_STREAM_MESSAGE_LEN/4; i++)
137  data[i] = ROAR_NET2HOST32(data[i]);
138
139 s->dir           = data[0];
140 s->pos_rel_id    = data[1];
141 s->info.rate     = data[2];
142 s->info.bits     = data[3];
143 s->info.channels = data[4];
144 s->info.codec    = data[5];
145
146 ROAR_DBG("roar_stream_m2s(*): s->info:");
147 roar_debug_audio_info_print(&s->info);
148
149 return 0;
150}
151
152//ll
Note: See TracBrowser for help on using the repository browser.