MT#65420 fill and use new width/height fields

Change-Id: I5cee971b2bab99440d8375a9826eb73b7e22077e
pull/2169/head
Richard Fuchs 3 weeks ago
parent 3306e84fbf
commit a2c3a6bbb8

@ -4500,9 +4500,13 @@ static struct ssrc_entry *__ssrc_handler_transcode_new(void *p) {
ch->bytes_per_packet = (ch->encoder->samples_per_packet ?: ch->encoder->samples_per_frame)
* h->dest_pt.codec_def->bits_per_sample / 8;
ilogs(codec, LOG_DEBUG, "Encoder created with clockrate %i, %i channels, using sample format %i "
ilogs(codec, LOG_DEBUG, "Encoder created with clockrate %i, %i channels using sample format %i, "
"or size %dx%d, using pixel format %d "
"(ptime %i for %i samples per frame and %i samples (%zu bytes) per packet, bitrate %i)",
ch->encoder_format.clockrate, ch->encoder_format.channels, ch->encoder_format.format,
ch->encoder_format.clockrate, ch->encoder_format.channels,
ch->encoder_format.format,
ch->encoder_format.width, ch->encoder_format.height,
ch->encoder_format.pix_fmt,
ch->ptime, ch->encoder->samples_per_frame, ch->encoder->samples_per_packet,
ch->bytes_per_packet, ch->bitrate);

@ -1068,6 +1068,8 @@ static int __ensure_codec_handler(struct media_player *mp, const rtp_payload_typ
src_pt.encoding = src_pt.codec_def->rtpname_str;
src_pt.channels = GET_CHANNELS(mp->coder.avstream->codecpar);
src_pt.clock_rate = mp->coder.avstream->codecpar->sample_rate;
src_pt.width = mp->coder.avstream->codecpar->width;
src_pt.height = mp->coder.avstream->codecpar->height;
codec_init_payload_type(&src_pt, mp->media->type_id);

@ -3,6 +3,7 @@
#include <libavformat/avformat.h>
#include <libavfilter/avfilter.h>
#include <libavutil/opt.h>
#include <libavutil/pixdesc.h>
#include "loglib.h"
#include "fix_frame_channel_layout.compat"
@ -42,6 +43,11 @@ const char *avc_decoder_init(decoder_t *dec, const str *extra_opts) {
SET_CHANNELS(dec->avc.avcctx, dec->in_format.channels);
DEF_CH_LAYOUT(&dec->avc.avcctx->CH_LAYOUT, dec->in_format.channels);
dec->avc.avcctx->sample_rate = dec->in_format.clockrate;
dec->avc.avcctx->time_base = (AVRational){1, dec->in_format.time_base ?: dec->in_format.clockrate};
dec->avc.avcctx->width = dec->in_format.width;
dec->avc.avcctx->height = dec->in_format.height;
//dec->avc.avcctx->pix_fmt = dec->in_format.pix_fmt;
int i = avcodec_open2(dec->avc.avcctx, codec, NULL);
if (i) {
@ -51,14 +57,20 @@ const char *avc_decoder_init(decoder_t *dec, const str *extra_opts) {
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 19, 0)
avcodec_get_supported_config(dec->avc.avcctx, codec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, (const void **) &dec->avc.sample_fmts, NULL);
avcodec_get_supported_config(dec->avc.avcctx, codec, AV_CODEC_CONFIG_PIX_FORMAT, 0, (const void **) &dec->avc.pixel_fmts, NULL);
#else
dec->avc.sample_fmts = codec->sample_fmts;
dec->avc.pixel_fmts = dec->avc.codec->pix_fmts;
#endif
for (const enum AVSampleFormat *sfmt = dec->avc.sample_fmts; sfmt && *sfmt != -1; sfmt++)
ilogs(internals, LOG_DEBUG, "supported sample format for input codec %s: %s",
codec->name, av_get_sample_fmt_name(*sfmt));
for (const enum AVPixelFormat *pfmt = dec->avc.pixel_fmts; pfmt && *pfmt != -1; pfmt++)
ilogs(internals, LOG_DEBUG, "supported pixel format for input codec %s: %s",
codec->name, av_get_pix_fmt_name(*pfmt));
return NULL;
}
@ -125,8 +137,10 @@ int avc_decoder_input(decoder_t *dec, const str *data, frame_q *out, bool mark)
}
if (got_frame) {
ilogs(internals, LOG_DEBUG, "raw frame from decoder pts %llu samples %u",
(unsigned long long) frame->pts, frame->nb_samples);
ilogs(internals, LOG_DEBUG, "raw frame from decoder pts %llu samples %u WxH %dx%d fmt %d",
(unsigned long long) frame->pts, frame->nb_samples,
frame->width, frame->height,
frame->format);
if (G_UNLIKELY(frame->pts == AV_NOPTS_VALUE))
frame->pts = dec->avc.avpkt->pts;
@ -187,21 +201,37 @@ const char *avc_encoder_init(encoder_t *enc, const str *extra_opts) {
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 19, 0)
avcodec_get_supported_config(enc->avc.avcctx, enc->avc.codec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, (const void **) &enc->avc.sample_fmts, NULL);
avcodec_get_supported_config(enc->avc.avcctx, enc->avc.codec, AV_CODEC_CONFIG_PIX_FORMAT, 0, (const void **) &enc->avc.pixel_fmts, NULL);
#else
enc->avc.sample_fmts = enc->avc.codec->sample_fmts;
enc->avc.pixel_fmts = enc->avc.codec->pix_fmts;
#endif
enc->actual_format.format = -1;
enc->actual_format.pix_fmt = -1;
for (const enum AVSampleFormat *sfmt = enc->avc.sample_fmts; sfmt && *sfmt != -1; sfmt++) {
ilogs(internals, LOG_DEBUG, "supported sample format for output codec %s: %s",
enc->avc.codec->name, av_get_sample_fmt_name(*sfmt));
if (*sfmt == enc->requested_format.format)
enc->actual_format.format = *sfmt;
}
for (const enum AVPixelFormat *pfmt = enc->avc.pixel_fmts; pfmt && *pfmt != -1; pfmt++) {
ilogs(internals, LOG_DEBUG, "supported pixel format for output codec %s: %s",
enc->avc.codec->name, av_get_pix_fmt_name(*pfmt));
if (*pfmt == enc->requested_format.pix_fmt)
enc->actual_format.pix_fmt = *pfmt;
}
if (enc->actual_format.format == -1 && enc->avc.sample_fmts)
enc->actual_format.format = enc->avc.sample_fmts[0];
ilogs(internals, LOG_DEBUG, "using output sample format %s for codec %s",
av_get_sample_fmt_name(enc->actual_format.format), enc->avc.codec->name);
if (enc->actual_format.pix_fmt == -1 && enc->avc.pixel_fmts)
enc->actual_format.pix_fmt = enc->avc.pixel_fmts[0];
ilogs(internals, LOG_DEBUG, "using output formats %s/%s for codec %s",
av_get_sample_fmt_name(enc->actual_format.format),
av_get_pix_fmt_name(enc->actual_format.pix_fmt),
enc->avc.codec->name);
if (enc->def->set_enc_options)
enc->def->set_enc_options(enc, extra_opts);
@ -210,7 +240,12 @@ const char *avc_encoder_init(encoder_t *enc, const str *extra_opts) {
DEF_CH_LAYOUT(&enc->avc.avcctx->CH_LAYOUT, enc->actual_format.channels);
enc->avc.avcctx->sample_rate = enc->actual_format.clockrate;
enc->avc.avcctx->sample_fmt = enc->actual_format.format;
enc->avc.avcctx->time_base = (AVRational){1,enc->actual_format.clockrate};
enc->avc.avcctx->height = enc->actual_format.height;
enc->avc.avcctx->width = enc->actual_format.width;
enc->avc.avcctx->pix_fmt = enc->actual_format.pix_fmt;
enc->avc.avcctx->time_base = (AVRational){1, enc->actual_format.time_base ?: enc->actual_format.clockrate};
enc->avc.avcctx->bit_rate = enc->bitrate;
int i = avcodec_open2(enc->avc.avcctx, enc->avc.codec, NULL);

@ -134,6 +134,7 @@ decoder_t *decoder_new_fmtp(codec_def_t *def, const format_t *src_fmt, int ptime
ret->in_format = *src_fmt;
ret->in_format.format = -1;
ret->in_format.pix_fmt = -1;
// output defaults to same as input
ret->dest_format = ret->in_format;
@ -148,6 +149,8 @@ decoder_t *decoder_new_fmtp(codec_def_t *def, const format_t *src_fmt, int ptime
def->select_decoder_format(ret, fmtp);
ret->in_format.clockrate = fraction_mult(ret->in_format.clockrate, &ret->clockrate_fact);
ret->in_format.time_base = fraction_mult(ret->in_format.time_base, &ret->clockrate_fact);
ret->dec_out_format = ret->in_format;
if (ptime > 0)
@ -410,6 +413,8 @@ void codeclib_init(int print) {
def->default_clockrate = -1;
if (!def->default_channels)
def->default_channels = -1;
if (!def->default_fps && def->media_type == MT_VIDEO)
def->default_fps = 30;
// init RFC-related info
const struct rtp_payload_type *pt = rtp_get_rfc_codec(&def->rtpname_str);
@ -661,6 +666,7 @@ int encoder_config_fmtp(encoder_t *enc, codec_def_t *def, int bitrate, int ptime
def->select_encoder_format(enc, &requested_format, input_format, fmtp);
requested_format.clockrate = fraction_mult(requested_format.clockrate, &enc->clockrate_fact);
requested_format.time_base = fraction_mult(requested_format.time_base, &enc->clockrate_fact);
// anything to do?
if (G_LIKELY(format_eq(&requested_format, &enc->requested_format))) {

@ -311,6 +311,7 @@ struct decoder_s {
AVCodecContext *avcctx;
AVPacket *avpkt;
const enum AVSampleFormat *sample_fmts;
const enum AVPixelFormat *pixel_fmts;
union {
struct {
@ -359,6 +360,7 @@ struct encoder_s {
const AVCodec *codec;
AVCodecContext *avcctx;
const enum AVSampleFormat *sample_fmts;
const enum AVPixelFormat *pixel_fmts;
union {
struct {

Loading…
Cancel
Save