switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "[OGG/OPUS Stream Decode] read_stream_thread(): switch_thread_self(): 0x%lx\n", switch_thread_self());
}
switch_thread_rwlock_rdlock(context->rwlock);
+ switch_mutex_lock(context->ogg_mutex);
if ((buffered_ogg_bytes = switch_buffer_inuse(context->ogg_buffer))) {
if (buffered_ogg_bytes <= OGG_MAX_PAGE_SIZE) {
}
}
+ switch_mutex_unlock(context->ogg_mutex);
switch_thread_rwlock_unlock(context->rwlock);
return NULL;
}
#endif
switch_thread_rwlock_rdlock(context->rwlock);
+ switch_mutex_lock(context->ogg_mutex);
memset(context->ogg_data, 0, sizeof(context->ogg_data));
if (encoded_data_len <= SWITCH_RECOMMENDED_BUFFER_SIZE) {
- switch_mutex_lock(context->ogg_mutex);
switch_buffer_write(context->ogg_buffer, encode_buf, encoded_data_len);
if ((buffered_ogg_bytes = switch_buffer_inuse(context->ogg_buffer)) >= ogg_bytes) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[OGG/OPUS Stream Decode] buffered ogg data bigger than max OGG page size, will flush\n");
*decoded_data_len = 0;
switch_buffer_zero(context->ogg_buffer);
- switch_mutex_unlock(context->ogg_mutex);
switch_goto_status(SWITCH_STATUS_SUCCESS, end);
}
}
- switch_mutex_unlock(context->ogg_mutex);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "[OGG/OPUS Stream Decode] too much data to buffer, flushing buffer!\n");
*decoded_data_len = 0;
end:
switch_thread_rwlock_unlock(context->rwlock);
+ switch_mutex_unlock(context->ogg_mutex);
return status;
}
uint32_t decoded_len;
size_t write_len;
unsigned char decbuf[SWITCH_RECOMMENDED_BUFFER_SIZE] = { 0 };
+ switch_stream_handle_t stream = { 0 };
#ifdef HAVE_OPUSFILE_ENCODE
switch_file_handle_t fh = { 0 };
unsigned char encbuf[SWITCH_RECOMMENDED_BUFFER_SIZE] = { 0 };
&codec_settings, fst_pool);
fst_check(status == SWITCH_STATUS_SUCCESS);
+ SWITCH_STANDARD_STREAM(stream);
+
+ switch_api_execute("opusfile_debug", "on", NULL, &stream);
+
+ switch_safe_free(stream.data);
+
#ifdef HAVE_OPUSFILE_ENCODE
status = switch_core_codec_init(&write_codec,
"OPUSSTREAM",
fhw.native_rate = filerate;
- flen = OGG_MIN_PAGE_SIZE;
+ flen = 4096;
while (switch_file_read(fd, &buf, &flen) == SWITCH_STATUS_SUCCESS || flen != 0) {
status = SWITCH_STATUS_SUCCESS;
while (status == SWITCH_STATUS_SUCCESS) {
status = switch_core_codec_decode(&read_codec, NULL, &buf, flen, filerate, &decbuf, &decoded_len, &rate, &flags);
- fst_requires(status == SWITCH_STATUS_SUCCESS);
+ fst_check(status == SWITCH_STATUS_SUCCESS);
write_len = decoded_len / sizeof(int16_t);
if (write_len) switch_core_file_write(&fhw, &decbuf, &write_len);
else break;