~emersion/vaapi-decoder

69fb9c1f56d59a8487bbbac0ae51e57aa47dd2e5 — Simon Ser 9 months ago bc7f7b0
Extract DRM frame pretty-printing into function
1 files changed, 22 insertions(+), 18 deletions(-)

M main.c
M main.c => main.c +22 -18
@@ 116,6 116,27 @@ static int decode_frame(AVFormatContext *input_ctx, int video_stream,
	return AVERROR_EOF;
}

static void print_drm_frame_desc(const AVDRMFrameDescriptor *drm_frame_desc) {
	fprintf(stderr, "DRM frame:\n");
	for (int i = 0; i < drm_frame_desc->nb_objects; i++) {
		const AVDRMObjectDescriptor *drm_object = &drm_frame_desc->objects[i];
		fprintf(stderr, "  object #%i: fd = %d, size = %zu, "
			"format_modifier = 0x%lX\n", i, drm_object->fd,
			drm_object->size, drm_object->format_modifier);
	}
	for (int i = 0; i < drm_frame_desc->nb_layers; i++) {
		const AVDRMLayerDescriptor *drm_layer = &drm_frame_desc->layers[i];
		fprintf(stderr, "  layer #%d: format = 0x%X\n",
			i, drm_layer->format);
		for (int j = 0; j < drm_layer->nb_planes; j++) {
			const AVDRMPlaneDescriptor *drm_plane = &drm_layer->planes[j];
			fprintf(stderr, "    plane #%d: object_index = %d, "
				"offset = %ld, pitch = %ld\n", j, drm_plane->object_index,
				drm_plane->offset, drm_plane->pitch);
		}
	}
}

int main(int argc, char *argv[]) {
	if (argc < 2) {
		fprintf(stderr, "usage: %s <file>\n", argv[0]);


@@ 216,24 237,7 @@ int main(int argc, char *argv[]) {
	}

	AVDRMFrameDescriptor *drm_frame_desc = (void *)drm_frame->data[0];
	fprintf(stderr, "DRM frame:\n");
	for (int i = 0; i < drm_frame_desc->nb_objects; i++) {
		AVDRMObjectDescriptor *drm_object = &drm_frame_desc->objects[i];
		fprintf(stderr, "  object #%i: fd = %d, size = %zu, "
			"format_modifier = 0x%lX\n", i, drm_object->fd,
			drm_object->size, drm_object->format_modifier);
	}
	for (int i = 0; i < drm_frame_desc->nb_layers; i++) {
		AVDRMLayerDescriptor *drm_layer = &drm_frame_desc->layers[i];
		fprintf(stderr, "  layer #%d: format = 0x%X\n",
			i, drm_layer->format);
		for (int j = 0; j < drm_layer->nb_planes; j++) {
			AVDRMPlaneDescriptor *drm_plane = &drm_layer->planes[j];
			fprintf(stderr, "    plane #%d: object_index = %d, "
				"offset = %ld, pitch = %ld\n", j, drm_plane->object_index,
				drm_plane->offset, drm_plane->pitch);
		}
	}
	print_drm_frame_desc(drm_frame_desc);

	// VA-API drivers may use separate layers with one plane each, or a single
	// layer with multiple planes. We need to handle both.