Functions | |
| switch_status_t | switch_core_perform_file_open (const char *file, const char *func, int line, switch_file_handle_t *fh, const char *file_path, uint8_t channels, uint32_t rate, unsigned int flags, switch_memory_pool_t *pool) |
| switch_status_t | switch_core_file_read (switch_file_handle_t *fh, void *data, switch_size_t *len) |
| switch_status_t | switch_core_file_write (switch_file_handle_t *fh, void *data, switch_size_t *len) |
| switch_status_t | switch_core_file_seek (switch_file_handle_t *fh, unsigned int *cur_pos, int64_t samples, int whence) |
| switch_status_t | switch_core_file_set_string (switch_file_handle_t *fh, switch_audio_col_t col, const char *string) |
| switch_status_t | switch_core_file_get_string (switch_file_handle_t *fh, switch_audio_col_t col, const char **string) |
| switch_status_t | switch_core_file_close (switch_file_handle_t *fh) |
|
|
00279 {
00280 switch_status_t status;
00281
00282 switch_assert(fh != NULL);
00283 switch_assert(fh->file_interface != NULL);
00284
00285 switch_clear_flag(fh, SWITCH_FILE_OPEN);
00286 status = fh->file_interface->file_close(fh);
00287
00288 if (fh->buffer) {
00289 switch_buffer_destroy(&fh->buffer);
00290 }
00291
00292 switch_resample_destroy(&fh->resampler);
00293
00294 if (switch_test_flag(fh, SWITCH_FILE_FLAG_FREE_POOL)) {
00295 switch_core_destroy_memory_pool(&fh->memory_pool);
00296 }
00297
00298 return status;
00299 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
00267 {
00268 switch_assert(fh != NULL);
00269 switch_assert(fh->file_interface != NULL);
00270
00271 if (!fh->file_interface->file_get_string) {
00272 return SWITCH_STATUS_FALSE;
00273 }
00274
00275 return fh->file_interface->file_get_string(fh, col, string);
00276 }
|
|
||||||||||||||||
|
00126 {
00127 switch_status_t status;
00128 switch_size_t orig_len = *len;
00129
00130 switch_assert(fh != NULL);
00131 switch_assert(fh->file_interface != NULL);
00132
00133 if (fh->buffer && switch_buffer_inuse(fh->buffer)) {
00134 *len = switch_buffer_read(fh->buffer, data, orig_len * 2) / 2;
00135 return SWITCH_STATUS_SUCCESS;
00136 }
00137
00138 if ((status = fh->file_interface->file_read(fh, data, len)) != SWITCH_STATUS_SUCCESS) {
00139 goto done;
00140 }
00141
00142 if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->native_rate != fh->samplerate) {
00143 if (!fh->resampler) {
00144 if (switch_resample_create(&fh->resampler,
00145 fh->native_rate,
00146 orig_len,
00147 fh->samplerate,
00148 (uint32_t)orig_len,
00149 fh->memory_pool) != SWITCH_STATUS_SUCCESS) {
00150 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
00151 return SWITCH_STATUS_GENERR;
00152 }
00153 }
00154
00155 fh->resampler->from_len = switch_short_to_float(data, fh->resampler->from, (int) *len);
00156 fh->resampler->to_len =
00157 switch_resample_process(fh->resampler, fh->resampler->from, fh->resampler->from_len, fh->resampler->to, fh->resampler->to_size, 0);
00158
00159 if (fh->resampler->to_len > orig_len) {
00160 if (!fh->buffer) {
00161 switch_buffer_create_dynamic(&fh->buffer, fh->resampler->to_len * 2, fh->resampler->to_len * 4, fh->resampler->to_len * 8);
00162 switch_assert(fh->buffer);
00163 }
00164 if (!fh->dbuf) {
00165 fh->dbuflen = fh->resampler->to_len * 8;
00166 fh->dbuf = switch_core_alloc(fh->memory_pool, fh->dbuflen);
00167 }
00168 switch_assert(fh->resampler->to_len <= fh->dbuflen);
00169
00170 switch_float_to_short(fh->resampler->to, (int16_t *) fh->dbuf, fh->resampler->to_len);
00171 switch_buffer_write(fh->buffer, fh->dbuf, fh->resampler->to_len * 2);
00172 *len = switch_buffer_read(fh->buffer, data, orig_len * 2) / 2;
00173 } else {
00174 switch_float_to_short(fh->resampler->to, data, fh->resampler->to_len);
00175 *len = fh->resampler->to_len;
00176 }
00177
00178 }
00179
00180 done:
00181
00182 return status;
00183 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
00236 {
00237 switch_status_t status;
00238
00239 switch_assert(fh != NULL);
00240 switch_assert(fh->file_interface != NULL);
00241
00242 if (!fh->file_interface->file_seek) {
00243 return SWITCH_STATUS_FALSE;
00244 }
00245
00246 switch_set_flag(fh, SWITCH_FILE_SEEK);
00247 status = fh->file_interface->file_seek(fh, cur_pos, samples, whence);
00248 if (samples) {
00249 fh->offset_pos = *cur_pos;
00250 }
00251 return status;
00252 }
|
|
||||||||||||||||
|
00255 {
00256 switch_assert(fh != NULL);
00257 switch_assert(fh->file_interface != NULL);
00258
00259 if (!fh->file_interface->file_set_string) {
00260 return SWITCH_STATUS_FALSE;
00261 }
00262
00263 return fh->file_interface->file_set_string(fh, col, string);
00264 }
|
|
||||||||||||||||
|
00186 {
00187 switch_size_t orig_len = *len;
00188
00189 switch_assert(fh != NULL);
00190 switch_assert(fh->file_interface != NULL);
00191
00192 if (!fh->file_interface->file_write) {
00193 return SWITCH_STATUS_FALSE;
00194 }
00195
00196 if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->native_rate != fh->samplerate) {
00197 if (!fh->resampler) {
00198 if (switch_resample_create(&fh->resampler,
00199 fh->native_rate,
00200 orig_len,
00201 fh->samplerate,
00202 (uint32_t)orig_len,
00203 fh->memory_pool) != SWITCH_STATUS_SUCCESS) {
00204 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
00205 return SWITCH_STATUS_GENERR;
00206 }
00207 }
00208
00209 fh->resampler->from_len = switch_short_to_float(data, fh->resampler->from, (int) *len);
00210 fh->resampler->to_len =
00211 switch_resample_process(fh->resampler, fh->resampler->from, fh->resampler->from_len, fh->resampler->to, fh->resampler->to_size, 0);
00212 if (fh->resampler->to_len > orig_len) {
00213 if (!fh->dbuf) {
00214 fh->dbuflen = fh->resampler->to_len * 2;
00215 fh->dbuf = switch_core_alloc(fh->memory_pool, fh->dbuflen);
00216 }
00217 switch_assert(fh->resampler->to_len <= fh->dbuflen);
00218 switch_float_to_short(fh->resampler->to, (int16_t *) fh->dbuf, fh->resampler->to_len);
00219 data = fh->dbuf;
00220 } else {
00221 switch_float_to_short(fh->resampler->to, data, fh->resampler->to_len);
00222 }
00223
00224 *len = fh->resampler->to_len;
00225
00226 }
00227
00228 if (!*len) {
00229 return SWITCH_STATUS_SUCCESS;
00230 }
00231
00232 return fh->file_interface->file_write(fh, data, len);
00233 }
|
Here is the call graph for this function:

