Browse code

avformat/dv: K&R formatting cosmetics

Diego Biurrun authored on 2013/08/06 09:55:02
Showing 1 changed files
... ...
@@ -63,7 +63,7 @@ static inline uint16_t dv_audio_12to16(uint16_t sample)
63 63
         shift--;
64 64
         result = (sample - (256 * shift)) << shift;
65 65
     } else {
66
-        shift = 0xe - shift;
66
+        shift  = 0xe - shift;
67 67
         result = ((sample + ((256 * shift) + 1)) << shift) - 1;
68 68
     }
69 69
 
... ...
@@ -75,19 +75,19 @@ static inline uint16_t dv_audio_12to16(uint16_t sample)
75 75
  * a fixed offset and if pack isn't there -- fails. We might want
76 76
  * to have a fallback mechanism for complete search of missing packs.
77 77
  */
78
-static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t)
78
+static const uint8_t *dv_extract_pack(uint8_t *frame, enum dv_pack_type t)
79 79
 {
80 80
     int offs;
81 81
 
82 82
     switch (t) {
83 83
     case dv_audio_source:
84
-        offs = (80*6 + 80*16*3 + 3);
84
+        offs = (80 * 6 + 80 * 16 * 3 + 3);
85 85
         break;
86 86
     case dv_audio_control:
87
-        offs = (80*6 + 80*16*4 + 3);
87
+        offs = (80 * 6 + 80 * 16 * 4 + 3);
88 88
         break;
89 89
     case dv_video_control:
90
-        offs = (80*5 + 48 + 5);
90
+        offs = (80 * 5 + 48 + 5);
91 91
         break;
92 92
     default:
93 93
         return NULL;
... ...
@@ -108,29 +108,29 @@ static const int dv_audio_frequency[3] = {
108 108
  * 3. Audio is always returned as 16bit linear samples: 12bit nonlinear samples
109 109
  *    are converted into 16bit linear ones.
110 110
  */
111
-static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4],
111
+static int dv_extract_audio(uint8_t *frame, uint8_t *ppcm[4],
112 112
                             const DVprofile *sys)
113 113
 {
114 114
     int size, chan, i, j, d, of, smpls, freq, quant, half_ch;
115 115
     uint16_t lc, rc;
116
-    const uint8_t* as_pack;
116
+    const uint8_t *as_pack;
117 117
     uint8_t *pcm, ipcm;
118 118
 
119 119
     as_pack = dv_extract_pack(frame, dv_audio_source);
120 120
     if (!as_pack)    /* No audio ? */
121 121
         return 0;
122 122
 
123
-    smpls =  as_pack[1] & 0x3f;       /* samples in this frame - min. samples */
124
-    freq  = (as_pack[4] >> 3) & 0x07; /* 0 - 48kHz, 1 - 44,1kHz, 2 - 32kHz */
125
-    quant =  as_pack[4] & 0x07;       /* 0 - 16bit linear, 1 - 12bit nonlinear */
123
+    smpls = as_pack[1]      & 0x3f; /* samples in this frame - min. samples */
124
+    freq  = as_pack[4] >> 3 & 0x07; /* 0 - 48kHz, 1 - 44,1kHz, 2 - 32kHz */
125
+    quant = as_pack[4]      & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */
126 126
 
127 127
     if (quant > 1)
128
-        return -1; /* unsupported quantization */
128
+        return -1;  /* unsupported quantization */
129 129
 
130 130
     if (freq >= FF_ARRAY_ELEMS(dv_audio_frequency))
131 131
         return AVERROR_INVALIDDATA;
132 132
 
133
-    size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */
133
+    size    = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */
134 134
     half_ch = sys->difseg_size / 2;
135 135
 
136 136
     /* We work with 720p frames split in half, thus even frames have
... ...
@@ -158,32 +158,41 @@ static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4],
158 158
             for (j = 0; j < 9; j++) {
159 159
                 for (d = 8; d < 80; d += 2) {
160 160
                     if (quant == 0) {  /* 16bit quantization */
161
-                        of = sys->audio_shuffle[i][j] + (d - 8) / 2 * sys->audio_stride;
162
-                        if (of*2 >= size)
161
+                        of = sys->audio_shuffle[i][j] +
162
+                             (d - 8) / 2 * sys->audio_stride;
163
+                        if (of * 2 >= size)
163 164
                             continue;
164 165
 
165
-                        pcm[of*2]   = frame[d+1]; // FIXME: maybe we have to admit
166
-                        pcm[of*2+1] = frame[d];   //        that DV is a big-endian PCM
167
-                        if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00)
168
-                            pcm[of*2+1] = 0;
166
+                        /* FIXME: maybe we have to admit that DV is a
167
+                         * big-endian PCM */
168
+                        pcm[of * 2]     = frame[d + 1];
169
+                        pcm[of * 2 + 1] = frame[d];
170
+
171
+                        if (pcm[of * 2 + 1] == 0x80 && pcm[of * 2] == 0x00)
172
+                            pcm[of * 2 + 1] = 0;
169 173
                     } else {           /* 12bit quantization */
170
-                        lc = ((uint16_t)frame[d]   << 4) |
171
-                             ((uint16_t)frame[d+2] >> 4);
172
-                        rc = ((uint16_t)frame[d+1] << 4) |
173
-                             ((uint16_t)frame[d+2] & 0x0f);
174
+                        lc = ((uint16_t)frame[d]     << 4) |
175
+                             ((uint16_t)frame[d + 2] >> 4);
176
+                        rc = ((uint16_t)frame[d + 1] << 4) |
177
+                             ((uint16_t)frame[d + 2] & 0x0f);
174 178
                         lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc));
