summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
Diffstat (limited to 'demux')
-rw-r--r--demux/demux.c14
-rw-r--r--demux/demux_lavf.c90
-rw-r--r--demux/mp_taglists.c158
-rw-r--r--demux/mp_taglists.h28
-rw-r--r--demux/stheader.h5
5 files changed, 26 insertions, 269 deletions
diff --git a/demux/demux.c b/demux/demux.c
index 2ebd79b863..848828acb2 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -339,6 +339,14 @@ static struct sh_stream *new_sh_stream(demuxer_t *demuxer,
return sh;
}
+static void free_sh_stream(struct sh_stream *sh)
+{
+ if (sh->lav_headers) {
+ avcodec_close(sh->lav_headers);
+ av_free(sh->lav_headers);
+ }
+}
+
sh_sub_t *new_sh_sub_sid(demuxer_t *demuxer, int id, int sid)
{
if (id > MAX_S_STREAMS - 1 || id < 0) {
@@ -372,7 +380,7 @@ static void free_sh_sub(sh_sub_t *sh)
mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_sub at %p\n", sh);
free(sh->extradata);
clear_parser((sh_common_t *)sh);
- talloc_free(sh);
+ free_sh_stream(sh->gsh);
}
sh_audio_t *new_sh_audio_aid(demuxer_t *demuxer, int id, int aid)
@@ -401,7 +409,7 @@ static void free_sh_audio(demuxer_t *demuxer, int id)
free(sh->wf);
free(sh->codecdata);
clear_parser((sh_common_t *)sh);
- talloc_free(sh);
+ free_sh_stream(sh->gsh);
}
sh_video_t *new_sh_video_vid(demuxer_t *demuxer, int id, int vid)
@@ -427,7 +435,7 @@ static void free_sh_video(sh_video_t *sh)
mp_msg(MSGT_DEMUXER, MSGL_DBG2, "DEMUXER: freeing sh_video at %p\n", sh);
free(sh->bih);
clear_parser((sh_common_t *)sh);
- talloc_free(sh);
+ free_sh_stream(sh->gsh);
}
void free_demuxer(demuxer_t *demuxer)
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index 7ae063777a..ca81a45f84 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -46,8 +46,6 @@
#include "stheader.h"
#include "core/m_option.h"
-#include "mp_taglists.h"
-
#define INITIAL_PROBE_SIZE STREAM_BUFFER_SIZE
#define PROBE_BUF_SIZE (2 * 1024 * 1024)
@@ -329,100 +327,36 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
AVStream *st = avfc->streams[i];
AVCodecContext *codec = st->codec;
struct sh_stream *sh = NULL;
- // Work around collisions resulting from the hacks changing codec_tag.
- int lavf_codec_tag = codec->codec_tag;
- // Don't use native MPEG codec tag values with our generic tag tables.
- // May contain for example value 3 for MP3, which we'd map to PCM audio.
- if (matches_avinputformat_name(priv, "mpeg") ||
- matches_avinputformat_name(priv, "mpegts"))
- codec->codec_tag = 0;
- int override_tag = mp_taglist_override(codec->codec_id);
- // For some formats (like PCM) always trust CODEC_ID_* more than codec_tag
- if (override_tag)
- codec->codec_tag = override_tag;
-
- const char *mp_codec = mp_codec_from_av_codec_id(codec->codec_id);
switch (codec->codec_type) {
case AVMEDIA_TYPE_AUDIO: {
- WAVEFORMATEX *wf;
- sh_audio_t *sh_audio;
- sh_audio = new_sh_audio_aid(demuxer, i, priv->audio_streams);
+ sh_audio_t *sh_audio = new_sh_audio_aid(demuxer, i, priv->audio_streams);
if (!sh_audio)
break;
sh = sh_audio->gsh;
priv->astreams[priv->audio_streams] = i;
- wf = calloc(sizeof(*wf) + codec->extradata_size, 1);
- // mp4a tag is used for all mp4 files no matter what they actually contain
- if (codec->codec_tag == MKTAG('m', 'p', '4', 'a'))
- codec->codec_tag = 0;
- if (!codec->codec_tag)
- codec->codec_tag = mp_taglist_audio(codec->codec_id);
- if (!codec->codec_tag)
- codec->codec_tag = -1;
- wf->wFormatTag = codec->codec_tag;
- wf->nChannels = codec->channels;
- wf->nSamplesPerSec = codec->sample_rate;
- wf->nAvgBytesPerSec = codec->bit_rate / 8;
- wf->nBlockAlign = codec->block_align;
- wf->wBitsPerSample = codec->bits_per_coded_sample;
- wf->cbSize = codec->extradata_size;
- if (codec->extradata_size)
- memcpy(wf + 1, codec->extradata, codec->extradata_size);
- sh_audio->wf = wf;
sh_audio->ds = demuxer->audio;
sh_audio->format = codec->codec_tag;
+
+ // probably unneeded
sh_audio->channels = codec->channels;
sh_audio->samplerate = codec->sample_rate;
sh_audio->i_bps = codec->bit_rate / 8;
- switch (codec->codec_id) {
- case CODEC_ID_PCM_ALAW:
- sh_audio->format = 0x6;
- break;
- case CODEC_ID_PCM_MULAW:
- sh_audio->format = 0x7;
- break;
- }
+
st->discard = AVDISCARD_ALL;
priv->audio_streams++;
break;
}
case AVMEDIA_TYPE_VIDEO: {
- sh_video_t *sh_video;
- BITMAPINFOHEADER *bih;
- sh_video = new_sh_video_vid(demuxer, i, priv->video_streams);
+ sh_video_t *sh_video = new_sh_video_vid(demuxer, i, priv->video_streams);
if (!sh_video)
break;
sh = sh_video->gsh;
priv->vstreams[priv->video_streams] = i;
if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
sh_video->gsh->attached_picture = true;
- bih = calloc(sizeof(*bih) + codec->extradata_size, 1);
-
- if (codec->codec_id == CODEC_ID_RAWVIDEO) {
- switch (codec->pix_fmt) {
- case PIX_FMT_RGB24:
- codec->codec_tag = MKTAG(24, 'B', 'G', 'R');
- case PIX_FMT_BGR24:
- codec->codec_tag = MKTAG(24, 'R', 'G', 'B');
- }
- if (!codec->codec_tag)
- codec->codec_tag = avcodec_pix_fmt_to_codec_tag(codec->pix_fmt);
- } else if (!codec->codec_tag) {
- codec->codec_tag = mp_taglist_video(codec->codec_id);
- /* 0 might mean either unset or rawvideo; if codec_id
- * was not RAWVIDEO assume it's unset
- */
- if (!codec->codec_tag)
- codec->codec_tag = -1;
- }
- bih->biSize = sizeof(*bih) + codec->extradata_size;
- bih->biWidth = codec->width;
- bih->biHeight = codec->height;
- bih->biBitCount = codec->bits_per_coded_sample;
- bih->biSizeImage = bih->biWidth * bih->biHeight * bih->biBitCount / 8;
- bih->biCompression = codec->codec_tag;
- sh_video->bih = bih;
+
+ sh_video->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.
@@ -441,7 +375,6 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
st->codec->ticks_per_frame);
sh_video->fps = fps;
sh_video->frametime = 1 / fps;
- sh_video->format = bih->biCompression;
if (st->sample_aspect_ratio.num)
sh_video->aspect = codec->width * st->sample_aspect_ratio.num
/ (float)(codec->height * st->sample_aspect_ratio.den);
@@ -455,8 +388,6 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
codec->height, codec->sample_aspect_ratio.den);
sh_video->ds = demuxer->video;
- if (codec->extradata_size)
- memcpy(sh_video->bih + 1, codec->extradata, codec->extradata_size);
if (demuxer->video->id != priv->video_streams
&& demuxer->video->id != -1)
st->discard = AVDISCARD_ALL;
@@ -518,8 +449,11 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
st->discard = AVDISCARD_ALL;
}
if (sh) {
- sh->codec = mp_codec;
- sh->lavf_codec_tag = lavf_codec_tag;
+ sh->codec = mp_codec_from_av_codec_id(codec->codec_id);
+ sh->lav_headers = avcodec_alloc_context3(codec->codec);
+ assert(sh->lav_headers);
+ avcodec_copy_context(sh->lav_headers, codec);
+
if (st->disposition & AV_DISPOSITION_DEFAULT)
sh->default_track = 1;
if (matches_avinputformat_name(priv, "mpeg"))
diff --git a/demux/mp_taglists.c b/demux/mp_taglists.c
deleted file mode 100644
index 2b3968dcf9..0000000000
--- a/demux/mp_taglists.c
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <libavformat/avformat.h>
-
-#include "config.h"
-#include "mp_taglists.h"
-
-struct tag {
- enum CodecID id;
- unsigned int tag;
-};
-
-static const struct tag mp_wav_tags[] = {
- { CODEC_ID_ADPCM_4XM, MKTAG('4', 'X', 'M', 'A')},
- { CODEC_ID_ADPCM_ADX, MKTAG('S', 'a', 'd', 'x')},
- { CODEC_ID_ADPCM_EA, MKTAG('A', 'D', 'E', 'A')},
- { CODEC_ID_ADPCM_EA_MAXIS_XA, MKTAG('A', 'D', 'X', 'A')},
- { CODEC_ID_ADPCM_IMA_WS, MKTAG('A', 'I', 'W', 'S')},
- { CODEC_ID_ADPCM_THP, MKTAG('T', 'H', 'P', 'A')},
- { CODEC_ID_ADPCM_XA, MKTAG('P', 'S', 'X', 'A')},
- { CODEC_ID_AMR_NB, MKTAG('n', 'b', 0, 0)},
- { CODEC_ID_COOK, MKTAG('c', 'o', 'o', 'k')},
- { CODEC_ID_DSICINAUDIO, MKTAG('D', 'C', 'I', 'A')},
- { CODEC_ID_EAC3, MKTAG('E', 'A', 'C', '3')},
- { CODEC_ID_INTERPLAY_DPCM, MKTAG('I', 'N', 'P', 'A')},
- { CODEC_ID_MLP, MKTAG('M', 'L', 'P', ' ')},
- { CODEC_ID_MP1, 0x50},
- { CODEC_ID_MP4ALS, MKTAG('A', 'L', 'S', ' ')},
- { CODEC_ID_MUSEPACK7, MKTAG('M', 'P', 'C', ' ')},
- { CODEC_ID_MUSEPACK8, MKTAG('M', 'P', 'C', '8')},
- { CODEC_ID_NELLYMOSER, MKTAG('N', 'E', 'L', 'L')},
- { CODEC_ID_PCM_LXF, MKTAG('P', 'L', 'X', 'F')},
- { CODEC_ID_QCELP, MKTAG('Q', 'c', 'l', 'p')},
- { CODEC_ID_QDM2, MKTAG('Q', 'D', 'M', '2')},
- { CODEC_ID_RA_144, MKTAG('1', '4', '_', '4')},
- { CODEC_ID_RA_288, MKTAG('2', '8', '_', '8')},
- { CODEC_ID_ROQ_DPCM, MKTAG('R', 'o', 'Q', 'A')},
- { CODEC_ID_SHORTEN, MKTAG('s', 'h', 'r', 'n')},
- { CODEC_ID_SPEEX, MKTAG('s', 'p', 'x', ' ')},
- { CODEC_ID_TTA, MKTAG('T', 'T', 'A', '1')},
- { CODEC_ID_TWINVQ, MKTAG('T', 'W', 'I', '2')},
- { CODEC_ID_WAVPACK, MKTAG('W', 'V', 'P', 'K')},
- { CODEC_ID_WESTWOOD_SND1, MKTAG('S', 'N', 'D', '1')},
- { CODEC_ID_XAN_DPCM, MKTAG('A', 'x', 'a', 'n')},
- { 0, 0 },
-};
-
-static const struct tag mp_codecid_override_tags[] = {
- { CODEC_ID_AAC, MKTAG('M', 'P', '4', 'A')},
- { CODEC_ID_AAC_LATM, MKTAG('M', 'P', '4', 'L')},
- { CODEC_ID_AC3, 0x2000},
- { CODEC_ID_ADPCM_IMA_AMV, MKTAG('A', 'M', 'V', 'A')},
- { CODEC_ID_BINKAUDIO_DCT, MKTAG('B', 'A', 'U', '1')},
- { CODEC_ID_BINKAUDIO_RDFT, MKTAG('B', 'A', 'U', '2')},
- { CODEC_ID_DTS, 0x2001},
- { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'd')},
- { CODEC_ID_EAC3, MKTAG('E', 'A', 'C', '3')},
- { CODEC_ID_H264, MKTAG('H', '2', '6', '4')},
- { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'V')},
- { CODEC_ID_PCM_S8, -1},
- { CODEC_ID_PCM_U8, -1},
- { CODEC_ID_PCM_S16BE, -1},
- { CODEC_ID_PCM_S16LE, -1},
- { CODEC_ID_PCM_S24BE, -1},
- { CODEC_ID_PCM_S24LE, -1},
- { CODEC_ID_PCM_S32BE, -1},
- { CODEC_ID_PCM_S32LE, -1},
- { CODEC_ID_PCM_BLURAY, MKTAG('B', 'P', 'C', 'M')},
- { CODEC_ID_MP2, 0x50},
- { CODEC_ID_MPEG2VIDEO, MKTAG('M', 'P', 'G', '2')},
- { CODEC_ID_TRUEHD, MKTAG('T', 'R', 'H', 'D')},
- { 0, 0 },
-};
-
-static const struct tag mp_bmp_tags[] = {
- { CODEC_ID_AMV, MKTAG('A', 'M', 'V', 'V')},
- { CODEC_ID_ANM, MKTAG('A', 'N', 'M', ' ')},
- { CODEC_ID_AVS, MKTAG('A', 'V', 'S', ' ')},
- { CODEC_ID_BETHSOFTVID, MKTAG('B', 'E', 'T', 'H')},
- { CODEC_ID_BFI, MKTAG('B', 'F', 'I', 'V')},
- { CODEC_ID_C93, MKTAG('C', '9', '3', 'V')},
- { CODEC_ID_CDGRAPHICS, MKTAG('C', 'D', 'G', 'R')},
- { CODEC_ID_DNXHD, MKTAG('A', 'V', 'd', 'n')},
- { CODEC_ID_DSICINVIDEO, MKTAG('D', 'C', 'I', 'V')},
- { CODEC_ID_DXA, MKTAG('D', 'X', 'A', '1')},
- { CODEC_ID_FLIC, MKTAG('F', 'L', 'I', 'C')},
- { CODEC_ID_IDCIN, MKTAG('I', 'D', 'C', 'I')},
- { CODEC_ID_INTERPLAY_VIDEO, MKTAG('I', 'N', 'P', 'V')},
- { CODEC_ID_JV, MKTAG('F', 'F', 'J', 'V')},
- { CODEC_ID_MDEC, MKTAG('M', 'D', 'E', 'C')},
- { CODEC_ID_MOTIONPIXELS, MKTAG('M', 'V', 'I', '1')},
- { CODEC_ID_NUV, MKTAG('N', 'U', 'V', '1')},
- { CODEC_ID_RL2, MKTAG('R', 'L', '2', 'V')},
- { CODEC_ID_ROQ, MKTAG('R', 'o', 'Q', 'V')},
- { CODEC_ID_RV10, MKTAG('R', 'V', '1', '0')},
- { CODEC_ID_RV20, MKTAG('R', 'V', '2', '0')},
- { CODEC_ID_RV30, MKTAG('R', 'V', '3', '0')},
- { CODEC_ID_RV40, MKTAG('R', 'V', '4', '0')},
- { CODEC_ID_SVQ3, MKTAG('S', 'V', 'Q', '3')},
- { CODEC_ID_TGV, MKTAG('f', 'V', 'G', 'T')},
- { CODEC_ID_THP, MKTAG('T', 'H', 'P', 'V')},
- { CODEC_ID_TIERTEXSEQVIDEO, MKTAG('T', 'S', 'E', 'Q')},
- { CODEC_ID_TXD, MKTAG('T', 'X', 'D', 'V')},
- { CODEC_ID_VP6A, MKTAG('V', 'P', '6', 'A')},
- { CODEC_ID_VMDVIDEO, MKTAG('V', 'M', 'D', 'V')},
- { CODEC_ID_WS_VQA, MKTAG('V', 'Q', 'A', 'V')},
- { CODEC_ID_XAN_WC3, MKTAG('W', 'C', '3', 'V')},
- { 0, 0 },
-};
-
-static unsigned int codec_get_tag(const struct tag *tags, enum CodecID id)
-{
- while (tags->id != CODEC_ID_NONE) {
- if (tags->id == id)
- return tags->tag;
- tags++;
- }
- return 0;
-}
-
-unsigned int mp_taglist_override(enum CodecID id)
-{
- return codec_get_tag(mp_codecid_override_tags, id);
-}
-
-unsigned int mp_taglist_video(enum CodecID id)
-{
- const struct AVCodecTag *tags[] = {avformat_get_riff_video_tags(), NULL };
- unsigned int tag = av_codec_get_tag(tags, id);
- if (tag)
- return tag;
- return codec_get_tag(mp_bmp_tags, id);
-}
-
-unsigned int mp_taglist_audio(enum CodecID id)
-{
- const struct AVCodecTag *tags[] = {avformat_get_riff_audio_tags(), NULL };
- unsigned int tag = av_codec_get_tag(tags, id);
- if (tag)
- return tag;
- return codec_get_tag(mp_wav_tags, id);
-}
diff --git a/demux/mp_taglists.h b/demux/mp_taglists.h
deleted file mode 100644
index d23a982a93..0000000000
--- a/demux/mp_taglists.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * This file is part of MPlayer.
- *
- * MPlayer is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * MPlayer is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with MPlayer; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef MPLAYER_MP_TAGLISTS_H
-#define MPLAYER_MP_TAGLISTS_H
-
-#include <libavcodec/avcodec.h>
-
-unsigned int mp_taglist_override(enum CodecID id);
-unsigned int mp_taglist_video(enum CodecID id);
-unsigned int mp_taglist_audio(enum CodecID id);
-
-#endif /* MPLAYER_MP_TAGLISTS_H */
diff --git a/demux/stheader.h b/demux/stheader.h
index bf9077ea0a..8d1822c99f 100644
--- a/demux/stheader.h
+++ b/demux/stheader.h
@@ -59,8 +59,9 @@ struct sh_stream {
// E.g. "h264" (usually corresponds to AVCodecDescriptor.name)
const char *codec;
- // Work around other hacks.
- int lavf_codec_tag;
+ // Codec specific header data (set by demux_lavf.c)
+ // Other demuxers use sh_audio->wf and sh_video->bih instead.
+ struct AVCodecContext *lav_headers;
char *title;
char *lang; // language code