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

bwolowiec subversion at mplayerhq.hu
Tue Aug 4 21:38:17 CEST 2009


Author: bwolowiec
Date: Tue Aug  4 21:38:17 2009
New Revision: 4940

Log:
Cosmetic: fix indentation and break long lines

Modified:
   spdif/spdif.c

Modified: spdif/spdif.c
==============================================================================
--- spdif/spdif.c	Tue Aug  4 21:28:07 2009	(r4939)
+++ spdif/spdif.c	Tue Aug  4 21:38:17 2009	(r4940)
@@ -33,9 +33,9 @@
 #define IEC958_MPEG1_LAYER23      0x05
 //#define IEC958_MPEG2_EXT          0x06 /* With extension */
 #define IEC958_MPEG2_AAC          0x07
-#define IEC958_MPEG2_LAYER1_LSF   0x08 /* Low Sampling Frequency */
-#define IEC958_MPEG2_LAYER2_LSF   0x09 /* Low Sampling Frequency */
-#define IEC958_MPEG2_LAYER3_LSF   0x0A /* Low Sampling Frequency */
+#define IEC958_MPEG2_LAYER1_LSF   0x08  /* Low Sampling Frequency */
+#define IEC958_MPEG2_LAYER2_LSF   0x09  /* Low Sampling Frequency */
+#define IEC958_MPEG2_LAYER3_LSF   0x0A  /* Low Sampling Frequency */
 #define IEC958_DTS1               0x0B
 #define IEC958_DTS2               0x0C
 #define IEC958_DTS3               0x0D
@@ -43,60 +43,74 @@
 #define IEC958_MPEG2_AAC_LSF_4096 (0x13|0x20)
 //#define IEC958_EAC3               0x15
 
-typedef struct IEC958Context{
-    int data_type;  ///< Burst info
-    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);
+typedef struct IEC958Context {
+    int data_type;              ///< Burst info
+    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);
 } IEC958Context;
 
