demux: merge sh_video/sh_audio/sh_sub

This is mainly a refactor. I'm hoping it will make some things easier
in the future due to cleanly separating codec metadata and stream
metadata.

Also, declare that the "codec" field can not be NULL anymore. demux.c
will set it to "" if it's NULL when added. This gets rid of a corner
case everything had to handle, but which rarely happened.
This commit is contained in:
wm4
2016-01-12 23:48:19 +01:00
parent 81f3b3aafe
commit 671df54e4d
24 changed files with 232 additions and 247 deletions

View File

@@ -79,12 +79,12 @@ static int init(struct dec_audio *da, const char *decoder)
AVCodecContext *lavc_context; AVCodecContext *lavc_context;
AVCodec *lavc_codec; AVCodec *lavc_codec;
struct sh_stream *sh = da->header; struct sh_stream *sh = da->header;
struct sh_audio *sh_audio = sh->audio; struct mp_codec_params *c = sh->codec;
struct priv *ctx = talloc_zero(NULL, struct priv); struct priv *ctx = talloc_zero(NULL, struct priv);
da->priv = ctx; da->priv = ctx;
ctx->force_channel_map = sh_audio->force_channels; ctx->force_channel_map = c->force_channels;
lavc_codec = avcodec_find_decoder_by_name(decoder); lavc_codec = avcodec_find_decoder_by_name(decoder);
if (!lavc_codec) { if (!lavc_codec) {
@@ -116,20 +116,20 @@ static int init(struct dec_audio *da, const char *decoder)
mp_set_avopts(da->log, lavc_context, opts->avopts); mp_set_avopts(da->log, lavc_context, opts->avopts);
lavc_context->codec_tag = sh->codec_tag; lavc_context->codec_tag = c->codec_tag;
lavc_context->sample_rate = sh_audio->samplerate; lavc_context->sample_rate = c->samplerate;
lavc_context->bit_rate = sh_audio->bitrate; lavc_context->bit_rate = c->bitrate;
lavc_context->block_align = sh_audio->block_align; lavc_context->block_align = c->block_align;
lavc_context->bits_per_coded_sample = sh_audio->bits_per_coded_sample; lavc_context->bits_per_coded_sample = c->bits_per_coded_sample;
lavc_context->channels = sh_audio->channels.num; lavc_context->channels = c->channels.num;
if (!mp_chmap_is_unknown(&sh_audio->channels)) if (!mp_chmap_is_unknown(&c->channels))
lavc_context->channel_layout = mp_chmap_to_lavc(&sh_audio->channels); lavc_context->channel_layout = mp_chmap_to_lavc(&c->channels);
// demux_mkv // demux_mkv
mp_lavc_set_extradata(lavc_context, sh->extradata, sh->extradata_size); mp_lavc_set_extradata(lavc_context, c->extradata, c->extradata_size);
if (sh->lav_headers) if (c->lav_headers)
mp_copy_lav_codec_headers(lavc_context, sh->lav_headers); mp_copy_lav_codec_headers(lavc_context, c->lav_headers);
mp_set_avcodec_threads(da->log, lavc_context, opts->threads); mp_set_avcodec_threads(da->log, lavc_context, opts->threads);
@@ -228,9 +228,8 @@ static int decode_packet(struct dec_audio *da, struct mp_audio **out)
if (lavc_chmap.num != avctx->channels) if (lavc_chmap.num != avctx->channels)
mp_chmap_from_channels(&lavc_chmap, avctx->channels); mp_chmap_from_channels(&lavc_chmap, avctx->channels);
if (priv->force_channel_map) { if (priv->force_channel_map) {
struct sh_audio *sh_audio = da->header->audio; if (lavc_chmap.num == da->header->codec->channels.num)
if (lavc_chmap.num == sh_audio->channels.num) lavc_chmap = da->header->codec->channels;
lavc_chmap = sh_audio->channels;
} }
mp_audio_set_channels(mpframe, &lavc_chmap); mp_audio_set_channels(mpframe, &lavc_chmap);

View File

@@ -88,7 +88,7 @@ struct mp_decoder_list *audio_decoder_list(void)
static struct mp_decoder_list *audio_select_decoders(struct dec_audio *d_audio) static struct mp_decoder_list *audio_select_decoders(struct dec_audio *d_audio)
{ {
struct MPOpts *opts = d_audio->opts; struct MPOpts *opts = d_audio->opts;
const char *codec = d_audio->header->codec; const char *codec = d_audio->header->codec->codec;
struct mp_decoder_list *list = audio_decoder_list(); struct mp_decoder_list *list = audio_decoder_list();
struct mp_decoder_list *new = struct mp_decoder_list *new =
@@ -146,7 +146,7 @@ int audio_init_best_codec(struct dec_audio *d_audio)
MP_VERBOSE(d_audio, "Selected audio codec: %s\n", d_audio->decoder_desc); MP_VERBOSE(d_audio, "Selected audio codec: %s\n", d_audio->decoder_desc);
} else { } else {
MP_ERR(d_audio, "Failed to initialize an audio decoder for codec '%s'.\n", MP_ERR(d_audio, "Failed to initialize an audio decoder for codec '%s'.\n",
d_audio->header->codec ? d_audio->header->codec : "<unknown>"); d_audio->header->codec->codec);
} }
talloc_free(list); talloc_free(list);

View File

@@ -70,20 +70,20 @@ static const char *map_audio_pcm_tag(uint32_t tag, int bits)
} }
} }
void mp_set_codec_from_tag(struct sh_stream *sh) void mp_set_codec_from_tag(struct mp_codec_params *c)
{ {
sh->codec = lookup_tag(sh->type, sh->codec_tag); c->codec = lookup_tag(c->type, c->codec_tag);
if (sh->audio && sh->audio->bits_per_coded_sample) { if (c->type == STREAM_AUDIO && c->bits_per_coded_sample) {
const char *codec = const char *codec =
map_audio_pcm_tag(sh->codec_tag, sh->audio->bits_per_coded_sample); map_audio_pcm_tag(c->codec_tag, c->bits_per_coded_sample);
if (codec) if (codec)
sh->codec = codec; c->codec = codec;
} }
} }
void mp_set_pcm_codec(struct sh_stream *sh, bool sign, bool is_float, int bits, void mp_set_pcm_codec(struct mp_codec_params *c, bool sign, bool is_float,
bool is_be) int bits, bool is_be)
{ {
// This uses libavcodec pcm codec names, e.g. "pcm_u16le". // This uses libavcodec pcm codec names, e.g. "pcm_u16le".
char codec[64] = "pcm_"; char codec[64] = "pcm_";
@@ -95,7 +95,7 @@ void mp_set_pcm_codec(struct sh_stream *sh, bool sign, bool is_float, int bits,
mp_snprintf_cat(codec, sizeof(codec), "%d", bits); mp_snprintf_cat(codec, sizeof(codec), "%d", bits);
if (bits != 8) if (bits != 8)
mp_snprintf_cat(codec, sizeof(codec), is_be ? "be" : "le"); mp_snprintf_cat(codec, sizeof(codec), is_be ? "be" : "le");
sh->codec = talloc_strdup(sh->audio, codec); c->codec = talloc_strdup(c, codec);
} }
static const char *const mimetype_to_codec[][2] = { static const char *const mimetype_to_codec[][2] = {

View File

@@ -21,12 +21,12 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
struct sh_stream; struct mp_codec_params;
void mp_set_codec_from_tag(struct sh_stream *sh); void mp_set_codec_from_tag(struct mp_codec_params *c);
void mp_set_pcm_codec(struct sh_stream *sh, bool sign, bool is_float, int bits, void mp_set_pcm_codec(struct mp_codec_params *c, bool sign, bool is_float,
bool is_be); int bits, bool is_be);
const char *mp_map_mimetype_to_video_codec(const char *mimetype); const char *mp_map_mimetype_to_video_codec(const char *mimetype);

View File

@@ -214,13 +214,9 @@ struct sh_stream *demux_alloc_sh_stream(enum stream_type type)
.index = -1, .index = -1,
.ff_index = -1, // may be overwritten by demuxer .ff_index = -1, // may be overwritten by demuxer
.demuxer_id = -1, // ... same .demuxer_id = -1, // ... same
.codec = talloc_zero(sh, struct mp_codec_params),
}; };
switch (sh->type) { sh->codec->type = type;
case STREAM_VIDEO: sh->video = talloc_zero(sh, struct sh_video); break;
case STREAM_AUDIO: sh->audio = talloc_zero(sh, struct sh_audio); break;
case STREAM_SUB: sh->sub = talloc_zero(sh, struct sh_sub); break;
}
return sh; return sh;
} }
@@ -241,6 +237,9 @@ void demux_add_sh_stream(struct demuxer *demuxer, struct sh_stream *sh)
.selected = in->autoselect, .selected = in->autoselect,
}; };
if (!sh->codec->codec)
sh->codec->codec = "";
sh->index = in->num_streams; sh->index = in->num_streams;
if (sh->ff_index < 0) if (sh->ff_index < 0)
sh->ff_index = sh->index; sh->ff_index = sh->index;
@@ -855,11 +854,11 @@ static void apply_replaygain(demuxer_t *demuxer, struct replaygain_data *rg)
struct demux_internal *in = demuxer->in; struct demux_internal *in = demuxer->in;
for (int n = 0; n < in->num_streams; n++) { for (int n = 0; n < in->num_streams; n++) {
struct sh_stream *sh = in->streams[n]; struct sh_stream *sh = in->streams[n];
if (sh->audio && !sh->audio->replaygain_data) { if (sh->type == STREAM_AUDIO && !sh->codec->replaygain_data) {
MP_VERBOSE(demuxer, "Replaygain: Track=%f/%f Album=%f/%f\n", MP_VERBOSE(demuxer, "Replaygain: Track=%f/%f Album=%f/%f\n",
rg->track_gain, rg->track_peak, rg->track_gain, rg->track_peak,
rg->album_gain, rg->album_peak); rg->album_gain, rg->album_peak);
sh->audio->replaygain_data = talloc_memdup(in, rg, sizeof(*rg)); sh->codec->replaygain_data = talloc_memdup(in, rg, sizeof(*rg));
} }
} }
} }

