2002-03-20 21:45:03 +00:00
|
|
|
/* GStreamer
|
2001-12-22 23:43:34 +00:00
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2009-06-27 20:23:02 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstaudio
|
|
|
|
* @short_description: Support library for audio elements
|
|
|
|
*
|
|
|
|
* This library contains some helper functions for audio elements.
|
|
|
|
*/
|
2001-12-22 23:43:34 +00:00
|
|
|
|
2003-10-31 20:03:29 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2002-04-13 00:46:23 +00:00
|
|
|
#include "audio.h"
|
2008-12-31 11:20:26 +00:00
|
|
|
#include "audio-enumtypes.h"
|
2001-12-22 23:43:34 +00:00
|
|
|
|
2004-01-12 19:35:54 +00:00
|
|
|
#include <gst/gststructure.h>
|
|
|
|
|
2007-02-15 15:17:23 +00:00
|
|
|
/**
|
|
|
|
* gst_audio_frame_byte_size:
|
|
|
|
* @pad: the #GstPad to get the caps from
|
|
|
|
*
|
|
|
|
* Calculate byte size of an audio frame.
|
|
|
|
*
|
2007-02-16 10:19:45 +00:00
|
|
|
* Returns: the byte size, or 0 if there was an error
|
2007-02-15 15:17:23 +00:00
|
|
|
*/
|
2001-12-22 23:43:34 +00:00
|
|
|
int
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_audio_frame_byte_size (GstPad * pad)
|
2001-12-22 23:43:34 +00:00
|
|
|
{
|
2007-02-15 15:17:23 +00:00
|
|
|
/* FIXME: this should be moved closer to the gstreamer core
|
|
|
|
* and be implemented for every mime type IMO
|
|
|
|
*/
|
2001-12-22 23:43:34 +00:00
|
|
|
|
|
|
|
int width = 0;
|
|
|
|
int channels = 0;
|
2003-12-27 19:37:17 +00:00
|
|
|
const GstCaps *caps = NULL;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
2001-12-22 23:43:34 +00:00
|
|
|
|
|
|
|
/* get caps of pad */
|
|
|
|
caps = GST_PAD_CAPS (pad);
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
if (caps == NULL) {
|
2001-12-22 23:43:34 +00:00
|
|
|
/* ERROR: could not get caps of pad */
|
2004-03-14 22:34:34 +00:00
|
|
|
g_warning ("gstaudio: could not get caps of pad %s:%s\n",
|
2006-03-07 12:49:03 +00:00
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
2001-12-22 23:43:34 +00:00
|
|
|
return 0;
|
2002-07-15 11:06:33 +00:00
|
|
|
}
|
2001-12-22 23:43:34 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_structure_get_int (structure, "width", &width);
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_structure_get_int (structure, "channels", &channels);
|
2004-03-14 22:34:34 +00:00
|
|
|
return (width / 8) * channels;
|
2001-12-22 23:43:34 +00:00
|
|
|
}
|
|
|
|
|
2007-02-15 15:17:23 +00:00
|
|
|
/**
|
|
|
|
* gst_audio_frame_length:
|
|
|
|
* @pad: the #GstPad to get the caps from
|
|
|
|
* @buf: the #GstBuffer
|
|
|
|
*
|
|
|
|
* Calculate length of buffer in frames.
|
|
|
|
*
|
|
|
|
* Returns: 0 if there's an error, or the number of frames if everything's ok
|
|
|
|
*/
|
2001-12-22 23:43:34 +00:00
|
|
|
long
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_audio_frame_length (GstPad * pad, GstBuffer * buf)
|
2001-12-22 23:43:34 +00:00
|
|
|
{
|
2007-02-15 15:17:23 +00:00
|
|
|
/* FIXME: this should be moved closer to the gstreamer core
|
|
|
|
* and be implemented for every mime type IMO
|
|
|
|
*/
|
2001-12-22 23:43:34 +00:00
|
|
|
int frame_byte_size = 0;
|
|
|
|
|
|
|
|
frame_byte_size = gst_audio_frame_byte_size (pad);
|
|
|
|
if (frame_byte_size == 0)
|
|
|
|
/* error */
|
|
|
|
return 0;
|
|
|
|
/* FIXME: this function assumes the buffer size to be a whole multiple
|
2004-03-14 22:34:34 +00:00
|
|
|
* of the frame byte size
|
2001-12-22 23:43:34 +00:00
|
|
|
*/
|
|
|
|
return GST_BUFFER_SIZE (buf) / frame_byte_size;
|
|
|
|
}
|
|
|
|
|
2007-02-15 15:17:23 +00:00
|
|
|
/**
|
|
|
|
* gst_audio_duration_from_pad_buffer:
|
|
|
|
* @pad: the #GstPad to get the caps from
|
|
|
|
* @buf: the #GstBuffer
|
|
|
|
*
|
|
|
|
* Calculate length in nanoseconds of audio buffer @buf based on capabilities of
|
|
|
|
* @pad.
|
|
|
|
*
|
2008-08-11 07:16:30 +00:00
|
|
|
* Returns: the length.
|
2007-02-15 15:17:23 +00:00
|
|
|
*/
|
2005-11-21 23:51:45 +00:00
|
|
|
GstClockTime
|
2005-11-21 22:56:33 +00:00
|
|
|
gst_audio_duration_from_pad_buffer (GstPad * pad, GstBuffer * buf)
|
|
|
|
{
|
|
|
|
long bytes = 0;
|
|
|
|
int width = 0;
|
|
|
|
int channels = 0;
|
|
|
|
int rate = 0;
|
|
|
|
|
|
|
|
GstClockTime length;
|
|
|
|
|
|
|
|
const GstCaps *caps = NULL;
|
|
|
|
GstStructure *structure;
|
|
|
|
|
|
|
|
g_assert (GST_IS_BUFFER (buf));
|
|
|
|
/* get caps of pad */
|
|
|
|
caps = GST_PAD_CAPS (pad);
|
|
|
|
if (caps == NULL) {
|
|
|
|
/* ERROR: could not get caps of pad */
|
|
|
|
g_warning ("gstaudio: could not get caps of pad %s:%s\n",
|
2006-03-07 12:49:03 +00:00
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
2005-11-21 22:56:33 +00:00
|
|
|
length = GST_CLOCK_TIME_NONE;
|
|
|
|
} else {
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
bytes = GST_BUFFER_SIZE (buf);
|
|
|
|
gst_structure_get_int (structure, "width", &width);
|
|
|
|
gst_structure_get_int (structure, "channels", &channels);
|
|
|
|
gst_structure_get_int (structure, "rate", &rate);
|
|
|
|
|
|
|
|
g_assert (bytes != 0);
|
|
|
|
g_assert (width != 0);
|
|
|
|
g_assert (channels != 0);
|
|
|
|
g_assert (rate != 0);
|
2005-11-21 23:51:45 +00:00
|
|
|
length = (bytes * 8 * GST_SECOND) / (rate * channels * width);
|
2005-11-21 22:56:33 +00:00
|
|
|
}
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2007-02-15 15:17:23 +00:00
|
|
|
/**
|
|
|
|
* gst_audio_is_buffer_framed:
|
|
|
|
* @pad: the #GstPad to get the caps from
|
|
|
|
* @buf: the #GstBuffer
|
|
|
|
*
|
|
|
|
* Check if the buffer size is a whole multiple of the frame size.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if buffer size is multiple.
|
|
|
|
*/
|
2004-03-14 22:34:34 +00:00
|
|
|
gboolean
|
|
|
|
gst_audio_is_buffer_framed (GstPad * pad, GstBuffer * buf)
|
2001-12-22 23:43:34 +00:00
|
|
|
{
|
|
|
|
if (GST_BUFFER_SIZE (buf) % gst_audio_frame_byte_size (pad) == 0)
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-03-24 20:55:44 +00:00
|
|
|
|
2004-01-12 19:35:54 +00:00
|
|
|
/* _getcaps helper functions
|
|
|
|
* sets structure fields to default for audio type
|
|
|
|
* flag determines which structure fields to set to default
|
|
|
|
* keep these functions in sync with the templates in audio.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* private helper function
|
|
|
|
* sets a list on the structure
|
|
|
|
* pass in structure, fieldname for the list, type of the list values,
|
|
|
|
* number of list values, and each of the values, terminating with NULL
|
|
|
|
*/
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
_gst_audio_structure_set_list (GstStructure * structure,
|
|
|
|
const gchar * fieldname, GType type, int number, ...)
|
2004-01-12 19:35:54 +00:00
|
|
|
{
|
|
|
|
va_list varargs;
|
|
|
|
GValue value = { 0 };
|
|
|
|
GArray *array;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
g_return_if_fail (structure != NULL);
|
|
|
|
|
|
|
|
g_value_init (&value, GST_TYPE_LIST);
|
|
|
|
array = g_value_peek_pointer (&value);
|
|
|
|
|
|
|
|
va_start (varargs, number);
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
for (j = 0; j < number; ++j) {
|
2004-01-12 19:35:54 +00:00
|
|
|
int i;
|
|
|
|
gboolean b;
|
|
|
|
|
|
|
|
GValue list_value = { 0 };
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
switch (type) {
|
2004-01-12 19:35:54 +00:00
|
|
|
case G_TYPE_INT:
|
2004-03-15 19:32:28 +00:00
|
|
|
i = va_arg (varargs, int);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
g_value_init (&list_value, G_TYPE_INT);
|
|
|
|
g_value_set_int (&list_value, i);
|
|
|
|
break;
|
2004-01-12 19:35:54 +00:00
|
|
|
case G_TYPE_BOOLEAN:
|
2004-03-15 19:32:28 +00:00
|
|
|
b = va_arg (varargs, gboolean);
|
|
|
|
g_value_init (&list_value, G_TYPE_BOOLEAN);
|
|
|
|
g_value_set_boolean (&list_value, b);
|
|
|
|
break;
|
2004-03-14 22:34:34 +00:00
|
|
|
default:
|
2004-03-15 19:32:28 +00:00
|
|
|
g_warning
|
|
|
|
("_gst_audio_structure_set_list: LIST of given type not implemented.");
|
2004-01-12 19:35:54 +00:00
|
|
|
}
|
|
|
|
g_array_append_val (array, list_value);
|
|
|
|
|
|
|
|
}
|
|
|
|
gst_structure_set_value (structure, fieldname, &value);
|
|
|
|
va_end (varargs);
|
|
|
|
}
|
|
|
|
|
2007-02-15 15:17:23 +00:00
|
|
|
/**
|
|
|
|
* gst_audio_structure_set_int:
|
|
|
|
* @structure: a #GstStructure
|
|
|
|
* @flag: a set of #GstAudioFieldFlag
|
|
|
|
*
|
|
|
|
* Do not use anymore.
|
2007-10-31 12:47:41 +00:00
|
|
|
*
|
|
|
|
* Deprecated: use gst_structure_set()
|
2007-02-15 15:17:23 +00:00
|
|
|
*/
|
2007-10-31 12:47:41 +00:00
|
|
|
#ifndef GST_REMOVE_DEPRECATED
|
2007-11-01 08:06:13 +00:00
|
|
|
#ifdef GST_DISABLE_DEPRECATED
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GST_AUDIO_FIELD_RATE = (1 << 0),
|
|
|
|
GST_AUDIO_FIELD_CHANNELS = (1 << 1),
|
|
|
|
GST_AUDIO_FIELD_ENDIANNESS = (1 << 2),
|
|
|
|
GST_AUDIO_FIELD_WIDTH = (1 << 3),
|
|
|
|
GST_AUDIO_FIELD_DEPTH = (1 << 4),
|
|
|
|
GST_AUDIO_FIELD_SIGNED = (1 << 5),
|
|
|
|
} GstAudioFieldFlag;
|
2010-03-11 12:32:14 +00:00
|
|
|
void
|
|
|
|
gst_audio_structure_set_int (GstStructure * structure, GstAudioFieldFlag flag);
|
2007-11-01 08:06:13 +00:00
|
|
|
#endif /* GST_DISABLE_DEPRECATED */
|
Correct all relevant warnings found by the sparse semantic code analyzer. This include marking several symbols static...
Original commit message from CVS:
* ext/alsa/gstalsamixertrack.c: (gst_alsa_mixer_track_get_type):
* ext/alsa/gstalsasink.c: (set_hwparams):
* ext/alsa/gstalsasrc.c: (set_hwparams):
* ext/gio/gstgio.c: (gst_gio_uri_handler_get_uri):
* ext/ogg/gstoggmux.h:
* ext/ogg/gstogmparse.c:
* gst-libs/gst/audio/audio.c:
* gst-libs/gst/fft/kiss_fft_f64.c: (kiss_fft_f64_alloc):
* gst-libs/gst/pbutils/missing-plugins.c:
(gst_missing_uri_sink_message_new),
(gst_missing_element_message_new),
(gst_missing_decoder_message_new),
(gst_missing_encoder_message_new):
* gst-libs/gst/rtp/gstbasertppayload.c:
* gst-libs/gst/rtp/gstrtcpbuffer.c:
(gst_rtcp_packet_bye_get_reason):
* gst/audioconvert/gstaudioconvert.c:
* gst/audioresample/gstaudioresample.c:
* gst/ffmpegcolorspace/imgconvert.c:
* gst/playback/test.c: (gen_video_element), (gen_audio_element):
* gst/typefind/gsttypefindfunctions.c:
* gst/videoscale/vs_4tap.c:
* gst/videoscale/vs_4tap.h:
* sys/v4l/gstv4lelement.c:
* sys/v4l/gstv4lsrc.c: (gst_v4lsrc_get_any_caps):
* sys/v4l/v4l_calls.c:
* sys/v4l/v4lsrc_calls.c: (gst_v4lsrc_capture_init),
(gst_v4lsrc_try_capture):
* sys/ximage/ximagesink.c: (gst_ximagesink_check_xshm_calls),
(gst_ximagesink_ximage_new):
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_check_xshm_calls),
(gst_xvimagesink_xvimage_new):
* tests/check/elements/audioconvert.c:
* tests/check/elements/audioresample.c:
(fail_unless_perfect_stream):
* tests/check/elements/audiotestsrc.c: (setup_audiotestsrc):
* tests/check/elements/decodebin.c:
* tests/check/elements/gdpdepay.c: (setup_gdpdepay),
(setup_gdpdepay_streamheader):
* tests/check/elements/gdppay.c: (setup_gdppay), (GST_START_TEST),
(setup_gdppay_streamheader):
* tests/check/elements/gnomevfssink.c: (setup_gnomevfssink):
* tests/check/elements/multifdsink.c: (setup_multifdsink):
* tests/check/elements/textoverlay.c:
* tests/check/elements/videorate.c: (setup_videorate):
* tests/check/elements/videotestsrc.c: (setup_videotestsrc):
* tests/check/elements/volume.c: (setup_volume):
* tests/check/elements/vorbisdec.c: (setup_vorbisdec):
* tests/check/elements/vorbistag.c:
* tests/check/generic/clock-selection.c:
* tests/check/generic/states.c: (setup), (teardown):
* tests/check/libs/cddabasesrc.c:
* tests/check/libs/video.c:
* tests/check/pipelines/gio.c:
* tests/check/pipelines/oggmux.c:
* tests/check/pipelines/simple-launch-lines.c:
(simple_launch_lines_suite):
* tests/check/pipelines/streamheader.c:
* tests/check/pipelines/theoraenc.c:
* tests/check/pipelines/vorbisdec.c:
* tests/check/pipelines/vorbisenc.c:
* tests/examples/seek/scrubby.c:
* tests/examples/seek/seek.c: (query_positions_elems),
(query_positions_pads):
* tests/icles/stress-xoverlay.c: (myclock):
Correct all relevant warnings found by the sparse semantic code
analyzer. This include marking several symbols static, using
NULL instead of 0 for pointers and using "foo (void)" instead
of "foo ()" for declarations.
* win32/common/libgstrtp.def:
Add gst_rtp_buffer_set_extension_data to the symbol definition file.
2008-03-03 06:04:31 +00:00
|
|
|
|
2004-01-12 19:35:54 +00:00
|
|
|
void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_audio_structure_set_int (GstStructure * structure, GstAudioFieldFlag flag)
|
2004-01-12 19:35:54 +00:00
|
|
|
{
|
2007-02-15 15:17:23 +00:00
|
|
|
/* was added here:
|
|
|
|
* http://webcvs.freedesktop.org/gstreamer/gst-plugins-base/gst-libs/gst/audio/audio.c?r1=1.16&r2=1.17
|
|
|
|
* but it is not used
|
|
|
|
*/
|
2004-01-12 19:35:54 +00:00
|
|
|
if (flag & GST_AUDIO_FIELD_RATE)
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_structure_set (structure, "rate", GST_TYPE_INT_RANGE, 1, G_MAXINT,
|
2004-03-15 19:32:28 +00:00
|
|
|
NULL);
|
2004-01-12 19:35:54 +00:00
|
|
|
if (flag & GST_AUDIO_FIELD_CHANNELS)
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_structure_set (structure, "channels", GST_TYPE_INT_RANGE, 1, G_MAXINT,
|
2004-03-15 19:32:28 +00:00
|
|
|
NULL);
|
2004-01-12 19:35:54 +00:00
|
|
|
if (flag & GST_AUDIO_FIELD_ENDIANNESS)
|
2004-03-14 22:34:34 +00:00
|
|
|
_gst_audio_structure_set_list (structure, "endianness", G_TYPE_INT, 2,
|
2004-03-15 19:32:28 +00:00
|
|
|
G_LITTLE_ENDIAN, G_BIG_ENDIAN, NULL);
|
2004-01-12 19:35:54 +00:00
|
|
|
if (flag & GST_AUDIO_FIELD_WIDTH)
|
2004-03-14 22:34:34 +00:00
|
|
|
_gst_audio_structure_set_list (structure, "width", G_TYPE_INT, 3, 8, 16, 32,
|
2004-03-15 19:32:28 +00:00
|
|
|
NULL);
|
2004-01-12 19:35:54 +00:00
|
|
|
if (flag & GST_AUDIO_FIELD_DEPTH)
|
|
|
|
gst_structure_set (structure, "depth", GST_TYPE_INT_RANGE, 1, 32, NULL);
|
|
|
|
if (flag & GST_AUDIO_FIELD_SIGNED)
|
2004-03-14 22:34:34 +00:00
|
|
|
_gst_audio_structure_set_list (structure, "signed", G_TYPE_BOOLEAN, 2, TRUE,
|
2004-03-15 19:32:28 +00:00
|
|
|
FALSE, NULL);
|
2004-01-12 19:35:54 +00:00
|
|
|
}
|
2007-10-31 12:47:41 +00:00
|
|
|
#endif /* GST_REMOVE_DEPRECATED */
|
2007-07-23 18:26:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_audio_buffer_clip:
|
|
|
|
* @buffer: The buffer to clip.
|
|
|
|
* @segment: Segment in %GST_FORMAT_TIME or %GST_FORMAT_DEFAULT to which the buffer should be clipped.
|
|
|
|
* @rate: sample rate.
|
|
|
|
* @frame_size: size of one audio frame in bytes.
|
|
|
|
*
|
|
|
|
* Clip the the buffer to the given %GstSegment.
|
|
|
|
*
|
2007-08-22 15:29:04 +00:00
|
|
|
* After calling this function the caller does not own a reference to
|
|
|
|
* @buffer anymore.
|
2007-07-23 18:26:09 +00:00
|
|
|
*
|
|
|
|
* Returns: %NULL if the buffer is completely outside the configured segment,
|
|
|
|
* otherwise the clipped buffer is returned.
|
|
|
|
*
|
2007-07-27 17:10:47 +00:00
|
|
|
* If the buffer has no timestamp, it is assumed to be inside the segment and
|
|
|
|
* is not clipped
|
|
|
|
*
|
2007-07-23 18:26:09 +00:00
|
|
|
* Since: 0.10.14
|
|
|
|
*/
|
|
|
|
GstBuffer *
|
|
|
|
gst_audio_buffer_clip (GstBuffer * buffer, GstSegment * segment, gint rate,
|
|
|
|
gint frame_size)
|
|
|
|
{
|
|
|
|
GstBuffer *ret;
|
|
|
|
GstClockTime timestamp = GST_CLOCK_TIME_NONE, duration = GST_CLOCK_TIME_NONE;
|
|
|
|
guint64 offset = GST_BUFFER_OFFSET_NONE, offset_end = GST_BUFFER_OFFSET_NONE;
|
|
|
|
guint8 *data;
|
|
|
|
guint size;
|
|
|
|
|
|
|
|
gboolean change_duration = TRUE, change_offset = TRUE, change_offset_end =
|
|
|
|
TRUE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (segment->format == GST_FORMAT_TIME ||
|
|
|
|
segment->format == GST_FORMAT_DEFAULT, buffer);
|
|
|
|
g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
|
2007-07-27 17:10:47 +00:00
|
|
|
|
|
|
|
if (!GST_BUFFER_TIMESTAMP_IS_VALID (buffer))
|
|
|
|
/* No timestamp - assume the buffer is completely in the segment */
|
|
|
|
return buffer;
|
2007-07-23 18:26:09 +00:00
|
|
|
|
|
|
|
/* Get copies of the buffer metadata to change later.
|
|
|
|
* Calculate the missing values for the calculations,
|
|
|
|
* they won't be changed later though. */
|
|
|
|
|
|
|
|
data = GST_BUFFER_DATA (buffer);
|
|
|
|
size = GST_BUFFER_SIZE (buffer);
|
|
|
|
|
|
|
|
timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
if (GST_BUFFER_DURATION_IS_VALID (buffer)) {
|
|
|
|
duration = GST_BUFFER_DURATION (buffer);
|
|
|
|
} else {
|
|
|
|
change_duration = FALSE;
|
|
|
|
duration = gst_util_uint64_scale (size / frame_size, GST_SECOND, rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_BUFFER_OFFSET_IS_VALID (buffer)) {
|
|
|
|
offset = GST_BUFFER_OFFSET (buffer);
|
|
|
|
} else {
|
|
|
|
change_offset = FALSE;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_BUFFER_OFFSET_END_IS_VALID (buffer)) {
|
|
|
|
offset_end = GST_BUFFER_OFFSET_END (buffer);
|
|
|
|
} else {
|
|
|
|
change_offset_end = FALSE;
|
|
|
|
offset_end = offset + size / frame_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (segment->format == GST_FORMAT_TIME) {
|
|
|
|
/* Handle clipping for GST_FORMAT_TIME */
|
|
|
|
|
|
|
|
gint64 start, stop, cstart, cstop, diff;
|
|
|
|
|
|
|
|
start = timestamp;
|
|
|
|
stop = timestamp + duration;
|
|
|
|
|
|
|
|
if (gst_segment_clip (segment, GST_FORMAT_TIME,
|
|
|
|
start, stop, &cstart, &cstop)) {
|
|
|
|
|
|
|
|
diff = cstart - start;
|
|
|
|
if (diff > 0) {
|
|
|
|
timestamp = cstart;
|
|
|
|
|
|
|
|
if (change_duration)
|
|
|
|
duration -= diff;
|
|
|
|
|
|
|
|
diff = gst_util_uint64_scale (diff, rate, GST_SECOND);
|
|
|
|
if (change_offset)
|
|
|
|
offset += diff;
|
|
|
|
data += diff * frame_size;
|
|
|
|
size -= diff * frame_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
diff = stop - cstop;
|
|
|
|
if (diff > 0) {
|
|
|
|
/* duration is always valid if stop is valid */
|
|
|
|
duration -= diff;
|
|
|
|
|
|
|
|
diff = gst_util_uint64_scale (diff, rate, GST_SECOND);
|
|
|
|
if (change_offset_end)
|
|
|
|
offset_end -= diff;
|
|
|
|
size -= diff * frame_size;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Handle clipping for GST_FORMAT_DEFAULT */
|
|
|
|
gint64 start, stop, cstart, cstop, diff;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_BUFFER_OFFSET_IS_VALID (buffer), buffer);
|
|
|
|
|
|
|
|
start = offset;
|
|
|
|
stop = offset_end;
|
|
|
|
|
|
|
|
if (gst_segment_clip (segment, GST_FORMAT_DEFAULT,
|
|
|
|
start, stop, &cstart, &cstop)) {
|
|
|
|
|
|
|
|
diff = cstart - start;
|
|
|
|
if (diff > 0) {
|
|
|
|
offset = cstart;
|
|
|
|
|
|
|
|
timestamp = gst_util_uint64_scale (cstart, GST_SECOND, rate);
|
|
|
|
|
|
|
|
if (change_duration)
|
|
|
|
duration -= gst_util_uint64_scale (diff, GST_SECOND, rate);
|
|
|
|
|
|
|
|
data += diff * frame_size;
|
|
|
|
size -= diff * frame_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
diff = stop - cstop;
|
|
|
|
if (diff > 0) {
|
|
|
|
offset_end = cstop;
|
|
|
|
|
|
|
|
if (change_duration)
|
|
|
|
duration -= gst_util_uint64_scale (diff, GST_SECOND, rate);
|
|
|
|
|
|
|
|
size -= diff * frame_size;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get a metadata writable buffer and apply all changes */
|
|
|
|
ret = gst_buffer_make_metadata_writable (buffer);
|
|
|
|
|
|
|
|
GST_BUFFER_TIMESTAMP (ret) = timestamp;
|
|
|
|
GST_BUFFER_SIZE (ret) = size;
|
|
|
|
GST_BUFFER_DATA (ret) = data;
|
|
|
|
|
|
|
|
if (change_duration)
|
|
|
|
GST_BUFFER_DURATION (ret) = duration;
|
|
|
|
if (change_offset)
|
|
|
|
GST_BUFFER_OFFSET (ret) = offset;
|
|
|
|
if (change_offset_end)
|
|
|
|
GST_BUFFER_OFFSET_END (ret) = offset_end;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|