|
||||||||||||||||||||||||||||||||||||||||
|
00045 {
00046 char *ext;
00047 switch_status_t status;
00048 char stream_name[128] = "";
00049 char *rhs = NULL;
00050
00051 if (switch_strlen_zero(file_path)) {
00052 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Filename\n");
00053 return SWITCH_STATUS_FALSE;
00054 }
00055
00056 if ((rhs = strstr(file_path, SWITCH_URL_SEPARATOR))) {
00057 switch_copy_string(stream_name, file_path, (rhs + 1) - file_path);
00058 ext = stream_name;
00059 file_path = rhs + 3;
00060 } else {
00061 if ((ext = strrchr(file_path, '.')) == 0) {
00062 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid Format\n");
00063 return SWITCH_STATUS_FALSE;
00064 }
00065 ext++;
00066 }
00067
00068 if ((fh->file_interface = switch_loadable_module_get_file_interface(ext)) == 0) {
00069 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "invalid file format [%s] for [%s]!\n", ext, file_path);
00070 return SWITCH_STATUS_GENERR;
00071 }
00072
00073 fh->file = file;
00074 fh->func = func;
00075 fh->line = line;
00076
00077 fh->flags = flags;
00078 if (pool) {
00079 fh->memory_pool = pool;
00080 } else {
00081 if ((status = switch_core_new_memory_pool(&fh->memory_pool)) != SWITCH_STATUS_SUCCESS) {
00082 return status;
00083 }
00084 switch_set_flag(fh, SWITCH_FILE_FLAG_FREE_POOL);
00085 }
00086
00087 if (rhs) {
00088 fh->handler = switch_core_strdup(fh->memory_pool, rhs);
00089 }
00090
00091 if (!fh->samplerate) {
00092 if (!(fh->samplerate = rate)) {
00093 fh->samplerate = 8000;
00094 }
00095 }
00096
00097 if (channels) {
00098 fh->channels = channels;
00099 } else {
00100 fh->channels = 1;
00101 }
00102
00103 if ((status = fh->file_interface->file_open(fh, file_path)) != SWITCH_STATUS_SUCCESS) {
00104 return status;
00105 }
00106
00107 if ((flags & SWITCH_FILE_FLAG_READ)) {
00108 fh->native_rate = fh->samplerate;
00109 } else {
00110 fh->native_rate = rate;
00111 }
00112
00113 if (fh->samplerate && rate && fh->samplerate != rate) {
00114 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Sample rate doesn't match\n");
00115 if ((flags & SWITCH_FILE_FLAG_READ)) {
00116 fh->samplerate = rate;
00117 }
00118 }
00119
00120 switch_set_flag(fh, SWITCH_FILE_OPEN);
00121
00122 return status;
00123 }
|
Here is the call graph for this function:

1.3.9.1