static GstM3U8MediaFile *gst_m3u8_media_file_new (gchar * uri,
gchar * title, GstClockTime duration, guint sequence);
+static void gst_m3u8_init_file_unref (GstM3U8InitFile * self);
static gchar *uri_join (const gchar * uri, const gchar * path);
GstM3U8 *
g_return_if_fail (self != NULL && self->ref_count > 0);
if (g_atomic_int_dec_and_test (&self->ref_count)) {
+ if (self->init_file)
+ gst_m3u8_init_file_unref (self->init_file);
g_free (self->title);
g_free (self->uri);
g_free (self->key);
}
}
+static GstM3U8InitFile *
+gst_m3u8_init_file_new (gchar * uri)
+{
+ GstM3U8InitFile *file;
+
+ file = g_new0 (GstM3U8InitFile, 1);
+ file->uri = uri;
+ file->ref_count = 1;
+
+ return file;
+}
+
+static GstM3U8InitFile *
+gst_m3u8_init_file_ref (GstM3U8InitFile * ifile)
+{
+ g_assert (ifile != NULL && ifile->ref_count > 0);
+
+ g_atomic_int_add (&ifile->ref_count, 1);
+ return ifile;
+}
+
+static void
+gst_m3u8_init_file_unref (GstM3U8InitFile * self)
+{
+ g_return_if_fail (self != NULL && self->ref_count > 0);
+
+ if (g_atomic_int_dec_and_test (&self->ref_count)) {
+ g_free (self->uri);
+ g_free (self);
+ }
+}
+
static gboolean
int_from_string (gchar * ptr, gchar ** endptr, gint * val)
{
gint64 mediasequence;
GList *previous_files = NULL;
gboolean have_mediasequence = FALSE;
+ GstM3U8InitFile *last_init_file = NULL;
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (data != NULL, FALSE);
}
file->discont = discontinuity;
+ if (last_init_file)
+ file->init_file = gst_m3u8_init_file_ref (last_init_file);
duration = 0;
title = NULL;
} else {
goto next_line;
}
+ } else if (g_str_has_prefix (data_ext_x, "MAP:")) {
+ gchar *v, *a, *header_uri = NULL;
+
+ data = data + 11;
+
+ while (data != NULL && parse_attributes (&data, &a, &v)) {
+ if (strcmp (a, "URI") == 0) {
+ header_uri =
+ uri_join (self->base_uri ? self->base_uri : self->uri, v);
+ } else if (strcmp (a, "BYTERANGE") == 0) {
+ if (int64_from_string (v, &v, &size)) {
+ if (*v == '@' && !int64_from_string (v + 1, &v, &offset)) {
+ g_free (header_uri);
+ goto next_line;
+ }
+ } else {
+ g_free (header_uri);
+ goto next_line;
+ }
+ }
+ }
+
+ if (header_uri) {
+ GstM3U8InitFile *init_file;
+ init_file = gst_m3u8_init_file_new (header_uri);
+
+ if (size != -1) {
+ init_file->size = size;
+ if (offset != -1)
+ init_file->offset = offset;
+ else
+ init_file->offset = 0;
+ } else {
+ init_file->size = -1;
+ init_file->offset = 0;
+ }
+ if (last_init_file)
+ gst_m3u8_init_file_unref (last_init_file);
+
+ last_init_file = init_file;
+ }
} else {
GST_LOG ("Ignored line: %s", data);
}
self->files = g_list_reverse (self->files);
+ if (last_init_file)
+ gst_m3u8_init_file_unref (last_init_file);
+
if (previous_files) {
gboolean consistent = TRUE;
typedef struct _GstM3U8 GstM3U8;
typedef struct _GstM3U8MediaFile GstM3U8MediaFile;
+typedef struct _GstM3U8InitFile GstM3U8InitFile;
typedef struct _GstHLSMedia GstHLSMedia;
typedef struct _GstM3U8Client GstM3U8Client;
typedef struct _GstHLSVariantStream GstHLSVariantStream;
guint8 iv[16];
gint64 offset, size;
gint ref_count; /* ATOMIC */
+ GstM3U8InitFile *init_file; /* Media Initialization (hold ref) */
+};
+
+struct _GstM3U8InitFile
+{
+ gchar *uri;
+ gint64 offset, size;
+ guint ref_count; /* ATOMIC */
};
GstM3U8MediaFile * gst_m3u8_media_file_ref (GstM3U8MediaFile * mfile);