diff --git a/libobs/obs-service.c b/libobs/obs-service.c index 57816557f..02bb686de 100644 --- a/libobs/obs-service.c +++ b/libobs/obs-service.c @@ -436,3 +436,19 @@ void obs_service_get_max_res_fps(const obs_service_t *service, int *cx, int *cy, service->info.get_max_res_fps(service->context.data, cx, cy, fps); } + +void obs_service_get_max_bitrate(const obs_service_t *service, + int *video_bitrate, int *audio_bitrate) +{ + if (video_bitrate) + *video_bitrate = 0; + if (audio_bitrate) + *audio_bitrate = 0; + + if (!obs_service_valid(service, "obs_service_get_max_bitrate")) + return; + + if (service->info.get_max_bitrate) + service->info.get_max_bitrate(service->context.data, + video_bitrate, audio_bitrate); +} diff --git a/libobs/obs-service.h b/libobs/obs-service.h index 7b03e7265..88c7bd0cb 100644 --- a/libobs/obs-service.h +++ b/libobs/obs-service.h @@ -75,6 +75,9 @@ struct obs_service_info { const char *(*get_output_type)(void *data); void (*get_max_res_fps)(void *data, int *cx, int *cy, int *fps); + + void (*get_max_bitrate)(void *data, int *video_bitrate, + int *audio_bitrate); }; EXPORT void obs_register_service_s(const struct obs_service_info *info, diff --git a/libobs/obs.h b/libobs/obs.h index 6e3593059..35b5fab29 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -2234,6 +2234,9 @@ EXPORT const char *obs_service_get_id(const obs_service_t *service); EXPORT void obs_service_get_max_res_fps(const obs_service_t *service, int *cx, int *cy, int *fps); +EXPORT void obs_service_get_max_bitrate(const obs_service_t *service, + int *video_bitrate, int *audio_bitrate); + /* NOTE: This function is temporary and should be removed/replaced at a later * date. */ EXPORT const char *obs_service_get_output_type(const obs_service_t *service); diff --git a/plugins/rtmp-services/rtmp-common.c b/plugins/rtmp-services/rtmp-common.c index f8995df38..3144ea5a7 100644 --- a/plugins/rtmp-services/rtmp-common.c +++ b/plugins/rtmp-services/rtmp-common.c @@ -690,6 +690,42 @@ static void rtmp_common_get_max_res_fps(void *data, int *cx, int *cy, int *fps) *fps = service->max_fps; } +static void rtmp_common_get_max_bitrate(void *data, int *video_bitrate, + int *audio_bitrate) +{ + struct rtmp_common *service = data; + json_t *root = open_services_file(); + json_t *item; + + if (!root) + return; + + json_t *json_service = find_service(root, service->service, NULL); + if (!json_service) { + goto fail; + } + + json_t *recommended = json_object_get(json_service, "recommended"); + if (!recommended) { + goto fail; + } + + if (audio_bitrate) { + item = json_object_get(recommended, "max audio bitrate"); + if (json_is_integer(item)) + *audio_bitrate = (int)json_integer_value(item); + } + + if (video_bitrate) { + item = json_object_get(recommended, "max video bitrate"); + if (json_is_integer(item)) + *video_bitrate = (int)json_integer_value(item); + } + +fail: + json_decref(root); +} + struct obs_service_info rtmp_common_service = { .id = "rtmp_common", .get_name = rtmp_common_getname, @@ -702,4 +738,5 @@ struct obs_service_info rtmp_common_service = { .apply_encoder_settings = rtmp_common_apply_settings, .get_output_type = rtmp_common_get_output_type, .get_max_res_fps = rtmp_common_get_max_res_fps, + .get_max_bitrate = rtmp_common_get_max_bitrate, };