mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-14 23:34:08 +00:00
libobs: Implement obs_service func to get max bitrates
(This commit also modifies rtmp-services) Implements obs_service_get_max_bitrate, which allows retrieving the maximum audio/video bitrates directly rather than being forced to use the apply method. Makes it a bit easier to get the bitrate values.
This commit is contained in:
parent
5f6793676d
commit
fb7747c56e
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue