[FFmpeg-cvslog] avformat/smacker: Cosmetics

2020-07-04 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Wed Jun 24 13:53:10 2020 +0200| [d534009f76133f9251676c25567710ee117f3bc8] | 
committer: Andreas Rheinhardt

avformat/smacker: Cosmetics

Mainly reindentation.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d534009f76133f9251676c25567710ee117f3bc8
---

 libavformat/smacker.c | 60 +--
 1 file changed, 29 insertions(+), 31 deletions(-)

diff --git a/libavformat/smacker.c b/libavformat/smacker.c
index 2e4a499a13..0ca5a87b8f 100644
--- a/libavformat/smacker.c
+++ b/libavformat/smacker.c
@@ -50,14 +50,14 @@ typedef struct SmackerContext {
 /* internal variables */
 int64_t next_frame_pos;
 int cur_frame;
+int videoindex;
+int indexes[7];
 /* current frame for demuxing */
 uint32_t frame_size;
 int flags;
 int next_audio_index;
 int new_palette;
 uint8_t pal[768];
-int indexes[7];
-int videoindex;
 int64_t aud_pts[7];
 } SmackerContext;
 
@@ -226,7 +226,6 @@ static int smacker_read_header(AVFormatContext *s)
 return 0;
 }
 
-
 static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
 SmackerContext *smk = s->priv_data;
@@ -243,7 +242,7 @@ static int smacker_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 flags = smk->frm_flags[smk->cur_frame];
 smk->flags = flags >> 1;
 /* handle palette change event */
