Cleanup and reindent.
---
 libavformat/flvenc.c |  129 ++++++++++++++++++++++++++-----------------------
 1 files changed, 68 insertions(+), 61 deletions(-)

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 8f06f1f..c14bb16 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -72,7 +72,8 @@ static int get_audio_flags(AVFormatContext *s, AVCodecContext 
*enc)
         return FLV_CODECID_AAC | FLV_SAMPLERATE_44100HZ | 
FLV_SAMPLESSIZE_16BIT | FLV_STEREO;
     else if (enc->codec_id == CODEC_ID_SPEEX) {
         if (enc->sample_rate != 16000) {
-            av_log(s, AV_LOG_ERROR, "flv only supports wideband (16kHz) Speex 
audio\n");
+            av_log(s, AV_LOG_ERROR,
+                   "flv only supports wideband (16kHz) Speex audio\n");
             return -1;
         }
         if (enc->channels != 1) {
@@ -81,7 +82,7 @@ static int get_audio_flags(AVFormatContext *s, AVCodecContext 
*enc)
         }
         return FLV_CODECID_SPEEX | FLV_SAMPLERATE_11025HZ | 
FLV_SAMPLESSIZE_16BIT;
     } else {
-    switch (enc->sample_rate) {
+        switch (enc->sample_rate) {
         case    44100:
             flags |= FLV_SAMPLERATE_44100HZ;
             break;
@@ -99,16 +100,18 @@ static int get_audio_flags(AVFormatContext *s, 
AVCodecContext *enc)
                 break;
             }
         default:
-            av_log(s, AV_LOG_ERROR, "flv does not support that sample rate, 
choose from (44100, 22050, 11025).\n");
+            av_log(s, AV_LOG_ERROR,
+                   "flv does not support that sample rate, choose from "
+                   "(44100, 22050, 11025).\n");
             return -1;
-    }
+        }
     }
 
     if (enc->channels > 1) {
         flags |= FLV_STEREO;
     }
 
-    switch(enc->codec_id){
+    switch(enc->codec_id) {
     case CODEC_ID_MP3:
         flags |= FLV_CODECID_MP3    | FLV_SAMPLESSIZE_16BIT;
         break;
@@ -153,14 +156,14 @@ static void put_amf_string(AVIOContext *pb, const char 
*str)
 
 static void put_avc_eos_tag(AVIOContext *pb, unsigned ts) {
     avio_w8(pb, FLV_TAG_TYPE_VIDEO);
-    avio_wb24(pb, 5);  /* Tag Data Size */
-    avio_wb24(pb, ts);  /* lower 24 bits of timestamp in ms*/
-    avio_w8(pb, (ts >> 24) & 0x7F);  /* MSB of ts in ms*/
-    avio_wb24(pb, 0);  /* StreamId = 0 */
-    avio_w8(pb, 23);  /* ub[4] FrameType = 1, ub[4] CodecId = 7 */
-    avio_w8(pb, 2);  /* AVC end of sequence */
-    avio_wb24(pb, 0);  /* Always 0 for AVC EOS. */
-    avio_wb32(pb, 16);  /* Size of FLV tag */
+    avio_wb24(pb, 5);               // Tag Data Size
+    avio_wb24(pb, ts);              // lower 24 bits of timestamp in ms
+    avio_w8(pb, (ts >> 24) & 0x7F); // MSB of ts in ms
+    avio_wb24(pb, 0);               // StreamId = 0
+    avio_w8(pb, 23);                // ub[4] FrameType = 1, ub[4] CodecId = 7
+    avio_w8(pb, 2);                 // AVC end of sequence
+    avio_wb24(pb, 0);               // Always 0 for AVC EOS
+    avio_wb32(pb, 16);              // Size of FLV tag
 }
 
 static void put_amf_double(AVIOContext *pb, double d)
@@ -184,34 +187,36 @@ static int flv_write_header(AVFormatContext *s)
     int64_t metadata_size_pos, data_size, metadata_count_pos;
     AVDictionaryEntry *tag = NULL;
 
-    for(i=0; i<s->nb_streams; i++){
+    for (i=0; i<s->nb_streams; i++) {
         AVCodecContext *enc = s->streams[i]->codec;
         FLVStreamContext *sc;
         switch (enc->codec_type) {
         case AVMEDIA_TYPE_VIDEO:
-            if (s->streams[i]->r_frame_rate.den && 
s->streams[i]->r_frame_rate.num) {
+            if (s->streams[i]->r_frame_rate.den &&
+                s->streams[i]->r_frame_rate.num) {
                 framerate = av_q2d(s->streams[i]->r_frame_rate);
             } else {
                 framerate = 1/av_q2d(s->streams[i]->codec->time_base);
             }
             video_enc = enc;
             if(enc->codec_tag == 0) {
-                av_log(s, AV_LOG_ERROR, "video codec not compatible with 
flv\n");
+                av_log(s, AV_LOG_ERROR,
+                       "video codec not compatible with flv\n");
                 return AVERROR_INVALIDDATA;
             }
-        break;
+            break;
         case AVMEDIA_TYPE_AUDIO:
             audio_enc = enc;
             if (get_audio_flags(s, enc) < 0)
                 return AVERROR_INVALIDDATA;
-        break;
+            break;
         case AVMEDIA_TYPE_DATA:
             if (enc->codec_id != CODEC_ID_TEXT) {
                 av_log(s, AV_LOG_ERROR, "codec not compatible with flv\n");
                 return AVERROR_INVALIDDATA;
             }
             data_enc = enc;
-        break;
+            break;
         default:
             av_log(s, AV_LOG_ERROR, "codec not compatible with flv\n");
             return AVERROR_INVALIDDATA;
@@ -229,24 +234,24 @@ static int flv_write_header(AVFormatContext *s)
     avio_write(pb, "FLV", 3);
     avio_w8(pb,1);
     avio_w8(pb,   FLV_HEADER_FLAG_HASAUDIO * !!audio_enc
-                 + FLV_HEADER_FLAG_HASVIDEO * !!video_enc);
+                + FLV_HEADER_FLAG_HASVIDEO * !!video_enc);
     avio_wb32(pb,9);
     avio_wb32(pb,0);
 
     for(i=0; i<s->nb_streams; i++){
         if(s->streams[i]->codec->codec_tag == 5){
-            avio_w8(pb,8); // message type
-            avio_wb24(pb,0); // include flags
-            avio_wb24(pb,0); // time stamp
-            avio_wb32(pb,0); // reserved
-            avio_wb32(pb,11); // size
-            flv->reserved=5;
+            avio_w8(pb, 8);    // message type
+            avio_wb24(pb,  0); // include flags
+            avio_wb24(pb,  0); // time stamp
+            avio_wb32(pb,  0); // reserved
+            avio_wb32(pb, 11); // size
+            flv->reserved = 5;
         }
     }
 
     /* write meta_tag */
     avio_w8(pb, 18);         // tag type META
-    metadata_size_pos= avio_tell(pb);
+    metadata_size_pos = avio_tell(pb);
     avio_wb24(pb, 0);          // size of data part (sum of all parts below)
     avio_wb24(pb, 0);          // time stamp
     avio_wb32(pb, 0);          // reserved
@@ -268,10 +273,11 @@ static int flv_write_header(AVFormatContext *s)
     avio_wb32(pb, metadata_count);
 
     put_amf_string(pb, "duration");
-    flv->duration_offset= avio_tell(pb);
-    put_amf_double(pb, s->duration / AV_TIME_BASE); // fill in the guessed 
duration, it'll be corrected later if incorrect
+    flv->duration_offset = avio_tell(pb);
+    // fill in the guessed duration, it will be updated later if incorrect
+    put_amf_double(pb, s->duration / AV_TIME_BASE);
 
-    if(video_enc){
+    if (video_enc) {
         put_amf_string(pb, "width");
         put_amf_double(pb, video_enc->width);
 
@@ -288,7 +294,7 @@ static int flv_write_header(AVFormatContext *s)
         put_amf_double(pb, video_enc->codec_tag);
     }
 
-    if(audio_enc){
+    if (audio_enc) {
         put_amf_string(pb, "audiodatarate");
         put_amf_double(pb, audio_enc->bit_rate / 1024.0);
 
@@ -318,7 +324,7 @@ static int flv_write_header(AVFormatContext *s)
     }
 
     put_amf_string(pb, "filesize");
-    flv->filesize_offset= avio_tell(pb);
+    flv->filesize_offset = avio_tell(pb);
     put_amf_double(pb, 0); // delayed write
 
     put_amf_string(pb, "");
@@ -380,7 +386,7 @@ static int flv_write_trailer(AVFormatContext *s)
         AVCodecContext *enc = s->streams[i]->codec;
         FLVStreamContext *sc = s->streams[i]->priv_data;
         if (enc->codec_type == AVMEDIA_TYPE_VIDEO &&
-                enc->codec_id == CODEC_ID_H264) {
+            enc->codec_id == CODEC_ID_H264) {
             put_avc_eos_tag(pb, sc->last_ts);
         }
     }
@@ -404,16 +410,16 @@ static int flv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
     FLVContext *flv = s->priv_data;
     FLVStreamContext *sc = s->streams[pkt->stream_index]->priv_data;
     unsigned ts;
-    int size= pkt->size;
-    uint8_t *data= NULL;
+    int size = pkt->size;
+    uint8_t *data = NULL;
     int flags, flags_size;
 
 //    av_log(s, AV_LOG_DEBUG, "type:%d pts: %"PRId64" size:%d\n", 
enc->codec_type, timestamp, size);
 
-    if(enc->codec_id == CODEC_ID_VP6 || enc->codec_id == CODEC_ID_VP6F ||
-       enc->codec_id == CODEC_ID_AAC)
+    if (enc->codec_id == CODEC_ID_VP6 || enc->codec_id == CODEC_ID_VP6F ||
+        enc->codec_id == CODEC_ID_AAC)
         flags_size= 2;
-    else if(enc->codec_id == CODEC_ID_H264)
+    else if (enc->codec_id == CODEC_ID_H264)
         flags_size= 5;
     else
         flags_size= 1;
@@ -429,22 +435,21 @@ static int flv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
         }
 
         flags |= pkt->flags & AV_PKT_FLAG_KEY ? FLV_FRAME_KEY : 
FLV_FRAME_INTER;
-    break;
+        break;
     case AVMEDIA_TYPE_AUDIO:
         flags = get_audio_flags(s, enc);
 
         assert(size);
 
         avio_w8(pb, FLV_TAG_TYPE_AUDIO);
-    break;
-
+        break;
     case AVMEDIA_TYPE_DATA:
         avio_w8(pb, FLV_TAG_TYPE_META);
-    break;
+        break;
     default:
         return AVERROR_INVALIDDATA;
-    break;
     }
+
     if (enc->codec_id == CODEC_ID_H264) {
         /* check if extradata looks like MP4 */
         if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) {
@@ -472,14 +477,15 @@ static int flv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
     if (sc->last_ts < ts)
         sc->last_ts = ts;
 
-    avio_wb24(pb,size + flags_size);
-    avio_wb24(pb,ts);
-    avio_w8(pb,(ts >> 24) & 0x7F); // timestamps are 32bits _signed_
-    avio_wb24(pb,flv->reserved);
+    avio_wb24(pb, size + flags_size);
+    avio_wb24(pb, ts);
+    avio_w8(pb, (ts >> 24) & 0x7F); // timestamps are 32bits _signed_
+    avio_wb24(pb, flv->reserved);
 
     if (enc->codec_type == AVMEDIA_TYPE_DATA) {
         int data_size;
         int metadata_size_pos = avio_tell(pb);
+
         avio_w8(pb, AMF_DATA_TYPE_STRING);
         put_amf_string(pb, "onTextData");
         avio_w8(pb, AMF_DATA_TYPE_MIXEDARRAY);
@@ -499,22 +505,23 @@ static int flv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
         avio_seek(pb, data_size + 10 - 3, SEEK_CUR);
         avio_wb32(pb, data_size + 11);
     } else {
-    avio_w8(pb,flags);
-    if (enc->codec_id == CODEC_ID_VP6)
-        avio_w8(pb,0);
-    if (enc->codec_id == CODEC_ID_VP6F)
-        avio_w8(pb, enc->extradata_size ? enc->extradata[0] : 0);
-    else if (enc->codec_id == CODEC_ID_AAC)
-        avio_w8(pb,1); // AAC raw
-    else if (enc->codec_id == CODEC_ID_H264) {
-        avio_w8(pb,1); // AVC NALU
-        avio_wb24(pb,pkt->pts - pkt->dts);
-    }
+        avio_w8(pb, flags);
+        if (enc->codec_id == CODEC_ID_VP6)
+            avio_w8(pb,0);
+        if (enc->codec_id == CODEC_ID_VP6F)
+            avio_w8(pb, enc->extradata_size ? enc->extradata[0] : 0);
+        else if (enc->codec_id == CODEC_ID_AAC)
+            avio_w8(pb,1); // AAC raw
+        else if (enc->codec_id == CODEC_ID_H264) {
+            avio_w8(pb,1); // AVC NALU
+            avio_wb24(pb,pkt->pts - pkt->dts);
+        }
 
-    avio_write(pb, data ? data : pkt->data, size);
+        avio_write(pb, data ? data : pkt->data, size);
 
-    avio_wb32(pb,size+flags_size+11); // previous tag size
-    flv->duration = FFMAX(flv->duration, pkt->pts + flv->delay + 
pkt->duration);
+        avio_wb32(pb, size + flags_size + 11); // previous tag size
+        flv->duration = FFMAX(flv->duration,
+                              pkt->pts + flv->delay + pkt->duration);
     }
     avio_flush(pb);
 
-- 
1.7.8.rc1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to