2008-05-13 08:35:55 +00:00
|
|
|
/* GStreamer
|
2008-11-11 17:29:03 +00:00
|
|
|
* Copyright (C) <2007> Nokia Corporation
|
|
|
|
* Copyright (C) <2007> Collabora Ltd
|
|
|
|
* @author: Olivier Crete <olivier.crete@collabora.co.uk>
|
2008-05-13 08:35:55 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-11-04 00:07:18 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-05-13 08:35:55 +00:00
|
|
|
*/
|
|
|
|
|
2008-11-11 17:29:03 +00:00
|
|
|
/*
|
|
|
|
* This payloader assumes that the data will ALWAYS come as zero or more
|
|
|
|
* 10 bytes frame of audio followed by 0 or 1 2 byte frame of silence.
|
|
|
|
* Any other buffer format won't work
|
|
|
|
*/
|
|
|
|
|
2008-05-13 08:35:55 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2008-11-11 17:29:03 +00:00
|
|
|
#include <config.h>
|
2008-05-13 08:35:55 +00:00
|
|
|
#endif
|
|
|
|
|
2008-11-11 17:29:03 +00:00
|
|
|
#include <string.h>
|
2008-05-13 08:35:55 +00:00
|
|
|
#include <gst/rtp/gstrtpbuffer.h>
|
2008-11-11 17:29:03 +00:00
|
|
|
#include <gst/base/gstadapter.h>
|
2015-08-04 17:59:17 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2008-11-11 17:29:03 +00:00
|
|
|
|
2021-02-12 12:16:28 +00:00
|
|
|
#include "gstrtpelements.h"
|
2008-11-11 17:29:03 +00:00
|
|
|
#include "gstrtpg729pay.h"
|
2015-08-04 17:59:17 +00:00
|
|
|
#include "gstrtputils.h"
|
2008-11-11 17:29:03 +00:00
|
|
|
|
2009-09-16 17:57:05 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (rtpg729pay_debug);
|
|
|
|
#define GST_CAT_DEFAULT (rtpg729pay_debug)
|
|
|
|
|
2008-11-11 17:29:03 +00:00
|
|
|
#define G729_FRAME_SIZE 10
|
|
|
|
#define G729B_CN_FRAME_SIZE 2
|
|
|
|
#define G729_FRAME_DURATION (10 * GST_MSECOND)
|
|
|
|
#define G729_FRAME_DURATION_MS (10)
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-11 11:25:01 +00:00
|
|
|
gst_rtp_g729_pay_set_caps (GstRTPBasePayload * payload, GstCaps * caps);
|
2008-11-11 17:29:03 +00:00
|
|
|
static GstFlowReturn
|
2011-11-11 11:25:01 +00:00
|
|
|
gst_rtp_g729_pay_handle_buffer (GstRTPBasePayload * payload, GstBuffer * buf);
|
2008-05-13 08:35:55 +00:00
|
|
|
|
2010-08-02 10:56:29 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_rtp_g729_pay_change_state (GstElement * element, GstStateChange transition);
|
|
|
|
|
2008-11-11 17:29:03 +00:00
|
|
|
static GstStaticPadTemplate gst_rtp_g729_pay_sink_template =
|
2008-05-13 08:35:55 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
2008-11-11 17:29:03 +00:00
|
|
|
GST_STATIC_CAPS ("audio/G729, " /* according to RFC 3555 */
|
|
|
|
"channels = (int) 1, " "rate = (int) 8000")
|
2008-05-13 08:35:55 +00:00
|
|
|
);
|
|
|
|
|
2008-11-11 17:29:03 +00:00
|
|
|
static GstStaticPadTemplate gst_rtp_g729_pay_src_template =
|
2008-05-13 08:35:55 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("application/x-rtp, "
|
|
|
|
"media = (string) \"audio\", "
|
2008-11-11 17:29:03 +00:00
|
|
|
"payload = (int) " GST_RTP_PAYLOAD_G729_STRING ", "
|
|
|
|
"clock-rate = (int) 8000, "
|
|
|
|
"encoding-name = (string) \"G729\"; "
|
2008-05-13 08:35:55 +00:00
|
|
|
"application/x-rtp, "
|
|
|
|
"media = (string) \"audio\", "
|
2008-11-11 17:29:03 +00:00
|
|
|
"payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
|
|
|
|
"clock-rate = (int) 8000, " "encoding-name = (string) \"G729\"")
|
2008-05-13 08:35:55 +00:00
|
|
|
);
|
|
|
|
|
2011-04-25 15:27:40 +00:00
|
|
|
#define gst_rtp_g729_pay_parent_class parent_class
|
2011-11-11 11:25:01 +00:00
|
|
|
G_DEFINE_TYPE (GstRTPG729Pay, gst_rtp_g729_pay, GST_TYPE_RTP_BASE_PAYLOAD);
|
2021-02-12 12:16:28 +00:00
|
|
|
GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (rtpg729pay, "rtpg729pay",
|
|
|
|
GST_RANK_SECONDARY, GST_TYPE_RTP_G729_PAY, rtp_element_init (plugin));
|
2008-05-13 08:35:55 +00:00
|
|
|
|
2010-08-02 10:56:29 +00:00
|
|
|
static void
|
|
|
|
gst_rtp_g729_pay_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstRTPG729Pay *pay = GST_RTP_G729_PAY (object);
|
|
|
|
|
|
|
|
g_object_unref (pay->adapter);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2008-05-13 08:35:55 +00:00
|
|
|
static void
|
2008-11-11 17:29:03 +00:00
|
|
|
gst_rtp_g729_pay_class_init (GstRTPG729PayClass * klass)
|
2008-05-13 08:35:55 +00:00
|
|
|
{
|
2010-08-02 10:56:29 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GstElementClass *gstelement_class = (GstElementClass *) klass;
|
2011-11-11 11:25:01 +00:00
|
|
|
GstRTPBasePayloadClass *payload_class = GST_RTP_BASE_PAYLOAD_CLASS (klass);
|
2008-05-13 08:35:55 +00:00
|
|
|
|
2011-04-25 15:27:40 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (rtpg729pay_debug, "rtpg729pay", 0,
|
|
|
|
"G.729 RTP Payloader");
|
|
|
|
|
2010-08-02 10:56:29 +00:00
|
|
|
gobject_class->finalize = gst_rtp_g729_pay_finalize;
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_rtp_g729_pay_change_state;
|
|
|
|
|
2016-03-04 01:30:12 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_rtp_g729_pay_sink_template);
|
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_rtp_g729_pay_src_template);
|
2011-04-25 15:27:40 +00:00
|
|
|
|
2012-04-09 23:51:41 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
|
|
|
"RTP G.729 payloader", "Codec/Payloader/Network/RTP",
|
2011-04-25 15:27:40 +00:00
|
|
|
"Packetize G.729 audio into RTP packets",
|
|
|
|
"Olivier Crete <olivier.crete@collabora.co.uk>");
|
|
|
|
|
2008-11-11 17:29:03 +00:00
|
|
|
payload_class->set_caps = gst_rtp_g729_pay_set_caps;
|
|
|
|
payload_class->handle_buffer = gst_rtp_g729_pay_handle_buffer;
|
2008-05-13 08:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-04-25 15:27:40 +00:00
|
|
|
gst_rtp_g729_pay_init (GstRTPG729Pay * pay)
|
2008-05-13 08:35:55 +00:00
|
|
|
{
|
2011-11-11 11:25:01 +00:00
|
|
|
GstRTPBasePayload *payload = GST_RTP_BASE_PAYLOAD (pay);
|
2008-05-13 08:35:55 +00:00
|
|
|
|
2008-11-11 17:29:03 +00:00
|
|
|
payload->pt = GST_RTP_PAYLOAD_G729;
|
2008-05-13 08:35:55 +00:00
|
|
|
|
2010-08-02 10:56:29 +00:00
|
|
|
pay->adapter = gst_adapter_new ();
|
|
|
|
}
|
2008-05-13 08:35:55 +00:00
|
|
|
|
2010-08-02 10:56:29 +00:00
|
|
|
static void
|
|
|
|
gst_rtp_g729_pay_reset (GstRTPG729Pay * pay)
|
|
|
|
{
|
|
|
|
gst_adapter_clear (pay->adapter);
|
|
|
|
pay->discont = FALSE;
|
2010-08-18 09:39:06 +00:00
|
|
|
pay->next_rtp_time = 0;
|
|
|
|
pay->first_ts = GST_CLOCK_TIME_NONE;
|
|
|
|
pay->first_rtp_time = 0;
|
2008-05-13 08:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-11 11:25:01 +00:00
|
|
|
gst_rtp_g729_pay_set_caps (GstRTPBasePayload * payload, GstCaps * caps)
|
2008-05-13 08:35:55 +00:00
|
|
|
{
|
2008-11-11 17:33:00 +00:00
|
|
|
gboolean res;
|
2008-05-13 08:35:55 +00:00
|
|
|
|
2015-08-06 02:33:37 +00:00
|
|
|
gst_rtp_base_payload_set_options (payload, "audio",
|
|
|
|
payload->pt != GST_RTP_PAYLOAD_G729, "G729", 8000);
|
2008-11-11 17:29:03 +00:00
|
|
|
|
2011-11-11 11:25:01 +00:00
|
|
|
res = gst_rtp_base_payload_set_outcaps (payload, NULL);
|
2008-11-11 17:29:03 +00:00
|
|
|
|
2008-11-11 17:33:00 +00:00
|
|
|
return res;
|
2008-11-11 17:29:03 +00:00
|
|
|
}
|
|
|
|
|
2010-08-02 10:56:29 +00:00
|
|
|
static GstFlowReturn
|
2015-07-01 15:58:56 +00:00
|
|
|
gst_rtp_g729_pay_push (GstRTPG729Pay * rtpg729pay, GstBuffer * buf)
|
2010-08-02 10:56:29 +00:00
|
|
|
{
|
2011-11-11 11:25:01 +00:00
|
|
|
GstRTPBasePayload *basepayload;
|
2010-08-18 09:39:06 +00:00
|
|
|
GstClockTime duration;
|
|
|
|
guint frames;
|
2010-08-02 10:56:29 +00:00
|
|
|
GstBuffer *outbuf;
|
|
|
|
GstFlowReturn ret;
|
2011-04-25 15:27:40 +00:00
|
|
|
GstRTPBuffer rtp = { NULL };
|
2015-07-01 15:58:56 +00:00
|
|
|
guint payload_len = gst_buffer_get_size (buf);
|
2010-08-02 10:56:29 +00:00
|
|
|
|
2011-11-11 11:25:01 +00:00
|
|
|
basepayload = GST_RTP_BASE_PAYLOAD (rtpg729pay);
|
2010-08-02 10:56:29 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (rtpg729pay, "Pushing %d bytes ts %" GST_TIME_FORMAT,
|
2010-08-18 09:39:06 +00:00
|
|
|
payload_len, GST_TIME_ARGS (rtpg729pay->next_ts));
|
2010-08-02 10:56:29 +00:00
|
|
|
|
|
|
|
/* create buffer to hold the payload */
|
2020-07-17 20:39:25 +00:00
|
|
|
outbuf =
|
|
|
|
gst_rtp_base_payload_allocate_output_buffer (GST_RTP_BASE_PAYLOAD
|
|
|
|
(rtpg729pay), 0, 0, 0);
|
2010-08-02 10:56:29 +00:00
|
|
|
|
2011-04-25 15:27:40 +00:00
|
|
|
gst_rtp_buffer_map (outbuf, GST_MAP_READWRITE, &rtp);
|
|
|
|
|
2010-08-02 10:56:29 +00:00
|
|
|
/* set metadata */
|
2010-08-18 09:39:06 +00:00
|
|
|
frames =
|
|
|
|
(payload_len / G729_FRAME_SIZE) + ((payload_len % G729_FRAME_SIZE) >> 1);
|
|
|
|
duration = frames * G729_FRAME_DURATION;
|
2015-06-10 12:33:50 +00:00
|
|
|
GST_BUFFER_PTS (outbuf) = rtpg729pay->next_ts;
|
2010-08-02 10:56:29 +00:00
|
|
|
GST_BUFFER_DURATION (outbuf) = duration;
|
2010-08-18 09:39:06 +00:00
|
|
|
GST_BUFFER_OFFSET (outbuf) = rtpg729pay->next_rtp_time;
|
|
|
|
rtpg729pay->next_ts += duration;
|
|
|
|
rtpg729pay->next_rtp_time += frames * 80;
|
2010-08-02 10:56:29 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (rtpg729pay->discont)) {
|
|
|
|
GST_DEBUG_OBJECT (basepayload, "discont, setting marker bit");
|
|
|
|
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
|
2011-04-25 15:27:40 +00:00
|
|
|
gst_rtp_buffer_set_marker (&rtp, TRUE);
|
2010-08-02 10:56:29 +00:00
|
|
|
rtpg729pay->discont = FALSE;
|
|
|
|
}
|
2011-04-25 15:27:40 +00:00
|
|
|
gst_rtp_buffer_unmap (&rtp);
|
2010-08-02 10:56:29 +00:00
|
|
|
|
2015-07-01 15:58:56 +00:00
|
|
|
/* append payload */
|
2017-05-24 11:57:10 +00:00
|
|
|
gst_rtp_copy_audio_meta (basepayload, outbuf, buf);
|
2015-07-01 15:58:56 +00:00
|
|
|
outbuf = gst_buffer_append (outbuf, buf);
|
2010-08-02 10:56:29 +00:00
|
|
|
|
2015-07-01 15:58:56 +00:00
|
|
|
ret = gst_rtp_base_payload_push (basepayload, outbuf);
|
2014-06-12 10:16:08 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-08-18 09:39:06 +00:00
|
|
|
static void
|
|
|
|
gst_rtp_g729_pay_recalc_rtp_time (GstRTPG729Pay * rtpg729pay, GstClockTime time)
|
|
|
|
{
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (rtpg729pay->first_ts)
|
|
|
|
&& GST_CLOCK_TIME_IS_VALID (time) && time >= rtpg729pay->first_ts) {
|
|
|
|
GstClockTime diff;
|
|
|
|
guint32 rtpdiff;
|
|
|
|
|
|
|
|
diff = time - rtpg729pay->first_ts;
|
|
|
|
rtpdiff = (diff / GST_MSECOND) * 8;
|
|
|
|
rtpg729pay->next_rtp_time = rtpg729pay->first_rtp_time + rtpdiff;
|
|
|
|
GST_DEBUG_OBJECT (rtpg729pay,
|
2010-09-17 09:07:02 +00:00
|
|
|
"elapsed time %" GST_TIME_FORMAT ", rtp %" G_GUINT32_FORMAT ", "
|
|
|
|
"new offset %" G_GUINT32_FORMAT, GST_TIME_ARGS (diff), rtpdiff,
|
2010-08-18 09:39:06 +00:00
|
|
|
rtpg729pay->next_rtp_time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-11 17:29:03 +00:00
|
|
|
static GstFlowReturn
|
2011-11-11 11:25:01 +00:00
|
|
|
gst_rtp_g729_pay_handle_buffer (GstRTPBasePayload * payload, GstBuffer * buf)
|
2008-11-11 17:29:03 +00:00
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2010-08-02 10:56:29 +00:00
|
|
|
GstRTPG729Pay *rtpg729pay = GST_RTP_G729_PAY (payload);
|
2008-11-11 17:29:03 +00:00
|
|
|
GstAdapter *adapter = NULL;
|
|
|
|
guint payload_len;
|
|
|
|
guint available;
|
|
|
|
guint maxptime_octets = G_MAXUINT;
|
|
|
|
guint minptime_octets = 0;
|
|
|
|
guint min_payload_len;
|
|
|
|
guint max_payload_len;
|
2011-04-25 15:27:40 +00:00
|
|
|
gsize size;
|
|
|
|
GstClockTime timestamp;
|
2008-11-11 17:29:03 +00:00
|
|
|
|
2011-04-25 15:27:40 +00:00
|
|
|
size = gst_buffer_get_size (buf);
|
2008-05-13 08:35:55 +00:00
|
|
|
|
2011-04-25 15:27:40 +00:00
|
|
|
if (size % G729_FRAME_SIZE != 0 &&
|
|
|
|
size % G729_FRAME_SIZE != G729B_CN_FRAME_SIZE)
|
2008-11-11 17:29:03 +00:00
|
|
|
goto invalid_size;
|
2008-05-13 08:35:55 +00:00
|
|
|
|
2008-11-11 17:29:03 +00:00
|
|
|
/* max number of bytes based on given ptime, has to be multiple of
|
|
|
|
* frame_duration */
|
|
|
|
if (payload->max_ptime != -1) {
|
2010-01-19 02:15:51 +00:00
|
|
|
guint ptime_ms = payload->max_ptime / GST_MSECOND;
|
2008-11-11 17:29:03 +00:00
|
|
|
|
|
|
|
maxptime_octets = G729_FRAME_SIZE *
|
|
|
|
(int) (ptime_ms / G729_FRAME_DURATION_MS);
|
|
|
|
|
|
|
|
if (maxptime_octets < G729_FRAME_SIZE) {
|
2010-08-02 10:56:29 +00:00
|
|
|
GST_WARNING_OBJECT (payload, "Given ptime %" G_GINT64_FORMAT
|
2008-11-12 16:37:06 +00:00
|
|
|
" is smaller than minimum %d ns, overwriting to minimum",
|
2008-11-11 17:29:03 +00:00
|
|
|
payload->max_ptime, G729_FRAME_DURATION_MS);
|
|
|
|
maxptime_octets = G729_FRAME_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
max_payload_len = MIN (
|
|
|
|
/* MTU max */
|
2011-11-11 11:25:01 +00:00
|
|
|
(int) (gst_rtp_buffer_calc_payload_len (GST_RTP_BASE_PAYLOAD_MTU
|
2010-08-02 10:56:29 +00:00
|
|
|
(payload), 0, 0) / G729_FRAME_SIZE)
|
|
|
|
* G729_FRAME_SIZE,
|
2008-11-11 17:29:03 +00:00
|
|
|
/* ptime max */
|
|
|
|
maxptime_octets);
|
|
|
|
|
|
|
|
/* min number of bytes based on a given ptime, has to be a multiple
|
|
|
|
of frame duration */
|
|
|
|
{
|
2009-12-31 21:27:30 +00:00
|
|
|
guint64 min_ptime = payload->min_ptime;
|
2008-11-11 17:29:03 +00:00
|
|
|
|
2010-01-19 02:15:51 +00:00
|
|
|
min_ptime = min_ptime / GST_MSECOND;
|
2008-11-11 17:29:03 +00:00
|
|
|
minptime_octets = G729_FRAME_SIZE *
|
|
|
|
(int) (min_ptime / G729_FRAME_DURATION_MS);
|
|
|
|
}
|
|
|
|
|
|
|
|
min_payload_len = MAX (minptime_octets, G729_FRAME_SIZE);
|
|
|
|
|
|
|
|
if (min_payload_len > max_payload_len) {
|
|
|
|
min_payload_len = max_payload_len;
|
|
|
|
}
|
|
|
|
|
2009-12-31 21:27:30 +00:00
|
|
|
/* If the ptime is specified in the caps, tried to adhere to it exactly */
|
2011-11-11 18:21:50 +00:00
|
|
|
if (payload->ptime) {
|
|
|
|
guint64 ptime = payload->ptime / GST_MSECOND;
|
2009-12-31 21:27:30 +00:00
|
|
|
guint ptime_in_bytes = G729_FRAME_SIZE *
|
2010-01-19 02:15:51 +00:00
|
|
|
(guint) (ptime / G729_FRAME_DURATION_MS);
|
2009-12-31 21:27:30 +00:00
|
|
|
|
|
|
|
/* clip to computed min and max lengths */
|
|
|
|
ptime_in_bytes = MAX (min_payload_len, ptime_in_bytes);
|
|
|
|
ptime_in_bytes = MIN (max_payload_len, ptime_in_bytes);
|
|
|
|
|
|
|
|
min_payload_len = max_payload_len = ptime_in_bytes;
|
|
|
|
}
|
|
|
|
|
2010-08-02 10:56:29 +00:00
|
|
|
GST_LOG_OBJECT (payload,
|
2008-11-11 17:29:03 +00:00
|
|
|
"Calculated min_payload_len %u and max_payload_len %u",
|
|
|
|
min_payload_len, max_payload_len);
|
|
|
|
|
2010-08-18 09:39:06 +00:00
|
|
|
adapter = rtpg729pay->adapter;
|
|
|
|
available = gst_adapter_available (adapter);
|
|
|
|
|
2015-06-10 12:33:50 +00:00
|
|
|
timestamp = GST_BUFFER_PTS (buf);
|
2011-04-25 15:27:40 +00:00
|
|
|
|
2010-08-18 09:39:06 +00:00
|
|
|
/* resync rtp time on discont or a discontinuous cn packet */
|
|
|
|
if (GST_BUFFER_IS_DISCONT (buf)) {
|
|
|
|
/* flush remainder */
|
|
|
|
if (available > 0) {
|
2015-07-01 15:58:56 +00:00
|
|
|
gst_rtp_g729_pay_push (rtpg729pay,
|
|
|
|
gst_adapter_take_buffer_fast (adapter, available));
|
2010-08-18 09:39:06 +00:00
|
|
|
available = 0;
|
|
|
|
}
|
2010-08-02 10:56:29 +00:00
|
|
|
rtpg729pay->discont = TRUE;
|
2011-04-25 15:27:40 +00:00
|
|
|
gst_rtp_g729_pay_recalc_rtp_time (rtpg729pay, timestamp);
|
2010-08-18 09:39:06 +00:00
|
|
|
}
|
2008-11-11 17:29:03 +00:00
|
|
|
|
2011-04-25 15:27:40 +00:00
|
|
|
if (size < G729_FRAME_SIZE)
|
|
|
|
gst_rtp_g729_pay_recalc_rtp_time (rtpg729pay, timestamp);
|
2010-08-18 09:39:06 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (rtpg729pay->first_ts))) {
|
2011-04-25 15:27:40 +00:00
|
|
|
rtpg729pay->first_ts = timestamp;
|
2010-08-18 09:39:06 +00:00
|
|
|
rtpg729pay->first_rtp_time = rtpg729pay->next_rtp_time;
|
|
|
|
}
|
2008-11-11 17:29:03 +00:00
|
|
|
|
2009-12-31 21:52:30 +00:00
|
|
|
/* let's reset the base timestamp when the adapter is empty */
|
2010-08-18 09:39:06 +00:00
|
|
|
if (available == 0)
|
2011-04-25 15:27:40 +00:00
|
|
|
rtpg729pay->next_ts = timestamp;
|
2008-11-11 17:29:03 +00:00
|
|
|
|
2011-04-25 15:27:40 +00:00
|
|
|
if (available == 0 && size >= min_payload_len && size <= max_payload_len) {
|
2015-07-07 14:48:40 +00:00
|
|
|
ret = gst_rtp_g729_pay_push (rtpg729pay, buf);
|
2009-12-31 21:52:30 +00:00
|
|
|
return ret;
|
2008-11-11 17:29:03 +00:00
|
|
|
}
|
|
|
|
|
2009-12-31 21:52:30 +00:00
|
|
|
gst_adapter_push (adapter, buf);
|
|
|
|
available = gst_adapter_available (adapter);
|
2010-08-18 09:39:06 +00:00
|
|
|
|
2008-11-11 17:29:03 +00:00
|
|
|
/* as long as we have full frames */
|
|
|
|
/* this loop will push all available buffers till the last frame */
|
|
|
|
while (available >= min_payload_len ||
|
|
|
|
available % G729_FRAME_SIZE == G729B_CN_FRAME_SIZE) {
|
|
|
|
/* We send as much as we can */
|
|
|
|
if (available <= max_payload_len) {
|
|
|
|
payload_len = available;
|
|
|
|
} else {
|
|
|
|
payload_len = MIN (max_payload_len,
|
|
|
|
(available / G729_FRAME_SIZE) * G729_FRAME_SIZE);
|
|
|
|
}
|
|
|
|
|
2015-07-01 15:58:56 +00:00
|
|
|
ret = gst_rtp_g729_pay_push (rtpg729pay,
|
|
|
|
gst_adapter_take_buffer_fast (adapter, payload_len));
|
2010-08-18 09:39:06 +00:00
|
|
|
available -= payload_len;
|
2008-11-11 17:29:03 +00:00
|
|
|
}
|
|
|
|
|
2008-05-13 08:35:55 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2008-11-11 17:29:03 +00:00
|
|
|
invalid_size:
|
2008-05-13 08:35:55 +00:00
|
|
|
{
|
2008-11-11 17:29:03 +00:00
|
|
|
GST_ELEMENT_ERROR (payload, STREAM, WRONG_TYPE,
|
|
|
|
("Invalid input buffer size"),
|
|
|
|
("Invalid buffer size, should be a multiple of"
|
|
|
|
" G729_FRAME_SIZE(10) with an optional G729B_CN_FRAME_SIZE(2)"
|
2011-11-21 19:31:31 +00:00
|
|
|
" added to it, but it is %" G_GSIZE_FORMAT, size));
|
2008-11-11 17:29:03 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
return GST_FLOW_ERROR;
|
2008-05-13 08:35:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-02 10:56:29 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_rtp_g729_pay_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
|
|
|
|
|
|
|
/* handle upwards state changes here */
|
|
|
|
switch (transition) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
/* handle downwards state changes */
|
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
gst_rtp_g729_pay_reset (GST_RTP_G729_PAY (element));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|