~titan-lien/ubuntu/saucy/totem/totem.dev

« back to all changes in this revision

Viewing changes to src/totem-properties-view.c

  • Committer: Package Import Robot
  • Author(s): Michael Biebl, Sjoerd Simons, Michael Biebl, Josselin Mouette
  • Date: 2011-11-27 06:21:34 UTC
  • mfrom: (1.4.8) (5.1.23 sid)
  • Revision ID: package-import@ubuntu.com-20111127062134-c3ikko9wdfn9m2av
Tags: 3.2.1-1
[ Sjoerd Simons ]
* New upstream release
* debian/control.in: Update build-depends
* debian/rules: Enable vala plugins
* debian/totem-plugins.install:
  - Add grilo and rotation plugins
  - Remove jamendo, thumbnail and tracker plugins

[ Michael Biebl ]
* debian/control.in:
  - Bump Depends on python-gobject to (>= 2.90.3).

[ Josselin Mouette ]
* Replace python-gobject dependencies by python-gi.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
#include <config.h>
30
30
 
 
31
#include <gtk/gtk.h>
 
32
#include <glib/gi18n-lib.h>
 
33
#include <gst/pbutils/pbutils.h>
 
34
 
31
35
#include "totem-properties-view.h"
32
 
 
33
36
#include "bacon-video-widget-properties.h"
34
 
#include "bacon-video-widget.h"
35
 
#include <glib/gi18n-lib.h>
36
 
#include <gtk/gtk.h>
37
37
 
38
38
struct TotemPropertiesViewPriv {
39
39
        GtkWidget *label;
40
40
        GtkWidget *vbox;
41
41
        BaconVideoWidgetProperties *props;
42
 
        BaconVideoWidget *bvw;
 
42
        GstDiscoverer *disco;
43
43
};
44
44
 
45
45
static GObjectClass *parent_class = NULL;
61
61
}
62
62
 
63
63
static void
64
 
on_got_metadata_event (BaconVideoWidget *bvw, TotemPropertiesView *props)
65
 
