~walkerlee/totem/pre-interview

« back to all changes in this revision

Viewing changes to src/gst/totem-gst-helpers.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-05-26 00:07:51 UTC
  • mfrom: (1.6.1) (24.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130526000751-kv8ap3x1di4qq8j2
Tags: 3.8.2-0ubuntu1
* Sync with Debian. Remaining changes: 
* debian/control.in:
  - Drop build-depends on libepc-ui-dev and libgrilo-0.2-dev (in universe)
  - Drop libxtst-dev build-depends so that the (redundant) fake key presses
    for inhibiting the screensaver are disabled (LP: #1007438)
  - Build-depend on libzeitgeist-dev
  - Suggest rather than recommend gstreamer components in universe
  - Add totem-plugins-extra
  - Add XB-Npp-Description and XB-Npp-Filename header to the 
    totem-mozilla package to improve ubufox/ubuntu plugin db integration 
  - Refer to Firefox in totem-mozilla description instead of Iceweasel
  - Don't have totem-mozilla recommend any particular browser
  - Drop obsolete python library dependencies since iplayer is no longer
    included
* debian/totem-common.install, debian/source_totem.py:
  - Install Ubuntu apport debugging hook
* debian/totem-plugins-extra.install:
  - Universe plugins split out of totem-plugins (currently only gromit)
* debian/totem-plugins.install:    
  - Skip the plugins split to -extra and add the zeitgeist plugin
* debian/rules:
  - Build with --fail-missing, to ensure we install everything. 
    + Ignore libtotem.{,l}a since we delibrately don't install these.
  - Re-enable hardening, make sure both PIE and BINDNOW are used
    by setting hardening=+all. (LP: #1039604)
* debian/patches/91_quicklist_entries.patch:
  - Add static quicklist
* debian/patches/92_gst-plugins-good.patch:
  - Build without unnecessary gstreamer1.0-bad dependency
* debian/patches/93_grilo_optional.patch:
  - Allow building without grilo while grilo MIR is still pending
* debian/patches/correct_desktop_mimetypes.patch:
  - Don't list the mimetypes after the unity lists
* debian/patches/revert_shell_menu.patch: 
  - revert the use of a shell menu until indicator-appmenu can handle
    the mixed shell/traditional menus itself
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 *
31
31
 */
32
32
 
 
33
#include "totem-gst-helpers.h"
 
34
 
33
35
#include <gst/tag/tag.h>
34
 
#include "totem-gst-helpers.h"
 
36
#include <gst/video/video-format.h>
35
37
 
36
38
void
37
39
totem_gst_message_print (GstMessage *msg,
65
67
    GST_ERROR ("uri     = %s", GST_STR_NULL (uri));
66
68
    g_free (uri);
67
69
 
68
 
    g_message ("Error: %s\n%s\n", GST_STR_NULL (err->message),
69
 
        GST_STR_NULL (dbg));
70
 
 
71
70
    g_error_free (err);
72
71
  }
73
72
  g_free (dbg);
74
73
}
75
74
 
76
 
static void
77
 
destroy_pixbuf (guchar *pix, gpointer data)
78
 
{
79
 
  gst_buffer_unref (GST_BUFFER (data));
80
 
}
81
 
 
82
 
GdkPixbuf *
83
 
totem_gst_playbin_get_frame (GstElement *play)
84
 
{
85
 
  GstStructure *s;
86
 
  GstBuffer *buf = NULL;
87
 
  GdkPixbuf *pixbuf;
88
 
  GstCaps *to_caps;
89
 
  gint outwidth = 0;
90
 
  gint outheight = 0;
91
 
 
92
 
  g_return_val_if_fail (play != NULL, NULL);
93
 
  g_return_val_if_fail (GST_IS_ELEMENT (play), NULL);
94
 
 
95
 
  /* our desired output format (RGB24) */
96
 
  to_caps = gst_caps_new_simple ("video/x-raw-rgb",
97
 
      "bpp", G_TYPE_INT, 24,
98
 
      "depth", G_TYPE_INT, 24,
99
 
      /* Note: we don't ask for a specific width/height here, so that
100
 
       * videoscale can adjust dimensions from a non-1/1 pixel aspect
101
 
       * ratio to a 1/1 pixel-aspect-ratio. We also don't ask for a
102
 
       * specific framerate, because the input framerate won't
103
 
       * necessarily match the output framerate if there's a deinterlacer
104
 
       * in the pipeline. */
105
 
      "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
106
 
      "endianness", G_TYPE_INT, G_BIG_ENDIAN,
107
 
      "red_mask", G_TYPE_INT, 0xff0000,
108
 
      "green_mask", G_TYPE_INT, 0x00ff00,
109
 
      "blue_mask", G_TYPE_INT, 0x0000ff,
110
 
      NULL);
111
 
 
112
 
  /* get frame */
113
 
  g_signal_emit_by_name (play, "convert-frame", to_caps, &buf);
114
 
  gst_caps_unref (to_caps);
115
 
 
116
 
  if (!buf) {
117
 
    GST_DEBUG ("Could not take screenshot: %s",
118
 
        "failed to retrieve or convert video frame");
119
 
    g_warning ("Could not take screenshot: %s",
120
 
        "failed to retrieve or convert video frame");
121
 
    return NULL;
122
 
  }
123
 
 
124
 
  if (!GST_BUFFER_CAPS (buf)) {
125
 
    GST_DEBUG ("Could not take screenshot: %s", "no caps on output buffer");
126
 
    g_warning ("Could not take screenshot: %s", "no caps on output buffer");
127
 
    return NULL;
128
 
  }
129
 
 
130
 
  GST_DEBUG ("frame caps: %" GST_PTR_FORMAT, GST_BUFFER_CAPS (buf));
131
 
 
132
 
  s = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0);
133
 
  gst_structure_get_int (s, "width", &outwidth);
134
 
  gst_structure_get_int (s, "height", &outheight);
135
 
  g_return_val_if_fail (outwidth > 0 && outheight > 0, NULL);
136
 
 
137
 
  /* create pixbuf from that - use our own destroy function */
138
 
  pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buf),
139
 
      GDK_COLORSPACE_RGB, FALSE, 8, outwidth, outheight,
140
 
      GST_ROUND_UP_4 (outwidth * 3), destroy_pixbuf, buf);
