2009-03-13 17:14:31 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2009-11-24 09:07:40 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
#include <fcntl.h>
|
2010-10-06 06:37:50 -04:00
|
|
|
#include <math.h>
|
2009-03-13 17:14:31 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2012-07-04 11:49:55 -04:00
|
|
|
#define GST_USE_UNSTABLE_API
|
2009-03-13 17:14:31 -04:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2012-10-25 17:26:17 -04:00
|
|
|
#include <gtk/gtk.h>
|
2012-11-16 11:04:19 -05:00
|
|
|
#include <gdk/gdk.h>
|
2012-10-25 17:26:17 -04:00
|
|
|
|
2013-08-14 04:34:58 -04:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
#include <meta/meta-cursor-tracker.h>
|
2018-01-03 02:55:38 -05:00
|
|
|
#include <meta/display.h>
|
2014-10-09 08:42:06 -04:00
|
|
|
#include <meta/compositor-mutter.h>
|
2013-08-14 04:34:58 -04:00
|
|
|
|
2014-10-09 08:42:06 -04:00
|
|
|
#include "shell-global.h"
|
2009-03-13 17:14:31 -04:00
|
|
|
#include "shell-recorder-src.h"
|
|
|
|
#include "shell-recorder.h"
|
2016-08-19 00:14:33 -04:00
|
|
|
#include "shell-util.h"
|
2009-03-13 17:14:31 -04:00
|
|
|
|
2013-05-22 11:48:56 -04:00
|
|
|
#define A11Y_APPS_SCHEMA "org.gnome.desktop.a11y.applications"
|
|
|
|
#define MAGNIFIER_ACTIVE_KEY "screen-magnifier-enabled"
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
typedef enum {
|
|
|
|
RECORDER_STATE_CLOSED,
|
|
|
|
RECORDER_STATE_RECORDING
|
|
|
|
} RecorderState;
|
|
|
|
|
|
|
|
typedef struct _RecorderPipeline RecorderPipeline;
|
|
|
|
|
|
|
|
struct _ShellRecorder {
|
|
|
|
GObject parent;
|
|
|
|
|
|
|
|
/* A "maximum" amount of memory to use for buffering. This is used
|
|
|
|
* to alert the user that they are filling up memory rather than
|
|
|
|
* any that actually affects recording. (In kB)
|
|
|
|
*/
|
|
|
|
guint memory_target;
|
|
|
|
guint memory_used; /* Current memory used. (In kB) */
|
|
|
|
|
|
|
|
RecorderState state;
|
|
|
|
|
|
|
|
ClutterStage *stage;
|
2013-05-08 13:24:19 -04:00
|
|
|
gboolean custom_area;
|
|
|
|
cairo_rectangle_int_t area;
|
2009-03-13 17:14:31 -04:00
|
|
|
int stage_width;
|
|
|
|
int stage_height;
|
|
|
|
|
2012-11-16 11:04:19 -05:00
|
|
|
GdkScreen *gdk_screen;
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
int pointer_x;
|
|
|
|
int pointer_y;
|
|
|
|
|
2013-05-22 11:48:56 -04:00
|
|
|
GSettings *a11y_settings;
|
2013-05-08 13:52:16 -04:00
|
|
|
gboolean draw_cursor;
|
2013-08-14 04:34:58 -04:00
|
|
|
MetaCursorTracker *cursor_tracker;
|
2009-03-13 17:14:31 -04:00
|
|
|
cairo_surface_t *cursor_image;
|
2013-08-14 04:34:58 -04:00
|
|
|
guint8 *cursor_memory;
|
2009-03-13 17:14:31 -04:00
|
|
|
int cursor_hot_x;
|
|
|
|
int cursor_hot_y;
|
|
|
|
|
2010-02-08 15:25:58 -05:00
|
|
|
int framerate;
|
2009-03-13 17:14:31 -04:00
|
|
|
char *pipeline_description;
|
2012-10-25 17:14:20 -04:00
|
|
|
char *file_template;
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
/* We might have multiple pipelines that are finishing encoding
|
|
|
|
* to go along with the current pipeline where we are recording.
|
|
|
|
*/
|
|
|
|
RecorderPipeline *current_pipeline; /* current pipeline */
|
|
|
|
GSList *pipelines; /* all pipelines */
|
|
|
|
|
2012-01-30 16:44:32 -05:00
|
|
|
GstClockTime last_frame_time; /* Timestamp for the last frame */
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
/* GSource IDs for different timeouts and idles */
|
|
|
|
guint redraw_timeout;
|
|
|
|
guint redraw_idle;
|
|
|
|
guint update_memory_used_timeout;
|
|
|
|
guint update_pointer_timeout;
|
2011-01-21 12:55:00 -05:00
|
|
|
guint repaint_hook_id;
|
2009-03-13 17:14:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _RecorderPipeline
|
|
|
|
{
|
|
|
|
ShellRecorder *recorder;
|
|
|
|
GstElement *pipeline;
|
|
|
|
GstElement *src;
|
|
|
|
int outfile;
|
2012-10-25 17:26:17 -04:00
|
|
|
char *filename;
|
2009-03-13 17:14:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void recorder_set_stage (ShellRecorder *recorder,
|
|
|
|
ClutterStage *stage);
|
2010-02-08 15:25:58 -05:00
|
|
|
static void recorder_set_framerate (ShellRecorder *recorder,
|
|
|
|
int framerate);
|
2009-03-13 17:14:31 -04:00
|
|
|
static void recorder_set_pipeline (ShellRecorder *recorder,
|
|
|
|
const char *pipeline);
|
2012-10-25 17:14:20 -04:00
|
|
|
static void recorder_set_file_template (ShellRecorder *recorder,
|
|
|
|
const char *file_template);
|
2013-05-08 13:52:16 -04:00
|
|
|
static void recorder_set_draw_cursor (ShellRecorder *recorder,
|
|
|
|
gboolean draw_cursor);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
static void recorder_pipeline_set_caps (RecorderPipeline *pipeline);
|
|
|
|
static void recorder_pipeline_closed (RecorderPipeline *pipeline);
|
|
|
|
|
2016-06-06 14:26:28 -04:00
|
|
|
static void recorder_remove_redraw_timeout (ShellRecorder *recorder);
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
2018-01-03 02:55:38 -05:00
|
|
|
PROP_DISPLAY,
|
2009-03-13 17:14:31 -04:00
|
|
|
PROP_STAGE,
|
2010-02-08 15:25:58 -05:00
|
|
|
PROP_FRAMERATE,
|
2009-03-13 17:14:31 -04:00
|
|
|
PROP_PIPELINE,
|
2013-05-08 13:52:16 -04:00
|
|
|
PROP_FILE_TEMPLATE,
|
|
|
|
PROP_DRAW_CURSOR
|
2009-03-13 17:14:31 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE(ShellRecorder, shell_recorder, G_TYPE_OBJECT);
|
|
|
|
|
2012-01-30 16:44:32 -05:00
|
|
|
/* The default value of the target frame rate; we'll never record more
|
|
|
|
* than this many frames per second, though we may record less if the
|
|
|
|
* screen isn't being redrawn. 30 is a compromise between smoothness
|
|
|
|
* and the size of the recording.
|
2009-03-13 17:14:31 -04:00
|
|
|
*/
|
2012-01-30 16:44:32 -05:00
|
|
|
#define DEFAULT_FRAMES_PER_SECOND 30
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
/* The time (in milliseconds) between querying the server for the cursor
|
|
|
|
* position.
|
|
|
|
*/
|
|
|
|
#define UPDATE_POINTER_TIME 100
|
|
|
|
|
|
|
|
/* The time we wait (in milliseconds) before redrawing when the memory used
|
|
|
|
* changes.
|
|
|
|
*/
|
|
|
|
#define UPDATE_MEMORY_USED_DELAY 500
|
|
|
|
|
|
|
|
/* Maximum time between frames, in milliseconds. If we don't send data
|
|
|
|
* for a long period of time, then when we send the next frame, a lot
|
|
|
|
* of work can be created for the encoder to do, so we want to force a
|
|
|
|
* periodic redraw when nothing happen.
|
|
|
|
*/
|
|
|
|
#define MAXIMUM_PAUSE_TIME 1000
|
|
|
|
|
2011-06-16 10:36:00 -04:00
|
|
|
/* The default pipeline.
|
2009-03-13 17:14:31 -04:00
|
|
|
*/
|
2015-01-11 06:16:40 -05:00
|
|
|
#define DEFAULT_PIPELINE "vp9enc min_quantizer=13 max_quantizer=13 cpu-used=5 deadline=1000000 threads=%T ! queue ! webmmux"
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
/* If we can find the amount of memory on the machine, we use half
|
|
|
|
* of that for memory_target, otherwise, we use this value, in kB.
|
|
|
|
*/
|
|
|
|
#define DEFAULT_MEMORY_TARGET (512*1024)
|
|
|
|
|
|
|
|
static guint
|
|
|
|
get_memory_target (void)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
/* Really simple "get amount of memory on the machine" if it
|
|
|
|
* doesn't work, you just get the default memory target.
|
|
|
|
*/
|
|
|
|
f = fopen("/proc/meminfo", "r");
|
|
|
|
if (!f)
|
|
|
|
return DEFAULT_MEMORY_TARGET;
|
|
|
|
|
|
|
|
while (!feof(f))
|
|
|
|
{
|
|
|
|
gchar line_buffer[1024];
|
|
|
|
guint mem_total;
|
|
|
|
if (fscanf(f, "MemTotal: %u", &mem_total) == 1)
|
|
|
|
{
|
|
|
|
fclose(f);
|
|
|
|
return mem_total / 2;
|
|
|
|
}
|
|
|
|
/* Skip to the next line and discard what we read */
|
2009-08-06 17:59:20 -04:00
|
|
|
if (fgets(line_buffer, sizeof(line_buffer), f) == NULL)
|
|
|
|
break;
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
return DEFAULT_MEMORY_TARGET;
|
|
|
|
}
|
|
|
|
|
2011-01-21 12:55:00 -05:00
|
|
|
/*
|
|
|
|
* Used to force full stage redraws during recording to avoid artifacts
|
|
|
|
*
|
|
|
|
* Note: That this will cause the stage to be repainted on
|
|
|
|
* every animation frame even if the frame wouldn't normally cause any new
|
|
|
|
* drawing
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
recorder_repaint_hook (gpointer data)
|
|
|
|
{
|
|
|
|
ClutterActor *stage = data;
|
|
|
|
clutter_actor_queue_redraw (stage);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
static void
|
|
|
|
shell_recorder_init (ShellRecorder *recorder)
|
|
|
|
{
|
2009-08-06 15:07:55 -04:00
|
|
|
/* Calling gst_init() is a no-op if GStreamer was previously initialized */
|
|
|
|
gst_init (NULL, NULL);
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
shell_recorder_src_register ();
|
|
|
|
|
2012-11-16 11:04:19 -05:00
|
|
|
recorder->gdk_screen = gdk_screen_get_default ();
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
recorder->memory_target = get_memory_target();
|
|
|
|
|
2013-05-22 11:48:56 -04:00
|
|
|
recorder->a11y_settings = g_settings_new (A11Y_APPS_SCHEMA);
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
recorder->state = RECORDER_STATE_CLOSED;
|
2010-02-08 15:25:58 -05:00
|
|
|
recorder->framerate = DEFAULT_FRAMES_PER_SECOND;
|
2013-05-08 13:52:16 -04:00
|
|
|
recorder->draw_cursor = TRUE;
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_recorder_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
ShellRecorder *recorder = SHELL_RECORDER (object);
|
|
|
|
|
|
|
|
if (recorder->update_memory_used_timeout)
|
|
|
|
g_source_remove (recorder->update_memory_used_timeout);
|
|
|
|
|
|
|
|
if (recorder->cursor_image)
|
|
|
|
cairo_surface_destroy (recorder->cursor_image);
|
2013-08-14 04:34:58 -04:00
|
|
|
if (recorder->cursor_memory)
|
|
|
|
g_free (recorder->cursor_memory);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
recorder_set_stage (recorder, NULL);
|
|
|
|
recorder_set_pipeline (recorder, NULL);
|
2012-10-25 17:14:20 -04:00
|
|
|
recorder_set_file_template (recorder, NULL);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
2016-06-06 14:26:28 -04:00
|
|
|
recorder_remove_redraw_timeout (recorder);
|
|
|
|
|
2013-05-22 11:48:56 -04:00
|
|
|
g_clear_object (&recorder->a11y_settings);
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
G_OBJECT_CLASS (shell_recorder_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recorder_on_stage_destroy (ClutterActor *actor,
|
|
|
|
ShellRecorder *recorder)
|
|
|
|
{
|
|
|
|
recorder_set_stage (recorder, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add together the memory used by all pipelines; both the
|
|
|
|
* currently recording pipeline and pipelines finishing
|
|
|
|
* recording asynchronously.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
recorder_update_memory_used (ShellRecorder *recorder,
|
|
|
|
gboolean repaint)
|
|
|
|
{
|
|
|
|
guint memory_used = 0;
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
for (l = recorder->pipelines; l; l = l->next)
|
|
|
|
{
|
|
|
|
RecorderPipeline *pipeline = l->data;
|
|
|
|
guint pipeline_memory_used;
|
|
|
|
|
|
|
|
g_object_get (pipeline->src,
|
|
|
|
"memory-used", &pipeline_memory_used,
|
|
|
|
NULL);
|
|
|
|
memory_used += pipeline_memory_used;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memory_used != recorder->memory_used)
|
2013-07-17 15:26:06 -04:00
|
|
|
recorder->memory_used = memory_used;
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Timeout used to avoid not drawing for more than MAXIMUM_PAUSE_TIME
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
recorder_redraw_timeout (gpointer data)
|
|
|
|
{
|
|
|
|
ShellRecorder *recorder = data;
|
|
|
|
|
|
|
|
recorder->redraw_timeout = 0;
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (recorder->stage));
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recorder_add_redraw_timeout (ShellRecorder *recorder)
|
|
|
|
{
|
|
|
|
if (recorder->redraw_timeout == 0)
|
|
|
|
{
|
|
|
|
recorder->redraw_timeout = g_timeout_add (MAXIMUM_PAUSE_TIME,
|
|
|
|
recorder_redraw_timeout,
|
|
|
|
recorder);
|
2014-04-10 13:27:23 -04:00
|
|
|
g_source_set_name_by_id (recorder->redraw_timeout, "[gnome-shell] recorder_redraw_timeout");
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recorder_remove_redraw_timeout (ShellRecorder *recorder)
|
|
|
|
{
|
|
|
|
if (recorder->redraw_timeout != 0)
|
|
|
|
{
|
|
|
|
g_source_remove (recorder->redraw_timeout);
|
|
|
|
recorder->redraw_timeout = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recorder_fetch_cursor_image (ShellRecorder *recorder)
|
|
|
|
{
|
2013-08-14 04:34:58 -04:00
|
|
|
CoglTexture *texture;
|
|
|
|
int width, height;
|
2009-03-13 17:14:31 -04:00
|
|
|
int stride;
|
2013-08-14 04:34:58 -04:00
|
|
|
guint8 *data;
|
2011-01-24 16:56:23 -05:00
|
|
|
|
2013-08-14 04:34:58 -04:00
|
|
|
texture = meta_cursor_tracker_get_sprite (recorder->cursor_tracker);
|
2016-06-06 14:28:34 -04:00
|
|
|
if (!texture)
|
|
|
|
return;
|
|
|
|
|
2018-02-07 04:31:33 -05:00
|
|
|
meta_cursor_tracker_get_hot (recorder->cursor_tracker,
|
|
|
|
&recorder->cursor_hot_x, &recorder->cursor_hot_y);
|
|
|
|
|
2013-08-14 04:34:58 -04:00
|
|
|
width = cogl_texture_get_width (texture);
|
|
|
|
height = cogl_texture_get_height (texture);
|
|
|
|
stride = 4 * width;
|
|
|
|
data = g_new (guint8, stride * height);
|
|
|
|
cogl_texture_get_data (texture, CLUTTER_CAIRO_FORMAT_ARGB32, stride, data);
|
2011-05-24 18:46:47 -04:00
|
|
|
|
2013-08-14 04:34:58 -04:00
|
|
|
/* FIXME: cairo-gl? */
|
|
|
|
recorder->cursor_image = cairo_image_surface_create_for_data (data,
|
|
|
|
CAIRO_FORMAT_ARGB32,
|
|
|
|
width, height,
|
|
|
|
stride);
|
|
|
|
recorder->cursor_memory = data;
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Overlay the cursor image on the frame. We draw the cursor image
|
|
|
|
* into the host-memory buffer after we've captured the frame. An
|
|
|
|
* alternate approach would be to turn off the cursor while recording
|
|
|
|
* and draw the cursor ourselves with GL, but then we'd need to figure
|
|
|
|
* out what the cursor looks like, or hard-code a non-system cursor.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
recorder_draw_cursor (ShellRecorder *recorder,
|
|
|
|
GstBuffer *buffer)
|
|
|
|
{
|
2012-07-04 11:49:55 -04:00
|
|
|
GstMapInfo info;
|
2009-03-13 17:14:31 -04:00
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
/* We don't show a cursor unless the hot spot is in the frame; this
|
|
|
|
* means that sometimes we aren't going to draw a cursor even when
|
|
|
|
* there is a little bit overlapping within the stage */
|
2013-05-08 13:24:19 -04:00
|
|
|
if (recorder->pointer_x < recorder->area.x ||
|
|
|
|
recorder->pointer_y < recorder->area.y ||
|
|
|
|
recorder->pointer_x >= recorder->area.x + recorder->area.width ||
|
|
|
|
recorder->pointer_y >= recorder->area.y + recorder->area.height)
|
2009-03-13 17:14:31 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!recorder->cursor_image)
|
|
|
|
recorder_fetch_cursor_image (recorder);
|
|
|
|
|
|
|
|
if (!recorder->cursor_image)
|
|
|
|
return;
|
|
|
|
|
2012-07-04 11:49:55 -04:00
|
|
|
gst_buffer_map (buffer, &info, GST_MAP_WRITE);
|
|
|
|
surface = cairo_image_surface_create_for_data (info.data,
|
2009-03-13 17:14:31 -04:00
|
|
|
CAIRO_FORMAT_ARGB32,
|
2013-05-08 13:24:19 -04:00
|
|
|
recorder->area.width,
|
|
|
|
recorder->area.height,
|
|
|
|
recorder->area.width * 4);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
cairo_set_source_surface (cr,
|
|
|
|
recorder->cursor_image,
|
2013-05-08 13:24:19 -04:00
|
|
|
recorder->pointer_x - recorder->cursor_hot_x - recorder->area.x,
|
|
|
|
recorder->pointer_y - recorder->cursor_hot_y - recorder->area.y);
|
2009-03-13 17:14:31 -04:00
|
|
|
cairo_paint (cr);
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
cairo_surface_destroy (surface);
|
2012-07-04 11:49:55 -04:00
|
|
|
gst_buffer_unmap (buffer, &info);
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve a frame and feed it into the pipeline
|
|
|
|
*/
|
|
|
|
static void
|
2016-06-27 03:57:28 -04:00
|
|
|
recorder_record_frame (ShellRecorder *recorder,
|
|
|
|
gboolean paint)
|
2009-03-13 17:14:31 -04:00
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
2016-06-27 03:57:28 -04:00
|
|
|
ClutterCapture *captures;
|
|
|
|
int n_captures;
|
|
|
|
cairo_surface_t *image;
|
2009-03-13 17:14:31 -04:00
|
|
|
guint size;
|
2016-06-27 03:57:28 -04:00
|
|
|
uint8_t *data;
|
|
|
|
GstMemory *memory;
|
|
|
|
int i;
|
2015-02-17 03:16:44 -05:00
|
|
|
GstClock *clock;
|
|
|
|
GstClockTime now, base_time;
|
2009-03-13 17:14:31 -04:00
|
|
|
|
2012-07-04 18:08:28 -04:00
|
|
|
g_return_if_fail (recorder->current_pipeline != NULL);
|
|
|
|
|
2012-01-30 16:38:45 -05:00
|
|
|
/* If we get into the red zone, stop buffering new frames; 13/16 is
|
|
|
|
* a bit more than the 3/4 threshold for a red indicator to keep the
|
|
|
|
* indicator from flashing between red and yellow. */
|
|
|
|
if (recorder->memory_used > (recorder->memory_target * 13) / 16)
|
|
|
|
return;
|
|
|
|
|
2012-01-30 16:44:32 -05:00
|
|
|
/* Drop frames to get down to something like the target frame rate; since frames
|
|
|
|
* are generated with VBlank sync, we don't have full control anyways, so we just
|
|
|
|
* drop frames if the interval since the last frame is less than 75% of the
|
|
|
|
* desired inter-frame interval.
|
|
|
|
*/
|
2015-02-17 03:16:44 -05:00
|
|
|
clock = gst_element_get_clock (recorder->current_pipeline->src);
|
|
|
|
|
|
|
|
/* If we have no clock yet, the pipeline is not yet in PLAYING */
|
|
|
|
if (!clock)
|
2012-01-30 16:44:32 -05:00
|
|
|
return;
|
|
|
|
|
2015-02-17 03:16:44 -05:00
|
|
|
base_time = gst_element_get_base_time (recorder->current_pipeline->src);
|
|
|
|
now = gst_clock_get_time (clock) - base_time;
|
|
|
|
gst_object_unref (clock);
|
|
|
|
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (recorder->last_frame_time) &&
|
|
|
|
now - recorder->last_frame_time < gst_util_uint64_scale_int (GST_SECOND, 3, 4 * recorder->framerate))
|
|
|
|
return;
|
2012-01-30 16:44:32 -05:00
|
|
|
recorder->last_frame_time = now;
|
|
|
|
|
2016-06-27 03:57:28 -04:00
|
|
|
clutter_stage_capture (recorder->stage, paint, &recorder->area,
|
|
|
|
&captures, &n_captures);
|
|
|
|
|
|
|
|
if (n_captures == 0)
|
|
|
|
return;
|
|
|
|
|
2016-08-19 00:14:33 -04:00
|
|
|
if (n_captures == 1)
|
|
|
|
image = cairo_surface_reference (captures[0].image);
|
|
|
|
else
|
|
|
|
image = shell_util_composite_capture_images (captures,
|
|
|
|
n_captures,
|
|
|
|
recorder->area.x,
|
|
|
|
recorder->area.y,
|
|
|
|
recorder->area.width,
|
|
|
|
recorder->area.height);
|
2016-06-27 03:57:28 -04:00
|
|
|
|
|
|
|
data = cairo_image_surface_get_data (image);
|
2016-08-19 00:14:33 -04:00
|
|
|
size = (cairo_image_surface_get_height (image) *
|
|
|
|
cairo_image_surface_get_stride (image));
|
2012-01-27 16:33:26 -05:00
|
|
|
|
2016-08-19 00:14:33 -04:00
|
|
|
for (i = 0; i < n_captures; i++)
|
2016-06-27 03:57:28 -04:00
|
|
|
cairo_surface_destroy (captures[i].image);
|
|
|
|
g_free (captures);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
buffer = gst_buffer_new();
|
2016-06-27 03:57:28 -04:00
|
|
|
memory = gst_memory_new_wrapped (0, data, size, 0, size,
|
|
|
|
image,
|
|
|
|
(GDestroyNotify) cairo_surface_destroy);
|
|
|
|
gst_buffer_insert_memory (buffer, -1, memory);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
2015-02-17 03:16:44 -05:00
|
|
|
GST_BUFFER_PTS(buffer) = now;
|
2010-02-05 16:10:21 -05:00
|
|
|
|
2013-05-22 11:48:56 -04:00
|
|
|
if (recorder->draw_cursor &&
|
|
|
|
!g_settings_get_boolean (recorder->a11y_settings, MAGNIFIER_ACTIVE_KEY))
|
2013-05-08 13:52:16 -04:00
|
|
|
recorder_draw_cursor (recorder, buffer);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
shell_recorder_src_add_buffer (SHELL_RECORDER_SRC (recorder->current_pipeline->src), buffer);
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
|
|
|
|
/* Reset the timeout that we used to avoid an overlong pause in the stream */
|
|
|
|
recorder_remove_redraw_timeout (recorder);
|
|
|
|
recorder_add_redraw_timeout (recorder);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We hook in by recording each frame right after the stage is painted
|
|
|
|
* by clutter before glSwapBuffers() makes it visible to the user.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
recorder_on_stage_paint (ClutterActor *actor,
|
|
|
|
ShellRecorder *recorder)
|
|
|
|
{
|
|
|
|
if (recorder->state == RECORDER_STATE_RECORDING)
|
2016-06-27 03:57:28 -04:00
|
|
|
recorder_record_frame (recorder, FALSE);
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recorder_update_size (ShellRecorder *recorder)
|
|
|
|
{
|
|
|
|
ClutterActorBox allocation;
|
|
|
|
|
|
|
|
clutter_actor_get_allocation_box (CLUTTER_ACTOR (recorder->stage), &allocation);
|
|
|
|
recorder->stage_width = (int)(0.5 + allocation.x2 - allocation.x1);
|
|
|
|
recorder->stage_height = (int)(0.5 + allocation.y2 - allocation.y1);
|
2013-05-08 13:24:19 -04:00
|
|
|
|
|
|
|
if (!recorder->custom_area)
|
|
|
|
{
|
|
|
|
recorder->area.x = 0;
|
|
|
|
recorder->area.y = 0;
|
|
|
|
recorder->area.width = recorder->stage_width;
|
|
|
|
recorder->area.height = recorder->stage_height;
|
|
|
|
}
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recorder_on_stage_notify_size (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
ShellRecorder *recorder)
|
|
|
|
{
|
|
|
|
recorder_update_size (recorder);
|
|
|
|
|
|
|
|
/* This breaks the recording but tweaking the GStreamer pipeline a bit
|
|
|
|
* might make it work, at least if the codec can handle a stream where
|
|
|
|
* the frame size changes in the middle.
|
|
|
|
*/
|
|
|
|
if (recorder->current_pipeline)
|
|
|
|
recorder_pipeline_set_caps (recorder->current_pipeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
recorder_idle_redraw (gpointer data)
|
|
|
|
{
|
|
|
|
ShellRecorder *recorder = data;
|
|
|
|
|
|
|
|
recorder->redraw_idle = 0;
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (recorder->stage));
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recorder_queue_redraw (ShellRecorder *recorder)
|
|
|
|
{
|
|
|
|
/* If we just queue a redraw on every mouse motion (for example), we
|
2009-06-06 13:07:41 -04:00
|
|
|
* starve Clutter, which operates at a very low priority. So
|
2009-03-13 17:14:31 -04:00
|
|
|
* we need to queue a "low priority redraw" after timeline updates
|
|
|
|
*/
|
|
|
|
if (recorder->state == RECORDER_STATE_RECORDING && recorder->redraw_idle == 0)
|
2014-04-10 13:27:23 -04:00
|
|
|
{
|
|
|
|
recorder->redraw_idle = g_idle_add_full (CLUTTER_PRIORITY_REDRAW + 1,
|
|
|
|
recorder_idle_redraw, recorder, NULL);
|
|
|
|
g_source_set_name_by_id (recorder->redraw_idle, "[gnome-shell] recorder_idle_redraw");
|
|
|
|
}
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
|
2013-08-14 04:34:58 -04:00
|
|
|
static void
|
|
|
|
on_cursor_changed (MetaCursorTracker *tracker,
|
|
|
|
ShellRecorder *recorder)
|
|
|
|
{
|
|
|
|
if (recorder->cursor_image)
|
|
|
|
{
|
|
|
|
cairo_surface_destroy (recorder->cursor_image);
|
|
|
|
recorder->cursor_image = NULL;
|
|
|
|
}
|
|
|
|
if (recorder->cursor_memory)
|
|
|
|
{
|
|
|
|
g_free (recorder->cursor_memory);
|
|
|
|
recorder->cursor_memory = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
recorder_queue_redraw (recorder);
|
|
|
|
}
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
static void
|
|
|
|
recorder_update_pointer (ShellRecorder *recorder)
|
|
|
|
{
|
2014-07-26 10:27:12 -04:00
|
|
|
int pointer_x, pointer_y;
|
2009-03-13 17:14:31 -04:00
|
|
|
|
2014-07-26 10:27:12 -04:00
|
|
|
meta_cursor_tracker_get_pointer (recorder->cursor_tracker, &pointer_x, &pointer_y, NULL);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
2014-07-26 10:27:12 -04:00
|
|
|
if (pointer_x != recorder->pointer_x || pointer_y != recorder->pointer_y)
|
|
|
|
{
|
|
|
|
recorder->pointer_x = pointer_x;
|
|
|
|
recorder->pointer_y = pointer_y;
|
|
|
|
recorder_queue_redraw (recorder);
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
recorder_update_pointer_timeout (gpointer data)
|
|
|
|
{
|
|
|
|
recorder_update_pointer (data);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recorder_add_update_pointer_timeout (ShellRecorder *recorder)
|
|
|
|
{
|
|
|
|
if (!recorder->update_pointer_timeout)
|
2014-04-10 13:27:23 -04:00
|
|
|
{
|
|
|
|
recorder->update_pointer_timeout = g_timeout_add (UPDATE_POINTER_TIME,
|
|
|
|
recorder_update_pointer_timeout,
|
|
|
|
recorder);
|
|
|
|
g_source_set_name_by_id (recorder->update_pointer_timeout, "[gnome-shell] recorder_update_pointer_timeout");
|
|
|
|
}
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recorder_remove_update_pointer_timeout (ShellRecorder *recorder)
|
|
|
|
{
|
|
|
|
if (recorder->update_pointer_timeout)
|
|
|
|
{
|
|
|
|
g_source_remove (recorder->update_pointer_timeout);
|
|
|
|
recorder->update_pointer_timeout = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-11 14:36:05 -04:00
|
|
|
static void
|
|
|
|
recorder_connect_stage_callbacks (ShellRecorder *recorder)
|
|
|
|
{
|
|
|
|
g_signal_connect (recorder->stage, "destroy",
|
|
|
|
G_CALLBACK (recorder_on_stage_destroy), recorder);
|
|
|
|
g_signal_connect_after (recorder->stage, "paint",
|
|
|
|
G_CALLBACK (recorder_on_stage_paint), recorder);
|
|
|
|
g_signal_connect (recorder->stage, "notify::width",
|
|
|
|
G_CALLBACK (recorder_on_stage_notify_size), recorder);
|
2014-06-27 17:14:10 -04:00
|
|
|
g_signal_connect (recorder->stage, "notify::height",
|
2013-03-11 14:36:05 -04:00
|
|
|
G_CALLBACK (recorder_on_stage_notify_size), recorder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recorder_disconnect_stage_callbacks (ShellRecorder *recorder)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (recorder->stage,
|
|
|
|
(void *)recorder_on_stage_destroy,
|
|
|
|
recorder);
|
|
|
|
g_signal_handlers_disconnect_by_func (recorder->stage,
|
|
|
|
(void *)recorder_on_stage_paint,
|
|
|
|
recorder);
|
|
|
|
g_signal_handlers_disconnect_by_func (recorder->stage,
|
|
|
|
(void *)recorder_on_stage_notify_size,
|
|
|
|
recorder);
|
|
|
|
|
|
|
|
/* We don't don't deselect for cursor changes in case someone else just
|
|
|
|
* happened to be selecting for cursor events on the same window; sending
|
|
|
|
* us the events is close to free in any case.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (recorder->redraw_idle)
|
|
|
|
{
|
|
|
|
g_source_remove (recorder->redraw_idle);
|
|
|
|
recorder->redraw_idle = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
static void
|
|
|
|
recorder_set_stage (ShellRecorder *recorder,
|
|
|
|
ClutterStage *stage)
|
|
|
|
{
|
|
|
|
if (recorder->stage == stage)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (recorder->current_pipeline)
|
|
|
|
shell_recorder_close (recorder);
|
|
|
|
|
|
|
|
if (recorder->stage)
|
2013-03-11 14:36:05 -04:00
|
|
|
recorder_disconnect_stage_callbacks (recorder);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
recorder->stage = stage;
|
|
|
|
|
|
|
|
if (recorder->stage)
|
2014-07-26 10:27:12 -04:00
|
|
|
recorder_update_size (recorder);
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
|
2013-08-14 04:34:58 -04:00
|
|
|
static void
|
2018-01-03 02:55:38 -05:00
|
|
|
recorder_set_display (ShellRecorder *recorder,
|
|
|
|
MetaDisplay *display)
|
2013-08-14 04:34:58 -04:00
|
|
|
{
|
|
|
|
MetaCursorTracker *tracker;
|
|
|
|
|
2018-01-03 02:55:38 -05:00
|
|
|
tracker = meta_cursor_tracker_get_for_display (display);
|
2013-08-14 04:34:58 -04:00
|
|
|
|
|
|
|
if (tracker == recorder->cursor_tracker)
|
|
|
|
return;
|
|
|
|
|
|
|
|
recorder->cursor_tracker = tracker;
|
|
|
|
g_signal_connect_object (tracker, "cursor-changed",
|
|
|
|
G_CALLBACK (on_cursor_changed), recorder, 0);
|
|
|
|
}
|
|
|
|
|
2010-02-08 15:25:58 -05:00
|
|
|
static void
|
|
|
|
recorder_set_framerate (ShellRecorder *recorder,
|
|
|
|
int framerate)
|
|
|
|
{
|
|
|
|
if (framerate == recorder->framerate)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (recorder->current_pipeline)
|
|
|
|
shell_recorder_close (recorder);
|
|
|
|
|
|
|
|
recorder->framerate = framerate;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (recorder), "framerate");
|
|
|
|
}
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
static void
|
|
|
|
recorder_set_pipeline (ShellRecorder *recorder,
|
|
|
|
const char *pipeline)
|
|
|
|
{
|
|
|
|
if (pipeline == recorder->pipeline_description ||
|
|
|
|
(pipeline && recorder->pipeline_description && strcmp (recorder->pipeline_description, pipeline) == 0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (recorder->current_pipeline)
|
|
|
|
shell_recorder_close (recorder);
|
|
|
|
|
|
|
|
if (recorder->pipeline_description)
|
|
|
|
g_free (recorder->pipeline_description);
|
|
|
|
|
|
|
|
recorder->pipeline_description = g_strdup (pipeline);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (recorder), "pipeline");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-10-25 17:14:20 -04:00
|
|
|
recorder_set_file_template (ShellRecorder *recorder,
|
|
|
|
const char *file_template)
|
2009-03-13 17:14:31 -04:00
|
|
|
{
|
2012-10-25 17:14:20 -04:00
|
|
|
if (file_template == recorder->file_template ||
|
|
|
|
(file_template && recorder->file_template && strcmp (recorder->file_template, file_template) == 0))
|
2009-03-13 17:14:31 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (recorder->current_pipeline)
|
|
|
|
shell_recorder_close (recorder);
|
|
|
|
|
2012-10-25 17:14:20 -04:00
|
|
|
if (recorder->file_template)
|
|
|
|
g_free (recorder->file_template);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
2012-10-25 17:14:20 -04:00
|
|
|
recorder->file_template = g_strdup (file_template);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
2012-10-25 17:14:20 -04:00
|
|
|
g_object_notify (G_OBJECT (recorder), "file-template");
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
|
2013-05-08 13:52:16 -04:00
|
|
|
static void
|
|
|
|
recorder_set_draw_cursor (ShellRecorder *recorder,
|
|
|
|
gboolean draw_cursor)
|
|
|
|
{
|
|
|
|
if (draw_cursor == recorder->draw_cursor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
recorder->draw_cursor = draw_cursor;
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (recorder), "draw-cursor");
|
|
|
|
}
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
static void
|
|
|
|
shell_recorder_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ShellRecorder *recorder = SHELL_RECORDER (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2018-01-03 02:55:38 -05:00
|
|
|
case PROP_DISPLAY:
|
|
|
|
recorder_set_display (recorder, g_value_get_object (value));
|
2013-08-14 04:34:58 -04:00
|
|
|
break;
|
2009-03-13 17:14:31 -04:00
|
|
|
case PROP_STAGE:
|
|
|
|
recorder_set_stage (recorder, g_value_get_object (value));
|
|
|
|
break;
|
2010-02-08 15:25:58 -05:00
|
|
|
case PROP_FRAMERATE:
|
|
|
|
recorder_set_framerate (recorder, g_value_get_int (value));
|
|
|
|
break;
|
2009-03-13 17:14:31 -04:00
|
|
|
case PROP_PIPELINE:
|
|
|
|
recorder_set_pipeline (recorder, g_value_get_string (value));
|
|
|
|
break;
|
2012-10-25 17:14:20 -04:00
|
|
|
case PROP_FILE_TEMPLATE:
|
|
|
|
recorder_set_file_template (recorder, g_value_get_string (value));
|
2009-03-13 17:14:31 -04:00
|
|
|
break;
|
2013-05-08 13:52:16 -04:00
|
|
|
case PROP_DRAW_CURSOR:
|
|
|
|
recorder_set_draw_cursor (recorder, g_value_get_boolean (value));
|
|
|
|
break;
|
2009-03-13 17:14:31 -04:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_recorder_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
ShellRecorder *recorder = SHELL_RECORDER (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_STAGE:
|
|
|
|
g_value_set_object (value, G_OBJECT (recorder->stage));
|
|
|
|
break;
|
2010-02-08 15:25:58 -05:00
|
|
|
case PROP_FRAMERATE:
|
|
|
|
g_value_set_int (value, recorder->framerate);
|
|
|
|
break;
|
2009-03-13 17:14:31 -04:00
|
|
|
case PROP_PIPELINE:
|
|
|
|
g_value_set_string (value, recorder->pipeline_description);
|
|
|
|
break;
|
2012-10-25 17:14:20 -04:00
|
|
|
case PROP_FILE_TEMPLATE:
|
|
|
|
g_value_set_string (value, recorder->file_template);
|
2009-03-13 17:14:31 -04:00
|
|
|
break;
|
2013-05-08 13:52:16 -04:00
|
|
|
case PROP_DRAW_CURSOR:
|
|
|
|
g_value_set_boolean (value, recorder->draw_cursor);
|
|
|
|
break;
|
2009-03-13 17:14:31 -04:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_recorder_class_init (ShellRecorderClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->finalize = shell_recorder_finalize;
|
|
|
|
gobject_class->get_property = shell_recorder_get_property;
|
|
|
|
gobject_class->set_property = shell_recorder_set_property;
|
|
|
|
|
2013-08-14 04:34:58 -04:00
|
|
|
g_object_class_install_property (gobject_class,
|
2018-01-03 02:55:38 -05:00
|
|
|
PROP_DISPLAY,
|
|
|
|
g_param_spec_object ("display",
|
|
|
|
"Display",
|
|
|
|
"Display to record",
|
|
|
|
META_TYPE_DISPLAY,
|
2013-08-14 04:34:58 -04:00
|
|
|
G_PARAM_WRITABLE));
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_STAGE,
|
|
|
|
g_param_spec_object ("stage",
|
|
|
|
"Stage",
|
|
|
|
"Stage to record",
|
|
|
|
CLUTTER_TYPE_STAGE,
|
|
|
|
G_PARAM_READWRITE));
|
2010-02-08 15:25:58 -05:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_FRAMERATE,
|
|
|
|
g_param_spec_int ("framerate",
|
|
|
|
"Framerate",
|
|
|
|
"Framerate used for resulting video in frames-per-second",
|
|
|
|
0,
|
|
|
|
G_MAXINT,
|
|
|
|
DEFAULT_FRAMES_PER_SECOND,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_PIPELINE,
|
|
|
|
g_param_spec_string ("pipeline",
|
|
|
|
"Pipeline",
|
|
|
|
"GStreamer pipeline description to encode recordings",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
2012-10-25 17:14:20 -04:00
|
|
|
PROP_FILE_TEMPLATE,
|
|
|
|
g_param_spec_string ("file-template",
|
|
|
|
"File Template",
|
2009-03-13 17:14:31 -04:00
|
|
|
"The filename template to use for output files",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE));
|
2013-05-08 13:52:16 -04:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_DRAW_CURSOR,
|
|
|
|
g_param_spec_boolean ("draw-cursor",
|
|
|
|
"Draw Cursor",
|
|
|
|
"Whether to record the cursor",
|
|
|
|
TRUE,
|
|
|
|
G_PARAM_READWRITE));
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets the GstCaps (video format, in this case) on the stream
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
recorder_pipeline_set_caps (RecorderPipeline *pipeline)
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
2012-07-04 11:49:55 -04:00
|
|
|
/* The data is always native-endian xRGB; videoconvert
|
2009-03-13 17:14:31 -04:00
|
|
|
* doesn't support little-endian xRGB, but does support
|
|
|
|
* big-endian BGRx.
|
|
|
|
*/
|
2012-07-04 11:49:55 -04:00
|
|
|
caps = gst_caps_new_simple ("video/x-raw",
|
2009-03-13 17:14:31 -04:00
|
|
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
2012-07-04 11:49:55 -04:00
|
|
|
"format", G_TYPE_STRING, "BGRx",
|
2009-03-13 17:14:31 -04:00
|
|
|
#else
|
2012-07-04 11:49:55 -04:00
|
|
|
"format", G_TYPE_STRING, "xRGB",
|
2009-03-13 17:14:31 -04:00
|
|
|
#endif
|
2010-02-08 15:25:58 -05:00
|
|
|
"framerate", GST_TYPE_FRACTION, pipeline->recorder->framerate, 1,
|
2013-05-08 13:24:19 -04:00
|
|
|
"width", G_TYPE_INT, pipeline->recorder->area.width,
|
|
|
|
"height", G_TYPE_INT, pipeline->recorder->area.height,
|
2009-03-13 17:14:31 -04:00
|
|
|
NULL);
|
|
|
|
g_object_set (pipeline->src, "caps", caps, NULL);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Augments the supplied pipeline with the source elements: the actual
|
|
|
|
* ShellRecorderSrc element where we inject frames then additional elements
|
|
|
|
* to convert the output into something palatable.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
recorder_pipeline_add_source (RecorderPipeline *pipeline)
|
|
|
|
{
|
|
|
|
GstPad *sink_pad = NULL, *src_pad = NULL;
|
|
|
|
gboolean result = FALSE;
|
2012-07-04 11:49:55 -04:00
|
|
|
GstElement *videoconvert;
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
sink_pad = gst_bin_find_unlinked_pad (GST_BIN (pipeline->pipeline), GST_PAD_SINK);
|
|
|
|
if (sink_pad == NULL)
|
|
|
|
{
|
|
|
|
g_warning("ShellRecorder: pipeline has no unlinked sink pad");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
pipeline->src = gst_element_factory_make ("shellrecordersrc", NULL);
|
|
|
|
if (pipeline->src == NULL)
|
|
|
|
{
|
|
|
|
g_warning ("Can't create recorder source element");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
gst_bin_add (GST_BIN (pipeline->pipeline), pipeline->src);
|
|
|
|
|
|
|
|
recorder_pipeline_set_caps (pipeline);
|
|
|
|
|
2012-07-04 11:49:55 -04:00
|
|
|
/* The videoconvert element is a generic converter; it will convert
|
2009-03-13 17:14:31 -04:00
|
|
|
* our supplied fixed format data into whatever the encoder wants
|
|
|
|
*/
|
2012-07-04 11:49:55 -04:00
|
|
|
videoconvert = gst_element_factory_make ("videoconvert", NULL);
|
|
|
|
if (!videoconvert)
|
2009-03-13 17:14:31 -04:00
|
|
|
{
|
2012-07-04 11:49:55 -04:00
|
|
|
g_warning("Can't create videoconvert element");
|
2009-03-13 17:14:31 -04:00
|
|
|
goto out;
|
|
|
|
}
|
2012-07-04 11:49:55 -04:00
|
|
|
gst_bin_add (GST_BIN (pipeline->pipeline), videoconvert);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
2012-07-04 11:49:55 -04:00
|
|
|
gst_element_link_many (pipeline->src, videoconvert, NULL);
|
|
|
|
src_pad = gst_element_get_static_pad (videoconvert, "src");
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
if (!src_pad)
|
|
|
|
{
|
|
|
|
g_warning("ShellRecorder: can't get src pad to link into pipeline");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_pad_link (src_pad, sink_pad) != GST_PAD_LINK_OK)
|
|
|
|
{
|
|
|
|
g_warning("ShellRecorder: can't link to sink pad");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = TRUE;
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (sink_pad)
|
|
|
|
gst_object_unref (sink_pad);
|
|
|
|
if (src_pad)
|
|
|
|
gst_object_unref (src_pad);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
get_absolute_path (char *maybe_relative)
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
if (g_path_is_absolute (maybe_relative))
|
|
|
|
path = g_strdup (maybe_relative);
|
|
|
|
else
|
|
|
|
{
|
2012-02-28 14:54:06 -05:00
|
|
|
const char *video_dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
|
2016-04-13 15:22:56 -04:00
|
|
|
if (!g_file_test (video_dir, G_FILE_TEST_EXISTS))
|
|
|
|
video_dir = g_get_home_dir ();
|
|
|
|
|
2012-02-24 17:16:51 -05:00
|
|
|
path = g_build_filename (video_dir, maybe_relative, NULL);
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open a file for writing. Opening the file ourselves and using fdsink has
|
|
|
|
* the advantage over filesink of being able to use O_EXCL when we want to
|
|
|
|
* avoid overwriting* an existing file. Returns -1 if the file couldn't
|
|
|
|
* be opened.
|
|
|
|
*/
|
|
|
|
static int
|
2012-10-25 17:26:17 -04:00
|
|
|
recorder_open_outfile (ShellRecorder *recorder,
|
|
|
|
char **outfilename)
|
2009-03-13 17:14:31 -04:00
|
|
|
{
|
|
|
|
const char *pattern;
|
|
|
|
int flags;
|
|
|
|
int outfile = -1;
|
|
|
|
|
2012-10-25 17:14:20 -04:00
|
|
|
pattern = recorder->file_template;
|
2009-03-13 17:14:31 -04:00
|
|
|
if (!pattern)
|
2012-06-04 19:30:54 -04:00
|
|
|
return -1;
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
GString *filename = g_string_new (NULL);
|
|
|
|
const char *p;
|
2012-02-28 15:01:49 -05:00
|
|
|
char *path;
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
for (p = pattern; *p; p++)
|
|
|
|
{
|
|
|
|
if (*p == '%')
|
|
|
|
{
|
|
|
|
switch (*(p + 1))
|
|
|
|
{
|
|
|
|
case '%':
|
|
|
|
case '\0':
|
|
|
|
g_string_append_c (filename, '%');
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
{
|
2012-02-24 12:05:29 -05:00
|
|
|
/* Appends date according to locale */
|
|
|
|
GDateTime *datetime = g_date_time_new_now_local ();
|
|
|
|
char *date_str = g_date_time_format (datetime, "%0x");
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
for (s = date_str; *s; s++)
|
|
|
|
if (G_IS_DIR_SEPARATOR (*s))
|
|
|
|
*s = '-';
|
|
|
|
|
|
|
|
g_string_append (filename, date_str);
|
|
|
|
g_free (date_str);
|
|
|
|
g_date_time_unref (datetime);
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
break;
|
2012-02-24 12:07:02 -05:00
|
|
|
case 't':
|
|
|
|
{
|
|
|
|
/* Appends time according to locale */
|
|
|
|
GDateTime *datetime = g_date_time_new_now_local ();
|
|
|
|
char *time_str = g_date_time_format (datetime, "%0X");
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
for (s = time_str; *s; s++)
|
|
|
|
if (G_IS_DIR_SEPARATOR (*s))
|
|
|
|
*s = ':';
|
|
|
|
|
|
|
|
g_string_append (filename, time_str);
|
|
|
|
g_free (time_str);
|
|
|
|
g_date_time_unref (datetime);
|
|
|
|
}
|
2012-06-04 23:17:43 -04:00
|
|
|
break;
|
2009-03-13 17:14:31 -04:00
|
|
|
default:
|
2012-06-04 19:43:04 -04:00
|
|
|
g_warning ("Unknown escape %%%c in filename", *(p + 1));
|
2009-03-13 17:14:31 -04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_string_append_c (filename, *p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If a filename is explicitly specified without %u then we assume the user
|
|
|
|
* is fine with over-writing the old contents; putting %u in the default
|
|
|
|
* should avoid problems with malicious symlinks.
|
|
|
|
*/
|
|
|
|
flags = O_WRONLY | O_CREAT | O_TRUNC;
|
|
|
|
|
2012-02-24 17:16:51 -05:00
|
|
|
path = get_absolute_path (filename->str);
|
|
|
|
outfile = open (path, flags, 0666);
|
2009-03-13 17:14:31 -04:00
|
|
|
if (outfile != -1)
|
|
|
|
{
|
|
|
|
g_printerr ("Recording to %s\n", path);
|
|
|
|
|
2012-10-25 17:26:17 -04:00
|
|
|
if (outfilename != NULL)
|
|
|
|
*outfilename = path;
|
|
|
|
else
|
|
|
|
g_free (path);
|
2009-03-13 17:14:31 -04:00
|
|
|
g_string_free (filename, TRUE);
|
2012-10-25 17:26:17 -04:00
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2012-06-04 19:31:45 -04:00
|
|
|
if (outfile == -1 && errno != EEXIST)
|
2009-03-13 17:14:31 -04:00
|
|
|
{
|
2016-08-19 13:10:28 -04:00
|
|
|
g_warning ("Cannot open output file '%s': %s", path, g_strerror (errno));
|
2009-03-13 17:14:31 -04:00
|
|
|
g_string_free (filename, TRUE);
|
2012-02-28 15:01:49 -05:00
|
|
|
g_free (path);
|
2009-03-13 17:14:31 -04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_string_free (filename, TRUE);
|
2012-02-28 15:01:49 -05:00
|
|
|
g_free (path);
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2012-02-24 17:16:51 -05:00
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
return outfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Augments the supplied pipeline with a sink element to write to the output
|
|
|
|
* file, if necessary.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
recorder_pipeline_add_sink (RecorderPipeline *pipeline)
|
|
|
|
{
|
|
|
|
GstPad *sink_pad = NULL, *src_pad = NULL;
|
|
|
|
GstElement *fdsink;
|
|
|
|
gboolean result = FALSE;
|
|
|
|
|
|
|
|
src_pad = gst_bin_find_unlinked_pad (GST_BIN (pipeline->pipeline), GST_PAD_SRC);
|
|
|
|
if (src_pad == NULL)
|
|
|
|
{
|
|
|
|
/* Nothing to do - assume that we were given a complete pipeline */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-10-25 17:26:17 -04:00
|
|
|
pipeline->outfile = recorder_open_outfile (pipeline->recorder,
|
|
|
|
&pipeline->filename);
|
2009-03-13 17:14:31 -04:00
|
|
|
if (pipeline->outfile == -1)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
fdsink = gst_element_factory_make ("fdsink", NULL);
|
|
|
|
if (fdsink == NULL)
|
|
|
|
{
|
|
|
|
g_warning("Can't create fdsink element");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
gst_bin_add (GST_BIN (pipeline->pipeline), fdsink);
|
|
|
|
g_object_set (fdsink, "fd", pipeline->outfile, NULL);
|
|
|
|
|
|
|
|
sink_pad = gst_element_get_static_pad (fdsink, "sink");
|
|
|
|
if (!sink_pad)
|
|
|
|
{
|
|
|
|
g_warning("ShellRecorder: can't get sink pad to link pipeline output");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_pad_link (src_pad, sink_pad) != GST_PAD_LINK_OK)
|
|
|
|
{
|
|
|
|
g_warning("ShellRecorder: can't link to sink pad");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = TRUE;
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (src_pad)
|
|
|
|
gst_object_unref (src_pad);
|
|
|
|
if (sink_pad)
|
|
|
|
gst_object_unref (sink_pad);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
recorder_update_memory_used_timeout (gpointer data)
|
|
|
|
{
|
|
|
|
ShellRecorder *recorder = data;
|
|
|
|
recorder->update_memory_used_timeout = 0;
|
|
|
|
|
|
|
|
recorder_update_memory_used (recorder, TRUE);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We throttle down the frequency which we recompute memory usage
|
|
|
|
* and draw the buffer indicator to avoid cutting into performance.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
recorder_pipeline_on_memory_used_changed (ShellRecorderSrc *src,
|
|
|
|
GParamSpec *spec,
|
|
|
|
RecorderPipeline *pipeline)
|
|
|
|
{
|
|
|
|
ShellRecorder *recorder = pipeline->recorder;
|
|
|
|
if (!recorder)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (recorder->update_memory_used_timeout == 0)
|
2014-04-10 13:27:23 -04:00
|
|
|
{
|
|
|
|
recorder->update_memory_used_timeout = g_timeout_add (UPDATE_MEMORY_USED_DELAY,
|
|
|
|
recorder_update_memory_used_timeout,
|
|
|
|
recorder);
|
|
|
|
g_source_set_name_by_id (recorder->update_memory_used_timeout, "[gnome-shell] recorder_update_memory_used_timeout");
|
|
|
|
}
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recorder_pipeline_free (RecorderPipeline *pipeline)
|
|
|
|
{
|
|
|
|
if (pipeline->pipeline != NULL)
|
|
|
|
gst_object_unref (pipeline->pipeline);
|
|
|
|
|
|
|
|
if (pipeline->outfile != -1)
|
|
|
|
close (pipeline->outfile);
|
|
|
|
|
2012-10-25 17:26:17 -04:00
|
|
|
g_free (pipeline->filename);
|
|
|
|
|
2012-07-26 17:26:55 -04:00
|
|
|
g_clear_object (&pipeline->recorder);
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
g_free (pipeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Function gets called on pipeline-global events; we use it to
|
|
|
|
* know when the pipeline is finished.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
recorder_pipeline_bus_watch (GstBus *bus,
|
|
|
|
GstMessage *message,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
RecorderPipeline *pipeline = data;
|
|
|
|
|
2015-09-23 14:43:42 -04:00
|
|
|
if (message->type == GST_MESSAGE_EOS)
|
2009-03-13 17:14:31 -04:00
|
|
|
{
|
|
|
|
recorder_pipeline_closed (pipeline);
|
|
|
|
return FALSE; /* remove watch */
|
2015-09-23 14:43:42 -04:00
|
|
|
}
|
|
|
|
else if (message->type == GST_MESSAGE_ERROR)
|
|
|
|
{
|
|
|
|
GError *error;
|
|
|
|
|
|
|
|
gst_message_parse_error (message, &error, NULL);
|
|
|
|
g_warning ("Error in recording pipeline: %s\n", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
recorder_pipeline_closed (pipeline);
|
|
|
|
return FALSE; /* remove watch */
|
2009-03-13 17:14:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Leave the watch in place */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clean up when the pipeline is finished
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
recorder_pipeline_closed (RecorderPipeline *pipeline)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (pipeline->src,
|
|
|
|
(gpointer) recorder_pipeline_on_memory_used_changed,
|
|
|
|
pipeline);
|
|
|
|
|
2013-03-11 14:36:05 -04:00
|
|
|
recorder_disconnect_stage_callbacks (pipeline->recorder);
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
gst_element_set_state (pipeline->pipeline, GST_STATE_NULL);
|
|
|
|
|
|
|
|
if (pipeline->recorder)
|
|
|
|
{
|
2012-10-25 17:26:17 -04:00
|
|
|
GtkRecentManager *recent_manager;
|
|
|
|
GFile *file;
|
|
|
|
char *uri;
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
ShellRecorder *recorder = pipeline->recorder;
|
|
|
|
if (pipeline == recorder->current_pipeline)
|
|
|
|
{
|
|
|
|
/* Error case; force a close */
|
|
|
|
recorder->current_pipeline = NULL;
|
|
|
|
shell_recorder_close (recorder);
|
|
|
|
}
|
|
|
|
|
2012-10-25 17:26:17 -04:00
|
|
|
recent_manager = gtk_recent_manager_get_default ();
|
|
|
|
|
|
|
|
file = g_file_new_for_path (pipeline->filename);
|
|
|
|
uri = g_file_get_uri (file);
|
|
|
|
gtk_recent_manager_add_item (recent_manager,
|
|
|
|
uri);
|
|
|
|
g_free (uri);
|
|
|
|
g_object_unref (file);
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
recorder->pipelines = g_slist_remove (recorder->pipelines, pipeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
recorder_pipeline_free (pipeline);
|
|
|
|
}
|
|
|
|
|
2011-01-21 13:33:11 -05:00
|
|
|
/*
|
|
|
|
* Replaces '%T' in the passed pipeline with the thread count,
|
2015-01-11 09:47:52 -05:00
|
|
|
* the maximum possible value is 64 (limit of what vp9enc supports)
|
2011-01-21 13:33:11 -05:00
|
|
|
*
|
|
|
|
* It is assumes that %T occurs only once.
|
|
|
|
*/
|
|
|
|
static char*
|
|
|
|
substitute_thread_count (const char *pipeline)
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
int n_threads;
|
|
|
|
GString *result;
|
|
|
|
|
|
|
|
tmp = strstr (pipeline, "%T");
|
|
|
|
|
|
|
|
if (!tmp)
|
|
|
|
return g_strdup (pipeline);
|
|
|
|
|
|
|
|
#ifdef _SC_NPROCESSORS_ONLN
|
2016-02-09 17:51:45 -05:00
|
|
|
{
|
|
|
|
int n_processors = sysconf (_SC_NPROCESSORS_ONLN); /* includes hyper-threading */
|
|
|
|
n_threads = MIN (MAX (1, n_processors - 1), 64);
|
|
|
|
}
|
2011-01-21 13:33:11 -05:00
|
|
|
#else
|
2016-02-09 17:51:45 -05:00
|
|
|
n_threads = 3;
|
2011-01-21 13:33:11 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
result = g_string_new (NULL);
|
|
|
|
g_string_append_len (result, pipeline, tmp - pipeline);
|
|
|
|
g_string_append_printf (result, "%d", n_threads);
|
|
|
|
g_string_append (result, tmp + 2);
|
|
|
|
|
2015-01-11 09:47:52 -05:00
|
|
|
return g_string_free (result, FALSE);
|
2011-01-21 13:33:11 -05:00
|
|
|
}
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
static gboolean
|
|
|
|
recorder_open_pipeline (ShellRecorder *recorder)
|
|
|
|
{
|
|
|
|
RecorderPipeline *pipeline;
|
|
|
|
const char *pipeline_description;
|
2011-01-21 13:33:11 -05:00
|
|
|
char *parsed_pipeline;
|
2009-03-13 17:14:31 -04:00
|
|
|
GError *error = NULL;
|
|
|
|
GstBus *bus;
|
|
|
|
|
2015-01-11 09:47:52 -05:00
|
|
|
pipeline = g_new0 (RecorderPipeline, 1);
|
2012-07-26 17:26:55 -04:00
|
|
|
pipeline->recorder = g_object_ref (recorder);
|
2009-03-13 17:14:31 -04:00
|
|
|
pipeline->outfile = - 1;
|
|
|
|
|
|
|
|
pipeline_description = recorder->pipeline_description;
|
|
|
|
if (!pipeline_description)
|
|
|
|
pipeline_description = DEFAULT_PIPELINE;
|
|
|
|
|
2011-01-21 13:33:11 -05:00
|
|
|
parsed_pipeline = substitute_thread_count (pipeline_description);
|
|
|
|
|
|
|
|
pipeline->pipeline = gst_parse_launch_full (parsed_pipeline, NULL,
|
2009-03-13 17:14:31 -04:00
|
|
|
GST_PARSE_FLAG_FATAL_ERRORS,
|
|
|
|
&error);
|
2011-01-21 13:33:11 -05:00
|
|
|
g_free (parsed_pipeline);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
if (pipeline->pipeline == NULL)
|
|
|
|
{
|
|
|
|
g_warning ("ShellRecorder: failed to parse pipeline: %s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!recorder_pipeline_add_source (pipeline))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!recorder_pipeline_add_sink (pipeline))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline->pipeline, GST_STATE_PLAYING);
|
|
|
|
|
|
|
|
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline->pipeline));
|
|
|
|
gst_bus_add_watch (bus, recorder_pipeline_bus_watch, pipeline);
|
|
|
|
gst_object_unref (bus);
|
|
|
|
|
|
|
|
g_signal_connect (pipeline->src, "notify::memory-used",
|
|
|
|
G_CALLBACK (recorder_pipeline_on_memory_used_changed), pipeline);
|
|
|
|
|
|
|
|
recorder->current_pipeline = pipeline;
|
|
|
|
recorder->pipelines = g_slist_prepend (recorder->pipelines, pipeline);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
error:
|
|
|
|
recorder_pipeline_free (pipeline);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recorder_close_pipeline (ShellRecorder *recorder)
|
|
|
|
{
|
|
|
|
if (recorder->current_pipeline != NULL)
|
|
|
|
{
|
|
|
|
/* This will send an EOS (end-of-stream) message after the last frame
|
|
|
|
* is written. The bus watch for the pipeline will get it and do
|
|
|
|
* final cleanup
|
|
|
|
*/
|
2014-06-11 16:18:39 -04:00
|
|
|
gst_element_send_event (recorder->current_pipeline->pipeline,
|
|
|
|
gst_event_new_eos());
|
2009-03-13 17:14:31 -04:00
|
|
|
recorder->current_pipeline = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* shell_recorder_new:
|
|
|
|
* @stage: The #ClutterStage
|
|
|
|
*
|
|
|
|
* Create a new #ShellRecorder to record movies of a #ClutterStage
|
|
|
|
*
|
|
|
|
* Return value: The newly created #ShellRecorder object
|
|
|
|
*/
|
|
|
|
ShellRecorder *
|
|
|
|
shell_recorder_new (ClutterStage *stage)
|
|
|
|
{
|
|
|
|
return g_object_new (SHELL_TYPE_RECORDER,
|
|
|
|
"stage", stage,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2010-02-08 15:25:58 -05:00
|
|
|
/**
|
|
|
|
* shell_recorder_set_framerate:
|
|
|
|
* @recorder: the #ShellRecorder
|
|
|
|
* @framerate: Framerate used for resulting video in frames-per-second.
|
|
|
|
*
|
2012-01-30 16:44:32 -05:00
|
|
|
* Sets the number of frames per second we try to record. Less frames
|
|
|
|
* will be recorded when the screen doesn't need to be redrawn this
|
|
|
|
* quickly. (This value will also be set as the framerate for the
|
|
|
|
* GStreamer pipeline; whether that has an effect on the resulting
|
|
|
|
* video will depend on the details of the pipeline and the codec. The
|
|
|
|
* default encoding to webm format doesn't pay attention to the pipeline
|
|
|
|
* framerate.)
|
2010-02-08 15:25:58 -05:00
|
|
|
*
|
2012-01-30 16:44:32 -05:00
|
|
|
* The default value is 30.
|
2010-02-08 15:25:58 -05:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
shell_recorder_set_framerate (ShellRecorder *recorder,
|
|
|
|
int framerate)
|
|
|
|
{
|
|
|
|
g_return_if_fail (SHELL_IS_RECORDER (recorder));
|
|
|
|
|
|
|
|
recorder_set_framerate (recorder, framerate);
|
|
|
|
}
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
/**
|
2012-10-25 17:14:20 -04:00
|
|
|
* shell_recorder_set_file_template:
|
2009-03-13 17:14:31 -04:00
|
|
|
* @recorder: the #ShellRecorder
|
2012-10-25 17:14:20 -04:00
|
|
|
* @file_template: the filename template to use for output files,
|
|
|
|
* or %NULL for the defalt value.
|
2009-03-13 17:14:31 -04:00
|
|
|
*
|
|
|
|
* Sets the filename that will be used when creating output
|
|
|
|
* files. This is only used if the configured pipeline has an
|
|
|
|
* unconnected source pad (as the default pipeline does). If
|
|
|
|
* the pipeline is complete, then the filename is unused. The
|
|
|
|
* provided string is used as a template.It can contain
|
|
|
|
* the following escapes:
|
|
|
|
*
|
|
|
|
* %d: The current date as YYYYYMMDD
|
|
|
|
* %%: A literal percent
|
|
|
|
*
|
|
|
|
* The default value is 'shell-%d%u-%c.ogg'.
|
|
|
|
*/
|
|
|
|
void
|
2012-10-25 17:14:20 -04:00
|
|
|
shell_recorder_set_file_template (ShellRecorder *recorder,
|
|
|
|
const char *file_template)
|
2009-03-13 17:14:31 -04:00
|
|
|
{
|
|
|
|
g_return_if_fail (SHELL_IS_RECORDER (recorder));
|
|
|
|
|
2012-10-25 17:14:20 -04:00
|
|
|
recorder_set_file_template (recorder, file_template);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-08 13:52:16 -04:00
|
|
|
void
|
|
|
|
shell_recorder_set_draw_cursor (ShellRecorder *recorder,
|
|
|
|
gboolean draw_cursor)
|
|
|
|
{
|
|
|
|
g_return_if_fail (SHELL_IS_RECORDER (recorder));
|
|
|
|
|
|
|
|
recorder_set_draw_cursor (recorder, draw_cursor);
|
|
|
|
}
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
/**
|
|
|
|
* shell_recorder_set_pipeline:
|
|
|
|
* @recorder: the #ShellRecorder
|
2014-05-28 15:54:02 -04:00
|
|
|
* @pipeline: (nullable): the GStreamer pipeline used to encode recordings
|
2010-02-10 06:48:59 -05:00
|
|
|
* or %NULL for the default value.
|
2009-03-13 17:14:31 -04:00
|
|
|
*
|
|
|
|
* Sets the GStreamer pipeline used to encode recordings.
|
|
|
|
* It follows the syntax used for gst-launch. The pipeline
|
|
|
|
* should have an unconnected sink pad where the recorded
|
|
|
|
* video is recorded. It will normally have a unconnected
|
|
|
|
* source pad; output from that pad will be written into the
|
2012-10-25 17:14:20 -04:00
|
|
|
* output file. (See shell_recorder_set_file_template().) However
|
2009-03-13 17:14:31 -04:00
|
|
|
* the pipeline can also take care of its own output - this
|
|
|
|
* might be used to send the output to an icecast server
|
|
|
|
* via shout2send or similar.
|
|
|
|
*
|
2015-01-11 06:16:40 -05:00
|
|
|
* The default value is 'vp9enc min_quantizer=13 max_quantizer=13 cpu-used=5 deadline=1000000 threads=%T ! queue ! webmmux'
|
2009-03-13 17:14:31 -04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
shell_recorder_set_pipeline (ShellRecorder *recorder,
|
|
|
|
const char *pipeline)
|
|
|
|
{
|
|
|
|
g_return_if_fail (SHELL_IS_RECORDER (recorder));
|
|
|
|
|
|
|
|
recorder_set_pipeline (recorder, pipeline);
|
|
|
|
}
|
|
|
|
|
2013-05-08 13:24:19 -04:00
|
|
|
void
|
|
|
|
shell_recorder_set_area (ShellRecorder *recorder,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
|
|
|
g_return_if_fail (SHELL_IS_RECORDER (recorder));
|
|
|
|
|
|
|
|
recorder->custom_area = TRUE;
|
|
|
|
recorder->area.x = CLAMP (x, 0, recorder->stage_width);
|
|
|
|
recorder->area.y = CLAMP (y, 0, recorder->stage_height);
|
|
|
|
recorder->area.width = CLAMP (width,
|
|
|
|
0, recorder->stage_width - recorder->area.x);
|
|
|
|
recorder->area.height = CLAMP (height,
|
|
|
|
0, recorder->stage_height - recorder->area.y);
|
|
|
|
|
|
|
|
/* This breaks the recording but tweaking the GStreamer pipeline a bit
|
|
|
|
* might make it work, at least if the codec can handle a stream where
|
|
|
|
* the frame size changes in the middle.
|
|
|
|
*/
|
|
|
|
if (recorder->current_pipeline)
|
|
|
|
recorder_pipeline_set_caps (recorder->current_pipeline);
|
|
|
|
}
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
/**
|
|
|
|
* shell_recorder_record:
|
|
|
|
* @recorder: the #ShellRecorder
|
2014-05-28 15:54:02 -04:00
|
|
|
* @filename_used: (out) (optional): actual filename used for recording
|
2009-03-13 17:14:31 -04:00
|
|
|
*
|
2012-06-04 19:32:06 -04:00
|
|
|
* Starts recording, Starting the recording may fail if the output file
|
2009-03-13 17:14:31 -04:00
|
|
|
* cannot be opened, or if the output stream cannot be created
|
|
|
|
* for other reasons. In that case a warning is printed to
|
|
|
|
* stderr. There is no way currently to get details on how
|
|
|
|
* recording failed to start.
|
|
|
|
*
|
|
|
|
* An extra reference count is added to the recorder if recording
|
|
|
|
* is succesfully started; the recording object will not be freed
|
|
|
|
* until recording is stopped even if the creator no longer holds
|
|
|
|
* a reference. Recording is automatically stopped if the stage
|
|
|
|
* is destroyed.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if recording was succesfully started
|
|
|
|
*/
|
|
|
|
gboolean
|
2013-05-06 18:11:57 -04:00
|
|
|
shell_recorder_record (ShellRecorder *recorder,
|
|
|
|
char **filename_used)
|
2009-03-13 17:14:31 -04:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (SHELL_IS_RECORDER (recorder), FALSE);
|
|
|
|
g_return_val_if_fail (recorder->stage != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (recorder->state != RECORDER_STATE_RECORDING, FALSE);
|
|
|
|
|
2012-06-04 19:32:06 -04:00
|
|
|
if (!recorder_open_pipeline (recorder))
|
|
|
|
return FALSE;
|
2009-03-13 17:14:31 -04:00
|
|
|
|
2013-05-06 18:11:57 -04:00
|
|
|
if (filename_used)
|
|
|
|
*filename_used = g_strdup (recorder->current_pipeline->filename);
|
|
|
|
|
2013-03-11 14:36:05 -04:00
|
|
|
recorder_connect_stage_callbacks (recorder);
|
|
|
|
|
2015-02-17 03:16:44 -05:00
|
|
|
recorder->last_frame_time = GST_CLOCK_TIME_NONE;
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
recorder->state = RECORDER_STATE_RECORDING;
|
2014-07-26 10:27:12 -04:00
|
|
|
recorder_update_pointer (recorder);
|
2009-03-13 17:14:31 -04:00
|
|
|
recorder_add_update_pointer_timeout (recorder);
|
|
|
|
|
2014-10-09 08:42:06 -04:00
|
|
|
/* Disable unredirection while we are recoring */
|
2018-01-03 02:55:38 -05:00
|
|
|
meta_disable_unredirect_for_display (shell_global_get_display (shell_global_get ()));
|
2014-10-09 08:42:06 -04:00
|
|
|
|
2011-01-21 12:55:00 -05:00
|
|
|
/* Set up repaint hook */
|
|
|
|
recorder->repaint_hook_id = clutter_threads_add_repaint_func(recorder_repaint_hook, recorder->stage, NULL);
|
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
/* Record an initial frame and also redraw with the indicator */
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (recorder->stage));
|
|
|
|
|
|
|
|
/* We keep a ref while recording to let a caller start a recording then
|
|
|
|
* drop their reference to the recorder
|
|
|
|
*/
|
|
|
|
g_object_ref (recorder);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-04 19:32:06 -04:00
|
|
|
* shell_recorder_close:
|
2009-03-13 17:14:31 -04:00
|
|
|
* @recorder: the #ShellRecorder
|
|
|
|
*
|
2012-06-04 19:32:06 -04:00
|
|
|
* Stops recording. It's possible to call shell_recorder_record()
|
|
|
|
* again to reopen a new recording stream, but unless change the
|
|
|
|
* recording filename, this may result in the old recording being
|
|
|
|
* overwritten.
|
2009-03-13 17:14:31 -04:00
|
|
|
*/
|
|
|
|
void
|
2012-06-04 19:32:06 -04:00
|
|
|
shell_recorder_close (ShellRecorder *recorder)
|
2009-03-13 17:14:31 -04:00
|
|
|
{
|
|
|
|
g_return_if_fail (SHELL_IS_RECORDER (recorder));
|
2012-06-04 19:32:06 -04:00
|
|
|
g_return_if_fail (recorder->state != RECORDER_STATE_CLOSED);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
/* We want to record one more frame since some time may have
|
|
|
|
* elapsed since the last frame
|
|
|
|
*/
|
2016-06-27 03:57:28 -04:00
|
|
|
recorder_record_frame (recorder, TRUE);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
2012-06-04 19:32:06 -04:00
|
|
|
recorder_remove_update_pointer_timeout (recorder);
|
|
|
|
recorder_close_pipeline (recorder);
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
/* Queue a redraw to remove the recording indicator */
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (recorder->stage));
|
2011-01-21 12:55:00 -05:00
|
|
|
|
|
|
|
if (recorder->repaint_hook_id != 0)
|
2012-06-04 19:32:06 -04:00
|
|
|
{
|
|
|
|
clutter_threads_remove_repaint_func (recorder->repaint_hook_id);
|
|
|
|
recorder->repaint_hook_id = 0;
|
|
|
|
}
|
2009-03-13 17:14:31 -04:00
|
|
|
|
|
|
|
recorder->state = RECORDER_STATE_CLOSED;
|
|
|
|
|
2014-10-09 08:55:13 -04:00
|
|
|
/* Reenable after the recording */
|
2018-01-03 02:55:38 -05:00
|
|
|
meta_enable_unredirect_for_display (shell_global_get_display (shell_global_get ()));
|
2014-10-09 08:42:06 -04:00
|
|
|
|
2009-03-13 17:14:31 -04:00
|
|
|
/* Release the refcount we took when we started recording */
|
|
|
|
g_object_unref (recorder);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* shell_recorder_is_recording:
|
|
|
|
*
|
|
|
|
* Determine if recording is currently in progress. (The recorder
|
|
|
|
* is not paused or closed.)
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the recorder is currently recording.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
shell_recorder_is_recording (ShellRecorder *recorder)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (SHELL_IS_RECORDER (recorder), FALSE);
|
|
|
|
|
|
|
|
return recorder->state == RECORDER_STATE_RECORDING;
|
|
|
|
}
|