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 <andreas.rheinhardt@gmail.com>
This commit is contained in:
		
							parent
							
								
									a9ad8867c4
								
							
						
					
					
						commit
						95e9cf813e
					
				| @ -91,6 +91,7 @@ static int smacker_read_header(AVFormatContext *s) | |||||||
|     AVIOContext *pb = s->pb; |     AVIOContext *pb = s->pb; | ||||||
|     SmackerContext *smk = s->priv_data; |     SmackerContext *smk = s->priv_data; | ||||||
|     AVStream *st; |     AVStream *st; | ||||||
|  |     AVCodecParameters *par; | ||||||
|     uint32_t magic, width, height, flags, treesize; |     uint32_t magic, width, height, flags, treesize; | ||||||
|     int i, ret, pts_inc; |     int i, ret, pts_inc; | ||||||
|     int tbase; |     int tbase; | ||||||
| @ -129,6 +130,7 @@ static int smacker_read_header(AVFormatContext *s) | |||||||
|     if (!st) |     if (!st) | ||||||
|         return AVERROR(ENOMEM); |         return AVERROR(ENOMEM); | ||||||
| 
 | 
 | ||||||
|  |     smk->videoindex = st->index; | ||||||
|     /* Smacker uses 100000 as internal timebase */ |     /* Smacker uses 100000 as internal timebase */ | ||||||
|     if (pts_inc < 0) |     if (pts_inc < 0) | ||||||
|         pts_inc = -pts_inc; |         pts_inc = -pts_inc; | ||||||
| @ -137,19 +139,24 @@ static int smacker_read_header(AVFormatContext *s) | |||||||
|     tbase = 100000; |     tbase = 100000; | ||||||
|     av_reduce(&tbase, &pts_inc, tbase, pts_inc, (1UL << 31) - 1); |     av_reduce(&tbase, &pts_inc, tbase, pts_inc, (1UL << 31) - 1); | ||||||
|     avpriv_set_pts_info(st, 33, pts_inc, tbase); |     avpriv_set_pts_info(st, 33, pts_inc, tbase); | ||||||
|  |     st->duration = smk->frames; | ||||||
| 
 | 
 | ||||||