175 179
                         rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc));
176 180
 
177
-                        of = sys->audio_shuffle[i%half_ch][j] + (d - 8) / 3 * sys->audio_stride;
178
-                        if (of*2 >= size)
181
+                        of = sys->audio_shuffle[i % half_ch][j] +
182
+                             (d - 8) / 3 * sys->audio_stride;
183
+                        if (of * 2 >= size)
179 184
                             continue;
180 185
 
181
-                        pcm[of*2]   = lc & 0xff; // FIXME: maybe we have to admit
182
-                        pcm[of*2+1] = lc >> 8;   //        that DV is a big-endian PCM
183
-                        of = sys->audio_shuffle[i%half_ch+half_ch][j] +
184
-                            (d - 8) / 3 * sys->audio_stride;
185
-                        pcm[of*2]   = rc & 0xff; // FIXME: maybe we have to admit
186
-                        pcm[of*2+1] = rc >> 8;   //        that DV is a big-endian PCM
186
+                        /* FIXME: maybe we have to admit that DV is a
187
+                         * big-endian PCM */
188
+                        pcm[of * 2]     = lc & 0xff;
189
+                        pcm[of * 2 + 1] = lc >> 8;
190
+                        of = sys->audio_shuffle[i % half_ch + half_ch][j] +
191
+                             (d - 8) / 3 * sys->audio_stride;
192
+                        /* FIXME: maybe we have to admit that DV is a
193
+                         * big-endian PCM */
194
+                        pcm[of * 2]     = rc & 0xff;
195
+                        pcm[of * 2 + 1] = rc >> 8;
187 196
                         ++d;
188 197
                     }
189 198
                 }
... ...
@@ -196,9 +205,9 @@ static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4],
196 196
     return size;
197 197
 }
198 198
 
199
-static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame)
199
+static int dv_extract_audio_info(DVDemuxContext *c, uint8_t *frame)
200 200
 {
201
-    const uint8_t* as_pack;
201
+    const uint8_t *as_pack;
202 202
     int freq, stype, smpls, quant, i, ach;
203 203
 
204 204
     as_pack = dv_extract_pack(frame, dv_audio_source);
... ...
@@ -207,10 +216,10 @@ static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame)
207 207
         return 0;
208 208
     }
209 209
 
