aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--audio/decode/ad_lavc.c31
-rw-r--r--audio/decode/dec_audio.c4
-rw-r--r--demux/codec_tags.c16
-rw-r--r--demux/codec_tags.h8
-rw-r--r--demux/demux.c15
-rw-r--r--demux/demux_disc.c24
-rw-r--r--demux/demux_lavf.c57
-rw-r--r--demux/demux_mf.c17
-rw-r--r--demux/demux_mkv.c90
-rw-r--r--demux/demux_mkv_timeline.c2
-rw-r--r--demux/demux_raw.c32
-rw-r--r--demux/demux_tv.c32
-rw-r--r--demux/stheader.h51
-rw-r--r--player/audio.c2
-rw-r--r--player/command.c23
-rw-r--r--player/loadfile.c2
-rw-r--r--player/sub.c6
-rw-r--r--player/video.c4
-rw-r--r--sub/dec_sub.c6
-rw-r--r--sub/sd.h2
-rw-r--r--sub/sd_ass.c10
-rw-r--r--sub/sd_lavc.c4
-rw-r--r--video/decode/dec_video.c16
-rw-r--r--video/decode/vd_lavc.c25
24 files changed, 232 insertions, 247 deletions
diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c
index f4a0a243d1..7e5c8d5aa5 100644
--- a/audio/decode/ad_lavc.c
+++ b/audio/decode/ad_lavc.c
@@ -79,12 +79,12 @@ static int init(struct dec_audio *da, const char *decoder)
AVCodecContext *lavc_context;
AVCodec *lavc_codec;
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);
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);
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);
- lavc_context->codec_tag = sh->codec_tag;
- lavc_context->sample_rate = sh_audio->samplerate;
- lavc_context->bit_rate = sh_audio->bitrate;
- lavc_context->block_align = sh_audio->block_align;
- lavc_context->bits_per_coded_sample = sh_audio->bits_per_coded_sample;
- lavc_context->channels = sh_audio->channels.num;
- if (!mp_chmap_is_unknown(&sh_audio->channels))
- lavc_context->channel_layout = mp_chmap_to_lavc(&sh_audio->channels);
+ lavc_context->codec_tag = c->codec_tag;
+ lavc_context->sample_rate = c->samplerate;
+ lavc_context->bit_rate = c->bitrate;
+ lavc_context->block_align = c->block_align;
+ lavc_context->bits_per_coded_sample = c->bits_per_coded_sample;
+ lavc_context->channels = c->channels.num;
+ if (!mp_chmap_is_unknown(&c->channels))
+ lavc_context->channel_layout = mp_chmap_to_lavc(&c->channels);
// 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)
- mp_copy_lav_codec_headers(lavc_context, sh->lav_headers);
+ if (c->lav_headers)
+ mp_copy_lav_codec_headers(lavc_context, c->lav_headers);
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)
mp_chmap_from_channels(&lavc_chmap, avctx->channels);
if (priv->force_channel_map) {
- struct sh_audio *sh_audio = da->header->audio;
- if (lavc_chmap.num == sh_audio->channels.num)
- lavc_chmap = sh_audio->channels;
+ if (lavc_chmap.num == da->header->codec->channels.num)
+ lavc_chmap = da->header->codec->channels;
}
mp_audio_set_channels(mpframe, &lavc_chmap);
diff --git a/audio/decode/dec_audio.c b/audio/decode/dec_audio.c
index 99c01b408e..f774ed1abd 100644
--- a/audio/decode/dec_audio.c
+++ b/audio/decode/dec_audio.c
@@ -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)
{
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 *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);
} else {
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);
diff --git a/demux/codec_tags.c b/demux/codec_tags.c
index c7b48f6038..7e91291e9e 100644
--- a/demux/codec_tags.c
+++ b/demux/codec_tags.c
@@ -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 =
- 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)
- sh->codec = codec;
+ c->codec = codec;
}
}
-void mp_set_pcm_codec(struct sh_stream *sh, bool sign, bool is_float, int bits,
- bool is_be)
+void mp_set_pcm_codec(struct mp_codec_params *c, bool sign, bool is_float,
+ int bits, bool is_be)
{
// This uses libavcodec pcm codec names, e.g. "pcm_u16le".
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);
if (bits != 8)
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] = {
diff --git a/demux/codec_tags.h b/demux/codec_tags.h
index 3489f0da5c..294759a299 100644
--- a/demux/codec_tags.h
+++ b/demux/codec_tags.h
@@ -21,12 +21,12 @@
#include <stdint.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,
- bool is_be);
+void mp_set_pcm_codec(struct mp_codec_params *c, bool sign, bool is_float,
+ int bits, bool is_be);
const char *mp_map_mimetype_to_video_codec(const char *mimetype);
diff --git a/demux/demux.c b/demux/demux.c
index b251674496..19ad6970b0 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -214,13 +214,9 @@ struct sh_stream *demux_alloc_sh_stream(enum stream_type type)
.index = -1,
.ff_index = -1, // may be overwritten by demuxer
.demuxer_id = -1, // ... same
+ .codec = talloc_zero(sh, struct mp_codec_params),
};
- switch (sh->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;
- }
-
+ sh->codec->type = type;
return sh;
}
@@ -241,6 +237,9 @@ void demux_add_sh_stream(struct demuxer *demuxer, struct sh_stream *sh)
.selected = in->autoselect,
};
+ if (!sh->codec->codec)
+ sh->codec->codec = "";
+
sh->index = in->num_streams;
if (sh->ff_index < 0)
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;
for (int n = 0; n < in->num_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",
rg->track_gain, rg->track_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));
}
}
}
diff --git a/demux/demux_disc.c b/demux/demux_disc.c
index 90c276b414..dcc3e7c79f 100644
--- a/demux/demux_disc.c
+++ b/demux/demux_disc.c
@@ -84,7 +84,7 @@ static void add_dvd_streams(demuxer_t *demuxer)
for (int n = 0; n < MPMIN(32, info.num_subs); n++) {
struct sh_stream *sh = demux_alloc_sh_stream(STREAM_SUB);
sh->demuxer_id = n + 0x20;
- sh->codec = "dvd_subtitle";
+ sh->codec->codec = "dvd_subtitle";
get_disc_lang(stream, sh);
// 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
@@ -111,8 +111,8 @@ static void add_dvd_streams(demuxer_t *demuxer)
}
s = talloc_asprintf_append(s, "\n");
- sh->extradata = s;
- sh->extradata_size = strlen(s);
+ sh->codec->extradata = s;
+ sh->codec->extradata_size = strlen(s);
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++) {
struct sh_stream *src = demux_get_stream(p->slave, n);
- if (src->sub) {
+ if (src->type == STREAM_SUB) {
struct sh_stream *sub = NULL;
if (src->demuxer_id >= 0x20 && src->demuxer_id <= 0x3F)
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
MP_TARRAY_APPEND(p, p->streams, p->num_streams, sh);
// Copy all stream fields that might be relevant
- sh->codec = talloc_strdup(sh, src->codec);
- sh->codec_tag = src->codec_tag;
- sh->lav_headers = src->lav_headers;
+ *sh->codec = *src->codec;
sh->demuxer_id = src->demuxer_id;
- if (src->video) {
+ if (src->type == STREAM_VIDEO) {
double ar;
if (stream_control(demuxer->stream, STREAM_CTRL_GET_ASPECT_RATIO, &ar)
== STREAM_OK)
{
- struct mp_image_params f = {.w = src->video->disp_w,
- .h = src->video->disp_h};
+ struct mp_image_params f = {.w = src->codec->disp_w,
+ .h = src->codec->disp_h};
mp_image_params_set_dsize(&f, 1728 * ar, 1728);
- sh->video->par_w = f.p_w;
- sh->video->par_h = f.p_h;
+ sh->codec->par_w = f.p_w;
+ sh->codec->par_h = f.p_h;
}
}
- if (src->audio)
- sh->audio = src->audio;
get_disc_lang(demuxer->stream, sh);
demux_add_sh_stream(demuxer, sh);
}
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index f9586c4788..712b208460 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -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++) {
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) ?
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) {
case AVMEDIA_TYPE_AUDIO: {
sh = demux_alloc_sh_stream(STREAM_AUDIO);
- sh_audio_t *sh_audio = sh->audio;
// probably unneeded
- mp_chmap_set_unknown(&sh_audio->channels, codec->channels);
+ mp_chmap_set_unknown(&sh->codec->channels, codec->channels);
if (codec->channel_layout)
- mp_chmap_from_lavc(&sh_audio->channels, codec->channel_layout);
- sh_audio->samplerate = codec->sample_rate;
- sh_audio->bitrate = codec->bit_rate;
+ mp_chmap_from_lavc(&sh->codec->channels, codec->channel_layout);
+ sh->codec->samplerate = codec->sample_rate;
+ sh->codec->bitrate = codec->bit_rate;
- export_replaygain(demuxer, sh_audio, st);
+ export_replaygain(demuxer, sh->codec, st);
break;
}
case AVMEDIA_TYPE_VIDEO: {
sh = demux_alloc_sh_stream(STREAM_VIDEO);
- sh_video_t *sh_video = sh->video;
if (st->disposition & AV_DISPOSITION_ATTACHED_PIC) {
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_video->disp_h = codec->height;
+ sh->codec->disp_w = codec->width;
+ sh->codec->disp_h = codec->height;
/* Try to make up some frame rate value, even if it's not reliable.
* FPS information is needed to support subtitle formats which base
* 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),
av_q2d(st->codec->time_base) *
st->codec->ticks_per_frame);
- sh_video->fps = fps;
+ sh->codec->fps = fps;
if (priv->format_hack.image_format)
- sh_video->fps = demuxer->opts->mf_fps;
- sh_video->par_w = st->sample_aspect_ratio.num;
- sh_video->par_h = st->sample_aspect_ratio.den;
+ sh->codec->fps = demuxer->opts->mf_fps;
+ sh->codec->par_w = st->sample_aspect_ratio.num;
+ sh->codec->par_h = st->sample_aspect_ratio.den;
uint8_t *sd = av_stream_get_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, NULL);
if (sd) {
double r = av_display_rotation_get((uint32_t *)sd);
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.
- sh_video->avi_dts = matches_avinputformat_name(priv, "avi");
+ sh->codec->avi_dts = matches_avinputformat_name(priv, "avi");
break;
}
case AVMEDIA_TYPE_SUBTITLE: {
- sh_sub_t *sh_sub;
sh = demux_alloc_sh_stream(STREAM_SUB);
- sh_sub = sh->sub;
if (codec->extradata_size) {
- sh->extradata = talloc_size(sh, codec->extradata_size);
- memcpy(sh->extradata, codec->extradata, codec->extradata_size);
- sh->extradata_size = codec->extradata_size;
+ sh->codec->extradata = talloc_size(sh, codec->extradata_size);
+ memcpy(sh->codec->extradata, codec->extradata, codec->extradata_size);
+ sh->codec->extradata_size = codec->extradata_size;
}
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) {
// File headers don't have a FPS set.
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 {
// Older libavformat versions. If the FPS matches the microdvd
// reader's default, assume it uses frame based timing.
if (codec->time_base.num == 125 && codec->time_base.den == 2997)
- sh_sub->frame_based = 23.976;
+ sh->codec->frame_based = 23.976;
}
}
break;
@@ -658,11 +655,11 @@ static void handle_new_stream(demuxer_t *demuxer, int i)
if (sh) {
sh->ff_index = st->index;
- sh->codec = mp_codec_from_av_codec_id(codec->codec_id);
- sh->codec_tag = codec->codec_tag;
- sh->lav_headers = avcodec_alloc_context3(NULL);
- if (sh->lav_headers)
- mp_copy_lav_codec_headers(sh->lav_headers, codec);
+ sh->codec->codec = mp_codec_from_av_codec_id(codec->codec_id);
+ sh->codec->codec_tag = codec->codec_tag;
+ sh->codec->lav_headers = avcodec_alloc_context3(NULL);
+ if (sh->codec->lav_headers)
+ mp_copy_lav_codec_headers(sh->codec->lav_headers, codec);
if (st->disposition & AV_DISPOSITION_DEFAULT)
sh->default_track = true;
@@ -1104,7 +1101,7 @@ static void demux_close_lavf(demuxer_t *demuxer)
av_freep(&priv->pb);
for (int n = 0; n < priv->num_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)
free_stream(priv->stream);
diff --git a/demux/demux_mf.c b/demux/demux_mf.c
index b41bf87aa3..a91d13dff2 100644
--- a/demux/demux_mf.c
+++ b/demux/demux_mf.c
@@ -165,7 +165,7 @@ static void demux_seek_mf(demuxer_t *demuxer, double rel_seek_secs, int flags)
if (flags & SEEK_FACTOR)
newpos += rel_seek_secs * (mf->nr_of_files - 1);
else
- newpos += rel_seek_secs * mf->sh->video->fps;
+ newpos += rel_seek_secs * mf->sh->codec->fps;
if (newpos < 0)
newpos = 0;
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);
if (dp) {
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;
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)
{
- sh_video_t *sh_video = NULL;
mf_t *mf;
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
struct sh_stream *sh = demux_alloc_sh_stream(STREAM_VIDEO);
- sh_video = sh->video;
+ struct mp_codec_params *c = sh->codec;
- sh->codec = codec;
- sh_video->disp_w = 0;
- sh_video->disp_h = 0;
- sh_video->fps = demuxer->opts->mf_fps;
+ c->codec = codec;
+ c->disp_w = 0;
+ c->disp_h = 0;
+ c->fps = demuxer->opts->mf_fps;
demux_add_sh_stream(demuxer, sh);
@@ -346,7 +345,7 @@ static int demux_control_mf(demuxer_t *demuxer, int cmd, void *arg)
switch (cmd) {
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;
default:
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c
index 3951452074..024f7e7e6e 100644
--- a/demux/demux_mkv.c
+++ b/demux/demux_mkv.c
@@ -1201,7 +1201,7 @@ static void add_coverart(struct demuxer *demuxer)
continue;
struct sh_stream *sh = demux_alloc_sh_stream(STREAM_VIDEO);
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);
if (sh->attached_picture) {
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;
struct sh_stream *sh = demux_alloc_sh_stream(STREAM_VIDEO);
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;
@@ -1288,11 +1288,11 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track)
if (track->v_height == 0)
track->v_height = AV_RL32(h + 8); // biHeight
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_size = track->private_size - 40;
- mp_set_codec_from_tag(sh);
+ mp_set_codec_from_tag(sh_v);
sh_v->avi_dts = true;
} else if (track->private_size >= RVPROPERTIES_SIZE
&& (!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;
uint32_t t2 = AV_RB32(src - 4);
switch (t2 == 0x10003000 || t2 == 0x10003001 ? '1' : track->codec_id[9]) {
- case '1': sh->codec = "rv10"; break;
- case '2': sh->codec = "rv20"; break;
- case '3': sh->codec = "rv30"; break;
- case '4': sh->codec = "rv40"; break;
+ case '1': sh_v->codec = "rv10"; break;
+ case '2': sh_v->codec = "rv20"; break;
+ case '3': sh_v->codec = "rv30"; break;
+ case '4': sh_v->codec = "rv40"; break;
}
// copy type1 and type2 info from rv properties
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;
} else if (strcmp(track->codec_id, "V_UNCOMPRESSED") == 0) {
// raw video, "like AVI" - this is a FourCC
- sh->codec_tag = track->colorspace;
- sh->codec = "rawvideo";
+ sh_v->codec_tag = track->colorspace;
+ sh_v->codec = "rawvideo";
} else if (strcmp(track->codec_id, "V_QUICKTIME") == 0) {
uint32_t fourcc1 = 0, fourcc2 = 0;
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') ||
fourcc2 == MP_FOURCC('S', 'V', 'Q', '3'))
{
- sh->codec = "svq3";
+ sh_v->codec = "svq3";
extradata = track->private_data;
extradata_size = track->private_size;
}
} else {
for (int i = 0; mkv_video_tags[i][0]; i++) {
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;
}
}
@@ -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")) {
track->parse = true;
track->parse_timebase = 1e9;
} 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) {
@@ -1361,9 +1361,9 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track)
goto done;
}
- sh->extradata = talloc_memdup(sh_v, extradata, extradata_size);
- sh->extradata_size = extradata_size;
- if (!sh->codec) {
+ sh_v->extradata = talloc_memdup(sh_v, extradata, extradata_size);
+ sh_v->extradata_size = extradata_size;
+ if (!sh_v->codec) {
MP_WARN(demuxer, "Unknown/unsupported CodecID (%s) or missing/bad "
"CodecPrivate data (track %u).\n",
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);
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)
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++) {
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;
}
}
@@ -1503,7 +1503,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
goto error;
MP_VERBOSE(demuxer, "track with MS compat audio.\n");
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)
track->a_channels = AV_RL16(h + 2); // nChannels
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_len = track->private_size - 18;
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")) {
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")) {
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")) {
- 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)) {
if (track->private_size < RAPROPERTIES4_SIZE)
goto error;
@@ -1563,29 +1563,29 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
extradata = src + offset;
if (!strcmp(track->codec_id, "A_REAL/ATRC")) {
- sh->codec = "atrac3";
+ sh_a->codec = "atrac3";
if (flavor >= MP_ARRAY_SIZE(atrc_fl2bps))
goto error;
sh_a->bitrate = atrc_fl2bps[flavor] * 8;
sh_a->block_align = track->sub_packet_size;
} else if (!strcmp(track->codec_id, "A_REAL/COOK")) {
- sh->codec = "cook";
+ sh_a->codec = "cook";
if (flavor >= MP_ARRAY_SIZE(cook_fl2bps))
goto error;
sh_a->bitrate = cook_fl2bps[flavor] * 8;
sh_a->block_align = track->sub_packet_size;
} else if (!strcmp(track->codec_id, "A_REAL/SIPR")) {
- sh->codec = "sipr";
+ sh_a->codec = "sipr";
if (flavor >= MP_ARRAY_SIZE(sipr_fl2bps))
goto error;
sh_a->bitrate = sipr_fl2bps[flavor] * 8;
sh_a->block_align = track->coded_framesize;
} 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->block_align = track->coded_framesize;
} else if (!strcmp(track->codec_id, "A_REAL/DNET")) {
- sh->codec = "ac3";
+ sh_a->codec = "ac3";
} else {
goto error;
}
@@ -1595,7 +1595,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
track->audio_timestamp =
talloc_array(track, double, track->sub_packet_h);
} 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) */
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;
}
} 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)) {
- sh->codec = "eac3";
+ sh_a->codec = "eac3";
}
- if (!sh->codec)
+ if (!sh_a->codec)
goto error;
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")) {
track->parse = true;
} 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)
track->default_duration = 0;
- sh->extradata = extradata;
- sh->extradata_size = extradata_len;
+ sh_a->extradata = extradata;
+ sh_a->extradata_size = extradata_len;
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);
init_track(demuxer, track, sh);
- sh->codec = subtitle_type;
+ sh->codec->codec = subtitle_type;
bstr in = (bstr){track->private_data, track->private_size};
bstr buffer = demux_mkv_decode(demuxer->log, track, in, 2);
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_size = buffer.len;
}
- sh->extradata = track->private_data;
- sh->extradata_size = track->private_size;
+ sh->codec->extradata = track->private_data;
+ sh->codec->extradata_size = track->private_size;
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)
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")) {
for (int x = 0; x < sph / 2; x++) {
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) {
track->sub_packet_cnt = 0;
// 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)
goto error;
// 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))
return;
- if (stream->codec && strcmp(stream->codec, "wavpack") == 0) {
+ if (strcmp(stream->codec->codec, "wavpack") == 0) {
int size = dp->len;
uint8_t *parsed;
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;
struct demux_packet *new = new_demux_packet(newlen);
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) {
- 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);
track->av_parser = av_parser_init(id);
if (codec)
@@ -2447,7 +2447,7 @@ static int handle_block(demuxer_t *demuxer, struct block_info *block_info)
* packets resulting from parsing. */
if (i == 0 || 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);
if (i == 0)
dp->duration = block_duration / 1e9;
diff --git a/demux/demux_mkv_timeline.c b/demux/demux_mkv_timeline.c
index 9212f6b39d..681f0b0760 100644
--- a/demux/demux_mkv_timeline.c
+++ b/demux/demux_mkv_timeline.c
@@ -485,7 +485,7 @@ static void check_track_compatibility(struct timeline *tl)
if (s) {
// There are actually many more things that in theory have to
// 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");
} else {
MP_WARN(tl, "Source %s lacks %s stream with TID=%d, which "
diff --git a/demux/demux_raw.c b/demux/demux_raw.c
index 5e492334ae..7fd9fdefa2 100644
--- a/demux/demux_raw.c
+++ b/demux/demux_raw.c
@@ -131,14 +131,14 @@ static int demux_rawaudio_open(demuxer_t *demuxer, enum demux_check check)
return -1;
struct sh_stream *sh = demux_alloc_sh_stream(STREAM_AUDIO);
- struct sh_audio *sh_audio = sh->audio;
- sh_audio->channels = opts->channels;
- sh_audio->force_channels = true;
- sh_audio->samplerate = opts->samplerate;
+ struct mp_codec_params *c = sh->codec;
+ c->channels = opts->channels;
+ c->force_channels = true;
+ c->samplerate = opts->samplerate;
int f = opts->aformat;
- // See PCM(): sign float bits endian
- mp_set_pcm_codec(sh, f & 1, f & 2, f >> 3, f & 4);
+ // See PCM(): sign float bits endian
+ mp_set_pcm_codec(sh->codec, f & 1, f & 2, f >> 3, f & 4);
int samplesize = ((f >> 3) + 7) / 8;
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;
*p = (struct priv) {
.sh = sh,
- .frame_size = samplesize * sh_audio->channels.num,
- .frame_rate = sh_audio->samplerate,
- .read_frames = sh_audio->samplerate / 8,
+ .frame_size = samplesize * c->channels.num,
+ .frame_rate = c->samplerate,
+ .read_frames = c->samplerate / 8,
};
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_video *sh_video = sh->video;
- sh->codec = decoder;
- sh->codec_tag = imgfmt;
- sh_video->fps = opts->fps;
- sh_video->disp_w = width;
- sh_video->disp_h = height;
+ struct mp_codec_params *c = sh->codec;
+ c->codec = decoder;
+ c->codec_tag = imgfmt;
+ c->fps = opts->fps;
+ c->disp_w = width;
+ c->disp_h = height;
demux_add_sh_stream(demuxer, sh);
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) {
.sh = sh,
.frame_size = imgsize,
- .frame_rate = sh_video->fps,
+ .frame_rate = c->fps,
.read_frames = 1,
};
diff --git a/demux/demux_tv.c b/demux/demux_tv.c
index a2d06591e0..4f1e3ac1c2 100644
--- a/demux/demux_tv.c
+++ b/demux/demux_tv.c
@@ -20,8 +20,6 @@
static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
{
tvi_handle_t *tvh;
- sh_video_t *sh_video;
- sh_audio_t *sh_audio = NULL;
const tvi_functions_t *funcs;
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;
struct sh_stream *sh_v = demux_alloc_sh_stream(STREAM_VIDEO);
- sh_video = sh_v->video;
/* get IMAGE FORMAT */
int fourcc;
funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FORMAT, &fourcc);
if (fourcc == MP_FOURCC_MJPEG) {
- sh_v->codec = "mjpeg";
+ sh_v->codec->codec = "mjpeg";
} else {
- sh_v->codec = "rawvideo";
- sh_v->codec_tag = fourcc;
+ sh_v->codec->codec = "rawvideo";
+ sh_v->codec->codec_tag = fourcc;
}
/* set FPS and FRAMETIME */
- if(!sh_video->fps)
+ if(!sh_v->codec->fps)
{
float tmp;
if (funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FPS, &tmp) != TVI_CONTROL_TRUE)
- sh_video->fps = 25.0f; /* on PAL */
- else sh_video->fps = tmp;
+ sh_v->codec->fps = 25.0f; /* on PAL */
+ else sh_v->codec->fps = tmp;
}
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(tvh->tv_param->immediate == 1)
@@ -84,10 +81,10 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
}
/* 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 */
- 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);
@@ -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);
- sh_audio = sh_a->audio;
funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_SAMPLERATE,
- &sh_audio->samplerate);
- int nchannels = sh_audio->channels.num;
+ &sh_a->codec->samplerate);
+ int nchannels = sh_a->codec->channels.num;
funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_CHANNELS,
&nchannels);
- mp_chmap_from_channels(&sh_audio->channels, nchannels);
+ mp_chmap_from_channels(&sh_a->codec->channels, nchannels);
// 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);
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:
diff --git a/demux/stheader.h b/demux/stheader.h
index c243eb921e..35be20885a 100644
--- a/demux/stheader.h
+++ b/demux/stheader.h
@@ -37,23 +37,8 @@ struct sh_stream {
int demuxer_id;
// FFmpeg stream index (AVFormatContext.streams[index]), or equivalent.
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)
- 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;
+ struct mp_codec_params *codec;
char *title;
char *lang; // language code
@@ -70,29 +55,43 @@ struct sh_stream {
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;
struct mp_chmap channels;
bool force_channels;
int bitrate; // compressed bits/sec
int block_align;
- int bits_per_coded_sample;
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
float fps; // frames per second (set only if constant fps)
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 rotate; // intended display rotation, in degrees, [0, 359]
int stereo_mode; // mp_stereo3d_mode (0 if none/unknown)
-} sh_video_t;
-typedef struct sh_sub {
- double frame_based; // timestamps are frame-based (and this is the
- // fallback framerate used for timestamps)
-} sh_sub_t;
+ // STREAM_VIDEO + STREAM_AUDIO
+ int bits_per_coded_sample;
+
+ // STREAM_SUB
+ double frame_based; // timestamps are frame-based (and this is the
+ // fallback framerate used for timestamps)
+};
#endif /* MPLAYER_STHEADER_H */
diff --git a/player/audio.c b/player/audio.c
index 8cbdb5aefa..0655dda51e 100644
--- a/player/audio.c
+++ b/player/audio.c
@@ -218,7 +218,7 @@ void reinit_audio_chain(struct MPContext *mpctx)
mpctx->d_audio->header = sh;
mpctx->d_audio->pool = mp_audio_pool_create(mpctx->d_audio);
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->ao_buffer = mp_audio_buffer_create(NULL);
if (!audio_init_best_codec(mpctx->d_audio))
diff --git a/player/command.c b/player/command.c
index 135d092d8b..0bee671e88 100644
--- a/player/command.c
+++ b/player/command.c
@@ -1713,7 +1713,7 @@ static int mp_property_audio_codec_name(void *ctx, struct m_property *prop,
int action, void *arg)
{
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);
}
@@ -1930,8 +1930,7 @@ static int property_switch_track_ff(void *ctx, struct m_property *prop,
static int track_channels(struct track *track)
{
- return track->stream && track->stream->audio
- ? track->stream->audio->channels.num : 0;
+ return track->stream ? track->stream->codec->channels.num : 0;
}
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 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[] = {
{"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)
{
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);
}
@@ -2512,15 +2511,15 @@ static int mp_property_vd_imgparams(void *ctx, struct m_property *prop,
struct dec_video *vd = mpctx->d_video;
if (!vd)
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) {
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"
// before the first frame is decoded.
struct m_sub_property props[] = {
- {"w", SUB_PROP_INT(sh->disp_w)},
- {"h", SUB_PROP_INT(sh->disp_h)},
+ {"w", SUB_PROP_INT(c->disp_w)},
+ {"h", SUB_PROP_INT(c->disp_h)},
{0}
};
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;
if (mpctx->d_video && aspect <= 0) {
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;
if (params && params->p_w > 0 && params->p_h > 0) {
int d_w, d_h;
mp_image_params_get_dsize(params, &d_w, &d_h);
aspect = (float)d_w / d_h;
- } else if (sh_video->disp_w && sh_video->disp_h) {
- aspect = (float)sh_video->disp_w / sh_video->disp_h;
+ } else if (c->disp_w && c->disp_h) {
+ aspect = (float)c->disp_w / c->disp_h;
}
}
*(float *)arg = aspect;
diff --git a/player/loadfile.c b/player/loadfile.c
index b28b9f3cc4..cdf3d5b0f8 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -134,7 +134,7 @@ static void print_stream(struct MPContext *mpctx, struct track *t)
APPEND(b, " [P]");
if (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>");
if (t->is_external)
APPEND(b, " (external)");
diff --git a/player/sub.c b/player/sub.c
index 5f2f13e88f..0492be4bc8 100644
--- a/player/sub.c
+++ b/player/sub.c
@@ -118,9 +118,9 @@ static bool init_subdec(struct MPContext *mpctx, struct track *track)
if (!track->dec_sub)
return false;
- struct sh_video *sh_video =
- mpctx->d_video ? mpctx->d_video->header->video : NULL;
- double fps = sh_video ? sh_video->fps : 25;
+ struct mp_codec_params *v_c =
+ mpctx->d_video ? mpctx->d_video->header->codec : NULL;
+ double fps = v_c ? v_c->fps : 25;
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
diff --git a/player/video.c b/player/video.c
index 7f1ab4dc21..d54f048038 100644
--- a/player/video.c
+++ b/player/video.c
@@ -277,10 +277,10 @@ int reinit_video_chain(struct MPContext *mpctx)
d_video->log = mp_log_new(d_video, mpctx->log, "!vd");
d_video->opts = mpctx->opts;
d_video->header = sh;
- d_video->fps = sh->video->fps;
+ d_video->fps = sh->codec->fps;
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) {
d_video->fps = opts->force_fps;
diff --git a/sub/dec_sub.c b/sub/dec_sub.c
index c0c98c42cc..561f8b8be8 100644
--- a/sub/dec_sub.c
+++ b/sub/dec_sub.c
@@ -81,7 +81,7 @@ void sub_destroy(struct dec_sub *sub)
struct dec_sub *sub_create(struct mpv_global *global, struct demuxer *demuxer,
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");
@@ -101,7 +101,7 @@ struct dec_sub *sub_create(struct mpv_global *global, struct demuxer *demuxer,
.opts = sub->opts,
.driver = driver,
.demuxer = demuxer,
- .sh = sh,
+ .codec = sh->codec,
};
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",
- sh->codec ? sh->codec : "<unknown>");
+ sh->codec->codec);
talloc_free(log);
return NULL;
}
diff --git a/sub/sd.h b/sub/sd.h
index 5945b00483..b142654ed1 100644
--- a/sub/sd.h
+++ b/sub/sd.h
@@ -18,7 +18,7 @@ struct sd {
void *priv;
struct demuxer *demuxer;
- struct sh_stream *sh;
+ struct mp_codec_params *codec;
};
struct sd_functions {
diff --git a/sub/sd_ass.c b/sub/sd_ass.c
index 658e952c28..2358ba45f6 100644
--- a/sub/sd_ass.c
+++ b/sub/sd_ass.c
@@ -165,12 +165,12 @@ static int init(struct sd *sd)
struct sd_ass_priv *ctx = talloc_zero(sd, struct sd_ass_priv);
sd->priv = ctx;
- char *extradata = sd->sh->extradata;
- int extradata_size = sd->sh->extradata_size;
+ char *extradata = sd->codec->extradata;
+ 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->converter = lavc_conv_create(sd->log, sd->sh->codec, extradata,
+ ctx->converter = lavc_conv_create(sd->log, sd->codec->codec, extradata,
extradata_size);
if (!ctx->converter)
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);
#endif
- ctx->frame_fps = sd->sh->sub->frame_based;
+ ctx->frame_fps = sd->codec->frame_based;
update_subtitle_speed(sd);
enable_output(sd, true);
diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c
index ae08026d9a..2da69e937e 100644
--- a/sub/sd_lavc.c
+++ b/sub/sd_lavc.c
@@ -95,7 +95,7 @@ static void get_resolution(struct sd *sd, int wh[2])
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
switch (cid) {
@@ -116,7 +116,7 @@ static int init(struct sd *sd)
ctx = avcodec_alloc_context3(sub_codec);
if (!ctx)
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)
goto error;
priv->avctx = ctx;
diff --git a/video/decode/dec_video.c b/video/decode/dec_video.c
index 9409ce146f..821aa2bda4 100644
--- a/video/decode/dec_video.c
+++ b/video/decode/dec_video.c
@@ -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_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);
@@ -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);
} else {
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) {
@@ -242,7 +242,7 @@ struct mp_image *video_decode(struct dec_video *d_video,
int drop_frame)
{
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;
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_dts = d_video->codec_dts;
- if (d_video->header->video->avi_dts)
+ if (d_video->header->codec->avi_dts)
drop_frame = 0;
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 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
// 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;
}
- 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");
- p.p_w = sh->par_w;
- p.p_h = sh->par_h;
+ p.p_w = c->par_w;
+ p.p_h = c->par_h;
}
if (opts->movie_aspect >= 0) {
diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c
index 614ec787ec..f47e72a1cd 100644
--- a/video/decode/vd_lavc.c
+++ b/video/decode/vd_lavc.c
@@ -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;
bool mp_rawvideo = false;
struct sh_stream *sh = vd->header;
+ struct mp_codec_params *c = sh->codec;
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
ctx->skip_frame = avctx->skip_frame;
- avctx->codec_tag = sh->codec_tag;
- avctx->coded_width = sh->video->disp_w;
- avctx->coded_height = sh->video->disp_h;
- avctx->bits_per_coded_sample = sh->video->bits_per_coded_sample;
+ avctx->codec_tag = c->codec_tag;
+ avctx->coded_width = c->disp_w;
+ avctx->coded_height = c->disp_h;
+ 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) {
- avctx->pix_fmt = imgfmt2pixfmt(sh->codec_tag);
+ avctx->pix_fmt = imgfmt2pixfmt(c->codec_tag);
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_imgfmt_to_name(sh->codec_tag));
+ mp_imgfmt_to_name(c->codec_tag));
}
- if (sh->lav_headers)
- mp_copy_lav_codec_headers(avctx, sh->lav_headers);
+ if (c->lav_headers)
+ mp_copy_lav_codec_headers(avctx, c->lav_headers);
/* open it */
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),
.chroma_location =
avchroma_location_to_mp(ctx->avctx->chroma_sample_location),
- .rotate = vd->header->video->rotate,
- .stereo_in = vd->header->video->stereo_mode,
+ .rotate = vd->header->codec->rotate,
+ .stereo_in = vd->header->codec->stereo_mode,
};
if (opts->video_rotate < 0) {