{
66
 
        GValue value = { 0, };
 
64
update_general (TotemPropertiesView *props,
 
65
                const GstTagList    *list)
 
66
{
 
67
        struct {
 
68
                const char *tag_name;
 
69
                const char *widget;
 
70
        } items[] = {
 
71
                { GST_TAG_TITLE, "title" },
 
72
                { GST_TAG_ARTIST, "artist" },
 
73
                { GST_TAG_ALBUM, "album" },
 
74
                { GST_TAG_COMMENT, "comment" },
 
75
        };
 
76
        guint i;
 
77
        GDate *date;
 
78
 
 
79
        for (i = 0; i < G_N_ELEMENTS(items); i++) {
 
80
                char *string;
 
81
 
 
82
                if (gst_tag_list_get_string_index (list, items[i].tag_name, 0, &string) != FALSE) {
 
83
                        bacon_video_widget_properties_set_label (props->priv->props,
 
84
                                                                 items[i].widget,
 
85
                                                                 string);
 
86
                        g_free (string);
 
87
                }
 
88
        }
 
89
 
 
90
        /* Date */
 
91
        if (gst_tag_list_get_date (list, GST_TAG_DATE, &date)) {
 
92
                char *string;
 
93
 
 
94
                string = g_strdup_printf ("%d", g_date_get_year (date));
 
95
                g_date_free (date);
 
96
                bacon_video_widget_properties_set_label (props->priv->props,
 
97
                                                         "year",
 
98
                                                         string);
 
99
                g_free (string);
 
100
        }
 
101
}
 
102
 
 
103
static void
 
104
set_codec (TotemPropertiesView     *props,
 
105
           GstDiscovererStreamInfo *info,
 
106
           const char              *widget)
 
107
{
 
108
        GstCaps *caps;
 
109
        const char *nick;
 
110
 
 
111
        nick = gst_discoverer_stream_info_get_stream_type_nick (info);
 
112
        if (g_str_equal (nick, "audio") == FALSE &&
 
113
            g_str_equal (nick, "video") == FALSE &&
 
114
            g_str_equal (nick, "container") == FALSE) {
 
115
                bacon_video_widget_properties_set_label (props->priv->props,
 
116
                                                         widget,
 
117
                                                         _("N/A"));
 
118
                return;
 
119
        }
 
120
 
 
121
        caps = gst_discoverer_stream_info_get_caps (info);
 
122
        if (caps) {
 
123
                if (gst_caps_is_fixed (caps)) {
 
124
                        char *string;
 
125
 
 
126
                        string = gst_pb_utils_get_codec_description (caps);
 
127
                        bacon_video_widget_properties_set_label (props->priv->props,
 
128
                                                                 widget,
 
129
                                                                 string);
 
130
                        g_free (string);
 
131
                }
 
132
                gst_caps_unref (caps);
 
133
        }
 
134
}
 
135
 
 
136
static void
 
137
set_bitrate (TotemPropertiesView    *props,
 
138
             guint                   bitrate,
 
139
             const char             *widget)
 
140
{
 
141
        char *string;
 
142
 
 
143
        if (!bitrate) {
 
144
                bacon_video_widget_properties_set_label (props->priv->props,
 
145
                                                         widget,
 
146
                                                         C_("Stream bit rate", "N/A"));
 
147
                return;
 
148
        }
 
149
        string = g_strdup_printf (_("%d kbps"), bitrate / 1000);
 
150
        bacon_video_widget_properties_set_label (props->priv->props,
 
151
                                                 widget,
 
152
                                                 string);
 
153
        g_free (string);
 
154
}
 
155
 
 
156
static void
 
157
update_video (TotemPropertiesView    *props,
 
158
              GstDiscovererVideoInfo *info)
 
159
{
 
160
        guint width, height;
 
161
        guint fps_n, fps_d;
 
162
        char *string;
 
163
 
 
164
        width = gst_discoverer_video_info_get_width (info);
 
165
        height = gst_discoverer_video_info_get_height (info);
 
166
        string = g_strdup_printf (N_("%d x %d"), width, height);
 
167
        bacon_video_widget_properties_set_label (props->priv->props,
 
168
                                                 "dimensions",
 
169
                                                 string);
 
170
        g_free (string);
 
171
 
 
172
        set_codec (props, (GstDiscovererStreamInfo *) info, "vcodec");
 
173
        set_bitrate (props, gst_discoverer_video_info_get_bitrate (info), "video_bitrate");
 
174
 
 
175
        /* Round up/down to the nearest integer framerate */
 
176
        fps_n = gst_discoverer_video_info_get_framerate_num (info);
 
177
        fps_d = gst_discoverer_video_info_get_framerate_denom (info);
 
178
        if (fps_d == 0)
 
179
                bacon_video_widget_properties_set_framerate (props->priv->props, 0);
 
180
        else
 
181
                bacon_video_widget_properties_set_framerate (props->priv->props,
 
182
                                                             (fps_n + fps_d/2) / fps_d);
 
183
}
 
184
 
 
185
static void
 
186
update_audio (TotemPropertiesView    *props,
 
187
              GstDiscovererAudioInfo *info)
 
188
{
 
189
        guint samplerate, channels;
 
190
 
 
191
        set_codec (props, (GstDiscovererStreamInfo *) info, "acodec");
 
192
 
 
193
        set_bitrate (props, gst_discoverer_audio_info_get_bitrate (info), "audio_bitrate");
 
194
 
 
195
        samplerate = gst_discoverer_audio_info_get_sample_rate (info);
 
196
        if (samplerate) {
 
197
                char *string;
 
198
                string = g_strdup_printf (_("%d Hz"), samplerate);
 
199
                bacon_video_widget_properties_set_label (props->priv->props,
 
200
                                                         "samplerate",
 
201
                                                         string);
 
202
        } else {
 
203
                bacon_video_widget_properties_set_label (props->priv->props,
 
204
                                                         "samplerate",
 
205
                                                         C_("Sample rate", "N/A"));
 
206
        }
 
207
 
 
208
        channels = gst_discoverer_audio_info_get_channels (info);
 
209
        if (channels) {
 
210
                char *string;
 
211
 
 
212
                if (channels > 2) {
 
213
                        string = g_strdup_printf ("%s %d.1", _("Surround"), channels - 1);
 
214
                } else if (channels == 1) {
 
215
                        string = g_strdup (_("Mono"));
 
216
                } else if (channels == 2) {
 
217
                        string = g_strdup (_("Stereo"));
 
218
                }
 
219
                bacon_video_widget_properties_set_label (props->priv->props,
 
220
                                                         "channels",
 
221
                                                         string);
 
222
        } else {
 
223
                bacon_video_widget_properties_set_label (props->priv->props,
 
224
                                                         "channels",
 
225
                                                         C_("Number of audio channels", "N/A"));
 
226
        }
 
227
}
 
228
 
 
229
static void
 
230
discovered_cb (GstDiscoverer       *discoverer,
 
231
               GstDiscovererInfo   *info,
 
232
               GError              *error,
 
233
               TotemPropertiesView *props)
 
234
{
 
235
        GList *video_streams, *audio_streams;
 
236
        const GstTagList *taglist;
67
237
        gboolean has_audio, has_video;
68
 
        const char *label = NULL;
69
 
 
70
 
        bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw),
71
 
                        BVW_INFO_HAS_VIDEO, &value);
