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