1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-25 16:33:02 +00:00

demux: remove gsh field from sh_audio/sh_video/sh_sub

This used to be needed to access the generic stream header from the
specific headers, which in turn was needed because the decoders had
access only to the specific headers. This is not the case anymore, so
this can finally be removed again.

Also move the "format" field from the specific headers to sh_stream.
This commit is contained in:
wm4 2013-11-23 21:37:56 +01:00
parent 639e672bd1
commit 904c73d2d2
12 changed files with 71 additions and 76 deletions

View File

@ -183,16 +183,17 @@ static int init(struct dec_audio *da, const char *decoder)
struct ad_lavc_param *opts = &mpopts->ad_lavc_param;
AVCodecContext *lavc_context;
AVCodec *lavc_codec;
struct sh_audio *sh_audio = da->header->audio;
struct sh_stream *sh = da->header;
struct sh_audio *sh_audio = sh->audio;
struct priv *ctx = talloc_zero(NULL, struct priv);
da->priv = ctx;
if (sh_audio->wf && strcmp(decoder, "pcm") == 0) {
decoder = find_pcm_decoder(tag_map, sh_audio->format,
decoder = find_pcm_decoder(tag_map, sh->format,
sh_audio->wf->wBitsPerSample);
} else if (sh_audio->wf && strcmp(decoder, "mp-pcm") == 0) {
decoder = find_pcm_decoder(af_map, sh_audio->format, 0);
decoder = find_pcm_decoder(af_map, sh->format, 0);
ctx->force_channel_map = true;
}
@ -229,7 +230,7 @@ static int init(struct dec_audio *da, const char *decoder)
}
}
lavc_context->codec_tag = sh_audio->format;
lavc_context->codec_tag = sh->format;
lavc_context->sample_rate = sh_audio->samplerate;
lavc_context->bit_rate = sh_audio->i_bps * 8;
lavc_context->channel_layout = mp_chmap_to_lavc(&sh_audio->channels);
@ -247,8 +248,8 @@ static int init(struct dec_audio *da, const char *decoder)
lavc_context->extradata_size);
}
if (sh_audio->gsh->lav_headers)
mp_copy_lav_codec_headers(lavc_context, sh_audio->gsh->lav_headers);
if (sh->lav_headers)
mp_copy_lav_codec_headers(lavc_context, sh->lav_headers);
/* open it */
if (avcodec_open2(lavc_context, lavc_codec, NULL) < 0) {

View File

@ -357,18 +357,21 @@ static const char *lookup_tag(const struct mp_codec_tag *mp_table,
return id == AV_CODEC_ID_NONE ? NULL : mp_codec_from_av_codec_id(id);
}
void mp_set_video_codec_from_tag(struct sh_video *sh)
void mp_set_codec_from_tag(struct sh_stream *sh)
{
sh->gsh->codec = lookup_tag(mp_video_codec_tags,
avformat_get_riff_video_tags(),
sh->format);
}
void mp_set_audio_codec_from_tag(struct sh_audio *sh)
{
sh->gsh->codec = lookup_tag(mp_audio_codec_tags,
avformat_get_riff_audio_tags(),
sh->format);
switch (sh->type) {
case STREAM_VIDEO:
sh->codec = lookup_tag(mp_video_codec_tags,
avformat_get_riff_video_tags(),
sh->format);
break;
case STREAM_AUDIO:
sh->codec = lookup_tag(mp_audio_codec_tags,
avformat_get_riff_audio_tags(),
sh->format);
break;
default: ;
}
}
uint32_t mp_video_fourcc_alias(uint32_t fourcc)

View File

@ -22,10 +22,8 @@
uint32_t mp_video_fourcc_alias(uint32_t fourcc);
struct sh_video;
struct sh_audio;
struct sh_stream;
void mp_set_audio_codec_from_tag(struct sh_audio *sh);
void mp_set_video_codec_from_tag(struct sh_video *sh);
void mp_set_codec_from_tag(struct sh_stream *sh);
#endif

View File

@ -247,19 +247,16 @@ struct sh_stream *new_sh_stream(demuxer_t *demuxer, enum stream_type type)
switch (sh->type) {
case STREAM_VIDEO: {
struct sh_video *sht = talloc_zero(demuxer, struct sh_video);
sht->gsh = sh;
sh->video = sht;
break;
}
case STREAM_AUDIO: {
struct sh_audio *sht = talloc_zero(demuxer, struct sh_audio);
sht->gsh = sh;
sh->audio = sht;
break;
}
case STREAM_SUB: {
struct sh_sub *sht = talloc_zero(demuxer, struct sh_sub);
sht->gsh = sh;
sh->sub = sht;
break;
}

View File

@ -394,7 +394,7 @@ static void handle_stream(demuxer_t *demuxer, int i)
break;
sh_audio_t *sh_audio = sh->audio;
sh_audio->format = codec->codec_tag;
sh->format = codec->codec_tag;
// probably unneeded
mp_chmap_from_channels(&sh_audio->channels, codec->channels);
@ -419,7 +419,7 @@ static void handle_stream(demuxer_t *demuxer, int i)
sh->attached_picture->keyframe = true;
}
sh_video->format = codec->codec_tag;
sh->format = codec->codec_tag;
sh_video->disp_w = codec->width;
sh_video->disp_h = codec->height;
/* Try to make up some frame rate value, even if it's not reliable.

View File

@ -196,7 +196,7 @@ static int demux_open_mf(demuxer_t *demuxer, enum demux_check check)
struct sh_stream *sh = new_sh_stream(demuxer, STREAM_VIDEO);
sh_video = sh->video;
sh_video->gsh->codec = codec;
sh->codec = codec;
sh_video->disp_w = 0;
sh_video->disp_h = 0;
sh_video->fps = mf_fps;

View File

@ -1301,8 +1301,8 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track)
return 1;
track->stream = sh;
sh_v = sh->video;
sh_v->gsh->demuxer_id = track->tnum;
sh_v->gsh->title = talloc_strdup(sh_v, track->name);
sh->demuxer_id = track->tnum;
sh->title = talloc_strdup(sh_v, track->name);
sh_v->bih = talloc_size(sh_v, sizeof(MP_BITMAPINFOHEADER) + extradata_size);
if (!sh_v->bih) {
mp_msg(MSGT_DEMUX, MSGL_FATAL, "Memory allocation failure!\n");
@ -1311,12 +1311,12 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track)
*sh_v->bih = *bih;
if (extradata_size)
memcpy(sh_v->bih + 1, extradata, extradata_size);
sh_v->format = sh_v->bih->biCompression;
sh->format = sh_v->bih->biCompression;
if (raw) {
sh_v->gsh->codec = "rawvideo";
sh->codec = "rawvideo";
} else {
mp_set_video_codec_from_tag(sh_v);
sh_v->format = mp_video_fourcc_alias(sh_v->format);
mp_set_codec_from_tag(sh);
sh->format = mp_video_fourcc_alias(sh->format);
}
if (track->v_frate == 0.0)
track->v_frate = 25.0;
@ -1398,10 +1398,10 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
sh_audio_t *sh_a = sh->audio;
if (track->language && (strcmp(track->language, "und") != 0))
sh_a->gsh->lang = talloc_strdup(sh_a, track->language);
sh_a->gsh->demuxer_id = track->tnum;
sh_a->gsh->title = talloc_strdup(sh_a, track->name);
sh_a->gsh->default_track = track->default_track;
sh->lang = talloc_strdup(sh_a, track->language);
sh->demuxer_id = track->tnum;
sh->title = talloc_strdup(sh_a, track->name);
sh->default_track = track->default_track;
if (!track->a_osfreq)
track->a_osfreq = track->a_sfreq;
if (track->ms_compat) {
@ -1444,7 +1444,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
}
}
sh_a->format = track->a_formattag;
sh->format = track->a_formattag;
sh_a->wf->wFormatTag = track->a_formattag;
mp_chmap_from_channels(&sh_a->channels, track->a_channels);
sh_a->wf->nChannels = track->a_channels;
@ -1464,7 +1464,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
sh_a->wf = NULL;
} else if (track->a_formattag == 0x0001) { /* PCM || PCM_BE */
if (!strcmp(track->codec_id, MKV_A_PCM_BE))
sh_a->format = MP_FOURCC('t', 'w', 'o', 's');
sh->format = MP_FOURCC('t', 'w', 'o', 's');
} else if (track->a_formattag == 0x0003) { /* PCM_FLT */
/* ok */
} else if (!strcmp(track->codec_id, MKV_A_QDMC)
@ -1525,7 +1525,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
}
} else if (!strcmp(track->codec_id, MKV_A_OPUS)
|| !strcmp(track->codec_id, MKV_A_OPUS_EXP)) {
sh_a->format = MP_FOURCC('O', 'p', 'u', 's');
sh->format = MP_FOURCC('O', 'p', 'u', 's');
copy_audio_private_data(sh_a, track);
} else if (!strncmp(track->codec_id, MKV_A_REALATRC, 7)) {
if (track->private_size < RAPROPERTIES4_SIZE)
@ -1597,7 +1597,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
ptr = track->private_data;
size = track->private_size;
} else {
sh_a->format = MP_FOURCC('f', 'L', 'a', 'C');
sh->format = MP_FOURCC('f', 'L', 'a', 'C');
ptr = track->private_data + sizeof(*sh_a->wf);
size = track->private_size - sizeof(*sh_a->wf);
}
@ -1647,7 +1647,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track)
if (sh_a->samplerate == 8000 && strcmp(track->codec_id, MKV_A_AC3) == 0)
track->default_duration = 0;
mp_set_audio_codec_from_tag(sh_a);
mp_set_codec_from_tag(sh);
return 0;
@ -1683,14 +1683,14 @@ static int demux_mkv_open_sub(demuxer_t *demuxer, mkv_track_t *track)
}
bstr in = (bstr){track->private_data, track->private_size};
struct sh_stream *gsh = new_sh_stream(demuxer, STREAM_SUB);
if (!gsh)
struct sh_stream *sh = new_sh_stream(demuxer, STREAM_SUB);
if (!sh)
return 1;
track->stream = gsh;
sh_sub_t *sh = gsh->sub;
sh->gsh->demuxer_id = track->tnum;
track->sh_sub = sh;
sh->gsh->codec = subtitle_type;
track->stream = sh;
sh_sub_t *sh_s = sh->sub;
sh->demuxer_id = track->tnum;
track->sh_sub = sh_s;
sh->codec = subtitle_type;
bstr buffer = demux_mkv_decode(track, in, 2);
if (buffer.start && buffer.start != track->private_data) {
talloc_free(track->private_data);
@ -1698,13 +1698,13 @@ 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 = talloc_size(sh, track->private_size);
memcpy(sh->extradata, track->private_data, track->private_size);
sh->extradata_len = track->private_size;
sh_s->extradata = talloc_size(sh, track->private_size);
memcpy(sh_s->extradata, track->private_data, track->private_size);
sh_s->extradata_len = track->private_size;
if (track->language && (strcmp(track->language, "und") != 0))
sh->gsh->lang = talloc_strdup(sh, track->language);
sh->gsh->title = talloc_strdup(sh, track->name);
sh->gsh->default_track = track->default_track;
sh->lang = talloc_strdup(sh, track->language);
sh->title = talloc_strdup(sh, track->name);
sh->default_track = track->default_track;
if (!subtitle_type) {
mp_tmsg(MSGT_DEMUX, MSGL_ERR,

View File

@ -87,8 +87,8 @@ static int demux_rawaudio_open(demuxer_t *demuxer, enum demux_check check)
sh = new_sh_stream(demuxer, STREAM_AUDIO);
sh_audio = sh->audio;
sh_audio->gsh->codec = "mp-pcm";
sh_audio->format = aformat;
sh->codec = "mp-pcm";
sh->format = aformat;
sh_audio->wf = w = talloc_zero(sh, MP_WAVEFORMATEX);
w->wFormatTag = 0;
sh_audio->channels = channels;
@ -175,8 +175,8 @@ static int demux_rawvideo_open(demuxer_t *demuxer, enum demux_check check)
sh = new_sh_stream(demuxer, STREAM_VIDEO);
sh_video = sh->video;
sh_video->gsh->codec = decoder;
sh_video->format = imgfmt;
sh->codec = decoder;
sh->format = imgfmt;
sh_video->fps = fps;
sh_video->disp_w = width;
sh_video->disp_h = height;

View File

@ -52,6 +52,9 @@ struct sh_stream {
// E.g. "h264" (usually corresponds to AVCodecDescriptor.name)
const char *codec;
// Usually a FourCC, exact meaning depends on codec.
unsigned int format;
// Codec specific header data (set by demux_lavf.c)
// Other demuxers use sh_audio->wf and sh_video->bih instead.
struct AVCodecContext *lav_headers;
@ -68,9 +71,6 @@ struct sh_stream {
};
typedef struct sh_audio {
struct sh_stream *gsh;
/* usually a FourCC, exact meaning depends on gsh->codec */
unsigned int format;
int samplerate;
struct mp_chmap channels;
int i_bps; // == bitrate (compressed bytes/sec)
@ -82,9 +82,6 @@ typedef struct sh_audio {
} sh_audio_t;
typedef struct sh_video {
struct sh_stream *gsh;
/* usually a FourCC, exact meaning depends on gsh->codec */
unsigned int format;
float fps; // frames per second (set only if constant fps)
float aspect; // aspect ratio stored in the file (for prescaling)
int i_bps; // == bitrate (compressed bytes/sec)
@ -93,7 +90,6 @@ typedef struct sh_video {
} sh_video_t;
typedef struct sh_sub {
struct sh_stream *gsh;
unsigned char *extradata; // extra header data passed from demuxer
int extradata_len;
int frame_based; // timestamps are frame-based

View File

@ -96,7 +96,7 @@ int reinit_video_chain(struct MPContext *mpctx)
goto no_video;
MP_VERBOSE(mpctx, "[V] fourcc:0x%X size:%dx%d fps:%5.3f\n",
sh->video->format,
sh->format,
sh->video->disp_w, sh->video->disp_h,
sh->video->fps);
if (opts->force_fps)

View File

@ -724,10 +724,10 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
int fourcc;
funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FORMAT, &fourcc);
if (fourcc == MP_FOURCC_MJPEG) {
sh_video->gsh->codec = "mjpeg";
sh_v->codec = "mjpeg";
} else {
sh_video->gsh->codec = "rawvideo";
sh_video->format = fourcc;
sh_v->codec = "rawvideo";
sh_v->format = fourcc;
}
/* set FPS and FRAMETIME */
@ -799,8 +799,8 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
&nchannels);
mp_chmap_from_channels(&sh_audio->channels, nchannels);
sh_audio->gsh->codec = "mp-pcm";
sh_audio->format = audio_format;
sh_a->codec = "mp-pcm";
sh_a->format = audio_format;
int samplesize = af_fmt2bits(audio_format) / 8;
@ -809,7 +809,7 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check)
// emulate WF for win32 codecs:
sh_audio->wf = talloc_zero(sh_audio, MP_WAVEFORMATEX);
sh_audio->wf->wFormatTag = sh_audio->format;
sh_audio->wf->wFormatTag = sh_a->format;
sh_audio->wf->nChannels = sh_audio->channels.num;
sh_audio->wf->wBitsPerSample = samplesize * 8;
sh_audio->wf->nSamplesPerSec = sh_audio->samplerate;

View File

@ -454,16 +454,16 @@ 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->video->format;
avctx->codec_tag = sh->format;
avctx->coded_width = sh->video->disp_w;
avctx->coded_height = sh->video->disp_h;
// demux_mkv
if (sh->video->bih)
set_from_bih(avctx, sh->video->format, sh->video->bih);
set_from_bih(avctx, sh->format, sh->video->bih);
if (mp_rawvideo) {
avctx->pix_fmt = imgfmt2pixfmt(sh->video->format);
avctx->pix_fmt = imgfmt2pixfmt(sh->format);
avctx->codec_tag = 0;
}