int zephyr_i2s_open_stream(I2S_Stream **stream, uint8_t *buf, uint8_t audio_in)
{
struct i2s_strm *i2s_stream;
int ret = 0;
i2s_stream = i2s_str_alloc();
if (!i2s_stream) {
printf("Cannot allocate i2s_strm\n");
return -1;
}
i2s_stream->devid = (audio_in) ? 1 : 2;
i2s_stream->i2s_buf = buf;
i2s_stream->state = I2S_STREAM_RUNNING;
*stream = i2s_stream;
pthread_attr_init(&i2s_stream->threadAttr);
pthread_attr_setstacksize(&i2s_stream->threadAttr, 1024);
ret = pthread_create(&i2s_stream->i2s_thread, &i2s_stream->threadAttr, audio_in ? i2s_thread_in : i2s_thread_out, i2s_stream);
if (ret != 0) {
printf("i2s pthread_create failed ret=%d\n",ret);
ret = -1;
}
else
ret = 0;
pthread_setschedprio(i2s_stream->i2s_thread, I2S_THREAD_PRIORITY);
if(audio_in)
pthread_setname_np(i2s_stream->i2s_thread, "i2s_thread_in");
else
pthread_setname_np(i2s_stream->i2s_thread, "i2s_thread_out");
return ret;
}