demux: merge extradata fields

MPlayer traditionally had completely separate sh_ structs for
audio/video/subs, without a good way to share fields. This meant that
fields shared across all these headers had to be duplicated. This commit
deduplicates essentially the last remaining duplicated fields.
This commit is contained in:
wm4 2015-06-21 18:06:14 +02:00
parent c66be698cd
commit be882175d8
8 changed files with 20 additions and 28 deletions

View File

@ -126,11 +126,7 @@ static int init(struct dec_audio *da, const char *decoder)
lavc_context->channel_layout = mp_chmap_to_lavc(&sh_audio->channels);
// demux_mkv
if (sh_audio->codecdata_len && sh_audio->codecdata &&
!lavc_context->extradata) {
mp_lavc_set_extradata(lavc_context, sh_audio->codecdata,
sh_audio->codecdata_len);
}
mp_lavc_set_extradata(lavc_context, sh->extradata, sh->extradata_size);
if (sh->lav_headers)
mp_copy_lav_codec_headers(lavc_context, sh->lav_headers);

View File

@ -112,8 +112,8 @@ static void add_dvd_streams(demuxer_t *demuxer)
}
s = talloc_asprintf_append(s, "\n");
sh->sub->extradata = s;
sh->sub->extradata_len = strlen(s);
sh->extradata = s;
sh->extradata_size = strlen(s);
}
}
}

View File

@ -592,9 +592,9 @@ static void handle_stream(demuxer_t *demuxer, int i)
sh_sub = sh->sub;
if (codec->extradata_size) {
sh_sub->extradata = talloc_size(sh, codec->extradata_size);
memcpy(sh_sub->extradata, codec->extradata, codec->extradata_size);
sh_sub->extradata_len = 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;
}
if (matches_avinputformat_name(priv, "microdvd")) {

View File

@ -95,8 +95,8 @@ static int d_check_file(struct demuxer *demuxer, enum demux_check check)
struct sh_stream *sh = new_sh_stream(demuxer, STREAM_SUB);
sh->codec = "ass";
sh->sub->extradata = cbuf.start;
sh->sub->extradata_len = cbuf.len;
sh->extradata = cbuf.start;
sh->extradata_size = cbuf.len;
demuxer->seekable = true;
demuxer->fully_read = true;

View File

@ -1310,8 +1310,8 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track)
return 1;
}
sh_v->extradata = talloc_memdup(sh_v, extradata, extradata_size);
sh_v->extradata_len = extradata_size;
sh->extradata = talloc_memdup(sh_v, extradata, extradata_size);
sh->extradata_size = extradata_size;
if (!sh->codec) {
MP_WARN(demuxer, "Unknown/unsupported CodecID (%s) or missing/bad "
"CodecPrivate data (track %u).\n",
@ -1574,8 +1574,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_a->codecdata = extradata;
sh_a->codecdata_len = extradata_len;
sh->extradata = extradata;
sh->extradata_size = extradata_len;
return 0;
@ -1629,9 +1629,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_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;
sh->extradata = track->private_data;
sh->extradata_size = track->private_size;
if (track->language && (strcmp(track->language, "und") != 0))
sh->lang = talloc_strdup(sh, track->language);
sh->title = talloc_strdup(sh, track->name);

View File

@ -49,6 +49,9 @@ struct sh_stream {
// 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;
@ -73,8 +76,6 @@ typedef struct sh_audio {
int bitrate; // compressed bits/sec
int block_align;
int bits_per_coded_sample;
unsigned char *codecdata;
int codecdata_len;
struct replaygain_data *replaygain_data;
} sh_audio_t;
@ -83,16 +84,12 @@ typedef struct sh_video {
float fps; // frames per second (set only if constant fps)
float aspect; // aspect ratio stored in the file (for prescaling)
int bits_per_coded_sample;
unsigned char *extradata;
int extradata_len;
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 {
unsigned char *extradata; // extra header data passed from demuxer
int extradata_len;
double frame_based; // timestamps are frame-based (and this is the
// fallback framerate used for timestamps)
bool is_utf8; // if false, subtitle packet charset is unknown

View File

@ -202,8 +202,8 @@ void sub_init_from_sh(struct dec_sub *sub, struct sh_stream *sh)
pthread_mutex_lock(&sub->lock);
if (sh->sub->extradata && !sub->init_sd.extradata)
sub_set_extradata(sub, sh->sub->extradata, sh->sub->extradata_len);
if (sh->extradata && !sub->init_sd.extradata)
sub_set_extradata(sub, sh->extradata, sh->extradata_size);
struct sd init_sd = sub->init_sd;
init_sd.codec = sh->codec;

View File

@ -404,7 +404,7 @@ static void init_avctx(struct dec_video *vd, const char *decoder,
avctx->coded_height = sh->video->disp_h;
avctx->bits_per_coded_sample = sh->video->bits_per_coded_sample;
mp_lavc_set_extradata(avctx, sh->video->extradata, sh->video->extradata_len);
mp_lavc_set_extradata(avctx, sh->extradata, sh->extradata_size);
if (mp_rawvideo) {
avctx->pix_fmt = imgfmt2pixfmt(sh->codec_tag);