]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/gst-plugins-ugly0-10.git/blobdiff - ext/dvdread/dvdreadsrc.c
dvdreadsrc: fix sector search for packed titles
[glsdk/gst-plugins-ugly0-10.git] / ext / dvdread / dvdreadsrc.c
index 79eb9801a9b75f1853876212579c3b3200820a39..a53019f9fd41dcdede6b7e670281c04c88423d94 100644 (file)
@@ -49,13 +49,6 @@ enum
   ARG_ANGLE
 };
 
-static GstElementDetails gst_dvd_read_src_details = {
-  "DVD Source",
-  "Source/File/DVD",
-  "Access a DVD title/chapter/angle using libdvdread",
-  "Erik Walthinsen <omega@cse.ogi.edu>",
-};
-
 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
     GST_PAD_SRC,
     GST_PAD_ALWAYS,
@@ -106,7 +99,10 @@ gst_dvd_read_src_base_init (gpointer g_class)
   gst_element_class_add_pad_template (element_class,
       gst_static_pad_template_get (&srctemplate));
 
-  gst_element_class_set_details (element_class, &gst_dvd_read_src_details);
+  gst_element_class_set_details_simple (element_class, "DVD Source",
+      "Source/File/DVD",
+      "Access a DVD title/chapter/angle using libdvdread",
+      "Erik Walthinsen <omega@cse.ogi.edu>");
 }
 
 static void
@@ -164,16 +160,17 @@ gst_dvd_read_src_class_init (GstDvdReadSrcClass * klass)
 
   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DEVICE,
       g_param_spec_string ("device", "Device",
-          "DVD device location", NULL, G_PARAM_READWRITE));
+          "DVD device location", NULL,
+          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TITLE,
       g_param_spec_int ("title", "title", "title",
-          1, 999, 1, G_PARAM_READWRITE));
+          1, 999, 1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CHAPTER,
       g_param_spec_int ("chapter", "chapter", "chapter",
-          1, 999, 1, G_PARAM_READWRITE));
+          1, 999, 1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ANGLE,
       g_param_spec_int ("angle", "angle", "angle",
-          1, 999, 1, G_PARAM_READWRITE));
+          1, 999, 1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_dvd_read_src_start);
   gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_dvd_read_src_stop);
@@ -607,7 +604,7 @@ commands_only_pgc:
     GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
         (_("Could not open DVD title %d. Interactive titles are not supported "
                 "by this element"), title_set_nr),
-        ("Commands-only PGC, not supported, use dvdnavsrc"));
+        ("Commands-only PGC, not supported, use rsndvdbin"));
     return FALSE;
   }
 }
@@ -620,10 +617,10 @@ gst_dvd_read_src_get_next_cell (GstDvdReadSrc * src, pgc_t * pgc, gint cell)
   if (pgc->cell_playback[cell].block_type != BLOCK_TYPE_ANGLE_BLOCK)
     return (cell + 1);
 
-  while (pgc->cell_playback[cell].block_mode == BLOCK_MODE_LAST_CELL)
+  while (pgc->cell_playback[cell].block_mode != BLOCK_MODE_LAST_CELL)
     ++cell;
 
-  return cell + 1;              /* really +1? (tpm) */
+  return cell + 1;
 }
 
 /* Returns true if the pack is a NAV pack */
