diff --git a/ffmpeg.c b/ffmpeg.c index 9a14294768..adc3ff7800 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -696,6 +696,15 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost) } if (pkt->size == 0 && pkt->side_data_elems == 0) return; + if (!ost->st->codecpar->extradata && avctx->extradata) { + ost->st->codecpar->extradata = av_malloc(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!ost->st->codecpar->extradata) { + av_log(NULL, AV_LOG_ERROR, "Could not allocate extradata buffer to copy parser data.\n"); + exit_program(1); + } + ost->st->codecpar->extradata_size = avctx->extradata_size; + memcpy(ost->st->codecpar->extradata, avctx->extradata, avctx->extradata_size); + } if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) { if (pkt->dts != AV_NOPTS_VALUE && diff --git a/ffserver.c b/ffserver.c index 5821870d2c..b5bd8f833b 100644 --- a/ffserver.c +++ b/ffserver.c @@ -2996,6 +2996,8 @@ static int prepare_sdp_description(FFServerStream *stream, uint8_t **pbuffer, for(i = 0; i < stream->nb_streams; i++) { avc->streams[i] = &avs[i]; avc->streams[i]->codec = stream->streams[i]->codec; + avcodec_parameters_from_context(stream->streams[i]->codecpar, stream->streams[i]->codec); + avc->streams[i]->codecpar = stream->streams[i]->codecpar; } *pbuffer = av_mallocz(2048); if (!*pbuffer) @@ -3536,6 +3538,8 @@ static AVStream *add_av_stream1(FFServerStream *stream, fst->priv_data = av_mallocz(sizeof(FeedData)); fst->internal = av_mallocz(sizeof(*fst->internal)); + fst->internal->avctx = avcodec_alloc_context3(NULL); + fst->codecpar = avcodec_parameters_alloc(); fst->index = stream->nb_streams; avpriv_set_pts_info(fst, 33, 1, 90000); fst->sample_aspect_ratio = codec->sample_aspect_ratio; diff --git a/libavdevice/alsa.c b/libavdevice/alsa.c index 75ac444993..8d27913a1a 100644 --- a/libavdevice/alsa.c +++ b/libavdevice/alsa.c @@ -175,7 +175,7 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode, snd_pcm_t *h; snd_pcm_hw_params_t *hw_params; snd_pcm_uframes_t buffer_size, period_size; - uint64_t layout = ctx->streams[0]->codec->channel_layout; + uint64_t layout = ctx->streams[0]->codecpar->channel_layout; if (ctx->filename[0] == 0) audio_device = "default"; else audio_device = ctx->filename; diff --git a/libavdevice/alsa_dec.c b/libavdevice/alsa_dec.c index 71a6ef4f4e..c50ce71506 100644 --- a/libavdevice/alsa_dec.c +++ b/libavdevice/alsa_dec.c @@ -79,11 +79,11 @@ static av_cold int audio_read_header(AVFormatContext *s1) } /* take real parameters */ - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = codec_id; - st->codec->sample_rate = s->sample_rate; - st->codec->channels = s->channels; - st->codec->frame_size = s->frame_size; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = codec_id; + st->codecpar->sample_rate = s->sample_rate; + st->codecpar->channels = s->channels; + st->codecpar->frame_size = s->frame_size; avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ /* microseconds instead of seconds, MHz instead of Hz */ s->timefilter = ff_timefilter_new(1000000.0 / s->sample_rate, diff --git a/libavdevice/alsa_enc.c b/libavdevice/alsa_enc.c index 10289a91a3..bddc61f4aa 100644 --- a/libavdevice/alsa_enc.c +++ b/libavdevice/alsa_enc.c @@ -55,20 +55,20 @@ static av_cold int audio_write_header(AVFormatContext *s1) enum AVCodecID codec_id; int res; - if (s1->nb_streams != 1 || s1->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO) { + if (s1->nb_streams != 1 || s1->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) { av_log(s1, AV_LOG_ERROR, "Only a single audio stream is supported.\n"); return AVERROR(EINVAL); } st = s1->streams[0]; - sample_rate = st->codec->sample_rate; - codec_id = st->codec->codec_id; + sample_rate = st->codecpar->sample_rate; + codec_id = st->codecpar->codec_id; res = ff_alsa_open(s1, SND_PCM_STREAM_PLAYBACK, &sample_rate, - st->codec->channels, &codec_id); - if (sample_rate != st->codec->sample_rate) { + st->codecpar->channels, &codec_id); + if (sample_rate != st->codecpar->sample_rate) { av_log(s1, AV_LOG_ERROR, "sample rate %d not available, nearest is %d\n", - st->codec->sample_rate, sample_rate); + st->codecpar->sample_rate, sample_rate); goto fail; } avpriv_set_pts_info(st, 64, 1, sample_rate); @@ -124,7 +124,7 @@ static int audio_write_frame(AVFormatContext *s1, int stream_index, /* ff_alsa_open() should have accepted only supported formats */ if ((flags & AV_WRITE_UNCODED_FRAME_QUERY)) - return av_sample_fmt_is_planar(s1->streams[stream_index]->codec->sample_fmt) ? + return av_sample_fmt_is_planar(s1->streams[stream_index]->codecpar->format) ? AVERROR(EINVAL) : 0; /* set only used fields */ pkt.data = (*frame)->data[0]; diff --git a/libavdevice/bktr.c b/libavdevice/bktr.c index c8a8953267..2902425b4d 100644 --- a/libavdevice/bktr.c +++ b/libavdevice/bktr.c @@ -286,14 +286,12 @@ static int grab_read_header(AVFormatContext *s1) s->per_frame = ((uint64_t)1000000 * framerate.den) / framerate.num; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->pix_fmt = AV_PIX_FMT_YUV420P; - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; - st->codec->width = s->width; - st->codec->height = s->height; - st->codec->time_base.den = framerate.num; - st->codec->time_base.num = framerate.den; - + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->format = AV_PIX_FMT_YUV420P; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->width = s->width; + st->codecpar->height = s->height; + st->avg_frame_rate = framerate; if (bktr_init(s1->filename, s->width, s->height, s->standard, &s->video_fd, &s->tuner_fd, -1, 0.0) < 0) { diff --git a/libavdevice/dshow.c b/libavdevice/dshow.c index f56c165539..678861da4b 100644 --- a/libavdevice/dshow.c +++ b/libavdevice/dshow.c @@ -918,7 +918,7 @@ dshow_add_device(AVFormatContext *avctx, { struct dshow_ctx *ctx = avctx->priv_data; AM_MEDIA_TYPE type; - AVCodecContext *codec; + AVCodecParameters *par; AVStream *st; int ret = AVERROR(EIO); @@ -933,7 +933,7 @@ dshow_add_device(AVFormatContext *avctx, libAVPin_ConnectionMediaType(ctx->capture_pin[devtype], &type); - codec = st->codec; + par = st->codecpar; if (devtype == VideoDevice) { BITMAPINFOHEADER *bih = NULL; AVRational time_base; @@ -952,33 +952,34 @@ dshow_add_device(AVFormatContext *avctx, goto error; } - codec->time_base = time_base; - codec->codec_type = AVMEDIA_TYPE_VIDEO; - codec->width = bih->biWidth; - codec->height = bih->biHeight; - codec->codec_tag = bih->biCompression; - codec->pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount); + st->avg_frame_rate = av_inv_q(time_base); + + par->codec_type = AVMEDIA_TYPE_VIDEO; + par->width = bih->biWidth; + par->height = bih->biHeight; + par->codec_tag = bih->biCompression; + par->format = dshow_pixfmt(bih->biCompression, bih->biBitCount); if (bih->biCompression == MKTAG('H', 'D', 'Y', 'C')) { av_log(avctx, AV_LOG_DEBUG, "attempt to use full range for HDYC...\n"); - codec->color_range = AVCOL_RANGE_MPEG; // just in case it needs this... + par->color_range = AVCOL_RANGE_MPEG; // just in case it needs this... } - if (codec->pix_fmt == AV_PIX_FMT_NONE) { + if (par->format == AV_PIX_FMT_NONE) { const AVCodecTag *const tags[] = { avformat_get_riff_video_tags(), NULL }; - codec->codec_id = av_codec_get_id(tags, bih->biCompression); - if (codec->codec_id == AV_CODEC_ID_NONE) { + par->codec_id = av_codec_get_id(tags, bih->biCompression); + if (par->codec_id == AV_CODEC_ID_NONE) { av_log(avctx, AV_LOG_ERROR, "Unknown compression type. " "Please report type 0x%X.\n", (int) bih->biCompression); return AVERROR_PATCHWELCOME; } - codec->bits_per_coded_sample = bih->biBitCount; + par->bits_per_coded_sample = bih->biBitCount; } else { - codec->codec_id = AV_CODEC_ID_RAWVIDEO; + par->codec_id = AV_CODEC_ID_RAWVIDEO; if (bih->biCompression == BI_RGB || bih->biCompression == BI_BITFIELDS) { - codec->bits_per_coded_sample = bih->biBitCount; - codec->extradata = av_malloc(9 + AV_INPUT_BUFFER_PADDING_SIZE); - if (codec->extradata) { - codec->extradata_size = 9; - memcpy(codec->extradata, "BottomUp", 9); + par->bits_per_coded_sample = bih->biBitCount; + par->extradata = av_malloc(9 + AV_INPUT_BUFFER_PADDING_SIZE); + if (par->extradata) { + par->extradata_size = 9; + memcpy(par->extradata, "BottomUp", 9); } } } @@ -993,11 +994,11 @@ dshow_add_device(AVFormatContext *avctx, goto error; } - codec->codec_type = AVMEDIA_TYPE_AUDIO; - codec->sample_fmt = sample_fmt_bits_per_sample(fx->wBitsPerSample); - codec->codec_id = waveform_codec_id(codec->sample_fmt); - codec->sample_rate = fx->nSamplesPerSec; - codec->channels = fx->nChannels; + par->codec_type = AVMEDIA_TYPE_AUDIO; + par->format = sample_fmt_bits_per_sample(fx->wBitsPerSample); + par->codec_id = waveform_codec_id(par->format); + par->sample_rate = fx->nSamplesPerSec; + par->channels = fx->nChannels; } avpriv_set_pts_info(st, 64, 1, 10000000); diff --git a/libavdevice/fbdev_dec.c b/libavdevice/fbdev_dec.c index e9a3639391..1505b2557d 100644 --- a/libavdevice/fbdev_dec.c +++ b/libavdevice/fbdev_dec.c @@ -126,13 +126,13 @@ static av_cold int fbdev_read_header(AVFormatContext *avctx) goto fail; } - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; - st->codec->width = fbdev->width; - st->codec->height = fbdev->height; - st->codec->pix_fmt = pix_fmt; - st->codec->time_base = av_inv_q(fbdev->framerate_q); - st->codec->bit_rate = + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->width = fbdev->width; + st->codecpar->height = fbdev->height; + st->codecpar->format = pix_fmt; + st->avg_frame_rate = fbdev->framerate_q; + st->codecpar->bit_rate = fbdev->width * fbdev->height * fbdev->bytes_per_pixel * av_q2d(fbdev->framerate_q) * 8; av_log(avctx, AV_LOG_INFO, @@ -140,7 +140,7 @@ static av_cold int fbdev_read_header(AVFormatContext *avctx) fbdev->width, fbdev->height, fbdev->varinfo.bits_per_pixel, av_get_pix_fmt_name(pix_fmt), fbdev->framerate_q.num, fbdev->framerate_q.den, - (int64_t)st->codec->bit_rate); + (int64_t)st->codecpar->bit_rate); return 0; fail: diff --git a/libavdevice/fbdev_enc.c b/libavdevice/fbdev_enc.c index 28efc7131b..b4e5f84975 100644 --- a/libavdevice/fbdev_enc.c +++ b/libavdevice/fbdev_enc.c @@ -48,7 +48,7 @@ static av_cold int fbdev_write_header(AVFormatContext *h) int ret, flags = O_RDWR; const char* device; - if (h->nb_streams != 1 || h->streams[0]->codec->codec_type != AVMEDIA_TYPE_VIDEO) { + if (h->nb_streams != 1 || h->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) { av_log(fbdev, AV_LOG_ERROR, "Only a single video stream is supported.\n"); return AVERROR(EINVAL); } @@ -105,11 +105,11 @@ static int fbdev_write_packet(AVFormatContext *h, AVPacket *pkt) enum AVPixelFormat fb_pix_fmt; int disp_height; int bytes_to_copy; - AVCodecContext *codec_ctx = h->streams[0]->codec; - enum AVPixelFormat video_pix_fmt = codec_ctx->pix_fmt; - int video_width = codec_ctx->width; - int video_height = codec_ctx->height; - int bytes_per_pixel = ((codec_ctx->bits_per_coded_sample + 7) >> 3); + AVCodecParameters *par = h->streams[0]->codecpar; + enum AVPixelFormat video_pix_fmt = par->format; + int video_width = par->width; + int video_height = par->height; + int bytes_per_pixel = ((par->bits_per_coded_sample + 7) >> 3); int src_line_size = video_width * bytes_per_pixel; int i; diff --git a/libavdevice/gdigrab.c b/libavdevice/gdigrab.c index 7db587cd97..4239ffae11 100644 --- a/libavdevice/gdigrab.c +++ b/libavdevice/gdigrab.c @@ -403,10 +403,11 @@ gdigrab_read_header(AVFormatContext *s1) } } - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_BMP; - st->codec->time_base = gdigrab->time_base; - st->codec->bit_rate = (gdigrab->header_size + gdigrab->frame_size) * 1/av_q2d(gdigrab->time_base) * 8; + st->avg_frame_rate = av_inv_q(gdigrab->time_base); + + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_BMP; + st->codecpar->bit_rate = (gdigrab->header_size + gdigrab->frame_size) * 1/av_q2d(gdigrab->time_base) * 8; return 0; diff --git a/libavdevice/jack.c b/libavdevice/jack.c index 545548423d..34e21527a7 100644 --- a/libavdevice/jack.c +++ b/libavdevice/jack.c @@ -262,14 +262,14 @@ static int audio_read_header(AVFormatContext *context) return AVERROR(ENOMEM); } - stream->codec->codec_type = AVMEDIA_TYPE_AUDIO; + stream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; #if HAVE_BIGENDIAN - stream->codec->codec_id = AV_CODEC_ID_PCM_F32BE; + stream->codecpar->codec_id = AV_CODEC_ID_PCM_F32BE; #else - stream->codec->codec_id = AV_CODEC_ID_PCM_F32LE; + stream->codecpar->codec_id = AV_CODEC_ID_PCM_F32LE; #endif - stream->codec->sample_rate = self->sample_rate; - stream->codec->channels = self->nports; + stream->codecpar->sample_rate = self->sample_rate; + stream->codecpar->channels = self->nports; avpriv_set_pts_info(stream, 64, 1, 1000000); /* 64 bits pts in us */ return 0; diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c index 8e9e67d3c2..a52d4730e5 100644 --- a/libavdevice/lavfi.c +++ b/libavdevice/lavfi.c @@ -108,8 +108,8 @@ static int create_subcc_streams(AVFormatContext *avctx) lavfi->sink_stream_subcc_map[sink_idx] = avctx->nb_streams; if (!(st = avformat_new_stream(avctx, NULL))) return AVERROR(ENOMEM); - st->codec->codec_id = AV_CODEC_ID_EIA_608; - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_EIA_608; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; } else { lavfi->sink_stream_subcc_map[sink_idx] = -1; } @@ -314,28 +314,28 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx) for (i = 0; i < lavfi->nb_sinks; i++) { AVFilterLink *link = lavfi->sinks[lavfi->stream_sink_map[i]]->inputs[0]; AVStream *st = avctx->streams[i]; - st->codec->codec_type = link->type; + st->codecpar->codec_type = link->type; avpriv_set_pts_info(st, 64, link->time_base.num, link->time_base.den); if (link->type == AVMEDIA_TYPE_VIDEO) { - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; - st->codec->pix_fmt = link->format; - st->codec->time_base = link->time_base; - st->codec->width = link->w; - st->codec->height = link->h; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->format = link->format; + st->avg_frame_rate = av_inv_q(link->time_base); + st->codecpar->width = link->w; + st->codecpar->height = link->h; st ->sample_aspect_ratio = - st->codec->sample_aspect_ratio = link->sample_aspect_ratio; + st->codecpar->sample_aspect_ratio = link->sample_aspect_ratio; avctx->probesize = FFMAX(avctx->probesize, link->w * link->h * av_get_padded_bits_per_pixel(av_pix_fmt_desc_get(link->format)) * 30); } else if (link->type == AVMEDIA_TYPE_AUDIO) { - st->codec->codec_id = av_get_pcm_codec(link->format, -1); - st->codec->channels = avfilter_link_get_channels(link); - st->codec->sample_fmt = link->format; - st->codec->sample_rate = link->sample_rate; - st->codec->time_base = link->time_base; - st->codec->channel_layout = link->channel_layout; - if (st->codec->codec_id == AV_CODEC_ID_NONE) + st->codecpar->codec_id = av_get_pcm_codec(link->format, -1); + st->codecpar->channels = avfilter_link_get_channels(link); + st->codecpar->format = link->format; + st->codecpar->sample_rate = link->sample_rate; + st->avg_frame_rate = av_inv_q(link->time_base); + st->codecpar->channel_layout = link->channel_layout; + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) av_log(avctx, AV_LOG_ERROR, "Could not find PCM codec for sample format %s.\n", av_get_sample_fmt_name(link->format)); diff --git a/libavdevice/libcdio.c b/libavdevice/libcdio.c index 9e9b0d86f3..f6d4fce256 100644 --- a/libavdevice/libcdio.c +++ b/libavdevice/libcdio.c @@ -85,19 +85,19 @@ static av_cold int read_header(AVFormatContext *ctx) } cdio_paranoia_modeset(s->paranoia, s->paranoia_mode); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; if (s->drive->bigendianp) - st->codec->codec_id = AV_CODEC_ID_PCM_S16BE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE; else - st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; - st->codec->sample_rate = 44100; - st->codec->channels = 2; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; + st->codecpar->sample_rate = 44100; + st->codecpar->channels = 2; if (s->drive->audio_last_sector != CDIO_INVALID_LSN && s->drive->audio_first_sector != CDIO_INVALID_LSN) st->duration = s->drive->audio_last_sector - s->drive->audio_first_sector; else if (s->drive->tracks) st->duration = s->drive->disc_toc[s->drive->tracks].dwStartSector; - avpriv_set_pts_info(st, 64, CDIO_CD_FRAMESIZE_RAW, 2*st->codec->channels*st->codec->sample_rate); + avpriv_set_pts_info(st, 64, CDIO_CD_FRAMESIZE_RAW, 2 * st->codecpar->channels * st->codecpar->sample_rate); for (i = 0; i < s->drive->tracks; i++) { char title[16]; diff --git a/libavdevice/libdc1394.c b/libavdevice/libdc1394.c index dcdca6064f..43fa232922 100644 --- a/libavdevice/libdc1394.c +++ b/libavdevice/libdc1394.c @@ -171,13 +171,12 @@ static inline int dc1394_read_common(AVFormatContext *c, goto out; } avpriv_set_pts_info(vst, 64, 1, 1000); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_RAWVIDEO; - vst->codec->time_base.den = framerate.num; - vst->codec->time_base.num = framerate.den; - vst->codec->width = fmt->width; - vst->codec->height = fmt->height; - vst->codec->pix_fmt = fmt->pix_fmt; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + vst->codecpar->width = fmt->width; + vst->codecpar->height = fmt->height; + vst->codecpar->format = fmt->pix_fmt; + vst->avg_frame_rate = framerate; /* packet init */ av_init_packet(&dc1394->packet); @@ -188,7 +187,7 @@ static inline int dc1394_read_common(AVFormatContext *c, dc1394->current_frame = 0; - vst->codec->bit_rate = av_rescale(dc1394->packet.size * 8, fps->frame_rate, 1000); + vst->codecpar->bit_rate = av_rescale(dc1394->packet.size * 8, fps->frame_rate, 1000); *select_fps = fps; *select_fmt = fmt; out: diff --git a/libavdevice/openal-dec.c b/libavdevice/openal-dec.c index e4daf53250..0647952f9c 100644 --- a/libavdevice/openal-dec.c +++ b/libavdevice/openal-dec.c @@ -128,7 +128,7 @@ static int read_header(AVFormatContext *ctx) int error = 0; const char *error_msg; AVStream *st = NULL; - AVCodecContext *codec = NULL; + AVCodecParameters *par = NULL; if (ad->list_devices) { print_al_capture_devices(ctx); @@ -156,11 +156,11 @@ static int read_header(AVFormatContext *ctx) avpriv_set_pts_info(st, 64, 1, 1000000); /* Set codec parameters */ - codec = st->codec; - codec->codec_type = AVMEDIA_TYPE_AUDIO; - codec->sample_rate = ad->sample_rate; - codec->channels = get_al_format_info(ad->sample_format)->channels; - codec->codec_id = get_al_format_info(ad->sample_format)->codec_id; + par = st->codecpar; + par->codec_type = AVMEDIA_TYPE_AUDIO; + par->sample_rate = ad->sample_rate; + par->channels = get_al_format_info(ad->sample_format)->channels; + par->codec_id = get_al_format_info(ad->sample_format)->codec_id; /* This is needed to read the audio data */ ad->sample_step = (av_get_bits_per_sample(get_al_format_info(ad->sample_format)->codec_id) * diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c index ba8d36abff..1dbbb80f44 100644 --- a/libavdevice/opengl_enc.c +++ b/libavdevice/opengl_enc.c @@ -678,11 +678,11 @@ static void opengl_compute_display_area(AVFormatContext *s) AVRational sar, dar; /* sample and display aspect ratios */ OpenGLContext *opengl = s->priv_data; AVStream *st = s->streams[0]; - AVCodecContext *encctx = st->codec; + AVCodecParameters *par = st->codecpar; /* compute overlay width and height from the codec context information */ sar = st->sample_aspect_ratio.num ? st->sample_aspect_ratio : (AVRational){ 1, 1 }; - dar = av_mul_q(sar, (AVRational){ encctx->width, encctx->height }); + dar = av_mul_q(sar, (AVRational){ par->width, par->height }); /* we suppose the screen has a 1/1 sample aspect ratio */ /* fit in the window */ @@ -1065,15 +1065,15 @@ static av_cold int opengl_write_header(AVFormatContext *h) int ret; if (h->nb_streams != 1 || - h->streams[0]->codec->codec_type != AVMEDIA_TYPE_VIDEO || - h->streams[0]->codec->codec_id != AV_CODEC_ID_RAWVIDEO) { + h->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO || + h->streams[0]->codecpar->codec_id != AV_CODEC_ID_RAWVIDEO) { av_log(opengl, AV_LOG_ERROR, "Only a single video stream is supported.\n"); return AVERROR(EINVAL); } st = h->streams[0]; - opengl->width = st->codec->width; - opengl->height = st->codec->height; - opengl->pix_fmt = st->codec->pix_fmt; + opengl->width = st->codecpar->width; + opengl->height = st->codecpar->height; + opengl->pix_fmt = st->codecpar->format; if (!opengl->window_width) opengl->window_width = opengl->width; if (!opengl->window_height) @@ -1200,7 +1200,7 @@ static uint8_t* opengl_get_plane_pointer(OpenGLContext *opengl, AVPacket *pkt, i static int opengl_draw(AVFormatContext *h, void *input, int repaint, int is_pkt) { OpenGLContext *opengl = h->priv_data; - enum AVPixelFormat pix_fmt = h->streams[0]->codec->pix_fmt; + enum AVPixelFormat pix_fmt = h->streams[0]->codecpar->format; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); int ret; diff --git a/libavdevice/oss_dec.c b/libavdevice/oss_dec.c index 3a9a20a233..9f748f2bc3 100644 --- a/libavdevice/oss_dec.c +++ b/libavdevice/oss_dec.c @@ -63,10 +63,10 @@ static int audio_read_header(AVFormatContext *s1) } /* take real parameters */ - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->codec_id; - st->codec->sample_rate = s->sample_rate; - st->codec->channels = s->channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = s->codec_id; + st->codecpar->sample_rate = s->sample_rate; + st->codecpar->channels = s->channels; avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ return 0; diff --git a/libavdevice/oss_enc.c b/libavdevice/oss_enc.c index 3781eb54e5..2268b4cfe4 100644 --- a/libavdevice/oss_enc.c +++ b/libavdevice/oss_enc.c @@ -49,8 +49,8 @@ static int audio_write_header(AVFormatContext *s1) int ret; st = s1->streams[0]; - s->sample_rate = st->codec->sample_rate; - s->channels = st->codec->channels; + s->sample_rate = st->codecpar->sample_rate; + s->channels = st->codecpar->channels; ret = ff_oss_audio_open(s1, 1, s1->filename); if (ret < 0) { return AVERROR(EIO); diff --git a/libavdevice/pulse_audio_dec.c b/libavdevice/pulse_audio_dec.c index aa0800b40b..95a1d6ecfa 100644 --- a/libavdevice/pulse_audio_dec.c +++ b/libavdevice/pulse_audio_dec.c @@ -242,10 +242,10 @@ static av_cold int pulse_read_header(AVFormatContext *s) pa_threaded_mainloop_unlock(pd->mainloop); /* take real parameters */ - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = codec_id; - st->codec->sample_rate = pd->sample_rate; - st->codec->channels = pd->channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = codec_id; + st->codecpar->sample_rate = pd->sample_rate; + st->codecpar->channels = pd->channels; avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ pd->timefilter = ff_timefilter_new(1000000.0 / pd->sample_rate, diff --git a/libavdevice/pulse_audio_enc.c b/libavdevice/pulse_audio_enc.c index b419a38d46..6fb634ee2b 100644 --- a/libavdevice/pulse_audio_enc.c +++ b/libavdevice/pulse_audio_enc.c @@ -452,7 +452,7 @@ static av_cold int pulse_write_header(AVFormatContext *h) PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_NOT_MONOTONIC; - if (h->nb_streams != 1 || h->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO) { + if (h->nb_streams != 1 || h->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) { av_log(s, AV_LOG_ERROR, "Only a single audio stream is supported.\n"); return AVERROR(EINVAL); } @@ -468,8 +468,8 @@ static av_cold int pulse_write_header(AVFormatContext *h) if (s->buffer_duration) { int64_t bytes = s->buffer_duration; - bytes *= st->codec->channels * st->codec->sample_rate * - av_get_bytes_per_sample(st->codec->sample_fmt); + bytes *= st->codecpar->channels * st->codecpar->sample_rate * + av_get_bytes_per_sample(st->codecpar->format); bytes /= 1000; buffer_attributes.tlength = FFMAX(s->buffer_size, av_clip64(bytes, 0, UINT32_MAX - 1)); av_log(s, AV_LOG_DEBUG, @@ -483,9 +483,9 @@ static av_cold int pulse_write_header(AVFormatContext *h) if (s->minreq) buffer_attributes.minreq = s->minreq; - sample_spec.format = ff_codec_id_to_pulse_format(st->codec->codec_id); - sample_spec.rate = st->codec->sample_rate; - sample_spec.channels = st->codec->channels; + sample_spec.format = ff_codec_id_to_pulse_format(st->codecpar->codec_id); + sample_spec.rate = st->codecpar->sample_rate; + sample_spec.channels = st->codecpar->channels; if (!pa_sample_spec_valid(&sample_spec)) { av_log(s, AV_LOG_ERROR, "Invalid sample spec.\n"); return AVERROR(EINVAL); @@ -494,10 +494,10 @@ static av_cold int pulse_write_header(AVFormatContext *h) if (sample_spec.channels == 1) { channel_map.channels = 1; channel_map.map[0] = PA_CHANNEL_POSITION_MONO; - } else if (st->codec->channel_layout) { - if (av_get_channel_layout_nb_channels(st->codec->channel_layout) != st->codec->channels) + } else if (st->codecpar->channel_layout) { + if (av_get_channel_layout_nb_channels(st->codecpar->channel_layout) != st->codecpar->channels) return AVERROR(EINVAL); - pulse_map_channels_to_pulse(st->codec->channel_layout, &channel_map); + pulse_map_channels_to_pulse(st->codecpar->channel_layout, &channel_map); /* Unknown channel is present in channel_layout, let PulseAudio use its default. */ if (channel_map.channels != sample_spec.channels) { av_log(s, AV_LOG_WARNING, "Unknown channel. Using defaul channel map.\n"); @@ -637,9 +637,8 @@ static int pulse_write_packet(AVFormatContext *h, AVPacket *pkt) s->timestamp += pkt->duration; } else { AVStream *st = h->streams[0]; - AVCodecContext *codec_ctx = st->codec; - AVRational r = { 1, codec_ctx->sample_rate }; - int64_t samples = pkt->size / (av_get_bytes_per_sample(codec_ctx->sample_fmt) * codec_ctx->channels); + AVRational r = { 1, st->codecpar->sample_rate }; + int64_t samples = pkt->size / (av_get_bytes_per_sample(st->codecpar->format) * st->codecpar->channels); s->timestamp += av_rescale_q(samples, r, st->time_base); } @@ -678,7 +677,7 @@ static int pulse_write_frame(AVFormatContext *h, int stream_index, /* Planar formats are not supported yet. */ if (flags & AV_WRITE_UNCODED_FRAME_QUERY) - return av_sample_fmt_is_planar(h->streams[stream_index]->codec->sample_fmt) ? + return av_sample_fmt_is_planar(h->streams[stream_index]->codecpar->format) ? AVERROR(EINVAL) : 0; pkt.data = (*frame)->data[0]; diff --git a/libavdevice/sdl.c b/libavdevice/sdl.c index 4cccfe528a..432275004c 100644 --- a/libavdevice/sdl.c +++ b/libavdevice/sdl.c @@ -94,12 +94,12 @@ static void compute_overlay_rect(AVFormatContext *s) AVRational sar, dar; /* sample and display aspect ratios */ SDLContext *sdl = s->priv_data; AVStream *st = s->streams[0]; - AVCodecContext *encctx = st->codec; + AVCodecParameters *par = st->codecpar; SDL_Rect *overlay_rect = &sdl->overlay_rect; /* compute overlay width and height from the codec context information */ sar = st->sample_aspect_ratio.num ? st->sample_aspect_ratio : (AVRational){ 1, 1 }; - dar = av_mul_q(sar, (AVRational){ encctx->width, encctx->height }); + dar = av_mul_q(sar, (AVRational){ par->width, par->height }); /* we suppose the screen has a 1/1 sample aspect ratio */ if (sdl->window_width && sdl->window_height) { @@ -115,10 +115,10 @@ static void compute_overlay_rect(AVFormatContext *s) } } else { if (sar.num > sar.den) { - overlay_rect->w = encctx->width; + overlay_rect->w = par->width; overlay_rect->h = av_rescale(overlay_rect->w, dar.den, dar.num); } else { - overlay_rect->h = encctx->height; + overlay_rect->h = par->height; overlay_rect->w = av_rescale(overlay_rect->h, dar.num, dar.den); } sdl->window_width = overlay_rect->w; @@ -137,7 +137,7 @@ static int event_thread(void *arg) SDLContext *sdl = s->priv_data; int flags = SDL_BASE_FLAGS | (sdl->window_fullscreen ? SDL_FULLSCREEN : 0); AVStream *st = s->streams[0]; - AVCodecContext *encctx = st->codec; + AVCodecParameters *par = st->codecpar; /* initialization */ if (SDL_Init(SDL_INIT_VIDEO) != 0) { @@ -155,19 +155,19 @@ static int event_thread(void *arg) goto init_end; } - sdl->overlay = SDL_CreateYUVOverlay(encctx->width, encctx->height, + sdl->overlay = SDL_CreateYUVOverlay(par->width, par->height, sdl->overlay_fmt, sdl->surface); - if (!sdl->overlay || sdl->overlay->pitches[0] < encctx->width) { + if (!sdl->overlay || sdl->overlay->pitches[0] < par->width) { av_log(s, AV_LOG_ERROR, "SDL does not support an overlay with size of %dx%d pixels\n", - encctx->width, encctx->height); + par->width, par->height); sdl->init_ret = AVERROR(EINVAL); goto init_end; } sdl->init_ret = 0; av_log(s, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s -> w:%d h:%d\n", - encctx->width, encctx->height, av_get_pix_fmt_name(encctx->pix_fmt), + par->width, par->height, av_get_pix_fmt_name(par->format), sdl->overlay_rect.w, sdl->overlay_rect.h); init_end: @@ -234,7 +234,7 @@ static int sdl_write_header(AVFormatContext *s) { SDLContext *sdl = s->priv_data; AVStream *st = s->streams[0]; - AVCodecContext *encctx = st->codec; + AVCodecParameters *par = st->codecpar; int i, ret; if (!sdl->window_title) @@ -251,15 +251,15 @@ static int sdl_write_header(AVFormatContext *s) } if ( s->nb_streams > 1 - || encctx->codec_type != AVMEDIA_TYPE_VIDEO - || encctx->codec_id != AV_CODEC_ID_RAWVIDEO) { + || par->codec_type != AVMEDIA_TYPE_VIDEO + || par->codec_id != AV_CODEC_ID_RAWVIDEO) { av_log(s, AV_LOG_ERROR, "Only supports one rawvideo stream\n"); ret = AVERROR(EINVAL); goto fail; } for (i = 0; sdl_overlay_pix_fmt_map[i].pix_fmt != AV_PIX_FMT_NONE; i++) { - if (sdl_overlay_pix_fmt_map[i].pix_fmt == encctx->pix_fmt) { + if (sdl_overlay_pix_fmt_map[i].pix_fmt == par->format) { sdl->overlay_fmt = sdl_overlay_pix_fmt_map[i].overlay_fmt; break; } @@ -268,7 +268,7 @@ static int sdl_write_header(AVFormatContext *s) if (!sdl->overlay_fmt) { av_log(s, AV_LOG_ERROR, "Unsupported pixel format '%s', choose one of yuv420p, yuyv422, or uyvy422\n", - av_get_pix_fmt_name(encctx->pix_fmt)); + av_get_pix_fmt_name(par->format)); ret = AVERROR(EINVAL); goto fail; } @@ -315,7 +315,7 @@ fail: static int sdl_write_packet(AVFormatContext *s, AVPacket *pkt) { SDLContext *sdl = s->priv_data; - AVCodecContext *encctx = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; uint8_t *data[4]; int linesize[4]; int i; @@ -324,7 +324,7 @@ static int sdl_write_packet(AVFormatContext *s, AVPacket *pkt) sdl_write_trailer(s); return AVERROR(EIO); } - av_image_fill_arrays(data, linesize, pkt->data, encctx->pix_fmt, encctx->width, encctx->height, 1); + av_image_fill_arrays(data, linesize, pkt->data, par->format, par->width, par->height, 1); SDL_LockMutex(sdl->mutex); SDL_FillRect(sdl->surface, &sdl->surface->clip_rect, diff --git a/libavdevice/sndio_dec.c b/libavdevice/sndio_dec.c index 6f1160e0f0..2d13232bf1 100644 --- a/libavdevice/sndio_dec.c +++ b/libavdevice/sndio_dec.c @@ -46,10 +46,10 @@ static av_cold int audio_read_header(AVFormatContext *s1) return ret; /* take real parameters */ - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->codec_id; - st->codec->sample_rate = s->sample_rate; - st->codec->channels = s->channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = s->codec_id; + st->codecpar->sample_rate = s->sample_rate; + st->codecpar->channels = s->channels; avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ diff --git a/libavdevice/sndio_enc.c b/libavdevice/sndio_enc.c index 52b9060ef6..47f500d71e 100644 --- a/libavdevice/sndio_enc.c +++ b/libavdevice/sndio_enc.c @@ -35,8 +35,8 @@ static av_cold int audio_write_header(AVFormatContext *s1) int ret; st = s1->streams[0]; - s->sample_rate = st->codec->sample_rate; - s->channels = st->codec->channels; + s->sample_rate = st->codecpar->sample_rate; + s->channels = st->codecpar->channels; ret = ff_sndio_open(s1, 1, s1->filename); diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index 383033e738..103fb105f2 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -938,8 +938,8 @@ static int v4l2_read_header(AVFormatContext *ctx) if ((res = v4l2_set_parameters(ctx)) < 0) goto fail; - st->codec->pix_fmt = ff_fmt_v4l2ff(desired_format, codec_id); - s->frame_size = av_image_get_buffer_size(st->codec->pix_fmt, + st->codecpar->format = ff_fmt_v4l2ff(desired_format, codec_id); + s->frame_size = av_image_get_buffer_size(st->codecpar->format, s->width, s->height, 1); if ((res = mmap_init(ctx)) || @@ -948,22 +948,22 @@ static int v4l2_read_header(AVFormatContext *ctx) s->top_field_first = first_field(s); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = codec_id; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = codec_id; if (codec_id == AV_CODEC_ID_RAWVIDEO) - st->codec->codec_tag = - avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt); + st->codecpar->codec_tag = + avcodec_pix_fmt_to_codec_tag(st->codecpar->format); else if (codec_id == AV_CODEC_ID_H264) { st->need_parsing = AVSTREAM_PARSE_FULL_ONCE; } if (desired_format == V4L2_PIX_FMT_YVU420) - st->codec->codec_tag = MKTAG('Y', 'V', '1', '2'); + st->codecpar->codec_tag = MKTAG('Y', 'V', '1', '2'); else if (desired_format == V4L2_PIX_FMT_YVU410) - st->codec->codec_tag = MKTAG('Y', 'V', 'U', '9'); - st->codec->width = s->width; - st->codec->height = s->height; + st->codecpar->codec_tag = MKTAG('Y', 'V', 'U', '9'); + st->codecpar->width = s->width; + st->codecpar->height = s->height; if (st->avg_frame_rate.den) - st->codec->bit_rate = s->frame_size * av_q2d(st->avg_frame_rate) * 8; + st->codecpar->bit_rate = s->frame_size * av_q2d(st->avg_frame_rate) * 8; return 0; diff --git a/libavdevice/v4l2enc.c b/libavdevice/v4l2enc.c index ac4068cbd4..faf6e07f86 100644 --- a/libavdevice/v4l2enc.c +++ b/libavdevice/v4l2enc.c @@ -33,7 +33,7 @@ static av_cold int write_header(AVFormatContext *s1) .type = V4L2_BUF_TYPE_VIDEO_OUTPUT }; V4L2Context *s = s1->priv_data; - AVCodecContext *enc_ctx; + AVCodecParameters *par; uint32_t v4l2_pixfmt; if (s1->flags & AVFMT_FLAG_NONBLOCK) @@ -47,19 +47,19 @@ static av_cold int write_header(AVFormatContext *s1) } if (s1->nb_streams != 1 || - s1->streams[0]->codec->codec_type != AVMEDIA_TYPE_VIDEO || - s1->streams[0]->codec->codec_id != AV_CODEC_ID_RAWVIDEO) { + s1->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO || + s1->streams[0]->codecpar->codec_id != AV_CODEC_ID_RAWVIDEO) { av_log(s1, AV_LOG_ERROR, "V4L2 output device supports only a single raw video stream\n"); return AVERROR(EINVAL); } - enc_ctx = s1->streams[0]->codec; + par = s1->streams[0]->codecpar; - v4l2_pixfmt = ff_fmt_ff2v4l(enc_ctx->pix_fmt, AV_CODEC_ID_RAWVIDEO); + v4l2_pixfmt = ff_fmt_ff2v4l(par->format, AV_CODEC_ID_RAWVIDEO); if (!v4l2_pixfmt) { // XXX: try to force them one by one? av_log(s1, AV_LOG_ERROR, "Unknown V4L2 pixel format equivalent for %s\n", - av_get_pix_fmt_name(enc_ctx->pix_fmt)); + av_get_pix_fmt_name(par->format)); return AVERROR(EINVAL); } @@ -69,10 +69,10 @@ static av_cold int write_header(AVFormatContext *s1) return res; } - fmt.fmt.pix.width = enc_ctx->width; - fmt.fmt.pix.height = enc_ctx->height; + fmt.fmt.pix.width = par->width; + fmt.fmt.pix.height = par->height; fmt.fmt.pix.pixelformat = v4l2_pixfmt; - fmt.fmt.pix.sizeimage = av_image_get_buffer_size(enc_ctx->pix_fmt, enc_ctx->width, enc_ctx->height, 1); + fmt.fmt.pix.sizeimage = av_image_get_buffer_size(par->format, par->width, par->height, 1); if (ioctl(s->fd, VIDIOC_S_FMT, &fmt) < 0) { res = AVERROR(errno); diff --git a/libavdevice/vfwcap.c b/libavdevice/vfwcap.c index e1f8b86699..2dcf5aa2ed 100644 --- a/libavdevice/vfwcap.c +++ b/libavdevice/vfwcap.c @@ -245,7 +245,7 @@ static int vfw_read_close(AVFormatContext *s) static int vfw_read_header(AVFormatContext *s) { struct vfw_ctx *ctx = s->priv_data; - AVCodecContext *codec; + AVCodecParameters *par; AVStream *st; int devnum; int bisize; @@ -377,29 +377,30 @@ static int vfw_read_header(AVFormatContext *s) if(!ret) goto fail; - codec = st->codec; - codec->time_base = av_inv_q(framerate_q); - codec->codec_type = AVMEDIA_TYPE_VIDEO; - codec->width = bi->bmiHeader.biWidth; - codec->height = bi->bmiHeader.biHeight; - codec->pix_fmt = vfw_pixfmt(biCompression, biBitCount); - if(codec->pix_fmt == AV_PIX_FMT_NONE) { - codec->codec_id = vfw_codecid(biCompression); - if(codec->codec_id == AV_CODEC_ID_NONE) { + st->avg_frame_rate = framerate_q; + + par = st->codecpar; + par->codec_type = AVMEDIA_TYPE_VIDEO; + par->width = bi->bmiHeader.biWidth; + par->height = bi->bmiHeader.biHeight; + par->format = vfw_pixfmt(biCompression, biBitCount); + if (par->format == AV_PIX_FMT_NONE) { + par->codec_id = vfw_codecid(biCompression); + if (par->codec_id == AV_CODEC_ID_NONE) { av_log(s, AV_LOG_ERROR, "Unknown compression type. " "Please report verbose (-v 9) debug information.\n"); vfw_read_close(s); return AVERROR_PATCHWELCOME; } - codec->bits_per_coded_sample = biBitCount; + par->bits_per_coded_sample = biBitCount; } else { - codec->codec_id = AV_CODEC_ID_RAWVIDEO; + par->codec_id = AV_CODEC_ID_RAWVIDEO; if(biCompression == BI_RGB) { - codec->bits_per_coded_sample = biBitCount; - codec->extradata = av_malloc(9 + AV_INPUT_BUFFER_PADDING_SIZE); - if (codec->extradata) { - codec->extradata_size = 9; - memcpy(codec->extradata, "BottomUp", 9); + par->bits_per_coded_sample = biBitCount; + par->extradata = av_malloc(9 + AV_INPUT_BUFFER_PADDING_SIZE); + if (par->extradata) { + par->extradata_size = 9; + memcpy(par->extradata, "BottomUp", 9); } } } diff --git a/libavdevice/x11grab.c b/libavdevice/x11grab.c index 9dc3472187..a78e7a47a6 100644 --- a/libavdevice/x11grab.c +++ b/libavdevice/x11grab.c @@ -355,11 +355,11 @@ static int x11grab_read_header(AVFormatContext *s1) x11grab->image = image; x11grab->use_shm = use_shm; - ret = pixfmt_from_image(s1, image, &st->codec->pix_fmt); + ret = pixfmt_from_image(s1, image, &st->codecpar->format); if (ret < 0) goto out; - if (st->codec->pix_fmt == AV_PIX_FMT_PAL8) { + if (st->codecpar->format == AV_PIX_FMT_PAL8) { color_map = DefaultColormap(dpy, screen); for (i = 0; i < 256; ++i) color[i].pixel = i; @@ -372,12 +372,13 @@ static int x11grab_read_header(AVFormatContext *s1) } - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; - st->codec->width = x11grab->width; - st->codec->height = x11grab->height; - st->codec->time_base = x11grab->time_base; - st->codec->bit_rate = x11grab->frame_size * 1 / av_q2d(x11grab->time_base) * 8; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->width = x11grab->width; + st->codecpar->height = x11grab->height; + st->codecpar->bit_rate = x11grab->frame_size * 1 / av_q2d(x11grab->time_base) * 8; + + st->avg_frame_rate = av_inv_q(x11grab->time_base); out: av_free(dpyname); diff --git a/libavdevice/xcbgrab.c b/libavdevice/xcbgrab.c index 2da7ec7d4f..9da46c8e0d 100644 --- a/libavdevice/xcbgrab.c +++ b/libavdevice/xcbgrab.c @@ -548,13 +548,12 @@ static int create_stream(AVFormatContext *s) st->avg_frame_rate.num }; c->time_frame = av_gettime(); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; - st->codec->width = c->width; - st->codec->height = c->height; - st->codec->time_base = c->time_base; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->width = c->width; + st->codecpar->height = c->height; - ret = pixfmt_from_pixmap_format(s, geo->depth, &st->codec->pix_fmt); + ret = pixfmt_from_pixmap_format(s, geo->depth, &st->codecpar->format); free(geo); diff --git a/libavdevice/xv.c b/libavdevice/xv.c index 64cddeb068..185de7569e 100644 --- a/libavdevice/xv.c +++ b/libavdevice/xv.c @@ -109,22 +109,22 @@ static int xv_write_header(AVFormatContext *s) XColor fgcolor; XWindowAttributes window_attrs; int num_formats = 0, j, tag, ret; - AVCodecContext *encctx = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; if ( s->nb_streams > 1 - || encctx->codec_type != AVMEDIA_TYPE_VIDEO - || encctx->codec_id != AV_CODEC_ID_RAWVIDEO) { + || par->codec_type != AVMEDIA_TYPE_VIDEO + || par->codec_id != AV_CODEC_ID_RAWVIDEO) { av_log(s, AV_LOG_ERROR, "Only supports one rawvideo stream\n"); return AVERROR(EINVAL); } - if (!(tag = xv_get_tag_from_format(encctx->pix_fmt))) { + if (!(tag = xv_get_tag_from_format(par->format))) { av_log(s, AV_LOG_ERROR, "Unsupported pixel format '%s', only yuv420p, uyvy422, yuyv422 are currently supported\n", - av_get_pix_fmt_name(encctx->pix_fmt)); + av_get_pix_fmt_name(par->format)); return AVERROR_PATCHWELCOME; } - xv->image_format = encctx->pix_fmt; + xv->image_format = par->format; xv->display = XOpenDisplay(xv->display_name); if (!xv->display) { @@ -132,12 +132,12 @@ static int xv_write_header(AVFormatContext *s) return AVERROR(EINVAL); } - xv->image_width = encctx->width; - xv->image_height = encctx->height; + xv->image_width = par->width; + xv->image_height = par->height; if (!xv->window_width && !xv->window_height) { - AVRational sar = encctx->sample_aspect_ratio; - xv->window_width = encctx->width; - xv->window_height = encctx->height; + AVRational sar = par->sample_aspect_ratio; + xv->window_width = par->width; + xv->window_height = par->height; if (sar.num) { if (sar.num > sar.den) xv->window_width = av_rescale(xv->window_width, sar.num, sar.den); @@ -189,14 +189,14 @@ static int xv_write_header(AVFormatContext *s) if (j >= num_formats) { av_log(s, AV_LOG_ERROR, "Device does not support pixel format %s, aborting\n", - av_get_pix_fmt_name(encctx->pix_fmt)); + av_get_pix_fmt_name(par->format)); ret = AVERROR(EINVAL); goto fail; } xv->gc = XCreateGC(xv->display, xv->window, 0, 0); - xv->image_width = encctx->width; - xv->image_height = encctx->height; + xv->image_width = par->width; + xv->image_height = par->height; xv->yuv_image = XvShmCreateImage(xv->display, xv->xv_port, tag, 0, xv->image_width, xv->image_height, &xv->yuv_shminfo); xv->yuv_shminfo.shmid = shmget(IPC_PRIVATE, xv->yuv_image->data_size, @@ -228,11 +228,11 @@ static void compute_display_area(AVFormatContext *s) XVContext *xv = s->priv_data; AVRational sar, dar; /* sample and display aspect ratios */ AVStream *st = s->streams[0]; - AVCodecContext *encctx = st->codec; + AVCodecParameters *par = st->codecpar; /* compute overlay width and height from the codec context information */ sar = st->sample_aspect_ratio.num ? st->sample_aspect_ratio : (AVRational){ 1, 1 }; - dar = av_mul_q(sar, (AVRational){ encctx->width, encctx->height }); + dar = av_mul_q(sar, (AVRational){ par->width, par->height }); /* we suppose the screen has a 1/1 sample aspect ratio */ /* fit in the window */ @@ -321,12 +321,12 @@ static int write_picture(AVFormatContext *s, uint8_t *input_data[4], static int xv_write_packet(AVFormatContext *s, AVPacket *pkt) { - AVCodecContext *ctx = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; uint8_t *data[4]; int linesize[4]; - av_image_fill_arrays(data, linesize, pkt->data, ctx->pix_fmt, - ctx->width, ctx->height, 1); + av_image_fill_arrays(data, linesize, pkt->data, par->format, + par->width, par->height, 1); return write_picture(s, data, linesize); } diff --git a/libavformat/3dostr.c b/libavformat/3dostr.c index 5325a03f90..3668e5f613 100644 --- a/libavformat/3dostr.c +++ b/libavformat/3dostr.c @@ -61,17 +61,17 @@ static int threedostr_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->sample_rate = avio_rb32(s->pb); - st->codec->channels = avio_rb32(s->pb); - if (st->codec->channels <= 0) + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->sample_rate = avio_rb32(s->pb); + st->codecpar->channels = avio_rb32(s->pb); + if (st->codecpar->channels <= 0) return AVERROR_INVALIDDATA; codec = avio_rl32(s->pb); avio_skip(s->pb, 4); if (ctrl_size == 20 || ctrl_size == 3 || ctrl_size == -1) - st->duration = (avio_rb32(s->pb) - 1) / st->codec->channels; + st->duration = (avio_rb32(s->pb) - 1) / st->codecpar->channels; else - st->duration = avio_rb32(s->pb) * 16 / st->codec->channels; + st->duration = avio_rb32(s->pb) * 16 / st->codecpar->channels; size -= 56; found_shdr = 1; break; @@ -95,15 +95,15 @@ static int threedostr_read_header(AVFormatContext *s) switch (codec) { case MKTAG('S','D','X','2'): - st->codec->codec_id = AV_CODEC_ID_SDX2_DPCM; - st->codec->block_align = 1 * st->codec->channels; + st->codecpar->codec_id = AV_CODEC_ID_SDX2_DPCM; + st->codecpar->block_align = 1 * st->codecpar->channels; break; default: avpriv_request_sample(s, "codec %X", codec); return AVERROR_PATCHWELCOME; } - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } @@ -142,7 +142,7 @@ static int threedostr_read_packet(AVFormatContext *s, AVPacket *pkt) ret = av_get_packet(s->pb, pkt, size); pkt->pos = pos; pkt->stream_index = 0; - pkt->duration = size / st->codec->channels; + pkt->duration = size / st->codecpar->channels; size = 0; found_ssmp = 1; break; diff --git a/libavformat/4xm.c b/libavformat/4xm.c index 70f0def3ed..2f2f6a6afc 100644 --- a/libavformat/4xm.c +++ b/libavformat/4xm.c @@ -108,16 +108,16 @@ static int parse_vtrk(AVFormatContext *s, fourxm->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_4XM; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_4XM; - st->codec->extradata = av_mallocz(4 + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + st->codecpar->extradata = av_mallocz(4 + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - st->codec->extradata_size = 4; - AV_WL32(st->codec->extradata, AV_RL32(buf + 16)); - st->codec->width = AV_RL32(buf + 36); - st->codec->height = AV_RL32(buf + 40); + st->codecpar->extradata_size = 4; + AV_WL32(st->codecpar->extradata, AV_RL32(buf + 16)); + st->codecpar->width = AV_RL32(buf + 36); + st->codecpar->height = AV_RL32(buf + 40); return 0; } @@ -173,23 +173,23 @@ static int parse_strk(AVFormatContext *s, fourxm->tracks[track].stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = 0; - st->codec->channels = fourxm->tracks[track].channels; - st->codec->sample_rate = fourxm->tracks[track].sample_rate; - st->codec->bits_per_coded_sample = fourxm->tracks[track].bits; - st->codec->bit_rate = st->codec->channels * - st->codec->sample_rate * - st->codec->bits_per_coded_sample; - st->codec->block_align = st->codec->channels * - st->codec->bits_per_coded_sample; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = 0; + st->codecpar->channels = fourxm->tracks[track].channels; + st->codecpar->sample_rate = fourxm->tracks[track].sample_rate; + st->codecpar->bits_per_coded_sample = fourxm->tracks[track].bits; + st->codecpar->bit_rate = st->codecpar->channels * + st->codecpar->sample_rate * + st->codecpar->bits_per_coded_sample; + st->codecpar->block_align = st->codecpar->channels * + st->codecpar->bits_per_coded_sample; if (fourxm->tracks[track].adpcm){ - st->codec->codec_id = AV_CODEC_ID_ADPCM_4XM; - } else if (st->codec->bits_per_coded_sample == 8) { - st->codec->codec_id = AV_CODEC_ID_PCM_U8; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_4XM; + } else if (st->codecpar->bits_per_coded_sample == 8) { + st->codecpar->codec_id = AV_CODEC_ID_PCM_U8; } else - st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; return 0; } diff --git a/libavformat/a64.c b/libavformat/a64.c index a7f93a27b1..2a0489dae4 100644 --- a/libavformat/a64.c +++ b/libavformat/a64.c @@ -26,7 +26,7 @@ static int a64_write_header(AVFormatContext *s) { - AVCodecContext *avctx = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; uint8_t header[5] = { 0x00, //load 0x40, //address @@ -35,20 +35,20 @@ static int a64_write_header(AVFormatContext *s) 0x00 //fps in 50/fps; }; - if (avctx->extradata_size < 4) { + if (par->extradata_size < 4) { av_log(s, AV_LOG_ERROR, "Missing extradata\n"); return AVERROR_INVALIDDATA; } - switch (avctx->codec_id) { + switch (par->codec_id) { case AV_CODEC_ID_A64_MULTI: header[2] = 0x00; - header[3] = AV_RB32(avctx->extradata+0); + header[3] = AV_RB32(par->extradata+0); header[4] = 2; break; case AV_CODEC_ID_A64_MULTI5: header[2] = 0x01; - header[3] = AV_RB32(avctx->extradata+0); + header[3] = AV_RB32(par->extradata+0); header[4] = 3; break; default: diff --git a/libavformat/aacdec.c b/libavformat/aacdec.c index 1b98e1ddb5..aa2375690d 100644 --- a/libavformat/aacdec.c +++ b/libavformat/aacdec.c @@ -84,9 +84,9 @@ static int adts_aac_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->iformat->raw_codec_id; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = s->iformat->raw_codec_id; + st->need_parsing = AVSTREAM_PARSE_FULL_RAW; ff_id3v1_read(s); if (s->pb->seekable && diff --git a/libavformat/aadec.c b/libavformat/aadec.c index 266a8e85ac..cf5f3d107a 100644 --- a/libavformat/aadec.c +++ b/libavformat/aadec.c @@ -173,22 +173,22 @@ static int aa_read_header(AVFormatContext *s) av_freep(&c->tea_ctx); return AVERROR(ENOMEM); } - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; if (!strcmp(codec_name, "mp332")) { - st->codec->codec_id = AV_CODEC_ID_MP3; - st->codec->sample_rate = 22050; + st->codecpar->codec_id = AV_CODEC_ID_MP3; + st->codecpar->sample_rate = 22050; st->need_parsing = AVSTREAM_PARSE_FULL_RAW; st->start_time = 0; } else if (!strcmp(codec_name, "acelp85")) { - st->codec->codec_id = AV_CODEC_ID_SIPR; - st->codec->block_align = 19; - st->codec->channels = 1; - st->codec->sample_rate = 8500; + st->codecpar->codec_id = AV_CODEC_ID_SIPR; + st->codecpar->block_align = 19; + st->codecpar->channels = 1; + st->codecpar->sample_rate = 8500; } else if (!strcmp(codec_name, "acelp16")) { - st->codec->codec_id = AV_CODEC_ID_SIPR; - st->codec->block_align = 20; - st->codec->channels = 1; - st->codec->sample_rate = 16000; + st->codecpar->codec_id = AV_CODEC_ID_SIPR; + st->codecpar->block_align = 20; + st->codecpar->channels = 1; + st->codecpar->sample_rate = 16000; } /* determine, and jump to audio start offset */ diff --git a/libavformat/acm.c b/libavformat/acm.c index afcafa8d7a..08dd9282fa 100644 --- a/libavformat/acm.c +++ b/libavformat/acm.c @@ -41,24 +41,24 @@ static int acm_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_INTERPLAY_ACM; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_INTERPLAY_ACM; - ff_alloc_extradata(st->codec, 14); - if (!st->codec->extradata) + ff_alloc_extradata(st->codecpar, 14); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - ret = avio_read(s->pb, st->codec->extradata, 14); + ret = avio_read(s->pb, st->codecpar->extradata, 14); if (ret < 10) return ret < 0 ? ret : AVERROR_EOF; - st->codec->channels = AV_RL16(st->codec->extradata + 8); - st->codec->sample_rate = AV_RL16(st->codec->extradata + 10); - if (st->codec->channels <= 0 || st->codec->sample_rate <= 0) + st->codecpar->channels = AV_RL16(st->codecpar->extradata + 8); + st->codecpar->sample_rate = AV_RL16(st->codecpar->extradata + 10); + if (st->codecpar->channels <= 0 || st->codecpar->sample_rate <= 0) return AVERROR_INVALIDDATA; st->start_time = 0; - st->duration = AV_RL32(st->codec->extradata + 4) / st->codec->channels; + st->duration = AV_RL32(st->codecpar->extradata + 4) / st->codecpar->channels; st->need_parsing = AVSTREAM_PARSE_FULL_RAW; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } diff --git a/libavformat/act.c b/libavformat/act.c index 35aacbc459..fe67411787 100644 --- a/libavformat/act.c +++ b/libavformat/act.c @@ -75,29 +75,29 @@ static int read_header(AVFormatContext *s) avio_skip(pb, 16); size=avio_rl32(pb); - ff_get_wav_header(s, pb, st->codec, size, 0); + ff_get_wav_header(s, pb, st->codecpar, size, 0); /* 8000Hz (Fine-rec) file format has 10 bytes long packets with 10ms of sound data in them */ - if (st->codec->sample_rate != 8000) { - av_log(s, AV_LOG_ERROR, "Sample rate %d is not supported.\n", st->codec->sample_rate); + if (st->codecpar->sample_rate != 8000) { + av_log(s, AV_LOG_ERROR, "Sample rate %d is not supported.\n", st->codecpar->sample_rate); return AVERROR_INVALIDDATA; } - st->codec->frame_size=80; - st->codec->channels=1; + st->codecpar->frame_size=80; + st->codecpar->channels=1; avpriv_set_pts_info(st, 64, 1, 100); - st->codec->codec_id=AV_CODEC_ID_G729; + st->codecpar->codec_id=AV_CODEC_ID_G729; avio_seek(pb, 257, SEEK_SET); msec=avio_rl16(pb); sec=avio_r8(pb); min=avio_rl32(pb); - st->duration = av_rescale(1000*(min*60+sec)+msec, st->codec->sample_rate, 1000 * st->codec->frame_size); + st->duration = av_rescale(1000*(min*60+sec)+msec, st->codecpar->sample_rate, 1000 * st->codecpar->frame_size); ctx->bytes_left_in_chunk=CHUNK_SIZE; @@ -113,10 +113,10 @@ static int read_packet(AVFormatContext *s, ACTContext *ctx = s->priv_data; AVIOContext *pb = s->pb; int ret; - int frame_size=s->streams[0]->codec->sample_rate==8000?10:22; + int frame_size=s->streams[0]->codecpar->sample_rate==8000?10:22; - if(s->streams[0]->codec->sample_rate==8000) + if(s->streams[0]->codecpar->sample_rate==8000) ret=av_new_packet(pkt, 10); else ret=av_new_packet(pkt, 11); @@ -124,7 +124,7 @@ static int read_packet(AVFormatContext *s, if(ret) return ret; - if(s->streams[0]->codec->sample_rate==4400 && !ctx->second_packet) + if(s->streams[0]->codecpar->sample_rate==4400 && !ctx->second_packet) { ret = avio_read(pb, ctx->audio_buffer, frame_size); @@ -147,7 +147,7 @@ static int read_packet(AVFormatContext *s, ctx->second_packet=1; } - else if(s->streams[0]->codec->sample_rate==4400 && ctx->second_packet) + else if(s->streams[0]->codecpar->sample_rate==4400 && ctx->second_packet) { pkt->data[0]=ctx->audio_buffer[5]; pkt->data[1]=ctx->audio_buffer[17]; diff --git a/libavformat/adp.c b/libavformat/adp.c index f53375aea0..9ab2ec4566 100644 --- a/libavformat/adp.c +++ b/libavformat/adp.c @@ -53,16 +53,16 @@ static int adp_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_DTK; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; - st->codec->channels = 2; - st->codec->sample_rate = 48000; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_DTK; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->channels = 2; + st->codecpar->sample_rate = 48000; st->start_time = 0; if (s->pb->seekable) - st->duration = av_get_audio_frame_duration(st->codec, avio_size(s->pb)); + st->duration = av_get_audio_frame_duration2(st->codecpar, avio_size(s->pb)); - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } diff --git a/libavformat/ads.c b/libavformat/ads.c index bda2673bad..73ea7c7d54 100644 --- a/libavformat/ads.c +++ b/libavformat/ads.c @@ -42,39 +42,39 @@ static int ads_read_header(AVFormatContext *s) return AVERROR(ENOMEM); avio_skip(s->pb, 8); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; codec = avio_rl32(s->pb); - st->codec->sample_rate = avio_rl32(s->pb); - if (st->codec->sample_rate <= 0) + st->codecpar->sample_rate = avio_rl32(s->pb); + if (st->codecpar->sample_rate <= 0) return AVERROR_INVALIDDATA; - st->codec->channels = avio_rl32(s->pb); - if (st->codec->channels <= 0) + st->codecpar->channels = avio_rl32(s->pb); + if (st->codecpar->channels <= 0) return AVERROR_INVALIDDATA; align = avio_rl32(s->pb); - if (align <= 0 || align > INT_MAX / st->codec->channels) + if (align <= 0 || align > INT_MAX / st->codecpar->channels) return AVERROR_INVALIDDATA; if (codec == 1) - st->codec->codec_id = AV_CODEC_ID_PCM_S16LE_PLANAR; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE_PLANAR; else - st->codec->codec_id = AV_CODEC_ID_ADPCM_PSX; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX; - st->codec->block_align = st->codec->channels * align; + st->codecpar->block_align = st->codecpar->channels * align; avio_skip(s->pb, 12); size = avio_rl32(s->pb); - if (st->codec->codec_id == AV_CODEC_ID_ADPCM_PSX) - st->duration = (size - 0x40) / 16 / st->codec->channels * 28; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + if (st->codecpar->codec_id == AV_CODEC_ID_ADPCM_PSX) + st->duration = (size - 0x40) / 16 / st->codecpar->channels * 28; + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } static int ads_read_packet(AVFormatContext *s, AVPacket *pkt) { - AVCodecContext *codec = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; int ret; - ret = av_get_packet(s->pb, pkt, codec->block_align); + ret = av_get_packet(s->pb, pkt, par->block_align); pkt->stream_index = 0; return ret; } diff --git a/libavformat/adtsenc.c b/libavformat/adtsenc.c index 242d7383f0..5e006dd38f 100644 --- a/libavformat/adtsenc.c +++ b/libavformat/adtsenc.c @@ -97,13 +97,13 @@ static int adts_decode_extradata(AVFormatContext *s, ADTSContext *adts, const ui static int adts_write_header(AVFormatContext *s) { ADTSContext *adts = s->priv_data; - AVCodecContext *avc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; if (adts->id3v2tag) ff_id3v2_write_simple(s, 4, ID3v2_DEFAULT_MAGIC); - if (avc->extradata_size > 0) - return adts_decode_extradata(s, adts, avc->extradata, - avc->extradata_size); + if (par->extradata_size > 0) + return adts_decode_extradata(s, adts, par->extradata, + par->extradata_size); return 0; } diff --git a/libavformat/adxdec.c b/libavformat/adxdec.c index 05cef0b07c..fd096702c9 100644 --- a/libavformat/adxdec.c +++ b/libavformat/adxdec.c @@ -50,15 +50,15 @@ static int adx_probe(AVProbeData *p) static int adx_read_packet(AVFormatContext *s, AVPacket *pkt) { ADXDemuxerContext *c = s->priv_data; - AVCodecContext *avctx = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; int ret, size; - if (avctx->channels <= 0) { - av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", avctx->channels); + if (par->channels <= 0) { + av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", par->channels); return AVERROR_INVALIDDATA; } - size = BLOCK_SIZE * avctx->channels; + size = BLOCK_SIZE * par->channels; pkt->pos = avio_tell(s->pb); pkt->stream_index = 0; @@ -82,37 +82,37 @@ static int adx_read_packet(AVFormatContext *s, AVPacket *pkt) static int adx_read_header(AVFormatContext *s) { ADXDemuxerContext *c = s->priv_data; - AVCodecContext *avctx; + AVCodecParameters *par; AVStream *st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - avctx = s->streams[0]->codec; + par = s->streams[0]->codecpar; if (avio_rb16(s->pb) != 0x8000) return AVERROR_INVALIDDATA; c->header_size = avio_rb16(s->pb) + 4; avio_seek(s->pb, -4, SEEK_CUR); - if (ff_get_extradata(avctx, s->pb, c->header_size) < 0) + if (ff_get_extradata(par, s->pb, c->header_size) < 0) return AVERROR(ENOMEM); - if (avctx->extradata_size < 12) { + if (par->extradata_size < 12) { av_log(s, AV_LOG_ERROR, "Invalid extradata size.\n"); return AVERROR_INVALIDDATA; } - avctx->channels = AV_RB8(avctx->extradata + 7); - avctx->sample_rate = AV_RB32(avctx->extradata + 8); + par->channels = AV_RB8 (par->extradata + 7); + par->sample_rate = AV_RB32(par->extradata + 8); - if (avctx->channels <= 0) { - av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", avctx->channels); + if (par->channels <= 0) { + av_log(s, AV_LOG_ERROR, "invalid number of channels %d\n", par->channels); return AVERROR_INVALIDDATA; } - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->iformat->raw_codec_id; + par->codec_type = AVMEDIA_TYPE_AUDIO; + par->codec_id = s->iformat->raw_codec_id; - avpriv_set_pts_info(st, 64, BLOCK_SAMPLES, avctx->sample_rate); + avpriv_set_pts_info(st, 64, BLOCK_SAMPLES, par->sample_rate); return 0; } diff --git a/libavformat/aea.c b/libavformat/aea.c index db415c9543..f4f1363f9b 100644 --- a/libavformat/aea.c +++ b/libavformat/aea.c @@ -67,29 +67,29 @@ static int aea_read_header(AVFormatContext *s) /* Parse the amount of channels and skip to pos 2048(0x800) */ avio_skip(s->pb, 264); - st->codec->channels = avio_r8(s->pb); + st->codecpar->channels = avio_r8(s->pb); avio_skip(s->pb, 1783); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ATRAC1; - st->codec->sample_rate = 44100; - st->codec->bit_rate = 292000; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ATRAC1; + st->codecpar->sample_rate = 44100; + st->codecpar->bit_rate = 292000; - if (st->codec->channels != 1 && st->codec->channels != 2) { - av_log(s,AV_LOG_ERROR,"Channels %d not supported!\n",st->codec->channels); + if (st->codecpar->channels != 1 && st->codecpar->channels != 2) { + av_log(s, AV_LOG_ERROR, "Channels %d not supported!\n", st->codecpar->channels); return AVERROR_INVALIDDATA; } - st->codec->channel_layout = (st->codec->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; + st->codecpar->channel_layout = (st->codecpar->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; - st->codec->block_align = AT1_SU_SIZE * st->codec->channels; + st->codecpar->block_align = AT1_SU_SIZE * st->codecpar->channels; return 0; } static int aea_read_packet(AVFormatContext *s, AVPacket *pkt) { - int ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align); + int ret = av_get_packet(s->pb, pkt, s->streams[0]->codecpar->block_align); pkt->stream_index = 0; if (ret <= 0) diff --git a/libavformat/afc.c b/libavformat/afc.c index 8dbd232fc1..542cb168fc 100644 --- a/libavformat/afc.c +++ b/libavformat/afc.c @@ -35,20 +35,20 @@ static int afc_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_AFC; - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_AFC; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; - if (ff_alloc_extradata(st->codec, 1)) + if (ff_alloc_extradata(st->codecpar, 1)) return AVERROR(ENOMEM); - st->codec->extradata[0] = 8 * st->codec->channels; + st->codecpar->extradata[0] = 8 * st->codecpar->channels; c->data_end = avio_rb32(s->pb) + 32LL; st->duration = avio_rb32(s->pb); - st->codec->sample_rate = avio_rb16(s->pb); + st->codecpar->sample_rate = avio_rb16(s->pb); avio_skip(s->pb, 22); - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c index 34b266d31e..bb5299c06f 100644 --- a/libavformat/aiffdec.c +++ b/libavformat/aiffdec.c @@ -95,7 +95,7 @@ static int get_aiff_header(AVFormatContext *s, int size, unsigned version) { AVIOContext *pb = s->pb; - AVCodecContext *codec = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; AIFFInputContext *aiff = s->priv_data; int exp; uint64_t val; @@ -104,10 +104,10 @@ static int get_aiff_header(AVFormatContext *s, int size, if (size & 1) size++; - codec->codec_type = AVMEDIA_TYPE_AUDIO; - codec->channels = avio_rb16(pb); + par->codec_type = AVMEDIA_TYPE_AUDIO; + par->channels = avio_rb16(pb); num_frames = avio_rb32(pb); - codec->bits_per_coded_sample = avio_rb16(pb); + par->bits_per_coded_sample = avio_rb16(pb); exp = avio_rb16(pb) - 16383 - 63; val = avio_rb64(pb); @@ -119,29 +119,29 @@ static int get_aiff_header(AVFormatContext *s, int size, sample_rate = val << exp; else sample_rate = (val + (1ULL<<(-exp-1))) >> -exp; - codec->sample_rate = sample_rate; + par->sample_rate = sample_rate; size -= 18; /* get codec id for AIFF-C */ if (size < 4) { version = AIFF; } else if (version == AIFF_C_VERSION1) { - codec->codec_tag = avio_rl32(pb); - codec->codec_id = ff_codec_get_id(ff_codec_aiff_tags, codec->codec_tag); - if (codec->codec_id == AV_CODEC_ID_NONE) { + par->codec_tag = avio_rl32(pb); + par->codec_id = ff_codec_get_id(ff_codec_aiff_tags, par->codec_tag); + if (par->codec_id == AV_CODEC_ID_NONE) { char tag[32]; - av_get_codec_tag_string(tag, sizeof(tag), codec->codec_tag); + av_get_codec_tag_string(tag, sizeof(tag), par->codec_tag); avpriv_request_sample(s, "unknown or unsupported codec tag: %s", tag); } size -= 4; } - if (version != AIFF_C_VERSION1 || codec->codec_id == AV_CODEC_ID_PCM_S16BE) { - codec->codec_id = aiff_codec_get_id(codec->bits_per_coded_sample); - codec->bits_per_coded_sample = av_get_bits_per_sample(codec->codec_id); + if (version != AIFF_C_VERSION1 || par->codec_id == AV_CODEC_ID_PCM_S16BE) { + par->codec_id = aiff_codec_get_id(par->bits_per_coded_sample); + par->bits_per_coded_sample = av_get_bits_per_sample(par->codec_id); aiff->block_duration = 1; } else { - switch (codec->codec_id) { + switch (par->codec_id) { case AV_CODEC_ID_PCM_F32BE: case AV_CODEC_ID_PCM_F64BE: case AV_CODEC_ID_PCM_S16LE: @@ -150,39 +150,39 @@ static int get_aiff_header(AVFormatContext *s, int size, aiff->block_duration = 1; break; case AV_CODEC_ID_ADPCM_IMA_QT: - codec->block_align = 34*codec->channels; + par->block_align = 34 * par->channels; break; case AV_CODEC_ID_MACE3: - codec->block_align = 2*codec->channels; + par->block_align = 2 * par->channels; break; case AV_CODEC_ID_ADPCM_G726LE: - codec->bits_per_coded_sample = 5; + par->bits_per_coded_sample = 5; case AV_CODEC_ID_ADPCM_IMA_WS: case AV_CODEC_ID_ADPCM_G722: case AV_CODEC_ID_MACE6: case AV_CODEC_ID_SDX2_DPCM: - codec->block_align = 1*codec->channels; + par->block_align = 1 * par->channels; break; case AV_CODEC_ID_GSM: - codec->block_align = 33; + par->block_align = 33; break; default: aiff->block_duration = 1; break; } - if (codec->block_align > 0) - aiff->block_duration = av_get_audio_frame_duration(codec, - codec->block_align); + if (par->block_align > 0) + aiff->block_duration = av_get_audio_frame_duration2(par, + par->block_align); } /* Block align needs to be computed in all cases, as the definition * is specific to applications -> here we use the WAVE format definition */ - if (!codec->block_align) - codec->block_align = (av_get_bits_per_sample(codec->codec_id) * codec->channels) >> 3; + if (!par->block_align) + par->block_align = (av_get_bits_per_sample(par->codec_id) * par->channels) >> 3; if (aiff->block_duration) { - codec->bit_rate = codec->sample_rate * (codec->block_align << 3) / - aiff->block_duration; + par->bit_rate = par->sample_rate * (par->block_align << 3) / + aiff->block_duration; } /* Chunk is over */ @@ -238,7 +238,7 @@ static int aiff_read_header(AVFormatContext *s) /* parse different chunks */ size = get_tag(pb, &tag); - if (size == AVERROR_EOF && offset > 0 && st->codec->block_align) { + if (size == AVERROR_EOF && offset > 0 && st->codecpar->block_align) { av_log(s, AV_LOG_WARNING, "header parser hit EOF\n"); goto got_sound; } @@ -288,7 +288,7 @@ static int aiff_read_header(AVFormatContext *s) offset = avio_rb32(pb); /* Offset of sound data */ avio_rb32(pb); /* BlockSize... don't care */ offset += avio_tell(pb); /* Compute absolute data offset */ - if (st->codec->block_align && !pb->seekable) /* Assume COMM already parsed */ + if (st->codecpar->block_align && !pb->seekable) /* Assume COMM already parsed */ goto got_sound; if (!pb->seekable) { av_log(s, AV_LOG_ERROR, "file is not seekable\n"); @@ -299,26 +299,26 @@ static int aiff_read_header(AVFormatContext *s) case MKTAG('w', 'a', 'v', 'e'): if ((uint64_t)size > (1<<30)) return -1; - if (ff_get_extradata(st->codec, pb, size) < 0) + if (ff_get_extradata(st->codecpar, pb, size) < 0) return AVERROR(ENOMEM); - if (st->codec->codec_id == AV_CODEC_ID_QDM2 && size>=12*4 && !st->codec->block_align) { - st->codec->block_align = AV_RB32(st->codec->extradata+11*4); - aiff->block_duration = AV_RB32(st->codec->extradata+9*4); - } else if (st->codec->codec_id == AV_CODEC_ID_QCELP) { + if (st->codecpar->codec_id == AV_CODEC_ID_QDM2 && size>=12*4 && !st->codecpar->block_align) { + st->codecpar->block_align = AV_RB32(st->codecpar->extradata+11*4); + aiff->block_duration = AV_RB32(st->codecpar->extradata+9*4); + } else if (st->codecpar->codec_id == AV_CODEC_ID_QCELP) { char rate = 0; if (size >= 25) - rate = st->codec->extradata[24]; + rate = st->codecpar->extradata[24]; switch (rate) { case 'H': // RATE_HALF - st->codec->block_align = 17; + st->codecpar->block_align = 17; break; case 'F': // RATE_FULL default: - st->codec->block_align = 35; + st->codecpar->block_align = 35; } aiff->block_duration = 160; - st->codec->bit_rate = st->codec->sample_rate * (st->codec->block_align << 3) / - aiff->block_duration; + st->codecpar->bit_rate = st->codecpar->sample_rate * (st->codecpar->block_align << 3) / + aiff->block_duration; } break; case MKTAG('C','H','A','N'): @@ -326,7 +326,7 @@ static int aiff_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; break; case 0: - if (offset > 0 && st->codec->block_align) // COMM && SSND + if (offset > 0 && st->codecpar->block_align) // COMM && SSND goto got_sound; default: /* Jump */ if (size & 1) /* Always even aligned */ @@ -336,13 +336,13 @@ static int aiff_read_header(AVFormatContext *s) } got_sound: - if (!st->codec->block_align) { + if (!st->codecpar->block_align) { av_log(s, AV_LOG_ERROR, "could not find COMM tag or invalid block_align value\n"); return -1; } /* Now positioned, get the sound data start and end */ - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); st->start_time = 0; st->duration = st->nb_frames * aiff->block_duration; @@ -368,26 +368,26 @@ static int aiff_read_packet(AVFormatContext *s, return AVERROR_EOF; /* Now for that packet */ - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_ADPCM_IMA_QT: case AV_CODEC_ID_GSM: case AV_CODEC_ID_QDM2: case AV_CODEC_ID_QCELP: - size = st->codec->block_align; + size = st->codecpar->block_align; break; default: - size = (MAX_SIZE / st->codec->block_align) * st->codec->block_align; + size = (MAX_SIZE / st->codecpar->block_align) * st->codecpar->block_align; } size = FFMIN(max_size, size); res = av_get_packet(s->pb, pkt, size); if (res < 0) return res; - if (size >= st->codec->block_align) + if (size >= st->codecpar->block_align) pkt->flags &= ~AV_PKT_FLAG_CORRUPT; /* Only one stream in an AIFF file */ pkt->stream_index = 0; - pkt->duration = (res / st->codec->block_align) * aiff->block_duration; + pkt->duration = (res / st->codecpar->block_align) * aiff->block_duration; return 0; } diff --git a/libavformat/aiffenc.c b/libavformat/aiffenc.c index 25dc5e6284..d876997f9b 100644 --- a/libavformat/aiffenc.c +++ b/libavformat/aiffenc.c @@ -102,16 +102,16 @@ static int aiff_write_header(AVFormatContext *s) { AIFFOutputContext *aiff = s->priv_data; AVIOContext *pb = s->pb; - AVCodecContext *enc; + AVCodecParameters *par; uint64_t sample_rate; int i, aifc = 0; aiff->audio_stream_idx = -1; for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (aiff->audio_stream_idx < 0 && st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (aiff->audio_stream_idx < 0 && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { aiff->audio_stream_idx = i; - } else if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO) { + } else if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) { av_log(s, AV_LOG_ERROR, "AIFF allows only one audio stream and a picture.\n"); return AVERROR(EINVAL); } @@ -121,12 +121,12 @@ static int aiff_write_header(AVFormatContext *s) return AVERROR(EINVAL); } - enc = s->streams[aiff->audio_stream_idx]->codec; + par = s->streams[aiff->audio_stream_idx]->codecpar; /* First verify if format is ok */ - if (!enc->codec_tag) + if (!par->codec_tag) return -1; - if (enc->codec_tag != MKTAG('N','O','N','E')) + if (par->codec_tag != MKTAG('N','O','N','E')) aifc = 1; /* FORM AIFF header */ @@ -136,7 +136,7 @@ static int aiff_write_header(AVFormatContext *s) ffio_wfourcc(pb, aifc ? "AIFC" : "AIFF"); if (aifc) { // compressed audio - if (!enc->block_align) { + if (!par->block_align) { av_log(s, AV_LOG_ERROR, "block align not set\n"); return -1; } @@ -146,10 +146,10 @@ static int aiff_write_header(AVFormatContext *s) avio_wb32(pb, 0xA2805140); } - if (enc->channels > 2 && enc->channel_layout) { + if (par->channels > 2 && par->channel_layout) { ffio_wfourcc(pb, "CHAN"); avio_wb32(pb, 12); - ff_mov_write_chan(pb, enc->channel_layout); + ff_mov_write_chan(pb, par->channel_layout); } put_meta(s, "title", MKTAG('N', 'A', 'M', 'E')); @@ -160,35 +160,35 @@ static int aiff_write_header(AVFormatContext *s) /* Common chunk */ ffio_wfourcc(pb, "COMM"); avio_wb32(pb, aifc ? 24 : 18); /* size */ - avio_wb16(pb, enc->channels); /* Number of channels */ + avio_wb16(pb, par->channels); /* Number of channels */ aiff->frames = avio_tell(pb); avio_wb32(pb, 0); /* Number of frames */ - if (!enc->bits_per_coded_sample) - enc->bits_per_coded_sample = av_get_bits_per_sample(enc->codec_id); - if (!enc->bits_per_coded_sample) { + if (!par->bits_per_coded_sample) + par->bits_per_coded_sample = av_get_bits_per_sample(par->codec_id); + if (!par->bits_per_coded_sample) { av_log(s, AV_LOG_ERROR, "could not compute bits per sample\n"); return -1; } - if (!enc->block_align) - enc->block_align = (enc->bits_per_coded_sample * enc->channels) >> 3; + if (!par->block_align) + par->block_align = (par->bits_per_coded_sample * par->channels) >> 3; - avio_wb16(pb, enc->bits_per_coded_sample); /* Sample size */ + avio_wb16(pb, par->bits_per_coded_sample); /* Sample size */ - sample_rate = av_double2int(enc->sample_rate); + sample_rate = av_double2int(par->sample_rate); avio_wb16(pb, (sample_rate >> 52) + (16383 - 1023)); avio_wb64(pb, UINT64_C(1) << 63 | sample_rate << 11); if (aifc) { - avio_wl32(pb, enc->codec_tag); + avio_wl32(pb, par->codec_tag); avio_wb16(pb, 0); } - if (enc->codec_tag == MKTAG('Q','D','M','2') && enc->extradata_size) { + if (par->codec_tag == MKTAG('Q','D','M','2') && par->extradata_size) { ffio_wfourcc(pb, "wave"); - avio_wb32(pb, enc->extradata_size); - avio_write(pb, enc->extradata, enc->extradata_size); + avio_wb32(pb, par->extradata_size); + avio_write(pb, par->extradata, par->extradata_size); } /* Sound data chunk */ @@ -199,7 +199,7 @@ static int aiff_write_header(AVFormatContext *s) avio_wb32(pb, 0); /* Block-size (block align) */ avpriv_set_pts_info(s->streams[aiff->audio_stream_idx], 64, 1, - s->streams[aiff->audio_stream_idx]->codec->sample_rate); + s->streams[aiff->audio_stream_idx]->codecpar->sample_rate); /* Data is starting here */ avio_flush(pb); @@ -217,7 +217,7 @@ static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt) int ret; AVPacketList *pict_list, *last; - if (s->streams[pkt->stream_index]->codec->codec_type != AVMEDIA_TYPE_VIDEO) + if (s->streams[pkt->stream_index]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) return 0; /* warn only once for each stream */ @@ -256,7 +256,7 @@ static int aiff_write_trailer(AVFormatContext *s) AVIOContext *pb = s->pb; AIFFOutputContext *aiff = s->priv_data; AVPacketList *pict_list = aiff->pict_list; - AVCodecContext *enc = s->streams[aiff->audio_stream_idx]->codec; + AVCodecParameters *par = s->streams[aiff->audio_stream_idx]->codecpar; /* Chunks sizes must be even */ int64_t file_size, end_size; @@ -269,7 +269,7 @@ static int aiff_write_trailer(AVFormatContext *s) if (s->pb->seekable) { /* Number of sample frames */ avio_seek(pb, aiff->frames, SEEK_SET); - avio_wb32(pb, (file_size-aiff->ssnd-12)/enc->block_align); + avio_wb32(pb, (file_size - aiff->ssnd - 12) / par->block_align); /* Sound Data chunk size */ avio_seek(pb, aiff->ssnd, SEEK_SET); diff --git a/libavformat/aixdec.c b/libavformat/aixdec.c index 83395581a4..5f40d6bdcf 100644 --- a/libavformat/aixdec.c +++ b/libavformat/aixdec.c @@ -61,11 +61,11 @@ static int aix_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_ADX; - st->codec->sample_rate = avio_rb32(s->pb); - st->codec->channels = avio_r8(s->pb); - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_ADX; + st->codecpar->sample_rate = avio_rb32(s->pb); + st->codecpar->channels = avio_r8(s->pb); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); avio_skip(s->pb, 3); } @@ -77,7 +77,7 @@ static int aix_read_header(AVFormatContext *s) if (size <= 8) return AVERROR_INVALIDDATA; avio_skip(s->pb, 8); - ff_get_extradata(s->streams[i]->codec, s->pb, size - 8); + ff_get_extradata(s->streams[i]->codecpar, s->pb, size - 8); } return 0; diff --git a/libavformat/amr.c b/libavformat/amr.c index 137df110ef..c113e92191 100644 --- a/libavformat/amr.c +++ b/libavformat/amr.c @@ -42,13 +42,13 @@ static const char AMRWB_header[] = "#!AMR-WB\n"; static int amr_write_header(AVFormatContext *s) { AVIOContext *pb = s->pb; - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; s->priv_data = NULL; - if (enc->codec_id == AV_CODEC_ID_AMR_NB) { + if (par->codec_id == AV_CODEC_ID_AMR_NB) { avio_write(pb, AMR_header, sizeof(AMR_header) - 1); /* magic number */ - } else if (enc->codec_id == AV_CODEC_ID_AMR_WB) { + } else if (par->codec_id == AV_CODEC_ID_AMR_WB) { avio_write(pb, AMRWB_header, sizeof(AMRWB_header) - 1); /* magic number */ } else { return -1; @@ -94,25 +94,25 @@ static int amr_read_header(AVFormatContext *s) return -1; } - st->codec->codec_tag = MKTAG('s', 'a', 'w', 'b'); - st->codec->codec_id = AV_CODEC_ID_AMR_WB; - st->codec->sample_rate = 16000; + st->codecpar->codec_tag = MKTAG('s', 'a', 'w', 'b'); + st->codecpar->codec_id = AV_CODEC_ID_AMR_WB; + st->codecpar->sample_rate = 16000; } else { - st->codec->codec_tag = MKTAG('s', 'a', 'm', 'r'); - st->codec->codec_id = AV_CODEC_ID_AMR_NB; - st->codec->sample_rate = 8000; + st->codecpar->codec_tag = MKTAG('s', 'a', 'm', 'r'); + st->codecpar->codec_id = AV_CODEC_ID_AMR_NB; + st->codecpar->sample_rate = 8000; } - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } static int amr_read_packet(AVFormatContext *s, AVPacket *pkt) { - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; int read, size = 0, toc, mode; int64_t pos = avio_tell(s->pb); AMRContext *amr = s->priv_data; @@ -125,13 +125,13 @@ static int amr_read_packet(AVFormatContext *s, AVPacket *pkt) toc = avio_r8(s->pb); mode = (toc >> 3) & 0x0F; - if (enc->codec_id == AV_CODEC_ID_AMR_NB) { + if (par->codec_id == AV_CODEC_ID_AMR_NB) { static const uint8_t packed_size[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 }; size = packed_size[mode] + 1; - } else if (enc->codec_id == AV_CODEC_ID_AMR_WB) { + } else if (par->codec_id == AV_CODEC_ID_AMR_WB) { static const uint8_t packed_size[16] = { 18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1 }; @@ -145,13 +145,13 @@ static int amr_read_packet(AVFormatContext *s, AVPacket *pkt) if (amr->cumulated_size < UINT64_MAX - size) { amr->cumulated_size += size; /* Both AMR formats have 50 frames per second */ - s->streams[0]->codec->bit_rate = amr->cumulated_size / ++amr->block_count * 8 * 50; + s->streams[0]->codecpar->bit_rate = amr->cumulated_size / ++amr->block_count * 8 * 50; } pkt->stream_index = 0; pkt->pos = pos; pkt->data[0] = toc; - pkt->duration = enc->codec_id == AV_CODEC_ID_AMR_NB ? 160 : 320; + pkt->duration = par->codec_id == AV_CODEC_ID_AMR_NB ? 160 : 320; read = avio_read(s->pb, pkt->data + 1, size - 1); if (read != size - 1) { diff --git a/libavformat/anm.c b/libavformat/anm.c index 23200474bd..b31757ab0a 100644 --- a/libavformat/anm.c +++ b/libavformat/anm.c @@ -100,11 +100,11 @@ static int read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_ANM; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = avio_rl16(pb); - st->codec->height = avio_rl16(pb); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_ANM; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = avio_rl16(pb); + st->codecpar->height = avio_rl16(pb); if (avio_r8(pb) != 0) goto invalid; avio_skip(pb, 1); /* frame rate multiplier info */ @@ -132,12 +132,12 @@ static int read_header(AVFormatContext *s) avio_skip(pb, 58); /* color cycling and palette data */ - st->codec->extradata_size = 16*8 + 4*256; - st->codec->extradata = av_mallocz(st->codec->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) { + st->codecpar->extradata_size = 16*8 + 4*256; + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) { return AVERROR(ENOMEM); } - ret = avio_read(pb, st->codec->extradata, st->codec->extradata_size); + ret = avio_read(pb, st->codecpar->extradata, st->codecpar->extradata_size); if (ret < 0) return ret; diff --git a/libavformat/apc.c b/libavformat/apc.c index 21bb514cd0..64c1c6db3e 100644 --- a/libavformat/apc.c +++ b/libavformat/apc.c @@ -46,28 +46,28 @@ static int apc_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_APC; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_APC; avio_rl32(pb); /* number of samples */ - st->codec->sample_rate = avio_rl32(pb); + st->codecpar->sample_rate = avio_rl32(pb); /* initial predictor values for adpcm decoder */ - if (ff_get_extradata(st->codec, pb, 2 * 4) < 0) + if (ff_get_extradata(st->codecpar, pb, 2 * 4) < 0) return AVERROR(ENOMEM); if (avio_rl32(pb)) { - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } else { - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } - st->codec->bits_per_coded_sample = 4; - st->codec->bit_rate = st->codec->bits_per_coded_sample * st->codec->channels - * st->codec->sample_rate; - st->codec->block_align = 1; + st->codecpar->bits_per_coded_sample = 4; + st->codecpar->bit_rate = st->codecpar->bits_per_coded_sample * st->codecpar->channels + * st->codecpar->sample_rate; + st->codecpar->block_align = 1; return 0; } diff --git a/libavformat/ape.c b/libavformat/ape.c index 3e819728cc..061f32866f 100644 --- a/libavformat/ape.c +++ b/libavformat/ape.c @@ -348,23 +348,23 @@ static int ape_read_header(AVFormatContext * s) total_blocks = (ape->totalframes == 0) ? 0 : ((ape->totalframes - 1) * ape->blocksperframe) + ape->finalframeblocks; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_APE; - st->codec->codec_tag = MKTAG('A', 'P', 'E', ' '); - st->codec->channels = ape->channels; - st->codec->sample_rate = ape->samplerate; - st->codec->bits_per_coded_sample = ape->bps; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_APE; + st->codecpar->codec_tag = MKTAG('A', 'P', 'E', ' '); + st->codecpar->channels = ape->channels; + st->codecpar->sample_rate = ape->samplerate; + st->codecpar->bits_per_coded_sample = ape->bps; st->nb_frames = ape->totalframes; st->start_time = 0; st->duration = total_blocks; avpriv_set_pts_info(st, 64, 1, ape->samplerate); - if (ff_alloc_extradata(st->codec, APE_EXTRADATA_SIZE)) + if (ff_alloc_extradata(st->codecpar, APE_EXTRADATA_SIZE)) return AVERROR(ENOMEM); - AV_WL16(st->codec->extradata + 0, ape->fileversion); - AV_WL16(st->codec->extradata + 2, ape->compressiontype); - AV_WL16(st->codec->extradata + 4, ape->formatflags); + AV_WL16(st->codecpar->extradata + 0, ape->fileversion); + AV_WL16(st->codecpar->extradata + 2, ape->compressiontype); + AV_WL16(st->codecpar->extradata + 4, ape->formatflags); pts = 0; for (i = 0; i < ape->totalframes; i++) { diff --git a/libavformat/apetag.c b/libavformat/apetag.c index 9d415b8b3e..53e076fb8b 100644 --- a/libavformat/apetag.c +++ b/libavformat/apetag.c @@ -89,16 +89,16 @@ static int ape_tag_read_field(AVFormatContext *s) } st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = id; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = id; st->attached_pic = pkt; st->attached_pic.stream_index = st->index; st->attached_pic.flags |= AV_PKT_FLAG_KEY; } else { - if (ff_get_extradata(st->codec, s->pb, size) < 0) + if (ff_get_extradata(st->codecpar, s->pb, size) < 0) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT; + st->codecpar->codec_type = AVMEDIA_TYPE_ATTACHMENT; } } else { value = av_malloc(size+1); diff --git a/libavformat/apngdec.c b/libavformat/apngdec.c index c6403a191d..bb17896ee5 100644 --- a/libavformat/apngdec.c +++ b/libavformat/apngdec.c @@ -122,9 +122,9 @@ end: return AVPROBE_SCORE_MAX; } -static int append_extradata(AVCodecContext *s, AVIOContext *pb, int len) +static int append_extradata(AVCodecParameters *par, AVIOContext *pb, int len) { - int previous_size = s->extradata_size; + int previous_size = par->extradata_size; int new_size, ret; uint8_t *new_extradata; @@ -132,13 +132,13 @@ static int append_extradata(AVCodecContext *s, AVIOContext *pb, int len) return AVERROR_INVALIDDATA; new_size = previous_size + len; - new_extradata = av_realloc(s->extradata, new_size + AV_INPUT_BUFFER_PADDING_SIZE); + new_extradata = av_realloc(par->extradata, new_size + AV_INPUT_BUFFER_PADDING_SIZE); if (!new_extradata) return AVERROR(ENOMEM); - s->extradata = new_extradata; - s->extradata_size = new_size; + par->extradata = new_extradata; + par->extradata_size = new_size; - if ((ret = avio_read(pb, s->extradata + previous_size, len)) < 0) + if ((ret = avio_read(pb, par->extradata + previous_size, len)) < 0) return ret; return previous_size; @@ -170,23 +170,23 @@ static int apng_read_header(AVFormatContext *s) /* set the timebase to something large enough (1/100,000 of second) * to hopefully cope with all sane frame durations */ avpriv_set_pts_info(st, 64, 1, 100000); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_APNG; - st->codec->width = avio_rb32(pb); - st->codec->height = avio_rb32(pb); - if ((ret = av_image_check_size(st->codec->width, st->codec->height, 0, s)) < 0) + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_APNG; + st->codecpar->width = avio_rb32(pb); + st->codecpar->height = avio_rb32(pb); + if ((ret = av_image_check_size(st->codecpar->width, st->codecpar->height, 0, s)) < 0) return ret; /* extradata will contain every chunk up to the first fcTL (excluded) */ - st->codec->extradata = av_malloc(len + 12 + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + st->codecpar->extradata = av_malloc(len + 12 + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - st->codec->extradata_size = len + 12; - AV_WB32(st->codec->extradata, len); - AV_WL32(st->codec->extradata+4, tag); - AV_WB32(st->codec->extradata+8, st->codec->width); - AV_WB32(st->codec->extradata+12, st->codec->height); - if ((ret = avio_read(pb, st->codec->extradata+16, 9)) < 0) + st->codecpar->extradata_size = len + 12; + AV_WB32(st->codecpar->extradata, len); + AV_WL32(st->codecpar->extradata+4, tag); + AV_WB32(st->codecpar->extradata+8, st->codecpar->width); + AV_WB32(st->codecpar->extradata+12, st->codecpar->height); + if ((ret = avio_read(pb, st->codecpar->extradata+16, 9)) < 0) goto fail; while (!avio_feof(pb)) { @@ -218,11 +218,11 @@ static int apng_read_header(AVFormatContext *s) switch (tag) { case MKTAG('a', 'c', 'T', 'L'): if ((ret = avio_seek(pb, -8, SEEK_CUR)) < 0 || - (ret = append_extradata(st->codec, pb, len + 12)) < 0) + (ret = append_extradata(st->codecpar, pb, len + 12)) < 0) goto fail; acTL_found = 1; - ctx->num_frames = AV_RB32(st->codec->extradata + ret + 8); - ctx->num_play = AV_RB32(st->codec->extradata + ret + 12); + ctx->num_frames = AV_RB32(st->codecpar->extradata + ret + 8); + ctx->num_play = AV_RB32(st->codecpar->extradata + ret + 12); av_log(s, AV_LOG_DEBUG, "num_frames: %"PRIu32", num_play: %"PRIu32"\n", ctx->num_frames, ctx->num_play); break; @@ -236,15 +236,15 @@ static int apng_read_header(AVFormatContext *s) return 0; default: if ((ret = avio_seek(pb, -8, SEEK_CUR)) < 0 || - (ret = append_extradata(st->codec, pb, len + 12)) < 0) + (ret = append_extradata(st->codecpar, pb, len + 12)) < 0) goto fail; } } fail: - if (st->codec->extradata_size) { - av_freep(&st->codec->extradata); - st->codec->extradata_size = 0; + if (st->codecpar->extradata_size) { + av_freep(&st->codecpar->extradata); + st->codecpar->extradata_size = 0; } return ret; } @@ -298,15 +298,15 @@ static int decode_fctl_chunk(AVFormatContext *s, APNGDemuxContext *ctx, AVPacket dispose_op, blend_op); - if (width != s->streams[0]->codec->width || - height != s->streams[0]->codec->height || + if (width != s->streams[0]->codecpar->width || + height != s->streams[0]->codecpar->height || x_offset != 0 || y_offset != 0) { if (sequence_number == 0 || - x_offset >= s->streams[0]->codec->width || - width > s->streams[0]->codec->width - x_offset || - y_offset >= s->streams[0]->codec->height || - height > s->streams[0]->codec->height - y_offset) + x_offset >= s->streams[0]->codecpar->width || + width > s->streams[0]->codecpar->width - x_offset || + y_offset >= s->streams[0]->codecpar->height || + height > s->streams[0]->codecpar->height - y_offset) return AVERROR_INVALIDDATA; ctx->is_key_frame = 0; } else { @@ -400,7 +400,7 @@ static int apng_read_packet(AVFormatContext *s, AVPacket *pkt) avio_seek(pb, -8, SEEK_CUR); return AVERROR_EOF; } - if ((ret = avio_seek(pb, s->streams[0]->codec->extradata_size + 8, SEEK_SET)) < 0) + if ((ret = avio_seek(pb, s->streams[0]->codecpar->extradata_size + 8, SEEK_SET)) < 0) return ret; return 0; default: diff --git a/libavformat/apngenc.c b/libavformat/apngenc.c index 4326a7cd3b..e25df2eb5e 100644 --- a/libavformat/apngenc.c +++ b/libavformat/apngenc.c @@ -80,8 +80,8 @@ static int apng_write_header(AVFormatContext *format_context) APNGMuxContext *apng = format_context->priv_data; if (format_context->nb_streams != 1 || - format_context->streams[0]->codec->codec_type != AVMEDIA_TYPE_VIDEO || - format_context->streams[0]->codec->codec_id != AV_CODEC_ID_APNG) { + format_context->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO || + format_context->streams[0]->codecpar->codec_id != AV_CODEC_ID_APNG) { av_log(format_context, AV_LOG_ERROR, "APNG muxer supports only a single video APNG stream.\n"); return AVERROR(EINVAL); @@ -106,7 +106,7 @@ static void flush_packet(AVFormatContext *format_context, AVPacket *packet) APNGMuxContext *apng = format_context->priv_data; AVIOContext *io_context = format_context->pb; AVStream *codec_stream = format_context->streams[0]; - AVCodecContext *codec_context = codec_stream->codec; + AVCodecParameters *codec_par = codec_stream->codecpar; av_assert0(apng->prev_packet); @@ -117,13 +117,13 @@ static void flush_packet(AVFormatContext *format_context, AVPacket *packet) av_log(format_context, AV_LOG_INFO, "Only a single frame so saving as a normal PNG.\n"); // Write normal PNG headers without acTL chunk - existing_acTL_chunk = apng_find_chunk(MKBETAG('a', 'c', 'T', 'L'), codec_context->extradata, codec_context->extradata_size); + existing_acTL_chunk = apng_find_chunk(MKBETAG('a', 'c', 'T', 'L'), codec_par->extradata, codec_par->extradata_size); if (existing_acTL_chunk) { uint8_t *chunk_after_acTL = existing_acTL_chunk + AV_RB32(existing_acTL_chunk) + 12; - avio_write(io_context, codec_context->extradata, existing_acTL_chunk - codec_context->extradata); - avio_write(io_context, chunk_after_acTL, codec_context->extradata + codec_context->extradata_size - chunk_after_acTL); + avio_write(io_context, codec_par->extradata, existing_acTL_chunk - codec_par->extradata); + avio_write(io_context, chunk_after_acTL, codec_par->extradata + codec_par->extradata_size - chunk_after_acTL); } else { - avio_write(io_context, codec_context->extradata, codec_context->extradata_size); + avio_write(io_context, codec_par->extradata, codec_par->extradata_size); } // Write frame data without fcTL chunk @@ -142,9 +142,9 @@ static void flush_packet(AVFormatContext *format_context, AVPacket *packet) uint8_t *existing_acTL_chunk; // Write normal PNG headers - avio_write(io_context, codec_context->extradata, codec_context->extradata_size); + avio_write(io_context, codec_par->extradata, codec_par->extradata_size); - existing_acTL_chunk = apng_find_chunk(MKBETAG('a', 'c', 'T', 'L'), codec_context->extradata, codec_context->extradata_size); + existing_acTL_chunk = apng_find_chunk(MKBETAG('a', 'c', 'T', 'L'), codec_par->extradata, codec_par->extradata_size); if (!existing_acTL_chunk) { uint8_t buf[8]; // Write animation control header diff --git a/libavformat/aqtitledec.c b/libavformat/aqtitledec.c index 7c864c8e10..f0e840b0f7 100644 --- a/libavformat/aqtitledec.c +++ b/libavformat/aqtitledec.c @@ -58,8 +58,8 @@ static int aqt_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 64, aqt->frame_rate.den, aqt->frame_rate.num); - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = AV_CODEC_ID_TEXT; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_TEXT; while (!avio_feof(s->pb)) { char line[4096]; diff --git a/libavformat/asfdec_f.c b/libavformat/asfdec_f.c index 711341328d..2c81b138f2 100644 --- a/libavformat/asfdec_f.c +++ b/libavformat/asfdec_f.c @@ -281,8 +281,8 @@ static int asf_read_picture(AVFormatContext *s, int len) goto fail; } st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = id; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = id; st->attached_pic = pkt; st->attached_pic.stream_index = st->index; st->attached_pic.flags |= AV_PKT_FLAG_KEY; @@ -436,7 +436,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) type = AVMEDIA_TYPE_VIDEO; } else if (!ff_guidcmp(&g, &ff_asf_jfif_media)) { type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MJPEG; + st->codecpar->codec_id = AV_CODEC_ID_MJPEG; } else if (!ff_guidcmp(&g, &ff_asf_command_stream)) { type = AVMEDIA_TYPE_DATA; } else if (!ff_guidcmp(&g, &ff_asf_ext_stream_embed_stream_header)) { @@ -470,18 +470,18 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) } } - st->codec->codec_type = type; + st->codecpar->codec_type = type; if (type == AVMEDIA_TYPE_AUDIO) { - int ret = ff_get_wav_header(s, pb, st->codec, type_specific_size, 0); + int ret = ff_get_wav_header(s, pb, st->codecpar, type_specific_size, 0); if (ret < 0) return ret; if (is_dvr_ms_audio) { // codec_id and codec_tag are unreliable in dvr_ms // files. Set them later by probing stream. st->request_probe = 1; - st->codec->codec_tag = 0; + st->codecpar->codec_tag = 0; } - if (st->codec->codec_id == AV_CODEC_ID_AAC) + if (st->codecpar->codec_id == AV_CODEC_ID_AAC) st->need_parsing = AVSTREAM_PARSE_NONE; else st->need_parsing = AVSTREAM_PARSE_FULL; @@ -507,52 +507,52 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size) avio_r8(pb); avio_rl16(pb); /* size */ sizeX = avio_rl32(pb); /* size */ - st->codec->width = avio_rl32(pb); - st->codec->height = avio_rl32(pb); + st->codecpar->width = avio_rl32(pb); + st->codecpar->height = avio_rl32(pb); /* not available for asf */ avio_rl16(pb); /* panes */ - st->codec->bits_per_coded_sample = avio_rl16(pb); /* depth */ + st->codecpar->bits_per_coded_sample = avio_rl16(pb); /* depth */ tag1 = avio_rl32(pb); avio_skip(pb, 20); if (sizeX > 40) { - st->codec->extradata_size = ffio_limit(pb, sizeX - 40); - st->codec->extradata = av_mallocz(st->codec->extradata_size + + st->codecpar->extradata_size = ffio_limit(pb, sizeX - 40); + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - avio_read(pb, st->codec->extradata, st->codec->extradata_size); + avio_read(pb, st->codecpar->extradata, st->codecpar->extradata_size); } /* Extract palette from extradata if bpp <= 8 */ /* This code assumes that extradata contains only palette */ /* This is true for all paletted codecs implemented in libavcodec */ - if (st->codec->extradata_size && (st->codec->bits_per_coded_sample <= 8)) { + if (st->codecpar->extradata_size && (st->codecpar->bits_per_coded_sample <= 8)) { #if HAVE_BIGENDIAN int i; - for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE) / 4; i++) - asf_st->palette[i] = av_bswap32(((uint32_t *)st->codec->extradata)[i]); + for (i = 0; i < FFMIN(st->codecpar->extradata_size, AVPALETTE_SIZE) / 4; i++) + asf_st->palette[i] = av_bswap32(((uint32_t *)st->codecpar->extradata)[i]); #else - memcpy(asf_st->palette, st->codec->extradata, - FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)); + memcpy(asf_st->palette, st->codecpar->extradata, + FFMIN(st->codecpar->extradata_size, AVPALETTE_SIZE)); #endif asf_st->palette_changed = 1; } - st->codec->codec_tag = tag1; - st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag1); + st->codecpar->codec_tag = tag1; + st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag1); if (tag1 == MKTAG('D', 'V', 'R', ' ')) { st->need_parsing = AVSTREAM_PARSE_FULL; /* issue658 contains wrong w/h and MS even puts a fake seq header * with wrong w/h in extradata while a correct one is in the stream. * maximum lameness */ - st->codec->width = - st->codec->height = 0; - av_freep(&st->codec->extradata); - st->codec->extradata_size = 0; + st->codecpar->width = + st->codecpar->height = 0; + av_freep(&st->codecpar->extradata); + st->codecpar->extradata_size = 0; } - if (st->codec->codec_id == AV_CODEC_ID_H264) + if (st->codecpar->codec_id == AV_CODEC_ID_H264) st->need_parsing = AVSTREAM_PARSE_FULL_ONCE; - if (st->codec->codec_id == AV_CODEC_ID_MPEG4) + if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) st->need_parsing = AVSTREAM_PARSE_FULL_ONCE; } pos2 = avio_tell(pb); @@ -890,21 +890,21 @@ static int asf_read_header(AVFormatContext *s) int stream_num = asf->asfid2avid[i]; if (stream_num >= 0) { AVStream *st = s->streams[stream_num]; - if (!st->codec->bit_rate) - st->codec->bit_rate = asf->stream_bitrates[i]; + if (!st->codecpar->bit_rate) + st->codecpar->bit_rate = asf->stream_bitrates[i]; if (asf->dar[i].num > 0 && asf->dar[i].den > 0) { av_reduce(&st->sample_aspect_ratio.num, &st->sample_aspect_ratio.den, asf->dar[i].num, asf->dar[i].den, INT_MAX); } else if ((asf->dar[0].num > 0) && (asf->dar[0].den > 0) && // Use ASF container value if the stream doesn't set AR. - (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)) + (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)) av_reduce(&st->sample_aspect_ratio.num, &st->sample_aspect_ratio.den, asf->dar[0].num, asf->dar[0].den, INT_MAX); - av_log(s, AV_LOG_TRACE, "i=%d, st->codec->codec_type:%d, asf->dar %d:%d sar=%d:%d\n", - i, st->codec->codec_type, asf->dar[i].num, asf->dar[i].den, + av_log(s, AV_LOG_TRACE, "i=%d, st->codecpar->codec_type:%d, asf->dar %d:%d sar=%d:%d\n", + i, st->codecpar->codec_type, asf->dar[i].num, asf->dar[i].den, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den); // copy and convert language codes to the frontend @@ -1316,9 +1316,9 @@ static int asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt) av_log(asf, AV_LOG_TRACE, "new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n", asf->stream_index, asf->packet_key_frame, asf_st->pkt.flags & AV_PKT_FLAG_KEY, - s->streams[asf->stream_index]->codec->codec_type == AVMEDIA_TYPE_AUDIO, + s->streams[asf->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO, asf_st->packet_obj_size); - if (s->streams[asf->stream_index]->codec->codec_type == AVMEDIA_TYPE_AUDIO) + if (s->streams[asf->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) asf->packet_key_frame = 1; if (asf->packet_key_frame) asf_st->pkt.flags |= AV_PKT_FLAG_KEY; @@ -1371,7 +1371,7 @@ static int asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt) /* test if whole packet is read */ if (asf_st->frag_offset == asf_st->pkt.size) { // workaround for macroshit radio DVR-MS files - if (s->streams[asf->stream_index]->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO && + if (s->streams[asf->stream_index]->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO && asf_st->pkt.size > 100) { int i; for (i = 0; i < asf_st->pkt.size && !asf_st->pkt.data[i]; i++) @@ -1492,7 +1492,7 @@ static void skip_to_key(AVFormatContext *s) for (i = 0; i < 128; i++) { int j = asf->asfid2avid[i]; ASFStream *asf_st = &asf->streams[i]; - if (j < 0 || s->streams[j]->codec->codec_type != AVMEDIA_TYPE_VIDEO) + if (j < 0 || s->streams[j]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) continue; asf_st->skip_to_key = 1; diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c index 2320c661cd..1c564a8339 100644 --- a/libavformat/asfdec_o.c +++ b/libavformat/asfdec_o.c @@ -431,8 +431,8 @@ static int asf_read_picture(AVFormatContext *s, int len) } st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codec->codec_type = asf_st->type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = id; + st->codecpar->codec_type = asf_st->type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = id; st->attached_pic = pkt; st->attached_pic.stream_index = asf_st->index = st->index; st->attached_pic.flags |= AV_PKT_FLAG_KEY; @@ -695,26 +695,26 @@ static int parse_video_info(AVIOContext *pb, AVStream *st) uint16_t size; unsigned int tag; - st->codec->width = avio_rl32(pb); - st->codec->height = avio_rl32(pb); + st->codecpar->width = avio_rl32(pb); + st->codecpar->height = avio_rl32(pb); avio_skip(pb, 1); // skip reserved flags size = avio_rl16(pb); // size of the Format Data tag = ff_get_bmp_header(pb, st, NULL); - st->codec->codec_tag = tag; - st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag); + st->codecpar->codec_tag = tag; + st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag); if (size > BMP_HEADER_SIZE) { int ret; - st->codec->extradata_size = size - BMP_HEADER_SIZE; - if (!(st->codec->extradata = av_malloc(st->codec->extradata_size + + st->codecpar->extradata_size = size - BMP_HEADER_SIZE; + if (!(st->codecpar->extradata = av_malloc(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE))) { - st->codec->extradata_size = 0; + st->codecpar->extradata_size = 0; return AVERROR(ENOMEM); } - memset(st->codec->extradata + st->codec->extradata_size , 0, + memset(st->codecpar->extradata + st->codecpar->extradata_size , 0, AV_INPUT_BUFFER_PADDING_SIZE); - if ((ret = avio_read(pb, st->codec->extradata, - st->codec->extradata_size)) < 0) + if ((ret = avio_read(pb, st->codecpar->extradata, + st->codecpar->extradata_size)) < 0) return ret; } return 0; @@ -773,7 +773,7 @@ static int asf_read_stream_properties(AVFormatContext *s, const GUIDParseTable * if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 32, 1, 1000); // pts should be dword, in milliseconds - st->codec->codec_type = type; + st->codecpar->codec_type = type; asf->asf_st[asf->nb_streams] = av_mallocz(sizeof(*asf_st)); if (!asf->asf_st[asf->nb_streams]) return AVERROR(ENOMEM); @@ -790,7 +790,7 @@ static int asf_read_stream_properties(AVFormatContext *s, const GUIDParseTable * switch (type) { case AVMEDIA_TYPE_AUDIO: asf_st->type = AVMEDIA_TYPE_AUDIO; - if ((ret = ff_get_wav_header(s, pb, st->codec, ts_data_len, 0)) < 0) + if ((ret = ff_get_wav_header(s, pb, st->codecpar, ts_data_len, 0)) < 0) return ret; break; case AVMEDIA_TYPE_VIDEO: @@ -867,7 +867,7 @@ static int asf_read_ext_stream_properties(AVFormatContext *s, const GUIDParseTab if (st) { st->start_time = start_time; st->duration = end_time - start_time; - st->codec->bit_rate = bitrate; + st->codecpar->bit_rate = bitrate; st->avg_frame_rate.num = 10000000; st->avg_frame_rate.den = time_per_frame; } diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c index 66551ea373..cfa4fadc07 100644 --- a/libavformat/asfenc.c +++ b/libavformat/asfenc.c @@ -392,7 +392,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int header_size, n, extra_size, extra_size2, wav_extra_size; int has_title, has_aspect_ratio = 0; int metadata_count; - AVCodecContext *enc; + AVCodecParameters *par; int64_t header_offset, cur_pos, hpos; int bit_rate; int64_t duration; @@ -419,14 +419,14 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, bit_rate = 0; for (n = 0; n < s->nb_streams; n++) { AVDictionaryEntry *entry; - enc = s->streams[n]->codec; + par = s->streams[n]->codecpar; avpriv_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */ - bit_rate += enc->bit_rate; - if ( enc->codec_type == AVMEDIA_TYPE_VIDEO - && enc->sample_aspect_ratio.num > 0 - && enc->sample_aspect_ratio.den > 0) + bit_rate += par->bit_rate; + if ( par->codec_type == AVMEDIA_TYPE_VIDEO + && par->sample_aspect_ratio.num > 0 + && par->sample_aspect_ratio.den > 0) has_aspect_ratio++; entry = av_dict_get(s->streams[n]->metadata, "language", NULL, 0); @@ -445,7 +445,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, asf->streams[n].stream_language_index = asf->nb_languages; asf->nb_languages++; } - if (enc->codec_type == AVMEDIA_TYPE_AUDIO) + if (par->codec_type == AVMEDIA_TYPE_AUDIO) audio_language_counts[asf->streams[n].stream_language_index]++; } } else { @@ -509,7 +509,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, if (audio_language_counts[i]) { avio_wl16(pb, audio_language_counts[i]); for (n = 0; n < s->nb_streams; n++) - if (asf->streams[n].stream_language_index == i && s->streams[n]->codec->codec_type == AVMEDIA_TYPE_AUDIO) + if (asf->streams[n].stream_language_index == i && s->streams[n]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) avio_wl16(pb, n + 1); } } @@ -523,10 +523,10 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, es_pos = put_header(pb, &ff_asf_extended_stream_properties_object); avio_wl64(pb, 0); /* start time */ avio_wl64(pb, 0); /* end time */ - avio_wl32(pb, s->streams[n]->codec->bit_rate); /* data bitrate bps */ + avio_wl32(pb, s->streams[n]->codecpar->bit_rate); /* data bitrate bps */ avio_wl32(pb, 5000); /* buffer size ms */ avio_wl32(pb, 0); /* initial buffer fullness */ - avio_wl32(pb, s->streams[n]->codec->bit_rate); /* peak data bitrate */ + avio_wl32(pb, s->streams[n]->codecpar->bit_rate); /* peak data bitrate */ avio_wl32(pb, 5000); /* maximum buffer size ms */ avio_wl32(pb, 0); /* max initial buffer fullness */ avio_wl32(pb, 0); /* max object size */ @@ -544,11 +544,11 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, hpos2 = put_header(pb, &ff_asf_metadata_header); avio_wl16(pb, 2 * has_aspect_ratio); for (n = 0; n < s->nb_streams; n++) { - enc = s->streams[n]->codec; - if ( enc->codec_type == AVMEDIA_TYPE_VIDEO - && enc->sample_aspect_ratio.num > 0 - && enc->sample_aspect_ratio.den > 0) { - AVRational sar = enc->sample_aspect_ratio; + par = s->streams[n]->codecpar; + if ( par->codec_type == AVMEDIA_TYPE_VIDEO + && par->sample_aspect_ratio.num > 0 + && par->sample_aspect_ratio.den > 0) { + AVRational sar = par->sample_aspect_ratio; avio_wl16(pb, 0); // the stream number is set like this below avio_wl16(pb, n + 1); @@ -620,11 +620,11 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t es_pos; // ASFStream *stream = &asf->streams[n]; - enc = s->streams[n]->codec; + par = s->streams[n]->codecpar; asf->streams[n].num = n + 1; asf->streams[n].seq = 1; - switch (enc->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: wav_extra_size = 0; extra_size = 18 + wav_extra_size; @@ -632,14 +632,14 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, break; default: case AVMEDIA_TYPE_VIDEO: - wav_extra_size = enc->extradata_size; + wav_extra_size = par->extradata_size; extra_size = 0x33 + wav_extra_size; extra_size2 = 0; break; } hpos = put_header(pb, &ff_asf_stream_header); - if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { + if (par->codec_type == AVMEDIA_TYPE_AUDIO) { ff_put_guid(pb, &ff_asf_audio_stream); ff_put_guid(pb, &ff_asf_audio_conceal_spread); } else { @@ -653,9 +653,9 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, avio_wl16(pb, n + 1); /* stream number */ avio_wl32(pb, 0); /* ??? */ - if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { + if (par->codec_type == AVMEDIA_TYPE_AUDIO) { /* WAVEFORMATEX header */ - int wavsize = ff_put_wav_header(pb, enc, FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX); + int wavsize = ff_put_wav_header(s, pb, par, FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX); if (wavsize < 0) return -1; @@ -667,23 +667,23 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, } /* ERROR Correction */ avio_w8(pb, 0x01); - if (enc->codec_id == AV_CODEC_ID_ADPCM_G726 || !enc->block_align) { + if (par->codec_id == AV_CODEC_ID_ADPCM_G726 || !par->block_align) { avio_wl16(pb, 0x0190); avio_wl16(pb, 0x0190); } else { - avio_wl16(pb, enc->block_align); - avio_wl16(pb, enc->block_align); + avio_wl16(pb, par->block_align); + avio_wl16(pb, par->block_align); } avio_wl16(pb, 0x01); avio_w8(pb, 0x00); } else { - avio_wl32(pb, enc->width); - avio_wl32(pb, enc->height); + avio_wl32(pb, par->width); + avio_wl32(pb, par->height); avio_w8(pb, 2); /* ??? */ - avio_wl16(pb, 40 + enc->extradata_size); /* size */ + avio_wl16(pb, 40 + par->extradata_size); /* size */ /* BITMAPINFOHEADER header */ - ff_put_bmp_header(pb, enc, ff_codec_bmp_tags, 1, 0); + ff_put_bmp_header(pb, par, ff_codec_bmp_tags, 1, 0); } end_header(pb, hpos); } @@ -697,17 +697,17 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, const AVCodecDescriptor *codec_desc; const char *desc; - enc = s->streams[n]->codec; - codec_desc = avcodec_descriptor_get(enc->codec_id); + par = s->streams[n]->codecpar; + codec_desc = avcodec_descriptor_get(par->codec_id); - if (enc->codec_type == AVMEDIA_TYPE_AUDIO) + if (par->codec_type == AVMEDIA_TYPE_AUDIO) avio_wl16(pb, 2); - else if (enc->codec_type == AVMEDIA_TYPE_VIDEO) + else if (par->codec_type == AVMEDIA_TYPE_VIDEO) avio_wl16(pb, 1); else avio_wl16(pb, -1); - if (enc->codec_id == AV_CODEC_ID_WMAV2) + if (par->codec_id == AV_CODEC_ID_WMAV2) desc = "Windows Media Audio V8"; else desc = codec_desc ? codec_desc->name : NULL; @@ -732,14 +732,14 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, avio_wl16(pb, 0); /* no parameters */ /* id */ - if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { + if (par->codec_type == AVMEDIA_TYPE_AUDIO) { avio_wl16(pb, 2); - avio_wl16(pb, enc->codec_tag); + avio_wl16(pb, par->codec_tag); } else { avio_wl16(pb, 4); - avio_wl32(pb, enc->codec_tag); + avio_wl32(pb, par->codec_tag); } - if (!enc->codec_tag) + if (!par->codec_tag) return -1; } end_header(pb, hpos); @@ -963,7 +963,7 @@ static void put_frame(AVFormatContext *s, ASFStream *stream, AVStream *avst, PACKET_HEADER_MIN_SIZE - 1; if (frag_len1 < payload_len && - avst->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + avst->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { flush_packet(s); continue; } @@ -1053,7 +1053,7 @@ static int asf_write_packet(AVFormatContext *s, AVPacket *pkt) ASFContext *asf = s->priv_data; AVIOContext *pb = s->pb; ASFStream *stream; - AVCodecContext *codec; + AVCodecParameters *par; uint32_t packet_number; int64_t pts; int start_sec; @@ -1061,10 +1061,10 @@ static int asf_write_packet(AVFormatContext *s, AVPacket *pkt) int ret; uint64_t offset = avio_tell(pb); - codec = s->streams[pkt->stream_index]->codec; + par = s->streams[pkt->stream_index]->codecpar; stream = &asf->streams[pkt->stream_index]; - if (codec->codec_type == AVMEDIA_TYPE_AUDIO) + if (par->codec_type == AVMEDIA_TYPE_AUDIO) flags &= ~AV_PKT_FLAG_KEY; pts = (pkt->pts != AV_NOPTS_VALUE) ? pkt->pts : pkt->dts; diff --git a/libavformat/assdec.c b/libavformat/assdec.c index 21148b60f9..d89c14e5b8 100644 --- a/libavformat/assdec.c +++ b/libavformat/assdec.c @@ -121,8 +121,8 @@ static int ass_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 64, 1, 100); - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = AV_CODEC_ID_ASS; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_ASS; av_bprint_init(&header, 0, AV_BPRINT_SIZE_UNLIMITED); av_bprint_init(&line, 0, AV_BPRINT_SIZE_UNLIMITED); @@ -153,7 +153,7 @@ static int ass_read_header(AVFormatContext *s) sub->duration = duration; } - res = avpriv_bprint_to_extradata(st->codec, &header); + res = ff_bprint_to_codecpar_extradata(st->codecpar, &header); if (res < 0) goto end; diff --git a/libavformat/assenc.c b/libavformat/assenc.c index 9a107aab7c..d50f18feb1 100644 --- a/libavformat/assenc.c +++ b/libavformat/assenc.c @@ -46,16 +46,16 @@ typedef struct ASSContext { static int write_header(AVFormatContext *s) { ASSContext *ass = s->priv_data; - AVCodecContext *avctx = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; - if (s->nb_streams != 1 || avctx->codec_id != AV_CODEC_ID_ASS) { + if (s->nb_streams != 1 || par->codec_id != AV_CODEC_ID_ASS) { av_log(s, AV_LOG_ERROR, "Exactly one ASS/SSA stream is needed.\n"); return AVERROR(EINVAL); } avpriv_set_pts_info(s->streams[0], 64, 1, 100); - if (avctx->extradata_size > 0) { - size_t header_size = avctx->extradata_size; - uint8_t *trailer = strstr(avctx->extradata, "\n[Events]"); + if (par->extradata_size > 0) { + size_t header_size = par->extradata_size; + uint8_t *trailer = strstr(par->extradata, "\n[Events]"); if (trailer) trailer = strstr(trailer, "Format:"); @@ -63,17 +63,17 @@ static int write_header(AVFormatContext *s) trailer = strstr(trailer, "\n"); if (trailer++) { - header_size = (trailer - avctx->extradata); - ass->trailer_size = avctx->extradata_size - header_size; + header_size = (trailer - par->extradata); + ass->trailer_size = par->extradata_size - header_size; if (ass->trailer_size) ass->trailer = trailer; } - avio_write(s->pb, avctx->extradata, header_size); - if (avctx->extradata[header_size - 1] != '\n') + avio_write(s->pb, par->extradata, header_size); + if (par->extradata[header_size - 1] != '\n') avio_write(s->pb, "\r\n", 2); - ass->ssa_mode = !strstr(avctx->extradata, "\n[V4+ Styles]"); - if (!strstr(avctx->extradata, "\n[Events]")) + ass->ssa_mode = !strstr(par->extradata, "\n[V4+ Styles]"); + if (!strstr(par->extradata, "\n[Events]")) avio_printf(s->pb, "[Events]\r\nFormat: %s, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\r\n", ass->ssa_mode ? "Marked" : "Layer"); } diff --git a/libavformat/astdec.c b/libavformat/astdec.c index 92c208d044..f3ca721ccf 100644 --- a/libavformat/astdec.c +++ b/libavformat/astdec.c @@ -48,8 +48,8 @@ static int ast_read_header(AVFormatContext *s) return AVERROR(ENOMEM); avio_skip(s->pb, 8); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = ff_codec_get_id(ff_codec_ast_tags, avio_rb16(s->pb)); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = ff_codec_get_id(ff_codec_ast_tags, avio_rb16(s->pb)); depth = avio_rb16(s->pb); if (depth != 16) { @@ -57,23 +57,23 @@ static int ast_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; } - st->codec->channels = avio_rb16(s->pb); - if (!st->codec->channels) + st->codecpar->channels = avio_rb16(s->pb); + if (!st->codecpar->channels) return AVERROR_INVALIDDATA; - if (st->codec->channels == 2) - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; - else if (st->codec->channels == 4) - st->codec->channel_layout = AV_CH_LAYOUT_4POINT0; + if (st->codecpar->channels == 2) + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + else if (st->codecpar->channels == 4) + st->codecpar->channel_layout = AV_CH_LAYOUT_4POINT0; avio_skip(s->pb, 2); - st->codec->sample_rate = avio_rb32(s->pb); - if (st->codec->sample_rate <= 0) + st->codecpar->sample_rate = avio_rb32(s->pb); + if (st->codecpar->sample_rate <= 0) return AVERROR_INVALIDDATA; st->start_time = 0; st->duration = avio_rb32(s->pb); avio_skip(s->pb, 40); - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } @@ -90,10 +90,10 @@ static int ast_read_packet(AVFormatContext *s, AVPacket *pkt) pos = avio_tell(s->pb); type = avio_rl32(s->pb); size = avio_rb32(s->pb); - if (size > INT_MAX / s->streams[0]->codec->channels) + if (size > INT_MAX / s->streams[0]->codecpar->channels) return AVERROR_INVALIDDATA; - size *= s->streams[0]->codec->channels; + size *= s->streams[0]->codecpar->channels; if ((ret = avio_skip(s->pb, 24)) < 0) // padding return ret; diff --git a/libavformat/astenc.c b/libavformat/astenc.c index cf7a12c95d..11f8717495 100644 --- a/libavformat/astenc.c +++ b/libavformat/astenc.c @@ -37,7 +37,7 @@ typedef struct ASTMuxContext { #define CHECK_LOOP(type) \ if (ast->loop ## type > 0) { \ - ast->loop ## type = av_rescale_rnd(ast->loop ## type, enc->sample_rate, 1000, AV_ROUND_DOWN); \ + ast->loop ## type = av_rescale_rnd(ast->loop ## type, par->sample_rate, 1000, AV_ROUND_DOWN); \ if (ast->loop ## type < 0 || ast->loop ## type > UINT_MAX) { \ av_log(s, AV_LOG_ERROR, "Invalid loop" #type " value\n"); \ return AVERROR(EINVAL); \ @@ -48,22 +48,22 @@ static int ast_write_header(AVFormatContext *s) { ASTMuxContext *ast = s->priv_data; AVIOContext *pb = s->pb; - AVCodecContext *enc; + AVCodecParameters *par; unsigned int codec_tag; if (s->nb_streams == 1) { - enc = s->streams[0]->codec; + par = s->streams[0]->codecpar; } else { av_log(s, AV_LOG_ERROR, "only one stream is supported\n"); return AVERROR(EINVAL); } - if (enc->codec_id == AV_CODEC_ID_ADPCM_AFC) { + if (par->codec_id == AV_CODEC_ID_ADPCM_AFC) { av_log(s, AV_LOG_ERROR, "muxing ADPCM AFC is not implemented\n"); return AVERROR_PATCHWELCOME; } - codec_tag = ff_codec_get_tag(ff_codec_ast_tags, enc->codec_id); + codec_tag = ff_codec_get_tag(ff_codec_ast_tags, par->codec_id); if (!codec_tag) { av_log(s, AV_LOG_ERROR, "unsupported codec\n"); return AVERROR(EINVAL); @@ -84,9 +84,9 @@ static int ast_write_header(AVFormatContext *s) avio_wb32(pb, 0); /* File size minus header */ avio_wb16(pb, codec_tag); avio_wb16(pb, 16); /* Bit depth */ - avio_wb16(pb, enc->channels); + avio_wb16(pb, par->channels); avio_wb16(pb, 0); /* Loop flag */ - avio_wb32(pb, enc->sample_rate); + avio_wb32(pb, par->sample_rate); ast->samples = avio_tell(pb); avio_wb32(pb, 0); /* Number of samples */ @@ -110,8 +110,8 @@ static int ast_write_packet(AVFormatContext *s, AVPacket *pkt) { AVIOContext *pb = s->pb; ASTMuxContext *ast = s->priv_data; - AVCodecContext *enc = s->streams[0]->codec; - int size = pkt->size / enc->channels; + AVCodecParameters *par = s->streams[0]->codecpar; + int size = pkt->size / par->channels; if (s->streams[0]->nb_frames == 0) ast->fbs = size; @@ -133,9 +133,9 @@ static int ast_write_trailer(AVFormatContext *s) { AVIOContext *pb = s->pb; ASTMuxContext *ast = s->priv_data; - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; int64_t file_size = avio_tell(pb); - int64_t samples = (file_size - 64 - (32 * s->streams[0]->nb_frames)) / enc->block_align; /* PCM_S16BE_PLANAR */ + int64_t samples = (file_size - 64 - (32 * s->streams[0]->nb_frames)) / par->block_align; /* PCM_S16BE_PLANAR */ av_log(s, AV_LOG_DEBUG, "total samples: %"PRId64"\n", samples); diff --git a/libavformat/au.c b/libavformat/au.c index 53702bcb42..67af2bfb89 100644 --- a/libavformat/au.c +++ b/libavformat/au.c @@ -132,16 +132,16 @@ static int au_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = id; - st->codec->codec_id = codec; - st->codec->channels = channels; - st->codec->sample_rate = rate; - st->codec->bits_per_coded_sample = bps; - st->codec->bit_rate = channels * rate * bps; - st->codec->block_align = FFMAX(bps * st->codec->channels / 8, 1); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = id; + st->codecpar->codec_id = codec; + st->codecpar->channels = channels; + st->codecpar->sample_rate = rate; + st->codecpar->bits_per_coded_sample = bps; + st->codecpar->bit_rate = channels * rate * bps; + st->codecpar->block_align = FFMAX(bps * st->codecpar->channels / 8, 1); if (data_size != AU_UNKNOWN_SIZE) - st->duration = (((int64_t)data_size)<<3) / (st->codec->channels * (int64_t)bps); + st->duration = (((int64_t)data_size)<<3) / (st->codecpar->channels * (int64_t)bps); st->start_time = 0; avpriv_set_pts_info(st, 64, 1, rate); @@ -168,15 +168,15 @@ AVInputFormat ff_au_demuxer = { static int au_write_header(AVFormatContext *s) { AVIOContext *pb = s->pb; - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; if (s->nb_streams != 1) { av_log(s, AV_LOG_ERROR, "only one stream is supported\n"); return AVERROR(EINVAL); } - enc->codec_tag = ff_codec_get_tag(codec_au_tags, enc->codec_id); - if (!enc->codec_tag) { + par->codec_tag = ff_codec_get_tag(codec_au_tags, par->codec_id); + if (!par->codec_tag) { av_log(s, AV_LOG_ERROR, "unsupported codec\n"); return AVERROR(EINVAL); } @@ -184,9 +184,9 @@ static int au_write_header(AVFormatContext *s) ffio_wfourcc(pb, ".snd"); /* magic number */ avio_wb32(pb, AU_HEADER_SIZE); /* header size */ avio_wb32(pb, AU_UNKNOWN_SIZE); /* data size */ - avio_wb32(pb, enc->codec_tag); /* codec ID */ - avio_wb32(pb, enc->sample_rate); - avio_wb32(pb, enc->channels); + avio_wb32(pb, par->codec_tag); /* codec ID */ + avio_wb32(pb, par->sample_rate); + avio_wb32(pb, par->channels); avio_wb64(pb, 0); /* annotation field */ avio_flush(pb); diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c index 6d1401d721..6d4954befe 100644 --- a/libavformat/audiointerleave.c +++ b/libavformat/audiointerleave.c @@ -33,7 +33,7 @@ void ff_audio_interleave_close(AVFormatContext *s) AVStream *st = s->streams[i]; AudioInterleaveContext *aic = st->priv_data; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) av_fifo_freep(&aic->fifo); } } @@ -55,9 +55,9 @@ int ff_audio_interleave_init(AVFormatContext *s, AVStream *st = s->streams[i]; AudioInterleaveContext *aic = st->priv_data; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - aic->sample_size = (st->codec->channels * - av_get_bits_per_sample(st->codec->codec_id)) / 8; + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + aic->sample_size = (st->codecpar->channels * + av_get_bits_per_sample(st->codecpar->codec_id)) / 8; if (!aic->sample_size) { av_log(s, AV_LOG_ERROR, "could not compute sample size\n"); return AVERROR(EINVAL); @@ -111,7 +111,7 @@ int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt if (pkt) { AVStream *st = s->streams[pkt->stream_index]; AudioInterleaveContext *aic = st->priv_data; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { unsigned new_size = av_fifo_size(aic->fifo) + pkt->size; if (new_size > aic->fifo_size) { if (av_fifo_realloc2(aic->fifo, new_size) < 0) @@ -131,7 +131,7 @@ int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { AVPacket new_pkt = { 0 }; while ((ret = interleave_new_audio_packet(s, &new_pkt, i, flush)) > 0) { if ((ret = ff_interleave_add_packet(s, &new_pkt, compare_ts)) < 0) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 5e918a04c3..02113f5c7b 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -872,18 +872,13 @@ typedef struct AVStream { * encoding: set by the user, replaced by libavformat if left unset */ int id; +#if FF_API_LAVF_AVCTX /** - * Codec context associated with this stream. Allocated and freed by - * libavformat. - * - * - decoding: The demuxer exports codec information stored in the headers - * here. - * - encoding: The user sets codec information, the muxer writes it to the - * output. Mandatory fields as specified in AVCodecContext - * documentation must be set even if this AVCodecContext is - * not actually used for encoding. + * @deprecated use the codecpar struct instead */ + attribute_deprecated AVCodecContext *codec; +#endif void *priv_data; #if FF_API_LAVF_FRAC @@ -990,6 +985,17 @@ typedef struct AVStream { int event_flags; #define AVSTREAM_EVENT_FLAG_METADATA_UPDATED 0x0001 ///< The call resulted in updated metadata. + /* + * Codec parameters associated with this stream. Allocated and freed by + * libavformat in avformat_new_stream() and avformat_free_context() + * respectively. + * + * - demuxing: filled by libavformat on stream creation or in + * avformat_find_stream_info() + * - muxing: filled by the caller before avformat_write_header() + */ + AVCodecParameters *codecpar; + /***************************************************************** * All fields below this line are not part of the public API. They * may not be used outside of libavformat and can be changed and diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 8ce07ab310..87c9bd4951 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -385,11 +385,11 @@ static void avi_read_nikon(AVFormatContext *s, uint64_t end) } } -static int avi_extract_stream_metadata(AVStream *st) +static int avi_extract_stream_metadata(AVFormatContext *s, AVStream *st) { GetByteContext gb; - uint8_t *data = st->codec->extradata; - int data_size = st->codec->extradata_size; + uint8_t *data = st->codecpar->extradata; + int data_size = st->codecpar->extradata_size; int tag, offset; if (!data || data_size < 8) { @@ -408,13 +408,13 @@ static int avi_extract_stream_metadata(AVStream *st) bytestream2_init(&gb, data + offset, data_size - offset); // decode EXIF tags from IFD, AVI is always little-endian - return avpriv_exif_decode_ifd(st->codec, &gb, 1, 0, &st->metadata); + return avpriv_exif_decode_ifd(s, &gb, 1, 0, &st->metadata); break; case MKTAG('C', 'A', 'S', 'I'): - avpriv_request_sample(st->codec, "RIFF stream data tag type CASI (%u)", tag); + avpriv_request_sample(s, "RIFF stream data tag type CASI (%u)", tag); break; case MKTAG('Z', 'o', 'r', 'a'): - avpriv_request_sample(st->codec, "RIFF stream data tag type Zora (%u)", tag); + avpriv_request_sample(s, "RIFF stream data tag type Zora (%u)", tag); break; default: break; @@ -456,12 +456,12 @@ static int calculate_bitrate(AVFormatContext *s) for (j = 0; j < st->nb_index_entries; j++) len += st->index_entries[j].size; - if (st->nb_index_entries < 2 || st->codec->bit_rate > 0) + if (st->nb_index_entries < 2 || st->codecpar->bit_rate > 0) continue; duration = st->index_entries[j-1].timestamp - st->index_entries[0].timestamp; bitrate = av_rescale(8*len, st->time_base.den, duration * st->time_base.num); if (bitrate <= INT_MAX && bitrate > 0) { - st->codec->bit_rate = bitrate; + st->codecpar->bit_rate = bitrate; } } return 1; @@ -603,8 +603,8 @@ static int avi_read_header(AVFormatContext *s) goto fail; ast = s->streams[0]->priv_data; - av_freep(&s->streams[0]->codec->extradata); - av_freep(&s->streams[0]->codec); + av_freep(&s->streams[0]->codecpar->extradata); + av_freep(&s->streams[0]->codecpar); if (s->streams[0]->info) av_freep(&s->streams[0]->info->duration_error); av_freep(&s->streams[0]->info); @@ -733,17 +733,17 @@ static int avi_read_header(AVFormatContext *s) if (cur_pos < list_end) size = FFMIN(size, list_end - cur_pos); st = s->streams[stream_index]; - if (st->codec->codec_type != AVMEDIA_TYPE_UNKNOWN) { + if (st->codecpar->codec_type != AVMEDIA_TYPE_UNKNOWN) { avio_skip(pb, size); break; } switch (codec_type) { case AVMEDIA_TYPE_VIDEO: if (amv_file_format) { - st->codec->width = avih_width; - st->codec->height = avih_height; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_AMV; + st->codecpar->width = avih_width; + st->codecpar->height = avih_height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_AMV; avio_skip(pb, size); break; } @@ -751,40 +751,40 @@ static int avi_read_header(AVFormatContext *s) if (tag1 == MKTAG('D', 'X', 'S', 'B') || tag1 == MKTAG('D', 'X', 'S', 'A')) { - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_tag = tag1; - st->codec->codec_id = AV_CODEC_ID_XSUB; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_tag = tag1; + st->codecpar->codec_id = AV_CODEC_ID_XSUB; break; } if (size > 10 * 4 && size < (1 << 30) && size < avi->fsize) { if (esize == size-1 && (esize&1)) { - st->codec->extradata_size = esize - 10 * 4; + st->codecpar->extradata_size = esize - 10 * 4; } else - st->codec->extradata_size = size - 10 * 4; - if (ff_get_extradata(st->codec, pb, st->codec->extradata_size) < 0) + st->codecpar->extradata_size = size - 10 * 4; + if (ff_get_extradata(st->codecpar, pb, st->codecpar->extradata_size) < 0) return AVERROR(ENOMEM); } // FIXME: check if the encoder really did this correctly - if (st->codec->extradata_size & 1) + if (st->codecpar->extradata_size & 1) avio_r8(pb); /* Extract palette from extradata if bpp <= 8. * This code assumes that extradata contains only palette. * This is true for all paletted codecs implemented in * FFmpeg. */ - if (st->codec->extradata_size && - (st->codec->bits_per_coded_sample <= 8)) { - int pal_size = (1 << st->codec->bits_per_coded_sample) << 2; + if (st->codecpar->extradata_size && + (st->codecpar->bits_per_coded_sample <= 8)) { + int pal_size = (1 << st->codecpar->bits_per_coded_sample) << 2; const uint8_t *pal_src; - pal_size = FFMIN(pal_size, st->codec->extradata_size); - pal_src = st->codec->extradata + - st->codec->extradata_size - pal_size; + pal_size = FFMIN(pal_size, st->codecpar->extradata_size); + pal_src = st->codecpar->extradata + + st->codecpar->extradata_size - pal_size; /* Exclude the "BottomUp" field from the palette */ - if (pal_src - st->codec->extradata >= 9 && - !memcmp(st->codec->extradata + st->codec->extradata_size - 9, "BottomUp", 9)) + if (pal_src - st->codecpar->extradata >= 9 && + !memcmp(st->codecpar->extradata + st->codecpar->extradata_size - 9, "BottomUp", 9)) pal_src -= 9; for (i = 0; i < pal_size / 4; i++) ast->pal[i] = 0xFFU<<24 | AV_RL32(pal_src+4*i); @@ -793,17 +793,17 @@ static int avi_read_header(AVFormatContext *s) print_tag("video", tag1, 0); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_tag = tag1; - st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_tag = tag1; + st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag1); /* If codec is not found yet, try with the mov tags. */ - if (!st->codec->codec_id) { + if (!st->codecpar->codec_id) { char tag_buf[32]; av_get_codec_tag_string(tag_buf, sizeof(tag_buf), tag1); - st->codec->codec_id = + st->codecpar->codec_id = ff_codec_get_id(ff_codec_movvideo_tags, tag1); - if (st->codec->codec_id) + if (st->codecpar->codec_id) av_log(s, AV_LOG_WARNING, "mov tag found in avi (fourcc %s)\n", tag_buf); @@ -812,44 +812,44 @@ static int avi_read_header(AVFormatContext *s) * for generating correct pts. */ st->need_parsing = AVSTREAM_PARSE_HEADERS; - if (st->codec->codec_id == AV_CODEC_ID_MPEG4 && + if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 && ast->handler == MKTAG('X', 'V', 'I', 'D')) - st->codec->codec_tag = MKTAG('X', 'V', 'I', 'D'); + st->codecpar->codec_tag = MKTAG('X', 'V', 'I', 'D'); - if (st->codec->codec_tag == MKTAG('V', 'S', 'S', 'H')) + if (st->codecpar->codec_tag == MKTAG('V', 'S', 'S', 'H')) st->need_parsing = AVSTREAM_PARSE_FULL; - if (st->codec->codec_id == AV_CODEC_ID_RV40) + if (st->codecpar->codec_id == AV_CODEC_ID_RV40) st->need_parsing = AVSTREAM_PARSE_NONE; - if (st->codec->codec_tag == 0 && st->codec->height > 0 && - st->codec->extradata_size < 1U << 30) { - st->codec->extradata_size += 9; - if ((ret = av_reallocp(&st->codec->extradata, - st->codec->extradata_size + + if (st->codecpar->codec_tag == 0 && st->codecpar->height > 0 && + st->codecpar->extradata_size < 1U << 30) { + st->codecpar->extradata_size += 9; + if ((ret = av_reallocp(&st->codecpar->extradata, + st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE)) < 0) { - st->codec->extradata_size = 0; + st->codecpar->extradata_size = 0; return ret; } else - memcpy(st->codec->extradata + st->codec->extradata_size - 9, + memcpy(st->codecpar->extradata + st->codecpar->extradata_size - 9, "BottomUp", 9); } - st->codec->height = FFABS(st->codec->height); + st->codecpar->height = FFABS(st->codecpar->height); // avio_skip(pb, size - 5 * 4); break; case AVMEDIA_TYPE_AUDIO: - ret = ff_get_wav_header(s, pb, st->codec, size, 0); + ret = ff_get_wav_header(s, pb, st->codecpar, size, 0); if (ret < 0) return ret; - ast->dshow_block_align = st->codec->block_align; - if (ast->sample_size && st->codec->block_align && - ast->sample_size != st->codec->block_align) { + ast->dshow_block_align = st->codecpar->block_align; + if (ast->sample_size && st->codecpar->block_align && + ast->sample_size != st->codecpar->block_align) { av_log(s, AV_LOG_WARNING, "sample size (%d) != block align (%d)\n", ast->sample_size, - st->codec->block_align); - ast->sample_size = st->codec->block_align; + st->codecpar->block_align); + ast->sample_size = st->codecpar->block_align; } /* 2-aligned * (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */ @@ -861,45 +861,45 @@ static int avi_read_header(AVFormatContext *s) /* ADTS header is in extradata, AAC without header must be * stored as exact frames. Parser not needed and it will * fail. */ - if (st->codec->codec_id == AV_CODEC_ID_AAC && - st->codec->extradata_size) + if (st->codecpar->codec_id == AV_CODEC_ID_AAC && + st->codecpar->extradata_size) st->need_parsing = AVSTREAM_PARSE_NONE; // The flac parser does not work with AVSTREAM_PARSE_TIMESTAMPS - if (st->codec->codec_id == AV_CODEC_ID_FLAC) + if (st->codecpar->codec_id == AV_CODEC_ID_FLAC) st->need_parsing = AVSTREAM_PARSE_NONE; /* AVI files with Xan DPCM audio (wrongly) declare PCM * audio in the header but have Axan as stream_code_tag. */ if (ast->handler == AV_RL32("Axan")) { - st->codec->codec_id = AV_CODEC_ID_XAN_DPCM; - st->codec->codec_tag = 0; + st->codecpar->codec_id = AV_CODEC_ID_XAN_DPCM; + st->codecpar->codec_tag = 0; ast->dshow_block_align = 0; } if (amv_file_format) { - st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_AMV; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_AMV; ast->dshow_block_align = 0; } - if ((st->codec->codec_id == AV_CODEC_ID_AAC || - st->codec->codec_id == AV_CODEC_ID_FLAC || - st->codec->codec_id == AV_CODEC_ID_MP2 ) && ast->dshow_block_align <= 4 && ast->dshow_block_align) { + if ((st->codecpar->codec_id == AV_CODEC_ID_AAC || + st->codecpar->codec_id == AV_CODEC_ID_FLAC || + st->codecpar->codec_id == AV_CODEC_ID_MP2 ) && ast->dshow_block_align <= 4 && ast->dshow_block_align) { av_log(s, AV_LOG_DEBUG, "overriding invalid dshow_block_align of %d\n", ast->dshow_block_align); ast->dshow_block_align = 0; } - if (st->codec->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 1024 && ast->sample_size == 1024 || - st->codec->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 4096 && ast->sample_size == 4096 || - st->codec->codec_id == AV_CODEC_ID_MP3 && ast->dshow_block_align == 1152 && ast->sample_size == 1152) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 1024 && ast->sample_size == 1024 || + st->codecpar->codec_id == AV_CODEC_ID_AAC && ast->dshow_block_align == 4096 && ast->sample_size == 4096 || + st->codecpar->codec_id == AV_CODEC_ID_MP3 && ast->dshow_block_align == 1152 && ast->sample_size == 1152) { av_log(s, AV_LOG_DEBUG, "overriding sample_size\n"); ast->sample_size = 0; } break; case AVMEDIA_TYPE_SUBTITLE: - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; st->request_probe= 1; avio_skip(pb, size); break; default: - st->codec->codec_type = AVMEDIA_TYPE_DATA; - st->codec->codec_id = AV_CODEC_ID_NONE; - st->codec->codec_tag = 0; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_id = AV_CODEC_ID_NONE; + st->codecpar->codec_tag = 0; avio_skip(pb, size); break; } @@ -907,8 +907,8 @@ static int avi_read_header(AVFormatContext *s) break; case MKTAG('s', 't', 'r', 'd'): if (stream_index >= (unsigned)s->nb_streams - || s->streams[stream_index]->codec->extradata_size - || s->streams[stream_index]->codec->codec_tag == MKTAG('H','2','6','4')) { + || s->streams[stream_index]->codecpar->extradata_size + || s->streams[stream_index]->codecpar->codec_tag == MKTAG('H','2','6','4')) { avio_skip(pb, size); } else { uint64_t cur_pos = avio_tell(pb); @@ -917,14 +917,14 @@ static int avi_read_header(AVFormatContext *s) st = s->streams[stream_index]; if (size<(1<<30)) { - if (ff_get_extradata(st->codec, pb, size) < 0) + if (ff_get_extradata(st->codecpar, pb, size) < 0) return AVERROR(ENOMEM); } - if (st->codec->extradata_size & 1) //FIXME check if the encoder really did this correctly + if (st->codecpar->extradata_size & 1) //FIXME check if the encoder really did this correctly avio_r8(pb); - ret = avi_extract_stream_metadata(st); + ret = avi_extract_stream_metadata(s, st); if (ret < 0) { av_log(s, AV_LOG_WARNING, "could not decoding EXIF data in stream header.\n"); } @@ -1014,8 +1014,8 @@ fail: if (dict_entry && !strcmp(dict_entry->value, "PotEncoder")) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if ( st->codec->codec_id == AV_CODEC_ID_MPEG1VIDEO - || st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO) + if ( st->codecpar->codec_id == AV_CODEC_ID_MPEG1VIDEO + || st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) st->need_parsing = AVSTREAM_PARSE_FULL; } @@ -1094,8 +1094,7 @@ static int read_gab2_sub(AVFormatContext *s, AVStream *st, AVPacket *pkt) if (!avformat_open_input(&ast->sub_ctx, "", sub_demuxer, NULL)) { ff_read_packet(ast->sub_ctx, &ast->sub_pkt); - *st->codec = *ast->sub_ctx->streams[0]->codec; - ast->sub_ctx->streams[0]->codec->extradata = NULL; + avcodec_parameters_copy(st->codecpar, ast->sub_ctx->streams[0]->codecpar); time_base = ast->sub_ctx->streams[0]->time_base; avpriv_set_pts_info(st, 64, time_base.num, time_base.den); } @@ -1232,8 +1231,8 @@ start_sync: // workaround for broken small-file-bug402.avi if ( d[2] == 'w' && d[3] == 'b' && n == 0 - && st ->codec->codec_type == AVMEDIA_TYPE_VIDEO - && st1->codec->codec_type == AVMEDIA_TYPE_AUDIO + && st ->codecpar->codec_type == AVMEDIA_TYPE_VIDEO + && st1->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && ast->prefix == 'd'*256+'c' && (d[2]*256+d[3] == ast1->prefix || !ast1->prefix_count) ) { @@ -1443,8 +1442,8 @@ resync: pkt->flags |= AV_PKT_FLAG_KEY; if (size < 0) av_packet_unref(pkt); - } else if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE && - !st->codec->codec_tag && read_gab2_sub(s, st, pkt)) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE && + !st->codecpar->codec_tag && read_gab2_sub(s, st, pkt)) { ast->frame_offset++; avi->stream_index = -1; ast->remaining = 0; @@ -1468,7 +1467,7 @@ resync: size); pkt->stream_index = avi->stream_index; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && st->index_entries) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->index_entries) { AVIndexEntry *e; int index; @@ -1479,7 +1478,7 @@ resync: if (index == st->nb_index_entries-1) { int key=1; uint32_t state=-1; - if (st->codec->codec_id == AV_CODEC_ID_MPEG4) { + if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) { const uint8_t *ptr = pkt->data, *end = ptr + FFMIN(size, 256); while (ptr < end) { ptr = avpriv_find_start_code(ptr, end, &state); @@ -1557,7 +1556,7 @@ static int avi_read_idx1(AVFormatContext *s, int size) avi->stream_index = -1; avio_seek(pb, idx1_pos, SEEK_SET); - if (s->nb_streams == 1 && s->streams[0]->codec->codec_tag == AV_RL32("MMES")) { + if (s->nb_streams == 1 && s->streams[0]->codecpar->codec_tag == AV_RL32("MMES")) { first_packet_pos = 0; data_offset = avi->movi_list; } @@ -1661,7 +1660,7 @@ static int check_stream_max_drift(AVFormatContext *s) max_dts = FFMAX(max_dts, dts); max_buffer = FFMAX(max_buffer, av_rescale(dts - min_dts, - st->codec->bit_rate, + st->codecpar->bit_rate, AV_TIME_BASE)); } } @@ -1847,7 +1846,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, if (st2->nb_index_entries <= 0) continue; -// av_assert1(st2->codec->block_align); +// av_assert1(st2->codecpar->block_align); av_assert0(fabs(av_q2d(st2->time_base) - ast2->scale / (double)ast2->rate) < av_q2d(st2->time_base) * 0.00000001); index = av_index_search_timestamp(st2, av_rescale_q(timestamp, @@ -1856,7 +1855,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, FFMAX(ast2->sample_size, 1), flags | AVSEEK_FLAG_BACKWARD | - (st2->codec->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0)); + (st2->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0)); if (index < 0) index = 0; ast2->seek_pos = st2->index_entries[index].pos; @@ -1872,7 +1871,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, index = av_index_search_timestamp( st2, av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1), - flags | AVSEEK_FLAG_BACKWARD | (st2->codec->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0)); + flags | AVSEEK_FLAG_BACKWARD | (st2->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0)); if (index < 0) index = 0; while (!avi->non_interleaved && index>0 && st2->index_entries[index-1].pos >= pos_min) diff --git a/libavformat/avienc.c b/libavformat/avienc.c index 7a7abb8718..c908c21e4f 100644 --- a/libavformat/avienc.c +++ b/libavformat/avienc.c @@ -180,21 +180,21 @@ static int avi_write_counters(AVFormatContext *s, int riff_id) AVIContext *avi = s->priv_data; int n, au_byterate, au_ssize, au_scale, nb_frames = 0; int64_t file_size; - AVCodecContext *stream; + AVCodecParameters *par; file_size = avio_tell(pb); for (n = 0; n < s->nb_streams; n++) { AVIStream *avist = s->streams[n]->priv_data; av_assert0(avist->frames_hdr_strm); - stream = s->streams[n]->codec; + par = s->streams[n]->codecpar; avio_seek(pb, avist->frames_hdr_strm, SEEK_SET); ff_parse_specific_params(s->streams[n], &au_byterate, &au_ssize, &au_scale); if (au_ssize == 0) avio_wl32(pb, avist->packet_count); else avio_wl32(pb, avist->audio_strm_length / au_ssize); - if (stream->codec_type == AVMEDIA_TYPE_VIDEO) + if (par->codec_type == AVMEDIA_TYPE_VIDEO) nb_frames = FFMAX(nb_frames, avist->packet_count); } if (riff_id == 1) { @@ -211,7 +211,7 @@ static void write_odml_master(AVFormatContext *s, int stream_index) { AVIOContext *pb = s->pb; AVStream *st = s->streams[stream_index]; - AVCodecContext *enc = st->codec; + AVCodecParameters *par = st->codecpar; AVIStream *avist = st->priv_data; unsigned char tag[5]; int j; @@ -225,7 +225,7 @@ static void write_odml_master(AVFormatContext *s, int stream_index) avio_w8(pb, 0); /* bIndexSubType (0 == frame index) */ avio_w8(pb, 0); /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */ avio_wl32(pb, 0); /* nEntriesInUse (will fill out later on) */ - ffio_wfourcc(pb, avi_stream2fourcc(tag, stream_index, enc->codec_type)); + ffio_wfourcc(pb, avi_stream2fourcc(tag, stream_index, par->codec_type)); /* dwChunkId */ avio_wl64(pb, 0); /* dwReserved[3] */ avio_wl32(pb, 0); /* Must be 0. */ @@ -239,7 +239,7 @@ static int avi_write_header(AVFormatContext *s) AVIContext *avi = s->priv_data; AVIOContext *pb = s->pb; int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale; - AVCodecContext *video_enc; + AVCodecParameters *video_par; AVStream *video_st = NULL; int64_t list1, list2, strh, strf; AVDictionaryEntry *t = NULL; @@ -266,12 +266,12 @@ static int avi_write_header(AVFormatContext *s) avio_wl32(pb, 14 * 4); bitrate = 0; - video_enc = NULL; + video_par = NULL; for (n = 0; n < s->nb_streams; n++) { - AVCodecContext *codec = s->streams[n]->codec; - bitrate += codec->bit_rate; - if (codec->codec_type == AVMEDIA_TYPE_VIDEO) { - video_enc = codec; + AVCodecParameters *par = s->streams[n]->codecpar; + bitrate += par->bit_rate; + if (par->codec_type == AVMEDIA_TYPE_VIDEO) { + video_par = par; video_st = s->streams[n]; } } @@ -295,9 +295,9 @@ static int avi_write_header(AVFormatContext *s) avio_wl32(pb, 0); /* initial frame */ avio_wl32(pb, s->nb_streams); /* nb streams */ avio_wl32(pb, 1024 * 1024); /* suggested buffer size */ - if (video_enc) { - avio_wl32(pb, video_enc->width); - avio_wl32(pb, video_enc->height); + if (video_par) { + avio_wl32(pb, video_par->width); + avio_wl32(pb, video_par->height); } else { avio_wl32(pb, 0); avio_wl32(pb, 0); @@ -310,18 +310,18 @@ static int avi_write_header(AVFormatContext *s) /* stream list */ for (i = 0; i < n; i++) { AVStream *st = s->streams[i]; - AVCodecContext *enc = st->codec; + AVCodecParameters *par = st->codecpar; AVIStream *avist = st->priv_data; list2 = ff_start_tag(pb, "LIST"); ffio_wfourcc(pb, "strl"); /* stream generic header */ strh = ff_start_tag(pb, "strh"); - switch (enc->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_SUBTITLE: // XSUB subtitles behave like video tracks, other subtitles // are not (yet) supported. - if (enc->codec_id != AV_CODEC_ID_XSUB) { + if (par->codec_id != AV_CODEC_ID_XSUB) { av_log(s, AV_LOG_ERROR, "Subtitle streams other than DivX XSUB are not supported by the AVI muxer.\n"); return AVERROR_PATCHWELCOME; @@ -339,9 +339,9 @@ static int avi_write_header(AVFormatContext *s) ffio_wfourcc(pb, "dats"); break; } - if (enc->codec_type == AVMEDIA_TYPE_VIDEO || - enc->codec_id == AV_CODEC_ID_XSUB) - avio_wl32(pb, enc->codec_tag); + if (par->codec_type == AVMEDIA_TYPE_VIDEO || + par->codec_id == AV_CODEC_ID_XSUB) + avio_wl32(pb, par->codec_tag); else avio_wl32(pb, 1); avist->strh_flags_offset = avio_tell(pb); @@ -352,14 +352,14 @@ static int avi_write_header(AVFormatContext *s) ff_parse_specific_params(st, &au_byterate, &au_ssize, &au_scale); - if ( enc->codec_type == AVMEDIA_TYPE_VIDEO - && enc->codec_id != AV_CODEC_ID_XSUB + if ( par->codec_type == AVMEDIA_TYPE_VIDEO + && par->codec_id != AV_CODEC_ID_XSUB && au_byterate > 1000LL*au_scale) { au_byterate = 600; au_scale = 1; } avpriv_set_pts_info(st, 64, au_scale, au_byterate); - if (enc->codec_id == AV_CODEC_ID_XSUB) + if (par->codec_id == AV_CODEC_ID_XSUB) au_scale = au_byterate = 0; avio_wl32(pb, au_scale); /* scale */ @@ -375,57 +375,57 @@ static int avi_write_header(AVFormatContext *s) avio_wl32(pb, 0); /* length, XXX: filled later */ /* suggested buffer size, is set to largest chunk size in avi_write_trailer */ - if (enc->codec_type == AVMEDIA_TYPE_VIDEO) + if (par->codec_type == AVMEDIA_TYPE_VIDEO) avio_wl32(pb, 1024 * 1024); - else if (enc->codec_type == AVMEDIA_TYPE_AUDIO) + else if (par->codec_type == AVMEDIA_TYPE_AUDIO) avio_wl32(pb, 12 * 1024); else avio_wl32(pb, 0); avio_wl32(pb, -1); /* quality */ avio_wl32(pb, au_ssize); /* sample size */ avio_wl32(pb, 0); - avio_wl16(pb, enc->width); - avio_wl16(pb, enc->height); + avio_wl16(pb, par->width); + avio_wl16(pb, par->height); ff_end_tag(pb, strh); - if (enc->codec_type != AVMEDIA_TYPE_DATA) { + if (par->codec_type != AVMEDIA_TYPE_DATA) { int ret, flags; enum AVPixelFormat pix_fmt; strf = ff_start_tag(pb, "strf"); - switch (enc->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_SUBTITLE: /* XSUB subtitles behave like video tracks, other subtitles * are not (yet) supported. */ - if (enc->codec_id != AV_CODEC_ID_XSUB) + if (par->codec_id != AV_CODEC_ID_XSUB) break; case AVMEDIA_TYPE_VIDEO: /* WMP expects RGB 5:5:5 rawvideo in avi to have bpp set to 16. */ - if ( !enc->codec_tag - && enc->codec_id == AV_CODEC_ID_RAWVIDEO - && enc->pix_fmt == AV_PIX_FMT_RGB555LE - && enc->bits_per_coded_sample == 15) - enc->bits_per_coded_sample = 16; + if ( !par->codec_tag + && par->codec_id == AV_CODEC_ID_RAWVIDEO + && par->format == AV_PIX_FMT_RGB555LE + && par->bits_per_coded_sample == 15) + par->bits_per_coded_sample = 16; avist->pal_offset = avio_tell(pb) + 40; - ff_put_bmp_header(pb, enc, ff_codec_bmp_tags, 0, 0); + ff_put_bmp_header(pb, par, ff_codec_bmp_tags, 0, 0); pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_avi, - enc->bits_per_coded_sample); - if ( !enc->codec_tag - && enc->codec_id == AV_CODEC_ID_RAWVIDEO - && enc->pix_fmt != pix_fmt - && enc->pix_fmt != AV_PIX_FMT_NONE) + par->bits_per_coded_sample); + if ( !par->codec_tag + && par->codec_id == AV_CODEC_ID_RAWVIDEO + && par->format != pix_fmt + && par->format != AV_PIX_FMT_NONE) av_log(s, AV_LOG_ERROR, "%s rawvideo cannot be written to avi, output file will be unreadable\n", - av_get_pix_fmt_name(enc->pix_fmt)); + av_get_pix_fmt_name(par->format)); break; case AVMEDIA_TYPE_AUDIO: flags = (avi->write_channel_mask == 0) ? FF_PUT_WAV_HEADER_SKIP_CHANNELMASK : 0; - if ((ret = ff_put_wav_header(pb, enc, flags)) < 0) + if ((ret = ff_put_wav_header(s, pb, par, flags)) < 0) return ret; break; default: av_log(s, AV_LOG_ERROR, "Invalid or not supported codec type '%s' found in the input\n", - (char *)av_x_if_null(av_get_media_type_string(enc->codec_type), "?")); + (char *)av_x_if_null(av_get_media_type_string(par->codec_type), "?")); return AVERROR(EINVAL); } ff_end_tag(pb, strf); @@ -433,7 +433,7 @@ static int avi_write_header(AVFormatContext *s) ff_riff_write_info_tag(s->pb, "strn", t->value); t = NULL; } - if (enc->codec_id == AV_CODEC_ID_XSUB + if (par->codec_id == AV_CODEC_ID_XSUB && (t = av_dict_get(s->streams[i]->metadata, "language", NULL, 0))) { const char* langstr = av_convert_lang_to(t->value, AV_LANG_ISO639_1); t = NULL; @@ -451,13 +451,13 @@ static int avi_write_header(AVFormatContext *s) write_odml_master(s, i); } - if (enc->codec_type == AVMEDIA_TYPE_VIDEO && + if (par->codec_type == AVMEDIA_TYPE_VIDEO && st->sample_aspect_ratio.num > 0 && st->sample_aspect_ratio.den > 0) { int vprp = ff_start_tag(pb, "vprp"); AVRational dar = av_mul_q(st->sample_aspect_ratio, - (AVRational) { enc->width, - enc->height }); + (AVRational) { par->width, + par->height }); int num, den; av_reduce(&num, &den, dar.num, dar.den, 0xFFFF); @@ -465,18 +465,18 @@ static int avi_write_header(AVFormatContext *s) avio_wl32(pb, 0); // video standard = unknown // TODO: should be avg_frame_rate avio_wl32(pb, (2LL*st->time_base.den + st->time_base.num - 1) / (2LL * st->time_base.num)); - avio_wl32(pb, enc->width); - avio_wl32(pb, enc->height); + avio_wl32(pb, par->width); + avio_wl32(pb, par->height); avio_wl16(pb, den); avio_wl16(pb, num); - avio_wl32(pb, enc->width); - avio_wl32(pb, enc->height); + avio_wl32(pb, par->width); + avio_wl32(pb, par->height); avio_wl32(pb, 1); // progressive FIXME - avio_wl32(pb, enc->height); - avio_wl32(pb, enc->width); - avio_wl32(pb, enc->height); - avio_wl32(pb, enc->width); + avio_wl32(pb, par->height); + avio_wl32(pb, par->width); + avio_wl32(pb, par->height); + avio_wl32(pb, par->width); avio_wl32(pb, 0); avio_wl32(pb, 0); @@ -544,7 +544,7 @@ static void update_odml_entry(AVFormatContext *s, int stream_index, int64_t ix, avio_wl64(pb, ix); /* qwOffset */ avio_wl32(pb, size); /* dwSize */ ff_parse_specific_params(s->streams[stream_index], &au_byterate, &au_ssize, &au_scale); - if (s->streams[stream_index]->codec->codec_type == AVMEDIA_TYPE_AUDIO && au_ssize > 0) { + if (s->streams[stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && au_ssize > 0) { uint32_t audio_segm_size = (avist->audio_strm_length - avist->indexes.audio_strm_offset); if ((audio_segm_size % au_ssize > 0) && !avist->sample_requested) { avpriv_request_sample(s, "OpenDML index duration for audio packets with partial frames"); @@ -586,7 +586,7 @@ static int avi_write_ix(AVFormatContext *s) AVIStream *avist = s->streams[i]->priv_data; int64_t ix; - avi_stream2fourcc(tag, i, s->streams[i]->codec->codec_type); + avi_stream2fourcc(tag, i, s->streams[i]->codecpar->codec_type); ix_tag[3] = '0' + i; /* Writing AVI OpenDML leaf index chunk */ @@ -654,7 +654,7 @@ static int avi_write_idx1(AVFormatContext *s) ffio_wfourcc(pb, ie->tag); else { avi_stream2fourcc(tag, stream_id, - s->streams[stream_id]->codec->codec_type); + s->streams[stream_id]->codecpar->codec_type); ffio_wfourcc(pb, tag); } avio_wl32(pb, ie->flags); @@ -673,11 +673,11 @@ static int avi_write_idx1(AVFormatContext *s) static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts) { AVIStream *avist = s->streams[stream_index]->priv_data; - AVCodecContext *enc = s->streams[stream_index]->codec; + AVCodecParameters *par = s->streams[stream_index]->codecpar; ff_dlog(s, "dts:%s packet_count:%d stream_index:%d\n", av_ts2str(dts), avist->packet_count, stream_index); - while (enc->block_align == 0 && dts != AV_NOPTS_VALUE && - dts > avist->packet_count && enc->codec_id != AV_CODEC_ID_XSUB && avist->packet_count) { + while (par->block_align == 0 && dts != AV_NOPTS_VALUE && + dts > avist->packet_count && par->codec_id != AV_CODEC_ID_XSUB && avist->packet_count) { AVPacket empty_packet; if (dts - avist->packet_count > 60000) { @@ -699,10 +699,10 @@ static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts) static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) { const int stream_index = pkt->stream_index; - AVCodecContext *enc = s->streams[stream_index]->codec; + AVCodecParameters *par = s->streams[stream_index]->codecpar; int ret; - if (enc->codec_id == AV_CODEC_ID_H264 && enc->codec_tag == MKTAG('H','2','6','4') && pkt->size) { + if (par->codec_id == AV_CODEC_ID_H264 && par->codec_tag == MKTAG('H','2','6','4') && pkt->size) { ret = ff_check_h264_startcode(s, s->streams[stream_index], pkt); if (ret < 0) return ret; @@ -714,27 +714,27 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) if (!pkt->size) return avi_write_packet_internal(s, pkt); /* Passthrough */ - if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (par->codec_type == AVMEDIA_TYPE_VIDEO) { AVIStream *avist = s->streams[stream_index]->priv_data; AVIOContext *pb = s->pb; AVPacket *opkt = pkt; - if (enc->codec_id == AV_CODEC_ID_RAWVIDEO && enc->codec_tag == 0) { - int64_t bpc = enc->bits_per_coded_sample != 15 ? enc->bits_per_coded_sample : 16; - int expected_stride = ((enc->width * bpc + 31) >> 5)*4; - ret = ff_reshuffle_raw_rgb(s, &pkt, enc, expected_stride); + if (par->codec_id == AV_CODEC_ID_RAWVIDEO && par->codec_tag == 0) { + int64_t bpc = par->bits_per_coded_sample != 15 ? par->bits_per_coded_sample : 16; + int expected_stride = ((par->width * bpc + 31) >> 5)*4; + ret = ff_reshuffle_raw_rgb(s, &pkt, par, expected_stride); if (ret < 0) return ret; } else ret = 0; - if (enc->pix_fmt == AV_PIX_FMT_PAL8) { + if (par->format == AV_PIX_FMT_PAL8) { int ret2 = ff_get_packet_palette(s, opkt, ret, avist->palette); if (ret2 < 0) return ret2; if (ret2) { - int pal_size = 1 << enc->bits_per_coded_sample; + int pal_size = 1 << par->bits_per_coded_sample; int pc_tag, i; - av_assert0(enc->bits_per_coded_sample >= 0 && enc->bits_per_coded_sample <= 8); + av_assert0(par->bits_per_coded_sample >= 0 && par->bits_per_coded_sample <= 8); if (pb->seekable && avist->pal_offset) { int64_t cur_offset = avio_tell(pb); @@ -749,7 +749,7 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) } if (memcmp(avist->palette, avist->old_palette, pal_size * 4)) { unsigned char tag[5]; - avi_stream2fourcc(tag, stream_index, enc->codec_type); + avi_stream2fourcc(tag, stream_index, par->codec_type); tag[2] = 'p'; tag[3] = 'c'; if (s->pb->seekable) { int ret; @@ -797,7 +797,7 @@ static int avi_write_packet_internal(AVFormatContext *s, AVPacket *pkt) AVIContext *avi = s->priv_data; AVIOContext *pb = s->pb; AVIStream *avist = s->streams[stream_index]->priv_data; - AVCodecContext *enc = s->streams[stream_index]->codec; + AVCodecParameters *par = s->streams[stream_index]->codecpar; if (pkt->dts != AV_NOPTS_VALUE) avist->last_dts = pkt->dts + pkt->duration; @@ -817,10 +817,10 @@ static int avi_write_packet_internal(AVFormatContext *s, AVPacket *pkt) avi->movi_list = avi_start_new_riff(s, pb, "AVIX", "movi"); } - avi_stream2fourcc(tag, stream_index, enc->codec_type); + avi_stream2fourcc(tag, stream_index, par->codec_type); if (pkt->flags & AV_PKT_FLAG_KEY) flags = 0x10; - if (enc->codec_type == AVMEDIA_TYPE_AUDIO) + if (par->codec_type == AVMEDIA_TYPE_AUDIO) avist->audio_strm_length += size; if (s->pb->seekable) { @@ -868,15 +868,15 @@ static int avi_write_trailer(AVFormatContext *s) avio_skip(pb, 16); for (n = nb_frames = 0; n < s->nb_streams; n++) { - AVCodecContext *stream = s->streams[n]->codec; + AVCodecParameters *par = s->streams[n]->codecpar; AVIStream *avist = s->streams[n]->priv_data; - if (stream->codec_type == AVMEDIA_TYPE_VIDEO) { + if (par->codec_type == AVMEDIA_TYPE_VIDEO) { if (nb_frames < avist->packet_count) nb_frames = avist->packet_count; } else { - if (stream->codec_id == AV_CODEC_ID_MP2 || - stream->codec_id == AV_CODEC_ID_MP3) + if (par->codec_id == AV_CODEC_ID_MP2 || + par->codec_id == AV_CODEC_ID_MP3) nb_frames += avist->packet_count; } } diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c index 45641c0fc1..13a4cf9ab0 100644 --- a/libavformat/avisynth.c +++ b/libavformat/avisynth.c @@ -232,10 +232,10 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st) AviSynthContext *avs = s->priv_data; int planar = 0; // 0: packed, 1: YUV, 2: Y8 - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; - st->codec->width = avs->vi->width; - st->codec->height = avs->vi->height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->width = avs->vi->width; + st->codecpar->height = avs->vi->height; st->avg_frame_rate = (AVRational) { avs->vi->fps_numerator, avs->vi->fps_denominator }; @@ -247,38 +247,38 @@ static int avisynth_create_stream_video(AVFormatContext *s, AVStream *st) switch (avs->vi->pixel_type) { #ifdef USING_AVISYNTH case AVS_CS_YV24: - st->codec->pix_fmt = AV_PIX_FMT_YUV444P; - planar = 1; + st->codecpar->format = AV_PIX_FMT_YUV444P; + planar = 1; break; case AVS_CS_YV16: - st->codec->pix_fmt = AV_PIX_FMT_YUV422P; - planar = 1; + st->codecpar->format = AV_PIX_FMT_YUV422P; + planar = 1; break; case AVS_CS_YV411: - st->codec->pix_fmt = AV_PIX_FMT_YUV411P; - planar = 1; + st->codecpar->format = AV_PIX_FMT_YUV411P; + planar = 1; break; case AVS_CS_Y8: - st->codec->pix_fmt = AV_PIX_FMT_GRAY8; - planar = 2; + st->codecpar->format = AV_PIX_FMT_GRAY8; + planar = 2; break; #endif case AVS_CS_BGR24: - st->codec->pix_fmt = AV_PIX_FMT_BGR24; + st->codecpar->format = AV_PIX_FMT_BGR24; break; case AVS_CS_BGR32: - st->codec->pix_fmt = AV_PIX_FMT_RGB32; + st->codecpar->format = AV_PIX_FMT_RGB32; break; case AVS_CS_YUY2: - st->codec->pix_fmt = AV_PIX_FMT_YUYV422; + st->codecpar->format = AV_PIX_FMT_YUYV422; break; case AVS_CS_YV12: - st->codec->pix_fmt = AV_PIX_FMT_YUV420P; - planar = 1; + st->codecpar->format = AV_PIX_FMT_YUV420P; + planar = 1; break; case AVS_CS_I420: // Is this even used anywhere? - st->codec->pix_fmt = AV_PIX_FMT_YUV420P; - planar = 1; + st->codecpar->format = AV_PIX_FMT_YUV420P; + planar = 1; break; default: av_log(s, AV_LOG_ERROR, @@ -307,27 +307,27 @@ static int avisynth_create_stream_audio(AVFormatContext *s, AVStream *st) { AviSynthContext *avs = s->priv_data; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->sample_rate = avs->vi->audio_samples_per_second; - st->codec->channels = avs->vi->nchannels; - st->duration = avs->vi->num_audio_samples; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->sample_rate = avs->vi->audio_samples_per_second; + st->codecpar->channels = avs->vi->nchannels; + st->duration = avs->vi->num_audio_samples; avpriv_set_pts_info(st, 64, 1, avs->vi->audio_samples_per_second); switch (avs->vi->sample_type) { case AVS_SAMPLE_INT8: - st->codec->codec_id = AV_CODEC_ID_PCM_U8; + st->codecpar->codec_id = AV_CODEC_ID_PCM_U8; break; case AVS_SAMPLE_INT16: - st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; break; case AVS_SAMPLE_INT24: - st->codec->codec_id = AV_CODEC_ID_PCM_S24LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE; break; case AVS_SAMPLE_INT32: - st->codec->codec_id = AV_CODEC_ID_PCM_S32LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE; break; case AVS_SAMPLE_FLOAT: - st->codec->codec_id = AV_CODEC_ID_PCM_F32LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_F32LE; break; default: av_log(s, AV_LOG_ERROR, @@ -636,7 +636,7 @@ static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt) /* If either stream reaches EOF, try to read the other one before * giving up. */ avisynth_next_stream(s, &st, pkt, &discard); - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { ret = avisynth_read_packet_video(s, pkt, discard); if (ret == AVERROR_EOF && avs_has_audio(avs->vi)) { avisynth_next_stream(s, &st, pkt, &discard); @@ -678,7 +678,7 @@ static int avisynth_read_seek(AVFormatContext *s, int stream_index, samplerate = (AVRational) { avs->vi->audio_samples_per_second, 1 }; st = s->streams[stream_index]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { /* AviSynth frame counts are signed int. */ if ((timestamp >= avs->vi->num_frames) || (timestamp > INT_MAX) || diff --git a/libavformat/avr.c b/libavformat/avr.c index a33134eed5..294160e024 100644 --- a/libavformat/avr.c +++ b/libavformat/avr.c @@ -46,22 +46,22 @@ static int avr_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; avio_skip(s->pb, 4); // magic avio_skip(s->pb, 8); // sample_name chan = avio_rb16(s->pb); if (!chan) { - st->codec->channels = 1; + st->codecpar->channels = 1; } else if (chan == 0xFFFFu) { - st->codec->channels = 2; + st->codecpar->channels = 2; } else { avpriv_request_sample(s, "chan %d", chan); return AVERROR_PATCHWELCOME; } - st->codec->bits_per_coded_sample = bps = avio_rb16(s->pb); + st->codecpar->bits_per_coded_sample = bps = avio_rb16(s->pb); sign = avio_rb16(s->pb); @@ -69,21 +69,21 @@ static int avr_read_header(AVFormatContext *s) avio_skip(s->pb, 2); // midi avio_skip(s->pb, 1); // replay speed - st->codec->sample_rate = avio_rb24(s->pb); + st->codecpar->sample_rate = avio_rb24(s->pb); avio_skip(s->pb, 4 * 3); avio_skip(s->pb, 2 * 3); avio_skip(s->pb, 20); avio_skip(s->pb, 64); - st->codec->codec_id = ff_get_pcm_codec_id(bps, 0, 1, sign); - if (st->codec->codec_id == AV_CODEC_ID_NONE) { + st->codecpar->codec_id = ff_get_pcm_codec_id(bps, 0, 1, sign); + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) { avpriv_request_sample(s, "Bps %d and sign %d", bps, sign); return AVERROR_PATCHWELCOME; } - st->codec->block_align = bps * st->codec->channels / 8; + st->codecpar->block_align = bps * st->codecpar->channels / 8; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } diff --git a/libavformat/avs.c b/libavformat/avs.c index b264b55ed1..763ba63f64 100644 --- a/libavformat/avs.c +++ b/libavformat/avs.c @@ -184,11 +184,11 @@ static int avs_read_packet(AVFormatContext * s, AVPacket * pkt) avs->st_video = avformat_new_stream(s, NULL); if (!avs->st_video) return AVERROR(ENOMEM); - avs->st_video->codec->codec_type = AVMEDIA_TYPE_VIDEO; - avs->st_video->codec->codec_id = AV_CODEC_ID_AVS; - avs->st_video->codec->width = avs->width; - avs->st_video->codec->height = avs->height; - avs->st_video->codec->bits_per_coded_sample=avs->bits_per_sample; + avs->st_video->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + avs->st_video->codecpar->codec_id = AV_CODEC_ID_AVS; + avs->st_video->codecpar->width = avs->width; + avs->st_video->codecpar->height = avs->height; + avs->st_video->codecpar->bits_per_coded_sample=avs->bits_per_sample; avs->st_video->nb_frames = avs->nb_frames; #if FF_API_R_FRAME_RATE avs->st_video->r_frame_rate = @@ -203,7 +203,7 @@ static int avs_read_packet(AVFormatContext * s, AVPacket * pkt) avs->st_audio = avformat_new_stream(s, NULL); if (!avs->st_audio) return AVERROR(ENOMEM); - avs->st_audio->codec->codec_type = AVMEDIA_TYPE_AUDIO; + avs->st_audio->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; } avs->remaining_audio_size = size - 4; size = avs_read_audio_packet(s, pkt); diff --git a/libavformat/bethsoftvid.c b/libavformat/bethsoftvid.c index 40a425271d..f516806d91 100644 --- a/libavformat/bethsoftvid.c +++ b/libavformat/bethsoftvid.c @@ -116,13 +116,13 @@ static int read_frame(BVID_DemuxContext *vid, AVIOContext *pb, AVPacket *pkt, "video packet"); } avpriv_set_pts_info(st, 64, 185, vid->sample_rate); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_BETHSOFTVID; - st->codec->width = vid->width; - st->codec->height = vid->height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_BETHSOFTVID; + st->codecpar->width = vid->width; + st->codecpar->height = vid->height; } st = s->streams[vid->video_index]; - npixels = st->codec->width * st->codec->height; + npixels = st->codecpar->width * st->codecpar->height; vidbuf_start = av_malloc(vidbuf_capacity = BUFFER_PADDING_SIZE); if(!vidbuf_start) @@ -245,13 +245,13 @@ static int vid_read_packet(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); vid->audio_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_PCM_U8; - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->bits_per_coded_sample = 8; - st->codec->sample_rate = vid->sample_rate; - st->codec->bit_rate = 8 * st->codec->sample_rate; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_PCM_U8; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->bits_per_coded_sample = 8; + st->codecpar->sample_rate = vid->sample_rate; + st->codecpar->bit_rate = 8 * st->codecpar->sample_rate; st->start_time = 0; avpriv_set_pts_info(st, 64, 1, vid->sample_rate); } diff --git a/libavformat/bfi.c b/libavformat/bfi.c index cc7f4948c9..568363dd91 100644 --- a/libavformat/bfi.c +++ b/libavformat/bfi.c @@ -75,38 +75,38 @@ static int bfi_read_header(AVFormatContext * s) avio_rl32(pb); fps = avio_rl32(pb); avio_skip(pb, 12); - vstream->codec->width = avio_rl32(pb); - vstream->codec->height = avio_rl32(pb); + vstream->codecpar->width = avio_rl32(pb); + vstream->codecpar->height = avio_rl32(pb); /*Load the palette to extradata */ avio_skip(pb, 8); - vstream->codec->extradata = av_malloc(768); - if (!vstream->codec->extradata) + vstream->codecpar->extradata = av_malloc(768); + if (!vstream->codecpar->extradata) return AVERROR(ENOMEM); - vstream->codec->extradata_size = 768; - avio_read(pb, vstream->codec->extradata, - vstream->codec->extradata_size); + vstream->codecpar->extradata_size = 768; + avio_read(pb, vstream->codecpar->extradata, + vstream->codecpar->extradata_size); - astream->codec->sample_rate = avio_rl32(pb); + astream->codecpar->sample_rate = avio_rl32(pb); /* Set up the video codec... */ avpriv_set_pts_info(vstream, 32, 1, fps); - vstream->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vstream->codec->codec_id = AV_CODEC_ID_BFI; - vstream->codec->pix_fmt = AV_PIX_FMT_PAL8; - vstream->nb_frames = - vstream->duration = bfi->nframes; + vstream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vstream->codecpar->codec_id = AV_CODEC_ID_BFI; + vstream->codecpar->format = AV_PIX_FMT_PAL8; + vstream->nb_frames = + vstream->duration = bfi->nframes; /* Set up the audio codec now... */ - astream->codec->codec_type = AVMEDIA_TYPE_AUDIO; - astream->codec->codec_id = AV_CODEC_ID_PCM_U8; - astream->codec->channels = 1; - astream->codec->channel_layout = AV_CH_LAYOUT_MONO; - astream->codec->bits_per_coded_sample = 8; - astream->codec->bit_rate = - astream->codec->sample_rate * astream->codec->bits_per_coded_sample; + astream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + astream->codecpar->codec_id = AV_CODEC_ID_PCM_U8; + astream->codecpar->channels = 1; + astream->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + astream->codecpar->bits_per_coded_sample = 8; + astream->codecpar->bit_rate = + astream->codecpar->sample_rate * astream->codecpar->bits_per_coded_sample; avio_seek(pb, chunk_header - 3, SEEK_SET); - avpriv_set_pts_info(astream, 64, 1, astream->codec->sample_rate); + avpriv_set_pts_info(astream, 64, 1, astream->codecpar->sample_rate); return 0; } diff --git a/libavformat/bink.c b/libavformat/bink.c index 332edbb7d9..56dbf9e1c1 100644 --- a/libavformat/bink.c +++ b/libavformat/bink.c @@ -89,7 +89,7 @@ static int read_header(AVFormatContext *s) if (!vst) return AVERROR(ENOMEM); - vst->codec->codec_tag = avio_rl32(pb); + vst->codecpar->codec_tag = avio_rl32(pb); bink->file_size = avio_rl32(pb) + 8; vst->duration = avio_rl32(pb); @@ -107,8 +107,8 @@ static int read_header(AVFormatContext *s) avio_skip(pb, 4); - vst->codec->width = avio_rl32(pb); - vst->codec->height = avio_rl32(pb); + vst->codecpar->width = avio_rl32(pb); + vst->codecpar->height = avio_rl32(pb); fps_num = avio_rl32(pb); fps_den = avio_rl32(pb); @@ -121,15 +121,15 @@ static int read_header(AVFormatContext *s) avpriv_set_pts_info(vst, 64, fps_den, fps_num); vst->avg_frame_rate = av_inv_q(vst->time_base); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_BINKVIDEO; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_BINKVIDEO; - if ((vst->codec->codec_tag & 0xFFFFFF) == MKTAG('K', 'B', '2', 0)) { + if ((vst->codecpar->codec_tag & 0xFFFFFF) == MKTAG('K', 'B', '2', 0)) { av_log(s, AV_LOG_WARNING, "Bink 2 video is not implemented\n"); - vst->codec->codec_id = AV_CODEC_ID_NONE; + vst->codecpar->codec_id = AV_CODEC_ID_NONE; } - if (ff_get_extradata(vst->codec, pb, 4) < 0) + if (ff_get_extradata(vst->codecpar, pb, 4) < 0) return AVERROR(ENOMEM); bink->num_audio_tracks = avio_rl32(pb); @@ -148,23 +148,23 @@ static int read_header(AVFormatContext *s) ast = avformat_new_stream(s, NULL); if (!ast) return AVERROR(ENOMEM); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_tag = 0; - ast->codec->sample_rate = avio_rl16(pb); - avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate); + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_tag = 0; + ast->codecpar->sample_rate = avio_rl16(pb); + avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate); flags = avio_rl16(pb); - ast->codec->codec_id = flags & BINK_AUD_USEDCT ? + ast->codecpar->codec_id = flags & BINK_AUD_USEDCT ? AV_CODEC_ID_BINKAUDIO_DCT : AV_CODEC_ID_BINKAUDIO_RDFT; if (flags & BINK_AUD_STEREO) { - ast->codec->channels = 2; - ast->codec->channel_layout = AV_CH_LAYOUT_STEREO; + ast->codecpar->channels = 2; + ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } else { - ast->codec->channels = 1; - ast->codec->channel_layout = AV_CH_LAYOUT_MONO; + ast->codecpar->channels = 1; + ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } - if (ff_alloc_extradata(ast->codec, 4)) + if (ff_alloc_extradata(ast->codecpar, 4)) return AVERROR(ENOMEM); - AV_WL32(ast->codec->extradata, vst->codec->codec_tag); + AV_WL32(ast->codecpar->extradata, vst->codecpar->codec_tag); } for (i = 0; i < bink->num_audio_tracks; i++) @@ -250,7 +250,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) (in bytes). We use this value to calcuate the audio PTS */ if (pkt->size >= 4) bink->audio_pts[bink->current_track -1] += - AV_RL32(pkt->data) / (2 * s->streams[bink->current_track]->codec->channels); + AV_RL32(pkt->data) / (2 * s->streams[bink->current_track]->codecpar->channels); return 0; } else { avio_skip(pb, audio_size); diff --git a/libavformat/bintext.c b/libavformat/bintext.c index 217ea49247..3a24c811ef 100644 --- a/libavformat/bintext.c +++ b/libavformat/bintext.c @@ -54,12 +54,12 @@ static AVStream * init_stream(AVFormatContext *s) AVStream *st = avformat_new_stream(s, NULL); if (!st) return NULL; - st->codec->codec_tag = 0; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_tag = 0; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; if (!bin->width) { - st->codec->width = (80<<3); - st->codec->height = (25<<4); + st->codecpar->width = (80<<3); + st->codecpar->height = (25<<4); } avpriv_set_pts_info(st, 60, bin->framerate.den, bin->framerate.num); @@ -74,9 +74,9 @@ static AVStream * init_stream(AVFormatContext *s) /** * Given filesize and width, calculate height (assume font_height of 16) */ -static void calculate_height(AVCodecContext *avctx, uint64_t fsize) +static void calculate_height(AVCodecParameters *par, uint64_t fsize) { - avctx->height = (fsize / ((avctx->width>>3)*2)) << 4; + par->height = (fsize / ((par->width>>3)*2)) << 4; } #endif @@ -119,11 +119,11 @@ static int next_tag_read(AVFormatContext *avctx, uint64_t *fsize) return 0; } -static void predict_width(AVCodecContext *avctx, uint64_t fsize, int got_width) +static void predict_width(AVCodecParameters *par, uint64_t fsize, int got_width) { /** attempt to guess width */ if (!got_width) - avctx->width = fsize > 4000 ? (160<<3) : (80<<3); + par->width = fsize > 4000 ? (160<<3) : (80<<3); } static int bintext_read_header(AVFormatContext *s) @@ -134,12 +134,12 @@ static int bintext_read_header(AVFormatContext *s) AVStream *st = init_stream(s); if (!st) return AVERROR(ENOMEM); - st->codec->codec_id = AV_CODEC_ID_BINTEXT; + st->codecpar->codec_id = AV_CODEC_ID_BINTEXT; - if (ff_alloc_extradata(st->codec, 2)) + if (ff_alloc_extradata(st->codecpar, 2)) return AVERROR(ENOMEM); - st->codec->extradata[0] = 16; - st->codec->extradata[1] = 0; + st->codecpar->extradata[0] = 16; + st->codecpar->extradata[1] = 0; if (pb->seekable) { int got_width = 0; @@ -147,8 +147,8 @@ static int bintext_read_header(AVFormatContext *s) if (ff_sauce_read(s, &bin->fsize, &got_width, 0) < 0) next_tag_read(s, &bin->fsize); if (!bin->width) { - predict_width(st->codec, bin->fsize, got_width); - calculate_height(st->codec, bin->fsize); + predict_width(st->codecpar, bin->fsize, got_width); + calculate_height(st->codecpar, bin->fsize); } avio_seek(pb, 0, SEEK_SET); } @@ -179,30 +179,30 @@ static int xbin_read_header(AVFormatContext *s) return AVERROR(ENOMEM); avio_skip(pb, 5); - st->codec->width = avio_rl16(pb)<<3; - st->codec->height = avio_rl16(pb); + st->codecpar->width = avio_rl16(pb)<<3; + st->codecpar->height = avio_rl16(pb); fontheight = avio_r8(pb); - st->codec->height *= fontheight; + st->codecpar->height *= fontheight; flags = avio_r8(pb); - st->codec->extradata_size = 2; + st->codecpar->extradata_size = 2; if ((flags & BINTEXT_PALETTE)) - st->codec->extradata_size += 48; + st->codecpar->extradata_size += 48; if ((flags & BINTEXT_FONT)) - st->codec->extradata_size += fontheight * (flags & 0x10 ? 512 : 256); - st->codec->codec_id = flags & 4 ? AV_CODEC_ID_XBIN : AV_CODEC_ID_BINTEXT; + st->codecpar->extradata_size += fontheight * (flags & 0x10 ? 512 : 256); + st->codecpar->codec_id = flags & 4 ? AV_CODEC_ID_XBIN : AV_CODEC_ID_BINTEXT; - if (ff_alloc_extradata(st->codec, st->codec->extradata_size)) + if (ff_alloc_extradata(st->codecpar, st->codecpar->extradata_size)) return AVERROR(ENOMEM); - st->codec->extradata[0] = fontheight; - st->codec->extradata[1] = flags; - if (avio_read(pb, st->codec->extradata + 2, st->codec->extradata_size - 2) < 0) + st->codecpar->extradata[0] = fontheight; + st->codecpar->extradata[1] = flags; + if (avio_read(pb, st->codecpar->extradata + 2, st->codecpar->extradata_size - 2) < 0) return AVERROR(EIO); if (pb->seekable) { - bin->fsize = avio_size(pb) - 9 - st->codec->extradata_size; + bin->fsize = avio_size(pb) - 9 - st->codecpar->extradata_size; ff_sauce_read(s, &bin->fsize, NULL, 0); - avio_seek(pb, 9 + st->codec->extradata_size, SEEK_SET); + avio_seek(pb, 9 + st->codecpar->extradata_size, SEEK_SET); } return 0; @@ -222,28 +222,28 @@ static int adf_read_header(AVFormatContext *s) st = init_stream(s); if (!st) return AVERROR(ENOMEM); - st->codec->codec_id = AV_CODEC_ID_BINTEXT; + st->codecpar->codec_id = AV_CODEC_ID_BINTEXT; - if (ff_alloc_extradata(st->codec, 2 + 48 + 4096)) + if (ff_alloc_extradata(st->codecpar, 2 + 48 + 4096)) return AVERROR(ENOMEM); - st->codec->extradata[0] = 16; - st->codec->extradata[1] = BINTEXT_PALETTE|BINTEXT_FONT; + st->codecpar->extradata[0] = 16; + st->codecpar->extradata[1] = BINTEXT_PALETTE|BINTEXT_FONT; - if (avio_read(pb, st->codec->extradata + 2, 24) < 0) + if (avio_read(pb, st->codecpar->extradata + 2, 24) < 0) return AVERROR(EIO); avio_skip(pb, 144); - if (avio_read(pb, st->codec->extradata + 2 + 24, 24) < 0) + if (avio_read(pb, st->codecpar->extradata + 2 + 24, 24) < 0) return AVERROR(EIO); - if (avio_read(pb, st->codec->extradata + 2 + 48, 4096) < 0) + if (avio_read(pb, st->codecpar->extradata + 2 + 48, 4096) < 0) return AVERROR(EIO); if (pb->seekable) { int got_width = 0; bin->fsize = avio_size(pb) - 1 - 192 - 4096; - st->codec->width = 80<<3; + st->codecpar->width = 80<<3; ff_sauce_read(s, &bin->fsize, &got_width, 0); if (!bin->width) - calculate_height(st->codec, bin->fsize); + calculate_height(st->codecpar, bin->fsize); avio_seek(pb, 1 + 192 + 4096, SEEK_SET); } return 0; @@ -277,24 +277,24 @@ static int idf_read_header(AVFormatContext *s) st = init_stream(s); if (!st) return AVERROR(ENOMEM); - st->codec->codec_id = AV_CODEC_ID_IDF; + st->codecpar->codec_id = AV_CODEC_ID_IDF; - if (ff_alloc_extradata(st->codec, 2 + 48 + 4096)) + if (ff_alloc_extradata(st->codecpar, 2 + 48 + 4096)) return AVERROR(ENOMEM); - st->codec->extradata[0] = 16; - st->codec->extradata[1] = BINTEXT_PALETTE|BINTEXT_FONT; + st->codecpar->extradata[0] = 16; + st->codecpar->extradata[1] = BINTEXT_PALETTE|BINTEXT_FONT; avio_seek(pb, avio_size(pb) - 4096 - 48, SEEK_SET); - if (avio_read(pb, st->codec->extradata + 2 + 48, 4096) < 0) + if (avio_read(pb, st->codecpar->extradata + 2 + 48, 4096) < 0) return AVERROR(EIO); - if (avio_read(pb, st->codec->extradata + 2, 48) < 0) + if (avio_read(pb, st->codecpar->extradata + 2, 48) < 0) return AVERROR(EIO); bin->fsize = avio_size(pb) - 12 - 4096 - 48; ff_sauce_read(s, &bin->fsize, &got_width, 0); if (!bin->width) - calculate_height(st->codec, bin->fsize); + calculate_height(st->codecpar, bin->fsize); avio_seek(pb, 12, SEEK_SET); return 0; } diff --git a/libavformat/bit.c b/libavformat/bit.c index 138d2feadb..c3f2fdfbe3 100644 --- a/libavformat/bit.c +++ b/libavformat/bit.c @@ -55,11 +55,11 @@ static int read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id=AV_CODEC_ID_G729; - st->codec->sample_rate=8000; - st->codec->block_align = 16; - st->codec->channels=1; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id=AV_CODEC_ID_G729; + st->codecpar->sample_rate=8000; + st->codecpar->block_align = 16; + st->codecpar->channels=1; avpriv_set_pts_info(st, 64, 1, 100); return 0; @@ -117,16 +117,16 @@ AVInputFormat ff_bit_demuxer = { #if CONFIG_MUXERS static int write_header(AVFormatContext *s) { - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; - if ((enc->codec_id != AV_CODEC_ID_G729) || enc->channels != 1) { + if ((par->codec_id != AV_CODEC_ID_G729) || par->channels != 1) { av_log(s, AV_LOG_ERROR, "only codec g729 with 1 channel is supported by this format\n"); return AVERROR(EINVAL); } - enc->bits_per_coded_sample = 16; - enc->block_align = (enc->bits_per_coded_sample * enc->channels) >> 3; + par->bits_per_coded_sample = 16; + par->block_align = (par->bits_per_coded_sample * par->channels) >> 3; return 0; } diff --git a/libavformat/bmv.c b/libavformat/bmv.c index f7a6068af3..c9580a29fd 100644 --- a/libavformat/bmv.c +++ b/libavformat/bmv.c @@ -47,20 +47,20 @@ static int bmv_read_header(AVFormatContext *s) st = avformat_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_BMV_VIDEO; - st->codec->width = 640; - st->codec->height = 429; - st->codec->pix_fmt = AV_PIX_FMT_PAL8; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_BMV_VIDEO; + st->codecpar->width = 640; + st->codecpar->height = 429; + st->codecpar->format = AV_PIX_FMT_PAL8; avpriv_set_pts_info(st, 16, 1, 12); ast = avformat_new_stream(s, 0); if (!ast) return AVERROR(ENOMEM); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = AV_CODEC_ID_BMV_AUDIO; - ast->codec->channels = 2; - ast->codec->channel_layout = AV_CH_LAYOUT_STEREO; - ast->codec->sample_rate = 22050; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = AV_CODEC_ID_BMV_AUDIO; + ast->codecpar->channels = 2; + ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + ast->codecpar->sample_rate = 22050; avpriv_set_pts_info(ast, 16, 1, 22050); c->get_next = 1; diff --git a/libavformat/boadec.c b/libavformat/boadec.c index be003e59c1..ac2a33b3f0 100644 --- a/libavformat/boadec.c +++ b/libavformat/boadec.c @@ -46,16 +46,16 @@ static int read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_MS; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_MS; avio_rl32(s->pb); avio_rl32(s->pb); - st->codec->sample_rate = avio_rl32(s->pb); - st->codec->channels = avio_rl32(s->pb); + st->codecpar->sample_rate = avio_rl32(s->pb); + st->codecpar->channels = avio_rl32(s->pb); s->internal->data_offset = avio_rl32(s->pb); avio_r8(s->pb); - st->codec->block_align = st->codec->channels * avio_rl32(s->pb); + st->codecpar->block_align = st->codecpar->channels * avio_rl32(s->pb); avio_seek(s->pb, s->internal->data_offset, SEEK_SET); @@ -66,7 +66,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) { AVStream *st = s->streams[0]; - return av_get_packet(s->pb, pkt, st->codec->block_align); + return av_get_packet(s->pb, pkt, st->codecpar->block_align); } AVInputFormat ff_boa_demuxer = { diff --git a/libavformat/brstm.c b/libavformat/brstm.c index 6fd44f168d..2e1cada158 100644 --- a/libavformat/brstm.c +++ b/libavformat/brstm.c @@ -99,7 +99,7 @@ static int read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; avio_skip(s->pb, 4); @@ -197,15 +197,15 @@ static int read_header(AVFormatContext *s) } loop = avio_r8(s->pb); // loop flag - st->codec->codec_id = codec; - st->codec->channels = avio_r8(s->pb); - if (!st->codec->channels) + st->codecpar->codec_id = codec; + st->codecpar->channels = avio_r8(s->pb); + if (!st->codecpar->channels) return AVERROR_INVALIDDATA; avio_skip(s->pb, 1); // padding - st->codec->sample_rate = bfstm ? read32(s) : read16(s); - if (st->codec->sample_rate <= 0) + st->codecpar->sample_rate = bfstm ? read32(s) : read16(s); + if (st->codecpar->sample_rate <= 0) return AVERROR_INVALIDDATA; if (!bfstm) @@ -214,7 +214,7 @@ static int read_header(AVFormatContext *s) if (loop) { if (av_dict_set_int(&s->metadata, "loop_start", av_rescale(read32(s), AV_TIME_BASE, - st->codec->sample_rate), + st->codecpar->sample_rate), 0) < 0) return AVERROR(ENOMEM); } else { @@ -223,7 +223,7 @@ static int read_header(AVFormatContext *s) st->start_time = 0; st->duration = read32(s); - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); if (!bfstm) start = read32(s); @@ -235,14 +235,14 @@ static int read_header(AVFormatContext *s) } b->block_size = read32(s); - if (b->block_size > UINT32_MAX / st->codec->channels) + if (b->block_size > UINT32_MAX / st->codecpar->channels) return AVERROR_INVALIDDATA; b->samples_per_block = read32(s); b->last_block_used_bytes = read32(s); b->last_block_samples = read32(s); b->last_block_size = read32(s); - if (b->last_block_size > UINT32_MAX / st->codec->channels) + if (b->last_block_size > UINT32_MAX / st->codecpar->channels) return AVERROR_INVALIDDATA; if (b->last_block_used_bytes > b->last_block_size) return AVERROR_INVALIDDATA; @@ -255,16 +255,16 @@ static int read_header(AVFormatContext *s) if (!bfstm) toffset = read32(s) + 16LL; else - toffset = toffset + read32(s) + st->codec->channels * 8 - 8; + toffset = toffset + read32(s) + st->codecpar->channels * 8 - 8; if (toffset > size) return AVERROR_INVALIDDATA; avio_skip(s->pb, pos + toffset - avio_tell(s->pb)); - b->table = av_mallocz(32 * st->codec->channels); + b->table = av_mallocz(32 * st->codecpar->channels); if (!b->table) return AVERROR(ENOMEM); - for (ch = 0; ch < st->codec->channels; ch++) { + for (ch = 0; ch < st->codecpar->channels; ch++) { if (avio_read(s->pb, b->table + ch * 32, 32) != 32) { ret = AVERROR_INVALIDDATA; goto fail; @@ -295,7 +295,7 @@ static int read_header(AVFormatContext *s) codec != AV_CODEC_ID_ADPCM_THP_LE) goto skip; - asize = b->block_count * st->codec->channels * 4; + asize = b->block_count * st->codecpar->channels * 4; if (size < asize) { ret = AVERROR_INVALIDDATA; goto fail; @@ -357,7 +357,7 @@ fail: static int read_packet(AVFormatContext *s, AVPacket *pkt) { - AVCodecContext *codec = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; BRSTMDemuxContext *b = s->priv_data; uint32_t samples, size, skip = 0; int ret, i; @@ -385,8 +385,8 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR_EOF; } - if (codec->codec_id == AV_CODEC_ID_ADPCM_THP || - codec->codec_id == AV_CODEC_ID_ADPCM_THP_LE) { + if (par->codec_id == AV_CODEC_ID_ADPCM_THP || + par->codec_id == AV_CODEC_ID_ADPCM_THP_LE) { uint8_t *dst; if (!b->adpc) { @@ -394,30 +394,30 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR_INVALIDDATA; } if (!b->table) { - b->table = av_mallocz(32 * codec->channels); + b->table = av_mallocz(32 * par->channels); if (!b->table) return AVERROR(ENOMEM); } if (size > (INT_MAX - 32 - 4) || - (32 + 4 + size) > (INT_MAX / codec->channels) || - (32 + 4 + size) * codec->channels > INT_MAX - 8) + (32 + 4 + size) > (INT_MAX / par->channels) || + (32 + 4 + size) * par->channels > INT_MAX - 8) return AVERROR_INVALIDDATA; - if (av_new_packet(pkt, 8 + (32 + 4 + size) * codec->channels) < 0) + if (av_new_packet(pkt, 8 + (32 + 4 + size) * par->channels) < 0) return AVERROR(ENOMEM); dst = pkt->data; - if (codec->codec_id == AV_CODEC_ID_ADPCM_THP_LE) { - bytestream_put_le32(&dst, size * codec->channels); + if (par->codec_id == AV_CODEC_ID_ADPCM_THP_LE) { + bytestream_put_le32(&dst, size * par->channels); bytestream_put_le32(&dst, samples); } else { - bytestream_put_be32(&dst, size * codec->channels); + bytestream_put_be32(&dst, size * par->channels); bytestream_put_be32(&dst, samples); } - bytestream_put_buffer(&dst, b->table, 32 * codec->channels); - bytestream_put_buffer(&dst, b->adpc + 4 * codec->channels * - (b->current_block - 1), 4 * codec->channels); + bytestream_put_buffer(&dst, b->table, 32 * par->channels); + bytestream_put_buffer(&dst, b->adpc + 4 * par->channels * + (b->current_block - 1), 4 * par->channels); - for (i = 0; i < codec->channels; i++) { + for (i = 0; i < par->channels; i++) { ret = avio_read(s->pb, dst, size); dst += size; avio_skip(s->pb, skip); @@ -428,7 +428,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) } pkt->duration = samples; } else { - size *= codec->channels; + size *= par->channels; ret = av_get_packet(s->pb, pkt, size); } @@ -449,7 +449,7 @@ static int read_seek(AVFormatContext *s, int stream_index, timestamp /= b->samples_per_block; ret = avio_seek(s->pb, b->data_start + timestamp * b->block_size * - st->codec->channels, SEEK_SET); + st->codecpar->channels, SEEK_SET); if (ret < 0) return ret; diff --git a/libavformat/c93.c b/libavformat/c93.c index 20ae9c4932..b1a245a3cf 100644 --- a/libavformat/c93.c +++ b/libavformat/c93.c @@ -83,10 +83,10 @@ static int read_header(AVFormatContext *s) if (!video) return AVERROR(ENOMEM); - video->codec->codec_type = AVMEDIA_TYPE_VIDEO; - video->codec->codec_id = AV_CODEC_ID_C93; - video->codec->width = 320; - video->codec->height = 192; + video->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + video->codecpar->codec_id = AV_CODEC_ID_C93; + video->codecpar->width = 320; + video->codecpar->height = 192; /* 4:3 320x200 with 8 empty lines */ video->sample_aspect_ratio = (AVRational) { 5, 6 }; avpriv_set_pts_info(video, 64, 2, 25); @@ -120,7 +120,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) c93->audio = avformat_new_stream(s, NULL); if (!c93->audio) return AVERROR(ENOMEM); - c93->audio->codec->codec_type = AVMEDIA_TYPE_AUDIO; + c93->audio->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; } avio_skip(pb, 26); /* VOC header */ ret = ff_voc_get_packet(s, pkt, c93->audio, datasize - 26); diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c index bfbbb02627..91b50c8199 100644 --- a/libavformat/cafdec.c +++ b/libavformat/cafdec.c @@ -69,29 +69,29 @@ static int read_desc_chunk(AVFormatContext *s) return AVERROR(ENOMEM); /* parse format description */ - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->sample_rate = av_int2double(avio_rb64(pb)); - st->codec->codec_tag = avio_rl32(pb); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->sample_rate = av_int2double(avio_rb64(pb)); + st->codecpar->codec_tag = avio_rl32(pb); flags = avio_rb32(pb); caf->bytes_per_packet = avio_rb32(pb); - st->codec->block_align = caf->bytes_per_packet; + st->codecpar->block_align = caf->bytes_per_packet; caf->frames_per_packet = avio_rb32(pb); - st->codec->channels = avio_rb32(pb); - st->codec->bits_per_coded_sample = avio_rb32(pb); + st->codecpar->channels = avio_rb32(pb); + st->codecpar->bits_per_coded_sample = avio_rb32(pb); /* calculate bit rate for constant size packets */ if (caf->frames_per_packet > 0 && caf->bytes_per_packet > 0) { - st->codec->bit_rate = (uint64_t)st->codec->sample_rate * (uint64_t)caf->bytes_per_packet * 8 - / (uint64_t)caf->frames_per_packet; + st->codecpar->bit_rate = (uint64_t)st->codecpar->sample_rate * (uint64_t)caf->bytes_per_packet * 8 + / (uint64_t)caf->frames_per_packet; } else { - st->codec->bit_rate = 0; + st->codecpar->bit_rate = 0; } /* determine codec */ - if (st->codec->codec_tag == MKTAG('l','p','c','m')) - st->codec->codec_id = ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, (flags ^ 0x2) | 0x4); + if (st->codecpar->codec_tag == MKTAG('l','p','c','m')) + st->codecpar->codec_id = ff_mov_get_lpcm_codec_id(st->codecpar->bits_per_coded_sample, (flags ^ 0x2) | 0x4); else - st->codec->codec_id = ff_codec_get_id(ff_codec_caf_tags, st->codec->codec_tag); + st->codecpar->codec_id = ff_codec_get_id(ff_codec_caf_tags, st->codecpar->codec_tag); return 0; } @@ -104,7 +104,7 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size) if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) return -1; - if (st->codec->codec_id == AV_CODEC_ID_AAC) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC) { /* The magic cookie format for AAC is an mp4 esds atom. The lavc AAC decoder requires the data from the codec specific description as extradata input. */ @@ -113,13 +113,13 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size) strt = avio_tell(pb); ff_mov_read_esds(s, pb); skip = size - (avio_tell(pb) - strt); - if (skip < 0 || !st->codec->extradata || - st->codec->codec_id != AV_CODEC_ID_AAC) { + if (skip < 0 || !st->codecpar->extradata || + st->codecpar->codec_id != AV_CODEC_ID_AAC) { av_log(s, AV_LOG_ERROR, "invalid AAC magic cookie\n"); return AVERROR_INVALIDDATA; } avio_skip(pb, skip); - } else if (st->codec->codec_id == AV_CODEC_ID_ALAC) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_ALAC) { #define ALAC_PREAMBLE 12 #define ALAC_HEADER 36 #define ALAC_NEW_KUKI 24 @@ -134,8 +134,8 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size) return AVERROR_INVALIDDATA; } - av_freep(&st->codec->extradata); - if (ff_alloc_extradata(st->codec, ALAC_HEADER)) + av_freep(&st->codecpar->extradata); + if (ff_alloc_extradata(st->codecpar, ALAC_HEADER)) return AVERROR(ENOMEM); /* For the old style cookie, we skip 12 bytes, then read 36 bytes. @@ -145,30 +145,30 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size) if (!memcmp(&preamble[4], "frmaalac", 8)) { if (size < ALAC_PREAMBLE + ALAC_HEADER) { av_log(s, AV_LOG_ERROR, "invalid ALAC magic cookie\n"); - av_freep(&st->codec->extradata); + av_freep(&st->codecpar->extradata); return AVERROR_INVALIDDATA; } - if (avio_read(pb, st->codec->extradata, ALAC_HEADER) != ALAC_HEADER) { + if (avio_read(pb, st->codecpar->extradata, ALAC_HEADER) != ALAC_HEADER) { av_log(s, AV_LOG_ERROR, "failed to read kuki header\n"); - av_freep(&st->codec->extradata); + av_freep(&st->codecpar->extradata); return AVERROR_INVALIDDATA; } avio_skip(pb, size - ALAC_PREAMBLE - ALAC_HEADER); } else { - AV_WB32(st->codec->extradata, 36); - memcpy(&st->codec->extradata[4], "alac", 4); - AV_WB32(&st->codec->extradata[8], 0); - memcpy(&st->codec->extradata[12], preamble, 12); - if (avio_read(pb, &st->codec->extradata[24], ALAC_NEW_KUKI - 12) != ALAC_NEW_KUKI - 12) { + AV_WB32(st->codecpar->extradata, 36); + memcpy(&st->codecpar->extradata[4], "alac", 4); + AV_WB32(&st->codecpar->extradata[8], 0); + memcpy(&st->codecpar->extradata[12], preamble, 12); + if (avio_read(pb, &st->codecpar->extradata[24], ALAC_NEW_KUKI - 12) != ALAC_NEW_KUKI - 12) { av_log(s, AV_LOG_ERROR, "failed to read new kuki header\n"); - av_freep(&st->codec->extradata); + av_freep(&st->codecpar->extradata); return AVERROR_INVALIDDATA; } avio_skip(pb, size - ALAC_NEW_KUKI); } } else { - av_freep(&st->codec->extradata); - if (ff_get_extradata(st->codec, pb, size) < 0) + av_freep(&st->codecpar->extradata); + if (ff_get_extradata(st->codecpar, pb, size) < 0) return AVERROR(ENOMEM); } @@ -323,15 +323,15 @@ static int read_header(AVFormatContext *s) if (caf->data_size > 0) st->nb_frames = (caf->data_size / caf->bytes_per_packet) * caf->frames_per_packet; } else if (st->nb_index_entries && st->duration > 0) { - st->codec->bit_rate = st->codec->sample_rate * caf->data_size * 8 / - st->duration; + st->codecpar->bit_rate = st->codecpar->sample_rate * caf->data_size * 8 / + st->duration; } else { av_log(s, AV_LOG_ERROR, "Missing packet table. It is required when " "block size or frame size are variable.\n"); return AVERROR_INVALIDDATA; } - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); st->start_time = 0; /* position the stream at the start of data */ diff --git a/libavformat/cafenc.c b/libavformat/cafenc.c index 0b2f649463..f2d7ec90b1 100644 --- a/libavformat/cafenc.c +++ b/libavformat/cafenc.c @@ -102,19 +102,19 @@ static uint32_t samples_per_packet(enum AVCodecID codec_id, int channels, int bl static int caf_write_header(AVFormatContext *s) { AVIOContext *pb = s->pb; - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; CAFContext *caf = s->priv_data; AVDictionaryEntry *t = NULL; - unsigned int codec_tag = ff_codec_get_tag(ff_codec_caf_tags, enc->codec_id); + unsigned int codec_tag = ff_codec_get_tag(ff_codec_caf_tags, par->codec_id); int64_t chunk_size = 0; - int frame_size = enc->frame_size; + int frame_size = par->frame_size; if (s->nb_streams != 1) { av_log(s, AV_LOG_ERROR, "CAF files have exactly one stream\n"); return AVERROR(EINVAL); } - switch (enc->codec_id) { + switch (par->codec_id) { case AV_CODEC_ID_AAC: av_log(s, AV_LOG_ERROR, "muxing codec currently unsupported\n"); return AVERROR_PATCHWELCOME; @@ -125,13 +125,13 @@ static int caf_write_header(AVFormatContext *s) return AVERROR_INVALIDDATA; } - if (!enc->block_align && !pb->seekable) { + if (!par->block_align && !pb->seekable) { av_log(s, AV_LOG_ERROR, "Muxing variable packet size not supported on non seekable output\n"); return AVERROR_INVALIDDATA; } - if (enc->codec_id != AV_CODEC_ID_MP3 || frame_size != 576) - frame_size = samples_per_packet(enc->codec_id, enc->channels, enc->block_align); + if (par->codec_id != AV_CODEC_ID_MP3 || frame_size != 576) + frame_size = samples_per_packet(par->codec_id, par->channels, par->block_align); ffio_wfourcc(pb, "caff"); //< mFileType avio_wb16(pb, 1); //< mFileVersion @@ -139,26 +139,26 @@ static int caf_write_header(AVFormatContext *s) ffio_wfourcc(pb, "desc"); //< Audio Description chunk avio_wb64(pb, 32); //< mChunkSize - avio_wb64(pb, av_double2int(enc->sample_rate)); //< mSampleRate + avio_wb64(pb, av_double2int(par->sample_rate)); //< mSampleRate avio_wl32(pb, codec_tag); //< mFormatID - avio_wb32(pb, codec_flags(enc->codec_id)); //< mFormatFlags - avio_wb32(pb, enc->block_align); //< mBytesPerPacket + avio_wb32(pb, codec_flags(par->codec_id)); //< mFormatFlags + avio_wb32(pb, par->block_align); //< mBytesPerPacket avio_wb32(pb, frame_size); //< mFramesPerPacket - avio_wb32(pb, enc->channels); //< mChannelsPerFrame - avio_wb32(pb, av_get_bits_per_sample(enc->codec_id)); //< mBitsPerChannel + avio_wb32(pb, par->channels); //< mChannelsPerFrame + avio_wb32(pb, av_get_bits_per_sample(par->codec_id)); //< mBitsPerChannel - if (enc->channel_layout) { + if (par->channel_layout) { ffio_wfourcc(pb, "chan"); avio_wb64(pb, 12); - ff_mov_write_chan(pb, enc->channel_layout); + ff_mov_write_chan(pb, par->channel_layout); } - if (enc->codec_id == AV_CODEC_ID_ALAC) { + if (par->codec_id == AV_CODEC_ID_ALAC) { ffio_wfourcc(pb, "kuki"); - avio_wb64(pb, 12 + enc->extradata_size); + avio_wb64(pb, 12 + par->extradata_size); avio_write(pb, "\0\0\0\14frmaalac", 12); - avio_write(pb, enc->extradata, enc->extradata_size); - } else if (enc->codec_id == AV_CODEC_ID_AMR_NB) { + avio_write(pb, par->extradata, par->extradata_size); + } else if (par->codec_id == AV_CODEC_ID_AMR_NB) { ffio_wfourcc(pb, "kuki"); avio_wb64(pb, 29); avio_write(pb, "\0\0\0\14frmasamr", 12); @@ -169,10 +169,10 @@ static int caf_write_header(AVFormatContext *s) avio_wb16(pb, 0x81FF); /* Mode set (all modes for AMR_NB) */ avio_w8(pb, 0x00); /* Mode change period (no restriction) */ avio_w8(pb, 0x01); /* Frames per sample */ - } else if (enc->codec_id == AV_CODEC_ID_QDM2) { + } else if (par->codec_id == AV_CODEC_ID_QDM2) { ffio_wfourcc(pb, "kuki"); - avio_wb64(pb, enc->extradata_size); - avio_write(pb, enc->extradata, enc->extradata_size); + avio_wb64(pb, par->extradata_size); + avio_write(pb, par->extradata, par->extradata_size); } ff_standardize_creation_time(s); @@ -204,7 +204,7 @@ static int caf_write_packet(AVFormatContext *s, AVPacket *pkt) CAFContext *caf = s->priv_data; avio_write(s->pb, pkt->data, pkt->size); - if (!s->streams[0]->codec->block_align) { + if (!s->streams[0]->codecpar->block_align) { void *pkt_sizes = caf->pkt_sizes; int i, alloc_size = caf->size_entries_used + 5; if (alloc_size < 0) { @@ -233,7 +233,7 @@ static int caf_write_trailer(AVFormatContext *s) { CAFContext *caf = s->priv_data; AVIOContext *pb = s->pb; - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; if (pb->seekable) { int64_t file_size = avio_tell(pb); @@ -241,11 +241,11 @@ static int caf_write_trailer(AVFormatContext *s) avio_seek(pb, caf->data, SEEK_SET); avio_wb64(pb, file_size - caf->data - 8); avio_seek(pb, file_size, SEEK_SET); - if (!enc->block_align) { + if (!par->block_align) { ffio_wfourcc(pb, "pakt"); avio_wb64(pb, caf->size_entries_used + 24); avio_wb64(pb, caf->packets); ///< mNumberPackets - avio_wb64(pb, caf->packets * samples_per_packet(enc->codec_id, enc->channels, enc->block_align)); ///< mNumberValidFrames + avio_wb64(pb, caf->packets * samples_per_packet(par->codec_id, par->channels, par->block_align)); ///< mNumberValidFrames avio_wb32(pb, 0); ///< mPrimingFrames avio_wb32(pb, 0); ///< mRemainderFrames avio_write(pb, caf->pkt_sizes, caf->size_entries_used); diff --git a/libavformat/cdg.c b/libavformat/cdg.c index b1f137ff33..05cac6e528 100644 --- a/libavformat/cdg.c +++ b/libavformat/cdg.c @@ -39,8 +39,8 @@ static int read_header(AVFormatContext *s) if (!vst) return AVERROR(ENOMEM); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_CDGRAPHICS; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_CDGRAPHICS; /// 75 sectors/sec * 4 packets/sector = 300 packets/sec avpriv_set_pts_info(vst, 32, 1, 300); diff --git a/libavformat/cdxl.c b/libavformat/cdxl.c index 0b8b199ce9..94a063c813 100644 --- a/libavformat/cdxl.c +++ b/libavformat/cdxl.c @@ -150,17 +150,17 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = 0; - st->codec->codec_id = AV_CODEC_ID_PCM_S8; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = 0; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S8; if (cdxl->header[1] & 0x10) { - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } else { - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } - st->codec->sample_rate = cdxl->sample_rate; + st->codecpar->sample_rate = cdxl->sample_rate; st->start_time = 0; cdxl->audio_stream_index = st->index; avpriv_set_pts_info(st, 64, 1, cdxl->sample_rate); @@ -179,11 +179,11 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_tag = 0; - st->codec->codec_id = AV_CODEC_ID_CDXL; - st->codec->width = width; - st->codec->height = height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_tag = 0; + st->codecpar->codec_id = AV_CODEC_ID_CDXL; + st->codecpar->width = width; + st->codecpar->height = height; if (audio_size + video_size && cdxl->filesize > 0) { frames = cdxl->filesize / (audio_size + video_size); diff --git a/libavformat/chromaprint.c b/libavformat/chromaprint.c index 4d67f43499..8c9a6c0111 100644 --- a/libavformat/chromaprint.c +++ b/libavformat/chromaprint.c @@ -85,17 +85,17 @@ static int write_header(AVFormatContext *s) st = s->streams[0]; - if (st->codec->channels > 2) { + if (st->codecpar->channels > 2) { av_log(s, AV_LOG_ERROR, "Only up to 2 channels are supported\n"); goto fail; } - if (st->codec->sample_rate < 1000) { + if (st->codecpar->sample_rate < 1000) { av_log(s, AV_LOG_ERROR, "Sampling rate must be at least 1000\n"); goto fail; } - if (!chromaprint_start(cpr->ctx, st->codec->sample_rate, st->codec->channels)) { + if (!chromaprint_start(cpr->ctx, st->codecpar->sample_rate, st->codecpar->channels)) { av_log(s, AV_LOG_ERROR, "Failed to start chromaprint\n"); goto fail; } diff --git a/libavformat/cinedec.c b/libavformat/cinedec.c index 318408436f..0efedda1a3 100644 --- a/libavformat/cinedec.c +++ b/libavformat/cinedec.c @@ -101,9 +101,9 @@ static int cine_read_header(AVFormatContext *avctx) st = avformat_new_stream(avctx, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; - st->codec->codec_tag = 0; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->codec_tag = 0; /* CINEFILEHEADER structure */ avio_skip(pb, 4); // Type, Headersize @@ -127,8 +127,8 @@ static int cine_read_header(AVFormatContext *avctx) /* BITMAPINFOHEADER structure */ avio_seek(pb, offImageHeader, SEEK_SET); avio_skip(pb, 4); //biSize - st->codec->width = avio_rl32(pb); - st->codec->height = avio_rl32(pb); + st->codecpar->width = avio_rl32(pb); + st->codecpar->height = avio_rl32(pb); if (avio_rl16(pb) != 1) // biPlanes return AVERROR_INVALIDDATA; @@ -144,7 +144,7 @@ static int cine_read_header(AVFormatContext *avctx) vflip = 0; break; case 0x100: /* BI_PACKED */ - st->codec->codec_tag = MKTAG('B', 'I', 'T', 0); + st->codecpar->codec_tag = MKTAG('B', 'I', 'T', 0); vflip = 1; break; default: @@ -167,8 +167,8 @@ static int cine_read_header(AVFormatContext *avctx) avio_skip(pb, 616); // Binning .. bFlipH if (!avio_rl32(pb) ^ vflip) { - st->codec->extradata = av_strdup("BottomUp"); - st->codec->extradata_size = 9; + st->codecpar->extradata = av_strdup("BottomUp"); + st->codecpar->extradata_size = 9; } avio_skip(pb, 4); // Grid @@ -193,17 +193,17 @@ static int cine_read_header(AVFormatContext *avctx) set_metadata_float(&st->metadata, "wbgain[0].b", av_int2float(avio_rl32(pb)), 1); avio_skip(pb, 36); // WBGain[1].. WBView - st->codec->bits_per_coded_sample = avio_rl32(pb); + st->codecpar->bits_per_coded_sample = avio_rl32(pb); if (compression == CC_RGB) { if (biBitCount == 8) { - st->codec->pix_fmt = AV_PIX_FMT_GRAY8; + st->codecpar->format = AV_PIX_FMT_GRAY8; } else if (biBitCount == 16) { - st->codec->pix_fmt = AV_PIX_FMT_GRAY16LE; + st->codecpar->format = AV_PIX_FMT_GRAY16LE; } else if (biBitCount == 24) { - st->codec->pix_fmt = AV_PIX_FMT_BGR24; + st->codecpar->format = AV_PIX_FMT_BGR24; } else if (biBitCount == 48) { - st->codec->pix_fmt = AV_PIX_FMT_BGR48LE; + st->codecpar->format = AV_PIX_FMT_BGR48LE; } else { avpriv_request_sample(avctx, "unsupported biBitCount %i", biBitCount); return AVERROR_INVALIDDATA; @@ -212,9 +212,9 @@ static int cine_read_header(AVFormatContext *avctx) switch (CFA & 0xFFFFFF) { case CFA_BAYER: if (biBitCount == 8) { - st->codec->pix_fmt = AV_PIX_FMT_BAYER_GBRG8; + st->codecpar->format = AV_PIX_FMT_BAYER_GBRG8; } else if (biBitCount == 16) { - st->codec->pix_fmt = AV_PIX_FMT_BAYER_GBRG16LE; + st->codecpar->format = AV_PIX_FMT_BAYER_GBRG16LE; } else { avpriv_request_sample(avctx, "unsupported biBitCount %i", biBitCount); return AVERROR_INVALIDDATA; @@ -222,9 +222,9 @@ static int cine_read_header(AVFormatContext *avctx) break; case CFA_BAYERFLIP: if (biBitCount == 8) { - st->codec->pix_fmt = AV_PIX_FMT_BAYER_RGGB8; + st->codecpar->format = AV_PIX_FMT_BAYER_RGGB8; } else if (biBitCount == 16) { - st->codec->pix_fmt = AV_PIX_FMT_BAYER_RGGB16LE; + st->codecpar->format = AV_PIX_FMT_BAYER_RGGB16LE; } else { avpriv_request_sample(avctx, "unsupported biBitCount %i", biBitCount); return AVERROR_INVALIDDATA; diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c index 20a37e022a..50d6689413 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -35,6 +35,7 @@ typedef enum ConcatMatchMode { typedef struct ConcatStream { AVBitStreamFilterContext *bsf; + AVCodecContext *avctx; int out_stream_index; } ConcatStream; @@ -164,19 +165,28 @@ static int copy_stream_props(AVStream *st, AVStream *source_st) { int ret; - if (st->codec->codec_id || !source_st->codec->codec_id) { - if (st->codec->extradata_size < source_st->codec->extradata_size) { - ret = ff_alloc_extradata(st->codec, - source_st->codec->extradata_size); + if (st->codecpar->codec_id || !source_st->codecpar->codec_id) { + if (st->codecpar->extradata_size < source_st->codecpar->extradata_size) { + if (st->codecpar->extradata) { + av_freep(&st->codecpar->extradata); + st->codecpar->extradata_size = 0; + } + ret = ff_alloc_extradata(st->codecpar, + source_st->codecpar->extradata_size); if (ret < 0) return ret; } - memcpy(st->codec->extradata, source_st->codec->extradata, - source_st->codec->extradata_size); + memcpy(st->codecpar->extradata, source_st->codecpar->extradata, + source_st->codecpar->extradata_size); return 0; } - if ((ret = avcodec_copy_context(st->codec, source_st->codec)) < 0) + if ((ret = avcodec_parameters_copy(st->codecpar, source_st->codecpar)) < 0) return ret; + /* We don't want to carry around MP4-style extradata, since we are usoign a bsf anyway. */ + if (st->codecpar->codec_id == AV_CODEC_ID_H264) { + av_freep(&st->codecpar->extradata); + st->codecpar->extradata_size = 0; + } st->r_frame_rate = source_st->r_frame_rate; st->avg_frame_rate = source_st->avg_frame_rate; st->time_base = source_st->time_base; @@ -192,9 +202,10 @@ static int detect_stream_specific(AVFormatContext *avf, int idx) AVStream *st = cat->avf->streams[idx]; ConcatStream *cs = &cat->cur_file->streams[idx]; AVBitStreamFilterContext *bsf; + int ret; - if (cat->auto_convert && st->codec->codec_id == AV_CODEC_ID_H264 && - (st->codec->extradata_size < 4 || AV_RB32(st->codec->extradata) != 1)) { + if (cat->auto_convert && st->codecpar->codec_id == AV_CODEC_ID_H264 && + (st->codecpar->extradata_size < 4 || AV_RB32(st->codecpar->extradata) != 1)) { av_log(cat->avf, AV_LOG_INFO, "Auto-inserting h264_mp4toannexb bitstream filter\n"); if (!(bsf = av_bitstream_filter_init("h264_mp4toannexb"))) { @@ -203,6 +214,17 @@ static int detect_stream_specific(AVFormatContext *avf, int idx) return AVERROR_BSF_NOT_FOUND; } cs->bsf = bsf; + + cs->avctx = avcodec_alloc_context3(NULL); + if (!cs->avctx) + return AVERROR(ENOMEM); + + ret = avcodec_parameters_to_context(cs->avctx, st->codecpar); + if (ret < 0) { + avcodec_free_context(&cs->avctx); + return ret; + } + } return 0; } @@ -338,15 +360,21 @@ static int open_file(AVFormatContext *avf, unsigned fileno) static int concat_read_close(AVFormatContext *avf) { ConcatContext *cat = avf->priv_data; - unsigned i; + unsigned i, j; - if (cat->avf) - avformat_close_input(&cat->avf); for (i = 0; i < cat->nb_files; i++) { av_freep(&cat->files[i].url); + for (j = 0; j < cat->avf->nb_streams; j++) { + if (cat->files[i].streams[j].avctx) + avcodec_free_context(&cat->files[i].streams[j].avctx); + if (cat->files[i].streams[j].bsf) + av_bitstream_filter_close(cat->files[i].streams[j].bsf); + } av_freep(&cat->files[i].streams); av_dict_free(&cat->files[i].metadata); } + if (cat->avf) + avformat_close_input(&cat->avf); av_freep(&cat->files); return 0; } @@ -499,7 +527,8 @@ static int filter_packet(AVFormatContext *avf, ConcatStream *cs, AVPacket *pkt) av_assert0(cs->out_stream_index >= 0); for (bsf = cs->bsf; bsf; bsf = bsf->next) { pkt2 = *pkt; - ret = av_bitstream_filter_filter(bsf, st->codec, NULL, + + ret = av_bitstream_filter_filter(bsf, cs->avctx, NULL, &pkt2.data, &pkt2.size, pkt->data, pkt->size, !!(pkt->flags & AV_PKT_FLAG_KEY)); @@ -507,6 +536,21 @@ static int filter_packet(AVFormatContext *avf, ConcatStream *cs, AVPacket *pkt) av_packet_unref(pkt); return ret; } + + if (cs->avctx->extradata_size > st->codecpar->extradata_size) { + int eret; + if (st->codecpar->extradata) + av_freep(&st->codecpar->extradata); + + eret = ff_alloc_extradata(st->codecpar, cs->avctx->extradata_size); + if (eret < 0) { + av_packet_unref(pkt); + return AVERROR(ENOMEM); + } + st->codecpar->extradata_size = cs->avctx->extradata_size; + memcpy(st->codecpar->extradata, cs->avctx->extradata, cs->avctx->extradata_size); + } + av_assert0(pkt2.buf); if (ret == 0 && pkt2.data != pkt->data) { if ((ret = av_copy_packet(&pkt2, pkt)) < 0) { diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c index 931d32d145..8ddf0f36e6 100644 --- a/libavformat/dashenc.c +++ b/libavformat/dashenc.c @@ -109,19 +109,19 @@ static int dash_write(void *opaque, uint8_t *buf, int buf_size) } // RFC 6381 -static void set_codec_str(AVFormatContext *s, AVCodecContext *codec, +static void set_codec_str(AVFormatContext *s, AVCodecParameters *par, char *str, int size) { const AVCodecTag *tags[2] = { NULL, NULL }; uint32_t tag; - if (codec->codec_type == AVMEDIA_TYPE_VIDEO) + if (par->codec_type == AVMEDIA_TYPE_VIDEO) tags[0] = ff_codec_movvideo_tags; - else if (codec->codec_type == AVMEDIA_TYPE_AUDIO) + else if (par->codec_type == AVMEDIA_TYPE_AUDIO) tags[0] = ff_codec_movaudio_tags; else return; - tag = av_codec_get_tag(tags, codec->codec_id); + tag = av_codec_get_tag(tags, par->codec_id); if (!tag) return; if (size < 5) @@ -132,17 +132,17 @@ static void set_codec_str(AVFormatContext *s, AVCodecContext *codec, if (!strcmp(str, "mp4a") || !strcmp(str, "mp4v")) { uint32_t oti; tags[0] = ff_mp4_obj_type; - oti = av_codec_get_tag(tags, codec->codec_id); + oti = av_codec_get_tag(tags, par->codec_id); if (oti) av_strlcatf(str, size, ".%02x", oti); else return; if (tag == MKTAG('m', 'p', '4', 'a')) { - if (codec->extradata_size >= 2) { - int aot = codec->extradata[0] >> 3; + if (par->extradata_size >= 2) { + int aot = par->extradata[0] >> 3; if (aot == 31) - aot = ((AV_RB16(codec->extradata) >> 5) & 0x3f) + 32; + aot = ((AV_RB16(par->extradata) >> 5) & 0x3f) + 32; av_strlcatf(str, size, ".%d", aot); } } else if (tag == MKTAG('m', 'p', '4', 'v')) { @@ -151,8 +151,8 @@ static void set_codec_str(AVFormatContext *s, AVCodecContext *codec, } } else if (!strcmp(str, "avc1")) { uint8_t *tmpbuf = NULL; - uint8_t *extradata = codec->extradata; - int extradata_size = codec->extradata_size; + uint8_t *extradata = par->extradata; + int extradata_size = par->extradata_size; if (!extradata_size) return; if (extradata[0] != 1) { @@ -515,10 +515,10 @@ static int write_manifest(AVFormatContext *s, int final) AVStream *st = s->streams[i]; OutputStream *os = &c->streams[i]; - if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO) + if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) continue; - avio_printf(out, "\t\t\tcodec_str, os->bandwidth_str, st->codec->width, st->codec->height); + avio_printf(out, "\t\t\tcodec_str, os->bandwidth_str, st->codecpar->width, st->codecpar->height); if (st->avg_frame_rate.num) avio_printf(out, " frameRate=\"%d/%d\"", st->avg_frame_rate.num, st->avg_frame_rate.den); avio_printf(out, ">\n"); @@ -534,11 +534,11 @@ static int write_manifest(AVFormatContext *s, int final) AVStream *st = s->streams[i]; OutputStream *os = &c->streams[i]; - if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO) + if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) continue; - avio_printf(out, "\t\t\t\n", i, os->codec_str, os->bandwidth_str, st->codec->sample_rate); - avio_printf(out, "\t\t\t\t\n", st->codec->channels); + avio_printf(out, "\t\t\t\n", i, os->codec_str, os->bandwidth_str, st->codecpar->sample_rate); + avio_printf(out, "\t\t\t\t\n", st->codecpar->channels); output_segment_list(&c->streams[i], out, c); avio_printf(out, "\t\t\t\n"); } @@ -598,9 +598,7 @@ static int dash_write_header(AVFormatContext *s) AVDictionary *opts = NULL; char filename[1024]; - os->bit_rate = s->streams[i]->codec->bit_rate ? - s->streams[i]->codec->bit_rate : - s->streams[i]->codec->rc_max_rate; + os->bit_rate = s->streams[i]->codecpar->bit_rate; if (os->bit_rate) { snprintf(os->bandwidth_str, sizeof(os->bandwidth_str), " bandwidth=\"%d\"", os->bit_rate); @@ -630,7 +628,7 @@ static int dash_write_header(AVFormatContext *s) ret = AVERROR(ENOMEM); goto fail; } - avcodec_copy_context(st->codec, s->streams[i]->codec); + avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar); st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio; st->time_base = s->streams[i]->time_base; ctx->avoid_negative_ts = s->avoid_negative_ts; @@ -670,7 +668,7 @@ static int dash_write_header(AVFormatContext *s) // already before being handed to this muxer, so we don't have mismatches // between the MPD and the actual segments. s->avoid_negative_ts = ctx->avoid_negative_ts; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { AVRational avg_frame_rate = s->streams[i]->avg_frame_rate; if (avg_frame_rate.num > 0) { if (av_cmp_q(avg_frame_rate, c->min_frame_rate) < 0) @@ -681,11 +679,11 @@ static int dash_write_header(AVFormatContext *s) c->ambiguous_frame_rate = 1; } c->has_video = 1; - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { c->has_audio = 1; } - set_codec_str(s, st->codec, os->codec_str, sizeof(os->codec_str)); + set_codec_str(s, st->codecpar, os->codec_str, sizeof(os->codec_str)); os->first_pts = AV_NOPTS_VALUE; os->max_pts = AV_NOPTS_VALUE; os->last_dts = AV_NOPTS_VALUE; @@ -774,24 +772,24 @@ static void find_index_range(AVFormatContext *s, const char *full_path, } static int update_stream_extradata(AVFormatContext *s, OutputStream *os, - AVCodecContext *codec) + AVCodecParameters *par) { uint8_t *extradata; - if (os->ctx->streams[0]->codec->extradata_size || !codec->extradata_size) + if (os->ctx->streams[0]->codecpar->extradata_size || !par->extradata_size) return 0; - extradata = av_malloc(codec->extradata_size); + extradata = av_malloc(par->extradata_size); if (!extradata) return AVERROR(ENOMEM); - memcpy(extradata, codec->extradata, codec->extradata_size); + memcpy(extradata, par->extradata, par->extradata_size); - os->ctx->streams[0]->codec->extradata = extradata; - os->ctx->streams[0]->codec->extradata_size = codec->extradata_size; + os->ctx->streams[0]->codecpar->extradata = extradata; + os->ctx->streams[0]->codecpar->extradata_size = par->extradata_size; - set_codec_str(s, codec, os->codec_str, sizeof(os->codec_str)); + set_codec_str(s, par, os->codec_str, sizeof(os->codec_str)); return 0; } @@ -817,7 +815,7 @@ static int dash_flush(AVFormatContext *s, int final, int stream) // Flush all audio streams as well, in sync with video keyframes, // but not the other video streams. if (stream >= 0 && i != stream) { - if (s->streams[i]->codec->codec_type != AVMEDIA_TYPE_AUDIO) + if (s->streams[i]->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) continue; // Make sure we don't flush audio streams multiple times, when // all video streams are flushed one at a time. @@ -896,7 +894,7 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) int64_t seg_end_duration = (os->segment_index) * (int64_t) c->min_seg_duration; int ret; - ret = update_stream_extradata(s, os, st->codec); + ret = update_stream_extradata(s, os, st->codecpar); if (ret < 0) return ret; @@ -921,7 +919,7 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt) if (os->first_pts == AV_NOPTS_VALUE) os->first_pts = pkt->pts; - if ((!c->has_video || st->codec->codec_type == AVMEDIA_TYPE_VIDEO) && + if ((!c->has_video || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && pkt->flags & AV_PKT_FLAG_KEY && os->packets_written && av_compare_ts(pkt->pts - os->first_pts, st->time_base, seg_end_duration, AV_TIME_BASE_Q) >= 0) { diff --git a/libavformat/dauddec.c b/libavformat/dauddec.c index f6e7491985..69196b0a1a 100644 --- a/libavformat/dauddec.c +++ b/libavformat/dauddec.c @@ -26,15 +26,15 @@ static int daud_header(AVFormatContext *s) { AVStream *st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_PCM_S24DAUD; - st->codec->codec_tag = MKTAG('d', 'a', 'u', 'd'); - st->codec->channels = 6; - st->codec->channel_layout = AV_CH_LAYOUT_5POINT1; - st->codec->sample_rate = 96000; - st->codec->bit_rate = 3 * 6 * 96000 * 8; - st->codec->block_align = 3 * 6; - st->codec->bits_per_coded_sample = 24; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S24DAUD; + st->codecpar->codec_tag = MKTAG('d', 'a', 'u', 'd'); + st->codecpar->channels = 6; + st->codecpar->channel_layout = AV_CH_LAYOUT_5POINT1; + st->codecpar->sample_rate = 96000; + st->codecpar->bit_rate = 3 * 6 * 96000 * 8; + st->codecpar->block_align = 3 * 6; + st->codecpar->bits_per_coded_sample = 24; return 0; } diff --git a/libavformat/daudenc.c b/libavformat/daudenc.c index 99b18d35aa..15a5afdfc9 100644 --- a/libavformat/daudenc.c +++ b/libavformat/daudenc.c @@ -23,8 +23,8 @@ static int daud_write_header(struct AVFormatContext *s) { - AVCodecContext *codec = s->streams[0]->codec; - if (codec->channels!=6 || codec->sample_rate!=96000) + AVCodecParameters *par = s->streams[0]->codecpar; + if (par->channels!=6 || par->sample_rate!=96000) return -1; return 0; } diff --git a/libavformat/dcstr.c b/libavformat/dcstr.c index 2ae61dec85..69fae417e8 100644 --- a/libavformat/dcstr.c +++ b/libavformat/dcstr.c @@ -39,35 +39,35 @@ static int dcstr_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->channels = avio_rl32(s->pb); - st->codec->sample_rate = avio_rl32(s->pb); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->channels = avio_rl32(s->pb); + st->codecpar->sample_rate = avio_rl32(s->pb); codec = avio_rl32(s->pb); align = avio_rl32(s->pb); avio_skip(s->pb, 4); st->duration = avio_rl32(s->pb); - st->codec->channels *= avio_rl32(s->pb); - if (!align || align > INT_MAX / st->codec->channels) + st->codecpar->channels *= avio_rl32(s->pb); + if (!align || align > INT_MAX / st->codecpar->channels) return AVERROR_INVALIDDATA; - st->codec->block_align = align * st->codec->channels; + st->codecpar->block_align = align * st->codecpar->channels; switch (codec) { - case 4: st->codec->codec_id = AV_CODEC_ID_ADPCM_AICA; break; - case 16: st->codec->codec_id = AV_CODEC_ID_PCM_S16LE_PLANAR; break; + case 4: st->codecpar->codec_id = AV_CODEC_ID_ADPCM_AICA; break; + case 16: st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE_PLANAR; break; default: avpriv_request_sample(s, "codec %X", codec); return AVERROR_PATCHWELCOME; } avio_skip(s->pb, 0x800 - avio_tell(s->pb)); - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } static int dcstr_read_packet(AVFormatContext *s, AVPacket *pkt) { - AVCodecContext *codec = s->streams[0]->codec; - return av_get_packet(s->pb, pkt, codec->block_align); + AVCodecParameters *par = s->streams[0]->codecpar; + return av_get_packet(s->pb, pkt, par->block_align); } AVInputFormat ff_dcstr_demuxer = { diff --git a/libavformat/dfa.c b/libavformat/dfa.c index b16672ccde..9858ee7941 100644 --- a/libavformat/dfa.c +++ b/libavformat/dfa.c @@ -56,10 +56,10 @@ static int dfa_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_DFA; - st->codec->width = avio_rl16(pb); - st->codec->height = avio_rl16(pb); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_DFA; + st->codecpar->width = avio_rl16(pb); + st->codecpar->height = avio_rl16(pb); mspf = avio_rl32(pb); if (!mspf) { av_log(s, AV_LOG_WARNING, "Zero FPS reported, defaulting to 10\n"); @@ -69,9 +69,9 @@ static int dfa_read_header(AVFormatContext *s) avio_skip(pb, 128 - 16); // padding st->duration = frames; - if (ff_alloc_extradata(st->codec, 2)) + if (ff_alloc_extradata(st->codecpar, 2)) return AVERROR(ENOMEM); - AV_WL16(st->codec->extradata, version); + AV_WL16(st->codecpar->extradata, version); if (version == 0x100) st->sample_aspect_ratio = (AVRational){2, 1}; diff --git a/libavformat/dsfdec.c b/libavformat/dsfdec.c index ae198b2e93..beb2fbf5aa 100644 --- a/libavformat/dsfdec.c +++ b/libavformat/dsfdec.c @@ -99,29 +99,29 @@ static int dsf_read_header(AVFormatContext *s) channel_type = avio_rl32(pb); if (channel_type < FF_ARRAY_ELEMS(dsf_channel_layout)) - st->codec->channel_layout = dsf_channel_layout[channel_type]; - if (!st->codec->channel_layout) + st->codecpar->channel_layout = dsf_channel_layout[channel_type]; + if (!st->codecpar->channel_layout) avpriv_request_sample(s, "channel type %i", channel_type); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->channels = avio_rl32(pb); - st->codec->sample_rate = avio_rl32(pb) / 8; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->channels = avio_rl32(pb); + st->codecpar->sample_rate = avio_rl32(pb) / 8; switch(avio_rl32(pb)) { - case 1: st->codec->codec_id = AV_CODEC_ID_DSD_LSBF_PLANAR; break; - case 8: st->codec->codec_id = AV_CODEC_ID_DSD_MSBF_PLANAR; break; + case 1: st->codecpar->codec_id = AV_CODEC_ID_DSD_LSBF_PLANAR; break; + case 8: st->codecpar->codec_id = AV_CODEC_ID_DSD_MSBF_PLANAR; break; default: avpriv_request_sample(s, "unknown most significant bit"); return AVERROR_INVALIDDATA; } avio_skip(pb, 8); - st->codec->block_align = avio_rl32(pb); - if (st->codec->block_align > INT_MAX / st->codec->channels) { + st->codecpar->block_align = avio_rl32(pb); + if (st->codecpar->block_align > INT_MAX / st->codecpar->channels) { avpriv_request_sample(s, "block_align overflow"); return AVERROR_INVALIDDATA; } - st->codec->block_align *= st->codec->channels; + st->codecpar->block_align *= st->codecpar->channels; avio_skip(pb, 4); /* data chunk */ @@ -145,7 +145,7 @@ static int dsf_read_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR_EOF; pkt->stream_index = 0; - return av_get_packet(pb, pkt, FFMIN(dsf->data_end - pos, st->codec->block_align)); + return av_get_packet(pb, pkt, FFMIN(dsf->data_end - pos, st->codecpar->block_align)); } AVInputFormat ff_dsf_demuxer = { diff --git a/libavformat/dsicin.c b/libavformat/dsicin.c index 6ba8c28c7e..bd4f3ad03a 100644 --- a/libavformat/dsicin.c +++ b/libavformat/dsicin.c @@ -116,11 +116,11 @@ static int cin_read_header(AVFormatContext *s) avpriv_set_pts_info(st, 32, 1, 12); cin->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_DSICINVIDEO; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = hdr->video_frame_width; - st->codec->height = hdr->video_frame_height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_DSICINVIDEO; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = hdr->video_frame_width; + st->codecpar->height = hdr->video_frame_height; /* initialize the audio decoder stream */ st = avformat_new_stream(s, NULL); @@ -129,14 +129,14 @@ static int cin_read_header(AVFormatContext *s) avpriv_set_pts_info(st, 32, 1, 22050); cin->audio_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_DSICINAUDIO; - st->codec->codec_tag = 0; /* no tag */ - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->sample_rate = 22050; - st->codec->bits_per_coded_sample = 8; - st->codec->bit_rate = st->codec->sample_rate * st->codec->bits_per_coded_sample * st->codec->channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_DSICINAUDIO; + st->codecpar->codec_tag = 0; /* no tag */ + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->sample_rate = 22050; + st->codecpar->bits_per_coded_sample = 8; + st->codecpar->bit_rate = st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample * st->codecpar->channels; return 0; } diff --git a/libavformat/dss.c b/libavformat/dss.c index bf7a1a4eaf..2f7f20d134 100644 --- a/libavformat/dss.c +++ b/libavformat/dss.c @@ -144,22 +144,22 @@ static int dss_read_header(AVFormatContext *s) ctx->audio_codec = avio_r8(pb); if (ctx->audio_codec == DSS_ACODEC_DSS_SP) { - st->codec->codec_id = AV_CODEC_ID_DSS_SP; - st->codec->sample_rate = 11025; + st->codecpar->codec_id = AV_CODEC_ID_DSS_SP; + st->codecpar->sample_rate = 11025; } else if (ctx->audio_codec == DSS_ACODEC_G723_1) { - st->codec->codec_id = AV_CODEC_ID_G723_1; - st->codec->sample_rate = 8000; + st->codecpar->codec_id = AV_CODEC_ID_G723_1; + st->codecpar->sample_rate = 8000; } else { avpriv_request_sample(s, "Support for codec %x in DSS", ctx->audio_codec); return AVERROR_PATCHWELCOME; } - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->channels = 1; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); st->start_time = 0; /* Jump over header */ @@ -235,7 +235,7 @@ static int dss_sp_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->duration = 264; pkt->pos = pos; pkt->stream_index = 0; - s->bit_rate = 8LL * ctx->packet_size * st->codec->sample_rate * 512 / (506 * pkt->duration); + s->bit_rate = 8LL * ctx->packet_size * st->codecpar->sample_rate * 512 / (506 * pkt->duration); if (ctx->counter < 0) { int size2 = ctx->counter + read_size; @@ -299,7 +299,7 @@ static int dss_723_1_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->data[0] = byte; offset = 1; pkt->duration = 240; - s->bit_rate = 8LL * size * st->codec->sample_rate * 512 / (506 * pkt->duration); + s->bit_rate = 8LL * size * st->codecpar->sample_rate * 512 / (506 * pkt->duration); pkt->stream_index = 0; diff --git a/libavformat/dtshddec.c b/libavformat/dtshddec.c index 0fd0304703..f3af096f3a 100644 --- a/libavformat/dtshddec.c +++ b/libavformat/dtshddec.c @@ -60,9 +60,9 @@ static int dtshd_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_DTS; - st->need_parsing = AVSTREAM_PARSE_FULL_RAW; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_DTS; + st->need_parsing = AVSTREAM_PARSE_FULL_RAW; while (!avio_feof(pb)) { chunk_type = avio_rb64(pb); diff --git a/libavformat/dump.c b/libavformat/dump.c index 86bb82da13..3d117f6fdf 100644 --- a/libavformat/dump.c +++ b/libavformat/dump.c @@ -440,14 +440,24 @@ static void dump_stream_format(AVFormatContext *ic, int i, AVStream *st = ic->streams[i]; AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0); char *separator = ic->dump_separator; - char **codec_separator = av_opt_ptr(st->codec->av_class, st->codec, "dump_separator"); - int use_format_separator = !*codec_separator; - - if (use_format_separator) - *codec_separator = av_strdup(separator); - avcodec_string(buf, sizeof(buf), st->codec, is_output); - if (use_format_separator) - av_freep(codec_separator); + AVCodecContext *avctx; + int ret; + + avctx = avcodec_alloc_context3(NULL); + if (!avctx) + return; + + ret = avcodec_parameters_to_context(avctx, st->codecpar); + if (ret < 0) { + avcodec_free_context(&avctx); + return; + } + + if (separator) + av_opt_set(avctx, "dump_separator", separator, 0); + avcodec_string(buf, sizeof(buf), avctx, is_output); + avcodec_free_context(&avctx); + av_log(NULL, AV_LOG_INFO, " Stream #%d:%d", index, i); /* the pid is an important information, so we display it */ @@ -460,35 +470,32 @@ static void dump_stream_format(AVFormatContext *ic, int i, st->time_base.num, st->time_base.den); av_log(NULL, AV_LOG_INFO, ": %s", buf); - if (st->sample_aspect_ratio.num && // default - av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)) { + if (st->sample_aspect_ratio.num && + av_cmp_q(st->sample_aspect_ratio, st->codecpar->sample_aspect_ratio)) { AVRational display_aspect_ratio; av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, - st->codec->width * (int64_t)st->sample_aspect_ratio.num, - st->codec->height * (int64_t)st->sample_aspect_ratio.den, + st->codecpar->width * (int64_t)st->sample_aspect_ratio.num, + st->codecpar->height * (int64_t)st->sample_aspect_ratio.den, 1024 * 1024); av_log(NULL, AV_LOG_INFO, ", SAR %d:%d DAR %d:%d", st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, display_aspect_ratio.num, display_aspect_ratio.den); } - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { int fps = st->avg_frame_rate.den && st->avg_frame_rate.num; int tbr = st->r_frame_rate.den && st->r_frame_rate.num; int tbn = st->time_base.den && st->time_base.num; - int tbc = st->codec->time_base.den && st->codec->time_base.num; - if (fps || tbr || tbn || tbc) + if (fps || tbr || tbn) av_log(NULL, AV_LOG_INFO, "%s", separator); if (fps) - print_fps(av_q2d(st->avg_frame_rate), tbr || tbn || tbc ? "fps, " : "fps"); + print_fps(av_q2d(st->avg_frame_rate), tbr || tbn ? "fps, " : "fps"); if (tbr) - print_fps(av_q2d(st->r_frame_rate), tbn || tbc ? "tbr, " : "tbr"); + print_fps(av_q2d(st->r_frame_rate), tbn ? "tbr, " : "tbr"); if (tbn) - print_fps(1 / av_q2d(st->time_base), tbc ? "tbn, " : "tbn"); - if (tbc) - print_fps(1 / av_q2d(st->codec->time_base), "tbc"); + print_fps(1 / av_q2d(st->time_base), "tbn"); } if (st->disposition & AV_DISPOSITION_DEFAULT) diff --git a/libavformat/dv.c b/libavformat/dv.c index b41d123996..c689d9b100 100644 --- a/libavformat/dv.c +++ b/libavformat/dv.c @@ -259,8 +259,8 @@ static int dv_extract_audio_info(DVDemuxContext *c, const uint8_t *frame) if (!c->ast[i]) break; avpriv_set_pts_info(c->ast[i], 64, 1, 30000); - c->ast[i]->codec->codec_type = AVMEDIA_TYPE_AUDIO; - c->ast[i]->codec->codec_id = AV_CODEC_ID_PCM_S16LE; + c->ast[i]->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + c->ast[i]->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; av_init_packet(&c->audio_pkt[i]); c->audio_pkt[i].size = 0; @@ -268,10 +268,10 @@ static int dv_extract_audio_info(DVDemuxContext *c, const uint8_t *frame) c->audio_pkt[i].stream_index = c->ast[i]->index; c->audio_pkt[i].flags |= AV_PKT_FLAG_KEY; } - c->ast[i]->codec->sample_rate = dv_audio_frequency[freq]; - c->ast[i]->codec->channels = 2; - c->ast[i]->codec->channel_layout = AV_CH_LAYOUT_STEREO; - c->ast[i]->codec->bit_rate = 2 * dv_audio_frequency[freq] * 16; + c->ast[i]->codecpar->sample_rate = dv_audio_frequency[freq]; + c->ast[i]->codecpar->channels = 2; + c->ast[i]->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + c->ast[i]->codecpar->bit_rate = 2 * dv_audio_frequency[freq] * 16; c->ast[i]->start_time = 0; } c->ach = i; @@ -282,10 +282,10 @@ static int dv_extract_audio_info(DVDemuxContext *c, const uint8_t *frame) static int dv_extract_video_info(DVDemuxContext *c, const uint8_t *frame) { const uint8_t *vsc_pack; - AVCodecContext *avctx; + AVCodecParameters *par; int apt, is16_9; - avctx = c->vst->codec; + par = c->vst->codecpar; avpriv_set_pts_info(c->vst, 64, c->sys->time_base.num, c->sys->time_base.den); @@ -297,7 +297,7 @@ static int dv_extract_video_info(DVDemuxContext *c, const uint8_t *frame) is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 || (!apt && (vsc_pack[2] & 0x07) == 0x07))); c->vst->sample_aspect_ratio = c->sys->sar[is16_9]; - avctx->bit_rate = av_rescale_q(c->sys->frame_size, + par->bit_rate = av_rescale_q(c->sys->frame_size, (AVRational) { 8, 1 }, c->sys->time_base); return c->sys->frame_size; @@ -336,9 +336,9 @@ DVDemuxContext *avpriv_dv_init_demux(AVFormatContext *s) } c->fctx = s; - c->vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - c->vst->codec->codec_id = AV_CODEC_ID_DVVIDEO; - c->vst->codec->bit_rate = 25000000; + c->vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + c->vst->codecpar->codec_id = AV_CODEC_ID_DVVIDEO; + c->vst->codecpar->bit_rate = 25000000; c->vst->start_time = 0; return c; @@ -380,7 +380,7 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, c->audio_pkt[i].pos = pos; c->audio_pkt[i].size = size; c->audio_pkt[i].pts = c->abytes * 30000 * 8 / - c->ast[i]->codec->bit_rate; + c->ast[i]->codecpar->bit_rate; ppcm[i] = c->audio_buf[i]; } if (c->ach) @@ -439,7 +439,7 @@ void ff_dv_offset_reset(DVDemuxContext *c, int64_t frame_offset) if (c->ach) { if (c->sys) { c->abytes = av_rescale_q(c->frames, c->sys->time_base, - (AVRational) { 8, c->ast[0]->codec->bit_rate }); + (AVRational) { 8, c->ast[0]->codecpar->bit_rate }); } else av_log(c->fctx, AV_LOG_ERROR, "cannot adjust audio bytes\n"); } diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c index 6cefe8be40..7ff2b729a0 100644 --- a/libavformat/dvenc.c +++ b/libavformat/dvenc.c @@ -105,13 +105,13 @@ static int dv_write_pack(enum dv_pack_type pack_id, DVMuxContext *c, uint8_t* bu case dv_audio_source: /* AAUX source pack */ va_start(ap, buf); channel = va_arg(ap, int); - if (c->ast[channel]->codec->sample_rate == 44100) { + if (c->ast[channel]->codecpar->sample_rate == 44100) { audio_type = 1; - } else if (c->ast[channel]->codec->sample_rate == 32000) + } else if (c->ast[channel]->codecpar->sample_rate == 32000) audio_type = 2; buf[1] = (1 << 7) | /* locked mode -- SMPTE only supports locked mode */ (1 << 6) | /* reserved -- always 1 */ - (dv_audio_frame_size(c->sys, c->frames, c->ast[channel]->codec->sample_rate) - + (dv_audio_frame_size(c->sys, c->frames, c->ast[channel]->codecpar->sample_rate) - c->sys->audio_min_samples[audio_type]); /* # of samples */ buf[2] = (0 << 7) | /* multi-stereo */ @@ -186,7 +186,7 @@ static int dv_write_pack(enum dv_pack_type pack_id, DVMuxContext *c, uint8_t* bu static void dv_inject_audio(DVMuxContext *c, int channel, uint8_t* frame_ptr) { int i, j, d, of, size; - size = 4 * dv_audio_frame_size(c->sys, c->frames, c->ast[channel]->codec->sample_rate); + size = 4 * dv_audio_frame_size(c->sys, c->frames, c->ast[channel]->codecpar->sample_rate); frame_ptr += channel * c->sys->difseg_size * 150 * 80; for (i = 0; i < c->sys->difseg_size; i++) { frame_ptr += 6 * 80; /* skip DIF segment header */ @@ -238,20 +238,21 @@ static void dv_inject_metadata(DVMuxContext *c, uint8_t* frame) * The following 3 functions constitute our interface to the world */ -static int dv_assemble_frame(DVMuxContext *c, AVStream* st, +static int dv_assemble_frame(AVFormatContext *s, + DVMuxContext *c, AVStream* st, uint8_t* data, int data_size, uint8_t** frame) { int i, reqasize; *frame = &c->frame_buf[0]; - switch (st->codec->codec_type) { + switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_VIDEO: /* FIXME: we have to have more sensible approach than this one */ if (c->has_video) - av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames); + av_log(s, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames); if (data_size != c->sys->frame_size) { - av_log(st->codec, AV_LOG_ERROR, "Unexpected frame size, %d != %d\n", + av_log(s, AV_LOG_ERROR, "Unexpected frame size, %d != %d\n", data_size, c->sys->frame_size); return AVERROR(ENOSYS); } @@ -264,10 +265,10 @@ static int dv_assemble_frame(DVMuxContext *c, AVStream* st, /* FIXME: we have to have more sensible approach than this one */ if (av_fifo_size(c->audio_data[i]) + data_size >= 100*MAX_AUDIO_FRAME_SIZE) - av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames); + av_log(s, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames); av_fifo_generic_write(c->audio_data[i], data, data_size, NULL); - reqasize = 4 * dv_audio_frame_size(c->sys, c->frames, st->codec->sample_rate); + reqasize = 4 * dv_audio_frame_size(c->sys, c->frames, st->codecpar->sample_rate); /* Let us see if we've got enough audio for one DV frame. */ c->has_audio |= ((reqasize <= av_fifo_size(c->audio_data[i])) << i); @@ -283,7 +284,7 @@ static int dv_assemble_frame(DVMuxContext *c, AVStream* st, c->has_audio = 0; for (i=0; i < c->n_ast; i++) { dv_inject_audio(c, i, *frame); - reqasize = 4 * dv_audio_frame_size(c->sys, c->frames, c->ast[i]->codec->sample_rate); + reqasize = 4 * dv_audio_frame_size(c->sys, c->frames, c->ast[i]->codecpar->sample_rate); av_fifo_drain(c->audio_data[i], reqasize); c->has_audio |= ((reqasize <= av_fifo_size(c->audio_data[i])) << i); } @@ -313,7 +314,7 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s) /* We have to sort out where audio and where video stream is */ for (i=0; inb_streams; i++) { - switch (s->streams[i]->codec->codec_type) { + switch (s->streams[i]->codecpar->codec_type) { case AVMEDIA_TYPE_VIDEO: if (vst) return NULL; vst = s->streams[i]; @@ -328,28 +329,28 @@ static DVMuxContext* dv_init_mux(AVFormatContext* s) } /* Some checks -- DV format is very picky about its incoming streams */ - if (!vst || vst->codec->codec_id != AV_CODEC_ID_DVVIDEO) + if (!vst || vst->codecpar->codec_id != AV_CODEC_ID_DVVIDEO) goto bail_out; for (i=0; in_ast; i++) { if (c->ast[i]) { - if(c->ast[i]->codec->codec_id != AV_CODEC_ID_PCM_S16LE || - c->ast[i]->codec->channels != 2) + if(c->ast[i]->codecpar->codec_id != AV_CODEC_ID_PCM_S16LE || + c->ast[i]->codecpar->channels != 2) goto bail_out; - if (c->ast[i]->codec->sample_rate != 48000 && - c->ast[i]->codec->sample_rate != 44100 && - c->ast[i]->codec->sample_rate != 32000 ) + if (c->ast[i]->codecpar->sample_rate != 48000 && + c->ast[i]->codecpar->sample_rate != 44100 && + c->ast[i]->codecpar->sample_rate != 32000 ) goto bail_out; } } - c->sys = av_dv_codec_profile2(vst->codec->width, vst->codec->height, - vst->codec->pix_fmt, vst->codec->time_base); + c->sys = av_dv_codec_profile2(vst->codecpar->width, vst->codecpar->height, + vst->codecpar->format, vst->time_base); if (!c->sys) goto bail_out; if ((c->sys->time_base.den != 25 && c->sys->time_base.den != 50) || c->sys->time_base.num != 1) { - if (c->ast[0] && c->ast[0]->codec->sample_rate != 48000) + if (c->ast[0] && c->ast[0]->codecpar->sample_rate != 48000) goto bail_out; - if (c->ast[1] && c->ast[1]->codec->sample_rate != 48000) + if (c->ast[1] && c->ast[1]->codecpar->sample_rate != 48000) goto bail_out; } @@ -420,7 +421,7 @@ static int dv_write_packet(struct AVFormatContext *s, AVPacket *pkt) uint8_t* frame; int fsize; - fsize = dv_assemble_frame(s->priv_data, s->streams[pkt->stream_index], + fsize = dv_assemble_frame(s, s->priv_data, s->streams[pkt->stream_index], pkt->data, pkt->size, &frame); if (fsize > 0) { avio_write(s->pb, frame, fsize); diff --git a/libavformat/dxa.c b/libavformat/dxa.c index 1a5822aab8..162838c135 100644 --- a/libavformat/dxa.c +++ b/libavformat/dxa.c @@ -106,11 +106,11 @@ static int dxa_read_header(AVFormatContext *s) ast = avformat_new_stream(s, NULL); if (!ast) return AVERROR(ENOMEM); - ret = ff_get_wav_header(s, pb, ast->codec, fsize, 0); + ret = ff_get_wav_header(s, pb, ast->codecpar, fsize, 0); if (ret < 0) return ret; - if (ast->codec->sample_rate > 0) - avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate); + if (ast->codecpar->sample_rate > 0) + avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate); // find 'data' chunk while(avio_tell(pb) < c->vidpos && !avio_feof(pb)){ tag = avio_rl32(pb); @@ -119,18 +119,18 @@ static int dxa_read_header(AVFormatContext *s) avio_skip(pb, fsize); } c->bpc = (fsize + c->frames - 1) / c->frames; - if(ast->codec->block_align) - c->bpc = ((c->bpc + ast->codec->block_align - 1) / ast->codec->block_align) * ast->codec->block_align; + if(ast->codecpar->block_align) + c->bpc = ((c->bpc + ast->codecpar->block_align - 1) / ast->codecpar->block_align) * ast->codecpar->block_align; c->bytes_left = fsize; c->wavpos = avio_tell(pb); avio_seek(pb, c->vidpos, SEEK_SET); } /* now we are ready: build format streams */ - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_DXA; - st->codec->width = w; - st->codec->height = h; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_DXA; + st->codecpar->width = w; + st->codecpar->height = h; av_reduce(&den, &num, den, num, (1UL<<31)-1); avpriv_set_pts_info(st, 33, num, den); /* flags & 0x80 means that image is interlaced, @@ -138,7 +138,7 @@ static int dxa_read_header(AVFormatContext *s) * either way set true height */ if(flags & 0xC0){ - st->codec->height >>= 1; + st->codecpar->height >>= 1; } c->readvid = !c->has_sound; c->vidpos = avio_tell(pb); diff --git a/libavformat/eacdata.c b/libavformat/eacdata.c index 165ff1af99..97eb66e36d 100644 --- a/libavformat/eacdata.c +++ b/libavformat/eacdata.c @@ -70,12 +70,12 @@ static int cdata_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->codec_id = AV_CODEC_ID_ADPCM_EA_XAS; - st->codec->channels = cdata->channels; - st->codec->channel_layout = channel_layout; - st->codec->sample_rate = sample_rate; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_EA_XAS; + st->codecpar->channels = cdata->channels; + st->codecpar->channel_layout = channel_layout; + st->codecpar->sample_rate = sample_rate; avpriv_set_pts_info(st, 64, 1, sample_rate); cdata->audio_pts = 0; diff --git a/libavformat/electronicarts.c b/libavformat/electronicarts.c index 8601782afa..b27da65801 100644 --- a/libavformat/electronicarts.c +++ b/libavformat/electronicarts.c @@ -499,14 +499,14 @@ static int init_video_stream(AVFormatContext *s, VideoProperties *video) if (!st) return AVERROR(ENOMEM); video->stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = video->codec; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = video->codec; // parsing is necessary to make FFmpeg generate correct timestamps - if (st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO) + if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) st->need_parsing = AVSTREAM_PARSE_HEADERS; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = video->width; - st->codec->height = video->height; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = video->width; + st->codecpar->height = video->height; st->duration = st->nb_frames = video->nb_frames; if (video->time_base.num) avpriv_set_pts_info(st, 64, video->time_base.num, video->time_base.den); @@ -551,17 +551,17 @@ static int ea_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 33, 1, ea->sample_rate); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = ea->audio_codec; - st->codec->codec_tag = 0; /* no tag */ - st->codec->channels = ea->num_channels; - st->codec->sample_rate = ea->sample_rate; - st->codec->bits_per_coded_sample = ea->bytes * 8; - st->codec->bit_rate = st->codec->channels * - st->codec->sample_rate * - st->codec->bits_per_coded_sample / 4; - st->codec->block_align = st->codec->channels * - st->codec->bits_per_coded_sample; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = ea->audio_codec; + st->codecpar->codec_tag = 0; /* no tag */ + st->codecpar->channels = ea->num_channels; + st->codecpar->sample_rate = ea->sample_rate; + st->codecpar->bits_per_coded_sample = ea->bytes * 8; + st->codecpar->bit_rate = st->codecpar->channels * + st->codecpar->sample_rate * + st->codecpar->bits_per_coded_sample / 4; + st->codecpar->block_align = st->codecpar->channels * + st->codecpar->bits_per_coded_sample; ea->audio_stream_index = st->index; st->start_time = 0; } diff --git a/libavformat/epafdec.c b/libavformat/epafdec.c index c737892325..29190fff72 100644 --- a/libavformat/epafdec.c +++ b/libavformat/epafdec.c @@ -66,15 +66,15 @@ static int epaf_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->channels = channels; - st->codec->sample_rate = sample_rate; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->channels = channels; + st->codecpar->sample_rate = sample_rate; switch (codec) { case 0: - st->codec->codec_id = le ? AV_CODEC_ID_PCM_S16LE : AV_CODEC_ID_PCM_S16BE; + st->codecpar->codec_id = le ? AV_CODEC_ID_PCM_S16LE : AV_CODEC_ID_PCM_S16BE; break; case 2: - st->codec->codec_id = AV_CODEC_ID_PCM_S8; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S8; break; case 1: avpriv_request_sample(s, "24-bit Paris PCM format"); @@ -82,10 +82,10 @@ static int epaf_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; } - st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id); - st->codec->block_align = st->codec->bits_per_coded_sample * st->codec->channels / 8; + st->codecpar->bits_per_coded_sample = av_get_bits_per_sample(st->codecpar->codec_id); + st->codecpar->block_align = st->codecpar->bits_per_coded_sample * st->codecpar->channels / 8; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); if (avio_skip(s->pb, 2024) < 0) return AVERROR_INVALIDDATA; diff --git a/libavformat/ffmdec.c b/libavformat/ffmdec.c index 257319bd06..53a9f1fca9 100644 --- a/libavformat/ffmdec.c +++ b/libavformat/ffmdec.c @@ -283,7 +283,7 @@ static int ffm2_read_header(AVFormatContext *s) AVIOContext *pb = s->pb; AVCodecContext *codec; const AVCodecDescriptor *codec_desc; - int ret; + int ret, i; int f_main = 0, f_cprv = -1, f_stvi = -1, f_stau = -1; AVCodec *enc; char *buffer; @@ -356,8 +356,12 @@ static int ffm2_read_header(AVFormatContext *s) codec->flags2 = avio_rb32(pb); codec->debug = avio_rb32(pb); if (codec->flags & AV_CODEC_FLAG_GLOBAL_HEADER) { - if (ff_get_extradata(codec, pb, avio_rb32(pb)) < 0) + int size = avio_rb32(pb); + codec->extradata = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!codec->extradata) return AVERROR(ENOMEM); + codec->extradata_size = size; + avio_read(pb, codec->extradata, size); } break; case MKBETAG('S', 'T', 'V', 'I'): @@ -476,6 +480,9 @@ static int ffm2_read_header(AVFormatContext *s) avio_seek(pb, next, SEEK_SET); } + for (i = 0; i < s->nb_streams; i++) + avcodec_parameters_from_context(s->streams[i]->codecpar, s->streams[i]->codec); + /* get until end of block reached */ while ((avio_tell(pb) % ffm->packet_size) != 0 && !pb->eof_reached) avio_r8(pb); @@ -617,9 +624,15 @@ static int ffm_read_header(AVFormatContext *s) goto fail; } if (codec->flags & AV_CODEC_FLAG_GLOBAL_HEADER) { - if (ff_get_extradata(codec, pb, avio_rb32(pb)) < 0) + int size = avio_rb32(pb); + codec->extradata = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!codec->extradata) return AVERROR(ENOMEM); + codec->extradata_size = size; + avio_read(pb, codec->extradata, size); } + + avcodec_parameters_from_context(st->codecpar, codec); } /* get until end of block reached */ diff --git a/libavformat/ffmetadec.c b/libavformat/ffmetadec.c index e226406932..3290b3b7bc 100644 --- a/libavformat/ffmetadec.c +++ b/libavformat/ffmetadec.c @@ -139,8 +139,8 @@ static int read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_DATA; - st->codec->codec_id = AV_CODEC_ID_FFMETADATA; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_id = AV_CODEC_ID_FFMETADATA; m = &st->metadata; } else if (!memcmp(line, ID_CHAPTER, strlen(ID_CHAPTER))) { diff --git a/libavformat/filmstripdec.c b/libavformat/filmstripdec.c index cdbb93b11a..414e276bfe 100644 --- a/libavformat/filmstripdec.c +++ b/libavformat/filmstripdec.c @@ -60,15 +60,15 @@ static int read_header(AVFormatContext *s) } avio_skip(pb, 2); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; - st->codec->pix_fmt = AV_PIX_FMT_RGBA; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = avio_rb16(pb); - st->codec->height = avio_rb16(pb); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->format = AV_PIX_FMT_RGBA; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = avio_rb16(pb); + st->codecpar->height = avio_rb16(pb); film->leading = avio_rb16(pb); - if (st->codec->width * 4LL * st->codec->height >= INT_MAX) { + if (st->codecpar->width * 4LL * st->codecpar->height >= INT_MAX) { av_log(s, AV_LOG_ERROR, "dimensions too large\n"); return AVERROR_PATCHWELCOME; } @@ -88,9 +88,9 @@ static int read_packet(AVFormatContext *s, if (avio_feof(s->pb)) return AVERROR(EIO); - pkt->dts = avio_tell(s->pb) / (st->codec->width * (int64_t)(st->codec->height + film->leading) * 4); - pkt->size = av_get_packet(s->pb, pkt, st->codec->width * st->codec->height * 4); - avio_skip(s->pb, st->codec->width * (int64_t) film->leading * 4); + pkt->dts = avio_tell(s->pb) / (st->codecpar->width * (int64_t)(st->codecpar->height + film->leading) * 4); + pkt->size = av_get_packet(s->pb, pkt, st->codecpar->width * st->codecpar->height * 4); + avio_skip(s->pb, st->codecpar->width * (int64_t) film->leading * 4); if (pkt->size < 0) return pkt->size; pkt->flags |= AV_PKT_FLAG_KEY; @@ -100,7 +100,7 @@ static int read_packet(AVFormatContext *s, static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { AVStream *st = s->streams[stream_index]; - if (avio_seek(s->pb, FFMAX(timestamp, 0) * st->codec->width * st->codec->height * 4, SEEK_SET) < 0) + if (avio_seek(s->pb, FFMAX(timestamp, 0) * st->codecpar->width * st->codecpar->height * 4, SEEK_SET) < 0) return -1; return 0; } diff --git a/libavformat/filmstripenc.c b/libavformat/filmstripenc.c index 9e2c71082f..8ead696360 100644 --- a/libavformat/filmstripenc.c +++ b/libavformat/filmstripenc.c @@ -35,7 +35,7 @@ typedef struct FilmstripMuxContext { static int write_header(AVFormatContext *s) { - if (s->streams[0]->codec->pix_fmt != AV_PIX_FMT_RGBA) { + if (s->streams[0]->codecpar->format != AV_PIX_FMT_RGBA) { av_log(s, AV_LOG_ERROR, "only AV_PIX_FMT_RGBA is supported\n"); return AVERROR_INVALIDDATA; } @@ -61,8 +61,8 @@ static int write_trailer(AVFormatContext *s) avio_wb32(pb, film->nb_frames); avio_wb16(pb, 0); // packing method avio_wb16(pb, 0); // reserved - avio_wb16(pb, st->codec->width); - avio_wb16(pb, st->codec->height); + avio_wb16(pb, st->codecpar->width); + avio_wb16(pb, st->codecpar->height); avio_wb16(pb, 0); // leading // TODO: should be avg_frame_rate avio_wb16(pb, st->time_base.den / st->time_base.num); diff --git a/libavformat/flac_picture.c b/libavformat/flac_picture.c index 7bd98258e4..a3217f02a6 100644 --- a/libavformat/flac_picture.c +++ b/libavformat/flac_picture.c @@ -132,10 +132,10 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size) st->attached_pic.flags |= AV_PKT_FLAG_KEY; st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = id; - st->codec->width = width; - st->codec->height = height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = id; + st->codecpar->width = width; + st->codecpar->height = height; av_dict_set(&st->metadata, "comment", ff_id3v2_picture_types[type], 0); if (desc) av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL); diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c index eb92216c45..19f10629c5 100644 --- a/libavformat/flacdec.c +++ b/libavformat/flacdec.c @@ -52,8 +52,8 @@ static int flac_read_header(AVFormatContext *s) AVStream *st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_FLAC; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_FLAC; st->need_parsing = AVSTREAM_PARSE_FULL_RAW; /* the parameters will be extracted from the compressed bitstream */ @@ -102,14 +102,14 @@ static int flac_read_header(AVFormatContext *s) RETURN_ERROR(AVERROR_INVALIDDATA); } found_streaminfo = 1; - st->codec->extradata = buffer; - st->codec->extradata_size = metadata_size; + st->codecpar->extradata = buffer; + st->codecpar->extradata_size = metadata_size; buffer = NULL; /* get sample rate and sample count from STREAMINFO header; * other parameters will be extracted by the parser */ - samplerate = AV_RB24(st->codec->extradata + 10) >> 4; - samples = (AV_RB64(st->codec->extradata + 13) >> 24) & ((1ULL << 36) - 1); + samplerate = AV_RB24(st->codecpar->extradata + 10) >> 4; + samples = (AV_RB64(st->codecpar->extradata + 13) >> 24) & ((1ULL << 36) - 1); /* set time base and duration */ if (samplerate > 0) { @@ -189,7 +189,7 @@ static int flac_read_header(AVFormatContext *s) av_log(s, AV_LOG_WARNING, "Invalid value of WAVEFORMATEXTENSIBLE_CHANNEL_MASK\n"); } else { - st->codec->channel_layout = mask; + st->codecpar->channel_layout = mask; av_dict_set(&s->metadata, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", NULL, 0); } } @@ -248,7 +248,7 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde return AV_NOPTS_VALUE; av_init_packet(&pkt); - parser = av_parser_init(st->codec->codec_id); + parser = av_parser_init(st->codecpar->codec_id); if (!parser){ return AV_NOPTS_VALUE; } @@ -263,7 +263,7 @@ static av_unused int64_t flac_read_timestamp(AVFormatContext *s, int stream_inde break; } av_init_packet(&out_pkt); - av_parser_parse2(parser, st->codec, + av_parser_parse2(parser, st->internal->avctx, &out_pkt.data, &out_pkt.size, pkt.data, pkt.size, pkt.pts, pkt.dts, *ppos); diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c index 321af50e6a..89b21e9e23 100644 --- a/libavformat/flacenc.c +++ b/libavformat/flacenc.c @@ -78,7 +78,7 @@ static int flac_write_header(struct AVFormatContext *s) { int ret; int padding = s->metadata_header_padding; - AVCodecContext *codec = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; FlacMuxerContext *c = s->priv_data; if (!c->write_header) @@ -88,7 +88,7 @@ static int flac_write_header(struct AVFormatContext *s) av_log(s, AV_LOG_ERROR, "only one stream is supported\n"); return AVERROR(EINVAL); } - if (codec->codec_id != AV_CODEC_ID_FLAC) { + if (par->codec_id != AV_CODEC_ID_FLAC) { av_log(s, AV_LOG_ERROR, "unsupported codec\n"); return AVERROR(EINVAL); } @@ -99,15 +99,15 @@ static int flac_write_header(struct AVFormatContext *s) * size of a metadata block so we must clip this value to 2^24-1. */ padding = av_clip_uintp2(padding, 24); - ret = ff_flac_write_header(s->pb, codec->extradata, - codec->extradata_size, 0); + ret = ff_flac_write_header(s->pb, par->extradata, + par->extradata_size, 0); if (ret) return ret; /* add the channel layout tag */ - if (codec->channel_layout && - !(codec->channel_layout & ~0x3ffffULL) && - !ff_flac_is_native_layout(codec->channel_layout)) { + if (par->channel_layout && + !(par->channel_layout & ~0x3ffffULL) && + !ff_flac_is_native_layout(par->channel_layout)) { AVDictionaryEntry *chmask = av_dict_get(s->metadata, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", NULL, 0); @@ -116,7 +116,7 @@ static int flac_write_header(struct AVFormatContext *s) "already present, this muxer will not overwrite it.\n"); } else { uint8_t buf[32]; - snprintf(buf, sizeof(buf), "0x%"PRIx64, codec->channel_layout); + snprintf(buf, sizeof(buf), "0x%"PRIx64, par->channel_layout); av_dict_set(&s->metadata, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0); } } @@ -142,7 +142,7 @@ static int flac_write_trailer(struct AVFormatContext *s) int64_t file_size; FlacMuxerContext *c = s->priv_data; uint8_t *streaminfo = c->streaminfo ? c->streaminfo : - s->streams[0]->codec->extradata; + s->streams[0]->codecpar->extradata; if (!c->write_header || !streaminfo) return 0; diff --git a/libavformat/flic.c b/libavformat/flic.c index 30de35158f..343b88852d 100644 --- a/libavformat/flic.c +++ b/libavformat/flic.c @@ -109,25 +109,25 @@ static int flic_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); flic->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_FLIC; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = AV_RL16(&header[0x08]); - st->codec->height = AV_RL16(&header[0x0A]); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_FLIC; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = AV_RL16(&header[0x08]); + st->codecpar->height = AV_RL16(&header[0x0A]); - if (!st->codec->width || !st->codec->height) { + if (!st->codecpar->width || !st->codecpar->height) { /* Ugly hack needed for the following sample: */ /* http://samples.mplayerhq.hu/fli-flc/fli-bugs/specular.flc */ av_log(s, AV_LOG_WARNING, "File with no specified width/height. Trying 640x480.\n"); - st->codec->width = 640; - st->codec->height = 480; + st->codecpar->width = 640; + st->codecpar->height = 480; } /* send over the whole 128-byte FLIC header */ - if (ff_alloc_extradata(st->codec, FLIC_HEADER_SIZE)) + if (ff_alloc_extradata(st->codecpar, FLIC_HEADER_SIZE)) return AVERROR(ENOMEM); - memcpy(st->codec->extradata, header, FLIC_HEADER_SIZE); + memcpy(st->codecpar->extradata, header, FLIC_HEADER_SIZE); /* peek at the preamble to detect TFTD videos - they seem to always start with an audio chunk */ if (avio_read(pb, preamble, FLIC_PREAMBLE_SIZE) != FLIC_PREAMBLE_SIZE) { @@ -152,21 +152,21 @@ static int flic_read_header(AVFormatContext *s) flic->audio_stream_index = ast->index; /* all audio frames are the same size, so use the size of the first chunk for block_align */ - ast->codec->block_align = AV_RL32(&preamble[0]); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = AV_CODEC_ID_PCM_U8; - ast->codec->codec_tag = 0; - ast->codec->sample_rate = FLIC_TFTD_SAMPLE_RATE; - ast->codec->channels = 1; - ast->codec->bit_rate = st->codec->sample_rate * 8; - ast->codec->bits_per_coded_sample = 8; - ast->codec->channel_layout = AV_CH_LAYOUT_MONO; - ast->codec->extradata_size = 0; + ast->codecpar->block_align = AV_RL32(&preamble[0]); + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = AV_CODEC_ID_PCM_U8; + ast->codecpar->codec_tag = 0; + ast->codecpar->sample_rate = FLIC_TFTD_SAMPLE_RATE; + ast->codecpar->channels = 1; + ast->codecpar->bit_rate = st->codecpar->sample_rate * 8; + ast->codecpar->bits_per_coded_sample = 8; + ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + ast->codecpar->extradata_size = 0; /* Since the header information is incorrect we have to figure out the * framerate using block_align and the fact that the audio is 22050 Hz. * We usually have two cases: 2205 -> 10 fps and 1470 -> 15 fps */ - avpriv_set_pts_info(st, 64, ast->codec->block_align, FLIC_TFTD_SAMPLE_RATE); + avpriv_set_pts_info(st, 64, ast->codecpar->block_align, FLIC_TFTD_SAMPLE_RATE); avpriv_set_pts_info(ast, 64, 1, FLIC_TFTD_SAMPLE_RATE); } else if (AV_RL16(&header[0x10]) == FLIC_CHUNK_MAGIC_1) { avpriv_set_pts_info(st, 64, FLIC_MC_SPEED, 70); @@ -175,10 +175,10 @@ static int flic_read_header(AVFormatContext *s) avio_seek(pb, 12, SEEK_SET); /* send over abbreviated FLIC header chunk */ - av_freep(&st->codec->extradata); - if (ff_alloc_extradata(st->codec, 12)) + av_freep(&st->codecpar->extradata); + if (ff_alloc_extradata(st->codecpar, 12)) return AVERROR(ENOMEM); - memcpy(st->codec->extradata, header, 12); + memcpy(st->codecpar->extradata, header, 12); } else if (magic_number == FLIC_FILE_MAGIC_1) { avpriv_set_pts_info(st, 64, speed, 70); diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 5090ac2157..04f20db1a5 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -97,26 +97,26 @@ static AVStream *create_stream(AVFormatContext *s, int codec_type) AVStream *st = avformat_new_stream(s, NULL); if (!st) return NULL; - st->codec->codec_type = codec_type; + st->codecpar->codec_type = codec_type; if (s->nb_streams>=3 ||( s->nb_streams==2 - && s->streams[0]->codec->codec_type != AVMEDIA_TYPE_SUBTITLE - && s->streams[1]->codec->codec_type != AVMEDIA_TYPE_SUBTITLE)) + && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE + && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE)) s->ctx_flags &= ~AVFMTCTX_NOHEADER; avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */ return st; } -static int flv_same_audio_codec(AVCodecContext *acodec, int flags) +static int flv_same_audio_codec(AVCodecParameters *apar, int flags) { int bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8; int flv_codecid = flags & FLV_AUDIO_CODECID_MASK; int codec_id; - if (!acodec->codec_id && !acodec->codec_tag) + if (!apar->codec_id && !apar->codec_tag) return 1; - if (acodec->bits_per_coded_sample != bits_per_coded_sample) + if (apar->bits_per_coded_sample != bits_per_coded_sample) return 0; switch (flv_codecid) { @@ -129,42 +129,42 @@ static int flv_same_audio_codec(AVCodecContext *acodec, int flags) #else : AV_CODEC_ID_PCM_S16LE; #endif - return codec_id == acodec->codec_id; + return codec_id == apar->codec_id; case FLV_CODECID_PCM_LE: codec_id = bits_per_coded_sample == 8 ? AV_CODEC_ID_PCM_U8 : AV_CODEC_ID_PCM_S16LE; - return codec_id == acodec->codec_id; + return codec_id == apar->codec_id; case FLV_CODECID_AAC: - return acodec->codec_id == AV_CODEC_ID_AAC; + return apar->codec_id == AV_CODEC_ID_AAC; case FLV_CODECID_ADPCM: - return acodec->codec_id == AV_CODEC_ID_ADPCM_SWF; + return apar->codec_id == AV_CODEC_ID_ADPCM_SWF; case FLV_CODECID_SPEEX: - return acodec->codec_id == AV_CODEC_ID_SPEEX; + return apar->codec_id == AV_CODEC_ID_SPEEX; case FLV_CODECID_MP3: - return acodec->codec_id == AV_CODEC_ID_MP3; + return apar->codec_id == AV_CODEC_ID_MP3; case FLV_CODECID_NELLYMOSER_8KHZ_MONO: case FLV_CODECID_NELLYMOSER_16KHZ_MONO: case FLV_CODECID_NELLYMOSER: - return acodec->codec_id == AV_CODEC_ID_NELLYMOSER; + return apar->codec_id == AV_CODEC_ID_NELLYMOSER; case FLV_CODECID_PCM_MULAW: - return acodec->sample_rate == 8000 && - acodec->codec_id == AV_CODEC_ID_PCM_MULAW; + return apar->sample_rate == 8000 && + apar->codec_id == AV_CODEC_ID_PCM_MULAW; case FLV_CODECID_PCM_ALAW: - return acodec->sample_rate == 8000 && - acodec->codec_id == AV_CODEC_ID_PCM_ALAW; + return apar->sample_rate == 8000 && + apar->codec_id == AV_CODEC_ID_PCM_ALAW; default: - return acodec->codec_tag == (flv_codecid >> FLV_AUDIO_CODECID_OFFSET); + return apar->codec_tag == (flv_codecid >> FLV_AUDIO_CODECID_OFFSET); } } static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, - AVCodecContext *acodec, int flv_codecid) + AVCodecParameters *apar, int flv_codecid) { switch (flv_codecid) { // no distinction between S16 and S8 PCM codec flags case FLV_CODECID_PCM: - acodec->codec_id = acodec->bits_per_coded_sample == 8 + apar->codec_id = apar->bits_per_coded_sample == 8 ? AV_CODEC_ID_PCM_U8 #if HAVE_BIGENDIAN : AV_CODEC_ID_PCM_S16BE; @@ -173,118 +173,118 @@ static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, #endif break; case FLV_CODECID_PCM_LE: - acodec->codec_id = acodec->bits_per_coded_sample == 8 + apar->codec_id = apar->bits_per_coded_sample == 8 ? AV_CODEC_ID_PCM_U8 : AV_CODEC_ID_PCM_S16LE; break; case FLV_CODECID_AAC: - acodec->codec_id = AV_CODEC_ID_AAC; + apar->codec_id = AV_CODEC_ID_AAC; break; case FLV_CODECID_ADPCM: - acodec->codec_id = AV_CODEC_ID_ADPCM_SWF; + apar->codec_id = AV_CODEC_ID_ADPCM_SWF; break; case FLV_CODECID_SPEEX: - acodec->codec_id = AV_CODEC_ID_SPEEX; - acodec->sample_rate = 16000; + apar->codec_id = AV_CODEC_ID_SPEEX; + apar->sample_rate = 16000; break; case FLV_CODECID_MP3: - acodec->codec_id = AV_CODEC_ID_MP3; + apar->codec_id = AV_CODEC_ID_MP3; astream->need_parsing = AVSTREAM_PARSE_FULL; break; case FLV_CODECID_NELLYMOSER_8KHZ_MONO: // in case metadata does not otherwise declare samplerate - acodec->sample_rate = 8000; - acodec->codec_id = AV_CODEC_ID_NELLYMOSER; + apar->sample_rate = 8000; + apar->codec_id = AV_CODEC_ID_NELLYMOSER; break; case FLV_CODECID_NELLYMOSER_16KHZ_MONO: - acodec->sample_rate = 16000; - acodec->codec_id = AV_CODEC_ID_NELLYMOSER; + apar->sample_rate = 16000; + apar->codec_id = AV_CODEC_ID_NELLYMOSER; break; case FLV_CODECID_NELLYMOSER: - acodec->codec_id = AV_CODEC_ID_NELLYMOSER; + apar->codec_id = AV_CODEC_ID_NELLYMOSER; break; case FLV_CODECID_PCM_MULAW: - acodec->sample_rate = 8000; - acodec->codec_id = AV_CODEC_ID_PCM_MULAW; + apar->sample_rate = 8000; + apar->codec_id = AV_CODEC_ID_PCM_MULAW; break; case FLV_CODECID_PCM_ALAW: - acodec->sample_rate = 8000; - acodec->codec_id = AV_CODEC_ID_PCM_ALAW; + apar->sample_rate = 8000; + apar->codec_id = AV_CODEC_ID_PCM_ALAW; break; default: avpriv_request_sample(s, "Audio codec (%x)", flv_codecid >> FLV_AUDIO_CODECID_OFFSET); - acodec->codec_tag = flv_codecid >> FLV_AUDIO_CODECID_OFFSET; + apar->codec_tag = flv_codecid >> FLV_AUDIO_CODECID_OFFSET; } } -static int flv_same_video_codec(AVCodecContext *vcodec, int flags) +static int flv_same_video_codec(AVCodecParameters *vpar, int flags) { int flv_codecid = flags & FLV_VIDEO_CODECID_MASK; - if (!vcodec->codec_id && !vcodec->codec_tag) + if (!vpar->codec_id && !vpar->codec_tag) return 1; switch (flv_codecid) { case FLV_CODECID_H263: - return vcodec->codec_id == AV_CODEC_ID_FLV1; + return vpar->codec_id == AV_CODEC_ID_FLV1; case FLV_CODECID_SCREEN: - return vcodec->codec_id == AV_CODEC_ID_FLASHSV; + return vpar->codec_id == AV_CODEC_ID_FLASHSV; case FLV_CODECID_SCREEN2: - return vcodec->codec_id == AV_CODEC_ID_FLASHSV2; + return vpar->codec_id == AV_CODEC_ID_FLASHSV2; case FLV_CODECID_VP6: - return vcodec->codec_id == AV_CODEC_ID_VP6F; + return vpar->codec_id == AV_CODEC_ID_VP6F; case FLV_CODECID_VP6A: - return vcodec->codec_id == AV_CODEC_ID_VP6A; + return vpar->codec_id == AV_CODEC_ID_VP6A; case FLV_CODECID_H264: - return vcodec->codec_id == AV_CODEC_ID_H264; + return vpar->codec_id == AV_CODEC_ID_H264; default: - return vcodec->codec_tag == flv_codecid; + return vpar->codec_tag == flv_codecid; } } static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_codecid, int read) { - AVCodecContext *vcodec = vstream->codec; + AVCodecParameters *par = vstream->codecpar; switch (flv_codecid) { case FLV_CODECID_H263: - vcodec->codec_id = AV_CODEC_ID_FLV1; + par->codec_id = AV_CODEC_ID_FLV1; break; case FLV_CODECID_REALH263: - vcodec->codec_id = AV_CODEC_ID_H263; + par->codec_id = AV_CODEC_ID_H263; break; // Really mean it this time case FLV_CODECID_SCREEN: - vcodec->codec_id = AV_CODEC_ID_FLASHSV; + par->codec_id = AV_CODEC_ID_FLASHSV; break; case FLV_CODECID_SCREEN2: - vcodec->codec_id = AV_CODEC_ID_FLASHSV2; + par->codec_id = AV_CODEC_ID_FLASHSV2; break; case FLV_CODECID_VP6: - vcodec->codec_id = AV_CODEC_ID_VP6F; + par->codec_id = AV_CODEC_ID_VP6F; case FLV_CODECID_VP6A: if (flv_codecid == FLV_CODECID_VP6A) - vcodec->codec_id = AV_CODEC_ID_VP6A; + par->codec_id = AV_CODEC_ID_VP6A; if (read) { - if (vcodec->extradata_size != 1) { - ff_alloc_extradata(vcodec, 1); + if (par->extradata_size != 1) { + ff_alloc_extradata(par, 1); } - if (vcodec->extradata) - vcodec->extradata[0] = avio_r8(s->pb); + if (par->extradata) + par->extradata[0] = avio_r8(s->pb); else avio_skip(s->pb, 1); } return 1; // 1 byte body size adjustment for flv_read_packet() case FLV_CODECID_H264: - vcodec->codec_id = AV_CODEC_ID_H264; + par->codec_id = AV_CODEC_ID_H264; vstream->need_parsing = AVSTREAM_PARSE_HEADERS; return 3; // not 4, reading packet type will consume one byte case FLV_CODECID_MPEG4: - vcodec->codec_id = AV_CODEC_ID_MPEG4; + par->codec_id = AV_CODEC_ID_MPEG4; return 3; default: avpriv_request_sample(s, "Video codec (%x)", flv_codecid); - vcodec->codec_tag = flv_codecid; + par->codec_tag = flv_codecid; } return 0; @@ -393,7 +393,7 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vstream, const char *key, int64_t max_pos, int depth) { - AVCodecContext *acodec, *vcodec; + AVCodecParameters *apar, *vpar; FLVContext *flv = s->priv_data; AVIOContext *ioc; AMFDataType amf_type; @@ -477,8 +477,8 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, } if (key) { - acodec = astream ? astream->codec : NULL; - vcodec = vstream ? vstream->codec : NULL; + apar = astream ? astream->codecpar : NULL; + vpar = vstream ? vstream->codecpar : NULL; // stream info doesn't live any deeper than the first object if (depth == 1) { @@ -486,36 +486,36 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, amf_type == AMF_DATA_TYPE_BOOL) { if (!strcmp(key, "duration")) s->duration = num_val * AV_TIME_BASE; - else if (!strcmp(key, "videodatarate") && vcodec && + else if (!strcmp(key, "videodatarate") && vpar && 0 <= (int)(num_val * 1024.0)) - vcodec->bit_rate = num_val * 1024.0; - else if (!strcmp(key, "audiodatarate") && acodec && + vpar->bit_rate = num_val * 1024.0; + else if (!strcmp(key, "audiodatarate") && apar && 0 <= (int)(num_val * 1024.0)) - acodec->bit_rate = num_val * 1024.0; + apar->bit_rate = num_val * 1024.0; else if (!strcmp(key, "datastream")) { AVStream *st = create_stream(s, AVMEDIA_TYPE_SUBTITLE); if (!st) return AVERROR(ENOMEM); - st->codec->codec_id = AV_CODEC_ID_TEXT; + st->codecpar->codec_id = AV_CODEC_ID_TEXT; } else if (flv->trust_metadata) { - if (!strcmp(key, "videocodecid") && vcodec) { + if (!strcmp(key, "videocodecid") && vpar) { flv_set_video_codec(s, vstream, num_val, 0); - } else if (!strcmp(key, "audiocodecid") && acodec) { + } else if (!strcmp(key, "audiocodecid") && apar) { int id = ((int)num_val) << FLV_AUDIO_CODECID_OFFSET; - flv_set_audio_codec(s, astream, acodec, id); - } else if (!strcmp(key, "audiosamplerate") && acodec) { - acodec->sample_rate = num_val; - } else if (!strcmp(key, "audiosamplesize") && acodec) { - acodec->bits_per_coded_sample = num_val; - } else if (!strcmp(key, "stereo") && acodec) { - acodec->channels = num_val + 1; - acodec->channel_layout = acodec->channels == 2 ? - AV_CH_LAYOUT_STEREO : - AV_CH_LAYOUT_MONO; - } else if (!strcmp(key, "width") && vcodec) { - vcodec->width = num_val; - } else if (!strcmp(key, "height") && vcodec) { - vcodec->height = num_val; + flv_set_audio_codec(s, astream, apar, id); + } else if (!strcmp(key, "audiosamplerate") && apar) { + apar->sample_rate = num_val; + } else if (!strcmp(key, "audiosamplesize") && apar) { + apar->bits_per_coded_sample = num_val; + } else if (!strcmp(key, "stereo") && apar) { + apar->channels = num_val + 1; + apar->channel_layout = apar->channels == 2 ? + AV_CH_LAYOUT_STEREO : + AV_CH_LAYOUT_MONO; + } else if (!strcmp(key, "width") && vpar) { + vpar->width = num_val; + } else if (!strcmp(key, "height") && vpar) { + vpar->height = num_val; } } } @@ -533,8 +533,8 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, } if (amf_type == AMF_DATA_TYPE_OBJECT && s->nb_streams == 1 && - ((!acodec && !strcmp(key, "audiocodecid")) || - (!vcodec && !strcmp(key, "videocodecid")))) + ((!apar && !strcmp(key, "audiocodecid")) || + (!vpar && !strcmp(key, "videocodecid")))) s->ctx_flags &= ~AVFMTCTX_NOHEADER; //If there is either audio/video missing, codecid will be an empty object if (!strcmp(key, "duration") || @@ -612,11 +612,11 @@ static int flv_read_metabody(AVFormatContext *s, int64_t next_pos) // the lookup every time it is called. for (i = 0; i < s->nb_streams; i++) { stream = s->streams[i]; - if (stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) + if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) vstream = stream; - else if (stream->codec->codec_type == AVMEDIA_TYPE_AUDIO) + else if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) astream = stream; - else if (stream->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) + else if (stream->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) dstream = stream; } @@ -629,23 +629,14 @@ static int flv_read_metabody(AVFormatContext *s, int64_t next_pos) static int flv_read_header(AVFormatContext *s) { - int offset, flags; FLVContext *flv = s->priv_data; + int offset; avio_skip(s->pb, 4); - flags = avio_r8(s->pb); + avio_r8(s->pb); // flags s->ctx_flags |= AVFMTCTX_NOHEADER; - if (flags & FLV_HEADER_FLAG_HASVIDEO) - if (!create_stream(s, AVMEDIA_TYPE_VIDEO)) - return AVERROR(ENOMEM); - if (flags & FLV_HEADER_FLAG_HASAUDIO) - if (!create_stream(s, AVMEDIA_TYPE_AUDIO)) - return AVERROR(ENOMEM); - // Flag doesn't indicate whether or not there is script-data present. Must - // create that stream if it's encountered. - offset = avio_rb32(s->pb); avio_seek(s->pb, offset, SEEK_SET); avio_skip(s->pb, 4); @@ -667,8 +658,8 @@ static int flv_read_close(AVFormatContext *s) static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size) { - av_freep(&st->codec->extradata); - if (ff_get_extradata(st->codec, s->pb, size) < 0) + av_freep(&st->codecpar->extradata); + if (ff_get_extradata(st->codecpar, s->pb, size) < 0) return AVERROR(ENOMEM); return 0; } @@ -786,7 +777,7 @@ static int flv_data_packet(AVFormatContext *s, AVPacket *pkt, for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) + if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) break; } @@ -794,7 +785,7 @@ static int flv_data_packet(AVFormatContext *s, AVPacket *pkt, st = create_stream(s, AVMEDIA_TYPE_SUBTITLE); if (!st) return AVERROR(ENOMEM); - st->codec->codec_id = AV_CODEC_ID_TEXT; + st->codecpar->codec_id = AV_CODEC_ID_TEXT; } pkt->dts = dts; @@ -945,15 +936,15 @@ skip: for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; if (stream_type == FLV_STREAM_TYPE_AUDIO) { - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && - (s->audio_codec_id || flv_same_audio_codec(st->codec, flags))) + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && + (s->audio_codec_id || flv_same_audio_codec(st->codecpar, flags))) break; } else if (stream_type == FLV_STREAM_TYPE_VIDEO) { - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && - (s->video_codec_id || flv_same_video_codec(st->codec, flags))) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + (s->video_codec_id || flv_same_video_codec(st->codecpar, flags))) break; } else if (stream_type == FLV_STREAM_TYPE_DATA) { - if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) + if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) break; } } @@ -1019,41 +1010,46 @@ retry_duration: sample_rate = 44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >> FLV_AUDIO_SAMPLERATE_OFFSET) >> 3; bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8; - if (!st->codec->channels || !st->codec->sample_rate || - !st->codec->bits_per_coded_sample) { - st->codec->channels = channels; - st->codec->channel_layout = channels == 1 + if (!st->codecpar->channels || !st->codecpar->sample_rate || + !st->codecpar->bits_per_coded_sample) { + st->codecpar->channels = channels; + st->codecpar->channel_layout = channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; - st->codec->sample_rate = sample_rate; - st->codec->bits_per_coded_sample = bits_per_coded_sample; + st->codecpar->sample_rate = sample_rate; + st->codecpar->bits_per_coded_sample = bits_per_coded_sample; } - if (!st->codec->codec_id) { - flv_set_audio_codec(s, st, st->codec, + if (!st->codecpar->codec_id) { + flv_set_audio_codec(s, st, st->codecpar, flags & FLV_AUDIO_CODECID_MASK); flv->last_sample_rate = - sample_rate = st->codec->sample_rate; + sample_rate = st->codecpar->sample_rate; flv->last_channels = - channels = st->codec->channels; + channels = st->codecpar->channels; } else { - AVCodecContext ctx = {0}; - ctx.sample_rate = sample_rate; - ctx.bits_per_coded_sample = bits_per_coded_sample; - flv_set_audio_codec(s, st, &ctx, flags & FLV_AUDIO_CODECID_MASK); - sample_rate = ctx.sample_rate; + AVCodecParameters *par = avcodec_parameters_alloc(); + if (!par) { + ret = AVERROR(ENOMEM); + goto leave; + } + par->sample_rate = sample_rate; + par->bits_per_coded_sample = bits_per_coded_sample; + flv_set_audio_codec(s, st, par, flags & FLV_AUDIO_CODECID_MASK); + sample_rate = par->sample_rate; + avcodec_parameters_free(&par); } } else if (stream_type == FLV_STREAM_TYPE_VIDEO) { size -= flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK, 1); } else if (stream_type == FLV_STREAM_TYPE_DATA) { - st->codec->codec_id = AV_CODEC_ID_TEXT; + st->codecpar->codec_id = AV_CODEC_ID_TEXT; } - if (st->codec->codec_id == AV_CODEC_ID_AAC || - st->codec->codec_id == AV_CODEC_ID_H264 || - st->codec->codec_id == AV_CODEC_ID_MPEG4) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC || + st->codecpar->codec_id == AV_CODEC_ID_H264 || + st->codecpar->codec_id == AV_CODEC_ID_MPEG4) { int type = avio_r8(s->pb); size--; - if (st->codec->codec_id == AV_CODEC_ID_H264 || st->codec->codec_id == AV_CODEC_ID_MPEG4) { + if (st->codecpar->codec_id == AV_CODEC_ID_H264 || st->codecpar->codec_id == AV_CODEC_ID_MPEG4) { // sign extension int32_t cts = (avio_rb24(s->pb) + 0xff800000) ^ 0xff800000; pts = dts + cts; @@ -1068,11 +1064,11 @@ retry_duration: dts = pts = AV_NOPTS_VALUE; } } - if (type == 0 && (!st->codec->extradata || st->codec->codec_id == AV_CODEC_ID_AAC || - st->codec->codec_id == AV_CODEC_ID_H264)) { + if (type == 0 && (!st->codecpar->extradata || st->codecpar->codec_id == AV_CODEC_ID_AAC || + st->codecpar->codec_id == AV_CODEC_ID_H264)) { AVDictionaryEntry *t; - if (st->codec->extradata) { + if (st->codecpar->extradata) { if ((ret = flv_queue_extradata(flv, s->pb, stream_type, size)) < 0) return ret; ret = FFERROR_REDO; @@ -1083,22 +1079,22 @@ retry_duration: /* Workaround for buggy Omnia A/XE encoder */ t = av_dict_get(s->metadata, "Encoder", NULL, 0); - if (st->codec->codec_id == AV_CODEC_ID_AAC && t && !strcmp(t->value, "Omnia A/XE")) - st->codec->extradata_size = 2; + if (st->codecpar->codec_id == AV_CODEC_ID_AAC && t && !strcmp(t->value, "Omnia A/XE")) + st->codecpar->extradata_size = 2; - if (st->codec->codec_id == AV_CODEC_ID_AAC && 0) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC && 0) { MPEG4AudioConfig cfg; - if (avpriv_mpeg4audio_get_config(&cfg, st->codec->extradata, - st->codec->extradata_size * 8, 1) >= 0) { - st->codec->channels = cfg.channels; - st->codec->channel_layout = 0; + if (avpriv_mpeg4audio_get_config(&cfg, st->codecpar->extradata, + st->codecpar->extradata_size * 8, 1) >= 0) { + st->codecpar->channels = cfg.channels; + st->codecpar->channel_layout = 0; if (cfg.ext_sample_rate) - st->codec->sample_rate = cfg.ext_sample_rate; + st->codecpar->sample_rate = cfg.ext_sample_rate; else - st->codec->sample_rate = cfg.sample_rate; + st->codecpar->sample_rate = cfg.sample_rate; av_log(s, AV_LOG_TRACE, "mp4a config channels %d sample rate %d\n", - st->codec->channels, st->codec->sample_rate); + st->codecpar->channels, st->codecpar->sample_rate); } } diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index ab71d41df7..d62ff70933 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -68,10 +68,10 @@ typedef struct FLVContext { int64_t duration; int64_t delay; ///< first dts delay (needed for AVC & Speex) - AVCodecContext *audio_enc; - AVCodecContext *video_enc; + AVCodecParameters *audio_par; + AVCodecParameters *video_par; double framerate; - AVCodecContext *data_enc; + AVCodecParameters *data_par; int flags; } FLVContext; @@ -80,27 +80,27 @@ typedef struct FLVStreamContext { int64_t last_ts; ///< last timestamp for each stream } FLVStreamContext; -static int get_audio_flags(AVFormatContext *s, AVCodecContext *enc) +static int get_audio_flags(AVFormatContext *s, AVCodecParameters *par) { - int flags = (enc->bits_per_coded_sample == 16) ? FLV_SAMPLESSIZE_16BIT + int flags = (par->bits_per_coded_sample == 16) ? FLV_SAMPLESSIZE_16BIT : FLV_SAMPLESSIZE_8BIT; - if (enc->codec_id == AV_CODEC_ID_AAC) // specs force these parameters + if (par->codec_id == AV_CODEC_ID_AAC) // specs force these parameters return FLV_CODECID_AAC | FLV_SAMPLERATE_44100HZ | FLV_SAMPLESSIZE_16BIT | FLV_STEREO; - else if (enc->codec_id == AV_CODEC_ID_SPEEX) { - if (enc->sample_rate != 16000) { + else if (par->codec_id == AV_CODEC_ID_SPEEX) { + if (par->sample_rate != 16000) { av_log(s, AV_LOG_ERROR, "FLV only supports wideband (16kHz) Speex audio\n"); return AVERROR(EINVAL); } - if (enc->channels != 1) { + if (par->channels != 1) { av_log(s, AV_LOG_ERROR, "FLV only supports mono Speex audio\n"); return AVERROR(EINVAL); } return FLV_CODECID_SPEEX | FLV_SAMPLERATE_11025HZ | FLV_SAMPLESSIZE_16BIT; } else { - switch (enc->sample_rate) { + switch (par->sample_rate) { case 44100: flags |= FLV_SAMPLERATE_44100HZ; break; @@ -113,22 +113,22 @@ static int get_audio_flags(AVFormatContext *s, AVCodecContext *enc) case 16000: // nellymoser only case 8000: // nellymoser only case 5512: // not MP3 - if (enc->codec_id != AV_CODEC_ID_MP3) { + if (par->codec_id != AV_CODEC_ID_MP3) { flags |= FLV_SAMPLERATE_SPECIAL; break; } default: av_log(s, AV_LOG_ERROR, "FLV does not support sample rate %d, " - "choose from (44100, 22050, 11025)\n", enc->sample_rate); + "choose from (44100, 22050, 11025)\n", par->sample_rate); return AVERROR(EINVAL); } } - if (enc->channels > 1) + if (par->channels > 1) flags |= FLV_STEREO; - switch (enc->codec_id) { + switch (par->codec_id) { case AV_CODEC_ID_MP3: flags |= FLV_CODECID_MP3 | FLV_SAMPLESSIZE_16BIT; break; @@ -145,9 +145,9 @@ static int get_audio_flags(AVFormatContext *s, AVCodecContext *enc) flags |= FLV_CODECID_ADPCM | FLV_SAMPLESSIZE_16BIT; break; case AV_CODEC_ID_NELLYMOSER: - if (enc->sample_rate == 8000) + if (par->sample_rate == 8000) flags |= FLV_CODECID_NELLYMOSER_8KHZ_MONO | FLV_SAMPLESSIZE_16BIT; - else if (enc->sample_rate == 16000) + else if (par->sample_rate == 16000) flags |= FLV_CODECID_NELLYMOSER_16KHZ_MONO | FLV_SAMPLESSIZE_16BIT; else flags |= FLV_CODECID_NELLYMOSER | FLV_SAMPLESSIZE_16BIT; @@ -159,11 +159,11 @@ static int get_audio_flags(AVFormatContext *s, AVCodecContext *enc) flags = FLV_CODECID_PCM_ALAW | FLV_SAMPLERATE_SPECIAL | FLV_SAMPLESSIZE_16BIT; break; case 0: - flags |= enc->codec_tag << 4; + flags |= par->codec_tag << 4; break; default: av_log(s, AV_LOG_ERROR, "Audio codec '%s' not compatible with FLV\n", - avcodec_get_name(enc->codec_id)); + avcodec_get_name(par->codec_id)); return AVERROR(EINVAL); } @@ -226,9 +226,9 @@ static void write_metadata(AVFormatContext *s, unsigned int ts) /* mixed array (hash) with size and string/type/data tuples */ avio_w8(pb, AMF_DATA_TYPE_MIXEDARRAY); metadata_count_pos = avio_tell(pb); - metadata_count = 4 * !!flv->video_enc + - 5 * !!flv->audio_enc + - 1 * !!flv->data_enc + + metadata_count = 4 * !!flv->video_par + + 5 * !!flv->audio_par + + 1 * !!flv->data_par + 2; // +2 for duration and file size avio_wb32(pb, metadata_count); @@ -239,15 +239,15 @@ static void write_metadata(AVFormatContext *s, unsigned int ts) // fill in the guessed duration, it'll be corrected later if incorrect put_amf_double(pb, s->duration / AV_TIME_BASE); - if (flv->video_enc) { + if (flv->video_par) { put_amf_string(pb, "width"); - put_amf_double(pb, flv->video_enc->width); + put_amf_double(pb, flv->video_par->width); put_amf_string(pb, "height"); - put_amf_double(pb, flv->video_enc->height); + put_amf_double(pb, flv->video_par->height); put_amf_string(pb, "videodatarate"); - put_amf_double(pb, flv->video_enc->bit_rate / 1024.0); + put_amf_double(pb, flv->video_par->bit_rate / 1024.0); if (flv->framerate != 0.0) { put_amf_string(pb, "framerate"); @@ -256,27 +256,27 @@ static void write_metadata(AVFormatContext *s, unsigned int ts) } put_amf_string(pb, "videocodecid"); - put_amf_double(pb, flv->video_enc->codec_tag); + put_amf_double(pb, flv->video_par->codec_tag); } - if (flv->audio_enc) { + if (flv->audio_par) { put_amf_string(pb, "audiodatarate"); - put_amf_double(pb, flv->audio_enc->bit_rate / 1024.0); + put_amf_double(pb, flv->audio_par->bit_rate / 1024.0); put_amf_string(pb, "audiosamplerate"); - put_amf_double(pb, flv->audio_enc->sample_rate); + put_amf_double(pb, flv->audio_par->sample_rate); put_amf_string(pb, "audiosamplesize"); - put_amf_double(pb, flv->audio_enc->codec_id == AV_CODEC_ID_PCM_U8 ? 8 : 16); + put_amf_double(pb, flv->audio_par->codec_id == AV_CODEC_ID_PCM_U8 ? 8 : 16); put_amf_string(pb, "stereo"); - put_amf_bool(pb, flv->audio_enc->channels == 2); + put_amf_bool(pb, flv->audio_par->channels == 2); put_amf_string(pb, "audiocodecid"); - put_amf_double(pb, flv->audio_enc->codec_tag); + put_amf_double(pb, flv->audio_par->codec_tag); } - if (flv->data_enc) { + if (flv->data_par) { put_amf_string(pb, "datastream"); put_amf_double(pb, 0.0); } @@ -351,68 +351,68 @@ static int flv_write_header(AVFormatContext *s) int64_t data_size; for (i = 0; i < s->nb_streams; i++) { - AVCodecContext *enc = s->streams[i]->codec; + AVCodecParameters *par = s->streams[i]->codecpar; FLVStreamContext *sc; - switch (enc->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: if (s->streams[i]->avg_frame_rate.den && s->streams[i]->avg_frame_rate.num) { flv->framerate = av_q2d(s->streams[i]->avg_frame_rate); } - if (flv->video_enc) { + if (flv->video_par) { av_log(s, AV_LOG_ERROR, "at most one video stream is supported in flv\n"); return AVERROR(EINVAL); } - flv->video_enc = enc; - if (!ff_codec_get_tag(flv_video_codec_ids, enc->codec_id)) - return unsupported_codec(s, "Video", enc->codec_id); + flv->video_par = par; + if (!ff_codec_get_tag(flv_video_codec_ids, par->codec_id)) + return unsupported_codec(s, "Video", par->codec_id); - if (enc->codec_id == AV_CODEC_ID_MPEG4 || - enc->codec_id == AV_CODEC_ID_H263) { + if (par->codec_id == AV_CODEC_ID_MPEG4 || + par->codec_id == AV_CODEC_ID_H263) { int error = s->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL; av_log(s, error ? AV_LOG_ERROR : AV_LOG_WARNING, - "Codec %s is not supported in the official FLV specification,\n", avcodec_get_name(enc->codec_id)); + "Codec %s is not supported in the official FLV specification,\n", avcodec_get_name(par->codec_id)); if (error) { av_log(s, AV_LOG_ERROR, "use vstrict=-1 / -strict -1 to use it anyway.\n"); return AVERROR(EINVAL); } - } else if (enc->codec_id == AV_CODEC_ID_VP6) { + } else if (par->codec_id == AV_CODEC_ID_VP6) { av_log(s, AV_LOG_WARNING, "Muxing VP6 in flv will produce flipped video on playback.\n"); } break; case AVMEDIA_TYPE_AUDIO: - if (flv->audio_enc) { + if (flv->audio_par) { av_log(s, AV_LOG_ERROR, "at most one audio stream is supported in flv\n"); return AVERROR(EINVAL); } - flv->audio_enc = enc; - if (get_audio_flags(s, enc) < 0) - return unsupported_codec(s, "Audio", enc->codec_id); - if (enc->codec_id == AV_CODEC_ID_PCM_S16BE) + flv->audio_par = par; + if (get_audio_flags(s, par) < 0) + return unsupported_codec(s, "Audio", par->codec_id); + if (par->codec_id == AV_CODEC_ID_PCM_S16BE) av_log(s, AV_LOG_WARNING, "16-bit big-endian audio in flv is valid but most likely unplayable (hardware dependent); use s16le\n"); break; case AVMEDIA_TYPE_DATA: - if (enc->codec_id != AV_CODEC_ID_TEXT && enc->codec_id != AV_CODEC_ID_NONE) - return unsupported_codec(s, "Data", enc->codec_id); - flv->data_enc = enc; + if (par->codec_id != AV_CODEC_ID_TEXT && par->codec_id != AV_CODEC_ID_NONE) + return unsupported_codec(s, "Data", par->codec_id); + flv->data_par = par; break; case AVMEDIA_TYPE_SUBTITLE: - if (enc->codec_id != AV_CODEC_ID_TEXT) { + if (par->codec_id != AV_CODEC_ID_TEXT) { av_log(s, AV_LOG_ERROR, "Subtitle codec '%s' for stream %d is not compatible with FLV\n", - avcodec_get_name(enc->codec_id), i); + avcodec_get_name(par->codec_id), i); return AVERROR_INVALIDDATA; } - flv->data_enc = enc; + flv->data_par = par; break; default: av_log(s, AV_LOG_ERROR, "Codec type '%s' for stream %d is not compatible with FLV\n", - av_get_media_type_string(enc->codec_type), i); + av_get_media_type_string(par->codec_type), i); return AVERROR(EINVAL); } avpriv_set_pts_info(s->streams[i], 32, 1, 1000); /* 32 bit pts in ms */ @@ -428,13 +428,13 @@ static int flv_write_header(AVFormatContext *s) avio_write(pb, "FLV", 3); avio_w8(pb, 1); - avio_w8(pb, FLV_HEADER_FLAG_HASAUDIO * !!flv->audio_enc + - FLV_HEADER_FLAG_HASVIDEO * !!flv->video_enc); + avio_w8(pb, FLV_HEADER_FLAG_HASAUDIO * !!flv->audio_par + + FLV_HEADER_FLAG_HASVIDEO * !!flv->video_par); avio_wb32(pb, 9); avio_wb32(pb, 0); for (i = 0; i < s->nb_streams; i++) - if (s->streams[i]->codec->codec_tag == 5) { + if (s->streams[i]->codecpar->codec_tag == 5) { avio_w8(pb, 8); // message type avio_wb24(pb, 0); // include flags avio_wb24(pb, 0); // time stamp @@ -446,32 +446,32 @@ static int flv_write_header(AVFormatContext *s) write_metadata(s, 0); for (i = 0; i < s->nb_streams; i++) { - AVCodecContext *enc = s->streams[i]->codec; - if (enc->codec_id == AV_CODEC_ID_AAC || enc->codec_id == AV_CODEC_ID_H264 || enc->codec_id == AV_CODEC_ID_MPEG4) { + AVCodecParameters *par = s->streams[i]->codecpar; + if (par->codec_id == AV_CODEC_ID_AAC || par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4) { int64_t pos; - avio_w8(pb, enc->codec_type == AVMEDIA_TYPE_VIDEO ? + avio_w8(pb, par->codec_type == AVMEDIA_TYPE_VIDEO ? FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO); avio_wb24(pb, 0); // size patched later avio_wb24(pb, 0); // ts avio_w8(pb, 0); // ts ext avio_wb24(pb, 0); // streamid pos = avio_tell(pb); - if (enc->codec_id == AV_CODEC_ID_AAC) { - avio_w8(pb, get_audio_flags(s, enc)); + if (par->codec_id == AV_CODEC_ID_AAC) { + avio_w8(pb, get_audio_flags(s, par)); avio_w8(pb, 0); // AAC sequence header - if (!enc->extradata_size && flv->flags & 1) { + if (!par->extradata_size && flv->flags & 1) { PutBitContext pbc; int samplerate_index; - int channels = flv->audio_enc->channels - (flv->audio_enc->channels == 8 ? 1 : 0); + int channels = flv->audio_par->channels - (flv->audio_par->channels == 8 ? 1 : 0); uint8_t data[2]; for (samplerate_index = 0; samplerate_index < 16; samplerate_index++) - if (flv->audio_enc->sample_rate == mpeg4audio_sample_rates[samplerate_index]) + if (flv->audio_par->sample_rate == mpeg4audio_sample_rates[samplerate_index]) break; init_put_bits(&pbc, data, sizeof(data)); - put_bits(&pbc, 5, flv->audio_enc->profile + 1); //profile + put_bits(&pbc, 5, flv->audio_par->profile + 1); //profile put_bits(&pbc, 4, samplerate_index); //sample rate index put_bits(&pbc, 4, channels); put_bits(&pbc, 1, 0); //frame length - 1024 samples @@ -484,12 +484,12 @@ static int flv_write_header(AVFormatContext *s) av_log(s, AV_LOG_WARNING, "AAC sequence header: %02x %02x.\n", data[0], data[1]); } - avio_write(pb, enc->extradata, enc->extradata_size); + avio_write(pb, par->extradata, par->extradata_size); } else { - avio_w8(pb, enc->codec_tag | FLV_FRAME_KEY); // flags + avio_w8(pb, par->codec_tag | FLV_FRAME_KEY); // flags avio_w8(pb, 0); // AVC sequence header avio_wb24(pb, 0); // composition time - ff_isom_write_avcc(pb, enc->extradata, enc->extradata_size); + ff_isom_write_avcc(pb, par->extradata, par->extradata_size); } data_size = avio_tell(pb) - pos; avio_seek(pb, -data_size - 10, SEEK_CUR); @@ -512,10 +512,10 @@ static int flv_write_trailer(AVFormatContext *s) /* Add EOS tag */ for (i = 0; i < s->nb_streams; i++) { - AVCodecContext *enc = s->streams[i]->codec; + AVCodecParameters *par = s->streams[i]->codecpar; FLVStreamContext *sc = s->streams[i]->priv_data; - if (enc->codec_type == AVMEDIA_TYPE_VIDEO && - (enc->codec_id == AV_CODEC_ID_H264 || enc->codec_id == AV_CODEC_ID_MPEG4)) + if (par->codec_type == AVMEDIA_TYPE_VIDEO && + (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4)) put_avc_eos_tag(pb, sc->last_ts); } @@ -538,7 +538,7 @@ static int flv_write_trailer(AVFormatContext *s) static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) { AVIOContext *pb = s->pb; - AVCodecContext *enc = s->streams[pkt->stream_index]->codec; + AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; FLVContext *flv = s->priv_data; FLVStreamContext *sc = s->streams[pkt->stream_index]->priv_data; unsigned ts; @@ -546,10 +546,10 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) uint8_t *data = NULL; int flags = -1, flags_size, ret; - if (enc->codec_id == AV_CODEC_ID_VP6F || enc->codec_id == AV_CODEC_ID_VP6A || - enc->codec_id == AV_CODEC_ID_VP6 || enc->codec_id == AV_CODEC_ID_AAC) + if (par->codec_id == AV_CODEC_ID_VP6F || par->codec_id == AV_CODEC_ID_VP6A || + par->codec_id == AV_CODEC_ID_VP6 || par->codec_id == AV_CODEC_ID_AAC) flags_size = 2; - else if (enc->codec_id == AV_CODEC_ID_H264 || enc->codec_id == AV_CODEC_ID_MPEG4) + else if (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4) flags_size = 5; else flags_size = 1; @@ -570,16 +570,16 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) s->event_flags &= ~AVSTREAM_EVENT_FLAG_METADATA_UPDATED; } - switch (enc->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: avio_w8(pb, FLV_TAG_TYPE_VIDEO); - flags = ff_codec_get_tag(flv_video_codec_ids, enc->codec_id); + flags = ff_codec_get_tag(flv_video_codec_ids, par->codec_id); flags |= pkt->flags & AV_PKT_FLAG_KEY ? FLV_FRAME_KEY : FLV_FRAME_INTER; break; case AVMEDIA_TYPE_AUDIO: - flags = get_audio_flags(s, enc); + flags = get_audio_flags(s, par); av_assert0(size); @@ -593,12 +593,12 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(EINVAL); } - if (enc->codec_id == AV_CODEC_ID_H264 || enc->codec_id == AV_CODEC_ID_MPEG4) { + if (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4) { /* check if extradata looks like mp4 formatted */ - if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) + if (par->extradata_size > 0 && *(uint8_t*)par->extradata != 1) if ((ret = ff_avc_parse_nal_units_buf(pkt->data, &data, &size)) < 0) return ret; - } else if (enc->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 && + } else if (par->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 && (AV_RB16(pkt->data) & 0xfff0) == 0xfff0) { if (!s->streams[pkt->stream_index]->nb_frames) { av_log(s, AV_LOG_ERROR, "Malformed AAC bitstream detected: " @@ -610,7 +610,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) } /* check Speex packet duration */ - if (enc->codec_id == AV_CODEC_ID_SPEEX && ts - sc->last_ts > 160) + if (par->codec_id == AV_CODEC_ID_SPEEX && ts - sc->last_ts > 160) av_log(s, AV_LOG_WARNING, "Warning: Speex stream has more than " "8 frames per packet. Adobe Flash " "Player cannot handle this!\n"); @@ -629,11 +629,11 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) avio_w8(pb, (ts >> 24) & 0x7F); // timestamps are 32 bits _signed_ avio_wb24(pb, flv->reserved); - if (enc->codec_type == AVMEDIA_TYPE_DATA || - enc->codec_type == AVMEDIA_TYPE_SUBTITLE ) { + if (par->codec_type == AVMEDIA_TYPE_DATA || + par->codec_type == AVMEDIA_TYPE_SUBTITLE ) { int data_size; int64_t metadata_size_pos = avio_tell(pb); - if (enc->codec_id == AV_CODEC_ID_TEXT) { + if (par->codec_id == AV_CODEC_ID_TEXT) { // legacy FFmpeg magic? avio_w8(pb, AMF_DATA_TYPE_STRING); put_amf_string(pb, "onTextData"); @@ -660,17 +660,17 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) } else { av_assert1(flags>=0); avio_w8(pb,flags); - if (enc->codec_id == AV_CODEC_ID_VP6) + if (par->codec_id == AV_CODEC_ID_VP6) avio_w8(pb,0); - if (enc->codec_id == AV_CODEC_ID_VP6F || enc->codec_id == AV_CODEC_ID_VP6A) { - if (enc->extradata_size) - avio_w8(pb, enc->extradata[0]); + if (par->codec_id == AV_CODEC_ID_VP6F || par->codec_id == AV_CODEC_ID_VP6A) { + if (par->extradata_size) + avio_w8(pb, par->extradata[0]); else - avio_w8(pb, ((FFALIGN(enc->width, 16) - enc->width) << 4) | - (FFALIGN(enc->height, 16) - enc->height)); - } else if (enc->codec_id == AV_CODEC_ID_AAC) + avio_w8(pb, ((FFALIGN(par->width, 16) - par->width) << 4) | + (FFALIGN(par->height, 16) - par->height)); + } else if (par->codec_id == AV_CODEC_ID_AAC) avio_w8(pb, 1); // AAC raw - else if (enc->codec_id == AV_CODEC_ID_H264 || enc->codec_id == AV_CODEC_ID_MPEG4) { + else if (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4) { avio_w8(pb, 1); // AVC NALU avio_wb24(pb, pkt->pts - pkt->dts); } diff --git a/libavformat/framecrcenc.c b/libavformat/framecrcenc.c index eacbc457b1..91bcdcd99e 100644 --- a/libavformat/framecrcenc.c +++ b/libavformat/framecrcenc.c @@ -31,11 +31,11 @@ static int framecrc_write_header(struct AVFormatContext *s) int i; for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - AVCodecContext *avctx = st->codec; - if (avctx->extradata) { - uint32_t crc = av_adler32_update(0, avctx->extradata, avctx->extradata_size); + AVCodecParameters *par = st->codecpar; + if (par->extradata) { + uint32_t crc = av_adler32_update(0, par->extradata, par->extradata_size); avio_printf(s->pb, "#extradata %d: %8d, 0x%08"PRIx32"\n", - i, avctx->extradata_size, crc); + i, par->extradata_size, crc); } } diff --git a/libavformat/frmdec.c b/libavformat/frmdec.c index 260afbc588..2f6b726427 100644 --- a/libavformat/frmdec.c +++ b/libavformat/frmdec.c @@ -58,30 +58,30 @@ static int frm_read_header(AVFormatContext *avctx) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; avio_skip(pb, 3); - st->codec->pix_fmt = avpriv_find_pix_fmt(frm_pix_fmt_tags, avio_r8(pb)); - if (!st->codec->pix_fmt) + st->codecpar->format = avpriv_find_pix_fmt(frm_pix_fmt_tags, avio_r8(pb)); + if (!st->codecpar->format) return AVERROR_INVALIDDATA; - st->codec->codec_tag = 0; - st->codec->width = avio_rl16(pb); - st->codec->height = avio_rl16(pb); + st->codecpar->codec_tag = 0; + st->codecpar->width = avio_rl16(pb); + st->codecpar->height = avio_rl16(pb); return 0; } static int frm_read_packet(AVFormatContext *avctx, AVPacket *pkt) { FrmContext *s = avctx->priv_data; - AVCodecContext *stc = avctx->streams[0]->codec; + AVCodecParameters *par = avctx->streams[0]->codecpar; int packet_size, ret; if (s->count) return AVERROR_EOF; - packet_size = av_image_get_buffer_size(stc->pix_fmt, stc->width, stc->height, 1); + packet_size = av_image_get_buffer_size(par->format, par->width, par->height, 1); if (packet_size < 0) return AVERROR_INVALIDDATA; @@ -89,7 +89,7 @@ static int frm_read_packet(AVFormatContext *avctx, AVPacket *pkt) if (ret < 0) return ret; - if (stc->pix_fmt == AV_PIX_FMT_BGRA) { + if (par->format == AV_PIX_FMT_BGRA) { int i; for (i = 3; i + 1 <= pkt->size; i += 4) pkt->data[i] = 0xFF - pkt->data[i]; diff --git a/libavformat/fsb.c b/libavformat/fsb.c index 2837c1919d..4f59576e35 100644 --- a/libavformat/fsb.c +++ b/libavformat/fsb.c @@ -39,7 +39,7 @@ static int fsb_read_header(AVFormatContext *s) AVIOContext *pb = s->pb; unsigned format, version, c; int64_t offset; - AVCodecContext *codec; + AVCodecParameters *par; AVStream *st = avformat_new_stream(s, NULL); avio_skip(pb, 3); // "FSB" @@ -53,9 +53,9 @@ static int fsb_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - codec = st->codec; - codec->codec_type = AVMEDIA_TYPE_AUDIO; - codec->codec_tag = 0; + par = st->codecpar; + par->codec_type = AVMEDIA_TYPE_AUDIO; + par->codec_tag = 0; if (version == 3) { offset = avio_rl32(pb) + 0x18; @@ -63,35 +63,35 @@ static int fsb_read_header(AVFormatContext *s) st->duration = avio_rl32(pb); avio_skip(pb, 12); format = avio_rl32(pb); - codec->sample_rate = avio_rl32(pb); - if (codec->sample_rate <= 0) + par->sample_rate = avio_rl32(pb); + if (par->sample_rate <= 0) return AVERROR_INVALIDDATA; avio_skip(pb, 6); - codec->channels = avio_rl16(pb); - if (!codec->channels) + par->channels = avio_rl16(pb); + if (!par->channels) return AVERROR_INVALIDDATA; if (format & 0x00000100) { - codec->codec_id = AV_CODEC_ID_PCM_S16LE; - codec->block_align = 4096 * codec->channels; + par->codec_id = AV_CODEC_ID_PCM_S16LE; + par->block_align = 4096 * par->channels; } else if (format & 0x00400000) { - codec->bits_per_coded_sample = 4; - codec->codec_id = AV_CODEC_ID_ADPCM_IMA_WAV; - codec->block_align = 36 * codec->channels; + par->bits_per_coded_sample = 4; + par->codec_id = AV_CODEC_ID_ADPCM_IMA_WAV; + par->block_align = 36 * par->channels; } else if (format & 0x00800000) { - codec->codec_id = AV_CODEC_ID_ADPCM_PSX; - codec->block_align = 16 * codec->channels; + par->codec_id = AV_CODEC_ID_ADPCM_PSX; + par->block_align = 16 * par->channels; } else if (format & 0x02000000) { - codec->codec_id = AV_CODEC_ID_ADPCM_THP; - codec->block_align = 8 * codec->channels; - if (codec->channels > INT_MAX / 32) + par->codec_id = AV_CODEC_ID_ADPCM_THP; + par->block_align = 8 * par->channels; + if (par->channels > INT_MAX / 32) return AVERROR_INVALIDDATA; - ff_alloc_extradata(codec, 32 * codec->channels); - if (!codec->extradata) + ff_alloc_extradata(par, 32 * par->channels); + if (!par->extradata) return AVERROR(ENOMEM); avio_seek(pb, 0x68, SEEK_SET); - for (c = 0; c < codec->channels; c++) { - avio_read(pb, codec->extradata + 32 * c, 32); + for (c = 0; c < par->channels; c++) { + avio_read(pb, par->extradata + 32 * c, 32); avio_skip(pb, 14); } } else { @@ -109,45 +109,45 @@ static int fsb_read_header(AVFormatContext *s) case 0x00001005: case 0x40001081: case 0x40200001: - codec->codec_id = AV_CODEC_ID_XMA2; + par->codec_id = AV_CODEC_ID_XMA2; break; case 0x40000802: - codec->codec_id = AV_CODEC_ID_ADPCM_THP; + par->codec_id = AV_CODEC_ID_ADPCM_THP; break; default: avpriv_request_sample(s, "format 0x%X", format); return AVERROR_PATCHWELCOME; } - codec->sample_rate = avio_rl32(pb); - if (codec->sample_rate <= 0) + par->sample_rate = avio_rl32(pb); + if (par->sample_rate <= 0) return AVERROR_INVALIDDATA; avio_skip(pb, 6); - codec->channels = avio_rl16(pb); - if (!codec->channels) + par->channels = avio_rl16(pb); + if (!par->channels) return AVERROR_INVALIDDATA; - switch (codec->codec_id) { + switch (par->codec_id) { case AV_CODEC_ID_XMA2: - ff_alloc_extradata(codec, 34); - if (!codec->extradata) + ff_alloc_extradata(par, 34); + if (!par->extradata) return AVERROR(ENOMEM); - memset(codec->extradata, 0, 34); - codec->block_align = 2048; + memset(par->extradata, 0, 34); + par->block_align = 2048; break; case AV_CODEC_ID_ADPCM_THP: - if (codec->channels > INT_MAX / 32) + if (par->channels > INT_MAX / 32) return AVERROR_INVALIDDATA; - ff_alloc_extradata(codec, 32 * codec->channels); - if (!codec->extradata) + ff_alloc_extradata(par, 32 * par->channels); + if (!par->extradata) return AVERROR(ENOMEM); avio_seek(pb, 0x80, SEEK_SET); - for (c = 0; c < codec->channels; c++) { - avio_read(pb, codec->extradata + 32 * c, 32); + for (c = 0; c < par->channels; c++) { + avio_read(pb, par->extradata + 32 * c, 32); avio_skip(pb, 14); } - codec->block_align = 8 * codec->channels; + par->block_align = 8 * par->channels; break; } } else { @@ -157,14 +157,14 @@ static int fsb_read_header(AVFormatContext *s) avio_skip(pb, offset - avio_tell(pb)); s->internal->data_offset = avio_tell(pb); - avpriv_set_pts_info(st, 64, 1, codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, par->sample_rate); return 0; } static int fsb_read_packet(AVFormatContext *s, AVPacket *pkt) { - AVCodecContext *codec = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; int64_t pos; int ret; @@ -172,25 +172,25 @@ static int fsb_read_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR_EOF; pos = avio_tell(s->pb); - if (codec->codec_id == AV_CODEC_ID_ADPCM_THP && - codec->channels > 1) { + if (par->codec_id == AV_CODEC_ID_ADPCM_THP && + par->channels > 1) { int i, ch; - ret = av_new_packet(pkt, codec->block_align); + ret = av_new_packet(pkt, par->block_align); if (ret < 0) return ret; for (i = 0; i < 4; i++) { - for (ch = 0; ch < codec->channels; ch++) { + for (ch = 0; ch < par->channels; ch++) { pkt->data[ch * 8 + i * 2 + 0] = avio_r8(s->pb); pkt->data[ch * 8 + i * 2 + 1] = avio_r8(s->pb); } } ret = 0; } else { - ret = av_get_packet(s->pb, pkt, codec->block_align); + ret = av_get_packet(s->pb, pkt, par->block_align); } - if (codec->codec_id == AV_CODEC_ID_XMA2 && pkt->size >= 1) + if (par->codec_id == AV_CODEC_ID_XMA2 && pkt->size >= 1) pkt->duration = (pkt->data[0] >> 2) * 512; pkt->pos = pos; diff --git a/libavformat/g722.c b/libavformat/g722.c index 1a87c7d28c..2feec01211 100644 --- a/libavformat/g722.c +++ b/libavformat/g722.c @@ -32,17 +32,17 @@ static int g722_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_G722; - st->codec->sample_rate = 16000; - st->codec->channels = 1; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_G722; + st->codecpar->sample_rate = 16000; + st->codecpar->channels = 1; - st->codec->bits_per_coded_sample = - av_get_bits_per_sample(st->codec->codec_id); + st->codecpar->bits_per_coded_sample = + av_get_bits_per_sample(st->codecpar->codec_id); - av_assert0(st->codec->bits_per_coded_sample > 0); + av_assert0(st->codecpar->bits_per_coded_sample > 0); - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } diff --git a/libavformat/g723_1.c b/libavformat/g723_1.c index 661e7bd399..27c8c3951b 100644 --- a/libavformat/g723_1.c +++ b/libavformat/g723_1.c @@ -39,13 +39,13 @@ static av_cold int g723_1_init(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_G723_1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->channels = 1; - st->codec->sample_rate = 8000; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_G723_1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->sample_rate = 8000; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); st->start_time = 0; return 0; diff --git a/libavformat/g729dec.c b/libavformat/g729dec.c index 349a014340..ee855d22d9 100644 --- a/libavformat/g729dec.c +++ b/libavformat/g729dec.c @@ -38,10 +38,10 @@ static int g729_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_G729; - st->codec->sample_rate = 8000; - st->codec->channels = 1; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_G729; + st->codecpar->sample_rate = 8000; + st->codecpar->channels = 1; if (s1 && s1->bit_rate) { s->bit_rate = s1->bit_rate; @@ -53,28 +53,28 @@ static int g729_read_header(AVFormatContext *s) } if (s->bit_rate == 6400) { - st->codec->block_align = 8; + st->codecpar->block_align = 8; } else if (s->bit_rate == 8000) { - st->codec->block_align = 10; + st->codecpar->block_align = 10; } else { av_log(s, AV_LOG_ERROR, "Only 8000 b/s and 6400 b/s bitrates are supported. Provided: %"PRId64" b/s\n", (int64_t)s->bit_rate); return AVERROR_INVALIDDATA; } - avpriv_set_pts_info(st, st->codec->block_align << 3, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, st->codecpar->block_align << 3, 1, st->codecpar->sample_rate); return 0; } static int g729_read_packet(AVFormatContext *s, AVPacket *pkt) { int ret; - ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align); + ret = av_get_packet(s->pb, pkt, s->streams[0]->codecpar->block_align); pkt->stream_index = 0; if (ret < 0) return ret; - pkt->dts = pkt->pts = pkt->pos / s->streams[0]->codec->block_align; + pkt->dts = pkt->pts = pkt->pos / s->streams[0]->codecpar->block_align; return ret; } diff --git a/libavformat/genh.c b/libavformat/genh.c index cb1a02f277..b683e026d1 100644 --- a/libavformat/genh.c +++ b/libavformat/genh.c @@ -52,50 +52,50 @@ static int genh_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->channels = avio_rl32(s->pb); - if (st->codec->channels <= 0) + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->channels = avio_rl32(s->pb); + if (st->codecpar->channels <= 0) return AVERROR_INVALIDDATA; - if (st->codec->channels == 1) - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - else if (st->codec->channels == 2) - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + if (st->codecpar->channels == 1) + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + else if (st->codecpar->channels == 2) + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; align = c->interleave_size = avio_rl32(s->pb); - if (align < 0 || align > INT_MAX / st->codec->channels) + if (align < 0 || align > INT_MAX / st->codecpar->channels) return AVERROR_INVALIDDATA; - st->codec->block_align = align * st->codec->channels; - st->codec->sample_rate = avio_rl32(s->pb); + st->codecpar->block_align = align * st->codecpar->channels; + st->codecpar->sample_rate = avio_rl32(s->pb); avio_skip(s->pb, 4); st->duration = avio_rl32(s->pb); codec = avio_rl32(s->pb); switch (codec) { - case 0: st->codec->codec_id = AV_CODEC_ID_ADPCM_PSX; break; + case 0: st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX; break; case 1: - case 11: st->codec->bits_per_coded_sample = 4; - st->codec->block_align = 36 * st->codec->channels; - st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_WAV; break; - case 2: st->codec->codec_id = AV_CODEC_ID_ADPCM_DTK; break; - case 3: st->codec->codec_id = st->codec->block_align > 0 ? + case 11: st->codecpar->bits_per_coded_sample = 4; + st->codecpar->block_align = 36 * st->codecpar->channels; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_WAV; break; + case 2: st->codecpar->codec_id = AV_CODEC_ID_ADPCM_DTK; break; + case 3: st->codecpar->codec_id = st->codecpar->block_align > 0 ? AV_CODEC_ID_PCM_S16BE_PLANAR : AV_CODEC_ID_PCM_S16BE; break; - case 4: st->codec->codec_id = st->codec->block_align > 0 ? + case 4: st->codecpar->codec_id = st->codecpar->block_align > 0 ? AV_CODEC_ID_PCM_S16LE_PLANAR : AV_CODEC_ID_PCM_S16LE; break; - case 5: st->codec->codec_id = st->codec->block_align > 0 ? + case 5: st->codecpar->codec_id = st->codecpar->block_align > 0 ? AV_CODEC_ID_PCM_S8_PLANAR : AV_CODEC_ID_PCM_S8; break; - case 6: st->codec->codec_id = AV_CODEC_ID_SDX2_DPCM; break; - case 7: ret = ff_alloc_extradata(st->codec, 2); + case 6: st->codecpar->codec_id = AV_CODEC_ID_SDX2_DPCM; break; + case 7: ret = ff_alloc_extradata(st->codecpar, 2); if (ret < 0) return ret; - AV_WL16(st->codec->extradata, 3); - st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_WS; break; - case 10: st->codec->codec_id = AV_CODEC_ID_ADPCM_AICA; break; - case 12: st->codec->codec_id = AV_CODEC_ID_ADPCM_THP; break; - case 13: st->codec->codec_id = AV_CODEC_ID_PCM_U8; break; - case 17: st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_QT; break; + AV_WL16(st->codecpar->extradata, 3); + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_WS; break; + case 10: st->codecpar->codec_id = AV_CODEC_ID_ADPCM_AICA; break; + case 12: st->codecpar->codec_id = AV_CODEC_ID_ADPCM_THP; break; + case 13: st->codecpar->codec_id = AV_CODEC_ID_PCM_U8; break; + case 17: st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_QT; break; default: avpriv_request_sample(s, "codec %d", codec); return AVERROR_PATCHWELCOME; @@ -117,25 +117,25 @@ static int genh_read_header(AVFormatContext *s) coef_splitted[0] = avio_rl32(s->pb); coef_splitted[1] = avio_rl32(s->pb); - if (st->codec->codec_id == AV_CODEC_ID_ADPCM_THP) { - if (st->codec->channels > 2) { - avpriv_request_sample(s, "channels %d>2", st->codec->channels); + if (st->codecpar->codec_id == AV_CODEC_ID_ADPCM_THP) { + if (st->codecpar->channels > 2) { + avpriv_request_sample(s, "channels %d>2", st->codecpar->channels); return AVERROR_PATCHWELCOME; } - ff_alloc_extradata(st->codec, 32 * st->codec->channels); - for (ch = 0; ch < st->codec->channels; ch++) { + ff_alloc_extradata(st->codecpar, 32 * st->codecpar->channels); + for (ch = 0; ch < st->codecpar->channels; ch++) { if (coef_type & 1) { avpriv_request_sample(s, "coef_type & 1"); return AVERROR_PATCHWELCOME; } else { avio_seek(s->pb, coef[ch], SEEK_SET); - avio_read(s->pb, st->codec->extradata + 32 * ch, 32); + avio_read(s->pb, st->codecpar->extradata + 32 * ch, 32); } } if (c->dsp_int_type == 1) { - st->codec->block_align = 8 * st->codec->channels; + st->codecpar->block_align = 8 * st->codecpar->channels; if (c->interleave_size != 1 && c->interleave_size != 2 && c->interleave_size != 4) @@ -145,38 +145,38 @@ static int genh_read_header(AVFormatContext *s) avio_skip(s->pb, start_offset - avio_tell(s->pb)); - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } static int genh_read_packet(AVFormatContext *s, AVPacket *pkt) { - AVCodecContext *codec = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; GENHDemuxContext *c = s->priv_data; int ret; - if (c->dsp_int_type == 1 && codec->codec_id == AV_CODEC_ID_ADPCM_THP && - codec->channels > 1) { + if (c->dsp_int_type == 1 && par->codec_id == AV_CODEC_ID_ADPCM_THP && + par->channels > 1) { int i, ch; if (avio_feof(s->pb)) return AVERROR_EOF; - ret = av_new_packet(pkt, 8 * codec->channels); + ret = av_new_packet(pkt, 8 * par->channels); if (ret < 0) return ret; for (i = 0; i < 8 / c->interleave_size; i++) { - for (ch = 0; ch < codec->channels; ch++) { + for (ch = 0; ch < par->channels; ch++) { pkt->data[ch * 8 + i*c->interleave_size+0] = avio_r8(s->pb); pkt->data[ch * 8 + i*c->interleave_size+1] = avio_r8(s->pb); } } ret = 0; - } else if (codec->codec_id == AV_CODEC_ID_SDX2_DPCM) { - ret = av_get_packet(s->pb, pkt, codec->block_align * 1024); + } else if (par->codec_id == AV_CODEC_ID_SDX2_DPCM) { + ret = av_get_packet(s->pb, pkt, par->block_align * 1024); } else { - ret = av_get_packet(s->pb, pkt, codec->block_align ? codec->block_align : 1024 * codec->channels); + ret = av_get_packet(s->pb, pkt, par->block_align ? par->block_align : 1024 * par->channels); } pkt->stream_index = 0; diff --git a/libavformat/gif.c b/libavformat/gif.c index 6537e557d6..91cd40db5c 100644 --- a/libavformat/gif.c +++ b/libavformat/gif.c @@ -50,12 +50,12 @@ static int get_palette_transparency_index(const uint32_t *palette) return smallest_alpha < 128 ? transparent_color_index : -1; } -static int gif_image_write_header(AVIOContext *pb, const AVCodecContext *avctx, +static int gif_image_write_header(AVIOContext *pb, AVStream *st, int loop_count, uint32_t *palette) { int i; int64_t aspect = 0; - const AVRational sar = avctx->sample_aspect_ratio; + const AVRational sar = st->sample_aspect_ratio; if (sar.num > 0 && sar.den > 0) { aspect = sar.num * 64LL / sar.den - 15; @@ -65,8 +65,8 @@ static int gif_image_write_header(AVIOContext *pb, const AVCodecContext *avctx, avio_write(pb, "GIF", 3); avio_write(pb, "89a", 3); - avio_wl16(pb, avctx->width); - avio_wl16(pb, avctx->height); + avio_wl16(pb, st->codecpar->width); + avio_wl16(pb, st->codecpar->height); if (palette) { const int bcid = get_palette_transparency_index(palette); @@ -112,26 +112,26 @@ typedef struct GIFContext { static int gif_write_header(AVFormatContext *s) { GIFContext *gif = s->priv_data; - AVCodecContext *video_enc; + AVCodecParameters *video_par; uint32_t palette[AVPALETTE_COUNT]; if (s->nb_streams != 1 || - s->streams[0]->codec->codec_type != AVMEDIA_TYPE_VIDEO || - s->streams[0]->codec->codec_id != AV_CODEC_ID_GIF) { + s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO || + s->streams[0]->codecpar->codec_id != AV_CODEC_ID_GIF) { av_log(s, AV_LOG_ERROR, "GIF muxer supports only a single video GIF stream.\n"); return AVERROR(EINVAL); } - video_enc = s->streams[0]->codec; + video_par = s->streams[0]->codecpar; avpriv_set_pts_info(s->streams[0], 64, 1, 100); - if (avpriv_set_systematic_pal2(palette, video_enc->pix_fmt) < 0) { - av_assert0(video_enc->pix_fmt == AV_PIX_FMT_PAL8); + if (avpriv_set_systematic_pal2(palette, video_par->format) < 0) { + av_assert0(video_par->format == AV_PIX_FMT_PAL8); /* delay header writing: we wait for the first palette to put it * globally */ } else { - gif_image_write_header(s->pb, video_enc, gif->loop, palette); + gif_image_write_header(s->pb, s->streams[0], gif->loop, palette); } return 0; @@ -183,7 +183,7 @@ static int flush_packet(AVFormatContext *s, AVPacket *new) static int gif_write_packet(AVFormatContext *s, AVPacket *pkt) { GIFContext *gif = s->priv_data; - const AVCodecContext *video_enc = s->streams[0]->codec; + AVStream *video_st = s->streams[0]; if (!gif->prev_pkt) { gif->prev_pkt = av_malloc(sizeof(*gif->prev_pkt)); @@ -191,7 +191,7 @@ static int gif_write_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(ENOMEM); /* Write the first palette as global palette */ - if (video_enc->pix_fmt == AV_PIX_FMT_PAL8) { + if (video_st->codecpar->format == AV_PIX_FMT_PAL8) { int size; void *palette = av_packet_get_side_data(pkt, AV_PKT_DATA_PALETTE, &size); @@ -203,7 +203,7 @@ static int gif_write_packet(AVFormatContext *s, AVPacket *pkt) av_log(s, AV_LOG_ERROR, "Invalid palette extradata\n"); return AVERROR_INVALIDDATA; } - gif_image_write_header(s->pb, video_enc, gif->loop, palette); + gif_image_write_header(s->pb, video_st, gif->loop, palette); } return av_copy_packet(gif->prev_pkt, pkt); diff --git a/libavformat/gifdec.c b/libavformat/gifdec.c index 48bd603dd0..8993ca615c 100644 --- a/libavformat/gifdec.c +++ b/libavformat/gifdec.c @@ -118,10 +118,10 @@ static int gif_read_header(AVFormatContext *s) /* GIF format operates with time in "hundredths of second", * therefore timebase is 1/100 */ avpriv_set_pts_info(st, 64, 1, 100); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_GIF; - st->codec->width = width; - st->codec->height = height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_GIF; + st->codecpar->width = width; + st->codecpar->height = height; /* jump to start because gif decoder needs header data too */ if (avio_seek(pb, 0, SEEK_SET) != 0) diff --git a/libavformat/gsmdec.c b/libavformat/gsmdec.c index 267ad6fe87..1627106a22 100644 --- a/libavformat/gsmdec.c +++ b/libavformat/gsmdec.c @@ -78,12 +78,12 @@ static int gsm_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->iformat->raw_codec_id; - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->sample_rate = c->sample_rate; - st->codec->bit_rate = GSM_BLOCK_SIZE * 8 * c->sample_rate / GSM_BLOCK_SAMPLES; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = s->iformat->raw_codec_id; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->sample_rate = c->sample_rate; + st->codecpar->bit_rate = GSM_BLOCK_SIZE * 8 * c->sample_rate / GSM_BLOCK_SAMPLES; avpriv_set_pts_info(st, 64, GSM_BLOCK_SAMPLES, GSM_SAMPLE_RATE); diff --git a/libavformat/gxf.c b/libavformat/gxf.c index d9b629d7de..399f745bc7 100644 --- a/libavformat/gxf.c +++ b/libavformat/gxf.c @@ -114,77 +114,77 @@ static int get_sindex(AVFormatContext *s, int id, int format) { switch (format) { case 3: case 4: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MJPEG; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MJPEG; break; case 13: case 14: case 15: case 16: case 25: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_DVVIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_DVVIDEO; break; case 11: case 12: case 20: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MPEG2VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MPEG2VIDEO; st->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. break; case 22: case 23: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MPEG1VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MPEG1VIDEO; st->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. break; case 9: - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_PCM_S24LE; - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->sample_rate = 48000; - st->codec->bit_rate = 3 * 1 * 48000 * 8; - st->codec->block_align = 3 * 1; - st->codec->bits_per_coded_sample = 24; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->sample_rate = 48000; + st->codecpar->bit_rate = 3 * 1 * 48000 * 8; + st->codecpar->block_align = 3 * 1; + st->codecpar->bits_per_coded_sample = 24; break; case 10: - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->sample_rate = 48000; - st->codec->bit_rate = 2 * 1 * 48000 * 8; - st->codec->block_align = 2 * 1; - st->codec->bits_per_coded_sample = 16; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->sample_rate = 48000; + st->codecpar->bit_rate = 2 * 1 * 48000 * 8; + st->codecpar->block_align = 2 * 1; + st->codecpar->bits_per_coded_sample = 16; break; case 17: - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_AC3; - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; - st->codec->sample_rate = 48000; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_AC3; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->sample_rate = 48000; break; case 26: /* AVCi50 / AVCi100 (AVC Intra) */ case 29: /* AVCHD */ - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_H264; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_H264; st->need_parsing = AVSTREAM_PARSE_HEADERS; break; // timecode tracks: case 7: case 8: case 24: - st->codec->codec_type = AVMEDIA_TYPE_DATA; - st->codec->codec_id = AV_CODEC_ID_NONE; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_id = AV_CODEC_ID_NONE; break; case 30: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_DNXHD; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_DNXHD; break; default: - st->codec->codec_type = AVMEDIA_TYPE_UNKNOWN; - st->codec->codec_id = AV_CODEC_ID_NONE; + st->codecpar->codec_type = AVMEDIA_TYPE_UNKNOWN; + st->codecpar->codec_id = AV_CODEC_ID_NONE; break; } return s->nb_streams - 1; @@ -532,11 +532,11 @@ static int gxf_packet(AVFormatContext *s, AVPacket *pkt) { avio_rb32(pb); // "timeline" field number avio_r8(pb); // flags avio_r8(pb); // reserved - if (st->codec->codec_id == AV_CODEC_ID_PCM_S24LE || - st->codec->codec_id == AV_CODEC_ID_PCM_S16LE) { + if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S24LE || + st->codecpar->codec_id == AV_CODEC_ID_PCM_S16LE) { int first = field_info >> 16; int last = field_info & 0xffff; // last is exclusive - int bps = av_get_bits_per_sample(st->codec->codec_id)>>3; + int bps = av_get_bits_per_sample(st->codecpar->codec_id)>>3; if (first <= last && last*bps <= pkt_len) { avio_skip(pb, first*bps); skip = pkt_len - last*bps; @@ -551,7 +551,7 @@ static int gxf_packet(AVFormatContext *s, AVPacket *pkt) { pkt->dts = field_nr; //set duration manually for DV or else lavf misdetects the frame rate - if (st->codec->codec_id == AV_CODEC_ID_DVVIDEO) + if (st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO) pkt->duration = si->fields_per_frame; return ret; diff --git a/libavformat/gxfenc.c b/libavformat/gxfenc.c index 8229fe9500..0a40ded2bd 100644 --- a/libavformat/gxfenc.c +++ b/libavformat/gxfenc.c @@ -124,7 +124,7 @@ static int gxf_find_lines_index(AVStream *st) int i; for (i = 0; i < 6; ++i) { - if (st->codec->height == gxf_lines_tab[i].height) { + if (st->codecpar->height == gxf_lines_tab[i].height) { sc->lines_index = gxf_lines_tab[i].index; return 0; } @@ -198,18 +198,18 @@ static int gxf_write_mpeg_auxiliary(AVIOContext *pb, AVStream *st) if (sc->b_per_i_or_p > 9) sc->b_per_i_or_p = 9; /* ensure value won't take more than one char */ } - if (st->codec->height == 512 || st->codec->height == 608) + if (st->codecpar->height == 512 || st->codecpar->height == 608) starting_line = 7; // VBI - else if (st->codec->height == 480) + else if (st->codecpar->height == 480) starting_line = 20; else starting_line = 23; // default PAL size = snprintf(buffer, sizeof(buffer), "Ver 1\nBr %.6f\nIpg 1\nPpi %d\nBpiop %d\n" "Pix 0\nCf %d\nCg %d\nSl %d\nnl16 %d\nVi 1\nf1 1\n", - (float)st->codec->bit_rate, sc->p_per_gop, sc->b_per_i_or_p, - st->codec->pix_fmt == AV_PIX_FMT_YUV422P ? 2 : 1, sc->first_gop_closed == 1, - starting_line, (st->codec->height + 15) / 16); + (float)st->codecpar->bit_rate, sc->p_per_gop, sc->b_per_i_or_p, + st->codecpar->format == AV_PIX_FMT_YUV422P ? 2 : 1, sc->first_gop_closed == 1, + starting_line, (st->codecpar->height + 15) / 16); av_assert0(size < sizeof(buffer)); avio_w8(pb, TRACK_MPG_AUX); avio_w8(pb, size + 1); @@ -223,7 +223,7 @@ static int gxf_write_dv_auxiliary(AVIOContext *pb, AVStream *st) avio_w8(pb, TRACK_AUX); avio_w8(pb, 8); - if (st->codec->pix_fmt == AV_PIX_FMT_YUV420P) + if (st->codecpar->format == AV_PIX_FMT_YUV420P) track_aux_data |= 0x01; /* marks stream as DVCAM instead of DVPRO */ track_aux_data |= 0x40000000; /* aux data is valid */ avio_wl64(pb, track_aux_data); @@ -520,7 +520,7 @@ static int gxf_write_umf_media_mpeg(AVIOContext *pb, AVStream *st) { GXFStreamContext *sc = st->priv_data; - if (st->codec->pix_fmt == AV_PIX_FMT_YUV422P) + if (st->codecpar->format == AV_PIX_FMT_YUV422P) avio_wl32(pb, 2); else avio_wl32(pb, 1); /* default to 420 */ @@ -529,9 +529,9 @@ static int gxf_write_umf_media_mpeg(AVIOContext *pb, AVStream *st) avio_wl32(pb, 1); /* I picture per GOP */ avio_wl32(pb, sc->p_per_gop); avio_wl32(pb, sc->b_per_i_or_p); - if (st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO) + if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) avio_wl32(pb, 2); - else if (st->codec->codec_id == AV_CODEC_ID_MPEG1VIDEO) + else if (st->codecpar->codec_id == AV_CODEC_ID_MPEG1VIDEO) avio_wl32(pb, 1); else avio_wl32(pb, 0); @@ -556,7 +556,7 @@ static int gxf_write_umf_media_dv(AVIOContext *pb, GXFStreamContext *sc, AVStrea { int dv_umf_data = 0; - if (st->codec->pix_fmt == AV_PIX_FMT_YUV420P) + if (st->codecpar->format == AV_PIX_FMT_YUV420P) dv_umf_data |= 0x20; /* marks as DVCAM instead of DVPRO */ avio_wl32(pb, dv_umf_data); avio_wl32(pb, 0); @@ -620,7 +620,7 @@ static int gxf_write_umf_media_description(AVFormatContext *s) gxf_write_umf_media_timecode(pb, gxf->tc.drop); else { AVStream *st = s->streams[i]; - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_MPEG1VIDEO: case AV_CODEC_ID_MPEG2VIDEO: gxf_write_umf_media_mpeg(pb, st); @@ -722,22 +722,22 @@ static int gxf_write_header(AVFormatContext *s) return AVERROR(ENOMEM); st->priv_data = sc; - sc->media_type = ff_codec_get_tag(gxf_media_types, st->codec->codec_id); - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - if (st->codec->codec_id != AV_CODEC_ID_PCM_S16LE) { + sc->media_type = ff_codec_get_tag(gxf_media_types, st->codecpar->codec_id); + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_id != AV_CODEC_ID_PCM_S16LE) { av_log(s, AV_LOG_ERROR, "only 16 BIT PCM LE allowed for now\n"); return -1; } - if (st->codec->sample_rate != 48000) { + if (st->codecpar->sample_rate != 48000) { av_log(s, AV_LOG_ERROR, "only 48000hz sampling rate is allowed\n"); return -1; } - if (st->codec->channels != 1) { + if (st->codecpar->channels != 1) { av_log(s, AV_LOG_ERROR, "only mono tracks are allowed\n"); return -1; } sc->track_type = 2; - sc->sample_rate = st->codec->sample_rate; + sc->sample_rate = st->codecpar->sample_rate; avpriv_set_pts_info(st, 64, 1, sc->sample_rate); sc->sample_size = 16; sc->frame_rate_index = -2; @@ -746,18 +746,18 @@ static int gxf_write_header(AVFormatContext *s) gxf->audio_tracks++; gxf->flags |= 0x04000000; /* audio is 16 bit pcm */ media_info = 'A'; - } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (i != 0) { av_log(s, AV_LOG_ERROR, "video stream must be the first track\n"); return -1; } /* FIXME check from time_base ? */ - if (st->codec->height == 480 || st->codec->height == 512) { /* NTSC or NTSC+VBI */ + if (st->codecpar->height == 480 || st->codecpar->height == 512) { /* NTSC or NTSC+VBI */ sc->frame_rate_index = 5; sc->sample_rate = 60; gxf->flags |= 0x00000080; gxf->time_base = (AVRational){ 1001, 60000 }; - } else if (st->codec->height == 576 || st->codec->height == 608) { /* PAL or PAL+VBI */ + } else if (st->codecpar->height == 576 || st->codecpar->height == 608) { /* PAL or PAL+VBI */ sc->frame_rate_index = 6; sc->media_type++; sc->sample_rate = 50; @@ -773,12 +773,12 @@ static int gxf_write_header(AVFormatContext *s) avpriv_set_pts_info(st, 64, gxf->time_base.num, gxf->time_base.den); if (gxf_find_lines_index(st) < 0) sc->lines_index = -1; - sc->sample_size = st->codec->bit_rate; + sc->sample_size = st->codecpar->bit_rate; sc->fields = 2; /* interlaced */ vsc = sc; - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_MJPEG: sc->track_type = 1; gxf->flags |= 0x00004000; @@ -797,7 +797,7 @@ static int gxf_write_header(AVFormatContext *s) media_info = 'M'; break; case AV_CODEC_ID_DVVIDEO: - if (st->codec->pix_fmt == AV_PIX_FMT_YUV422P) { + if (st->codecpar->format == AV_PIX_FMT_YUV422P) { sc->media_type += 2; sc->track_type = 6; gxf->flags |= 0x00002000; @@ -903,7 +903,7 @@ static int gxf_write_media_preamble(AVFormatContext *s, AVPacket *pkt, int size) /* If the video is frame-encoded, the frame numbers shall be represented by * even field numbers. * see SMPTE360M-2004 6.4.2.1.3 Media field number */ - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { field_nb = gxf->nb_fields; } else { field_nb = av_rescale_rnd(pkt->dts, gxf->time_base.den, @@ -913,10 +913,10 @@ static int gxf_write_media_preamble(AVFormatContext *s, AVPacket *pkt, int size) avio_w8(pb, sc->media_type); avio_w8(pb, st->index); avio_wb32(pb, field_nb); - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { avio_wb16(pb, 0); avio_wb16(pb, size / 2); - } else if (st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) { int frame_type = gxf_parse_mpeg_frame(sc, pkt->data, pkt->size); if (frame_type == AV_PICTURE_TYPE_I) { avio_w8(pb, 0x0d); @@ -929,7 +929,7 @@ static int gxf_write_media_preamble(AVFormatContext *s, AVPacket *pkt, int size) sc->pframes++; } avio_wb24(pb, size); - } else if (st->codec->codec_id == AV_CODEC_ID_DVVIDEO) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO) { avio_w8(pb, size / 4096); avio_wb24(pb, 0); } else @@ -951,15 +951,15 @@ static int gxf_write_packet(AVFormatContext *s, AVPacket *pkt) int ret; gxf_write_packet_header(pb, PKT_MEDIA); - if (st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */ + if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */ padding = 4 - pkt->size % 4; - else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) + else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) padding = GXF_AUDIO_PACKET_SIZE - pkt->size; gxf_write_media_preamble(s, pkt, pkt->size + padding); avio_write(pb, pkt->data, pkt->size); gxf_write_padding(pb, padding); - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (!(gxf->flt_entries_nb % 500)) { int err; if ((err = av_reallocp_array(&gxf->flt_entries, @@ -997,7 +997,7 @@ static int gxf_compare_field_nb(AVFormatContext *s, AVPacket *next, AVPacket *cu for (i = 0; i < 2; i++) { AVStream *st = s->streams[pkt[i]->stream_index]; sc[i] = st->priv_data; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { field_nb[i] = av_rescale_rnd(pkt[i]->dts, gxf->time_base.den, (int64_t)48000*gxf->time_base.num, AV_ROUND_UP); field_nb[i] &= ~1; // compare against even field number because audio must be before video @@ -1011,7 +1011,7 @@ static int gxf_compare_field_nb(AVFormatContext *s, AVPacket *next, AVPacket *cu static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) { - if (pkt && s->streams[pkt->stream_index]->codec->codec_type == AVMEDIA_TYPE_VIDEO) + if (pkt && s->streams[pkt->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) pkt->duration = 2; // enforce 2 fields return ff_audio_rechunk_interleave(s, out, pkt, flush, ff_interleave_packet_per_dts, gxf_compare_field_nb); diff --git a/libavformat/hdsenc.c b/libavformat/hdsenc.c index 3e6e821a82..e56b3c4dc1 100644 --- a/libavformat/hdsenc.c +++ b/libavformat/hdsenc.c @@ -340,18 +340,18 @@ static int hds_write_header(AVFormatContext *s) AVFormatContext *ctx; AVStream *st = s->streams[i]; - if (!st->codec->bit_rate) { + if (!st->codecpar->bit_rate) { av_log(s, AV_LOG_ERROR, "No bit rate set for stream %d\n", i); ret = AVERROR(EINVAL); goto fail; } - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (os->has_video) { c->nb_streams++; os++; } os->has_video = 1; - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { if (os->has_audio) { c->nb_streams++; os++; @@ -362,7 +362,7 @@ static int hds_write_header(AVFormatContext *s) ret = AVERROR(EINVAL); goto fail; } - os->bitrate += s->streams[i]->codec->bit_rate; + os->bitrate += s->streams[i]->codecpar->bit_rate; if (!os->ctx) { os->first_stream = i; @@ -391,8 +391,8 @@ static int hds_write_header(AVFormatContext *s) ret = AVERROR(ENOMEM); goto fail; } - avcodec_copy_context(st->codec, s->streams[i]->codec); - st->codec->codec_tag = 0; + avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar); + st->codecpar->codec_tag = 0; st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio; st->time_base = s->streams[i]->time_base; } @@ -519,7 +519,7 @@ static int hds_write_packet(AVFormatContext *s, AVPacket *pkt) if (st->first_dts == AV_NOPTS_VALUE) st->first_dts = pkt->dts; - if ((!os->has_video || st->codec->codec_type == AVMEDIA_TYPE_VIDEO) && + if ((!os->has_video || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && av_compare_ts(pkt->dts - st->first_dts, st->time_base, end_dts, AV_TIME_BASE_Q) >= 0 && pkt->flags & AV_PKT_FLAG_KEY && os->packets_written) { diff --git a/libavformat/hls.c b/libavformat/hls.c index fb87954316..7953e825bb 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -1384,7 +1384,7 @@ static void add_metadata_from_renditions(AVFormatContext *s, struct playlist *pl for (i = 0; i < pls->ctx->nb_streams; i++) { AVStream *st = s->streams[pls->stream_offset + i]; - if (st->codec->codec_type != type) + if (st->codecpar->codec_type != type) continue; for (; rend_idx < pls->n_renditions; rend_idx++) { @@ -1659,7 +1659,7 @@ static int hls_read_header(AVFormatContext *s) } st->id = i; - avcodec_copy_context(st->codec, pls->ctx->streams[j]->codec); + avcodec_parameters_copy(st->codecpar, pls->ctx->streams[j]->codecpar); if (pls->is_id3_timestamped) /* custom timestamps via id3 */ avpriv_set_pts_info(st, 33, 1, MPEG_TIME_BASE); diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index fd36b213fd..a9fa5d8aef 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -296,14 +296,14 @@ static int hls_mux_init(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st; AVFormatContext *loc; - if (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) + if (s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) loc = vtt_oc; else loc = oc; if (!(st = avformat_new_stream(loc, NULL))) return AVERROR(ENOMEM); - avcodec_copy_context(st->codec, s->streams[i]->codec); + avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar); st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio; st->time_base = s->streams[i]->time_base; } @@ -659,9 +659,9 @@ static int hls_write_header(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { hls->has_video += - s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO; + s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO; hls->has_subtitle += - s->streams[i]->codec->codec_type == AVMEDIA_TYPE_SUBTITLE; + s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE; } if (hls->has_video > 1) @@ -763,7 +763,7 @@ static int hls_write_header(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *inner_st; AVStream *outer_st = s->streams[i]; - if (outer_st->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) + if (outer_st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) inner_st = hls->avf->streams[i]; else if (hls->vtt_avf) inner_st = hls->vtt_avf->streams[0]; @@ -799,7 +799,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) int ret, can_split = 1; int stream_index = 0; - if( st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE ) { + if( st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE ) { oc = hls->vtt_avf; stream_index = 0; } else { @@ -812,9 +812,9 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) } if (hls->has_video) { - can_split = st->codec->codec_type == AVMEDIA_TYPE_VIDEO && + can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && pkt->flags & AV_PKT_FLAG_KEY; - is_ref_pkt = st->codec->codec_type == AVMEDIA_TYPE_VIDEO; + is_ref_pkt = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO; } if (pkt->pts == AV_NOPTS_VALUE) is_ref_pkt = can_split = 0; @@ -853,7 +853,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) if (ret < 0) return ret; - if( st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE ) + if( st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE ) oc = hls->vtt_avf; else oc = hls->avf; diff --git a/libavformat/hnm.c b/libavformat/hnm.c index 8bd8097bf7..24d4e808a5 100644 --- a/libavformat/hnm.c +++ b/libavformat/hnm.c @@ -108,15 +108,15 @@ static int hnm_read_header(AVFormatContext *s) if (!(vst = avformat_new_stream(s, NULL))) return AVERROR(ENOMEM); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_HNM4_VIDEO; - vst->codec->codec_tag = 0; - vst->codec->width = hnm->width; - vst->codec->height = hnm->height; - vst->codec->extradata = av_mallocz(1); - - vst->codec->extradata_size = 1; - memcpy(vst->codec->extradata, &hnm->version, 1); + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_HNM4_VIDEO; + vst->codecpar->codec_tag = 0; + vst->codecpar->width = hnm->width; + vst->codecpar->height = hnm->height; + vst->codecpar->extradata = av_mallocz(1); + + vst->codecpar->extradata_size = 1; + memcpy(vst->codecpar->extradata, &hnm->version, 1); vst->start_time = 0; diff --git a/libavformat/icodec.c b/libavformat/icodec.c index 17acfb4b2f..8019a35f44 100644 --- a/libavformat/icodec.c +++ b/libavformat/icodec.c @@ -99,9 +99,9 @@ static int read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->width = avio_r8(pb); - st->codec->height = avio_r8(pb); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->width = avio_r8(pb); + st->codecpar->height = avio_r8(pb); ico->images[i].nb_pal = avio_r8(pb); if (ico->images[i].nb_pal == 255) ico->images[i].nb_pal = 0; @@ -117,20 +117,20 @@ static int read_header(AVFormatContext *s) codec = avio_rl32(pb); switch (codec) { case MKTAG(0x89, 'P', 'N', 'G'): - st->codec->codec_id = AV_CODEC_ID_PNG; - st->codec->width = 0; - st->codec->height = 0; + st->codecpar->codec_id = AV_CODEC_ID_PNG; + st->codecpar->width = 0; + st->codecpar->height = 0; break; case 40: if (ico->images[i].size < 40) return AVERROR_INVALIDDATA; - st->codec->codec_id = AV_CODEC_ID_BMP; + st->codecpar->codec_id = AV_CODEC_ID_BMP; tmp = avio_rl32(pb); if (tmp) - st->codec->width = tmp; + st->codecpar->width = tmp; tmp = avio_rl32(pb); if (tmp) - st->codec->height = tmp / 2; + st->codecpar->height = tmp / 2; break; default: avpriv_request_sample(s, "codec %d", codec); @@ -157,7 +157,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) if ((ret = avio_seek(pb, image->offset, SEEK_SET)) < 0) return ret; - if (s->streams[ico->current_image]->codec->codec_id == AV_CODEC_ID_PNG) { + if (s->streams[ico->current_image]->codecpar->codec_id == AV_CODEC_ID_PNG) { if ((ret = av_get_packet(pb, pkt, image->size)) < 0) return ret; } else { @@ -177,13 +177,13 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) if ((ret = avio_read(pb, buf, image->size)) < 0) return ret; - st->codec->bits_per_coded_sample = AV_RL16(buf + 14); + st->codecpar->bits_per_coded_sample = AV_RL16(buf + 14); if (AV_RL32(buf + 32)) image->nb_pal = AV_RL32(buf + 32); - if (st->codec->bits_per_coded_sample <= 8 && !image->nb_pal) { - image->nb_pal = 1 << st->codec->bits_per_coded_sample; + if (st->codecpar->bits_per_coded_sample <= 8 && !image->nb_pal) { + image->nb_pal = 1 << st->codecpar->bits_per_coded_sample; AV_WL32(buf + 32, image->nb_pal); } diff --git a/libavformat/icoenc.c b/libavformat/icoenc.c index 53d4420f37..a7ada19fcd 100644 --- a/libavformat/icoenc.c +++ b/libavformat/icoenc.c @@ -42,33 +42,33 @@ typedef struct { IcoImage *images; } IcoMuxContext; -static int ico_check_attributes(AVFormatContext *s, const AVCodecContext *c) +static int ico_check_attributes(AVFormatContext *s, const AVCodecParameters *p) { - if (c->codec_id == AV_CODEC_ID_BMP) { - if (c->pix_fmt == AV_PIX_FMT_PAL8 && AV_PIX_FMT_RGB32 != AV_PIX_FMT_BGRA) { + if (p->codec_id == AV_CODEC_ID_BMP) { + if (p->format == AV_PIX_FMT_PAL8 && AV_PIX_FMT_RGB32 != AV_PIX_FMT_BGRA) { av_log(s, AV_LOG_ERROR, "Wrong endianness for bmp pixel format\n"); return AVERROR(EINVAL); - } else if (c->pix_fmt != AV_PIX_FMT_PAL8 && - c->pix_fmt != AV_PIX_FMT_RGB555LE && - c->pix_fmt != AV_PIX_FMT_BGR24 && - c->pix_fmt != AV_PIX_FMT_BGRA) { + } else if (p->format != AV_PIX_FMT_PAL8 && + p->format != AV_PIX_FMT_RGB555LE && + p->format != AV_PIX_FMT_BGR24 && + p->format != AV_PIX_FMT_BGRA) { av_log(s, AV_LOG_ERROR, "BMP must be 1bit, 4bit, 8bit, 16bit, 24bit, or 32bit\n"); return AVERROR(EINVAL); } - } else if (c->codec_id == AV_CODEC_ID_PNG) { - if (c->pix_fmt != AV_PIX_FMT_RGBA) { + } else if (p->codec_id == AV_CODEC_ID_PNG) { + if (p->format != AV_PIX_FMT_RGBA) { av_log(s, AV_LOG_ERROR, "PNG in ico requires pixel format to be rgba\n"); return AVERROR(EINVAL); } } else { - const AVCodecDescriptor *codesc = avcodec_descriptor_get(c->codec_id); + const AVCodecDescriptor *codesc = avcodec_descriptor_get(p->codec_id); av_log(s, AV_LOG_ERROR, "Unsupported codec %s\n", codesc ? codesc->name : ""); return AVERROR(EINVAL); } - if (c->width > 256 || - c->height > 256) { - av_log(s, AV_LOG_ERROR, "Unsupported dimensions %dx%d (dimensions cannot exceed 256x256)\n", c->width, c->height); + if (p->width > 256 || + p->height > 256) { + av_log(s, AV_LOG_ERROR, "Unsupported dimensions %dx%d (dimensions cannot exceed 256x256)\n", p->width, p->height); return AVERROR(EINVAL); } @@ -95,7 +95,7 @@ static int ico_write_header(AVFormatContext *s) avio_skip(pb, 2); // skip the number of images for (i = 0; i < s->nb_streams; i++) { - if (ret = ico_check_attributes(s, s->streams[i]->codec)) + if (ret = ico_check_attributes(s, s->streams[i]->codecpar)) return ret; // Fill in later when writing trailer... @@ -116,7 +116,7 @@ static int ico_write_packet(AVFormatContext *s, AVPacket *pkt) IcoMuxContext *ico = s->priv_data; IcoImage *image; AVIOContext *pb = s->pb; - AVCodecContext *c = s->streams[pkt->stream_index]->codec; + AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; int i; if (ico->current_image >= ico->nb_images) { @@ -127,11 +127,11 @@ static int ico_write_packet(AVFormatContext *s, AVPacket *pkt) image = &ico->images[ico->current_image++]; image->offset = avio_tell(pb); - image->width = (c->width == 256) ? 0 : c->width; - image->height = (c->height == 256) ? 0 : c->height; + image->width = (par->width == 256) ? 0 : par->width; + image->height = (par->height == 256) ? 0 : par->height; - if (c->codec_id == AV_CODEC_ID_PNG) { - image->bits = c->bits_per_coded_sample; + if (par->codec_id == AV_CODEC_ID_PNG) { + image->bits = par->bits_per_coded_sample; image->size = pkt->size; avio_write(pb, pkt->data, pkt->size); @@ -142,13 +142,13 @@ static int ico_write_packet(AVFormatContext *s, AVPacket *pkt) } image->bits = AV_RL16(pkt->data + 28); // allows things like 1bit and 4bit images to be preserved - image->size = pkt->size - 14 + c->height * (c->width + 7) / 8; + image->size = pkt->size - 14 + par->height * (par->width + 7) / 8; avio_write(pb, pkt->data + 14, 8); // Skip the BITMAPFILEHEADER header avio_wl32(pb, AV_RL32(pkt->data + 22) * 2); // rewrite height as 2 * height avio_write(pb, pkt->data + 26, pkt->size - 26); - for (i = 0; i < c->height * (c->width + 7) / 8; ++i) + for (i = 0; i < par->height * (par->width + 7) / 8; ++i) avio_w8(pb, 0x00); // Write bitmask (opaque) } @@ -169,8 +169,8 @@ static int ico_write_trailer(AVFormatContext *s) avio_w8(pb, ico->images[i].width); avio_w8(pb, ico->images[i].height); - if (s->streams[i]->codec->codec_id == AV_CODEC_ID_BMP && - s->streams[i]->codec->pix_fmt == AV_PIX_FMT_PAL8) { + if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_BMP && + s->streams[i]->codecpar->format == AV_PIX_FMT_PAL8) { avio_w8(pb, (ico->images[i].bits >= 8) ? 0 : 1 << ico->images[i].bits); } else { avio_w8(pb, 0); diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c index addf937afd..46b939432a 100644 --- a/libavformat/id3v2.c +++ b/libavformat/id3v2.c @@ -1091,11 +1091,11 @@ int ff_id3v2_parse_apic(AVFormatContext *s, ID3v2ExtraMeta **extra_meta) return AVERROR(ENOMEM); st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = apic->id; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = apic->id; if (AV_RB64(apic->buf->data) == 0x89504e470d0a1a0a) - st->codec->codec_id = AV_CODEC_ID_PNG; + st->codecpar->codec_id = AV_CODEC_ID_PNG; if (apic->description[0]) av_dict_set(&st->metadata, "title", apic->description, 0); diff --git a/libavformat/id3v2enc.c b/libavformat/id3v2enc.c index e4ccdf9fb3..781974128b 100644 --- a/libavformat/id3v2enc.c +++ b/libavformat/id3v2enc.c @@ -269,7 +269,7 @@ int ff_id3v2_write_apic(AVFormatContext *s, ID3v2EncContext *id3, AVPacket *pkt) /* get the mimetype*/ while (mime->id != AV_CODEC_ID_NONE) { - if (mime->id == st->codec->codec_id) { + if (mime->id == st->codecpar->codec_id) { mimetype = mime->str; break; } diff --git a/libavformat/idcin.c b/libavformat/idcin.c index 10afed6fa4..bfc2051d9d 100644 --- a/libavformat/idcin.c +++ b/libavformat/idcin.c @@ -198,14 +198,14 @@ static int idcin_read_header(AVFormatContext *s) avpriv_set_pts_info(st, 33, 1, IDCIN_FPS); st->start_time = 0; idcin->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_IDCIN; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = width; - st->codec->height = height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_IDCIN; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = width; + st->codecpar->height = height; /* load up the Huffman tables into extradata */ - if ((ret = ff_get_extradata(st->codec, pb, HUFFMAN_TABLE_SIZE)) < 0) + if ((ret = ff_get_extradata(st->codecpar, pb, HUFFMAN_TABLE_SIZE)) < 0) return ret; if (idcin->audio_present) { @@ -216,19 +216,19 @@ static int idcin_read_header(AVFormatContext *s) avpriv_set_pts_info(st, 63, 1, sample_rate); st->start_time = 0; idcin->audio_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = 1; - st->codec->channels = channels; - st->codec->channel_layout = channels > 1 ? AV_CH_LAYOUT_STEREO : - AV_CH_LAYOUT_MONO; - st->codec->sample_rate = sample_rate; - st->codec->bits_per_coded_sample = bytes_per_sample * 8; - st->codec->bit_rate = sample_rate * bytes_per_sample * 8 * channels; - st->codec->block_align = idcin->block_align = bytes_per_sample * channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = 1; + st->codecpar->channels = channels; + st->codecpar->channel_layout = channels > 1 ? AV_CH_LAYOUT_STEREO : + AV_CH_LAYOUT_MONO; + st->codecpar->sample_rate = sample_rate; + st->codecpar->bits_per_coded_sample = bytes_per_sample * 8; + st->codecpar->bit_rate = sample_rate * bytes_per_sample * 8 * channels; + st->codecpar->block_align = idcin->block_align = bytes_per_sample * channels; if (bytes_per_sample == 1) - st->codec->codec_id = AV_CODEC_ID_PCM_U8; + st->codecpar->codec_id = AV_CODEC_ID_PCM_U8; else - st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; if (sample_rate % 14 != 0) { idcin->audio_chunk_size1 = (sample_rate / 14) * diff --git a/libavformat/idroqdec.c b/libavformat/idroqdec.c index 76bb3924b1..fe8d5c6fe3 100644 --- a/libavformat/idroqdec.c +++ b/libavformat/idroqdec.c @@ -130,14 +130,14 @@ static int roq_read_packet(AVFormatContext *s, return AVERROR(ENOMEM); avpriv_set_pts_info(st, 63, 1, roq->frame_rate); roq->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_ROQ; - st->codec->codec_tag = 0; /* no fourcc */ + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_ROQ; + st->codecpar->codec_tag = 0; /* no fourcc */ if (avio_read(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != RoQ_CHUNK_PREAMBLE_SIZE) return AVERROR(EIO); - st->codec->width = roq->width = AV_RL16(preamble); - st->codec->height = roq->height = AV_RL16(preamble + 2); + st->codecpar->width = roq->width = AV_RL16(preamble); + st->codecpar->height = roq->height = AV_RL16(preamble + 2); break; } /* don't care about this chunk anymore */ @@ -178,22 +178,22 @@ static int roq_read_packet(AVFormatContext *s, return AVERROR(ENOMEM); avpriv_set_pts_info(st, 32, 1, RoQ_AUDIO_SAMPLE_RATE); roq->audio_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ROQ_DPCM; - st->codec->codec_tag = 0; /* no tag */ + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ROQ_DPCM; + st->codecpar->codec_tag = 0; /* no tag */ if (chunk_type == RoQ_SOUND_STEREO) { - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } else { - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } - roq->audio_channels = st->codec->channels; - st->codec->sample_rate = RoQ_AUDIO_SAMPLE_RATE; - st->codec->bits_per_coded_sample = 16; - st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * - st->codec->bits_per_coded_sample; - st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; + roq->audio_channels = st->codecpar->channels; + st->codecpar->sample_rate = RoQ_AUDIO_SAMPLE_RATE; + st->codecpar->bits_per_coded_sample = 16; + st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate * + st->codecpar->bits_per_coded_sample; + st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample; } case RoQ_QUAD_VQ: if (chunk_type == RoQ_QUAD_VQ) { diff --git a/libavformat/idroqenc.c b/libavformat/idroqenc.c index 28a3aba9d4..8122efef83 100644 --- a/libavformat/idroqenc.c +++ b/libavformat/idroqenc.c @@ -29,25 +29,24 @@ static int roq_write_header(struct AVFormatContext *s) 0x84, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, /* fps: */ 0x1E, 0x00 }; int n; - AVCodecContext *avctx; // set the actual fps for(n=0;nnb_streams;n++) { - if ((avctx=s->streams[n]->codec)->codec_type == AVMEDIA_TYPE_VIDEO) { + if (s->streams[n]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { unsigned int fps; - if (avctx->time_base.num != 1) { - av_log(avctx, AV_LOG_ERROR, "Frame rate must be integer\n"); + if (s->streams[n]->avg_frame_rate.den != 1) { + av_log(s, AV_LOG_ERROR, "Frame rate must be integer\n"); return AVERROR(EINVAL); } - if ((fps=avctx->time_base.den) > 255) { - av_log(avctx, AV_LOG_ERROR, "Frame rate may not exceed 255fps\n"); + if ((fps=s->streams[n]->avg_frame_rate.num) > 255) { + av_log(s, AV_LOG_ERROR, "Frame rate may not exceed 255fps\n"); return AVERROR(EINVAL); } if (fps != 30) { - av_log(avctx, AV_LOG_WARNING, "For vintage compatibility fps must be 30\n"); + av_log(s, AV_LOG_WARNING, "For vintage compatibility fps must be 30\n"); } header[6] = fps; diff --git a/libavformat/iff.c b/libavformat/iff.c index 2889083151..4f1158161d 100644 --- a/libavformat/iff.c +++ b/libavformat/iff.c @@ -262,21 +262,21 @@ static int parse_dsd_prop(AVFormatContext *s, AVStream *st, uint64_t eof) case MKTAG('C','H','N','L'): if (size < 2) return AVERROR_INVALIDDATA; - st->codec->channels = avio_rb16(pb); - if (size < 2 + st->codec->channels * 4) + st->codecpar->channels = avio_rb16(pb); + if (size < 2 + st->codecpar->channels * 4) return AVERROR_INVALIDDATA; - st->codec->channel_layout = 0; - if (st->codec->channels > FF_ARRAY_ELEMS(dsd_layout)) { + st->codecpar->channel_layout = 0; + if (st->codecpar->channels > FF_ARRAY_ELEMS(dsd_layout)) { avpriv_request_sample(s, "channel layout"); break; } - for (i = 0; i < st->codec->channels; i++) + for (i = 0; i < st->codecpar->channels; i++) dsd_layout[i] = avio_rl32(pb); for (i = 0; i < FF_ARRAY_ELEMS(dsd_channel_layout); i++) { const DSDLayoutDesc * d = &dsd_channel_layout[i]; - if (av_get_channel_layout_nb_channels(d->layout) == st->codec->channels && - !memcmp(d->dsd_layout, dsd_layout, st->codec->channels * sizeof(uint32_t))) { - st->codec->channel_layout = d->layout; + if (av_get_channel_layout_nb_channels(d->layout) == st->codecpar->channels && + !memcmp(d->dsd_layout, dsd_layout, st->codecpar->channels * sizeof(uint32_t))) { + st->codecpar->channel_layout = d->layout; break; } } @@ -286,8 +286,8 @@ static int parse_dsd_prop(AVFormatContext *s, AVStream *st, uint64_t eof) if (size < 4) return AVERROR_INVALIDDATA; tag = avio_rl32(pb); - st->codec->codec_id = ff_codec_get_id(dsd_codec_tags, tag); - if (!st->codec->codec_id) { + st->codecpar->codec_id = ff_codec_get_id(dsd_codec_tags, tag); + if (!st->codecpar->codec_id) { av_log(s, AV_LOG_ERROR, "'%c%c%c%c' compression is not supported\n", tag&0xFF, (tag>>8)&0xFF, (tag>>16)&0xFF, (tag>>24)&0xFF); return AVERROR_PATCHWELCOME; @@ -297,7 +297,7 @@ static int parse_dsd_prop(AVFormatContext *s, AVStream *st, uint64_t eof) case MKTAG('F','S',' ',' '): if (size < 4) return AVERROR_INVALIDDATA; - st->codec->sample_rate = avio_rb32(pb) / 8; + st->codecpar->sample_rate = avio_rb32(pb) / 8; break; case MKTAG('I','D','3',' '): @@ -323,8 +323,8 @@ static int parse_dsd_prop(AVFormatContext *s, AVStream *st, uint64_t eof) config = avio_rb16(pb); if (config != 0xFFFF) { if (config < FF_ARRAY_ELEMS(dsd_loudspeaker_config)) - st->codec->channel_layout = dsd_loudspeaker_config[config]; - if (!st->codec->channel_layout) + st->codecpar->channel_layout = dsd_loudspeaker_config[config]; + if (!st->codecpar->channel_layout) avpriv_request_sample(s, "loudspeaker configuration %d", config); } break; @@ -360,15 +360,15 @@ static int iff_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; iff->is_64bit = avio_rl32(pb) == ID_FRM8; avio_skip(pb, iff->is_64bit ? 8 : 4); // codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content - st->codec->codec_tag = avio_rl32(pb); - if (st->codec->codec_tag == ID_ANIM) { + st->codecpar->codec_tag = avio_rl32(pb); + if (st->codecpar->codec_tag == ID_ANIM) { avio_skip(pb, 8); - st->codec->codec_tag = avio_rl32(pb); + st->codecpar->codec_tag = avio_rl32(pb); } iff->bitmap_compression = -1; iff->svx8_compression = -1; @@ -386,12 +386,12 @@ static int iff_read_header(AVFormatContext *s) switch(chunk_id) { case ID_VHDR: - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; if (data_size < 14) return AVERROR_INVALIDDATA; avio_skip(pb, 12); - st->codec->sample_rate = avio_rb16(pb); + st->codecpar->sample_rate = avio_rb16(pb); if (data_size >= 16) { avio_skip(pb, 1); iff->svx8_compression = avio_r8(pb); @@ -399,7 +399,7 @@ static int iff_read_header(AVFormatContext *s) break; case ID_MHDR: - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; if (data_size < 32) return AVERROR_INVALIDDATA; @@ -411,13 +411,13 @@ static int iff_read_header(AVFormatContext *s) if (!den) return AVERROR_INVALIDDATA; avio_skip(pb, 2); - st->codec->sample_rate = num / den; - st->codec->channels = avio_rb16(pb); + st->codecpar->sample_rate = num / den; + st->codecpar->channels = avio_rb16(pb); iff->maud_compression = avio_rb16(pb); - if (st->codec->channels == 1) - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - else if (st->codec->channels == 2) - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + if (st->codecpar->channels == 1) + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + else if (st->codecpar->channels == 2) + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; break; case ID_ABIT: @@ -434,11 +434,11 @@ static int iff_read_header(AVFormatContext *s) if (data_size < 4) return AVERROR_INVALIDDATA; if (avio_rb32(pb) < 6) { - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } else { - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } break; @@ -454,22 +454,22 @@ static int iff_read_header(AVFormatContext *s) data_size); return AVERROR_INVALIDDATA; } - st->codec->extradata_size = data_size + IFF_EXTRA_VIDEO_SIZE; - st->codec->extradata = av_malloc(data_size + IFF_EXTRA_VIDEO_SIZE + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + st->codecpar->extradata_size = data_size + IFF_EXTRA_VIDEO_SIZE; + st->codecpar->extradata = av_malloc(data_size + IFF_EXTRA_VIDEO_SIZE + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - if (avio_read(pb, st->codec->extradata + IFF_EXTRA_VIDEO_SIZE, data_size) < 0) + if (avio_read(pb, st->codecpar->extradata + IFF_EXTRA_VIDEO_SIZE, data_size) < 0) return AVERROR(EIO); break; case ID_BMHD: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; if (data_size <= 8) return AVERROR_INVALIDDATA; - st->codec->width = avio_rb16(pb); - st->codec->height = avio_rb16(pb); + st->codecpar->width = avio_rb16(pb); + st->codecpar->height = avio_rb16(pb); avio_skip(pb, 4); // x, y offset - st->codec->bits_per_coded_sample = avio_r8(pb); + st->codecpar->bits_per_coded_sample = avio_r8(pb); if (data_size >= 10) masking = avio_r8(pb); if (data_size >= 11) @@ -490,15 +490,15 @@ static int iff_read_header(AVFormatContext *s) if ((fmt_size = avio_read(pb, fmt, sizeof(fmt))) < 0) return fmt_size; if (fmt_size == sizeof(deep_rgb24) && !memcmp(fmt, deep_rgb24, sizeof(deep_rgb24))) - st->codec->pix_fmt = AV_PIX_FMT_RGB24; + st->codecpar->format = AV_PIX_FMT_RGB24; else if (fmt_size == sizeof(deep_rgba) && !memcmp(fmt, deep_rgba, sizeof(deep_rgba))) - st->codec->pix_fmt = AV_PIX_FMT_RGBA; + st->codecpar->format = AV_PIX_FMT_RGBA; else if (fmt_size == sizeof(deep_bgra) && !memcmp(fmt, deep_bgra, sizeof(deep_bgra))) - st->codec->pix_fmt = AV_PIX_FMT_BGRA; + st->codecpar->format = AV_PIX_FMT_BGRA; else if (fmt_size == sizeof(deep_argb) && !memcmp(fmt, deep_argb, sizeof(deep_argb))) - st->codec->pix_fmt = AV_PIX_FMT_ARGB; + st->codecpar->format = AV_PIX_FMT_ARGB; else if (fmt_size == sizeof(deep_abgr) && !memcmp(fmt, deep_abgr, sizeof(deep_abgr))) - st->codec->pix_fmt = AV_PIX_FMT_ABGR; + st->codecpar->format = AV_PIX_FMT_ABGR; else { avpriv_request_sample(s, "color format %.16s", fmt); return AVERROR_PATCHWELCOME; @@ -506,22 +506,22 @@ static int iff_read_header(AVFormatContext *s) break; case ID_DGBL: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; if (data_size < 8) return AVERROR_INVALIDDATA; - st->codec->width = avio_rb16(pb); - st->codec->height = avio_rb16(pb); + st->codecpar->width = avio_rb16(pb); + st->codecpar->height = avio_rb16(pb); iff->bitmap_compression = avio_rb16(pb); st->sample_aspect_ratio.num = avio_r8(pb); st->sample_aspect_ratio.den = avio_r8(pb); - st->codec->bits_per_coded_sample = 24; + st->codecpar->bits_per_coded_sample = 24; break; case ID_DLOC: if (data_size < 4) return AVERROR_INVALIDDATA; - st->codec->width = avio_rb16(pb); - st->codec->height = avio_rb16(pb); + st->codecpar->width = avio_rb16(pb); + st->codecpar->height = avio_rb16(pb); break; case ID_TVDC: @@ -545,7 +545,7 @@ static int iff_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; version = avio_rb32(pb); av_log(s, AV_LOG_DEBUG, "DSIFF v%d.%d.%d.%d\n",version >> 24, (version >> 16) & 0xFF, (version >> 8) & 0xFF, version & 0xFF); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; break; case MKTAG('D','I','I','N'): @@ -628,35 +628,35 @@ static int iff_read_header(AVFormatContext *s) avio_seek(pb, iff->body_pos, SEEK_SET); - switch(st->codec->codec_type) { + switch(st->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: - avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 32, 1, st->codecpar->sample_rate); - if (st->codec->codec_tag == ID_16SV) - st->codec->codec_id = AV_CODEC_ID_PCM_S16BE_PLANAR; - else if (st->codec->codec_tag == ID_MAUD) { + if (st->codecpar->codec_tag == ID_16SV) + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE_PLANAR; + else if (st->codecpar->codec_tag == ID_MAUD) { if (iff->maud_bits == 8 && !iff->maud_compression) { - st->codec->codec_id = AV_CODEC_ID_PCM_U8; + st->codecpar->codec_id = AV_CODEC_ID_PCM_U8; } else if (iff->maud_bits == 16 && !iff->maud_compression) { - st->codec->codec_id = AV_CODEC_ID_PCM_S16BE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE; } else if (iff->maud_bits == 8 && iff->maud_compression == 2) { - st->codec->codec_id = AV_CODEC_ID_PCM_ALAW; + st->codecpar->codec_id = AV_CODEC_ID_PCM_ALAW; } else if (iff->maud_bits == 8 && iff->maud_compression == 3) { - st->codec->codec_id = AV_CODEC_ID_PCM_MULAW; + st->codecpar->codec_id = AV_CODEC_ID_PCM_MULAW; } else { avpriv_request_sample(s, "compression %d and bit depth %d", iff->maud_compression, iff->maud_bits); return AVERROR_PATCHWELCOME; } - } else if (st->codec->codec_tag != ID_DSD) { + } else if (st->codecpar->codec_tag != ID_DSD) { switch (iff->svx8_compression) { case COMP_NONE: - st->codec->codec_id = AV_CODEC_ID_PCM_S8_PLANAR; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S8_PLANAR; break; case COMP_FIB: - st->codec->codec_id = AV_CODEC_ID_8SVX_FIB; + st->codecpar->codec_id = AV_CODEC_ID_8SVX_FIB; break; case COMP_EXP: - st->codec->codec_id = AV_CODEC_ID_8SVX_EXP; + st->codecpar->codec_id = AV_CODEC_ID_8SVX_EXP; break; default: av_log(s, AV_LOG_ERROR, @@ -665,29 +665,29 @@ static int iff_read_header(AVFormatContext *s) } } - st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id); - st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * st->codec->bits_per_coded_sample; - st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; + st->codecpar->bits_per_coded_sample = av_get_bits_per_sample(st->codecpar->codec_id); + st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample; + st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample; break; case AVMEDIA_TYPE_VIDEO: - iff->bpp = st->codec->bits_per_coded_sample; + iff->bpp = st->codecpar->bits_per_coded_sample; if ((screenmode & 0x800 /* Hold And Modify */) && iff->bpp <= 8) { iff->ham = iff->bpp > 6 ? 6 : 4; - st->codec->bits_per_coded_sample = 24; + st->codecpar->bits_per_coded_sample = 24; } iff->flags = (screenmode & 0x80 /* Extra HalfBrite */) && iff->bpp <= 8; iff->masking = masking; iff->transparency = transparency; - if (!st->codec->extradata) { - st->codec->extradata_size = IFF_EXTRA_VIDEO_SIZE; - st->codec->extradata = av_malloc(IFF_EXTRA_VIDEO_SIZE + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (!st->codecpar->extradata) { + st->codecpar->extradata_size = IFF_EXTRA_VIDEO_SIZE; + st->codecpar->extradata = av_malloc(IFF_EXTRA_VIDEO_SIZE + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); } - av_assert0(st->codec->extradata_size >= IFF_EXTRA_VIDEO_SIZE); - buf = st->codec->extradata; + av_assert0(st->codecpar->extradata_size >= IFF_EXTRA_VIDEO_SIZE); + buf = st->codecpar->extradata; bytestream_put_be16(&buf, IFF_EXTRA_VIDEO_SIZE); bytestream_put_byte(&buf, iff->bitmap_compression); bytestream_put_byte(&buf, iff->bpp); @@ -696,7 +696,7 @@ static int iff_read_header(AVFormatContext *s) bytestream_put_be16(&buf, iff->transparency); bytestream_put_byte(&buf, iff->masking); bytestream_put_buffer(&buf, iff->tvdc, sizeof(iff->tvdc)); - st->codec->codec_id = AV_CODEC_ID_IFF_ILBM; + st->codecpar->codec_id = AV_CODEC_ID_IFF_ILBM; break; default: return -1; @@ -717,15 +717,15 @@ static int iff_read_packet(AVFormatContext *s, if (pos >= iff->body_end) return AVERROR_EOF; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - if (st->codec->codec_tag == ID_DSD || st->codec->codec_tag == ID_MAUD) { - ret = av_get_packet(pb, pkt, FFMIN(iff->body_end - pos, 1024 * st->codec->block_align)); + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_tag == ID_DSD || st->codecpar->codec_tag == ID_MAUD) { + ret = av_get_packet(pb, pkt, FFMIN(iff->body_end - pos, 1024 * st->codecpar->block_align)); } else { if (iff->body_size > INT_MAX) return AVERROR_INVALIDDATA; ret = av_get_packet(pb, pkt, iff->body_size); } - } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { uint8_t *buf; if (iff->body_size > INT_MAX - 2) diff --git a/libavformat/ilbc.c b/libavformat/ilbc.c index ebee2fb0fa..50e3c3cc76 100644 --- a/libavformat/ilbc.c +++ b/libavformat/ilbc.c @@ -28,22 +28,22 @@ static const char mode30_header[] = "#!iLBC30\n"; static int ilbc_write_header(AVFormatContext *s) { AVIOContext *pb = s->pb; - AVCodecContext *enc; + AVCodecParameters *par; if (s->nb_streams != 1) { av_log(s, AV_LOG_ERROR, "Unsupported number of streams\n"); return AVERROR(EINVAL); } - enc = s->streams[0]->codec; + par = s->streams[0]->codecpar; - if (enc->codec_id != AV_CODEC_ID_ILBC) { + if (par->codec_id != AV_CODEC_ID_ILBC) { av_log(s, AV_LOG_ERROR, "Unsupported codec\n"); return AVERROR(EINVAL); } - if (enc->block_align == 50) { + if (par->block_align == 50) { avio_write(pb, mode30_header, sizeof(mode30_header) - 1); - } else if (enc->block_align == 38) { + } else if (par->block_align == 38) { avio_write(pb, mode20_header, sizeof(mode20_header) - 1); } else { av_log(s, AV_LOG_ERROR, "Unsupported mode\n"); @@ -79,18 +79,18 @@ static int ilbc_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_id = AV_CODEC_ID_ILBC; - st->codec->sample_rate = 8000; - st->codec->channels = 1; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ILBC; + st->codecpar->sample_rate = 8000; + st->codecpar->channels = 1; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; st->start_time = 0; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); if (!memcmp(header, mode20_header, sizeof(mode20_header) - 1)) { - st->codec->block_align = 38; - st->codec->bit_rate = 15200; + st->codecpar->block_align = 38; + st->codecpar->bit_rate = 15200; } else if (!memcmp(header, mode30_header, sizeof(mode30_header) - 1)) { - st->codec->block_align = 50; - st->codec->bit_rate = 13333; + st->codecpar->block_align = 50; + st->codecpar->bit_rate = 13333; } else { av_log(s, AV_LOG_ERROR, "Unrecognized iLBC file header\n"); return AVERROR_INVALIDDATA; @@ -102,16 +102,16 @@ static int ilbc_read_header(AVFormatContext *s) static int ilbc_read_packet(AVFormatContext *s, AVPacket *pkt) { - AVCodecContext *enc = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; int ret; - if ((ret = av_new_packet(pkt, enc->block_align)) < 0) + if ((ret = av_new_packet(pkt, par->block_align)) < 0) return ret; pkt->stream_index = 0; pkt->pos = avio_tell(s->pb); - pkt->duration = enc->block_align == 38 ? 160 : 240; - if ((ret = avio_read(s->pb, pkt->data, enc->block_align)) != enc->block_align) { + pkt->duration = par->block_align == 38 ? 160 : 240; + if ((ret = avio_read(s->pb, pkt->data, par->block_align)) != par->block_align) { av_packet_unref(pkt); return ret < 0 ? ret : AVERROR(EIO); } diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index 6864374897..8dfb8138ad 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -221,8 +221,8 @@ int ff_img_read_header(AVFormatContext *s1) avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num); if (s->width && s->height) { - st->codec->width = s->width; - st->codec->height = s->height; + st->codecpar->width = s->width; + st->codecpar->height = s->height; } if (!s->is_pipe) { @@ -307,18 +307,18 @@ int ff_img_read_header(AVFormatContext *s1) } if (s1->video_codec_id) { - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = s1->video_codec_id; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = s1->video_codec_id; } else if (s1->audio_codec_id) { - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s1->audio_codec_id; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = s1->audio_codec_id; } else if (s1->iformat->raw_codec_id) { - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = s1->iformat->raw_codec_id; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = s1->iformat->raw_codec_id; } else { const char *str = strrchr(s->path, '.'); s->split_planes = str && !av_strcasecmp(str + 1, "y"); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; if (s1->pb) { int probe_buffer_size = 2048; uint8_t *probe_buffer = av_realloc(NULL, probe_buffer_size + AVPROBE_PADDING_SIZE); @@ -346,7 +346,7 @@ int ff_img_read_header(AVFormatContext *s1) !fmt->raw_codec_id) continue; if (fmt->read_probe(&pd) > 0) { - st->codec->codec_id = fmt->raw_codec_id; + st->codecpar->codec_id = fmt->raw_codec_id; break; } } @@ -355,16 +355,16 @@ int ff_img_read_header(AVFormatContext *s1) } else ffio_rewind_with_probe_data(s1->pb, &probe_buffer, probe_buffer_size); } - if (st->codec->codec_id == AV_CODEC_ID_NONE) - st->codec->codec_id = ff_guess_image2_codec(s->path); - if (st->codec->codec_id == AV_CODEC_ID_LJPEG) - st->codec->codec_id = AV_CODEC_ID_MJPEG; - if (st->codec->codec_id == AV_CODEC_ID_ALIAS_PIX) // we cannot distingiush this from BRENDER_PIX - st->codec->codec_id = AV_CODEC_ID_NONE; + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) + st->codecpar->codec_id = ff_guess_image2_codec(s->path); + if (st->codecpar->codec_id == AV_CODEC_ID_LJPEG) + st->codecpar->codec_id = AV_CODEC_ID_MJPEG; + if (st->codecpar->codec_id == AV_CODEC_ID_ALIAS_PIX) // we cannot distingiush this from BRENDER_PIX + st->codecpar->codec_id = AV_CODEC_ID_NONE; } - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && pix_fmt != AV_PIX_FMT_NONE) - st->codec->pix_fmt = pix_fmt; + st->codecpar->format = pix_fmt; return 0; } @@ -377,7 +377,7 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt) int i, res; int size[3] = { 0 }, ret[3] = { 0 }; AVIOContext *f[3] = { NULL }; - AVCodecContext *codec = s1->streams[0]->codec; + AVCodecParameters *par = s1->streams[0]->codecpar; if (!s->is_pipe) { /* loop over input */ @@ -418,7 +418,7 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt) filename[strlen(filename) - 1] = 'U' + i; } - if (codec->codec_id == AV_CODEC_ID_NONE) { + if (par->codec_id == AV_CODEC_ID_NONE) { AVProbeData pd = { 0 }; AVInputFormat *ifmt; uint8_t header[PROBE_BUF_MIN + AVPROBE_PADDING_SIZE]; @@ -436,11 +436,11 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt) ifmt = av_probe_input_format3(&pd, 1, &score); if (ifmt && ifmt->read_packet == ff_img_read_packet && ifmt->raw_codec_id) - codec->codec_id = ifmt->raw_codec_id; + par->codec_id = ifmt->raw_codec_id; } - if (codec->codec_id == AV_CODEC_ID_RAWVIDEO && !codec->width) - infer_size(&codec->width, &codec->height, size[0]); + if (par->codec_id == AV_CODEC_ID_RAWVIDEO && !par->width) + infer_size(&par->width, &par->height, size[0]); } else { f[0] = s1->pb; if (avio_feof(f[0]) && s->loop && s->is_pipe) diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c index ebbac2bf7b..32c68e4d10 100644 --- a/libavformat/img2enc.c +++ b/libavformat/img2enc.c @@ -50,7 +50,7 @@ static int write_header(AVFormatContext *s) { VideoMuxData *img = s->priv_data; AVStream *st = s->streams[0]; - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(st->codec->pix_fmt); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(st->codecpar->format); av_strlcpy(img->path, s->filename, sizeof(img->path)); @@ -60,9 +60,9 @@ static int write_header(AVFormatContext *s) else img->is_pipe = 1; - if (st->codec->codec_id == AV_CODEC_ID_GIF) { + if (st->codecpar->codec_id == AV_CODEC_ID_GIF) { img->muxer = "gif"; - } else if (st->codec->codec_id == AV_CODEC_ID_RAWVIDEO) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_RAWVIDEO) { const char *str = strrchr(img->path, '.'); img->split_planes = str && !av_strcasecmp(str + 1, "y") @@ -80,8 +80,8 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) VideoMuxData *img = s->priv_data; AVIOContext *pb[4]; char filename[1024]; - AVCodecContext *codec = s->streams[pkt->stream_index]->codec; - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(codec->pix_fmt); + AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(par->format); int i; int nb_renames = 0; @@ -123,8 +123,8 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) } if (img->split_planes) { - int ysize = codec->width * codec->height; - int usize = AV_CEIL_RSHIFT(codec->width, desc->log2_chroma_w) * AV_CEIL_RSHIFT(codec->height, desc->log2_chroma_h); + int ysize = par->width * par->height; + int usize = AV_CEIL_RSHIFT(par->width, desc->log2_chroma_w) * AV_CEIL_RSHIFT(par->height, desc->log2_chroma_h); if (desc->comp[0].depth >= 9) { ysize *= 2; usize *= 2; @@ -159,7 +159,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) fmt->pb = pb[0]; if ((ret = av_copy_packet(&pkt2, pkt)) < 0 || (ret = av_dup_packet(&pkt2)) < 0 || - (ret = avcodec_copy_context(st->codec, s->streams[0]->codec)) < 0 || + (ret = avcodec_parameters_copy(st->codecpar, s->streams[0]->codecpar)) < 0 || (ret = avformat_write_header(fmt, NULL)) < 0 || (ret = av_interleaved_write_frame(fmt, &pkt2)) < 0 || (ret = av_write_trailer(fmt)) < 0) { diff --git a/libavformat/internal.h b/libavformat/internal.h index cd390ddf70..1719deb219 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -144,6 +144,22 @@ struct AVStreamInternal { * Whether or not check_bitstream should still be run on each packet */ int bitstream_checked; + + /** + * The codec context used by avformat_find_stream_info, the parser, etc. + */ + AVCodecContext *avctx; + /** + * 1 if avctx has been initialized with the values from the codec parameters + */ + int avctx_inited; + + enum AVCodecID orig_codec_id; + + /** + * Whether the internal avctx needs to be updated from codecpar (after a late change to codecpar) + */ + int need_context_update; }; #ifdef __GNUC__ @@ -497,7 +513,7 @@ static inline int ff_rename(const char *oldpath, const char *newpath, void *logc * @param size size of extradata * @return 0 if OK, AVERROR_xxx on error */ -int ff_alloc_extradata(AVCodecContext *avctx, int size); +int ff_alloc_extradata(AVCodecParameters *par, int size); /** * Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end @@ -506,7 +522,7 @@ int ff_alloc_extradata(AVCodecContext *avctx, int size); * @param size size of extradata * @return >= 0 if OK, AVERROR_xxx on error */ -int ff_get_extradata(AVCodecContext *avctx, AVIOContext *pb, int size); +int ff_get_extradata(AVCodecParameters *par, AVIOContext *pb, int size); /** * add frame for rfps calculation. @@ -581,7 +597,7 @@ int ff_standardize_creation_time(AVFormatContext *s); * non-zero if a new packet was allocated and ppkt has to be freed * CONTAINS_PAL if in addition to a new packet the old contained a palette */ -int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecContext *enc, int expected_stride); +int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecParameters *par, int expected_stride); /** * Retrieves the palette from a packet, either from side data, or diff --git a/libavformat/ipmovie.c b/libavformat/ipmovie.c index bc5d8ccb62..bb34aae749 100644 --- a/libavformat/ipmovie.c +++ b/libavformat/ipmovie.c @@ -221,19 +221,19 @@ static int init_audio(AVFormatContext *s) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 32, 1, ipmovie->audio_sample_rate); ipmovie->audio_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = ipmovie->audio_type; - st->codec->codec_tag = 0; /* no tag */ - st->codec->channels = ipmovie->audio_channels; - st->codec->channel_layout = st->codec->channels == 1 ? AV_CH_LAYOUT_MONO : + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = ipmovie->audio_type; + st->codecpar->codec_tag = 0; /* no tag */ + st->codecpar->channels = ipmovie->audio_channels; + st->codecpar->channel_layout = st->codecpar->channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; - st->codec->sample_rate = ipmovie->audio_sample_rate; - st->codec->bits_per_coded_sample = ipmovie->audio_bits; - st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * - st->codec->bits_per_coded_sample; - if (st->codec->codec_id == AV_CODEC_ID_INTERPLAY_DPCM) - st->codec->bit_rate /= 2; - st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; + st->codecpar->sample_rate = ipmovie->audio_sample_rate; + st->codecpar->bits_per_coded_sample = ipmovie->audio_bits; + st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate * + st->codecpar->bits_per_coded_sample; + if (st->codecpar->codec_id == AV_CODEC_ID_INTERPLAY_DPCM) + st->codecpar->bit_rate /= 2; + st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample; return 0; } @@ -623,12 +623,12 @@ static int ipmovie_read_header(AVFormatContext *s) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 63, 1, 1000000); ipmovie->video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_INTERPLAY_VIDEO; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = ipmovie->video_width; - st->codec->height = ipmovie->video_height; - st->codec->bits_per_coded_sample = ipmovie->video_bpp; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_INTERPLAY_VIDEO; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = ipmovie->video_width; + st->codecpar->height = ipmovie->video_height; + st->codecpar->bits_per_coded_sample = ipmovie->video_bpp; if (ipmovie->audio_type) { return init_audio(s); diff --git a/libavformat/ircamdec.c b/libavformat/ircamdec.c index f9533ec4a5..59f3a49411 100644 --- a/libavformat/ircamdec.c +++ b/libavformat/ircamdec.c @@ -85,19 +85,19 @@ static int ircam_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->channels = channels; - st->codec->sample_rate = sample_rate; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->channels = channels; + st->codecpar->sample_rate = sample_rate; - st->codec->codec_id = ff_codec_get_id(tags, tag); - if (st->codec->codec_id == AV_CODEC_ID_NONE) { + st->codecpar->codec_id = ff_codec_get_id(tags, tag); + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) { av_log(s, AV_LOG_ERROR, "unknown tag %X\n", tag); return AVERROR_INVALIDDATA; } - st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id); - st->codec->block_align = st->codec->bits_per_coded_sample * st->codec->channels / 8; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + st->codecpar->bits_per_coded_sample = av_get_bits_per_sample(st->codecpar->codec_id); + st->codecpar->block_align = st->codecpar->bits_per_coded_sample * st->codecpar->channels / 8; + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); avio_skip(s->pb, 1008); return 0; diff --git a/libavformat/ircamenc.c b/libavformat/ircamenc.c index 1a829d4c08..323ecb37ee 100644 --- a/libavformat/ircamenc.c +++ b/libavformat/ircamenc.c @@ -28,7 +28,7 @@ static int ircam_write_header(AVFormatContext *s) { - AVCodecContext *codec = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; uint32_t tag; if (s->nb_streams != 1) { @@ -36,15 +36,15 @@ static int ircam_write_header(AVFormatContext *s) return AVERROR(EINVAL); } - tag = ff_codec_get_tag(ff_codec_ircam_le_tags, codec->codec_id); + tag = ff_codec_get_tag(ff_codec_ircam_le_tags, par->codec_id); if (!tag) { av_log(s, AV_LOG_ERROR, "unsupported codec\n"); return AVERROR(EINVAL); } avio_wl32(s->pb, 0x0001A364); - avio_wl32(s->pb, av_q2intfloat((AVRational){codec->sample_rate, 1})); - avio_wl32(s->pb, codec->channels); + avio_wl32(s->pb, av_q2intfloat((AVRational){par->sample_rate, 1})); + avio_wl32(s->pb, par->channels); avio_wl32(s->pb, tag); ffio_fill(s->pb, 0, 1008); return 0; diff --git a/libavformat/isom.c b/libavformat/isom.c index 2ca126585f..d8a330c0b2 100644 --- a/libavformat/isom.c +++ b/libavformat/isom.c @@ -465,47 +465,43 @@ int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext avio_r8(pb); /* stream type */ avio_rb24(pb); /* buffer size db */ - if(avcodec_is_open(st->codec)) { - av_log(fc, AV_LOG_DEBUG, "codec open in read_dec_config_descr\n"); - return -1; - } - v = avio_rb32(pb); - if (v < INT32_MAX) - st->codec->rc_max_rate = v; + // TODO: fix this + //if (v < INT32_MAX) + // st->codecpar->rc_max_rate = v; - st->codec->bit_rate = avio_rb32(pb); /* avg bitrate */ + st->codecpar->bit_rate = avio_rb32(pb); /* avg bitrate */ codec_id= ff_codec_get_id(ff_mp4_obj_type, object_type_id); if (codec_id) - st->codec->codec_id= codec_id; + st->codecpar->codec_id = codec_id; av_log(fc, AV_LOG_TRACE, "esds object type id 0x%02x\n", object_type_id); len = ff_mp4_read_descr(fc, pb, &tag); if (tag == MP4DecSpecificDescrTag) { av_log(fc, AV_LOG_TRACE, "Specific MPEG4 header len=%d\n", len); if (!len || (uint64_t)len > (1<<30)) return -1; - av_free(st->codec->extradata); - if ((ret = ff_get_extradata(st->codec, pb, len)) < 0) + av_free(st->codecpar->extradata); + if ((ret = ff_get_extradata(st->codecpar, pb, len)) < 0) return ret; - if (st->codec->codec_id == AV_CODEC_ID_AAC) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC) { MPEG4AudioConfig cfg = {0}; - avpriv_mpeg4audio_get_config(&cfg, st->codec->extradata, - st->codec->extradata_size * 8, 1); - st->codec->channels = cfg.channels; + avpriv_mpeg4audio_get_config(&cfg, st->codecpar->extradata, + st->codecpar->extradata_size * 8, 1); + st->codecpar->channels = cfg.channels; if (cfg.object_type == 29 && cfg.sampling_index < 3) // old mp3on4 - st->codec->sample_rate = avpriv_mpa_freq_tab[cfg.sampling_index]; + st->codecpar->sample_rate = avpriv_mpa_freq_tab[cfg.sampling_index]; else if (cfg.ext_sample_rate) - st->codec->sample_rate = cfg.ext_sample_rate; + st->codecpar->sample_rate = cfg.ext_sample_rate; else - st->codec->sample_rate = cfg.sample_rate; + st->codecpar->sample_rate = cfg.sample_rate; av_log(fc, AV_LOG_TRACE, "mp4a config channels %d obj %d ext obj %d " - "sample rate %d ext sample rate %d\n", st->codec->channels, + "sample rate %d ext sample rate %d\n", st->codecpar->channels, cfg.object_type, cfg.ext_object_type, cfg.sample_rate, cfg.ext_sample_rate); - if (!(st->codec->codec_id = ff_codec_get_id(mp4_audio_types, + if (!(st->codecpar->codec_id = ff_codec_get_id(mp4_audio_types, cfg.object_type))) - st->codec->codec_id = AV_CODEC_ID_AAC; + st->codecpar->codec_id = AV_CODEC_ID_AAC; } } return 0; diff --git a/libavformat/iss.c b/libavformat/iss.c index fbde505a2d..95b35dc78a 100644 --- a/libavformat/iss.c +++ b/libavformat/iss.c @@ -107,23 +107,23 @@ static av_cold int iss_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_ISS; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_ISS; if (stereo) { - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } else { - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } - st->codec->sample_rate = 44100; + st->codecpar->sample_rate = 44100; if(rate_divisor > 0) - st->codec->sample_rate /= rate_divisor; - st->codec->bits_per_coded_sample = 4; - st->codec->bit_rate = st->codec->channels * st->codec->sample_rate - * st->codec->bits_per_coded_sample; - st->codec->block_align = iss->packet_size; - avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate); + st->codecpar->sample_rate /= rate_divisor; + st->codecpar->bits_per_coded_sample = 4; + st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate + * st->codecpar->bits_per_coded_sample; + st->codecpar->block_align = iss->packet_size; + avpriv_set_pts_info(st, 32, 1, st->codecpar->sample_rate); return 0; } @@ -138,8 +138,8 @@ static int iss_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->stream_index = 0; pkt->pts = avio_tell(s->pb) - iss->sample_start_pos; - if(s->streams[0]->codec->channels > 0) - pkt->pts /= s->streams[0]->codec->channels*2; + if(s->streams[0]->codecpar->channels > 0) + pkt->pts /= s->streams[0]->codecpar->channels*2; return 0; } diff --git a/libavformat/iv8.c b/libavformat/iv8.c index f1e351cbb6..077d905b4b 100644 --- a/libavformat/iv8.c +++ b/libavformat/iv8.c @@ -45,8 +45,8 @@ static int read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MPEG4; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MPEG4; st->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 64, 1, 90000); diff --git a/libavformat/ivfdec.c b/libavformat/ivfdec.c index c0fdafbf02..197c099bc3 100644 --- a/libavformat/ivfdec.c +++ b/libavformat/ivfdec.c @@ -46,11 +46,11 @@ static int read_header(AVFormatContext *s) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_tag = avio_rl32(s->pb); - st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, st->codec->codec_tag); - st->codec->width = avio_rl16(s->pb); - st->codec->height = avio_rl16(s->pb); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_tag = avio_rl32(s->pb); + st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, st->codecpar->codec_tag); + st->codecpar->width = avio_rl16(s->pb); + st->codecpar->height = avio_rl16(s->pb); time_base.den = avio_rl32(s->pb); time_base.num = avio_rl32(s->pb); st->duration = avio_rl64(s->pb); diff --git a/libavformat/ivfenc.c b/libavformat/ivfenc.c index 490b0a921a..5dbcd97611 100644 --- a/libavformat/ivfenc.c +++ b/libavformat/ivfenc.c @@ -28,25 +28,25 @@ typedef struct IVFEncContext { static int ivf_write_header(AVFormatContext *s) { - AVCodecContext *ctx; + AVCodecParameters *par; AVIOContext *pb = s->pb; if (s->nb_streams != 1) { av_log(s, AV_LOG_ERROR, "Format supports only exactly one video stream\n"); return AVERROR(EINVAL); } - ctx = s->streams[0]->codec; - if (ctx->codec_type != AVMEDIA_TYPE_VIDEO || - !(ctx->codec_id == AV_CODEC_ID_VP8 || ctx->codec_id == AV_CODEC_ID_VP9)) { + par = s->streams[0]->codecpar; + if (par->codec_type != AVMEDIA_TYPE_VIDEO || + !(par->codec_id == AV_CODEC_ID_VP8 || par->codec_id == AV_CODEC_ID_VP9)) { av_log(s, AV_LOG_ERROR, "Currently only VP8 and VP9 are supported!\n"); return AVERROR(EINVAL); } avio_write(pb, "DKIF", 4); avio_wl16(pb, 0); // version avio_wl16(pb, 32); // header length - avio_wl32(pb, ctx->codec_tag ? ctx->codec_tag : ctx->codec_id == AV_CODEC_ID_VP9 ? AV_RL32("VP90") : AV_RL32("VP80")); - avio_wl16(pb, ctx->width); - avio_wl16(pb, ctx->height); + avio_wl32(pb, par->codec_tag ? par->codec_tag : par->codec_id == AV_CODEC_ID_VP9 ? AV_RL32("VP90") : AV_RL32("VP80")); + avio_wl16(pb, par->width); + avio_wl16(pb, par->height); avio_wl32(pb, s->streams[0]->time_base.den); avio_wl32(pb, s->streams[0]->time_base.num); avio_wl64(pb, 0xFFFFFFFFFFFFFFFFULL); @@ -91,7 +91,7 @@ static int ivf_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt) int ret = 1; AVStream *st = s->streams[pkt->stream_index]; - if (st->codec->codec_id == AV_CODEC_ID_VP9) + if (st->codecpar->codec_id == AV_CODEC_ID_VP9) ret = ff_stream_add_bitstream_filter(st, "vp9_superframe", NULL); return ret; diff --git a/libavformat/jacosubdec.c b/libavformat/jacosubdec.c index 0436a9328d..520c435cc5 100644 --- a/libavformat/jacosubdec.c +++ b/libavformat/jacosubdec.c @@ -167,8 +167,8 @@ static int jacosub_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 64, 1, 100); - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = AV_CODEC_ID_JACOSUB; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_JACOSUB; jacosub->timeres = 30; @@ -230,7 +230,7 @@ static int jacosub_read_header(AVFormatContext *s) } /* general/essential directives in the extradata */ - ret = avpriv_bprint_to_extradata(st->codec, &header); + ret = ff_bprint_to_codecpar_extradata(st->codecpar, &header); if (ret < 0) goto fail; diff --git a/libavformat/jacosubenc.c b/libavformat/jacosubenc.c index a11e45a4aa..0954f5f058 100644 --- a/libavformat/jacosubenc.c +++ b/libavformat/jacosubenc.c @@ -21,10 +21,10 @@ static int jacosub_write_header(AVFormatContext *s) { - const AVCodecContext *avctx = s->streams[0]->codec; + const AVCodecParameters *par = s->streams[0]->codecpar; - if (avctx->extradata_size) { - avio_write(s->pb, avctx->extradata, avctx->extradata_size - 1); + if (par->extradata_size) { + avio_write(s->pb, par->extradata, par->extradata_size - 1); avio_flush(s->pb); } return 0; diff --git a/libavformat/jvdec.c b/libavformat/jvdec.c index a31c7236ff..b2c067fb99 100644 --- a/libavformat/jvdec.c +++ b/libavformat/jvdec.c @@ -85,11 +85,11 @@ static int read_header(AVFormatContext *s) if (!ast || !vst) return AVERROR(ENOMEM); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_JV; - vst->codec->codec_tag = 0; /* no fourcc */ - vst->codec->width = avio_rl16(pb); - vst->codec->height = avio_rl16(pb); + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_JV; + vst->codecpar->codec_tag = 0; /* no fourcc */ + vst->codecpar->width = avio_rl16(pb); + vst->codecpar->height = avio_rl16(pb); vst->duration = vst->nb_frames = ast->nb_index_entries = avio_rl16(pb); @@ -97,13 +97,13 @@ static int read_header(AVFormatContext *s) avio_skip(pb, 4); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = AV_CODEC_ID_PCM_U8; - ast->codec->codec_tag = 0; /* no fourcc */ - ast->codec->sample_rate = avio_rl16(pb); - ast->codec->channels = 1; - ast->codec->channel_layout = AV_CH_LAYOUT_MONO; - avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate); + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = AV_CODEC_ID_PCM_U8; + ast->codecpar->codec_tag = 0; /* no fourcc */ + ast->codecpar->sample_rate = avio_rl16(pb); + ast->codecpar->channels = 1; + ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate); avio_skip(pb, 10); diff --git a/libavformat/latmenc.c b/libavformat/latmenc.c index 9713b1b8ec..43ca4821cb 100644 --- a/libavformat/latmenc.c +++ b/libavformat/latmenc.c @@ -85,13 +85,13 @@ static int latm_decode_extradata(LATMContext *ctx, uint8_t *buf, int size) static int latm_write_header(AVFormatContext *s) { LATMContext *ctx = s->priv_data; - AVCodecContext *avctx = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; - if (avctx->codec_id == AV_CODEC_ID_AAC_LATM) + if (par->codec_id == AV_CODEC_ID_AAC_LATM) return 0; - if (avctx->extradata_size > 0 && - latm_decode_extradata(ctx, avctx->extradata, avctx->extradata_size) < 0) + if (par->extradata_size > 0 && + latm_decode_extradata(ctx, par->extradata, par->extradata_size) < 0) return AVERROR_INVALIDDATA; return 0; @@ -100,7 +100,7 @@ static int latm_write_header(AVFormatContext *s) static void latm_write_frame_header(AVFormatContext *s, PutBitContext *bs) { LATMContext *ctx = s->priv_data; - AVCodecContext *avctx = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; int header_size; /* AudioMuxElement */ @@ -116,16 +116,16 @@ static void latm_write_frame_header(AVFormatContext *s, PutBitContext *bs) /* AudioSpecificConfig */ if (ctx->object_type == AOT_ALS) { - header_size = avctx->extradata_size-(ctx->off >> 3); - avpriv_copy_bits(bs, &avctx->extradata[ctx->off >> 3], header_size); + header_size = par->extradata_size-(ctx->off >> 3); + avpriv_copy_bits(bs, &par->extradata[ctx->off >> 3], header_size); } else { // + 3 assumes not scalable and dependsOnCoreCoder == 0, // see decode_ga_specific_config in libavcodec/aacdec.c - avpriv_copy_bits(bs, avctx->extradata, ctx->off + 3); + avpriv_copy_bits(bs, par->extradata, ctx->off + 3); if (!ctx->channel_conf) { GetBitContext gb; - int ret = init_get_bits8(&gb, avctx->extradata, avctx->extradata_size); + int ret = init_get_bits8(&gb, par->extradata, par->extradata_size); av_assert0(ret >= 0); // extradata size has been checked already, so this should not fail skip_bits_long(&gb, ctx->off + 3); avpriv_copy_pce_data(bs, &gb); @@ -151,10 +151,10 @@ static int latm_write_packet(AVFormatContext *s, AVPacket *pkt) int i, len; uint8_t loas_header[] = "\x56\xe0\x00"; - if (s->streams[0]->codec->codec_id == AV_CODEC_ID_AAC_LATM) + if (s->streams[0]->codecpar->codec_id == AV_CODEC_ID_AAC_LATM) return ff_raw_write_packet(s, pkt); - if (!s->streams[0]->codec->extradata) { + if (!s->streams[0]->codecpar->extradata) { if(pkt->size > 2 && pkt->data[0] == 0x56 && (pkt->data[1] >> 4) == 0xe && (AV_RB16(pkt->data + 1) & 0x1FFF) + 3 == pkt->size) return ff_raw_write_packet(s, pkt); @@ -218,7 +218,7 @@ static int latm_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt) int ret = 1; AVStream *st = s->streams[pkt->stream_index]; - if (st->codec->codec_id == AV_CODEC_ID_AAC) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC) { if (pkt->size > 2 && (AV_RB16(pkt->data) & 0xfff0) == 0xfff0) ret = ff_stream_add_bitstream_filter(st, "aac_adtstoasc", NULL); } diff --git a/libavformat/libgme.c b/libavformat/libgme.c index 276477b308..228273dc90 100644 --- a/libavformat/libgme.c +++ b/libavformat/libgme.c @@ -126,10 +126,10 @@ static int read_header_gme(AVFormatContext *s) avpriv_set_pts_info(st, 64, 1, 1000); if (st->duration > 0) st->duration = gme->info->length; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_NE(AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE); - st->codec->channels = 2; - st->codec->sample_rate = gme->sample_rate; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_NE(AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE); + st->codecpar->channels = 2; + st->codecpar->sample_rate = gme->sample_rate; return 0; } diff --git a/libavformat/libmodplug.c b/libavformat/libmodplug.c index 75699e89b4..f18c610c46 100644 --- a/libavformat/libmodplug.c +++ b/libavformat/libmodplug.c @@ -224,10 +224,10 @@ static int modplug_read_header(AVFormatContext *s) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 64, 1, 1000); st->duration = ModPlug_GetLength(modplug->f); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; - st->codec->channels = settings.mChannels; - st->codec->sample_rate = settings.mFrequency; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; + st->codecpar->channels = settings.mChannels; + st->codecpar->sample_rate = settings.mFrequency; // timebase = 1/1000, 2ch 16bits 44.1kHz-> 2*2*44100 modplug->ts_per_packet = 1000*AUDIO_PKT_SIZE / (4*44100.); @@ -238,10 +238,10 @@ static int modplug_read_header(AVFormatContext *s) return AVERROR(ENOMEM); avpriv_set_pts_info(vst, 64, 1, 1000); vst->duration = st->duration; - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_XBIN; - vst->codec->width = modplug->w << 3; - vst->codec->height = modplug->h << 3; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_XBIN; + vst->codecpar->width = modplug->w << 3; + vst->codecpar->height = modplug->h << 3; modplug->linesize = modplug->w * 3; modplug->fsize = modplug->linesize * modplug->h; } diff --git a/libavformat/libnut.c b/libavformat/libnut.c index 92623ed452..48f0928622 100644 --- a/libavformat/libnut.c +++ b/libavformat/libnut.c @@ -75,19 +75,19 @@ static int nut_write_header(AVFormatContext * avf) { return AVERROR(ENOMEM); for (i = 0; i < avf->nb_streams; i++) { - AVCodecContext * codec = avf->streams[i]->codec; + AVCodecParameters *par = avf->streams[i]->codecpar; int j; int fourcc = 0; int num, denom, ssize; - s[i].type = codec->codec_type == AVMEDIA_TYPE_VIDEO ? NUT_VIDEO_CLASS : NUT_AUDIO_CLASS; + s[i].type = par->codec_type == AVMEDIA_TYPE_VIDEO ? NUT_VIDEO_CLASS : NUT_AUDIO_CLASS; - if (codec->codec_tag) fourcc = codec->codec_tag; - else fourcc = ff_codec_get_tag(nut_tags, codec->codec_id); + if (par->codec_tag) fourcc = par->codec_tag; + else fourcc = ff_codec_get_tag(nut_tags, par->codec_id); if (!fourcc) { - if (codec->codec_type == AVMEDIA_TYPE_VIDEO) fourcc = ff_codec_get_tag(ff_codec_bmp_tags, codec->codec_id); - if (codec->codec_type == AVMEDIA_TYPE_AUDIO) fourcc = ff_codec_get_tag(ff_codec_wav_tags, codec->codec_id); + if (par->codec_type == AVMEDIA_TYPE_VIDEO) fourcc = ff_codec_get_tag(ff_codec_bmp_tags, par->codec_id); + if (par->codec_type == AVMEDIA_TYPE_AUDIO) fourcc = ff_codec_get_tag(ff_codec_wav_tags, par->codec_id); } s[i].fourcc_len = 4; @@ -101,20 +101,20 @@ static int nut_write_header(AVFormatContext * avf) { s[i].time_base.den = num; s[i].fixed_fps = 0; - s[i].decode_delay = codec->has_b_frames; - s[i].codec_specific_len = codec->extradata_size; - s[i].codec_specific = codec->extradata; + s[i].decode_delay = par->video_delay; + s[i].codec_specific_len = par->extradata_size; + s[i].codec_specific = par->extradata; - if (codec->codec_type == AVMEDIA_TYPE_VIDEO) { - s[i].width = codec->width; - s[i].height = codec->height; + if (par->codec_type == AVMEDIA_TYPE_VIDEO) { + s[i].width = par->width; + s[i].height = par->height; s[i].sample_width = 0; s[i].sample_height = 0; s[i].colorspace_type = 0; } else { - s[i].samplerate_num = codec->sample_rate; + s[i].samplerate_num = par->sample_rate; s[i].samplerate_denom = 1; - s[i].channel_count = codec->channels; + s[i].channel_count = par->channels; } } @@ -226,45 +226,45 @@ static int nut_read_header(AVFormatContext * avf) { if (!st) return AVERROR(ENOMEM); - for (j = 0; j < s[i].fourcc_len && j < 8; j++) st->codec->codec_tag |= s[i].fourcc[j]<<(j*8); + for (j = 0; j < s[i].fourcc_len && j < 8; j++) st->codecpar->codec_tag |= s[i].fourcc[j]<<(j*8); - st->codec->has_b_frames = s[i].decode_delay; + st->codecpar->video_delay = s[i].decode_delay; - st->codec->extradata_size = s[i].codec_specific_len; - if (st->codec->extradata_size) { - if(ff_alloc_extradata(st->codec, st->codec->extradata_size)){ + st->codecpar->extradata_size = s[i].codec_specific_len; + if (st->codecpar->extradata_size) { + if(ff_alloc_extradata(st->codecpar, st->codecpar->extradata_size)){ nut_demuxer_uninit(nut); priv->nut = NULL; return AVERROR(ENOMEM); } - memcpy(st->codec->extradata, s[i].codec_specific, st->codec->extradata_size); + memcpy(st->codecpar->extradata, s[i].codec_specific, st->codecpar->extradata_size); } avpriv_set_pts_info(avf->streams[i], 60, s[i].time_base.num, s[i].time_base.den); st->start_time = 0; st->duration = s[i].max_pts; - st->codec->codec_id = ff_codec_get_id(nut_tags, st->codec->codec_tag); + st->codecpar->codec_id = ff_codec_get_id(nut_tags, st->codecpar->codec_tag); switch(s[i].type) { case NUT_AUDIO_CLASS: - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - if (st->codec->codec_id == AV_CODEC_ID_NONE) st->codec->codec_id = ff_codec_get_id(ff_codec_wav_tags, st->codec->codec_tag); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) st->codecpar->codec_id = ff_codec_get_id(ff_codec_wav_tags, st->codecpar->codec_tag); - st->codec->channels = s[i].channel_count; - st->codec->sample_rate = s[i].samplerate_num / s[i].samplerate_denom; + st->codecpar->channels = s[i].channel_count; + st->codecpar->sample_rate = s[i].samplerate_num / s[i].samplerate_denom; break; case NUT_VIDEO_CLASS: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - if (st->codec->codec_id == AV_CODEC_ID_NONE) st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, st->codec->codec_tag); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, st->codecpar->codec_tag); - st->codec->width = s[i].width; - st->codec->height = s[i].height; + st->codecpar->width = s[i].width; + st->codecpar->height = s[i].height; st->sample_aspect_ratio.num = s[i].sample_width; st->sample_aspect_ratio.den = s[i].sample_height; break; } - if (st->codec->codec_id == AV_CODEC_ID_NONE) av_log(avf, AV_LOG_ERROR, "Unknown codec?!\n"); + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) av_log(avf, AV_LOG_ERROR, "Unknown codec?!\n"); } return 0; diff --git a/libavformat/lmlm4.c b/libavformat/lmlm4.c index 899f449634..d0cf8feb03 100644 --- a/libavformat/lmlm4.c +++ b/libavformat/lmlm4.c @@ -65,15 +65,15 @@ static int lmlm4_read_header(AVFormatContext *s) if (!(st = avformat_new_stream(s, NULL))) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MPEG4; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MPEG4; st->need_parsing = AVSTREAM_PARSE_HEADERS; avpriv_set_pts_info(st, 64, 1001, 30000); if (!(st = avformat_new_stream(s, NULL))) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_MP2; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_MP2; st->need_parsing = AVSTREAM_PARSE_HEADERS; /* the parameters will be extracted from the compressed bitstream */ diff --git a/libavformat/loasdec.c b/libavformat/loasdec.c index c41809be00..70440559d2 100644 --- a/libavformat/loasdec.c +++ b/libavformat/loasdec.c @@ -73,8 +73,8 @@ static int loas_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->iformat->raw_codec_id; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = s->iformat->raw_codec_id; st->need_parsing = AVSTREAM_PARSE_FULL_RAW; //LCM of all possible AAC sample rates diff --git a/libavformat/lrcdec.c b/libavformat/lrcdec.c index d3655fccd5..12f74b22a0 100644 --- a/libavformat/lrcdec.c +++ b/libavformat/lrcdec.c @@ -165,8 +165,8 @@ static int lrc_read_header(AVFormatContext *s) } avpriv_set_pts_info(st, 64, 1, 1000); lrc->ts_offset = 0; - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = AV_CODEC_ID_TEXT; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_TEXT; av_bprint_init(&line, 0, AV_BPRINT_SIZE_UNLIMITED); while(!avio_feof(s->pb)) { diff --git a/libavformat/lrcenc.c b/libavformat/lrcenc.c index 74268cc681..c5fda64738 100644 --- a/libavformat/lrcenc.c +++ b/libavformat/lrcenc.c @@ -39,15 +39,15 @@ static int lrc_write_header(AVFormatContext *s) const AVDictionaryEntry *metadata_item; if(s->nb_streams != 1 || - s->streams[0]->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) { + s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) { av_log(s, AV_LOG_ERROR, "LRC supports only a single subtitle stream.\n"); return AVERROR(EINVAL); } - if(s->streams[0]->codec->codec_id != AV_CODEC_ID_SUBRIP && - s->streams[0]->codec->codec_id != AV_CODEC_ID_TEXT) { + if(s->streams[0]->codecpar->codec_id != AV_CODEC_ID_SUBRIP && + s->streams[0]->codecpar->codec_id != AV_CODEC_ID_TEXT) { av_log(s, AV_LOG_ERROR, "Unsupported subtitle codec: %s\n", - avcodec_get_name(s->streams[0]->codec->codec_id)); + avcodec_get_name(s->streams[0]->codecpar->codec_id)); return AVERROR(EINVAL); } avpriv_set_pts_info(s->streams[0], 64, 1, 100); diff --git a/libavformat/lvfdec.c b/libavformat/lvfdec.c index 81aec599ba..b8af25609f 100644 --- a/libavformat/lvfdec.c +++ b/libavformat/lvfdec.c @@ -62,14 +62,14 @@ static int lvf_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; avio_skip(s->pb, 4); - st->codec->width = avio_rl32(s->pb); - st->codec->height = avio_rl32(s->pb); + st->codecpar->width = avio_rl32(s->pb); + st->codecpar->height = avio_rl32(s->pb); avio_skip(s->pb, 4); - st->codec->codec_tag = avio_rl32(s->pb); - st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, - st->codec->codec_tag); + st->codecpar->codec_tag = avio_rl32(s->pb); + st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, + st->codecpar->codec_tag); avpriv_set_pts_info(st, 32, 1, 1000); break; case MKTAG('0', '1', 'f', 'm'): @@ -77,14 +77,14 @@ static int lvf_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = avio_rl16(s->pb); - st->codec->channels = avio_rl16(s->pb); - st->codec->sample_rate = avio_rl16(s->pb); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = avio_rl16(s->pb); + st->codecpar->channels = avio_rl16(s->pb); + st->codecpar->sample_rate = avio_rl16(s->pb); avio_skip(s->pb, 8); - st->codec->bits_per_coded_sample = avio_r8(s->pb); - st->codec->codec_id = ff_codec_get_id(ff_codec_wav_tags, - st->codec->codec_tag); + st->codecpar->bits_per_coded_sample = avio_r8(s->pb); + st->codecpar->codec_id = ff_codec_get_id(ff_codec_wav_tags, + st->codecpar->codec_tag); avpriv_set_pts_info(st, 32, 1, 1000); break; case 0: diff --git a/libavformat/lxfdec.c b/libavformat/lxfdec.c index c00b4bdea5..99e56f243f 100644 --- a/libavformat/lxfdec.c +++ b/libavformat/lxfdec.c @@ -178,25 +178,25 @@ static int get_packet_header(AVFormatContext *s) //set codec based on specified audio bitdepth //we only support tightly packed 16-, 20-, 24- and 32-bit PCM at the moment - st->codec->bits_per_coded_sample = (audio_format >> 6) & 0x3F; + st->codecpar->bits_per_coded_sample = (audio_format >> 6) & 0x3F; - if (st->codec->bits_per_coded_sample != (audio_format & 0x3F)) { + if (st->codecpar->bits_per_coded_sample != (audio_format & 0x3F)) { av_log(s, AV_LOG_WARNING, "only tightly packed PCM currently supported\n"); return AVERROR_PATCHWELCOME; } - switch (st->codec->bits_per_coded_sample) { - case 16: st->codec->codec_id = AV_CODEC_ID_PCM_S16LE_PLANAR; break; - case 20: st->codec->codec_id = AV_CODEC_ID_PCM_LXF; break; - case 24: st->codec->codec_id = AV_CODEC_ID_PCM_S24LE_PLANAR; break; - case 32: st->codec->codec_id = AV_CODEC_ID_PCM_S32LE_PLANAR; break; + switch (st->codecpar->bits_per_coded_sample) { + case 16: st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE_PLANAR; break; + case 20: st->codecpar->codec_id = AV_CODEC_ID_PCM_LXF; break; + case 24: st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE_PLANAR; break; + case 32: st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE_PLANAR; break; default: av_log(s, AV_LOG_WARNING, "only 16-, 20-, 24- and 32-bit PCM currently supported\n"); return AVERROR_PATCHWELCOME; } - samples = track_size * 8 / st->codec->bits_per_coded_sample; + samples = track_size * 8 / st->codecpar->bits_per_coded_sample; //use audio packet size to determine video standard //for NTSC we have one 8008-sample audio frame per five video frames @@ -257,11 +257,11 @@ static int lxf_read_header(AVFormatContext *s) expiration_date = AV_RL16(&header_data[58]); disk_params = AV_RL32(&header_data[116]); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->bit_rate = 1000000 * ((video_params >> 14) & 0xFF); - st->codec->codec_tag = video_params & 0xF; - st->codec->codec_id = ff_codec_get_id(lxf_tags, st->codec->codec_tag); - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->bit_rate = 1000000 * ((video_params >> 14) & 0xFF); + st->codecpar->codec_tag = video_params & 0xF; + st->codecpar->codec_id = ff_codec_get_id(lxf_tags, st->codecpar->codec_tag); + st->need_parsing = AVSTREAM_PARSE_HEADERS; av_log(s, AV_LOG_DEBUG, "record: %x = %i-%02i-%02i\n", record_date, 1900 + (record_date & 0x7F), (record_date >> 7) & 0xF, @@ -278,11 +278,11 @@ static int lxf_read_header(AVFormatContext *s) if (!(st = avformat_new_stream(s, NULL))) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->sample_rate = LXF_SAMPLERATE; - st->codec->channels = lxf->channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->sample_rate = LXF_SAMPLERATE; + st->codecpar->channels = lxf->channels; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); } avio_skip(s->pb, lxf->extended_size); diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 28bb77b4ae..fa301a7900 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1737,7 +1737,7 @@ static int matroska_parse_flac(AVFormatContext *s, av_log(s, AV_LOG_WARNING, "Invalid value of WAVEFORMATEXTENSIBLE_CHANNEL_MASK\n"); } else - st->codec->channel_layout = mask; + st->codecpar->channel_layout = mask; } av_dict_free(&dict); } @@ -1785,14 +1785,14 @@ static int mkv_parse_video_color(AVStream *st, const MatroskaTrack *track) { const int has_mastering_luminance = mastering_meta->max_luminance > 0; if (track->video.color.matrix_coefficients != AVCOL_SPC_RESERVED) - st->codec->colorspace = track->video.color.matrix_coefficients; + st->codecpar->color_space = track->video.color.matrix_coefficients; if (track->video.color.primaries != AVCOL_PRI_RESERVED) - st->codec->color_primaries = track->video.color.primaries; + st->codecpar->color_primaries = track->video.color.primaries; if (track->video.color.transfer_characteristics != AVCOL_TRC_RESERVED) - st->codec->color_trc = track->video.color.transfer_characteristics; + st->codecpar->color_trc = track->video.color.transfer_characteristics; if (track->video.color.range != AVCOL_RANGE_UNSPECIFIED && track->video.color.range <= AVCOL_RANGE_JPEG) - st->codec->color_range = track->video.color.range; + st->codecpar->color_range = track->video.color.range; if (has_mastering_primaries || has_mastering_luminance) { // Use similar rationals as other standards. @@ -2009,11 +2009,11 @@ static int matroska_parse_tracks(AVFormatContext *s) ffio_init_context(&b, track->codec_priv.data, track->codec_priv.size, 0, NULL, NULL, NULL, NULL); - ret = ff_get_wav_header(s, &b, st->codec, track->codec_priv.size, 0); + ret = ff_get_wav_header(s, &b, st->codecpar, track->codec_priv.size, 0); if (ret < 0) return ret; - codec_id = st->codec->codec_id; - fourcc = st->codec->codec_tag; + codec_id = st->codecpar->codec_id; + fourcc = st->codecpar->codec_tag; extradata_offset = FFMIN(track->codec_priv.size, 18); } else if (!strcmp(track->codec_id, "A_QUICKTIME") /* Normally 36, but allow noncompliant private data */ @@ -2185,15 +2185,15 @@ static int matroska_parse_tracks(AVFormatContext *s) if (!track->audio.buf) return AVERROR(ENOMEM); if (codec_id == AV_CODEC_ID_RA_288) { - st->codec->block_align = track->audio.coded_framesize; + st->codecpar->block_align = track->audio.coded_framesize; track->codec_priv.size = 0; } else { if (codec_id == AV_CODEC_ID_SIPR && flavor < 4) { static const int sipr_bit_rate[4] = { 6504, 8496, 5000, 16000 }; track->audio.sub_packet_size = ff_sipr_subpk_size[flavor]; - st->codec->bit_rate = sipr_bit_rate[flavor]; + st->codecpar->bit_rate = sipr_bit_rate[flavor]; } - st->codec->block_align = track->audio.sub_packet_size; + st->codecpar->block_align = track->audio.sub_packet_size; extradata_offset = 78; } } else if (codec_id == AV_CODEC_ID_FLAC && track->codec_priv.size) { @@ -2219,7 +2219,7 @@ static int matroska_parse_tracks(AVFormatContext *s) (AVRational){ 1, 1000000000 }, st->time_base); - st->codec->codec_id = codec_id; + st->codecpar->codec_id = codec_id; if (strcmp(track->language, "und")) av_dict_set(&st->metadata, "language", track->language, 0); @@ -2230,14 +2230,14 @@ static int matroska_parse_tracks(AVFormatContext *s) if (track->flag_forced) st->disposition |= AV_DISPOSITION_FORCED; - if (!st->codec->extradata) { + if (!st->codecpar->extradata) { if (extradata) { - st->codec->extradata = extradata; - st->codec->extradata_size = extradata_size; + st->codecpar->extradata = extradata; + st->codecpar->extradata_size = extradata_size; } else if (track->codec_priv.data && track->codec_priv.size > 0) { - if (ff_alloc_extradata(st->codec, track->codec_priv.size)) + if (ff_alloc_extradata(st->codecpar, track->codec_priv.size)) return AVERROR(ENOMEM); - memcpy(st->codec->extradata, + memcpy(st->codecpar->extradata, track->codec_priv.data + extradata_offset, track->codec_priv.size); } @@ -2248,22 +2248,22 @@ static int matroska_parse_tracks(AVFormatContext *s) int display_width_mul = 1; int display_height_mul = 1; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_tag = fourcc; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_tag = fourcc; if (bit_depth >= 0) - st->codec->bits_per_coded_sample = bit_depth; - st->codec->width = track->video.pixel_width; - st->codec->height = track->video.pixel_height; + st->codecpar->bits_per_coded_sample = bit_depth; + st->codecpar->width = track->video.pixel_width; + st->codecpar->height = track->video.pixel_height; if (track->video.stereo_mode && track->video.stereo_mode < MATROSKA_VIDEO_STEREOMODE_TYPE_NB) mkv_stereo_mode_display_mul(track->video.stereo_mode, &display_width_mul, &display_height_mul); av_reduce(&st->sample_aspect_ratio.num, &st->sample_aspect_ratio.den, - st->codec->height * track->video.display_width * display_width_mul, - st->codec->width * track->video.display_height * display_height_mul, + st->codecpar->height * track->video.display_width * display_width_mul, + st->codecpar->width * track->video.display_height * display_height_mul, 255); - if (st->codec->codec_id != AV_CODEC_ID_HEVC) + if (st->codecpar->codec_id != AV_CODEC_ID_HEVC) st->need_parsing = AVSTREAM_PARSE_HEADERS; if (track->default_duration) { @@ -2312,29 +2312,28 @@ static int matroska_parse_tracks(AVFormatContext *s) return ret; } } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) { - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = fourcc; - st->codec->sample_rate = track->audio.out_samplerate; - st->codec->channels = track->audio.channels; - if (!st->codec->bits_per_coded_sample) - st->codec->bits_per_coded_sample = track->audio.bitdepth; - if (st->codec->codec_id == AV_CODEC_ID_MP3) + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = fourcc; + st->codecpar->sample_rate = track->audio.out_samplerate; + st->codecpar->channels = track->audio.channels; + if (!st->codecpar->bits_per_coded_sample) + st->codecpar->bits_per_coded_sample = track->audio.bitdepth; + if (st->codecpar->codec_id == AV_CODEC_ID_MP3) st->need_parsing = AVSTREAM_PARSE_FULL; - else if (st->codec->codec_id != AV_CODEC_ID_AAC) + else if (st->codecpar->codec_id != AV_CODEC_ID_AAC) st->need_parsing = AVSTREAM_PARSE_HEADERS; if (track->codec_delay > 0) { - st->codec->delay = av_rescale_q(track->codec_delay, - st->time_base, - (AVRational){1, st->codec->sample_rate}); + st->codecpar->initial_padding = av_rescale_q(track->codec_delay, + st->time_base, + (AVRational){1, st->codecpar->sample_rate}); } if (track->seek_preroll > 0) { - av_codec_set_seek_preroll(st->codec, - av_rescale_q(track->seek_preroll, - (AVRational){1, 1000000000}, - (AVRational){1, st->codec->sample_rate})); + st->codecpar->seek_preroll = av_rescale_q(track->seek_preroll, + (AVRational){1, 1000000000}, + (AVRational){1, st->codecpar->sample_rate}); } } else if (codec_id == AV_CODEC_ID_WEBVTT) { - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; if (!strcmp(track->codec_id, "D_WEBVTT/CAPTIONS")) { st->disposition |= AV_DISPOSITION_CAPTIONS; @@ -2344,8 +2343,8 @@ static int matroska_parse_tracks(AVFormatContext *s) st->disposition |= AV_DISPOSITION_METADATA; } } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) { - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - if (st->codec->codec_id == AV_CODEC_ID_ASS) + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + if (st->codecpar->codec_id == AV_CODEC_ID_ASS) matroska->contains_ssa = 1; } } @@ -2441,21 +2440,21 @@ static int matroska_read_header(AVFormatContext *s) break; av_dict_set(&st->metadata, "filename", attachments[j].filename, 0); av_dict_set(&st->metadata, "mimetype", attachments[j].mime, 0); - st->codec->codec_id = AV_CODEC_ID_NONE; + st->codecpar->codec_id = AV_CODEC_ID_NONE; for (i = 0; ff_mkv_image_mime_tags[i].id != AV_CODEC_ID_NONE; i++) { if (!strncmp(ff_mkv_image_mime_tags[i].str, attachments[j].mime, strlen(ff_mkv_image_mime_tags[i].str))) { - st->codec->codec_id = ff_mkv_image_mime_tags[i].id; + st->codecpar->codec_id = ff_mkv_image_mime_tags[i].id; break; } } attachments[j].stream = st; - if (st->codec->codec_id != AV_CODEC_ID_NONE) { - st->disposition |= AV_DISPOSITION_ATTACHED_PIC; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + if (st->codecpar->codec_id != AV_CODEC_ID_NONE) { + st->disposition |= AV_DISPOSITION_ATTACHED_PIC; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; av_init_packet(&st->attached_pic); if ((res = av_new_packet(&st->attached_pic, attachments[j].bin.size)) < 0) @@ -2464,16 +2463,16 @@ static int matroska_read_header(AVFormatContext *s) st->attached_pic.stream_index = st->index; st->attached_pic.flags |= AV_PKT_FLAG_KEY; } else { - st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT; - if (ff_alloc_extradata(st->codec, attachments[j].bin.size)) + st->codecpar->codec_type = AVMEDIA_TYPE_ATTACHMENT; + if (ff_alloc_extradata(st->codecpar, attachments[j].bin.size)) break; - memcpy(st->codec->extradata, attachments[j].bin.data, + memcpy(st->codecpar->extradata, attachments[j].bin.data, attachments[j].bin.size); for (i = 0; ff_mkv_mime_tags[i].id != AV_CODEC_ID_NONE; i++) { if (!strncmp(ff_mkv_mime_tags[i].str, attachments[j].mime, strlen(ff_mkv_mime_tags[i].str))) { - st->codec->codec_id = ff_mkv_mime_tags[i].id; + st->codecpar->codec_id = ff_mkv_mime_tags[i].id; break; } } @@ -2677,7 +2676,7 @@ static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska, uint8_t *data, int size, uint64_t timecode, int64_t pos) { - int a = st->codec->block_align; + int a = st->codecpar->block_align; int sps = track->audio.sub_packet_size; int cfs = track->audio.coded_framesize; int h = track->audio.sub_packet_h; @@ -2688,7 +2687,7 @@ static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska, if (!track->audio.pkt_cnt) { if (track->audio.sub_packet_cnt == 0) track->audio.buf_timecode = timecode; - if (st->codec->codec_id == AV_CODEC_ID_RA_288) { + if (st->codecpar->codec_id == AV_CODEC_ID_RA_288) { if (size < cfs * h / 2) { av_log(matroska->ctx, AV_LOG_ERROR, "Corrupt int4 RM-style audio packet size\n"); @@ -2697,7 +2696,7 @@ static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska, for (x = 0; x < h / 2; x++) memcpy(track->audio.buf + x * 2 * w + y * cfs, data + x * cfs, cfs); - } else if (st->codec->codec_id == AV_CODEC_ID_SIPR) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_SIPR) { if (size < w) { av_log(matroska->ctx, AV_LOG_ERROR, "Corrupt sipr RM-style audio packet size\n"); @@ -2717,7 +2716,7 @@ static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska, } if (++track->audio.sub_packet_cnt >= h) { - if (st->codec->codec_id == AV_CODEC_ID_SIPR) + if (st->codecpar->codec_id == AV_CODEC_ID_SIPR) ff_rm_reorder_sipr_data(track->audio.buf, h, w); track->audio.sub_packet_cnt = 0; track->audio.pkt_cnt = h * w / a; @@ -2759,10 +2758,10 @@ static int matroska_parse_wavpack(MatroskaTrack *track, uint8_t *src, uint16_t ver; int ret, offset = 0; - if (srclen < 12 || track->stream->codec->extradata_size < 2) + if (srclen < 12 || track->stream->codecpar->extradata_size < 2) return AVERROR_INVALIDDATA; - ver = AV_RL16(track->stream->codec->extradata); + ver = AV_RL16(track->stream->codecpar->extradata); samples = AV_RL32(src); src += 4; @@ -2964,7 +2963,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska, return res; } - if (st->codec->codec_id == AV_CODEC_ID_WAVPACK) { + if (st->codecpar->codec_id == AV_CODEC_ID_WAVPACK) { uint8_t *wv_data; res = matroska_parse_wavpack(track, pkt_data, &wv_data, &pkt_size); if (res < 0) { @@ -2977,7 +2976,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska, pkt_data = wv_data; } - if (st->codec->codec_id == AV_CODEC_ID_PRORES && + if (st->codecpar->codec_id == AV_CODEC_ID_PRORES && AV_RB32(&data[4]) != MKBETAG('i', 'c', 'p', 'f')) offset = 8; @@ -2994,7 +2993,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska, goto fail; } - if (st->codec->codec_id == AV_CODEC_ID_PRORES && offset == 8) { + if (st->codecpar->codec_id == AV_CODEC_ID_PRORES && offset == 8) { uint8_t *buf = pkt->data; bytestream_put_be32(&buf, pkt_size); bytestream_put_be32(&buf, MKBETAG('i', 'c', 'p', 'f')); @@ -3033,7 +3032,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska, AV_WL32(side_data, 0); AV_WL32(side_data + 4, av_rescale_q(discard_padding, (AVRational){1, 1000000000}, - (AVRational){1, st->codec->sample_rate})); + (AVRational){1, st->codecpar->sample_rate})); } if (track->ms_compat) @@ -3045,7 +3044,7 @@ static int matroska_parse_frame(MatroskaDemuxContext *matroska, #if FF_API_CONVERGENCE_DURATION FF_DISABLE_DEPRECATION_WARNINGS - if (st->codec->codec_id == AV_CODEC_ID_SUBRIP) { + if (st->codecpar->codec_id == AV_CODEC_ID_SUBRIP) { pkt->convergence_duration = lace_duration; } FF_ENABLE_DEPRECATION_WARNINGS @@ -3135,8 +3134,8 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, if (track->audio.samplerate == 8000) { // If this is needed for more codecs, then add them here - if (st->codec->codec_id == AV_CODEC_ID_AC3) { - if (track->audio.samplerate != st->codec->sample_rate || !st->codec->frame_size) + if (st->codecpar->codec_id == AV_CODEC_ID_AC3) { + if (track->audio.samplerate != st->codecpar->sample_rate || !st->codecpar->frame_size) trust_default_duration = 0; } } @@ -3156,18 +3155,18 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, break; } - if ((st->codec->codec_id == AV_CODEC_ID_RA_288 || - st->codec->codec_id == AV_CODEC_ID_COOK || - st->codec->codec_id == AV_CODEC_ID_SIPR || - st->codec->codec_id == AV_CODEC_ID_ATRAC3) && - st->codec->block_align && track->audio.sub_packet_size) { + if ((st->codecpar->codec_id == AV_CODEC_ID_RA_288 || + st->codecpar->codec_id == AV_CODEC_ID_COOK || + st->codecpar->codec_id == AV_CODEC_ID_SIPR || + st->codecpar->codec_id == AV_CODEC_ID_ATRAC3) && + st->codecpar->block_align && track->audio.sub_packet_size) { res = matroska_parse_rm_audio(matroska, track, st, data, lace_size[n], timecode, pos); if (res) goto end; - } else if (st->codec->codec_id == AV_CODEC_ID_WEBVTT) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_WEBVTT) { res = matroska_parse_webvtt(matroska, track, st, data, lace_size[n], timecode, lace_duration, diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 0546686d8e..2be0629309 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -486,7 +486,7 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) { int tracknum = entry[j].stream_idx; av_assert0(tracknum>=0 && tracknumstreams[tracknum]->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) + if (tracks[tracknum].has_cue && s->streams[tracknum]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) continue; tracks[tracknum].has_cue = 1; ctp_nb ++; @@ -502,7 +502,7 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) { int tracknum = entry[j].stream_idx; av_assert0(tracknum>=0 && tracknumstreams[tracknum]->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) + if (tracks[tracknum].has_cue && s->streams[tracknum]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) continue; tracks[tracknum].has_cue = 1; track_positions = start_ebml_master(pb, MATROSKA_ID_CUETRACKPOSITION, MAX_CUETRACKPOS_SIZE); @@ -521,19 +521,19 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra return currentpos; } -static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecContext *codec) +static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par) { const uint8_t *header_start[3]; int header_len[3]; int first_header_size; int j; - if (codec->codec_id == AV_CODEC_ID_VORBIS) + if (par->codec_id == AV_CODEC_ID_VORBIS) first_header_size = 30; else first_header_size = 42; - if (avpriv_split_xiph_headers(codec->extradata, codec->extradata_size, + if (avpriv_split_xiph_headers(par->extradata, par->extradata_size, first_header_size, header_start, header_len) < 0) { av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n"); return -1; @@ -549,22 +549,22 @@ static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecContex return 0; } -static int put_wv_codecpriv(AVIOContext *pb, AVCodecContext *codec) +static int put_wv_codecpriv(AVIOContext *pb, AVCodecParameters *par) { - if (codec->extradata && codec->extradata_size == 2) - avio_write(pb, codec->extradata, 2); + if (par->extradata && par->extradata_size == 2) + avio_write(pb, par->extradata, 2); else avio_wl16(pb, 0x403); // fallback to the version mentioned in matroska specs return 0; } static int put_flac_codecpriv(AVFormatContext *s, - AVIOContext *pb, AVCodecContext *codec) + AVIOContext *pb, AVCodecParameters *par) { - int write_comment = (codec->channel_layout && - !(codec->channel_layout & ~0x3ffffULL) && - !ff_flac_is_native_layout(codec->channel_layout)); - int ret = ff_flac_write_header(pb, codec->extradata, codec->extradata_size, + int write_comment = (par->channel_layout && + !(par->channel_layout & ~0x3ffffULL) && + !ff_flac_is_native_layout(par->channel_layout)); + int ret = ff_flac_write_header(pb, par->extradata, par->extradata_size, !write_comment); if (ret < 0) @@ -577,7 +577,7 @@ static int put_flac_codecpriv(AVFormatContext *s, uint8_t buf[32], *data, *p; int64_t len; - snprintf(buf, sizeof(buf), "0x%"PRIx64, codec->channel_layout); + snprintf(buf, sizeof(buf), "0x%"PRIx64, par->channel_layout); av_dict_set(&dict, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0); len = ff_vorbiscomment_length(dict, vendor); @@ -605,13 +605,13 @@ static int put_flac_codecpriv(AVFormatContext *s, return 0; } -static int get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec, +static int get_aac_sample_rates(AVFormatContext *s, AVCodecParameters *par, int *sample_rate, int *output_sample_rate) { MPEG4AudioConfig mp4ac; - if (avpriv_mpeg4audio_get_config(&mp4ac, codec->extradata, - codec->extradata_size * 8, 1) < 0) { + if (avpriv_mpeg4audio_get_config(&mp4ac, par->extradata, + par->extradata_size * 8, 1) < 0) { av_log(s, AV_LOG_ERROR, "Error parsing AAC extradata, unable to determine samplerate.\n"); return AVERROR(EINVAL); @@ -623,48 +623,48 @@ static int get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec, } static int mkv_write_native_codecprivate(AVFormatContext *s, - AVCodecContext *codec, + AVCodecParameters *par, AVIOContext *dyn_cp) { - switch (codec->codec_id) { + switch (par->codec_id) { case AV_CODEC_ID_VORBIS: case AV_CODEC_ID_THEORA: - return put_xiph_codecpriv(s, dyn_cp, codec); + return put_xiph_codecpriv(s, dyn_cp, par); case AV_CODEC_ID_FLAC: - return put_flac_codecpriv(s, dyn_cp, codec); + return put_flac_codecpriv(s, dyn_cp, par); case AV_CODEC_ID_WAVPACK: - return put_wv_codecpriv(dyn_cp, codec); + return put_wv_codecpriv(dyn_cp, par); case AV_CODEC_ID_H264: - return ff_isom_write_avcc(dyn_cp, codec->extradata, - codec->extradata_size); + return ff_isom_write_avcc(dyn_cp, par->extradata, + par->extradata_size); case AV_CODEC_ID_HEVC: - ff_isom_write_hvcc(dyn_cp, codec->extradata, - codec->extradata_size, 0); + ff_isom_write_hvcc(dyn_cp, par->extradata, + par->extradata_size, 0); return 0; case AV_CODEC_ID_ALAC: - if (codec->extradata_size < 36) { + if (par->extradata_size < 36) { av_log(s, AV_LOG_ERROR, "Invalid extradata found, ALAC expects a 36-byte " "QuickTime atom."); return AVERROR_INVALIDDATA; } else - avio_write(dyn_cp, codec->extradata + 12, - codec->extradata_size - 12); + avio_write(dyn_cp, par->extradata + 12, + par->extradata_size - 12); break; default: - if (codec->codec_id == AV_CODEC_ID_PRORES && - ff_codec_get_id(ff_codec_movvideo_tags, codec->codec_tag) == AV_CODEC_ID_PRORES) { - avio_wl32(dyn_cp, codec->codec_tag); - } else if (codec->extradata_size && codec->codec_id != AV_CODEC_ID_TTA) - avio_write(dyn_cp, codec->extradata, codec->extradata_size); + if (par->codec_id == AV_CODEC_ID_PRORES && + ff_codec_get_id(ff_codec_movvideo_tags, par->codec_tag) == AV_CODEC_ID_PRORES) { + avio_wl32(dyn_cp, par->codec_tag); + } else if (par->extradata_size && par->codec_id != AV_CODEC_ID_TTA) + avio_write(dyn_cp, par->extradata, par->extradata_size); } return 0; } static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, - AVCodecContext *codec, int native_id, - int qt_id) + AVCodecParameters *par, + int native_id, int qt_id) { AVIOContext *dyn_cp; uint8_t *codecpriv; @@ -675,52 +675,52 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, return ret; if (native_id) { - ret = mkv_write_native_codecprivate(s, codec, dyn_cp); - } else if (codec->codec_type == AVMEDIA_TYPE_VIDEO) { + ret = mkv_write_native_codecprivate(s, par, dyn_cp); + } else if (par->codec_type == AVMEDIA_TYPE_VIDEO) { if (qt_id) { - if (!codec->codec_tag) - codec->codec_tag = ff_codec_get_tag(ff_codec_movvideo_tags, - codec->codec_id); - if (codec->extradata_size) { - if ( ff_codec_get_id(ff_codec_movvideo_tags, codec->codec_tag) == codec->codec_id - && ff_codec_get_id(ff_codec_movvideo_tags, AV_RL32(codec->extradata + 4)) != codec->codec_id + if (!par->codec_tag) + par->codec_tag = ff_codec_get_tag(ff_codec_movvideo_tags, + par->codec_id); + if (par->extradata_size) { + if ( ff_codec_get_id(ff_codec_movvideo_tags, par->codec_tag) == par->codec_id + && ff_codec_get_id(ff_codec_movvideo_tags, AV_RL32(par->extradata + 4)) != par->codec_id ) { int i; - avio_wb32(dyn_cp, 0x5a + codec->extradata_size); - avio_wl32(dyn_cp, codec->codec_tag); + avio_wb32(dyn_cp, 0x5a + par->extradata_size); + avio_wl32(dyn_cp, par->codec_tag); for(i = 0; i < 0x5a - 8; i++) avio_w8(dyn_cp, 0); } - avio_write(dyn_cp, codec->extradata, codec->extradata_size); + avio_write(dyn_cp, par->extradata, par->extradata_size); } } else { - if (!ff_codec_get_tag(ff_codec_bmp_tags, codec->codec_id)) + if (!ff_codec_get_tag(ff_codec_bmp_tags, par->codec_id)) av_log(s, AV_LOG_WARNING, "codec %s is not supported by this format\n", - avcodec_get_name(codec->codec_id)); + avcodec_get_name(par->codec_id)); - if (!codec->codec_tag) - codec->codec_tag = ff_codec_get_tag(ff_codec_bmp_tags, - codec->codec_id); - if (!codec->codec_tag && codec->codec_id != AV_CODEC_ID_RAWVIDEO) { + if (!par->codec_tag) + par->codec_tag = ff_codec_get_tag(ff_codec_bmp_tags, + par->codec_id); + if (!par->codec_tag && par->codec_id != AV_CODEC_ID_RAWVIDEO) { av_log(s, AV_LOG_ERROR, "No bmp codec tag found for codec %s\n", - avcodec_get_name(codec->codec_id)); + avcodec_get_name(par->codec_id)); ret = AVERROR(EINVAL); } - ff_put_bmp_header(dyn_cp, codec, ff_codec_bmp_tags, 0, 0); + ff_put_bmp_header(dyn_cp, par, ff_codec_bmp_tags, 0, 0); } - } else if (codec->codec_type == AVMEDIA_TYPE_AUDIO) { + } else if (par->codec_type == AVMEDIA_TYPE_AUDIO) { unsigned int tag; - tag = ff_codec_get_tag(ff_codec_wav_tags, codec->codec_id); + tag = ff_codec_get_tag(ff_codec_wav_tags, par->codec_id); if (!tag) { av_log(s, AV_LOG_ERROR, "No wav codec tag found for codec %s\n", - avcodec_get_name(codec->codec_id)); + avcodec_get_name(par->codec_id)); ret = AVERROR(EINVAL); } - if (!codec->codec_tag) - codec->codec_tag = tag; + if (!par->codec_tag) + par->codec_tag = tag; - ff_put_wav_header(dyn_cp, codec, FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX); + ff_put_wav_header(s, dyn_cp, par, FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX); } codecpriv_size = avio_close_dyn_buf(dyn_cp, &codecpriv); @@ -731,28 +731,28 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, return ret; } -static int mkv_write_video_color(AVIOContext *pb, AVCodecContext *codec, AVStream *st) { +static int mkv_write_video_color(AVIOContext *pb, AVCodecParameters *par, AVStream *st) { int side_data_size = 0; const uint8_t *side_data = av_stream_get_side_data( st, AV_PKT_DATA_MASTERING_DISPLAY_METADATA, &side_data_size); ebml_master colorinfo = start_ebml_master(pb, MATROSKA_ID_VIDEOCOLOR, 0); - if (codec->color_trc != AVCOL_TRC_UNSPECIFIED && - codec->color_trc < AVCOL_TRC_NB) { + if (par->color_trc != AVCOL_TRC_UNSPECIFIED && + par->color_trc < AVCOL_TRC_NB) { put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORTRANSFERCHARACTERISTICS, - codec->color_trc); + par->color_trc); } - if (codec->colorspace != AVCOL_SPC_UNSPECIFIED && - codec->colorspace < AVCOL_SPC_NB) { - put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORMATRIXCOEFF, codec->colorspace); + if (par->color_space != AVCOL_SPC_UNSPECIFIED && + par->color_space < AVCOL_SPC_NB) { + put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORMATRIXCOEFF, par->color_space); } - if (codec->color_primaries != AVCOL_PRI_UNSPECIFIED && - codec->color_primaries < AVCOL_PRI_NB) { - put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORPRIMARIES, codec->color_primaries); + if (par->color_primaries != AVCOL_PRI_UNSPECIFIED && + par->color_primaries < AVCOL_PRI_NB) { + put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORPRIMARIES, par->color_primaries); } - if (codec->color_range != AVCOL_RANGE_UNSPECIFIED && - codec->color_range < AVCOL_RANGE_NB) { - put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORRANGE, codec->color_range); + if (par->color_range != AVCOL_RANGE_UNSPECIFIED && + par->color_range < AVCOL_RANGE_NB) { + put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORRANGE, par->color_range); } if (side_data_size == sizeof(AVMasteringDisplayMetadata)) { ebml_master meta_element = start_ebml_master( @@ -892,34 +892,34 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, int i, AVIOContext *pb, int default_stream_exists) { AVStream *st = s->streams[i]; - AVCodecContext *codec = st->codec; + AVCodecParameters *par = st->codecpar; ebml_master subinfo, track; int native_id = 0; int qt_id = 0; - int bit_depth = av_get_bits_per_sample(codec->codec_id); - int sample_rate = codec->sample_rate; + int bit_depth = av_get_bits_per_sample(par->codec_id); + int sample_rate = par->sample_rate; int output_sample_rate = 0; int display_width_div = 1; int display_height_div = 1; int j, ret; AVDictionaryEntry *tag; - if (codec->codec_type == AVMEDIA_TYPE_ATTACHMENT) { + if (par->codec_type == AVMEDIA_TYPE_ATTACHMENT) { mkv->have_attachments = 1; return 0; } - if (!bit_depth && codec->codec_id != AV_CODEC_ID_ADPCM_G726) { - if (codec->bits_per_raw_sample) - bit_depth = codec->bits_per_raw_sample; + if (!bit_depth && par->codec_id != AV_CODEC_ID_ADPCM_G726) { + if (par->bits_per_coded_sample) + bit_depth = par->bits_per_coded_sample; else - bit_depth = av_get_bytes_per_sample(codec->sample_fmt) << 3; + bit_depth = av_get_bytes_per_sample(par->format) << 3; } if (!bit_depth) - bit_depth = codec->bits_per_coded_sample; + bit_depth = par->bits_per_coded_sample; - if (codec->codec_id == AV_CODEC_ID_AAC) { - ret = get_aac_sample_rates(s, codec, &sample_rate, &output_sample_rate); + if (par->codec_id == AV_CODEC_ID_AAC) { + ret = get_aac_sample_rates(s, par, &sample_rate, &output_sample_rate); if (ret < 0) return ret; } @@ -934,7 +934,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, if ((tag = av_dict_get(st->metadata, "title", NULL, 0))) put_ebml_string(pb, MATROSKA_ID_TRACKNAME, tag->value); tag = av_dict_get(st->metadata, "language", NULL, 0); - if (mkv->mode != MODE_WEBM || codec->codec_id != AV_CODEC_ID_WEBVTT) { + if (mkv->mode != MODE_WEBM || par->codec_id != AV_CODEC_ID_WEBVTT) { put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, tag && tag->value ? tag->value:"und"); } else if (tag && tag->value) { put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, tag->value); @@ -948,7 +948,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, if (st->disposition & AV_DISPOSITION_FORCED) put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGFORCED, 1); - if (mkv->mode == MODE_WEBM && codec->codec_id == AV_CODEC_ID_WEBVTT) { + if (mkv->mode == MODE_WEBM && par->codec_id == AV_CODEC_ID_WEBVTT) { const char *codec_id; if (st->disposition & AV_DISPOSITION_CAPTIONS) { codec_id = "D_WEBVTT/CAPTIONS"; @@ -968,13 +968,13 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, // look for a codec ID string specific to mkv to use, // if none are found, use AVI codes for (j = 0; ff_mkv_codec_tags[j].id != AV_CODEC_ID_NONE; j++) { - if (ff_mkv_codec_tags[j].id == codec->codec_id) { + if (ff_mkv_codec_tags[j].id == par->codec_id) { put_ebml_string(pb, MATROSKA_ID_CODECID, ff_mkv_codec_tags[j].str); native_id = 1; break; } } - if (codec->codec_id == AV_CODEC_ID_RAWVIDEO && !codec->codec_tag) { + if (par->codec_id == AV_CODEC_ID_RAWVIDEO && !par->codec_tag) { if (mkv->allow_raw_vfw) { native_id = 0; } else { @@ -985,50 +985,50 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, } } - if (codec->codec_type == AVMEDIA_TYPE_AUDIO && codec->initial_padding && codec->codec_id == AV_CODEC_ID_OPUS) { - int64_t codecdelay = av_rescale_q(codec->initial_padding, + if (par->codec_type == AVMEDIA_TYPE_AUDIO && par->initial_padding && par->codec_id == AV_CODEC_ID_OPUS) { + int64_t codecdelay = av_rescale_q(par->initial_padding, (AVRational){ 1, 48000 }, (AVRational){ 1, 1000000000 }); if (codecdelay < 0) { av_log(s, AV_LOG_ERROR, "Initial padding is invalid\n"); return AVERROR(EINVAL); } -// mkv->tracks[i].ts_offset = av_rescale_q(codec->initial_padding, -// (AVRational){ 1, codec->sample_rate }, +// mkv->tracks[i].ts_offset = av_rescale_q(par->initial_padding, +// (AVRational){ 1, par->sample_rate }, // st->time_base); put_ebml_uint(pb, MATROSKA_ID_CODECDELAY, codecdelay); } - if (codec->codec_id == AV_CODEC_ID_OPUS) { + if (par->codec_id == AV_CODEC_ID_OPUS) { put_ebml_uint(pb, MATROSKA_ID_SEEKPREROLL, OPUS_SEEK_PREROLL); } - if (mkv->mode == MODE_WEBM && !(codec->codec_id == AV_CODEC_ID_VP8 || - codec->codec_id == AV_CODEC_ID_VP9 || - codec->codec_id == AV_CODEC_ID_OPUS || - codec->codec_id == AV_CODEC_ID_VORBIS || - codec->codec_id == AV_CODEC_ID_WEBVTT)) { + if (mkv->mode == MODE_WEBM && !(par->codec_id == AV_CODEC_ID_VP8 || + par->codec_id == AV_CODEC_ID_VP9 || + par->codec_id == AV_CODEC_ID_OPUS || + par->codec_id == AV_CODEC_ID_VORBIS || + par->codec_id == AV_CODEC_ID_WEBVTT)) { av_log(s, AV_LOG_ERROR, "Only VP8 or VP9 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM.\n"); return AVERROR(EINVAL); } - switch (codec->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_VIDEO); if( st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0 - && av_cmp_q(av_inv_q(st->avg_frame_rate), codec->time_base) > 0) + && av_cmp_q(av_inv_q(st->avg_frame_rate), st->time_base) > 0) put_ebml_uint(pb, MATROSKA_ID_TRACKDEFAULTDURATION, 1000000000LL * st->avg_frame_rate.den / st->avg_frame_rate.num); else - put_ebml_uint(pb, MATROSKA_ID_TRACKDEFAULTDURATION, 1000000000LL * codec->time_base.num / codec->time_base.den); + put_ebml_uint(pb, MATROSKA_ID_TRACKDEFAULTDURATION, 1000000000LL * st->time_base.num / st->time_base.den); if (!native_id && - ff_codec_get_tag(ff_codec_movvideo_tags, codec->codec_id) && - ((!ff_codec_get_tag(ff_codec_bmp_tags, codec->codec_id) && codec->codec_id != AV_CODEC_ID_RAWVIDEO) || - codec->codec_id == AV_CODEC_ID_SVQ1 || - codec->codec_id == AV_CODEC_ID_SVQ3 || - codec->codec_id == AV_CODEC_ID_CINEPAK)) + ff_codec_get_tag(ff_codec_movvideo_tags, par->codec_id) && + ((!ff_codec_get_tag(ff_codec_bmp_tags, par->codec_id) && par->codec_id != AV_CODEC_ID_RAWVIDEO) || + par->codec_id == AV_CODEC_ID_SVQ1 || + par->codec_id == AV_CODEC_ID_SVQ3 || + par->codec_id == AV_CODEC_ID_CINEPAK)) qt_id = 1; if (qt_id) @@ -1042,8 +1042,8 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKVIDEO, 0); // XXX: interlace flag? - put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELWIDTH , codec->width); - put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELHEIGHT, codec->height); + put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELWIDTH , par->width); + put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELHEIGHT, par->height); // check both side data and metadata for stereo information, // write the result to the bitstream if any is found @@ -1055,31 +1055,31 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, if (((tag = av_dict_get(st->metadata, "alpha_mode", NULL, 0)) && atoi(tag->value)) || ((tag = av_dict_get( s->metadata, "alpha_mode", NULL, 0)) && atoi(tag->value)) || - (codec->pix_fmt == AV_PIX_FMT_YUVA420P)) { + (par->format == AV_PIX_FMT_YUVA420P)) { put_ebml_uint(pb, MATROSKA_ID_VIDEOALPHAMODE, 1); } // write DisplayWidth and DisplayHeight, they contain the size of // a single source view and/or the display aspect ratio if (st->sample_aspect_ratio.num) { - int64_t d_width = av_rescale(codec->width, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den); + int64_t d_width = av_rescale(par->width, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den); if (d_width > INT_MAX) { av_log(s, AV_LOG_ERROR, "Overflow in display width\n"); return AVERROR(EINVAL); } put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , d_width / display_width_div); - put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, codec->height / display_height_div); + put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, par->height / display_height_div); } else if (display_width_div != 1 || display_height_div != 1) { - put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , codec->width / display_width_div); - put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, codec->height / display_height_div); + put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , par->width / display_width_div); + put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, par->height / display_height_div); } - if (codec->codec_id == AV_CODEC_ID_RAWVIDEO) { - uint32_t color_space = av_le2ne32(codec->codec_tag); + if (par->codec_id == AV_CODEC_ID_RAWVIDEO) { + uint32_t color_space = av_le2ne32(par->codec_tag); put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLORSPACE, &color_space, sizeof(color_space)); } if (s->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL) { - mkv_write_video_color(pb, codec, st); + mkv_write_video_color(pb, par, st); } end_ebml_master(pb, subinfo); break; @@ -1092,7 +1092,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, put_ebml_string(pb, MATROSKA_ID_CODECID, "A_MS/ACM"); subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKAUDIO, 0); - put_ebml_uint (pb, MATROSKA_ID_AUDIOCHANNELS , codec->channels); + put_ebml_uint (pb, MATROSKA_ID_AUDIOCHANNELS , par->channels); put_ebml_float (pb, MATROSKA_ID_AUDIOSAMPLINGFREQ, sample_rate); if (output_sample_rate) put_ebml_float(pb, MATROSKA_ID_AUDIOOUTSAMPLINGFREQ, output_sample_rate); @@ -1103,11 +1103,11 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, case AVMEDIA_TYPE_SUBTITLE: if (!native_id) { - av_log(s, AV_LOG_ERROR, "Subtitle codec %d is not supported.\n", codec->codec_id); + av_log(s, AV_LOG_ERROR, "Subtitle codec %d is not supported.\n", par->codec_id); return AVERROR(ENOSYS); } - if (mkv->mode != MODE_WEBM || codec->codec_id != AV_CODEC_ID_WEBVTT) + if (mkv->mode != MODE_WEBM || par->codec_id != AV_CODEC_ID_WEBVTT) native_id = MATROSKA_TRACK_TYPE_SUBTITLE; put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, native_id); @@ -1117,8 +1117,8 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, return AVERROR(EINVAL); } - if (mkv->mode != MODE_WEBM || codec->codec_id != AV_CODEC_ID_WEBVTT) { - ret = mkv_write_codecprivate(s, pb, codec, native_id, qt_id); + if (mkv->mode != MODE_WEBM || par->codec_id != AV_CODEC_ID_WEBVTT) { + ret = mkv_write_codecprivate(s, pb, par, native_id, qt_id); if (ret < 0) return ret; } @@ -1383,7 +1383,7 @@ static int mkv_write_attachments(AVFormatContext *s) const char *mimetype = NULL; uint64_t fileuid; - if (st->codec->codec_type != AVMEDIA_TYPE_ATTACHMENT) + if (st->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT) continue; attached_file = start_ebml_master(pb, MATROSKA_ID_ATTACHEDFILE, 0); @@ -1397,15 +1397,15 @@ static int mkv_write_attachments(AVFormatContext *s) put_ebml_string(pb, MATROSKA_ID_FILENAME, t->value); if (t = av_dict_get(st->metadata, "mimetype", NULL, 0)) mimetype = t->value; - else if (st->codec->codec_id != AV_CODEC_ID_NONE ) { + else if (st->codecpar->codec_id != AV_CODEC_ID_NONE ) { int i; for (i = 0; ff_mkv_mime_tags[i].id != AV_CODEC_ID_NONE; i++) - if (ff_mkv_mime_tags[i].id == st->codec->codec_id) { + if (ff_mkv_mime_tags[i].id == st->codecpar->codec_id) { mimetype = ff_mkv_mime_tags[i].str; break; } for (i = 0; ff_mkv_image_mime_tags[i].id != AV_CODEC_ID_NONE; i++) - if (ff_mkv_image_mime_tags[i].id == st->codec->codec_id) { + if (ff_mkv_image_mime_tags[i].id == st->codecpar->codec_id) { mimetype = ff_mkv_image_mime_tags[i].str; break; } @@ -1422,7 +1422,7 @@ static int mkv_write_attachments(AVFormatContext *s) if (!sha) return AVERROR(ENOMEM); av_sha_init(sha, 160); - av_sha_update(sha, st->codec->extradata, st->codec->extradata_size); + av_sha_update(sha, st->codecpar->extradata, st->codecpar->extradata_size); av_sha_final(sha, digest); av_free(sha); fileuid = AV_RL64(digest); @@ -1433,7 +1433,7 @@ static int mkv_write_attachments(AVFormatContext *s) fileuid, i); put_ebml_string(pb, MATROSKA_ID_FILEMIMETYPE, mimetype); - put_ebml_binary(pb, MATROSKA_ID_FILEDATA, st->codec->extradata, st->codec->extradata_size); + put_ebml_binary(pb, MATROSKA_ID_FILEDATA, st->codecpar->extradata, st->codecpar->extradata_size); put_ebml_uint(pb, MATROSKA_ID_FILEUID, fileuid); end_ebml_master(pb, attached_file); } @@ -1462,18 +1462,18 @@ static int mkv_write_header(AVFormatContext *s) version = 4; for (i = 0; i < s->nb_streams; i++) { - if (s->streams[i]->codec->codec_id == AV_CODEC_ID_ATRAC3 || - s->streams[i]->codec->codec_id == AV_CODEC_ID_COOK || - s->streams[i]->codec->codec_id == AV_CODEC_ID_RA_288 || - s->streams[i]->codec->codec_id == AV_CODEC_ID_SIPR || - s->streams[i]->codec->codec_id == AV_CODEC_ID_RV10 || - s->streams[i]->codec->codec_id == AV_CODEC_ID_RV20) { + if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_ATRAC3 || + s->streams[i]->codecpar->codec_id == AV_CODEC_ID_COOK || + s->streams[i]->codecpar->codec_id == AV_CODEC_ID_RA_288 || + s->streams[i]->codecpar->codec_id == AV_CODEC_ID_SIPR || + s->streams[i]->codecpar->codec_id == AV_CODEC_ID_RV10 || + s->streams[i]->codecpar->codec_id == AV_CODEC_ID_RV20) { av_log(s, AV_LOG_ERROR, "The Matroska muxer does not yet support muxing %s\n", - avcodec_get_name(s->streams[i]->codec->codec_id)); + avcodec_get_name(s->streams[i]->codecpar->codec_id)); return AVERROR_PATCHWELCOME; } - if (s->streams[i]->codec->codec_id == AV_CODEC_ID_OPUS || + if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_OPUS || av_dict_get(s->streams[i]->metadata, "stereo_mode", NULL, 0) || av_dict_get(s->streams[i]->metadata, "alpha_mode", NULL, 0)) version = 4; @@ -1684,7 +1684,7 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, unsigned int blockid, AVPacket *pkt, int keyframe) { MatroskaMuxContext *mkv = s->priv_data; - AVCodecContext *codec = s->streams[pkt->stream_index]->codec; + AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; uint8_t *data = NULL, *side_data = NULL; int offset = 0, size = pkt->size, side_data_size = 0; int64_t ts = mkv->tracks[pkt->stream_index].write_dts ? pkt->dts : pkt->pts; @@ -1697,14 +1697,14 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, "pts %" PRId64 ", dts %" PRId64 ", duration %" PRId64 ", keyframe %d\n", avio_tell(pb), pkt->size, pkt->pts, pkt->dts, pkt->duration, keyframe != 0); - if (codec->codec_id == AV_CODEC_ID_H264 && codec->extradata_size > 0 && - (AV_RB24(codec->extradata) == 1 || AV_RB32(codec->extradata) == 1)) + if (par->codec_id == AV_CODEC_ID_H264 && par->extradata_size > 0 && + (AV_RB24(par->extradata) == 1 || AV_RB32(par->extradata) == 1)) ff_avc_parse_nal_units_buf(pkt->data, &data, &size); - else if (codec->codec_id == AV_CODEC_ID_HEVC && codec->extradata_size > 6 && - (AV_RB24(codec->extradata) == 1 || AV_RB32(codec->extradata) == 1)) + else if (par->codec_id == AV_CODEC_ID_HEVC && par->extradata_size > 6 && + (AV_RB24(par->extradata) == 1 || AV_RB32(par->extradata) == 1)) /* extradata is Annex B, assume the bitstream is too and convert it */ ff_hevc_annexb2mp4_buf(pkt->data, &data, &size, 0, NULL); - else if (codec->codec_id == AV_CODEC_ID_WAVPACK) { + else if (par->codec_id == AV_CODEC_ID_WAVPACK) { int ret = mkv_strip_wavpack(pkt->data, &data, &size); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Error stripping a WavPack packet.\n"); @@ -1713,7 +1713,7 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, } else data = pkt->data; - if (codec->codec_id == AV_CODEC_ID_PRORES && size >= 8) { + if (par->codec_id == AV_CODEC_ID_PRORES && size >= 8) { /* Matroska specification requires to remove the first QuickTime atom */ size -= 8; @@ -1726,7 +1726,7 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, if (side_data && side_data_size >= 10) { discard_padding = av_rescale_q(AV_RL32(side_data + 4), - (AVRational){1, codec->sample_rate}, + (AVRational){1, par->sample_rate}, (AVRational){1, 1000000000}); } @@ -1858,7 +1858,7 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int add_ { MatroskaMuxContext *mkv = s->priv_data; AVIOContext *pb = s->pb; - AVCodecContext *codec = s->streams[pkt->stream_index]->codec; + AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; int keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY); int duration = pkt->duration; int ret; @@ -1900,14 +1900,14 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int add_ relative_packet_pos = avio_tell(s->pb) - mkv->cluster.pos; - if (codec->codec_type != AVMEDIA_TYPE_SUBTITLE) { + if (par->codec_type != AVMEDIA_TYPE_SUBTITLE) { mkv_write_block(s, pb, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe); - if (s->pb->seekable && (codec->codec_type == AVMEDIA_TYPE_VIDEO && keyframe || add_cue)) { + if (s->pb->seekable && (par->codec_type == AVMEDIA_TYPE_VIDEO && keyframe || add_cue)) { ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, dash_tracknum, ts, mkv->cluster_pos, relative_packet_pos, -1); if (ret < 0) return ret; } } else { - if (codec->codec_id == AV_CODEC_ID_WEBVTT) { + if (par->codec_id == AV_CODEC_ID_WEBVTT) { duration = mkv_write_vtt_blocks(s, pb, pkt); } else { ebml_master blockgroup = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP, @@ -1947,7 +1947,7 @@ FF_ENABLE_DEPRECATION_WARNINGS static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) { MatroskaMuxContext *mkv = s->priv_data; - int codec_type = s->streams[pkt->stream_index]->codec->codec_type; + int codec_type = s->streams[pkt->stream_index]->codecpar->codec_type; int keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY); int cluster_size; int64_t cluster_time; @@ -2183,10 +2183,10 @@ static int mkv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt) int ret = 1; AVStream *st = s->streams[pkt->stream_index]; - if (st->codec->codec_id == AV_CODEC_ID_AAC) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC) { if (pkt->size > 2 && (AV_RB16(pkt->data) & 0xfff0) == 0xfff0) ret = ff_stream_add_bitstream_filter(st, "aac_adtstoasc", NULL); - } else if (st->codec->codec_id == AV_CODEC_ID_VP9) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_VP9) { ret = ff_stream_add_bitstream_filter(st, "vp9_superframe", NULL); } diff --git a/libavformat/mgsts.c b/libavformat/mgsts.c index 8cbc9521d6..0720de8d86 100644 --- a/libavformat/mgsts.c +++ b/libavformat/mgsts.c @@ -55,13 +55,13 @@ static int read_header(AVFormatContext *s) st->nb_frames = st->duration = avio_rb32(pb); fps = av_d2q(av_int2float(avio_rb32(pb)), INT_MAX); - st->codec->width = avio_rb32(pb); - st->codec->height = avio_rb32(pb); + st->codecpar->width = avio_rb32(pb); + st->codecpar->height = avio_rb32(pb); avio_skip(pb, 12); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_tag = avio_rb32(pb); - st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, - st->codec->codec_tag); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_tag = avio_rb32(pb); + st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, + st->codecpar->codec_tag); avpriv_set_pts_info(st, 64, fps.den, fps.num); avio_skip(pb, 20); diff --git a/libavformat/microdvddec.c b/libavformat/microdvddec.c index 727ff947e7..c2f1ac45cd 100644 --- a/libavformat/microdvddec.c +++ b/libavformat/microdvddec.c @@ -114,11 +114,11 @@ static int microdvd_read_header(AVFormatContext *s) has_real_fps = 1; continue; } - if (!st->codec->extradata && sscanf(line, "{DEFAULT}{}%c", &c) == 1) { - st->codec->extradata = av_strdup(line + 11); - if (!st->codec->extradata) + if (!st->codecpar->extradata && sscanf(line, "{DEFAULT}{}%c", &c) == 1) { + st->codecpar->extradata = av_strdup(line + 11); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - st->codec->extradata_size = strlen(st->codec->extradata) + 1; + st->codecpar->extradata_size = strlen(st->codecpar->extradata) + 1; continue; } } @@ -150,8 +150,8 @@ static int microdvd_read_header(AVFormatContext *s) pts_info = microdvd->frame_rate; } avpriv_set_pts_info(st, 64, pts_info.den, pts_info.num); - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = AV_CODEC_ID_MICRODVD; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_MICRODVD; return 0; } diff --git a/libavformat/microdvdenc.c b/libavformat/microdvdenc.c index 4d8438437b..04f475b645 100644 --- a/libavformat/microdvdenc.c +++ b/libavformat/microdvdenc.c @@ -25,21 +25,21 @@ static int microdvd_write_header(struct AVFormatContext *s) { - AVCodecContext *avctx = s->streams[0]->codec; - AVRational tb = avctx->time_base; + AVCodecParameters *par = s->streams[0]->codecpar; + AVRational framerate = s->streams[0]->avg_frame_rate; - if (s->nb_streams != 1 || avctx->codec_id != AV_CODEC_ID_MICRODVD) { + if (s->nb_streams != 1 || par->codec_id != AV_CODEC_ID_MICRODVD) { av_log(s, AV_LOG_ERROR, "Exactly one MicroDVD stream is needed.\n"); return -1; } - if (avctx->extradata && avctx->extradata_size > 0) { + if (par->extradata && par->extradata_size > 0) { avio_write(s->pb, "{DEFAULT}{}", 11); - avio_write(s->pb, avctx->extradata, avctx->extradata_size); + avio_write(s->pb, par->extradata, par->extradata_size); avio_flush(s->pb); } - avpriv_set_pts_info(s->streams[0], 64, tb.num, tb.den); + avpriv_set_pts_info(s->streams[0], 64, framerate.num, framerate.den); return 0; } diff --git a/libavformat/mlvdec.c b/libavformat/mlvdec.c index 288b2a1010..665b28d4f8 100644 --- a/libavformat/mlvdec.c +++ b/libavformat/mlvdec.c @@ -130,32 +130,32 @@ static int scan_file(AVFormatContext *avctx, AVStream *vst, AVStream *ast, int f break; size -= 16; if (vst && type == MKTAG('R','A','W','I') && size >= 164) { - vst->codec->width = avio_rl16(pb); - vst->codec->height = avio_rl16(pb); - ret = av_image_check_size(vst->codec->width, vst->codec->height, 0, avctx); + vst->codecpar->width = avio_rl16(pb); + vst->codecpar->height = avio_rl16(pb); + ret = av_image_check_size(vst->codecpar->width, vst->codecpar->height, 0, avctx); if (ret < 0) return ret; if (avio_rl32(pb) != 1) avpriv_request_sample(avctx, "raw api version"); avio_skip(pb, 20); // pointer, width, height, pitch, frame_size - vst->codec->bits_per_coded_sample = avio_rl32(pb); - if (vst->codec->bits_per_coded_sample < 0 || - vst->codec->bits_per_coded_sample > (INT_MAX - 7) / (vst->codec->width * vst->codec->height)) { + vst->codecpar->bits_per_coded_sample = avio_rl32(pb); + if (vst->codecpar->bits_per_coded_sample < 0 || + vst->codecpar->bits_per_coded_sample > (INT_MAX - 7) / (vst->codecpar->width * vst->codecpar->height)) { av_log(avctx, AV_LOG_ERROR, "invalid bits_per_coded_sample %d (size: %dx%d)\n", - vst->codec->bits_per_coded_sample, - vst->codec->width, vst->codec->height); + vst->codecpar->bits_per_coded_sample, + vst->codecpar->width, vst->codecpar->height); return AVERROR_INVALIDDATA; } avio_skip(pb, 8 + 16 + 24); // black_level, white_level, xywh, active_area, exposure_bias if (avio_rl32(pb) != 0x2010100) /* RGGB */ avpriv_request_sample(avctx, "cfa_pattern"); avio_skip(pb, 80); // calibration_illuminant1, color_matrix1, dynamic_range - vst->codec->pix_fmt = AV_PIX_FMT_BAYER_RGGB16LE; - vst->codec->codec_tag = MKTAG('B', 'I', 'T', 16); + vst->codecpar->format = AV_PIX_FMT_BAYER_RGGB16LE; + vst->codecpar->codec_tag = MKTAG('B', 'I', 'T', 16); size -= 164; } else if (ast && type == MKTAG('W', 'A', 'V', 'I') && size >= 16) { - ret = ff_get_wav_header(avctx, pb, ast->codec, 16, 0); + ret = ff_get_wav_header(avctx, pb, ast->codecpar, 16, 0); if (ret < 0) return ret; size -= 16; @@ -286,23 +286,23 @@ static int read_header(AVFormatContext *avctx) vst->nb_frames = nb_video_frames; if ((mlv->class[0] & (MLV_CLASS_FLAG_DELTA|MLV_CLASS_FLAG_LZMA))) avpriv_request_sample(avctx, "compression"); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; switch (mlv->class[0] & ~(MLV_CLASS_FLAG_DELTA|MLV_CLASS_FLAG_LZMA)) { case MLV_VIDEO_CLASS_RAW: - vst->codec->codec_id = AV_CODEC_ID_RAWVIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; break; case MLV_VIDEO_CLASS_YUV: - vst->codec->pix_fmt = AV_PIX_FMT_YUV420P; - vst->codec->codec_id = AV_CODEC_ID_RAWVIDEO; - vst->codec->codec_tag = 0; + vst->codecpar->format = AV_PIX_FMT_YUV420P; + vst->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + vst->codecpar->codec_tag = 0; break; case MLV_VIDEO_CLASS_JPEG: - vst->codec->codec_id = AV_CODEC_ID_MJPEG; - vst->codec->codec_tag = 0; + vst->codecpar->codec_id = AV_CODEC_ID_MJPEG; + vst->codecpar->codec_tag = 0; break; case MLV_VIDEO_CLASS_H264: - vst->codec->codec_id = AV_CODEC_ID_H264; - vst->codec->codec_tag = 0; + vst->codecpar->codec_id = AV_CODEC_ID_H264; + vst->codecpar->codec_tag = 0; break; default: avpriv_request_sample(avctx, "unknown video class"); @@ -320,8 +320,8 @@ static int read_header(AVFormatContext *avctx) if ((mlv->class[1] & ~MLV_CLASS_FLAG_LZMA) != MLV_AUDIO_CLASS_WAV) avpriv_request_sample(avctx, "unknown audio class"); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - avpriv_set_pts_info(ast, 33, 1, ast->codec->sample_rate); + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + avpriv_set_pts_info(ast, 33, 1, ast->codecpar->sample_rate); } if (vst) { @@ -413,15 +413,15 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt) if (size < 16) return AVERROR_INVALIDDATA; avio_skip(pb, 12); //timestamp, frameNumber - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) avio_skip(pb, 8); // cropPosX, cropPosY, panPosX, panPosY space = avio_rl32(pb); avio_skip(pb, space); if ((mlv->class[st->id] & (MLV_CLASS_FLAG_DELTA|MLV_CLASS_FLAG_LZMA))) { ret = AVERROR_PATCHWELCOME; - } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { - ret = av_get_packet(pb, pkt, (st->codec->width * st->codec->height * st->codec->bits_per_coded_sample + 7) >> 3); + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + ret = av_get_packet(pb, pkt, (st->codecpar->width * st->codecpar->height * st->codecpar->bits_per_coded_sample + 7) >> 3); } else { // AVMEDIA_TYPE_AUDIO if (space > UINT_MAX - 24 || size < (24 + space)) return AVERROR_INVALIDDATA; diff --git a/libavformat/mm.c b/libavformat/mm.c index 81ae1a510e..8a1382e03c 100644 --- a/libavformat/mm.c +++ b/libavformat/mm.c @@ -109,11 +109,11 @@ static int read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MMVIDEO; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = width; - st->codec->height = height; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MMVIDEO; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = width; + st->codecpar->height = height; avpriv_set_pts_info(st, 64, 1, frame_rate); /* audio stream */ @@ -121,12 +121,12 @@ static int read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->codec_id = AV_CODEC_ID_PCM_U8; - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->sample_rate = 8000; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->codec_id = AV_CODEC_ID_PCM_U8; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->sample_rate = 8000; avpriv_set_pts_info(st, 64, 1, 8000); /* 8000 hz */ } diff --git a/libavformat/mmf.c b/libavformat/mmf.c index c2acec91eb..b8a9cad32e 100644 --- a/libavformat/mmf.c +++ b/libavformat/mmf.c @@ -73,14 +73,14 @@ static int mmf_write_header(AVFormatContext *s) "VN:Lavf," : "VN:"LIBAVFORMAT_IDENT","; - rate = mmf_rate_code(s->streams[0]->codec->sample_rate); + rate = mmf_rate_code(s->streams[0]->codecpar->sample_rate); if (rate < 0) { av_log(s, AV_LOG_ERROR, "Unsupported sample rate %d, supported are 4000, 8000, 11025, 22050 and 44100\n", - s->streams[0]->codec->sample_rate); + s->streams[0]->codecpar->sample_rate); return AVERROR(EINVAL); } - mmf->stereo = s->streams[0]->codec->channels > 1; + mmf->stereo = s->streams[0]->codecpar->channels > 1; if (mmf->stereo && s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { av_log(s, AV_LOG_ERROR, "Yamaha SMAF stereo is experimental, " @@ -121,7 +121,7 @@ static int mmf_write_header(AVFormatContext *s) mmf->awapos = ff_start_tag(pb, "Awa\x01"); - avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); + avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codecpar->sample_rate); avio_flush(pb); @@ -162,7 +162,7 @@ static int mmf_write_trailer(AVFormatContext *s) /* "play wav" */ avio_w8(pb, 0); /* start time */ avio_w8(pb, (mmf->stereo << 6) | 1); /* (channel << 6) | wavenum */ - gatetime = size * 500 / s->streams[0]->codec->sample_rate; + gatetime = size * 500 / s->streams[0]->codecpar->sample_rate; put_varlength(pb, gatetime); /* duration */ /* "nop" */ @@ -262,16 +262,16 @@ static int mmf_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_YAMAHA; - st->codec->sample_rate = rate; - st->codec->channels = (params >> 7) + 1; - st->codec->channel_layout = params >> 7 ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; - st->codec->bits_per_coded_sample = 4; - st->codec->bit_rate = st->codec->sample_rate * - st->codec->bits_per_coded_sample; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_YAMAHA; + st->codecpar->sample_rate = rate; + st->codecpar->channels = (params >> 7) + 1; + st->codecpar->channel_layout = params >> 7 ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; + st->codecpar->bits_per_coded_sample = 4; + st->codecpar->bit_rate = st->codecpar->sample_rate * + st->codecpar->bits_per_coded_sample; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } diff --git a/libavformat/mov.c b/libavformat/mov.c index 3fa8fcc2f6..06c15fba6d 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -209,8 +209,8 @@ static int mov_read_covr(MOVContext *c, AVIOContext *pb, int type, int len) st->attached_pic.stream_index = st->index; st->attached_pic.flags |= AV_PKT_FLAG_KEY; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = id; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = id; return 0; } @@ -660,13 +660,13 @@ static int mov_read_hdlr(MOVContext *c, AVIOContext *pb, MOVAtom atom) st = c->fc->streams[c->fc->nb_streams-1]; if (type == MKTAG('v','i','d','e')) - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; else if (type == MKTAG('s','o','u','n')) - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; else if (type == MKTAG('m','1','a',' ')) - st->codec->codec_id = AV_CODEC_ID_MP2; + st->codecpar->codec_id = AV_CODEC_ID_MP2; else if ((type == MKTAG('s','u','b','p')) || (type == MKTAG('c','l','c','p'))) - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; avio_rb32(pb); /* component manufacture */ avio_rb32(pb); /* component flags */ @@ -740,15 +740,19 @@ static int mov_read_dac3(MOVContext *c, AVIOContext *pb, MOVAtom atom) bsmod = (ac3info >> 14) & 0x7; acmod = (ac3info >> 11) & 0x7; lfeon = (ac3info >> 10) & 0x1; - st->codec->channels = ((int[]){2,1,2,3,3,4,4,5})[acmod] + lfeon; - st->codec->channel_layout = avpriv_ac3_channel_layout_tab[acmod]; + st->codecpar->channels = ((int[]){2,1,2,3,3,4,4,5})[acmod] + lfeon; + st->codecpar->channel_layout = avpriv_ac3_channel_layout_tab[acmod]; if (lfeon) - st->codec->channel_layout |= AV_CH_LOW_FREQUENCY; + st->codecpar->channel_layout |= AV_CH_LOW_FREQUENCY; *ast = bsmod; - if (st->codec->channels > 1 && bsmod == 0x7) + if (st->codecpar->channels > 1 && bsmod == 0x7) *ast = AV_AUDIO_SERVICE_TYPE_KARAOKE; +#if FF_API_LAVF_AVCTX + FF_DISABLE_DEPRECATION_WARNINGS st->codec->audio_service_type = *ast; + FF_ENABLE_DEPRECATION_WARNINGS +#endif return 0; } @@ -776,15 +780,19 @@ static int mov_read_dec3(MOVContext *c, AVIOContext *pb, MOVAtom atom) bsmod = (eac3info >> 12) & 0x1f; acmod = (eac3info >> 9) & 0x7; lfeon = (eac3info >> 8) & 0x1; - st->codec->channel_layout = avpriv_ac3_channel_layout_tab[acmod]; + st->codecpar->channel_layout = avpriv_ac3_channel_layout_tab[acmod]; if (lfeon) - st->codec->channel_layout |= AV_CH_LOW_FREQUENCY; - st->codec->channels = av_get_channel_layout_nb_channels(st->codec->channel_layout); + st->codecpar->channel_layout |= AV_CH_LOW_FREQUENCY; + st->codecpar->channels = av_get_channel_layout_nb_channels(st->codecpar->channel_layout); *ast = bsmod; - if (st->codec->channels > 1 && bsmod == 0x7) + if (st->codecpar->channels > 1 && bsmod == 0x7) *ast = AV_AUDIO_SERVICE_TYPE_KARAOKE; +#if FF_API_LAVF_AVCTX + FF_DISABLE_DEPRECATION_WARNINGS st->codec->audio_service_type = *ast; + FF_ENABLE_DEPRECATION_WARNINGS +#endif return 0; } @@ -814,15 +822,15 @@ static int mov_read_ddts(MOVContext *c, AVIOContext *pb, MOVAtom atom) } st = c->fc->streams[c->fc->nb_streams-1]; - st->codec->sample_rate = get_bits_long(&gb, 32); + st->codecpar->sample_rate = get_bits_long(&gb, 32); skip_bits_long(&gb, 32); /* max bitrate */ - st->codec->bit_rate = get_bits_long(&gb, 32); - st->codec->bits_per_coded_sample = get_bits(&gb, 8); + st->codecpar->bit_rate = get_bits_long(&gb, 32); + st->codecpar->bits_per_coded_sample = get_bits(&gb, 8); frame_duration_code = get_bits(&gb, 2); skip_bits(&gb, 30); /* various fields */ channel_layout_code = get_bits(&gb, 16); - st->codec->frame_size = + st->codecpar->frame_size = (frame_duration_code == 0) ? 512 : (frame_duration_code == 1) ? 1024 : (frame_duration_code == 2) ? 2048 : @@ -831,7 +839,7 @@ static int mov_read_ddts(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (channel_layout_code > 0xff) { av_log(c->fc, AV_LOG_WARNING, "Unsupported DTS audio channel layout"); } - st->codec->channel_layout = + st->codecpar->channel_layout = ((channel_layout_code & 0x1) ? AV_CH_FRONT_CENTER : 0) | ((channel_layout_code & 0x2) ? AV_CH_FRONT_LEFT : 0) | ((channel_layout_code & 0x2) ? AV_CH_FRONT_RIGHT : 0) | @@ -839,7 +847,7 @@ static int mov_read_ddts(MOVContext *c, AVIOContext *pb, MOVAtom atom) ((channel_layout_code & 0x4) ? AV_CH_SIDE_RIGHT : 0) | ((channel_layout_code & 0x8) ? AV_CH_LOW_FREQUENCY : 0); - st->codec->channels = av_get_channel_layout_nb_channels(st->codec->channel_layout); + st->codecpar->channels = av_get_channel_layout_nb_channels(st->codecpar->channel_layout); return 0; } @@ -872,7 +880,7 @@ static int mov_read_wfex(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; st = c->fc->streams[c->fc->nb_streams-1]; - if ((ret = ff_get_wav_header(c->fc, pb, st->codec, atom.size, 0)) < 0) + if ((ret = ff_get_wav_header(c->fc, pb, st->codecpar, atom.size, 0)) < 0) av_log(c->fc, AV_LOG_WARNING, "get_wav_header failed\n"); return ret; @@ -1217,18 +1225,18 @@ static int mov_read_enda(MOVContext *c, AVIOContext *pb, MOVAtom atom) little_endian = avio_rb16(pb) & 0xFF; av_log(c->fc, AV_LOG_TRACE, "enda %d\n", little_endian); if (little_endian == 1) { - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_PCM_S24BE: - st->codec->codec_id = AV_CODEC_ID_PCM_S24LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE; break; case AV_CODEC_ID_PCM_S32BE: - st->codec->codec_id = AV_CODEC_ID_PCM_S32LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE; break; case AV_CODEC_ID_PCM_F32BE: - st->codec->codec_id = AV_CODEC_ID_PCM_F32LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_F32LE; break; case AV_CODEC_ID_PCM_F64BE: - st->codec->codec_id = AV_CODEC_ID_PCM_F64LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_F64LE; break; default: break; @@ -1270,9 +1278,9 @@ static int mov_read_colr(MOVContext *c, AVIOContext *pb, MOVAtom atom) uint8_t color_range = avio_r8(pb) >> 7; av_log(c->fc, AV_LOG_TRACE, " full %"PRIu8"", color_range); if (color_range) - st->codec->color_range = AVCOL_RANGE_JPEG; + st->codecpar->color_range = AVCOL_RANGE_JPEG; else - st->codec->color_range = AVCOL_RANGE_MPEG; + st->codecpar->color_range = AVCOL_RANGE_MPEG; /* 14496-12 references JPEG XR specs (rather than the more complete * 23001-8) so some adjusting is required */ if (color_primaries >= AVCOL_PRI_FILM) @@ -1283,26 +1291,26 @@ static int mov_read_colr(MOVContext *c, AVIOContext *pb, MOVAtom atom) color_trc = AVCOL_TRC_UNSPECIFIED; if (color_matrix >= AVCOL_SPC_BT2020_NCL) color_matrix = AVCOL_SPC_UNSPECIFIED; - st->codec->color_primaries = color_primaries; - st->codec->color_trc = color_trc; - st->codec->colorspace = color_matrix; + st->codecpar->color_primaries = color_primaries; + st->codecpar->color_trc = color_trc; + st->codecpar->color_space = color_matrix; } else if (!strncmp(color_parameter_type, "nclc", 4)) { /* color primaries, Table 4-4 */ switch (color_primaries) { - case 1: st->codec->color_primaries = AVCOL_PRI_BT709; break; - case 5: st->codec->color_primaries = AVCOL_PRI_SMPTE170M; break; - case 6: st->codec->color_primaries = AVCOL_PRI_SMPTE240M; break; + case 1: st->codecpar->color_primaries = AVCOL_PRI_BT709; break; + case 5: st->codecpar->color_primaries = AVCOL_PRI_SMPTE170M; break; + case 6: st->codecpar->color_primaries = AVCOL_PRI_SMPTE240M; break; } /* color transfer, Table 4-5 */ switch (color_trc) { - case 1: st->codec->color_trc = AVCOL_TRC_BT709; break; - case 7: st->codec->color_trc = AVCOL_TRC_SMPTE240M; break; + case 1: st->codecpar->color_trc = AVCOL_TRC_BT709; break; + case 7: st->codecpar->color_trc = AVCOL_TRC_SMPTE240M; break; } /* color matrix, Table 4-6 */ switch (color_matrix) { - case 1: st->codec->colorspace = AVCOL_SPC_BT709; break; - case 6: st->codec->colorspace = AVCOL_SPC_BT470BG; break; - case 7: st->codec->colorspace = AVCOL_SPC_SMPTE240M; break; + case 1: st->codecpar->color_space = AVCOL_SPC_BT709; break; + case 6: st->codecpar->color_space = AVCOL_SPC_BT470BG; break; + case 7: st->codecpar->color_space = AVCOL_SPC_SMPTE240M; break; } } av_log(c->fc, AV_LOG_TRACE, "\n"); @@ -1339,28 +1347,28 @@ static int mov_read_fiel(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (decoded_field_order == AV_FIELD_UNKNOWN && mov_field_order) { av_log(NULL, AV_LOG_ERROR, "Unknown MOV field order 0x%04x\n", mov_field_order); } - st->codec->field_order = decoded_field_order; + st->codecpar->field_order = decoded_field_order; return 0; } -static int mov_realloc_extradata(AVCodecContext *codec, MOVAtom atom) +static int mov_realloc_extradata(AVCodecParameters *par, MOVAtom atom) { int err = 0; - uint64_t size = (uint64_t)codec->extradata_size + atom.size + 8 + AV_INPUT_BUFFER_PADDING_SIZE; + uint64_t size = (uint64_t)par->extradata_size + atom.size + 8 + AV_INPUT_BUFFER_PADDING_SIZE; if (size > INT_MAX || (uint64_t)atom.size > INT_MAX) return AVERROR_INVALIDDATA; - if ((err = av_reallocp(&codec->extradata, size)) < 0) { - codec->extradata_size = 0; + if ((err = av_reallocp(&par->extradata, size)) < 0) { + par->extradata_size = 0; return err; } - codec->extradata_size = size - AV_INPUT_BUFFER_PADDING_SIZE; + par->extradata_size = size - AV_INPUT_BUFFER_PADDING_SIZE; return 0; } /* Read a whole atom into the extradata return the size of the atom read, possibly truncated if != atom.size */ static int64_t mov_read_atom_into_extradata(MOVContext *c, AVIOContext *pb, MOVAtom atom, - AVCodecContext *codec, uint8_t *buf) + AVCodecParameters *par, uint8_t *buf) { int64_t result = atom.size; int err; @@ -1369,11 +1377,11 @@ static int64_t mov_read_atom_into_extradata(MOVContext *c, AVIOContext *pb, MOVA AV_WL32(buf + 4, atom.type); err = ffio_read_size(pb, buf + 8, atom.size); if (err < 0) { - codec->extradata_size -= atom.size; + par->extradata_size -= atom.size; return err; } else if (err < atom.size) { av_log(c->fc, AV_LOG_WARNING, "truncated extradata\n"); - codec->extradata_size -= atom.size - err; + par->extradata_size -= atom.size - err; result = err; } memset(buf + 8 + err, 0, AV_INPUT_BUFFER_PADDING_SIZE); @@ -1392,15 +1400,15 @@ static int mov_read_extradata(MOVContext *c, AVIOContext *pb, MOVAtom atom, return 0; st = c->fc->streams[c->fc->nb_streams-1]; - if (st->codec->codec_id != codec_id) + if (st->codecpar->codec_id != codec_id) return 0; /* unexpected codec_id - don't mess with extradata */ - original_size = st->codec->extradata_size; - err = mov_realloc_extradata(st->codec, atom); + original_size = st->codecpar->extradata_size; + err = mov_realloc_extradata(st->codecpar, atom); if (err) return err; - err = mov_read_atom_into_extradata(c, pb, atom, st->codec, st->codec->extradata + original_size); + err = mov_read_atom_into_extradata(c, pb, atom, st->codecpar, st->codecpar->extradata + original_size); if (err < 0) return err; return 0; // Note: this is the original behavior to ignore truncation. @@ -1440,10 +1448,10 @@ static int mov_read_targa_y216(MOVContext *c, AVIOContext *pb, MOVAtom atom) int ret = mov_read_extradata(c, pb, atom, AV_CODEC_ID_TARGA_Y216); if (!ret && c->fc->nb_streams >= 1) { - AVCodecContext *avctx = c->fc->streams[c->fc->nb_streams-1]->codec; - if (avctx->extradata_size >= 40) { - avctx->height = AV_RB16(&avctx->extradata[36]); - avctx->width = AV_RB16(&avctx->extradata[38]); + AVCodecParameters *par = c->fc->streams[c->fc->nb_streams-1]->codecpar; + if (par->extradata_size >= 40) { + par->height = AV_RB16(&par->extradata[36]); + par->width = AV_RB16(&par->extradata[38]); } } return ret; @@ -1452,16 +1460,16 @@ static int mov_read_targa_y216(MOVContext *c, AVIOContext *pb, MOVAtom atom) static int mov_read_ares(MOVContext *c, AVIOContext *pb, MOVAtom atom) { if (c->fc->nb_streams >= 1) { - AVCodecContext *codec = c->fc->streams[c->fc->nb_streams-1]->codec; - if (codec->codec_tag == MKTAG('A', 'V', 'i', 'n') && - codec->codec_id == AV_CODEC_ID_H264 && + AVCodecParameters *par = c->fc->streams[c->fc->nb_streams-1]->codecpar; + if (par->codec_tag == MKTAG('A', 'V', 'i', 'n') && + par->codec_id == AV_CODEC_ID_H264 && atom.size > 11) { avio_skip(pb, 10); /* For AVID AVCI50, force width of 1440 to be able to select the correct SPS and PPS */ if (avio_rb16(pb) == 0xd4d) - codec->width = 1440; + par->width = 1440; return 0; - } else if (codec->codec_tag == MKTAG('A', 'V', 'd', '1') && + } else if (par->codec_tag == MKTAG('A', 'V', 'd', '1') && atom.size >= 24) { int num, den; avio_skip(pb, 12); @@ -1492,28 +1500,28 @@ static int mov_read_aclr(MOVContext *c, AVIOContext *pb, MOVAtom atom) int length = 0; uint64_t original_size; if (c->fc->nb_streams >= 1) { - AVCodecContext *codec = c->fc->streams[c->fc->nb_streams-1]->codec; - if (codec->codec_id == AV_CODEC_ID_H264) + AVCodecParameters *par = c->fc->streams[c->fc->nb_streams-1]->codecpar; + if (par->codec_id == AV_CODEC_ID_H264) return 0; if (atom.size == 16) { - original_size = codec->extradata_size; - ret = mov_realloc_extradata(codec, atom); + original_size = par->extradata_size; + ret = mov_realloc_extradata(par, atom); if (!ret) { - length = mov_read_atom_into_extradata(c, pb, atom, codec, codec->extradata + original_size); + length = mov_read_atom_into_extradata(c, pb, atom, par, par->extradata + original_size); if (length == atom.size) { - const uint8_t range_value = codec->extradata[original_size + 19]; + const uint8_t range_value = par->extradata[original_size + 19]; switch (range_value) { case 1: - codec->color_range = AVCOL_RANGE_MPEG; + par->color_range = AVCOL_RANGE_MPEG; break; case 2: - codec->color_range = AVCOL_RANGE_JPEG; + par->color_range = AVCOL_RANGE_JPEG; break; default: av_log(c, AV_LOG_WARNING, "ignored unknown aclr value (%d)\n", range_value); break; } - ff_dlog(c, "color_range: %d\n", codec->color_range); + ff_dlog(c, "color_range: %d\n", par->color_range); } else { /* For some reason the whole atom was not added to the extradata */ av_log(c, AV_LOG_ERROR, "aclr not decoded - incomplete atom\n"); @@ -1546,16 +1554,16 @@ static int mov_read_wave(MOVContext *c, AVIOContext *pb, MOVAtom atom) if ((uint64_t)atom.size > (1<<30)) return AVERROR_INVALIDDATA; - if (st->codec->codec_id == AV_CODEC_ID_QDM2 || - st->codec->codec_id == AV_CODEC_ID_QDMC || - st->codec->codec_id == AV_CODEC_ID_SPEEX) { + if (st->codecpar->codec_id == AV_CODEC_ID_QDM2 || + st->codecpar->codec_id == AV_CODEC_ID_QDMC || + st->codecpar->codec_id == AV_CODEC_ID_SPEEX) { // pass all frma atom to codec, needed at least for QDMC and QDM2 - av_freep(&st->codec->extradata); - ret = ff_get_extradata(st->codec, pb, atom.size); + av_freep(&st->codecpar->extradata); + ret = ff_get_extradata(st->codecpar, pb, atom.size); if (ret < 0) return ret; } else if (atom.size > 8) { /* to read frma, esds atoms */ - if (st->codec->codec_id == AV_CODEC_ID_ALAC && atom.size >= 24) { + if (st->codecpar->codec_id == AV_CODEC_ID_ALAC && atom.size >= 24) { uint64_t buffer; ret = ffio_ensure_seekback(pb, 8); if (ret < 0) @@ -1567,16 +1575,16 @@ static int mov_read_wave(MOVContext *c, AVIOContext *pb, MOVAtom atom) && buffer >> 32 >= 8) { avio_skip(pb, -8); atom.size += 8; - } else if (!st->codec->extradata_size) { + } else if (!st->codecpar->extradata_size) { #define ALAC_EXTRADATA_SIZE 36 - st->codec->extradata = av_mallocz(ALAC_EXTRADATA_SIZE + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + st->codecpar->extradata = av_mallocz(ALAC_EXTRADATA_SIZE + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - st->codec->extradata_size = ALAC_EXTRADATA_SIZE; - AV_WB32(st->codec->extradata , ALAC_EXTRADATA_SIZE); - AV_WB32(st->codec->extradata + 4, MKTAG('a','l','a','c')); - AV_WB64(st->codec->extradata + 12, buffer); - avio_read(pb, st->codec->extradata + 20, 16); + st->codecpar->extradata_size = ALAC_EXTRADATA_SIZE; + AV_WB32(st->codecpar->extradata , ALAC_EXTRADATA_SIZE); + AV_WB32(st->codecpar->extradata + 4, MKTAG('a','l','a','c')); + AV_WB64(st->codecpar->extradata + 12, buffer); + avio_read(pb, st->codecpar->extradata + 20, 16); avio_skip(pb, atom.size - 24); return 0; } @@ -1613,12 +1621,12 @@ static int mov_read_glbl(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (type == MKTAG('f','i','e','l') && size == atom.size) return mov_read_default(c, pb, atom); } - if (st->codec->extradata_size > 1 && st->codec->extradata) { + if (st->codecpar->extradata_size > 1 && st->codecpar->extradata) { av_log(c, AV_LOG_WARNING, "ignoring multiple glbl\n"); return 0; } - av_freep(&st->codec->extradata); - ret = ff_get_extradata(st->codec, pb, atom.size); + av_freep(&st->codecpar->extradata); + ret = ff_get_extradata(st->codecpar, pb, atom.size); if (ret < 0) return ret; @@ -1643,8 +1651,8 @@ static int mov_read_dvc1(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; avio_seek(pb, 6, SEEK_CUR); - av_freep(&st->codec->extradata); - ret = ff_get_extradata(st->codec, pb, atom.size - 7); + av_freep(&st->codecpar->extradata); + ret = ff_get_extradata(st->codecpar, pb, atom.size - 7); if (ret < 0) return ret; @@ -1671,8 +1679,8 @@ static int mov_read_strf(MOVContext *c, AVIOContext *pb, MOVAtom atom) return AVERROR_INVALIDDATA; avio_skip(pb, 40); - av_freep(&st->codec->extradata); - ret = ff_get_extradata(st->codec, pb, atom.size - 40); + av_freep(&st->codecpar->extradata); + ret = ff_get_extradata(st->codecpar, pb, atom.size - 40); if (ret < 0) return ret; @@ -1747,26 +1755,26 @@ static int mov_codec_id(AVStream *st, uint32_t format) (format & 0xFFFF) == 'T' + ('S' << 8))) id = ff_codec_get_id(ff_codec_wav_tags, av_bswap32(format) & 0xFFFF); - if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO && id > 0) { - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - } else if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO && + if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO && id > 0) { + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + } else if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO && /* skip old asf mpeg4 tag */ format && format != MKTAG('m','p','4','s')) { id = ff_codec_get_id(ff_codec_movvideo_tags, format); if (id <= 0) id = ff_codec_get_id(ff_codec_bmp_tags, format); if (id > 0) - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - else if (st->codec->codec_type == AVMEDIA_TYPE_DATA || - (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE && - st->codec->codec_id == AV_CODEC_ID_NONE)) { + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA || + (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE && + st->codecpar->codec_id == AV_CODEC_ID_NONE)) { id = ff_codec_get_id(ff_codec_movsubtitle_tags, format); if (id > 0) - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; } } - st->codec->codec_tag = format; + st->codecpar->codec_tag = format; return id; } @@ -1788,8 +1796,8 @@ static void mov_parse_stsd_video(MOVContext *c, AVIOContext *pb, avio_rb32(pb); /* temporal quality */ avio_rb32(pb); /* spatial quality */ - st->codec->width = avio_rb16(pb); /* width */ - st->codec->height = avio_rb16(pb); /* height */ + st->codecpar->width = avio_rb16(pb); /* width */ + st->codecpar->height = avio_rb16(pb); /* height */ avio_rb32(pb); /* horiz resolution */ avio_rb32(pb); /* vert resolution */ @@ -1808,21 +1816,21 @@ static void mov_parse_stsd_video(MOVContext *c, AVIOContext *pb, /* codec_tag YV12 triggers an UV swap in rawdec.c */ if (!memcmp(codec_name, "Planar Y'CbCr 8-bit 4:2:0", 25)) { - st->codec->codec_tag = MKTAG('I', '4', '2', '0'); - st->codec->width &= ~1; - st->codec->height &= ~1; + st->codecpar->codec_tag = MKTAG('I', '4', '2', '0'); + st->codecpar->width &= ~1; + st->codecpar->height &= ~1; } /* Flash Media Server uses tag H263 with Sorenson Spark */ - if (st->codec->codec_tag == MKTAG('H','2','6','3') && + if (st->codecpar->codec_tag == MKTAG('H','2','6','3') && !memcmp(codec_name, "Sorenson H263", 13)) - st->codec->codec_id = AV_CODEC_ID_FLV1; + st->codecpar->codec_id = AV_CODEC_ID_FLV1; - st->codec->bits_per_coded_sample = avio_rb16(pb); /* depth */ + st->codecpar->bits_per_coded_sample = avio_rb16(pb); /* depth */ avio_seek(pb, stsd_start, SEEK_SET); - if (ff_get_qtpalette(st->codec->codec_id, pb, sc->palette)) { - st->codec->bits_per_coded_sample &= 0x1F; + if (ff_get_qtpalette(st->codecpar->codec_id, pb, sc->palette)) { + st->codecpar->bits_per_coded_sample &= 0x1F; sc->has_palette = 1; } } @@ -1837,14 +1845,14 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb, avio_rb16(pb); /* revision level */ avio_rb32(pb); /* vendor */ - st->codec->channels = avio_rb16(pb); /* channel count */ - st->codec->bits_per_coded_sample = avio_rb16(pb); /* sample size */ - av_log(c->fc, AV_LOG_TRACE, "audio channels %d\n", st->codec->channels); + st->codecpar->channels = avio_rb16(pb); /* channel count */ + st->codecpar->bits_per_coded_sample = avio_rb16(pb); /* sample size */ + av_log(c->fc, AV_LOG_TRACE, "audio channels %d\n", st->codecpar->channels); sc->audio_cid = avio_rb16(pb); avio_rb16(pb); /* packet size = 0 */ - st->codec->sample_rate = ((avio_rb32(pb) >> 16)); + st->codecpar->sample_rate = ((avio_rb32(pb) >> 16)); // Read QT version 1 fields. In version 0 these do not exist. av_log(c->fc, AV_LOG_TRACE, "version =%d, isom =%d\n", version, c->isom); @@ -1858,22 +1866,22 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb, avio_rb32(pb); /* bytes per sample */ } else if (version == 2) { avio_rb32(pb); /* sizeof struct only */ - st->codec->sample_rate = av_int2double(avio_rb64(pb)); - st->codec->channels = avio_rb32(pb); + st->codecpar->sample_rate = av_int2double(avio_rb64(pb)); + st->codecpar->channels = avio_rb32(pb); avio_rb32(pb); /* always 0x7F000000 */ - st->codec->bits_per_coded_sample = avio_rb32(pb); + st->codecpar->bits_per_coded_sample = avio_rb32(pb); flags = avio_rb32(pb); /* lpcm format specific flag */ sc->bytes_per_frame = avio_rb32(pb); sc->samples_per_frame = avio_rb32(pb); - if (st->codec->codec_tag == MKTAG('l','p','c','m')) - st->codec->codec_id = - ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, + if (st->codecpar->codec_tag == MKTAG('l','p','c','m')) + st->codecpar->codec_id = + ff_mov_get_lpcm_codec_id(st->codecpar->bits_per_coded_sample, flags); } if (version == 0 || (version == 1 && sc->audio_cid != -2)) { /* can't correctly handle variable sized packet as audio unit */ - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_MP2: case AV_CODEC_ID_MP3: st->need_parsing = AVSTREAM_PARSE_FULL; @@ -1883,43 +1891,43 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb, } if (sc->format == 0) { - if (st->codec->bits_per_coded_sample == 8) - st->codec->codec_id = mov_codec_id(st, MKTAG('r','a','w',' ')); - else if (st->codec->bits_per_coded_sample == 16) - st->codec->codec_id = mov_codec_id(st, MKTAG('t','w','o','s')); + if (st->codecpar->bits_per_coded_sample == 8) + st->codecpar->codec_id = mov_codec_id(st, MKTAG('r','a','w',' ')); + else if (st->codecpar->bits_per_coded_sample == 16) + st->codecpar->codec_id = mov_codec_id(st, MKTAG('t','w','o','s')); } - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_PCM_S8: case AV_CODEC_ID_PCM_U8: - if (st->codec->bits_per_coded_sample == 16) - st->codec->codec_id = AV_CODEC_ID_PCM_S16BE; + if (st->codecpar->bits_per_coded_sample == 16) + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE; break; case AV_CODEC_ID_PCM_S16LE: case AV_CODEC_ID_PCM_S16BE: - if (st->codec->bits_per_coded_sample == 8) - st->codec->codec_id = AV_CODEC_ID_PCM_S8; - else if (st->codec->bits_per_coded_sample == 24) - st->codec->codec_id = - st->codec->codec_id == AV_CODEC_ID_PCM_S16BE ? + if (st->codecpar->bits_per_coded_sample == 8) + st->codecpar->codec_id = AV_CODEC_ID_PCM_S8; + else if (st->codecpar->bits_per_coded_sample == 24) + st->codecpar->codec_id = + st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE ? AV_CODEC_ID_PCM_S24BE : AV_CODEC_ID_PCM_S24LE; - else if (st->codec->bits_per_coded_sample == 32) - st->codec->codec_id = - st->codec->codec_id == AV_CODEC_ID_PCM_S16BE ? + else if (st->codecpar->bits_per_coded_sample == 32) + st->codecpar->codec_id = + st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE ? AV_CODEC_ID_PCM_S32BE : AV_CODEC_ID_PCM_S32LE; break; /* set values for old format before stsd version 1 appeared */ case AV_CODEC_ID_MACE3: sc->samples_per_frame = 6; - sc->bytes_per_frame = 2 * st->codec->channels; + sc->bytes_per_frame = 2 * st->codecpar->channels; break; case AV_CODEC_ID_MACE6: sc->samples_per_frame = 6; - sc->bytes_per_frame = 1 * st->codec->channels; + sc->bytes_per_frame = 1 * st->codecpar->channels; break; case AV_CODEC_ID_ADPCM_IMA_QT: sc->samples_per_frame = 64; - sc->bytes_per_frame = 34 * st->codec->channels; + sc->bytes_per_frame = 34 * st->codecpar->channels; break; case AV_CODEC_ID_GSM: sc->samples_per_frame = 160; @@ -1929,10 +1937,10 @@ static void mov_parse_stsd_audio(MOVContext *c, AVIOContext *pb, break; } - bits_per_sample = av_get_bits_per_sample(st->codec->codec_id); + bits_per_sample = av_get_bits_per_sample(st->codecpar->codec_id); if (bits_per_sample) { - st->codec->bits_per_coded_sample = bits_per_sample; - sc->sample_size = (bits_per_sample >> 3) * st->codec->channels; + st->codecpar->bits_per_coded_sample = bits_per_sample; + sc->sample_size = (bits_per_sample >> 3) * st->codecpar->channels; } } @@ -1944,10 +1952,10 @@ static void mov_parse_stsd_subtitle(MOVContext *c, AVIOContext *pb, // color, fonts, and default styles, so fake an atom to read it MOVAtom fake_atom = { .size = size }; // mp4s contains a regular esds atom - if (st->codec->codec_tag != AV_RL32("mp4s")) + if (st->codecpar->codec_tag != AV_RL32("mp4s")) mov_read_glbl(c, pb, fake_atom); - st->codec->width = sc->width; - st->codec->height = sc->height; + st->codecpar->width = sc->width; + st->codecpar->height = sc->height; } static uint32_t yuv_to_rgba(uint32_t ycbcr) @@ -1969,15 +1977,15 @@ static uint32_t yuv_to_rgba(uint32_t ycbcr) static int mov_rewrite_dvd_sub_extradata(AVStream *st) { char buf[256] = {0}; - uint8_t *src = st->codec->extradata; + uint8_t *src = st->codecpar->extradata; int i; - if (st->codec->extradata_size != 64) + if (st->codecpar->extradata_size != 64) return 0; - if (st->codec->width > 0 && st->codec->height > 0) + if (st->codecpar->width > 0 && st->codecpar->height > 0) snprintf(buf, sizeof(buf), "size: %dx%d\n", - st->codec->width, st->codec->height); + st->codecpar->width, st->codecpar->height); av_strlcat(buf, "palette: ", sizeof(buf)); for (i = 0; i < 16; i++) { @@ -1990,13 +1998,13 @@ static int mov_rewrite_dvd_sub_extradata(AVStream *st) if (av_strlcat(buf, "\n", sizeof(buf)) >= sizeof(buf)) return 0; - av_freep(&st->codec->extradata); - st->codec->extradata_size = 0; - st->codec->extradata = av_mallocz(strlen(buf) + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + av_freep(&st->codecpar->extradata); + st->codecpar->extradata_size = 0; + st->codecpar->extradata = av_mallocz(strlen(buf) + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - st->codec->extradata_size = strlen(buf); - memcpy(st->codec->extradata, buf, st->codec->extradata_size); + st->codecpar->extradata_size = strlen(buf); + memcpy(st->codecpar->extradata, buf, st->codecpar->extradata_size); return 0; } @@ -2007,39 +2015,48 @@ static int mov_parse_stsd_data(MOVContext *c, AVIOContext *pb, { int ret; - if (st->codec->codec_tag == MKTAG('t','m','c','d')) { + if (st->codecpar->codec_tag == MKTAG('t','m','c','d')) { if ((int)size != size) return AVERROR(ENOMEM); - ret = ff_get_extradata(st->codec, pb, size); + ret = ff_get_extradata(st->codecpar, pb, size); if (ret < 0) return ret; if (size > 16) { MOVStreamContext *tmcd_ctx = st->priv_data; int val; - val = AV_RB32(st->codec->extradata + 4); + val = AV_RB32(st->codecpar->extradata + 4); tmcd_ctx->tmcd_flags = val; - if (val & 1) - st->codec->flags2 |= AV_CODEC_FLAG2_DROP_FRAME_TIMECODE; - st->codec->time_base.den = st->codec->extradata[16]; /* number of frame */ - st->codec->time_base.num = 1; + st->avg_frame_rate.num = st->codecpar->extradata[16]; /* number of frame */ + st->avg_frame_rate.den = 1; +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS + st->codec->time_base = av_inv_q(st->avg_frame_rate); +FF_ENABLE_DEPRECATION_WARNINGS +#endif /* adjust for per frame dur in counter mode */ if (tmcd_ctx->tmcd_flags & 0x0008) { - int timescale = AV_RB32(st->codec->extradata + 8); - int framedur = AV_RB32(st->codec->extradata + 12); + int timescale = AV_RB32(st->codecpar->extradata + 8); + int framedur = AV_RB32(st->codecpar->extradata + 12); + st->avg_frame_rate.num *= timescale; + st->avg_frame_rate.den *= framedur; +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS st->codec->time_base.den *= timescale; st->codec->time_base.num *= framedur; +FF_ENABLE_DEPRECATION_WARNINGS +#endif } if (size > 30) { - uint32_t len = AV_RB32(st->codec->extradata + 18); /* name atom length */ - uint32_t format = AV_RB32(st->codec->extradata + 22); + uint32_t len = AV_RB32(st->codecpar->extradata + 18); /* name atom length */ + uint32_t format = AV_RB32(st->codecpar->extradata + 22); if (format == AV_RB32("name") && (int64_t)size >= (int64_t)len + 18) { - uint16_t str_size = AV_RB16(st->codec->extradata + 26); /* string length */ + uint16_t str_size = AV_RB16(st->codecpar->extradata + 26); /* string length */ if (str_size > 0 && size >= (int)str_size + 26) { char *reel_name = av_malloc(str_size + 1); if (!reel_name) return AVERROR(ENOMEM); - memcpy(reel_name, st->codec->extradata + 30, str_size); + memcpy(reel_name, st->codecpar->extradata + 30, str_size); reel_name[str_size] = 0; /* Add null terminator */ /* don't add reel_name if emtpy string */ if (*reel_name == 0) { @@ -2061,12 +2078,12 @@ static int mov_parse_stsd_data(MOVContext *c, AVIOContext *pb, static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb, AVStream *st, MOVStreamContext *sc) { - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && - !st->codec->sample_rate && sc->time_scale > 1) - st->codec->sample_rate = sc->time_scale; + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && + !st->codecpar->sample_rate && sc->time_scale > 1) + st->codecpar->sample_rate = sc->time_scale; /* special codec parameters handling */ - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { #if CONFIG_DV_DEMUXER case AV_CODEC_ID_DVAUDIO: c->dv_fctx = avformat_alloc_context(); @@ -2080,33 +2097,33 @@ static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb, return AVERROR(ENOMEM); } sc->dv_audio_container = 1; - st->codec->codec_id = AV_CODEC_ID_PCM_S16LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; break; #endif /* no ifdef since parameters are always those */ case AV_CODEC_ID_QCELP: - st->codec->channels = 1; + st->codecpar->channels = 1; // force sample rate for qcelp when not stored in mov - if (st->codec->codec_tag != MKTAG('Q','c','l','p')) - st->codec->sample_rate = 8000; + if (st->codecpar->codec_tag != MKTAG('Q','c','l','p')) + st->codecpar->sample_rate = 8000; // FIXME: Why is the following needed for some files? sc->samples_per_frame = 160; if (!sc->bytes_per_frame) sc->bytes_per_frame = 35; break; case AV_CODEC_ID_AMR_NB: - st->codec->channels = 1; + st->codecpar->channels = 1; /* force sample rate for amr, stsd in 3gp does not store sample rate */ - st->codec->sample_rate = 8000; + st->codecpar->sample_rate = 8000; break; case AV_CODEC_ID_AMR_WB: - st->codec->channels = 1; - st->codec->sample_rate = 16000; + st->codecpar->channels = 1; + st->codecpar->sample_rate = 16000; break; case AV_CODEC_ID_MP2: case AV_CODEC_ID_MP3: /* force type after stsd for m1a hdlr */ - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; break; case AV_CODEC_ID_GSM: case AV_CODEC_ID_ADPCM_MS: @@ -2115,12 +2132,12 @@ static int mov_finalize_stsd_codec(MOVContext *c, AVIOContext *pb, case AV_CODEC_ID_MACE3: case AV_CODEC_ID_MACE6: case AV_CODEC_ID_QDM2: - st->codec->block_align = sc->bytes_per_frame; + st->codecpar->block_align = sc->bytes_per_frame; break; case AV_CODEC_ID_ALAC: - if (st->codec->extradata_size == 36) { - st->codec->channels = AV_RB8 (st->codec->extradata + 21); - st->codec->sample_rate = AV_RB32(st->codec->extradata + 32); + if (st->codecpar->extradata_size == 36) { + st->codecpar->channels = AV_RB8 (st->codecpar->extradata + 21); + st->codecpar->sample_rate = AV_RB32(st->codecpar->extradata + 32); } break; case AV_CODEC_ID_AC3: @@ -2194,11 +2211,11 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) return AVERROR_INVALIDDATA; } - if (mov_skip_multiple_stsd(c, pb, st->codec->codec_tag, format, + if (mov_skip_multiple_stsd(c, pb, st->codecpar->codec_tag, format, size - (avio_tell(pb) - start_pos))) continue; - sc->pseudo_stream_id = st->codec->codec_tag ? -1 : pseudo_stream_id; + sc->pseudo_stream_id = st->codecpar->codec_tag ? -1 : pseudo_stream_id; sc->dref_id= dref_id; sc->format = format; @@ -2207,16 +2224,16 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) av_log(c->fc, AV_LOG_TRACE, "size=%"PRId64" 4CC= %c%c%c%c/0x%08x codec_type=%d\n", size, (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff, - (format >> 24) & 0xff, format, st->codec->codec_type); + (format >> 24) & 0xff, format, st->codecpar->codec_type); - if (st->codec->codec_type==AVMEDIA_TYPE_VIDEO) { - st->codec->codec_id = id; + if (st->codecpar->codec_type==AVMEDIA_TYPE_VIDEO) { + st->codecpar->codec_id = id; mov_parse_stsd_video(c, pb, st, sc); - } else if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO) { - st->codec->codec_id = id; + } else if (st->codecpar->codec_type==AVMEDIA_TYPE_AUDIO) { + st->codecpar->codec_id = id; mov_parse_stsd_audio(c, pb, st, sc); - } else if (st->codec->codec_type==AVMEDIA_TYPE_SUBTITLE){ - st->codec->codec_id = id; + } else if (st->codecpar->codec_type==AVMEDIA_TYPE_SUBTITLE){ + st->codecpar->codec_id = id; mov_parse_stsd_subtitle(c, pb, st, sc, size - (avio_tell(pb) - start_pos)); } else { @@ -2349,7 +2366,7 @@ static int mov_read_stss(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (!entries) { sc->keyframe_absent = 1; - if (!st->need_parsing && st->codec->codec_type == AVMEDIA_TYPE_VIDEO) + if (!st->need_parsing && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) st->need_parsing = AVSTREAM_PARSE_HEADERS; return 0; } @@ -2685,16 +2702,16 @@ static void mov_build_index(MOVContext *mov, AVStream *st) /* more than 16 frames delay, dts are likely wrong this happens with files created by iMovie */ sc->wrong_dts = 1; - st->codec->has_b_frames = 1; + st->codecpar->video_delay = 1; } } - if (!unsupported && st->codec->codec_id == AV_CODEC_ID_AAC && start_time > 0) + if (!unsupported && st->codecpar->codec_id == AV_CODEC_ID_AAC && start_time > 0) sc->start_pad = start_time; } /* only use old uncompressed audio chunk demuxing when stts specifies it */ - if (!(st->codec->codec_type == AVMEDIA_TYPE_AUDIO && + if (!(st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && sc->stts_count == 1 && sc->stts_data[0].duration == 1)) { unsigned int current_sample = 0; unsigned int stts_sample = 0; @@ -2766,7 +2783,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) if (sc->keyframe_absent && !sc->stps_count && !rap_group_present - && (st->codec->codec_type == AVMEDIA_TYPE_AUDIO || (i==0 && j==0))) + && (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO || (i==0 && j==0))) keyframe = 1; if (keyframe) distance = 0; @@ -2782,7 +2799,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) av_log(mov->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", " "size %d, distance %d, keyframe %d\n", st->index, current_sample, current_offset, current_dts, sample_size, distance, keyframe); - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && st->nb_index_entries < 100) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->nb_index_entries < 100) ff_rfps_add_frame(mov->fc, st, current_dts); } @@ -2819,7 +2836,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } } if (st->duration > 0) - st->codec->bit_rate = stream_size*8*sc->time_scale/st->duration; + st->codecpar->bit_rate = stream_size*8*sc->time_scale/st->duration; } else { unsigned chunk_samples, total = 0; @@ -3040,7 +3057,7 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (!sc) return AVERROR(ENOMEM); st->priv_data = sc; - st->codec->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; sc->ffindex = st->index; c->trak_index = st->index; @@ -3086,12 +3103,12 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc->pb_is_copied = 1; } - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { - if (!st->sample_aspect_ratio.num && st->codec->width && st->codec->height && + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (!st->sample_aspect_ratio.num && st->codecpar->width && st->codecpar->height && sc->height && sc->width && - (st->codec->width != sc->width || st->codec->height != sc->height)) { - st->sample_aspect_ratio = av_d2q(((double)st->codec->height * sc->width) / - ((double)st->codec->width * sc->height), INT_MAX); + (st->codecpar->width != sc->width || st->codecpar->height != sc->height)) { + st->sample_aspect_ratio = av_d2q(((double)st->codecpar->height * sc->width) / + ((double)st->codecpar->width * sc->height), INT_MAX); } #if FF_API_R_FRAME_RATE @@ -3102,14 +3119,14 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) } // done for ai5q, ai52, ai55, ai1q, ai12 and ai15. - if (!st->codec->extradata_size && st->codec->codec_id == AV_CODEC_ID_H264 && - TAG_IS_AVCI(st->codec->codec_tag)) { + if (!st->codecpar->extradata_size && st->codecpar->codec_id == AV_CODEC_ID_H264 && + TAG_IS_AVCI(st->codecpar->codec_tag)) { ret = ff_generate_avci_extradata(st); if (ret < 0) return ret; } - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { #if CONFIG_H261_DECODER case AV_CODEC_ID_H261: #endif @@ -3119,16 +3136,16 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) #if CONFIG_MPEG4_DECODER case AV_CODEC_ID_MPEG4: #endif - st->codec->width = 0; /* let decoder init width/height */ - st->codec->height= 0; + st->codecpar->width = 0; /* let decoder init width/height */ + st->codecpar->height= 0; break; } // If the duration of the mp3 packets is not constant, then they could need a parser - if (st->codec->codec_id == AV_CODEC_ID_MP3 + if (st->codecpar->codec_id == AV_CODEC_ID_MP3 && sc->stts_count > 3 && sc->stts_count*10 > st->nb_frames - && sc->time_scale == st->codec->sample_rate) { + && sc->time_scale == st->codecpar->sample_rate) { st->need_parsing = AVSTREAM_PARSE_FULL; } /* Do not need those anymore. */ @@ -3613,7 +3630,7 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) frag->time = AV_NOPTS_VALUE; } sc->ctts_count++; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) keyframe = 1; else keyframe = @@ -4004,15 +4021,15 @@ static int mov_read_frma(MOVContext *c, AVIOContext *pb, MOVAtom atom) case MKTAG('e','n','c','v'): // encrypted video case MKTAG('e','n','c','a'): // encrypted audio id = mov_codec_id(st, format); - if (st->codec->codec_id != AV_CODEC_ID_NONE && - st->codec->codec_id != id) { + if (st->codecpar->codec_id != AV_CODEC_ID_NONE && + st->codecpar->codec_id != id) { av_log(c->fc, AV_LOG_WARNING, "ignoring 'frma' atom of '%.4s', stream has codec id %d\n", - (char*)&format, st->codec->codec_id); + (char*)&format, st->codecpar->codec_id); break; } - st->codec->codec_id = id; + st->codecpar->codec_id = id; sc->format = format; break; @@ -4597,8 +4614,7 @@ static int parse_timecode_in_framenum_format(AVFormatContext *s, AVStream *st, { AVTimecode tc; char buf[AV_TIMECODE_STR_SIZE]; - AVRational rate = {st->codec->time_base.den, - st->codec->time_base.num}; + AVRational rate = st->avg_frame_rate; int ret = av_timecode_init(&tc, rate, flags, 0, s); if (ret < 0) return ret; @@ -4710,7 +4726,7 @@ static int tmcd_is_referenced(AVFormatContext *s, int tmcd_id) AVStream *st = s->streams[i]; MOVStreamContext *sc = st->priv_data; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sc->timecode_track == tmcd_id) return 1; } @@ -4725,7 +4741,7 @@ static void export_orphan_timecode(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_tag == MKTAG('t','m','c','d') && + if (st->codecpar->codec_tag == MKTAG('t','m','c','d') && !tmcd_is_referenced(s, i + 1)) { AVDictionaryEntry *tcr = av_dict_get(st->metadata, "timecode", NULL, 0); if (tcr) { @@ -4885,7 +4901,7 @@ static int mov_read_header(AVFormatContext *s) if (mov->chapter_track > 0 && !mov->ignore_chapters) mov_read_chapters(s); for (i = 0; i < s->nb_streams; i++) - if (s->streams[i]->codec->codec_tag == AV_RL32("tmcd")) + if (s->streams[i]->codecpar->codec_tag == AV_RL32("tmcd")) mov_read_timecode_track(s, s->streams[i]); } @@ -4914,25 +4930,25 @@ static int mov_read_header(AVFormatContext *s) AVStream *st = s->streams[i]; MOVStreamContext *sc = st->priv_data; fix_timescale(mov, sc); - if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->codec->codec_id == AV_CODEC_ID_AAC) { + if(st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->codec_id == AV_CODEC_ID_AAC) { st->skip_samples = sc->start_pad; } - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && sc->nb_frames_for_fps > 0 && sc->duration_for_fps > 0) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && sc->nb_frames_for_fps > 0 && sc->duration_for_fps > 0) av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, sc->time_scale*(int64_t)sc->nb_frames_for_fps, sc->duration_for_fps, INT_MAX); - if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { - if (st->codec->width <= 0 || st->codec->height <= 0) { - st->codec->width = sc->width; - st->codec->height = sc->height; + if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { + if (st->codecpar->width <= 0 || st->codecpar->height <= 0) { + st->codecpar->width = sc->width; + st->codecpar->height = sc->height; } - if (st->codec->codec_id == AV_CODEC_ID_DVD_SUBTITLE) { + if (st->codecpar->codec_id == AV_CODEC_ID_DVD_SUBTITLE) { if ((err = mov_rewrite_dvd_sub_extradata(st)) < 0) return err; } } if (mov->handbrake_version && mov->handbrake_version <= 1000000*0 + 1000*10 + 2 && // 0.10.2 - st->codec->codec_id == AV_CODEC_ID_MP3 + st->codecpar->codec_id == AV_CODEC_ID_MP3 ) { av_log(s, AV_LOG_VERBOSE, "Forcing full parsing for mp3 stream\n"); st->need_parsing = AVSTREAM_PARSE_FULL; @@ -4944,7 +4960,7 @@ static int mov_read_header(AVFormatContext *s) AVStream *st = s->streams[i]; MOVStreamContext *sc = st->priv_data; if (st->duration > 0) - st->codec->bit_rate = sc->data_size * 8 * sc->time_scale / st->duration; + st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale / st->duration; } } @@ -4953,7 +4969,7 @@ static int mov_read_header(AVFormatContext *s) AVStream *st = s->streams[i]; MOVStreamContext *sc = st->priv_data; if (sc->duration_for_fps > 0) { - st->codec->bit_rate = sc->data_size * 8 * sc->time_scale / + st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale / sc->duration_for_fps; } } @@ -4961,7 +4977,7 @@ static int mov_read_header(AVFormatContext *s) for (i = 0; i < mov->bitrates_count && i < s->nb_streams; i++) { if (mov->bitrates[i]) { - s->streams[i]->codec->bit_rate = mov->bitrates[i]; + s->streams[i]->codecpar->bit_rate = mov->bitrates[i]; } } @@ -4971,7 +4987,7 @@ static int mov_read_header(AVFormatContext *s) AVStream *st = s->streams[i]; MOVStreamContext *sc = st->priv_data; - switch (st->codec->codec_type) { + switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: err = ff_replaygain_export(st, s->metadata); if (err < 0) { diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index cba07c51e5..dc8bf8dccc 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -588,9 +588,9 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st, } if (layout_tag == 0) { if (label_mask) - st->codec->channel_layout = label_mask; + st->codecpar->channel_layout = label_mask; } else - st->codec->channel_layout = ff_mov_get_channel_layout(layout_tag, bitmap); + st->codecpar->channel_layout = ff_mov_get_channel_layout(layout_tag, bitmap); avio_skip(pb, size - 12); return 0; diff --git a/libavformat/movenc-test.c b/libavformat/movenc-test.c index 8c69c767a7..e7928a6c6a 100644 --- a/libavformat/movenc-test.c +++ b/libavformat/movenc-test.c @@ -159,33 +159,33 @@ static void init_fps(int bf, int audio_preroll, int fps) st = avformat_new_stream(ctx, NULL); if (!st) exit(1); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_H264; - st->codec->width = 640; - st->codec->height = 480; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_H264; + st->codecpar->width = 640; + st->codecpar->height = 480; st->time_base.num = 1; st->time_base.den = 30; - st->codec->extradata_size = sizeof(h264_extradata); - st->codec->extradata = av_mallocz(st->codec->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + st->codecpar->extradata_size = sizeof(h264_extradata); + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) exit(1); - memcpy(st->codec->extradata, h264_extradata, sizeof(h264_extradata)); + memcpy(st->codecpar->extradata, h264_extradata, sizeof(h264_extradata)); video_st = st; st = avformat_new_stream(ctx, NULL); if (!st) exit(1); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_AAC; - st->codec->sample_rate = 44100; - st->codec->channels = 2; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_AAC; + st->codecpar->sample_rate = 44100; + st->codecpar->channels = 2; st->time_base.num = 1; st->time_base.den = 44100; - st->codec->extradata_size = sizeof(aac_extradata); - st->codec->extradata = av_mallocz(st->codec->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + st->codecpar->extradata_size = sizeof(aac_extradata); + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) exit(1); - memcpy(st->codec->extradata, aac_extradata, sizeof(aac_extradata)); + memcpy(st->codecpar->extradata, aac_extradata, sizeof(aac_extradata)); audio_st = st; if (avformat_write_header(ctx, &opts) < 0) @@ -195,9 +195,9 @@ static void init_fps(int bf, int audio_preroll, int fps) frames = 0; gop_size = 30; duration = video_st->time_base.den / fps; - audio_duration = 1024LL * audio_st->time_base.den / audio_st->codec->sample_rate; + audio_duration = 1024LL * audio_st->time_base.den / audio_st->codecpar->sample_rate; if (audio_preroll) - audio_preroll = 2048LL * audio_st->time_base.den / audio_st->codec->sample_rate; + audio_preroll = 2048LL * audio_st->time_base.den / audio_st->codecpar->sample_rate; bframes = bf; video_dts = bframes ? -duration : 0; diff --git a/libavformat/movenc.c b/libavformat/movenc.c index efaac36ba6..5acb9aff12 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -370,7 +370,7 @@ static int handle_eac3(MOVMuxContext *mov, AVPacket *pkt, MOVTrack *track) if (hdr->substreamid == info->num_ind_sub + 1) { //info->num_ind_sub++; - avpriv_request_sample(track->enc, "Multiple independent substreams"); + avpriv_request_sample(track->par, "Multiple independent substreams"); return AVERROR_PATCHWELCOME; } else if (hdr->substreamid < info->num_ind_sub || hdr->substreamid == 0 && info->substream[0].bsid) { @@ -513,8 +513,8 @@ end: */ static int mov_write_extradata_tag(AVIOContext *pb, MOVTrack *track) { - avio_write(pb, track->enc->extradata, track->enc->extradata_size); - return track->enc->extradata_size; + avio_write(pb, track->par->extradata, track->par->extradata_size); + return track->par->extradata_size; } static int mov_write_enda_tag(AVIOContext *pb) @@ -573,18 +573,18 @@ static int mov_write_esds_tag(AVIOContext *pb, MOVTrack *track) // Basic put_descr(pb, 0x04, 13 + decoder_specific_info_len); // Object type indication - if ((track->enc->codec_id == AV_CODEC_ID_MP2 || - track->enc->codec_id == AV_CODEC_ID_MP3) && - track->enc->sample_rate > 24000) + if ((track->par->codec_id == AV_CODEC_ID_MP2 || + track->par->codec_id == AV_CODEC_ID_MP3) && + track->par->sample_rate > 24000) avio_w8(pb, 0x6B); // 11172-3 else - avio_w8(pb, ff_codec_get_tag(ff_mp4_obj_type, track->enc->codec_id)); + avio_w8(pb, ff_codec_get_tag(ff_mp4_obj_type, track->par->codec_id)); // the following fields is made of 6 bits to identify the streamtype (4 for video, 5 for audio) // plus 1 bit to indicate upstream and 1 bit set to 1 (reserved) - if (track->enc->codec_id == AV_CODEC_ID_DVD_SUBTITLE) + if (track->par->codec_id == AV_CODEC_ID_DVD_SUBTITLE) avio_w8(pb, (0x38 << 2) | 1); // flags (= NeroSubpicStream) - else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) + else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) avio_w8(pb, 0x15); // flags (= Audiostream) else avio_w8(pb, 0x11); // flags (= Visualstream) @@ -595,7 +595,7 @@ static int mov_write_esds_tag(AVIOContext *pb, MOVTrack *track) // Basic avio_wb24(pb, props ? props->buffer_size / 8 : 0); // Buffersize DB avg_bitrate = compute_avg_bitrate(track); - avio_wb32(pb, props ? FFMAX3(props->max_bitrate, props->avg_bitrate, avg_bitrate) : FFMAX(track->enc->bit_rate, avg_bitrate)); // maxbitrate (FIXME should be max rate in any 1 sec window) + avio_wb32(pb, props ? FFMAX3(props->max_bitrate, props->avg_bitrate, avg_bitrate) : FFMAX(track->par->bit_rate, avg_bitrate)); // maxbitrate (FIXME should be max rate in any 1 sec window) avio_wb32(pb, avg_bitrate); if (track->vos_len) { @@ -626,39 +626,39 @@ static int mov_pcm_be_gt16(enum AVCodecID codec_id) codec_id == AV_CODEC_ID_PCM_F64BE; } -static int mov_write_ms_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_ms_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { int ret; int64_t pos = avio_tell(pb); avio_wb32(pb, 0); avio_wl32(pb, track->tag); // store it byteswapped - track->enc->codec_tag = av_bswap16(track->tag >> 16); - if ((ret = ff_put_wav_header(pb, track->enc, 0)) < 0) + track->par->codec_tag = av_bswap16(track->tag >> 16); + if ((ret = ff_put_wav_header(s, pb, track->par, 0)) < 0) return ret; return update_size(pb, pos); } -static int mov_write_wfex_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_wfex_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { int ret; int64_t pos = avio_tell(pb); avio_wb32(pb, 0); ffio_wfourcc(pb, "wfex"); - if ((ret = ff_put_wav_header(pb, track->enc, FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX)) < 0) + if ((ret = ff_put_wav_header(s, pb, track->st->codecpar, FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX)) < 0) return ret; return update_size(pb, pos); } -static int mov_write_chan_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_chan_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { uint32_t layout_tag, bitmap; int64_t pos = avio_tell(pb); - layout_tag = ff_mov_get_channel_layout_tag(track->enc->codec_id, - track->enc->channel_layout, + layout_tag = ff_mov_get_channel_layout_tag(track->par->codec_id, + track->par->channel_layout, &bitmap); if (!layout_tag) { - av_log(track->enc, AV_LOG_WARNING, "not writing 'chan' tag due to " + av_log(s, AV_LOG_WARNING, "not writing 'chan' tag due to " "lack of channel information\n"); return 0; } @@ -677,41 +677,41 @@ static int mov_write_chan_tag(AVIOContext *pb, MOVTrack *track) return update_size(pb, pos); } -static int mov_write_wave_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_wave_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { int64_t pos = avio_tell(pb); avio_wb32(pb, 0); /* size */ ffio_wfourcc(pb, "wave"); - if (track->enc->codec_id != AV_CODEC_ID_QDM2) { + if (track->par->codec_id != AV_CODEC_ID_QDM2) { avio_wb32(pb, 12); /* size */ ffio_wfourcc(pb, "frma"); avio_wl32(pb, track->tag); } - if (track->enc->codec_id == AV_CODEC_ID_AAC) { + if (track->par->codec_id == AV_CODEC_ID_AAC) { /* useless atom needed by mplayer, ipod, not needed by quicktime */ avio_wb32(pb, 12); /* size */ ffio_wfourcc(pb, "mp4a"); avio_wb32(pb, 0); mov_write_esds_tag(pb, track); - } else if (mov_pcm_le_gt16(track->enc->codec_id)) { + } else if (mov_pcm_le_gt16(track->par->codec_id)) { mov_write_enda_tag(pb); - } else if (mov_pcm_be_gt16(track->enc->codec_id)) { + } else if (mov_pcm_be_gt16(track->par->codec_id)) { mov_write_enda_tag_be(pb); - } else if (track->enc->codec_id == AV_CODEC_ID_AMR_NB) { + } else if (track->par->codec_id == AV_CODEC_ID_AMR_NB) { mov_write_amr_tag(pb, track); - } else if (track->enc->codec_id == AV_CODEC_ID_AC3) { + } else if (track->par->codec_id == AV_CODEC_ID_AC3) { mov_write_ac3_tag(pb, track); - } else if (track->enc->codec_id == AV_CODEC_ID_EAC3) { + } else if (track->par->codec_id == AV_CODEC_ID_EAC3) { mov_write_eac3_tag(pb, track); - } else if (track->enc->codec_id == AV_CODEC_ID_ALAC || - track->enc->codec_id == AV_CODEC_ID_QDM2) { + } else if (track->par->codec_id == AV_CODEC_ID_ALAC || + track->par->codec_id == AV_CODEC_ID_QDM2) { mov_write_extradata_tag(pb, track); - } else if (track->enc->codec_id == AV_CODEC_ID_ADPCM_MS || - track->enc->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) { - mov_write_ms_tag(pb, track); + } else if (track->par->codec_id == AV_CODEC_ID_ADPCM_MS || + track->par->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) { + mov_write_ms_tag(s, pb, track); } avio_wb32(pb, 8); /* size */ @@ -880,7 +880,7 @@ static int get_samples_per_packet(MOVTrack *track) { int i, first_duration; -// return track->enc->frame_size; +// return track->par->frame_size; /* use 1 for raw PCM */ if (!track->audio_vbr) @@ -897,7 +897,7 @@ static int get_samples_per_packet(MOVTrack *track) return first_duration; } -static int mov_write_audio_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track) +static int mov_write_audio_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track) { int64_t pos = avio_tell(pb); int version = 0; @@ -905,14 +905,14 @@ static int mov_write_audio_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *tr if (track->mode == MODE_MOV) { if (track->timescale > UINT16_MAX) { - if (mov_get_lpcm_flags(track->enc->codec_id)) + if (mov_get_lpcm_flags(track->par->codec_id)) tag = AV_RL32("lpcm"); version = 2; - } else if (track->audio_vbr || mov_pcm_le_gt16(track->enc->codec_id) || - mov_pcm_be_gt16(track->enc->codec_id) || - track->enc->codec_id == AV_CODEC_ID_ADPCM_MS || - track->enc->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV || - track->enc->codec_id == AV_CODEC_ID_QDM2) { + } else if (track->audio_vbr || mov_pcm_le_gt16(track->par->codec_id) || + mov_pcm_be_gt16(track->par->codec_id) || + track->par->codec_id == AV_CODEC_ID_ADPCM_MS || + track->par->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV || + track->par->codec_id == AV_CODEC_ID_QDM2) { version = 1; } } @@ -939,21 +939,21 @@ static int mov_write_audio_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *tr avio_wb16(pb, 0); avio_wb32(pb, 0x00010000); avio_wb32(pb, 72); - avio_wb64(pb, av_double2int(track->enc->sample_rate)); - avio_wb32(pb, track->enc->channels); + avio_wb64(pb, av_double2int(track->par->sample_rate)); + avio_wb32(pb, track->par->channels); avio_wb32(pb, 0x7F000000); - avio_wb32(pb, av_get_bits_per_sample(track->enc->codec_id)); - avio_wb32(pb, mov_get_lpcm_flags(track->enc->codec_id)); + avio_wb32(pb, av_get_bits_per_sample(track->par->codec_id)); + avio_wb32(pb, mov_get_lpcm_flags(track->par->codec_id)); avio_wb32(pb, track->sample_size); avio_wb32(pb, get_samples_per_packet(track)); } else { if (track->mode == MODE_MOV) { - avio_wb16(pb, track->enc->channels); - if (track->enc->codec_id == AV_CODEC_ID_PCM_U8 || - track->enc->codec_id == AV_CODEC_ID_PCM_S8) + avio_wb16(pb, track->par->channels); + if (track->par->codec_id == AV_CODEC_ID_PCM_U8 || + track->par->codec_id == AV_CODEC_ID_PCM_S8) avio_wb16(pb, 8); /* bits per sample */ - else if (track->enc->codec_id == AV_CODEC_ID_ADPCM_G726) - avio_wb16(pb, track->enc->bits_per_coded_sample); + else if (track->par->codec_id == AV_CODEC_ID_ADPCM_G726) + avio_wb16(pb, track->par->bits_per_coded_sample); else avio_wb16(pb, 16); avio_wb16(pb, track->audio_vbr ? -2 : 0); /* compression ID */ @@ -964,51 +964,51 @@ static int mov_write_audio_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *tr } avio_wb16(pb, 0); /* packet size (= 0) */ - avio_wb16(pb, track->enc->sample_rate <= UINT16_MAX ? - track->enc->sample_rate : 0); + avio_wb16(pb, track->par->sample_rate <= UINT16_MAX ? + track->par->sample_rate : 0); avio_wb16(pb, 0); /* Reserved */ } if (version == 1) { /* SoundDescription V1 extended info */ - if (mov_pcm_le_gt16(track->enc->codec_id) || - mov_pcm_be_gt16(track->enc->codec_id)) + if (mov_pcm_le_gt16(track->par->codec_id) || + mov_pcm_be_gt16(track->par->codec_id)) avio_wb32(pb, 1); /* must be 1 for uncompressed formats */ else - avio_wb32(pb, track->enc->frame_size); /* Samples per packet */ - avio_wb32(pb, track->sample_size / track->enc->channels); /* Bytes per packet */ + avio_wb32(pb, track->par->frame_size); /* Samples per packet */ + avio_wb32(pb, track->sample_size / track->par->channels); /* Bytes per packet */ avio_wb32(pb, track->sample_size); /* Bytes per frame */ avio_wb32(pb, 2); /* Bytes per sample */ } if (track->mode == MODE_MOV && - (track->enc->codec_id == AV_CODEC_ID_AAC || - track->enc->codec_id == AV_CODEC_ID_AC3 || - track->enc->codec_id == AV_CODEC_ID_EAC3 || - track->enc->codec_id == AV_CODEC_ID_AMR_NB || - track->enc->codec_id == AV_CODEC_ID_ALAC || - track->enc->codec_id == AV_CODEC_ID_ADPCM_MS || - track->enc->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV || - track->enc->codec_id == AV_CODEC_ID_QDM2 || - (mov_pcm_le_gt16(track->enc->codec_id) && version==1) || - (mov_pcm_be_gt16(track->enc->codec_id) && version==1))) - mov_write_wave_tag(pb, track); + (track->par->codec_id == AV_CODEC_ID_AAC || + track->par->codec_id == AV_CODEC_ID_AC3 || + track->par->codec_id == AV_CODEC_ID_EAC3 || + track->par->codec_id == AV_CODEC_ID_AMR_NB || + track->par->codec_id == AV_CODEC_ID_ALAC || + track->par->codec_id == AV_CODEC_ID_ADPCM_MS || + track->par->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV || + track->par->codec_id == AV_CODEC_ID_QDM2 || + (mov_pcm_le_gt16(track->par->codec_id) && version==1) || + (mov_pcm_be_gt16(track->par->codec_id) && version==1))) + mov_write_wave_tag(s, pb, track); else if (track->tag == MKTAG('m','p','4','a')) mov_write_esds_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_AMR_NB) + else if (track->par->codec_id == AV_CODEC_ID_AMR_NB) mov_write_amr_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_AC3) + else if (track->par->codec_id == AV_CODEC_ID_AC3) mov_write_ac3_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_EAC3) + else if (track->par->codec_id == AV_CODEC_ID_EAC3) mov_write_eac3_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_ALAC) + else if (track->par->codec_id == AV_CODEC_ID_ALAC) mov_write_extradata_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_WMAPRO) - mov_write_wfex_tag(pb, track); + else if (track->par->codec_id == AV_CODEC_ID_WMAPRO) + mov_write_wfex_tag(s, pb, track); else if (track->vos_len > 0) mov_write_glbl_tag(pb, track); - if (track->mode == MODE_MOV && track->enc->codec_type == AVMEDIA_TYPE_AUDIO) - mov_write_chan_tag(pb, track); + if (track->mode == MODE_MOV && track->par->codec_type == AVMEDIA_TYPE_AUDIO) + mov_write_chan_tag(s, pb, track); if (mov->encryption_scheme != MOV_ENC_NONE) { ff_mov_cenc_write_sinf_tag(track, pb, mov->encryption_kid); @@ -1078,8 +1078,8 @@ static int mov_write_avid_tag(AVIOContext *pb, MOVTrack *track) ffio_wfourcc(pb, "ACLR"); ffio_wfourcc(pb, "ACLR"); ffio_wfourcc(pb, "0001"); - if (track->enc->color_range == AVCOL_RANGE_MPEG || /* Legal range (16-235) */ - track->enc->color_range == AVCOL_RANGE_UNSPECIFIED) { + if (track->par->color_range == AVCOL_RANGE_MPEG || /* Legal range (16-235) */ + track->par->color_range == AVCOL_RANGE_UNSPECIFIED) { avio_wb32(pb, 1); /* Corresponds to 709 in official encoder */ } else { /* Full range (0-255) */ avio_wb32(pb, 2); /* Corresponds to RGB in official encoder */ @@ -1098,18 +1098,18 @@ static int mov_write_avid_tag(AVIOContext *pb, MOVTrack *track) ffio_wfourcc(pb, "ARES"); ffio_wfourcc(pb, "0001"); avio_wb32(pb, cid); /* dnxhd cid, some id ? */ - avio_wb32(pb, track->enc->width); + avio_wb32(pb, track->par->width); /* values below are based on samples created with quicktime and avid codecs */ if (interlaced) { - avio_wb32(pb, track->enc->height / 2); + avio_wb32(pb, track->par->height / 2); avio_wb32(pb, 2); /* unknown */ avio_wb32(pb, 0); /* unknown */ avio_wb32(pb, 4); /* unknown */ } else { - avio_wb32(pb, track->enc->height); + avio_wb32(pb, track->par->height); avio_wb32(pb, 1); /* unknown */ avio_wb32(pb, 0); /* unknown */ - if (track->enc->height == 1080) + if (track->par->height == 1080) avio_wb32(pb, 5); /* unknown */ else avio_wb32(pb, 6); /* unknown */ @@ -1125,9 +1125,9 @@ static int mov_write_dpxe_tag(AVIOContext *pb, MOVTrack *track) { avio_wb32(pb, 12); ffio_wfourcc(pb, "DpxE"); - if (track->enc->extradata_size >= 12 && - !memcmp(&track->enc->extradata[4], "DpxE", 4)) { - avio_wb32(pb, track->enc->extradata[11]); + if (track->par->extradata_size >= 12 && + !memcmp(&track->par->extradata[4], "DpxE", 4)) { + avio_wb32(pb, track->par->extradata[11]); } else { avio_wb32(pb, 1); } @@ -1136,21 +1136,21 @@ static int mov_write_dpxe_tag(AVIOContext *pb, MOVTrack *track) static int mp4_get_codec_tag(AVFormatContext *s, MOVTrack *track) { - int tag = track->enc->codec_tag; + int tag = track->par->codec_tag; - if (!ff_codec_get_tag(ff_mp4_obj_type, track->enc->codec_id)) + if (!ff_codec_get_tag(ff_mp4_obj_type, track->par->codec_id)) return 0; - if (track->enc->codec_id == AV_CODEC_ID_H264) tag = MKTAG('a','v','c','1'); - else if (track->enc->codec_id == AV_CODEC_ID_HEVC) tag = MKTAG('h','e','v','1'); - else if (track->enc->codec_id == AV_CODEC_ID_AC3) tag = MKTAG('a','c','-','3'); - else if (track->enc->codec_id == AV_CODEC_ID_EAC3) tag = MKTAG('e','c','-','3'); - else if (track->enc->codec_id == AV_CODEC_ID_DIRAC) tag = MKTAG('d','r','a','c'); - else if (track->enc->codec_id == AV_CODEC_ID_MOV_TEXT) tag = MKTAG('t','x','3','g'); - else if (track->enc->codec_id == AV_CODEC_ID_VC1) tag = MKTAG('v','c','-','1'); - else if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) tag = MKTAG('m','p','4','v'); - else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) tag = MKTAG('m','p','4','a'); - else if (track->enc->codec_id == AV_CODEC_ID_DVD_SUBTITLE) tag = MKTAG('m','p','4','s'); + if (track->par->codec_id == AV_CODEC_ID_H264) tag = MKTAG('a','v','c','1'); + else if (track->par->codec_id == AV_CODEC_ID_HEVC) tag = MKTAG('h','e','v','1'); + else if (track->par->codec_id == AV_CODEC_ID_AC3) tag = MKTAG('a','c','-','3'); + else if (track->par->codec_id == AV_CODEC_ID_EAC3) tag = MKTAG('e','c','-','3'); + else if (track->par->codec_id == AV_CODEC_ID_DIRAC) tag = MKTAG('d','r','a','c'); + else if (track->par->codec_id == AV_CODEC_ID_MOV_TEXT) tag = MKTAG('t','x','3','g'); + else if (track->par->codec_id == AV_CODEC_ID_VC1) tag = MKTAG('v','c','-','1'); + else if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) tag = MKTAG('m','p','4','v'); + else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) tag = MKTAG('m','p','4','a'); + else if (track->par->codec_id == AV_CODEC_ID_DVD_SUBTITLE) tag = MKTAG('m','p','4','s'); return tag; } @@ -1168,13 +1168,13 @@ static const AVCodecTag codec_ipod_tags[] = { static int ipod_get_codec_tag(AVFormatContext *s, MOVTrack *track) { - int tag = track->enc->codec_tag; + int tag = track->par->codec_tag; // keep original tag for subs, ipod supports both formats - if (!(track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE && + if (!(track->par->codec_type == AVMEDIA_TYPE_SUBTITLE && (tag == MKTAG('t', 'x', '3', 'g') || tag == MKTAG('t', 'e', 'x', 't')))) - tag = ff_codec_get_tag(codec_ipod_tags, track->enc->codec_id); + tag = ff_codec_get_tag(codec_ipod_tags, track->par->codec_id); if (!av_match_ext(s->filename, "m4a") && !av_match_ext(s->filename, "m4b") && @@ -1189,17 +1189,17 @@ static int mov_get_dv_codec_tag(AVFormatContext *s, MOVTrack *track) { int tag; - if (track->enc->width == 720) { /* SD */ - if (track->enc->height == 480) { /* NTSC */ - if (track->enc->pix_fmt == AV_PIX_FMT_YUV422P) tag = MKTAG('d','v','5','n'); + if (track->par->width == 720) { /* SD */ + if (track->par->height == 480) { /* NTSC */ + if (track->par->format == AV_PIX_FMT_YUV422P) tag = MKTAG('d','v','5','n'); else tag = MKTAG('d','v','c',' '); - }else if (track->enc->pix_fmt == AV_PIX_FMT_YUV422P) tag = MKTAG('d','v','5','p'); - else if (track->enc->pix_fmt == AV_PIX_FMT_YUV420P) tag = MKTAG('d','v','c','p'); + }else if (track->par->format == AV_PIX_FMT_YUV422P) tag = MKTAG('d','v','5','p'); + else if (track->par->format == AV_PIX_FMT_YUV420P) tag = MKTAG('d','v','c','p'); else tag = MKTAG('d','v','p','p'); - } else if (track->enc->height == 720) { /* HD 720 line */ + } else if (track->par->height == 720) { /* HD 720 line */ if (track->st->time_base.den == 50) tag = MKTAG('d','v','h','q'); else tag = MKTAG('d','v','h','p'); - } else if (track->enc->height == 1080) { /* HD 1080 line */ + } else if (track->par->height == 1080) { /* HD 1080 line */ if (track->st->time_base.den == 25) tag = MKTAG('d','v','h','5'); else tag = MKTAG('d','v','h','6'); } else { @@ -1212,29 +1212,34 @@ static int mov_get_dv_codec_tag(AVFormatContext *s, MOVTrack *track) static AVRational find_fps(AVFormatContext *s, AVStream *st) { - AVRational rate = {st->codec->time_base.den, st->codec->time_base.num}; - /* if the codec time base makes no sense, try to fallback on stream frame rate */ + AVRational rate = st->avg_frame_rate; + +#if FF_API_LAVF_AVCTX + FF_DISABLE_DEPRECATION_WARNINGS + rate = av_inv_q(st->codec->time_base); if (av_timecode_check_frame_rate(rate) < 0) { av_log(s, AV_LOG_DEBUG, "timecode: tbc=%d/%d invalid, fallback on %d/%d\n", rate.num, rate.den, st->avg_frame_rate.num, st->avg_frame_rate.den); rate = st->avg_frame_rate; } + FF_ENABLE_DEPRECATION_WARNINGS +#endif return rate; } static int mov_get_mpeg2_xdcam_codec_tag(AVFormatContext *s, MOVTrack *track) { - int tag = track->enc->codec_tag; - int interlaced = track->enc->field_order > AV_FIELD_PROGRESSIVE; + int tag = track->par->codec_tag; + int interlaced = track->par->field_order > AV_FIELD_PROGRESSIVE; AVStream *st = track->st; int rate = av_q2d(find_fps(s, st)); if (!tag) tag = MKTAG('m', '2', 'v', '1'); //fallback tag - if (track->enc->pix_fmt == AV_PIX_FMT_YUV420P) { - if (track->enc->width == 1280 && track->enc->height == 720) { + if (track->par->format == AV_PIX_FMT_YUV420P) { + if (track->par->width == 1280 && track->par->height == 720) { if (!interlaced) { if (rate == 24) tag = MKTAG('x','d','v','4'); else if (rate == 25) tag = MKTAG('x','d','v','5'); @@ -1242,7 +1247,7 @@ static int mov_get_mpeg2_xdcam_codec_tag(AVFormatContext *s, MOVTrack *track) else if (rate == 50) tag = MKTAG('x','d','v','a'); else if (rate == 60) tag = MKTAG('x','d','v','9'); } - } else if (track->enc->width == 1440 && track->enc->height == 1080) { + } else if (track->par->width == 1440 && track->par->height == 1080) { if (!interlaced) { if (rate == 24) tag = MKTAG('x','d','v','6'); else if (rate == 25) tag = MKTAG('x','d','v','7'); @@ -1251,7 +1256,7 @@ static int mov_get_mpeg2_xdcam_codec_tag(AVFormatContext *s, MOVTrack *track) if (rate == 25) tag = MKTAG('x','d','v','3'); else if (rate == 30) tag = MKTAG('x','d','v','2'); } - } else if (track->enc->width == 1920 && track->enc->height == 1080) { + } else if (track->par->width == 1920 && track->par->height == 1080) { if (!interlaced) { if (rate == 24) tag = MKTAG('x','d','v','d'); else if (rate == 25) tag = MKTAG('x','d','v','e'); @@ -1261,8 +1266,8 @@ static int mov_get_mpeg2_xdcam_codec_tag(AVFormatContext *s, MOVTrack *track) else if (rate == 30) tag = MKTAG('x','d','v','b'); } } - } else if (track->enc->pix_fmt == AV_PIX_FMT_YUV422P) { - if (track->enc->width == 1280 && track->enc->height == 720) { + } else if (track->par->format == AV_PIX_FMT_YUV422P) { + if (track->par->width == 1280 && track->par->height == 720) { if (!interlaced) { if (rate == 24) tag = MKTAG('x','d','5','4'); else if (rate == 25) tag = MKTAG('x','d','5','5'); @@ -1270,7 +1275,7 @@ static int mov_get_mpeg2_xdcam_codec_tag(AVFormatContext *s, MOVTrack *track) else if (rate == 50) tag = MKTAG('x','d','5','a'); else if (rate == 60) tag = MKTAG('x','d','5','9'); } - } else if (track->enc->width == 1920 && track->enc->height == 1080) { + } else if (track->par->width == 1920 && track->par->height == 1080) { if (!interlaced) { if (rate == 24) tag = MKTAG('x','d','5','d'); else if (rate == 25) tag = MKTAG('x','d','5','e'); @@ -1287,16 +1292,16 @@ static int mov_get_mpeg2_xdcam_codec_tag(AVFormatContext *s, MOVTrack *track) static int mov_get_h264_codec_tag(AVFormatContext *s, MOVTrack *track) { - int tag = track->enc->codec_tag; - int interlaced = track->enc->field_order > AV_FIELD_PROGRESSIVE; + int tag = track->par->codec_tag; + int interlaced = track->par->field_order > AV_FIELD_PROGRESSIVE; AVStream *st = track->st; int rate = av_q2d(find_fps(s, st)); if (!tag) tag = MKTAG('a', 'v', 'c', 'i'); //fallback tag - if (track->enc->pix_fmt == AV_PIX_FMT_YUV420P10) { - if (track->enc->width == 960 && track->enc->height == 720) { + if (track->par->format == AV_PIX_FMT_YUV420P10) { + if (track->par->width == 960 && track->par->height == 720) { if (!interlaced) { if (rate == 24) tag = MKTAG('a','i','5','p'); else if (rate == 25) tag = MKTAG('a','i','5','q'); @@ -1304,7 +1309,7 @@ static int mov_get_h264_codec_tag(AVFormatContext *s, MOVTrack *track) else if (rate == 50) tag = MKTAG('a','i','5','q'); else if (rate == 60) tag = MKTAG('a','i','5','p'); } - } else if (track->enc->width == 1440 && track->enc->height == 1080) { + } else if (track->par->width == 1440 && track->par->height == 1080) { if (!interlaced) { if (rate == 24) tag = MKTAG('a','i','5','3'); else if (rate == 25) tag = MKTAG('a','i','5','2'); @@ -1314,8 +1319,8 @@ static int mov_get_h264_codec_tag(AVFormatContext *s, MOVTrack *track) else if (rate == 60) tag = MKTAG('a','i','5','6'); } } - } else if (track->enc->pix_fmt == AV_PIX_FMT_YUV422P10) { - if (track->enc->width == 1280 && track->enc->height == 720) { + } else if (track->par->format == AV_PIX_FMT_YUV422P10) { + if (track->par->width == 1280 && track->par->height == 720) { if (!interlaced) { if (rate == 24) tag = MKTAG('a','i','1','p'); else if (rate == 25) tag = MKTAG('a','i','1','q'); @@ -1323,7 +1328,7 @@ static int mov_get_h264_codec_tag(AVFormatContext *s, MOVTrack *track) else if (rate == 50) tag = MKTAG('a','i','1','q'); else if (rate == 60) tag = MKTAG('a','i','1','p'); } - } else if (track->enc->width == 1920 && track->enc->height == 1080) { + } else if (track->par->width == 1920 && track->par->height == 1080) { if (!interlaced) { if (rate == 24) tag = MKTAG('a','i','1','3'); else if (rate == 25) tag = MKTAG('a','i','1','2'); @@ -1333,9 +1338,9 @@ static int mov_get_h264_codec_tag(AVFormatContext *s, MOVTrack *track) else if (rate == 50) tag = MKTAG('a','i','1','5'); else if (rate == 60) tag = MKTAG('a','i','1','6'); } - } else if ( track->enc->width == 4096 && track->enc->height == 2160 - || track->enc->width == 3840 && track->enc->height == 2160 - || track->enc->width == 2048 && track->enc->height == 1080) { + } else if ( track->par->width == 4096 && track->par->height == 2160 + || track->par->width == 3840 && track->par->height == 2160 + || track->par->width == 2048 && track->par->height == 1080) { tag = MKTAG('a','i','v','x'); } } @@ -1367,68 +1372,68 @@ static const struct { static int mov_get_rawvideo_codec_tag(AVFormatContext *s, MOVTrack *track) { - int tag = track->enc->codec_tag; + int tag = track->par->codec_tag; int i; enum AVPixelFormat pix_fmt; for (i = 0; i < FF_ARRAY_ELEMS(mov_pix_fmt_tags); i++) { - if (track->enc->pix_fmt == mov_pix_fmt_tags[i].pix_fmt) { + if (track->par->format == mov_pix_fmt_tags[i].pix_fmt) { tag = mov_pix_fmt_tags[i].tag; - track->enc->bits_per_coded_sample = mov_pix_fmt_tags[i].bps; - if (track->enc->codec_tag == mov_pix_fmt_tags[i].tag) + track->par->bits_per_coded_sample = mov_pix_fmt_tags[i].bps; + if (track->par->codec_tag == mov_pix_fmt_tags[i].tag) break; } } pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_mov, - track->enc->bits_per_coded_sample); + track->par->bits_per_coded_sample); if (tag == MKTAG('r','a','w',' ') && - track->enc->pix_fmt != pix_fmt && - track->enc->pix_fmt != AV_PIX_FMT_NONE) + track->par->format != pix_fmt && + track->par->format != AV_PIX_FMT_NONE) av_log(s, AV_LOG_ERROR, "%s rawvideo cannot be written to mov, output file will be unreadable\n", - av_get_pix_fmt_name(track->enc->pix_fmt)); + av_get_pix_fmt_name(track->par->format)); return tag; } static int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track) { - int tag = track->enc->codec_tag; + int tag = track->par->codec_tag; if (!tag || (s->strict_std_compliance >= FF_COMPLIANCE_NORMAL && - (track->enc->codec_id == AV_CODEC_ID_DVVIDEO || - track->enc->codec_id == AV_CODEC_ID_RAWVIDEO || - track->enc->codec_id == AV_CODEC_ID_H263 || - track->enc->codec_id == AV_CODEC_ID_H264 || - track->enc->codec_id == AV_CODEC_ID_MPEG2VIDEO || - av_get_bits_per_sample(track->enc->codec_id)))) { // pcm audio - if (track->enc->codec_id == AV_CODEC_ID_DVVIDEO) + (track->par->codec_id == AV_CODEC_ID_DVVIDEO || + track->par->codec_id == AV_CODEC_ID_RAWVIDEO || + track->par->codec_id == AV_CODEC_ID_H263 || + track->par->codec_id == AV_CODEC_ID_H264 || + track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO || + av_get_bits_per_sample(track->par->codec_id)))) { // pcm audio + if (track->par->codec_id == AV_CODEC_ID_DVVIDEO) tag = mov_get_dv_codec_tag(s, track); - else if (track->enc->codec_id == AV_CODEC_ID_RAWVIDEO) + else if (track->par->codec_id == AV_CODEC_ID_RAWVIDEO) tag = mov_get_rawvideo_codec_tag(s, track); - else if (track->enc->codec_id == AV_CODEC_ID_MPEG2VIDEO) + else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO) tag = mov_get_mpeg2_xdcam_codec_tag(s, track); - else if (track->enc->codec_id == AV_CODEC_ID_H264) + else if (track->par->codec_id == AV_CODEC_ID_H264) tag = mov_get_h264_codec_tag(s, track); - else if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) { - tag = ff_codec_get_tag(ff_codec_movvideo_tags, track->enc->codec_id); + else if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) { + tag = ff_codec_get_tag(ff_codec_movvideo_tags, track->par->codec_id); if (!tag) { // if no mac fcc found, try with Microsoft tags - tag = ff_codec_get_tag(ff_codec_bmp_tags, track->enc->codec_id); + tag = ff_codec_get_tag(ff_codec_bmp_tags, track->par->codec_id); if (tag) av_log(s, AV_LOG_WARNING, "Using MS style video codec tag, " "the file may be unplayable!\n"); } - } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) { - tag = ff_codec_get_tag(ff_codec_movaudio_tags, track->enc->codec_id); + } else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) { + tag = ff_codec_get_tag(ff_codec_movaudio_tags, track->par->codec_id); if (!tag) { // if no mac fcc found, try with Microsoft tags - int ms_tag = ff_codec_get_tag(ff_codec_wav_tags, track->enc->codec_id); + int ms_tag = ff_codec_get_tag(ff_codec_wav_tags, track->par->codec_id); if (ms_tag) { tag = MKTAG('m', 's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff)); av_log(s, AV_LOG_WARNING, "Using MS style audio codec tag, " "the file may be unplayable!\n"); } } - } else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) - tag = ff_codec_get_tag(ff_codec_movsubtitle_tags, track->enc->codec_id); + } else if (track->par->codec_type == AVMEDIA_TYPE_SUBTITLE) + tag = ff_codec_get_tag(ff_codec_movsubtitle_tags, track->par->codec_id); } return tag; @@ -1462,14 +1467,14 @@ static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track) tag = mp4_get_codec_tag(s, track); else if (track->mode == MODE_ISM) { tag = mp4_get_codec_tag(s, track); - if (!tag && track->enc->codec_id == AV_CODEC_ID_WMAPRO) + if (!tag && track->par->codec_id == AV_CODEC_ID_WMAPRO) tag = MKTAG('w', 'm', 'a', ' '); } else if (track->mode == MODE_IPOD) tag = ipod_get_codec_tag(s, track); else if (track->mode & MODE_3GP) - tag = ff_codec_get_tag(codec_3gp_tags, track->enc->codec_id); + tag = ff_codec_get_tag(codec_3gp_tags, track->par->codec_id); else if (track->mode == MODE_F4V) - tag = ff_codec_get_tag(codec_f4v_tags, track->enc->codec_id); + tag = ff_codec_get_tag(codec_f4v_tags, track->par->codec_id); else tag = mov_get_codec_tag(s, track); @@ -1496,11 +1501,11 @@ static const uint16_t fiel_data[] = { 0x0000, 0x0100, 0x0201, 0x0206, 0x0209, 0x020e }; -static int mov_write_fiel_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_fiel_tag(AVIOContext *pb, MOVTrack *track, int field_order) { unsigned mov_field_order = 0; - if (track->enc->field_order < FF_ARRAY_ELEMS(fiel_data)) - mov_field_order = fiel_data[track->enc->field_order]; + if (field_order < FF_ARRAY_ELEMS(fiel_data)) + mov_field_order = fiel_data[field_order]; else return 0; avio_wb32(pb, 10); @@ -1518,10 +1523,10 @@ static int mov_write_subtitle_tag(AVIOContext *pb, MOVTrack *track) avio_wb16(pb, 0); /* Reserved */ avio_wb16(pb, 1); /* Data-reference index */ - if (track->enc->codec_id == AV_CODEC_ID_DVD_SUBTITLE) + if (track->par->codec_id == AV_CODEC_ID_DVD_SUBTITLE) mov_write_esds_tag(pb, track); - else if (track->enc->extradata_size) - avio_write(pb, track->enc->extradata, track->enc->extradata_size); + else if (track->par->extradata_size) + avio_write(pb, track->par->extradata, track->par->extradata_size); return update_size(pb, pos); } @@ -1529,8 +1534,8 @@ static int mov_write_subtitle_tag(AVIOContext *pb, MOVTrack *track) static int mov_write_pasp_tag(AVIOContext *pb, MOVTrack *track) { AVRational sar; - av_reduce(&sar.num, &sar.den, track->enc->sample_aspect_ratio.num, - track->enc->sample_aspect_ratio.den, INT_MAX); + av_reduce(&sar.num, &sar.den, track->par->sample_aspect_ratio.num, + track->par->sample_aspect_ratio.den, INT_MAX); avio_wb32(pb, 16); ffio_wfourcc(pb, "pasp"); @@ -1544,7 +1549,7 @@ static int mov_write_gama_tag(AVIOContext *pb, MOVTrack *track, double gamma) uint32_t gama = 0; if (gamma <= 0.0) { - gamma = avpriv_get_gamma_from_trc(track->enc->color_trc); + gamma = avpriv_get_gamma_from_trc(track->par->color_trc); } av_log(pb, AV_LOG_DEBUG, "gamma value %g\n", gamma); @@ -1569,32 +1574,32 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack *track) // Ref (MOV): https://developer.apple.com/library/mac/technotes/tn2162/_index.html#//apple_ref/doc/uid/DTS40013070-CH1-TNTAG9 // Ref (MP4): ISO/IEC 14496-12:2012 - if (track->enc->color_primaries == AVCOL_PRI_UNSPECIFIED && - track->enc->color_trc == AVCOL_TRC_UNSPECIFIED && - track->enc->colorspace == AVCOL_SPC_UNSPECIFIED) { - if ((track->enc->width >= 1920 && track->enc->height >= 1080) - || (track->enc->width == 1280 && track->enc->height == 720)) { + if (track->par->color_primaries == AVCOL_PRI_UNSPECIFIED && + track->par->color_trc == AVCOL_TRC_UNSPECIFIED && + track->par->color_space == AVCOL_SPC_UNSPECIFIED) { + if ((track->par->width >= 1920 && track->par->height >= 1080) + || (track->par->width == 1280 && track->par->height == 720)) { av_log(NULL, AV_LOG_WARNING, "color primaries unspecified, assuming bt709\n"); - track->enc->color_primaries = AVCOL_PRI_BT709; - } else if (track->enc->width == 720 && track->height == 576) { + track->par->color_primaries = AVCOL_PRI_BT709; + } else if (track->par->width == 720 && track->height == 576) { av_log(NULL, AV_LOG_WARNING, "color primaries unspecified, assuming bt470bg\n"); - track->enc->color_primaries = AVCOL_PRI_BT470BG; - } else if (track->enc->width == 720 && + track->par->color_primaries = AVCOL_PRI_BT470BG; + } else if (track->par->width == 720 && (track->height == 486 || track->height == 480)) { av_log(NULL, AV_LOG_WARNING, "color primaries unspecified, assuming smpte170\n"); - track->enc->color_primaries = AVCOL_PRI_SMPTE170M; + track->par->color_primaries = AVCOL_PRI_SMPTE170M; } else { av_log(NULL, AV_LOG_WARNING, "color primaries unspecified, unable to assume anything\n"); } - switch (track->enc->color_primaries) { + switch (track->par->color_primaries) { case AVCOL_PRI_BT709: - track->enc->color_trc = AVCOL_TRC_BT709; - track->enc->colorspace = AVCOL_SPC_BT709; + track->par->color_trc = AVCOL_TRC_BT709; + track->par->color_space = AVCOL_SPC_BT709; break; case AVCOL_PRI_SMPTE170M: case AVCOL_PRI_BT470BG: - track->enc->color_trc = AVCOL_TRC_BT709; - track->enc->colorspace = AVCOL_SPC_SMPTE170M; + track->par->color_trc = AVCOL_TRC_BT709; + track->par->color_space = AVCOL_SPC_SMPTE170M; break; } } @@ -1608,20 +1613,20 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack *track) ffio_wfourcc(pb, "nclx"); else ffio_wfourcc(pb, "nclc"); - switch (track->enc->color_primaries) { + switch (track->par->color_primaries) { case AVCOL_PRI_BT709: avio_wb16(pb, 1); break; case AVCOL_PRI_SMPTE170M: case AVCOL_PRI_SMPTE240M: avio_wb16(pb, 6); break; case AVCOL_PRI_BT470BG: avio_wb16(pb, 5); break; default: avio_wb16(pb, 2); } - switch (track->enc->color_trc) { + switch (track->par->color_trc) { case AVCOL_TRC_BT709: avio_wb16(pb, 1); break; case AVCOL_TRC_SMPTE170M: avio_wb16(pb, 1); break; // remapped case AVCOL_TRC_SMPTE240M: avio_wb16(pb, 7); break; default: avio_wb16(pb, 2); } - switch (track->enc->colorspace) { + switch (track->par->color_space) { case AVCOL_SPC_BT709: avio_wb16(pb, 1); break; case AVCOL_SPC_BT470BG: case AVCOL_SPC_SMPTE170M: avio_wb16(pb, 6); break; @@ -1630,7 +1635,7 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack *track) } if (track->mode == MODE_MP4) { - int full_range = track->enc->color_range == AVCOL_RANGE_JPEG; + int full_range = track->par->color_range == AVCOL_RANGE_JPEG; avio_w8(pb, full_range << 7); return 19; } else { @@ -1641,26 +1646,26 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack *track) static void find_compressor(char * compressor_name, int len, MOVTrack *track) { AVDictionaryEntry *encoder; - int xdcam_res = (track->enc->width == 1280 && track->enc->height == 720) - || (track->enc->width == 1440 && track->enc->height == 1080) - || (track->enc->width == 1920 && track->enc->height == 1080); + int xdcam_res = (track->par->width == 1280 && track->par->height == 720) + || (track->par->width == 1440 && track->par->height == 1080) + || (track->par->width == 1920 && track->par->height == 1080); if (track->mode == MODE_MOV && (encoder = av_dict_get(track->st->metadata, "encoder", NULL, 0))) { av_strlcpy(compressor_name, encoder->value, 32); - } else if (track->enc->codec_id == AV_CODEC_ID_MPEG2VIDEO && xdcam_res) { - int interlaced = track->enc->field_order > AV_FIELD_PROGRESSIVE; + } else if (track->par->codec_id == AV_CODEC_ID_MPEG2VIDEO && xdcam_res) { + int interlaced = track->par->field_order > AV_FIELD_PROGRESSIVE; AVStream *st = track->st; int rate = av_q2d(find_fps(NULL, st)); av_strlcatf(compressor_name, len, "XDCAM"); - if (track->enc->pix_fmt == AV_PIX_FMT_YUV422P) { + if (track->par->format == AV_PIX_FMT_YUV422P) { av_strlcatf(compressor_name, len, " HD422"); - } else if(track->enc->width == 1440) { + } else if(track->par->width == 1440) { av_strlcatf(compressor_name, len, " HD"); } else av_strlcatf(compressor_name, len, " EX"); - av_strlcatf(compressor_name, len, " %d%c", track->enc->height, interlaced ? 'i' : 'p'); + av_strlcatf(compressor_name, len, " %d%c", track->par->height, interlaced ? 'i' : 'p'); av_strlcatf(compressor_name, len, "%d", rate * (interlaced + 1)); } @@ -1686,7 +1691,7 @@ static int mov_write_video_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *tr avio_wb16(pb, 0); /* Codec stream revision (=0) */ if (track->mode == MODE_MOV) { ffio_wfourcc(pb, "FFMP"); /* Vendor */ - if (track->enc->codec_id == AV_CODEC_ID_RAWVIDEO) { + if (track->par->codec_id == AV_CODEC_ID_RAWVIDEO) { avio_wb32(pb, 0); /* Temporal Quality */ avio_wb32(pb, 0x400); /* Spatial Quality = lossless*/ } else { @@ -1698,7 +1703,7 @@ static int mov_write_video_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *tr avio_wb32(pb, 0); /* Reserved */ avio_wb32(pb, 0); /* Reserved */ } - avio_wb16(pb, track->enc->width); /* Video width */ + avio_wb16(pb, track->par->width); /* Video width */ avio_wb16(pb, track->height); /* Video height */ avio_wb32(pb, 0x00480000); /* Horizontal resolution 72dpi */ avio_wb32(pb, 0x00480000); /* Vertical resolution 72dpi */ @@ -1710,14 +1715,14 @@ static int mov_write_video_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *tr avio_w8(pb, strlen(compressor_name)); avio_write(pb, compressor_name, 31); - if (track->mode == MODE_MOV && track->enc->bits_per_coded_sample) - avio_wb16(pb, track->enc->bits_per_coded_sample | - (track->enc->pix_fmt == AV_PIX_FMT_GRAY8 ? 0x20 : 0)); + if (track->mode == MODE_MOV && track->par->bits_per_coded_sample) + avio_wb16(pb, track->par->bits_per_coded_sample | + (track->par->format == AV_PIX_FMT_GRAY8 ? 0x20 : 0)); else avio_wb16(pb, 0x18); /* Reserved */ - if (track->mode == MODE_MOV && track->enc->pix_fmt == AV_PIX_FMT_PAL8) { - int pal_size = 1 << track->enc->bits_per_coded_sample; + if (track->mode == MODE_MOV && track->par->format == AV_PIX_FMT_PAL8) { + int pal_size = 1 << track->par->bits_per_coded_sample; int i; avio_wb16(pb, 0); /* Color table ID */ avio_wb32(pb, 0); /* Color table seed */ @@ -1738,38 +1743,48 @@ static int mov_write_video_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *tr if (track->tag == MKTAG('m','p','4','v')) mov_write_esds_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_H263) + else if (track->par->codec_id == AV_CODEC_ID_H263) mov_write_d263_tag(pb); - else if (track->enc->codec_id == AV_CODEC_ID_AVUI || - track->enc->codec_id == AV_CODEC_ID_SVQ3) { + else if (track->par->codec_id == AV_CODEC_ID_AVUI || + track->par->codec_id == AV_CODEC_ID_SVQ3) { mov_write_extradata_tag(pb, track); avio_wb32(pb, 0); - } else if (track->enc->codec_id == AV_CODEC_ID_DNXHD) { + } else if (track->par->codec_id == AV_CODEC_ID_DNXHD) { mov_write_avid_tag(pb, track); avid = 1; - } else if (track->enc->codec_id == AV_CODEC_ID_HEVC) + } else if (track->par->codec_id == AV_CODEC_ID_HEVC) mov_write_hvcc_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_H264 && !TAG_IS_AVCI(track->tag)) { + else if (track->par->codec_id == AV_CODEC_ID_H264 && !TAG_IS_AVCI(track->tag)) { mov_write_avcc_tag(pb, track); if (track->mode == MODE_IPOD) mov_write_uuid_tag_ipod(pb); - } else if (track->enc->codec_id == AV_CODEC_ID_VC1 && track->vos_len > 0) + } else if (track->par->codec_id == AV_CODEC_ID_VC1 && track->vos_len > 0) mov_write_dvc1_tag(pb, track); - else if (track->enc->codec_id == AV_CODEC_ID_VP6F || - track->enc->codec_id == AV_CODEC_ID_VP6A) { + else if (track->par->codec_id == AV_CODEC_ID_VP6F || + track->par->codec_id == AV_CODEC_ID_VP6A) { /* Don't write any potential extradata here - the cropping * is signalled via the normal width/height fields. */ - } else if (track->enc->codec_id == AV_CODEC_ID_R10K) { - if (track->enc->codec_tag == MKTAG('R','1','0','k')) + } else if (track->par->codec_id == AV_CODEC_ID_R10K) { + if (track->par->codec_tag == MKTAG('R','1','0','k')) mov_write_dpxe_tag(pb, track); } else if (track->vos_len > 0) mov_write_glbl_tag(pb, track); - if (track->enc->codec_id != AV_CODEC_ID_H264 && - track->enc->codec_id != AV_CODEC_ID_MPEG4 && - track->enc->codec_id != AV_CODEC_ID_DNXHD) - if (track->enc->field_order != AV_FIELD_UNKNOWN) - mov_write_fiel_tag(pb, track); + if (track->par->codec_id != AV_CODEC_ID_H264 && + track->par->codec_id != AV_CODEC_ID_MPEG4 && + track->par->codec_id != AV_CODEC_ID_DNXHD) { + int field_order = track->par->field_order; + +#if FF_API_LAVF_AVCTX + FF_DISABLE_DEPRECATION_WARNINGS + if (field_order != track->st->codec->field_order && track->st->codec->field_order != AV_FIELD_UNKNOWN) + field_order = track->st->codec->field_order; + FF_ENABLE_DEPRECATION_WARNINGS +#endif + + if (field_order != AV_FIELD_UNKNOWN) + mov_write_fiel_tag(pb, track, field_order); + } if (mov->flags & FF_MOV_FLAG_WRITE_GAMA) { if (track->mode == MODE_MOV) @@ -1784,8 +1799,8 @@ static int mov_write_video_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *tr av_log(mov->fc, AV_LOG_WARNING, "Not writing 'colr' atom. Format is not MOV or MP4.\n"); } - if (track->enc->sample_aspect_ratio.den && track->enc->sample_aspect_ratio.num && - track->enc->sample_aspect_ratio.den != track->enc->sample_aspect_ratio.num) { + if (track->par->sample_aspect_ratio.den && track->par->sample_aspect_ratio.num && + track->par->sample_aspect_ratio.den != track->par->sample_aspect_ratio.num) { mov_write_pasp_tag(pb, track); } @@ -1844,10 +1859,25 @@ static int mov_write_tmcd_tag(AVIOContext *pb, MOVTrack *track) { int64_t pos = avio_tell(pb); #if 1 - int frame_duration = av_rescale(track->timescale, track->enc->time_base.num, track->enc->time_base.den); - int nb_frames = ROUNDED_DIV(track->enc->time_base.den, track->enc->time_base.num); + int frame_duration; + int nb_frames; AVDictionaryEntry *t = NULL; + if (!track->st->avg_frame_rate.num || !track->st->avg_frame_rate.den) { +#if FF_API_LAVF_AVCTX + FF_DISABLE_DEPRECATION_WARNINGS + frame_duration = av_rescale(track->timescale, track->st->codec->time_base.num, track->st->codec->time_base.den); + nb_frames = ROUNDED_DIV(track->st->codec->time_base.den, track->st->codec->time_base.num); + FF_ENABLE_DEPRECATION_WARNINGS +#else + av_log(NULL, AV_LOG_ERROR, "avg_frame_rate not set for tmcd track.\n"); + return AVERROR(EINVAL); +#endif + } else { + frame_duration = av_rescale(track->timescale, track->st->avg_frame_rate.num, track->st->avg_frame_rate.den); + nb_frames = ROUNDED_DIV(track->st->avg_frame_rate.den, track->st->avg_frame_rate.num); + } + if (nb_frames > 255) { av_log(NULL, AV_LOG_ERROR, "fps %d is too large\n", nb_frames); return AVERROR(EINVAL); @@ -1877,28 +1907,28 @@ static int mov_write_tmcd_tag(AVIOContext *pb, MOVTrack *track) ffio_wfourcc(pb, "tmcd"); /* Data format */ avio_wb32(pb, 0); /* Reserved */ avio_wb32(pb, 1); /* Data reference index */ - if (track->enc->extradata_size) - avio_write(pb, track->enc->extradata, track->enc->extradata_size); + if (track->par->extradata_size) + avio_write(pb, track->par->extradata, track->par->extradata_size); #endif return update_size(pb, pos); } -static int mov_write_stsd_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track) +static int mov_write_stsd_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track) { int64_t pos = avio_tell(pb); avio_wb32(pb, 0); /* size */ ffio_wfourcc(pb, "stsd"); avio_wb32(pb, 0); /* version & flags */ avio_wb32(pb, 1); /* entry count */ - if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) + if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) mov_write_video_tag(pb, mov, track); - else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) - mov_write_audio_tag(pb, mov, track); - else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) + else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) + mov_write_audio_tag(s, pb, mov, track); + else if (track->par->codec_type == AVMEDIA_TYPE_SUBTITLE) mov_write_subtitle_tag(pb, track); - else if (track->enc->codec_tag == MKTAG('r','t','p',' ')) + else if (track->par->codec_tag == MKTAG('r','t','p',' ')) mov_write_rtp_tag(pb, track); - else if (track->enc->codec_tag == MKTAG('t','m','c','d')) + else if (track->par->codec_tag == MKTAG('t','m','c','d')) mov_write_tmcd_tag(pb, track); return update_size(pb, pos); } @@ -1946,7 +1976,7 @@ static int mov_write_stts_tag(AVIOContext *pb, MOVTrack *track) uint32_t atom_size; int i; - if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO && !track->audio_vbr) { + if (track->par->codec_type == AVMEDIA_TYPE_AUDIO && !track->audio_vbr) { stts_entries = av_malloc(sizeof(*stts_entries)); /* one entry */ if (!stts_entries) return AVERROR(ENOMEM); @@ -1999,22 +2029,22 @@ static int mov_write_dref_tag(AVIOContext *pb) return 28; } -static int mov_write_stbl_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track) +static int mov_write_stbl_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track) { int64_t pos = avio_tell(pb); int ret; avio_wb32(pb, 0); /* size */ ffio_wfourcc(pb, "stbl"); - mov_write_stsd_tag(pb, mov, track); + mov_write_stsd_tag(s, pb, mov, track); mov_write_stts_tag(pb, track); - if ((track->enc->codec_type == AVMEDIA_TYPE_VIDEO || - track->enc->codec_tag == MKTAG('r','t','p',' ')) && + if ((track->par->codec_type == AVMEDIA_TYPE_VIDEO || + track->par->codec_tag == MKTAG('r','t','p',' ')) && track->has_keyframes && track->has_keyframes < track->entry) mov_write_stss_tag(pb, track, MOV_SYNC_SAMPLE); if (track->mode == MODE_MOV && track->flags & MOV_TRACK_STPS) mov_write_stss_tag(pb, track, MOV_PARTIAL_SYNC_SAMPLE); - if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO && + if (track->par->codec_type == AVMEDIA_TYPE_VIDEO && track->flags & MOV_TRACK_CTTS && track->entry) { if ((ret = mov_write_ctts_tag(pb, track)) < 0) @@ -2104,7 +2134,7 @@ static int mov_write_gmhd_tag(AVIOContext *pb, MOVTrack *track) avio_wb16(pb, 0x0000); } - if (track->enc->codec_tag == MKTAG('t','m','c','d')) { + if (track->par->codec_tag == MKTAG('t','m','c','d')) { int64_t tmcd_pos = avio_tell(pb); avio_wb32(pb, 0); /* size */ ffio_wfourcc(pb, "tmcd"); @@ -2139,7 +2169,7 @@ static int is_clcp_track(MOVTrack *track) track->tag == MKTAG('c','6','0','8'); } -static int mov_write_hdlr_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_hdlr_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track) { const char *hdlr, *descr = NULL, *hdlr_type = NULL; int64_t pos = avio_tell(pb); @@ -2150,13 +2180,13 @@ static int mov_write_hdlr_tag(AVIOContext *pb, MOVTrack *track) if (track) { hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0"; - if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) { hdlr_type = "vide"; descr = "VideoHandler"; - } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) { + } else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) { hdlr_type = "soun"; descr = "SoundHandler"; - } else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) { + } else if (track->par->codec_type == AVMEDIA_TYPE_SUBTITLE) { if (is_clcp_track(track)) { hdlr_type = "clcp"; descr = "ClosedCaptionHandler"; @@ -2170,20 +2200,20 @@ static int mov_write_hdlr_tag(AVIOContext *pb, MOVTrack *track) } descr = "SubtitleHandler"; } - } else if (track->enc->codec_tag == MKTAG('r','t','p',' ')) { + } else if (track->par->codec_tag == MKTAG('r','t','p',' ')) { hdlr_type = "hint"; descr = "HintHandler"; - } else if (track->enc->codec_tag == MKTAG('t','m','c','d')) { + } else if (track->par->codec_tag == MKTAG('t','m','c','d')) { hdlr_type = "tmcd"; descr = "TimeCodeHandler"; } else { char tag_buf[32]; av_get_codec_tag_string(tag_buf, sizeof(tag_buf), - track->enc->codec_tag); + track->par->codec_tag); - av_log(track->enc, AV_LOG_WARNING, + av_log(s, AV_LOG_WARNING, "Unknown hldr_type for %s / 0x%04X, writing dummy values\n", - tag_buf, track->enc->codec_tag); + tag_buf, track->par->codec_tag); } if (track->st) { // hdlr.name is used by some players to identify the content title @@ -2227,18 +2257,18 @@ static int mov_write_hmhd_tag(AVIOContext *pb) return 28; } -static int mov_write_minf_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track) +static int mov_write_minf_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track) { int64_t pos = avio_tell(pb); int ret; avio_wb32(pb, 0); /* size */ ffio_wfourcc(pb, "minf"); - if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) + if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) mov_write_vmhd_tag(pb); - else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) + else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) mov_write_smhd_tag(pb); - else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) { + else if (track->par->codec_type == AVMEDIA_TYPE_SUBTITLE) { if (track->tag == MKTAG('t','e','x','t') || is_clcp_track(track)) { mov_write_gmhd_tag(pb, track); } else { @@ -2253,9 +2283,9 @@ static int mov_write_minf_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *tra mov_write_gmhd_tag(pb, track); } if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */ - mov_write_hdlr_tag(pb, NULL); + mov_write_hdlr_tag(s, pb, NULL); mov_write_dinf_tag(pb); - if ((ret = mov_write_stbl_tag(pb, mov, track)) < 0) + if ((ret = mov_write_stbl_tag(s, pb, mov, track)) < 0) return ret; return update_size(pb, pos); } @@ -2299,8 +2329,8 @@ static int mov_write_mdhd_tag(AVIOContext *pb, MOVMuxContext *mov, return 32; } -static int mov_write_mdia_tag(AVIOContext *pb, MOVMuxContext *mov, - MOVTrack *track) +static int mov_write_mdia_tag(AVFormatContext *s, AVIOContext *pb, + MOVMuxContext *mov, MOVTrack *track) { int64_t pos = avio_tell(pb); int ret; @@ -2308,8 +2338,8 @@ static int mov_write_mdia_tag(AVIOContext *pb, MOVMuxContext *mov, avio_wb32(pb, 0); /* size */ ffio_wfourcc(pb, "mdia"); mov_write_mdhd_tag(pb, mov, track); - mov_write_hdlr_tag(pb, track); - if ((ret = mov_write_minf_tag(pb, mov, track)) < 0) + mov_write_hdlr_tag(s, pb, track); + if ((ret = mov_write_minf_tag(s, pb, mov, track)) < 0) return ret; return update_size(pb, pos); } @@ -2349,7 +2379,7 @@ static int mov_write_tkhd_tag(AVIOContext *pb, MOVMuxContext *mov, if (mov->per_stream_grouping) group = st->index; else - group = st->codec->codec_type; + group = st->codecpar->codec_type; display_matrix = (uint32_t*)av_stream_get_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, &display_matrix_size); @@ -2388,7 +2418,7 @@ static int mov_write_tkhd_tag(AVIOContext *pb, MOVMuxContext *mov, avio_wb16(pb, 0); /* layer */ avio_wb16(pb, group); /* alternate group) */ /* Volume, only for audio */ - if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) + if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) avio_wb16(pb, 0x0100); else avio_wb16(pb, 0); @@ -2403,28 +2433,28 @@ static int mov_write_tkhd_tag(AVIOContext *pb, MOVMuxContext *mov, for (i = 0; i < 9; i++) avio_wb32(pb, display_matrix[i]); } else if (rotation == 90) { - write_matrix(pb, 0, 1, -1, 0, track->enc->height, 0); + write_matrix(pb, 0, 1, -1, 0, track->par->height, 0); } else if (rotation == 180) { - write_matrix(pb, -1, 0, 0, -1, track->enc->width, track->enc->height); + write_matrix(pb, -1, 0, 0, -1, track->par->width, track->par->height); } else if (rotation == 270) { - write_matrix(pb, 0, -1, 1, 0, 0, track->enc->width); + write_matrix(pb, 0, -1, 1, 0, 0, track->par->width); } else { write_matrix(pb, 1, 0, 0, 1, 0, 0); } /* Track width and height, for visual only */ - if (st && (track->enc->codec_type == AVMEDIA_TYPE_VIDEO || - track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE)) { + if (st && (track->par->codec_type == AVMEDIA_TYPE_VIDEO || + track->par->codec_type == AVMEDIA_TYPE_SUBTITLE)) { if (track->mode == MODE_MOV) { - avio_wb32(pb, track->enc->width << 16); + avio_wb32(pb, track->par->width << 16); avio_wb32(pb, track->height << 16); } else { int64_t track_width_1616 = av_rescale(st->sample_aspect_ratio.num, - track->enc->width * 0x10000LL, + track->par->width * 0x10000LL, st->sample_aspect_ratio.den); if (!track_width_1616 || - track->height != track->enc->height || + track->height != track->par->height || track_width_1616 > UINT32_MAX) - track_width_1616 = track->enc->width * 0x10000U; + track_width_1616 = track->par->width * 0x10000U; avio_wb32(pb, track_width_1616); avio_wb32(pb, track->height * 0x10000U); } @@ -2437,8 +2467,8 @@ static int mov_write_tkhd_tag(AVIOContext *pb, MOVMuxContext *mov, static int mov_write_tapt_tag(AVIOContext *pb, MOVTrack *track) { - int32_t width = av_rescale(track->enc->sample_aspect_ratio.num, track->enc->width, - track->enc->sample_aspect_ratio.den); + int32_t width = av_rescale(track->par->sample_aspect_ratio.num, track->par->width, + track->par->sample_aspect_ratio.den); int64_t pos = avio_tell(pb); @@ -2449,19 +2479,19 @@ static int mov_write_tapt_tag(AVIOContext *pb, MOVTrack *track) ffio_wfourcc(pb, "clef"); avio_wb32(pb, 0); avio_wb32(pb, width << 16); - avio_wb32(pb, track->enc->height << 16); + avio_wb32(pb, track->par->height << 16); avio_wb32(pb, 20); ffio_wfourcc(pb, "prof"); avio_wb32(pb, 0); avio_wb32(pb, width << 16); - avio_wb32(pb, track->enc->height << 16); + avio_wb32(pb, track->par->height << 16); avio_wb32(pb, 20); ffio_wfourcc(pb, "enof"); avio_wb32(pb, 0); - avio_wb32(pb, track->enc->width << 16); - avio_wb32(pb, track->enc->height << 16); + avio_wb32(pb, track->par->width << 16); + avio_wb32(pb, track->par->height << 16); return update_size(pb, pos); } @@ -2643,7 +2673,7 @@ static int mov_write_track_udta_tag(AVIOContext *pb, MOVMuxContext *mov, return 0; } -static int mov_write_trak_tag(AVIOContext *pb, MOVMuxContext *mov, +static int mov_write_trak_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track, AVStream *st) { int64_t pos = avio_tell(pb); @@ -2673,14 +2703,14 @@ static int mov_write_trak_tag(AVIOContext *pb, MOVMuxContext *mov, if (track->tref_tag) mov_write_tref_tag(pb, track); - if ((ret = mov_write_mdia_tag(pb, mov, track)) < 0) + if ((ret = mov_write_mdia_tag(s, pb, mov, track)) < 0) return ret; if (track->mode == MODE_PSP) mov_write_uuid_tag_psp(pb, track); // PSP Movies require this uuid box if (track->tag == MKTAG('r','t','p',' ')) mov_write_udta_sdp(pb, track); if (track->mode == MODE_MOV) { - if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) { double sample_aspect_ratio = av_q2d(st->sample_aspect_ratio); if (st->sample_aspect_ratio.num && 1.0 != sample_aspect_ratio) { mov_write_tapt_tag(pb, track); @@ -2704,8 +2734,8 @@ static int mov_write_iods_tag(AVIOContext *pb, MOVMuxContext *mov) int video_profile = mov->iods_video_profile; for (i = 0; i < mov->nb_streams; i++) { if (mov->tracks[i].entry > 0 || mov->flags & FF_MOV_FLAG_EMPTY_MOOV) { - has_audio |= mov->tracks[i].enc->codec_type == AVMEDIA_TYPE_AUDIO; - has_video |= mov->tracks[i].enc->codec_type == AVMEDIA_TYPE_VIDEO; + has_audio |= mov->tracks[i].par->codec_type == AVMEDIA_TYPE_AUDIO; + has_video |= mov->tracks[i].par->codec_type == AVMEDIA_TYPE_VIDEO; } } if (audio_profile < 0) @@ -3254,7 +3284,7 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov, if (track->tag == MKTAG('r','t','p',' ')) { track->tref_tag = MKTAG('h','i','n','t'); track->tref_id = mov->tracks[track->src_track].track_id; - } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) { + } else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) { int * fallback, size; fallback = (int*)av_stream_get_side_data(track->st, AV_PKT_DATA_FALLBACK_TRACK, @@ -3284,7 +3314,7 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov, mov_write_iods_tag(pb, mov); for (i = 0; i < mov->nb_streams; i++) { if (mov->tracks[i].entry > 0 || mov->flags & FF_MOV_FLAG_FRAGMENT) { - int ret = mov_write_trak_tag(pb, mov, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL); + int ret = mov_write_trak_tag(s, pb, mov, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL); if (ret < 0) return ret; } @@ -3349,41 +3379,41 @@ static int mov_write_isml_manifest(AVIOContext *pb, MOVMuxContext *mov) * here yet */ int track_id = i + 1; - if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) { type = "video"; - } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) { + } else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) { type = "audio"; } else { continue; } avio_printf(pb, "<%s systemBitrate=\"%"PRId64"\">\n", type, - (int64_t)track->enc->bit_rate); - param_write_int(pb, "systemBitrate", track->enc->bit_rate); + (int64_t)track->par->bit_rate); + param_write_int(pb, "systemBitrate", track->par->bit_rate); param_write_int(pb, "trackID", track_id); - if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) { - if (track->enc->codec_id == AV_CODEC_ID_H264) { + if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) { + if (track->par->codec_id == AV_CODEC_ID_H264) { uint8_t *ptr; - int size = track->enc->extradata_size; - if (!ff_avc_write_annexb_extradata(track->enc->extradata, &ptr, + int size = track->par->extradata_size; + if (!ff_avc_write_annexb_extradata(track->par->extradata, &ptr, &size)) { param_write_hex(pb, "CodecPrivateData", - ptr ? ptr : track->enc->extradata, + ptr ? ptr : track->par->extradata, size); av_free(ptr); } param_write_string(pb, "FourCC", "H264"); - } else if (track->enc->codec_id == AV_CODEC_ID_VC1) { + } else if (track->par->codec_id == AV_CODEC_ID_VC1) { param_write_string(pb, "FourCC", "WVC1"); - param_write_hex(pb, "CodecPrivateData", track->enc->extradata, - track->enc->extradata_size); + param_write_hex(pb, "CodecPrivateData", track->par->extradata, + track->par->extradata_size); } - param_write_int(pb, "MaxWidth", track->enc->width); - param_write_int(pb, "MaxHeight", track->enc->height); - param_write_int(pb, "DisplayWidth", track->enc->width); - param_write_int(pb, "DisplayHeight", track->enc->height); + param_write_int(pb, "MaxWidth", track->par->width); + param_write_int(pb, "MaxHeight", track->par->height); + param_write_int(pb, "DisplayWidth", track->par->width); + param_write_int(pb, "DisplayHeight", track->par->height); } else { - if (track->enc->codec_id == AV_CODEC_ID_AAC) { - switch (track->enc->profile) + if (track->par->codec_id == AV_CODEC_ID_AAC) { + switch (track->par->profile) { case FF_PROFILE_AAC_HE_V2: param_write_string(pb, "FourCC", "AACP"); @@ -3394,18 +3424,18 @@ static int mov_write_isml_manifest(AVIOContext *pb, MOVMuxContext *mov) default: param_write_string(pb, "FourCC", "AACL"); } - } else if (track->enc->codec_id == AV_CODEC_ID_WMAPRO) { + } else if (track->par->codec_id == AV_CODEC_ID_WMAPRO) { param_write_string(pb, "FourCC", "WMAP"); } - param_write_hex(pb, "CodecPrivateData", track->enc->extradata, - track->enc->extradata_size); + param_write_hex(pb, "CodecPrivateData", track->par->extradata, + track->par->extradata_size); param_write_int(pb, "AudioTag", ff_codec_get_tag(ff_codec_wav_tags, - track->enc->codec_id)); - param_write_int(pb, "Channels", track->enc->channels); - param_write_int(pb, "SamplingRate", track->enc->sample_rate); + track->par->codec_id)); + param_write_int(pb, "Channels", track->par->channels); + param_write_int(pb, "SamplingRate", track->par->sample_rate); param_write_int(pb, "BitsPerSample", 16); - param_write_int(pb, "PacketSize", track->enc->block_align ? - track->enc->block_align : 4); + param_write_int(pb, "PacketSize", track->par->block_align ? + track->par->block_align : 4); } avio_printf(pb, "\n", type); } @@ -3482,7 +3512,7 @@ static int mov_write_tfhd_tag(AVIOContext *pb, MOVMuxContext *mov, track->default_sample_flags = get_sample_flags(track, &track->cluster[1]); else track->default_sample_flags = - track->enc->codec_type == AVMEDIA_TYPE_VIDEO ? + track->par->codec_type == AVMEDIA_TYPE_VIDEO ? (MOV_FRAG_SAMPLE_FLAG_DEPENDS_YES | MOV_FRAG_SAMPLE_FLAG_IS_NON_SYNC) : MOV_FRAG_SAMPLE_FLAG_DEPENDS_NO; avio_wb32(pb, track->default_sample_flags); @@ -3917,9 +3947,9 @@ static int mov_write_ftyp_tag(AVIOContext *pb, AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) has_video = 1; - if (st->codec->codec_id == AV_CODEC_ID_H264) + if (st->codecpar->codec_id == AV_CODEC_ID_H264) has_h264 = 1; } @@ -3985,13 +4015,13 @@ static int mov_write_ftyp_tag(AVIOContext *pb, AVFormatContext *s) static void mov_write_uuidprof_tag(AVIOContext *pb, AVFormatContext *s) { AVStream *video_st = s->streams[0]; - AVCodecContext *video_codec = s->streams[0]->codec; - AVCodecContext *audio_codec = s->streams[1]->codec; - int audio_rate = audio_codec->sample_rate; + AVCodecParameters *video_par = s->streams[0]->codecpar; + AVCodecParameters *audio_par = s->streams[1]->codecpar; + int audio_rate = audio_par->sample_rate; // TODO: should be avg_frame_rate int frame_rate = ((video_st->time_base.den) * (0x10000)) / (video_st->time_base.num); - int audio_kbitrate = audio_codec->bit_rate / 1000; - int video_kbitrate = FFMIN(video_codec->bit_rate / 1000, 800 - audio_kbitrate); + int audio_kbitrate = audio_par->bit_rate / 1000; + int video_kbitrate = FFMIN(video_par->bit_rate / 1000, 800 - audio_kbitrate); avio_wb32(pb, 0x94); /* size */ ffio_wfourcc(pb, "uuid"); @@ -4020,13 +4050,13 @@ static void mov_write_uuidprof_tag(AVIOContext *pb, AVFormatContext *s) avio_wb32(pb, audio_kbitrate); avio_wb32(pb, audio_kbitrate); avio_wb32(pb, audio_rate); - avio_wb32(pb, audio_codec->channels); + avio_wb32(pb, audio_par->channels); avio_wb32(pb, 0x34); /* size */ ffio_wfourcc(pb, "VPRF"); /* video */ avio_wb32(pb, 0x0); avio_wb32(pb, 0x1); /* TrackID */ - if (video_codec->codec_id == AV_CODEC_ID_H264) { + if (video_par->codec_id == AV_CODEC_ID_H264) { ffio_wfourcc(pb, "avc1"); avio_wb16(pb, 0x014D); avio_wb16(pb, 0x0015); @@ -4040,8 +4070,8 @@ static void mov_write_uuidprof_tag(AVIOContext *pb, AVFormatContext *s) avio_wb32(pb, video_kbitrate); avio_wb32(pb, frame_rate); avio_wb32(pb, frame_rate); - avio_wb16(pb, video_codec->width); - avio_wb16(pb, video_codec->height); + avio_wb16(pb, video_par->width); + avio_wb16(pb, video_par->height); avio_wb32(pb, 0x010001); /* ? */ } @@ -4055,9 +4085,9 @@ static int mov_write_identification(AVIOContext *pb, AVFormatContext *s) int video_streams_nb = 0, audio_streams_nb = 0, other_streams_nb = 0; for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) video_streams_nb++; - else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) + else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) audio_streams_nb++; else other_streams_nb++; @@ -4371,7 +4401,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) MOVMuxContext *mov = s->priv_data; AVIOContext *pb = s->pb; MOVTrack *trk = &mov->tracks[pkt->stream_index]; - AVCodecContext *enc = trk->enc; + AVCodecParameters *par = trk->par; unsigned int samples_in_chunk = 0; int size = pkt->size, ret = 0; uint8_t *reformatted_data = NULL; @@ -4415,7 +4445,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) } } - if (enc->codec_id == AV_CODEC_ID_AMR_NB) { + if (par->codec_id == AV_CODEC_ID_AMR_NB) { /* We must find out how many AMR blocks there are in one packet */ static const uint16_t packed_size[16] = {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1}; @@ -4429,28 +4459,28 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) av_log(s, AV_LOG_ERROR, "fatal error, input is not a single packet, implement a AVParser for it\n"); return -1; } - } else if (enc->codec_id == AV_CODEC_ID_ADPCM_MS || - enc->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) { - samples_in_chunk = enc->frame_size; + } else if (par->codec_id == AV_CODEC_ID_ADPCM_MS || + par->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV) { + samples_in_chunk = trk->par->frame_size; } else if (trk->sample_size) samples_in_chunk = size / trk->sample_size; else samples_in_chunk = 1; /* copy extradata if it exists */ - if (trk->vos_len == 0 && enc->extradata_size > 0 && + if (trk->vos_len == 0 && par->extradata_size > 0 && !TAG_IS_AVCI(trk->tag) && - (enc->codec_id != AV_CODEC_ID_DNXHD)) { - trk->vos_len = enc->extradata_size; + (par->codec_id != AV_CODEC_ID_DNXHD)) { + trk->vos_len = par->extradata_size; trk->vos_data = av_malloc(trk->vos_len); if (!trk->vos_data) { ret = AVERROR(ENOMEM); goto err; } - memcpy(trk->vos_data, enc->extradata, trk->vos_len); + memcpy(trk->vos_data, par->extradata, trk->vos_len); } - if (enc->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 && + if (par->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 && (AV_RB16(pkt->data) & 0xfff0) == 0xfff0) { if (!s->streams[pkt->stream_index]->nb_frames) { av_log(s, AV_LOG_ERROR, "Malformed AAC bitstream detected: " @@ -4460,7 +4490,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) } av_log(s, AV_LOG_WARNING, "aac bitstream error\n"); } - if (enc->codec_id == AV_CODEC_ID_H264 && trk->vos_len > 0 && *(uint8_t *)trk->vos_data != 1 && !TAG_IS_AVCI(trk->tag)) { + if (par->codec_id == AV_CODEC_ID_H264 && trk->vos_len > 0 && *(uint8_t *)trk->vos_data != 1 && !TAG_IS_AVCI(trk->tag)) { /* from x264 or from bytestream h264 */ /* nal reformating needed */ if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams) { @@ -4478,7 +4508,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) size = ff_avc_parse_nal_units(pb, pkt->data, pkt->size); } } - } else if (enc->codec_id == AV_CODEC_ID_HEVC && trk->vos_len > 6 && + } else if (par->codec_id == AV_CODEC_ID_HEVC && trk->vos_len > 6 && (AV_RB24(trk->vos_data) == 1 || AV_RB32(trk->vos_data) == 1)) { /* extradata is Annex B, assume the bitstream is too and convert it */ if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams) { @@ -4488,7 +4518,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) size = ff_hevc_annexb2mp4(pb, pkt->data, pkt->size, 0, NULL); } #if CONFIG_AC3_PARSER - } else if (enc->codec_id == AV_CODEC_ID_EAC3) { + } else if (par->codec_id == AV_CODEC_ID_EAC3) { size = handle_eac3(mov, pkt, trk); if (size < 0) return size; @@ -4498,8 +4528,8 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) #endif } else { if (mov->encryption_scheme == MOV_ENC_CENC_AES_CTR) { - if (enc->codec_id == AV_CODEC_ID_H264 && enc->extradata_size > 4) { - int nal_size_length = (enc->extradata[4] & 0x3) + 1; + if (par->codec_id == AV_CODEC_ID_H264 && par->extradata_size > 4) { + int nal_size_length = (par->extradata[4] & 0x3) + 1; ret = ff_mov_cenc_avc_write_nal_units(s, &trk->cenc, nal_size_length, pb, pkt->data, size); } else { ret = ff_mov_cenc_write_packet(&trk->cenc, pb, pkt->data, size); @@ -4513,8 +4543,8 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) } } - if ((enc->codec_id == AV_CODEC_ID_DNXHD || - enc->codec_id == AV_CODEC_ID_AC3) && !trk->vos_len) { + if ((par->codec_id == AV_CODEC_ID_DNXHD || + par->codec_id == AV_CODEC_ID_AC3) && !trk->vos_len) { /* copy frame to create needed atoms */ trk->vos_len = size; trk->vos_data = av_malloc(size); @@ -4618,10 +4648,10 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) trk->cluster[trk->entry].cts + pkt->duration); - if (enc->codec_id == AV_CODEC_ID_VC1) { + if (par->codec_id == AV_CODEC_ID_VC1) { mov_parse_vc1_frame(pkt, trk); } else if (pkt->flags & AV_PKT_FLAG_KEY) { - if (mov->mode == MODE_MOV && enc->codec_id == AV_CODEC_ID_MPEG2VIDEO && + if (mov->mode == MODE_MOV && par->codec_id == AV_CODEC_ID_MPEG2VIDEO && trk->entry > 0) { // force sync sample for the first key frame mov_parse_mpeg2_frame(pkt, &trk->cluster[trk->entry].flags); if (trk->cluster[trk->entry].flags & MOV_PARTIAL_SYNC_SAMPLE) @@ -4651,7 +4681,7 @@ static int mov_write_single_packet(AVFormatContext *s, AVPacket *pkt) { MOVMuxContext *mov = s->priv_data; MOVTrack *trk = &mov->tracks[pkt->stream_index]; - AVCodecContext *enc = trk->enc; + AVCodecParameters *par = trk->par; int64_t frag_duration = 0; int size = pkt->size; @@ -4682,7 +4712,7 @@ static int mov_write_single_packet(AVFormatContext *s, AVPacket *pkt) frag_duration >= mov->max_fragment_duration) || (mov->max_fragment_size && mov->mdat_size + size >= mov->max_fragment_size) || (mov->flags & FF_MOV_FLAG_FRAG_KEYFRAME && - enc->codec_type == AVMEDIA_TYPE_VIDEO && + par->codec_type == AVMEDIA_TYPE_VIDEO && trk->entry && pkt->flags & AV_PKT_FLAG_KEY)) { if (frag_duration >= mov->min_fragment_duration) { // Set the duration of this track to line up with the next @@ -4755,7 +4785,7 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) MOVTrack *trk = &mov->tracks[i]; int ret; - if (trk->enc->codec_id == AV_CODEC_ID_MOV_TEXT && + if (trk->par->codec_id == AV_CODEC_ID_MOV_TEXT && trk->track_duration < pkt->dts && (trk->entry == 0 || !trk->last_sample_is_subtitle_end)) { ret = mov_write_subtitle_end_packet(s, i, trk->track_duration); @@ -4764,26 +4794,26 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) } } - if (trk->mode == MODE_MOV && trk->enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (trk->mode == MODE_MOV && trk->par->codec_type == AVMEDIA_TYPE_VIDEO) { AVPacket *opkt = pkt; int ret; if (trk->is_unaligned_qt_rgb) { - int64_t bpc = trk->enc->bits_per_coded_sample != 15 ? trk->enc->bits_per_coded_sample : 16; - int expected_stride = ((trk->enc->width * bpc + 15) >> 4)*2; - ret = ff_reshuffle_raw_rgb(s, &pkt, trk->enc, expected_stride); + int64_t bpc = trk->par->bits_per_coded_sample != 15 ? trk->par->bits_per_coded_sample : 16; + int expected_stride = ((trk->par->width * bpc + 15) >> 4)*2; + ret = ff_reshuffle_raw_rgb(s, &pkt, trk->par, expected_stride); if (ret < 0) return ret; } else ret = 0; - if (trk->enc->pix_fmt == AV_PIX_FMT_PAL8 && !trk->pal_done) { + if (trk->par->format == AV_PIX_FMT_PAL8 && !trk->pal_done) { int ret2 = ff_get_packet_palette(s, opkt, ret, trk->palette); if (ret2 < 0) return ret2; if (ret2) trk->pal_done++; - } else if (trk->enc->codec_id == AV_CODEC_ID_RAWVIDEO && - (trk->enc->pix_fmt == AV_PIX_FMT_GRAY8 || - trk->enc->pix_fmt == AV_PIX_FMT_MONOBLACK)) { + } else if (trk->par->codec_id == AV_CODEC_ID_RAWVIDEO && + (trk->par->format == AV_PIX_FMT_GRAY8 || + trk->par->format == AV_PIX_FMT_MONOBLACK)) { for (i = 0; i < pkt->size; i++) pkt->data[i] = ~pkt->data[i]; } @@ -4812,16 +4842,16 @@ static int mov_create_chapter_track(AVFormatContext *s, int tracknum) track->mode = mov->mode; track->tag = MKTAG('t','e','x','t'); track->timescale = MOV_TIMESCALE; - track->enc = avcodec_alloc_context3(NULL); - if (!track->enc) + track->par = avcodec_parameters_alloc(); + if (!track->par) return AVERROR(ENOMEM); - track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE; + track->par->codec_type = AVMEDIA_TYPE_SUBTITLE; #if 0 // These properties are required to make QT recognize the chapter track uint8_t chapter_properties[43] = { 0, 0, 0, 0, 0, 0, 0, 1, }; - if (ff_alloc_extradata(track->enc, sizeof(chapter_properties))) + if (ff_alloc_extradata(track->par, sizeof(chapter_properties))) return AVERROR(ENOMEM); - memcpy(track->enc->extradata, chapter_properties, sizeof(chapter_properties)); + memcpy(track->par->extradata, chapter_properties, sizeof(chapter_properties)); #else if (avio_open_dyn_buf(&pb) >= 0) { int size; @@ -4860,8 +4890,8 @@ static int mov_create_chapter_track(AVFormatContext *s, int tracknum) avio_w8(pb, 0x00); // font name length if ((size = avio_close_dyn_buf(pb, &buf)) > 0) { - track->enc->extradata = buf; - track->enc->extradata_size = size; + track->par->extradata = buf; + track->par->extradata_size = size; } else { av_freep(&buf); } @@ -4924,12 +4954,12 @@ static int mov_create_timecode_track(AVFormatContext *s, int index, int src_inde track->st = src_st; /* encode context: tmcd data stream */ - track->enc = avcodec_alloc_context3(NULL); - if (!track->enc) + track->par = avcodec_parameters_alloc(); + if (!track->par) return AVERROR(ENOMEM); - track->enc->codec_type = AVMEDIA_TYPE_DATA; - track->enc->codec_tag = track->tag; - track->enc->time_base = av_inv_q(rate); + track->par->codec_type = AVMEDIA_TYPE_DATA; + track->par->codec_tag = track->tag; + track->st->avg_frame_rate = av_inv_q(rate); /* the tmcd track just contains one packet with the frame number */ pkt.data = av_malloc(pkt.size); @@ -4967,15 +4997,15 @@ static void enable_tracks(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_type <= AVMEDIA_TYPE_UNKNOWN || - st->codec->codec_type >= AVMEDIA_TYPE_NB) + if (st->codecpar->codec_type <= AVMEDIA_TYPE_UNKNOWN || + st->codecpar->codec_type >= AVMEDIA_TYPE_NB) continue; - if (first[st->codec->codec_type] < 0) - first[st->codec->codec_type] = i; + if (first[st->codecpar->codec_type] < 0) + first[st->codecpar->codec_type] = i; if (st->disposition & AV_DISPOSITION_DEFAULT) { mov->tracks[i].flags |= MOV_TRACK_ENABLED; - enabled[st->codec->codec_type]++; + enabled[st->codecpar->codec_type]++; } } @@ -4999,16 +5029,16 @@ static void mov_free(AVFormatContext *s) int i; if (mov->chapter_track) { - if (mov->tracks[mov->chapter_track].enc) - av_freep(&mov->tracks[mov->chapter_track].enc->extradata); - av_freep(&mov->tracks[mov->chapter_track].enc); + if (mov->tracks[mov->chapter_track].par) + av_freep(&mov->tracks[mov->chapter_track].par->extradata); + av_freep(&mov->tracks[mov->chapter_track].par); } for (i = 0; i < mov->nb_streams; i++) { if (mov->tracks[i].tag == MKTAG('r','t','p',' ')) ff_mov_close_hinting(&mov->tracks[i]); else if (mov->tracks[i].tag == MKTAG('t','m','c','d') && mov->nb_meta_tmcd) - av_freep(&mov->tracks[i].enc); + av_freep(&mov->tracks[i].par); av_freep(&mov->tracks[i].cluster); av_freep(&mov->tracks[i].frag_info); @@ -5043,7 +5073,7 @@ static int mov_create_dvd_sub_decoder_specific_info(MOVTrack *track, int i, width = 720, height = 480; int have_palette = 0, have_size = 0; uint32_t palette[16]; - char *cur = st->codec->extradata; + char *cur = st->codecpar->extradata; while (cur && *cur) { if (strncmp("palette:", cur, 8) == 0) { @@ -5080,8 +5110,8 @@ static int mov_create_dvd_sub_decoder_specific_info(MOVTrack *track, } track->vos_len = 16 * 4; } - st->codec->width = width; - st->codec->height = track->height = height; + st->codecpar->width = width; + st->codecpar->height = track->height = height; return 0; } @@ -5187,8 +5217,8 @@ static int mov_write_header(AVFormatContext *s) hint_track = mov->nb_streams; for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO || - st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || + st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { mov->nb_streams++; } } @@ -5200,7 +5230,7 @@ static int mov_write_header(AVFormatContext *s) /* +1 tmcd track for each video stream with a timecode */ for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && (global_tcr || av_dict_get(st->metadata, "timecode", NULL, 0))) mov->nb_meta_tmcd++; } @@ -5209,7 +5239,7 @@ static int mov_write_header(AVFormatContext *s) if (mov->nb_meta_tmcd) { for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_tag == MKTAG('t','m','c','d')) { + if (st->codecpar->codec_tag == MKTAG('t','m','c','d')) { av_log(s, AV_LOG_WARNING, "You requested a copy of the original timecode track " "so timecode metadata are now ignored\n"); mov->nb_meta_tmcd = 0; @@ -5257,7 +5287,7 @@ static int mov_write_header(AVFormatContext *s) AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL,0); track->st = st; - track->enc = st->codec; + track->par = st->codecpar; track->language = ff_mov_iso639_to_lang(lang?lang->value:"und", mov->mode!=MODE_MOV); if (track->language < 0) track->language = 0; @@ -5266,7 +5296,7 @@ static int mov_write_header(AVFormatContext *s) if (!track->tag) { av_log(s, AV_LOG_ERROR, "Could not find tag for codec %s in stream #%d, " "codec not currently supported in container\n", - avcodec_get_name(st->codec->codec_id), i); + avcodec_get_name(st->codecpar->codec_id), i); ret = AVERROR(EINVAL); goto error; } @@ -5276,11 +5306,11 @@ static int mov_write_header(AVFormatContext *s) track->start_dts = AV_NOPTS_VALUE; track->start_cts = AV_NOPTS_VALUE; track->end_pts = AV_NOPTS_VALUE; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (track->tag == MKTAG('m','x','3','p') || track->tag == MKTAG('m','x','3','n') || track->tag == MKTAG('m','x','4','p') || track->tag == MKTAG('m','x','4','n') || track->tag == MKTAG('m','x','5','p') || track->tag == MKTAG('m','x','5','n')) { - if (st->codec->width != 720 || (st->codec->height != 608 && st->codec->height != 512)) { + if (st->codecpar->width != 720 || (st->codecpar->height != 608 && st->codecpar->height != 512)) { av_log(s, AV_LOG_ERROR, "D-10/IMX must use 720x608 or 720x512 video resolution\n"); ret = AVERROR(EINVAL); goto error; @@ -5294,8 +5324,8 @@ static int mov_write_header(AVFormatContext *s) while(track->timescale < 10000) track->timescale *= 2; } - if (st->codec->width > 65535 || st->codec->height > 65535) { - av_log(s, AV_LOG_ERROR, "Resolution %dx%d too large for mov/mp4\n", st->codec->width, st->codec->height); + if (st->codecpar->width > 65535 || st->codecpar->height > 65535) { + av_log(s, AV_LOG_ERROR, "Resolution %dx%d too large for mov/mp4\n", st->codecpar->width, st->codecpar->height); ret = AVERROR(EINVAL); goto error; } @@ -5305,10 +5335,10 @@ static int mov_write_header(AVFormatContext *s) "file may not be playable by quicktime. Specify a shorter timebase\n" "or choose different container.\n"); if (track->mode == MODE_MOV && - track->enc->codec_id == AV_CODEC_ID_RAWVIDEO && + track->par->codec_id == AV_CODEC_ID_RAWVIDEO && track->tag == MKTAG('r','a','w',' ')) { - enum AVPixelFormat pix_fmt = track->enc->pix_fmt; - if (pix_fmt == AV_PIX_FMT_NONE && track->enc->bits_per_coded_sample == 1) + enum AVPixelFormat pix_fmt = track->par->format; + if (pix_fmt == AV_PIX_FMT_NONE && track->par->bits_per_coded_sample == 1) pix_fmt = AV_PIX_FMT_MONOWHITE; track->is_unaligned_qt_rgb = pix_fmt == AV_PIX_FMT_RGB24 || @@ -5318,50 +5348,50 @@ static int mov_write_header(AVFormatContext *s) pix_fmt == AV_PIX_FMT_MONOWHITE || pix_fmt == AV_PIX_FMT_MONOBLACK; } - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - track->timescale = st->codec->sample_rate; - if (!st->codec->frame_size && !av_get_bits_per_sample(st->codec->codec_id)) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + track->timescale = st->codecpar->sample_rate; + if (!st->codecpar->frame_size && !av_get_bits_per_sample(st->codecpar->codec_id)) { av_log(s, AV_LOG_WARNING, "track %d: codec frame size is not set\n", i); track->audio_vbr = 1; - }else if (st->codec->codec_id == AV_CODEC_ID_ADPCM_MS || - st->codec->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV || - st->codec->codec_id == AV_CODEC_ID_ILBC){ - if (!st->codec->block_align) { + }else if (st->codecpar->codec_id == AV_CODEC_ID_ADPCM_MS || + st->codecpar->codec_id == AV_CODEC_ID_ADPCM_IMA_WAV || + st->codecpar->codec_id == AV_CODEC_ID_ILBC){ + if (!st->codecpar->block_align) { av_log(s, AV_LOG_ERROR, "track %d: codec block align is not set for adpcm\n", i); ret = AVERROR(EINVAL); goto error; } - track->sample_size = st->codec->block_align; - }else if (st->codec->frame_size > 1){ /* assume compressed audio */ + track->sample_size = st->codecpar->block_align; + }else if (st->codecpar->frame_size > 1){ /* assume compressed audio */ track->audio_vbr = 1; }else{ - track->sample_size = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels; + track->sample_size = (av_get_bits_per_sample(st->codecpar->codec_id) >> 3) * st->codecpar->channels; } - if (st->codec->codec_id == AV_CODEC_ID_ILBC || - st->codec->codec_id == AV_CODEC_ID_ADPCM_IMA_QT) { + if (st->codecpar->codec_id == AV_CODEC_ID_ILBC || + st->codecpar->codec_id == AV_CODEC_ID_ADPCM_IMA_QT) { track->audio_vbr = 1; } if (track->mode != MODE_MOV && - track->enc->codec_id == AV_CODEC_ID_MP3 && track->timescale < 16000) { + track->par->codec_id == AV_CODEC_ID_MP3 && track->timescale < 16000) { if (s->strict_std_compliance >= FF_COMPLIANCE_NORMAL) { av_log(s, AV_LOG_ERROR, "track %d: muxing mp3 at %dhz is not standard, to mux anyway set strict to -1\n", - i, track->enc->sample_rate); + i, track->par->sample_rate); ret = AVERROR(EINVAL); goto error; } else { av_log(s, AV_LOG_WARNING, "track %d: muxing mp3 at %dhz is not standard in MP4\n", - i, track->enc->sample_rate); + i, track->par->sample_rate); } } - } else if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { track->timescale = st->time_base.den; - } else if (st->codec->codec_type == AVMEDIA_TYPE_DATA) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) { track->timescale = st->time_base.den; } else { track->timescale = MOV_TIMESCALE; } if (!track->height) - track->height = st->codec->height; + track->height = st->codecpar->height; /* The ism specific timescale isn't mandatory, but is assumed by * some tools, such as mp4split. */ if (mov->mode == MODE_ISM) @@ -5370,23 +5400,23 @@ static int mov_write_header(AVFormatContext *s) avpriv_set_pts_info(st, 64, 1, track->timescale); /* copy extradata if it exists */ - if (st->codec->extradata_size) { - if (st->codec->codec_id == AV_CODEC_ID_DVD_SUBTITLE) + if (st->codecpar->extradata_size) { + if (st->codecpar->codec_id == AV_CODEC_ID_DVD_SUBTITLE) mov_create_dvd_sub_decoder_specific_info(track, st); - else if (!TAG_IS_AVCI(track->tag) && st->codec->codec_id != AV_CODEC_ID_DNXHD) { - track->vos_len = st->codec->extradata_size; + else if (!TAG_IS_AVCI(track->tag) && st->codecpar->codec_id != AV_CODEC_ID_DNXHD) { + track->vos_len = st->codecpar->extradata_size; track->vos_data = av_malloc(track->vos_len); if (!track->vos_data) { ret = AVERROR(ENOMEM); goto error; } - memcpy(track->vos_data, st->codec->extradata, track->vos_len); + memcpy(track->vos_data, st->codecpar->extradata, track->vos_len); } } if (mov->encryption_scheme == MOV_ENC_CENC_AES_CTR) { ret = ff_mov_cenc_init(&track->cenc, mov->encryption_key, - track->enc->codec_id == AV_CODEC_ID_H264, s->flags & AVFMT_FLAG_BITEXACT); + track->par->codec_id == AV_CODEC_ID_H264, s->flags & AVFMT_FLAG_BITEXACT); if (ret) { goto error; } @@ -5398,8 +5428,8 @@ static int mov_write_header(AVFormatContext *s) AVStream *st= s->streams[i]; MOVTrack *track= &mov->tracks[i]; - if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO || - track->enc->channel_layout != AV_CH_LAYOUT_MONO) + if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || + track->par->channel_layout != AV_CH_LAYOUT_MONO) continue; for (j = 0; j < s->nb_streams; j++) { @@ -5408,8 +5438,8 @@ static int mov_write_header(AVFormatContext *s) if (j == i) continue; - if (stj->codec->codec_type != AVMEDIA_TYPE_AUDIO || - trackj->enc->channel_layout != AV_CH_LAYOUT_MONO || + if (stj->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || + trackj->par->channel_layout != AV_CH_LAYOUT_MONO || trackj->language != track->language || trackj->tag != track->tag ) @@ -5451,8 +5481,8 @@ static int mov_write_header(AVFormatContext *s) /* Initialize the hint tracks for each audio and video stream */ for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO || - st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || + st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { if ((ret = ff_mov_init_hinting(s, hint_track, i)) < 0) goto error; hint_track++; @@ -5466,7 +5496,7 @@ static int mov_write_header(AVFormatContext *s) AVStream *st = s->streams[i]; t = global_tcr; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { if (!t) t = av_dict_get(st->metadata, "timecode", NULL, 0); if (!t) @@ -5650,7 +5680,7 @@ static int mov_write_trailer(AVFormatContext *s) */ for (i = 0; i < mov->nb_streams; i++) { MOVTrack *trk = &mov->tracks[i]; - if (trk->enc->codec_id == AV_CODEC_ID_MOV_TEXT && + if (trk->par->codec_id == AV_CODEC_ID_MOV_TEXT && !trk->last_sample_is_subtitle_end) { mov_write_subtitle_end_packet(s, i, trk->track_duration); trk->last_sample_is_subtitle_end = 1; diff --git a/libavformat/movenc.h b/libavformat/movenc.h index 44caff9711..1090085a5a 100644 --- a/libavformat/movenc.h +++ b/libavformat/movenc.h @@ -101,7 +101,7 @@ typedef struct MOVTrack { int track_id; int tag; ///< stsd fourcc AVStream *st; - AVCodecContext *enc; + AVCodecParameters *par; int multichannel_as_mono; int vos_len; diff --git a/libavformat/movenchint.c b/libavformat/movenchint.c index 9e667edce4..964026ec71 100644 --- a/libavformat/movenchint.c +++ b/libavformat/movenchint.c @@ -37,11 +37,11 @@ int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index) track->tag = MKTAG('r','t','p',' '); track->src_track = src_index; - track->enc = avcodec_alloc_context3(NULL); - if (!track->enc) + track->par = avcodec_parameters_alloc(); + if (!track->par) goto fail; - track->enc->codec_type = AVMEDIA_TYPE_DATA; - track->enc->codec_tag = track->tag; + track->par->codec_type = AVMEDIA_TYPE_DATA; + track->par->codec_tag = track->tag; ret = ff_rtp_chain_mux_open(&track->rtp_ctx, s, src_st, NULL, RTP_MAX_PACKET_SIZE, src_index); @@ -58,7 +58,7 @@ int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index) fail: av_log(s, AV_LOG_WARNING, "Unable to initialize hinting of stream %d\n", src_index); - av_freep(&track->enc); + avcodec_parameters_free(&track->par); /* Set a default timescale, to avoid crashes in av_dump_format */ track->timescale = 90000; return ret; @@ -460,7 +460,7 @@ void ff_mov_close_hinting(MOVTrack *track) { AVFormatContext *rtp_ctx = track->rtp_ctx; - av_freep(&track->enc); + avcodec_parameters_free(&track->par); sample_queue_free(&track->sample_queue); if (!rtp_ctx) return; diff --git a/libavformat/mp3dec.c b/libavformat/mp3dec.c index 672d643cec..3725d6717c 100644 --- a/libavformat/mp3dec.c +++ b/libavformat/mp3dec.c @@ -331,7 +331,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base) st->duration = av_rescale_q(mp3->frames, (AVRational){spf, c.sample_rate}, st->time_base); if (mp3->header_filesize && mp3->frames && !mp3->is_cbr) - st->codec->bit_rate = av_rescale(mp3->header_filesize, 8 * c.sample_rate, mp3->frames * (int64_t)spf); + st->codecpar->bit_rate = av_rescale(mp3->header_filesize, 8 * c.sample_rate, mp3->frames * (int64_t)spf); return 0; } @@ -348,8 +348,8 @@ static int mp3_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_MP3; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_MP3; st->need_parsing = AVSTREAM_PARSE_FULL_RAW; st->start_time = 0; diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c index 71f5178a50..de6340192c 100644 --- a/libavformat/mp3enc.c +++ b/libavformat/mp3enc.c @@ -129,7 +129,7 @@ static const uint8_t xing_offtbl[2][2] = {{32, 17}, {17, 9}}; static int mp3_write_xing(AVFormatContext *s) { MP3Context *mp3 = s->priv_data; - AVCodecContext *codec = s->streams[mp3->audio_stream_idx]->codec; + AVCodecParameters *par = s->streams[mp3->audio_stream_idx]->codecpar; AVDictionaryEntry *enc = av_dict_get(s->streams[mp3->audio_stream_idx]->metadata, "encoder", NULL, 0); AVIOContext *dyn_ctx; int32_t header; @@ -148,9 +148,9 @@ static int mp3_write_xing(AVFormatContext *s) for (i = 0; i < FF_ARRAY_ELEMS(avpriv_mpa_freq_tab); i++) { const uint16_t base_freq = avpriv_mpa_freq_tab[i]; - if (codec->sample_rate == base_freq) ver = 0x3; // MPEG 1 - else if (codec->sample_rate == base_freq / 2) ver = 0x2; // MPEG 2 - else if (codec->sample_rate == base_freq / 4) ver = 0x0; // MPEG 2.5 + if (par->sample_rate == base_freq) ver = 0x3; // MPEG 1 + else if (par->sample_rate == base_freq / 2) ver = 0x2; // MPEG 2 + else if (par->sample_rate == base_freq / 4) ver = 0x0; // MPEG 2.5 else continue; srate_idx = i; @@ -161,7 +161,7 @@ static int mp3_write_xing(AVFormatContext *s) return -1; } - switch (codec->channels) { + switch (par->channels) { case 1: channels = MPA_MONO; break; case 2: channels = MPA_STEREO; break; default: av_log(s, AV_LOG_WARNING, "Unsupported number of channels, " @@ -177,7 +177,7 @@ static int mp3_write_xing(AVFormatContext *s) for (bitrate_idx = 1; bitrate_idx < 15; bitrate_idx++) { int bit_rate = 1000 * avpriv_mpa_bitrate_tab[ver != 3][3 - 1][bitrate_idx]; - int error = FFABS(bit_rate - codec->bit_rate); + int error = FFABS(bit_rate - par->bit_rate); if (error < best_bitrate_error) { best_bitrate_error = error; @@ -249,10 +249,10 @@ static int mp3_write_xing(AVFormatContext *s) avio_w8(dyn_ctx, 0); // unknown abr/minimal bitrate // encoder delay - if (codec->initial_padding - 528 - 1 >= 1 << 12) { + if (par->initial_padding - 528 - 1 >= 1 << 12) { av_log(s, AV_LOG_WARNING, "Too many samples of initial padding.\n"); } - avio_wb24(dyn_ctx, FFMAX(codec->initial_padding - 528 - 1, 0)<<12); + avio_wb24(dyn_ctx, FFMAX(par->initial_padding - 528 - 1, 0)<<12); avio_w8(dyn_ctx, 0); // misc avio_w8(dyn_ctx, 0); // mp3gain @@ -575,14 +575,14 @@ static int mp3_write_header(struct AVFormatContext *s) mp3->audio_stream_idx = -1; for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - if (mp3->audio_stream_idx >= 0 || st->codec->codec_id != AV_CODEC_ID_MP3) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + if (mp3->audio_stream_idx >= 0 || st->codecpar->codec_id != AV_CODEC_ID_MP3) { av_log(s, AV_LOG_ERROR, "Invalid audio stream. Exactly one MP3 " "audio stream is required.\n"); return AVERROR(EINVAL); } mp3->audio_stream_idx = i; - } else if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO) { + } else if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) { av_log(s, AV_LOG_ERROR, "Only audio streams and pictures are allowed in MP3.\n"); return AVERROR(EINVAL); } diff --git a/libavformat/mpc.c b/libavformat/mpc.c index d0c1b85a30..ffd1c56c1c 100644 --- a/libavformat/mpc.c +++ b/libavformat/mpc.c @@ -89,16 +89,16 @@ static int mpc_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_MUSEPACK7; - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; - st->codec->bits_per_coded_sample = 16; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_MUSEPACK7; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->bits_per_coded_sample = 16; - if (ff_get_extradata(st->codec, s->pb, 16) < 0) + if (ff_get_extradata(st->codecpar, s->pb, 16) < 0) return AVERROR(ENOMEM); - st->codec->sample_rate = mpc_rate[st->codec->extradata[2] & 3]; - avpriv_set_pts_info(st, 32, MPC_FRAMESIZE, st->codec->sample_rate); + st->codecpar->sample_rate = mpc_rate[st->codecpar->extradata[2] & 3]; + avpriv_set_pts_info(st, 32, MPC_FRAMESIZE, st->codecpar->sample_rate); /* scan for seekpoints */ st->start_time = 0; st->duration = c->fcount; diff --git a/libavformat/mpc8.c b/libavformat/mpc8.c index bf597b88a5..288caa0639 100644 --- a/libavformat/mpc8.c +++ b/libavformat/mpc8.c @@ -248,18 +248,18 @@ static int mpc8_read_header(AVFormatContext *s) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_MUSEPACK8; - st->codec->bits_per_coded_sample = 16; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_MUSEPACK8; + st->codecpar->bits_per_coded_sample = 16; - if (ff_get_extradata(st->codec, pb, 2) < 0) + if (ff_get_extradata(st->codecpar, pb, 2) < 0) return AVERROR(ENOMEM); - st->codec->channels = (st->codec->extradata[1] >> 4) + 1; - st->codec->sample_rate = mpc8_rate[st->codec->extradata[0] >> 5]; - avpriv_set_pts_info(st, 32, 1152 << (st->codec->extradata[1]&3)*2, st->codec->sample_rate); + st->codecpar->channels = (st->codecpar->extradata[1] >> 4) + 1; + st->codecpar->sample_rate = mpc8_rate[st->codecpar->extradata[0] >> 5]; + avpriv_set_pts_info(st, 32, 1152 << (st->codecpar->extradata[1]&3)*2, st->codecpar->sample_rate); st->start_time = 0; - st->duration = c->samples / (1152 << (st->codec->extradata[1]&3)*2); + st->duration = c->samples / (1152 << (st->codecpar->extradata[1]&3)*2); size -= avio_tell(pb) - pos; if (size > 0) avio_skip(pb, size); diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c index 77d5cd10ab..c83c02681a 100644 --- a/libavformat/mpeg.c +++ b/libavformat/mpeg.c @@ -597,13 +597,13 @@ skip: if (!st) goto skip; st->id = startcode; - st->codec->codec_type = type; - st->codec->codec_id = codec_id; - if ( st->codec->codec_id == AV_CODEC_ID_PCM_MULAW - || st->codec->codec_id == AV_CODEC_ID_PCM_ALAW) { - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; - st->codec->sample_rate = 8000; + st->codecpar->codec_type = type; + st->codecpar->codec_id = codec_id; + if ( st->codecpar->codec_id == AV_CODEC_ID_PCM_MULAW + || st->codecpar->codec_id == AV_CODEC_ID_PCM_ALAW) { + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->sample_rate = 8000; } st->request_probe = request_probe; st->need_parsing = AVSTREAM_PARSE_FULL; @@ -612,7 +612,7 @@ found: if (st->discard >= AVDISCARD_ALL) goto skip; if (startcode >= 0xa0 && startcode <= 0xaf) { - if (st->codec->codec_id == AV_CODEC_ID_MLP) { + if (st->codecpar->codec_id == AV_CODEC_ID_MLP) { if (len < 6) goto skip; avio_skip(s->pb, 6); @@ -791,8 +791,8 @@ static int vobsub_read_header(AVFormatContext *s) goto end; } st->id = stream_id; - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = AV_CODEC_ID_DVD_SUBTITLE; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_DVD_SUBTITLE; avpriv_set_pts_info(st, 64, 1, 1000); av_dict_set(&st->metadata, "language", id, 0); if (alt[0]) @@ -869,8 +869,8 @@ static int vobsub_read_header(AVFormatContext *s) av_bprint_finalize(&header, &header_str); for (i = 0; i < s->nb_streams; i++) { AVStream *sub_st = s->streams[i]; - sub_st->codec->extradata = av_strdup(header_str); - sub_st->codec->extradata_size = header.len; + sub_st->codecpar->extradata = av_strdup(header_str); + sub_st->codecpar->extradata_size = header.len; } av_free(header_str); diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c index 2e095495f0..358031d83d 100644 --- a/libavformat/mpegenc.c +++ b/libavformat/mpegenc.c @@ -348,35 +348,35 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx) avpriv_set_pts_info(st, 64, 1, 90000); - switch (st->codec->codec_type) { + switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: if (!s->is_mpeg2 && - (st->codec->codec_id == AV_CODEC_ID_AC3 || - st->codec->codec_id == AV_CODEC_ID_DTS || - st->codec->codec_id == AV_CODEC_ID_PCM_S16BE)) + (st->codecpar->codec_id == AV_CODEC_ID_AC3 || + st->codecpar->codec_id == AV_CODEC_ID_DTS || + st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE)) av_log(ctx, AV_LOG_WARNING, "%s in MPEG-1 system streams is not widely supported, " "consider using the vob or the dvd muxer " "to force a MPEG-2 program stream.\n", - avcodec_get_name(st->codec->codec_id)); - if (st->codec->codec_id == AV_CODEC_ID_AC3) { + avcodec_get_name(st->codecpar->codec_id)); + if (st->codecpar->codec_id == AV_CODEC_ID_AC3) { stream->id = ac3_id++; - } else if (st->codec->codec_id == AV_CODEC_ID_DTS) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_DTS) { stream->id = dts_id++; - } else if (st->codec->codec_id == AV_CODEC_ID_PCM_S16BE) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE) { stream->id = lpcm_id++; for (j = 0; j < 4; j++) { - if (lpcm_freq_tab[j] == st->codec->sample_rate) + if (lpcm_freq_tab[j] == st->codecpar->sample_rate) break; } if (j == 4) goto fail; - if (st->codec->channels > 8) + if (st->codecpar->channels > 8) return -1; stream->lpcm_header[0] = 0x0c; - stream->lpcm_header[1] = (st->codec->channels - 1) | (j << 4); + stream->lpcm_header[1] = (st->codecpar->channels - 1) | (j << 4); stream->lpcm_header[2] = 0x80; - stream->lpcm_align = st->codec->channels * 2; + stream->lpcm_align = st->codecpar->channels * 2; } else { stream->id = mpa_id++; } @@ -387,7 +387,7 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx) s->audio_bound++; break; case AVMEDIA_TYPE_VIDEO: - if (st->codec->codec_id == AV_CODEC_ID_H264) + if (st->codecpar->codec_id == AV_CODEC_ID_H264) stream->id = h264_id++; else stream->id = mpv_id++; @@ -415,7 +415,7 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx) break; default: av_log(ctx, AV_LOG_ERROR, "Invalid media type %s for output stream #%d\n", - av_get_media_type_string(st->codec->codec_type), i); + av_get_media_type_string(st->codecpar->codec_type), i); return AVERROR(EINVAL); } stream->fifo = av_fifo_alloc(16); @@ -435,7 +435,7 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx) if (props) codec_rate = props->max_bitrate; else - codec_rate = st->codec->bit_rate; + codec_rate = st->codecpar->bit_rate; if (!codec_rate) codec_rate = (1 << 21) * 8 * 50 / ctx->nb_streams; @@ -444,7 +444,7 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx) if ((stream->id & 0xe0) == AUDIO_ID) audio_bitrate += codec_rate; - else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) + else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) video_bitrate += codec_rate; } @@ -984,7 +984,7 @@ retry: /* for subtitle, a single PES packet must be generated, * so we flush after every single subtitle packet */ if (s->packet_size > avail_data && !flush - && st->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) + && st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) return 0; if (avail_data == 0) continue; @@ -1115,7 +1115,7 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt) int64_t pts, dts; PacketDesc *pkt_desc; int preload; - const int is_iframe = st->codec->codec_type == AVMEDIA_TYPE_VIDEO && + const int is_iframe = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && (pkt->flags & AV_PKT_FLAG_KEY); preload = av_rescale(s->preload, 90000, AV_TIME_BASE); diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index dbec2558b1..5cdab58016 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -762,16 +762,15 @@ static void mpegts_find_stream_type(AVStream *st, uint32_t stream_type, const StreamType *types) { - if (avcodec_is_open(st->codec)) { - av_log(NULL, AV_LOG_DEBUG, "cannot set stream info, codec is open\n"); - return; - } - for (; types->stream_type; types++) if (stream_type == types->stream_type) { - st->codec->codec_type = types->codec_type; - st->codec->codec_id = types->codec_id; - st->request_probe = 0; + if (st->codecpar->codec_type != types->codec_type || + st->codecpar->codec_id != types->codec_id) { + st->codecpar->codec_type = types->codec_type; + st->codecpar->codec_id = types->codec_id; + st->internal->need_context_update = 1; + } + st->request_probe = 0; return; } } @@ -779,18 +778,19 @@ static void mpegts_find_stream_type(AVStream *st, static int mpegts_set_stream_info(AVStream *st, PESContext *pes, uint32_t stream_type, uint32_t prog_reg_desc) { - int old_codec_type = st->codec->codec_type; - int old_codec_id = st->codec->codec_id; + int old_codec_type = st->codecpar->codec_type; + int old_codec_id = st->codecpar->codec_id; + int old_codec_tag = st->codecpar->codec_tag; - if (avcodec_is_open(st->codec)) { - av_log(pes->stream, AV_LOG_DEBUG, "cannot set stream info, codec is open\n"); + if (avcodec_is_open(st->internal->avctx)) { + av_log(pes->stream, AV_LOG_DEBUG, "cannot set stream info, internal codec is open\n"); return 0; } avpriv_set_pts_info(st, 33, 1, 90000); st->priv_data = pes; - st->codec->codec_type = AVMEDIA_TYPE_DATA; - st->codec->codec_id = AV_CODEC_ID_NONE; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_id = AV_CODEC_ID_NONE; st->need_parsing = AVSTREAM_PARSE_FULL; pes->st = st; pes->stream_type = stream_type; @@ -799,14 +799,14 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, "stream=%d stream_type=%x pid=%x prog_reg_desc=%.4s\n", st->index, pes->stream_type, pes->pid, (char *)&prog_reg_desc); - st->codec->codec_tag = pes->stream_type; + st->codecpar->codec_tag = pes->stream_type; mpegts_find_stream_type(st, pes->stream_type, ISO_types); if (pes->stream_type == 4) st->request_probe = 50; if ((prog_reg_desc == AV_RL32("HDMV") || prog_reg_desc == AV_RL32("HDPR")) && - st->codec->codec_id == AV_CODEC_ID_NONE) { + st->codecpar->codec_id == AV_CODEC_ID_NONE) { mpegts_find_stream_type(st, pes->stream_type, HDMV_types); if (pes->stream_type == 0x83) { // HDMV TrueHD streams also contain an AC3 coded version of the @@ -827,28 +827,33 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, sub_st->id = pes->pid; avpriv_set_pts_info(sub_st, 33, 1, 90000); sub_st->priv_data = sub_pes; - sub_st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - sub_st->codec->codec_id = AV_CODEC_ID_AC3; + sub_st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + sub_st->codecpar->codec_id = AV_CODEC_ID_AC3; sub_st->need_parsing = AVSTREAM_PARSE_FULL; sub_pes->sub_st = pes->sub_st = sub_st; } } - if (st->codec->codec_id == AV_CODEC_ID_NONE) + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) mpegts_find_stream_type(st, pes->stream_type, MISC_types); - if (st->codec->codec_id == AV_CODEC_ID_NONE) { - st->codec->codec_id = old_codec_id; - st->codec->codec_type = old_codec_type; + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) { + st->codecpar->codec_id = old_codec_id; + st->codecpar->codec_type = old_codec_type; } - if ((st->codec->codec_id == AV_CODEC_ID_NONE || + if ((st->codecpar->codec_id == AV_CODEC_ID_NONE || (st->request_probe > 0 && st->request_probe < AVPROBE_SCORE_STREAM_RETRY / 5)) && - !avcodec_is_open(st->codec) && st->probe_packets > 0 && stream_type == STREAM_TYPE_PRIVATE_DATA) { - st->codec->codec_type = AVMEDIA_TYPE_DATA; - st->codec->codec_id = AV_CODEC_ID_BIN_DATA; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_id = AV_CODEC_ID_BIN_DATA; st->request_probe = AVPROBE_SCORE_STREAM_RETRY / 5; } + /* queue a context update if properties changed */ + if (old_codec_type != st->codecpar->codec_type || + old_codec_id != st->codecpar->codec_id || + old_codec_tag != st->codecpar->codec_tag) + st->internal->need_context_update = 1; + return 0; } @@ -1061,7 +1066,7 @@ static int mpegts_push_data(MpegTSFilter *filter, code != 0x1ff && code != 0x1f2 && /* program_stream_directory, DSMCC_stream */ code != 0x1f8) { /* ITU-T Rec. H.222.1 type E stream */ pes->state = MPEGTS_PESHEADER; - if (pes->st->codec->codec_id == AV_CODEC_ID_NONE && !pes->st->request_probe) { + if (pes->st->codecpar->codec_id == AV_CODEC_ID_NONE && !pes->st->request_probe) { av_log(pes->stream, AV_LOG_TRACE, "pid=%x stream_type=%x probing\n", pes->pid, @@ -1158,8 +1163,8 @@ skip: buf_size -= 5; } if ( pes->ts->fix_teletext_pts - && ( pes->st->codec->codec_id == AV_CODEC_ID_DVB_TELETEXT - || pes->st->codec->codec_id == AV_CODEC_ID_DVB_SUBTITLE) + && ( pes->st->codecpar->codec_id == AV_CODEC_ID_DVB_TELETEXT + || pes->st->codecpar->codec_id == AV_CODEC_ID_DVB_SUBTITLE) ) { AVProgram *p = NULL; while ((p = av_find_program_from_stream(pes->stream, p, pes->st->index))) { @@ -1175,7 +1180,7 @@ skip: int i; for (i = 0; i < p->nb_stream_indexes; i++) { AVStream *pst = pes->stream->streams[p->stream_index[i]]; - if (pst->codec->codec_type == AVMEDIA_TYPE_VIDEO) + if (pst->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) st = pst; } } @@ -1189,10 +1194,10 @@ skip: pes->st->pts_wrap_behavior = st->pts_wrap_behavior; if (pes->dts == AV_NOPTS_VALUE || pes->dts < pcr) { pes->pts = pes->dts = pcr; - } else if (pes->st->codec->codec_id == AV_CODEC_ID_DVB_TELETEXT && + } else if (pes->st->codecpar->codec_id == AV_CODEC_ID_DVB_TELETEXT && pes->dts > pcr + 3654 + 9000) { pes->pts = pes->dts = pcr + 3654 + 9000; - } else if (pes->st->codec->codec_id == AV_CODEC_ID_DVB_SUBTITLE && + } else if (pes->st->codecpar->codec_id == AV_CODEC_ID_DVB_SUBTITLE && pes->dts > pcr + 10*90000) { //10sec pes->pts = pes->dts = pcr + 3654 + 9000; } @@ -1554,14 +1559,15 @@ static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, mp4_descr[i].dec_config_descr_len, 0, NULL, NULL, NULL, NULL); ff_mp4_read_dec_config_descr(s, st, &pb); - if (st->codec->codec_id == AV_CODEC_ID_AAC && - st->codec->extradata_size > 0) + if (st->codecpar->codec_id == AV_CODEC_ID_AAC && + st->codecpar->extradata_size > 0) st->need_parsing = 0; - if (st->codec->codec_id == AV_CODEC_ID_H264 && - st->codec->extradata_size > 0) + if (st->codecpar->codec_id == AV_CODEC_ID_H264 && + st->codecpar->extradata_size > 0) st->need_parsing = 0; - st->codec->codec_type = avcodec_get_type(st->codec->codec_id); + st->codecpar->codec_type = avcodec_get_type(st->codecpar->codec_id); + st->internal->need_context_update = 1; } } for (i = 0; i < mp4_descr_count; i++) @@ -1609,7 +1615,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type av_log(fc, AV_LOG_TRACE, "tag: 0x%02x len=%d\n", desc_tag, desc_len); - if ((st->codec->codec_id == AV_CODEC_ID_NONE || st->request_probe > 0) && + if ((st->codecpar->codec_id == AV_CODEC_ID_NONE || st->request_probe > 0) && stream_type == STREAM_TYPE_PRIVATE_DATA) mpegts_find_stream_type(st, desc_tag, DESC_types); @@ -1628,10 +1634,12 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type mp4_descr[i].dec_config_descr_len, 0, NULL, NULL, NULL, NULL); ff_mp4_read_dec_config_descr(fc, st, &pb); - if (st->codec->codec_id == AV_CODEC_ID_AAC && - st->codec->extradata_size > 0) + if (st->codecpar->codec_id == AV_CODEC_ID_AAC && + st->codecpar->extradata_size > 0) { st->need_parsing = 0; - if (st->codec->codec_id == AV_CODEC_ID_MPEG4SYSTEMS) + st->internal->need_context_update = 1; + } + if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4SYSTEMS) mpegts_open_section_filter(ts, pid, m4sl_cb, ts, 1); } break; @@ -1639,8 +1647,8 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type if (get16(pp, desc_end) < 0) break; if (mp4_descr_count > 0 && - (st->codec->codec_id == AV_CODEC_ID_AAC_LATM || - (st->request_probe == 0 && st->codec->codec_id == AV_CODEC_ID_NONE) || + (st->codecpar->codec_id == AV_CODEC_ID_AAC_LATM || + (st->request_probe == 0 && st->codecpar->codec_id == AV_CODEC_ID_NONE) || st->request_probe > 0) && mp4_descr->dec_config_descr_len && mp4_descr->es_id == pid) { AVIOContext pb; @@ -1648,10 +1656,11 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type mp4_descr->dec_config_descr_len, 0, NULL, NULL, NULL, NULL); ff_mp4_read_dec_config_descr(fc, st, &pb); - if (st->codec->codec_id == AV_CODEC_ID_AAC && - st->codec->extradata_size > 0) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC && + st->codecpar->extradata_size > 0) { st->request_probe = st->need_parsing = 0; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->internal->need_context_update = 1; } } break; @@ -1667,16 +1676,16 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type /* 4 bytes per language code (3 bytes) with comma or NUL byte should fit language buffer */ av_assert0(language_count <= sizeof(language) / 4); - if (st->codec->extradata == NULL) { - if (ff_alloc_extradata(st->codec, language_count * 2)) { + if (st->codecpar->extradata == NULL) { + if (ff_alloc_extradata(st->codecpar, language_count * 2)) { return AVERROR(ENOMEM); } } - if (st->codec->extradata_size < language_count * 2) + if (st->codecpar->extradata_size < language_count * 2) return AVERROR_INVALIDDATA; - extradata = st->codec->extradata; + extradata = st->codecpar->extradata; for (i = 0; i < language_count; i++) { language[i * 4 + 0] = get8(pp, desc_end); @@ -1692,6 +1701,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type language[i * 4 - 1] = 0; av_dict_set(&st->metadata, "language", language, 0); + st->internal->need_context_update = 1; } } break; @@ -1717,16 +1727,16 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type /* 4 bytes per language code (3 bytes) with comma or NUL byte should fit language buffer */ av_assert0(language_count <= sizeof(language) / 4); - if (st->codec->extradata == NULL) { - if (ff_alloc_extradata(st->codec, language_count * 5)) { + if (st->codecpar->extradata == NULL) { + if (ff_alloc_extradata(st->codecpar, language_count * 5)) { return AVERROR(ENOMEM); } } - if (st->codec->extradata_size < language_count * 5) + if (st->codecpar->extradata_size < language_count * 5) return AVERROR_INVALIDDATA; - extradata = st->codec->extradata; + extradata = st->codecpar->extradata; for (i = 0; i < language_count; i++) { language[i * 4 + 0] = get8(pp, desc_end); @@ -1755,6 +1765,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type language[i * 4 - 1] = 0; av_dict_set(&st->metadata, "language", language, 0); + st->internal->need_context_update = 1; } } break; @@ -1782,10 +1793,10 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type } break; case 0x05: /* registration descriptor */ - st->codec->codec_tag = bytestream_get_le32(pp); - av_log(fc, AV_LOG_TRACE, "reg_desc=%.4s\n", (char *)&st->codec->codec_tag); - if (st->codec->codec_id == AV_CODEC_ID_NONE || st->request_probe > 0) - mpegts_find_stream_type(st, st->codec->codec_tag, REGD_types); + st->codecpar->codec_tag = bytestream_get_le32(pp); + av_log(fc, AV_LOG_TRACE, "reg_desc=%.4s\n", (char *)&st->codecpar->codec_tag); + if (st->codecpar->codec_id == AV_CODEC_ID_NONE || st->request_probe > 0) + mpegts_find_stream_type(st, st->codecpar->codec_tag, REGD_types); break; case 0x52: /* stream identifier descriptor */ st->stream_identifier = 1 + get8(pp, desc_end); @@ -1794,39 +1805,40 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type if (get16(pp, desc_end) == 0xFFFF) *pp += 4; if (get8(pp, desc_end) == 0xFF) { - st->codec->codec_tag = bytestream_get_le32(pp); - if (st->codec->codec_id == AV_CODEC_ID_NONE) - mpegts_find_stream_type(st, st->codec->codec_tag, METADATA_types); + st->codecpar->codec_tag = bytestream_get_le32(pp); + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) + mpegts_find_stream_type(st, st->codecpar->codec_tag, METADATA_types); } break; case 0x7f: /* DVB extension descriptor */ ext_desc_tag = get8(pp, desc_end); if (ext_desc_tag < 0) return AVERROR_INVALIDDATA; - if (st->codec->codec_id == AV_CODEC_ID_OPUS && + if (st->codecpar->codec_id == AV_CODEC_ID_OPUS && ext_desc_tag == 0x80) { /* User defined (provisional Opus) */ - if (!st->codec->extradata) { - st->codec->extradata = av_mallocz(sizeof(opus_default_extradata) + - AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) + if (!st->codecpar->extradata) { + st->codecpar->extradata = av_mallocz(sizeof(opus_default_extradata) + + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) return AVERROR(ENOMEM); - st->codec->extradata_size = sizeof(opus_default_extradata); - memcpy(st->codec->extradata, opus_default_extradata, sizeof(opus_default_extradata)); + st->codecpar->extradata_size = sizeof(opus_default_extradata); + memcpy(st->codecpar->extradata, opus_default_extradata, sizeof(opus_default_extradata)); channel_config_code = get8(pp, desc_end); if (channel_config_code < 0) return AVERROR_INVALIDDATA; if (channel_config_code <= 0x8) { - st->codec->extradata[9] = channels = channel_config_code ? channel_config_code : 2; - st->codec->extradata[18] = channel_config_code ? (channels > 2) : /* Dual Mono */ 255; - st->codec->extradata[19] = opus_stream_cnt[channel_config_code]; - st->codec->extradata[20] = opus_coupled_stream_cnt[channel_config_code]; - memcpy(&st->codec->extradata[21], opus_channel_map[channels - 1], channels); + st->codecpar->extradata[9] = channels = channel_config_code ? channel_config_code : 2; + st->codecpar->extradata[18] = channel_config_code ? (channels > 2) : /* Dual Mono */ 255; + st->codecpar->extradata[19] = opus_stream_cnt[channel_config_code]; + st->codecpar->extradata[20] = opus_coupled_stream_cnt[channel_config_code]; + memcpy(&st->codecpar->extradata[21], opus_channel_map[channels - 1], channels); } else { avpriv_request_sample(fc, "Opus in MPEG-TS - channel_config_code > 0x8"); } st->need_parsing = AVSTREAM_PARSE_FULL; + st->internal->need_context_update = 1; } } break; @@ -1963,7 +1975,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len if (!st) goto out; st->id = pid; - st->codec->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; } } @@ -1994,7 +2006,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len stream_type == 0x83 && pes->sub_st) { av_program_add_stream_index(ts->stream, h->id, pes->sub_st->index); - pes->sub_st->codec->codec_tag = st->codec->codec_tag; + pes->sub_st->codecpar->codec_tag = st->codecpar->codec_tag; } } p = desc_list_end; @@ -2278,7 +2290,7 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet) int types = 0; for (i = 0; i < ts->stream->nb_streams; i++) { AVStream *st = ts->stream->streams[i]; - types |= 1<codec->codec_type; + types |= 1<codecpar->codec_type; } if ((types & (1< 100000) { av_log(ts->stream, AV_LOG_DEBUG, "All programs have pmt, headers found\n"); @@ -2571,8 +2583,8 @@ static int mpegts_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 60, 1, 27000000); - st->codec->codec_type = AVMEDIA_TYPE_DATA; - st->codec->codec_id = AV_CODEC_ID_MPEG2TS; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_id = AV_CODEC_ID_MPEG2TS; /* we iterate until we find two PCRs to estimate the bitrate */ pcr_pid = -1; @@ -2603,7 +2615,7 @@ static int mpegts_read_header(AVFormatContext *s) ts->pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]); ts->cur_pcr = pcrs[0] - ts->pcr_incr * packet_count[0]; s->bit_rate = TS_PACKET_SIZE * 8 * 27000000LL / ts->pcr_incr; - st->codec->bit_rate = s->bit_rate; + st->codecpar->bit_rate = s->bit_rate; st->start_time = ts->cur_pcr; av_log(ts->stream, AV_LOG_TRACE, "start=%0.3f pcr=%0.3f incr=%d\n", st->start_time / 1000000.0, pcrs[0] / 27e6, ts->pcr_incr); diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index 51677eaaf4..f4cb862bb9 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -293,7 +293,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) err = 1; break; } - switch (st->codec->codec_id) { + switch (st->codecpar->codec_id) { case AV_CODEC_ID_MPEG1VIDEO: case AV_CODEC_ID_MPEG2VIDEO: stream_type = STREAM_TYPE_VIDEO_MPEG2; @@ -358,19 +358,19 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) q += 2; /* patched after */ /* write optional descriptors here */ - switch (st->codec->codec_type) { + switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: - if (st->codec->codec_id==AV_CODEC_ID_AC3 && (ts->flags & MPEGTS_FLAG_SYSTEM_B)) { + if (st->codecpar->codec_id==AV_CODEC_ID_AC3 && (ts->flags & MPEGTS_FLAG_SYSTEM_B)) { *q++=0x6a; // AC3 descriptor see A038 DVB SI *q++=1; // 1 byte, all flags sets to 0 *q++=0; // omit all fields... } - if (st->codec->codec_id==AV_CODEC_ID_EAC3 && (ts->flags & MPEGTS_FLAG_SYSTEM_B)) { + if (st->codecpar->codec_id==AV_CODEC_ID_EAC3 && (ts->flags & MPEGTS_FLAG_SYSTEM_B)) { *q++=0x7a; // EAC3 descriptor see A038 DVB SI *q++=1; // 1 byte, all flags sets to 0 *q++=0; // omit all fields... } - if (st->codec->codec_id==AV_CODEC_ID_S302M) { + if (st->codecpar->codec_id==AV_CODEC_ID_S302M) { *q++ = 0x05; /* MPEG-2 registration descriptor*/ *q++ = 4; *q++ = 'B'; @@ -378,7 +378,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) *q++ = 'S'; *q++ = 'D'; } - if (st->codec->codec_id==AV_CODEC_ID_OPUS) { + if (st->codecpar->codec_id==AV_CODEC_ID_OPUS) { /* 6 bytes registration descriptor, 4 bytes Opus audio descriptor */ if (q - data > SECTION_LENGTH - 6 - 4) { err = 1; @@ -396,12 +396,12 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) *q++ = 2; *q++ = 0x80; - if (st->codec->extradata && st->codec->extradata_size >= 19) { - if (st->codec->extradata[18] == 0 && st->codec->channels <= 2) { + if (st->codecpar->extradata && st->codecpar->extradata_size >= 19) { + if (st->codecpar->extradata[18] == 0 && st->codecpar->channels <= 2) { /* RTP mapping family */ - *q++ = st->codec->channels; - } else if (st->codec->extradata[18] == 1 && st->codec->channels <= 8 && - st->codec->extradata_size >= 21 + st->codec->channels) { + *q++ = st->codecpar->channels; + } else if (st->codecpar->extradata[18] == 1 && st->codecpar->channels <= 8 && + st->codecpar->extradata_size >= 21 + st->codecpar->channels) { static const uint8_t coupled_stream_counts[9] = { 1, 0, 1, 1, 2, 2, 2, 3, 3 }; @@ -427,14 +427,14 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) }; /* Vorbis mapping family */ - if (st->codec->extradata[19] == st->codec->channels - coupled_stream_counts[st->codec->channels] && - st->codec->extradata[20] == coupled_stream_counts[st->codec->channels] && - memcmp(&st->codec->extradata[21], channel_map_a[st->codec->channels-1], st->codec->channels) == 0) { - *q++ = st->codec->channels; - } else if (st->codec->channels >= 2 && st->codec->extradata[19] == st->codec->channels && - st->codec->extradata[20] == 0 && - memcmp(&st->codec->extradata[21], channel_map_b[st->codec->channels-1], st->codec->channels) == 0) { - *q++ = st->codec->channels | 0x80; + if (st->codecpar->extradata[19] == st->codecpar->channels - coupled_stream_counts[st->codecpar->channels] && + st->codecpar->extradata[20] == coupled_stream_counts[st->codecpar->channels] && + memcmp(&st->codecpar->extradata[21], channel_map_a[st->codecpar->channels-1], st->codecpar->channels) == 0) { + *q++ = st->codecpar->channels; + } else if (st->codecpar->channels >= 2 && st->codecpar->extradata[19] == st->codecpar->channels && + st->codecpar->extradata[20] == 0 && + memcmp(&st->codecpar->extradata[21], channel_map_b[st->codecpar->channels-1], st->codecpar->channels) == 0) { + *q++ = st->codecpar->channels | 0x80; } else { /* Unsupported, could write an extended descriptor here */ av_log(s, AV_LOG_ERROR, "Unsupported Opus Vorbis-style channel mapping"); @@ -442,12 +442,12 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) } } else { /* Unsupported */ - av_log(s, AV_LOG_ERROR, "Unsupported Opus channel mapping for family %d", st->codec->extradata[18]); + av_log(s, AV_LOG_ERROR, "Unsupported Opus channel mapping for family %d", st->codecpar->extradata[18]); *q++ = 0xff; } - } else if (st->codec->channels <= 2) { + } else if (st->codecpar->channels <= 2) { /* Assume RTP mapping family */ - *q++ = st->codec->channels; + *q++ = st->codecpar->channels; } else { /* Unsupported */ av_log(s, AV_LOG_ERROR, "Unsupported Opus channel mapping"); @@ -498,7 +498,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) const char default_language[] = "und"; const char *language = lang && strlen(lang->value) >= 3 ? lang->value : default_language; - if (st->codec->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { + if (st->codecpar->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { uint8_t *len_ptr; int extradata_copied = 0; @@ -517,9 +517,9 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) if (*language != '\0') language++; - if (st->codec->extradata_size - extradata_copied >= 5) { - *q++ = st->codec->extradata[extradata_copied + 4]; /* subtitling_type */ - memcpy(q, st->codec->extradata + extradata_copied, 4); /* composition_page_id and ancillary_page_id */ + if (st->codecpar->extradata_size - extradata_copied >= 5) { + *q++ = st->codecpar->extradata[extradata_copied + 4]; /* subtitling_type */ + memcpy(q, st->codecpar->extradata + extradata_copied, 4); /* composition_page_id and ancillary_page_id */ extradata_copied += 5; q += 4; } else { @@ -527,9 +527,9 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) * 0x10 - normal with no monitor aspect ratio criticality * 0x20 - for the hard of hearing with no monitor aspect ratio criticality */ *q++ = (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED) ? 0x20 : 0x10; - if ((st->codec->extradata_size == 4) && (extradata_copied == 0)) { + if ((st->codecpar->extradata_size == 4) && (extradata_copied == 0)) { /* support of old 4-byte extradata format */ - memcpy(q, st->codec->extradata, 4); /* composition_page_id and ancillary_page_id */ + memcpy(q, st->codecpar->extradata, 4); /* composition_page_id and ancillary_page_id */ extradata_copied += 4; q += 4; } else { @@ -540,7 +540,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) } *len_ptr = q - len_ptr - 1; - } else if (st->codec->codec_id == AV_CODEC_ID_DVB_TELETEXT) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_DVB_TELETEXT) { uint8_t *len_ptr = NULL; int extradata_copied = 0; @@ -556,8 +556,8 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) if (*language != '\0') language++; - if (st->codec->extradata_size - 1 > extradata_copied) { - memcpy(q, st->codec->extradata + extradata_copied, 2); + if (st->codecpar->extradata_size - 1 > extradata_copied) { + memcpy(q, st->codecpar->extradata + extradata_copied, 2); extradata_copied += 2; q += 2; } else { @@ -592,7 +592,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) } break; case AVMEDIA_TYPE_DATA: - if (st->codec->codec_id == AV_CODEC_ID_SMPTE_KLV) { + if (st->codecpar->codec_id == AV_CODEC_ID_SMPTE_KLV) { *q++ = 0x05; /* MPEG-2 registration descriptor */ *q++ = 4; *q++ = 'K'; @@ -866,13 +866,13 @@ static int mpegts_init(AVFormatContext *s) ts_st->first_pts_check = 1; ts_st->cc = 15; /* update PCR pid by using the first video stream */ - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && service->pcr_pid == 0x1fff) { service->pcr_pid = ts_st->pid; pcr_st = st; } - if (st->codec->codec_id == AV_CODEC_ID_AAC && - st->codec->extradata_size > 0) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC && + st->codecpar->extradata_size > 0) { AVStream *ast; ts_st->amux = avformat_alloc_context(); if (!ts_st->amux) { @@ -890,7 +890,7 @@ static int mpegts_init(AVFormatContext *s) ret = AVERROR(ENOMEM); goto fail; } - ret = avcodec_copy_context(ast->codec, st->codec); + ret = avcodec_parameters_copy(ast->codecpar, st->codecpar); if (ret != 0) goto fail; ast->time_base = st->time_base; @@ -898,8 +898,8 @@ static int mpegts_init(AVFormatContext *s) if (ret < 0) goto fail; } - if (st->codec->codec_id == AV_CODEC_ID_OPUS) { - ts_st->opus_pending_trim_start = st->codec->initial_padding * 48000 / st->codec->sample_rate; + if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) { + ts_st->opus_pending_trim_start = st->codecpar->initial_padding * 48000 / st->codecpar->sample_rate; } } @@ -927,14 +927,15 @@ static int mpegts_init(AVFormatContext *s) /* Arbitrary values, PAT/PMT will also be written on video key frames */ ts->sdt_packet_period = 200; ts->pat_packet_period = 40; - if (pcr_st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - if (!pcr_st->codec->frame_size) { + if (pcr_st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + int frame_size = av_get_audio_frame_duration2(pcr_st->codecpar, 0); + if (!frame_size) { av_log(s, AV_LOG_WARNING, "frame size not set\n"); service->pcr_packet_period = - pcr_st->codec->sample_rate / (10 * 512); + pcr_st->codecpar->sample_rate / (10 * 512); } else { service->pcr_packet_period = - pcr_st->codec->sample_rate / (10 * pcr_st->codec->frame_size); + pcr_st->codecpar->sample_rate / (10 * frame_size); } } else { // max delta PCR 0.1s @@ -1132,10 +1133,10 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, int afc_len, stuffing_len; int64_t pcr = -1; /* avoid warning */ int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE); - int force_pat = st->codec->codec_type == AVMEDIA_TYPE_VIDEO && key && !ts_st->prev_payload_key; + int force_pat = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && key && !ts_st->prev_payload_key; - av_assert0(ts_st->payload != buf || st->codec->codec_type != AVMEDIA_TYPE_VIDEO); - if (ts->flags & MPEGTS_FLAG_PAT_PMT_AT_FRAMES && st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + av_assert0(ts_st->payload != buf || st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO); + if (ts->flags & MPEGTS_FLAG_PAT_PMT_AT_FRAMES && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { force_pat = 1; } @@ -1205,31 +1206,31 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, *q++ = 0x01; is_dvb_subtitle = 0; is_dvb_teletext = 0; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { - if (st->codec->codec_id == AV_CODEC_ID_DIRAC) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_id == AV_CODEC_ID_DIRAC) *q++ = 0xfd; else *q++ = 0xe0; - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && - (st->codec->codec_id == AV_CODEC_ID_MP2 || - st->codec->codec_id == AV_CODEC_ID_MP3 || - st->codec->codec_id == AV_CODEC_ID_AAC)) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && + (st->codecpar->codec_id == AV_CODEC_ID_MP2 || + st->codecpar->codec_id == AV_CODEC_ID_MP3 || + st->codecpar->codec_id == AV_CODEC_ID_AAC)) { *q++ = 0xc0; - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && - st->codec->codec_id == AV_CODEC_ID_AC3 && + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && + st->codecpar->codec_id == AV_CODEC_ID_AC3 && ts->m2ts_mode) { *q++ = 0xfd; - } else if (st->codec->codec_type == AVMEDIA_TYPE_DATA) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) { *q++ = stream_id != -1 ? stream_id : 0xfc; if (stream_id == 0xbd) /* asynchronous KLV */ pts = dts = AV_NOPTS_VALUE; } else { *q++ = 0xbd; - if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { - if (st->codec->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { + if (st->codecpar->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { is_dvb_subtitle = 1; - } else if (st->codec->codec_id == AV_CODEC_ID_DVB_TELETEXT) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_DVB_TELETEXT) { is_dvb_teletext = 1; } } @@ -1244,8 +1245,8 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, header_len += 5; flags |= 0x40; } - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && - st->codec->codec_id == AV_CODEC_ID_DIRAC) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + st->codecpar->codec_id == AV_CODEC_ID_DIRAC) { /* set PES_extension_flag */ pes_extension = 1; flags |= 0x01; @@ -1259,8 +1260,8 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, * otherwise it will not play sound on blu-ray */ if (ts->m2ts_mode && - st->codec->codec_type == AVMEDIA_TYPE_AUDIO && - st->codec->codec_id == AV_CODEC_ID_AC3) { + st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && + st->codecpar->codec_id == AV_CODEC_ID_AC3) { /* set PES_extension_flag */ pes_extension = 1; flags |= 0x01; @@ -1278,14 +1279,14 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, } if (len > 0xffff) len = 0; - if (ts->omit_video_pes_length && st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (ts->omit_video_pes_length && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { len = 0; } *q++ = len >> 8; *q++ = len; val = 0x80; /* data alignment indicator is required for subtitle and data streams */ - if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE || st->codec->codec_type == AVMEDIA_TYPE_DATA) + if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE || st->codecpar->codec_type == AVMEDIA_TYPE_DATA) val |= 0x04; *q++ = val; *q++ = flags; @@ -1298,7 +1299,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, write_pts(q, 1, dts); q += 5; } - if (pes_extension && st->codec->codec_id == AV_CODEC_ID_DIRAC) { + if (pes_extension && st->codecpar->codec_id == AV_CODEC_ID_DIRAC) { flags = 0x01; /* set PES_extension_flag_2 */ *q++ = flags; *q++ = 0x80 | 0x01; /* marker bit + extension length */ @@ -1309,7 +1310,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, /* For Blu-ray AC3 Audio Setting extended flags */ if (ts->m2ts_mode && pes_extension && - st->codec->codec_id == AV_CODEC_ID_AC3) { + st->codecpar->codec_id == AV_CODEC_ID_AC3) { flags = 0x01; /* set PES_extension_flag_2 */ *q++ = flags; *q++ = 0x80 | 0x01; /* marker bit + extension length */ @@ -1503,15 +1504,15 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) } ts_st->first_pts_check = 0; - if (st->codec->codec_id == AV_CODEC_ID_H264) { + if (st->codecpar->codec_id == AV_CODEC_ID_H264) { const uint8_t *p = buf, *buf_end = p + size; uint32_t state = -1; - int extradd = (pkt->flags & AV_PKT_FLAG_KEY) ? st->codec->extradata_size : 0; + int extradd = (pkt->flags & AV_PKT_FLAG_KEY) ? st->codecpar->extradata_size : 0; int ret = ff_check_h264_startcode(s, st, pkt); if (ret < 0) return ret; - if (extradd && AV_RB24(st->codec->extradata) > 1) + if (extradd && AV_RB24(st->codecpar->extradata) > 1) extradd = 0; do { @@ -1528,7 +1529,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) data = av_malloc(pkt->size + 6 + extradd); if (!data) return AVERROR(ENOMEM); - memcpy(data + 6, st->codec->extradata, extradd); + memcpy(data + 6, st->codecpar->extradata, extradd); memcpy(data + 6 + extradd, pkt->data, pkt->size); AV_WB32(data, 0x00000001); data[4] = 0x09; @@ -1536,7 +1537,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) buf = data; size = pkt->size + 6 + extradd; } - } else if (st->codec->codec_id == AV_CODEC_ID_AAC) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_AAC) { if (pkt->size < 2) { av_log(s, AV_LOG_ERROR, "AAC packet too short\n"); return AVERROR_INVALIDDATA; @@ -1569,11 +1570,11 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) buf = data; } } - } else if (st->codec->codec_id == AV_CODEC_ID_HEVC) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_HEVC) { int ret = check_hevc_startcode(s, st, pkt); if (ret < 0) return ret; - } else if (st->codec->codec_id == AV_CODEC_ID_OPUS) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) { if (pkt->size < 2) { av_log(s, AV_LOG_ERROR, "Opus packet too short\n"); return AVERROR_INVALIDDATA; @@ -1594,7 +1595,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) &side_data_size); if (side_data && side_data_size >= 10) { - trim_end = AV_RL32(side_data + 4) * 48000 / st->codec->sample_rate; + trim_end = AV_RL32(side_data + 4) * 48000 / st->codecpar->sample_rate; } ctrl_header_size = pkt->size + 2 + pkt->size / 255 + 1; @@ -1673,7 +1674,7 @@ static int mpegts_write_packet_internal(AVFormatContext *s, AVPacket *pkt) ts_st->opus_queued_samples = 0; } - if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO || size > ts->pes_payload_size) { + if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || size > ts->pes_payload_size) { av_assert0(!ts_st->payload_size); // for video and subtitle, write a single pes packet mpegts_write_pes(s, st, buf, size, pts, dts, @@ -1766,11 +1767,11 @@ static int mpegts_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt int ret = 1; AVStream *st = s->streams[pkt->stream_index]; - if (st->codec->codec_id == AV_CODEC_ID_H264) { + if (st->codecpar->codec_id == AV_CODEC_ID_H264) { if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 && AV_RB24(pkt->data) != 0x000001) ret = ff_stream_add_bitstream_filter(st, "h264_mp4toannexb", NULL); - } else if (st->codec->codec_id == AV_CODEC_ID_HEVC) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_HEVC) { if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 && AV_RB24(pkt->data) != 0x000001) ret = ff_stream_add_bitstream_filter(st, "hevc_mp4toannexb", NULL); diff --git a/libavformat/mpjpegdec.c b/libavformat/mpjpegdec.c index 6f85e5620f..4c7764412f 100644 --- a/libavformat/mpjpegdec.c +++ b/libavformat/mpjpegdec.c @@ -151,8 +151,8 @@ static int mpjpeg_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MJPEG; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MJPEG; avpriv_set_pts_info(st, 60, 1, 25); diff --git a/libavformat/mpl2dec.c b/libavformat/mpl2dec.c index 81cc0bbb2d..59589d5b5e 100644 --- a/libavformat/mpl2dec.c +++ b/libavformat/mpl2dec.c @@ -80,8 +80,8 @@ static int mpl2_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 64, 1, 10); - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = AV_CODEC_ID_MPL2; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_MPL2; while (!avio_feof(s->pb)) { char line[4096]; diff --git a/libavformat/mpsubdec.c b/libavformat/mpsubdec.c index c5a50ecb5c..1236efa712 100644 --- a/libavformat/mpsubdec.c +++ b/libavformat/mpsubdec.c @@ -100,8 +100,8 @@ static int mpsub_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 64, pts_info.den, pts_info.num); - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = AV_CODEC_ID_TEXT; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_TEXT; ff_subtitles_queue_finalize(s, &mpsub->q); diff --git a/libavformat/msf.c b/libavformat/msf.c index 97a6dc6929..0551e9bc24 100644 --- a/libavformat/msf.c +++ b/libavformat/msf.c @@ -51,41 +51,41 @@ static int msf_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; codec = avio_rb32(s->pb); - st->codec->channels = avio_rb32(s->pb); - if (st->codec->channels <= 0 || st->codec->channels >= INT_MAX / 1024) + st->codecpar->channels = avio_rb32(s->pb); + if (st->codecpar->channels <= 0 || st->codecpar->channels >= INT_MAX / 1024) return AVERROR_INVALIDDATA; size = avio_rb32(s->pb); - st->codec->sample_rate = avio_rb32(s->pb); - if (st->codec->sample_rate <= 0) + st->codecpar->sample_rate = avio_rb32(s->pb); + if (st->codecpar->sample_rate <= 0) return AVERROR_INVALIDDATA; align = avio_rb32(s->pb) ; - if (align > INT_MAX / st->codec->channels) + if (align > INT_MAX / st->codecpar->channels) return AVERROR_INVALIDDATA; - st->codec->block_align = align; + st->codecpar->block_align = align; switch (codec) { - case 0: st->codec->codec_id = AV_CODEC_ID_PCM_S16BE; break; - case 3: st->codec->block_align = 16 * st->codec->channels; - st->codec->codec_id = AV_CODEC_ID_ADPCM_PSX; break; + case 0: st->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE; break; + case 3: st->codecpar->block_align = 16 * st->codecpar->channels; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX; break; case 7: st->need_parsing = AVSTREAM_PARSE_FULL_RAW; - st->codec->codec_id = AV_CODEC_ID_MP3; break; + st->codecpar->codec_id = AV_CODEC_ID_MP3; break; default: avpriv_request_sample(s, "Codec %d", codec); return AVERROR_PATCHWELCOME; } - st->duration = av_get_audio_frame_duration(st->codec, size); + st->duration = av_get_audio_frame_duration2(st->codecpar, size); avio_skip(s->pb, 0x40 - avio_tell(s->pb)); - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } static int msf_read_packet(AVFormatContext *s, AVPacket *pkt) { - AVCodecContext *codec = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; - return av_get_packet(s->pb, pkt, codec->block_align ? codec->block_align : 1024 * codec->channels); + return av_get_packet(s->pb, pkt, par->block_align ? par->block_align : 1024 * par->channels); } AVInputFormat ff_msf_demuxer = { diff --git a/libavformat/msnwc_tcp.c b/libavformat/msnwc_tcp.c index 5abf006cc0..3c73ac7b2c 100644 --- a/libavformat/msnwc_tcp.c +++ b/libavformat/msnwc_tcp.c @@ -74,17 +74,17 @@ static int msnwc_tcp_probe(AVProbeData *p) static int msnwc_tcp_read_header(AVFormatContext *ctx) { AVIOContext *pb = ctx->pb; - AVCodecContext *codec; + AVCodecParameters *par; AVStream *st; st = avformat_new_stream(ctx, NULL); if (!st) return AVERROR(ENOMEM); - codec = st->codec; - codec->codec_type = AVMEDIA_TYPE_VIDEO; - codec->codec_id = AV_CODEC_ID_MIMIC; - codec->codec_tag = MKTAG('M', 'L', '2', '0'); + par = st->codecpar; + par->codec_type = AVMEDIA_TYPE_VIDEO; + par->codec_id = AV_CODEC_ID_MIMIC; + par->codec_tag = MKTAG('M', 'L', '2', '0'); avpriv_set_pts_info(st, 32, 1, 1000); diff --git a/libavformat/mtv.c b/libavformat/mtv.c index a91e4c8649..dcf4aa4288 100644 --- a/libavformat/mtv.c +++ b/libavformat/mtv.c @@ -165,13 +165,13 @@ static int mtv_read_header(AVFormatContext *s) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 64, 1, mtv->video_fps); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; - st->codec->pix_fmt = AV_PIX_FMT_RGB565BE; - st->codec->width = mtv->img_width; - st->codec->height = mtv->img_height; - st->codec->extradata = av_strdup("BottomUp"); - st->codec->extradata_size = 9; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->format = AV_PIX_FMT_RGB565BE; + st->codecpar->width = mtv->img_width; + st->codecpar->height = mtv->img_height; + st->codecpar->extradata = av_strdup("BottomUp"); + st->codecpar->extradata_size = 9; // audio - mp3 @@ -180,10 +180,10 @@ static int mtv_read_header(AVFormatContext *s) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 64, 1, MTV_AUDIO_SAMPLING_RATE); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_MP3; - st->codec->bit_rate = mtv->audio_br; - st->need_parsing = AVSTREAM_PARSE_FULL; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_MP3; + st->codecpar->bit_rate = mtv->audio_br; + st->need_parsing = AVSTREAM_PARSE_FULL; // Jump over header diff --git a/libavformat/musx.c b/libavformat/musx.c index ca43254028..aff6c31a86 100644 --- a/libavformat/musx.c +++ b/libavformat/musx.c @@ -55,32 +55,32 @@ static int musx_read_header(AVFormatContext *s) if (version == 201) { avio_skip(s->pb, 8); offset = avio_rl32(s->pb); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_PSX; - st->codec->channels = 2; - st->codec->sample_rate = 32000; - st->codec->block_align = 0x80 * st->codec->channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX; + st->codecpar->channels = 2; + st->codecpar->sample_rate = 32000; + st->codecpar->block_align = 0x80 * st->codecpar->channels; } else if (version == 10) { type = avio_rl32(s->pb); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; offset = 0x800; switch (type) { case MKTAG('P', 'S', '3', '_'): - st->codec->channels = 2; - st->codec->sample_rate = 44100; + st->codecpar->channels = 2; + st->codecpar->sample_rate = 44100; avio_skip(s->pb, 44); coding = avio_rl32(s->pb); if (coding == MKTAG('D', 'A', 'T', '4') || coding == MKTAG('D', 'A', 'T', '8')) { avio_skip(s->pb, 4); - st->codec->channels = avio_rl32(s->pb); - if (st->codec->channels <= 0 || - st->codec->channels > INT_MAX / 0x20) + st->codecpar->channels = avio_rl32(s->pb); + if (st->codecpar->channels <= 0 || + st->codecpar->channels > INT_MAX / 0x20) return AVERROR_INVALIDDATA; - st->codec->sample_rate = avio_rl32(s->pb); + st->codecpar->sample_rate = avio_rl32(s->pb); } - st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_DAT4; - st->codec->block_align = 0x20 * st->codec->channels; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_DAT4; + st->codecpar->block_align = 0x20 * st->codecpar->channels; break; case MKTAG('W', 'I', 'I', '_'): avio_skip(s->pb, 44); @@ -91,31 +91,31 @@ static int musx_read_header(AVFormatContext *s) return AVERROR_PATCHWELCOME; } avio_skip(s->pb, 4); - st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_DAT4; - st->codec->channels = avio_rl32(s->pb); - if (st->codec->channels <= 0 || - st->codec->channels > INT_MAX / 0x20) + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_DAT4; + st->codecpar->channels = avio_rl32(s->pb); + if (st->codecpar->channels <= 0 || + st->codecpar->channels > INT_MAX / 0x20) return AVERROR_INVALIDDATA; - st->codec->sample_rate = avio_rl32(s->pb); - st->codec->block_align = 0x20 * st->codec->channels; + st->codecpar->sample_rate = avio_rl32(s->pb); + st->codecpar->block_align = 0x20 * st->codecpar->channels; break; case MKTAG('X', 'E', '_', '_'): - st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_DAT4; - st->codec->channels = 2; - st->codec->sample_rate = 32000; - st->codec->block_align = 0x20 * st->codec->channels; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_DAT4; + st->codecpar->channels = 2; + st->codecpar->sample_rate = 32000; + st->codecpar->block_align = 0x20 * st->codecpar->channels; break; case MKTAG('P', 'S', 'P', '_'): - st->codec->codec_id = AV_CODEC_ID_ADPCM_PSX; - st->codec->channels = 2; - st->codec->sample_rate = 32768; - st->codec->block_align = 0x80 * st->codec->channels; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX; + st->codecpar->channels = 2; + st->codecpar->sample_rate = 32768; + st->codecpar->block_align = 0x80 * st->codecpar->channels; break; case MKTAG('P', 'S', '2', '_'): - st->codec->codec_id = AV_CODEC_ID_ADPCM_PSX; - st->codec->channels = 2; - st->codec->sample_rate = 32000; - st->codec->block_align = 0x80 * st->codec->channels; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX; + st->codecpar->channels = 2; + st->codecpar->sample_rate = 32000; + st->codecpar->block_align = 0x80 * st->codecpar->channels; break; default: avpriv_request_sample(s, "Unsupported type: %X", type); @@ -124,25 +124,25 @@ static int musx_read_header(AVFormatContext *s) } else if (version == 6 || version == 5 || version == 4) { type = avio_rl32(s->pb); avio_skip(s->pb, 20); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->channels = 2; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->channels = 2; switch (type) { case MKTAG('G', 'C', '_', '_'): - st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_DAT4; - st->codec->block_align = 0x20 * st->codec->channels; - st->codec->sample_rate = 32000; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_DAT4; + st->codecpar->block_align = 0x20 * st->codecpar->channels; + st->codecpar->sample_rate = 32000; offset = avio_rb32(s->pb); break; case MKTAG('P', 'S', '2', '_'): - st->codec->codec_id = AV_CODEC_ID_ADPCM_PSX; - st->codec->block_align = 0x80 * st->codec->channels; - st->codec->sample_rate = 32000; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX; + st->codecpar->block_align = 0x80 * st->codecpar->channels; + st->codecpar->sample_rate = 32000; offset = avio_rl32(s->pb); break; case MKTAG('X', 'B', '_', '_'): - st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_DAT4; - st->codec->block_align = 0x20 * st->codec->channels; - st->codec->sample_rate = 44100; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_DAT4; + st->codecpar->block_align = 0x20 * st->codecpar->channels; + st->codecpar->sample_rate = 44100; offset = avio_rl32(s->pb); break; default: @@ -155,16 +155,16 @@ static int musx_read_header(AVFormatContext *s) avio_seek(s->pb, offset, SEEK_SET); - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } static int musx_read_packet(AVFormatContext *s, AVPacket *pkt) { - AVCodecContext *codec = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; - return av_get_packet(s->pb, pkt, codec->block_align); + return av_get_packet(s->pb, pkt, par->block_align); } AVInputFormat ff_musx_demuxer = { diff --git a/libavformat/mux.c b/libavformat/mux.c index 9ca5df4095..33301f1d79 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -117,24 +117,24 @@ AVRational ff_choose_timebase(AVFormatContext *s, AVStream *st, int min_precisio enum AVChromaLocation ff_choose_chroma_location(AVFormatContext *s, AVStream *st) { - AVCodecContext *avctx = st->codec; - const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(avctx->pix_fmt); + AVCodecParameters *par = st->codecpar; + const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(par->format); - if (avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED) - return avctx->chroma_sample_location; + if (par->chroma_location != AVCHROMA_LOC_UNSPECIFIED) + return par->chroma_location; if (pix_desc) { if (pix_desc->log2_chroma_h == 0) { return AVCHROMA_LOC_TOPLEFT; } else if (pix_desc->log2_chroma_w == 1 && pix_desc->log2_chroma_h == 1) { - if (avctx->field_order == AV_FIELD_UNKNOWN || avctx->field_order == AV_FIELD_PROGRESSIVE) { - switch (avctx->codec_id) { + if (par->field_order == AV_FIELD_UNKNOWN || par->field_order == AV_FIELD_PROGRESSIVE) { + switch (par->codec_id) { case AV_CODEC_ID_MJPEG: case AV_CODEC_ID_MPEG1VIDEO: return AVCHROMA_LOC_CENTER; } } - if (avctx->field_order == AV_FIELD_UNKNOWN || avctx->field_order != AV_FIELD_PROGRESSIVE) { - switch (avctx->codec_id) { + if (par->field_order == AV_FIELD_UNKNOWN || par->field_order != AV_FIELD_PROGRESSIVE) { + switch (par->codec_id) { case AV_CODEC_ID_MPEG2VIDEO: return AVCHROMA_LOC_LEFT; } } @@ -214,12 +214,12 @@ static int validate_codec_tag(AVFormatContext *s, AVStream *st) for (n = 0; s->oformat->codec_tag[n]; n++) { avctag = s->oformat->codec_tag[n]; while (avctag->id != AV_CODEC_ID_NONE) { - if (avpriv_toupper4(avctag->tag) == avpriv_toupper4(st->codec->codec_tag)) { + if (avpriv_toupper4(avctag->tag) == avpriv_toupper4(st->codecpar->codec_tag)) { id = avctag->id; - if (id == st->codec->codec_id) + if (id == st->codecpar->codec_id) return 1; } - if (avctag->id == st->codec->codec_id) + if (avctag->id == st->codecpar->codec_id) tag = avctag->tag; avctag++; } @@ -237,7 +237,7 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) int ret = 0, i; AVStream *st; AVDictionary *tmp = NULL; - AVCodecContext *codec = NULL; + AVCodecParameters *par = NULL; AVOutputFormat *of = s->oformat; const AVCodecDescriptor *desc; AVDictionaryEntry *e; @@ -251,6 +251,8 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) (ret = av_opt_set_dict2(s->priv_data, &tmp, AV_OPT_SEARCH_CHILDREN)) < 0) goto fail; +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS if (s->nb_streams && s->streams[0]->codec->flags & AV_CODEC_FLAG_BITEXACT) { if (!(s->flags & AVFMT_FLAG_BITEXACT)) { #if FF_API_LAVF_BITEXACT @@ -268,6 +270,8 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) #endif } } +FF_ENABLE_DEPRECATION_WARNINGS +#endif // some sanity checks if (s->nb_streams == 0 && !(of->flags & AVFMT_NOSTREAMS)) { @@ -277,58 +281,72 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) } for (i = 0; i < s->nb_streams; i++) { - st = s->streams[i]; - codec = st->codec; + st = s->streams[i]; + par = st->codecpar; #if FF_API_LAVF_CODEC_TB FF_DISABLE_DEPRECATION_WARNINGS - if (!st->time_base.num && codec->time_base.num) { + if (!st->time_base.num && st->codec->time_base.num) { av_log(s, AV_LOG_WARNING, "Using AVStream.codec.time_base as a " "timebase hint to the muxer is deprecated. Set " "AVStream.time_base instead.\n"); - avpriv_set_pts_info(st, 64, codec->time_base.num, codec->time_base.den); + avpriv_set_pts_info(st, 64, st->codec->time_base.num, st->codec->time_base.den); + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + +#if FF_API_LAVF_AVCTX +FF_DISABLE_DEPRECATION_WARNINGS + if (st->codecpar->codec_type == AVMEDIA_TYPE_UNKNOWN && + st->codec->codec_type != AVMEDIA_TYPE_UNKNOWN) { + av_log(s, AV_LOG_WARNING, "Using AVStream.codec to pass codec " + "parameters to muxers is deprecated, use AVStream.codecpar " + "instead.\n"); + ret = avcodec_parameters_from_context(st->codecpar, st->codec); + if (ret < 0) + goto fail; } FF_ENABLE_DEPRECATION_WARNINGS #endif if (!st->time_base.num) { /* fall back on the default timebase values */ - if (codec->codec_type == AVMEDIA_TYPE_AUDIO && codec->sample_rate) - avpriv_set_pts_info(st, 64, 1, codec->sample_rate); + if (par->codec_type == AVMEDIA_TYPE_AUDIO && par->sample_rate) + avpriv_set_pts_info(st, 64, 1, par->sample_rate); else avpriv_set_pts_info(st, 33, 1, 90000); } - switch (codec->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: - if (codec->sample_rate <= 0) { + if (par->sample_rate <= 0) { av_log(s, AV_LOG_ERROR, "sample rate not set\n"); ret = AVERROR(EINVAL); goto fail; } - if (!codec->block_align) - codec->block_align = codec->channels * - av_get_bits_per_sample(codec->codec_id) >> 3; + if (!par->block_align) + par->block_align = par->channels * + av_get_bits_per_sample(par->codec_id) >> 3; break; case AVMEDIA_TYPE_VIDEO: - if ((codec->width <= 0 || codec->height <= 0) && + if ((par->width <= 0 || par->height <= 0) && !(of->flags & AVFMT_NODIMENSIONS)) { av_log(s, AV_LOG_ERROR, "dimensions not set\n"); ret = AVERROR(EINVAL); goto fail; } - if (av_cmp_q(st->sample_aspect_ratio, codec->sample_aspect_ratio) - && fabs(av_q2d(st->sample_aspect_ratio) - av_q2d(codec->sample_aspect_ratio)) > 0.004*av_q2d(st->sample_aspect_ratio) + if (av_cmp_q(st->sample_aspect_ratio, par->sample_aspect_ratio) + && fabs(av_q2d(st->sample_aspect_ratio) - av_q2d(par->sample_aspect_ratio)) > 0.004*av_q2d(st->sample_aspect_ratio) ) { if (st->sample_aspect_ratio.num != 0 && st->sample_aspect_ratio.den != 0 && - codec->sample_aspect_ratio.num != 0 && - codec->sample_aspect_ratio.den != 0) { + par->sample_aspect_ratio.num != 0 && + par->sample_aspect_ratio.den != 0) { av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between muxer " "(%d/%d) and encoder layer (%d/%d)\n", st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, - codec->sample_aspect_ratio.num, - codec->sample_aspect_ratio.den); + par->sample_aspect_ratio.num, + par->sample_aspect_ratio.den); ret = AVERROR(EINVAL); goto fail; } @@ -336,36 +354,36 @@ FF_ENABLE_DEPRECATION_WARNINGS break; } - desc = avcodec_descriptor_get(codec->codec_id); + desc = avcodec_descriptor_get(par->codec_id); if (desc && desc->props & AV_CODEC_PROP_REORDER) st->internal->reorder = 1; if (of->codec_tag) { - if ( codec->codec_tag - && codec->codec_id == AV_CODEC_ID_RAWVIDEO - && ( av_codec_get_tag(of->codec_tag, codec->codec_id) == 0 - || av_codec_get_tag(of->codec_tag, codec->codec_id) == MKTAG('r', 'a', 'w', ' ')) + if ( par->codec_tag + && par->codec_id == AV_CODEC_ID_RAWVIDEO + && ( av_codec_get_tag(of->codec_tag, par->codec_id) == 0 + || av_codec_get_tag(of->codec_tag, par->codec_id) == MKTAG('r', 'a', 'w', ' ')) && !validate_codec_tag(s, st)) { // the current rawvideo encoding system ends up setting // the wrong codec_tag for avi/mov, we override it here - codec->codec_tag = 0; + par->codec_tag = 0; } - if (codec->codec_tag) { + if (par->codec_tag) { if (!validate_codec_tag(s, st)) { char tagbuf[32], tagbuf2[32]; - av_get_codec_tag_string(tagbuf, sizeof(tagbuf), codec->codec_tag); - av_get_codec_tag_string(tagbuf2, sizeof(tagbuf2), av_codec_get_tag(s->oformat->codec_tag, codec->codec_id)); + av_get_codec_tag_string(tagbuf, sizeof(tagbuf), par->codec_tag); + av_get_codec_tag_string(tagbuf2, sizeof(tagbuf2), av_codec_get_tag(s->oformat->codec_tag, par->codec_id)); av_log(s, AV_LOG_ERROR, "Tag %s/0x%08x incompatible with output codec id '%d' (%s)\n", - tagbuf, codec->codec_tag, codec->codec_id, tagbuf2); + tagbuf, par->codec_tag, par->codec_id, tagbuf2); ret = AVERROR_INVALIDDATA; goto fail; } } else - codec->codec_tag = av_codec_get_tag(of->codec_tag, codec->codec_id); + par->codec_tag = av_codec_get_tag(of->codec_tag, par->codec_id); } - if (codec->codec_type != AVMEDIA_TYPE_ATTACHMENT) + if (par->codec_type != AVMEDIA_TYPE_ATTACHMENT) s->internal->nb_interleaved_streams++; } @@ -421,12 +439,12 @@ static int init_pts(AVFormatContext *s) int64_t den = AV_NOPTS_VALUE; st = s->streams[i]; - switch (st->codec->codec_type) { + switch (st->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: - den = (int64_t)st->time_base.num * st->codec->sample_rate; + den = (int64_t)st->time_base.num * st->codecpar->sample_rate; break; case AVMEDIA_TYPE_VIDEO: - den = (int64_t)st->time_base.num * st->codec->time_base.den; + den = (int64_t)st->time_base.num * st->time_base.den; break; default: break; @@ -490,10 +508,11 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) #if FF_API_COMPUTE_PKT_FIELDS2 +FF_DISABLE_DEPRECATION_WARNINGS //FIXME merge with compute_pkt_fields static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket *pkt) { - int delay = FFMAX(st->codec->has_b_frames, st->codec->max_b_frames > 0); + int delay = FFMAX(st->codecpar->video_delay, st->internal->avctx->max_b_frames > 0); int num, den, i; int frame_size; @@ -553,8 +572,8 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket * if (st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) && - st->codec->codec_type != AVMEDIA_TYPE_SUBTITLE && - st->codec->codec_type != AVMEDIA_TYPE_DATA && + st->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE && + st->codecpar->codec_type != AVMEDIA_TYPE_DATA && st->cur_dts >= pkt->dts) || st->cur_dts > pkt->dts)) { av_log(s, AV_LOG_ERROR, "Application provided invalid, non monotonically increasing dts to muxer in stream %d: %s >= %s\n", @@ -591,11 +610,12 @@ static int compute_muxer_pkt_fields(AVFormatContext *s, AVStream *st, AVPacket * } break; case AVMEDIA_TYPE_VIDEO: - frac_add(st->priv_pts, (int64_t)st->time_base.den * st->codec->time_base.num); + frac_add(st->priv_pts, (int64_t)st->time_base.den * st->time_base.num); break; } return 0; } +FF_ENABLE_DEPRECATION_WARNINGS #endif /** @@ -715,7 +735,7 @@ static int check_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(EINVAL); } - if (s->streams[pkt->stream_index]->codec->codec_type == AVMEDIA_TYPE_ATTACHMENT) { + if (s->streams[pkt->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_ATTACHMENT) { av_log(s, AV_LOG_ERROR, "Received a packet for an attachment stream.\n"); return AVERROR(EINVAL); } @@ -853,7 +873,7 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, st->interleaver_chunk_size = 0; this_pktl->pkt.flags |= CHUNK_START; if (max && st->interleaver_chunk_duration > max) { - int64_t syncoffset = (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)*max/2; + int64_t syncoffset = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)*max/2; int64_t syncto = av_rescale(pkt->dts + syncoffset, 1, max)*max - syncoffset; st->interleaver_chunk_duration += (pkt->dts - syncto)/8 - max; @@ -898,12 +918,12 @@ static int interleave_compare_dts(AVFormatContext *s, AVPacket *next, AVStream *st2 = s->streams[next->stream_index]; int comp = av_compare_ts(next->dts, st2->time_base, pkt->dts, st->time_base); - if (s->audio_preload && ((st->codec->codec_type == AVMEDIA_TYPE_AUDIO) != (st2->codec->codec_type == AVMEDIA_TYPE_AUDIO))) { - int64_t ts = av_rescale_q(pkt ->dts, st ->time_base, AV_TIME_BASE_Q) - s->audio_preload*(st ->codec->codec_type == AVMEDIA_TYPE_AUDIO); - int64_t ts2= av_rescale_q(next->dts, st2->time_base, AV_TIME_BASE_Q) - s->audio_preload*(st2->codec->codec_type == AVMEDIA_TYPE_AUDIO); + if (s->audio_preload && ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) != (st2->codecpar->codec_type == AVMEDIA_TYPE_AUDIO))) { + int64_t ts = av_rescale_q(pkt ->dts, st ->time_base, AV_TIME_BASE_Q) - s->audio_preload*(st ->codecpar->codec_type == AVMEDIA_TYPE_AUDIO); + int64_t ts2= av_rescale_q(next->dts, st2->time_base, AV_TIME_BASE_Q) - s->audio_preload*(st2->codecpar->codec_type == AVMEDIA_TYPE_AUDIO); if (ts == ts2) { - ts= ( pkt ->dts* st->time_base.num*AV_TIME_BASE - s->audio_preload*(int64_t)(st ->codec->codec_type == AVMEDIA_TYPE_AUDIO)* st->time_base.den)*st2->time_base.den - -( next->dts*st2->time_base.num*AV_TIME_BASE - s->audio_preload*(int64_t)(st2->codec->codec_type == AVMEDIA_TYPE_AUDIO)*st2->time_base.den)* st->time_base.den; + ts= ( pkt ->dts* st->time_base.num*AV_TIME_BASE - s->audio_preload*(int64_t)(st ->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)* st->time_base.den)*st2->time_base.den + -( next->dts*st2->time_base.num*AV_TIME_BASE - s->audio_preload*(int64_t)(st2->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)*st2->time_base.den)* st->time_base.den; ts2=0; } comp= (ts>ts2) - (tsnb_streams; i++) { if (s->streams[i]->last_in_packet_buffer) { ++stream_count; - } else if (s->streams[i]->codec->codec_type != AVMEDIA_TYPE_ATTACHMENT && - s->streams[i]->codec->codec_id != AV_CODEC_ID_VP8 && - s->streams[i]->codec->codec_id != AV_CODEC_ID_VP9) { + } else if (s->streams[i]->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT && + s->streams[i]->codecpar->codec_id != AV_CODEC_ID_VP8 && + s->streams[i]->codecpar->codec_id != AV_CODEC_ID_VP9) { ++noninterleaved_count; } } @@ -1034,9 +1054,16 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) } } - av_apply_bitstream_filters(st->codec, pkt, st->internal->bsfc); + av_apply_bitstream_filters(st->internal->avctx, pkt, st->internal->bsfc); if (pkt->size == 0 && pkt->side_data_elems == 0) return 0; + if (!st->codecpar->extradata && st->internal->avctx->extradata) { + int eret = ff_alloc_extradata(st->codecpar, st->internal->avctx->extradata_size); + if (eret < 0) + return AVERROR(ENOMEM); + st->codecpar->extradata_size = st->internal->avctx->extradata_size; + memcpy(st->codecpar->extradata, st->internal->avctx->extradata, st->internal->avctx->extradata_size); + } if (s->debug & FF_FDEBUG_TS) av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame size:%d dts:%s pts:%s\n", diff --git a/libavformat/mvdec.c b/libavformat/mvdec.c index 7aa6452f66..80ef4b1569 100644 --- a/libavformat/mvdec.c +++ b/libavformat/mvdec.c @@ -106,9 +106,9 @@ static int set_channels(AVFormatContext *avctx, AVStream *st, int channels) av_log(avctx, AV_LOG_ERROR, "Channel count %d invalid.\n", channels); return AVERROR_INVALIDDATA; } - st->codec->channels = channels; - st->codec->channel_layout = (st->codec->channels == 1) ? AV_CH_LAYOUT_MONO - : AV_CH_LAYOUT_STEREO; + st->codecpar->channels = channels; + st->codecpar->channel_layout = (st->codecpar->channels == 1) ? AV_CH_LAYOUT_MONO + : AV_CH_LAYOUT_STEREO; return 0; } @@ -156,10 +156,10 @@ static int parse_audio_var(AVFormatContext *avctx, AVStream *st, } else if (!strcmp(name, "NUM_CHANNELS")) { return set_channels(avctx, st, var_read_int(pb, size)); } else if (!strcmp(name, "SAMPLE_RATE")) { - st->codec->sample_rate = var_read_int(pb, size); - avpriv_set_pts_info(st, 33, 1, st->codec->sample_rate); + st->codecpar->sample_rate = var_read_int(pb, size); + avpriv_set_pts_info(st, 33, 1, st->codecpar->sample_rate); } else if (!strcmp(name, "SAMPLE_WIDTH")) { - st->codec->bits_per_coded_sample = var_read_int(pb, size) * 8; + st->codecpar->bits_per_coded_sample = var_read_int(pb, size) * 8; } else return AVERROR_INVALIDDATA; @@ -181,16 +181,16 @@ static int parse_video_var(AVFormatContext *avctx, AVStream *st, if (!str) return AVERROR_INVALIDDATA; if (!strcmp(str, "1")) { - st->codec->codec_id = AV_CODEC_ID_MVC1; + st->codecpar->codec_id = AV_CODEC_ID_MVC1; } else if (!strcmp(str, "2")) { - st->codec->pix_fmt = AV_PIX_FMT_ABGR; - st->codec->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->format = AV_PIX_FMT_ABGR; + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; } else if (!strcmp(str, "3")) { - st->codec->codec_id = AV_CODEC_ID_SGIRLE; + st->codecpar->codec_id = AV_CODEC_ID_SGIRLE; } else if (!strcmp(str, "10")) { - st->codec->codec_id = AV_CODEC_ID_MJPEG; + st->codecpar->codec_id = AV_CODEC_ID_MJPEG; } else if (!strcmp(str, "MVC2")) { - st->codec->codec_id = AV_CODEC_ID_MVC2; + st->codecpar->codec_id = AV_CODEC_ID_MVC2; } else { avpriv_request_sample(avctx, "Video compression %s", str); } @@ -200,18 +200,18 @@ static int parse_video_var(AVFormatContext *avctx, AVStream *st, avpriv_set_pts_info(st, 64, fps.den, fps.num); st->avg_frame_rate = fps; } else if (!strcmp(name, "HEIGHT")) { - st->codec->height = var_read_int(pb, size); + st->codecpar->height = var_read_int(pb, size); } else if (!strcmp(name, "PIXEL_ASPECT")) { st->sample_aspect_ratio = var_read_float(pb, size); av_reduce(&st->sample_aspect_ratio.num, &st->sample_aspect_ratio.den, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, INT_MAX); } else if (!strcmp(name, "WIDTH")) { - st->codec->width = var_read_int(pb, size); + st->codecpar->width = var_read_int(pb, size); } else if (!strcmp(name, "ORIENTATION")) { if (var_read_int(pb, size) == 1101) { - st->codec->extradata = av_strdup("BottomUp"); - st->codec->extradata_size = 9; + st->codecpar->extradata = av_strdup("BottomUp"); + st->codecpar->extradata_size = 9; } } else if (!strcmp(name, "Q_SPATIAL") || !strcmp(name, "Q_TEMPORAL")) { var_read_metadata(avctx, name, size); @@ -259,8 +259,8 @@ static void read_index(AVIOContext *pb, AVStream *st) uint32_t size = avio_rb32(pb); avio_skip(pb, 8); av_add_index_entry(st, pos, timestamp, size, 0, AVINDEX_KEYFRAME); - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - timestamp += size / (st->codec->channels * 2); + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + timestamp += size / (st->codecpar->channels * 2); } else { timestamp++; } @@ -293,37 +293,37 @@ static int mv_read_header(AVFormatContext *avctx) if (!vst) return AVERROR(ENOMEM); avpriv_set_pts_info(vst, 64, 1, 15); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; vst->avg_frame_rate = av_inv_q(vst->time_base); vst->nb_frames = avio_rb32(pb); v = avio_rb32(pb); switch (v) { case 1: - vst->codec->codec_id = AV_CODEC_ID_MVC1; + vst->codecpar->codec_id = AV_CODEC_ID_MVC1; break; case 2: - vst->codec->pix_fmt = AV_PIX_FMT_ARGB; - vst->codec->codec_id = AV_CODEC_ID_RAWVIDEO; + vst->codecpar->format = AV_PIX_FMT_ARGB; + vst->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; break; default: avpriv_request_sample(avctx, "Video compression %i", v); break; } - vst->codec->codec_tag = 0; - vst->codec->width = avio_rb32(pb); - vst->codec->height = avio_rb32(pb); + vst->codecpar->codec_tag = 0; + vst->codecpar->width = avio_rb32(pb); + vst->codecpar->height = avio_rb32(pb); avio_skip(pb, 12); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; ast->nb_frames = vst->nb_frames; - ast->codec->sample_rate = avio_rb32(pb); - avpriv_set_pts_info(ast, 33, 1, ast->codec->sample_rate); + ast->codecpar->sample_rate = avio_rb32(pb); + avpriv_set_pts_info(ast, 33, 1, ast->codecpar->sample_rate); if (set_channels(avctx, ast, avio_rb32(pb)) < 0) return AVERROR_INVALIDDATA; v = avio_rb32(pb); if (v == AUDIO_FORMAT_SIGNED) { - ast->codec->codec_id = AV_CODEC_ID_PCM_S16BE; + ast->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE; } else { avpriv_request_sample(avctx, "Audio compression (format %i)", v); } @@ -341,7 +341,7 @@ static int mv_read_header(AVFormatContext *avctx) avio_skip(pb, 8); av_add_index_entry(ast, pos, timestamp, asize, 0, AVINDEX_KEYFRAME); av_add_index_entry(vst, pos + asize, i, vsize, 0, AVINDEX_KEYFRAME); - timestamp += asize / (ast->codec->channels * 2); + timestamp += asize / (ast->codecpar->channels * 2); } } else if (!version && avio_rb16(pb) == 3) { avio_skip(pb, 4); @@ -356,21 +356,21 @@ static int mv_read_header(AVFormatContext *avctx) ast = avformat_new_stream(avctx, NULL); if (!ast) return AVERROR(ENOMEM); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; if ((read_table(avctx, ast, parse_audio_var)) < 0) return ret; if (mv->acompression == 100 && mv->aformat == AUDIO_FORMAT_SIGNED && - ast->codec->bits_per_coded_sample == 16) { - ast->codec->codec_id = AV_CODEC_ID_PCM_S16BE; + ast->codecpar->bits_per_coded_sample == 16) { + ast->codecpar->codec_id = AV_CODEC_ID_PCM_S16BE; } else { avpriv_request_sample(avctx, "Audio compression %i (format %i, sr %i)", mv->acompression, mv->aformat, - ast->codec->bits_per_coded_sample); - ast->codec->codec_id = AV_CODEC_ID_NONE; + ast->codecpar->bits_per_coded_sample); + ast->codecpar->codec_id = AV_CODEC_ID_NONE; } - if (ast->codec->channels <= 0) { + if (ast->codecpar->channels <= 0) { av_log(avctx, AV_LOG_ERROR, "No valid channel count found.\n"); return AVERROR_INVALIDDATA; } @@ -383,7 +383,7 @@ static int mv_read_header(AVFormatContext *avctx) vst = avformat_new_stream(avctx, NULL); if (!vst) return AVERROR(ENOMEM); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; if ((ret = read_table(avctx, vst, parse_video_var))<0) return ret; } diff --git a/libavformat/mvi.c b/libavformat/mvi.c index a7cfcb9a7a..9f90faf56b 100644 --- a/libavformat/mvi.c +++ b/libavformat/mvi.c @@ -54,18 +54,18 @@ static int read_header(AVFormatContext *s) if (!vst) return AVERROR(ENOMEM); - if (ff_alloc_extradata(vst->codec, 2)) + if (ff_alloc_extradata(vst->codecpar, 2)) return AVERROR(ENOMEM); version = avio_r8(pb); - vst->codec->extradata[0] = avio_r8(pb); - vst->codec->extradata[1] = avio_r8(pb); + vst->codecpar->extradata[0] = avio_r8(pb); + vst->codecpar->extradata[1] = avio_r8(pb); frames_count = avio_rl32(pb); msecs_per_frame = avio_rl32(pb); - vst->codec->width = avio_rl16(pb); - vst->codec->height = avio_rl16(pb); + vst->codecpar->width = avio_rl16(pb); + vst->codecpar->height = avio_rl16(pb); avio_r8(pb); - ast->codec->sample_rate = avio_rl16(pb); + ast->codecpar->sample_rate = avio_rl16(pb); mvi->audio_data_size = avio_rl32(pb); avio_r8(pb); player_version = avio_rl32(pb); @@ -80,20 +80,20 @@ static int read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; } - avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = AV_CODEC_ID_PCM_U8; - ast->codec->channels = 1; - ast->codec->channel_layout = AV_CH_LAYOUT_MONO; - ast->codec->bits_per_coded_sample = 8; - ast->codec->bit_rate = ast->codec->sample_rate * 8; + avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate); + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = AV_CODEC_ID_PCM_U8; + ast->codecpar->channels = 1; + ast->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + ast->codecpar->bits_per_coded_sample = 8; + ast->codecpar->bit_rate = ast->codecpar->sample_rate * 8; avpriv_set_pts_info(vst, 64, msecs_per_frame, 1000000); vst->avg_frame_rate = av_inv_q(vst->time_base); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_MOTIONPIXELS; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_MOTIONPIXELS; - mvi->get_int = (vst->codec->width * vst->codec->height < (1 << 16)) ? avio_rl16 : avio_rl24; + mvi->get_int = (vst->codecpar->width * vst->codecpar->height < (1 << 16)) ? avio_rl16 : avio_rl24; mvi->audio_frame_size = ((uint64_t)mvi->audio_data_size << MVI_FRAC_BITS) / frames_count; if (mvi->audio_frame_size <= 1 << MVI_FRAC_BITS - 1) { @@ -103,7 +103,7 @@ static int read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; } - mvi->audio_size_counter = (ast->codec->sample_rate * 830 / mvi->audio_frame_size - 1) * mvi->audio_frame_size; + mvi->audio_size_counter = (ast->codecpar->sample_rate * 830 / mvi->audio_frame_size - 1) * mvi->audio_frame_size; mvi->audio_size_left = mvi->audio_data_size; return 0; diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 40b4d79996..f8cf92283f 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -405,15 +405,15 @@ static int mxf_get_d10_aes3_packet(AVIOContext *pb, AVStream *st, AVPacket *pkt, data_ptr = pkt->data; end_ptr = pkt->data + length; buf_ptr = pkt->data + 4; /* skip SMPTE 331M header */ - for (; end_ptr - buf_ptr >= st->codec->channels * 4; ) { - for (i = 0; i < st->codec->channels; i++) { + for (; end_ptr - buf_ptr >= st->codecpar->channels * 4; ) { + for (i = 0; i < st->codecpar->channels; i++) { uint32_t sample = bytestream_get_le32(&buf_ptr); - if (st->codec->bits_per_coded_sample == 24) + if (st->codecpar->bits_per_coded_sample == 24) bytestream_put_le24(&data_ptr, (sample >> 4) & 0xffffff); else bytestream_put_le16(&data_ptr, (sample >> 12) & 0xffff); } - buf_ptr += 32 - st->codec->channels*4; // always 8 channels stored SMPTE 331M + buf_ptr += 32 - st->codecpar->channels*4; // always 8 channels stored SMPTE 331M } av_shrink_packet(pkt, data_ptr - pkt->data); return 0; @@ -1969,7 +1969,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) PRINT_KEY(mxf->fc, "data definition ul", source_track->sequence->data_definition_ul); codec_ul = mxf_get_codec_ul(ff_mxf_data_definition_uls, &source_track->sequence->data_definition_ul); - st->codec->codec_type = codec_ul->id; + st->codecpar->codec_type = codec_ul->id; if (!descriptor) { av_log(mxf->fc, AV_LOG_INFO, "source track %d: stream %d, no descriptor found\n", source_track->track_id, st->index); @@ -1993,14 +1993,14 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) /* TODO: drop PictureEssenceCoding and SoundEssenceCompression, only check EssenceContainer */ codec_ul = mxf_get_codec_ul(ff_mxf_codec_uls, &descriptor->essence_codec_ul); - st->codec->codec_id = (enum AVCodecID)codec_ul->id; - if (st->codec->codec_id == AV_CODEC_ID_NONE) { + st->codecpar->codec_id = (enum AVCodecID)codec_ul->id; + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) { codec_ul = mxf_get_codec_ul(ff_mxf_codec_uls, &descriptor->codec_ul); - st->codec->codec_id = (enum AVCodecID)codec_ul->id; + st->codecpar->codec_id = (enum AVCodecID)codec_ul->id; } av_log(mxf->fc, AV_LOG_VERBOSE, "%s: Universal Label: ", - avcodec_get_name(st->codec->codec_id)); + avcodec_get_name(st->codecpar->codec_id)); for (k = 0; k < 16; k++) { av_log(mxf->fc, AV_LOG_VERBOSE, "%.2x", descriptor->essence_codec_ul[k]); @@ -2015,16 +2015,16 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) mxf_parse_physical_source_package(mxf, source_track, st); - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { source_track->intra_only = mxf_is_intra_only(descriptor); container_ul = mxf_get_codec_ul(mxf_picture_essence_container_uls, essence_container_ul); - if (st->codec->codec_id == AV_CODEC_ID_NONE) - st->codec->codec_id = container_ul->id; - st->codec->width = descriptor->width; - st->codec->height = descriptor->height; /* Field height, not frame height */ + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) + st->codecpar->codec_id = container_ul->id; + st->codecpar->width = descriptor->width; + st->codecpar->height = descriptor->height; /* Field height, not frame height */ switch (descriptor->frame_layout) { case FullFrame: - st->codec->field_order = AV_FIELD_PROGRESSIVE; + st->codecpar->field_order = AV_FIELD_PROGRESSIVE; break; case OneField: /* Every other line is stored and needs to be duplicated. */ @@ -2035,14 +2035,14 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) case MixedFields: break; case SegmentedFrame: - st->codec->field_order = AV_FIELD_PROGRESSIVE; + st->codecpar->field_order = AV_FIELD_PROGRESSIVE; case SeparateFields: switch (descriptor->field_dominance) { case MXF_TFF: - st->codec->field_order = AV_FIELD_TT; + st->codecpar->field_order = AV_FIELD_TT; break; case MXF_BFF: - st->codec->field_order = AV_FIELD_BB; + st->codecpar->field_order = AV_FIELD_BB; break; default: avpriv_request_sample(mxf->fc, @@ -2052,27 +2052,27 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) break; } /* Turn field height into frame height. */ - st->codec->height *= 2; + st->codecpar->height *= 2; break; default: av_log(mxf->fc, AV_LOG_INFO, "Unknown frame layout type: %d\n", descriptor->frame_layout); } - if (st->codec->codec_id == AV_CODEC_ID_RAWVIDEO) { - st->codec->pix_fmt = descriptor->pix_fmt; - if (st->codec->pix_fmt == AV_PIX_FMT_NONE) { + if (st->codecpar->codec_id == AV_CODEC_ID_RAWVIDEO) { + st->codecpar->format = descriptor->pix_fmt; + if (st->codecpar->format == AV_PIX_FMT_NONE) { pix_fmt_ul = mxf_get_codec_ul(ff_mxf_pixel_format_uls, &descriptor->essence_codec_ul); - st->codec->pix_fmt = (enum AVPixelFormat)pix_fmt_ul->id; - if (st->codec->pix_fmt == AV_PIX_FMT_NONE) { - st->codec->codec_tag = mxf_get_codec_ul(ff_mxf_codec_tag_uls, - &descriptor->essence_codec_ul)->id; - if (!st->codec->codec_tag) { + st->codecpar->format = (enum AVPixelFormat)pix_fmt_ul->id; + if (st->codecpar->format== AV_PIX_FMT_NONE) { + st->codecpar->codec_tag = mxf_get_codec_ul(ff_mxf_codec_tag_uls, + &descriptor->essence_codec_ul)->id; + if (!st->codecpar->codec_tag) { /* support files created before RP224v10 by defaulting to UYVY422 if subsampling is 4:2:2 and component depth is 8-bit */ if (descriptor->horiz_subsampling == 2 && descriptor->vert_subsampling == 1 && descriptor->component_depth == 8) { - st->codec->pix_fmt = AV_PIX_FMT_UYVY422; + st->codecpar->format = AV_PIX_FMT_UYVY422; } } } @@ -2087,16 +2087,16 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } if (descriptor->aspect_ratio.num && descriptor->aspect_ratio.den) st->display_aspect_ratio = descriptor->aspect_ratio; - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { container_ul = mxf_get_codec_ul(mxf_sound_essence_container_uls, essence_container_ul); /* Only overwrite existing codec ID if it is unset or A-law, which is the default according to SMPTE RP 224. */ - if (st->codec->codec_id == AV_CODEC_ID_NONE || (st->codec->codec_id == AV_CODEC_ID_PCM_ALAW && (enum AVCodecID)container_ul->id != AV_CODEC_ID_NONE)) - st->codec->codec_id = (enum AVCodecID)container_ul->id; - st->codec->channels = descriptor->channels; - st->codec->bits_per_coded_sample = descriptor->bits_per_sample; + if (st->codecpar->codec_id == AV_CODEC_ID_NONE || (st->codecpar->codec_id == AV_CODEC_ID_PCM_ALAW && (enum AVCodecID)container_ul->id != AV_CODEC_ID_NONE)) + st->codecpar->codec_id = (enum AVCodecID)container_ul->id; + st->codecpar->channels = descriptor->channels; + st->codecpar->bits_per_coded_sample = descriptor->bits_per_sample; if (descriptor->sample_rate.den > 0) { - st->codec->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den; + st->codecpar->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den; avpriv_set_pts_info(st, 64, descriptor->sample_rate.den, descriptor->sample_rate.num); } else { av_log(mxf->fc, AV_LOG_WARNING, "invalid sample rate (%d/%d) " @@ -2113,20 +2113,20 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) st->time_base); /* TODO: implement AV_CODEC_ID_RAWAUDIO */ - if (st->codec->codec_id == AV_CODEC_ID_PCM_S16LE) { + if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16LE) { if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24) - st->codec->codec_id = AV_CODEC_ID_PCM_S24LE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S24LE; else if (descriptor->bits_per_sample == 32) - st->codec->codec_id = AV_CODEC_ID_PCM_S32LE; - } else if (st->codec->codec_id == AV_CODEC_ID_PCM_S16BE) { + st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE; + } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE) { if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24) - st->codec->codec_id = AV_CODEC_ID_PCM_S24BE; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S24BE; else if (descriptor->bits_per_sample == 32) - st->codec->codec_id = AV_CODEC_ID_PCM_S32BE; - } else if (st->codec->codec_id == AV_CODEC_ID_MP2) { + st->codecpar->codec_id = AV_CODEC_ID_PCM_S32BE; + } else if (st->codecpar->codec_id == AV_CODEC_ID_MP2) { st->need_parsing = AVSTREAM_PARSE_FULL; } - } else if (st->codec->codec_type == AVMEDIA_TYPE_DATA) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA) { int codec_id = mxf_get_codec_ul(mxf_data_essence_container_uls, essence_container_ul)->id; if (codec_id >= 0 && @@ -2136,19 +2136,19 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) } } if (descriptor->extradata) { - if (!ff_alloc_extradata(st->codec, descriptor->extradata_size)) { - memcpy(st->codec->extradata, descriptor->extradata, descriptor->extradata_size); + if (!ff_alloc_extradata(st->codecpar, descriptor->extradata_size)) { + memcpy(st->codecpar->extradata, descriptor->extradata, descriptor->extradata_size); } - } else if (st->codec->codec_id == AV_CODEC_ID_H264) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_H264) { int coded_width = mxf_get_codec_ul(mxf_intra_only_picture_coded_width, &descriptor->essence_codec_ul)->id; if (coded_width) - st->codec->width = coded_width; + st->codecpar->width = coded_width; ret = ff_generate_avci_extradata(st); if (ret < 0) return ret; } - if (st->codec->codec_type != AVMEDIA_TYPE_DATA && (*essence_container_ul)[15] > 0x01) { + if (st->codecpar->codec_type != AVMEDIA_TYPE_DATA && (*essence_container_ul)[15] > 0x01) { /* TODO: decode timestamps */ st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; } @@ -2579,8 +2579,8 @@ static void mxf_handle_small_eubc(AVFormatContext *s) /* expect PCM with exactly one index table segment and a small (< 32) EUBC */ if (s->nb_streams != 1 || - s->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO || - !is_pcm(s->streams[0]->codec->codec_id) || + s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || + !is_pcm(s->streams[0]->codecpar->codec_id) || mxf->nb_index_tables != 1 || mxf->index_tables[0].nb_segments != 1 || mxf->index_tables[0].segments[0]->edit_unit_byte_count >= 32) @@ -2609,7 +2609,7 @@ static int mxf_handle_missing_index_segment(MXFContext *mxf) return 0; /* TODO: support raw video without an index if they exist */ - if (s->nb_streams != 1 || s->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO || !is_pcm(s->streams[0]->codec->codec_id)) + if (s->nb_streams != 1 || s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_AUDIO || !is_pcm(s->streams[0]->codecpar->codec_id)) return 0; /* check if file already has a IndexTableSegment */ @@ -2643,7 +2643,7 @@ static int mxf_handle_missing_index_segment(MXFContext *mxf) st = s->streams[0]; segment->type = IndexTableSegment; /* stream will be treated as small EditUnitByteCount */ - segment->edit_unit_byte_count = (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3; + segment->edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->channels) >> 3; segment->index_start_position = 0; segment->index_duration = s->streams[0]->duration; segment->index_sid = p->index_sid; @@ -2918,22 +2918,22 @@ static int mxf_compute_sample_count(MXFContext *mxf, int stream_index, return 0; } -static int mxf_set_audio_pts(MXFContext *mxf, AVCodecContext *codec, +static int mxf_set_audio_pts(MXFContext *mxf, AVCodecParameters *par, AVPacket *pkt) { MXFTrack *track = mxf->fc->streams[pkt->stream_index]->priv_data; - int64_t bits_per_sample = codec->bits_per_coded_sample; + int64_t bits_per_sample = par->bits_per_coded_sample; if (!bits_per_sample) - bits_per_sample = av_get_bits_per_sample(codec->codec_id); + bits_per_sample = av_get_bits_per_sample(par->codec_id); pkt->pts = track->sample_count; - if ( codec->channels <= 0 + if ( par->channels <= 0 || bits_per_sample <= 0 - || codec->channels * (int64_t)bits_per_sample < 8) + || par->channels * (int64_t)bits_per_sample < 8) return AVERROR(EINVAL); - track->sample_count += pkt->size / (codec->channels * (int64_t)bits_per_sample / 8); + track->sample_count += pkt->size / (par->channels * (int64_t)bits_per_sample / 8); return 0; } @@ -2961,7 +2961,7 @@ static int mxf_read_packet_old(AVFormatContext *s, AVPacket *pkt) int64_t next_ofs, next_klv; AVStream *st; MXFTrack *track; - AVCodecContext *codec; + AVCodecParameters *par; if (index < 0) { av_log(s, AV_LOG_ERROR, @@ -3006,9 +3006,9 @@ static int mxf_read_packet_old(AVFormatContext *s, AVPacket *pkt) pkt->stream_index = index; pkt->pos = klv.offset; - codec = st->codec; + par = st->codecpar; - if (codec->codec_type == AVMEDIA_TYPE_VIDEO && next_ofs >= 0) { + if (par->codec_type == AVMEDIA_TYPE_VIDEO && next_ofs >= 0) { /* mxf->current_edit_unit good - see if we have an * index table to derive timestamps from */ MXFIndexTable *t = &mxf->index_tables[0]; @@ -3021,8 +3021,8 @@ static int mxf_read_packet_old(AVFormatContext *s, AVPacket *pkt) * let utils.c figure out DTS since it can be < PTS if low_delay = 0 (Sony IMX30) */ pkt->pts = mxf->current_edit_unit; } - } else if (codec->codec_type == AVMEDIA_TYPE_AUDIO) { - ret = mxf_set_audio_pts(mxf, codec, pkt); + } else if (par->codec_type == AVMEDIA_TYPE_AUDIO) { + ret = mxf_set_audio_pts(mxf, par, pkt); if (ret < 0) return ret; } @@ -3088,12 +3088,12 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->stream_index = 0; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && t->ptses && + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && t->ptses && mxf->current_edit_unit >= 0 && mxf->current_edit_unit < t->nb_ptses) { pkt->dts = mxf->current_edit_unit + t->first_dts; pkt->pts = t->ptses[mxf->current_edit_unit]; - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - int ret = mxf_set_audio_pts(mxf, st->codec, pkt); + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + int ret = mxf_set_audio_pts(mxf, st->codecpar, pkt); if (ret < 0) return ret; } @@ -3172,7 +3172,7 @@ static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti MXFTrack *source_track = st->priv_data; /* if audio then truncate sample_time to EditRate */ - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) sample_time = av_rescale_q(sample_time, st->time_base, av_inv_q(source_track->edit_rate)); @@ -3231,7 +3231,7 @@ static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti AVStream *cur_st = s->streams[i]; MXFTrack *cur_track = cur_st->priv_data; uint64_t current_sample_count = 0; - if (cur_st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (cur_st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { ret = mxf_compute_sample_count(mxf, i, ¤t_sample_count); if (ret < 0) return ret; diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index cd13f89787..36a43e4a41 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -834,14 +834,14 @@ static void mxf_write_common_fields(AVFormatContext *s, AVStream *st) if (st == mxf->timecode_track) avio_write(pb, smpte_12m_timecode_track_data_ul, 16); else { - const MXFCodecUL *data_def_ul = mxf_get_data_definition_ul(st->codec->codec_type); + const MXFCodecUL *data_def_ul = mxf_get_data_definition_ul(st->codecpar->codec_type); avio_write(pb, data_def_ul->uid, 16); } // write duration mxf_write_local_tag(pb, 8, 0x0202); - if (st != mxf->timecode_track && s->oformat == &ff_mxf_opatom_muxer && st->codec->codec_type == AVMEDIA_TYPE_AUDIO){ + if (st != mxf->timecode_track && s->oformat == &ff_mxf_opatom_muxer && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO){ avio_wb64(pb, mxf->body_offset / mxf->edit_unit_byte_count); } else { avio_wb64(pb, mxf->duration); @@ -1010,7 +1010,7 @@ static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke { MXFStreamContext *sc = st->priv_data; AVIOContext *pb = s->pb; - int stored_height = (st->codec->height+15)/16*16; + int stored_height = (st->codecpar->height+15)/16*16; int display_height; int f1, f2; unsigned desc_size = size+8+8+8+8+8+8+8+5+16+4+12+20+5; @@ -1022,27 +1022,27 @@ static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke mxf_write_generic_desc(s, st, key, desc_size); mxf_write_local_tag(pb, 4, 0x3203); - avio_wb32(pb, st->codec->width); + avio_wb32(pb, st->codecpar->width); mxf_write_local_tag(pb, 4, 0x3202); avio_wb32(pb, stored_height>>sc->interlaced); mxf_write_local_tag(pb, 4, 0x3209); - avio_wb32(pb, st->codec->width); + avio_wb32(pb, st->codecpar->width); - if (st->codec->height == 608) // PAL + VBI + if (st->codecpar->height == 608) // PAL + VBI display_height = 576; - else if (st->codec->height == 512) // NTSC + VBI + else if (st->codecpar->height == 512) // NTSC + VBI display_height = 486; else - display_height = st->codec->height; + display_height = st->codecpar->height; mxf_write_local_tag(pb, 4, 0x3208); avio_wb32(pb, display_height>>sc->interlaced); // presentation Y offset mxf_write_local_tag(pb, 4, 0x320B); - avio_wb32(pb, (st->codec->height - display_height)>>sc->interlaced); + avio_wb32(pb, (st->codecpar->height - display_height)>>sc->interlaced); // component depth mxf_write_local_tag(pb, 4, 0x3301); @@ -1066,10 +1066,10 @@ static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID ke avio_w8(pb, sc->interlaced); // video line map - switch (st->codec->height) { - case 576: f1 = 23; f2 = st->codec->codec_id == AV_CODEC_ID_DVVIDEO ? 335 : 336; break; + switch (st->codecpar->height) { + case 576: f1 = 23; f2 = st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO ? 335 : 336; break; case 608: f1 = 7; f2 = 320; break; - case 480: f1 = 20; f2 = st->codec->codec_id == AV_CODEC_ID_DVVIDEO ? 285 : 283; break; + case 480: f1 = 20; f2 = st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO ? 285 : 283; break; case 512: f1 = 7; f2 = 270; break; case 720: f1 = 26; f2 = 0; break; // progressive case 1080: f1 = 21; f2 = 584; break; @@ -1111,9 +1111,9 @@ static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st) { AVIOContext *pb = s->pb; MXFStreamContext *sc = st->priv_data; - int profile_and_level = (st->codec->profile<<4) | st->codec->level; + int profile_and_level = (st->codecpar->profile<<4) | st->codecpar->level; - if (st->codec->codec_id != AV_CODEC_ID_H264) { + if (st->codecpar->codec_id != AV_CODEC_ID_H264) { mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key, 8+5); // bit rate @@ -1122,7 +1122,7 @@ static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st) // profile and level mxf_write_local_tag(pb, 1, 0x8007); - if (!st->codec->profile) + if (!st->codecpar->profile) profile_and_level |= 0x80; // escape bit avio_w8(pb, profile_and_level); } else { @@ -1153,16 +1153,16 @@ static void mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, con // write audio sampling rate mxf_write_local_tag(pb, 8, 0x3D03); - avio_wb32(pb, st->codec->sample_rate); + avio_wb32(pb, st->codecpar->sample_rate); avio_wb32(pb, 1); mxf_write_local_tag(pb, 4, 0x3D07); if (mxf->channel_count == -1) { - if (show_warnings && (s->oformat == &ff_mxf_d10_muxer) && (st->codec->channels != 4) && (st->codec->channels != 8)) + if (show_warnings && (s->oformat == &ff_mxf_d10_muxer) && (st->codecpar->channels != 4) && (st->codecpar->channels != 8)) av_log(s, AV_LOG_WARNING, "the number of audio channels shall be 4 or 8 : the output will not comply to MXF D-10 specs, use -d10_channelcount to fix this\n"); - avio_wb32(pb, st->codec->channels); + avio_wb32(pb, st->codecpar->channels); } else if (s->oformat == &ff_mxf_d10_muxer) { - if (show_warnings && (mxf->channel_count < st->codec->channels)) + if (show_warnings && (mxf->channel_count < st->codecpar->channels)) av_log(s, AV_LOG_WARNING, "d10_channelcount < actual number of audio channels : some channels will be discarded\n"); if (show_warnings && (mxf->channel_count != 4) && (mxf->channel_count != 8)) av_log(s, AV_LOG_WARNING, "d10_channelcount shall be set to 4 or 8 : the output will not comply to MXF D-10 specs\n"); @@ -1170,11 +1170,11 @@ static void mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, con } else { if (show_warnings && mxf->channel_count != -1 && s->oformat != &ff_mxf_opatom_muxer) av_log(s, AV_LOG_ERROR, "-d10_channelcount requires MXF D-10 and will be ignored\n"); - avio_wb32(pb, st->codec->channels); + avio_wb32(pb, st->codecpar->channels); } mxf_write_local_tag(pb, 4, 0x3D01); - avio_wb32(pb, av_get_bits_per_sample(st->codec->codec_id)); + avio_wb32(pb, av_get_bits_per_sample(st->codecpar->codec_id)); } static void mxf_write_wav_common(AVFormatContext *s, AVStream *st, const UID key, unsigned size) @@ -1184,11 +1184,11 @@ static void mxf_write_wav_common(AVFormatContext *s, AVStream *st, const UID key mxf_write_generic_sound_common(s, st, key, size+6+8); mxf_write_local_tag(pb, 2, 0x3D0A); - avio_wb16(pb, st->codec->block_align); + avio_wb16(pb, st->codecpar->block_align); // avg bytes per sec mxf_write_local_tag(pb, 4, 0x3D09); - avio_wb32(pb, st->codec->block_align*st->codec->sample_rate); + avio_wb32(pb, st->codecpar->block_align*st->codecpar->sample_rate); } static void mxf_write_wav_desc(AVFormatContext *s, AVStream *st) @@ -1729,10 +1729,10 @@ AVPacket *pkt) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; MXFStreamContext *sc = st->priv_data; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { mxf->edit_unit_byte_count += 16 + 4 + sc->aic.samples[0]*sc->aic.sample_size; mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count); - } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { mxf->edit_unit_byte_count += 16 + 4 + frame_size; mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count); } @@ -1804,10 +1804,10 @@ static int mxf_parse_dv_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; MXFStreamContext *sc = st->priv_data; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { mxf->edit_unit_byte_count += 16 + 4 + sc->aic.samples[0]*sc->aic.sample_size; mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count); - } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { mxf->edit_unit_byte_count += 16 + 4 + frame_size; mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count); } @@ -1861,7 +1861,7 @@ static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st, --buf; switch (state & 0x1f) { case NAL_SPS: - st->codec->profile = buf[1]; + st->codecpar->profile = buf[1]; e->flags |= 0x40; break; case NAL_PPS: @@ -1881,7 +1881,7 @@ static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st, sc->aspect_ratio = (AVRational){ 16, 9 }; // 16:9 is mandatory for broadcast HD sc->component_depth = 10; // AVC Intra is always 10 Bit - sc->interlaced = st->codec->field_order != AV_FIELD_PROGRESSIVE ? 1 : 0; + sc->interlaced = st->codecpar->field_order != AV_FIELD_PROGRESSIVE ? 1 : 0; if (sc->interlaced) sc->field_dominance = 1; // top field first is mandatory for AVC Intra @@ -1891,7 +1891,7 @@ static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st, if (frame_size == mxf_h264_codec_uls[i].frame_size && sc->interlaced == mxf_h264_codec_uls[i].interlaced) { sc->codec_ul = &mxf_h264_codec_uls[i].uid; return 1; - } else if (st->codec->profile == mxf_h264_codec_uls[i].profile) { + } else if (st->codecpar->profile == mxf_h264_codec_uls[i].profile) { sc->codec_ul = &mxf_h264_codec_uls[i].uid; uid_found = 1; } @@ -1918,21 +1918,21 @@ static const UID mxf_mpeg2_codec_uls[] = { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x03,0x00 }, // MP@H-14 Long GOP }; -static const UID *mxf_get_mpeg2_codec_ul(AVCodecContext *avctx) +static const UID *mxf_get_mpeg2_codec_ul(AVCodecParameters *par) { int long_gop = 1; - if (avctx->profile == 4) { // Main - if (avctx->level == 8) // Main + if (par->profile == 4) { // Main + if (par->level == 8) // Main return &mxf_mpeg2_codec_uls[0+long_gop]; - else if (avctx->level == 4) // High + else if (par->level == 4) // High return &mxf_mpeg2_codec_uls[4+long_gop]; - else if (avctx->level == 6) // High 14 + else if (par->level == 6) // High 14 return &mxf_mpeg2_codec_uls[8+long_gop]; - } else if (avctx->profile == 0) { // 422 - if (avctx->level == 5) // Main + } else if (par->profile == 0) { // 422 + if (par->level == 5) // Main return &mxf_mpeg2_codec_uls[2+long_gop]; - else if (avctx->level == 2) // High + else if (par->level == 2) // High return &mxf_mpeg2_codec_uls[6+long_gop]; } return NULL; @@ -1949,8 +1949,8 @@ static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, c = (c<<8) + pkt->data[i]; if (c == 0x1b5) { if ((pkt->data[i+1] & 0xf0) == 0x10) { // seq ext - st->codec->profile = pkt->data[i+1] & 0x07; - st->codec->level = pkt->data[i+2] >> 4; + st->codecpar->profile = pkt->data[i+1] & 0x07; + st->codecpar->level = pkt->data[i+2] >> 4; } else if (i + 5 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x80) { // pict coding ext sc->interlaced = !(pkt->data[i+5] & 0x80); // progressive frame if (sc->interlaced) @@ -1971,7 +1971,7 @@ static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, case 4: sc->aspect_ratio = (AVRational){221,100}; break; default: av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den, - st->codec->width, st->codec->height, 1024*1024); + st->codecpar->width, st->codecpar->height, 1024*1024); } } else if (c == 0x100) { // pic int pict_type = (pkt->data[i+2]>>3) & 0x07; @@ -1992,7 +1992,7 @@ static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, } } if (s->oformat != &ff_mxf_d10_muxer) - sc->codec_ul = mxf_get_mpeg2_codec_ul(st->codec); + sc->codec_ul = mxf_get_mpeg2_codec_ul(st->codecpar); return !!sc->codec_ul; } @@ -2061,13 +2061,13 @@ static int mxf_write_header(AVFormatContext *s) return AVERROR(ENOMEM); st->priv_data = sc; - if (((i == 0) ^ (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)) && s->oformat != &ff_mxf_opatom_muxer) { + if (((i == 0) ^ (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)) && s->oformat != &ff_mxf_opatom_muxer) { av_log(s, AV_LOG_ERROR, "there must be exactly one video stream and it must be the first one\n"); return -1; } - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { - const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codec->pix_fmt); + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(st->codecpar->format); // TODO: should be avg_frame_rate AVRational rate, tbc = st->time_base; // Default component depth to 8 @@ -2099,7 +2099,7 @@ static int mxf_write_header(AVFormatContext *s) if((ret = mxf_init_timecode(s, st, rate)) < 0) return ret; - sc->video_bit_rate = st->codec->bit_rate ? st->codec->bit_rate : st->codec->rc_max_rate; + sc->video_bit_rate = st->codecpar->bit_rate; if (s->oformat == &ff_mxf_d10_muxer) { if ((sc->video_bit_rate == 50000000) && (mxf->time_base.den == 25)) { sc->index = 3; @@ -2127,31 +2127,31 @@ static int mxf_write_header(AVFormatContext *s) } if (mxf->signal_standard >= 0) sc->signal_standard = mxf->signal_standard; - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - if (st->codec->sample_rate != 48000) { + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->sample_rate != 48000) { av_log(s, AV_LOG_ERROR, "only 48khz is implemented\n"); return -1; } - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); if (s->oformat == &ff_mxf_d10_muxer) { if (st->index != 1) { av_log(s, AV_LOG_ERROR, "MXF D-10 only support one audio track\n"); return -1; } - if (st->codec->codec_id != AV_CODEC_ID_PCM_S16LE && - st->codec->codec_id != AV_CODEC_ID_PCM_S24LE) { + if (st->codecpar->codec_id != AV_CODEC_ID_PCM_S16LE && + st->codecpar->codec_id != AV_CODEC_ID_PCM_S24LE) { av_log(s, AV_LOG_ERROR, "MXF D-10 only support 16 or 24 bits le audio\n"); } sc->index = ((MXFStreamContext*)s->streams[0]->priv_data)->index + 1; } else if (s->oformat == &ff_mxf_opatom_muxer) { AVRational tbc = av_inv_q(mxf->audio_edit_rate); - if (st->codec->codec_id != AV_CODEC_ID_PCM_S16LE && - st->codec->codec_id != AV_CODEC_ID_PCM_S24LE) { + if (st->codecpar->codec_id != AV_CODEC_ID_PCM_S16LE && + st->codecpar->codec_id != AV_CODEC_ID_PCM_S24LE) { av_log(s, AV_LOG_ERROR, "Only pcm_s16le and pcm_s24le audio codecs are implemented\n"); return AVERROR_PATCHWELCOME; } - if (st->codec->channels != 1) { + if (st->codecpar->channels != 1) { av_log(s, AV_LOG_ERROR, "MXF OPAtom only supports single channel audio\n"); return AVERROR(EINVAL); } @@ -2167,7 +2167,7 @@ static int mxf_write_header(AVFormatContext *s) return ret; mxf->timecode_base = (tbc.den + tbc.num/2) / tbc.num; - mxf->edit_unit_byte_count = (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3; + mxf->edit_unit_byte_count = (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->channels) >> 3; sc->index = 2; } else { mxf->slice_count = 1; @@ -2175,7 +2175,7 @@ static int mxf_write_header(AVFormatContext *s) } if (!sc->index) { - sc->index = mxf_get_essence_container_ul_index(st->codec->codec_id); + sc->index = mxf_get_essence_container_ul_index(st->codecpar->codec_id); if (sc->index == -1) { av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, " "codec not currently supported in container\n", i); @@ -2309,7 +2309,7 @@ static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacke { MXFContext *mxf = s->priv_data; AVIOContext *pb = s->pb; - int frame_size = pkt->size / st->codec->block_align; + int frame_size = pkt->size / st->codecpar->block_align; uint8_t *samples = pkt->data; uint8_t *end = pkt->data + pkt->size; int i; @@ -2318,12 +2318,12 @@ static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacke avio_w8(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1)); avio_wl16(pb, frame_size); - avio_w8(pb, (1<codec->channels)-1); + avio_w8(pb, (1<codecpar->channels)-1); while (samples < end) { - for (i = 0; i < st->codec->channels; i++) { + for (i = 0; i < st->codecpar->channels; i++) { uint32_t sample; - if (st->codec->codec_id == AV_CODEC_ID_PCM_S24LE) { + if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S24LE) { sample = AV_RL24(samples)<< 4; samples += 3; } else { @@ -2406,22 +2406,22 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt) } } - if (st->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO) { + if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) { if (!mxf_parse_mpeg2_frame(s, st, pkt, &ie)) { av_log(s, AV_LOG_ERROR, "could not get mpeg2 profile and level\n"); return -1; } - } else if (st->codec->codec_id == AV_CODEC_ID_DNXHD) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_DNXHD) { if (!mxf_parse_dnxhd_frame(s, st, pkt)) { av_log(s, AV_LOG_ERROR, "could not get dnxhd profile\n"); return -1; } - } else if (st->codec->codec_id == AV_CODEC_ID_DVVIDEO) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO) { if (!mxf_parse_dv_frame(s, st, pkt)) { av_log(s, AV_LOG_ERROR, "could not get dv profile\n"); return -1; } - } else if (st->codec->codec_id == AV_CODEC_ID_H264) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_H264) { if (!mxf_parse_h264_frame(s, st, pkt, &ie)) { av_log(s, AV_LOG_ERROR, "could not get h264 profile\n"); return -1; @@ -2477,7 +2477,7 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt) mxf_write_klv_fill(s); avio_write(pb, sc->track_essence_element_key, 16); // write key if (s->oformat == &ff_mxf_d10_muxer) { - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) mxf_write_d10_video_packet(s, st, pkt); else mxf_write_d10_audio_packet(s, st, pkt); diff --git a/libavformat/mxg.c b/libavformat/mxg.c index 45cc5b5284..6fbf99cfa3 100644 --- a/libavformat/mxg.c +++ b/libavformat/mxg.c @@ -48,20 +48,20 @@ static int mxg_read_header(AVFormatContext *s) video_st = avformat_new_stream(s, NULL); if (!video_st) return AVERROR(ENOMEM); - video_st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - video_st->codec->codec_id = AV_CODEC_ID_MXPEG; + video_st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + video_st->codecpar->codec_id = AV_CODEC_ID_MXPEG; avpriv_set_pts_info(video_st, 64, 1, 1000000); audio_st = avformat_new_stream(s, NULL); if (!audio_st) return AVERROR(ENOMEM); - audio_st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - audio_st->codec->codec_id = AV_CODEC_ID_PCM_ALAW; - audio_st->codec->channels = 1; - audio_st->codec->channel_layout = AV_CH_LAYOUT_MONO; - audio_st->codec->sample_rate = 8000; - audio_st->codec->bits_per_coded_sample = 8; - audio_st->codec->block_align = 1; + audio_st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + audio_st->codecpar->codec_id = AV_CODEC_ID_PCM_ALAW; + audio_st->codecpar->channels = 1; + audio_st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + audio_st->codecpar->sample_rate = 8000; + audio_st->codecpar->bits_per_coded_sample = 8; + audio_st->codecpar->block_align = 1; avpriv_set_pts_info(audio_st, 64, 1, 1000000); mxg->soi_ptr = mxg->buffer_ptr = mxg->buffer = 0; diff --git a/libavformat/ncdec.c b/libavformat/ncdec.c index 745ba61eb2..8cadcc7cd7 100644 --- a/libavformat/ncdec.c +++ b/libavformat/ncdec.c @@ -51,8 +51,8 @@ static int nc_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MPEG4; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MPEG4; st->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 64, 1, 100); diff --git a/libavformat/nistspheredec.c b/libavformat/nistspheredec.c index 359d9e38a5..782d1dfbfb 100644 --- a/libavformat/nistspheredec.c +++ b/libavformat/nistspheredec.c @@ -43,7 +43,7 @@ static int nist_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; ff_get_line(s->pb, buffer, sizeof(buffer)); ff_get_line(s->pb, buffer, sizeof(buffer)); @@ -58,29 +58,29 @@ static int nist_read_header(AVFormatContext *s) return AVERROR_INVALIDDATA; if (!memcmp(buffer, "end_head", 8)) { - if (!st->codec->bits_per_coded_sample) - st->codec->bits_per_coded_sample = bps << 3; + if (!st->codecpar->bits_per_coded_sample) + st->codecpar->bits_per_coded_sample = bps << 3; if (!av_strcasecmp(coding, "pcm")) { - if (st->codec->codec_id == AV_CODEC_ID_NONE) - st->codec->codec_id = ff_get_pcm_codec_id(st->codec->bits_per_coded_sample, + if (st->codecpar->codec_id == AV_CODEC_ID_NONE) + st->codecpar->codec_id = ff_get_pcm_codec_id(st->codecpar->bits_per_coded_sample, 0, be, 0xFFFF); } else if (!av_strcasecmp(coding, "alaw")) { - st->codec->codec_id = AV_CODEC_ID_PCM_ALAW; + st->codecpar->codec_id = AV_CODEC_ID_PCM_ALAW; } else if (!av_strcasecmp(coding, "ulaw") || !av_strcasecmp(coding, "mu-law")) { - st->codec->codec_id = AV_CODEC_ID_PCM_MULAW; + st->codecpar->codec_id = AV_CODEC_ID_PCM_MULAW; } else if (!av_strncasecmp(coding, "pcm,embedded-shorten", 20)) { - st->codec->codec_id = AV_CODEC_ID_SHORTEN; - if (ff_alloc_extradata(st->codec, 1)) - st->codec->extradata[0] = 1; + st->codecpar->codec_id = AV_CODEC_ID_SHORTEN; + if (ff_alloc_extradata(st->codecpar, 1)) + st->codecpar->extradata[0] = 1; } else { avpriv_request_sample(s, "coding %s", coding); } - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); - st->codec->block_align = st->codec->bits_per_coded_sample * st->codec->channels / 8; + st->codecpar->block_align = st->codecpar->bits_per_coded_sample * st->codecpar->channels / 8; if (avio_tell(s->pb) > header_size) return AVERROR_INVALIDDATA; @@ -89,7 +89,7 @@ static int nist_read_header(AVFormatContext *s) return 0; } else if (!memcmp(buffer, "channel_count", 13)) { - sscanf(buffer, "%*s %*s %"SCNd32, &st->codec->channels); + sscanf(buffer, "%*s %*s %"SCNd32, &st->codecpar->channels); } else if (!memcmp(buffer, "sample_byte_format", 18)) { sscanf(buffer, "%*s %*s %31s", format); @@ -98,7 +98,7 @@ static int nist_read_header(AVFormatContext *s) } else if (!av_strcasecmp(format, "10")) { be = 1; } else if (!av_strcasecmp(format, "mu-law")) { - st->codec->codec_id = AV_CODEC_ID_PCM_MULAW; + st->codecpar->codec_id = AV_CODEC_ID_PCM_MULAW; } else if (av_strcasecmp(format, "1")) { avpriv_request_sample(s, "sample byte format %s", format); return AVERROR_PATCHWELCOME; @@ -110,9 +110,9 @@ static int nist_read_header(AVFormatContext *s) } else if (!memcmp(buffer, "sample_n_bytes", 14)) { sscanf(buffer, "%*s %*s %"SCNd32, &bps); } else if (!memcmp(buffer, "sample_rate", 11)) { - sscanf(buffer, "%*s %*s %"SCNd32, &st->codec->sample_rate); + sscanf(buffer, "%*s %*s %"SCNd32, &st->codecpar->sample_rate); } else if (!memcmp(buffer, "sample_sig_bits", 15)) { - sscanf(buffer, "%*s %*s %"SCNd32, &st->codec->bits_per_coded_sample); + sscanf(buffer, "%*s %*s %"SCNd32, &st->codecpar->bits_per_coded_sample); } else { char key[32], value[32]; if (sscanf(buffer, "%31s %*s %31s", key, value) == 2) { diff --git a/libavformat/nsvdec.c b/libavformat/nsvdec.c index 95fab644a7..7f892973cc 100644 --- a/libavformat/nsvdec.c +++ b/libavformat/nsvdec.c @@ -434,12 +434,12 @@ static int nsv_parse_NSVs_header(AVFormatContext *s) if (!nst) goto fail; st->priv_data = nst; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_tag = vtag; - st->codec->codec_id = ff_codec_get_id(nsv_codec_video_tags, vtag); - st->codec->width = vwidth; - st->codec->height = vheight; - st->codec->bits_per_coded_sample = 24; /* depth XXX */ + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_tag = vtag; + st->codecpar->codec_id = ff_codec_get_id(nsv_codec_video_tags, vtag); + st->codecpar->width = vwidth; + st->codecpar->height = vheight; + st->codecpar->bits_per_coded_sample = 24; /* depth XXX */ avpriv_set_pts_info(st, 64, framerate.den, framerate.num); st->start_time = 0; @@ -465,9 +465,9 @@ static int nsv_parse_NSVs_header(AVFormatContext *s) if (!nst) goto fail; st->priv_data = nst; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = atag; - st->codec->codec_id = ff_codec_get_id(nsv_codec_audio_tags, atag); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = atag; + st->codecpar->codec_id = ff_codec_get_id(nsv_codec_audio_tags, atag); st->need_parsing = AVSTREAM_PARSE_FULL; /* for PCM we will read a chunk later and put correct info */ @@ -614,7 +614,7 @@ null_chunk_retry: pkt = &nsv->ahead[NSV_ST_AUDIO]; /* read raw audio specific header on the first audio chunk... */ /* on ALL audio chunks ?? seems so! */ - if (asize && st[NSV_ST_AUDIO]->codec->codec_tag == MKTAG('P', 'C', 'M', ' ')/* && fill_header*/) { + if (asize && st[NSV_ST_AUDIO]->codecpar->codec_tag == MKTAG('P', 'C', 'M', ' ')/* && fill_header*/) { uint8_t bps; uint8_t channels; uint16_t samplerate; @@ -632,11 +632,11 @@ null_chunk_retry: } bps /= channels; // ??? if (bps == 8) - st[NSV_ST_AUDIO]->codec->codec_id = AV_CODEC_ID_PCM_U8; + st[NSV_ST_AUDIO]->codecpar->codec_id = AV_CODEC_ID_PCM_U8; samplerate /= 4;/* UGH ??? XXX */ channels = 1; - st[NSV_ST_AUDIO]->codec->channels = channels; - st[NSV_ST_AUDIO]->codec->sample_rate = samplerate; + st[NSV_ST_AUDIO]->codecpar->channels = channels; + st[NSV_ST_AUDIO]->codecpar->sample_rate = samplerate; av_log(s, AV_LOG_TRACE, "NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate); } } diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c index 4df6a57a67..7286a26e17 100644 --- a/libavformat/nutdec.c +++ b/libavformat/nutdec.c @@ -415,11 +415,11 @@ static int decode_stream_header(NUTContext *nut) class = ffio_read_varlen(bc); tmp = get_fourcc(bc); - st->codec->codec_tag = tmp; + st->codecpar->codec_tag = tmp; switch (class) { case 0: - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = av_codec_get_id((const AVCodecTag * const []) { + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = av_codec_get_id((const AVCodecTag * const []) { ff_nut_video_tags, ff_codec_bmp_tags, ff_codec_movvideo_tags, @@ -428,8 +428,8 @@ static int decode_stream_header(NUTContext *nut) tmp); break; case 1: - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = av_codec_get_id((const AVCodecTag * const []) { + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = av_codec_get_id((const AVCodecTag * const []) { ff_nut_audio_tags, ff_codec_wav_tags, ff_nut_audio_extra_tags, @@ -438,18 +438,18 @@ static int decode_stream_header(NUTContext *nut) tmp); break; case 2: - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = ff_codec_get_id(ff_nut_subtitle_tags, tmp); + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = ff_codec_get_id(ff_nut_subtitle_tags, tmp); break; case 3: - st->codec->codec_type = AVMEDIA_TYPE_DATA; - st->codec->codec_id = ff_codec_get_id(ff_nut_data_tags, tmp); + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_id = ff_codec_get_id(ff_nut_data_tags, tmp); break; default: av_log(s, AV_LOG_ERROR, "unknown stream class (%d)\n", class); return AVERROR(ENOSYS); } - if (class < 3 && st->codec->codec_id == AV_CODEC_ID_NONE) + if (class < 3 && st->codecpar->codec_id == AV_CODEC_ID_NONE) av_log(s, AV_LOG_ERROR, "Unknown codec tag '0x%04x' for stream number %d\n", (unsigned int) tmp, stream_id); @@ -458,18 +458,18 @@ static int decode_stream_header(NUTContext *nut) GET_V(stc->msb_pts_shift, tmp < 16); stc->max_pts_distance = ffio_read_varlen(bc); GET_V(stc->decode_delay, tmp < 1000); // sanity limit, raise this if Moore's law is true - st->codec->has_b_frames = stc->decode_delay; + st->codecpar->video_delay = stc->decode_delay; ffio_read_varlen(bc); // stream flags - GET_V(st->codec->extradata_size, tmp < (1 << 30)); - if (st->codec->extradata_size) { - if (ff_get_extradata(st->codec, bc, st->codec->extradata_size) < 0) + GET_V(st->codecpar->extradata_size, tmp < (1 << 30)); + if (st->codecpar->extradata_size) { + if (ff_get_extradata(st->codecpar, bc, st->codecpar->extradata_size) < 0) return AVERROR(ENOMEM); } - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { - GET_V(st->codec->width, tmp > 0); - GET_V(st->codec->height, tmp > 0); + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + GET_V(st->codecpar->width, tmp > 0); + GET_V(st->codecpar->height, tmp > 0); st->sample_aspect_ratio.num = ffio_read_varlen(bc); st->sample_aspect_ratio.den = ffio_read_varlen(bc); if ((!st->sample_aspect_ratio.num) != (!st->sample_aspect_ratio.den)) { @@ -479,10 +479,10 @@ static int decode_stream_header(NUTContext *nut) goto fail; } ffio_read_varlen(bc); /* csp type */ - } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - GET_V(st->codec->sample_rate, tmp > 0); + } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + GET_V(st->codecpar->sample_rate, tmp > 0); ffio_read_varlen(bc); // samplerate_den - GET_V(st->codec->channels, tmp > 0); + GET_V(st->codecpar->channels, tmp > 0); } if (skip_reserved(bc, end) || ffio_get_checksum(bc)) { av_log(s, AV_LOG_ERROR, @@ -495,9 +495,9 @@ static int decode_stream_header(NUTContext *nut) stc->time_base->den); return 0; fail: - if (st && st->codec) { - av_freep(&st->codec->extradata); - st->codec->extradata_size = 0; + if (st && st->codecpar) { + av_freep(&st->codecpar->extradata); + st->codecpar->extradata_size = 0; } return ret; } diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c index 3a415a4584..9e422e1aa8 100644 --- a/libavformat/nutenc.c +++ b/libavformat/nutenc.c @@ -35,32 +35,32 @@ #include "avio_internal.h" #include "riff.h" -static int find_expected_header(AVCodecContext *c, int size, int key_frame, +static int find_expected_header(AVCodecParameters *p, int size, int key_frame, uint8_t out[64]) { - int sample_rate = c->sample_rate; + int sample_rate = p->sample_rate; if (size > 4096) return 0; AV_WB24(out, 1); - if (c->codec_id == AV_CODEC_ID_MPEG4) { + if (p->codec_id == AV_CODEC_ID_MPEG4) { if (key_frame) { return 3; } else { out[3] = 0xB6; return 4; } - } else if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO || - c->codec_id == AV_CODEC_ID_MPEG2VIDEO) { + } else if (p->codec_id == AV_CODEC_ID_MPEG1VIDEO || + p->codec_id == AV_CODEC_ID_MPEG2VIDEO) { return 3; - } else if (c->codec_id == AV_CODEC_ID_H264) { + } else if (p->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 (p->codec_id == AV_CODEC_ID_MP3 || + p->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; + int layer = p->codec_id == AV_CODEC_ID_MP3 ? 3 : 2; unsigned int header = 0xFFF00000; lsf = sample_rate < (24000 + 32000) / 2; @@ -102,12 +102,13 @@ static int find_expected_header(AVCodecContext *c, int size, int key_frame, return 0; } -static int find_header_idx(AVFormatContext *s, AVCodecContext *c, int size, int frame_type) +static int find_header_idx(AVFormatContext *s, AVCodecParameters *p, int size, + int frame_type) { NUTContext *nut = s->priv_data; uint8_t out[64]; int i; - int len = find_expected_header(c, size, frame_type, out); + int len = find_expected_header(p, size, frame_type, out); for (i = 1; i < nut->header_count; i++) { if (len == nut->header_len[i] && !memcmp(out, nut->header[i], len)) { @@ -167,18 +168,18 @@ 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; - AVCodecContext *codec = s->streams[stream_id]->codec; - int is_audio = codec->codec_type == AVMEDIA_TYPE_AUDIO; + AVCodecParameters *par = s->streams[stream_id]->codecpar; + int is_audio = par->codec_type == AVMEDIA_TYPE_AUDIO; int intra_only = /*codec->intra_only || */ is_audio; int pred_count; int frame_size = 0; - if (codec->codec_type == AVMEDIA_TYPE_AUDIO) { - frame_size = av_get_audio_frame_duration(codec, 0); - if (codec->codec_id == AV_CODEC_ID_VORBIS && !frame_size) + if (par->codec_type == AVMEDIA_TYPE_AUDIO) { + frame_size = av_get_audio_frame_duration2(par, 0); + if (par->codec_id == AV_CODEC_ID_VORBIS && !frame_size) frame_size = 64; } else { - AVRational f = av_div_q(codec->time_base, *nut->stream[stream_id].time_base); + AVRational f = av_div_q(av_inv_q(s->streams[stream_id]->avg_frame_rate), *nut->stream[stream_id].time_base); if (f.den == 1 && f.num>0) frame_size = f.num; } @@ -193,7 +194,7 @@ static void build_frame_code(AVFormatContext *s) ft->stream_id = stream_id; ft->size_mul = 1; if (is_audio) - ft->header_idx = find_header_idx(s, codec, -1, key_frame); + ft->header_idx = find_header_idx(s, par, -1, key_frame); start2++; } } @@ -204,11 +205,11 @@ static void build_frame_code(AVFormatContext *s) int frame_bytes; int pts; - if (codec->block_align > 0) { - frame_bytes = codec->block_align; + if (par->block_align > 0) { + frame_bytes = par->block_align; } else { - int frame_size = av_get_audio_frame_duration(codec, 0); - frame_bytes = frame_size * (int64_t)codec->bit_rate / (8 * codec->sample_rate); + int frame_size = av_get_audio_frame_duration2(par, 0); + frame_bytes = frame_size * (int64_t)par->bit_rate / (8 * par->sample_rate); } for (pts = 0; pts < 2; pts++) { @@ -219,7 +220,7 @@ static void build_frame_code(AVFormatContext *s) ft->size_mul = frame_bytes + 2; ft->size_lsb = frame_bytes + pred; ft->pts_delta = pts * frame_size; - ft->header_idx = find_header_idx(s, codec, frame_bytes + pred, key_frame); + ft->header_idx = find_header_idx(s, par, frame_bytes + pred, key_frame); start2++; } } @@ -233,14 +234,14 @@ static void build_frame_code(AVFormatContext *s) } #endif - if (codec->has_b_frames) { + if (par->video_delay) { pred_count = 5; pred_table[0] = -2; pred_table[1] = -1; pred_table[2] = 1; pred_table[3] = 3; pred_table[4] = 4; - } else if (codec->codec_id == AV_CODEC_ID_VORBIS) { + } else if (par->codec_id == AV_CODEC_ID_VORBIS) { pred_count = 3; pred_table[0] = 2; pred_table[1] = 9; @@ -266,7 +267,7 @@ static void build_frame_code(AVFormatContext *s) ft->size_lsb = index - start3; ft->pts_delta = pred_table[pred]; if (is_audio) - ft->header_idx = find_header_idx(s, codec, -1, key_frame); + ft->header_idx = find_header_idx(s, par, -1, key_frame); } } } @@ -425,18 +426,19 @@ static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, AVStream *st, int i) { NUTContext *nut = avctx->priv_data; - AVCodecContext *codec = st->codec; + AVCodecParameters *par = st->codecpar; ff_put_v(bc, i); - switch (codec->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: ff_put_v(bc, 0); break; case AVMEDIA_TYPE_AUDIO: ff_put_v(bc, 1); break; case AVMEDIA_TYPE_SUBTITLE: ff_put_v(bc, 2); break; default: ff_put_v(bc, 3); break; } ff_put_v(bc, 4); - if (codec->codec_tag) { - avio_wl32(bc, codec->codec_tag); + + if (par->codec_tag) { + avio_wl32(bc, par->codec_tag); } else { av_log(avctx, AV_LOG_ERROR, "No codec tag defined for stream %d\n", i); return AVERROR(EINVAL); @@ -445,21 +447,21 @@ static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, ff_put_v(bc, nut->stream[i].time_base - nut->time_base); ff_put_v(bc, nut->stream[i].msb_pts_shift); ff_put_v(bc, nut->stream[i].max_pts_distance); - ff_put_v(bc, codec->has_b_frames); + ff_put_v(bc, par->video_delay); avio_w8(bc, 0); /* flags: 0x1 - fixed_fps, 0x2 - index_present */ - ff_put_v(bc, codec->extradata_size); - avio_write(bc, codec->extradata, codec->extradata_size); + ff_put_v(bc, par->extradata_size); + avio_write(bc, par->extradata, par->extradata_size); - switch (codec->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_AUDIO: - ff_put_v(bc, codec->sample_rate); + ff_put_v(bc, par->sample_rate); ff_put_v(bc, 1); - ff_put_v(bc, codec->channels); + ff_put_v(bc, par->channels); break; case AVMEDIA_TYPE_VIDEO: - ff_put_v(bc, codec->width); - ff_put_v(bc, codec->height); + ff_put_v(bc, par->width); + ff_put_v(bc, par->height); if (st->sample_aspect_ratio.num <= 0 || st->sample_aspect_ratio.den <= 0) { @@ -530,12 +532,12 @@ static int write_streaminfo(NUTContext *nut, AVIOContext *bc, int stream_id) { if (st->disposition & ff_nut_dispositions[i].flag) count += add_info(dyn_bc, "Disposition", ff_nut_dispositions[i].str); } - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { uint8_t buf[256]; if (st->r_frame_rate.num>0 && st->r_frame_rate.den>0) snprintf(buf, sizeof(buf), "%d/%d", st->r_frame_rate.num, st->r_frame_rate.den); else - snprintf(buf, sizeof(buf), "%d/%d", st->codec->time_base.den, st->codec->time_base.num); + snprintf(buf, sizeof(buf), "%d/%d", st->avg_frame_rate.num, st->avg_frame_rate.den); count += add_info(dyn_bc, "r_frame_rate", buf); } dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf); @@ -730,8 +732,8 @@ static int nut_write_header(AVFormatContext *s) AVRational time_base; ff_parse_specific_params(st, &time_base.den, &ssize, &time_base.num); - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->codec->sample_rate) { - time_base = (AVRational) {1, st->codec->sample_rate}; + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && st->codecpar->sample_rate) { + time_base = (AVRational) {1, st->codecpar->sample_rate}; } else { time_base = ff_choose_timebase(s, st, 48000); } diff --git a/libavformat/nuv.c b/libavformat/nuv.c index c30da60711..57eea9e604 100644 --- a/libavformat/nuv.c +++ b/libavformat/nuv.c @@ -83,11 +83,11 @@ static int get_codec_data(AVIOContext *pb, AVStream *vst, avio_skip(pb, 6); size = PKTSIZE(avio_rl32(pb)); if (vst && subtype == 'R') { - if (vst->codec->extradata) { - av_freep(&vst->codec->extradata); - vst->codec->extradata_size = 0; + if (vst->codecpar->extradata) { + av_freep(&vst->codecpar->extradata); + vst->codecpar->extradata_size = 0; } - if (ff_get_extradata(vst->codec, pb, size) < 0) + if (ff_get_extradata(vst->codecpar, pb, size) < 0) return AVERROR(ENOMEM); size = 0; if (!myth) @@ -101,32 +101,32 @@ static int get_codec_data(AVIOContext *pb, AVStream *vst, break; avio_rl32(pb); // version if (vst) { - vst->codec->codec_tag = avio_rl32(pb); - vst->codec->codec_id = - ff_codec_get_id(ff_codec_bmp_tags, vst->codec->codec_tag); - if (vst->codec->codec_tag == MKTAG('R', 'J', 'P', 'G')) - vst->codec->codec_id = AV_CODEC_ID_NUV; + vst->codecpar->codec_tag = avio_rl32(pb); + vst->codecpar->codec_id = + ff_codec_get_id(ff_codec_bmp_tags, vst->codecpar->codec_tag); + if (vst->codecpar->codec_tag == MKTAG('R', 'J', 'P', 'G')) + vst->codecpar->codec_id = AV_CODEC_ID_NUV; } else avio_skip(pb, 4); if (ast) { int id; - ast->codec->codec_tag = avio_rl32(pb); - ast->codec->sample_rate = avio_rl32(pb); - ast->codec->bits_per_coded_sample = avio_rl32(pb); - ast->codec->channels = avio_rl32(pb); - ast->codec->channel_layout = 0; + ast->codecpar->codec_tag = avio_rl32(pb); + ast->codecpar->sample_rate = avio_rl32(pb); + ast->codecpar->bits_per_coded_sample = avio_rl32(pb); + ast->codecpar->channels = avio_rl32(pb); + ast->codecpar->channel_layout = 0; - id = ff_wav_codec_get_id(ast->codec->codec_tag, - ast->codec->bits_per_coded_sample); + id = ff_wav_codec_get_id(ast->codecpar->codec_tag, + ast->codecpar->bits_per_coded_sample); if (id == AV_CODEC_ID_NONE) { - id = ff_codec_get_id(nuv_audio_tags, ast->codec->codec_tag); + id = ff_codec_get_id(nuv_audio_tags, ast->codecpar->codec_tag); if (id == AV_CODEC_ID_PCM_S16LE) - id = ff_get_pcm_codec_id(ast->codec->bits_per_coded_sample, + id = ff_get_pcm_codec_id(ast->codecpar->bits_per_coded_sample, 0, 0, ~1); } - ast->codec->codec_id = id; + ast->codecpar->codec_id = id; ast->need_parsing = AVSTREAM_PARSE_FULL; } else @@ -199,11 +199,11 @@ static int nuv_header(AVFormatContext *s) if (ret < 0) return ret; - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_id = AV_CODEC_ID_NUV; - vst->codec->width = width; - vst->codec->height = height; - vst->codec->bits_per_coded_sample = 10; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_NUV; + vst->codecpar->width = width; + vst->codecpar->height = height; + vst->codecpar->bits_per_coded_sample = 10; vst->sample_aspect_ratio = av_d2q(aspect * height / width, 10000); #if FF_API_R_FRAME_RATE @@ -220,14 +220,14 @@ static int nuv_header(AVFormatContext *s) return AVERROR(ENOMEM); ctx->a_id = ast->index; - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = AV_CODEC_ID_PCM_S16LE; - ast->codec->channels = 2; - ast->codec->channel_layout = AV_CH_LAYOUT_STEREO; - ast->codec->sample_rate = 44100; - ast->codec->bit_rate = 2 * 2 * 44100 * 8; - ast->codec->block_align = 2 * 2; - ast->codec->bits_per_coded_sample = 16; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; + ast->codecpar->channels = 2; + ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + ast->codecpar->sample_rate = 44100; + ast->codecpar->bit_rate = 2 * 2 * 44100 * 8; + ast->codecpar->block_align = 2 * 2; + ast->codecpar->bits_per_coded_sample = 16; avpriv_set_pts_info(ast, 32, 1, 1000); } else ctx->a_id = -1; @@ -235,7 +235,7 @@ static int nuv_header(AVFormatContext *s) if ((ret = get_codec_data(pb, vst, ast, is_mythtv)) < 0) return ret; - ctx->rtjpg_video = vst && vst->codec->codec_id == AV_CODEC_ID_NUV; + ctx->rtjpg_video = vst && vst->codecpar->codec_id == AV_CODEC_ID_NUV; return 0; } diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c index 9f1e0abb31..528d8db551 100644 --- a/libavformat/oggdec.c +++ b/libavformat/oggdec.c @@ -760,7 +760,7 @@ static void ogg_validate_keyframe(AVFormatContext *s, int idx, int pstart, int p struct ogg_stream *os = ogg->streams + idx; int invalid = 0; if (psize) { - switch (s->streams[idx]->codec->codec_id) { + switch (s->streams[idx]->codecpar->codec_id) { case AV_CODEC_ID_THEORA: invalid = !!(os->pflags & AV_PKT_FLAG_KEY) != !(os->buf[pstart] & 0x40); break; @@ -903,7 +903,7 @@ static int ogg_read_seek(AVFormatContext *s, int stream_index, // Try seeking to a keyframe first. If this fails (very possible), // av_seek_frame will fall back to ignoring keyframes - if (s->streams[stream_index]->codec->codec_type == AVMEDIA_TYPE_VIDEO + if (s->streams[stream_index]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && !(flags & AVSEEK_FLAG_ANY)) os->keyframe_seek = 1; diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c index 4907512989..f998af39ac 100644 --- a/libavformat/oggenc.c +++ b/libavformat/oggenc.c @@ -223,7 +223,7 @@ static int ogg_buffer_data(AVFormatContext *s, AVStream *st, // them as such, otherwise seeking will not work correctly at the very // least with old libogg versions. // Do not try to flush header packets though, that will create broken files. - if (st->codec->codec_id == AV_CODEC_ID_THEORA && !header && + if (st->codecpar->codec_id == AV_CODEC_ID_THEORA && !header && (ogg_granule_to_timestamp(oggstream, granule) > ogg_granule_to_timestamp(oggstream, oggstream->last_granule) + 1 || ogg_key_granule(oggstream, granule))) { @@ -311,13 +311,13 @@ static uint8_t *ogg_write_vorbiscomment(int64_t offset, int bitexact, return p0; } -static int ogg_build_flac_headers(AVCodecContext *avctx, +static int ogg_build_flac_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m) { uint8_t *p; - if (avctx->extradata_size < FLAC_STREAMINFO_SIZE) + if (par->extradata_size < FLAC_STREAMINFO_SIZE) return AVERROR(EINVAL); // first packet: STREAMINFO @@ -334,7 +334,7 @@ static int ogg_build_flac_headers(AVCodecContext *avctx, bytestream_put_buffer(&p, "fLaC", 4); bytestream_put_byte(&p, 0x00); // streaminfo bytestream_put_be24(&p, 34); - bytestream_put_buffer(&p, avctx->extradata, FLAC_STREAMINFO_SIZE); + bytestream_put_buffer(&p, par->extradata, FLAC_STREAMINFO_SIZE); // second packet: VorbisComment p = ogg_write_vorbiscomment(4, bitexact, &oggstream->header_len[1], m, 0); @@ -349,13 +349,13 @@ static int ogg_build_flac_headers(AVCodecContext *avctx, #define SPEEX_HEADER_SIZE 80 -static int ogg_build_speex_headers(AVCodecContext *avctx, +static int ogg_build_speex_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m) { uint8_t *p; - if (avctx->extradata_size < SPEEX_HEADER_SIZE) + if (par->extradata_size < SPEEX_HEADER_SIZE) return AVERROR_INVALIDDATA; // first packet: Speex header @@ -364,7 +364,7 @@ static int ogg_build_speex_headers(AVCodecContext *avctx, return AVERROR(ENOMEM); oggstream->header[0] = p; oggstream->header_len[0] = SPEEX_HEADER_SIZE; - bytestream_put_buffer(&p, avctx->extradata, SPEEX_HEADER_SIZE); + bytestream_put_buffer(&p, par->extradata, SPEEX_HEADER_SIZE); AV_WL32(&oggstream->header[0][68], 0); // set extra_headers to 0 // second packet: VorbisComment @@ -378,22 +378,22 @@ static int ogg_build_speex_headers(AVCodecContext *avctx, #define OPUS_HEADER_SIZE 19 -static int ogg_build_opus_headers(AVCodecContext *avctx, +static int ogg_build_opus_headers(AVCodecParameters *par, OGGStreamContext *oggstream, int bitexact, AVDictionary **m) { uint8_t *p; - if (avctx->extradata_size < OPUS_HEADER_SIZE) + if (par->extradata_size < OPUS_HEADER_SIZE) return AVERROR_INVALIDDATA; /* first packet: Opus header */ - p = av_mallocz(avctx->extradata_size); + p = av_mallocz(par->extradata_size); if (!p) return AVERROR(ENOMEM); oggstream->header[0] = p; - oggstream->header_len[0] = avctx->extradata_size; - bytestream_put_buffer(&p, avctx->extradata, avctx->extradata_size); + oggstream->header_len[0] = par->extradata_size; + bytestream_put_buffer(&p, par->extradata, par->extradata_size); /* second packet: VorbisComment */ p = ogg_write_vorbiscomment(8, bitexact, &oggstream->header_len[1], m, 0); @@ -440,24 +440,24 @@ static int ogg_write_header(AVFormatContext *s) AVStream *st = s->streams[i]; unsigned serial_num = i + ogg->serial_offset; - if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { - if (st->codec->codec_id == AV_CODEC_ID_OPUS) + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) /* Opus requires a fixed 48kHz clock */ avpriv_set_pts_info(st, 64, 1, 48000); else - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); } - if (st->codec->codec_id != AV_CODEC_ID_VORBIS && - st->codec->codec_id != AV_CODEC_ID_THEORA && - st->codec->codec_id != AV_CODEC_ID_SPEEX && - st->codec->codec_id != AV_CODEC_ID_FLAC && - st->codec->codec_id != AV_CODEC_ID_OPUS) { + if (st->codecpar->codec_id != AV_CODEC_ID_VORBIS && + st->codecpar->codec_id != AV_CODEC_ID_THEORA && + st->codecpar->codec_id != AV_CODEC_ID_SPEEX && + st->codecpar->codec_id != AV_CODEC_ID_FLAC && + st->codecpar->codec_id != AV_CODEC_ID_OPUS) { av_log(s, AV_LOG_ERROR, "Unsupported codec id in stream %d\n", i); return AVERROR(EINVAL); } - if (!st->codec->extradata || !st->codec->extradata_size) { + if (!st->codecpar->extradata || !st->codecpar->extradata_size) { av_log(s, AV_LOG_ERROR, "No extradata present\n"); return AVERROR_INVALIDDATA; } @@ -481,8 +481,8 @@ static int ogg_write_header(AVFormatContext *s) av_dict_copy(&st->metadata, s->metadata, AV_DICT_DONT_OVERWRITE); st->priv_data = oggstream; - if (st->codec->codec_id == AV_CODEC_ID_FLAC) { - int err = ogg_build_flac_headers(st->codec, oggstream, + if (st->codecpar->codec_id == AV_CODEC_ID_FLAC) { + int err = ogg_build_flac_headers(st->codecpar, oggstream, s->flags & AVFMT_FLAG_BITEXACT, &st->metadata); if (err) { @@ -490,8 +490,8 @@ static int ogg_write_header(AVFormatContext *s) av_freep(&st->priv_data); return err; } - } else if (st->codec->codec_id == AV_CODEC_ID_SPEEX) { - int err = ogg_build_speex_headers(st->codec, oggstream, + } else if (st->codecpar->codec_id == AV_CODEC_ID_SPEEX) { + int err = ogg_build_speex_headers(st->codecpar, oggstream, s->flags & AVFMT_FLAG_BITEXACT, &st->metadata); if (err) { @@ -499,8 +499,8 @@ static int ogg_write_header(AVFormatContext *s) av_freep(&st->priv_data); return err; } - } else if (st->codec->codec_id == AV_CODEC_ID_OPUS) { - int err = ogg_build_opus_headers(st->codec, oggstream, + } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) { + int err = ogg_build_opus_headers(st->codecpar, oggstream, s->flags & AVFMT_FLAG_BITEXACT, &st->metadata); if (err) { @@ -510,12 +510,12 @@ static int ogg_write_header(AVFormatContext *s) } } else { uint8_t *p; - const char *cstr = st->codec->codec_id == AV_CODEC_ID_VORBIS ? "vorbis" : "theora"; - int header_type = st->codec->codec_id == AV_CODEC_ID_VORBIS ? 3 : 0x81; - int framing_bit = st->codec->codec_id == AV_CODEC_ID_VORBIS ? 1 : 0; + const char *cstr = st->codecpar->codec_id == AV_CODEC_ID_VORBIS ? "vorbis" : "theora"; + int header_type = st->codecpar->codec_id == AV_CODEC_ID_VORBIS ? 3 : 0x81; + int framing_bit = st->codecpar->codec_id == AV_CODEC_ID_VORBIS ? 1 : 0; - if (avpriv_split_xiph_headers(st->codec->extradata, st->codec->extradata_size, - st->codec->codec_id == AV_CODEC_ID_VORBIS ? 30 : 42, + if (avpriv_split_xiph_headers(st->codecpar->extradata, st->codecpar->extradata_size, + st->codecpar->codec_id == AV_CODEC_ID_VORBIS ? 30 : 42, (const uint8_t**)oggstream->header, oggstream->header_len) < 0) { av_log(s, AV_LOG_ERROR, "Extradata corrupted\n"); av_freep(&st->priv_data); @@ -532,7 +532,7 @@ static int ogg_write_header(AVFormatContext *s) bytestream_put_byte(&p, header_type); bytestream_put_buffer(&p, cstr, 6); - if (st->codec->codec_id == AV_CODEC_ID_THEORA) { + if (st->codecpar->codec_id == AV_CODEC_ID_THEORA) { /** KFGSHIFT is the width of the less significant section of the granule position The less significant section is the frame count since the last keyframe */ oggstream->kfgshift = ((oggstream->header[0][40]&3)<<3)|(oggstream->header[0][41]>>5); @@ -575,7 +575,7 @@ static int ogg_write_packet_internal(AVFormatContext *s, AVPacket *pkt) int ret; int64_t granule; - if (st->codec->codec_id == AV_CODEC_ID_THEORA) { + if (st->codecpar->codec_id == AV_CODEC_ID_THEORA) { int64_t pts = oggstream->vrev < 1 ? pkt->pts : pkt->pts + pkt->duration; int pframe_count; if (pkt->flags & AV_PKT_FLAG_KEY) @@ -587,10 +587,10 @@ static int ogg_write_packet_internal(AVFormatContext *s, AVPacket *pkt) pframe_count = 0; } granule = (oggstream->last_kf_pts<kfgshift) | pframe_count; - } else if (st->codec->codec_id == AV_CODEC_ID_OPUS) + } else if (st->codecpar->codec_id == AV_CODEC_ID_OPUS) granule = pkt->pts + pkt->duration + - av_rescale_q(st->codec->initial_padding, - (AVRational){ 1, st->codec->sample_rate }, + av_rescale_q(st->codecpar->initial_padding, + (AVRational){ 1, st->codecpar->sample_rate }, st->time_base); else granule = pkt->pts + pkt->duration; @@ -643,9 +643,9 @@ static int ogg_write_trailer(AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; OGGStreamContext *oggstream = st->priv_data; - if (st->codec->codec_id == AV_CODEC_ID_FLAC || - st->codec->codec_id == AV_CODEC_ID_SPEEX || - st->codec->codec_id == AV_CODEC_ID_OPUS) { + if (st->codecpar->codec_id == AV_CODEC_ID_FLAC || + st->codecpar->codec_id == AV_CODEC_ID_SPEEX || + st->codecpar->codec_id == AV_CODEC_ID_OPUS) { av_freep(&oggstream->header[0]); } av_freep(&oggstream->header[1]); diff --git a/libavformat/oggparsecelt.c b/libavformat/oggparsecelt.c index 2c0c511c7b..6d567f988a 100644 --- a/libavformat/oggparsecelt.c +++ b/libavformat/oggparsecelt.c @@ -48,7 +48,7 @@ static int celt_header(AVFormatContext *s, int idx) priv = av_malloc(sizeof(struct oggcelt_private)); if (!priv) return AVERROR(ENOMEM); - if (ff_alloc_extradata(st->codec, 2 * sizeof(uint32_t)) < 0) { + if (ff_alloc_extradata(st->codecpar, 2 * sizeof(uint32_t)) < 0) { av_free(priv); return AVERROR(ENOMEM); } @@ -59,17 +59,17 @@ static int celt_header(AVFormatContext *s, int idx) overlap = AV_RL32(p + 48); /* unused bytes per packet field skipped */ extra_headers = AV_RL32(p + 56); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_CELT; - st->codec->sample_rate = sample_rate; - st->codec->channels = nb_channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_CELT; + st->codecpar->sample_rate = sample_rate; + st->codecpar->channels = nb_channels; if (sample_rate) avpriv_set_pts_info(st, 64, 1, sample_rate); priv->extra_headers_left = 1 + extra_headers; av_free(os->private); os->private = priv; - AV_WL32(st->codec->extradata + 0, overlap); - AV_WL32(st->codec->extradata + 4, version); + AV_WL32(st->codecpar->extradata + 0, overlap); + AV_WL32(st->codecpar->extradata + 4, version); return 1; } else if (priv && priv->extra_headers_left) { /* Extra headers (vorbiscomment) */ diff --git a/libavformat/oggparsedaala.c b/libavformat/oggparsedaala.c index 3651ca188b..89bda58994 100644 --- a/libavformat/oggparsedaala.c +++ b/libavformat/oggparsedaala.c @@ -84,7 +84,7 @@ static int daala_header(AVFormatContext *s, int idx) struct ogg *ogg = s->priv_data; struct ogg_stream *os = ogg->streams + idx; AVStream *st = s->streams[idx]; - int cds = st->codec->extradata_size + os->psize + 2; + int cds = st->codecpar->extradata_size + os->psize + 2; DaalaInfoHeader *hdr = os->private; if (!(os->buf[os->pstart] & 0x80)) @@ -106,8 +106,8 @@ static int daala_header(AVFormatContext *s, int idx) hdr->version_min = bytestream2_get_byte(&gb); hdr->version_sub = bytestream2_get_byte(&gb); - st->codec->width = bytestream2_get_ne32(&gb); - st->codec->height = bytestream2_get_ne32(&gb); + st->codecpar->width = bytestream2_get_ne32(&gb); + st->codecpar->height = bytestream2_get_ne32(&gb); st->sample_aspect_ratio.num = bytestream2_get_ne32(&gb); st->sample_aspect_ratio.den = bytestream2_get_ne32(&gb); @@ -146,13 +146,13 @@ static int daala_header(AVFormatContext *s, int idx) hdr->format.ydec[i] = bytestream2_get_byte(&gb); } - if ((st->codec->pix_fmt = daala_match_pix_fmt(&hdr->format)) < 0) + if ((st->codecpar->format = daala_match_pix_fmt(&hdr->format)) < 0) av_log(s, AV_LOG_ERROR, "Unsupported pixel format - %i %i\n", hdr->format.depth, hdr->format.planes); - st->codec->codec_id = AV_CODEC_ID_DAALA; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->codecpar->codec_id = AV_CODEC_ID_DAALA; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->need_parsing = AVSTREAM_PARSE_HEADERS; hdr->init_d = 1; break; @@ -173,18 +173,18 @@ static int daala_header(AVFormatContext *s, int idx) break; } - if ((err = av_reallocp(&st->codec->extradata, + if ((err = av_reallocp(&st->codecpar->extradata, cds + AV_INPUT_BUFFER_PADDING_SIZE)) < 0) { - st->codec->extradata_size = 0; + st->codecpar->extradata_size = 0; return err; } - memset(st->codec->extradata + cds, 0, AV_INPUT_BUFFER_PADDING_SIZE); - cdp = st->codec->extradata + st->codec->extradata_size; + memset(st->codecpar->extradata + cds, 0, AV_INPUT_BUFFER_PADDING_SIZE); + cdp = st->codecpar->extradata + st->codecpar->extradata_size; *cdp++ = os->psize >> 8; *cdp++ = os->psize & 0xff; memcpy(cdp, os->buf + os->pstart, os->psize); - st->codec->extradata_size = cds; + st->codecpar->extradata_size = cds; return 1; } diff --git a/libavformat/oggparsedirac.c b/libavformat/oggparsedirac.c index 3e5e3930b2..9a67e25f3d 100644 --- a/libavformat/oggparsedirac.c +++ b/libavformat/oggparsedirac.c @@ -34,25 +34,25 @@ static int dirac_header(AVFormatContext *s, int idx) int ret; // already parsed the header - if (st->codec->codec_id == AV_CODEC_ID_DIRAC) + if (st->codecpar->codec_id == AV_CODEC_ID_DIRAC) return 0; ret = av_dirac_parse_sequence_header(&dsh, os->buf + os->pstart + 13, (os->psize - 13), s); if (ret < 0) return ret; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_DIRAC; - st->codec->width = dsh->width; - st->codec->height = dsh->height; - st->codec->pix_fmt = dsh->pix_fmt; - st->codec->color_range = dsh->color_range; - st->codec->color_trc = dsh->color_trc; - st->codec->color_primaries = dsh->color_primaries; - st->codec->colorspace = dsh->colorspace; - st->codec->profile = dsh->profile; - st->codec->level = dsh->level; - if (av_image_check_sar(st->codec->width, st->codec->height, dsh->sample_aspect_ratio) >= 0) + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_DIRAC; + st->codecpar->width = dsh->width; + st->codecpar->height = dsh->height; + st->codecpar->format = dsh->pix_fmt; + st->codecpar->color_range = dsh->color_range; + st->codecpar->color_trc = dsh->color_trc; + st->codecpar->color_primaries = dsh->color_primaries; + st->codecpar->color_space = dsh->colorspace; + st->codecpar->profile = dsh->profile; + st->codecpar->level = dsh->level; + if (av_image_check_sar(st->codecpar->width, st->codecpar->height, dsh->sample_aspect_ratio) >= 0) st->sample_aspect_ratio = dsh->sample_aspect_ratio; // dirac in ogg always stores timestamps as though the video were interlaced @@ -93,8 +93,8 @@ static int old_dirac_header(AVFormatContext *s, int idx) if (buf[0] != 'K') return 0; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_DIRAC; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_DIRAC; avpriv_set_pts_info(st, 64, AV_RB32(buf+12), AV_RB32(buf+8)); return 1; } diff --git a/libavformat/oggparseflac.c b/libavformat/oggparseflac.c index c7fb44618d..f08d07d7ab 100644 --- a/libavformat/oggparseflac.c +++ b/libavformat/oggparseflac.c @@ -57,15 +57,15 @@ flac_header (AVFormatContext * s, int idx) if (get_bits_long(&gb, 32) != FLAC_STREAMINFO_SIZE) return -1; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_FLAC; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_FLAC; st->need_parsing = AVSTREAM_PARSE_HEADERS; - if (ff_alloc_extradata(st->codec, FLAC_STREAMINFO_SIZE) < 0) + if (ff_alloc_extradata(st->codecpar, FLAC_STREAMINFO_SIZE) < 0) return AVERROR(ENOMEM); - memcpy(st->codec->extradata, streaminfo_start, st->codec->extradata_size); + memcpy(st->codecpar->extradata, streaminfo_start, st->codecpar->extradata_size); - samplerate = AV_RB24(st->codec->extradata + 10) >> 4; + samplerate = AV_RB24(st->codecpar->extradata + 10) >> 4; if (!samplerate) return AVERROR_INVALIDDATA; @@ -84,27 +84,38 @@ old_flac_header (AVFormatContext * s, int idx) AVStream *st = s->streams[idx]; struct ogg_stream *os = ogg->streams + idx; AVCodecParserContext *parser = av_parser_init(AV_CODEC_ID_FLAC); - int size; + AVCodecContext *avctx; + int size, ret; uint8_t *data; if (!parser) return -1; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_FLAC; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_FLAC; + + avctx = avcodec_alloc_context3(NULL); + if (!avctx) + return -1; + + ret = avcodec_parameters_to_context(avctx, st->codecpar); + if (ret < 0) + return -1; parser->flags = PARSER_FLAG_COMPLETE_FRAMES; - av_parser_parse2(parser, st->codec, + av_parser_parse2(parser, avctx, &data, &size, os->buf + os->pstart, os->psize, AV_NOPTS_VALUE, AV_NOPTS_VALUE, -1); av_parser_close(parser); - if (st->codec->sample_rate) { - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + if (avctx->sample_rate) { + avpriv_set_pts_info(st, 64, 1, avctx->sample_rate); + avcodec_free_context(&avctx); return 0; } + avcodec_free_context(&avctx); return 1; } diff --git a/libavformat/oggparseogm.c b/libavformat/oggparseogm.c index d63c83b1c2..65c2d5f274 100644 --- a/libavformat/oggparseogm.c +++ b/libavformat/oggparseogm.c @@ -52,28 +52,28 @@ ogm_header(AVFormatContext *s, int idx) if (bytestream2_peek_byte(&p) == 'v'){ int tag; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; bytestream2_skip(&p, 8); tag = bytestream2_get_le32(&p); - st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag); - st->codec->codec_tag = tag; - if (st->codec->codec_id == AV_CODEC_ID_MPEG4) + st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag); + st->codecpar->codec_tag = tag; + if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) st->need_parsing = AVSTREAM_PARSE_HEADERS; } else if (bytestream2_peek_byte(&p) == 't') { - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = AV_CODEC_ID_TEXT; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_TEXT; bytestream2_skip(&p, 12); } else { uint8_t acid[5] = { 0 }; int cid; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; bytestream2_skip(&p, 8); bytestream2_get_buffer(&p, acid, 4); acid[4] = 0; cid = strtol(acid, NULL, 16); - st->codec->codec_id = ff_codec_get_id(ff_codec_wav_tags, cid); + st->codecpar->codec_id = ff_codec_get_id(ff_codec_wav_tags, cid); // our parser completely breaks AAC in Ogg - if (st->codec->codec_id != AV_CODEC_ID_AAC) + if (st->codecpar->codec_id != AV_CODEC_ID_AAC) st->need_parsing = AVSTREAM_PARSE_FULL; } @@ -89,25 +89,25 @@ ogm_header(AVFormatContext *s, int idx) bytestream2_skip(&p, 4); /* default_len */ bytestream2_skip(&p, 8); /* buffersize + bits_per_sample */ - if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){ - st->codec->width = bytestream2_get_le32(&p); - st->codec->height = bytestream2_get_le32(&p); + if(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO){ + st->codecpar->width = bytestream2_get_le32(&p); + st->codecpar->height = bytestream2_get_le32(&p); avpriv_set_pts_info(st, 64, time_unit, spu * 10000000); } else { - st->codec->channels = bytestream2_get_le16(&p); + st->codecpar->channels = bytestream2_get_le16(&p); bytestream2_skip(&p, 2); /* block_align */ - st->codec->bit_rate = bytestream2_get_le32(&p) * 8; - st->codec->sample_rate = spu * 10000000 / time_unit; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); - if (size >= 56 && st->codec->codec_id == AV_CODEC_ID_AAC) { + st->codecpar->bit_rate = bytestream2_get_le32(&p) * 8; + st->codecpar->sample_rate = spu * 10000000 / time_unit; + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); + if (size >= 56 && st->codecpar->codec_id == AV_CODEC_ID_AAC) { bytestream2_skip(&p, 4); size -= 4; } if (size > 52) { av_assert0(AV_INPUT_BUFFER_PADDING_SIZE <= 52); size -= 52; - ff_alloc_extradata(st->codec, size); - bytestream2_get_buffer(&p, st->codec->extradata, st->codec->extradata_size); + ff_alloc_extradata(st->codecpar, size); + bytestream2_get_buffer(&p, st->codecpar->extradata, st->codecpar->extradata_size); } } } else if (bytestream2_peek_byte(&p) == 3) { @@ -141,20 +141,20 @@ ogm_dshow_header(AVFormatContext *s, int idx) if (os->psize < 184) return AVERROR_INVALIDDATA; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, AV_RL32(p + 68)); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, AV_RL32(p + 68)); avpriv_set_pts_info(st, 64, AV_RL64(p + 164), 10000000); - st->codec->width = AV_RL32(p + 176); - st->codec->height = AV_RL32(p + 180); + st->codecpar->width = AV_RL32(p + 176); + st->codecpar->height = AV_RL32(p + 180); } else if(t == 0x05589f81){ if (os->psize < 136) return AVERROR_INVALIDDATA; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = ff_codec_get_id(ff_codec_wav_tags, AV_RL16(p + 124)); - st->codec->channels = AV_RL16(p + 126); - st->codec->sample_rate = AV_RL32(p + 128); - st->codec->bit_rate = AV_RL32(p + 132) * 8; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = ff_codec_get_id(ff_codec_wav_tags, AV_RL16(p + 124)); + st->codecpar->channels = AV_RL16(p + 126); + st->codecpar->sample_rate = AV_RL32(p + 128); + st->codecpar->bit_rate = AV_RL32(p + 132) * 8; } return 1; diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c index c8b02fab4d..8191b1083c 100644 --- a/libavformat/oggparseopus.c +++ b/libavformat/oggparseopus.c @@ -52,24 +52,24 @@ static int opus_header(AVFormatContext *avf, int idx) if (os->flags & OGG_FLAG_BOS) { if (os->psize < OPUS_HEAD_SIZE || (AV_RL8(packet + 8) & 0xF0) != 0) return AVERROR_INVALIDDATA; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_OPUS; - st->codec->channels = AV_RL8 (packet + 9); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_OPUS; + st->codecpar->channels = AV_RL8(packet + 9); + priv->pre_skip = AV_RL16(packet + 10); - st->codec->delay = priv->pre_skip; + st->codecpar->initial_padding = priv->pre_skip; /*orig_sample_rate = AV_RL32(packet + 12);*/ /*gain = AV_RL16(packet + 16);*/ /*channel_map = AV_RL8 (packet + 18);*/ - if (ff_alloc_extradata(st->codec, os->psize)) + if (ff_alloc_extradata(st->codecpar, os->psize)) return AVERROR(ENOMEM); - memcpy(st->codec->extradata, packet, os->psize); + memcpy(st->codecpar->extradata, packet, os->psize); - st->codec->sample_rate = 48000; - av_codec_set_seek_preroll(st->codec, - av_rescale(OPUS_SEEK_PREROLL_MS, - st->codec->sample_rate, 1000)); + st->codecpar->sample_rate = 48000; + st->codecpar->seek_preroll = av_rescale(OPUS_SEEK_PREROLL_MS, + st->codecpar->sample_rate, 1000); avpriv_set_pts_info(st, 64, 1, 48000); priv->need_comments = 1; return 1; diff --git a/libavformat/oggparseskeleton.c b/libavformat/oggparseskeleton.c index 6c2105f324..532fa6aefa 100644 --- a/libavformat/oggparseskeleton.c +++ b/libavformat/oggparseskeleton.c @@ -34,7 +34,7 @@ static int skeleton_header(AVFormatContext *s, int idx) uint64_t start_granule; int target_idx, start_time; - st->codec->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; if ((os->flags & OGG_FLAG_EOS) && os->psize == 0) return 1; diff --git a/libavformat/oggparsespeex.c b/libavformat/oggparsespeex.c index c86b12713e..d7b153aa15 100644 --- a/libavformat/oggparsespeex.c +++ b/libavformat/oggparsespeex.c @@ -57,33 +57,33 @@ static int speex_header(AVFormatContext *s, int idx) { if (spxp->seq == 0) { int frames_per_packet; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_SPEEX; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_SPEEX; if (os->psize < 68) { av_log(s, AV_LOG_ERROR, "speex packet too small\n"); return AVERROR_INVALIDDATA; } - st->codec->sample_rate = AV_RL32(p + 36); - st->codec->channels = AV_RL32(p + 48); - if (st->codec->channels < 1 || st->codec->channels > 2) { + st->codecpar->sample_rate = AV_RL32(p + 36); + st->codecpar->channels = AV_RL32(p + 48); + if (st->codecpar->channels < 1 || st->codecpar->channels > 2) { av_log(s, AV_LOG_ERROR, "invalid channel count. Speex must be mono or stereo.\n"); return AVERROR_INVALIDDATA; } - st->codec->channel_layout = st->codec->channels == 1 ? AV_CH_LAYOUT_MONO : - AV_CH_LAYOUT_STEREO; + st->codecpar->channel_layout = st->codecpar->channels == 1 ? AV_CH_LAYOUT_MONO : + AV_CH_LAYOUT_STEREO; spxp->packet_size = AV_RL32(p + 56); frames_per_packet = AV_RL32(p + 64); if (frames_per_packet) spxp->packet_size *= frames_per_packet; - if (ff_alloc_extradata(st->codec, os->psize) < 0) + if (ff_alloc_extradata(st->codecpar, os->psize) < 0) return AVERROR(ENOMEM); - memcpy(st->codec->extradata, p, st->codec->extradata_size); + memcpy(st->codecpar->extradata, p, st->codecpar->extradata_size); - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); } else ff_vorbis_stream_comment(s, st, p, os->psize); diff --git a/libavformat/oggparsetheora.c b/libavformat/oggparsetheora.c index 5f057c3c8a..b14f9f0669 100644 --- a/libavformat/oggparsetheora.c +++ b/libavformat/oggparsetheora.c @@ -41,7 +41,7 @@ static int theora_header(AVFormatContext *s, int idx) struct ogg_stream *os = ogg->streams + idx; AVStream *st = s->streams[idx]; TheoraParams *thp = os->private; - int cds = st->codec->extradata_size + os->psize + 2; + int cds = st->codecpar->extradata_size + os->psize + 2; int err; uint8_t *cdp; @@ -72,8 +72,8 @@ static int theora_header(AVFormatContext *s, int idx) return AVERROR(ENOSYS); } - st->codec->width = get_bits(&gb, 16) << 4; - st->codec->height = get_bits(&gb, 16) << 4; + st->codecpar->width = get_bits(&gb, 16) << 4; + st->codecpar->height = get_bits(&gb, 16) << 4; if (thp->version >= 0x030400) skip_bits(&gb, 100); @@ -81,10 +81,10 @@ static int theora_header(AVFormatContext *s, int idx) if (thp->version >= 0x030200) { int width = get_bits_long(&gb, 24); int height = get_bits_long(&gb, 24); - if (width <= st->codec->width && width > st->codec->width - 16 && - height <= st->codec->height && height > st->codec->height - 16) { - st->codec->width = width; - st->codec->height = height; + if (width <= st->codecpar->width && width > st->codecpar->width - 16 && + height <= st->codecpar->height && height > st->codecpar->height - 16) { + st->codecpar->width = width; + st->codecpar->height = height; } skip_bits(&gb, 16); @@ -110,8 +110,8 @@ static int theora_header(AVFormatContext *s, int idx) thp->gpshift = get_bits(&gb, 5); thp->gpmask = (1U << thp->gpshift) - 1; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_THEORA; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_THEORA; st->need_parsing = AVSTREAM_PARSE_HEADERS; } break; @@ -126,18 +126,18 @@ static int theora_header(AVFormatContext *s, int idx) return AVERROR_INVALIDDATA; } - if ((err = av_reallocp(&st->codec->extradata, + if ((err = av_reallocp(&st->codecpar->extradata, cds + AV_INPUT_BUFFER_PADDING_SIZE)) < 0) { - st->codec->extradata_size = 0; + st->codecpar->extradata_size = 0; return err; } - memset(st->codec->extradata + cds, 0, AV_INPUT_BUFFER_PADDING_SIZE); + memset(st->codecpar->extradata + cds, 0, AV_INPUT_BUFFER_PADDING_SIZE); - cdp = st->codec->extradata + st->codec->extradata_size; + cdp = st->codecpar->extradata + st->codecpar->extradata_size; *cdp++ = os->psize >> 8; *cdp++ = os->psize & 0xff; memcpy(cdp, os->buf + os->pstart, os->psize); - st->codec->extradata_size = cds; + st->codecpar->extradata_size = cds; return 1; } diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c index b96be98974..a8cd6c9f97 100644 --- a/libavformat/oggparsevorbis.c +++ b/libavformat/oggparsevorbis.c @@ -335,14 +335,14 @@ static int vorbis_header(AVFormatContext *s, int idx) return AVERROR_INVALIDDATA; channels = bytestream_get_byte(&p); - if (st->codec->channels && channels != st->codec->channels) { + if (st->codecpar->channels && channels != st->codecpar->channels) { av_log(s, AV_LOG_ERROR, "Channel change is not supported\n"); return AVERROR_PATCHWELCOME; } - st->codec->channels = channels; + st->codecpar->channels = channels; srate = bytestream_get_le32(&p); p += 4; // skip maximum bitrate - st->codec->bit_rate = bytestream_get_le32(&p); // nominal bitrate + st->codecpar->bit_rate = bytestream_get_le32(&p); // nominal bitrate p += 4; // skip minimum bitrate blocksize = bytestream_get_byte(&p); @@ -357,11 +357,11 @@ static int vorbis_header(AVFormatContext *s, int idx) if (bytestream_get_byte(&p) != 1) /* framing_flag */ return AVERROR_INVALIDDATA; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_VORBIS; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_VORBIS; if (srate > 0) { - st->codec->sample_rate = srate; + st->codecpar->sample_rate = srate; avpriv_set_pts_info(st, 64, 1, srate); } } else if (os->buf[os->pstart] == 3) { @@ -381,17 +381,17 @@ static int vorbis_header(AVFormatContext *s, int idx) } } } else { - int ret = fixup_vorbis_headers(s, priv, &st->codec->extradata); + int ret = fixup_vorbis_headers(s, priv, &st->codecpar->extradata); if (ret < 0) { - st->codec->extradata_size = 0; + st->codecpar->extradata_size = 0; return ret; } - st->codec->extradata_size = ret; + st->codecpar->extradata_size = ret; - priv->vp = av_vorbis_parse_init(st->codec->extradata, st->codec->extradata_size); + priv->vp = av_vorbis_parse_init(st->codecpar->extradata, st->codecpar->extradata_size); if (!priv->vp) { - av_freep(&st->codec->extradata); - st->codec->extradata_size = 0; + av_freep(&st->codecpar->extradata); + st->codecpar->extradata_size = 0; return AVERROR_UNKNOWN; } } diff --git a/libavformat/oggparsevp8.c b/libavformat/oggparsevp8.c index 7aed8abad3..d57419e9f0 100644 --- a/libavformat/oggparsevp8.c +++ b/libavformat/oggparsevp8.c @@ -51,16 +51,16 @@ static int vp8_header(AVFormatContext *s, int idx) return AVERROR_INVALIDDATA; } - st->codec->width = AV_RB16(p + 8); - st->codec->height = AV_RB16(p + 10); + st->codecpar->width = AV_RB16(p + 8); + st->codecpar->height = AV_RB16(p + 10); st->sample_aspect_ratio.num = AV_RB24(p + 12); st->sample_aspect_ratio.den = AV_RB24(p + 15); framerate.num = AV_RB32(p + 18); framerate.den = AV_RB32(p + 22); avpriv_set_pts_info(st, 64, framerate.den, framerate.num); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_VP8; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_VP8; st->need_parsing = AVSTREAM_PARSE_HEADERS; break; case 0x02: diff --git a/libavformat/omadec.c b/libavformat/omadec.c index 132992dd33..6e476dbf25 100644 --- a/libavformat/omadec.c +++ b/libavformat/omadec.c @@ -342,10 +342,10 @@ static int oma_read_header(AVFormatContext *s) return AVERROR(ENOMEM); st->start_time = 0; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_tag = buf[32]; - st->codec->codec_id = ff_codec_get_id(ff_oma_codec_tags, - st->codec->codec_tag); + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_tag = buf[32]; + st->codecpar->codec_id = ff_codec_get_id(ff_oma_codec_tags, + st->codecpar->codec_tag); switch (buf[32]) { case OMA_CODECID_ATRAC3: @@ -362,17 +362,17 @@ static int oma_read_header(AVFormatContext *s) /* get stereo coding mode, 1 for joint-stereo */ jsflag = (codec_params >> 17) & 1; - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; - st->codec->sample_rate = samplerate; - st->codec->bit_rate = st->codec->sample_rate * framesize * 8 / 1024; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->sample_rate = samplerate; + st->codecpar->bit_rate = st->codecpar->sample_rate * framesize * 8 / 1024; /* fake the ATRAC3 extradata * (wav format, makes stream copy to wav work) */ - if (ff_alloc_extradata(st->codec, 14)) + if (ff_alloc_extradata(st->codecpar, 14)) return AVERROR(ENOMEM); - edata = st->codec->extradata; + edata = st->codecpar->extradata; AV_WL16(&edata[0], 1); // always 1 AV_WL32(&edata[2], samplerate); // samples rate AV_WL16(&edata[6], jsflag); // coding mode @@ -380,7 +380,7 @@ static int oma_read_header(AVFormatContext *s) AV_WL16(&edata[10], 1); // always 1 // AV_WL16(&edata[12], 0); // always 0 - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); break; case OMA_CODECID_ATRAC3P: channel_id = (codec_params >> 10) & 7; @@ -389,16 +389,16 @@ static int oma_read_header(AVFormatContext *s) "Invalid ATRAC-X channel id: %"PRIu32"\n", channel_id); return AVERROR_INVALIDDATA; } - st->codec->channel_layout = ff_oma_chid_to_native_layout[channel_id - 1]; - st->codec->channels = ff_oma_chid_to_num_channels[channel_id - 1]; + st->codecpar->channel_layout = ff_oma_chid_to_native_layout[channel_id - 1]; + st->codecpar->channels = ff_oma_chid_to_num_channels[channel_id - 1]; framesize = ((codec_params & 0x3FF) * 8) + 8; samplerate = ff_oma_srate_tab[(codec_params >> 13) & 7] * 100; if (!samplerate) { av_log(s, AV_LOG_ERROR, "Unsupported sample rate\n"); return AVERROR_INVALIDDATA; } - st->codec->sample_rate = samplerate; - st->codec->bit_rate = samplerate * framesize * 8 / 2048; + st->codecpar->sample_rate = samplerate; + st->codecpar->bit_rate = samplerate * framesize * 8 / 2048; avpriv_set_pts_info(st, 64, 1, samplerate); break; case OMA_CODECID_MP3: @@ -407,22 +407,22 @@ static int oma_read_header(AVFormatContext *s) break; case OMA_CODECID_LPCM: /* PCM 44.1 kHz 16 bit stereo big-endian */ - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; - st->codec->sample_rate = 44100; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->sample_rate = 44100; framesize = 1024; /* bit rate = sample rate x PCM block align (= 4) x 8 */ - st->codec->bit_rate = st->codec->sample_rate * 32; - st->codec->bits_per_coded_sample = - av_get_bits_per_sample(st->codec->codec_id); - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + st->codecpar->bit_rate = st->codecpar->sample_rate * 32; + st->codecpar->bits_per_coded_sample = + av_get_bits_per_sample(st->codecpar->codec_id); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); break; default: av_log(s, AV_LOG_ERROR, "Unsupported codec %d!\n", buf[32]); return AVERROR(ENOSYS); } - st->codec->block_align = framesize; + st->codecpar->block_align = framesize; return 0; } @@ -432,8 +432,8 @@ static int oma_read_packet(AVFormatContext *s, AVPacket *pkt) { OMAContext *oc = s->priv_data; AVStream *st = s->streams[0]; - int packet_size = st->codec->block_align; - int byte_rate = st->codec->bit_rate >> 3; + int packet_size = st->codecpar->block_align; + int byte_rate = st->codecpar->bit_rate >> 3; int64_t pos = avio_tell(s->pb); int ret = av_get_packet(s->pb, pkt, packet_size); diff --git a/libavformat/omaenc.c b/libavformat/omaenc.c index fe0669f5c9..d89cc37ee0 100644 --- a/libavformat/omaenc.c +++ b/libavformat/omaenc.c @@ -30,21 +30,21 @@ static av_cold int oma_write_header(AVFormatContext *s) { int i; - AVCodecContext *format; + AVCodecParameters *par; int srate_index; int isjointstereo; - format = s->streams[0]->codec; + par = s->streams[0]->codecpar; /* check for support of the format first */ for (srate_index = 0; ; srate_index++) { if (ff_oma_srate_tab[srate_index] == 0) { av_log(s, AV_LOG_ERROR, "Sample rate %d not supported in OpenMG audio\n", - format->sample_rate); + par->sample_rate); return AVERROR(EINVAL); } - if (ff_oma_srate_tab[srate_index] * 100 == format->sample_rate) + if (ff_oma_srate_tab[srate_index] * 100 == par->sample_rate) break; } @@ -58,16 +58,16 @@ static av_cold int oma_write_header(AVFormatContext *s) for (i = 0; i < 6; i++) avio_wl32(s->pb, 0); /* Padding + DRM id */ - switch(format->codec_tag) { + switch (par->codec_tag) { case OMA_CODECID_ATRAC3: - if (format->channels != 2) { + if (par->channels != 2) { av_log(s, AV_LOG_ERROR, "ATRAC3 in OMA is only supported with 2 channels\n"); return AVERROR(EINVAL); } - if (format->extradata_size == 14) /* WAV format extradata */ - isjointstereo = format->extradata[6] != 0; - else if(format->extradata_size == 10) /* RM format extradata */ - isjointstereo = format->extradata[8] == 0x12; + if (par->extradata_size == 14) /* WAV format extradata */ + isjointstereo = par->extradata[6] != 0; + else if(par->extradata_size == 10) /* RM format extradata */ + isjointstereo = par->extradata[8] == 0x12; else { av_log(s, AV_LOG_ERROR, "ATRAC3: Unsupported extradata size\n"); return AVERROR(EINVAL); @@ -75,17 +75,17 @@ static av_cold int oma_write_header(AVFormatContext *s) avio_wb32(s->pb, (OMA_CODECID_ATRAC3 << 24) | (isjointstereo << 17) | (srate_index << 13) | - (format->block_align/8)); + (par->block_align/8)); break; case OMA_CODECID_ATRAC3P: avio_wb32(s->pb, (OMA_CODECID_ATRAC3P << 24) | (srate_index << 13) | - (format->channels << 10) | - (format->block_align/8 - 1)); + (par->channels << 10) | + (par->block_align/8 - 1)); break; default: av_log(s, AV_LOG_ERROR, "unsupported codec tag %d for write\n", - format->codec_tag); + par->codec_tag); return AVERROR(EINVAL); } for (i = 0; i < (EA3_HEADER_SIZE - 36)/4; i++) diff --git a/libavformat/paf.c b/libavformat/paf.c index 4fc5006f40..fa30cdd72a 100644 --- a/libavformat/paf.c +++ b/libavformat/paf.c @@ -104,13 +104,13 @@ static int read_header(AVFormatContext *s) p->nb_frames = avio_rl32(pb); avio_skip(pb, 4); - vst->codec->width = avio_rl32(pb); - vst->codec->height = avio_rl32(pb); + vst->codecpar->width = avio_rl32(pb); + vst->codecpar->height = avio_rl32(pb); avio_skip(pb, 4); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; - vst->codec->codec_tag = 0; - vst->codec->codec_id = AV_CODEC_ID_PAF_VIDEO; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_tag = 0; + vst->codecpar->codec_id = AV_CODEC_ID_PAF_VIDEO; avpriv_set_pts_info(vst, 64, 1, 10); ast = avformat_new_stream(s, 0); @@ -118,12 +118,12 @@ static int read_header(AVFormatContext *s) return AVERROR(ENOMEM); ast->start_time = 0; - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_tag = 0; - ast->codec->codec_id = AV_CODEC_ID_PAF_AUDIO; - ast->codec->channels = 2; - ast->codec->channel_layout = AV_CH_LAYOUT_STEREO; - ast->codec->sample_rate = 22050; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_tag = 0; + ast->codecpar->codec_id = AV_CODEC_ID_PAF_AUDIO; + ast->codecpar->channels = 2; + ast->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; + ast->codecpar->sample_rate = 22050; avpriv_set_pts_info(ast, 64, 1, 22050); p->buffer_size = avio_rl32(pb); diff --git a/libavformat/pcm.c b/libavformat/pcm.c index f62075fc82..806f91b6b1 100644 --- a/libavformat/pcm.c +++ b/libavformat/pcm.c @@ -30,7 +30,7 @@ int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt) { int ret, size; - size= RAW_SAMPLES*s->streams[0]->codec->block_align; + size= RAW_SAMPLES*s->streams[0]->codecpar->block_align; if (size <= 0) return AVERROR(EINVAL); @@ -51,10 +51,10 @@ int ff_pcm_read_seek(AVFormatContext *s, st = s->streams[0]; - block_align = st->codec->block_align ? st->codec->block_align : - (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3; - byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 : - block_align * st->codec->sample_rate; + block_align = st->codecpar->block_align ? st->codecpar->block_align : + (av_get_bits_per_sample(st->codecpar->codec_id) * st->codecpar->channels) >> 3; + byte_rate = st->codecpar->bit_rate ? st->codecpar->bit_rate >> 3 : + block_align * st->codecpar->sample_rate; if (block_align <= 0 || byte_rate <= 0) return -1; diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c index 2584c33c24..df94345a5a 100644 --- a/libavformat/pcmdec.c +++ b/libavformat/pcmdec.c @@ -42,20 +42,20 @@ static int pcm_read_header(AVFormatContext *s) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->iformat->raw_codec_id; - st->codec->sample_rate = s1->sample_rate; - st->codec->channels = s1->channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = s->iformat->raw_codec_id; + st->codecpar->sample_rate = s1->sample_rate; + st->codecpar->channels = s1->channels; - st->codec->bits_per_coded_sample = - av_get_bits_per_sample(st->codec->codec_id); + st->codecpar->bits_per_coded_sample = + av_get_bits_per_sample(st->codecpar->codec_id); - av_assert0(st->codec->bits_per_coded_sample > 0); + av_assert0(st->codecpar->bits_per_coded_sample > 0); - st->codec->block_align = - st->codec->bits_per_coded_sample * st->codec->channels / 8; + st->codecpar->block_align = + st->codecpar->bits_per_coded_sample * st->codecpar->channels / 8; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } diff --git a/libavformat/pjsdec.c b/libavformat/pjsdec.c index a88d533192..bb587b569a 100644 --- a/libavformat/pjsdec.c +++ b/libavformat/pjsdec.c @@ -70,8 +70,8 @@ static int pjs_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 64, 1, 10); - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = AV_CODEC_ID_PJS; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_PJS; while (!avio_feof(s->pb)) { char line[4096]; diff --git a/libavformat/pmpdec.c b/libavformat/pmpdec.c index ec966b3e1a..0e80a095fb 100644 --- a/libavformat/pmpdec.c +++ b/libavformat/pmpdec.c @@ -54,22 +54,22 @@ static int pmp_header(AVFormatContext *s) AVStream *vst = avformat_new_stream(s, NULL); if (!vst) return AVERROR(ENOMEM); - vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; avio_skip(pb, 8); switch (avio_rl32(pb)) { case 0: - vst->codec->codec_id = AV_CODEC_ID_MPEG4; + vst->codecpar->codec_id = AV_CODEC_ID_MPEG4; break; case 1: - vst->codec->codec_id = AV_CODEC_ID_H264; + vst->codecpar->codec_id = AV_CODEC_ID_H264; break; default: av_log(s, AV_LOG_ERROR, "Unsupported video format\n"); break; } - index_cnt = avio_rl32(pb); - vst->codec->width = avio_rl32(pb); - vst->codec->height = avio_rl32(pb); + index_cnt = avio_rl32(pb); + vst->codecpar->width = avio_rl32(pb); + vst->codecpar->height = avio_rl32(pb); tb_num = avio_rl32(pb); tb_den = avio_rl32(pb); @@ -117,10 +117,10 @@ static int pmp_header(AVFormatContext *s) AVStream *ast = avformat_new_stream(s, NULL); if (!ast) return AVERROR(ENOMEM); - ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; - ast->codec->codec_id = audio_codec_id; - ast->codec->channels = channels; - ast->codec->sample_rate = srate; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_id = audio_codec_id; + ast->codecpar->channels = channels; + ast->codecpar->sample_rate = srate; avpriv_set_pts_info(ast, 32, 1, srate); } return 0; diff --git a/libavformat/psxstr.c b/libavformat/psxstr.c index 38186f7fd1..ca89fcfe58 100644 --- a/libavformat/psxstr.c +++ b/libavformat/psxstr.c @@ -199,11 +199,11 @@ static int str_read_packet(AVFormatContext *s, str->channels[channel].video_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MDEC; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = AV_RL16(§or[0x28]); - st->codec->height = AV_RL16(§or[0x2A]); + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MDEC; + st->codecpar->codec_tag = 0; /* no fourcc */ + st->codecpar->width = AV_RL16(§or[0x28]); + st->codecpar->height = AV_RL16(§or[0x2A]); } /* if this is the first sector of the frame, allocate a pkt */ @@ -248,22 +248,22 @@ static int str_read_packet(AVFormatContext *s, str->channels[channel].audio_stream_index = st->index; - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_ADPCM_XA; - st->codec->codec_tag = 0; /* no fourcc */ + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_ADPCM_XA; + st->codecpar->codec_tag = 0; /* no fourcc */ if (fmt & 1) { - st->codec->channels = 2; - st->codec->channel_layout = AV_CH_LAYOUT_STEREO; + st->codecpar->channels = 2; + st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO; } else { - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; } - st->codec->sample_rate = (fmt&4)?18900:37800; - // st->codec->bit_rate = 0; //FIXME; - st->codec->block_align = 128; + st->codecpar->sample_rate = (fmt&4)?18900:37800; + // st->codecpar->bit_rate = 0; //FIXME; + st->codecpar->block_align = 128; - avpriv_set_pts_info(st, 64, 18 * 224 / st->codec->channels, - st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 18 * 224 / st->codecpar->channels, + st->codecpar->sample_rate); st->start_time = 0; } pkt = ret_pkt; diff --git a/libavformat/pva.c b/libavformat/pva.c index 900ad6133d..16381db905 100644 --- a/libavformat/pva.c +++ b/libavformat/pva.c @@ -59,16 +59,16 @@ static int pva_read_header(AVFormatContext *s) { if (!(st = avformat_new_stream(s, NULL))) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_MPEG2VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_MPEG2VIDEO; st->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 32, 1, 90000); av_add_index_entry(st, 0, 0, 0, 0, AVINDEX_KEYFRAME); if (!(st = avformat_new_stream(s, NULL))) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_MP2; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_MP2; st->need_parsing = AVSTREAM_PARSE_FULL; avpriv_set_pts_info(st, 33, 1, 90000); av_add_index_entry(st, 0, 0, 0, 0, AVINDEX_KEYFRAME); diff --git a/libavformat/pvfdec.c b/libavformat/pvfdec.c index c678046156..b9f6d4f2c2 100644 --- a/libavformat/pvfdec.c +++ b/libavformat/pvfdec.c @@ -51,14 +51,14 @@ static int pvf_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->channels = channels; - st->codec->sample_rate = sample_rate; - st->codec->codec_id = ff_get_pcm_codec_id(bps, 0, 1, 0xFFFF); - st->codec->bits_per_coded_sample = bps; - st->codec->block_align = bps * st->codec->channels / 8; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->channels = channels; + st->codecpar->sample_rate = sample_rate; + st->codecpar->codec_id = ff_get_pcm_codec_id(bps, 0, 1, 0xFFFF); + st->codecpar->bits_per_coded_sample = bps; + st->codecpar->block_align = bps * st->codecpar->channels / 8; - avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; } diff --git a/libavformat/qcp.c b/libavformat/qcp.c index ad4a8ae79c..b842e2633c 100644 --- a/libavformat/qcp.c +++ b/libavformat/qcp.c @@ -101,29 +101,29 @@ static int qcp_read_header(AVFormatContext *s) avio_rb32(pb); // "RIFF" avio_skip(pb, 4 + 8 + 4 + 1 + 1); // filesize + "QLCMfmt " + chunk-size + major-version + minor-version - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->channels = 1; - st->codec->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; avio_read(pb, buf, 16); if (is_qcelp_13k_guid(buf)) { - st->codec->codec_id = AV_CODEC_ID_QCELP; + st->codecpar->codec_id = AV_CODEC_ID_QCELP; } else if (!memcmp(buf, guid_evrc, 16)) { - st->codec->codec_id = AV_CODEC_ID_EVRC; + st->codecpar->codec_id = AV_CODEC_ID_EVRC; } else if (!memcmp(buf, guid_smv, 16)) { - st->codec->codec_id = AV_CODEC_ID_SMV; + st->codecpar->codec_id = AV_CODEC_ID_SMV; } else if (!memcmp(buf, guid_4gv, 16)) { - st->codec->codec_id = AV_CODEC_ID_4GV; + st->codecpar->codec_id = AV_CODEC_ID_4GV; } else { av_log(s, AV_LOG_ERROR, "Unknown codec GUID "FF_PRI_GUID".\n", FF_ARG_GUID(buf)); return AVERROR_INVALIDDATA; } avio_skip(pb, 2 + 80); // codec-version + codec-name - st->codec->bit_rate = avio_rl16(pb); + st->codecpar->bit_rate = avio_rl16(pb); s->packet_size = avio_rl16(pb); avio_skip(pb, 2); // block-size - st->codec->sample_rate = avio_rl16(pb); + st->codecpar->sample_rate = avio_rl16(pb); avio_skip(pb, 2); // sample-size memset(c->rates_per_mode, -1, sizeof(c->rates_per_mode)); diff --git a/libavformat/r3d.c b/libavformat/r3d.c index 94c3015fd5..b609488839 100644 --- a/libavformat/r3d.c +++ b/libavformat/r3d.c @@ -62,8 +62,8 @@ static int r3d_read_red1(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = AV_CODEC_ID_JPEG2000; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = AV_CODEC_ID_JPEG2000; tmp = avio_r8(s->pb); // major version tmp2 = avio_r8(s->pb); // minor version @@ -80,8 +80,8 @@ static int r3d_read_red1(AVFormatContext *s) avio_skip(s->pb, 32); // unknown - st->codec->width = avio_rb32(s->pb); - st->codec->height = avio_rb32(s->pb); + st->codecpar->width = avio_rb32(s->pb); + st->codecpar->height = avio_rb32(s->pb); tmp = avio_rb16(s->pb); // unknown av_log(s, AV_LOG_TRACE, "unknown2 %d\n", tmp); @@ -103,7 +103,7 @@ static int r3d_read_red1(AVFormatContext *s) av_dict_set(&st->metadata, "filename", filename, 0); av_log(s, AV_LOG_TRACE, "filename %s\n", filename); - av_log(s, AV_LOG_TRACE, "resolution %dx%d\n", st->codec->width, st->codec->height); + av_log(s, AV_LOG_TRACE, "resolution %dx%d\n", st->codecpar->width, st->codecpar->height); av_log(s, AV_LOG_TRACE, "timescale %d\n", st->time_base.den); av_log(s, AV_LOG_TRACE, "frame rate %d/%d\n", framerate.num, framerate.den); @@ -284,9 +284,9 @@ static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom) st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = AV_CODEC_ID_PCM_S32BE; - st->codec->channels = r3d->audio_channels; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_PCM_S32BE; + st->codecpar->channels = r3d->audio_channels; avpriv_set_pts_info(st, 32, 1, s->streams[0]->time_base.den); } else { st = s->streams[1]; @@ -294,8 +294,8 @@ static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom) dts = avio_rb32(s->pb); - st->codec->sample_rate = avio_rb32(s->pb); - if (st->codec->sample_rate <= 0) { + st->codecpar->sample_rate = avio_rb32(s->pb); + if (st->codecpar->sample_rate <= 0) { av_log(s, AV_LOG_ERROR, "Bad sample rate\n"); return AVERROR_INVALIDDATA; } @@ -326,10 +326,10 @@ static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom) pkt->stream_index = 1; pkt->dts = dts; - if (st->codec->sample_rate) - pkt->duration = av_rescale(samples, st->time_base.den, st->codec->sample_rate); + if (st->codecpar->sample_rate) + pkt->duration = av_rescale(samples, st->time_base.den, st->codecpar->sample_rate); av_log(s, AV_LOG_TRACE, "pkt dts %"PRId64" duration %"PRId64" samples %d sample rate %d\n", - pkt->dts, pkt->duration, samples, st->codec->sample_rate); + pkt->dts, pkt->duration, samples, st->codecpar->sample_rate); return 0; } diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c index 35ad1181c2..8c734dbb30 100644 --- a/libavformat/rawdec.c +++ b/libavformat/rawdec.c @@ -57,8 +57,8 @@ int ff_raw_audio_read_header(AVFormatContext *s) AVStream *st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - st->codec->codec_id = s->iformat->raw_codec_id; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = s->iformat->raw_codec_id; st->need_parsing = AVSTREAM_PARSE_FULL_RAW; st->start_time = 0; /* the parameters will be extracted from the compressed bitstream */ @@ -80,12 +80,12 @@ int ff_raw_video_read_header(AVFormatContext *s) goto fail; } - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = s->iformat->raw_codec_id; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = s->iformat->raw_codec_id; st->need_parsing = AVSTREAM_PARSE_FULL_RAW; - st->codec->framerate = s1->framerate; - st->codec->time_base = av_inv_q(s1->framerate); + st->avg_frame_rate = s1->framerate; + st->internal->avctx->framerate = s1->framerate; avpriv_set_pts_info(st, 64, 1, 1200000); fail: @@ -97,8 +97,8 @@ int ff_raw_data_read_header(AVFormatContext *s) AVStream *st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_DATA; - st->codec->codec_id = s->iformat->raw_codec_id; + st->codecpar->codec_type = AVMEDIA_TYPE_DATA; + st->codecpar->codec_id = s->iformat->raw_codec_id; st->start_time = 0; return 0; } diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c index 14ba9fbf47..4b8b41ca04 100644 --- a/libavformat/rawenc.c +++ b/libavformat/rawenc.c @@ -60,11 +60,11 @@ AVOutputFormat ff_ac3_muxer = { static int adx_write_trailer(AVFormatContext *s) { AVIOContext *pb = s->pb; - AVCodecContext *avctx = s->streams[0]->codec; + AVCodecParameters *par = s->streams[0]->codecpar; if (pb->seekable) { int64_t file_size = avio_tell(pb); - uint64_t sample_count = (file_size - 36) / avctx->channels / 18 * 32; + uint64_t sample_count = (file_size - 36) / par->channels / 18 * 32; if (sample_count <= UINT32_MAX) { avio_seek(pb, 12, SEEK_SET); avio_wb32(pb, sample_count); diff --git a/libavformat/rawutils.c b/libavformat/rawutils.c index 26ebbb5629..996412adb9 100644 --- a/libavformat/rawutils.c +++ b/libavformat/rawutils.c @@ -22,30 +22,30 @@ #include "avformat.h" #include "internal.h" -int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecContext *enc, int expected_stride) +int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecParameters *par, int expected_stride) { int ret; AVPacket *pkt = *ppkt; - int64_t bpc = enc->bits_per_coded_sample != 15 ? enc->bits_per_coded_sample : 16; - int min_stride = (enc->width * bpc + 7) >> 3; - int with_pal_size = min_stride * enc->height + 1024; + int64_t bpc = par->bits_per_coded_sample != 15 ? par->bits_per_coded_sample : 16; + int min_stride = (par->width * bpc + 7) >> 3; + int with_pal_size = min_stride * par->height + 1024; int contains_pal = bpc == 8 && pkt->size == with_pal_size; - int size = contains_pal ? min_stride * enc->height : pkt->size; - int stride = size / enc->height; + int size = contains_pal ? min_stride * par->height : pkt->size; + int stride = size / par->height; int padding = expected_stride - FFMIN(expected_stride, stride); int y; AVPacket *new_pkt; - if (pkt->size == expected_stride * enc->height) + if (pkt->size == expected_stride * par->height) return 0; - if (size != stride * enc->height) + if (size != stride * par->height) return 0; new_pkt = av_packet_alloc(); if (!new_pkt) return AVERROR(ENOMEM); - ret = av_new_packet(new_pkt, expected_stride * enc->height); + ret = av_new_packet(new_pkt, expected_stride * par->height); if (ret < 0) goto fail; @@ -53,7 +53,7 @@ int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecContext *en if (ret < 0) goto fail; - for (y = 0; yheight; y++) { + for (y = 0; yheight; y++) { memcpy(new_pkt->data + y*expected_stride, pkt->data + y*stride, FFMIN(expected_stride, stride)); memset(new_pkt->data + y*expected_stride + expected_stride - padding, 0, padding); } diff --git a/libavformat/rawvideodec.c b/libavformat/rawvideodec.c index 91bdba0e9a..b037aeaa59 100644 --- a/libavformat/rawvideodec.c +++ b/libavformat/rawvideodec.c @@ -45,9 +45,9 @@ static int rawvideo_read_header(AVFormatContext *ctx) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; - st->codec->codec_id = ctx->iformat->raw_codec_id; + st->codecpar->codec_id = ctx->iformat->raw_codec_id; if ((pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) { av_log(ctx, AV_LOG_ERROR, "No such pixel format: %s.\n", @@ -57,14 +57,14 @@ static int rawvideo_read_header(AVFormatContext *ctx) avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num); - st->codec->width = s->width; - st->codec->height = s->height; - st->codec->pix_fmt = pix_fmt; - packet_size = av_image_get_buffer_size(st->codec->pix_fmt, s->width, s->height, 1); + st->codecpar->width = s->width; + st->codecpar->height = s->height; + st->codecpar->format = pix_fmt; + packet_size = av_image_get_buffer_size(st->codecpar->format, s->width, s->height, 1); if (packet_size < 0) return packet_size; ctx->packet_size = packet_size; - st->codec->bit_rate = av_rescale_q(ctx->packet_size, + st->codecpar->bit_rate = av_rescale_q(ctx->packet_size, (AVRational){8,1}, st->time_base); return 0; diff --git a/libavformat/rdt.c b/libavformat/rdt.c index 0300b76928..6cb4d6aa42 100644 --- a/libavformat/rdt.c +++ b/libavformat/rdt.c @@ -309,7 +309,7 @@ rdt_parse_packet (AVFormatContext *ctx, PayloadContext *rdt, AVStream *st, if (res < 0) return res; if (res > 0) { - if (st->codec->codec_id == AV_CODEC_ID_AAC) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC) { memcpy (rdt->buffer, buf + pos, len - pos); rdt->rmctx->pb = avio_alloc_context (rdt->buffer, len - pos, 0, NULL, NULL, NULL, NULL); @@ -322,7 +322,7 @@ get_cache: ff_rm_retrieve_cache (rdt->rmctx, rdt->rmctx->pb, st, rdt->rmst[st->index], pkt); if (rdt->audio_pkt_cnt == 0 && - st->codec->codec_id == AV_CODEC_ID_AAC) + st->codecpar->codec_id == AV_CODEC_ID_AAC) av_freep(&rdt->rmctx->pb); } pkt->stream_index = st->index; @@ -448,7 +448,7 @@ real_parse_asm_rule(AVStream *st, const char *p, const char *end) { do { /* can be either averagebandwidth= or AverageBandwidth= */ - if (sscanf(p, " %*1[Aa]verage%*1[Bb]andwidth=%"SCNd64, &st->codec->bit_rate) == 1) + if (sscanf(p, " %*1[Aa]verage%*1[Bb]andwidth=%"SCNd64, &st->codecpar->bit_rate) == 1) break; if (!(p = strchr(p, ',')) || p > end) p = end; @@ -464,7 +464,7 @@ add_dstream(AVFormatContext *s, AVStream *orig_st) if (!(st = avformat_new_stream(s, NULL))) return NULL; st->id = orig_st->id; - st->codec->codec_type = orig_st->codec->codec_type; + st->codecpar->codec_type = orig_st->codecpar->codec_type; st->first_dts = orig_st->first_dts; return st; diff --git a/libavformat/realtextdec.c b/libavformat/realtextdec.c index f13321c91a..618d4f78ec 100644 --- a/libavformat/realtextdec.c +++ b/libavformat/realtextdec.c @@ -70,8 +70,8 @@ static int realtext_read_header(AVFormatContext *s) if (!st) return AVERROR(ENOMEM); avpriv_set_pts_info(st, 64, 1, 100); - st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; - st->codec->codec_id = AV_CODEC_ID_REALTEXT; + st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codecpar->codec_id = AV_CODEC_ID_REALTEXT; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED); @@ -89,12 +89,12 @@ static int realtext_read_header(AVFormatContext *s) if (p) duration = read_ts(p); - st->codec->extradata = av_strdup(buf.str); - if (!st->codec->extradata) { + st->codecpar->extradata = av_strdup(buf.str); + if (!st->codecpar->extradata) { res = AVERROR(ENOMEM); goto end; } - st->codec->extradata_size = buf.len + 1; + st->codecpar->extradata_size = buf.len + 1; } else { /* if we just read a