FS-7512: add audio to png
This commit is contained in:
parent
8c56410d7f
commit
70953c868b
|
@ -23,7 +23,9 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
*
|
*
|
||||||
* mod_png -- play a png as video
|
* Seven Du <dujinfang@gmail.com>
|
||||||
|
*
|
||||||
|
* mod_png -- play a png as video, optionally with audio
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -44,6 +46,7 @@ struct png_file_context {
|
||||||
int sent;
|
int sent;
|
||||||
int max;
|
int max;
|
||||||
int samples;
|
int samples;
|
||||||
|
switch_file_handle_t *audio_fh;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct png_file_context png_file_context_t;
|
typedef struct png_file_context png_file_context_t;
|
||||||
|
@ -87,6 +90,7 @@ static switch_status_t png_file_open(switch_file_handle_t *handle, const char *p
|
||||||
context->max = 10000;
|
context->max = 10000;
|
||||||
|
|
||||||
if (handle->params) {
|
if (handle->params) {
|
||||||
|
const char *audio_file = switch_event_get_header(handle->params, "audio_file");
|
||||||
const char *max = switch_event_get_header(handle->params, "png_ms");
|
const char *max = switch_event_get_header(handle->params, "png_ms");
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
||||||
|
@ -94,6 +98,21 @@ static switch_status_t png_file_open(switch_file_handle_t *handle, const char *p
|
||||||
tmp = atol(max);
|
tmp = atol(max);
|
||||||
context->max = tmp;
|
context->max = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (audio_file) {
|
||||||
|
context->audio_fh = switch_core_alloc(handle->memory_pool, sizeof(*context->audio_fh));
|
||||||
|
switch_assert(context->audio_fh);
|
||||||
|
|
||||||
|
if (switch_core_file_open(context->audio_fh,
|
||||||
|
audio_file,
|
||||||
|
handle->channels,
|
||||||
|
handle->samplerate,
|
||||||
|
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
|
||||||
|
NULL) != SWITCH_STATUS_SUCCESS) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to open audio file %s\n", audio_file);
|
||||||
|
context->audio_fh = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context->max) {
|
if (context->max) {
|
||||||
|
@ -120,6 +139,8 @@ static switch_status_t png_file_close(switch_file_handle_t *handle)
|
||||||
|
|
||||||
switch_img_free(&context->img);
|
switch_img_free(&context->img);
|
||||||
|
|
||||||
|
if (context->audio_fh) switch_core_file_close(context->audio_fh);
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,6 +149,10 @@ static switch_status_t png_file_read(switch_file_handle_t *handle, void *data, s
|
||||||
|
|
||||||
png_file_context_t *context = (png_file_context_t *)handle->private_info;
|
png_file_context_t *context = (png_file_context_t *)handle->private_info;
|
||||||
|
|
||||||
|
if (context->audio_fh) {
|
||||||
|
return switch_core_file_read(context->audio_fh, data, len);
|
||||||
|
}
|
||||||
|
|
||||||
if (!context->img || !context->samples) {
|
if (!context->img || !context->samples) {
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue