6 get_position_info (GstElement * cdparanoia)
8 GstFormat track_format;
9 const GstFormat *formats;
12 track_format = gst_format_get_by_nick ("track");
13 g_assert (track_format != 0);
15 pad = gst_element_get_pad (cdparanoia, "src");
16 formats = gst_pad_get_formats (pad);
19 const GstFormatDefinition *definition;
24 definition = gst_format_get_details (*formats);
27 res = gst_pad_query (pad, GST_QUERY_POSITION, &format, &position);
29 if (format == GST_FORMAT_TIME) {
30 position /= GST_SECOND;
31 g_print ("%s: %lld:%02lld", definition->nick, position / 60,
34 g_print ("%s: %lld", definition->nick, position);
46 get_track_info (GstElement * cdparanoia)
48 GstFormat track_format;
49 gint64 total_tracks = 0, total_time = 0;
51 const GstFormat *formats;
53 gint64 time_count = 0;
55 track_format = gst_format_get_by_nick ("track");
56 g_assert (track_format != 0);
58 pad = gst_element_get_pad (cdparanoia, "src");
59 formats = gst_pad_get_formats (pad);
61 /* we loop over all supported formats and report the total
64 const GstFormatDefinition *definition;
69 definition = gst_format_get_details (*formats);
72 res = gst_pad_query (pad, GST_QUERY_TOTAL, &format, &total);
74 if (format == GST_FORMAT_TIME) {
76 g_print ("%s total: %lld:%02lld\n", definition->nick, total / 60,
79 g_print ("%s total: %lld\n", definition->nick, total);
81 if (format == track_format)
83 else if (format == GST_FORMAT_TIME)
86 g_print ("failed to get %s total\n", definition->nick);
91 /* then we loop over all the tracks to get more info.
92 * since pad_convert always works from 0, the time from track 1 needs
93 * to be substracted from track 2 */
94 for (i = 0; i <= total_tracks; i++) {
98 if (i < total_tracks) {
101 format = GST_FORMAT_TIME;
102 res = gst_pad_convert (pad, track_format, i, &format, &time);
110 /* for the first track (i==0) we wait until we have the
111 * time of the next track */
113 gint64 length = time - time_count;
115 g_print ("track %d: %lld:%02lld -> %lld:%02lld, length: %lld:%02lld\n",
117 time_count / 60, time_count % 60,
118 time / 60, time % 60, length / 60, length % 60);
121 g_print ("could not get time for track %d\n", i);
129 main (int argc, char **argv)
131 GstElement *pipeline;
132 GstElement *cdparanoia;
135 GstFormat track_format;
140 gst_init (&argc, &argv);
142 pipeline = gst_pipeline_new ("pipeline");
144 cdparanoia = gst_element_factory_make ("cdparanoia", "cdparanoia");
145 g_assert (cdparanoia);
146 g_object_set (G_OBJECT (cdparanoia), "paranoia_mode", 0, NULL);
148 osssink = gst_element_factory_make ("osssink", "osssink");
151 gst_bin_add (GST_BIN (pipeline), cdparanoia);
152 gst_bin_add (GST_BIN (pipeline), osssink);
154 gst_element_link_pads (cdparanoia, "src", osssink, "sink");
156 g_signal_connect (G_OBJECT (pipeline), "deep_notify",
157 G_CALLBACK (gst_element_default_deep_notify), NULL);
159 gst_element_set_state (pipeline, GST_STATE_PAUSED);
161 /* now we go into probe mode */
162 get_track_info (cdparanoia);
164 track_format = gst_format_get_by_nick ("track");
165 g_assert (track_format != 0);
167 pad = gst_element_get_pad (cdparanoia, "src");
170 g_print ("playing from track 3\n");
172 event = gst_event_new_seek (track_format |
173 GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, 3);
175 res = gst_pad_send_event (pad, event);
177 g_warning ("seek failed");
179 gst_element_set_state (pipeline, GST_STATE_PLAYING);
182 while (gst_bin_iterate (GST_BIN (pipeline))) {
183 get_position_info (cdparanoia);
187 gst_element_set_state (pipeline, GST_STATE_PAUSED);
189 g_print ("\nplaying from second 25 to second 29\n");
190 /* seek to some seconds */
191 event = gst_event_new_segment_seek (GST_FORMAT_TIME |
192 GST_SEEK_METHOD_SET |
193 GST_SEEK_FLAG_FLUSH, 25 * GST_SECOND, 29 * GST_SECOND);
194 res = gst_pad_send_event (pad, event);
196 g_warning ("seek failed");
198 gst_element_set_state (pipeline, GST_STATE_PLAYING);
200 while (gst_bin_iterate (GST_BIN (pipeline))) {
201 get_position_info (cdparanoia);
205 /* shutdown everything again */
206 gst_element_set_state (pipeline, GST_STATE_NULL);