Mostly cosmetic changes adding some intermediate to shorten the lines.
Unified · Split
| @@ -140,88 +140,103 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) · 139 unmodified lines | ||
| 140 | 140 | int ret = 0, i; |
| 141 | 141 | AVStream *st; |
| 142 | 142 | AVDictionary *tmp = NULL; |
| 143 | + AVCodecContext *codec = NULL; | |
| 144 | + AVOutputFormat *of = s->oformat; | |
| 143 | 145 | |
| 144 | 146 | if (options) |
| 145 | 147 | av_dict_copy(&tmp, *options, 0); |
| 148 | + | |
| 146 | 149 | if ((ret = av_opt_set_dict(s, &tmp)) < 0) |
| 147 | 150 | goto fail; |
| 148 | 151 | |
| 149 | 152 | // some sanity checks |
| 150 | − if (s->nb_streams == 0 && !(s->oformat->flags & AVFMT_NOSTREAMS)) { | |
| 153 | + if (s->nb_streams == 0 && !(of->flags & AVFMT_NOSTREAMS)) { | |
| 151 | 154 | av_log(s, AV_LOG_ERROR, "no streams\n"); |
| 152 | 155 | ret = AVERROR(EINVAL); |
| 153 | 156 | goto fail; |
| 154 | 157 | } |
| 155 | 158 | |
| 156 | 159 | for (i = 0; i < s->nb_streams; i++) { |
| 157 | − st = s->streams[i]; | |
| 160 | + st = s->streams[i]; | |
| 161 | + codec = st->codec; | |
| 158 | 162 | |
| 159 | − switch (st->codec->codec_type) { | |
| 163 | + switch (codec->codec_type) { | |
| 160 | 164 | case AVMEDIA_TYPE_AUDIO: |
| 161 | − if (st->codec->sample_rate <= 0) { | |
| 165 | + if (codec->sample_rate <= 0) { | |
| 162 | 166 | av_log(s, AV_LOG_ERROR, "sample rate not set\n"); |
| 163 | 167 | ret = AVERROR(EINVAL); |
| 164 | 168 | goto fail; |
| 165 | 169 | } |
| 166 | − if (!st->codec->block_align) | |
| 167 | − st->codec->block_align = st->codec->channels * | |
| 168 | − av_get_bits_per_sample(st->codec->codec_id) >> 3; | |
| 170 | + if (!codec->block_align) | |
| 171 | + codec->block_align = codec->channels * | |
| 172 | + av_get_bits_per_sample(codec->codec_id) >> 3; | |
| 169 | 173 | break; |
| 170 | 174 | case AVMEDIA_TYPE_VIDEO: |
| 171 | − if (st->codec->time_base.num <= 0 || st->codec->time_base.den <= 0) { //FIXME audio too? | |
| 175 | + if (codec->time_base.num <= 0 || | |
| 176 | + codec->time_base.den <= 0) { //FIXME audio too? | |
| 172 | 177 | av_log(s, AV_LOG_ERROR, "time base not set\n"); |
| 173 | 178 | ret = AVERROR(EINVAL); |
| 174 | 179 | goto fail; |
| 175 | 180 | } |
| 176 | − if ((st->codec->width <= 0 || st->codec->height <= 0) && !(s->oformat->flags & AVFMT_NODIMENSIONS)) { | |
| 181 | + | |
| 182 | + if ((codec->width <= 0 || codec->height <= 0) && | |
| 183 | + !(of->flags & AVFMT_NODIMENSIONS)) { | |
| 177 | 184 | av_log(s, AV_LOG_ERROR, "dimensions not set\n"); |
| 178 | 185 | ret = AVERROR(EINVAL); |
| 179 | 186 | goto fail; |
| 180 | 187 | } |
| 181 | − if (av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)) { | |
| 188 | + | |
| 189 | + if (av_cmp_q(st->sample_aspect_ratio, | |
| 190 | + codec->sample_aspect_ratio)) { | |
| 182 | 191 | av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between muxer " |
| 183 | 192 | "(%d/%d) and encoder layer (%d/%d)\n", |
| 184 | 193 | st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, |
| 185 | − st->codec->sample_aspect_ratio.num, | |
| 186 | − st->codec->sample_aspect_ratio.den); | |
| 194 | + codec->sample_aspect_ratio.num, | |
| 195 | + codec->sample_aspect_ratio.den); | |
| 187 | 196 | ret = AVERROR(EINVAL); |
| 188 | 197 | goto fail; |
| 189 | 198 | } |
| 190 | 199 | break; |
| 191 | 200 | } |
| 192 | 201 | |
| 193 | − if (s->oformat->codec_tag) { | |
| 194 | − if (st->codec->codec_tag && st->codec->codec_id == AV_CODEC_ID_RAWVIDEO && av_codec_get_tag(s->oformat->codec_tag, st->codec->codec_id) == 0 && !validate_codec_tag(s, st)) { | |
| 195 | − //the current rawvideo encoding system ends up setting the wrong codec_tag for avi, we override it here | |
| 196 | − st->codec->codec_tag = 0; | |
| 202 | + if (of->codec_tag) { | |
| 203 | + if (codec->codec_tag && | |
| 204 | + codec->codec_id == AV_CODEC_ID_RAWVIDEO && | |
| 205 | + !av_codec_get_tag(of->codec_tag, codec->codec_id) && | |
| 206 | + !validate_codec_tag(s, st)) { | |
| 207 | + // the current rawvideo encoding system ends up setting | |
| 208 | + // the wrong codec_tag for avi, we override it here | |
| 209 | + codec->codec_tag = 0; | |
| 197 | 210 | } |
| 198 | − if (st->codec->codec_tag) { | |
| 211 | + if (codec->codec_tag) { | |
| 199 | 212 | if (!validate_codec_tag(s, st)) { |
| 200 | 213 | char tagbuf[32]; |
| 201 | − av_get_codec_tag_string(tagbuf, sizeof(tagbuf), st->codec->codec_tag); | |
| 214 | + av_get_codec_tag_string(tagbuf, sizeof(tagbuf), codec->codec_tag); | |
| 202 | 215 | av_log(s, AV_LOG_ERROR, |
| 203 | 216 | "Tag %s/0x%08x incompatible with output codec id '%d'\n", |
| 204 | − tagbuf, st->codec->codec_tag, st->codec->codec_id); | |
| 217 | + tagbuf, codec->codec_tag, codec->codec_id); | |
| 205 | 218 | ret = AVERROR_INVALIDDATA; |
| 206 | 219 | goto fail; |
| 207 | 220 | } |
| 208 | 221 | } else |
| 209 | − st->codec->codec_tag = av_codec_get_tag(s->oformat->codec_tag, st->codec->codec_id); | |
| 222 | + codec->codec_tag = av_codec_get_tag(of->codec_tag, codec->codec_id); | |
| 210 | 223 | } |
| 211 | 224 | |
| 212 | − if (s->oformat->flags & AVFMT_GLOBALHEADER && | |
| 213 | − !(st->codec->flags & CODEC_FLAG_GLOBAL_HEADER)) | |
| 214 | − av_log(s, AV_LOG_WARNING, "Codec for stream %d does not use global headers but container format requires global headers\n", i); | |
| 225 | + if (of->flags & AVFMT_GLOBALHEADER && | |
| 226 | + !(codec->flags & CODEC_FLAG_GLOBAL_HEADER)) | |
| 227 | + av_log(s, AV_LOG_WARNING, | |
| 228 | + "Codec for stream %d does not use global headers " | |
| 229 | + "but container format requires global headers\n", i); | |
| 215 | 230 | } |
| 216 | 231 | |
| 217 | − if (!s->priv_data && s->oformat->priv_data_size > 0) { | |
| 218 | − s->priv_data = av_mallocz(s->oformat->priv_data_size); | |
| 232 | + if (!s->priv_data && of->priv_data_size > 0) { | |
| 233 | + s->priv_data = av_mallocz(of->priv_data_size); | |
| 219 | 234 | if (!s->priv_data) { |
| 220 | 235 | ret = AVERROR(ENOMEM); |
| 221 | 236 | goto fail; |
| 222 | 237 | } |
| 223 | − if (s->oformat->priv_class) { | |
| 224 | − *(const AVClass **)s->priv_data = s->oformat->priv_class; | |
| 238 | + if (of->priv_class) { | |
| 239 | + *(const AVClass **)s->priv_data = of->priv_class; | |
| 225 | 240 | av_opt_set_defaults(s->priv_data); |
| 226 | 241 | if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0) |
| 227 | 242 | goto fail; |