1 /* GStreamer DVD title source
2 * Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) 2001 Billy Biggs <vektor@dumbterm.net>.
4 * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
34 #include "dvdreadsrc.h"
36 #include <gst/gst-i18n-plugin.h>
38 GST_DEBUG_CATEGORY_STATIC (gstgst_dvd_read_src_debug);
39 #define GST_CAT_DEFAULT (gstgst_dvd_read_src_debug)
41 static void gst_dvd_read_src_do_init (GType dvdreadsrc_type);
52 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
55 GST_STATIC_CAPS ("video/mpeg, mpegversion=2, systemstream=(boolean)true"));
57 static GstFormat title_format;
58 static GstFormat angle_format;
59 static GstFormat sector_format;
60 static GstFormat chapter_format;
62 static gboolean gst_dvd_read_src_start (GstBaseSrc * basesrc);
63 static gboolean gst_dvd_read_src_stop (GstBaseSrc * basesrc);
64 static GstFlowReturn gst_dvd_read_src_create (GstPushSrc * pushsrc,
66 static gboolean gst_dvd_read_src_src_query (GstBaseSrc * basesrc,
68 static gboolean gst_dvd_read_src_src_event (GstBaseSrc * basesrc,
70 static gboolean gst_dvd_read_src_goto_title (GstDvdReadSrc * src, gint title,
72 static gboolean gst_dvd_read_src_goto_chapter (GstDvdReadSrc * src,
74 static gboolean gst_dvd_read_src_goto_sector (GstDvdReadSrc * src, gint angle);
75 static void gst_dvd_read_src_set_property (GObject * object, guint prop_id,
76 const GValue * value, GParamSpec * pspec);
77 static void gst_dvd_read_src_get_property (GObject * object, guint prop_id,
78 GValue * value, GParamSpec * pspec);
79 static GstEvent *gst_dvd_read_src_make_clut_change_event (GstDvdReadSrc * src,
81 static gboolean gst_dvd_read_src_get_size (GstDvdReadSrc * src, gint64 * size);
82 static gboolean gst_dvd_read_src_do_seek (GstBaseSrc * src, GstSegment * s);
83 static gint64 gst_dvd_read_src_convert_timecode (dvd_time_t * time);
84 static gint gst_dvd_read_src_get_next_cell (GstDvdReadSrc * src,
85 pgc_t * pgc, gint cell);
86 static GstClockTime gst_dvd_read_src_get_time_for_sector (GstDvdReadSrc * src,
88 static gint gst_dvd_read_src_get_sector_from_time (GstDvdReadSrc * src,
91 GST_BOILERPLATE_FULL (GstDvdReadSrc, gst_dvd_read_src, GstPushSrc,
92 GST_TYPE_PUSH_SRC, gst_dvd_read_src_do_init);
95 gst_dvd_read_src_base_init (gpointer g_class)
97 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
99 gst_element_class_add_pad_template (element_class,
100 gst_static_pad_template_get (&srctemplate));
102 gst_element_class_set_details_simple (element_class, "DVD Source",
104 "Access a DVD title/chapter/angle using libdvdread",
105 "Erik Walthinsen <omega@cse.ogi.edu>");
109 gst_dvd_read_src_finalize (GObject * object)
111 GstDvdReadSrc *src = GST_DVD_READ_SRC (object);
113 g_free (src->location);
114 g_free (src->last_uri);
116 G_OBJECT_CLASS (parent_class)->finalize (object);
120 gst_dvd_read_src_init (GstDvdReadSrc * src, GstDvdReadSrcClass * klass)
123 src->vts_file = NULL;
124 src->vmg_file = NULL;
125 src->dvd_title = NULL;
127 src->location = g_strdup ("/dev/dvd");
128 src->last_uri = NULL;
129 src->new_seek = TRUE;
130 src->new_cell = TRUE;
131 src->change_cell = FALSE;
133 src->uri_chapter = 1;
136 src->title_lang_event_pending = NULL;
137 src->pending_clut_event = NULL;
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));
145 gst_dvd_read_src_is_seekable (GstBaseSrc * src)
151 gst_dvd_read_src_class_init (GstDvdReadSrcClass * klass)
153 GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass);
154 GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
155 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
157 gobject_class->finalize = gst_dvd_read_src_finalize;
158 gobject_class->set_property = gst_dvd_read_src_set_property;
159 gobject_class->get_property = gst_dvd_read_src_get_property;
161 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DEVICE,
162 g_param_spec_string ("device", "Device",
163 "DVD device location", NULL,
164 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
165 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TITLE,
166 g_param_spec_int ("title", "title", "title",
167 1, 999, 1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
168 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CHAPTER,
169 g_param_spec_int ("chapter", "chapter", "chapter",
170 1, 999, 1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
171 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ANGLE,
172 g_param_spec_int ("angle", "angle", "angle",
173 1, 999, 1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
175 gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_dvd_read_src_start);
176 gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_dvd_read_src_stop);
177 gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_dvd_read_src_src_query);
178 gstbasesrc_class->event = GST_DEBUG_FUNCPTR (gst_dvd_read_src_src_event);
179 gstbasesrc_class->do_seek = GST_DEBUG_FUNCPTR (gst_dvd_read_src_do_seek);
180 gstbasesrc_class->is_seekable =
181 GST_DEBUG_FUNCPTR (gst_dvd_read_src_is_seekable);
183 gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_dvd_read_src_create);
187 gst_dvd_read_src_start (GstBaseSrc * basesrc)
189 GstDvdReadSrc *src = GST_DVD_READ_SRC (basesrc);
191 g_return_val_if_fail (src->location != NULL, FALSE);
193 GST_DEBUG_OBJECT (src, "Opening DVD '%s'", src->location);
195 if ((src->dvd = DVDOpen (src->location)) == NULL)
198 /* Load the video manager to find out the information about the titles */
199 GST_DEBUG_OBJECT (src, "Loading VMG info");
201 if (!(src->vmg_file = ifoOpen (src->dvd, 0)))
202 goto ifo_open_failed;
204 src->tt_srpt = src->vmg_file->tt_srpt;
206 src->title = src->uri_title - 1;
207 src->chapter = src->uri_chapter - 1;
208 src->angle = src->uri_angle - 1;
210 if (!gst_dvd_read_src_goto_title (src, src->title, src->angle))
211 goto title_open_failed;
213 if (!gst_dvd_read_src_goto_chapter (src, src->chapter))
214 goto chapter_open_failed;
216 src->new_seek = FALSE;
217 src->change_cell = TRUE;
224 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
225 (_("Could not open DVD")),
226 ("DVDOpen(%s) failed: %s", src->location, g_strerror (errno)));
231 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
232 (_("Could not open DVD")),
233 ("ifoOpen() failed: %s", g_strerror (errno)));
238 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
239 (_("Could not open DVD title %d"), src->uri_title), (NULL));
244 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
245 (_("Failed to go to chapter %d of DVD title %d"),
246 src->uri_chapter, src->uri_title), (NULL));
252 gst_dvd_read_src_stop (GstBaseSrc * basesrc)
254 GstDvdReadSrc *src = GST_DVD_READ_SRC (basesrc);
257 ifoClose (src->vts_file);
258 src->vts_file = NULL;
261 ifoClose (src->vmg_file);
262 src->vmg_file = NULL;
264 if (src->dvd_title) {
265 DVDCloseFile (src->dvd_title);
266 src->dvd_title = NULL;
272 src->new_cell = TRUE;
273 src->new_seek = TRUE;
274 src->change_cell = FALSE;
277 src->need_newsegment = TRUE;
278 src->vts_tmapt = NULL;
279 if (src->title_lang_event_pending) {
280 gst_event_unref (src->title_lang_event_pending);
281 src->title_lang_event_pending = NULL;
283 if (src->pending_clut_event) {
284 gst_event_unref (src->pending_clut_event);
285 src->pending_clut_event = NULL;
287 if (src->chapter_starts) {
288 g_free (src->chapter_starts);
289 src->chapter_starts = NULL;
292 GST_LOG_OBJECT (src, "closed DVD");
298 cur_title_get_chapter_pgc (GstDvdReadSrc * src, gint chapter, gint * p_pgn,
299 gint * p_pgc_id, pgc_t ** p_pgc)
304 g_assert (chapter >= 0 && chapter < src->num_chapters);
306 pgc_id = src->vts_ptt_srpt->title[src->ttn - 1].ptt[chapter].pgcn;
307 pgn = src->vts_ptt_srpt->title[src->ttn - 1].ptt[chapter].pgn;
308 pgc = src->vts_file->vts_pgcit->pgci_srp[pgc_id - 1].pgc;
316 cur_title_get_chapter_bounds (GstDvdReadSrc * src, gint chapter,
317 gint * p_first_cell, gint * p_last_cell)
320 gint pgn, pgc_id, pgn_next_ch;
322 g_assert (chapter >= 0 && chapter < src->num_chapters);
324 cur_title_get_chapter_pgc (src, chapter, &pgn, &pgc_id, &pgc);
326 *p_first_cell = pgc->program_map[pgn - 1] - 1;
328 if (chapter == (src->num_chapters - 1)) {
329 *p_last_cell = pgc->nr_of_cells;
331 pgn_next_ch = src->vts_ptt_srpt->title[src->ttn - 1].ptt[chapter + 1].pgn;
332 *p_last_cell = pgc->program_map[pgn_next_ch - 1] - 1;
337 gst_dvd_read_src_goto_chapter (GstDvdReadSrc * src, gint chapter)
341 /* make sure the chapter number is valid for this title */
342 if (chapter < 0 || chapter >= src->num_chapters) {
343 GST_WARNING_OBJECT (src, "invalid chapter %d (only %d available)",
344 chapter, src->num_chapters);
345 chapter = CLAMP (chapter, 0, src->num_chapters - 1);
348 /* determine which program chain we want to watch. This is
349 * based on the chapter number */
350 cur_title_get_chapter_pgc (src, chapter, &src->pgn, &src->pgc_id,
352 cur_title_get_chapter_bounds (src, chapter, &src->start_cell,
355 GST_LOG_OBJECT (src, "Opened chapter %d - cell %d-%d", chapter + 1,
356 src->start_cell, src->last_cell);
358 /* retrieve position */
360 for (i = 0; i < chapter; i++) {
363 cur_title_get_chapter_bounds (src, i, &c1, &c2);
367 src->cur_pgc->cell_playback[c1].last_sector -
368 src->cur_pgc->cell_playback[c1].first_sector;
373 /* prepare reading for new cell */
374 src->new_cell = TRUE;
375 src->next_cell = src->start_cell;
377 src->chapter = chapter;
379 if (src->pending_clut_event)
380 gst_event_unref (src->pending_clut_event);
382 src->pending_clut_event =
383 gst_dvd_read_src_make_clut_change_event (src, src->cur_pgc->palette);
389 gst_dvd_read_src_get_chapter_starts (GstDvdReadSrc * src)
391 GstClockTime uptohere;
394 g_free (src->chapter_starts);
395 src->chapter_starts = g_new (GstClockTime, src->num_chapters);
397 uptohere = (GstClockTime) 0;
398 for (c = 0; c < src->num_chapters; ++c) {
399 GstClockTime chapter_duration = 0;
400 gint cell_start, cell_end, cell;
404 cur_title_get_chapter_pgc (src, c, &pgn, &pgc_id, &pgc);
405 cur_title_get_chapter_bounds (src, c, &cell_start, &cell_end);
408 while (cell < cell_end) {
409 dvd_time_t *cell_duration;
411 cell_duration = &pgc->cell_playback[cell].playback_time;
412 chapter_duration += gst_dvd_read_src_convert_timecode (cell_duration);
413 cell = gst_dvd_read_src_get_next_cell (src, pgc, cell);
416 src->chapter_starts[c] = uptohere;
418 GST_INFO_OBJECT (src, "[%02u] Chapter %02u starts at %" GST_TIME_FORMAT
419 ", dur = %" GST_TIME_FORMAT ", cells %d-%d", src->title + 1, c + 1,
420 GST_TIME_ARGS (uptohere), GST_TIME_ARGS (chapter_duration),
421 cell_start, cell_end);
423 uptohere += chapter_duration;
428 gst_dvd_read_src_goto_title (GstDvdReadSrc * src, gint title, gint angle)
431 gchar lang_code[3] = { '\0', '\0', '\0' }, *t;
438 /* make sure our title number is valid */
439 num_titles = src->tt_srpt->nr_of_srpts;
440 GST_INFO_OBJECT (src, "There are %d titles on this DVD", num_titles);
441 if (title < 0 || title >= num_titles)
444 src->num_chapters = src->tt_srpt->title[title].nr_of_ptts;
445 GST_INFO_OBJECT (src, "Title %d has %d chapters", title + 1,
448 /* make sure the angle number is valid for this title */
449 src->num_angles = src->tt_srpt->title[title].nr_of_angles;
450 GST_LOG_OBJECT (src, "Title %d has %d angles", title + 1, src->num_angles);
451 if (angle < 0 || angle >= src->num_angles) {
452 GST_WARNING_OBJECT (src, "Invalid angle %d (only %d available)",
453 angle, src->num_angles);
454 angle = CLAMP (angle, 0, src->num_angles - 1);
457 /* load the VTS information for the title set our title is in */
458 title_set_nr = src->tt_srpt->title[title].title_set_nr;
459 src->vts_file = ifoOpen (src->dvd, title_set_nr);
460 if (src->vts_file == NULL)
461 goto ifo_open_failed;
463 src->ttn = src->tt_srpt->title[title].vts_ttn;
464 src->vts_ptt_srpt = src->vts_file->vts_ptt_srpt;
466 /* interactive title? */
467 if (src->num_chapters > 0 &&
468 src->vts_ptt_srpt->title[src->ttn - 1].ptt[0].pgn == 0) {
469 goto commands_only_pgc;
472 /* we've got enough info, time to open the title set data */
473 src->dvd_title = DVDOpenFile (src->dvd, title_set_nr, DVD_READ_TITLE_VOBS);
474 if (src->dvd_title == NULL)
475 goto title_open_failed;
477 GST_INFO_OBJECT (src, "Opened title %d, angle %d", title + 1, angle);
483 if (src->title_lang_event_pending) {
484 gst_event_unref (src->title_lang_event_pending);
485 src->title_lang_event_pending = NULL;
488 s = gst_structure_new ("application/x-gst-dvd",
489 "event", G_TYPE_STRING, "dvd-lang-codes", NULL);
491 /* so we can filter out invalid/unused streams (same for all chapters) */
492 cur_title_get_chapter_pgc (src, 0, &pgn0, &pgc0_id, &pgc0);
495 for (i = 0; i < src->vts_file->vtsi_mat->nr_of_vts_audio_streams; i++) {
496 const audio_attr_t *a;
498 /* audio stream present? */
499 if (pgc0 != NULL && (pgc0->audio_control[i] & 0x8000) == 0)
502 a = &src->vts_file->vtsi_mat->vts_audio_attr[i];
504 t = g_strdup_printf ("audio-%d-format", i);
505 gst_structure_set (s, t, G_TYPE_INT, (int) a->audio_format, NULL);
509 t = g_strdup_printf ("audio-%d-language", i);
510 lang_code[0] = (a->lang_code >> 8) & 0xff;
511 lang_code[1] = a->lang_code & 0xff;
512 gst_structure_set (s, t, G_TYPE_STRING, lang_code, NULL);
518 GST_INFO_OBJECT (src, "[%02d] Audio %02d: lang='%s', format=%d",
519 src->title + 1, i, lang_code, (gint) a->audio_format);
523 for (i = 0; i < src->vts_file->vtsi_mat->nr_of_vts_subp_streams; i++) {
524 const subp_attr_t *u;
526 /* subpicture stream present? */
527 if (pgc0 != NULL && (pgc0->subp_control[i] & 0x80000000) == 0)
530 u = &src->vts_file->vtsi_mat->vts_subp_attr[i];
533 t = g_strdup_printf ("subtitle-%d-language", i);
534 lang_code[0] = (u->lang_code >> 8) & 0xff;
535 lang_code[1] = u->lang_code & 0xff;
536 gst_structure_set (s, t, G_TYPE_STRING, lang_code, NULL);
542 GST_INFO_OBJECT (src, "[%02d] Subtitle %02d: lang='%s', type=%d",
543 src->title + 1, i, lang_code, u->type);
546 src->title_lang_event_pending =
547 gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, s);
549 /* dump seek tables */
550 src->vts_tmapt = src->vts_file->vts_tmapt;
551 if (src->vts_tmapt) {
554 GST_LOG_OBJECT (src, "nr_of_tmaps = %d", src->vts_tmapt->nr_of_tmaps);
555 for (i = 0; i < src->vts_tmapt->nr_of_tmaps; ++i) {
556 GST_LOG_OBJECT (src, "======= Table %d ===================", i);
557 GST_LOG_OBJECT (src, "Offset relative to VTS_TMAPTI: %d",
558 src->vts_tmapt->tmap_offset[i]);
559 GST_LOG_OBJECT (src, "Time unit (seconds) : %d",
560 src->vts_tmapt->tmap[i].tmu);
561 GST_LOG_OBJECT (src, "Number of entries : %d",
562 src->vts_tmapt->tmap[i].nr_of_entries);
563 for (j = 0; j < src->vts_tmapt->tmap[i].nr_of_entries; j++) {
566 time = src->vts_tmapt->tmap[i].tmu * (j + 1) * GST_SECOND;
567 GST_LOG_OBJECT (src, "Time: %" GST_TIME_FORMAT " VOBU "
568 "Sector: 0x%08x %s", GST_TIME_ARGS (time),
569 src->vts_tmapt->tmap[i].map_ent[j] & 0x7fffffff,
570 (src->vts_tmapt->tmap[i].map_ent[j] >> 31) ? "discontinuity" : "");
574 GST_WARNING_OBJECT (src, "no vts_tmapt - seeking will suck");
577 gst_dvd_read_src_get_chapter_starts (src);
584 GST_WARNING_OBJECT (src, "Invalid title %d (only %d available)",
590 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
591 (_("Could not open DVD title %d"), title_set_nr),
592 ("ifoOpen(%d) failed: %s", title_set_nr, g_strerror (errno)));
597 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
598 (_("Could not open DVD title %d"), title_set_nr),
599 ("Can't open title VOBS (VTS_%02d_1.VOB)", title_set_nr));
604 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
605 (_("Could not open DVD title %d. Interactive titles are not supported "
606 "by this element"), title_set_nr),
607 ("Commands-only PGC, not supported, use rsndvdbin"));
612 /* FIXME: double-check this function, compare against original */
614 gst_dvd_read_src_get_next_cell (GstDvdReadSrc * src, pgc_t * pgc, gint cell)
616 /* Check if we're entering an angle block. */
617 if (pgc->cell_playback[cell].block_type != BLOCK_TYPE_ANGLE_BLOCK)
620 while (pgc->cell_playback[cell].block_mode != BLOCK_MODE_LAST_CELL)
626 /* Returns true if the pack is a NAV pack */
628 gst_dvd_read_src_is_nav_pack (const guint8 * data, gint lbn, dsi_t * dsi_pack)
630 if (GST_READ_UINT32_BE (data + 0x26) != 0x000001BF)
633 /* Check that this is substream 0 (PCI) */
637 if (GST_READ_UINT32_BE (data + 0x400) != 0x000001BF)
640 /* Check that this is substream 1 (DSI) */
641 if (data[0x406] != 1)
644 /* Check sizes of PCI and DSI packets */
645 if (GST_READ_UINT16_BE (data + 0x2a) != 0x03d4)
648 if (GST_READ_UINT16_BE (data + 0x404) != 0x03fa)
651 /* Read the DSI packet into the provided struct and check it */
652 navRead_DSI (dsi_pack, (unsigned char *) data + DSI_START_BYTE);
653 if (lbn != dsi_pack->dsi_gi.nv_pck_lbn)
659 /* find time for sector from index, returns NONE if there is no exact match */
661 gst_dvd_read_src_get_time_for_sector (GstDvdReadSrc * src, guint sector)
665 if (src->vts_tmapt == NULL || src->vts_tmapt->nr_of_tmaps == 0)
666 return GST_CLOCK_TIME_NONE;
668 for (i = 0; i < src->vts_tmapt->nr_of_tmaps; ++i) {
669 for (j = 0; j < src->vts_tmapt->tmap[i].nr_of_entries; ++j) {
670 if ((src->vts_tmapt->tmap[i].map_ent[j] & 0x7fffffff) == sector)
671 return src->vts_tmapt->tmap[i].tmu * (j + 1) * GST_SECOND;
676 return (GstClockTime) 0;
678 return GST_CLOCK_TIME_NONE;
681 /* returns the sector in the index at (or before) the given time, or -1 */
683 gst_dvd_read_src_get_sector_from_time (GstDvdReadSrc * src, GstClockTime ts)
687 if (src->vts_tmapt == NULL || src->vts_tmapt->nr_of_tmaps == 0)
691 for (i = 0; i < src->vts_tmapt->nr_of_tmaps; ++i) {
692 for (j = 0; j < src->vts_tmapt->tmap[i].nr_of_entries; ++j) {
693 GstClockTime entry_time;
695 entry_time = src->vts_tmapt->tmap[i].tmu * (j + 1) * GST_SECOND;
696 if (entry_time <= ts) {
697 sector = src->vts_tmapt->tmap[i].map_ent[j] & 0x7fffffff;
699 if (entry_time >= ts) {
714 GST_DVD_READ_ERROR = -1,
715 GST_DVD_READ_EOS = -2,
716 GST_DVD_READ_AGAIN = -3
719 static GstDvdReadReturn
720 gst_dvd_read_src_read (GstDvdReadSrc * src, gint angle, gint new_seek,
725 guint8 oneblock[DVD_VIDEO_LB_LEN];
727 guint next_vobu, cur_output_size;
732 seg = &(GST_BASE_SRC (src)->segment);
734 /* playback by cell in this pgc, starting at the cell for our chapter */
736 src->cur_cell = src->start_cell;
740 if (src->cur_cell >= src->last_cell) {
741 /* advance to next chapter */
742 if (src->chapter == (src->num_chapters - 1) ||
743 (seg->format == chapter_format && seg->stop != -1 &&
744 src->chapter == (seg->stop - 1))) {
745 GST_DEBUG_OBJECT (src, "end of chapter segment");
749 GST_INFO_OBJECT (src, "end of chapter %d, switch to next",
753 gst_dvd_read_src_goto_chapter (src, src->chapter);
755 return GST_DVD_READ_AGAIN;
758 if (src->new_cell || new_seek) {
760 src->cur_cell = src->next_cell;
761 if (src->cur_cell >= src->last_cell) {
762 GST_LOG_OBJECT (src, "last cell in chapter");
767 /* take angle into account */
768 if (src->cur_pgc->cell_playback[src->cur_cell].block_type
769 == BLOCK_TYPE_ANGLE_BLOCK)
770 src->cur_cell += angle;
772 /* calculate next cell */
774 gst_dvd_read_src_get_next_cell (src, src->cur_pgc, src->cur_cell);
776 /* we loop until we're out of this cell */
777 src->cur_pack = src->cur_pgc->cell_playback[src->cur_cell].first_sector;
778 src->new_cell = FALSE;
779 GST_DEBUG_OBJECT (src, "Starting new cell %d @ pack %d", src->cur_cell,
783 if (src->cur_pack >= src->cur_pgc->cell_playback[src->cur_cell].last_sector) {
784 src->new_cell = TRUE;
785 GST_LOG_OBJECT (src, "Beyond last sector for cell %d, going to next cell",
787 return GST_DVD_READ_AGAIN;
790 /* read NAV packet */
795 len = DVDReadBlocks (src->dvd_title, src->cur_pack, 1, oneblock);
799 if (!gst_dvd_read_src_is_nav_pack (oneblock, src->cur_pack, &dsi_pack)) {
800 GST_LOG_OBJECT (src, "Skipping nav packet @ pack %d", src->cur_pack);
803 if (retries < 2000) {
806 GST_LOG_OBJECT (src, "No nav packet @ pack %d after 2000 blocks",
812 /* determine where we go next. These values are the ones we
813 * mostly care about */
814 cur_output_size = dsi_pack.dsi_gi.vobu_ea + 1;
816 /* If we're not at the end of this cell, we can determine the next
817 * VOBU to display using the VOBU_SRI information section of the
818 * DSI. Using this value correctly follows the current angle,
819 * avoiding the doubled scenes in The Matrix, and makes our life
822 * Otherwise, we set our next address past the end of this cell to
823 * force the code above to go to the next cell in the program. */
824 if (dsi_pack.vobu_sri.next_vobu != SRI_END_OF_CELL) {
825 next_vobu = src->cur_pack + (dsi_pack.vobu_sri.next_vobu & 0x7fffffff);
827 next_vobu = src->cur_pgc->cell_playback[src->cur_cell].last_sector + 1;
830 g_assert (cur_output_size < 1024);
832 /* create the buffer (TODO: use buffer pool?) */
833 buf = gst_buffer_new_and_alloc (cur_output_size * DVD_VIDEO_LB_LEN);
835 GST_LOG_OBJECT (src, "Going to read %u sectors @ pack %d", cur_output_size,
838 /* read in and output cursize packs */
839 len = DVDReadBlocks (src->dvd_title, src->cur_pack, cur_output_size,
840 GST_BUFFER_DATA (buf));
842 if (len != cur_output_size)
843 goto block_read_error;
845 GST_BUFFER_SIZE (buf) = cur_output_size * DVD_VIDEO_LB_LEN;
846 /* GST_BUFFER_OFFSET (buf) = priv->cur_pack * DVD_VIDEO_LB_LEN; */
847 GST_BUFFER_TIMESTAMP (buf) =
848 gst_dvd_read_src_get_time_for_sector (src, src->cur_pack);
850 gst_buffer_set_caps (buf, GST_PAD_CAPS (GST_BASE_SRC_PAD (src)));
854 GST_LOG_OBJECT (src, "Read %u sectors", cur_output_size);
856 src->cur_pack = next_vobu;
858 next_time = GST_BUFFER_TIMESTAMP (buf);
859 if (GST_CLOCK_TIME_IS_VALID (next_time) && seg->format == GST_FORMAT_TIME &&
860 GST_CLOCK_TIME_IS_VALID (seg->stop) &&
861 next_time > seg->stop + 5 * GST_SECOND) {
862 GST_DEBUG_OBJECT (src, "end of TIME segment");
866 return GST_DVD_READ_OK;
871 GST_INFO_OBJECT (src, "Reached end-of-segment/stream - EOS");
872 return GST_DVD_READ_EOS;
876 GST_ERROR_OBJECT (src, "Read failed for block %d", src->cur_pack);
877 return GST_DVD_READ_ERROR;
881 GST_ERROR_OBJECT (src, "Read failed for %d blocks at %d",
882 cur_output_size, src->cur_pack);
883 gst_buffer_unref (buf);
884 return GST_DVD_READ_ERROR;
888 /* we don't cache the result on purpose */
890 gst_dvd_read_descrambler_available (void)
896 module = g_module_open ("libdvdcss", 0);
897 if (module != NULL) {
898 res = g_module_symbol (module, "dvdcss_open", &sym);
899 g_module_close (module);
908 gst_dvd_read_src_create (GstPushSrc * pushsrc, GstBuffer ** p_buf)
910 GstDvdReadSrc *src = GST_DVD_READ_SRC (pushsrc);
914 g_return_val_if_fail (src->dvd != NULL, GST_FLOW_ERROR);
916 srcpad = GST_BASE_SRC (src)->srcpad;
918 if (src->need_newsegment) {
919 gst_pad_push_event (srcpad,
920 gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_BYTES,
921 (gint64) src->cur_pack * DVD_VIDEO_LB_LEN, -1, 0));
922 src->need_newsegment = FALSE;
926 gst_dvd_read_src_goto_title (src, src->title, src->angle);
927 gst_dvd_read_src_goto_chapter (src, src->chapter);
929 src->new_seek = FALSE;
930 src->change_cell = TRUE;
933 if (src->title_lang_event_pending) {
934 gst_pad_push_event (srcpad, src->title_lang_event_pending);
935 src->title_lang_event_pending = NULL;
938 if (src->pending_clut_event) {
939 gst_pad_push_event (srcpad, src->pending_clut_event);
940 src->pending_clut_event = NULL;
945 res = gst_dvd_read_src_read (src, src->angle, src->change_cell, p_buf);
946 } while (res == GST_DVD_READ_AGAIN);
949 case GST_DVD_READ_ERROR:{
950 /* FIXME: figure out a way to detect if scrambling is the problem */
951 if (!gst_dvd_read_descrambler_available ()) {
952 GST_ELEMENT_ERROR (src, RESOURCE, READ,
953 (_("Could not read DVD. This may be because the DVD is encrypted "
954 "and a DVD decryption library is not installed.")), (NULL));
956 GST_ELEMENT_ERROR (src, RESOURCE, READ, (_("Could not read DVD.")),
959 return GST_FLOW_ERROR;
961 case GST_DVD_READ_EOS:{
962 return GST_FLOW_UNEXPECTED;
964 case GST_DVD_READ_OK:{
965 src->change_cell = FALSE;
972 g_return_val_if_reached (GST_FLOW_UNEXPECTED);
976 gst_dvd_read_src_set_property (GObject * object, guint prop_id,
977 const GValue * value, GParamSpec * pspec)
979 GstDvdReadSrc *src = GST_DVD_READ_SRC (object);
982 GST_OBJECT_LOCK (src);
983 started = GST_OBJECT_FLAG_IS_SET (src, GST_BASE_SRC_STARTED);
988 g_warning ("%s: property '%s' needs to be set before the device is "
989 "opened", GST_ELEMENT_NAME (src), pspec->name);
993 g_free (src->location);
994 /* clear the filename if we get a NULL (is that possible?) */
995 if (g_value_get_string (value) == NULL) {
996 src->location = g_strdup ("/dev/dvd");
998 src->location = g_strdup (g_value_get_string (value));
1003 src->uri_title = g_value_get_int (value);
1005 src->title = src->uri_title - 1;
1006 src->new_seek = TRUE;
1010 src->uri_chapter = g_value_get_int (value);
1012 src->chapter = src->uri_chapter - 1;
1013 src->new_seek = TRUE;
1017 src->uri_angle = g_value_get_int (value);
1019 src->angle = src->uri_angle - 1;
1023 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1027 GST_OBJECT_UNLOCK (src);
1031 gst_dvd_read_src_get_property (GObject * object, guint prop_id, GValue * value,
1034 GstDvdReadSrc *src = GST_DVD_READ_SRC (object);
1036 GST_OBJECT_LOCK (src);
1040 g_value_set_string (value, src->location);
1043 g_value_set_int (value, src->uri_title);
1046 g_value_set_int (value, src->uri_chapter);
1049 g_value_set_int (value, src->uri_angle);
1052 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1056 GST_OBJECT_UNLOCK (src);
1060 gst_dvd_read_src_get_size (GstDvdReadSrc * src, gint64 * size)
1062 gboolean ret = FALSE;
1064 if (src->dvd_title) {
1067 blocks = DVDFileSize (src->dvd_title);
1069 *size = (gint64) blocks *DVD_VIDEO_LB_LEN;
1073 GST_WARNING_OBJECT (src, "DVDFileSize(%p) failed!", src->dvd_title);
1080 /*** Querying and seeking ***/
1083 gst_dvd_read_src_handle_seek_event (GstDvdReadSrc * src, GstEvent * event)
1086 GstSeekType cur_type, end_type;
1087 gint64 new_off, total;
1093 gst_event_parse_seek (event, &rate, &format, &flags, &cur_type, &new_off,
1097 GST_DEBUG_OBJECT (src, "cannot do backwards playback yet");
1101 if (end_type != GST_SEEK_TYPE_NONE) {
1102 if ((format != chapter_format && format != GST_FORMAT_TIME) ||
1103 end_type != GST_SEEK_TYPE_SET) {
1104 GST_DEBUG_OBJECT (src, "end seek type not supported");
1109 if (cur_type != GST_SEEK_TYPE_SET) {
1110 GST_DEBUG_OBJECT (src, "only SEEK_TYPE_SET is supported");
1114 if (format == angle_format) {
1115 GST_OBJECT_LOCK (src);
1116 if (new_off < 0 || new_off >= src->num_angles) {
1117 GST_OBJECT_UNLOCK (src);
1118 GST_DEBUG_OBJECT (src, "invalid angle %d, only %d available",
1119 src->num_angles, src->num_angles);
1122 src->angle = (gint) new_off;
1123 GST_OBJECT_UNLOCK (src);
1124 GST_DEBUG_OBJECT (src, "switched to angle %d", (gint) new_off + 1);
1128 if (format != chapter_format && format != title_format &&
1129 format != GST_FORMAT_BYTES && format != GST_FORMAT_TIME) {
1130 GST_DEBUG_OBJECT (src, "unsupported seek format %d (%s)", format,
1131 gst_format_get_name (format));
1135 if (format == GST_FORMAT_BYTES) {
1136 GST_DEBUG_OBJECT (src, "Requested seek to byte %" G_GUINT64_FORMAT,
1138 } else if (format == GST_FORMAT_TIME) {
1139 GST_DEBUG_OBJECT (src, "Requested seek to time %" GST_TIME_FORMAT,
1140 GST_TIME_ARGS (new_off));
1141 if (gst_dvd_read_src_get_sector_from_time (src, new_off) < 0) {
1142 GST_DEBUG_OBJECT (src, "Can't find sector for requested time");
1147 srcpad = GST_BASE_SRC_PAD (src);
1149 /* check whether the seek looks reasonable (ie within possible range) */
1150 if (format == GST_FORMAT_BYTES) {
1151 GST_OBJECT_LOCK (src);
1152 query_ok = gst_dvd_read_src_get_size (src, &total);
1153 GST_OBJECT_UNLOCK (src);
1155 query_ok = gst_pad_query_duration (srcpad, &format, &total);
1159 GST_DEBUG_OBJECT (src, "Failed to query duration in format %s",
1160 gst_format_get_name (format));
1164 GST_DEBUG_OBJECT (src, "Total %s: %12" G_GINT64_FORMAT,
1165 gst_format_get_name (format), total);
1166 GST_DEBUG_OBJECT (src, "Seek to %s: %12" G_GINT64_FORMAT,
1167 gst_format_get_name (format), new_off);
1169 if (new_off >= total) {
1170 GST_DEBUG_OBJECT (src, "Seek position out of range");
1174 /* set segment to seek format; this allows us to use the do_seek
1175 * virtual function and let the base source handle all the tricky
1176 * stuff for us. We don't use the segment internally anyway */
1177 /* FIXME: can't take the stream lock here - what to do? */
1178 GST_OBJECT_LOCK (src);
1179 GST_BASE_SRC (src)->segment.format = format;
1180 GST_BASE_SRC (src)->segment.start = 0;
1181 GST_BASE_SRC (src)->segment.stop = total;
1182 GST_BASE_SRC (src)->segment.duration = total;
1183 GST_OBJECT_UNLOCK (src);
1185 return GST_BASE_SRC_CLASS (parent_class)->event (GST_BASE_SRC (src), event);
1189 gst_dvd_read_src_do_seek (GstBaseSrc * basesrc, GstSegment * s)
1193 src = GST_DVD_READ_SRC (basesrc);
1195 GST_DEBUG_OBJECT (src, "Seeking to %s: %12" G_GINT64_FORMAT,
1196 gst_format_get_name (s->format), s->last_stop);
1198 if (s->format == sector_format || s->format == GST_FORMAT_BYTES
1199 || s->format == GST_FORMAT_TIME) {
1202 old = src->cur_pack;
1204 if (s->format == sector_format) {
1205 src->cur_pack = s->last_stop;
1206 } else if (s->format == GST_FORMAT_TIME) {
1209 sector = gst_dvd_read_src_get_sector_from_time (src, s->last_stop);
1211 GST_DEBUG_OBJECT (src, "Time %" GST_TIME_FORMAT " => sector %d",
1212 GST_TIME_ARGS (s->last_stop), sector);
1214 /* really shouldn't happen, we've checked this earlier ... */
1215 g_return_val_if_fail (sector >= 0, FALSE);
1217 src->cur_pack = sector;
1220 src->cur_pack = s->last_stop / DVD_VIDEO_LB_LEN;
1221 if (((gint64) src->cur_pack * DVD_VIDEO_LB_LEN) != s->last_stop) {
1222 GST_LOG_OBJECT (src, "rounded down offset %" G_GINT64_FORMAT " => %"
1223 G_GINT64_FORMAT, s->last_stop,
1224 (gint64) src->cur_pack * DVD_VIDEO_LB_LEN);
1228 if (!gst_dvd_read_src_goto_sector (src, src->angle)) {
1229 GST_DEBUG_OBJECT (src, "seek to sector 0x%08x failed", src->cur_pack);
1230 src->cur_pack = old;
1234 GST_LOG_OBJECT (src, "seek to sector 0x%08x ok", src->cur_pack);
1235 } else if (s->format == chapter_format) {
1236 if (!gst_dvd_read_src_goto_chapter (src, (gint) s->last_stop)) {
1237 GST_DEBUG_OBJECT (src, "seek to chapter %d failed",
1238 (gint) s->last_stop + 1);
1241 GST_INFO_OBJECT (src, "seek to chapter %d ok", (gint) s->last_stop + 1);
1242 src->chapter = s->last_stop;
1243 } else if (s->format == title_format) {
1244 if (!gst_dvd_read_src_goto_title (src, (gint) s->last_stop, src->angle) ||
1245 !gst_dvd_read_src_goto_chapter (src, 0)) {
1246 GST_DEBUG_OBJECT (src, "seek to title %d failed", (gint) s->last_stop);
1249 src->title = (gint) s->last_stop;
1251 GST_INFO_OBJECT (src, "seek to title %d ok", src->title + 1);
1253 g_return_val_if_reached (FALSE);
1256 src->need_newsegment = TRUE;
1261 gst_dvd_read_src_src_event (GstBaseSrc * basesrc, GstEvent * event)
1263 GstDvdReadSrc *src = GST_DVD_READ_SRC (basesrc);
1266 GST_LOG_OBJECT (src, "handling %s event", GST_EVENT_TYPE_NAME (event));
1268 switch (GST_EVENT_TYPE (event)) {
1269 case GST_EVENT_SEEK:
1270 res = gst_dvd_read_src_handle_seek_event (src, event);
1273 res = GST_BASE_SRC_CLASS (parent_class)->event (basesrc, event);
1281 gst_dvd_read_src_make_clut_change_event (GstDvdReadSrc * src,
1284 GstStructure *structure;
1288 structure = gst_structure_new ("application/x-gst-dvd",
1289 "event", G_TYPE_STRING, "dvd-spu-clut-change", NULL);
1291 /* Create a separate field for each value in the table. */
1292 for (i = 0; i < 16; i++) {
1293 g_snprintf (name, sizeof (name), "clut%02d", i);
1294 gst_structure_set (structure, name, G_TYPE_INT, (int) clut[i], NULL);
1297 /* Create the DVD event and put the structure into it. */
1298 return gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, structure);
1302 gst_dvd_read_src_convert_timecode (dvd_time_t * time)
1305 const gint64 one_hour = 3600 * GST_SECOND;
1306 const gint64 one_min = 60 * GST_SECOND;
1308 g_return_val_if_fail ((time->hour >> 4) < 0xa
1309 && (time->hour & 0xf) < 0xa, -1);
1310 g_return_val_if_fail ((time->minute >> 4) < 0x7
1311 && (time->minute & 0xf) < 0xa, -1);
1312 g_return_val_if_fail ((time->second >> 4) < 0x7
1313 && (time->second & 0xf) < 0xa, -1);
1315 ret_time = ((time->hour >> 4) * 10 + (time->hour & 0xf)) * one_hour;
1316 ret_time += ((time->minute >> 4) * 10 + (time->minute & 0xf)) * one_min;
1317 ret_time += ((time->second >> 4) * 10 + (time->second & 0xf)) * GST_SECOND;
1323 gst_dvd_read_src_do_duration_query (GstDvdReadSrc * src, GstQuery * query)
1328 gst_query_parse_duration (query, &format, NULL);
1331 case GST_FORMAT_TIME:{
1332 if (src->cur_pgc == NULL)
1334 val = gst_dvd_read_src_convert_timecode (&src->cur_pgc->playback_time);
1339 case GST_FORMAT_BYTES:{
1340 if (!gst_dvd_read_src_get_size (src, &val))
1345 if (format == sector_format) {
1346 val = DVDFileSize (src->dvd_title);
1347 } else if (format == title_format) {
1348 val = src->tt_srpt->nr_of_srpts;
1349 } else if (format == chapter_format) {
1350 val = src->num_chapters;
1351 } else if (format == angle_format) {
1352 val = src->tt_srpt->title[src->title].nr_of_angles;
1354 GST_DEBUG_OBJECT (src, "Don't know how to handle format %d (%s)",
1355 format, gst_format_get_name (format));
1362 GST_LOG_OBJECT (src, "duration = %" G_GINT64_FORMAT " %s", val,
1363 gst_format_get_name (format));
1365 gst_query_set_duration (query, format, val);
1370 gst_dvd_read_src_do_position_query (GstDvdReadSrc * src, GstQuery * query)
1375 gst_query_parse_position (query, &format, NULL);
1378 case GST_FORMAT_BYTES:{
1379 val = (gint64) src->cur_pack * DVD_VIDEO_LB_LEN;
1383 if (format == sector_format) {
1384 val = src->cur_pack;
1385 } else if (format == title_format) {
1387 } else if (format == chapter_format) {
1389 } else if (format == angle_format) {
1392 GST_DEBUG_OBJECT (src, "Don't know how to handle format %d (%s)",
1393 format, gst_format_get_name (format));
1400 GST_LOG_OBJECT (src, "position = %" G_GINT64_FORMAT " %s", val,
1401 gst_format_get_name (format));
1403 gst_query_set_position (query, format, val);
1408 gst_dvd_read_src_do_convert_query (GstDvdReadSrc * src, GstQuery * query)
1410 GstFormat src_format, dest_format;
1411 gboolean ret = FALSE;
1412 gint64 src_val, dest_val = -1;
1414 gst_query_parse_convert (query, &src_format, &src_val, &dest_format, NULL);
1416 if (src_format == dest_format) {
1422 /* Formats to consider: TIME, DEFAULT, BYTES, title, chapter, sector.
1423 * Note: title and chapter are counted as starting from 0 here, just like
1424 * in the context of seek events. Another note: DEFAULT format is undefined */
1426 if (src_format == GST_FORMAT_BYTES) {
1427 src_format = sector_format;
1428 src_val /= DVD_VIDEO_LB_LEN;
1431 if (src_format == sector_format) {
1433 if (dest_format == GST_FORMAT_TIME && src_val < G_MAXUINT) {
1434 dest_val = gst_dvd_read_src_get_time_for_sector (src, (guint) src_val);
1435 ret = (dest_val >= 0);
1436 } else if (dest_format == GST_FORMAT_BYTES) {
1437 dest_val = src_val * DVD_VIDEO_LB_LEN;
1442 } else if (src_format == title_format) {
1444 if (dest_format == GST_FORMAT_TIME) {
1445 /* not really true, but we use this to trick the base source into
1446 * handling seeks in title-format for us (the source won't know that
1447 * we changed the title in this case) (changing titles should really
1448 * be done with an interface rather than a seek, but for now we're
1449 * stuck with this mechanism. Fix in 0.11) */
1450 dest_val = (GstClockTime) 0;
1455 } else if (src_format == chapter_format) {
1456 /* CHAPTER => xyz */
1457 if (dest_format == GST_FORMAT_TIME) {
1458 if (src->num_chapters >= 0 && src_val < src->num_chapters) {
1459 dest_val = src->chapter_starts[src_val];
1462 } else if (dest_format == sector_format) {
1466 } else if (src_format == GST_FORMAT_TIME) {
1468 if (dest_format == sector_format || dest_format == GST_FORMAT_BYTES) {
1469 dest_val = gst_dvd_read_src_get_sector_from_time (src, src_val);
1470 ret = (dest_val >= 0);
1471 if (dest_format == GST_FORMAT_BYTES)
1472 dest_val *= DVD_VIDEO_LB_LEN;
1473 } else if (dest_format == chapter_format) {
1474 if (src->chapter_starts != NULL) {
1477 for (i = src->num_chapters - 1; i >= 0; --i) {
1478 if (src->chapter_starts && src->chapter_starts[i] >= src_val) {
1497 gst_query_set_convert (query, src_format, src_val, dest_format, dest_val);
1504 gst_dvd_read_src_src_query (GstBaseSrc * basesrc, GstQuery * query)
1506 GstDvdReadSrc *src = GST_DVD_READ_SRC (basesrc);
1508 gboolean res = TRUE;
1510 GST_LOG_OBJECT (src, "handling %s query",
1511 gst_query_type_get_name (GST_QUERY_TYPE (query)));
1513 GST_OBJECT_LOCK (src);
1514 started = (GST_OBJECT_FLAG_IS_SET (src, GST_BASE_SRC_STARTED));
1515 GST_OBJECT_UNLOCK (src);
1518 GST_DEBUG_OBJECT (src, "query failed: not started");
1522 switch (GST_QUERY_TYPE (query)) {
1523 case GST_QUERY_DURATION:
1524 GST_OBJECT_LOCK (src);
1525 res = gst_dvd_read_src_do_duration_query (src, query);
1526 GST_OBJECT_UNLOCK (src);
1528 case GST_QUERY_POSITION:
1529 GST_OBJECT_LOCK (src);
1530 res = gst_dvd_read_src_do_position_query (src, query);
1531 GST_OBJECT_UNLOCK (src);
1533 case GST_QUERY_CONVERT:
1534 GST_OBJECT_LOCK (src);
1535 res = gst_dvd_read_src_do_convert_query (src, query);
1536 GST_OBJECT_UNLOCK (src);
1539 res = GST_BASE_SRC_CLASS (parent_class)->query (basesrc, query);
1547 gst_dvd_read_src_goto_sector (GstDvdReadSrc * src, int angle)
1549 gint seek_to = src->cur_pack;
1550 gint chapter, sectors, next, cur, i;
1552 /* retrieve position */
1554 for (i = 0; i < src->num_chapters; i++) {
1557 cur_title_get_chapter_bounds (src, i, &c1, &c2);
1559 for (next = cur = c1; cur < c2;) {
1562 src->cur_pgc->cell_playback[cur].last_sector -
1563 src->cur_pgc->cell_playback[cur].first_sector;
1564 if (src->cur_pack + sectors > seek_to) {
1568 src->cur_pack += sectors;
1571 if (src->cur_pgc->cell_playback[cur].block_type == BLOCK_TYPE_ANGLE_BLOCK)
1573 next = gst_dvd_read_src_get_next_cell (src, src->cur_pgc, cur);
1577 GST_DEBUG_OBJECT (src, "Seek to sector %u failed", seek_to);
1583 /* so chapter $chapter and cell $cur contain our sector
1584 * of interest. Let's go there! */
1585 GST_INFO_OBJECT (src, "Seek succeeded, going to chapter %u, cell %u",
1588 gst_dvd_read_src_goto_chapter (src, chapter);
1589 src->cur_cell = cur;
1590 src->next_cell = next;
1591 src->new_cell = FALSE;
1592 src->cur_pack = seek_to;
1599 /*** URI interface ***/
1602 gst_dvd_read_src_uri_get_type (void)
1608 gst_dvd_read_src_uri_get_protocols (void)
1610 static gchar *protocols[] = { (gchar *) "dvd", NULL };
1615 static const gchar *
1616 gst_dvd_read_src_uri_get_uri (GstURIHandler * handler)
1618 GstDvdReadSrc *src = GST_DVD_READ_SRC (handler);
1620 GST_OBJECT_LOCK (src);
1622 g_free (src->last_uri);
1623 src->last_uri = g_strdup_printf ("dvd://%d,%d,%d", src->uri_title,
1624 src->uri_chapter, src->uri_angle);
1626 GST_OBJECT_UNLOCK (src);
1628 return src->last_uri;
1632 gst_dvd_read_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
1634 GstDvdReadSrc *src = GST_DVD_READ_SRC (handler);
1638 protocol = gst_uri_get_protocol (uri);
1639 ret = (protocol != NULL && g_str_equal (protocol, "dvd"));
1646 /* parse out the new t/c/a and seek to them */
1648 gchar *location = NULL;
1653 location = gst_uri_get_location (uri);
1658 GST_OBJECT_LOCK (src);
1661 src->uri_chapter = 1;
1664 strcur = strs = g_strsplit (location, ",", 0);
1665 while (strcur && *strcur) {
1668 if (!sscanf (*strcur, "%d", &val))
1672 g_warning ("Invalid value %d in URI '%s'. Must be 1 or greater",
1679 src->uri_title = val;
1682 src->uri_chapter = val;
1685 src->uri_angle = val;
1693 if (pos > 0 && GST_OBJECT_FLAG_IS_SET (src, GST_BASE_SRC_STARTED)) {
1694 src->title = src->uri_title - 1;
1695 src->chapter = src->uri_chapter - 1;
1696 src->angle = src->uri_angle - 1;
1697 src->new_seek = TRUE;
1700 GST_OBJECT_UNLOCK (src);
1710 gst_dvd_read_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
1712 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
1714 iface->get_type = gst_dvd_read_src_uri_get_type;
1715 iface->get_protocols = gst_dvd_read_src_uri_get_protocols;
1716 iface->get_uri = gst_dvd_read_src_uri_get_uri;
1717 iface->set_uri = gst_dvd_read_src_uri_set_uri;
1721 gst_dvd_read_src_do_init (GType dvdreadsrc_type)
1723 static const GInterfaceInfo urihandler_info = {
1724 gst_dvd_read_src_uri_handler_init,
1729 g_type_add_interface_static (dvdreadsrc_type, GST_TYPE_URI_HANDLER,
1732 title_format = gst_format_register ("title", "DVD title");
1733 angle_format = gst_format_register ("angle", "DVD angle");
1734 sector_format = gst_format_register ("sector", "DVD sector");
1735 chapter_format = gst_format_register ("chapter", "DVD chapter");
1739 plugin_init (GstPlugin * plugin)
1741 GST_DEBUG_CATEGORY_INIT (gstgst_dvd_read_src_debug, "dvdreadsrc", 0,
1742 "DVD reader element based on dvdreadsrc");
1745 GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
1747 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1748 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1749 #endif /* ENABLE_NLS */
1751 if (!gst_element_register (plugin, "dvdreadsrc", GST_RANK_SECONDARY,
1752 GST_TYPE_DVD_READ_SRC)) {
1759 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1762 "Access a DVD with dvdread",
1763 plugin_init, VERSION, "GPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);