#include <gtk/gtk.h>
#include "simp.h"
-GtkWidget* gl_area = NULL;
-
void simp_file_add(GtkMenuButton* self, gpointer user_data)
{
printf("%s(),%d\n", __func__, __LINE__);
{
printf("%s(),%d\n", __func__, __LINE__);
- gtk_gl_area_queue_render(GTK_GL_AREA(gl_area));
+ gtk_gl_area_queue_render(GTK_GL_AREA(user_data));
}
static void resize (GtkGLArea* self, gint width, gint height, gpointer user_data)
printf("%s(),%d\n", __func__, __LINE__);
}
-static gboolean render(GtkGLArea *area, GdkGLContext *context)
+static gboolean render(GtkGLArea* self, GdkGLContext* context, gpointer user_data)
{
- if (gtk_gl_area_get_error (area) != NULL)
+ simp_avio_t* gl = user_data;
+
+ if (gtk_gl_area_get_error (self) != NULL)
return FALSE;
glViewport(0, 0, 1920, 1080);
glClear (GL_COLOR_BUFFER_BIT);
// draw
+ simp_avio_run(gl);
glFlush ();
static gboolean button_release_event (GtkWidget* self, GdkEventButton* event, gpointer user_data)
{
- gtk_gl_area_queue_render(GTK_GL_AREA(gl_area));
+ gtk_gl_area_queue_render(GTK_GL_AREA(user_data));
return TRUE;
}
{
printf("%s(),%d\n", __func__, __LINE__);
- GtkBuilder *builder;
- GObject *window;
+ simp_filter_t* f = NULL;
+ simp_avio_t* in = NULL;
+ simp_avio_t* out = NULL;
+ simp_avio_t* alsa = NULL;
+ simp_avio_t* gl = NULL;
+
+ GtkBuilder* builder;
+ GObject* window;
- GObject *menu_file_quit;
- GObject *menu_file_add;
+ GObject* menu_file_quit;
+ GObject* menu_file_add;
- GObject *button_record;
- GObject *button_pause;
- GObject *button_stop;
+ GObject* button_record;
+ GObject* button_pause;
+ GObject* button_stop;
- GError *error = NULL;
+ GObject* gl_area;
+// GtkWidget* gl_area = NULL;
+ GError* error = NULL;
gtk_init (&argc, &argv);
+ avdevice_register_all();
+
builder = gtk_builder_new();
if (gtk_builder_add_from_file (builder, "simp.glade", &error) == 0)
{
button_pause = gtk_builder_get_object (builder, "button_pause");
button_stop = gtk_builder_get_object (builder, "button_stop");
- gl_area = GTK_WIDGET(gtk_builder_get_object(builder, "gl_area"));
+ gl_area = gtk_builder_get_object (builder, "gl_area");
+// gl_area = GTK_WIDGET(gtk_builder_get_object(builder, "gl_area"));
+
+ if (simp_avio_open(&in, "ffmpeg_input", argv[1], NULL) < 0) {
+ scf_loge("\n");
+ return -1;
+ }
+
+ if (simp_avio_open(&alsa, "ffmpeg_alsa", NULL, "hw:0") < 0) {
+ scf_loge("\n");
+ return -1;
+ }
+
+ if (simp_avio_open(&gl, "gl", NULL, NULL) < 0) {
+ scf_loge("\n");
+ return -1;
+ }
+
+ if (simp_filter_open(&f) < 0) {
+ scf_loge("\n");
+ return -1;
+ }
+
+ simp_filter_add_input (f, in);
+ simp_filter_add_output(f, alsa);
+ simp_filter_add_output(f, gl);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(menu_file_quit, "activate", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(menu_file_add, "activate", G_CALLBACK(simp_file_add), builder);
- g_signal_connect(button_record, "clicked", G_CALLBACK(simp_record), builder);
- g_signal_connect(button_pause, "clicked", G_CALLBACK(simp_pause), builder);
- g_signal_connect(button_stop, "clicked", G_CALLBACK(simp_stop), builder);
+ g_signal_connect(button_record, "clicked", G_CALLBACK(simp_record), f);
+ g_signal_connect(button_pause, "clicked", G_CALLBACK(simp_pause), f);
+ g_signal_connect(button_stop, "clicked", G_CALLBACK(simp_stop), f);
+
+ g_signal_connect(gl_area, "resize", G_CALLBACK(resize), gl);
+ g_signal_connect(gl_area, "unrealize", G_CALLBACK(unrealize), gl);
+ g_signal_connect(gl_area, "render", G_CALLBACK(render), gl);
+
+ g_signal_connect(window, "button-release-event", G_CALLBACK(button_release_event), f);
- g_signal_connect(gl_area, "resize", G_CALLBACK(resize), NULL);
- g_signal_connect(gl_area, "unrealize", G_CALLBACK(unrealize), NULL);
- g_signal_connect(gl_area, "render", G_CALLBACK(render), NULL);
+ f->speed.num = 1;
+ f->speed.den = 1;
- g_signal_connect(window, "button-release-event", G_CALLBACK(button_release_event), NULL);
+ if (simp_filter_run(f) < 0) {
+ scf_loge("\n");
+ return -1;
+ }
+
+ if (simp_avio_run(alsa) < 0) {
+ scf_loge("\n");
+ return -1;
+ }
+
+ if (simp_avio_run(in) < 0) {
+ scf_loge("\n");
+ return -1;
+ }
gtk_widget_show_all(GTK_WIDGET(window));
-#include"chess_gl.h"
-#include"pieces.h"
+#include"simp.h"
const float G_PI = 3.1415926;
return 0;
}
-int _gl_open(simp_avio_t* io, const char* in, const char* out);
+int _gtk_gl_open(simp_avio_t* io, const char* in, const char* out)
{
simp_gl_t* gl = calloc(1, sizeof(simp_gl_t));
if (!gl)
return -ENOMEM;
+ io->priv = gl;
+ return 0;
+}
+
+static int _gl_init(simp_gl_t* gl)
+{
init_buffers(gl);
GLint status = 0;
glGetShaderiv (fragment_shader, GL_COMPILE_STATUS, &status);
printf("#1, status: %d\n", status);
- program = glCreateProgram();
- glAttachShader(program, vertex_shader);
- glAttachShader(program, fragment_shader);
- glLinkProgram (program);
- glGetProgramiv(program, GL_LINK_STATUS, &status);
+ gl->program = glCreateProgram();
+ glAttachShader(gl->program, vertex_shader);
+ glAttachShader(gl->program, fragment_shader);
+ glLinkProgram (gl->program);
+ glGetProgramiv(gl->program, GL_LINK_STATUS, &status);
printf("#2, status: %d\n", status);
init_texture(&gl->texture_y, GL_RED, SIMP_GL_WIDTH, SIMP_GL_HEIGHT, gl->y);
init_texture(&gl->texture_u, GL_RED, SIMP_GL_WIDTH / 2, SIMP_GL_HEIGHT / 2, gl->u);
init_texture(&gl->texture_v, GL_RED, SIMP_GL_WIDTH / 2, SIMP_GL_HEIGHT / 2, gl->v);
- io->priv = gl;
return 0;
}
-int simp_gl_draw(simp_gl_t* gl)
+static int _gtk_gl_run(simp_avio_t* io)
{
- float mvp[16];
+ simp_gl_t* gl = io->priv;
+
+ float mvp[16];
+
+ if (!gl->init)
+ _gl_init(gl);
compute_mvp(mvp, 0, 0, 0);
return 0;
}
-simp_avio_ops_t simp_avio_gl =
+simp_avio_ops_t simp_avio_gtk_gl =
{
- .type = "gl",
- .open = _gl_open,
- .close = _gl_close,
- .run = _gl_run,
- .stop = _gl_stop,
+ .type = "gtk_gl",
+ .open = _gtk_gl_open,
+ .run = _gtk_gl_run,
};