141
 
 
142
 
  if (!pixbuf) {
143
 
    GST_DEBUG ("Could not take screenshot: %s", "could not create pixbuf");
144
 
    g_warning ("Could not take screenshot: %s", "could not create pixbuf");
145
 
    gst_buffer_unref (buf);
146
 
  }
147
 
 
148
 
  return pixbuf;
149
 
}
150
 
 
151
 
static GdkPixbuf *
152
 
totem_gst_buffer_to_pixbuf (GstBuffer *buffer)
153
 
{
154
 
  GdkPixbufLoader *loader;
155
 
  GdkPixbuf *pixbuf = NULL;
156
 
  GError *err = NULL;
157
 
 
158
 
  loader = gdk_pixbuf_loader_new ();
159
 
 
160
 
  if (gdk_pixbuf_loader_write (loader, buffer->data, buffer->size, &err) &&
161
 
      gdk_pixbuf_loader_close (loader, &err)) {
162
 
    pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
163
 
    if (pixbuf)
164
 
      g_object_ref (pixbuf);
165
 
  } else {
166
 
    GST_WARNING("could not convert tag image to pixbuf: %s", err->message);
167
 
    g_error_free (err);
168
 
  }
169
 
 
170
 
  g_object_unref (loader);
171
 
  return pixbuf;
172
 
}
173
 
 
174
 
static const GValue *
175
 
totem_gst_tag_list_get_cover_real (GstTagList *tag_list)
176
 
{
177
 
  const GValue *cover_value = NULL;
178
 
  guint i;
179
 
 
180
 
  for (i = 0; ; i++) {
181
 
    const GValue *value;
182
 
    GstBuffer *buffer;
183
 
    GstStructure *caps_struct;
184
 
    int type;
185
 
 
186
 
    value = gst_tag_list_get_value_index (tag_list,
187
 
                                          GST_TAG_IMAGE,
188
 
                                          i);
189
 
    if (value == NULL)
190
 
      break;
191
 
 
192
 
    buffer = gst_value_get_buffer (value);
193
 
 
194
 
    caps_struct = gst_caps_get_structure (buffer->caps, 0);
195
 
    gst_structure_get_enum (caps_struct,
196
 
                            "image-type",
197
 
                            GST_TYPE_TAG_IMAGE_TYPE,
198
 
                            &type);
199
 
    if (type == GST_TAG_IMAGE_TYPE_UNDEFINED) {
200
 
      if (cover_value == NULL)
201
 
        cover_value = value;
202
 
    } else if (type == GST_TAG_IMAGE_TYPE_FRONT_COVER) {
203
 
      cover_value = value;
204
 
      break;
205
 
    }
206
 
  }
207
 
 
208
 
  return cover_value;
209
 
}
210
 
 
211
 
GdkPixbuf *
212
 
totem_gst_tag_list_get_cover (GstTagList *tag_list)
213
 
{
214
 
  const GValue *cover_value;
215
 
 
216
 
  g_return_val_if_fail (tag_list != NULL, FALSE);
217
 
 
218
 
  cover_value = totem_gst_tag_list_get_cover_real (tag_list);
219
 
  /* Fallback to preview */
220
 
  if (!cover_value) {
221
 
    cover_value = gst_tag_list_get_value_index (tag_list,
222
 
                                                GST_TAG_PREVIEW_IMAGE,
223
 
                                                0);
224
 
  }
225
 
 
226
 
  if (cover_value) {
227
 
    GstBuffer *buffer;
228
 
    GdkPixbuf *pixbuf;
229
 
 
230
 
    buffer = gst_value_get_buffer (cover_value);
231
 
    pixbuf = totem_gst_buffer_to_pixbuf (buffer);
232
 
    return pixbuf;
233
 
  }
234
 
 
235
 
  return NULL;
236
 
}
237
 
 
238
75
/*
239
76
 * vim: sw=2 ts=8 cindent noai bs=2
240
77
 */