72
 
        has_video = g_value_get_boolean (&value);
73
 
        g_value_unset (&value);
74
 
 
75
 
        bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw),
76
 
                        BVW_INFO_HAS_AUDIO, &value);
77
 
        has_audio = g_value_get_boolean (&value);
78
 
        g_value_unset (&value);
79
 
 
80
 
        if (has_audio == FALSE) {
81
 
                if (has_video == FALSE) {
82
 
                        //FIXME this should be setting an error?
83
 
                        label = N_("Audio/Video");
84
 
                } else {
85
 
                        label = N_("Video");
86
 
                }
87
 
        } else {
88
 
                if (has_video == FALSE) {
89
 
                        label = N_("Audio");
90
 
                } else {
91
 
                        label = N_("Audio/Video");
92
 
                }
 
238
        const char *label;
 
239
        GstClockTime duration;
 
240
        GstDiscovererStreamInfo *sinfo;
 
241
 
 
242
        if (error) {
 
243
                g_warning ("Couldn't get information about '%s': %s",
 
244
                           gst_discoverer_info_get_uri (info),
 
245
                           error->message);
 
246
                return;
93
247
        }
94
248
 
 
249
        video_streams = gst_discoverer_info_get_video_streams (info);
 
250
        has_video = (video_streams != NULL);
 
251
        audio_streams = gst_discoverer_info_get_audio_streams (info);
 
252
        has_audio = (audio_streams != NULL);
 
253
 
 
254
        if (has_audio == has_video)
 
255
                label = N_("Audio/Video");
 
256
        else if (has_audio)
 
257
                label = N_("Audio");
 
258
        else
 
259
                label = N_("Video");
 
260
 
95
261
        gtk_label_set_text (GTK_LABEL (props->priv->label), _(label));
96
262
 
97
 
        bacon_video_widget_properties_update
98
 
                (props->priv->props, GTK_WIDGET (props->priv->bvw));
 
263
        /* Widgets */
 
264
        bacon_video_widget_properties_set_has_type (props->priv->props,
 
265
                                                    has_video,
 
266
                                                    has_audio);
 
267
 
 
268
        /* General */
 
269
        duration = gst_discoverer_info_get_duration (info);
 
270
        bacon_video_widget_properties_set_duration (props->priv->props, duration / GST_SECOND * 1000);
 
271
 
 
272
        sinfo = gst_discoverer_info_get_stream_info (info);
 
273
        if (sinfo) {
 
274
                set_codec (props, sinfo, "container");
 
275
                gst_discoverer_stream_info_unref (sinfo);
 
276
        }
 
277
 
 
278
        taglist = gst_discoverer_info_get_tags (info);
 
279
        update_general (props, taglist);
 
280
 
 
281
        /* Video and Audio */
 
282
        if (video_streams)
 
283
                update_video (props, video_streams->data);
 
284
        if (audio_streams)
 
285
                update_audio (props, audio_streams->data);
 
286
 
 
287
        gst_discoverer_stream_info_list_free (video_streams);
 
288
        gst_discoverer_stream_info_list_free (audio_streams);
99
289
}
100
290
 
101
291
static void
105
295
 
106
296
        props->priv = g_new0 (TotemPropertiesViewPriv, 1);
107
297
 
