Changeset 2924:fdaddc789f71 in roaraudio for libroardsp/transcode_speex.c
- Timestamp:
- 10/16/09 18:05:32 (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroardsp/transcode_speex.c
r2923 r2924 138 138 int roar_xcoder_speex_proc_header(struct roar_xcoder * state) { 139 139 struct roar_xcoder_speex * self = state->inst; 140 uint16_t tmp_net; 141 int tmp; 142 SpeexStereoState stereo = SPEEX_STEREO_STATE_INIT; 143 SpeexCallback callback; 144 char magic[ROAR_SPEEX_MAGIC_LEN]; 140 145 141 146 // we do allready open streams not considder an error. … … 149 154 150 155 if ( state->encode ) { 151 } else {152 }153 154 // on no error...155 return 0;156 }157 158 int roar_xcoder_speex_encode (struct roar_xcoder * state, void * buf, size_t len) {159 struct roar_xcoder_speex * self = state->inst;160 uint16_t tmp_net;161 int pkg_len;162 163 if (!state->encode)164 return -1;165 166 ROAR_DBG("roar_xcoder_speex_encode(*): Encoding...");167 168 if ( state->stage == ROAR_XCODER_STAGE_INITED ) {169 156 if ( roar_vio_write(state->backend, ROAR_SPEEX_MAGIC, ROAR_SPEEX_MAGIC_LEN) != ROAR_SPEEX_MAGIC_LEN ) 170 157 return -1; … … 179 166 180 167 state->stage = ROAR_XCODER_STAGE_OPENED; 181 } 182 183 speex_bits_reset(&(self->bits)); 184 185 if ( self->stereo ) 186 speex_encode_stereo_int((spx_int16_t *) buf, self->frame_size, &(self->bits)); 187 188 speex_encode_int(self->xcoder, (spx_int16_t *) buf, &(self->bits)); 189 190 pkg_len = speex_bits_write(&(self->bits), self->cc + 2, self->max_cc); 191 192 *((uint16_t*)self->cc) = ROAR_HOST2NET16(pkg_len); 193 194 if ( roar_vio_write(state->backend, self->cc, pkg_len + 2) != (pkg_len + 2) ) 195 return -1; 196 197 return 0; 198 } 199 200 // TODO: move all the init thingys into a seperate function 201 int roar_xcoder_speex_decode (struct roar_xcoder * state, void * buf, size_t len) { 202 struct roar_xcoder_speex * self = state->inst; 203 char magic[ROAR_SPEEX_MAGIC_LEN]; 204 uint16_t tmp_net; 205 int pkg_len; 206 int tmp; 207 SpeexStereoState stereo = SPEEX_STEREO_STATE_INIT; 208 SpeexCallback callback; 209 210 ROAR_DBG("roar_xcoder_speex_decode(state=%p, buf=%p, len=%lu) = ?", state, buf, (unsigned long)len); 211 212 if ( state->stage == ROAR_XCODER_STAGE_INITED ) { 168 } else { 213 169 ROAR_DBG("roar_xcoder_speex_decode(state=%p, buf=%p, len=%lu): state->stage = INITED", state, buf, (unsigned long)len); 214 170 if ( roar_vio_read(state->backend, magic, ROAR_SPEEX_MAGIC_LEN) != ROAR_SPEEX_MAGIC_LEN ) … … 262 218 } 263 219 220 // on no error... 221 return 0; 222 } 223 224 int roar_xcoder_speex_encode (struct roar_xcoder * state, void * buf, size_t len) { 225 struct roar_xcoder_speex * self = state->inst; 226 int pkg_len; 227 228 if (!state->encode) 229 return -1; 230 231 ROAR_DBG("roar_xcoder_speex_encode(*): Encoding..."); 232 233 if ( state->stage == ROAR_XCODER_STAGE_INITED ) 234 if ( roar_xcoder_speex_proc_header(state) == -1 ) 235 return -1; 236 237 speex_bits_reset(&(self->bits)); 238 239 if ( self->stereo ) 240 speex_encode_stereo_int((spx_int16_t *) buf, self->frame_size, &(self->bits)); 241 242 speex_encode_int(self->xcoder, (spx_int16_t *) buf, &(self->bits)); 243 244 pkg_len = speex_bits_write(&(self->bits), self->cc + 2, self->max_cc); 245 246 *((uint16_t*)self->cc) = ROAR_HOST2NET16(pkg_len); 247 248 if ( roar_vio_write(state->backend, self->cc, pkg_len + 2) != (pkg_len + 2) ) 249 return -1; 250 251 return 0; 252 } 253 254 // TODO: move all the init thingys into a seperate function 255 int roar_xcoder_speex_decode (struct roar_xcoder * state, void * buf, size_t len) { 256 struct roar_xcoder_speex * self = state->inst; 257 uint16_t tmp_net; 258 int pkg_len; 259 260 ROAR_DBG("roar_xcoder_speex_decode(state=%p, buf=%p, len=%lu) = ?", state, buf, (unsigned long)len); 261 262 if ( state->stage == ROAR_XCODER_STAGE_INITED ) 263 if ( roar_xcoder_speex_proc_header(state) == -1 ) 264 return -1; 265 264 266 ROAR_DBG("roar_xcoder_speex_decode(state=%p, buf=%p, len=%lu): state->stage = %s", state, buf, (unsigned long)len, 265 267 state->stage == ROAR_XCODER_STAGE_OPENED ? "OPENED" : "???"
Note: See TracChangeset
for help on using the changeset viewer.