210
-    smpls =  as_pack[1] & 0x3f;       /* samples in this frame - min. samples */
211
-    freq  = (as_pack[4] >> 3) & 0x07; /* 0 - 48kHz, 1 - 44,1kHz, 2 - 32kHz */
212
-    stype = (as_pack[3] & 0x1f);      /* 0 - 2CH, 2 - 4CH, 3 - 8CH */
213
-    quant =  as_pack[4] & 0x07;       /* 0 - 16bit linear, 1 - 12bit nonlinear */
210
+    smpls = as_pack[1]      & 0x3f; /* samples in this frame - min. samples */
211
+    freq  = as_pack[4] >> 3 & 0x07; /* 0 - 48kHz, 1 - 44,1kHz, 2 - 32kHz */
212
+    stype = as_pack[3]      & 0x1f; /* 0 - 2CH, 2 - 4CH, 3 - 8CH */
213
+    quant = as_pack[4]      & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */
214 214
 
215 215
     if (freq >= FF_ARRAY_ELEMS(dv_audio_frequency)) {
216 216
         av_log(c->fctx, AV_LOG_ERROR,
... ...
@@ -225,7 +234,7 @@ static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame)
225 225
     }
226 226
 
227 227
     /* note: ach counts PAIRS of channels (i.e. stereo channels) */
228
-    ach = ((int[4]){  1,  0,  2,  4})[stype];
228
+    ach = ((int[4]) { 1, 0, 2, 4 })[stype];
229 229
     if (ach == 1 && quant && freq == 2)
230 230
         ach = 2;
231 231
 
... ...
@@ -245,21 +254,21 @@ static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame)
245 245
             c->audio_pkt[i].stream_index = c->ast[i]->index;
246 246
             c->audio_pkt[i].flags       |= AV_PKT_FLAG_KEY;
247 247
         }
248
-        c->ast[i]->codec->sample_rate = dv_audio_frequency[freq];
249
-        c->ast[i]->codec->channels    = 2;
248
+        c->ast[i]->codec->sample_rate    = dv_audio_frequency[freq];
249
+        c->ast[i]->codec->channels       = 2;
250 250
         c->ast[i]->codec->channel_layout = AV_CH_LAYOUT_STEREO;
251
-        c->ast[i]->codec->bit_rate    = 2 * dv_audio_frequency[freq] * 16;
252
-        c->ast[i]->start_time         = 0;
251
+        c->ast[i]->codec->bit_rate       = 2 * dv_audio_frequency[freq] * 16;
252
+        c->ast[i]->start_time            = 0;
253 253
     }
254 254
     c->ach = i;
255 255
 
256
-    return (c->sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */;
256
+    return (c->sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */
257 257
 }
258 258
 
259
-static int dv_extract_video_info(DVDemuxContext *c, uint8_t* frame)
259
+static int dv_extract_video_info(DVDemuxContext *c, uint8_t *frame)
260 260
 {
261
-    const uint8_t* vsc_pack;
262
-    AVCodecContext* avctx;
261
+    const uint8_t *vsc_pack;
262
+    AVCodecContext *avctx;
263 263
     int apt, is16_9;
264 264
     int size = 0;
265 265
 
... ...
@@ -268,9 +277,9 @@ static int dv_extract_video_info(DVDemuxContext *c, uint8_t* frame)
268 268
 
269 269
         avpriv_set_pts_info(c->vst, 64, c->sys->time_base.num,
270 270
                             c->sys->time_base.den);
271
-        avctx->time_base= c->sys->time_base;
272
-        if (!avctx->width){
273
-            avctx->width = c->sys->width;
271
+        avctx->time_base = c->sys->time_base;
272
+        if (!avctx->width) {
273
+            avctx->width  = c->sys->width;
274 274
             avctx->height = c->sys->height;
275 275
         }
276 276
         avctx->pix_fmt = c->sys->pix_fmt;
... ...
@@ -281,18 +290,17 @@ static int dv_extract_video_info(DVDemuxContext *c, uint8_t* frame)
281 281
         is16_9   = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 ||
282 282
                                  (!apt && (vsc_pack[2] & 0x07) == 0x07)));
283 283
         c->vst->sample_aspect_ratio = c->sys->sar[is16_9];
284
-        avctx->bit_rate = av_rescale_q(c->sys->frame_size, (AVRational){8,1},
284
+        avctx->bit_rate = av_rescale_q(c->sys->frame_size,
285
+                                       (AVRational) { 8, 1 },
285 286
                                        c->sys->time_base);
286 287
         size = c->sys->frame_size;
287 288
     }
288 289
     return size;
289 290
 }
