*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#include "_stdint.h"
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "dvdreadsrc.h"
+#include <gmodule.h>
+
#include <gst/gst-i18n-plugin.h>
GST_DEBUG_CATEGORY_STATIC (gstgst_dvd_read_src_debug);
static void gst_dvd_read_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static GstEvent *gst_dvd_read_src_make_clut_change_event (GstDvdReadSrc * src,
- const guint * clut);
+ const guint32 * clut);
static gboolean gst_dvd_read_src_get_size (GstDvdReadSrc * src, gint64 * size);
static gboolean gst_dvd_read_src_do_seek (GstBaseSrc * src, GstSegment * s);
static gint64 gst_dvd_read_src_convert_timecode (dvd_time_t * time);
static void gst_dvd_read_src_uri_handler_init (gpointer g_iface,
gpointer iface_data);
+static gboolean dvdread_element_init (GstPlugin * plugin);
#define gst_dvd_read_src_parent_class parent_class
G_DEFINE_TYPE_WITH_CODE (GstDvdReadSrc, gst_dvd_read_src, GST_TYPE_PUSH_SRC,
G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER,
gst_dvd_read_src_uri_handler_init));
+GST_ELEMENT_REGISTER_DEFINE_CUSTOM (dvdreadsrc, dvdread_element_init);
static void
gst_dvd_read_src_finalize (GObject * object)
static void
gst_dvd_read_src_init (GstDvdReadSrc * src)
{
+ GstCaps *src_caps = gst_static_pad_template_get_caps (&srctemplate);
src->dvd = NULL;
src->vts_file = NULL;
src->vmg_file = NULL;
src->dvd_title = NULL;
src->location = g_strdup ("/dev/dvd");
+ src->first_seek = TRUE;
src->new_seek = TRUE;
src->new_cell = TRUE;
src->change_cell = FALSE;
src->pending_clut_event = NULL;
gst_pad_use_fixed_caps (GST_BASE_SRC_PAD (src));
- gst_pad_set_caps (GST_BASE_SRC_PAD (src),
- gst_static_pad_template_get_caps (&srctemplate));
+ gst_pad_set_caps (GST_BASE_SRC_PAD (src), src_caps);
+ gst_caps_unref (src_caps);
}
static gboolean
g_param_spec_int ("angle", "angle", "angle",
1, 999, 1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
- gst_element_class_add_pad_template (gstelement_class,
- gst_static_pad_template_get (&srctemplate));
+ gst_element_class_add_static_pad_template (gstelement_class, &srctemplate);
- gst_element_class_set_details_simple (gstelement_class, "DVD Source",
+ gst_element_class_set_static_metadata (gstelement_class, "DVD Source",
"Source/File/DVD",
"Access a DVD title/chapter/angle using libdvdread",
"Erik Walthinsen <omega@cse.ogi.edu>");
src->new_seek = FALSE;
src->change_cell = TRUE;
+ src->first_seek = TRUE;
+
return TRUE;
/* ERRORS */
*p_first_cell = pgc->program_map[pgn - 1] - 1;
+ /* last cell is used as a 'up to boundary', not 'up to and including',
+ * i.e. it is the first cell not included in the chapter range */
if (chapter == (src->num_chapters - 1)) {
*p_last_cell = pgc->nr_of_cells;
} else {
pgn_next_ch = src->vts_ptt_srpt->title[src->ttn - 1].ptt[chapter + 1].pgn;
*p_last_cell = pgc->program_map[pgn_next_ch - 1] - 1;
}
+
+ GST_DEBUG_OBJECT (src, "Chapter %d bounds: %d %d (within %d cells)",
+ chapter, *p_first_cell, *p_last_cell, pgc->nr_of_cells);
}
static gboolean
gst_dvd_read_src_goto_chapter (GstDvdReadSrc * src, gint chapter)
{
gint i;
+ const guint8 *palette;
/* make sure the chapter number is valid for this title */
if (chapter < 0 || chapter >= src->num_chapters) {
if (src->pending_clut_event)
gst_event_unref (src->pending_clut_event);
+ /* Work around GCC 9 compiler warning here about taking address of packed
+ * member, which may result in an unaligned pointer access */
+ palette = (const guint8 *) src->cur_pgc->palette;
src->pending_clut_event =
- gst_dvd_read_src_make_clut_change_event (src, src->cur_pgc->palette);
+ gst_dvd_read_src_make_clut_change_event (src, (const guint32 *) palette);
return TRUE;
}
t = g_strdup_printf ("audio-%d-format", i);
gst_structure_set (s, t, G_TYPE_INT, (int) a->audio_format, NULL);
g_free (t);
+ t = g_strdup_printf ("audio-%d-stream", i);
+ gst_structure_set (s, t, G_TYPE_INT, (int) i, NULL);
+ g_free (t);
if (a->lang_type) {
t = g_strdup_printf ("audio-%d-language", i);
/* subtitle */
for (i = 0; i < src->vts_file->vtsi_mat->nr_of_vts_subp_streams; i++) {
const subp_attr_t *u;
+ const video_attr_t *v;
+ gint sid;
/* subpicture stream present? */
if (pgc0 != NULL && (pgc0->subp_control[i] & 0x80000000) == 0)
continue;
u = &src->vts_file->vtsi_mat->vts_subp_attr[i];
+ v = &src->vts_file->vtsi_mat->vts_video_attr;
+
+ sid = i;
+ if (pgc0 != NULL) {
+ if (v->display_aspect_ratio == 0) /* 4:3 */
+ sid = (pgc0->subp_control[i] >> 24) & 0x1f;
+ else if (v->display_aspect_ratio == 3) /* 16:9 */
+ sid = (pgc0->subp_control[i] >> 8) & 0x1f;
+ }
if (u->type) {
- t = g_strdup_printf ("subtitle-%d-language", i);
+ t = g_strdup_printf ("subpicture-%d-language", i);
lang_code[0] = (u->lang_code >> 8) & 0xff;
lang_code[1] = u->lang_code & 0xff;
gst_structure_set (s, t, G_TYPE_STRING, lang_code, NULL);
g_free (t);
+ t = g_strdup_printf ("subpicture-%d-stream", i);
+ gst_structure_set (s, t, G_TYPE_INT, (int) sid, NULL);
+ g_free (t);
+ t = g_strdup_printf ("subpicture-%d-format", i);
+ gst_structure_set (s, t, G_TYPE_INT, (int) 0, NULL);
+ g_free (t);
} else {
lang_code[0] = '\0';
}
GST_INFO_OBJECT (src, "[%02d] Subtitle %02d: lang='%s', type=%d",
- src->title + 1, i, lang_code, u->type);
+ src->title + 1, sid, lang_code, u->type);
}
src->title_lang_event_pending =
for (j = 0; j < src->vts_tmapt->tmap[i].nr_of_entries; j++) {
guint64 time;
- time = src->vts_tmapt->tmap[i].tmu * (j + 1) * GST_SECOND;
+ time = (guint64) src->vts_tmapt->tmap[i].tmu * (j + 1) * GST_SECOND;
GST_LOG_OBJECT (src, "Time: %" GST_TIME_FORMAT " VOBU "
"Sector: 0x%08x %s", GST_TIME_ARGS (time),
src->vts_tmapt->tmap[i].map_ent[j] & 0x7fffffff,
for (i = 0; i < src->vts_tmapt->nr_of_tmaps; ++i) {
for (j = 0; j < src->vts_tmapt->tmap[i].nr_of_entries; ++j) {
if ((src->vts_tmapt->tmap[i].map_ent[j] & 0x7fffffff) == sector)
- return src->vts_tmapt->tmap[i].tmu * (j + 1) * GST_SECOND;
+ return (guint64) src->vts_tmapt->tmap[i].tmu * (j + 1) * GST_SECOND;
}
}
if (src->vts_tmapt == NULL || src->vts_tmapt->nr_of_tmaps < src->ttn)
return -1;
- sector = 0;
+ sector = src->vts_tmapt->tmap[src->ttn - 1].map_ent[0] & 0x7fffffff;
+
for (j = 0; j < src->vts_tmapt->tmap[src->ttn - 1].nr_of_entries; ++j) {
GstClockTime entry_time;
- entry_time = src->vts_tmapt->tmap[src->ttn - 1].tmu * (j + 1) * GST_SECOND;
+ entry_time =
+ (guint64) 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;
}
gint len;
gint retries;
gint64 next_time;
- guint8 *data;
+ GstMapInfo map;
seg = &(GST_BASE_SRC (src)->segment);
g_assert (cur_output_size < 1024);
/* create the buffer (TODO: use buffer pool?) */
- buf = gst_buffer_new_allocate (NULL, cur_output_size * DVD_VIDEO_LB_LEN, 0);
+ buf =
+ gst_buffer_new_allocate (NULL, cur_output_size * DVD_VIDEO_LB_LEN, NULL);
GST_LOG_OBJECT (src, "Going to read %u sectors @ pack %d", cur_output_size,
src->cur_pack);
- data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
+ gst_buffer_map (buf, &map, GST_MAP_WRITE);
/* read in and output cursize packs */
- len = DVDReadBlocks (src->dvd_title, src->cur_pack, cur_output_size, data);
+ len =
+ DVDReadBlocks (src->dvd_title, src->cur_pack, cur_output_size, map.data);
if (len != cur_output_size)
goto block_read_error;
- gst_buffer_unmap (buf, data, cur_output_size * DVD_VIDEO_LB_LEN);
+ gst_buffer_unmap (buf, &map);
+ gst_buffer_resize (buf, 0, cur_output_size * DVD_VIDEO_LB_LEN);
/* GST_BUFFER_OFFSET (buf) = priv->cur_pack * DVD_VIDEO_LB_LEN; */
GST_BUFFER_TIMESTAMP (buf) =
gst_dvd_read_src_get_time_for_sector (src, src->cur_pack);
{
GST_ERROR_OBJECT (src, "Read failed for %d blocks at %d",
cur_output_size, src->cur_pack);
- gst_buffer_unmap (buf, data, 0);
+ gst_buffer_unmap (buf, &map);
gst_buffer_unref (buf);
return GST_DVD_READ_ERROR;
}
return GST_FLOW_ERROR;
}
case GST_DVD_READ_EOS:{
- return GST_FLOW_UNEXPECTED;
+ return GST_FLOW_EOS;
}
case GST_DVD_READ_OK:{
src->change_cell = FALSE;
break;
}
- g_return_val_if_reached (GST_FLOW_UNEXPECTED);
+ g_return_val_if_reached (GST_FLOW_EOS);
}
static void
if (started) {
g_warning ("%s: property '%s' needs to be set before the device is "
"opened", GST_ELEMENT_NAME (src), pspec->name);
- break;;
+ break;
}
g_free (src->location);
if (g_value_get_string (value) == NULL) {
src->location = g_strdup ("/dev/dvd");
} else {
- src->location = g_strdup (g_value_get_string (value));
+ src->location = g_value_dup_string (value);
}
break;
}
gboolean ret = FALSE;
if (src->dvd_title) {
- gsize blocks;
+ gssize blocks;
blocks = DVDFileSize (src->dvd_title);
if (blocks >= 0) {
GST_DEBUG_OBJECT (src, "Seeking to %s: %12" G_GINT64_FORMAT,
gst_format_get_name (s->format), s->position);
+ /* Ignore the first seek to 0, as it breaks starting playback
+ * from another chapter by seeking back to sector 0 */
+ if (src->first_seek && s->format == GST_FORMAT_BYTES && s->start == 0) {
+ src->first_seek = FALSE;
+ return TRUE;
+ }
+
if (s->format == sector_format || s->format == GST_FORMAT_BYTES
|| s->format == GST_FORMAT_TIME) {
guint old;
static GstEvent *
gst_dvd_read_src_make_clut_change_event (GstDvdReadSrc * src,
- const guint * clut)
+ const guint32 * clut)
{
GstStructure *structure;
gchar name[16];
}
/* Create the DVD event and put the structure into it. */
- return gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM, structure);
+ return gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_STICKY, structure);
}
static gint64
gst_dvd_read_src_do_duration_query (GstDvdReadSrc * src, GstQuery * query)
{
GstFormat format;
- gint64 val;
+ gint64 val = 0;
gst_query_parse_duration (query, &format, NULL);
gst_dvd_read_src_src_query (GstBaseSrc * basesrc, GstQuery * query)
{
GstDvdReadSrc *src = GST_DVD_READ_SRC (basesrc);
- gboolean started;
gboolean res = TRUE;
- GST_LOG_OBJECT (src, "handling %s query",
- gst_query_type_get_name (GST_QUERY_TYPE (query)));
-
- GST_OBJECT_LOCK (src);
- started = (GST_OBJECT_FLAG_IS_SET (src, GST_BASE_SRC_FLAG_STARTED));
- GST_OBJECT_UNLOCK (src);
-
- if (!started) {
- GST_DEBUG_OBJECT (src, "query failed: not started");
- return FALSE;
- }
+ GST_LOG_OBJECT (src, "handling %s query", GST_QUERY_TYPE_NAME (query));
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_DURATION:
GST_OBJECT_LOCK (src);
- res = gst_dvd_read_src_do_duration_query (src, query);
+ if (GST_OBJECT_FLAG_IS_SET (src, GST_BASE_SRC_FLAG_STARTED)) {
+ res = gst_dvd_read_src_do_duration_query (src, query);
+ } else {
+ GST_DEBUG_OBJECT (src, "query failed: not started");
+ res = FALSE;
+ }
GST_OBJECT_UNLOCK (src);
break;
case GST_QUERY_POSITION:
GST_OBJECT_LOCK (src);
- res = gst_dvd_read_src_do_position_query (src, query);
+ if (GST_OBJECT_FLAG_IS_SET (src, GST_BASE_SRC_FLAG_STARTED)) {
+ res = gst_dvd_read_src_do_position_query (src, query);
+ } else {
+ GST_DEBUG_OBJECT (src, "query failed: not started");
+ res = FALSE;
+ }
GST_OBJECT_UNLOCK (src);
break;
case GST_QUERY_CONVERT:
GST_OBJECT_LOCK (src);
- res = gst_dvd_read_src_do_convert_query (src, query);
+ if (GST_OBJECT_FLAG_IS_SET (src, GST_BASE_SRC_FLAG_STARTED)) {
+ res = gst_dvd_read_src_do_convert_query (src, query);
+ } else {
+ GST_DEBUG_OBJECT (src, "query failed: not started");
+ res = FALSE;
+ }
GST_OBJECT_UNLOCK (src);
break;
default:
gint first = src->cur_pgc->cell_playback[cur].first_sector;
gint last = src->cur_pgc->cell_playback[cur].last_sector;
GST_DEBUG_OBJECT (src, "Cell %d sector bounds: %d %d", cur, first, last);
- if (seek_to >= first && seek_to <= last) {
- GST_DEBUG_OBJECT (src, "Seek target found in chapter %d", i);
- chapter = i;
- goto done;
- }
cur = next;
if (src->cur_pgc->cell_playback[cur].block_type == BLOCK_TYPE_ANGLE_BLOCK)
cur += angle;
next = gst_dvd_read_src_get_next_cell (src, src->cur_pgc, cur);
+ /* seeking to 0 should end up at first chapter in any case */
+ if ((seek_to >= first && seek_to <= last) || (seek_to == 0 && i == 0)) {
+ GST_DEBUG_OBJECT (src, "Seek target found in chapter %d", i);
+ chapter = i;
+ goto done;
+ }
}
}
}
static gboolean
-plugin_init (GstPlugin * plugin)
+dvdread_element_init (GstPlugin * plugin)
{
GST_DEBUG_CATEGORY_INIT (gstgst_dvd_read_src_debug, "dvdreadsrc", 0,
"DVD reader element based on dvdreadsrc");
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
#endif /* ENABLE_NLS */
+ return gst_element_register (plugin, "dvdreadsrc", GST_RANK_NONE,
+ GST_TYPE_DVD_READ_SRC);
+}
- if (!gst_element_register (plugin, "dvdreadsrc", GST_RANK_SECONDARY,
- GST_TYPE_DVD_READ_SRC)) {
- return FALSE;
- }
-
- return TRUE;
+static gboolean
+plugin_init (GstPlugin * plugin)
+{
+ return GST_ELEMENT_REGISTER (dvdreadsrc, plugin);
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
- "dvdread",
+ dvdread,
"Access a DVD with dvdread",
plugin_init, VERSION, "GPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);