Skip to content

Commit c9052a7

Browse files
committed
- add some debug logging
- add an option for dumping the engine render layers - fix omxplayer view updates when using locales that use `,` as the decimal separator
1 parent 821a5c6 commit c9052a7

File tree

5 files changed

+119
-25
lines changed

5 files changed

+119
-25
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ project(flutter-pi LANGUAGES C VERSION "1.0.0")
3434
message(STATUS "Generator .............. ${CMAKE_GENERATOR}")
3535
message(STATUS "Build Type ............. ${CMAKE_BUILD_TYPE}")
3636

37-
OPTION(OMXPLAYER_SUPPORTS_RUNTIME_ROTATION "Whether omxplayer supports runtime rotation." OFF)
37+
option(OMXPLAYER_SUPPORTS_RUNTIME_ROTATION "Whether omxplayer supports runtime rotation." OFF)
38+
option(DUMP_ENGINE_LAYERS "True if flutter-pi should dump the list of rendering layers that the flutter engine sends to flutter-pi on each draw." OFF)
3839

3940
if(NOT FLUTTER_EMBEDDER_HEADER)
4041

include/collection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ static inline uint64_t get_monotonic_time(void) {
421421

422422
#ifdef DEBUG
423423
#define DEBUG_ASSERT(__cond) assert(__cond)
424-
#define DEBUG_ASSERT_MSG(__cond, __msg) assert((__msg, (__cond))
424+
#define DEBUG_ASSERT_MSG(__cond, __msg) assert((__cond) && __msg)
425425
#else
426426
#define DEBUG_ASSERT(__cond) do {} while (false)
427427
#define DEBUG_ASSERT_MSG(__cond, __msg) do {} while (false)

src/compositor.c

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
#include <compositor.h>
2222
#include <cursor.h>
2323

24+
#define LOG_ERROR(...) fprintf(stderr, "[compositor] " __VA_ARGS__)
25+
#ifdef DEBUG
26+
# define LOG_DEBUG(...) fprintf(stderr, "[compositor] " __VA_ARGS__)
27+
#else
28+
# define LOG_DEBUG(...) do {} while (0)
29+
#endif
30+
2431
struct view_cb_data {
2532
int64_t view_id;
2633
platform_view_mount_cb mount;
@@ -1061,6 +1068,57 @@ static bool on_present_layers(
10611068
schedule_fake_page_flip_event = compositor->do_blocking_atomic_commits;
10621069
use_atomic_modesetting = drmdev->supports_atomic_modesetting;
10631070

1071+
#ifdef DUMP_ENGINE_LAYERS
1072+
LOG_DEBUG("layers:\n");
1073+
for (int i = 0; i < layers_count; i++) {
1074+
if (layers[i]->type == kFlutterLayerContentTypeBackingStore) {
1075+
LOG_DEBUG(" backing store (offset: %f, %f. size: %f, %f)\n", layers[i]->offset.x, layers[i]->offset.y, layers[i]->size.width, layers[i]->size.height);
1076+
} else {
1077+
DEBUG_ASSERT(layers[i]->type == kFlutterLayerContentTypePlatformView);
1078+
1079+
LOG_DEBUG(" platform view (id: %"PRId64", offset: %f, %f, size: %f, %f) mutations:\n", layers[i]->platform_view->identifier, layers[i]->offset.x, layers[i]->offset.y, layers[i]->size.width, layers[i]->size.height);
1080+
for (size_t j = 0; j < layers[i]->platform_view->mutations_count; j++) {
1081+
const FlutterPlatformViewMutation *mut = layers[i]->platform_view->mutations[j];
1082+
switch (mut->type) {
1083+
case kFlutterPlatformViewMutationTypeOpacity:
1084+
LOG_DEBUG(" opacity %f\n", mut->opacity);
1085+
break;
1086+
case kFlutterPlatformViewMutationTypeClipRect:
1087+
LOG_DEBUG(" clip rect (ltrb: %f, %f, %f, %f)\n", mut->clip_rect.left, mut->clip_rect.top, mut->clip_rect.right, mut->clip_rect.bottom);
1088+
break;
1089+
case kFlutterPlatformViewMutationTypeClipRoundedRect:
1090+
LOG_DEBUG(
1091+
" clip rounded rect (ltrb: %f, %f, %f, %f, corner radii ul, ur, br, bl: %f, %f, %f, %f)\n",
1092+
mut->clip_rounded_rect.rect.left, mut->clip_rounded_rect.rect.top, mut->clip_rounded_rect.rect.right, mut->clip_rounded_rect.rect.bottom,
1093+
mut->clip_rounded_rect.upper_left_corner_radius,
1094+
mut->clip_rounded_rect.upper_right_corner_radius,
1095+
mut->clip_rounded_rect.lower_right_corner_radius,
1096+
mut->clip_rounded_rect.lower_left_corner_radius
1097+
);
1098+
break;
1099+
case kFlutterPlatformViewMutationTypeTransformation:
1100+
LOG_DEBUG(
1101+
" transform (matrix: %f %f %f; %f %f %f; %f %f %f)\n",
1102+
mut->transformation.scaleX,
1103+
mut->transformation.skewX,
1104+
mut->transformation.transX,
1105+
mut->transformation.skewY,
1106+
mut->transformation.scaleY,
1107+
mut->transformation.transY,
1108+
mut->transformation.pers0,
1109+
mut->transformation.pers1,
1110+
mut->transformation.pers2
1111+
);
1112+
break;
1113+
default:
1114+
DEBUG_ASSERT_MSG(0, "invalid platform view mutation type\n");
1115+
break;
1116+
}
1117+
}
1118+
}
1119+
}
1120+
#endif
1121+
10641122
req = NULL;
10651123
if (use_atomic_modesetting) {
10661124
ok = drmdev_new_atomic_req(compositor->drmdev, &req);
@@ -1414,7 +1472,8 @@ static bool on_present_layers(
14141472
legacy_rendertarget_set_mode && (plane->type == DRM_PLANE_TYPE_PRIMARY)
14151473
);
14161474
}
1417-
} else if (layers[i]->type == kFlutterLayerContentTypePlatformView) {
1475+
} else {
1476+
DEBUG_ASSERT(layers[i]->type == kFlutterLayerContentTypePlatformView);
14181477
cb_data = get_cbs_for_view_id_locked(layers[i]->platform_view->identifier);
14191478

14201479
if ((cb_data != NULL) && (cb_data->present != NULL)) {

src/plugins/omxplayer_video_player.c

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626

2727
#include <plugins/omxplayer_video_player.h>
2828

29+
#define LOG_ERROR(...) fprintf(stderr, "[omxplayer video player plugin] " __VA_ARGS__)
30+
#ifdef DEBUG
31+
# define LOG_DEBUG(...) fprintf(stderr, "[omxplayer video player plugin] " __VA_ARGS__)
32+
#else
33+
# define LOG_DEBUG(...) do {} while (0)
34+
#endif
35+
2936
static struct {
3037
bool initialized;
3138

@@ -190,18 +197,17 @@ static int on_mount(
190197
zpos = -126;
191198
}
192199

193-
194200
struct aa_rect rect = get_aa_bounding_rect(params->rect);
195201

196202
return cqueue_enqueue(
197203
&player->mgr->task_queue,
198204
&(struct omxplayer_mgr_task) {
199205
.type = kUpdateView,
200206
.responsehandle = NULL,
201-
.offset_x = rect.offset.x,
202-
.offset_y = rect.offset.y,
203-
.width = rect.size.x,
204-
.height = rect.size.y,
207+
.offset_x = round(rect.offset.x),
208+
.offset_y = round(rect.offset.y),
209+
.width = round(rect.size.x),
210+
.height = round(rect.size.y),
205211
.zpos = zpos,
206212
.orientation = get_orientation_from_rotation(params->rotation)
207213
}
@@ -617,6 +623,8 @@ static void *mgr_entry(void *userdata) {
617623
goto fail_kill_registered_player;
618624
}
619625

626+
627+
LOG_DEBUG("respond success on_create(). player_id: %" PRId64 "\n", mgr->player->player_id);
620628
// creation was a success! respond to the dart-side with our player id.
621629
platch_respond_success_std(task.responsehandle, &STDINT64(mgr->player->player_id));
622630

@@ -761,14 +769,19 @@ static void *mgr_entry(void *userdata) {
761769
platch_respond_success_std(task.responsehandle, NULL);
762770
} else if (task.type == kUpdateView) {
763771
char video_pos_str[256];
772+
773+
// Use integers here even if omxplayer supports floats because if we print floats,
774+
// snprintf might use `,` as the decimal delimiter depending on the locale.
775+
// This is only an issue because I set the application to be locale-aware using setlocale(LC_ALL, "")
776+
// since that's needed for locale support.
764777
snprintf(
765778
video_pos_str,
766779
sizeof(video_pos_str),
767-
"%f %f %f %f",
768-
(double) task.offset_x,
769-
(double) task.offset_y,
770-
(double) (task.offset_x + task.width),
771-
(double) (task.offset_y + task.height)
780+
"%d %d %d %d",
781+
task.offset_x,
782+
task.offset_y,
783+
task.offset_x + task.width,
784+
task.offset_y + task.height
772785
);
773786

774787
ok = sd_bus_call_method(
@@ -1019,6 +1032,8 @@ static int on_initialize(
10191032
return respond_init_failed(responsehandle);
10201033
}
10211034

1035+
LOG_DEBUG("on_initialize\n");
1036+
10221037
return platch_respond_success_std(responsehandle, NULL);
10231038
}
10241039

@@ -1110,6 +1125,15 @@ static int on_create(
11101125
);
11111126
}
11121127

1128+
LOG_DEBUG(
1129+
"on_create(sourceType: %s, asset: %s, uri: \"%s\", packageName: %s, formatHint: %s)\n",
1130+
source_type == kDataSourceTypeAsset ? "asset" : source_type == kDataSourceTypeNetwork ? "network" : "file",
1131+
asset,
1132+
uri,
1133+
package_name,
1134+
format_hint
1135+
);
1136+
11131137
mgr = calloc(1, sizeof *mgr);
11141138
if (mgr == NULL) {
11151139
return platch_respond_native_error_std(responsehandle, ENOMEM);
@@ -1209,6 +1233,8 @@ static int on_dispose(
12091233
return ok;
12101234
}
12111235

1236+
LOG_DEBUG("on_dispose(%"PRId64")\n", player->player_id);
1237+
12121238
return cqueue_enqueue(&player->mgr->task_queue, &(const struct omxplayer_mgr_task) {
12131239
.type = kDispose,
12141240
.responsehandle = responsehandle
@@ -1237,6 +1263,8 @@ static int on_set_looping(
12371263
);
12381264
}
12391265

1266+
LOG_DEBUG("on_set_looping(player_id: %"PRId64", looping: %s)\n", player->player_id, loop ? "yes" : "no");
1267+
12401268
return cqueue_enqueue(&player->mgr->task_queue, &(const struct omxplayer_mgr_task) {
12411269
.type = kSetLooping,
12421270
.loop = loop,
@@ -1266,6 +1294,8 @@ static int on_set_volume(
12661294
);
12671295
}
12681296

1297+
LOG_DEBUG("on_set_volume(player_id: %"PRId64", volume: %f)\n", player->player_id, volume);
1298+
12691299
return cqueue_enqueue(&player->mgr->task_queue, &(const struct omxplayer_mgr_task) {
12701300
.type = kSetVolume,
12711301
.volume = volume,
@@ -1283,6 +1313,8 @@ static int on_play(
12831313
ok = get_player_from_map_arg(arg, &player, responsehandle);
12841314
if (ok != 0) return ok;
12851315

1316+
LOG_DEBUG("on_play(player_id: %"PRId64")\n", player->player_id);
1317+
12861318
return cqueue_enqueue(&player->mgr->task_queue, &(const struct omxplayer_mgr_task) {
12871319
.type = kPlay,
12881320
.responsehandle = responsehandle
@@ -1299,6 +1331,8 @@ static int on_get_position(
12991331
ok = get_player_from_map_arg(arg, &player, responsehandle);
13001332
if (ok != 0) return ok;
13011333

1334+
LOG_DEBUG("on_get_position(player_id: %"PRId64")\n", player->player_id);
1335+
13021336
return cqueue_enqueue(&player->mgr->task_queue, &(const struct omxplayer_mgr_task) {
13031337
.type = kGetPosition,
13041338
.responsehandle = responsehandle
@@ -1327,6 +1361,8 @@ static int on_seek_to(
13271361
);
13281362
}
13291363

1364+
LOG_DEBUG("on_seek_to(player_id: %"PRId64", position: %"PRId64")\n", player->player_id, position);
1365+
13301366
return cqueue_enqueue(&player->mgr->task_queue, &(const struct omxplayer_mgr_task) {
13311367
.type = kSetPosition,
13321368
.position = position,
@@ -1344,6 +1380,8 @@ static int on_pause(
13441380
ok = get_player_from_map_arg(arg, &player, responsehandle);
13451381
if (ok != 0) return ok;
13461382

1383+
LOG_DEBUG("on_pause(player_id: %"PRId64")\n", player->player_id);
1384+
13471385
return cqueue_enqueue(&player->mgr->task_queue, &(const struct omxplayer_mgr_task) {
13481386
.type = kPause,
13491387
.responsehandle = responsehandle
@@ -1371,10 +1409,11 @@ static int on_create_platform_view(
13711409
"Expected `arg['platformViewId']` to be an integer."
13721410
);
13731411
}
1412+
1413+
LOG_DEBUG("on_create_platform_view(player_id: %"PRId64", platform view id: %"PRId64")\n", player->player_id, view_id);
13741414

13751415
if (player->has_view) {
1376-
fprintf(stderr, "[omxplayer_video_player plugin] Flutter attempted to register more than one platform view for one player instance.\n");
1377-
1416+
LOG_ERROR("Flutter attempted to register more than one platform view for one player instance.\n");
13781417
return platch_respond_illegal_arg_std(
13791418
responsehandle,
13801419
"Attempted to register more than one platform view for this player instance."
@@ -1421,22 +1460,16 @@ static int on_dispose_platform_view(
14211460
);
14221461
}
14231462

1463+
LOG_DEBUG("on_dispose_platform_view(player_id: %"PRId64", platform view id: %"PRId64")\n", player->player_id, view_id);
1464+
14241465
if (player->view_id != view_id) {
1425-
fprintf(
1426-
stderr,
1427-
"[omxplayer_video_player plugin] Flutter attempted to dispose an omxplayer platform view that is not associated with this player.\n"
1428-
);
1466+
LOG_ERROR("Flutter attempted to dispose an omxplayer platform view that is not associated with this player.\n");
14291467

14301468
return platch_respond_illegal_arg_std(responsehandle, "Attempted to dispose on omxplayer view that is not associated with `arg['playerId']`.");
14311469
} else {
14321470
ok = compositor_remove_view_callbacks(view_id);
14331471
if (ok != 0) {
1434-
fprintf(
1435-
stderr,
1436-
"[omxplayer_video_player plugin] Could not remove view callbacks for platform view %" PRId64 ". compositor_remove_view_callbacks: %s\n",
1437-
view_id,
1438-
strerror(ok)
1439-
);
1472+
LOG_ERROR("Could not remove view callbacks for platform view %" PRId64 ". compositor_remove_view_callbacks: %s\n", view_id, strerror(ok));
14401473
return platch_respond_native_error_std(responsehandle, ok);
14411474
}
14421475

third_party/backward-cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 49243890982c7c8de7aaa3887765f6523c2e10dd

0 commit comments

Comments
 (0)