Asterisk - The Open Source Telephony Project  GIT-master-93d0901
Macros
smoother.h File Reference

Asterisk internal frame definitions. More...

#include "asterisk/endian.h"
Include dependency graph for smoother.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define AST_SMOOTHER_FLAG_BE   (1 << 1)
 
#define AST_SMOOTHER_FLAG_FORCED   (1 << 2)
 
#define AST_SMOOTHER_FLAG_G729   (1 << 0)
 

AST_Smoother

int __ast_smoother_feed (struct ast_smoother *s, struct ast_frame *f, int swap)
 
#define ast_smoother_feed(s, f)   __ast_smoother_feed(s, f, 0)
 
#define ast_smoother_feed_be(s, f)   __ast_smoother_feed(s, f, 0)
 
#define ast_smoother_feed_le(s, f)   __ast_smoother_feed(s, f, 1)
 
void ast_smoother_free (struct ast_smoother *s)
 
int ast_smoother_get_flags (struct ast_smoother *smoother)
 
struct ast_smootherast_smoother_new (int bytes)
 
struct ast_frameast_smoother_read (struct ast_smoother *s)
 
void ast_smoother_reconfigure (struct ast_smoother *s, int bytes)
 Reconfigure an existing smoother to output a different number of bytes per frame. More...
 
void ast_smoother_reset (struct ast_smoother *s, int bytes)
 
void ast_smoother_set_flags (struct ast_smoother *smoother, int flags)
 
int ast_smoother_test_flag (struct ast_smoother *s, int flag)
 

Detailed Description

Asterisk internal frame definitions.

Definition in file smoother.h.

Macro Definition Documentation

◆ ast_smoother_feed

#define ast_smoother_feed (   s,
 
)    __ast_smoother_feed(s, f, 0)

Definition at line 75 of file smoother.h.

◆ ast_smoother_feed_be

#define ast_smoother_feed_be (   s,
 
)    __ast_smoother_feed(s, f, 0)

Definition at line 80 of file smoother.h.

◆ ast_smoother_feed_le

#define ast_smoother_feed_le (   s,
 
)    __ast_smoother_feed(s, f, 1)

Definition at line 81 of file smoother.h.

◆ AST_SMOOTHER_FLAG_BE

#define AST_SMOOTHER_FLAG_BE   (1 << 1)

Definition at line 35 of file smoother.h.

◆ AST_SMOOTHER_FLAG_FORCED

#define AST_SMOOTHER_FLAG_FORCED   (1 << 2)

Definition at line 36 of file smoother.h.

◆ AST_SMOOTHER_FLAG_G729

#define AST_SMOOTHER_FLAG_G729   (1 << 0)

Definition at line 34 of file smoother.h.

Function Documentation

◆ __ast_smoother_feed()

int __ast_smoother_feed ( struct ast_smoother s,
struct ast_frame f,
int  swap 
)

Definition at line 133 of file smoother.c.