290 291
 
291
-/*
292
- * The following 3 functions constitute our interface to the world
293
- */
292
+/* The following 3 functions constitute our interface to the world */
294 293
 
295
-DVDemuxContext* avpriv_dv_init_demux(AVFormatContext *s)
294
+DVDemuxContext *avpriv_dv_init_demux(AVFormatContext *s)
296 295
 {
297 296
     DVDemuxContext *c;
298 297
 
... ...
@@ -322,9 +330,9 @@ int avpriv_dv_get_packet(DVDemuxContext *c, AVPacket *pkt)
322 322
 
323 323
     for (i = 0; i < c->ach; i++) {
324 324
         if (c->ast[i] && c->audio_pkt[i].size) {
325
-            *pkt = c->audio_pkt[i];
325
+            *pkt                 = c->audio_pkt[i];
326 326
             c->audio_pkt[i].size = 0;
327
-            size = pkt->size;
327
+            size                 = pkt->size;
328 328
             break;
329 329
         }
330 330
     }
... ...
@@ -333,10 +341,10 @@ int avpriv_dv_get_packet(DVDemuxContext *c, AVPacket *pkt)
333 333
 }
334 334
 
335 335
 int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
336
-                      uint8_t* buf, int buf_size)
336
+                             uint8_t *buf, int buf_size)
337 337
 {
338 338
     int size, i;
339
-    uint8_t *ppcm[4] = {0};
339
+    uint8_t *ppcm[4] = { 0 };
340 340
 
341 341
     if (buf_size < DV_PROFILE_BYTES ||
342 342
         !(c->sys = avpriv_dv_frame_profile(c->sys, buf, buf_size)) ||
... ...
@@ -349,7 +357,8 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
349 349
     size = dv_extract_audio_info(c, buf);
350 350
     for (i = 0; i < c->ach; i++) {
351 351
         c->audio_pkt[i].size = size;
352
-        c->audio_pkt[i].pts  = c->abytes * 30000 * 8 / c->ast[i]->codec->bit_rate;
352
+        c->audio_pkt[i].pts  = c->abytes * 30000 * 8 /
353
+                               c->ast[i]->codec->bit_rate;
353 354
         ppcm[i] = c->audio_buf[i];
354 355
     }
355 356
     if (c->ach)
... ...
@@ -362,7 +371,7 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
362 362
             c->audio_pkt[2].size = c->audio_pkt[3].size = 0;
363 363
         } else {
364 364
             c->audio_pkt[0].size = c->audio_pkt[1].size = 0;
365
-            c->abytes += size;
365
+            c->abytes           += size;
366 366
         }
367 367
     } else {
368 368
         c->abytes += size;
... ...
@@ -383,28 +392,31 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
383 383
 }
384 384
 
385 385
 static int64_t dv_frame_offset(AVFormatContext *s, DVDemuxContext *c,
386
-                              int64_t timestamp, int flags)
386
+                               int64_t timestamp, int flags)
387 387
 {
388 388
     // FIXME: sys may be wrong if last dv_read_packet() failed (buffer is junk)
389
-    const DVprofile* sys = avpriv_dv_codec_profile(c->vst->codec);
389
+    const DVprofile *sys = avpriv_dv_codec_profile(c->vst->codec);
390 390
     int64_t offset;
391
-    int64_t size = avio_size(s->pb) - s->data_offset;
392
-    int64_t max_offset = ((size-1) / sys->frame_size) * sys->frame_size;
391
+    int64_t size       = avio_size(s->pb) - s->data_offset;
392
+    int64_t max_offset = ((size - 1) / sys->frame_size) * sys->frame_size;
393 393
 
394 394
     offset = sys->frame_size * timestamp;
395 395
 
396
-    if (size >= 0 && offset > max_offset) offset = max_offset;
397
-    else if (offset < 0) offset = 0;
396
+    if (size >= 0 && offset > max_offset)
397
+        offset = max_offset;
398
+    else if (offset < 0)
399
+        offset = 0;
398 400
 
399 401
     return offset + s->data_offset;
400 402
 }
401 403
 
402 404
 void ff_dv_offset_reset(DVDemuxContext *c, int64_t frame_offset)