@@ -685,23 +682,21 @@ gst_dvd_read_src_get_time_for_sector (GstDvdReadSrc * src, guint sector)
 static gint
 gst_dvd_read_src_get_sector_from_time (GstDvdReadSrc * src, GstClockTime ts)
 {
-  gint sector, i, j;
+  gint sector, j;
 
-  if (src->vts_tmapt == NULL || src->vts_tmapt->nr_of_tmaps == 0)
+  if (src->vts_tmapt == NULL || src->vts_tmapt->nr_of_tmaps < src->ttn)
     return -1;
 
   sector = 0;
-  for (i = 0; i < src->vts_tmapt->nr_of_tmaps; ++i) {
-    for (j = 0; j < src->vts_tmapt->tmap[i].nr_of_entries; ++j) {
-      GstClockTime entry_time;
+  for (j = 0; j < src->vts_tmapt->tmap[src->ttn - 1].nr_of_entries; ++j) {
+    GstClockTime entry_time;
 
-      entry_time = src->vts_tmapt->tmap[i].tmu * (j + 1) * GST_SECOND;
-      if (entry_time <= ts) {
-        sector = src->vts_tmapt->tmap[i].map_ent[j] & 0x7fffffff;
-      }
-      if (entry_time >= ts) {
-        return sector;
-      }
+    entry_time = src->vts_tmapt->tmap[src->ttn - 1].tmu * (j + 1) * GST_SECOND;
+    if (entry_time <= ts) {
+      sector = src->vts_tmapt->tmap[src->ttn - 1].map_ent[j] & 0x7fffffff;
+    }
+    if (entry_time >= ts) {
+      return sector;
     }
   }
 
@@ -727,7 +722,7 @@ gst_dvd_read_src_read (GstDvdReadSrc * src, gint angle, gint new_seek,
   GstSegment *seg;
   guint8 oneblock[DVD_VIDEO_LB_LEN];
   dsi_t dsi_pack;
-  guint next_vobu, next_ilvu_start, cur_output_size;
+  guint next_vobu, cur_output_size;
   gint len;
   gint retries;
   gint64 next_time;
@@ -814,7 +809,6 @@ nav_retry:
 
   /* determine where we go next. These values are the ones we
    * mostly care about */
-  next_ilvu_start = src->cur_pack + dsi_pack.sml_agli.data[angle].address;
   cur_output_size = dsi_pack.dsi_gi.vobu_ea + 1;
 
   /* If we're not at the end of this cell, we can determine the next
@@ -889,6 +883,25 @@ block_read_error:
   }
 }
 
+/* we don't cache the result on purpose */
+static gboolean
+gst_dvd_read_descrambler_available (void)
+{
+  GModule *module;
+  gpointer sym;
+  gsize res;
+
+  module = g_module_open ("libdvdcss", 0);
+  if (module != NULL) {
+    res = g_module_symbol (module, "dvdcss_open", &sym);
+    g_module_close (module);
+  } else {
+    res = FALSE;
+  }
+
+  return res;
+}
+
 static GstFlowReturn
 gst_dvd_read_src_create (GstPushSrc * pushsrc, GstBuffer ** p_buf)
 {
@@ -932,7 +945,15 @@ gst_dvd_read_src_create (GstPushSrc * pushsrc, GstBuffer ** p_buf)
 
   switch (res) {
     case GST_DVD_READ_ERROR:{
-      GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), (NULL));
+      /* FIXME: figure out a way to detect if scrambling is the problem */
+      if (!gst_dvd_read_descrambler_available ()) {
+        GST_ELEMENT_ERROR (src, RESOURCE, READ,
+            (_("Could not read DVD. This may be because the DVD is encrypted "
+                    "and a DVD decryption library is not installed.")), (NULL));
+      } else {
+        GST_ELEMENT_ERROR (src, RESOURCE, READ, (_("Could not read DVD.")),
+            (NULL));
+      }
       return GST_FLOW_ERROR;
     }
     case GST_DVD_READ_EOS:{
@@ -1584,7 +1605,7 @@ gst_dvd_read_src_uri_get_type (void)
 static gchar **
 gst_dvd_read_src_uri_get_protocols (void)
 {
-  static gchar *protocols[] = { "dvd", NULL };
+  static gchar *protocols[] = { (gchar *) "dvd", NULL };
 
   return protocols;
 }
@@ -1722,6 +1743,7 @@ plugin_init (GstPlugin * plugin)
   GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
       LOCALEDIR);
   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 #endif /* ENABLE_NLS */
 
   if (!gst_element_register (plugin, "dvdreadsrc", GST_RANK_SECONDARY,