View File

@@ -84,7 +84,7 @@ static void add_dvd_streams(demuxer_t *demuxer)
for (int n = 0; n < MPMIN(32, info.num_subs); n++) { for (int n = 0; n < MPMIN(32, info.num_subs); n++) {
struct sh_stream *sh = demux_alloc_sh_stream(STREAM_SUB); struct sh_stream *sh = demux_alloc_sh_stream(STREAM_SUB);
sh->demuxer_id = n + 0x20; sh->demuxer_id = n + 0x20;
sh->codec = "dvd_subtitle"; sh->codec->codec = "dvd_subtitle";
get_disc_lang(stream, sh); get_disc_lang(stream, sh);
// p->streams _must_ match with p->slave->streams, so we can't add // p->streams _must_ match with p->slave->streams, so we can't add
// it yet - it has to be done when the real stream appears, which // it yet - it has to be done when the real stream appears, which
@@ -111,8 +111,8 @@ static void add_dvd_streams(demuxer_t *demuxer)
} }
s = talloc_asprintf_append(s, "\n"); s = talloc_asprintf_append(s, "\n");
sh->extradata = s; sh->codec->extradata = s;
sh->extradata_size = strlen(s); sh->codec->extradata_size = strlen(s);
demux_add_sh_stream(demuxer, sh); demux_add_sh_stream(demuxer, sh);
} }
@@ -125,7 +125,7 @@ static void add_streams(demuxer_t *demuxer)
for (int n = p->num_streams; n < demux_get_num_stream(p->slave); n++) { for (int n = p->num_streams; n < demux_get_num_stream(p->slave); n++) {
struct sh_stream *src = demux_get_stream(p->slave, n); struct sh_stream *src = demux_get_stream(p->slave, n);
if (src->sub) { if (src->type == STREAM_SUB) {
struct sh_stream *sub = NULL; struct sh_stream *sub = NULL;
if (src->demuxer_id >= 0x20 && src->demuxer_id <= 0x3F) if (src->demuxer_id >= 0x20 && src->demuxer_id <= 0x3F)
sub = p->dvd_subs[src->demuxer_id - 0x20]; sub = p->dvd_subs[src->demuxer_id - 0x20];
@@ -139,24 +139,20 @@ static void add_streams(demuxer_t *demuxer)
assert(p->num_streams == n); // directly mapped assert(p->num_streams == n); // directly mapped
MP_TARRAY_APPEND(p, p->streams, p->num_streams, sh); MP_TARRAY_APPEND(p, p->streams, p->num_streams, sh);
// Copy all stream fields that might be relevant // Copy all stream fields that might be relevant
sh->codec = talloc_strdup(sh, src->codec); *sh->codec = *src->codec;
sh->codec_tag = src->codec_tag;
sh->lav_headers = src->lav_headers;
sh->demuxer_id = src->demuxer_id; sh->demuxer_id = src->demuxer_id;
if (src->video) { if (src->type == STREAM_VIDEO) {
double ar; double ar;
if (stream_control(demuxer->stream, STREAM_CTRL_GET_ASPECT_RATIO, &ar) if (stream_control(demuxer->stream, STREAM_CTRL_GET_ASPECT_RATIO, &ar)
== STREAM_OK) == STREAM_OK)
{ {
struct mp_image_params f = {.w = src->video->disp_w, struct mp_image_params f = {.w = src->codec->disp_w,
.h = src->video->disp_h}; .h = src->codec->disp_h};
mp_image_params_set_dsize(&f, 1728 * ar, 1728); mp_image_params_set_dsize(&f, 1728 * ar, 1728);
sh->video->par_w = f.p_w; sh->codec->par_w = f.p_w;
sh->video->par_h = f.p_h; sh->codec->par_h = f.p_h;
} }
} }
if (src->audio)
sh->audio = src->audio;
get_disc_lang(demuxer->stream, sh); get_disc_lang(demuxer->stream, sh);
demux_add_sh_stream(demuxer, sh); demux_add_sh_stream(demuxer, sh);
} }

View File

@@ -499,7 +499,8 @@ static void select_tracks(struct demuxer *demuxer, int start)
} }
} }
static void export_replaygain(demuxer_t *demuxer, sh_audio_t *sh, AVStream *st) static void export_replaygain(demuxer_t *demuxer, struct mp_codec_params *c,
AVStream *st)
{ {
for (int i = 0; i < st->nb_side_data; i++) { for (int i = 0; i < st->nb_side_data; i++) {
AVReplayGain *av_rgain; AVReplayGain *av_rgain;
@@ -524,7 +525,7 @@ static void export_replaygain(demuxer_t *demuxer, sh_audio_t *sh, AVStream *st)
rgain->album_peak = (av_rgain->album_peak != 0.0) ? rgain->album_peak = (av_rgain->album_peak != 0.0) ?
av_rgain->album_peak / 100000.0f : 1.0; av_rgain->album_peak / 100000.0f : 1.0;
sh->replaygain_data = rgain; c->replaygain_data = rgain;
} }
} }
@@ -552,22 +553,20 @@ static void handle_new_stream(demuxer_t *demuxer, int i)
switch (codec->codec_type) { switch (codec->codec_type) {
case AVMEDIA_TYPE_AUDIO: { case AVMEDIA_TYPE_AUDIO: {
sh = demux_alloc_sh_stream(STREAM_AUDIO); sh = demux_alloc_sh_stream(STREAM_AUDIO);
sh_audio_t *sh_audio = sh->audio;
// probably unneeded // probably unneeded
mp_chmap_set_unknown(&sh_audio->channels, codec->channels); mp_chmap_set_unknown(&sh->codec->channels, codec->channels);
if (codec->channel_layout) if (codec->channel_layout)
mp_chmap_from_lavc(&sh_audio->channels, codec->channel_layout); mp_chmap_from_lavc(&sh->codec->channels, codec->channel_layout);
sh_audio->samplerate = codec->sample_rate; sh->codec->samplerate = codec->sample_rate;
sh_audio->bitrate = codec->bit_rate; sh->codec->bitrate = codec->bit_rate;
export_replaygain(demuxer, sh_audio, st); export_replaygain(demuxer, sh->codec, st);
break; break;
} }
case AVMEDIA_TYPE_VIDEO: { case AVMEDIA_TYPE_VIDEO: {
sh = demux_alloc_sh_stream(STREAM_VIDEO); sh = demux_alloc_sh_stream(STREAM_VIDEO);
sh_video_t *sh_video = sh->video;
if (st->disposition & AV_DISPOSITION_ATTACHED_PIC) { if (st->disposition & AV_DISPOSITION_ATTACHED_PIC) {
sh->attached_picture = new_demux_packet_from(st->attached_pic.data, sh->attached_picture = new_demux_packet_from(st->attached_pic.data,
@@ -579,8 +578,8 @@ static void handle_new_stream(demuxer_t *demuxer, int i)
} }
} }
sh_video->disp_w = codec->width; sh->codec->disp_w = codec->width;
sh_video->disp_h = codec->height; sh->codec->disp_h = codec->height;
/* Try to make up some frame rate value, even if it's not reliable. /* Try to make up some frame rate value, even if it's not reliable.
* FPS information is needed to support subtitle formats which base * FPS information is needed to support subtitle formats which base
* timing on frame numbers. * timing on frame numbers.
@@ -595,33 +594,31 @@ static void handle_new_stream(demuxer_t *demuxer, int i)
fps = 1.0 / FFMAX(av_q2d(st->time_base), fps = 1.0 / FFMAX(av_q2d(st->time_base),
av_q2d(st->codec->time_base) * av_q2d(st->codec->time_base) *
st->codec->ticks_per_frame); st->codec->ticks_per_frame);
sh_video->fps = fps; sh->codec->fps = fps;
if (priv->format_hack.image_format) if (priv->format_hack.image_format)
sh_video->fps = demuxer->opts->mf_fps; sh->codec->fps = demuxer->opts->mf_fps;
sh_video->par_w = st->sample_aspect_ratio.num; sh->codec->par_w = st->sample_aspect_ratio.num;
sh_video->par_h = st->sample_aspect_ratio.den; sh->codec->par_h = st->sample_aspect_ratio.den;
uint8_t *sd = av_stream_get_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, NULL); uint8_t *sd = av_stream_get_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, NULL);
if (sd) { if (sd) {
double r = av_display_rotation_get((uint32_t *)sd); double r = av_display_rotation_get((uint32_t *)sd);
if (!isnan(r)) if (!isnan(r))
sh_video->rotate = (((int)(-r) % 360) + 360) % 360; sh->codec->rotate = (((int)(-r) % 360) + 360) % 360;
} }
// This also applies to vfw-muxed mkv, but we can't detect these easily. // This also applies to vfw-muxed mkv, but we can't detect these easily.
sh_video->avi_dts = matches_avinputformat_name(priv, "avi"); sh->codec->avi_dts = matches_avinputformat_name(priv, "avi");
break; break;
} }
case AVMEDIA_TYPE_SUBTITLE: { case AVMEDIA_TYPE_SUBTITLE: {
sh_sub_t *sh_sub;
sh = demux_alloc_sh_stream(STREAM_SUB); sh = demux_alloc_sh_stream(STREAM_SUB);
sh_sub = sh->sub;
if (codec->extradata_size) { if (codec->extradata_size) {
sh->extradata = talloc_size(sh, codec->extradata_size); sh->codec->extradata = talloc_size(sh, codec->extradata_size);
memcpy(sh->extradata, codec->extradata, codec->extradata_size); memcpy(sh->codec->extradata, codec->extradata, codec->extradata_size);
sh->extradata_size = codec->extradata_size; sh->codec->extradata_size = codec->extradata_size;
} }
if (matches_avinputformat_name(priv, "microdvd")) { if (matches_avinputformat_name(priv, "microdvd")) {
@@ -629,12 +626,12 @@ static void handle_new_stream(demuxer_t *demuxer, int i)
if (av_opt_get_q(avfc, "subfps", AV_OPT_SEARCH_CHILDREN, &r) >= 0) { if (av_opt_get_q(avfc, "subfps", AV_OPT_SEARCH_CHILDREN, &r) >= 0) {
// File headers don't have a FPS set. // File headers don't have a FPS set.
if (r.num < 1 || r.den < 1) if (r.num < 1 || r.den < 1)
sh_sub->frame_based = av_q2d(av_inv_q(codec->time_base)); sh->codec->frame_based = av_q2d(av_inv_q(codec->time_base));
} else { } else {
// Older libavformat versions. If the FPS matches the microdvd // Older libavformat versions. If the FPS matches the microdvd
// reader's default, assume it uses frame based timing. // reader's default, assume it uses frame based timing.
if (codec->time_base.num == 125 && codec->time_base.den == 2997) if (codec->time_base.num == 125 && codec->time_base.den == 2997)
sh_sub->frame_based = 23.976; sh->codec->frame_based = 23.976;
} }
} }
break; break;
@@ -658,11 +655,11 @@ static void handle_new_stream(demuxer_t *demuxer, int i)
if (sh) { if (sh) {
sh->ff_index = st->index; sh->ff_index = st->index;
sh->codec = mp_codec_from_av_codec_id(codec->codec_id); sh->codec->codec = mp_codec_from_av_codec_id(codec->codec_id);
sh->codec_tag = codec->codec_tag; sh->codec->codec_tag = codec->codec_tag;
sh->lav_headers = avcodec_alloc_context3(NULL); sh->codec->lav_headers = avcodec_alloc_context3(NULL);
if (sh->lav_headers) if (sh->codec->lav_headers)
mp_copy_lav_codec_headers(sh->lav_headers, codec); mp_copy_lav_codec_headers(sh->codec->lav_headers, codec);
if (st->disposition & AV_DISPOSITION_DEFAULT) if (st->disposition & AV_DISPOSITION_DEFAULT)
sh->default_track = true; sh->default_track = true;
@@ -1104,7 +1101,7 @@ static void demux_close_lavf(demuxer_t *demuxer)
av_freep(&priv->pb); av_freep(&priv->pb);
for (int n = 0; n < priv->num_streams; n++) { for (int n = 0; n < priv->num_streams; n++) {
if (priv->streams[n]) if (priv->streams[n])
avcodec_free_context(&priv->streams[n]->lav_headers); avcodec_free_context(&priv->streams[n]->codec->lav_headers);
} }
if (priv->stream != demuxer->stream) if (priv->stream != demuxer->stream)
free_stream(priv->stream); free_stream(priv->stream);

View File

@@ -165,7 +165,7 @@ static void demux_seek_mf(demuxer_t *demuxer, double rel_seek_secs, int flags)
if (flags & SEEK_FACTOR) if (flags & SEEK_FACTOR)
newpos += rel_seek_secs * (mf->nr_of_files - 1); newpos += rel_seek_secs * (mf->nr_of_files - 1);
else else
newpos += rel_seek_secs * mf->sh->video->fps; newpos += rel_seek_secs * mf->sh->codec->fps;
if (newpos < 0) if (newpos < 0)
newpos = 0; newpos = 0;
if (newpos >= mf->nr_of_files) if (newpos >= mf->nr_of_files)
@@ -199,7 +199,7 @@ static int demux_mf_fill_buffer(demuxer_t *demuxer)
demux_packet_t *dp = new_demux_packet(data.len); demux_packet_t *dp = new_demux_packet(data.len);
if (dp) { if (dp) {
memcpy(dp->buffer, data.start, data.len); memcpy(dp->buffer, data.start, data.len);
dp->pts = mf->curr_frame / mf->sh->video->fps; dp->pts = mf->curr_frame / mf->sh->codec->fps;
dp->keyframe = true; dp->keyframe = true;
demux_add_packet(mf->sh, dp); demux_add_packet(mf->sh, dp);
} }
@@ -291,7 +291,6 @@ static const char *probe_format(mf_t *mf, char *type, enum demux_check check)
static int demux_open_mf(demuxer_t *demuxer, enum demux_check check) static int demux_open_mf(demuxer_t *demuxer, enum demux_check check)
{ {
sh_video_t *sh_video = NULL;
mf_t *mf; mf_t *mf;
if (strncmp(demuxer->stream->url, "mf://", 5) == 0 && if (strncmp(demuxer->stream->url, "mf://", 5) == 0 &&
@@ -317,12 +316,12 @@ static int demux_open_mf(demuxer_t *demuxer, enum demux_check check)
// create a new video stream header // create a new video stream header
struct sh_stream *sh = demux_alloc_sh_stream(STREAM_VIDEO); struct sh_stream *sh = demux_alloc_sh_stream(STREAM_VIDEO);
sh_video = sh->video; struct mp_codec_params *c = sh->codec;
sh->codec = codec; c->codec = codec;
sh_video->disp_w = 0; c->disp_w = 0;
sh_video->disp_h = 0; c->disp_h = 0;
sh_video->fps = demuxer->opts->mf_fps; c->fps = demuxer->opts->mf_fps;
demux_add_sh_stream(demuxer, sh); demux_add_sh_stream(demuxer, sh);
@@ -346,7 +345,7 @@ static int demux_control_mf(demuxer_t *demuxer, int cmd, void *arg)
switch (cmd) { switch (cmd) {
case DEMUXER_CTRL_GET_TIME_LENGTH: case DEMUXER_CTRL_GET_TIME_LENGTH:
*((double *)arg) = (double)mf->nr_of_files / mf->sh->video->fps; *((double *)arg) = (double)mf->nr_of_files / mf->sh->codec->fps;
return DEMUXER_CTRL_OK; return DEMUXER_CTRL_OK;
default: default:

View File

@@ -1201,7 +1201,7 @@ static void add_coverart(struct demuxer *demuxer)
continue; continue;
struct sh_stream *sh = demux_alloc_sh_stream(STREAM_VIDEO); struct sh_stream *sh = demux_alloc_sh_stream(STREAM_VIDEO);
sh->demuxer_id = -1 - sh->index; // don't clash with mkv IDs sh->demuxer_id = -1 - sh->index; // don't clash with mkv IDs
sh->codec = codec; sh->codec->codec = codec;
sh->attached_picture = new_demux_packet_from(att->data, att->data_size); sh->attached_picture = new_demux_packet_from(att->data, att->data_size);
if (sh->attached_picture) { if (sh->attached_picture) {
sh->attached_picture->pts = 0; sh->attached_picture->pts = 0;
@@ -1273,7 +1273,7 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track)
unsigned int extradata_size = 0; unsigned int extradata_size = 0;
struct sh_stream *sh = demux_alloc_sh_stream(STREAM_VIDEO); struct sh_stream *sh = demux_alloc_sh_stream(STREAM_VIDEO);
init_track(demuxer, track, sh); init_track(demuxer, track, sh);
sh_video_t *sh_v = sh->video; struct mp_codec_params *sh_v = sh->codec;
sh_v->bits_per_coded_sample = 24; sh_v->bits_per_coded_sample = 24;
@@ -1288,11 +1288,11 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track)
if (track->v_height == 0) if (track->v_height == 0)
track->v_height = AV_RL32(h + 8); // biHeight track->v_height = AV_RL32(h + 8); // biHeight
sh_v->bits_per_coded_sample = AV_RL16(h + 14); // biBitCount sh_v->bits_per_coded_sample = AV_RL16(h + 14); // biBitCount
sh->codec_tag = AV_RL32(h + 16); // biCompression sh_v->codec_tag = AV_RL32(h + 16); // biCompression
extradata = track->private_data + 40; extradata = track->private_data + 40;
extradata_size = track->private_size - 40; extradata_size = track->private_size - 40;
mp_set_codec_from_tag(sh); mp_set_codec_from_tag(sh_v);
sh_v->avi_dts = true; sh_v->avi_dts = true;
} else if (track->private_size >= RVPROPERTIES_SIZE } else if (track->private_size >= RVPROPERTIES_SIZE
&& (!strcmp(track->codec_id, "V_REAL/RV10") && (!strcmp(track->codec_id, "V_REAL/RV10")
@@ -1308,10 +1308,10 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track)
cnt = track->private_size - RVPROPERTIES_SIZE; cnt = track->private_size - RVPROPERTIES_SIZE;
uint32_t t2 = AV_RB32(src - 4); uint32_t t2 = AV_RB32(src - 4);
switch (t2 == 0x10003000 || t2 == 0x10003001 ? '1' : track->codec_id[9]) { switch (t2 == 0x10003000 || t2 == 0x10003001 ? '1' : track->codec_id[9]) {
case '1': sh->codec = "rv10"; break; case '1': sh_v->codec = "rv10"; break;
case '2': sh->codec = "rv20"; break; case '2': sh_v->codec = "rv20"; break;
case '3': sh->codec = "rv30"; break; case '3': sh_v->codec = "rv30"; break;
case '4': sh->codec = "rv40"; break; case '4': sh_v->codec = "rv40"; break;
} }
// copy type1 and type2 info from rv properties // copy type1 and type2 info from rv properties
extradata_size = cnt + 8; extradata_size = cnt + 8;
@@ -1320,8 +1320,8 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track)
track->parse_timebase = 1e3; track->parse_timebase = 1e3;
} else if (strcmp(track->codec_id, "V_UNCOMPRESSED") == 0) { } else if (strcmp(track->codec_id, "V_UNCOMPRESSED") == 0) {
// raw video, "like AVI" - this is a FourCC // raw video, "like AVI" - this is a FourCC
sh->codec_tag = track->colorspace; sh_v->codec_tag = track->colorspace;
sh->codec = "rawvideo"; sh_v->codec = "rawvideo";
} else if (strcmp(track->codec_id, "V_QUICKTIME") == 0) { } else if (strcmp(track->codec_id, "V_QUICKTIME") == 0) {
uint32_t fourcc1 = 0, fourcc2 = 0; uint32_t fourcc1 = 0, fourcc2 = 0;
if (track->private_size >= 8) { if (track->private_size >= 8) {
@@ -1331,14 +1331,14 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track)
if (fourcc1 == MP_FOURCC('S', 'V', 'Q', '3') || if (fourcc1 == MP_FOURCC('S', 'V', 'Q', '3') ||
fourcc2 == MP_FOURCC('S', 'V', 'Q', '3')) fourcc2 == MP_FOURCC('S', 'V', 'Q', '3'))
{ {
sh->codec = "svq3"; sh_v->codec = "svq3";
extradata = track->private_data; extradata = track->private_data;
extradata_size = track->private_size; extradata_size = track->private_size;
} }
} else { } else {
for (int i = 0; mkv_video_tags[i][0]; i++) { for (int i = 0; mkv_video_tags[i][0]; i++) {
if (!strcmp(mkv_video_tags[i][0], track->codec_id)) { if (!strcmp(mkv_video_tags[i][0], track->codec_id)) {
sh->codec = mkv_video_tags[i][1]; sh_v->codec = mkv_video_tags[i][1];
break; break;
} }
} }
@@ -1348,12 +1348,12 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track)
} }
} }
const char *codec = sh->codec ? sh->codec : ""; const char *codec = sh_v->codec ? sh_v->codec : "";
if (!strcmp(codec, "vp9")) { if (!strcmp(codec, "vp9")) {
track->parse = true; track->parse = true;
track->parse_timebase = 1e9; track->parse_timebase = 1e9;
} else if (!strcmp(codec, "mjpeg")) { } else if (!strcmp(codec, "mjpeg")) {
sh->codec_tag = MP_FOURCC('m', 'j', 'p', 'g'); sh_v->codec_tag = MP_FOURCC('m', 'j', 'p', 'g');
} }
if (extradata_size > 0x1000000) { if (extradata_size > 0x1000000) {
@@ -1361,9 +1361,9 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track)
goto done; goto done;
} }
sh->extradata = talloc_memdup(sh_v, extradata, extradata_size); sh_v->extradata = talloc_memdup(sh_v, extradata, extradata_size);
sh->extradata_size = extradata_size; sh_v->extradata_size = extradata_size;
if (!sh->codec) { if (!sh_v->codec) {
MP_WARN(demuxer, "Unknown/unsupported CodecID (%s) or missing/bad " MP_WARN(demuxer, "Unknown/unsupported CodecID (%s) or missing/bad "
"CodecPrivate data (track %u).\n", "CodecPrivate data (track %u).\n",
track->codec_id, track->tnum); track->codec_id, track->tnum);
@@ -1477,7 +1477,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
{ {
struct sh_stream *sh = demux_alloc_sh_stream(STREAM_AUDIO); struct sh_stream *sh = demux_alloc_sh_stream(STREAM_AUDIO);
init_track(demuxer, track, sh); init_track(demuxer, track, sh);
sh_audio_t *sh_a = sh->audio; struct mp_codec_params *sh_a = sh->codec;
if (track->private_size > 0x1000000) if (track->private_size > 0x1000000)
goto error; goto error;
@@ -1492,7 +1492,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
for (int i = 0; mkv_audio_tags[i][0]; i++) { for (int i = 0; mkv_audio_tags[i][0]; i++) {
if (!strcmp(mkv_audio_tags[i][0], track->codec_id)) { if (!strcmp(mkv_audio_tags[i][0], track->codec_id)) {
sh->codec = mkv_audio_tags[i][1]; sh_a->codec = mkv_audio_tags[i][1];
break; break;
} }
} }
@@ -1503,7 +1503,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
goto error; goto error;
MP_VERBOSE(demuxer, "track with MS compat audio.\n"); MP_VERBOSE(demuxer, "track with MS compat audio.\n");
unsigned char *h = track->private_data; unsigned char *h = track->private_data;
sh->codec_tag = AV_RL16(h + 0); // wFormatTag sh_a->codec_tag = AV_RL16(h + 0); // wFormatTag
if (track->a_channels == 0) if (track->a_channels == 0)
track->a_channels = AV_RL16(h + 2); // nChannels track->a_channels = AV_RL16(h + 2); // nChannels
if (sh_a->samplerate == 0) if (sh_a->samplerate == 0)
@@ -1515,15 +1515,15 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
extradata = track->private_data + 18; extradata = track->private_data + 18;
extradata_len = track->private_size - 18; extradata_len = track->private_size - 18;
sh_a->bits_per_coded_sample = track->a_bps; sh_a->bits_per_coded_sample = track->a_bps;
mp_set_codec_from_tag(sh); mp_set_codec_from_tag(sh_a);
} else if (!strcmp(track->codec_id, "A_PCM/INT/LIT")) { } else if (!strcmp(track->codec_id, "A_PCM/INT/LIT")) {
bool sign = sh_a->bits_per_coded_sample > 8; bool sign = sh_a->bits_per_coded_sample > 8;
mp_set_pcm_codec(sh, sign, false, sh_a->bits_per_coded_sample, false); mp_set_pcm_codec(sh_a, sign, false, sh_a->bits_per_coded_sample, false);
} else if (!strcmp(track->codec_id, "A_PCM/INT/BIG")) { } else if (!strcmp(track->codec_id, "A_PCM/INT/BIG")) {
bool sign = sh_a->bits_per_coded_sample > 8; bool sign = sh_a->bits_per_coded_sample > 8;
mp_set_pcm_codec(sh, sign, false, sh_a->bits_per_coded_sample, true); mp_set_pcm_codec(sh_a, sign, false, sh_a->bits_per_coded_sample, true);
} else if (!strcmp(track->codec_id, "A_PCM/FLOAT/IEEE")) { } else if (!strcmp(track->codec_id, "A_PCM/FLOAT/IEEE")) {
sh->codec = sh_a->bits_per_coded_sample == 64 ? "pcm_f64le" : "pcm_f32le"; sh_a->codec = sh_a->bits_per_coded_sample == 64 ? "pcm_f64le" : "pcm_f32le";
} else if (!strncmp(track->codec_id, "A_REAL/", 7)) { } else if (!strncmp(track->codec_id, "A_REAL/", 7)) {
if (track->private_size < RAPROPERTIES4_SIZE) if (track->private_size < RAPROPERTIES4_SIZE)
goto error; goto error;
@@ -1563,29 +1563,29 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
extradata = src + offset; extradata = src + offset;
if (!strcmp(track->codec_id, "A_REAL/ATRC")) { if (!strcmp(track->codec_id, "A_REAL/ATRC")) {
sh->codec = "atrac3"; sh_a->codec = "atrac3";
if (flavor >= MP_ARRAY_SIZE(atrc_fl2bps)) if (flavor >= MP_ARRAY_SIZE(atrc_fl2bps))
goto error; goto error;
sh_a->bitrate = atrc_fl2bps[flavor] * 8; sh_a->bitrate = atrc_fl2bps[flavor] * 8;
sh_a->block_align = track->sub_packet_size; sh_a->block_align = track->sub_packet_size;
} else if (!strcmp(track->codec_id, "A_REAL/COOK")) { } else if (!strcmp(track->codec_id, "A_REAL/COOK")) {
sh->codec = "cook"; sh_a->codec = "cook";
if (flavor >= MP_ARRAY_SIZE(cook_fl2bps)) if (flavor >= MP_ARRAY_SIZE(cook_fl2bps))
goto error; goto error;
sh_a->bitrate = cook_fl2bps[flavor] * 8; sh_a->bitrate = cook_fl2bps[flavor] * 8;
sh_a->block_align = track->sub_packet_size; sh_a->block_align = track->sub_packet_size;
} else if (!strcmp(track->codec_id, "A_REAL/SIPR")) { } else if (!strcmp(track->codec_id, "A_REAL/SIPR")) {
sh->codec = "sipr"; sh_a->codec = "sipr";
if (flavor >= MP_ARRAY_SIZE(sipr_fl2bps)) if (flavor >= MP_ARRAY_SIZE(sipr_fl2bps))
goto error; goto error;
sh_a->bitrate = sipr_fl2bps[flavor] * 8; sh_a->bitrate = sipr_fl2bps[flavor] * 8;
sh_a->block_align = track->coded_framesize; sh_a->block_align = track->coded_framesize;
} else if (!strcmp(track->codec_id, "A_REAL/28_8")) { } else if (!strcmp(track->codec_id, "A_REAL/28_8")) {
sh->codec = "ra_288"; sh_a->codec = "ra_288";
sh_a->bitrate = 3600 * 8; sh_a->bitrate = 3600 * 8;
sh_a->block_align = track->coded_framesize; sh_a->block_align = track->coded_framesize;
} else if (!strcmp(track->codec_id, "A_REAL/DNET")) { } else if (!strcmp(track->codec_id, "A_REAL/DNET")) {
sh->codec = "ac3"; sh_a->codec = "ac3";
} else { } else {
goto error; goto error;
} }
@@ -1595,7 +1595,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
track->audio_timestamp = track->audio_timestamp =
talloc_array(track, double, track->sub_packet_h); talloc_array(track, double, track->sub_packet_h);
} else if (!strncmp(track->codec_id, "A_AAC/", 6)) { } else if (!strncmp(track->codec_id, "A_AAC/", 6)) {
sh->codec = "aac"; sh_a->codec = "aac";
/* Recreate the 'private data' (not needed for plain A_AAC) */ /* Recreate the 'private data' (not needed for plain A_AAC) */
int srate_idx = aac_get_sample_rate_index(track->a_sfreq); int srate_idx = aac_get_sample_rate_index(track->a_sfreq);
@@ -1627,17 +1627,17 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
track->default_duration = 1024.0 / sh_a->samplerate; track->default_duration = 1024.0 / sh_a->samplerate;
} }
} else if (!strncmp(track->codec_id, "A_AC3/", 6)) { } else if (!strncmp(track->codec_id, "A_AC3/", 6)) {
sh->codec = "ac3"; sh_a->codec = "ac3";
} else if (!strncmp(track->codec_id, "A_EAC3/", 7)) { } else if (!strncmp(track->codec_id, "A_EAC3/", 7)) {
sh->codec = "eac3"; sh_a->codec = "eac3";
} }
if (!sh->codec) if (!sh_a->codec)
goto error; goto error;
mp_chmap_set_unknown(&sh_a->channels, track->a_channels); mp_chmap_set_unknown(&sh_a->channels, track->a_channels);
const char *codec = sh->codec; const char *codec = sh_a->codec;
if (!strcmp(codec, "mp3") || !strcmp(codec, "truehd")) { if (!strcmp(codec, "mp3") || !strcmp(codec, "truehd")) {
track->parse = true; track->parse = true;
} else if (!strcmp(codec, "flac")) { } else if (!strcmp(codec, "flac")) {
@@ -1681,8 +1681,8 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
if (sh_a->samplerate == 8000 && strcmp(codec, "ac3") == 0) if (sh_a->samplerate == 8000 && strcmp(codec, "ac3") == 0)
track->default_duration = 0; track->default_duration = 0;
sh->extradata = extradata; sh_a->extradata = extradata;
sh->extradata_size = extradata_len; sh_a->extradata_size = extradata_len;
demux_add_sh_stream(demuxer, sh); demux_add_sh_stream(demuxer, sh);
@@ -1727,7 +1727,7 @@ static int demux_mkv_open_sub(demuxer_t *demuxer, mkv_track_t *track)
struct sh_stream *sh = demux_alloc_sh_stream(STREAM_SUB); struct sh_stream *sh = demux_alloc_sh_stream(STREAM_SUB);
init_track(demuxer, track, sh); init_track(demuxer, track, sh);
sh->codec = subtitle_type; sh->codec->codec = subtitle_type;
bstr in = (bstr){track->private_data, track->private_size}; bstr in = (bstr){track->private_data, track->private_size};
bstr buffer = demux_mkv_decode(demuxer->log, track, in, 2); bstr buffer = demux_mkv_decode(demuxer->log, track, in, 2);
if (buffer.start && buffer.start != track->private_data) { if (buffer.start && buffer.start != track->private_data) {
@@ -1736,8 +1736,8 @@ static int demux_mkv_open_sub(demuxer_t *demuxer, mkv_track_t *track)
track->private_data = buffer.start; track->private_data = buffer.start;
track->private_size = buffer.len; track->private_size = buffer.len;
} }
sh->extradata = track->private_data; sh->codec->extradata = track->private_data;
sh->extradata_size = track->private_size; sh->codec->extradata_size = track->private_size;
demux_add_sh_stream(demuxer, sh); demux_add_sh_stream(demuxer, sh);
@@ -2027,7 +2027,7 @@ static bool handle_realaudio(demuxer_t *demuxer, mkv_track_t *track,
if (!track->audio_buf || !track->audio_timestamp || !track->stream) if (!track->audio_buf || !track->audio_timestamp || !track->stream)
return false; return false;
const char *codec = track->stream->codec ? track->stream->codec : ""; const char *codec = track->stream->codec->codec ? track->stream->codec->codec : "";
if (!strcmp(codec, "ra_288")) { if (!strcmp(codec, "ra_288")) {
for (int x = 0; x < sph / 2; x++) { for (int x = 0; x < sph / 2; x++) {
uint64_t dst_offset = x * 2 * w + spc * (uint64_t)cfs; uint64_t dst_offset = x * 2 * w + spc * (uint64_t)cfs;
@@ -2087,7 +2087,7 @@ static bool handle_realaudio(demuxer_t *demuxer, mkv_track_t *track,
if (++(track->sub_packet_cnt) == sph) { if (++(track->sub_packet_cnt) == sph) {
track->sub_packet_cnt = 0; track->sub_packet_cnt = 0;
// apk_usize has same range as coded_framesize in worst case // apk_usize has same range as coded_framesize in worst case
uint32_t apk_usize = track->stream->audio->block_align; uint32_t apk_usize = track->stream->codec->block_align;
if (apk_usize > audiobuf_size) if (apk_usize > audiobuf_size)
goto error; goto error;
// Release all the audio packets // Release all the audio packets
@@ -2222,7 +2222,7 @@ static void mkv_parse_and_add_packet(demuxer_t *demuxer, mkv_track_t *track,
if (stream->type == STREAM_AUDIO && handle_realaudio(demuxer, track, dp)) if (stream->type == STREAM_AUDIO && handle_realaudio(demuxer, track, dp))
return; return;
if (stream->codec && strcmp(stream->codec, "wavpack") == 0) { if (strcmp(stream->codec->codec, "wavpack") == 0) {
int size = dp->len; int size = dp->len;
uint8_t *parsed; uint8_t *parsed;
if (libav_parse_wavpack(track, dp->buffer, &parsed, &size) >= 0) { if (libav_parse_wavpack(track, dp->buffer, &parsed, &size) >= 0) {
@@ -2236,7 +2236,7 @@ static void mkv_parse_and_add_packet(demuxer_t *demuxer, mkv_track_t *track,
} }
} }
if (stream->codec && strcmp(stream->codec, "prores") == 0) { if (strcmp(stream->codec->codec, "prores") == 0) {
size_t newlen = dp->len + 8; size_t newlen = dp->len + 8;
struct demux_packet *new = new_demux_packet(newlen); struct demux_packet *new = new_demux_packet(newlen);
if (new) { if (new) {
@@ -2251,7 +2251,7 @@ static void mkv_parse_and_add_packet(demuxer_t *demuxer, mkv_track_t *track,
} }
if (track->parse && !track->av_parser) { if (track->parse && !track->av_parser) {
int id = mp_codec_to_av_codec_id(track->stream->codec); int id = mp_codec_to_av_codec_id(track->stream->codec->codec);
const AVCodec *codec = avcodec_find_decoder(id); const AVCodec *codec = avcodec_find_decoder(id);
track->av_parser = av_parser_init(id); track->av_parser = av_parser_init(id);
if (codec) if (codec)
@@ -2447,7 +2447,7 @@ static int handle_block(demuxer_t *demuxer, struct block_info *block_info)
* packets resulting from parsing. */ * packets resulting from parsing. */
if (i == 0 || track->default_duration) if (i == 0 || track->default_duration)
dp->pts = mkv_d->last_pts + i * track->default_duration; dp->pts = mkv_d->last_pts + i * track->default_duration;
if (stream->video && stream->video->avi_dts) if (stream->codec->avi_dts)
MPSWAP(double, dp->pts, dp->dts); MPSWAP(double, dp->pts, dp->dts);
if (i == 0) if (i == 0)
dp->duration = block_duration / 1e9; dp->duration = block_duration / 1e9;

View File

@@ -485,7 +485,7 @@ static void check_track_compatibility(struct timeline *tl)
if (s) { if (s) {
// There are actually many more things that in theory have to // There are actually many more things that in theory have to
// match (though mpv's implementation doesn't care). // match (though mpv's implementation doesn't care).
if (s->codec && m->codec && strcmp(s->codec, m->codec) != 0) if (strcmp(s->codec->codec, m->codec->codec) != 0)
MP_WARN(tl, "Timeline segments have mismatching codec.\n"); MP_WARN(tl, "Timeline segments have mismatching codec.\n");
} else { } else {
MP_WARN(tl, "Source %s lacks %s stream with TID=%d, which " MP_WARN(tl, "Source %s lacks %s stream with TID=%d, which "

View File

@@ -131,14 +131,14 @@ static int demux_rawaudio_open(demuxer_t *demuxer, enum demux_check check)
return -1; return -1;
struct sh_stream *sh = demux_alloc_sh_stream(STREAM_AUDIO); struct sh_stream *sh = demux_alloc_sh_stream(STREAM_AUDIO);
struct sh_audio *sh_audio = sh->audio; struct mp_codec_params *c = sh->codec;
sh_audio->channels = opts->channels; c->channels = opts->channels;
sh_audio->force_channels = true; c->force_channels = true;
sh_audio->samplerate = opts->samplerate; c->samplerate = opts->samplerate;
int f = opts->aformat; int f = opts->aformat;
// See PCM(): sign float bits endian // See PCM(): sign float bits endian
mp_set_pcm_codec(sh, f & 1, f & 2, f >> 3, f & 4); mp_set_pcm_codec(sh->codec, f & 1, f & 2, f >> 3, f & 4);
int samplesize = ((f >> 3) + 7) / 8; int samplesize = ((f >> 3) + 7) / 8;
demux_add_sh_stream(demuxer, sh); demux_add_sh_stream(demuxer, sh);
@@ -147,9 +147,9 @@ static int demux_rawaudio_open(demuxer_t *demuxer, enum demux_check check)
demuxer->priv = p; demuxer->priv = p;
*p = (struct priv) { *p = (struct priv) {
.sh = sh, .sh = sh,
.frame_size = samplesize * sh_audio->channels.num, .frame_size = samplesize * c->channels.num,
.frame_rate = sh_audio->samplerate, .frame_rate = c->samplerate,
.read_frames = sh_audio->samplerate / 8, .read_frames = c->samplerate / 8,
}; };
return 0; return 0;
@@ -220,12 +220,12 @@ static int demux_rawvideo_open(demuxer_t *demuxer, enum demux_check check)
} }
struct sh_stream *sh = demux_alloc_sh_stream(STREAM_VIDEO); struct sh_stream *sh = demux_alloc_sh_stream(STREAM_VIDEO);
struct sh_video *sh_video = sh->video; struct mp_codec_params *c = sh->codec;
sh->codec = decoder; c->codec = decoder;
sh->codec_tag = imgfmt; c->codec_tag = imgfmt;
sh_video->fps = opts->fps; c->fps = opts->fps;
sh_video->disp_w = width; c->disp_w = width;
sh_video->disp_h = height; c->disp_h = height;
demux_add_sh_stream(demuxer, sh); demux_add_sh_stream(demuxer, sh);
struct priv *p = talloc_ptrtype(demuxer, p); struct priv *p = talloc_ptrtype(demuxer, p);
@@ -233,7 +233,7 @@ static int demux_rawvideo_open(demuxer_t *demuxer, enum demux_check check)
*p = (struct priv) { *p = (struct priv) {
.sh = sh, .sh = sh,
.frame_size = imgsize, .frame_size = imgsize,
.frame_rate = sh_video->fps, .frame_rate = c->fps,
.read_frames = 1, .read_frames = 1,
}; };

View File

@@ -20,8 +20,6 @@
static int demux_open_tv(demuxer_t *demuxer, enum demux_check check) static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
{ {
tvi_handle_t *tvh; tvi_handle_t *tvh;
sh_video_t *sh_video;
sh_audio_t *sh_audio = NULL;
const tvi_functions_t *funcs; const tvi_functions_t *funcs;
if (check > DEMUX_CHECK_REQUEST || demuxer->stream->type != STREAMTYPE_TV) if (check > DEMUX_CHECK_REQUEST || demuxer->stream->type != STREAMTYPE_TV)
@@ -51,30 +49,29 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
demuxer->priv=tvh; demuxer->priv=tvh;
struct sh_stream *sh_v = demux_alloc_sh_stream(STREAM_VIDEO); struct sh_stream *sh_v = demux_alloc_sh_stream(STREAM_VIDEO);
sh_video = sh_v->video;
/* get IMAGE FORMAT */ /* get IMAGE FORMAT */
int fourcc; int fourcc;
funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FORMAT, &fourcc); funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FORMAT, &fourcc);
if (fourcc == MP_FOURCC_MJPEG) { if (fourcc == MP_FOURCC_MJPEG) {
sh_v->codec = "mjpeg"; sh_v->codec->codec = "mjpeg";
} else { } else {
sh_v->codec = "rawvideo"; sh_v->codec->codec = "rawvideo";
sh_v->codec_tag = fourcc; sh_v->codec->codec_tag = fourcc;
} }
/* set FPS and FRAMETIME */ /* set FPS and FRAMETIME */
if(!sh_video->fps) if(!sh_v->codec->fps)
{ {
float tmp; float tmp;
if (funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FPS, &tmp) != TVI_CONTROL_TRUE) if (funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FPS, &tmp) != TVI_CONTROL_TRUE)
sh_video->fps = 25.0f; /* on PAL */ sh_v->codec->fps = 25.0f; /* on PAL */
else sh_video->fps = tmp; else sh_v->codec->fps = tmp;
} }
if (tvh->tv_param->fps != -1.0f) if (tvh->tv_param->fps != -1.0f)
sh_video->fps = tvh->tv_param->fps; sh_v->codec->fps = tvh->tv_param->fps;
/* If playback only mode, go to immediate mode, fail silently */ /* If playback only mode, go to immediate mode, fail silently */
if(tvh->tv_param->immediate == 1) if(tvh->tv_param->immediate == 1)
@@ -84,10 +81,10 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
} }
/* set width */ /* set width */
funcs->control(tvh->priv, TVI_CONTROL_VID_GET_WIDTH, &sh_video->disp_w); funcs->control(tvh->priv, TVI_CONTROL_VID_GET_WIDTH, &sh_v->codec->disp_w);
/* set height */ /* set height */
funcs->control(tvh->priv, TVI_CONTROL_VID_GET_HEIGHT, &sh_video->disp_h); funcs->control(tvh->priv, TVI_CONTROL_VID_GET_HEIGHT, &sh_v->codec->disp_h);
demux_add_sh_stream(demuxer, sh_v); demux_add_sh_stream(demuxer, sh_v);
@@ -118,22 +115,21 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
} }
struct sh_stream *sh_a = demux_alloc_sh_stream(STREAM_AUDIO); struct sh_stream *sh_a = demux_alloc_sh_stream(STREAM_AUDIO);
sh_audio = sh_a->audio;
funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_SAMPLERATE, funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_SAMPLERATE,
&sh_audio->samplerate); &sh_a->codec->samplerate);
int nchannels = sh_audio->channels.num; int nchannels = sh_a->codec->channels.num;
funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_CHANNELS, funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_CHANNELS,
&nchannels); &nchannels);
mp_chmap_from_channels(&sh_audio->channels, nchannels); mp_chmap_from_channels(&sh_a->codec->channels, nchannels);
// s16ne // s16ne
mp_set_pcm_codec(sh_a, true, false, 16, BYTE_ORDER == BIG_ENDIAN); mp_set_pcm_codec(sh_a->codec, true, false, 16, BYTE_ORDER == BIG_ENDIAN);
demux_add_sh_stream(demuxer, sh_a); demux_add_sh_stream(demuxer, sh_a);
MP_VERBOSE(tvh, " TV audio: %d channels, %d bits, %d Hz\n", MP_VERBOSE(tvh, " TV audio: %d channels, %d bits, %d Hz\n",
nchannels, 16, sh_audio->samplerate); nchannels, 16, sh_a->codec->samplerate);
} }
no_audio: no_audio:

View File

@@ -37,23 +37,8 @@ struct sh_stream {
int demuxer_id; int demuxer_id;
// FFmpeg stream index (AVFormatContext.streams[index]), or equivalent. // FFmpeg stream index (AVFormatContext.streams[index]), or equivalent.
int ff_index; int ff_index;
// One of these is non-NULL, the others are NULL, depending on the stream
// type.
struct sh_audio *audio;
struct sh_video *video;
struct sh_sub *sub;
// E.g. "h264" (usually corresponds to AVCodecDescriptor.name) struct mp_codec_params *codec;
const char *codec;
// Usually a FourCC, exact meaning depends on codec.
unsigned int codec_tag;
unsigned char *extradata; // codec specific per-stream header
int extradata_size;
// Codec specific header data (set by demux_lavf.c only)
struct AVCodecContext *lav_headers;
char *title; char *title;
char *lang; // language code char *lang; // language code
@@ -70,29 +55,43 @@ struct sh_stream {
struct demux_stream *ds; struct demux_stream *ds;
}; };
typedef struct sh_audio { struct mp_codec_params {
enum stream_type type;
// E.g. "h264" (usually corresponds to AVCodecDescriptor.name)
const char *codec;
// Usually a FourCC, exact meaning depends on codec.
unsigned int codec_tag;
unsigned char *extradata; // codec specific per-stream header
int extradata_size;
// Codec specific header data (set by demux_lavf.c only)
struct AVCodecContext *lav_headers;
// STREAM_AUDIO
int samplerate; int samplerate;
struct mp_chmap channels; struct mp_chmap channels;
bool force_channels; bool force_channels;
int bitrate; // compressed bits/sec int bitrate; // compressed bits/sec
int block_align; int block_align;
int bits_per_coded_sample;
struct replaygain_data *replaygain_data; struct replaygain_data *replaygain_data;
} sh_audio_t;
typedef struct sh_video { // STREAM_VIDEO
bool avi_dts; // use DTS timing; first frame and DTS is 0 bool avi_dts; // use DTS timing; first frame and DTS is 0
float fps; // frames per second (set only if constant fps) float fps; // frames per second (set only if constant fps)
int par_w, par_h; // pixel aspect ratio (0 if unknown/square) int par_w, par_h; // pixel aspect ratio (0 if unknown/square)
int bits_per_coded_sample;
int disp_w, disp_h; // display size int disp_w, disp_h; // display size
int rotate; // intended display rotation, in degrees, [0, 359] int rotate; // intended display rotation, in degrees, [0, 359]
int stereo_mode; // mp_stereo3d_mode (0 if none/unknown) int stereo_mode; // mp_stereo3d_mode (0 if none/unknown)
} sh_video_t;
typedef struct sh_sub { // STREAM_VIDEO + STREAM_AUDIO
double frame_based; // timestamps are frame-based (and this is the int bits_per_coded_sample;
// fallback framerate used for timestamps)
} sh_sub_t; // STREAM_SUB
double frame_based; // timestamps are frame-based (and this is the
// fallback framerate used for timestamps)
};
#endif /* MPLAYER_STHEADER_H */ #endif /* MPLAYER_STHEADER_H */

View File

@@ -218,7 +218,7 @@ void reinit_audio_chain(struct MPContext *mpctx)
mpctx->d_audio->header = sh; mpctx->d_audio->header = sh;
mpctx->d_audio->pool = mp_audio_pool_create(mpctx->d_audio); mpctx->d_audio->pool = mp_audio_pool_create(mpctx->d_audio);
mpctx->d_audio->afilter = af_new(mpctx->global); mpctx->d_audio->afilter = af_new(mpctx->global);
mpctx->d_audio->afilter->replaygain_data = sh->audio->replaygain_data; mpctx->d_audio->afilter->replaygain_data = sh->codec->replaygain_data;
mpctx->d_audio->spdif_passthrough = true; mpctx->d_audio->spdif_passthrough = true;
mpctx->ao_buffer = mp_audio_buffer_create(NULL); mpctx->ao_buffer = mp_audio_buffer_create(NULL);
if (!audio_init_best_codec(mpctx->d_audio)) if (!audio_init_best_codec(mpctx->d_audio))

View File

@@ -1713,7 +1713,7 @@ static int mp_property_audio_codec_name(void *ctx, struct m_property *prop,
int action, void *arg) int action, void *arg)
{ {
MPContext *mpctx = ctx; MPContext *mpctx = ctx;
const char *c = mpctx->d_audio ? mpctx->d_audio->header->codec : NULL; const char *c = mpctx->d_audio ? mpctx->d_audio->header->codec->codec : NULL;
return m_property_strdup_ro(action, arg, c); return m_property_strdup_ro(action, arg, c);
} }
@@ -1930,8 +1930,7 @@ static int property_switch_track_ff(void *ctx, struct m_property *prop,
static int track_channels(struct track *track) static int track_channels(struct track *track)
{ {
return track->stream && track->stream->audio return track->stream ? track->stream->codec->channels.num : 0;
? track->stream->audio->channels.num : 0;
} }
static int get_track_entry(int item, int action, void *arg, void *ctx) static int get_track_entry(int item, int action, void *arg, void *ctx)
@@ -1939,7 +1938,7 @@ static int get_track_entry(int item, int action, void *arg, void *ctx)
struct MPContext *mpctx = ctx; struct MPContext *mpctx = ctx;
struct track *track = mpctx->tracks[item]; struct track *track = mpctx->tracks[item];
const char *codec = track->stream ? track->stream->codec : NULL; const char *codec = track->stream ? track->stream->codec->codec : NULL;
struct m_sub_property props[] = { struct m_sub_property props[] = {
{"id", SUB_PROP_INT(track->user_tid)}, {"id", SUB_PROP_INT(track->user_tid)},
@@ -2431,7 +2430,7 @@ static int mp_property_video_format(void *ctx, struct m_property *prop,
int action, void *arg) int action, void *arg)
{ {
MPContext *mpctx = ctx; MPContext *mpctx = ctx;
const char *c = mpctx->d_video ? mpctx->d_video->header->codec : NULL; const char *c = mpctx->d_video ? mpctx->d_video->header->codec->codec : NULL;
return m_property_strdup_ro(action, arg, c); return m_property_strdup_ro(action, arg, c);
} }
@@ -2512,15 +2511,15 @@ static int mp_property_vd_imgparams(void *ctx, struct m_property *prop,
struct dec_video *vd = mpctx->d_video; struct dec_video *vd = mpctx->d_video;
if (!vd) if (!vd)
return M_PROPERTY_UNAVAILABLE; return M_PROPERTY_UNAVAILABLE;
struct sh_video *sh = vd->header->video; struct mp_codec_params *c = vd->header->codec;
if (vd->vfilter->override_params.imgfmt) { if (vd->vfilter->override_params.imgfmt) {
return property_imgparams(vd->vfilter->override_params, action, arg); return property_imgparams(vd->vfilter->override_params, action, arg);
} else if (sh->disp_w && sh->disp_h) { } else if (c->disp_w && c->disp_h) {
// Simplistic fallback for stupid scripts querying "width"/"height" // Simplistic fallback for stupid scripts querying "width"/"height"
// before the first frame is decoded. // before the first frame is decoded.
struct m_sub_property props[] = { struct m_sub_property props[] = {
{"w", SUB_PROP_INT(sh->disp_w)}, {"w", SUB_PROP_INT(c->disp_w)},
{"h", SUB_PROP_INT(sh->disp_h)}, {"h", SUB_PROP_INT(c->disp_h)},
{0} {0}
}; };
return m_property_read_sub(props, action, arg); return m_property_read_sub(props, action, arg);
@@ -2779,14 +2778,14 @@ static int mp_property_aspect(void *ctx, struct m_property *prop,
float aspect = mpctx->opts->movie_aspect; float aspect = mpctx->opts->movie_aspect;
if (mpctx->d_video && aspect <= 0) { if (mpctx->d_video && aspect <= 0) {
struct dec_video *d_video = mpctx->d_video; struct dec_video *d_video = mpctx->d_video;
struct sh_video *sh_video = d_video->header->video; struct mp_codec_params *c = d_video->header->codec;
struct mp_image_params *params = &d_video->vfilter->override_params; struct mp_image_params *params = &d_video->vfilter->override_params;
if (params && params->p_w > 0 && params->p_h > 0) { if (params && params->p_w > 0 && params->p_h > 0) {
int d_w, d_h; int d_w, d_h;
mp_image_params_get_dsize(params, &d_w, &d_h); mp_image_params_get_dsize(params, &d_w, &d_h);
aspect = (float)d_w / d_h; aspect = (float)d_w / d_h;
} else if (sh_video->disp_w && sh_video->disp_h) { } else if (c->disp_w && c->disp_h) {
aspect = (float)sh_video->disp_w / sh_video->disp_h; aspect = (float)c->disp_w / c->disp_h;
} }
} }
*(float *)arg = aspect; *(float *)arg = aspect;

View File

@@ -134,7 +134,7 @@ static void print_stream(struct MPContext *mpctx, struct track *t)
APPEND(b, " [P]"); APPEND(b, " [P]");
if (t->title) if (t->title)
APPEND(b, " '%s'", t->title); APPEND(b, " '%s'", t->title);
const char *codec = s ? s->codec : NULL; const char *codec = s ? s->codec->codec : NULL;
APPEND(b, " (%s)", codec ? codec : "<unknown>"); APPEND(b, " (%s)", codec ? codec : "<unknown>");
if (t->is_external) if (t->is_external)
APPEND(b, " (external)"); APPEND(b, " (external)");

View File

@@ -118,9 +118,9 @@ static bool init_subdec(struct MPContext *mpctx, struct track *track)
if (!track->dec_sub) if (!track->dec_sub)
return false; return false;
struct sh_video *sh_video = struct mp_codec_params *v_c =
mpctx->d_video ? mpctx->d_video->header->video : NULL; mpctx->d_video ? mpctx->d_video->header->codec : NULL;
double fps = sh_video ? sh_video->fps : 25; double fps = v_c ? v_c->fps : 25;
sub_control(track->dec_sub, SD_CTRL_SET_VIDEO_DEF_FPS, &fps); sub_control(track->dec_sub, SD_CTRL_SET_VIDEO_DEF_FPS, &fps);
// Don't do this if the file has video/audio streams. Don't do it even // Don't do this if the file has video/audio streams. Don't do it even

View File

@@ -277,10 +277,10 @@ int reinit_video_chain(struct MPContext *mpctx)
d_video->log = mp_log_new(d_video, mpctx->log, "!vd"); d_video->log = mp_log_new(d_video, mpctx->log, "!vd");
d_video->opts = mpctx->opts; d_video->opts = mpctx->opts;
d_video->header = sh; d_video->header = sh;
d_video->fps = sh->video->fps; d_video->fps = sh->codec->fps;
d_video->vo = mpctx->video_out; d_video->vo = mpctx->video_out;
MP_VERBOSE(d_video, "Container reported FPS: %f\n", sh->video->fps); MP_VERBOSE(d_video, "Container reported FPS: %f\n", sh->codec->fps);
if (opts->force_fps) { if (opts->force_fps) {
d_video->fps = opts->force_fps; d_video->fps = opts->force_fps;

View File

@@ -81,7 +81,7 @@ void sub_destroy(struct dec_sub *sub)
struct dec_sub *sub_create(struct mpv_global *global, struct demuxer *demuxer, struct dec_sub *sub_create(struct mpv_global *global, struct demuxer *demuxer,
struct sh_stream *sh) struct sh_stream *sh)
{ {
assert(demuxer && sh && sh->sub); assert(demuxer && sh && sh->type == STREAM_SUB);
struct mp_log *log = mp_log_new(NULL, global->log, "sub"); struct mp_log *log = mp_log_new(NULL, global->log, "sub");
@@ -101,7 +101,7 @@ struct dec_sub *sub_create(struct mpv_global *global, struct demuxer *demuxer,
.opts = sub->opts, .opts = sub->opts,
.driver = driver, .driver = driver,
.demuxer = demuxer, .demuxer = demuxer,
.sh = sh, .codec = sh->codec,
}; };
if (sh->codec && sub->sd->driver->init(sub->sd) >= 0) if (sh->codec && sub->sd->driver->init(sub->sd) >= 0)
@@ -113,7 +113,7 @@ struct dec_sub *sub_create(struct mpv_global *global, struct demuxer *demuxer,
} }
mp_err(log, "Could not find subtitle decoder for format '%s'.\n", mp_err(log, "Could not find subtitle decoder for format '%s'.\n",
sh->codec ? sh->codec : "<unknown>"); sh->codec->codec);
talloc_free(log); talloc_free(log);
return NULL; return NULL;
} }

View File

@@ -18,7 +18,7 @@ struct sd {
void *priv; void *priv;
struct demuxer *demuxer; struct demuxer *demuxer;
struct sh_stream *sh; struct mp_codec_params *codec;
}; };
struct sd_functions { struct sd_functions {

View File

@@ -165,12 +165,12 @@ static int init(struct sd *sd)
struct sd_ass_priv *ctx = talloc_zero(sd, struct sd_ass_priv); struct sd_ass_priv *ctx = talloc_zero(sd, struct sd_ass_priv);
sd->priv = ctx; sd->priv = ctx;
char *extradata = sd->sh->extradata; char *extradata = sd->codec->extradata;
int extradata_size = sd->sh->extradata_size; int extradata_size = sd->codec->extradata_size;
if (strcmp(sd->sh->codec, "ass") != 0) { if (strcmp(sd->codec->codec, "ass") != 0) {
ctx->is_converted = true; ctx->is_converted = true;
ctx->converter = lavc_conv_create(sd->log, sd->sh->codec, extradata, ctx->converter = lavc_conv_create(sd->log, sd->codec->codec, extradata,
extradata_size); extradata_size);
if (!ctx->converter) if (!ctx->converter)
return -1; return -1;
@@ -203,7 +203,7 @@ static int init(struct sd *sd)
ass_set_check_readorder(ctx->ass_track, sd->opts->sub_clear_on_seek ? 0 : 1); ass_set_check_readorder(ctx->ass_track, sd->opts->sub_clear_on_seek ? 0 : 1);
#endif #endif
ctx->frame_fps = sd->sh->sub->frame_based; ctx->frame_fps = sd->codec->frame_based;
update_subtitle_speed(sd); update_subtitle_speed(sd);
enable_output(sd, true); enable_output(sd, true);

View File

@@ -95,7 +95,7 @@ static void get_resolution(struct sd *sd, int wh[2])
static int init(struct sd *sd) static int init(struct sd *sd)
{ {
enum AVCodecID cid = mp_codec_to_av_codec_id(sd->sh->codec); enum AVCodecID cid = mp_codec_to_av_codec_id(sd->codec->codec);
// Supported codecs must be known to decode to paletted bitmaps // Supported codecs must be known to decode to paletted bitmaps
switch (cid) { switch (cid) {
@@ -116,7 +116,7 @@ static int init(struct sd *sd)
ctx = avcodec_alloc_context3(sub_codec); ctx = avcodec_alloc_context3(sub_codec);
if (!ctx) if (!ctx)
goto error; goto error;
mp_lavc_set_extradata(ctx, sd->sh->extradata, sd->sh->extradata_size); mp_lavc_set_extradata(ctx, sd->codec->extradata, sd->codec->extradata_size);
if (avcodec_open2(ctx, sub_codec, NULL) < 0) if (avcodec_open2(ctx, sub_codec, NULL) < 0)
goto error; goto error;
priv->avctx = ctx; priv->avctx = ctx;

View File

@@ -168,7 +168,7 @@ bool video_init_best_codec(struct dec_video *d_video, char* video_decoders)
struct mp_decoder_entry *decoder = NULL; struct mp_decoder_entry *decoder = NULL;
struct mp_decoder_list *list = struct mp_decoder_list *list =
mp_select_video_decoders(d_video->header->codec, video_decoders); mp_select_video_decoders(d_video->header->codec->codec, video_decoders);
mp_print_decoders(d_video->log, MSGL_V, "Codec list:", list); mp_print_decoders(d_video->log, MSGL_V, "Codec list:", list);
@@ -196,7 +196,7 @@ bool video_init_best_codec(struct dec_video *d_video, char* video_decoders)
MP_VERBOSE(d_video, "Selected video codec: %s\n", d_video->decoder_desc); MP_VERBOSE(d_video, "Selected video codec: %s\n", d_video->decoder_desc);
} else { } else {
MP_ERR(d_video, "Failed to initialize a video decoder for codec '%s'.\n", MP_ERR(d_video, "Failed to initialize a video decoder for codec '%s'.\n",
d_video->header->codec ? d_video->header->codec : "<unknown>"); d_video->header->codec->codec);
} }
if (d_video->header->missing_timestamps) { if (d_video->header->missing_timestamps) {
@@ -242,7 +242,7 @@ struct mp_image *video_decode(struct dec_video *d_video,
int drop_frame) int drop_frame)
{ {
struct MPOpts *opts = d_video->opts; struct MPOpts *opts = d_video->opts;
bool avi_pts = d_video->header->video->avi_dts && opts->correct_pts; bool avi_pts = d_video->header->codec->avi_dts && opts->correct_pts;
struct demux_packet packet_copy; struct demux_packet packet_copy;
if (packet && packet->dts == MP_NOPTS_VALUE) { if (packet && packet->dts == MP_NOPTS_VALUE) {
@@ -264,7 +264,7 @@ struct mp_image *video_decode(struct dec_video *d_video,
double prev_codec_pts = d_video->codec_pts; double prev_codec_pts = d_video->codec_pts;
double prev_codec_dts = d_video->codec_dts; double prev_codec_dts = d_video->codec_dts;
if (d_video->header->video->avi_dts) if (d_video->header->codec->avi_dts)
drop_frame = 0; drop_frame = 0;
MP_STATS(d_video, "start decode video"); MP_STATS(d_video, "start decode video");
@@ -339,7 +339,7 @@ int video_reconfig_filters(struct dec_video *d_video,
{ {
struct MPOpts *opts = d_video->opts; struct MPOpts *opts = d_video->opts;
struct mp_image_params p = *params; struct mp_image_params p = *params;
struct sh_video *sh = d_video->header->video; struct mp_codec_params *c = d_video->header->codec;
// While mp_image_params normally always have to have d_w/d_h set, the // While mp_image_params normally always have to have d_w/d_h set, the
// decoder signals unknown bitstream aspect ratio with both set to 0. // decoder signals unknown bitstream aspect ratio with both set to 0.
@@ -364,10 +364,10 @@ int video_reconfig_filters(struct dec_video *d_video,
break; break;
} }
if (use_container && sh->par_w > 0 && sh->par_h) { if (use_container && c->par_w > 0 && c->par_h) {
MP_VERBOSE(d_video, "Using container aspect ratio.\n"); MP_VERBOSE(d_video, "Using container aspect ratio.\n");
p.p_w = sh->par_w; p.p_w = c->par_w;
p.p_h = sh->par_h; p.p_h = c->par_h;
} }
if (opts->movie_aspect >= 0) { if (opts->movie_aspect >= 0) {

View File

@@ -352,6 +352,7 @@ static void init_avctx(struct dec_video *vd, const char *decoder,
struct vd_lavc_params *lavc_param = vd->opts->vd_lavc_params; struct vd_lavc_params *lavc_param = vd->opts->vd_lavc_params;
bool mp_rawvideo = false; bool mp_rawvideo = false;
struct sh_stream *sh = vd->header; struct sh_stream *sh = vd->header;
struct mp_codec_params *c = sh->codec;
assert(!ctx->avctx); assert(!ctx->avctx);
@@ -414,23 +415,23 @@ static void init_avctx(struct dec_video *vd, const char *decoder,
// Do this after the above avopt handling in case it changes values // Do this after the above avopt handling in case it changes values
ctx->skip_frame = avctx->skip_frame; ctx->skip_frame = avctx->skip_frame;
avctx->codec_tag = sh->codec_tag; avctx->codec_tag = c->codec_tag;
avctx->coded_width = sh->video->disp_w; avctx->coded_width = c->disp_w;
avctx->coded_height = sh->video->disp_h; avctx->coded_height = c->disp_h;
avctx->bits_per_coded_sample = sh->video->bits_per_coded_sample; avctx->bits_per_coded_sample = c->bits_per_coded_sample;
mp_lavc_set_extradata(avctx, sh->extradata, sh->extradata_size); mp_lavc_set_extradata(avctx, c->extradata, c->extradata_size);
if (mp_rawvideo) { if (mp_rawvideo) {
avctx->pix_fmt = imgfmt2pixfmt(sh->codec_tag); avctx->pix_fmt = imgfmt2pixfmt(c->codec_tag);
avctx->codec_tag = 0; avctx->codec_tag = 0;
if (avctx->pix_fmt == AV_PIX_FMT_NONE && sh->codec_tag) if (avctx->pix_fmt == AV_PIX_FMT_NONE && c->codec_tag)
MP_ERR(vd, "Image format %s not supported by lavc.\n", MP_ERR(vd, "Image format %s not supported by lavc.\n",
mp_imgfmt_to_name(sh->codec_tag)); mp_imgfmt_to_name(c->codec_tag));
} }
if (sh->lav_headers) if (c->lav_headers)
mp_copy_lav_codec_headers(avctx, sh->lav_headers); mp_copy_lav_codec_headers(avctx, c->lav_headers);
/* open it */ /* open it */
if (avcodec_open2(avctx, lavc_codec, NULL) < 0) if (avcodec_open2(avctx, lavc_codec, NULL) < 0)
@@ -506,8 +507,8 @@ static void update_image_params(struct dec_video *vd, AVFrame *frame,
.gamma = avcol_trc_to_mp_csp_trc(ctx->avctx->color_trc), .gamma = avcol_trc_to_mp_csp_trc(ctx->avctx->color_trc),
.chroma_location = .chroma_location =
avchroma_location_to_mp(ctx->avctx->chroma_sample_location), avchroma_location_to_mp(ctx->avctx->chroma_sample_location),
.rotate = vd->header->video->rotate, .rotate = vd->header->codec->rotate,
.stereo_in = vd->header->video->stereo_mode, .stereo_in = vd->header->codec->stereo_mode,
}; };
if (opts->video_rotate < 0) { if (opts->video_rotate < 0) {