example: use core methods to register types

This commit is contained in:
Wim Taymans 2019-02-06 11:43:47 +01:00
parent 703309f6cd
commit 3424c05298
2 changed files with 22 additions and 18 deletions

View file

@ -39,13 +39,13 @@ struct type {
uint32_t meta_cursor; uint32_t meta_cursor;
}; };
static inline void init_type(struct type *type, struct spa_type_map *map) static inline void init_type(struct type *type, struct pw_type *map)
{ {
spa_type_media_type_map(map, &type->media_type); pw_type_get(map, SPA_TYPE__MediaType, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype); pw_type_get(map, SPA_TYPE__MediaSubtype, &type->media_subtype);
spa_type_format_video_map(map, &type->format_video); pw_type_get(map, SPA_TYPE_FORMAT__Video, &type->format_video);
spa_type_video_format_map(map, &type->video_format); pw_type_get(map, SPA_TYPE__VideoFormat, &type->video_format);
type->meta_cursor = spa_type_map_get_id(map, SPA_TYPE_META__Cursor); pw_type_get(map, SPA_TYPE_META__Cursor, &type->meta_cursor);
} }
#define WIDTH 640 #define WIDTH 640
@ -295,8 +295,10 @@ on_stream_format_changed(void *_data, const struct spa_pod *format)
return; return;
} }
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG)) {
fprintf(stderr, "got format:\n"); fprintf(stderr, "got format:\n");
spa_debug_format(2, data->t->map, format); spa_debug_format(2, data->t->map, format);
}
spa_format_video_raw_parse(format, &data->format, &data->type.format_video); spa_format_video_raw_parse(format, &data->format, &data->type.format_video);
@ -422,8 +424,10 @@ static void on_state_changed(void *_data, enum pw_remote_state old, enum pw_remo
NULL); NULL);
params[0] = spa_pod_builder_pop(&b); params[0] = spa_pod_builder_pop(&b);
if (pw_log_level_enabled(SPA_LOG_LEVEL_DEBUG)) {
fprintf(stderr, "supported formats:\n"); fprintf(stderr, "supported formats:\n");
spa_debug_format(2, data->t->map, params[0]); spa_debug_format(2, data->t->map, params[0]);
}
pw_stream_add_listener(data->stream, pw_stream_add_listener(data->stream,
&data->stream_listener, &data->stream_listener,
@ -506,7 +510,7 @@ int main(int argc, char *argv[])
data.remote = pw_remote_new(data.core, NULL, 0); data.remote = pw_remote_new(data.core, NULL, 0);
data.path = argc > 1 ? argv[1] : NULL; data.path = argc > 1 ? argv[1] : NULL;
init_type(&data.type, data.t->map); init_type(&data.type, data.t);
if (SDL_Init(SDL_INIT_VIDEO) < 0) { if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "can't initialize SDL: %s\n", SDL_GetError()); fprintf(stderr, "can't initialize SDL: %s\n", SDL_GetError());

View file

@ -38,13 +38,13 @@ struct type {
uint32_t meta_cursor; uint32_t meta_cursor;
}; };
static inline void init_type(struct type *type, struct spa_type_map *map) static inline void init_type(struct type *type, struct pw_type *map)
{ {
spa_type_media_type_map(map, &type->media_type); pw_type_get(map, SPA_TYPE__MediaType, &type->media_type);
spa_type_media_subtype_map(map, &type->media_subtype); pw_type_get(map, SPA_TYPE__MediaSubtype, &type->media_subtype);
spa_type_format_video_map(map, &type->format_video); pw_type_get(map, SPA_TYPE_FORMAT__Video, &type->format_video);
spa_type_video_format_map(map, &type->video_format); pw_type_get(map, SPA_TYPE__VideoFormat, &type->video_format);
type->meta_cursor = spa_type_map_get_id(map, SPA_TYPE_META__Cursor); pw_type_get(map, SPA_TYPE_META__Cursor, &type->meta_cursor);
} }
#define BPP 3 #define BPP 3
@ -334,7 +334,7 @@ int main(int argc, char *argv[])
data.t = pw_core_get_type(data.core); data.t = pw_core_get_type(data.core);
data.remote = pw_remote_new(data.core, NULL, 0); data.remote = pw_remote_new(data.core, NULL, 0);
init_type(&data.type, data.t->map); init_type(&data.type, data.t);
data.timer = pw_loop_add_timer(pw_main_loop_get_loop(data.loop), on_timeout, &data); data.timer = pw_loop_add_timer(pw_main_loop_get_loop(data.loop), on_timeout, &data);