本文整理汇总了C++中GST_BUFFER_OFFSET_END函数的典型用法代码示例。如果您正苦于以下问题:C++ GST_BUFFER_OFFSET_END函数的具体用法?C++ GST_BUFFER_OFFSET_END怎么用?C++ GST_BUFFER_OFFSET_END使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GST_BUFFER_OFFSET_END函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gst_ogg_avi_parse_push_packet
static GstFlowReturn
gst_ogg_avi_parse_push_packet (GstOggAviParse * ogg, ogg_packet * packet)
{
GstBuffer *buffer;
GstFlowReturn result;
/* allocate space for header and body */
buffer = gst_buffer_new_and_alloc (packet->bytes);
memcpy (GST_BUFFER_DATA (buffer), packet->packet, packet->bytes);
GST_LOG_OBJECT (ogg, "created buffer %p from page", buffer);
GST_BUFFER_OFFSET_END (buffer) = packet->granulepos;
if (ogg->discont) {
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
ogg->discont = FALSE;
}
result = gst_pad_push (ogg->srcpad, buffer);
return result;
}
示例2: gst_identity_update_last_message_for_buffer
static void
gst_identity_update_last_message_for_buffer (GstIdentity * identity,
const gchar * action, GstBuffer * buf)
{
gchar ts_str[64], dur_str[64];
GST_OBJECT_LOCK (identity);
g_free (identity->last_message);
identity->last_message = g_strdup_printf ("%s ******* (%s:%s)i "
"(%u bytes, timestamp: %s, duration: %s, offset: %" G_GINT64_FORMAT ", "
"offset_end: % " G_GINT64_FORMAT ", flags: %d) %p", action,
GST_DEBUG_PAD_NAME (GST_BASE_TRANSFORM_CAST (identity)->sinkpad),
GST_BUFFER_SIZE (buf),
print_pretty_time (ts_str, sizeof (ts_str), GST_BUFFER_TIMESTAMP (buf)),
print_pretty_time (dur_str, sizeof (dur_str), GST_BUFFER_DURATION (buf)),
GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf),
GST_BUFFER_FLAGS (buf), buf);
GST_OBJECT_UNLOCK (identity);
gst_identity_notify_last_message (identity);
}
示例3: gst_kate_parse_push_buffer
static GstFlowReturn
gst_kate_parse_push_buffer (GstKateParse * parse, GstBuffer * buf,
gint64 granulepos)
{
GST_LOG_OBJECT (parse, "granulepos %16" G_GINT64_MODIFIER "x", granulepos);
if (granulepos < 0) {
/* packets coming not from Ogg won't have a granpos in the offset end,
so we have to synthesize one here - only problem is we don't know
the backlink - pretend there's none for now */
GST_INFO_OBJECT (parse, "No granulepos on buffer, synthesizing one");
granulepos =
kate_duration_granule (&parse->ki,
GST_BUFFER_TIMESTAMP (buf) /
(double) GST_SECOND) << kate_granule_shift (&parse->ki);
}
GST_BUFFER_OFFSET (buf) =
kate_granule_time (&parse->ki, granulepos) * GST_SECOND;
GST_BUFFER_OFFSET_END (buf) = granulepos;
GST_BUFFER_TIMESTAMP (buf) = GST_BUFFER_OFFSET (buf);
gst_buffer_set_caps (buf, GST_PAD_CAPS (parse->srcpad));
return gst_pad_push (parse->srcpad, buf);
}
示例4: gst_rtp_dtmf_depay_process
//.........这里部分代码省略.........
/* clip to whole units of unit_time */
if (rtpdtmfdepay->unit_time) {
guint unit_time_clock =
(rtpdtmfdepay->unit_time * depayload->clock_rate) / 1000;
if (dtmf_payload.duration % unit_time_clock) {
/* Make sure we don't overflow the duration */
if (dtmf_payload.duration < G_MAXUINT16 - unit_time_clock)
dtmf_payload.duration += unit_time_clock -
(dtmf_payload.duration % unit_time_clock);
else
dtmf_payload.duration -= dtmf_payload.duration % unit_time_clock;
}
}
/* clip to max duration */
if (rtpdtmfdepay->max_duration) {
guint max_duration_clock =
(rtpdtmfdepay->max_duration * depayload->clock_rate) / 1000;
if (max_duration_clock < G_MAXUINT16 &&
dtmf_payload.duration > max_duration_clock)
dtmf_payload.duration = max_duration_clock;
}
GST_DEBUG_OBJECT (depayload, "Received new RTP DTMF packet : "
"marker=%d - timestamp=%u - event=%d - duration=%d",
marker, timestamp, dtmf_payload.event, dtmf_payload.duration);
GST_DEBUG_OBJECT (depayload,
"Previous information : timestamp=%u - duration=%d",
rtpdtmfdepay->previous_ts, rtpdtmfdepay->previous_duration);
/* First packet */
if (marker || rtpdtmfdepay->previous_ts != timestamp) {
rtpdtmfdepay->sample = 0;
rtpdtmfdepay->previous_ts = timestamp;
rtpdtmfdepay->previous_duration = dtmf_payload.duration;
rtpdtmfdepay->first_gst_ts = GST_BUFFER_TIMESTAMP (buf);
structure = gst_structure_new ("dtmf-event",
"number", G_TYPE_INT, dtmf_payload.event,
"volume", G_TYPE_INT, dtmf_payload.volume,
"type", G_TYPE_INT, 1, "method", G_TYPE_INT, 1, NULL);
if (structure) {
dtmf_message =
gst_message_new_element (GST_OBJECT (depayload), structure);
if (dtmf_message) {
if (!gst_element_post_message (GST_ELEMENT (depayload), dtmf_message)) {
GST_ERROR_OBJECT (depayload,
"Unable to send dtmf-event message to bus");
}
} else {
GST_ERROR_OBJECT (depayload, "Unable to create dtmf-event message");
}
} else {
GST_ERROR_OBJECT (depayload, "Unable to create dtmf-event structure");
}
} else {
guint16 duration = dtmf_payload.duration;
dtmf_payload.duration -= rtpdtmfdepay->previous_duration;
/* If late buffer, ignore */
if (duration > rtpdtmfdepay->previous_duration)
rtpdtmfdepay->previous_duration = duration;
}
GST_DEBUG_OBJECT (depayload, "new previous duration : %d - new duration : %d"
" - diff : %d - clock rate : %d - timestamp : %llu",
rtpdtmfdepay->previous_duration, dtmf_payload.duration,
(rtpdtmfdepay->previous_duration - dtmf_payload.duration),
depayload->clock_rate, GST_BUFFER_TIMESTAMP (buf));
/* If late or duplicate packet (like the redundant end packet). Ignore */
if (dtmf_payload.duration > 0) {
outbuf = gst_buffer_new ();
gst_dtmf_src_generate_tone (rtpdtmfdepay, dtmf_payload, outbuf);
GST_BUFFER_TIMESTAMP (outbuf) = rtpdtmfdepay->first_gst_ts +
(rtpdtmfdepay->previous_duration - dtmf_payload.duration) *
GST_SECOND / depayload->clock_rate;
GST_BUFFER_OFFSET (outbuf) =
(rtpdtmfdepay->previous_duration - dtmf_payload.duration) *
GST_SECOND / depayload->clock_rate;
GST_BUFFER_OFFSET_END (outbuf) = rtpdtmfdepay->previous_duration *
GST_SECOND / depayload->clock_rate;
GST_DEBUG_OBJECT (depayload, "timestamp : %llu - time %" GST_TIME_FORMAT,
GST_BUFFER_TIMESTAMP (buf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
}
return outbuf;
bad_packet:
GST_ELEMENT_WARNING (rtpdtmfdepay, STREAM, DECODE,
("Packet did not validate"), (NULL));
return NULL;
}
示例5: send_buffers_before
static GstFlowReturn
send_buffers_before(AudioTrim *filter, gint64 before)
{
GstFlowReturn ret = GST_FLOW_OK;
GList *b = filter->buffers;
while(b) {
GstBuffer *buf = b->data;
b->data = NULL;
if ((gint64)GST_BUFFER_OFFSET(buf) >= before) {
gst_buffer_unref(buf);
} else {
if ((gint64)GST_BUFFER_OFFSET_END(buf) > before) {
GstBuffer *head = buffer_head(filter, buf, before);
gst_buffer_unref(buf);
buf = head;
}
ret = gst_pad_push(filter->srcpad, buf);
if (ret != GST_FLOW_OK) break;
}
b = g_list_next(b);
}
release_buffers(filter);
return ret;
}
示例6: send_buffers_after
static GstFlowReturn
send_buffers_after(AudioTrim *filter, gint64 after)
{
GstFlowReturn ret = GST_FLOW_OK;
GList *b = filter->buffers;
while(b) {
GstBuffer *buf = b->data;
b->data = NULL;
if ((gint64)GST_BUFFER_OFFSET_END(buf) <= after) {
gst_buffer_unref(buf);
} else {
if ((gint64)GST_BUFFER_OFFSET(buf) < after) {
GstBuffer *tail = buffer_tail(filter, buf, after);
gst_buffer_unref(buf);
buf = tail;
}
ret = gst_pad_push(filter->srcpad, buf);
if (ret != GST_FLOW_OK) break;
}
b = g_list_next(b);
}
release_buffers(filter);
return ret;
}
示例7: getTimeStamp
void ofxGstRTPServer::newOscMsg(ofxOscMessage & msg, GstClockTime timestamp){
if(!appSrcOsc) return;
GstClockTime now = timestamp;
if(!oscAutoTimestamp){
if(now==GST_CLOCK_TIME_NONE){
now = getTimeStamp();
}
if(firstOscFrame){
prevTimestampOsc = now;
firstOscFrame = false;
return;
}
}
PooledOscPacket * pooledOscPkg = oscPacketPool.newBuffer();
appendMessage(msg,pooledOscPkg->packet);
GstBuffer * buffer = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY,(void*)pooledOscPkg->compressedData(),pooledOscPkg->compressedSize(),0,pooledOscPkg->compressedSize(),pooledOscPkg,(GDestroyNotify)&ofxOscPacketPool::relaseBuffer);
if(!oscAutoTimestamp){
GST_BUFFER_OFFSET(buffer) = numFrameOsc++;
GST_BUFFER_OFFSET_END(buffer) = numFrameOsc;
GST_BUFFER_DTS (buffer) = now;
GST_BUFFER_PTS (buffer) = now;
GST_BUFFER_DURATION(buffer) = now-prevTimestampOsc;
prevTimestampOsc = now;
}
GstFlowReturn flow_return = gst_app_src_push_buffer((GstAppSrc*)appSrcOsc, buffer);
if (flow_return != GST_FLOW_OK) {
ofLogError() << "error pushing osc buffer: flow_return was " << flow_return;
}
}
示例8: gst_audio_fx_base_fir_filter_push_residue
void
gst_audio_fx_base_fir_filter_push_residue (GstAudioFXBaseFIRFilter * self)
{
GstBuffer *outbuf;
GstFlowReturn res;
gint rate = GST_AUDIO_FILTER_RATE (self);
gint channels = GST_AUDIO_FILTER_CHANNELS (self);
gint bps = GST_AUDIO_FILTER_BPS (self);
gint outsize, outsamples;
GstMapInfo map;
guint8 *in, *out;
if (channels == 0 || rate == 0 || self->nsamples_in == 0) {
self->buffer_fill = 0;
g_free (self->buffer);
self->buffer = NULL;
return;
}
/* Calculate the number of samples and their memory size that
* should be pushed from the residue */
outsamples = self->nsamples_in - (self->nsamples_out - self->latency);
if (outsamples <= 0) {
self->buffer_fill = 0;
g_free (self->buffer);
self->buffer = NULL;
return;
}
outsize = outsamples * channels * bps;
if (!self->fft || self->low_latency) {
gint64 diffsize, diffsamples;
/* Process the difference between latency and residue length samples
* to start at the actual data instead of starting at the zeros before
* when we only got one buffer smaller than latency */
diffsamples =
((gint64) self->latency) - ((gint64) self->buffer_fill) / channels;
if (diffsamples > 0) {
diffsize = diffsamples * channels * bps;
in = g_new0 (guint8, diffsize);
out = g_new0 (guint8, diffsize);
self->nsamples_out += self->process (self, in, out, diffsamples);
g_free (in);
g_free (out);
}
outbuf = gst_buffer_new_and_alloc (outsize);
/* Convolve the residue with zeros to get the actual remaining data */
in = g_new0 (guint8, outsize);
gst_buffer_map (outbuf, &map, GST_MAP_READWRITE);
self->nsamples_out += self->process (self, in, map.data, outsamples);
gst_buffer_unmap (outbuf, &map);
g_free (in);
} else {
guint gensamples = 0;
outbuf = gst_buffer_new_and_alloc (outsize);
gst_buffer_map (outbuf, &map, GST_MAP_READWRITE);
while (gensamples < outsamples) {
guint step_insamples = self->block_length - self->buffer_fill;
guint8 *zeroes = g_new0 (guint8, step_insamples * channels * bps);
guint8 *out = g_new (guint8, self->block_length * channels * bps);
guint step_gensamples;
step_gensamples = self->process (self, zeroes, out, step_insamples);
g_free (zeroes);
memcpy (map.data + gensamples * bps, out, MIN (step_gensamples,
outsamples - gensamples) * bps);
gensamples += MIN (step_gensamples, outsamples - gensamples);
g_free (out);
}
self->nsamples_out += gensamples;
gst_buffer_unmap (outbuf, &map);
}
/* Set timestamp, offset, etc from the values we
* saved when processing the regular buffers */
if (GST_CLOCK_TIME_IS_VALID (self->start_ts))
GST_BUFFER_TIMESTAMP (outbuf) = self->start_ts;
else
GST_BUFFER_TIMESTAMP (outbuf) = 0;
GST_BUFFER_TIMESTAMP (outbuf) +=
gst_util_uint64_scale_int (self->nsamples_out - outsamples -
self->latency, GST_SECOND, rate);
GST_BUFFER_DURATION (outbuf) =
gst_util_uint64_scale_int (outsamples, GST_SECOND, rate);
if (self->start_off != GST_BUFFER_OFFSET_NONE) {
GST_BUFFER_OFFSET (outbuf) =
self->start_off + self->nsamples_out - outsamples - self->latency;
GST_BUFFER_OFFSET_END (outbuf) = GST_BUFFER_OFFSET (outbuf) + outsamples;
}
//.........这里部分代码省略.........
示例9: gst_aiff_parse_stream_data
static GstFlowReturn
gst_aiff_parse_stream_data (GstAiffParse * aiff)
{
GstBuffer *buf = NULL;
GstFlowReturn res = GST_FLOW_OK;
guint64 desired, obtained;
GstClockTime timestamp, next_timestamp, duration;
guint64 pos, nextpos;
iterate_adapter:
GST_LOG_OBJECT (aiff,
"offset: %" G_GINT64_FORMAT " , end: %" G_GINT64_FORMAT " , dataleft: %"
G_GINT64_FORMAT, aiff->offset, aiff->end_offset, aiff->dataleft);
/* Get the next n bytes and output them */
if (aiff->dataleft == 0 || aiff->dataleft < aiff->bytes_per_sample)
goto found_eos;
/* scale the amount of data by the segment rate so we get equal
* amounts of data regardless of the playback rate */
desired =
MIN (gst_guint64_to_gdouble (aiff->dataleft),
MAX_BUFFER_SIZE * aiff->segment.abs_rate);
if (desired >= aiff->bytes_per_sample && aiff->bytes_per_sample > 0)
desired -= (desired % aiff->bytes_per_sample);
GST_LOG_OBJECT (aiff, "Fetching %" G_GINT64_FORMAT " bytes of data "
"from the sinkpad", desired);
if (aiff->streaming) {
guint avail = gst_adapter_available (aiff->adapter);
if (avail < desired) {
GST_LOG_OBJECT (aiff, "Got only %d bytes of data from the sinkpad",
avail);
return GST_FLOW_OK;
}
buf = gst_adapter_take_buffer (aiff->adapter, desired);
} else {
if ((res = gst_pad_pull_range (aiff->sinkpad, aiff->offset,
desired, &buf)) != GST_FLOW_OK)
goto pull_error;
}
/* If we have a pending close/start segment, send it now. */
if (G_UNLIKELY (aiff->close_segment != NULL)) {
gst_pad_push_event (aiff->srcpad, aiff->close_segment);
aiff->close_segment = NULL;
}
if (G_UNLIKELY (aiff->start_segment != NULL)) {
gst_pad_push_event (aiff->srcpad, aiff->start_segment);
aiff->start_segment = NULL;
}
obtained = GST_BUFFER_SIZE (buf);
/* our positions in bytes */
pos = aiff->offset - aiff->datastart;
nextpos = pos + obtained;
/* update offsets, does not overflow. */
GST_BUFFER_OFFSET (buf) = pos / aiff->bytes_per_sample;
GST_BUFFER_OFFSET_END (buf) = nextpos / aiff->bytes_per_sample;
if (aiff->bps > 0) {
/* and timestamps if we have a bitrate, be careful for overflows */
timestamp = uint64_ceiling_scale (pos, GST_SECOND, (guint64) aiff->bps);
next_timestamp =
uint64_ceiling_scale (nextpos, GST_SECOND, (guint64) aiff->bps);
duration = next_timestamp - timestamp;
/* update current running segment position */
gst_segment_set_last_stop (&aiff->segment, GST_FORMAT_TIME, next_timestamp);
} else {
/* no bitrate, all we know is that the first sample has timestamp 0, all
* other positions and durations have unknown timestamp. */
if (pos == 0)
timestamp = 0;
else
timestamp = GST_CLOCK_TIME_NONE;
duration = GST_CLOCK_TIME_NONE;
/* update current running segment position with byte offset */
gst_segment_set_last_stop (&aiff->segment, GST_FORMAT_BYTES, nextpos);
}
if (aiff->discont) {
GST_DEBUG_OBJECT (aiff, "marking DISCONT");
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
aiff->discont = FALSE;
}
GST_BUFFER_TIMESTAMP (buf) = timestamp;
GST_BUFFER_DURATION (buf) = duration;
gst_buffer_set_caps (buf, aiff->caps);
GST_LOG_OBJECT (aiff,
"Got buffer. timestamp:%" GST_TIME_FORMAT " , duration:%" GST_TIME_FORMAT
", size:%u", GST_TIME_ARGS (timestamp), GST_TIME_ARGS (duration),
GST_BUFFER_SIZE (buf));
//.........这里部分代码省略.........
示例10: gst_split_file_src_create
static GstFlowReturn
gst_split_file_src_create (GstBaseSrc * basesrc, guint64 offset, guint size,
GstBuffer ** buffer)
{
GstSplitFileSrc *src = GST_SPLIT_FILE_SRC (basesrc);
GstFilePart cur_part;
GInputStream *stream;
GCancellable *cancel;
GSeekable *seekable;
GstBuffer *buf;
GError *err = NULL;
guint64 read_offset;
guint8 *data;
guint to_read;
cur_part = src->parts[src->cur_part];
if (offset < cur_part.start || offset > cur_part.stop) {
if (!gst_split_file_src_find_part_for_offset (src, offset, &src->cur_part))
return GST_FLOW_UNEXPECTED;
cur_part = src->parts[src->cur_part];
}
GST_LOG_OBJECT (src, "current part: %u (%" G_GUINT64_FORMAT " - "
"%" G_GUINT64_FORMAT ", %s)", src->cur_part, cur_part.start,
cur_part.stop, cur_part.path);
buf = gst_buffer_new_and_alloc (size);
GST_BUFFER_OFFSET (buf) = offset;
data = GST_BUFFER_DATA (buf);
cancel = src->cancellable;
while (size > 0) {
guint64 bytes_to_end_of_part;
gsize read = 0;
/* we want the offset into the file part */
read_offset = offset - cur_part.start;
GST_LOG ("Reading part %03u from offset %" G_GUINT64_FORMAT " (%s)",
src->cur_part, read_offset, cur_part.path);
/* FIXME: only seek when needed (hopefully gio is smart) */
seekable = G_SEEKABLE (cur_part.stream);
if (!g_seekable_seek (seekable, read_offset, G_SEEK_SET, cancel, &err))
goto seek_failed;
GST_LOG_OBJECT (src, "now: %" G_GUINT64_FORMAT, g_seekable_tell (seekable));
bytes_to_end_of_part = (cur_part.stop - cur_part.start) + 1 - read_offset;
to_read = MIN (size, bytes_to_end_of_part);
GST_LOG_OBJECT (src, "reading %u bytes from part %u (bytes to end of "
"part: %u)", to_read, src->cur_part, (guint) bytes_to_end_of_part);
stream = G_INPUT_STREAM (cur_part.stream);
/* NB: we won't try to read beyond EOF */
if (!g_input_stream_read_all (stream, data, to_read, &read, cancel, &err))
goto read_failed;
GST_LOG_OBJECT (src, "read %u bytes", (guint) read);
data += read;
size -= read;
offset += read;
/* are we done? */
if (size == 0)
break;
GST_LOG_OBJECT (src, "%u bytes left to read for this chunk", size);
/* corner case, this should never really happen (assuming basesrc clips
* requests beyond the file size) */
if (read < to_read) {
if (src->cur_part == src->num_parts - 1) {
/* last file part, stop reading and truncate buffer */
GST_BUFFER_SIZE (buf) = offset - GST_BUFFER_OFFSET (buf);
break;
} else {
goto file_part_changed;
}
}
++src->cur_part;
cur_part = src->parts[src->cur_part];
}
GST_BUFFER_OFFSET_END (buf) = offset;
*buffer = buf;
GST_LOG_OBJECT (src, "read %u bytes into buf %p", GST_BUFFER_SIZE (buf), buf);
return GST_FLOW_OK;
/* ERRORS */
seek_failed:
{
//.........这里部分代码省略.........
示例11: gst_identity_transform_ip
static GstFlowReturn
gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
{
GstFlowReturn ret = GST_FLOW_OK;
GstIdentity *identity = GST_IDENTITY (trans);
GstClockTime runtimestamp = G_GINT64_CONSTANT (0);
gsize size;
size = gst_buffer_get_size (buf);
if (identity->check_imperfect_timestamp)
gst_identity_check_imperfect_timestamp (identity, buf);
if (identity->check_imperfect_offset)
gst_identity_check_imperfect_offset (identity, buf);
/* update prev values */
identity->prev_timestamp = GST_BUFFER_TIMESTAMP (buf);
identity->prev_duration = GST_BUFFER_DURATION (buf);
identity->prev_offset_end = GST_BUFFER_OFFSET_END (buf);
identity->prev_offset = GST_BUFFER_OFFSET (buf);
if (identity->error_after >= 0) {
identity->error_after--;
if (identity->error_after == 0)
goto error_after;
}
if (identity->drop_probability > 0.0) {
if ((gfloat) (1.0 * rand () / (RAND_MAX)) < identity->drop_probability)
goto dropped;
}
if (identity->dump) {
GstMapInfo info;
gst_buffer_map (buf, &info, GST_MAP_READ);
gst_util_dump_mem (info.data, info.size);
gst_buffer_unmap (buf, &info);
}
if (!identity->silent) {
gst_identity_update_last_message_for_buffer (identity, "chain", buf, size);
}
if (identity->datarate > 0) {
GstClockTime time = gst_util_uint64_scale_int (identity->offset,
GST_SECOND, identity->datarate);
GST_BUFFER_TIMESTAMP (buf) = time;
GST_BUFFER_DURATION (buf) = size * GST_SECOND / identity->datarate;
}
if (identity->signal_handoffs)
g_signal_emit (identity, gst_identity_signals[SIGNAL_HANDOFF], 0, buf);
if (trans->segment.format == GST_FORMAT_TIME)
runtimestamp = gst_segment_to_running_time (&trans->segment,
GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (buf));
if ((identity->sync) && (trans->segment.format == GST_FORMAT_TIME)) {
GstClock *clock;
GST_OBJECT_LOCK (identity);
if ((clock = GST_ELEMENT (identity)->clock)) {
GstClockReturn cret;
GstClockTime timestamp;
timestamp = runtimestamp + GST_ELEMENT (identity)->base_time;
/* save id if we need to unlock */
identity->clock_id = gst_clock_new_single_shot_id (clock, timestamp);
GST_OBJECT_UNLOCK (identity);
cret = gst_clock_id_wait (identity->clock_id, NULL);
GST_OBJECT_LOCK (identity);
if (identity->clock_id) {
gst_clock_id_unref (identity->clock_id);
identity->clock_id = NULL;
}
if (cret == GST_CLOCK_UNSCHEDULED)
ret = GST_FLOW_EOS;
}
GST_OBJECT_UNLOCK (identity);
}
identity->offset += size;
if (identity->sleep_time && ret == GST_FLOW_OK)
g_usleep (identity->sleep_time);
if (identity->single_segment && (trans->segment.format == GST_FORMAT_TIME)
&& (ret == GST_FLOW_OK)) {
GST_BUFFER_TIMESTAMP (buf) = runtimestamp;
GST_BUFFER_OFFSET (buf) = GST_CLOCK_TIME_NONE;
GST_BUFFER_OFFSET_END (buf) = GST_CLOCK_TIME_NONE;
}
return ret;
//.........这里部分代码省略.........
示例12: gst_ks_video_src_timestamp_buffer
static gboolean
gst_ks_video_src_timestamp_buffer (GstKsVideoSrc * self, GstBuffer * buf,
GstClockTime presentation_time)
{
GstKsVideoSrcPrivate *priv = GST_KS_VIDEO_SRC_GET_PRIVATE (self);
GstClockTime duration;
GstClock *clock;
GstClockTime timestamp;
duration = gst_ks_video_device_get_duration (priv->device);
GST_OBJECT_LOCK (self);
clock = GST_ELEMENT_CLOCK (self);
if (clock != NULL) {
gst_object_ref (clock);
timestamp = GST_ELEMENT (self)->base_time;
if (GST_CLOCK_TIME_IS_VALID (presentation_time)) {
if (presentation_time > GST_ELEMENT (self)->base_time)
presentation_time -= GST_ELEMENT (self)->base_time;
else
presentation_time = 0;
}
} else {
timestamp = GST_CLOCK_TIME_NONE;
}
GST_OBJECT_UNLOCK (self);
if (clock != NULL) {
/* The time according to the current clock */
timestamp = gst_clock_get_time (clock) - timestamp;
if (timestamp > duration)
timestamp -= duration;
else
timestamp = 0;
if (GST_CLOCK_TIME_IS_VALID (presentation_time)) {
/*
* We don't use this for anything yet, need to ponder how to deal
* with pins that use an internal clock and timestamp from 0.
*/
GstClockTimeDiff diff = GST_CLOCK_DIFF (presentation_time, timestamp);
GST_DEBUG_OBJECT (self, "diff between gst and driver timestamp: %"
G_GINT64_FORMAT, diff);
}
gst_object_unref (clock);
clock = NULL;
/* Unless it's the first frame, align the current timestamp on a multiple
* of duration since the previous */
if (GST_CLOCK_TIME_IS_VALID (priv->prev_ts)) {
GstClockTime delta;
guint delta_remainder, delta_offset;
/* REVISIT: I've seen this happen with the GstSystemClock on Windows,
* scary... */
if (timestamp < priv->prev_ts) {
GST_INFO_OBJECT (self, "clock is ticking backwards");
return FALSE;
}
/* Round to a duration boundary */
delta = timestamp - priv->prev_ts;
delta_remainder = delta % duration;
if (delta_remainder < duration / 3)
timestamp -= delta_remainder;
else
timestamp += duration - delta_remainder;
/* How many frames are we off then? */
delta = timestamp - priv->prev_ts;
delta_offset = delta / duration;
if (delta_offset == 1) /* perfect */
GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DISCONT);
else if (delta_offset > 1) {
guint lost = delta_offset - 1;
GST_INFO_OBJECT (self, "lost %d frame%s, setting discont flag",
lost, (lost > 1) ? "s" : "");
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
} else if (delta_offset == 0) { /* overproduction, skip this frame */
GST_INFO_OBJECT (self, "skipping frame");
return FALSE;
}
priv->offset += delta_offset;
}
priv->prev_ts = timestamp;
}
GST_BUFFER_OFFSET (buf) = priv->offset;
GST_BUFFER_OFFSET_END (buf) = GST_BUFFER_OFFSET (buf) + 1;
GST_BUFFER_TIMESTAMP (buf) = timestamp;
GST_BUFFER_DURATION (buf) = duration;
return TRUE;
//.........这里部分代码省略.........
示例13: gst_base_video_decoder_finish_frame
//.........这里部分代码省略.........
gst_base_video_decoder_get_field_duration (base_video_decoder,
frame->n_fields);
}
if (GST_CLOCK_TIME_IS_VALID (base_video_decoder->last_timestamp)) {
if (frame->presentation_timestamp < base_video_decoder->last_timestamp) {
GST_WARNING ("decreasing timestamp (%" GST_TIME_FORMAT " < %"
GST_TIME_FORMAT ")", GST_TIME_ARGS (frame->presentation_timestamp),
GST_TIME_ARGS (base_video_decoder->last_timestamp));
}
}
base_video_decoder->last_timestamp = frame->presentation_timestamp;
src_buffer = frame->src_buffer;
GST_BUFFER_FLAG_UNSET (src_buffer, GST_BUFFER_FLAG_DELTA_UNIT);
if (base_video_decoder->state.interlaced) {
#ifndef GST_VIDEO_BUFFER_TFF
#define GST_VIDEO_BUFFER_TFF (GST_MINI_OBJECT_FLAG_LAST << 5)
#endif
#ifndef GST_VIDEO_BUFFER_RFF
#define GST_VIDEO_BUFFER_RFF (GST_MINI_OBJECT_FLAG_LAST << 6)
#endif
#ifndef GST_VIDEO_BUFFER_ONEFIELD
#define GST_VIDEO_BUFFER_ONEFIELD (GST_MINI_OBJECT_FLAG_LAST << 7)
#endif
if (GST_VIDEO_FRAME_FLAG_IS_SET (frame, GST_VIDEO_FRAME_FLAG_TFF)) {
GST_BUFFER_FLAG_SET (src_buffer, GST_VIDEO_BUFFER_TFF);
} else {
GST_BUFFER_FLAG_UNSET (src_buffer, GST_VIDEO_BUFFER_TFF);
}
GST_BUFFER_FLAG_UNSET (src_buffer, GST_VIDEO_BUFFER_RFF);
GST_BUFFER_FLAG_UNSET (src_buffer, GST_VIDEO_BUFFER_ONEFIELD);
if (frame->n_fields == 3) {
GST_BUFFER_FLAG_SET (src_buffer, GST_VIDEO_BUFFER_RFF);
} else if (frame->n_fields == 1) {
GST_BUFFER_FLAG_SET (src_buffer, GST_VIDEO_BUFFER_ONEFIELD);
}
}
if (base_video_decoder->discont) {
GST_BUFFER_FLAG_UNSET (src_buffer, GST_BUFFER_FLAG_DISCONT);
base_video_decoder->discont = FALSE;
}
GST_BUFFER_TIMESTAMP (src_buffer) = frame->presentation_timestamp;
GST_BUFFER_DURATION (src_buffer) = frame->presentation_duration;
GST_BUFFER_OFFSET (src_buffer) = GST_BUFFER_OFFSET_NONE;
GST_BUFFER_OFFSET_END (src_buffer) = GST_BUFFER_OFFSET_NONE;
GST_DEBUG ("pushing frame %" GST_TIME_FORMAT,
GST_TIME_ARGS (frame->presentation_timestamp));
gst_base_video_decoder_set_src_caps (base_video_decoder);
if (base_video_decoder->sink_clipping) {
gint64 start = GST_BUFFER_TIMESTAMP (src_buffer);
gint64 stop = GST_BUFFER_TIMESTAMP (src_buffer) +
GST_BUFFER_DURATION (src_buffer);
if (gst_segment_clip (&base_video_decoder->segment, GST_FORMAT_TIME,
start, stop, &start, &stop)) {
GST_BUFFER_TIMESTAMP (src_buffer) = start;
GST_BUFFER_DURATION (src_buffer) = stop - start;
GST_DEBUG ("accepting buffer inside segment: %" GST_TIME_FORMAT
" %" GST_TIME_FORMAT
" seg %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT
" time %" GST_TIME_FORMAT,
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (src_buffer)),
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (src_buffer) +
GST_BUFFER_DURATION (src_buffer)),
GST_TIME_ARGS (base_video_decoder->segment.start),
GST_TIME_ARGS (base_video_decoder->segment.stop),
GST_TIME_ARGS (base_video_decoder->segment.time));
} else {
GST_DEBUG ("dropping buffer outside segment: %" GST_TIME_FORMAT
" %" GST_TIME_FORMAT
" seg %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT
" time %" GST_TIME_FORMAT,
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (src_buffer)),
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (src_buffer) +
GST_BUFFER_DURATION (src_buffer)),
GST_TIME_ARGS (base_video_decoder->segment.start),
GST_TIME_ARGS (base_video_decoder->segment.stop),
GST_TIME_ARGS (base_video_decoder->segment.time));
gst_video_frame_unref (frame);
return GST_FLOW_OK;
}
}
gst_buffer_ref (src_buffer);
gst_video_frame_unref (frame);
if (base_video_decoder_class->shape_output)
return base_video_decoder_class->shape_output (base_video_decoder,
src_buffer);
return gst_pad_push (GST_BASE_VIDEO_DECODER_SRC_PAD (base_video_decoder),
src_buffer);
}
示例14: gst_file_src_create_read
static GstFlowReturn
gst_file_src_create_read (GstFileSrc * src, guint64 offset, guint length,
GstBuffer ** buffer)
{
int ret;
GstBuffer *buf;
if (G_UNLIKELY (src->read_position != offset)) {
off_t res;
res = lseek (src->fd, offset, SEEK_SET);
if (G_UNLIKELY (res < 0 || res != offset))
goto seek_failed;
src->read_position = offset;
}
buf = gst_buffer_try_new_and_alloc (length);
if (G_UNLIKELY (buf == NULL && length > 0)) {
GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", length);
return GST_FLOW_ERROR;
}
/* No need to read anything if length is 0 */
if (length > 0) {
GST_LOG_OBJECT (src, "Reading %d bytes at offset 0x%" G_GINT64_MODIFIER "x",
length, offset);
ret = read (src->fd, GST_BUFFER_DATA (buf), length);
if (G_UNLIKELY (ret < 0))
goto could_not_read;
/* seekable regular files should have given us what we expected */
if (G_UNLIKELY ((guint) ret < length && src->seekable))
goto unexpected_eos;
/* other files should eos if they read 0 and more was requested */
if (G_UNLIKELY (ret == 0 && length > 0))
goto eos;
length = ret;
GST_BUFFER_SIZE (buf) = length;
GST_BUFFER_OFFSET (buf) = offset;
GST_BUFFER_OFFSET_END (buf) = offset + length;
src->read_position += length;
}
*buffer = buf;
return GST_FLOW_OK;
/* ERROR */
seek_failed:
{
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), GST_ERROR_SYSTEM);
return GST_FLOW_ERROR;
}
could_not_read:
{
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), GST_ERROR_SYSTEM);
gst_buffer_unref (buf);
return GST_FLOW_ERROR;
}
unexpected_eos:
{
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
("unexpected end of file."));
gst_buffer_unref (buf);
return GST_FLOW_ERROR;
}
eos:
{
GST_DEBUG ("non-regular file hits EOS");
gst_buffer_unref (buf);
return GST_FLOW_UNEXPECTED;
}
}
示例15: gst_fake_src_create
static GstFlowReturn
gst_fake_src_create (GstBaseSrc * basesrc, guint64 offset, guint length,
GstBuffer ** ret)
{
GstFakeSrc *src;
GstBuffer *buf;
GstClockTime time;
gsize size;
src = GST_FAKE_SRC (basesrc);
buf = gst_fake_src_create_buffer (src, &size);
GST_BUFFER_OFFSET (buf) = offset;
if (src->datarate > 0) {
time = (src->bytes_sent * GST_SECOND) / src->datarate;
GST_BUFFER_DURATION (buf) = size * GST_SECOND / src->datarate;
} else if (gst_base_src_is_live (basesrc)) {
GstClock *clock;
clock = gst_element_get_clock (GST_ELEMENT (src));
if (clock) {
time = gst_clock_get_time (clock);
time -= gst_element_get_base_time (GST_ELEMENT (src));
gst_object_unref (clock);
} else {
/* not an error not to have a clock */
time = GST_CLOCK_TIME_NONE;
}
} else {
time = GST_CLOCK_TIME_NONE;
}
GST_BUFFER_DTS (buf) = time;
GST_BUFFER_PTS (buf) = time;
if (!src->silent) {
gchar dts_str[64], pts_str[64], dur_str[64];
gchar *flag_str;
GST_OBJECT_LOCK (src);
g_free (src->last_message);
if (GST_BUFFER_DTS (buf) != GST_CLOCK_TIME_NONE) {
g_snprintf (dts_str, sizeof (dts_str), "%" GST_TIME_FORMAT,
GST_TIME_ARGS (GST_BUFFER_DTS (buf)));
} else {
g_strlcpy (dts_str, "none", sizeof (dts_str));
}
if (GST_BUFFER_PTS (buf) != GST_CLOCK_TIME_NONE) {
g_snprintf (pts_str, sizeof (pts_str), "%" GST_TIME_FORMAT,
GST_TIME_ARGS (GST_BUFFER_PTS (buf)));
} else {
g_strlcpy (pts_str, "none", sizeof (pts_str));
}
if (GST_BUFFER_DURATION (buf) != GST_CLOCK_TIME_NONE) {
g_snprintf (dur_str, sizeof (dur_str), "%" GST_TIME_FORMAT,
GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
} else {
g_strlcpy (dur_str, "none", sizeof (dur_str));
}
flag_str = gst_buffer_get_flags_string (buf);
src->last_message =
g_strdup_printf ("create ******* (%s:%s) (%u bytes, dts: %s, pts:%s"
", duration: %s, offset: %" G_GINT64_FORMAT ", offset_end: %"
G_GINT64_FORMAT ", flags: %08x %s) %p",
GST_DEBUG_PAD_NAME (GST_BASE_SRC_CAST (src)->srcpad), (guint) size,
dts_str, pts_str, dur_str, GST_BUFFER_OFFSET (buf),
GST_BUFFER_OFFSET_END (buf), GST_MINI_OBJECT_CAST (buf)->flags,
flag_str, buf);
g_free (flag_str);
GST_OBJECT_UNLOCK (src);
g_object_notify_by_pspec ((GObject *) src, pspec_last_message);
}
if (src->signal_handoffs) {
GST_LOG_OBJECT (src, "pre handoff emit");
g_signal_emit (src, gst_fake_src_signals[SIGNAL_HANDOFF], 0, buf,
basesrc->srcpad);
GST_LOG_OBJECT (src, "post handoff emit");
}
src->bytes_sent += size;
*ret = buf;
return GST_FLOW_OK;
}