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