-static int spdif_header_ac3(AVFormatContext *s, AVPacket *pkt){
+static int spdif_header_ac3(AVFormatContext * s, AVPacket * pkt)
+{
     IEC958Context *ctx = s->priv_data;
     int bitstream_mode = pkt->data[6] & 0x7;
 
     ctx->data_type = IEC958_AC3 | (bitstream_mode << 8);
-    ctx->pkt_offset = AC3_FRAME_SIZE<<2;
+    ctx->pkt_offset = AC3_FRAME_SIZE << 2;
     return 0;
 }
 
-static int spdif_header_dts(AVFormatContext *s, AVPacket *pkt){
+static int spdif_header_dts(AVFormatContext * s, AVPacket * pkt)
+{
     IEC958Context *ctx = s->priv_data;
-    uint32_t syncword_dts = (pkt->data[0] << 24) | (pkt->data[1]<<16) | (pkt->data[2]<<8) | pkt->data[3];
+    uint32_t syncword_dts =
+        (pkt->data[0] << 24) | (pkt->data[1] << 16) | (pkt->
+                                                       data[2] << 8) |
+        pkt->data[3];
     int samples;
 
-    switch(syncword_dts){
-        case DCA_MARKER_RAW_BE:
-            samples = ((((pkt->data[4] & 0x01) << 6) | (pkt->data[5] >> 2)) + 1) << 5;
-            break;
-        case DCA_MARKER_RAW_LE:
-            samples = ((((pkt->data[5] & 0x01) << 6) | (pkt->data[4] >> 2)) + 1) << 5;
-            break;
-        case DCA_MARKER_14B_BE:
-            samples = ((((pkt->data[5] & 0x07) << 4) | (pkt->data[6] & 0x3f)) >> 2) << 5;
-            break;
-        case DCA_MARKER_14B_LE:
-            samples = ((((pkt->data[4] & 0x07) << 4) | (pkt->data[7] & 0x3f)) >> 2) << 5;
-            break;
-        default:
-            av_log(s, AV_LOG_ERROR, "bad DTS syncword\n");
-            return -1;
+    switch (syncword_dts) {
+    case DCA_MARKER_RAW_BE:
+        samples =
+            ((((pkt->data[4] & 0x01) << 6) | (pkt->data[5] >> 2)) +
+                                              1) << 5;
+        break;
+    case DCA_MARKER_RAW_LE:
+        samples =
+            ((((pkt->data[5] & 0x01) << 6) | (pkt->data[4] >> 2)) +
+                                              1) << 5;
+        break;
+    case DCA_MARKER_14B_BE:
+        samples =
+            ((((pkt->data[5] & 0x07) << 4) | (pkt->
+                                              data[6] & 0x3f)) >> 2) << 5;
+        break;
+    case DCA_MARKER_14B_LE:
+        samples =
+            ((((pkt->data[4] & 0x07) << 4) | (pkt->
+                                              data[7] & 0x3f)) >> 2) << 5;
+        break;
+    default:
+        av_log(s, AV_LOG_ERROR, "bad DTS syncword\n");
+        return -1;
     }
     av_log(s, AV_LOG_DEBUG, "samples=%i\n", samples);
-    switch(samples){
-        case 512:
-            ctx->data_type = IEC958_DTS1;
-            break;
-        case 1024:
-            ctx->data_type = IEC958_DTS2;
-            break;
-        case 2048:
-            ctx->data_type = IEC958_DTS3;
-            break;
-        default:
-            av_log(s, AV_LOG_ERROR, "%i samples in DTS frame not supported\n", samples);
-            return -1;
+    switch (samples) {
+    case 512:
+        ctx->data_type = IEC958_DTS1;
+        break;
+    case 1024:
+        ctx->data_type = IEC958_DTS2;
+        break;
+    case 2048:
+        ctx->data_type = IEC958_DTS3;
+        break;
+    default:
+        av_log(s, AV_LOG_ERROR, "%i samples in DTS frame not supported\n",
+               samples);
+        return -1;
     }
-    ctx->pkt_offset = samples<<2;
+    ctx->pkt_offset = samples << 2;
 
     return 0;
 }
@@ -113,68 +127,72 @@ static const uint16_t mpeg_pkt_offset[2]
     { 384,    1152,   1152 }, // MPEG1
 };
 
-static int spdif_header_mpeg(AVFormatContext *s, AVPacket *pkt){
+static int spdif_header_mpeg(AVFormatContext * s, AVPacket * pkt)
+{
     IEC958Context *ctx = s->priv_data;
-    int lsf = (pkt->data[1]>>3)&1;
-    int layer = 3-((pkt->data[1]>>1)&3);
+    int lsf = (pkt->data[1] >> 3) & 1;
+    int layer = 3 - ((pkt->data[1] >> 1) & 3);
 
     av_log(s, AV_LOG_DEBUG, "lsf: %i layer: %i\n", lsf, layer);
     ctx->data_type = mpeg_data_type[lsf][layer];
-    ctx->pkt_offset = mpeg_pkt_offset[lsf][layer]<<2;
+    ctx->pkt_offset = mpeg_pkt_offset[lsf][layer] << 2;
     // TODO Data type dependant info (normal/karaoke, dynamic range control)
     return 0;
 }
 
-static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt){
+static int spdif_header_aac(AVFormatContext * s, AVPacket * pkt)
+{
     IEC958Context *ctx = s->priv_data;
     AACADTSHeaderInfo hdr;
     GetBitContext gbc;
     int ret;
 
-    init_get_bits(&gbc, pkt->data, AAC_ADTS_HEADER_SIZE*8);
+    init_get_bits(&gbc, pkt->data, AAC_ADTS_HEADER_SIZE * 8);
     ret = ff_aac_parse_header(&gbc, &hdr);
 
-    ctx->pkt_offset = hdr.samples<<2;
-    switch(hdr.num_aac_frames){
-        case 1:
-            ctx->data_type = IEC958_MPEG2_AAC;
-            break;
-        case 2:
-            ctx->data_type = IEC958_MPEG2_AAC_LSF_2048;
-            break;
-        case 4:
-            ctx->data_type = IEC958_MPEG2_AAC_LSF_4096;
-            break;
-        default:
-            av_log(s, AV_LOG_ERROR, "%i samples in AAC frame not supported\n", hdr.samples);
-            return -1;
+    ctx->pkt_offset = hdr.samples << 2;
+    switch (hdr.num_aac_frames) {
+    case 1:
+        ctx->data_type = IEC958_MPEG2_AAC;
+        break;
+    case 2:
+        ctx->data_type = IEC958_MPEG2_AAC_LSF_2048;
+        break;
+    case 4:
+        ctx->data_type = IEC958_MPEG2_AAC_LSF_4096;
+        break;
+    default:
+        av_log(s, AV_LOG_ERROR, "%i samples in AAC frame not supported\n",
+               hdr.samples);
+        return -1;
     }
     //TODO Data type dependent info (LC profile/SBR)
     return 0;
 }
 
-static int spdif_write_header(AVFormatContext *s){
+static int spdif_write_header(AVFormatContext * s)
+{
     IEC958Context *ctx = s->priv_data;
 
-    switch(s->streams[0]->codec->codec_id){
-        case CODEC_ID_AC3:
-            ctx->header_info = spdif_header_ac3;
-            break;
-        case CODEC_ID_MP1:
-        case CODEC_ID_MP2:
-        case CODEC_ID_MP3:
-            ctx->header_info = spdif_header_mpeg;
-            break;
-        case CODEC_ID_DTS:
-            ctx->header_info = spdif_header_dts;
-            break;
-        case CODEC_ID_AAC:
-            ctx->header_info = spdif_header_aac;
-            break;
+    switch (s->streams[0]->codec->codec_id) {
+    case CODEC_ID_AC3:
+        ctx->header_info = spdif_header_ac3;
+        break;
+    case CODEC_ID_MP1:
+    case CODEC_ID_MP2:
+    case CODEC_ID_MP3:
+        ctx->header_info = spdif_header_mpeg;
+        break;
+    case CODEC_ID_DTS:
+        ctx->header_info = spdif_header_dts;
+        break;
+    case CODEC_ID_AAC:
+        ctx->header_info = spdif_header_aac;
+        break;
 
-        default:
-            av_log(s, AV_LOG_ERROR, "codec not supported\n");
-            return -1;
+    default:
+        av_log(s, AV_LOG_ERROR, "codec not supported\n");
+        return -1;
     }
     put_le16(s->pb, 0);
     put_le16(s->pb, 0);
@@ -183,14 +201,15 @@ static int spdif_write_header(AVFormatCo
     return 0;
 }
 
-static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt){
+static int spdif_write_packet(struct AVFormatContext *s, AVPacket * pkt)
+{
     IEC958Context *ctx = s->priv_data;
-    uint16_t *data = (uint16_t *)pkt->data;
+    uint16_t *data = (uint16_t *) pkt->data;
     int i;
 
-    ctx->pkt_size = ((pkt->size+1)>>1)<<4;
+    ctx->pkt_size = ((pkt->size + 1) >> 1) << 4;
 
-    (*ctx->header_info)(s, pkt);
+    (*ctx->header_info) (s, pkt);
 
     put_le16(s->pb, SYNCWORD1);      //Pa
     put_le16(s->pb, SYNCWORD2);      //Pb
@@ -198,22 +217,23 @@ static int spdif_write_packet(struct AVF
     put_le16(s->pb, ctx->pkt_size);  //Pd
 
     //XXX memcpy... ?
-    for(i=0; i<pkt->size>>1; i++)
+    for (i = 0; i < pkt->size >> 1; i++)
         put_be16(s->pb, data[i]);
 
-    if(pkt->size&1)
-        put_be16(s->pb, pkt->data[pkt->size-1]);
+    if (pkt->size & 1)
+        put_be16(s->pb, pkt->data[pkt->size - 1]);
 
-    i=(ctx->pkt_offset - BURST_HEADER_SIZE - pkt->size) >> 1;
-    if(i < 0){
+    i = (ctx->pkt_offset - BURST_HEADER_SIZE - pkt->size) >> 1;
+    if (i < 0) {
         av_log(s, AV_LOG_ERROR, "bitrate is too high\n");
         return -1;
     }
 
-    for(; i>0; i--)
+    for (; i > 0; i--)
         put_le16(s->pb, 0);
 
-    av_log(s, AV_LOG_DEBUG, "type=%x len=%i pkt_offset=%i\n", ctx->data_type, pkt->size, ctx->pkt_offset);
+    av_log(s, AV_LOG_DEBUG, "type=%x len=%i pkt_offset=%i\n",
+           ctx->data_type, pkt->size, ctx->pkt_offset);
 
     put_flush_packet(s->pb);
     return 0;
@@ -232,4 +252,3 @@ AVOutputFormat spdif_muxer = {
     NULL,
     //.flags=
 };
-


More information about the FFmpeg-soc mailing list