|
18 | 18 | #define OUTPUT_MODE_STREAMING_OR_RECORDING 4 |
19 | 19 | #define OUTPUT_MODE_VIRTUAL_CAMERA 5 |
20 | 20 |
|
| 21 | +#define BACKGROUND_CHANNEL 0 |
| 22 | +#define SOURCE_CHANNEL 1 |
| 23 | + |
21 | 24 | struct source_record_filter_context { |
22 | 25 | obs_source_t *source; |
23 | 26 | video_t *video_output; |
@@ -364,7 +367,7 @@ static void remove_filter(void *data, calldata_t *calldata) |
364 | 367 | signal_handler_disconnect(sh, "stop", remove_filter, filter); |
365 | 368 | obs_source_t *source = obs_filter_get_parent(filter->source); |
366 | 369 | if (!source && filter->view) { |
367 | | - source = obs_view_get_source(filter->view, 0); |
| 370 | + source = obs_view_get_source(filter->view, SOURCE_CHANNEL); |
368 | 371 | obs_source_release(source); |
369 | 372 | } |
370 | 373 | obs_source_filter_remove(source, filter->source); |
@@ -832,12 +835,31 @@ static void source_record_filter_update(void *data, obs_data_t *settings) |
832 | 835 | } |
833 | 836 |
|
834 | 837 | if (parent && filter->view && (record || replay_buffer)) { |
835 | | - obs_source_t *view_source = obs_view_get_source(filter->view, 0); |
| 838 | + obs_source_t *view_source = obs_view_get_source(filter->view, SOURCE_CHANNEL); |
836 | 839 | if (view_source != parent) |
837 | | - obs_view_set_source(filter->view, 0, parent); |
| 840 | + obs_view_set_source(filter->view, SOURCE_CHANNEL, parent); |
838 | 841 | obs_source_release(view_source); |
839 | 842 | } |
840 | 843 |
|
| 844 | + if (parent && filter->view) { |
| 845 | + obs_source_t *background_source = obs_view_get_source(filter->view, BACKGROUND_CHANNEL); |
| 846 | + if (!background_source) { |
| 847 | + background_source = obs_source_create_private("color_source", "Source Record Background", NULL); |
| 848 | + obs_view_set_source(filter->view, BACKGROUND_CHANNEL, background_source); |
| 849 | + } |
| 850 | + obs_data_t *css = obs_source_get_settings(background_source); |
| 851 | + if (obs_data_get_int(css, "color") != obs_data_get_int(settings, "backgroundColor") || |
| 852 | + obs_data_get_int(css, "width") != obs_source_get_width(parent) || |
| 853 | + obs_data_get_int(css, "height") != obs_source_get_height(parent)) { |
| 854 | + obs_data_set_int(css, "color", obs_data_get_int(settings, "backgroundColor")); |
| 855 | + obs_data_set_int(css, "width", obs_source_get_width(parent)); |
| 856 | + obs_data_set_int(css, "height", obs_source_get_height(parent)); |
| 857 | + obs_source_update(background_source, css); |
| 858 | + } |
| 859 | + obs_data_release(css); |
| 860 | + obs_source_release(background_source); |
| 861 | + } |
| 862 | + |
841 | 863 | if (record != filter->record) { |
842 | 864 | if (record) { |
843 | 865 | if (obs_source_enabled(filter->source) && filter->video_output) |
@@ -917,9 +939,9 @@ static void source_record_filter_update(void *data, obs_data_t *settings) |
917 | 939 | } |
918 | 940 |
|
919 | 941 | if (parent && filter->view && stream) { |
920 | | - obs_source_t *view_source = obs_view_get_source(filter->view, 0); |
| 942 | + obs_source_t *view_source = obs_view_get_source(filter->view, SOURCE_CHANNEL); |
921 | 943 | if (view_source != parent) |
922 | | - obs_view_set_source(filter->view, 0, parent); |
| 944 | + obs_view_set_source(filter->view, SOURCE_CHANNEL, parent); |
923 | 945 | obs_source_release(view_source); |
924 | 946 | } |
925 | 947 |
|
@@ -1119,7 +1141,8 @@ static void source_record_delayed_destroy(void *data) |
1119 | 1141 | obs_service_release(context->service); |
1120 | 1142 |
|
1121 | 1143 | if (context->video_output && context->view) { |
1122 | | - obs_view_set_source(context->view, 0, NULL); |
| 1144 | + obs_view_set_source(context->view, BACKGROUND_CHANNEL, NULL); |
| 1145 | + obs_view_set_source(context->view, SOURCE_CHANNEL, NULL); |
1123 | 1146 | obs_view_remove(context->view); |
1124 | 1147 | context->video_output = NULL; |
1125 | 1148 | } |
@@ -1369,11 +1392,29 @@ static void source_record_filter_tick(void *data, float seconds) |
1369 | 1392 | obs_data_t *s = obs_source_get_settings(context->source); |
1370 | 1393 | update_encoder(context, s); |
1371 | 1394 | if (context->record || context->stream || context->replayBuffer) { |
1372 | | - obs_source_t *view_source = obs_view_get_source(context->view, 0); |
| 1395 | + obs_source_t *view_source = obs_view_get_source(context->view, SOURCE_CHANNEL); |
1373 | 1396 | if (view_source != parent) |
1374 | | - obs_view_set_source(context->view, 0, parent); |
| 1397 | + obs_view_set_source(context->view, SOURCE_CHANNEL, parent); |
1375 | 1398 | obs_source_release(view_source); |
1376 | 1399 | } |
| 1400 | + |
| 1401 | + obs_source_t *background_source = obs_view_get_source(context->view, BACKGROUND_CHANNEL); |
| 1402 | + if (!background_source) { |
| 1403 | + background_source = obs_source_create_private("color_source", "Source Record Background", NULL); |
| 1404 | + obs_view_set_source(context->view, BACKGROUND_CHANNEL, background_source); |
| 1405 | + } |
| 1406 | + obs_data_t *css = obs_source_get_settings(background_source); |
| 1407 | + if (obs_data_get_int(css, "color") != obs_data_get_int(s, "backgroundColor") || |
| 1408 | + obs_data_get_int(css, "width") != obs_source_get_width(parent) || |
| 1409 | + obs_data_get_int(css, "height") != obs_source_get_height(parent)) { |
| 1410 | + obs_data_set_int(css, "color", obs_data_get_int(s, "backgroundColor")); |
| 1411 | + obs_data_set_int(css, "width", obs_source_get_width(parent)); |
| 1412 | + obs_data_set_int(css, "height", obs_source_get_height(parent)); |
| 1413 | + obs_source_update(background_source, css); |
| 1414 | + } |
| 1415 | + obs_data_release(css); |
| 1416 | + obs_source_release(background_source); |
| 1417 | + |
1377 | 1418 | if (context->record) |
1378 | 1419 | start_file_output(context, s); |
1379 | 1420 | if (context->stream) |
@@ -1766,6 +1807,10 @@ static void source_record_filter_filter_remove(void *data, obs_source_t *parent) |
1766 | 1807 | run_queued(force_stop_output_task, so); |
1767 | 1808 | context->replayOutput = NULL; |
1768 | 1809 | } |
| 1810 | + if (context->view) { |
| 1811 | + obs_view_set_source(context->view, BACKGROUND_CHANNEL, NULL); |
| 1812 | + obs_view_set_source(context->view, SOURCE_CHANNEL, NULL); |
| 1813 | + } |
1769 | 1814 | obs_frontend_remove_event_callback(frontend_event, context); |
1770 | 1815 | } |
1771 | 1816 |
|
@@ -2495,3 +2540,8 @@ void obs_module_unload(void) |
2495 | 2540 | { |
2496 | 2541 | da_free(source_record_filters); |
2497 | 2542 | } |
| 2543 | + |
| 2544 | +const char *obs_module_name(void) |
| 2545 | +{ |
| 2546 | + return obs_module_text("SourceRecord"); |
| 2547 | +} |
0 commit comments