Add semicolons after GST_BOILERPLATE[_FULL] so that indent doesn't mess up following...
[platform/upstream/gstreamer.git] / ext / dvdread / dvdreadsrc.c
1 /* GStreamer
2  * Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) 2001 Billy Biggs <vektor@dumbterm.net>.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include "_stdint.h"
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <string.h>
31 #include <errno.h>
32
33 #include "dvdreadsrc.h"
34
35 /* #include <gst/gst-i18n-plugin.h> */
36 /* FIXME: remove once GETTEXT_PACKAGE etc. is set */
37 #define _(s) s
38
39 GST_DEBUG_CATEGORY_STATIC (gstgst_dvd_read_src_debug);
40 #define GST_CAT_DEFAULT (gstgst_dvd_read_src_debug)
41
42 static void gst_dvd_read_src_do_init (GType dvdreadsrc_type);
43
44 enum
45 {
46   ARG_0,
47   ARG_DEVICE,
48   ARG_TITLE,
49   ARG_CHAPTER,
50   ARG_ANGLE
51 };
52
53 static GstElementDetails gst_dvd_read_src_details = {
54   "DVD Source",
55   "Source/File/DVD",
56   "Access a DVD title/chapter/angle using libdvdread",
57   "Erik Walthinsen <omega@cse.ogi.edu>",
58 };
59
60 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
61     GST_PAD_SRC,
62     GST_PAD_ALWAYS,
63     GST_STATIC_CAPS ("video/mpeg, mpegversion=2, systemstream=(boolean)true"));
64
65 static GstFormat title_format;
66 static GstFormat angle_format;
67 static GstFormat sector_format;
68 static GstFormat chapter_format;
69
70 static gboolean gst_dvd_read_src_start (GstBaseSrc * basesrc);
71 static gboolean gst_dvd_read_src_stop (GstBaseSrc * basesrc);
72 static GstFlowReturn gst_dvd_read_src_create (GstPushSrc * pushsrc,
73     GstBuffer ** buf);
74 static gboolean gst_dvd_read_src_src_query (GstBaseSrc * basesrc,
75     GstQuery * query);
76 static gboolean gst_dvd_read_src_src_event (GstBaseSrc * basesrc,
77     GstEvent * event);
78 static gboolean gst_dvd_read_src_goto_title (GstDvdReadSrc * src, gint title,
79     gint angle);
80 static gboolean gst_dvd_read_src_goto_chapter (GstDvdReadSrc * src,
81     gint chapter);
82 static gboolean gst_dvd_read_src_goto_sector (GstDvdReadSrc * src, gint angle);
83 static void gst_dvd_read_src_set_property (GObject * object, guint prop_id,
84     const GValue * value, GParamSpec * pspec);
85 static void gst_dvd_read_src_get_property (GObject * object, guint prop_id,
86     GValue * value, GParamSpec * pspec);
87 static GstEvent *gst_dvd_read_src_make_clut_change_event (GstDvdReadSrc * src,
88     const guint * clut);
89 static gboolean gst_dvd_read_src_get_size (GstDvdReadSrc * src, gint64 * size);
90
91 GST_BOILERPLATE_FULL (GstDvdReadSrc, gst_dvd_read_src, GstPushSrc,
92     GST_TYPE_PUSH_SRC, gst_dvd_read_src_do_init);
93
94 static void
95 gst_dvd_read_src_base_init (gpointer g_class)
96 {
97   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
98
99   gst_element_class_add_pad_template (element_class,
100       gst_static_pad_template_get (&srctemplate));
101
102   gst_element_class_set_details (element_class, &gst_dvd_read_src_details);
103 }
104
105 static void
106 gst_dvd_read_src_finalize (GObject * object)
107 {
108   GstDvdReadSrc *src = GST_DVD_READ_SRC (object);
109
110   g_free (src->location);
111   g_free (src->last_uri);
112
113   G_OBJECT_CLASS (parent_class)->finalize (object);
114 }
115
116 static void
117 gst_dvd_read_src_init (GstDvdReadSrc * src, GstDvdReadSrcClass * klass)
118 {
119   src->dvd = NULL;
120   src->vts_file = NULL;
121   src->vmg_file = NULL;
122   src->dvd_title = NULL;
123
124   src->location = g_strdup ("/dev/dvd");
125   src->last_uri = NULL;
126   src->new_seek = TRUE;
127   src->new_cell = TRUE;
128   src->change_cell = FALSE;
129   src->uri_title = 1;
130   src->uri_chapter = 1;
131   src->uri_angle = 1;
132
133   src->seek_pend = FALSE;
134   src->flush_pend = FALSE;
135   src->seek_pend_fmt = GST_FORMAT_UNDEFINED;
136   src->title_lang_event_pending = NULL;
137   src->pending_clut_event = NULL;
138
139   gst_pad_use_fixed_caps (GST_BASE_SRC_PAD (src));
140   gst_pad_set_caps (GST_BASE_SRC_PAD (src),
141       gst_static_pad_template_get_caps (&srctemplate));
142 }
143
144 static void
145 gst_dvd_read_src_class_init (GstDvdReadSrcClass * klass)
146 {
147   GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass);
148   GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
149   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
150
151   gobject_class->finalize = gst_dvd_read_src_finalize;
152   gobject_class->set_property = gst_dvd_read_src_set_property;
153   gobject_class->get_property = gst_dvd_read_src_get_property;
154
155   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DEVICE,
156       g_param_spec_string ("device", "Device",
157           "DVD device location", NULL, G_PARAM_READWRITE));
158   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TITLE,
159       g_param_spec_int ("title", "title", "title",
160           1, 999, 1, G_PARAM_READWRITE));
161   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CHAPTER,
162       g_param_spec_int ("chapter", "chapter", "chapter",
163           1, 999, 1, G_PARAM_READWRITE));
164   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ANGLE,
165       g_param_spec_int ("angle", "angle", "angle",
166           1, 999, 1, G_PARAM_READWRITE));
167
168   gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_dvd_read_src_start);
169   gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_dvd_read_src_stop);
170   gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_dvd_read_src_src_query);
171   gstbasesrc_class->event = GST_DEBUG_FUNCPTR (gst_dvd_read_src_src_event);
172
173   gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_dvd_read_src_create);
174 }
175
176 static gboolean
177 gst_dvd_read_src_start (GstBaseSrc * basesrc)
178 {
179   GstDvdReadSrc *src = GST_DVD_READ_SRC (basesrc);
180
181   g_return_val_if_fail (src->location != NULL, FALSE);
182
183   GST_DEBUG_OBJECT (src, "Opening DVD '%s'", src->location);
184
185   if ((src->dvd = DVDOpen (src->location)) == NULL)
186     goto open_failed;
187
188   /* Load the video manager to find out the information about the titles */
189   GST_DEBUG_OBJECT (src, "Loading VMG info");
190
191   if (!(src->vmg_file = ifoOpen (src->dvd, 0)))
192     goto ifo_open_failed;
193
194   src->tt_srpt = src->vmg_file->tt_srpt;
195
196   src->title = src->uri_title - 1;
197   src->chapter = src->uri_chapter - 1;
198   src->angle = src->uri_angle - 1;
199
200   if (!gst_dvd_read_src_goto_title (src, src->title, src->angle))
201     goto title_open_failed;
202
203   if (!gst_dvd_read_src_goto_chapter (src, src->chapter))
204     goto chapter_open_failed;
205
206   src->new_seek = FALSE;
207   src->change_cell = TRUE;
208
209   return TRUE;
210
211   /* ERRORS */
212 open_failed:
213   {
214     GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
215         (_("Could not open DVD")),
216         ("DVDOpen(%s) failed: %s", src->location, g_strerror (errno)));
217     return FALSE;
218   }
219 ifo_open_failed:
220   {
221     GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
222         (_("Could not open DVD")),
223         ("ifoOpen() failed: %s", g_strerror (errno)));
224     return FALSE;
225   }
226 title_open_failed:
227   {
228     GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
229         (_("Could not open DVD title %d"), src->uri_title), (NULL));
230     return FALSE;
231   }
232 chapter_open_failed:
233   {
234     GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
235         (_("Failed to go to chapter %d of DVD title %d"),
236             src->uri_chapter, src->uri_title), (NULL));
237     return FALSE;
238   }
239 }
240
241 static gboolean
242 gst_dvd_read_src_stop (GstBaseSrc * basesrc)
243 {
244   GstDvdReadSrc *src = GST_DVD_READ_SRC (basesrc);
245
246   if (src->vts_file) {
247     ifoClose (src->vts_file);
248     src->vts_file = NULL;
249   }
250   if (src->vmg_file) {
251     ifoClose (src->vmg_file);
252     src->vmg_file = NULL;
253   }
254   if (src->dvd_title) {
255     DVDCloseFile (src->dvd_title);
256     src->dvd_title = NULL;
257   }
258   if (src->dvd) {
259     DVDClose (src->dvd);
260     src->dvd = NULL;
261   }
262   src->new_cell = TRUE;
263   src->new_seek = TRUE;
264   src->change_cell = FALSE;
265   src->chapter = 0;
266   src->title = 0;
267   src->flush_pend = FALSE;
268   src->seek_pend = FALSE;
269   src->seek_pend_fmt = GST_FORMAT_UNDEFINED;
270   if (src->title_lang_event_pending) {
271     gst_event_unref (src->title_lang_event_pending);
272     src->title_lang_event_pending = NULL;
273   }
274   if (src->pending_clut_event) {
275     gst_event_unref (src->pending_clut_event);
276     src->pending_clut_event = NULL;
277   }
278
279   GST_LOG_OBJECT (src, "closed DVD");
280
281   return TRUE;
282 }
283
284 static void
285 cur_title_get_chapter_pgc (GstDvdReadSrc * src, gint chapter, gint * p_pgn,
286     gint * p_pgc_id, pgc_t ** p_pgc)
287 {
288   pgc_t *pgc;
289   gint pgn, pgc_id;
290
291   g_assert (chapter >= 0 && chapter < src->num_chapters);
292
293   pgc_id = src->vts_ptt_srpt->title[src->ttn - 1].ptt[chapter].pgcn;
294   pgn = src->vts_ptt_srpt->title[src->ttn - 1].ptt[chapter].pgn;
295   pgc = src->vts_file->vts_pgcit->pgci_srp[pgc_id - 1].pgc;
296
297   *p_pgn = pgn;
298   *p_pgc_id = pgc_id;
299   *p_pgc = pgc;
300 }
301
302 static void
303 cur_title_get_chapter_bounds (GstDvdReadSrc * src, gint chapter,
304     gint * p_first_cell, gint * p_last_cell)
305 {
306   pgc_t *pgc;
307   gint pgn, pgc_id, pgn_next_ch;
308
309   g_assert (chapter >= 0 && chapter < src->num_chapters);
310
311   cur_title_get_chapter_pgc (src, chapter, &pgn, &pgc_id, &pgc);
312
313   *p_first_cell = pgc->program_map[pgn - 1] - 1;
314
315   if (chapter == (src->num_chapters - 1)) {
316     *p_last_cell = pgc->nr_of_cells;
317   } else {
318     pgn_next_ch = src->vts_ptt_srpt->title[src->ttn - 1].ptt[chapter + 1].pgn;
319     *p_last_cell = pgc->program_map[pgn_next_ch - 1] - 1;
320   }
321 }
322
323 static gboolean
324 gst_dvd_read_src_goto_chapter (GstDvdReadSrc * src, gint chapter)
325 {
326   gint i;
327
328   /* make sure the chapter number is valid for this title */
329   if (chapter < 0 || chapter >= src->num_chapters) {
330     GST_WARNING_OBJECT (src, "invalid chapter %d (only %d available)",
331         chapter, src->num_chapters);
332     chapter = CLAMP (chapter, 0, src->num_chapters - 1);
333   }
334
335   /* determine which program chain we want to watch. This is
336    * based on the chapter number */
337   cur_title_get_chapter_pgc (src, chapter, &src->pgn, &src->pgc_id,
338       &src->cur_pgc);
339   cur_title_get_chapter_bounds (src, chapter, &src->start_cell,
340       &src->last_cell);
341
342   GST_LOG_OBJECT (src, "Opened chapter %d - cell %d-%d", chapter,
343       src->start_cell, src->last_cell);
344
345   /* retrieve position */
346   src->cur_pack = 0;
347   for (i = 0; i < chapter; i++) {
348     gint c1, c2;
349
350     cur_title_get_chapter_bounds (src, i, &c1, &c2);
351
352     while (c1 < c2) {
353       src->cur_pack +=
354           src->cur_pgc->cell_playback[c1].last_sector -
355           src->cur_pgc->cell_playback[c1].first_sector;
356       ++c1;
357     }
358   }
359
360   /* prepare reading for new cell */
361   src->new_cell = TRUE;
362   src->next_cell = src->start_cell;
363
364   src->chapter = chapter;
365
366   if (src->pending_clut_event)
367     gst_event_unref (src->pending_clut_event);
368
369   src->pending_clut_event =
370       gst_dvd_read_src_make_clut_change_event (src, src->cur_pgc->palette);
371
372   return TRUE;
373 }
374
375 static gboolean
376 gst_dvd_read_src_goto_title (GstDvdReadSrc * src, gint title, gint angle)
377 {
378   GstStructure *s;
379   gchar lang_code[3] = { '\0', '\0', '\0' }, *t;
380   gint title_set_nr;
381   gint num_titles;
382   gint num_angles;
383   gint i;
384
385   /* make sure our title number is valid */
386   num_titles = src->tt_srpt->nr_of_srpts;
387   GST_INFO_OBJECT (src, "There are %d titles on this DVD", num_titles);
388   if (title < 0 || title >= num_titles)
389     goto invalid_title;
390
391   src->num_chapters = src->tt_srpt->title[title].nr_of_ptts;
392   GST_INFO_OBJECT (src, "Title %d has %d chapters", title, src->num_chapters);
393
394   /* make sure the angle number is valid for this title */
395   num_angles = src->tt_srpt->title[title].nr_of_angles;
396   GST_LOG_OBJECT (src, "Title %d has %d angles", title, num_angles);
397   if (angle < 0 || angle >= num_angles) {
398     GST_WARNING_OBJECT (src, "Invalid angle %d (only %d available)",
399         angle, num_angles);
400     angle = CLAMP (angle, 0, num_angles - 1);
401   }
402
403   /* load the VTS information for the title set our title is in */
404   title_set_nr = src->tt_srpt->title[title].title_set_nr;
405   src->vts_file = ifoOpen (src->dvd, title_set_nr);
406   if (src->vts_file == NULL)
407     goto ifo_open_failed;
408
409   src->ttn = src->tt_srpt->title[title].vts_ttn;
410   src->vts_ptt_srpt = src->vts_file->vts_ptt_srpt;
411
412   /* we've got enough info, time to open the title set data */
413   src->dvd_title = DVDOpenFile (src->dvd, title_set_nr, DVD_READ_TITLE_VOBS);
414   if (src->dvd_title == NULL)
415     goto title_open_failed;
416
417   GST_INFO_OBJECT (src, "Opened title %d, angle %d", title, angle);
418   src->title = title;
419   src->angle = angle;
420
421   /* build event */
422
423   if (src->title_lang_event_pending) {
424     gst_event_unref (src->title_lang_event_pending);
425     src->title_lang_event_pending = NULL;
426   }
427
428   s = gst_structure_new ("application/x-gst-dvd",
429       "event", G_TYPE_STRING, "dvd-lang-codes", NULL);
430
431   /* audio */
432   for (i = 0; i < src->vts_file->vtsi_mat->nr_of_vts_audio_streams; i++) {
433     const audio_attr_t *a = &src->vts_file->vtsi_mat->vts_audio_attr[i];
434
435     t = g_strdup_printf ("audio-%d-format", i);
436     gst_structure_set (s, t, G_TYPE_INT, (int) a->audio_format, NULL);
437     g_free (t);
438
439     if (a->lang_type) {
440       t = g_strdup_printf ("audio-%d-language", i);
441       lang_code[0] = (a->lang_code >> 8) & 0xff;
442       lang_code[1] = a->lang_code & 0xff;
443       gst_structure_set (s, t, G_TYPE_STRING, lang_code, NULL);
444       g_free (t);
445     } else {
446       lang_code[0] = '\0';
447     }
448
449     GST_INFO_OBJECT (src, "[%02d] Audio    %02d: lang='%s', format=%d",
450         src->title, i, lang_code, (gint) a->audio_format);
451   }
452
453   /* subtitle */
454   for (i = 0; i < src->vts_file->vtsi_mat->nr_of_vts_subp_streams; i++) {
455     const subp_attr_t *u = &src->vts_file->vtsi_mat->vts_subp_attr[i];
456
457     if (u->type) {
458       t = g_strdup_printf ("subtitle-%d-language", i);
459       lang_code[0] = (u->lang_code >> 8) & 0xff;
460       lang_code[1] = u->lang_code & 0xff;
461       gst_structure_set (s, t, G_TYPE_STRING, lang_code, NULL);
462       g_free (t);
463     } else {
464       lang_code[0] = '\0';
465     }
466
467     GST_INFO_OBJECT (src, "[%02d] Subtitle %02d: lang='%s', format=%d",
468         src->title, i, lang_code);
469   }
470
471   src->title_lang_event_pending =
472       gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, s);
473
474   return TRUE;
475
476   /* ERRORS */
477 invalid_title:
478   {
479     GST_WARNING_OBJECT (src, "Invalid title %d (only %d available)",
480         title, num_titles);
481     return FALSE;
482   }
483 ifo_open_failed:
484   {
485     GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
486         (_("Could not open DVD title %d"), title_set_nr),
487         ("ifoOpen(%d) failed: %s", title_set_nr, g_strerror (errno)));
488     return FALSE;
489   }
490 title_open_failed:
491   {
492     GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
493         (_("Could not open DVD title %d"), title_set_nr),
494         ("Can't open title VOBS (VTS_%02d_1.VOB)", title_set_nr));
495     return FALSE;
496   }
497 }
498
499 /* FIXME: double-check this function, compare against original */
500 static gint
501 gst_dvd_read_src_get_next_cell_for (GstDvdReadSrc * src, gint cell)
502 {
503   /* Check if we're entering an angle block. */
504   if (src->cur_pgc->cell_playback[cell].block_type != BLOCK_TYPE_ANGLE_BLOCK)
505     return (cell + 1);
506
507   while (src->cur_pgc->cell_playback[cell].block_mode == BLOCK_MODE_LAST_CELL)
508     ++cell;
509
510   return cell + 1;              /* really +1? (tpm) */
511 }
512
513 /* Returns true if the pack is a NAV pack.  This check is clearly insufficient,
514  * and sometimes we incorrectly think that valid other packs are NAV packs.  I
515  * need to make this stronger. */
516 static gboolean
517 gst_dvd_read_src_is_nav_pack (const guint8 * buffer)
518 {
519   return (buffer[41] == 0xbf && buffer[1027] == 0xbf);
520 }
521
522 typedef enum
523 {
524   GST_DVD_READ_OK = 0,
525   GST_DVD_READ_ERROR = -1,
526   GST_DVD_READ_EOS = -2,
527   GST_DVD_READ_AGAIN = -3
528 } GstDvdReadReturn;
529
530 static GstDvdReadReturn
531 gst_dvd_read_src_read (GstDvdReadSrc * src, gint angle, gint new_seek,
532     GstBuffer ** p_buf)
533 {
534   GstBuffer *buf;
535   guint8 oneblock[DVD_VIDEO_LB_LEN];
536   dsi_t dsi_pack;
537   guint next_vobu, next_ilvu_start, cur_output_size;
538   gint len;
539
540   /* playback by cell in this pgc, starting at the cell for our chapter */
541   if (new_seek)
542     src->cur_cell = src->start_cell;
543
544 again:
545
546   if (src->cur_cell >= src->last_cell) {
547     /* advance to next chapter */
548     if (src->chapter == (src->num_chapters - 1))
549       goto eos;
550
551     GST_INFO_OBJECT (src, "end of chapter %d, switch to next", src->chapter);
552
553     ++src->chapter;
554     gst_dvd_read_src_goto_chapter (src, src->chapter);
555
556     return GST_DVD_READ_AGAIN;
557   }
558
559   if (src->new_cell || new_seek) {
560     if (!new_seek) {
561       src->cur_cell = src->next_cell;
562       if (src->cur_cell >= src->last_cell) {
563         GST_LOG_OBJECT (src, "last cell in chapter");
564         goto again;
565       }
566     }
567
568     /* take angle into account */
569     if (src->cur_pgc->cell_playback[src->cur_cell].block_type
570         == BLOCK_TYPE_ANGLE_BLOCK)
571       src->cur_cell += angle;
572
573     /* calculate next cell */
574     src->next_cell = gst_dvd_read_src_get_next_cell_for (src, src->cur_cell);
575
576     /* we loop until we're out of this cell */
577     src->cur_pack = src->cur_pgc->cell_playback[src->cur_cell].first_sector;
578     src->new_cell = FALSE;
579   }
580
581   if (src->cur_pack >= src->cur_pgc->cell_playback[src->cur_cell].last_sector) {
582     src->new_cell = TRUE;
583     GST_LOG_OBJECT (src, "Beyond last sector, go to next cell");
584     return GST_DVD_READ_AGAIN;
585   }
586
587   /* read NAV packet */
588 nav_retry:
589
590   len = DVDReadBlocks (src->dvd_title, src->cur_pack, 1, oneblock);
591   if (len == 0)
592     goto read_error;
593
594   if (!gst_dvd_read_src_is_nav_pack (oneblock)) {
595     src->cur_pack++;
596     goto nav_retry;
597   }
598
599   /* parse the contained dsi packet */
600   navRead_DSI (&dsi_pack, &oneblock[DSI_START_BYTE]);
601   g_assert (src->cur_pack == dsi_pack.dsi_gi.nv_pck_lbn);
602
603   /* determine where we go next. These values are the ones we
604    * mostly care about */
605   next_ilvu_start = src->cur_pack + dsi_pack.sml_agli.data[angle].address;
606   cur_output_size = dsi_pack.dsi_gi.vobu_ea;
607
608   /* If we're not at the end of this cell, we can determine the next
609    * VOBU to display using the VOBU_SRI information section of the
610    * DSI.  Using this value correctly follows the current angle,
611    * avoiding the doubled scenes in The Matrix, and makes our life
612    * really happy.
613    *
614    * Otherwise, we set our next address past the end of this cell to
615    * force the code above to go to the next cell in the program. */
616   if (dsi_pack.vobu_sri.next_vobu != SRI_END_OF_CELL) {
617     next_vobu = src->cur_pack + (dsi_pack.vobu_sri.next_vobu & 0x7fffffff);
618   } else {
619     next_vobu = src->cur_pack + cur_output_size + 1;
620   }
621
622   g_assert (cur_output_size < 1024);
623   ++src->cur_pack;
624
625   /* create the buffer (TODO: use buffer pool?) */
626   buf = gst_buffer_new_and_alloc (cur_output_size * DVD_VIDEO_LB_LEN);
627
628   /* read in and output cursize packs */
629   len = DVDReadBlocks (src->dvd_title, src->cur_pack, cur_output_size,
630       GST_BUFFER_DATA (buf));
631
632   if (len != cur_output_size)
633     goto block_read_error;
634
635   GST_BUFFER_SIZE (buf) = cur_output_size * DVD_VIDEO_LB_LEN;
636   /* GST_BUFFER_OFFSET (buf) = priv->cur_pack * DVD_VIDEO_LB_LEN; */
637
638   gst_buffer_set_caps (buf, GST_PAD_CAPS (GST_BASE_SRC_PAD (src)));
639
640   *p_buf = buf;
641
642   src->cur_pack = next_vobu;
643
644   GST_LOG_OBJECT (src, "Read %u sectors", cur_output_size);
645
646   return GST_DVD_READ_OK;
647
648   /* ERRORS */
649 eos:
650   {
651     GST_INFO_OBJECT (src, "last chapter done - EOS");
652     return GST_DVD_READ_EOS;
653   }
654 read_error:
655   {
656     GST_ERROR_OBJECT (src, "Read failed for block %d", src->cur_pack);
657     return GST_DVD_READ_ERROR;
658   }
659 block_read_error:
660   {
661     GST_ERROR_OBJECT (src, "Read failed for %d blocks at %d",
662         cur_output_size, src->cur_pack);
663     gst_buffer_unref (buf);
664     return GST_DVD_READ_ERROR;
665   }
666 }
667
668 static GstFlowReturn
669 gst_dvd_read_src_create (GstPushSrc * pushsrc, GstBuffer ** p_buf)
670 {
671   GstDvdReadSrc *src = GST_DVD_READ_SRC (pushsrc);
672   GstPad *srcpad;
673   gint res;
674
675   g_return_val_if_fail (src->dvd != NULL, GST_FLOW_ERROR);
676
677   srcpad = GST_BASE_SRC (src)->srcpad;
678
679   /* handle events, if any */
680   if (src->seek_pend) {
681     if (src->flush_pend) {
682       gst_pad_push_event (srcpad, gst_event_new_flush_start ());
683       gst_pad_push_event (srcpad, gst_event_new_flush_stop ());
684       src->flush_pend = FALSE;
685     }
686
687     if (src->seek_pend_fmt != GST_FORMAT_UNDEFINED) {
688       if (src->seek_pend_fmt == title_format) {
689         gst_dvd_read_src_goto_title (src, src->title, src->angle);
690       }
691       gst_dvd_read_src_goto_chapter (src, src->chapter);
692
693       src->seek_pend_fmt = GST_FORMAT_UNDEFINED;
694     } else {
695       if (!gst_dvd_read_src_goto_sector (src, src->angle)) {
696         GST_DEBUG_OBJECT (src, "seek to sector failed, going EOS");
697         gst_pad_push_event (srcpad, gst_event_new_eos ());
698         return GST_FLOW_UNEXPECTED;
699       }
700     }
701
702     gst_pad_push_event (srcpad,
703         gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_BYTES,
704             src->cur_pack * DVD_VIDEO_LB_LEN, -1, 0));
705
706     src->seek_pend = FALSE;
707   }
708
709   if (src->new_seek) {
710     gst_dvd_read_src_goto_title (src, src->title, src->angle);
711     gst_dvd_read_src_goto_chapter (src, src->chapter);
712
713     src->new_seek = FALSE;
714     src->change_cell = TRUE;
715   }
716
717   if (src->title_lang_event_pending) {
718     gst_pad_push_event (srcpad, src->title_lang_event_pending);
719     src->title_lang_event_pending = NULL;
720   }
721
722   if (src->pending_clut_event) {
723     gst_pad_push_event (srcpad, src->pending_clut_event);
724     src->pending_clut_event = NULL;
725   }
726
727   /* read it in */
728   do {
729     res = gst_dvd_read_src_read (src, src->angle, src->change_cell, p_buf);
730   } while (res == GST_DVD_READ_AGAIN);
731
732   switch (res) {
733     case GST_DVD_READ_ERROR:{
734       GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), (NULL));
735       return GST_FLOW_ERROR;
736     }
737     case GST_DVD_READ_EOS:{
738       GST_INFO_OBJECT (src, "Reached EOS");
739       return GST_FLOW_UNEXPECTED;
740     }
741     case GST_DVD_READ_OK:{
742       src->change_cell = FALSE;
743       return GST_FLOW_OK;
744     }
745     default:
746       break;
747   }
748
749   g_return_val_if_reached (GST_FLOW_UNEXPECTED);
750 }
751
752 static void
753 gst_dvd_read_src_set_property (GObject * object, guint prop_id,
754     const GValue * value, GParamSpec * pspec)
755 {
756   GstDvdReadSrc *src = GST_DVD_READ_SRC (object);
757   gboolean started;
758
759   GST_OBJECT_LOCK (src);
760   started = GST_OBJECT_FLAG_IS_SET (src, GST_BASE_SRC_STARTED);
761
762   switch (prop_id) {
763     case ARG_DEVICE:{
764       if (started) {
765         g_warning ("%s: property '%s' needs to be set before the device is "
766             "opened", GST_ELEMENT_NAME (src), pspec->name);
767         break;;
768       }
769
770       g_free (src->location);
771       /* clear the filename if we get a NULL (is that possible?) */
772       if (g_value_get_string (value) == NULL) {
773         src->location = g_strdup ("/dev/dvd");
774       } else {
775         src->location = g_strdup (g_value_get_string (value));
776       }
777       break;
778     }
779     case ARG_TITLE:
780       src->uri_title = g_value_get_int (value);
781       if (started) {
782         src->title = src->uri_title - 1;
783         src->new_seek = TRUE;
784       }
785       break;
786     case ARG_CHAPTER:
787       src->uri_chapter = g_value_get_int (value);
788       if (started) {
789         src->chapter = src->uri_chapter - 1;
790         src->new_seek = TRUE;
791       }
792       break;
793     case ARG_ANGLE:
794       src->uri_angle = g_value_get_int (value);
795       if (started) {
796         src->angle = src->uri_angle - 1;
797       }
798       break;
799     default:
800       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
801       break;
802   }
803
804   GST_OBJECT_UNLOCK (src);
805 }
806
807 static void
808 gst_dvd_read_src_get_property (GObject * object, guint prop_id, GValue * value,
809     GParamSpec * pspec)
810 {
811   GstDvdReadSrc *src = GST_DVD_READ_SRC (object);
812
813   GST_OBJECT_LOCK (src);
814
815   switch (prop_id) {
816     case ARG_DEVICE:
817       g_value_set_string (value, src->location);
818       break;
819     case ARG_TITLE:
820       g_value_set_int (value, src->uri_title);
821       break;
822     case ARG_CHAPTER:
823       g_value_set_int (value, src->uri_chapter);
824       break;
825     case ARG_ANGLE:
826       g_value_set_int (value, src->uri_angle);
827       break;
828     default:
829       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
830       break;
831   }
832
833   GST_OBJECT_UNLOCK (src);
834 }
835
836 static gboolean
837 gst_dvd_read_src_get_size (GstDvdReadSrc * src, gint64 * size)
838 {
839   gboolean ret = FALSE;
840
841   if (src->dvd_title) {
842     gsize blocks;
843
844     blocks = DVDFileSize (src->dvd_title);
845     if (blocks >= 0) {
846       *size = (gint64) blocks *DVD_VIDEO_LB_LEN;
847
848       ret = TRUE;
849     } else {
850       GST_WARNING_OBJECT (src, "DVDFileSize(%p) failed!", src->dvd_title);
851     }
852   }
853
854   return ret;
855 }
856
857 /*** Querying and seeking ***/
858
859 static gboolean
860 gst_dvd_read_src_do_seek (GstDvdReadSrc * src, GstEvent * event)
861 {
862   GstSeekFlags flags;
863   GstSeekType cur_type, end_type;
864   gint64 new_off, total, cur;
865   GstFormat format;
866   GstPad *srcpad;
867   gboolean query_ok;
868   gdouble rate;
869
870   srcpad = GST_BASE_SRC (src)->srcpad;
871
872   gst_event_parse_seek (event, &rate, &format, &flags, &cur_type, &new_off,
873       &end_type, NULL);
874
875   if (end_type != GST_SEEK_TYPE_NONE) {
876     GST_WARNING_OBJECT (src, "End seek type not supported, will be ignored");
877   }
878
879   switch (format) {
880     case GST_FORMAT_BYTES:
881       break;
882     default:{
883       if (format != chapter_format &&
884           format != sector_format &&
885           format != angle_format && format != title_format) {
886         GST_DEBUG_OBJECT (src, "Unsupported seek format %d (%s)", format,
887             gst_format_get_name (format));
888         return FALSE;
889       }
890       break;
891     }
892   }
893
894   /* get current offset and length */
895   if (format == GST_FORMAT_BYTES) {
896     GST_OBJECT_LOCK (src);
897     query_ok = gst_dvd_read_src_get_size (src, &total);
898     cur = (gint64) src->cur_pack * DVD_VIDEO_LB_LEN;
899     GST_OBJECT_UNLOCK (src);
900   } else {
901     query_ok = gst_pad_query_duration (srcpad, &format, &total)
902         && gst_pad_query_position (srcpad, &format, &cur);
903   }
904
905   if (!query_ok) {
906     GST_DEBUG_OBJECT (src, "Failed to query duration/position");
907     return FALSE;
908   }
909
910   GST_DEBUG_OBJECT (src, "Current    %s: %12" G_GINT64_FORMAT,
911       gst_format_get_name (format), cur);
912   GST_DEBUG_OBJECT (src, "Total      %s: %12" G_GINT64_FORMAT,
913       gst_format_get_name (format), total);
914
915   /* get absolute */
916   switch (cur_type) {
917     case GST_SEEK_TYPE_SET:
918       /* no-op */
919       break;
920     case GST_SEEK_TYPE_CUR:
921       new_off += cur;
922       break;
923     case GST_SEEK_TYPE_END:
924       new_off = total - new_off;
925       break;
926     default:
927       GST_DEBUG_OBJECT (src, "Unsupported seek method");
928       return FALSE;
929   }
930
931   if (new_off < 0 || new_off >= total) {
932     GST_DEBUG_OBJECT (src, "Invalid seek position %" G_GINT64_FORMAT, new_off);
933     return FALSE;
934   }
935
936   if (cur == new_off) {
937     GST_DEBUG_OBJECT (src, "We're already at that position!");
938     return TRUE;
939   }
940
941   GST_LOG_OBJECT (src, "Seeking to %s: %12" G_GINT64_FORMAT,
942       gst_format_get_name (format), new_off);
943
944   GST_OBJECT_LOCK (src);
945
946   if (format == angle_format) {
947     src->angle = new_off;
948     goto done;
949   }
950
951   if (format == sector_format) {
952     src->cur_pack = new_off;
953   } else if (format == GST_FORMAT_BYTES) {
954     src->cur_pack = new_off / DVD_VIDEO_LB_LEN;
955     if ((src->cur_pack * DVD_VIDEO_LB_LEN) != new_off) {
956       GST_LOG_OBJECT (src, "rounded down offset %" G_GINT64_FORMAT " => %"
957           G_GINT64_FORMAT, new_off, (gint64) src->cur_pack * DVD_VIDEO_LB_LEN);
958     }
959   } else if (format == chapter_format) {
960     src->cur_pack = 0;
961     src->chapter = new_off;
962     src->seek_pend_fmt = format;
963   } else if (format == title_format) {
964     src->cur_pack = 0;
965     src->title = new_off;
966     src->chapter = 0;
967     src->seek_pend_fmt = format;
968   } else {
969     GST_OBJECT_UNLOCK (src);
970     g_return_val_if_reached (FALSE);
971   }
972
973   /* leave for events */
974   src->seek_pend = TRUE;
975   if ((flags & GST_SEEK_FLAG_FLUSH) != 0)
976     src->flush_pend = TRUE;
977
978 done:
979
980   GST_OBJECT_UNLOCK (src);
981
982   return TRUE;
983 }
984
985 static gboolean
986 gst_dvd_read_src_src_event (GstBaseSrc * basesrc, GstEvent * event)
987 {
988   GstDvdReadSrc *src = GST_DVD_READ_SRC (basesrc);
989   gboolean res;
990
991   GST_LOG_OBJECT (src, "handling %s event", GST_EVENT_TYPE_NAME (event));
992
993   switch (GST_EVENT_TYPE (event)) {
994     case GST_EVENT_SEEK:
995       res = gst_dvd_read_src_do_seek (src, event);
996       break;
997     default:
998       res = GST_BASE_SRC_CLASS (parent_class)->event (basesrc, event);
999       break;
1000   }
1001
1002   return res;
1003 }
1004
1005 static GstEvent *
1006 gst_dvd_read_src_make_clut_change_event (GstDvdReadSrc * src,
1007     const guint * clut)
1008 {
1009   GstStructure *structure;
1010   gchar name[16];
1011   gint i;
1012
1013   structure = gst_structure_new ("application/x-gst-dvd",
1014       "event", G_TYPE_STRING, "dvd-spu-clut-change", NULL);
1015
1016   /* Create a separate field for each value in the table. */
1017   for (i = 0; i < 16; i++) {
1018     g_snprintf (name, sizeof (name), "clut%02d", i);
1019     gst_structure_set (structure, name, G_TYPE_INT, (int) clut[i], NULL);
1020   }
1021
1022   /* Create the DVD event and put the structure into it. */
1023   return gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, structure);
1024 }
1025
1026 static gint64
1027 gst_dvd_read_src_convert_timecode (dvd_time_t * time)
1028 {
1029   gint64 ret_time;
1030   const gint64 one_hour = 3600 * GST_SECOND;
1031   const gint64 one_min = 60 * GST_SECOND;
1032
1033   g_return_val_if_fail ((time->hour >> 4) < 0xa
1034       && (time->hour & 0xf) < 0xa, -1);
1035   g_return_val_if_fail ((time->minute >> 4) < 0x7
1036       && (time->minute & 0xf) < 0xa, -1);
1037   g_return_val_if_fail ((time->second >> 4) < 0x7
1038       && (time->second & 0xf) < 0xa, -1);
1039
1040   ret_time = ((time->hour >> 4) * 10 + (time->hour & 0xf)) * one_hour;
1041   ret_time += ((time->minute >> 4) * 10 + (time->minute & 0xf)) * one_min;
1042   ret_time += ((time->second >> 4) * 10 + (time->second & 0xf)) * GST_SECOND;
1043
1044   return ret_time;
1045 }
1046
1047 static gboolean
1048 gst_dvd_read_src_do_duration_query (GstDvdReadSrc * src, GstQuery * query)
1049 {
1050   GstFormat format;
1051   gint64 val;
1052
1053   gst_query_parse_duration (query, &format, NULL);
1054
1055   switch (format) {
1056     case GST_FORMAT_TIME:{
1057       if (src->cur_pgc == NULL)
1058         return FALSE;
1059       val = gst_dvd_read_src_convert_timecode (&src->cur_pgc->playback_time);
1060       if (val < 0)
1061         return FALSE;
1062       break;
1063     }
1064     case GST_FORMAT_BYTES:{
1065       if (!gst_dvd_read_src_get_size (src, &val))
1066         return FALSE;
1067       break;
1068     }
1069     default:{
1070       if (format == sector_format) {
1071         val = DVDFileSize (src->dvd_title);
1072       } else if (format == title_format) {
1073         val = src->tt_srpt->nr_of_srpts;
1074       } else if (format == chapter_format) {
1075         val = src->num_chapters;
1076       } else if (format == angle_format) {
1077         val = src->tt_srpt->title[src->title].nr_of_angles;
1078       } else {
1079         GST_DEBUG_OBJECT (src, "Don't know how to handle format %d (%s)",
1080             format, gst_format_get_name (format));
1081         return FALSE;
1082       }
1083       break;
1084     }
1085   }
1086
1087   GST_LOG_OBJECT (src, "duration = %" G_GINT64_FORMAT " %s", val,
1088       gst_format_get_name (format));
1089
1090   gst_query_set_duration (query, format, val);
1091   return TRUE;
1092 }
1093
1094 static gboolean
1095 gst_dvd_read_src_do_position_query (GstDvdReadSrc * src, GstQuery * query)
1096 {
1097   GstFormat format;
1098   gint64 val;
1099
1100   gst_query_parse_position (query, &format, NULL);
1101
1102   switch (format) {
1103     case GST_FORMAT_BYTES:{
1104       val = src->cur_pack * DVD_VIDEO_LB_LEN;
1105       break;
1106     }
1107     default:{
1108       if (format == sector_format) {
1109         val = src->cur_pack;
1110       } else if (format == title_format) {
1111         val = src->title;
1112       } else if (format == chapter_format) {
1113         val = src->chapter;
1114       } else if (format == angle_format) {
1115         val = src->angle;
1116       } else {
1117         GST_DEBUG_OBJECT (src, "Don't know how to handle format %d (%s)",
1118             format, gst_format_get_name (format));
1119         return FALSE;
1120       }
1121       break;
1122     }
1123   }
1124
1125   GST_LOG_OBJECT (src, "position = %" G_GINT64_FORMAT " %s", val,
1126       gst_format_get_name (format));
1127
1128   gst_query_set_position (query, format, val);
1129   return TRUE;
1130 }
1131
1132 static gboolean
1133 gst_dvd_read_src_src_query (GstBaseSrc * basesrc, GstQuery * query)
1134 {
1135   GstDvdReadSrc *src = GST_DVD_READ_SRC (basesrc);
1136   gboolean started;
1137   gboolean res = TRUE;
1138
1139   GST_LOG_OBJECT (src, "handling %s query",
1140       gst_query_type_get_name (GST_QUERY_TYPE (query)));
1141
1142   GST_OBJECT_LOCK (src);
1143   started = (GST_OBJECT_FLAG_IS_SET (src, GST_BASE_SRC_STARTED));
1144   GST_OBJECT_UNLOCK (src);
1145
1146   if (!started) {
1147     GST_DEBUG_OBJECT (src, "query failed: not started");
1148     return FALSE;
1149   }
1150
1151   switch (GST_QUERY_TYPE (query)) {
1152     case GST_QUERY_DURATION:
1153       GST_OBJECT_LOCK (src);
1154       res = gst_dvd_read_src_do_duration_query (src, query);
1155       GST_OBJECT_UNLOCK (src);
1156       break;
1157     case GST_QUERY_POSITION:
1158       GST_OBJECT_LOCK (src);
1159       res = gst_dvd_read_src_do_position_query (src, query);
1160       GST_OBJECT_UNLOCK (src);
1161       break;
1162     default:
1163       res = GST_BASE_SRC_CLASS (parent_class)->query (basesrc, query);
1164       break;
1165   }
1166
1167   return res;
1168 }
1169
1170 static gboolean
1171 gst_dvd_read_src_goto_sector (GstDvdReadSrc * src, int angle)
1172 {
1173   gint seek_to = src->cur_pack;
1174   gint chapter, sectors, next, cur, i;
1175
1176   /* retrieve position */
1177   src->cur_pack = 0;
1178   for (i = 0; i < src->num_chapters; i++) {
1179     gint c1, c2;
1180
1181     cur_title_get_chapter_bounds (src, i, &c1, &c2);
1182
1183     for (next = cur = c1; cur < c2;) {
1184       if (next != cur) {
1185         sectors =
1186             src->cur_pgc->cell_playback[cur].last_sector -
1187             src->cur_pgc->cell_playback[cur].first_sector;
1188         if (src->cur_pack + sectors > seek_to) {
1189           chapter = i;
1190           goto done;
1191         }
1192         src->cur_pack += sectors;
1193       }
1194       cur = next;
1195       if (src->cur_pgc->cell_playback[cur].block_type == BLOCK_TYPE_ANGLE_BLOCK)
1196         cur += angle;
1197       next = gst_dvd_read_src_get_next_cell_for (src, cur);
1198     }
1199   }
1200
1201   GST_DEBUG_OBJECT (src, "Seek to sector %u failed", seek_to);
1202
1203   return FALSE;
1204
1205 done:
1206   {
1207     /* so chapter $chapter and cell $cur contain our sector
1208      * of interest. Let's go there! */
1209     GST_INFO_OBJECT (src, "Seek succeeded, going to chapter %u, cell %u",
1210         chapter, cur);
1211
1212     gst_dvd_read_src_goto_chapter (src, chapter);
1213     src->cur_cell = cur;
1214     src->next_cell = next;
1215     src->new_cell = FALSE;
1216     src->cur_pack = seek_to;
1217
1218     return TRUE;
1219   }
1220 }
1221
1222
1223 /*** URI interface ***/
1224
1225 static GstURIType
1226 gst_dvd_read_src_uri_get_type (void)
1227 {
1228   return GST_URI_SRC;
1229 }
1230
1231 static gchar **
1232 gst_dvd_read_src_uri_get_protocols (void)
1233 {
1234   static gchar *protocols[] = { "dvd", NULL };
1235
1236   return protocols;
1237 }
1238
1239 static const gchar *
1240 gst_dvd_read_src_uri_get_uri (GstURIHandler * handler)
1241 {
1242   GstDvdReadSrc *src = GST_DVD_READ_SRC (handler);
1243
1244   GST_OBJECT_LOCK (src);
1245
1246   g_free (src->last_uri);
1247   src->last_uri = g_strdup_printf ("dvd://%d,%d,%d", src->uri_title,
1248       src->uri_chapter, src->uri_angle);
1249
1250   GST_OBJECT_UNLOCK (src);
1251
1252   return src->last_uri;
1253 }
1254
1255 static gboolean
1256 gst_dvd_read_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
1257 {
1258   GstDvdReadSrc *src = GST_DVD_READ_SRC (handler);
1259   gboolean ret;
1260   gchar *protocol;
1261
1262   protocol = gst_uri_get_protocol (uri);
1263   ret = (protocol != NULL && g_str_equal (protocol, "dvd"));
1264   g_free (protocol);
1265   protocol = NULL;
1266
1267   if (!ret)
1268     return ret;
1269
1270   /* parse out the new t/c/a and seek to them */
1271   {
1272     gchar *location = NULL;
1273     gchar **strs;
1274     gchar **strcur;
1275     gint pos = 0;
1276
1277     location = gst_uri_get_location (uri);
1278
1279     if (!location)
1280       return ret;
1281
1282     GST_OBJECT_LOCK (src);
1283
1284     src->uri_title = 1;
1285     src->uri_chapter = 1;
1286     src->uri_angle = 1;
1287
1288     strcur = strs = g_strsplit (location, ",", 0);
1289     while (strcur && *strcur) {
1290       gint val;
1291
1292       if (!sscanf (*strcur, "%d", &val))
1293         break;
1294
1295       if (val <= 0) {
1296         g_warning ("Invalid value %d in URI '%s'. Must be 1 or greater",
1297             val, location);
1298         break;
1299       }
1300
1301       switch (pos) {
1302         case 0:
1303           src->uri_title = val;
1304           break;
1305         case 1:
1306           src->uri_chapter = val;
1307           break;
1308         case 2:
1309           src->uri_angle = val;
1310           break;
1311       }
1312
1313       strcur++;
1314       pos++;
1315     }
1316
1317     if (pos > 0 && GST_OBJECT_FLAG_IS_SET (src, GST_BASE_SRC_STARTED)) {
1318       src->title = src->uri_title - 1;
1319       src->chapter = src->uri_chapter - 1;
1320       src->angle = src->uri_angle - 1;
1321       src->new_seek = TRUE;
1322     }
1323
1324     GST_OBJECT_UNLOCK (src);
1325
1326     g_strfreev (strs);
1327     g_free (location);
1328   }
1329
1330   return ret;
1331 }
1332
1333 static void
1334 gst_dvd_read_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
1335 {
1336   GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
1337
1338   iface->get_type = gst_dvd_read_src_uri_get_type;
1339   iface->get_protocols = gst_dvd_read_src_uri_get_protocols;
1340   iface->get_uri = gst_dvd_read_src_uri_get_uri;
1341   iface->set_uri = gst_dvd_read_src_uri_set_uri;
1342 }
1343
1344 static void
1345 gst_dvd_read_src_do_init (GType dvdreadsrc_type)
1346 {
1347   static const GInterfaceInfo urihandler_info = {
1348     gst_dvd_read_src_uri_handler_init,
1349     NULL,
1350     NULL
1351   };
1352
1353   g_type_add_interface_static (dvdreadsrc_type, GST_TYPE_URI_HANDLER,
1354       &urihandler_info);
1355
1356   title_format = gst_format_register ("title", "DVD title");
1357   angle_format = gst_format_register ("angle", "DVD angle");
1358   sector_format = gst_format_register ("sector", "DVD sector");
1359   chapter_format = gst_format_register ("chapter", "DVD chapter");
1360 }
1361
1362 static gboolean
1363 plugin_init (GstPlugin * plugin)
1364 {
1365   GST_DEBUG_CATEGORY_INIT (gstgst_dvd_read_src_debug, "dvdreadsrc", 0,
1366       "DVD reader element based on dvdreadsrc");
1367
1368   if (!gst_element_register (plugin, "dvdreadsrc", GST_RANK_SECONDARY,
1369           GST_TYPE_DVD_READ_SRC)) {
1370     return FALSE;
1371   }
1372
1373   return TRUE;
1374 }
1375
1376 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1377     GST_VERSION_MINOR,
1378     "dvdread",
1379     "Access a DVD with dvdread",
1380     plugin_init, VERSION, "GPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);