#define ABSDIFF(a,b) ((a) < (b) ? (b) - (a) : (a) - (b))
+#define PACKETIZER_GROUP_LOCK(p) g_mutex_lock(&((p)->group_lock))
+#define PACKETIZER_GROUP_UNLOCK(p) g_mutex_unlock(&((p)->group_lock))
+
static void mpegts_packetizer_dispose (GObject * object);
static void mpegts_packetizer_finalize (GObject * object);
static GstClockTime calculate_skew (MpegTSPCR * pcr, guint64 pcrtime,
static void
mpegts_packetizer_init (MpegTSPacketizer2 * packetizer)
{
+ g_mutex_init (&packetizer->group_lock);
+
packetizer->adapter = gst_adapter_new ();
packetizer->offset = 0;
packetizer->empty = TRUE;
") offset:%" G_GUINT64_FORMAT, packet->pid, packet->pcr,
GST_TIME_ARGS (PCRTIME_TO_GSTTIME (packet->pcr)), packet->offset);
+ PACKETIZER_GROUP_LOCK (packetizer);
if (packetizer->calculate_skew
&& GST_CLOCK_TIME_IS_VALID (packetizer->last_in_time)) {
pcrtable = get_pcr_table (packetizer, packet->pid);
pcrtable = get_pcr_table (packetizer, packet->pid);
record_pcr (packetizer, pcrtable, packet->pcr, packet->offset);
}
+ PACKETIZER_GROUP_UNLOCK (packetizer);
}
#ifndef GST_DISABLE_GST_DEBUG
/* OPCR */
packetizer->last_in_time = GST_CLOCK_TIME_NONE;
/* Close current PCR group */
+ PACKETIZER_GROUP_LOCK (packetizer);
+
for (i = 0; i < MAX_PCR_OBS_CHANNELS; i++) {
if (packetizer->observations[i])
_close_current_group (packetizer->observations[i]);
else
break;
}
+ PACKETIZER_GROUP_UNLOCK (packetizer);
}
void
packetizer->last_in_time = GST_CLOCK_TIME_NONE;
/* Close current PCR group */
+ PACKETIZER_GROUP_LOCK (packetizer);
for (i = 0; i < MAX_PCR_OBS_CHANNELS; i++) {
if (packetizer->observations[i])
_close_current_group (packetizer->observations[i]);
else
break;
}
+ PACKETIZER_GROUP_UNLOCK (packetizer);
if (hard) {
/* For pull mode seeks in tsdemux the observation must be preserved */
if (G_UNLIKELY (offset < packetizer->refoffset))
return GST_CLOCK_TIME_NONE;
+ PACKETIZER_GROUP_LOCK (packetizer);
+
pcrtable = get_pcr_table (packetizer, pid);
if (g_list_length (pcrtable->groups) < 1) {
+ PACKETIZER_GROUP_UNLOCK (packetizer);
GST_WARNING ("Not enough observations to return a duration estimate");
return GST_CLOCK_TIME_NONE;
}
res =
PCRTIME_TO_GSTTIME (gst_util_uint64_scale (offset - packetizer->refoffset,
lastpcr, lastoffset));
+
+ PACKETIZER_GROUP_UNLOCK (packetizer);
+
GST_DEBUG ("Returning timestamp %" GST_TIME_FORMAT " for offset %"
G_GUINT64_FORMAT, GST_TIME_ARGS (res), offset);
GstClockTime pts, guint16 pcr_pid)
{
GstClockTime res = GST_CLOCK_TIME_NONE;
- MpegTSPCR *pcrtable = get_pcr_table (packetizer, pcr_pid);
+ MpegTSPCR *pcrtable;
+
+ PACKETIZER_GROUP_LOCK (packetizer);
+ pcrtable = get_pcr_table (packetizer, pcr_pid);
/* Use clock skew if present */
if (packetizer->calculate_skew
} else
GST_WARNING ("Not enough information to calculate proper timestamp");
+ PACKETIZER_GROUP_UNLOCK (packetizer);
+
GST_DEBUG ("Returning timestamp %" GST_TIME_FORMAT " for pts %"
GST_TIME_FORMAT " pcr_pid:0x%04x", GST_TIME_ARGS (res),
GST_TIME_ARGS (pts), pcr_pid);
if (!packetizer->calculate_offset)
return -1;
+ PACKETIZER_GROUP_LOCK (packetizer);
pcrtable = get_pcr_table (packetizer, pcr_pid);
- if (pcrtable->groups == NULL)
+ if (pcrtable->groups == NULL) {
+ PACKETIZER_GROUP_UNLOCK (packetizer);
return -1;
+ }
querypcr = GSTTIME_TO_PCRTIME (ts);
prevgroup->values[prevgroup->last_value].pcr + prevgroup->pcr_offset;
}
+ PACKETIZER_GROUP_UNLOCK (packetizer);
+
GST_DEBUG ("Using prev PCR %" G_GUINT64_FORMAT " offset %" G_GUINT64_FORMAT,
firstpcr, firstoffset);
GST_DEBUG ("Using last PCR %" G_GUINT64_FORMAT " offset %" G_GUINT64_FORMAT,
{
GST_DEBUG ("Setting reference offset to %" G_GUINT64_FORMAT, refoffset);
+ PACKETIZER_GROUP_LOCK (packetizer);
packetizer->refoffset = refoffset;
+ PACKETIZER_GROUP_UNLOCK (packetizer);
}
void
gboolean apply = FALSE;
/* fast path */
+ PACKETIZER_GROUP_LOCK (packetizer);
pcrtable = get_pcr_table (packetizer, pcr_pid);
- if (pcrtable == NULL || pcrtable->current->group == NULL)
+ if (pcrtable == NULL || pcrtable->current->group == NULL) {
+ PACKETIZER_GROUP_UNLOCK (packetizer);
return;
+ }
pcr_offset = GSTTIME_TO_PCRTIME (offset);
delta = pcr_offset - group->pcr_offset;
if (delta == 0) {
GST_DEBUG ("No shift to apply");
+ PACKETIZER_GROUP_UNLOCK (packetizer);
return;
}
GST_DEBUG ("Shifting groups by %" GST_TIME_FORMAT
tgroup->first_offset,
GST_TIME_ARGS (PCRTIME_TO_GSTTIME (tgroup->pcr_offset)));
}
+ PACKETIZER_GROUP_UNLOCK (packetizer);
}