Skip to content

Commit

Permalink
Merge commit '9200514ad8717c63f82101dc394f4378854325bf'
Browse files Browse the repository at this point in the history
* commit '9200514ad8717c63f82101dc394f4378854325bf':
  lavf: replace AVStream.codec with AVStream.codecpar

This has been a HUGE effort from:
    - Derek Buitenhuis <[email protected]>
    - Hendrik Leppkes <[email protected]>
    - wm4 <[email protected]>
    - Clément Bœsch <[email protected]>
    - James Almer <[email protected]>
    - Michael Niedermayer <[email protected]>
    - Rostislav Pehlivanov <[email protected]>

Merged-by: Derek Buitenhuis <[email protected]>
  • Loading branch information
dwbuiten committed Apr 10, 2016
2 parents 60b7518 + 9200514 commit 6f69f7a
Show file tree
Hide file tree
Showing 362 changed files with 6,555 additions and 6,079 deletions.
9 changes: 9 additions & 0 deletions ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
4 changes: 4 additions & 0 deletions ffserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libavdevice/alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions libavdevice/alsa_dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions libavdevice/alsa_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down
14 changes: 6 additions & 8 deletions libavdevice/bktr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
49 changes: 25 additions & 24 deletions libavdevice/dshow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
Expand All @@ -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);
}
}
}
Expand All @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions libavdevice/fbdev_dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,21 @@ 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,
"w:%d h:%d bpp:%d pixfmt:%s fps:%d/%d bit_rate:%"PRId64"\n",
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:
Expand Down
12 changes: 6 additions & 6 deletions libavdevice/fbdev_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;

Expand Down
9 changes: 5 additions & 4 deletions libavdevice/gdigrab.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions libavdevice/jack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 16 additions & 16 deletions libavdevice/lavfi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
Expand Down
12 changes: 6 additions & 6 deletions libavdevice/libcdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Loading

0 comments on commit 6f69f7a

Please sign in to comment.