Review in patch form, I fixed things which looked strange in git show -w
please squash, the rest looks ok or was whitespace only

Janne
---
 libavformat/nutenc.c | 90 ++++++++++++++++++++++------------------------------
 1 file changed, 38 insertions(+), 52 deletions(-)

diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 4e35e28..581a202 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -45,13 +45,13 @@ static int find_expected_header(AVCodecContext *c, int 
size, int key_frame,
             out[3] = 0xB6;
             return 4;
         }
-    } else if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO || c->codec_id ==
-               AV_CODEC_ID_MPEG2VIDEO) {
+    } else if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO ||
+               c->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
         return 3;
     } else if (c->codec_id == AV_CODEC_ID_H264) {
         return 3;
-    } else if (c->codec_id == AV_CODEC_ID_MP3 || c->codec_id ==
-               AV_CODEC_ID_MP2) {
+    } else if (c->codec_id == AV_CODEC_ID_MP3 ||
+               c->codec_id == AV_CODEC_ID_MP2) {
         int lsf, mpeg25, sample_rate_index, bitrate_index, frame_size;
         int layer           = c->codec_id == AV_CODEC_ID_MP3 ? 3 : 2;
         unsigned int header = 0xFFF00000;
@@ -71,9 +71,8 @@ static int find_expected_header(AVCodecContext *c, int size, 
int key_frame,
         for (bitrate_index = 2; bitrate_index < 30; bitrate_index++) {
             frame_size =
                 avpriv_mpa_bitrate_tab[lsf][layer - 1][bitrate_index >> 1];
-            frame_size =
-                (frame_size *
-                 144000) / (sample_rate << lsf) + (bitrate_index & 1);
+            frame_size = (frame_size * 144000) / (sample_rate << lsf) +
+                (bitrate_index & 1);
 
             if (frame_size == size)
                 break;
@@ -108,8 +107,7 @@ static int find_header_idx(AVFormatContext *s, 
AVCodecContext *c, int size,
     int len = find_expected_header(c, size, frame_type, out);
 
     for (i = 1; i < nut->header_count; i++) {
-        if (len == nut->header_len[i]
-            && !memcmp(out, nut->header[i], len)) {
+        if (len == nut->header_len[i] && !memcmp(out, nut->header[i], len)) {
             return i;
         }
     }
@@ -164,19 +162,15 @@ static void build_frame_code(AVFormatContext *s)
     }
 
     for (stream_id = 0; stream_id < s->nb_streams; stream_id++) {
-        int start2 = start +
-                     (end - start) * stream_id / s->nb_streams;
-        int end2 = start +
-                   (end - start) * (stream_id + 1) / s->nb_streams;
+        int start2 = start + (end - start) * stream_id       / s->nb_streams;
+        int end2   = start + (end - start) * (stream_id + 1) / s->nb_streams;
         AVCodecContext *codec = s->streams[stream_id]->codec;
         int is_audio          = codec->codec_type == AVMEDIA_TYPE_AUDIO;
         int intra_only        = /*codec->intra_only || */ is_audio;
         int pred_count;
 
         for (key_frame = 0; key_frame < 2; key_frame++) {
-            if (intra_only && keyframe_0_esc && key_frame == 0)
-                continue;
-            else {
+            if (!intra_only || !keyframe_0_esc || key_frame != 0) {
                 FrameCode *ft = &nut->frame_code[start2];
                 ft->flags     = FLAG_KEY * key_frame;
                 ft->flags    |= FLAG_SIZE_MSB | FLAG_CODED_PTS;
@@ -201,9 +195,7 @@ static void build_frame_code(AVFormatContext *s)
                     ft->size_mul   = frame_bytes + 2;
                     ft->size_lsb   = frame_bytes + pred;
                     ft->pts_delta  = pts;
-                    ft->header_idx =
-                        find_header_idx(s, codec, frame_bytes + pred,
-                                        key_frame);
+                    ft->header_idx = find_header_idx(s, codec, frame_bytes + 
pred, key_frame);
                     start2++;
                 }
         } else {
@@ -252,9 +244,9 @@ static void build_frame_code(AVFormatContext *s)
     }
     memmove(&nut->frame_code['N' + 1], &nut->frame_code['N'],
             sizeof(FrameCode) * (255 - 'N'));
-    nut->frame_code[0].flags           =
-        nut->frame_code[255].flags     =
-            nut->frame_code['N'].flags = FLAG_INVALID;
+    nut->frame_code[0].flags       =
+        nut->frame_code[255].flags =
+        nut->frame_code['N'].flags = FLAG_INVALID;
 }
 
 static void put_tt(NUTContext *nut, AVRational *time_base, AVIOContext *bc,
@@ -374,18 +366,13 @@ static void write_mainheader(NUTContext *nut, AVIOContext 
*bc)
                 j--;
                 continue;
             }
-            if (nut->frame_code[i].pts_delta != tmp_pts)
-                break;
-            if (nut->frame_code[i].flags != tmp_flags)
-                break;
-            if (nut->frame_code[i].stream_id != tmp_stream)
-                break;
-            if (nut->frame_code[i].size_mul != tmp_mul)
-                break;
-            if (nut->frame_code[i].size_lsb != tmp_size + j)
-                break;
-//            if(nut->frame_code[i].res       != tmp_res   ) break;
-            if (nut->frame_code[i].header_idx != tmp_head_idx)
+            if (nut->frame_code[i].pts_delta  != tmp_pts      ||
+                nut->frame_code[i].flags      != tmp_flags    ||
+                nut->frame_code[i].stream_id  != tmp_stream   ||
+                nut->frame_code[i].size_mul   != tmp_mul      ||
+                nut->frame_code[i].size_lsb   != tmp_size + j ||
+//              nut->frame_code[i].res        != tmp_res      ||
+                nut->frame_code[i].header_idx != tmp_head_idx)
                 break;
         }
         if (j != tmp_mul - tmp_size)
@@ -426,13 +413,17 @@ static int write_streamheader(AVFormatContext *avctx, 
AVIOContext *bc,
 
     ff_put_v(bc, i);
     switch (codec->codec_type) {
-    case AVMEDIA_TYPE_VIDEO: ff_put_v(bc, 0);
+    case AVMEDIA_TYPE_VIDEO:
+        ff_put_v(bc, 0);
         break;
-    case AVMEDIA_TYPE_AUDIO: ff_put_v(bc, 1);
+    case AVMEDIA_TYPE_AUDIO:
+        ff_put_v(bc, 1);
         break;
-    case AVMEDIA_TYPE_SUBTITLE: ff_put_v(bc, 2);
+    case AVMEDIA_TYPE_SUBTITLE:
+        ff_put_v(bc, 2);
         break;
-    default: ff_put_v(bc, 3);
+    default:
+        ff_put_v(bc, 3);
         break;
     }
     ff_put_v(bc, 4);
@@ -466,8 +457,8 @@ static int write_streamheader(AVFormatContext *avctx, 
AVIOContext *bc,
         ff_put_v(bc, codec->width);
         ff_put_v(bc, codec->height);
 
-        if (st->sample_aspect_ratio.num <= 0 || st->sample_aspect_ratio.den <=
-            0) {
+        if (st->sample_aspect_ratio.num <= 0 ||
+            st->sample_aspect_ratio.den <= 0) {
             ff_put_v(bc, 0);
             ff_put_v(bc, 0);
         } else {
@@ -594,9 +585,8 @@ static int write_headers(AVFormatContext *avctx, 
AVIOContext *bc)
         ret = avio_open_dyn_buf(&dyn_bc);
         if (ret < 0)
             return ret;
-        if ((ret =
-                 write_streamheader(avctx, dyn_bc, nut->avf->streams[i],
-                                    i)) < 0)
+        ret = write_streamheader(avctx, dyn_bc, nut->avf->streams[i], i);
+        if (ret < 0)
             return ret;
         put_packet(nut, bc, dyn_bc, 1, STREAM_STARTCODE);
     }
@@ -734,13 +724,12 @@ static int get_needed_flags(NUTContext *nut, 
StreamContext *nus, FrameCode *fc,
         flags |= FLAG_CODED_PTS;
     if (pkt->size > 2 * nut->max_distance)
         flags |= FLAG_CHECKSUM;
-    if (FFABS(pkt->pts - nus->last_pts)
-        > nus->max_pts_distance)
+    if (FFABS(pkt->pts - nus->last_pts) > nus->max_pts_distance)
         flags |= FLAG_CHECKSUM;
     if (pkt->size < nut->header_len[fc->header_idx] ||
         (pkt->size > 4096 && fc->header_idx)        ||
         memcmp(pkt->data, nut->header[fc->header_idx],
-                  nut->header_len[fc->header_idx]))
+               nut->header_len[fc->header_idx]))
         flags |= FLAG_HEADER_IDX;
 
     return flags | (fc->flags & FLAG_CODED);
@@ -799,12 +788,9 @@ static int nut_write_packet(AVFormatContext *s, AVPacket 
*pkt)
         ff_nut_reset_ts(nut, *nus->time_base, pkt->dts);
         for (i = 0; i < s->nb_streams; i++) {
             AVStream *st   = s->streams[i];
-            int64_t dts_tb = av_rescale_rnd(
-                pkt->dts,
-                nus->time_base->num *
-                (int64_t)nut->stream[i].time_base->den,
-                nus->time_base->den *
-                (int64_t)nut->stream[i].time_base->num,
+            int64_t dts_tb = av_rescale_rnd(pkt->dts,
+                nus->time_base->num * (int64_t)nut->stream[i].time_base->den,
+                nus->time_base->den * (int64_t)nut->stream[i].time_base->num,
                 AV_ROUND_DOWN);
             int index = av_index_search_timestamp(st, dts_tb,
                                                   AVSEEK_FLAG_BACKWARD);
-- 
1.7.12.4

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to