Revision af1e8ffd libavformat/spdifenc.c

View differences:

libavformat/spdifenc.c
76 76
    /* AVOptions: */
77 77
    int dtshd_rate;
78 78
    int dtshd_fallback;
79
#define SPDIF_FLAG_BIGENDIAN    0x01
80
    int spdif_flags;
79 81

  
80 82
    /// function, which generates codec dependent header information.
81 83
    /// Sets data_type and pkt_offset, and length_code, out_bytes, out_buf if necessary
......
83 85
} IEC61937Context;
84 86

  
85 87
static const AVOption options[] = {
88
{ "spdif_flags", "IEC 61937 encapsulation flags", offsetof(IEC61937Context, spdif_flags), FF_OPT_TYPE_FLAGS, 0, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "spdif_flags" },
89
{ "be", "output in big-endian format (for use as s16be)", 0, FF_OPT_TYPE_CONST, SPDIF_FLAG_BIGENDIAN, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "spdif_flags" },
86 90
{ "dtshd_rate", "mux complete DTS frames in HD mode at the specified IEC958 rate (in Hz, default 0=disabled)", offsetof(IEC61937Context, dtshd_rate), FF_OPT_TYPE_INT, 0, 0, 768000, AV_OPT_FLAG_ENCODING_PARAM },
87 91
{ "dtshd_fallback_time", "min secs to strip HD for after an overflow (-1: till the end, default 60)", offsetof(IEC61937Context, dtshd_fallback), FF_OPT_TYPE_INT, 60, -1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
88 92
{ NULL },
......
477 481
    return 0;
478 482
}
479 483

  
484
static av_always_inline void spdif_put_16(IEC61937Context *ctx,
485
                                          ByteIOContext *pb, unsigned int val)
486
{
487
    if (ctx->spdif_flags & SPDIF_FLAG_BIGENDIAN)
488
        put_be16(pb, val);
489
    else
490
        put_le16(pb, val);
491
}
492

  
480 493
static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt)
481 494
{
482 495
    IEC61937Context *ctx = s->priv_data;
......
501 514
    }
502 515

  
503 516
    if (ctx->use_preamble) {
504
        put_le16(s->pb, SYNCWORD1);       //Pa
505
        put_le16(s->pb, SYNCWORD2);       //Pb
506
        put_le16(s->pb, ctx->data_type);  //Pc
507
        put_le16(s->pb, ctx->length_code);//Pd
517
        spdif_put_16(ctx, s->pb, SYNCWORD1);       //Pa
518
        spdif_put_16(ctx, s->pb, SYNCWORD2);       //Pb
519
        spdif_put_16(ctx, s->pb, ctx->data_type);  //Pc
520
        spdif_put_16(ctx, s->pb, ctx->length_code);//Pd
508 521
    }
509 522

  
510
    if (HAVE_BIGENDIAN ^ ctx->extra_bswap) {
523
    if (ctx->extra_bswap ^ (ctx->spdif_flags & SPDIF_FLAG_BIGENDIAN)) {
511 524
    put_buffer(s->pb, ctx->out_buf, ctx->out_bytes & ~1);
512 525
    } else {
513 526
    av_fast_malloc(&ctx->buffer, &ctx->buffer_size, ctx->out_bytes + FF_INPUT_BUFFER_PADDING_SIZE);
......
517 530
    put_buffer(s->pb, ctx->buffer, ctx->out_bytes & ~1);
518 531
    }
519 532

  
533
    /* a final lone byte has to be MSB aligned */
520 534
    if (ctx->out_bytes & 1)
521
        put_be16(s->pb, ctx->out_buf[ctx->out_bytes - 1]);
535
        spdif_put_16(ctx, s->pb, ctx->out_buf[ctx->out_bytes - 1] << 8);
522 536

  
523 537
    put_nbyte(s->pb, 0, padding);
524 538

  

Also available in: Unified diff