108
 
        props->priv->bvw = BACON_VIDEO_WIDGET (bacon_video_widget_new
109
 
                        (-1, -1, BVW_USE_TYPE_METADATA, &err));
110
 
 
111
 
        if (props->priv->bvw != NULL)
112
 
        {
113
 
                /* Reference it, so that it's not floating */
114
 
                g_object_ref (props->priv->bvw);
115
 
 
116
 
                g_signal_connect (G_OBJECT (props->priv->bvw),
117
 
                                "got-metadata",
118
 
                                G_CALLBACK (on_got_metadata_event),
119
 
                                props);
120
 
        } else {
121
 
                g_warning ("Error: %s", err ? err->message : "bla");
122
 
        }
123
 
 
124
298
        props->priv->vbox = bacon_video_widget_properties_new ();
125
299
        gtk_table_resize (GTK_TABLE (props), 1, 1);
126
300
        gtk_container_add (GTK_CONTAINER (props), props->priv->vbox);
127
301
        gtk_widget_show (GTK_WIDGET (props));
128
302
 
129
303
        props->priv->props = BACON_VIDEO_WIDGET_PROPERTIES (props->priv->vbox);
 
304
 
 
305
        props->priv->disco = gst_discoverer_new (GST_SECOND * 60, &err);
 
306
        if (props->priv->disco == NULL) {
 
307
                g_warning ("Could not create discoverer object: %s", err->message);
 
308
                g_error_free (err);
 
309
                return;
 
310
        }
 
311
        g_signal_connect (props->priv->disco, "discovered",
 
312
                          G_CALLBACK (discovered_cb), props);
130
313
}
131
314
 
132
315
static void
138
321
 
139
322
        if (props->priv != NULL)
140
323
        {
141
 
                if (props->priv->bvw != NULL)
142
 
                        g_object_unref (G_OBJECT (props->priv->bvw));
143
 
                if (props->priv->label != NULL)
144
 
                g_object_unref (G_OBJECT (props->priv->label));
145
 
                props->priv->bvw = NULL;
146
 
                props->priv->label = NULL;
 
324
                if (props->priv->disco != NULL) {
 
325
                        g_object_unref (G_OBJECT (props->priv->disco));
 
326
                        props->priv->disco = NULL;
 
327
                }
 
328
                if (props->priv->label != NULL) {
 
329
                        g_object_unref (G_OBJECT (props->priv->label));
 
330
                        props->priv->label = NULL;
 
331
                }
147
332
                g_free (props->priv);
148
333
        }
149
334
        props->priv = NULL;
166
351
 
167
352
void
168
353
totem_properties_view_set_location (TotemPropertiesView *props,
169
 
                                     const char *location)
 
354
                                    const char          *location)
170
355
{
171
356
        g_assert (TOTEM_IS_PROPERTIES_VIEW (props));
172
357
 
173
 
        if (location != NULL && props->priv->bvw != NULL) {
174
 
                GError *error = NULL;
175
 
 
176
 
                bacon_video_widget_close (props->priv->bvw);
177
 
                bacon_video_widget_properties_reset (props->priv->props);
178
 
 
179
 
                if (bacon_video_widget_open (props->priv->bvw, location, NULL, &error) == FALSE) {
180
 
                        g_warning ("Couldn't open %s: %s", location, error->message);
181
 
                        g_error_free (error);
 
358
        if (props->priv->disco)
 
359
                gst_discoverer_stop (props->priv->disco);
 
360
 
 
361
        bacon_video_widget_properties_reset (props->priv->props);
 
362
 
 
363
        if (location != NULL && props->priv->disco != NULL) {
 
364
                gst_discoverer_start (props->priv->disco);
 
365
 
 
366
                if (gst_discoverer_discover_uri_async (props->priv->disco, location) == FALSE) {
 
367
                        g_warning ("Couldn't add %s to list", location);
182
368
                        return;
183
369
                }
184
 
 
185
 
                bacon_video_widget_close (props->priv->bvw);
186
 
        } else {
187
 
                if (props->priv->bvw != NULL)
188
 
                        bacon_video_widget_close (props->priv->bvw);
189
 
                bacon_video_widget_properties_reset (props->priv->props);
190
370
        }
191
371
}
192
372