st/gui: Support RGBA, unusual strides, and add higher bitrate option

This commit is contained in:
Moses Turner 2022-02-18 19:26:56 -06:00
parent 433ae0d9c6
commit 0dcc73d5cf
3 changed files with 27 additions and 7 deletions

View file

@ -4,6 +4,7 @@
* @file
* @brief OpenGL functions to drive the gui.
* @author Jakob Bornecrantz <jakob@collabora.com>
* @author Moses Turner <moses@collabora.com>
* @ingroup gui
*/
@ -79,17 +80,28 @@ destroy(struct xrt_frame_node *node)
}
static void
update_r8g8b8(struct gui_ogl_sink *s, GLint w, GLint h, uint8_t *data)
update_r8g8b8x8(struct gui_ogl_sink *s, GLint w, GLint h, GLint stride, uint8_t *data)
{
glBindTexture(GL_TEXTURE_2D, s->tex.id);
glPixelStorei(GL_UNPACK_ROW_LENGTH, stride / 4);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glBindTexture(GL_TEXTURE_2D, 0);
}
static void
update_r8g8b8(struct gui_ogl_sink *s, GLint w, GLint h, GLint stride, uint8_t *data)
{
glBindTexture(GL_TEXTURE_2D, s->tex.id);
glPixelStorei(GL_UNPACK_ROW_LENGTH, stride / 3);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
glBindTexture(GL_TEXTURE_2D, 0);
}
static void
update_l8(struct gui_ogl_sink *s, GLint w, GLint h, uint8_t *data)
update_l8(struct gui_ogl_sink *s, GLint w, GLint h, GLint stride, uint8_t *data)
{
glBindTexture(GL_TEXTURE_2D, s->tex.id);
glPixelStorei(GL_UNPACK_ROW_LENGTH, stride);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, w, h, 0, GL_RED, GL_UNSIGNED_BYTE, data);
GLint swizzleMask[] = {GL_RED, GL_RED, GL_RED, GL_ONE};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
@ -112,11 +124,12 @@ gui_ogl_sink_update(struct gui_ogl_texture *tex)
return;
}
GLint w, h;
GLint w, h, stride;
uint8_t *data;
w = frame->width;
h = frame->height;
stride = frame->stride;
if (tex->w != (uint32_t)w || tex->h != (uint32_t)h) {
tex->w = w;
@ -132,8 +145,10 @@ gui_ogl_sink_update(struct gui_ogl_texture *tex)
data = frame->data;
switch (frame->format) {
case XRT_FORMAT_R8G8B8: update_r8g8b8(s, w, h, data); break;
case XRT_FORMAT_L8: update_l8(s, w, h, data); break;
case XRT_FORMAT_R8G8B8: update_r8g8b8(s, w, h, stride, data); break;
case XRT_FORMAT_R8G8B8A8:
case XRT_FORMAT_R8G8B8X8: update_r8g8b8x8(s, w, h, stride, data); break;
case XRT_FORMAT_L8: update_l8(s, w, h, stride, data); break;
default: break;
}

View file

@ -60,6 +60,7 @@ create_pipeline(struct gui_record_window *rw)
switch (rw->gst.bitrate) {
default:
case GUI_RECORD_BITRATE_32768: bitrate = "32768"; break;
case GUI_RECORD_BITRATE_4096: bitrate = "4096"; break;
case GUI_RECORD_BITRATE_2048: bitrate = "2048"; break;
case GUI_RECORD_BITRATE_1024: bitrate = "1024"; break;
@ -166,7 +167,8 @@ draw_gst(struct gui_record_window *rw)
os_mutex_unlock(&rw->gst.mutex);
igComboStr("Pipeline", (int *)&rw->gst.pipeline, "SW Fast\0SW Medium\0SW Slow\0SW Veryslow\0VAAPI H264\0\0", 5);
igComboStr("Bitrate", (int *)&rw->gst.bitrate, "4096bps\0002048bps\0001024bps\0\0", 3);
igComboStr("Bitrate", (int *)&rw->gst.bitrate, "32768bps (Be careful!)\0004096bps\0002048bps\0001024bps\0\0",
3);
igInputText("Filename", rw->gst.filename, sizeof(rw->gst.filename), 0, NULL, NULL);
@ -266,13 +268,15 @@ gui_window_record_init(struct gui_record_window *rw)
}
snprintf(rw->gst.filename, sizeof(rw->gst.filename), "/tmp/capture.mp4");
rw->gst.bitrate = GUI_RECORD_BITRATE_4096;
#endif
// Setup the preview texture.
rw->texture.scale = 1;
struct xrt_frame_sink *tmp = NULL;
rw->texture.ogl = gui_ogl_sink_create("View", &rw->texture.xfctx, &tmp);
u_sink_create_to_r8g8b8_or_l8(&rw->texture.xfctx, tmp, &tmp);
u_sink_create_to_r8g8b8_r8g8b8a8_r8g8b8x8_or_l8(&rw->texture.xfctx, tmp, &tmp);
u_sink_queue_create(&rw->texture.xfctx, 1, tmp, &rw->texture.sink);
return true;

View file

@ -27,6 +27,7 @@ struct gui_ogl_texture;
enum gui_record_bitrate
{
GUI_RECORD_BITRATE_32768,
GUI_RECORD_BITRATE_4096,
GUI_RECORD_BITRATE_2048,
GUI_RECORD_BITRATE_1024,