[Asterisk-Dev]
Re: [Asterisk-cvs] asterisk/include/asterisk frame.h, 1.35.2.1,
1.35.2.2
Michael Manousos
manousos at inaccessnetworks.com
Tue Apr 5 04:43:06 MST 2005
russell at lists.digium.com wrote:
> Update of /usr/cvsroot/asterisk/include/asterisk
> In directory mongoose.digium.com:/tmp/cvs-serv5421/include/asterisk
>
> Modified Files:
> Tag: v1-0
> frame.h
> Log Message:
> handle AST_FORMAT_SLINEAR endianness properly on big-endian systems (bug #3865)
>
>
> Index: frame.h
> ===================================================================
> RCS file: /usr/cvsroot/asterisk/include/asterisk/frame.h,v
> retrieving revision 1.35.2.1
> retrieving revision 1.35.2.2
> diff -u -d -r1.35.2.1 -r1.35.2.2
> --- frame.h 5 Dec 2004 05:17:51 -0000 1.35.2.1
> +++ frame.h 5 Apr 2005 07:10:06 -0000 1.35.2.2
> @@ -329,6 +329,18 @@
> */
> int ast_fr_fdhangup(int fd);
>
> +void ast_memcpy_byteswap(void *dst, void *src, int samples);
> +
> +/* Helpers for byteswapping native samples to/from
> + little-endian and big-endian. */
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
> +#define ast_frame_byteswap_le(fr) do { ; } while(0)
> +#define ast_frame_byteswap_be(fr) do { struct ast_frame *__f = (fr); ast_memcpy_byteswap(__f->data, __f->data, __f->samples); } while(0)
> +#else
> +#define ast_frame_byteswap_le(fr) do { struct ast_frame *__f = (fr); ast_memcpy_byteswap(__f->data, __f->data, __f->samples); } while(0)
> +#define ast_frame_byteswap_be(fr) do { ; } while(0)
> +#endif
> +
> //! Get the name of a format
> /*!
> * \param format id of format
> @@ -375,8 +387,16 @@
> extern int ast_smoother_get_flags(struct ast_smoother *smoother);
> extern void ast_smoother_free(struct ast_smoother *s);
> extern void ast_smoother_reset(struct ast_smoother *s, int bytes);
> -extern int ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f);
> +extern int __ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f, int swap);
> extern struct ast_frame *ast_smoother_read(struct ast_smoother *s);
> +#define ast_smoother_feed(s,f) do { __ast_smoother_feed(s, f, 0); } while(0)
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
> +#define ast_smoother_feed_be(s,f) do { __ast_smoother_feed(s, f, 1); } while(0)
> +#define ast_smoother_feed_le(s,f) do { __ast_smoother_feed(s, f, 0); } while(0)
> +#else
> +#define ast_smoother_feed_be(s,f) do { __ast_smoother_feed(s, f, 0); } while(0)
> +#define ast_smoother_feed_le(s,f) do { __ast_smoother_feed(s, f, 1); } while(0)
> +#endif
>
> extern void ast_frame_dump(char *name, struct ast_frame *f, char *prefix);
The change of the 'ast_smoother_feed' into a define is not absolutely
right.
First it breaks code that uses this function inside a control block
e.g. if (ast_smoother_feed(...)).
Second, you can't tell whether the feed succeeded or failed.
The best solution would be to keep ast_smoother_feed a function
and move the '#if __BYTE_ORDER...' stuff inside that function
respecting the return value of __ast_smoother_feed(...).
Michael.
More information about the asterisk-dev
mailing list