-if(flags & SMACKER_PAL){
+if (flags & SMACKER_PAL) {
 int size, sz, t, off, j, pos;
 uint8_t *pal = smk->pal;
 uint8_t oldpal[768];
@@ -258,12 +257,12 @@ static int smacker_read_packet(AVFormatContext *s, 
AVPacket *pkt)
 smk->frame_size -= size--;
 sz = 0;
 pos = avio_tell(s->pb) + size;
-while(sz < 256){
+while (sz < 256) {
 t = avio_r8(s->pb);
-if(t & 0x80){ /* skip palette entries */
-sz += (t & 0x7F) + 1;
+if (t & 0x80) { /* skip palette entries */
+sz  +=  (t & 0x7F) + 1;
 pal += ((t & 0x7F) + 1) * 3;
-} else if(t & 0x40){ /* copy with offset */
+} else if (t & 0x40) { /* copy with offset */
 off = avio_r8(s->pb);
 j = (t & 0x3F) + 1;
 if (off + j > 0x100) {
@@ -274,7 +273,7 @@ static int smacker_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 goto next_frame;
 }
 off *= 3;
-while(j-- && sz < 256) {
+while (j-- && sz < 256) {
 *pal++ = oldpal[off + 0];
 *pal++ = oldpal[off + 1];
 *pal++ = oldpal[off + 2];
@@ -295,16 +294,16 @@ static int smacker_read_packet(AVFormatContext *s, 
AVPacket *pkt)
 
 for (int i = smk->next_audio_index; i < 7; i++) {
 if (smk->flags & (1 << i)) {
-uint32_t size;
+uint32_t size;
 
-size = avio_rl32(s->pb);
+size = avio_rl32(s->pb);
 if ((int)size < 8 || size > smk->frame_size) {
-av_log(s, AV_LOG_ERROR, "Invalid audio part size\n");
-ret = AVERROR_INVALIDDATA;
-goto next_frame;
-}
+av_log(s, AV_LOG_ERROR, "Invalid audio part size\n");
+ret = AVERROR_INVALIDDATA;
+goto next_frame;
+}
 smk->frame_size -= size;
-size   -= 4;
+size-= 4;
 
 if (smk->indexes[i] < 0) {
 avio_skip(s->pb, size);
@@ -312,36 +311,35 @@ static int smacker_read_packet(AVFormatContext *s, 
AVPacket *pkt)
 }
 if ((ret = av_get_packet(s->pb, pkt, size)) != size) {
 ret = ret < 0 ? ret : AVERROR_INVALIDDATA;
-goto next_frame;
-}
+goto next_frame;
+}
 pkt->stream_index = smk->indexes[i];
 pkt->pts  = smk->aud_pts[i];
 smk->aud_pts[i]  += AV_RL32(pkt->data);
 smk->next_audio_index = i + 1;
 return 0;
-}
 }
+}
 
 if (smk->frame_size >= INT_MAX/2) {
-ret = AVERROR_INVALIDDATA;
-goto next_frame;
-}
+ret = AVERROR_INVALIDDATA;
+goto next_frame;
+}
 if ((ret = av_new_packet(pkt, smk->frame_size + 769)) < 0)
-goto next_frame;
+goto next_frame;
 flags = smk->new_palette;
-if(smk->frm_size[smk->cur_frame] & 1)
+if (smk->frm_size[smk->cur_frame] & 1)
 flags |= 2;
 pkt->data[0] = flags;
-memcpy(pkt->data + 1, smk->pal, 768);
+memcpy(pkt->data + 1, smk->pal, 768);
 ret = ffio_read_size(s->pb, 

[FFmpeg-cvslog] avformat/smacker: Cosmetics

2020-04-08 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Sun Mar 29 10:28:29 2020 +0200| [95e9cf813e2610c0ffb39f5b276af6ea7f566315] | 
committer: Andreas Rheinhardt

avformat/smacker: Cosmetics

This is mainly about improving legibility of the code and getting rid of
overlong lines by using variables for st->codecpar instead of accessing
the codecparameters via st->codecpar->.

Also, some code has been moved to better fitting places.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=95e9cf813e2610c0ffb39f5b276af6ea7f566315
---

 libavformat/smacker.c | 75 +++
 1 file changed, 40 insertions(+), 35 deletions(-)

diff --git a/libavformat/smacker.c b/libavformat/smacker.c
index c934615c54..8b1e185817 100644
--- a/libavformat/smacker.c
+++ b/libavformat/smacker.c
@@ -91,6 +91,7 @@ static int smacker_read_header(AVFormatContext *s)
 AVIOContext *pb = s->pb;
 SmackerContext *smk = s->priv_data;
 AVStream *st;
+AVCodecParameters *par;
 uint32_t magic, width, height, flags, treesize;
 int i, ret, pts_inc;
 int tbase;
@@ -129,6 +130,7 @@ static int smacker_read_header(AVFormatContext *s)
 if (!st)
 return AVERROR(ENOMEM);
 
+smk->videoindex = st->index;
 /* Smacker uses 10 as internal timebase */
 if (pts_inc < 0)
 pts_inc = -pts_inc;
@@ -137,23 +139,28 @@ static int smacker_read_header(AVFormatContext *s)
 tbase = 10;
 av_reduce(, _inc, tbase, pts_inc, (1UL << 31) - 1);
 avpriv_set_pts_info(st, 33, pts_inc, tbase);
+st->duration = smk->frames;
 
 /* init video codec */
-st->codecpar->width = width;
-st->codecpar->height= height;
-st->codecpar->codec_tag = magic;
-
-if ((ret = ff_alloc_extradata(st->codecpar, treesize + 16)) < 0) {
+par = st->codecpar;
+par->width  = width;
+par->height = height;
+par->format = AV_PIX_FMT_PAL8;
+par->codec_type = AVMEDIA_TYPE_VIDEO;
+par->codec_id   = AV_CODEC_ID_SMACKVIDEO;
+par->codec_tag  = magic;
+
+if ((ret = ff_alloc_extradata(par, treesize + 16)) < 0) {
 av_log(s, AV_LOG_ERROR,
"Cannot allocate %"PRIu32" bytes of extradata\n",
treesize + 16);
 return ret;
 }
-if ((ret = ffio_read_size(pb, st->codecpar->extradata, 16)) < 0)
+if ((ret = ffio_read_size(pb, par->extradata, 16)) < 0)
 return ret;
 
 /* handle possible audio streams */
-for(i = 0; i < 7; i++) {
+for (i = 0; i < 7; i++) {
 uint32_t rate = avio_rl24(pb);
 uint8_t aflag = avio_r8(pb);
 
@@ -161,40 +168,44 @@ static int smacker_read_header(AVFormatContext *s)
 
 if (rate) {
 AVStream *ast = avformat_new_stream(s, NULL);
+AVCodecParameters *par;
 if (!ast)
 return AVERROR(ENOMEM);
 
 smk->indexes[i] = ast->index;
-ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
+par = ast->codecpar;
+par->codec_type = AVMEDIA_TYPE_AUDIO;
 if (aflag & SMK_AUD_BINKAUD) {
-ast->codecpar->codec_id  = AV_CODEC_ID_BINKAUDIO_RDFT;
+par->codec_id  = AV_CODEC_ID_BINKAUDIO_RDFT;
 } else if (aflag & SMK_AUD_USEDCT) {
-ast->codecpar->codec_id  = AV_CODEC_ID_BINKAUDIO_DCT;
+par->codec_id  = AV_CODEC_ID_BINKAUDIO_DCT;
 } else if (aflag & SMK_AUD_PACKED) {
-ast->codecpar->codec_id  = AV_CODEC_ID_SMACKAUDIO;
-ast->codecpar->codec_tag = MKTAG('S', 'M', 'K', 'A');
+par->codec_id  = AV_CODEC_ID_SMACKAUDIO;
+par->codec_tag = MKTAG('S', 'M', 'K', 'A');
 } else {
-ast->codecpar->codec_id  = AV_CODEC_ID_PCM_U8;
+par->codec_id  = AV_CODEC_ID_PCM_U8;
 }
 if (aflag & SMK_AUD_STEREO) {
-ast->codecpar->channels   = 2;
-ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
+par->channels   = 2;
+par->channel_layout = AV_CH_LAYOUT_STEREO;
 } else {
-ast->codecpar->channels   = 1;
-ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO;
+par->channels   = 1;
+par->channel_layout = AV_CH_LAYOUT_MONO;
 }
-ast->codecpar->sample_rate = rate;
-ast->codecpar->bits_per_coded_sample = (aflag & SMK_AUD_16BITS) ? 
16 : 8;
-if (ast->codecpar->bits_per_coded_sample == 16 &&
-ast->codecpar->codec_id == AV_CODEC_ID_PCM_U8)
-ast->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
-avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate
-* ast->codecpar->channels * 
ast->codecpar->bits_per_coded_sample / 8);
+par->sample_rate = rate;
+