[FFmpeg-soc] [soc]: r5067 - spdif/spdif.c

Reimar Döffinger Reimar.Doeffinger at gmx.de
Thu Aug 13 12:05:10 CEST 2009


On Thu, Aug 13, 2009 at 11:10:21AM +0200, bwolowiec wrote:
> Modified: spdif/spdif.c
> ==============================================================================
> --- spdif/spdif.c	Thu Aug 13 10:28:04 2009	(r5066)
> +++ spdif/spdif.c	Thu Aug 13 11:10:21 2009	(r5067)
> @@ -29,6 +29,8 @@
>  #include "libavcodec/ac3.h"
>  #include "libavcodec/dca.h"
>  #include "libavcodec/aac_parser.h"
> +#define __USE_XOPEN
> +#include <unistd.h>

That needs a feature test, but I think it would be better to add a
DSPUtil function, similar to bswap_buf

> @@ -55,6 +57,10 @@ typedef struct IEC958Context {
>      int pkt_size;               ///< Length code (number of bits or bytes - according to data_type)
>      int pkt_offset;             ///< Repetition period of a data burst in bytes
>      int (*header_info) (AVFormatContext *s, AVPacket *pkt);
> +#if !HAVE_BIGENDIAN
> +    uint8_t *buffer;
> +    int buffer_size;
> +#endif

I'd be in favour of leaving this in unconditionally, even if it is
strictly speaking useless bloat on big endian.


> @@ -186,6 +192,10 @@ static int spdif_header_aac(AVFormatCont
>  static int spdif_write_header(AVFormatContext *s)
>  {
>      IEC958Context *ctx = s->priv_data;
> +#if !HAVE_BIGENDIAN
> +    ctx->buffer_size = 0;
> +    ctx->buffer = NULL;
> +#endif

pointless, the context is initialized to 0.

> +#if !HAVE_BIGENDIAN
> +    IEC958Context *ctx = s->priv_data;
> +    av_free(ctx->buffer);
> +#endif

av_freep
And in principle you can do that without #if, too.

> @@ -237,13 +256,13 @@ static int spdif_write_packet(struct AVF
>  #if HAVE_BIGENDIAN
>      put_buffer(s->pb, pkt->data, pkt->size & ~1);
>  #else
> -    {
> -        //XXX swab... ?
> -        uint16_t *data = (uint16_t *) pkt->data;
> -        int i;
> -        for (i = 0; i < pkt->size >> 1; i++)
> -            put_be16(s->pb, data[i]);
> +    if (ctx->buffer_size < pkt->size) {
> +        av_fast_malloc(&ctx->buffer, &ctx->buffer_size, pkt->size + FF_INPUT_BUFFER_PADDING_SIZE);
> +        if (!ctx->buffer)
> +            return AVERROR(ENOMEM);
>      }
> +    swab(pkt->data, ctx->buffer, pkt->size & ~1);
> +    put_buffer(s->pb, ctx->buffer, pkt->size & ~1);
>  #endif

Btw. using
if (HAVE_BIGENDIAN) {
...
} else {
}

will ensure that compilation of both paths is checked on all builds, and
unless someone compiles with -O0 results in the same code.


More information about the FFmpeg-soc mailing list