More codestyle

This commit is contained in:
Martijn Braam 2020-12-06 16:03:25 +01:00
parent 5703ecc786
commit 4df62aa21e
2 changed files with 198 additions and 164 deletions

View File

@ -6,7 +6,8 @@
#include <string.h>
#include <unistd.h>
double get_time()
double
get_time()
{
struct timeval t;
struct timezone tzp;
@ -14,9 +15,12 @@ double get_time()
return t.tv_sec + t.tv_usec * 1e-6;
}
void on_capture(MPImage image, void *user_data)
void
on_capture(MPImage image, void *user_data)
{
size_t num_bytes = mp_pixel_format_width_to_bytes(image.pixel_format, image.width) * image.height;
size_t num_bytes =
mp_pixel_format_width_to_bytes(image.pixel_format, image.width) *
image.height;
uint8_t *data = malloc(num_bytes);
memcpy(data, image.data, num_bytes);
@ -25,10 +29,12 @@ void on_capture(MPImage image, void *user_data)
free(data);
}
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
if (argc != 2 && argc != 3) {
printf("Usage: %s <media_device_name> [<sub_device_name>]\n", argv[0]);
printf("Usage: %s <media_device_name> [<sub_device_name>]\n",
argv[0]);
return 1;
}
@ -54,7 +60,8 @@ int main(int argc, char *argv[])
int video_fd;
uint32_t video_entity_id;
{
const struct media_v2_entity *entity = mp_device_find_entity(device, video_name);
const struct media_v2_entity *entity =
mp_device_find_entity(device, video_name);
if (!entity) {
printf("Unable to find video device interface\n");
return 1;
@ -62,7 +69,8 @@ int main(int argc, char *argv[])
video_entity_id = entity->id;
const struct media_v2_interface *iface = mp_device_find_entity_interface(device, video_entity_id);
const struct media_v2_interface *iface =
mp_device_find_entity_interface(device, video_entity_id);
char buf[256];
if (!mp_find_device_path(iface->devnode, buf, 256)) {
@ -78,30 +86,38 @@ int main(int argc, char *argv[])
}
int subdev_fd = -1;
if (subdev_name)
{
const struct media_v2_entity *entity = mp_device_find_entity(device, subdev_name);
if (subdev_name) {
const struct media_v2_entity *entity =
mp_device_find_entity(device, subdev_name);
if (!entity) {
printf("Unable to find sub-device\n");
return 1;
}
const struct media_v2_pad *source_pad = mp_device_get_pad_from_entity(device, entity->id);
const struct media_v2_pad *sink_pad = mp_device_get_pad_from_entity(device, video_entity_id);
const struct media_v2_pad *source_pad =
mp_device_get_pad_from_entity(device, entity->id);
const struct media_v2_pad *sink_pad =
mp_device_get_pad_from_entity(device, video_entity_id);
// Disable other links
const struct media_v2_entity *entities = mp_device_get_entities(device);
const struct media_v2_entity *entities =
mp_device_get_entities(device);
for (int i = 0; i < mp_device_get_num_entities(device); ++i) {
if (entities[i].id != video_entity_id && entities[i].id != entity->id) {
const struct media_v2_pad *pad = mp_device_get_pad_from_entity(device, entities[i].id);
mp_device_setup_link(device, pad->id, sink_pad->id, false);
if (entities[i].id != video_entity_id &&
entities[i].id != entity->id) {
const struct media_v2_pad *pad =
mp_device_get_pad_from_entity(
device, entities[i].id);
mp_device_setup_link(device, pad->id, sink_pad->id,
false);
}
}
// Then enable ours
mp_device_setup_link(device, source_pad->id, sink_pad->id, true);
const struct media_v2_interface *iface = mp_device_find_entity_interface(device, entity->id);
const struct media_v2_interface *iface =
mp_device_find_entity_interface(device, entity->id);
char buf[256];
if (!mp_find_device_path(iface->devnode, buf, 256)) {
@ -126,11 +142,15 @@ int main(int argc, char *argv[])
double control_list_end = get_time();
printf("Available controls: (took %fms)\n", (control_list_end - open_end) * 1000);
for (MPControlList *list = controls; list; list = mp_control_list_next(list)) {
printf("Available controls: (took %fms)\n",
(control_list_end - open_end) * 1000);
for (MPControlList *list = controls; list;
list = mp_control_list_next(list)) {
MPControl *c = mp_control_list_get(list);
printf(" %32s id:%s type:%s default:%d\n", c->name, mp_control_id_to_str(c->id), mp_control_type_to_str(c->type), c->default_value);
printf(" %32s id:%s type:%s default:%d\n", c->name,
mp_control_id_to_str(c->id), mp_control_type_to_str(c->type),
c->default_value);
}
double mode_list_begin = get_time();
@ -139,10 +159,14 @@ int main(int argc, char *argv[])
double mode_list_end = get_time();
printf("Available modes: (took %fms)\n", (mode_list_end - mode_list_begin) * 1000);
for (MPCameraModeList *list = modes; list; list = mp_camera_mode_list_next(list)) {
printf("Available modes: (took %fms)\n",
(mode_list_end - mode_list_begin) * 1000);
for (MPCameraModeList *list = modes; list;
list = mp_camera_mode_list_next(list)) {
MPCameraMode *m = mp_camera_mode_list_get(list);
printf(" %dx%d interval:%d/%d fmt:%s\n", m->width, m->height, m->frame_interval.numerator, m->frame_interval.denominator, mp_pixel_format_to_str(m->pixel_format));
printf(" %dx%d interval:%d/%d fmt:%s\n", m->width, m->height,
m->frame_interval.numerator, m->frame_interval.denominator,
mp_pixel_format_to_str(m->pixel_format));
// Skip really slow framerates
if (m->frame_interval.denominator < 15) {
@ -156,7 +180,8 @@ int main(int argc, char *argv[])
mp_camera_start_capture(camera);
double last = get_time();
printf(" Testing 10 captures, starting took %fms\n", (last - start_capture) * 1000);
printf(" Testing 10 captures, starting took %fms\n",
(last - start_capture) * 1000);
for (int i = 0; i < 10; ++i) {
mp_camera_capture_image(camera, on_capture, NULL);

View File

@ -2,7 +2,9 @@
#include <linux/media.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
int
main(int argc, char *argv[])
{
MPDeviceList *list = mp_device_list_new();
while (list) {
@ -15,33 +17,40 @@ int main(int argc, char *argv[]) {
printf(" HW Revision: %d\n", info->hw_revision);
printf(" Driver Version: %d\n", info->driver_version);
const struct media_v2_entity *entities = mp_device_get_entities(device);
const struct media_v2_entity *entities =
mp_device_get_entities(device);
size_t num = mp_device_get_num_entities(device);
printf(" Entities (%ld):\n", num);
for (int i = 0; i < num; ++i) {
printf(" %d %s (%d)\n", entities[i].id, entities[i].name, entities[i].function);
printf(" %d %s (%d)\n", entities[i].id, entities[i].name,
entities[i].function);
}
const struct media_v2_interface *interfaces = mp_device_get_interfaces(device);
const struct media_v2_interface *interfaces =
mp_device_get_interfaces(device);
num = mp_device_get_num_interfaces(device);
printf(" Interfaces (%ld):\n", num);
for (int i = 0; i < num; ++i) {
printf(" %d (%d - %d) devnode %d:%d\n", interfaces[i].id, interfaces[i].intf_type, interfaces[i].flags, interfaces[i].devnode.major, interfaces[i].devnode.minor);
printf(" %d (%d - %d) devnode %d:%d\n", interfaces[i].id,
interfaces[i].intf_type, interfaces[i].flags,
interfaces[i].devnode.major,
interfaces[i].devnode.minor);
}
const struct media_v2_pad *pads = mp_device_get_pads(device);
num = mp_device_get_num_pads(device);
printf(" Pads (%ld):\n", num);
for (int i = 0; i < num; ++i) {
printf(" %d for device:%d (%d)\n", pads[i].id, pads[i].entity_id, pads[i].flags);
printf(" %d for device:%d (%d)\n", pads[i].id,
pads[i].entity_id, pads[i].flags);
}
const struct media_v2_link *links = mp_device_get_links(device);
num = mp_device_get_num_links(device);
printf(" Links (%ld):\n", num);
for (int i = 0; i < num; ++i) {
printf(" %d from:%d to:%d (%d)\n", links[i].id, links[i].source_id, links[i].sink_id, links[i].flags);
printf(" %d from:%d to:%d (%d)\n", links[i].id,
links[i].source_id, links[i].sink_id, links[i].flags);
}
list = mp_device_list_next(list);