134 {
135  if (f->frametype != AST_FRAME_VOICE) {
136  ast_log(LOG_WARNING, "Huh? Can't smooth a non-voice frame!\n");
137  return -1;
138  }
139  if (!s->format) {
140  s->format = ao2_bump(f->subclass.format);
141  s->samplesperbyte = (float)f->samples / (float)f->datalen;
143  ast_log(LOG_WARNING, "Smoother was working on %s format frames, now trying to feed %s?\n",
145  return -1;
146  }
147  if (s->len + f->datalen > SMOOTHER_SIZE) {
148  ast_log(LOG_WARNING, "Out of smoother space\n");
149  return -1;
150  }
151  if (((f->datalen == s->size) ||
152  ((f->datalen < 10) && (s->flags & AST_SMOOTHER_FLAG_G729))) &&
153  !s->opt &&
154  !s->len &&
155  (f->offset >= AST_MIN_OFFSET)) {
156  /* Optimize by sending the frame we just got
157  on the next read, thus eliminating the douple
158  copy */
159  if (swap)
161  s->opt = f;
162  s->opt_needs_swap = swap ? 1 : 0;
163  return 0;
164  }
165 
166  return smoother_frame_feed(s, f, swap);
167 }
#define ast_log
Definition: astobj2.c:42
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
@ AST_FORMAT_CMP_NOT_EQUAL
Definition: format.h:38
#define AST_MIN_OFFSET
void ast_swapcopy_samples(void *dst, const void *src, int samples)
Definition: main/frame.c:396
@ AST_FRAME_VOICE
#define LOG_WARNING
Definition: logger.h:275
static int smoother_frame_feed(struct ast_smoother *s, struct ast_frame *f, int swap)
Definition: smoother.c:57
#define SMOOTHER_SIZE
Definition: smoother.c:41
#define AST_SMOOTHER_FLAG_G729
Definition: smoother.h:34
struct ast_format * format
struct ast_frame_subclass subclass
enum ast_frame_type frametype
union ast_frame::@253 data
struct ast_frame * opt
Definition: smoother.c:53
unsigned int opt_needs_swap
Definition: smoother.c:48
struct ast_format * format
Definition: smoother.c:45
float samplesperbyte
Definition: smoother.c:47

References ao2_bump, ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, ast_format_get_name(), AST_FRAME_VOICE, ast_log, AST_MIN_OFFSET, AST_SMOOTHER_FLAG_G729, ast_swapcopy_samples(), ast_frame::data, ast_frame::datalen, ast_smoother::f, ast_smoother::flags, ast_frame_subclass::format, ast_smoother::format, ast_frame::frametype, ast_smoother::len, LOG_WARNING, ast_frame::offset, ast_smoother::opt, ast_smoother::opt_needs_swap, ast_frame::ptr, ast_frame::samples, ast_smoother::samplesperbyte, ast_smoother::size, smoother_frame_feed(), SMOOTHER_SIZE, and ast_frame::subclass.

◆ ast_smoother_free()

void ast_smoother_free ( struct ast_smoother s)

◆ ast_smoother_get_flags()

int ast_smoother_get_flags ( struct ast_smoother smoother)

Definition at line 118 of file smoother.c.

119 {
120  return s->flags;
121 }

References ast_smoother::flags.

◆ ast_smoother_new()

struct ast_smoother* ast_smoother_new ( int  bytes)

Definition at line 108 of file smoother.c.

109 {
110  struct ast_smoother *s;
111  if (size < 1)
112  return NULL;
113  if ((s = ast_calloc(1, sizeof(*s))))
115  return s;
116 }
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define NULL
Definition: resample.c:96
void ast_smoother_reset(struct ast_smoother *s, int bytes)
Definition: smoother.c:79

References ast_calloc, ast_smoother_reset(), NULL, and ast_smoother::size.

Referenced by ast_rtp_write(), generic_fax_exec(), mbl_load_device(), and multicast_rtp_write().

◆ ast_smoother_read()

struct ast_frame* ast_smoother_read ( struct ast_smoother s)

Definition at line 169 of file smoother.c.

170 {
171  struct ast_frame *opt;
172  int len;
173 
174  /* IF we have an optimization frame, send it */
175  if (s->opt) {
176  if (s->opt->offset < AST_FRIENDLY_OFFSET)
177  ast_log(LOG_WARNING, "Returning a frame of inappropriate offset (%d).\n",
178  s->opt->offset);
179  opt = s->opt;
180  s->opt = NULL;
181  return opt;
182  }
183 
184  /* Make sure we have enough data */
185  if (s->len < s->size) {
186  /* Or, if this is a G.729 frame with VAD on it, send it immediately anyway */
187  if (!((s->flags & AST_SMOOTHER_FLAG_G729) && (s->len % 10)))
188  return NULL;
189  }
190  len = s->size;
191  if (len > s->len)
192  len = s->len;
193  /* Make frame */
195  s->f.subclass.format = s->format;
198  s->f.datalen = len;
199  /* Samples will be improper given VAD, but with VAD the concept really doesn't even exist */
200  s->f.samples = len * s->samplesperbyte; /* XXX rounding */
201  s->f.delivery = s->delivery;
202  /* Fill Data */
203  memcpy(s->f.data.ptr, s->data, len);
204  s->len -= len;
205  /* Move remaining data to the front if applicable */
206  if (s->len) {
207  /* In principle this should all be fine because if we are sending
208  G.729 VAD, the next timestamp will take over anyway */
209  memmove(s->data, s->data + len, s->len);
210  if (!ast_tvzero(s->delivery)) {
211  /* If we have delivery time, increment it, otherwise, leave it at 0 */
214  }
215  }
216  /* Return frame */
217  return &s->f;
218 }
unsigned int ast_format_get_sample_rate(const struct ast_format *format)
Get the sample rate of a media format.
Definition: format.c:379
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
Data structure associated with a single frame of data.
struct timeval delivery
struct timeval delivery
Definition: smoother.c:50
struct ast_frame f
Definition: smoother.c:49
char framedata[SMOOTHER_SIZE+AST_FRIENDLY_OFFSET]
Definition: smoother.c:52
char data[SMOOTHER_SIZE]
Definition: smoother.c:51
struct timeval ast_samp2tv(unsigned int _nsamp, unsigned int _rate)
Returns a timeval corresponding to the duration of n samples at rate r. Useful to convert samples to ...
Definition: time.h:238
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
Definition: time.h:108
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: extconf.c:2282

References ast_format_get_sample_rate(), AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log, ast_samp2tv(), AST_SMOOTHER_FLAG_G729, ast_tvadd(), ast_tvzero(), ast_frame::data, ast_smoother::data, ast_frame::datalen, ast_frame::delivery, ast_smoother::delivery, ast_smoother::f, ast_smoother::flags, ast_frame_subclass::format, ast_smoother::format, ast_smoother::framedata, ast_frame::frametype, len(), ast_smoother::len, LOG_WARNING, NULL, ast_frame::offset, ast_smoother::opt, ast_frame::ptr, ast_frame::samples, ast_smoother::samplesperbyte, ast_smoother::size, and ast_frame::subclass.

Referenced by ast_rtp_write(), generic_fax_exec(), mbl_read(), mbl_write(), and multicast_rtp_write().

◆ ast_smoother_reconfigure()

void ast_smoother_reconfigure ( struct ast_smoother s,
int  bytes 
)

Reconfigure an existing smoother to output a different number of bytes per frame.

Parameters
sthe smoother to reconfigure
bytesthe desired number of bytes per output frame

Definition at line 86 of file smoother.c.

87 {
88  /* if there is no change, then nothing to do */
89  if (s->size == bytes) {
90  return;
91  }
92  /* set the new desired output size */
93  s->size = bytes;
94  /* if there is no 'optimized' frame in the smoother,
95  * then there is nothing left to do
96  */
97  if (!s->opt) {
98  return;
99  }
100  /* there is an 'optimized' frame here at the old size,
101  * but it must now be put into the buffer so the data
102  * can be extracted at the new size
103  */
105  s->opt = NULL;
106 }

References NULL, ast_smoother::opt, ast_smoother::opt_needs_swap, ast_smoother::size, and smoother_frame_feed().

◆ ast_smoother_reset()

void ast_smoother_reset ( struct ast_smoother s,
int  bytes 
)

Definition at line 79 of file smoother.c.

80 {
81  ao2_cleanup(s->format);
82  memset(s, 0, sizeof(*s));
83  s->size = bytes;
84 }

References ao2_cleanup, ast_smoother::format, and ast_smoother::size.

Referenced by ast_smoother_new(), and mbl_new().

◆ ast_smoother_set_flags()

void ast_smoother_set_flags ( struct ast_smoother smoother,
int  flags 
)

Definition at line 123 of file smoother.c.

124 {
125  s->flags = flags;
126 }

References ast_smoother::flags.

Referenced by ast_rtp_write(), and multicast_rtp_write().

◆ ast_smoother_test_flag()

int ast_smoother_test_flag ( struct ast_smoother s,
int  flag 
)

Definition at line 128 of file smoother.c.

129 {
130  return (s->flags & flag);
131 }
long int flag
Definition: f2c.h:83

References ast_smoother::flags.

Referenced by ast_rtp_write(), and multicast_rtp_write().