mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-06-06 13:08:55 +00:00
FS-11521: [mod_av] support colorspace from params of file interface
https://freeswitch.org/jira/browse/FS-11521
This commit is contained in:
parent
863a0b1d2a
commit
036d3e8085
@ -126,6 +126,7 @@ struct av_file_context {
|
|||||||
AVFormatContext *fc;
|
AVFormatContext *fc;
|
||||||
AVCodec *audio_codec;
|
AVCodec *audio_codec;
|
||||||
AVCodec *video_codec;
|
AVCodec *video_codec;
|
||||||
|
enum AVColorSpace colorspace;
|
||||||
|
|
||||||
int has_audio;
|
int has_audio;
|
||||||
int has_video;
|
int has_video;
|
||||||
@ -573,8 +574,9 @@ GCC_DIAG_ON(deprecated-declarations)
|
|||||||
|
|
||||||
// av_opt_set_int(c->priv_data, "slice-max-size", SWITCH_DEFAULT_VIDEO_SIZE, 0);
|
// av_opt_set_int(c->priv_data, "slice-max-size", SWITCH_DEFAULT_VIDEO_SIZE, 0);
|
||||||
|
|
||||||
c->colorspace = avformat_globals.colorspace;
|
c->colorspace = context->colorspace;
|
||||||
c->color_range = AVCOL_RANGE_JPEG;
|
c->color_range = AVCOL_RANGE_JPEG;
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "colorspace = %d\n", c->colorspace);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -1605,6 +1607,7 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa
|
|||||||
context->offset = DFT_RECORD_OFFSET;
|
context->offset = DFT_RECORD_OFFSET;
|
||||||
context->handle = handle;
|
context->handle = handle;
|
||||||
context->audio_timer = 1;
|
context->audio_timer = 1;
|
||||||
|
context->colorspace = avformat_globals.colorspace;
|
||||||
|
|
||||||
if (handle->params) {
|
if (handle->params) {
|
||||||
if ((tmp = switch_event_get_header(handle->params, "av_video_offset"))) {
|
if ((tmp = switch_event_get_header(handle->params, "av_video_offset"))) {
|
||||||
@ -1615,6 +1618,14 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa
|
|||||||
context->audio_timer = 0;
|
context->audio_timer = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ((tmp = switch_event_get_header(handle->params, "colorspace"))) {
|
||||||
|
int value = atoi(tmp);
|
||||||
|
enum AVColorSpace colorspace = UINTVAL(value);
|
||||||
|
|
||||||
|
if (colorspace <= AVCOL_SPC_NB) {
|
||||||
|
context->colorspace = colorspace;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_mutex_init(&context->mutex, SWITCH_MUTEX_NESTED, handle->memory_pool);
|
switch_mutex_init(&context->mutex, SWITCH_MUTEX_NESTED, handle->memory_pool);
|
||||||
|
@ -42,11 +42,11 @@ FST_CORE_BEGIN("conf")
|
|||||||
}
|
}
|
||||||
FST_SETUP_END()
|
FST_SETUP_END()
|
||||||
|
|
||||||
FST_TEST_BEGIN(avformat_test)
|
FST_TEST_BEGIN(avformat_test_colorspace_RGB)
|
||||||
{
|
{
|
||||||
switch_status_t status;
|
switch_status_t status;
|
||||||
switch_image_t *img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, 1280, 720, 1);
|
switch_image_t *img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, 1280, 720, 1);
|
||||||
switch_file_handle_t fh = { 0 };
|
switch_file_handle_t fh = { 0 };
|
||||||
uint8_t data[SAMPLES * 2] = { 0 };
|
uint8_t data[SAMPLES * 2] = { 0 };
|
||||||
switch_frame_t frame = { 0 };
|
switch_frame_t frame = { 0 };
|
||||||
switch_size_t len = SAMPLES;
|
switch_size_t len = SAMPLES;
|
||||||
@ -54,9 +54,9 @@ FST_CORE_BEGIN("conf")
|
|||||||
|
|
||||||
fst_requires(img);
|
fst_requires(img);
|
||||||
|
|
||||||
status = switch_core_file_open(&fh, "./test.mp4", 1, 8000, flags, fst_pool);
|
status = switch_core_file_open(&fh, "{colorspace=0}./test_RGB.mp4", 1, 8000, flags, fst_pool);
|
||||||
fst_requires(status == SWITCH_STATUS_SUCCESS);
|
fst_requires(status == SWITCH_STATUS_SUCCESS);
|
||||||
fst_requires(switch_test_flag(&fh, SWITCH_FILE_OPEN));
|
fst_requires(switch_test_flag(&fh, SWITCH_FILE_OPEN));
|
||||||
|
|
||||||
status = switch_core_file_write(&fh, data, &len);
|
status = switch_core_file_write(&fh, data, &len);
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "status: %d len: %d\n", status, len);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "status: %d len: %d\n", status, len);
|
||||||
@ -91,7 +91,62 @@ FST_CORE_BEGIN("conf")
|
|||||||
switch_yield(100000);
|
switch_yield(100000);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_core_file_close(&fh);
|
switch_core_file_close(&fh);
|
||||||
|
switch_img_free(&img);
|
||||||
|
switch_img_free(&ccimg);
|
||||||
|
}
|
||||||
|
FST_TEST_END()
|
||||||
|
|
||||||
|
FST_TEST_BEGIN(avformat_test_colorspace_BT7)
|
||||||
|
{
|
||||||
|
switch_status_t status;
|
||||||
|
switch_image_t *img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, 1280, 720, 1);
|
||||||
|
switch_file_handle_t fh = { 0 };
|
||||||
|
uint8_t data[SAMPLES * 2] = { 0 };
|
||||||
|
switch_frame_t frame = { 0 };
|
||||||
|
switch_size_t len = SAMPLES;
|
||||||
|
uint32_t flags = SWITCH_FILE_FLAG_WRITE | SWITCH_FILE_DATA_SHORT | SWITCH_FILE_FLAG_VIDEO;
|
||||||
|
|
||||||
|
fst_requires(img);
|
||||||
|
|
||||||
|
status = switch_core_file_open(&fh, "{colorspace=1}./test_BT7.mp4", 1, 8000, flags, fst_pool);
|
||||||
|
fst_requires(status == SWITCH_STATUS_SUCCESS);
|
||||||
|
fst_requires(switch_test_flag(&fh, SWITCH_FILE_OPEN));
|
||||||
|
|
||||||
|
status = switch_core_file_write(&fh, data, &len);
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "status: %d len: %d\n", status, len);
|
||||||
|
fst_check(status == SWITCH_STATUS_SUCCESS);
|
||||||
|
// fst_requires(len == SAMPLES);
|
||||||
|
|
||||||
|
frame.img = img;
|
||||||
|
status = switch_core_file_write_video(&fh, &frame);
|
||||||
|
fst_check(status == SWITCH_STATUS_SUCCESS);
|
||||||
|
|
||||||
|
switch_image_t *ccimg = switch_img_read_png("./cluecon.png", SWITCH_IMG_FMT_ARGB);
|
||||||
|
fst_requires(ccimg);
|
||||||
|
|
||||||
|
switch_rgb_color_t color = {0};
|
||||||
|
color.a = 255;
|
||||||
|
|
||||||
|
for (int i = 0; i < 30; i++) {
|
||||||
|
len = SAMPLES;
|
||||||
|
|
||||||
|
if (i == 10) {
|
||||||
|
color.r = 255;
|
||||||
|
} else if (i == 20) {
|
||||||
|
color.r = 0;
|
||||||
|
color.b = 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_img_fill(img, 0, 0, img->d_w, img->d_h, &color);
|
||||||
|
switch_img_patch(img, ccimg, i * 10, i * 10);
|
||||||
|
|
||||||
|
status = switch_core_file_write(&fh, data, &len);
|
||||||
|
status = switch_core_file_write_video(&fh, &frame);
|
||||||
|
switch_yield(100000);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_core_file_close(&fh);
|
||||||
switch_img_free(&img);
|
switch_img_free(&img);
|
||||||
switch_img_free(&ccimg);
|
switch_img_free(&ccimg);
|
||||||
}
|
}
|
||||||
@ -101,7 +156,7 @@ FST_CORE_BEGIN("conf")
|
|||||||
{
|
{
|
||||||
const char *err = NULL;
|
const char *err = NULL;
|
||||||
switch_sleep(1000000);
|
switch_sleep(1000000);
|
||||||
fst_check(switch_loadable_module_unload_module(SWITCH_GLOBAL_dirs.mod_dir, (char *)"mod_av", SWITCH_TRUE, &err) == SWITCH_STATUS_SUCCESS);
|
//fst_check(switch_loadable_module_unload_module(SWITCH_GLOBAL_dirs.mod_dir, (char *)"mod_av", SWITCH_TRUE, &err) == SWITCH_STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
FST_TEARDOWN_END()
|
FST_TEARDOWN_END()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user