403 405
 {
404
-    c->frames= frame_offset;
406
+    c->frames = frame_offset;
405 407
     if (c->ach)
406
-        c->abytes= av_rescale_q(c->frames, c->sys->time_base,
407
-                                (AVRational){8, c->ast[0]->codec->bit_rate});
408
+        c->abytes = av_rescale_q(c->frames, c->sys->time_base,
409
+                                 (AVRational) { 8, c->ast[0]->codec->bit_rate });
410
+
408 411
     c->audio_pkt[0].size = c->audio_pkt[1].size = 0;
409 412
     c->audio_pkt[2].size = c->audio_pkt[3].size = 0;
410 413
 }
... ...
@@ -414,7 +426,7 @@ void ff_dv_offset_reset(DVDemuxContext *c, int64_t frame_offset)
414 414
  ************************************************************/
415 415
 
416 416
 typedef struct RawDVContext {
417
-    DVDemuxContext* dv_demux;
417
+    DVDemuxContext *dv_demux;
418 418
     uint8_t         buf[DV_MAX_FRAME_SIZE];
419 419
 } RawDVContext;
420 420
 
... ...
@@ -448,19 +460,22 @@ static int dv_read_header(AVFormatContext *s)
448 448
         avio_seek(s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0)
449 449
         return AVERROR(EIO);
450 450
 
451
-    c->dv_demux->sys = avpriv_dv_frame_profile(c->dv_demux->sys, c->buf, DV_PROFILE_BYTES);
451
+    c->dv_demux->sys = avpriv_dv_frame_profile(c->dv_demux->sys,
452
+                                               c->buf,
453
+                                               DV_PROFILE_BYTES);
452 454
     if (!c->dv_demux->sys) {
453
-        av_log(s, AV_LOG_ERROR, "Can't determine profile of DV input stream.\n");
455
+        av_log(s, AV_LOG_ERROR,
456
+               "Can't determine profile of DV input stream.\n");
454 457
         return -1;
455 458
     }
456 459
 
457
-    s->bit_rate = av_rescale_q(c->dv_demux->sys->frame_size, (AVRational){8,1},
460
+    s->bit_rate = av_rescale_q(c->dv_demux->sys->frame_size,
461
+                               (AVRational) { 8, 1 },
458 462
                                c->dv_demux->sys->time_base);
459 463
 
460 464
     return 0;
461 465
 }
462 466
 
463
-
464 467
 static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
465 468
 {
466 469
     int size;
... ...
@@ -482,7 +497,7 @@ static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
482 482
 }
483 483
 
484 484
 static int dv_read_seek(AVFormatContext *s, int stream_index,
485
-                       int64_t timestamp, int flags)
485
+                        int64_t timestamp, int flags)
486 486
 {
487 487
     RawDVContext *r   = s->priv_data;
488 488
     DVDemuxContext *c = r->dv_demux;
... ...
@@ -506,7 +521,7 @@ static int dv_probe(AVProbeData *p)
506 506
 {
507 507
     unsigned state, marker_pos = 0;
508 508
     int i;
509
-    int matches = 0;
509
+    int matches           = 0;
510 510
     int secondary_matches = 0;
511 511
 
512 512
     if (p->buf_size < 5)
... ...
@@ -527,10 +542,13 @@ static int dv_probe(AVProbeData *p)
527 527
         state = (state << 8) | p->buf[i];
528 528
     }
529 529
 
530
-    if (matches && p->buf_size / matches < 1024*1024) {
531
-        if (matches > 4 || (secondary_matches >= 10 && p->buf_size / secondary_matches < 24000))
532
-            return AVPROBE_SCORE_MAX*3/4; // not max to avoid dv in mov to match
533
-        return AVPROBE_SCORE_MAX/4;
530
+    if (matches && p->buf_size / matches < 1024 * 1024) {
531
+        if (matches > 4 ||
532
+            (secondary_matches >= 10 &&
533
+             p->buf_size / secondary_matches < 24000))
534
+            // not max to avoid dv in mov to match
535
+            return AVPROBE_SCORE_MAX * 3 / 4;
536
+        return AVPROBE_SCORE_MAX / 4;
534 537
     }
535 538
     return 0;
536 539
 }