summaryrefslogtreecommitdiffstats
path: root/libmpdemux
diff options
context:
space:
mode:
Diffstat (limited to 'libmpdemux')
-rw-r--r--libmpdemux/aviheader.c59
-rw-r--r--libmpdemux/demux_avi.c3
-rw-r--r--libmpdemux/demux_lavf.c26
-rw-r--r--libmpdemux/demux_ts.c64
-rw-r--r--libmpdemux/demuxer.c4
-rw-r--r--libmpdemux/demuxer.h1
-rw-r--r--libmpdemux/ebml.c2
-rw-r--r--libmpdemux/stheader.h3
8 files changed, 59 insertions, 103 deletions
diff --git a/libmpdemux/aviheader.c b/libmpdemux/aviheader.c
index 1b0683339e..0c47386dc5 100644
--- a/libmpdemux/aviheader.c
+++ b/libmpdemux/aviheader.c
@@ -74,9 +74,6 @@ while(1){
char* hdr=NULL;
//
if(stream_eof(demuxer->stream)) break;
- // Imply -forceidx if -saveidx is specified
- if (index_file_save)
- index_mode = 2;
//
if(id==mmioFOURCC('L','I','S','T')){
unsigned len=stream_read_dword_le(demuxer->stream); // list size
@@ -587,44 +584,6 @@ freeout:
}
-/* Read a saved index file */
-if (index_file_load) {
- FILE *fp;
- char magic[7];
- unsigned int i;
-
- if ((fp = fopen(index_file_load, "r")) == NULL) {
- mp_tmsg(MSGT_HEADER,MSGL_ERR, "Can't read index file %s: %s\n", index_file_load, strerror(errno));
- goto gen_index;
- }
- fread(&magic, 6, 1, fp);
- if (strncmp(magic, "MPIDX1", 6)) {
- mp_tmsg(MSGT_HEADER,MSGL_ERR, "%s is not a valid MPlayer index file.\n", index_file_load);
- goto gen_index;
- }
- fread(&priv->idx_size, sizeof(priv->idx_size), 1, fp);
- priv->idx=malloc(priv->idx_size*sizeof(AVIINDEXENTRY));
- if (!priv->idx) {
- mp_tmsg(MSGT_HEADER,MSGL_ERR, "Could not allocate memory for index data from %s.\n", index_file_load);
- priv->idx_size = 0;
- goto gen_index;
- }
-
- for (i=0; i<priv->idx_size;i++) {
- AVIINDEXENTRY *idx;
- idx=&((AVIINDEXENTRY *)priv->idx)[i];
- fread(idx, sizeof(AVIINDEXENTRY), 1, fp);
- if (feof(fp)) {
- mp_tmsg(MSGT_HEADER,MSGL_ERR, "premature end of index file %s\n", index_file_load);
- free(priv->idx);
- priv->idx_size = 0;
- goto gen_index;
- }
- }
- fclose(fp);
- mp_tmsg(MSGT_HEADER,MSGL_INFO, "Loaded index file: %s\n", index_file_load);
-}
-gen_index:
if(index_mode>=2 || (priv->idx_size==0 && index_mode==1)){
int idx_pos = 0;
// build index for file:
@@ -711,23 +670,5 @@ skip_chunk:
mp_tmsg(MSGT_HEADER,MSGL_INFO,"AVI: Generated index table for %d chunks!\n",priv->idx_size);
if( mp_msg_test(MSGT_HEADER,MSGL_DBG2) ) print_index(priv->idx,priv->idx_size,MSGL_DBG2);
- /* Write generated index to a file */
- if (index_file_save) {
- FILE *fp;
- unsigned int i;
-
- if ((fp=fopen(index_file_save, "w")) == NULL) {
- mp_tmsg(MSGT_HEADER,MSGL_ERR, "Couldn't write index file %s: %s\n", index_file_save, strerror(errno));
- return;
- }
- fwrite("MPIDX1", 6, 1, fp);
- fwrite(&priv->idx_size, sizeof(priv->idx_size), 1, fp);
- for (i=0; i<priv->idx_size; i++) {
- AVIINDEXENTRY *idx = &((AVIINDEXENTRY *)priv->idx)[i];
- fwrite(idx, sizeof(AVIINDEXENTRY), 1, fp);
- }
- fclose(fp);
- mp_tmsg(MSGT_HEADER,MSGL_INFO, "Saved index file: %s\n", index_file_save);
- }
}
}
diff --git a/libmpdemux/demux_avi.c b/libmpdemux/demux_avi.c
index 3841cf2736..887494c6cd 100644
--- a/libmpdemux/demux_avi.c
+++ b/libmpdemux/demux_avi.c
@@ -283,7 +283,7 @@ do{
if(ds)
if(ds->packs+1>=MAX_PACKS || ds->bytes+len>=MAX_PACK_BYTES){
// this packet will cause a buffer overflow, switch to -ni mode!!!
- mp_tmsg(MSGT_DEMUX,MSGL_WARN,"\nBadly interleaved AVI file detected - switching to -ni mode...\n");
+ mp_tmsg(MSGT_DEMUX,MSGL_WARN,"\nBadly interleaved AVI file detected - switching to --avi-ni mode...\n");
if(priv->idx_size>0){
// has index
demux->type=DEMUXER_TYPE_AVI_NI;
@@ -432,7 +432,6 @@ do{
// AVI demuxer parameters:
int index_mode=-1; // -1=untouched 0=don't use index 1=use (generate) index
-char *index_file_save = NULL, *index_file_load = NULL;
int force_ni=0; // force non-interleaved AVI parsing
static demuxer_t* demux_open_avi(demuxer_t* demuxer){
diff --git a/libmpdemux/demux_lavf.c b/libmpdemux/demux_lavf.c
index 5802f1068a..dadf81e146 100644
--- a/libmpdemux/demux_lavf.c
+++ b/libmpdemux/demux_lavf.c
@@ -200,7 +200,8 @@ static int lavf_check_file(demuxer_t *demuxer)
mp_msg(MSGT_DEMUX, MSGL_WARN, "Stream url is not set!\n");
avpd.filename = "";
}
- if (!strncmp(avpd.filename, "ffmpeg://", 9))
+ if (!strncmp(avpd.filename, "ffmpeg://", 9) ||
+ !strncmp(avpd.filename, "lavf://", 7))
avpd.filename += 9;
avpd.buf_size = probe_data_size;
@@ -291,6 +292,8 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
int stream_id;
AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0);
AVDictionaryEntry *title = av_dict_get(st->metadata, "title", NULL, 0);
+ // 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") ||
@@ -319,6 +322,7 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
stream_type = "audio";
priv->astreams[priv->audio_streams] = i;
sh_audio->libav_codec_id = codec->codec_id;
+ sh_audio->gsh->lavf_codec_tag = lavf_codec_tag;
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'))
@@ -331,7 +335,7 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
wf->nChannels = codec->channels;
wf->nSamplesPerSec = codec->sample_rate;
wf->nAvgBytesPerSec = codec->bit_rate / 8;
- wf->nBlockAlign = codec->block_align ? codec->block_align : 1;
+ wf->nBlockAlign = codec->block_align;
wf->wBitsPerSample = codec->bits_per_coded_sample;
wf->cbSize = codec->extradata_size;
if (codec->extradata_size)
@@ -402,6 +406,7 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
stream_type = "video";
priv->vstreams[priv->video_streams] = i;
sh_video->libav_codec_id = codec->codec_id;
+ sh_video->gsh->lavf_codec_tag = lavf_codec_tag;
bih = calloc(sizeof(*bih) + codec->extradata_size, 1);
if (codec->codec_id == CODEC_ID_RAWVIDEO) {
@@ -488,8 +493,8 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
case AVMEDIA_TYPE_SUBTITLE: {
sh_sub_t *sh_sub;
char type;
- /* only support text subtitles for now */
- if (codec->codec_id == CODEC_ID_TEXT)
+ if (codec->codec_id == CODEC_ID_TEXT ||
+ codec->codec_id == AV_CODEC_ID_SUBRIP)
type = 't';
else if (codec->codec_id == CODEC_ID_MOV_TEXT)
type = 'm';
@@ -516,6 +521,7 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i)
stream_type = "subtitle";
priv->sstreams[priv->sub_streams] = i;
sh_sub->libav_codec_id = codec->codec_id;
+ sh_sub->gsh->lavf_codec_tag = lavf_codec_tag;
sh_sub->type = type;
if (codec->extradata_size) {
sh_sub->extradata = malloc(codec->extradata_size);
@@ -616,10 +622,12 @@ static demuxer_t *demux_open_lavf(demuxer_t *demuxer)
}
if (demuxer->stream->url) {
- if (!strncmp(demuxer->stream->url, "ffmpeg://rtsp:", 14))
- av_strlcpy(mp_filename, demuxer->stream->url + 9,
- sizeof(mp_filename));
- else
+ if (demuxer->stream->lavf_type && !strcmp(demuxer->stream->lavf_type,
+ "rtsp")) {
+ // Remove possible leading ffmpeg:// or lavf://
+ char *name = strstr(demuxer->stream->url, "rtsp:");
+ av_strlcpy(mp_filename, name, sizeof(mp_filename));
+ } else
av_strlcat(mp_filename, demuxer->stream->url, sizeof(mp_filename));
} else
av_strlcat(mp_filename, "foobar.dummy", sizeof(mp_filename));
@@ -1004,7 +1012,7 @@ redo:
prog->aid = program->stream_index[i];
break;
case AVMEDIA_TYPE_SUBTITLE:
- if (prog->sid == -2 && priv->avfc->streams[program->stream_index[i]]->codec->codec_id == CODEC_ID_TEXT)
+ if (prog->sid == -2)
prog->sid = program->stream_index[i];
break;
}
diff --git a/libmpdemux/demux_ts.c b/libmpdemux/demux_ts.c
index dbf12b7456..b59066327d 100644
--- a/libmpdemux/demux_ts.c
+++ b/libmpdemux/demux_ts.c
@@ -81,6 +81,7 @@ typedef enum
AUDIO_AAC_LATM = mmioFOURCC('M', 'P', '4', 'L'),
AUDIO_TRUEHD = mmioFOURCC('T', 'R', 'H', 'D'),
AUDIO_S302M = mmioFOURCC('B', 'S', 'S', 'D'),
+ AUDIO_PCM_BR = mmioFOURCC('B', 'P', 'C', 'M'),
SPU_DVD = 0x3000000,
SPU_DVB = 0x3000001,
SPU_TELETEXT = 0x3000002,
@@ -257,6 +258,7 @@ static int IS_AUDIO(es_stream_type_t type)
case AUDIO_MP2:
case AUDIO_A52:
case AUDIO_LPCM_BE:
+ case AUDIO_PCM_BR:
case AUDIO_AAC:
case AUDIO_AAC_LATM:
case AUDIO_DTS:
@@ -333,7 +335,7 @@ try_fec:
}
static int parse_avc_sps(uint8_t *buf, int len, int *w, int *h);
-static inline uint8_t *pid_lang_from_pmt(ts_priv_t *priv, int pid);
+static uint8_t *pid_lang_from_pmt(ts_priv_t *priv, int pid);
static void ts_add_stream(demuxer_t * demuxer, ES_stream_t *es)
{
@@ -528,7 +530,7 @@ static int ts_check_file(demuxer_t * demuxer)
}
-static inline int32_t progid_idx_in_pmt(ts_priv_t *priv, uint16_t progid)
+static int32_t progid_idx_in_pmt(ts_priv_t *priv, uint16_t progid)
{
int x;
@@ -545,7 +547,7 @@ static inline int32_t progid_idx_in_pmt(ts_priv_t *priv, uint16_t progid)
}
-static inline int32_t progid_for_pid(ts_priv_t *priv, int pid, int32_t req) //finds the first program listing a pid
+static int32_t progid_for_pid(ts_priv_t *priv, int pid, int32_t req) //finds the first program listing a pid
{
int i, j;
pmt_t *pmt;
@@ -575,7 +577,7 @@ static inline int32_t progid_for_pid(ts_priv_t *priv, int pid, int32_t req) //f
return -1;
}
-static inline int32_t prog_pcr_pid(ts_priv_t *priv, int progid)
+static int32_t prog_pcr_pid(ts_priv_t *priv, int progid)
{
int i;
@@ -590,7 +592,7 @@ static inline int32_t prog_pcr_pid(ts_priv_t *priv, int progid)
}
-static inline int pid_match_lang(ts_priv_t *priv, uint16_t pid, char *lang)
+static int pid_match_lang(ts_priv_t *priv, uint16_t pid, char *lang)
{
uint16_t i, j;
pmt_t *pmt;
@@ -891,6 +893,8 @@ static off_t ts_detect_streams(demuxer_t *demuxer, tsdemux_init_t *param)
mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO DTS(pid=%d)", param->apid);
else if(param->atype == AUDIO_LPCM_BE)
mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO LPCM(pid=%d)", param->apid);
+ else if(param->atype == AUDIO_PCM_BR)
+ mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO PCMBR(pid=%d)", param->apid);
else if(param->atype == AUDIO_AAC)
mp_msg(MSGT_DEMUXER, MSGL_INFO, "AUDIO AAC(pid=%d)", param->apid);
else if(param->atype == AUDIO_AAC_LATM)
@@ -1660,7 +1664,7 @@ static void ts_dump_streams(ts_priv_t *priv)
}
-static inline int32_t prog_idx_in_pat(ts_priv_t *priv, uint16_t progid)
+static int32_t prog_idx_in_pat(ts_priv_t *priv, uint16_t progid)
{
int x;
@@ -1677,7 +1681,7 @@ static inline int32_t prog_idx_in_pat(ts_priv_t *priv, uint16_t progid)
}
-static inline int32_t prog_id_in_pat(ts_priv_t *priv, uint16_t pid)
+static int32_t prog_id_in_pat(ts_priv_t *priv, uint16_t pid)
{
int x;
@@ -1750,7 +1754,6 @@ static int parse_pat(ts_priv_t * priv, int is_start, unsigned char *buff, int si
unsigned char *base;
int entries, i;
uint16_t progid;
- struct pat_progs_t *tmp;
ts_section_t *section;
section = &(priv->pat.section);
@@ -1784,14 +1787,14 @@ static int parse_pat(ts_priv_t * priv, int is_start, unsigned char *buff, int si
if((idx = prog_idx_in_pat(priv, progid)) == -1)
{
- int sz = sizeof(struct pat_progs_t) * (priv->pat.progs_cnt+1);
- tmp = realloc_struct(priv->pat.progs, priv->pat.progs_cnt+1, sizeof(struct pat_progs_t));
- if(tmp == NULL)
+ priv->pat.progs = realloc_struct(priv->pat.progs, priv->pat.progs_cnt+1, sizeof(struct pat_progs_t));
+ if(!priv->pat.progs)
{
+ int sz = sizeof(struct pat_progs_t) * (priv->pat.progs_cnt+1);
+ priv->pat.progs_cnt = 0;
mp_msg(MSGT_DEMUX, MSGL_ERR, "PARSE_PAT: COULDN'T REALLOC %d bytes, NEXT\n", sz);
break;
}
- priv->pat.progs = tmp;
idx = priv->pat.progs_cnt;
priv->pat.progs_cnt++;
}
@@ -1807,7 +1810,7 @@ static int parse_pat(ts_priv_t * priv, int is_start, unsigned char *buff, int si
}
-static inline int32_t es_pid_in_pmt(pmt_t * pmt, uint16_t pid)
+static int32_t es_pid_in_pmt(pmt_t * pmt, uint16_t pid)
{
uint16_t i;
@@ -2043,7 +2046,7 @@ static uint16_t parse_mp4_es_descriptor(pmt_t *pmt, uint8_t *buf, int len)
{
int i = 0, j = 0, k, found;
uint8_t flag;
- mp4_es_descr_t es, *target_es = NULL, *tmp;
+ mp4_es_descr_t es, *target_es = NULL;
mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4ES: len=%d\n", len);
memset(&es, 0, sizeof(mp4_es_descr_t));
@@ -2078,13 +2081,13 @@ static uint16_t parse_mp4_es_descriptor(pmt_t *pmt, uint8_t *buf, int len)
if(! found)
{
- tmp = realloc_struct(pmt->mp4es, pmt->mp4es_cnt+1, sizeof(mp4_es_descr_t));
- if(tmp == NULL)
+ pmt->mp4es = realloc_struct(pmt->mp4es, pmt->mp4es_cnt+1, sizeof(mp4_es_descr_t));
+ if(!pmt->mp4es)
{
+ pmt->mp4es_cnt = 0;
fprintf(stderr, "CAN'T REALLOC MP4_ES_DESCR\n");
continue;
}
- pmt->mp4es = tmp;
target_es = &(pmt->mp4es[pmt->mp4es_cnt]);
pmt->mp4es_cnt++;
}
@@ -2283,7 +2286,7 @@ static int parse_descriptors(struct pmt_es_t *es, uint8_t *ptr)
else if(ptr[j] == 0x56) // Teletext
{
if(descr_len >= 5) {
- memcpy(es->lang, ptr+2, 3);
+ memcpy(es->lang, ptr+j+2, 3);
es->lang[3] = 0;
}
es->type = SPU_TELETEXT;
@@ -2419,8 +2422,6 @@ static int parse_pmt(ts_priv_t * priv, uint16_t progid, uint16_t pid, int is_sta
int32_t idx, es_count, section_bytes;
uint8_t m=0;
int skip;
- pmt_t *tmp;
- struct pmt_es_t *tmp_es;
ts_section_t *section;
ES_stream_t *tss;
int i;
@@ -2429,14 +2430,14 @@ static int parse_pmt(ts_priv_t * priv, uint16_t progid, uint16_t pid, int is_sta
if(idx == -1)
{
- int sz = (priv->pmt_cnt + 1) * sizeof(pmt_t);
- tmp = realloc_struct(priv->pmt, priv->pmt_cnt + 1, sizeof(pmt_t));
- if(tmp == NULL)
+ priv->pmt = realloc_struct(priv->pmt, priv->pmt_cnt + 1, sizeof(pmt_t));
+ if(!priv->pmt)
{
+ int sz = (priv->pmt_cnt + 1) * sizeof(pmt_t);
+ priv->pmt_cnt = 0;
mp_msg(MSGT_DEMUX, MSGL_ERR, "PARSE_PMT: COULDN'T REALLOC %d bytes, NEXT\n", sz);
return 0;
}
- priv->pmt = tmp;
idx = priv->pmt_cnt;
memset(&(priv->pmt[idx]), 0, sizeof(pmt_t));
priv->pmt_cnt++;
@@ -2490,14 +2491,14 @@ static int parse_pmt(ts_priv_t * priv, uint16_t progid, uint16_t pid, int is_sta
idx = es_pid_in_pmt(pmt, es_pid);
if(idx == -1)
{
- int sz = sizeof(struct pmt_es_t) * (pmt->es_cnt + 1);
- tmp_es = realloc_struct(pmt->es, pmt->es_cnt + 1, sizeof(struct pmt_es_t));
- if(tmp_es == NULL)
+ pmt->es = realloc_struct(pmt->es, pmt->es_cnt + 1, sizeof(struct pmt_es_t));
+ if(!pmt->es)
{
+ int sz = sizeof(struct pmt_es_t) * (pmt->es_cnt + 1);
+ pmt->es_cnt = 0;
mp_msg(MSGT_DEMUX, MSGL_ERR, "PARSE_PMT, COULDN'T ALLOCATE %d bytes for PMT_ES\n", sz);
continue;
}
- pmt->es = tmp_es;
idx = pmt->es_cnt;
memset(&(pmt->es[idx]), 0, sizeof(struct pmt_es_t));
pmt->es_cnt++;
@@ -2560,6 +2561,9 @@ static int parse_pmt(ts_priv_t * priv, uint16_t progid, uint16_t pid, int is_sta
case 0x13:
pmt->es[idx].type = SL_SECTION;
break;
+ case 0x80:
+ pmt->es[idx].type = AUDIO_PCM_BR;
+ break;
case 0x81:
pmt->es[idx].type = AUDIO_A52;
break;
@@ -2643,7 +2647,7 @@ static pmt_t* pmt_of_pid(ts_priv_t *priv, int pid, mp4_decoder_config_t **mp4_de
}
-static inline int32_t pid_type_from_pmt(ts_priv_t *priv, int pid)
+static int32_t pid_type_from_pmt(ts_priv_t *priv, int pid)
{
int32_t pmt_idx, pid_idx, i, j;
@@ -2670,7 +2674,7 @@ static inline int32_t pid_type_from_pmt(ts_priv_t *priv, int pid)
}
-static inline uint8_t *pid_lang_from_pmt(ts_priv_t *priv, int pid)
+static uint8_t *pid_lang_from_pmt(ts_priv_t *priv, int pid)
{
int32_t pmt_idx, pid_idx, i, j;
diff --git a/libmpdemux/demuxer.c b/libmpdemux/demuxer.c
index 55b5d0f1c0..b827a64018 100644
--- a/libmpdemux/demuxer.c
+++ b/libmpdemux/demuxer.c
@@ -272,7 +272,7 @@ demuxer_t *new_demuxer(struct MPOpts *opts, stream_t *stream, int type,
if (!(d->desc = get_demuxer_desc_from_type(type)))
mp_msg(MSGT_DEMUXER, MSGL_ERR,
"BUG! Invalid demuxer type in new_demuxer(), "
- "big troubles ahead.");
+ "big troubles ahead.\n");
if (filename) // Filename hack for avs_check_file
d->filename = strdup(filename);
stream_seek(stream, stream->start_pos);
@@ -657,7 +657,7 @@ int ds_fill_buffer(demux_stream_t *ds)
}
#define MaybeNI _("Maybe you are playing a non-interleaved stream/file or the codec failed?\n" \
- "For AVI files, try to force non-interleaved mode with the -ni option.\n")
+ "For AVI files, try to force non-interleaved mode with the --demuxer=avi --avi-ni options.\n")
if (demux->audio->packs >= MAX_PACKS
|| demux->audio->bytes >= MAX_PACK_BYTES) {
diff --git a/libmpdemux/demuxer.h b/libmpdemux/demuxer.h
index 62316c0ef0..f44c728c1e 100644
--- a/libmpdemux/demuxer.h
+++ b/libmpdemux/demuxer.h
@@ -369,7 +369,6 @@ int demux_seek(struct demuxer *demuxer, float rel_seek_secs, float audio_delay,
// AVI demuxer params:
extern int index_mode; // -1=untouched 0=don't use index 1=use (generate) index
-extern char *index_file_save, *index_file_load;
extern int force_ni;
extern int pts_from_bps;
diff --git a/libmpdemux/ebml.c b/libmpdemux/ebml.c
index 9bce3b5182..fba8177805 100644
--- a/libmpdemux/ebml.c
+++ b/libmpdemux/ebml.c
@@ -130,6 +130,8 @@ uint64_t ebml_read_length(stream_t *s, int *length)
}
if (j == num_ffs)
return EBML_UINT_INVALID;
+ if (len >= 1ULL<<63) // Can happen if stream_read_char returns EOF
+ return EBML_UINT_INVALID;
return len;
}
diff --git a/libmpdemux/stheader.h b/libmpdemux/stheader.h
index f55e8d2722..2d214966d2 100644
--- a/libmpdemux/stheader.h
+++ b/libmpdemux/stheader.h
@@ -54,6 +54,9 @@ struct sh_stream {
struct sh_video *video;
struct sh_sub *sub;
+ // Work around other hacks.
+ int lavf_codec_tag;
+
char *title;
bool default_track;