mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 01:00:37 +00:00
dtmf: convert to bit accessors
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/949>
This commit is contained in:
parent
c071cbbe30
commit
850a6f5f6f
3 changed files with 24 additions and 27 deletions
|
@ -34,19 +34,9 @@
|
|||
|
||||
typedef struct
|
||||
{
|
||||
unsigned event:8; /* Current DTMF event */
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
unsigned volume:6; /* power level of the tone, in dBm0 */
|
||||
unsigned r:1; /* Reserved-bit */
|
||||
unsigned e:1; /* End-bit */
|
||||
#elif G_BYTE_ORDER == G_BIG_ENDIAN
|
||||
unsigned e:1; /* End-bit */
|
||||
unsigned r:1; /* Reserved-bit */
|
||||
unsigned volume:6; /* power level of the tone, in dBm0 */
|
||||
#else
|
||||
#error "G_BYTE_ORDER should be big or little endian."
|
||||
#endif
|
||||
unsigned duration:16; /* Duration of digit, in timestamp units */
|
||||
guint8 event; /* Current DTMF event */
|
||||
guint8 volume; /* power level of the tone, in dBm0 */
|
||||
guint16 duration; /* Duration of digit, in timestamp units */
|
||||
} GstRTPDTMFPayload;
|
||||
|
||||
#endif /* __GST_RTP_DTMF_COMMON_H__ */
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
#include <math.h>
|
||||
|
||||
#include <gst/audio/audio.h>
|
||||
#include <gst/base/gstbitreader.h>
|
||||
#include <gst/rtp/gstrtpbuffer.h>
|
||||
|
||||
#define DEFAULT_PACKET_INTERVAL 50 /* ms */
|
||||
|
@ -357,7 +358,7 @@ gst_rtp_dtmf_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
|
|||
|
||||
GstRtpDTMFDepay *rtpdtmfdepay = NULL;
|
||||
GstBuffer *outbuf = NULL;
|
||||
gint payload_len;
|
||||
guint payload_len;
|
||||
guint8 *payload = NULL;
|
||||
guint32 timestamp;
|
||||
GstRTPDTMFPayload dtmf_payload;
|
||||
|
@ -365,6 +366,7 @@ gst_rtp_dtmf_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
|
|||
GstStructure *structure = NULL;
|
||||
GstMessage *dtmf_message = NULL;
|
||||
GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT;
|
||||
GstBitReader bitreader;
|
||||
|
||||
rtpdtmfdepay = GST_RTP_DTMF_DEPAY (depayload);
|
||||
|
||||
|
@ -373,10 +375,14 @@ gst_rtp_dtmf_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
|
|||
payload_len = gst_rtp_buffer_get_payload_len (&rtpbuffer);
|
||||
payload = gst_rtp_buffer_get_payload (&rtpbuffer);
|
||||
|
||||
if (payload_len != sizeof (GstRTPDTMFPayload))
|
||||
if (payload_len != 4)
|
||||
goto bad_packet;
|
||||
|
||||
memcpy (&dtmf_payload, payload, sizeof (GstRTPDTMFPayload));
|
||||
gst_bit_reader_init (&bitreader, payload, payload_len);
|
||||
gst_bit_reader_get_bits_uint8 (&bitreader, &dtmf_payload.event, 8);
|
||||
gst_bit_reader_skip (&bitreader, 2);
|
||||
gst_bit_reader_get_bits_uint8 (&bitreader, &dtmf_payload.volume, 6);
|
||||
gst_bit_reader_get_bits_uint16 (&bitreader, &dtmf_payload.duration, 16);
|
||||
|
||||
if (dtmf_payload.event > MAX_EVENT)
|
||||
goto bad_packet;
|
||||
|
@ -385,8 +391,6 @@ gst_rtp_dtmf_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
|
|||
|
||||
timestamp = gst_rtp_buffer_get_timestamp (&rtpbuffer);
|
||||
|
||||
dtmf_payload.duration = g_ntohs (dtmf_payload.duration);
|
||||
|
||||
/* clip to whole units of unit_time */
|
||||
if (rtpdtmfdepay->unit_time) {
|
||||
guint unit_time_clock =
|
||||
|
|
|
@ -85,6 +85,7 @@
|
|||
#include <glib.h>
|
||||
|
||||
#include "gstrtpdtmfsrc.h"
|
||||
#include <gst/base/gstbitwriter.h>
|
||||
|
||||
#define GST_RTP_DTMF_TYPE_EVENT 1
|
||||
#define DEFAULT_PTIME 40 /* ms */
|
||||
|
@ -537,8 +538,6 @@ gst_rtp_dtmf_prepare_rtp_headers (GstRTPDTMFSrc * dtmfsrc,
|
|||
/* Only the very first packet gets a marker */
|
||||
if (dtmfsrc->first_packet) {
|
||||
gst_rtp_buffer_set_marker (rtpbuf, TRUE);
|
||||
} else if (dtmfsrc->last_packet) {
|
||||
dtmfsrc->payload->e = 1;
|
||||
}
|
||||
|
||||
dtmfsrc->seqnum++;
|
||||
|
@ -552,10 +551,12 @@ static GstBuffer *
|
|||
gst_rtp_dtmf_src_create_next_rtp_packet (GstRTPDTMFSrc * dtmfsrc)
|
||||
{
|
||||
GstBuffer *buf;
|
||||
GstRTPDTMFPayload *payload;
|
||||
GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT;
|
||||
GstBitWriter bitwriter;
|
||||
guint8 *payload;
|
||||
guint8 end = dtmfsrc->last_packet ? 0x02 : 0;
|
||||
|
||||
buf = gst_rtp_buffer_new_allocate (sizeof (GstRTPDTMFPayload), 0, 0);
|
||||
buf = gst_rtp_buffer_new_allocate (4, 0, 0);
|
||||
|
||||
gst_rtp_buffer_map (buf, GST_MAP_READWRITE, &rtpbuffer);
|
||||
|
||||
|
@ -569,12 +570,14 @@ gst_rtp_dtmf_src_create_next_rtp_packet (GstRTPDTMFSrc * dtmfsrc)
|
|||
GST_BUFFER_DURATION (buf) = dtmfsrc->ptime * GST_MSECOND;
|
||||
GST_BUFFER_PTS (buf) = dtmfsrc->timestamp;
|
||||
|
||||
payload = (GstRTPDTMFPayload *) gst_rtp_buffer_get_payload (&rtpbuffer);
|
||||
payload = gst_rtp_buffer_get_payload (&rtpbuffer);
|
||||
|
||||
/* copy payload and convert to network-byte order */
|
||||
memmove (payload, dtmfsrc->payload, sizeof (GstRTPDTMFPayload));
|
||||
|
||||
payload->duration = g_htons (payload->duration);
|
||||
memset (payload, 0, 4);
|
||||
gst_bit_writer_init_with_data (&bitwriter, payload, 4, FALSE);
|
||||
gst_bit_writer_put_bits_uint8 (&bitwriter, dtmfsrc->payload->event, 8);
|
||||
gst_bit_writer_put_bits_uint8 (&bitwriter, end, 2);
|
||||
gst_bit_writer_put_bits_uint8 (&bitwriter, dtmfsrc->payload->volume, 6);
|
||||
gst_bit_writer_put_bits_uint16 (&bitwriter, dtmfsrc->payload->duration, 16);
|
||||
|
||||
if (dtmfsrc->redundancy_count <= 1 && dtmfsrc->last_packet) {
|
||||
GstClockTime inter_digit_interval = MIN_INTER_DIGIT_INTERVAL;
|
||||
|
|
Loading…
Reference in a new issue