|     /* init video codec */ |     /* init video codec */ | ||||||
|     st->codecpar->width     = width; |     par = st->codecpar; | ||||||
|     st->codecpar->height    = height; |     par->width      = width; | ||||||
|     st->codecpar->codec_tag = magic; |     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(st->codecpar, treesize + 16)) < 0) { |     if ((ret = ff_alloc_extradata(par, treesize + 16)) < 0) { | ||||||
|         av_log(s, AV_LOG_ERROR, |         av_log(s, AV_LOG_ERROR, | ||||||
|                "Cannot allocate %"PRIu32" bytes of extradata\n", |                "Cannot allocate %"PRIu32" bytes of extradata\n", | ||||||
|                treesize + 16); |                treesize + 16); | ||||||
|         return ret; |         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; |         return ret; | ||||||
| 
 | 
 | ||||||
|     /* handle possible audio streams */ |     /* handle possible audio streams */ | ||||||
| @ -161,38 +168,42 @@ static int smacker_read_header(AVFormatContext *s) | |||||||
| 
 | 
 | ||||||
|         if (rate) { |         if (rate) { | ||||||
|             AVStream *ast = avformat_new_stream(s, NULL); |             AVStream *ast = avformat_new_stream(s, NULL); | ||||||
|  |             AVCodecParameters *par; | ||||||
|             if (!ast) |             if (!ast) | ||||||
|                 return AVERROR(ENOMEM); |                 return AVERROR(ENOMEM); | ||||||
| 
 | 
 | ||||||
|             smk->indexes[i] = ast->index; |             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) { |             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) { |             } 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) { |             } else if (aflag & SMK_AUD_PACKED) { | ||||||
|                 ast->codecpar->codec_id  = AV_CODEC_ID_SMACKAUDIO; |                 par->codec_id  = AV_CODEC_ID_SMACKAUDIO; | ||||||
|                 ast->codecpar->codec_tag = MKTAG('S', 'M', 'K', 'A'); |                 par->codec_tag = MKTAG('S', 'M', 'K', 'A'); | ||||||
|             } else { |             } else { | ||||||
|                 ast->codecpar->codec_id  = AV_CODEC_ID_PCM_U8; |                 par->codec_id  = AV_CODEC_ID_PCM_U8; | ||||||
|             } |             } | ||||||
|             if (aflag & SMK_AUD_STEREO) { |             if (aflag & SMK_AUD_STEREO) { | ||||||
|                 ast->codecpar->channels       = 2; |                 par->channels       = 2; | ||||||
|                 ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; |                 par->channel_layout = AV_CH_LAYOUT_STEREO; | ||||||
|             } else { |             } else { | ||||||
|                 ast->codecpar->channels       = 1; |                 par->channels       = 1; | ||||||
|                 ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO; |                 par->channel_layout = AV_CH_LAYOUT_MONO; | ||||||
|             } |             } | ||||||
|             ast->codecpar->sample_rate = rate; |             par->sample_rate = rate; | ||||||
|             ast->codecpar->bits_per_coded_sample = (aflag & SMK_AUD_16BITS) ? 16 : 8; |             par->bits_per_coded_sample = (aflag & SMK_AUD_16BITS) ? 16 : 8; | ||||||
|             if (ast->codecpar->bits_per_coded_sample == 16 && |             if (par->bits_per_coded_sample == 16 && | ||||||
|                 ast->codecpar->codec_id == AV_CODEC_ID_PCM_U8) |                 par->codec_id == AV_CODEC_ID_PCM_U8) | ||||||
|                 ast->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; |                 par->codec_id = AV_CODEC_ID_PCM_S16LE; | ||||||
|             avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate |             avpriv_set_pts_info(ast, 64, 1, par->sample_rate * par->channels | ||||||
|                     * ast->codecpar->channels * ast->codecpar->bits_per_coded_sample / 8); |                                             * par->bits_per_coded_sample / 8); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|     avio_rl32(pb); /* padding */ |     avio_rl32(pb); /* padding */ | ||||||
|  | 
 | ||||||
|     /* setup data */ |     /* setup data */ | ||||||
|     smk->frm_size  = av_malloc_array(smk->frames, sizeof(*smk->frm_size)); |     smk->frm_size  = av_malloc_array(smk->frames, sizeof(*smk->frm_size)); | ||||||
|     smk->frm_flags = av_malloc(smk->frames); |     smk->frm_flags = av_malloc(smk->frames); | ||||||
| @ -210,15 +221,9 @@ static int smacker_read_header(AVFormatContext *s) | |||||||
|         smk->frm_flags[i] = avio_r8(pb); |         smk->frm_flags[i] = avio_r8(pb); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     smk->videoindex = st->index; |  | ||||||
|     st->codecpar->format = AV_PIX_FMT_PAL8; |  | ||||||
|     st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; |  | ||||||
|     st->codecpar->codec_id = AV_CODEC_ID_SMACKVIDEO; |  | ||||||
|     st->duration = smk->frames; |  | ||||||
| 
 |  | ||||||
|     /* load trees to extradata, they will be unpacked by decoder */ |     /* load trees to extradata, they will be unpacked by decoder */ | ||||||
|     ret = avio_read(pb, st->codecpar->extradata + 16, st->codecpar->extradata_size - 16); |     ret = avio_read(pb, par->extradata + 16, par->extradata_size - 16); | ||||||
|     if(ret != st->codecpar->extradata_size - 16){ |     if (ret != par->extradata_size - 16) { | ||||||
|         av_freep(&smk->frm_size); |         av_freep(&smk->frm_size); | ||||||
|         av_freep(&smk->frm_flags); |         av_freep(&smk->frm_flags); | ||||||
|         return AVERROR(EIO); |         return AVERROR(EIO); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user