Mercurial > mplayer.hg
annotate libmpdemux/demux_mpg.c @ 16301:c730c7939457
Slightly reduce unnecessary verbosity.
author | diego |
---|---|
date | Wed, 24 Aug 2005 00:46:04 +0000 |
parents | 6b86089c2edd |
children | fb95057e370e |
rev | line source |
---|---|
1 | 1 // MPG/VOB file parser for DEMUXER v2.5 by A'rpi/ESP-team |
2 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
3 #include <stdio.h> |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
4 #include <stdlib.h> |
1430 | 5 #include <unistd.h> |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
6 |
1567 | 7 #include "config.h" |
8 #include "mp_msg.h" | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1735
diff
changeset
|
9 #include "help_mp.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
10 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
11 #include "stream.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
12 #include "demuxer.h" |
1466 | 13 #include "parse_es.h" |
2338 | 14 #include "stheader.h" |
4711 | 15 #include "mp3_hdr.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
16 |
524
9105fc95636c
A fast'n'ugly hack to correct DVD VOB playback problems
lgb
parents:
501
diff
changeset
|
17 //#define MAX_PS_PACKETSIZE 2048 |
501 | 18 #define MAX_PS_PACKETSIZE (224*1024) |
19 | |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
20 #define UNKNOWN 0 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
21 #define VIDEO_MPEG1 0x10000001 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
22 #define VIDEO_MPEG2 0x10000002 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
23 #define VIDEO_MPEG4 0x10000004 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
24 #define VIDEO_H264 0x10000005 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
25 #define AUDIO_MP2 0x50 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
26 #define AUDIO_A52 0x2000 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
27 #define AUDIO_LPCM_BE 0x10001 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
28 #define AUDIO_AAC mmioFOURCC('M', 'P', '4', 'A') |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
29 |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
30 typedef struct mpg_demuxer { |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
31 float last_pts; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
32 float final_pts; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
33 int has_valid_timestamps; |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
34 unsigned int es_map[0x40]; //es map of stream types (associated to the pes id) from 0xb0 to 0xef |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
35 int num_a_streams; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
36 int a_stream_ids[MAX_A_STREAMS]; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
37 } mpg_demuxer_t; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
38 |
547 | 39 static int mpeg_pts_error=0; |
40 | |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
41 static int parse_psm(demuxer_t *demux, int len) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
42 unsigned char c, id, type; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
43 unsigned int plen, prog_len, es_map_len; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
44 mpg_demuxer_t *priv = (mpg_demuxer_t *) demux->priv; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
45 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
46 mp_dbg(MSGT_DEMUX,MSGL_V, "PARSE_PSM, len=%d\n", len); |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
47 if(! len) |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
48 return 0; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
49 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
50 c = stream_read_char(demux->stream); |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
51 if(! (c & 0x80)) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
52 stream_skip(demux->stream, len - 1); //not yet valid, discard |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
53 return 0; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
54 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
55 stream_skip(demux->stream, 1); |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
56 prog_len = stream_read_word(demux->stream); //length of program descriptors |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
57 stream_skip(demux->stream, prog_len); //.. that we ignore |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
58 es_map_len = stream_read_word(demux->stream); //length of elementary streams map |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
59 es_map_len = min(es_map_len, len - prog_len - 8); //sanity check |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
60 while(es_map_len > 0) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
61 type = stream_read_char(demux->stream); |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
62 id = stream_read_char(demux->stream); |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
63 if(id >= 0xB0 && id <= 0xEF && priv) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
64 int idoffset = id - 0xB0; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
65 switch(type) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
66 case 0x1: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
67 priv->es_map[idoffset] = VIDEO_MPEG1; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
68 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
69 case 0x2: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
70 priv->es_map[idoffset] = VIDEO_MPEG2; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
71 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
72 case 0x3: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
73 case 0x4: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
74 priv->es_map[idoffset] = AUDIO_MP2; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
75 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
76 case 0x0f: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
77 case 0x11: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
78 priv->es_map[idoffset] = AUDIO_AAC; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
79 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
80 case 0x10: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
81 priv->es_map[idoffset] = VIDEO_MPEG4; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
82 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
83 case 0x1b: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
84 priv->es_map[idoffset] = VIDEO_H264; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
85 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
86 case 0x81: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
87 priv->es_map[idoffset] = AUDIO_A52; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
88 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
89 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
90 mp_dbg(MSGT_DEMUX,MSGL_V, "PSM ES, id=0x%x, type=%x, stype: %x\n", id, type, priv->es_map[idoffset]); |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
91 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
92 plen = stream_read_word(demux->stream); //length of elementary stream descriptors |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
93 plen = min(plen, es_map_len); //sanity check |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
94 stream_skip(demux->stream, plen); //skip descriptors for now |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
95 es_map_len -= 4 + plen; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
96 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
97 stream_skip(demux->stream, 4); //skip crc32 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
98 return 1; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
99 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
100 |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
101 /// Open an mpg physical stream |
16175 | 102 static demuxer_t* demux_mpg_open(demuxer_t* demuxer) { |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
103 stream_t *s = demuxer->stream; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
104 off_t pos = stream_tell(s); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
105 off_t end_seq_start = demuxer->movi_end-500000; // 500000 is a wild guess |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
106 float half_pts = 0.0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
107 mpg_demuxer_t* mpg_d; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
108 |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
109 if (!ds_fill_buffer(demuxer->video)) return 0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
110 mpg_d = (mpg_demuxer_t*)calloc(1,sizeof(mpg_demuxer_t)); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
111 demuxer->priv = mpg_d; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
112 mpg_d->final_pts = 0.0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
113 mpg_d->has_valid_timestamps = 1; |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
114 mpg_d->num_a_streams = 0; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
115 if (demuxer->seekable && stream_tell(demuxer->stream) < end_seq_start) { |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
116 stream_seek(s,(pos + end_seq_start / 2)); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
117 while ((!s->eof) && ds_fill_buffer(demuxer->video) && half_pts == 0.0) { |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
118 half_pts = mpg_d->last_pts; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
119 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
120 stream_seek(s,end_seq_start); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
121 while ((!s->eof) && ds_fill_buffer(demuxer->video)) { |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
122 if (mpg_d->final_pts < mpg_d->last_pts) mpg_d->final_pts = mpg_d->last_pts; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
123 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
124 // educated guess about validity of timestamps |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
125 if (mpg_d->final_pts > 3 * half_pts || mpg_d->final_pts < 1.5 * half_pts) { |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
126 mpg_d->has_valid_timestamps = 0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
127 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
128 ds_free_packs(demuxer->audio); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
129 ds_free_packs(demuxer->video); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
130 demuxer->stream->eof=0; // clear eof flag |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
131 demuxer->video->eof=0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
132 demuxer->audio->eof=0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
133 |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
134 stream_seek(s,pos); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
135 ds_fill_buffer(demuxer->video); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
136 } |
16175 | 137 return demuxer; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
138 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
139 |
16175 | 140 static void demux_close_mpg(demuxer_t* demuxer) { |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
141 mpg_demuxer_t* mpg_d = demuxer->priv; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
142 if (mpg_d) free(mpg_d); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
143 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
144 |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
145 |
1 | 146 static unsigned int read_mpeg_timestamp(stream_t *s,int c){ |
147 int d,e; | |
148 unsigned int pts; | |
149 d=stream_read_word(s); | |
150 e=stream_read_word(s); | |
547 | 151 if( ((c&1)!=1) || ((d&1)!=1) || ((e&1)!=1) ){ |
152 ++mpeg_pts_error; | |
153 return 0; // invalid pts | |
154 } | |
1 | 155 pts=(((c>>1)&7)<<30)|((d>>1)<<15)|(e>>1); |
1567 | 156 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"{%d}",pts); |
1 | 157 return pts; |
158 } | |
159 | |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
160 static void new_audio_stream(demuxer_t *demux, int aid){ |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
161 if(!demux->a_streams[aid]){ |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
162 mpg_demuxer_t *mpg_d=(mpg_demuxer_t*)demux->priv; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
163 sh_audio_t* sh_a; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
164 new_sh_audio(demux,aid); |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
165 sh_a = (sh_audio_t*)demux->a_streams[aid]; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
166 switch(aid & 0xE0){ // 1110 0000 b (high 3 bit: type low 5: id) |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
167 case 0x00: sh_a->format=0x50;break; // mpeg |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
168 case 0xA0: sh_a->format=0x10001;break; // dvd pcm |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
169 case 0x80: if((aid & 0xF8) == 0x88) sh_a->format=0x2001;//dts |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
170 else sh_a->format=0x2000;break; // ac3 |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
171 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
172 if (mpg_d) mpg_d->a_stream_ids[mpg_d->num_a_streams++] = aid; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
173 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
174 if(demux->audio->id==-1) demux->audio->id=aid; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
175 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
176 |
1 | 177 static int demux_mpg_read_packet(demuxer_t *demux,int id){ |
178 int d; | |
179 int len; | |
180 unsigned char c=0; | |
181 unsigned int pts=0; | |
182 unsigned int dts=0; | |
183 demux_stream_t *ds=NULL; | |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
184 mpg_demuxer_t *priv = (mpg_demuxer_t *) demux->priv; |
1 | 185 |
1567 | 186 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"demux_read_packet: %X\n",id); |
1 | 187 |
536 | 188 // if(id==0x1F0){ |
189 // demux->synced=0; // force resync after 0x1F0 | |
190 // return -1; | |
191 //} | |
501 | 192 |
1 | 193 // if(id==0x1BA) packet_start_pos=stream_tell(demux->stream); |
501 | 194 if(id<0x1BC || id>=0x1F0) return -1; |
1 | 195 if(id==0x1BE) return -1; // padding stream |
196 if(id==0x1BF) return -1; // private2 | |
197 | |
198 len=stream_read_word(demux->stream); | |
1567 | 199 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"PACKET len=%d",len); |
536 | 200 // if(len==62480){ demux->synced=0;return -1;} /* :) */ |
501 | 201 if(len==0 || len>MAX_PS_PACKETSIZE){ |
1567 | 202 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Invalid PS packet len: %d\n",len); |
501 | 203 return -2; // invalid packet !!!!!! |
204 } | |
1 | 205 |
547 | 206 mpeg_pts_error=0; |
207 | |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
208 if(id==0x1BC) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
209 parse_psm(demux, len); |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
210 return 0; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
211 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
212 |
1 | 213 while(len>0){ // Skip stuFFing bytes |
214 c=stream_read_char(demux->stream);--len; | |
215 if(c!=0xFF)break; | |
216 } | |
217 if((c>>6)==1){ // Read (skip) STD scale & size value | |
218 // printf(" STD_scale=%d",(c>>5)&1); | |
219 d=((c&0x1F)<<8)|stream_read_char(demux->stream); | |
220 len-=2; | |
221 // printf(" STD_size=%d",d); | |
222 c=stream_read_char(demux->stream); | |
223 } | |
224 // Read System-1 stream timestamps: | |
225 if((c>>4)==2){ | |
226 pts=read_mpeg_timestamp(demux->stream,c); | |
227 len-=4; | |
228 } else | |
229 if((c>>4)==3){ | |
230 pts=read_mpeg_timestamp(demux->stream,c); | |
231 c=stream_read_char(demux->stream); | |
232 if((c>>4)!=1) pts=0; //printf("{ERROR4}"); | |
233 dts=read_mpeg_timestamp(demux->stream,c); | |
234 len-=4+1+4; | |
235 } else | |
236 if((c>>6)==2){ | |
237 int pts_flags; | |
238 int hdrlen; | |
239 // System-2 (.VOB) stream: | |
492 | 240 if((c>>4)&3) { |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1735
diff
changeset
|
241 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_EncryptedVOB); |
492 | 242 } |
1 | 243 c=stream_read_char(demux->stream); pts_flags=c>>6; |
244 c=stream_read_char(demux->stream); hdrlen=c; | |
245 len-=2; | |
1567 | 246 mp_dbg(MSGT_DEMUX,MSGL_DBG3," hdrlen=%d (len=%d)",hdrlen,len); |
247 if(hdrlen>len){ mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: invalid header length \n"); return -1;} | |
7671 | 248 if(pts_flags==2 && hdrlen>=5){ |
1 | 249 c=stream_read_char(demux->stream); |
250 pts=read_mpeg_timestamp(demux->stream,c); | |
251 len-=5;hdrlen-=5; | |
252 } else | |
7671 | 253 if(pts_flags==3 && hdrlen>=10){ |
1 | 254 c=stream_read_char(demux->stream); |
255 pts=read_mpeg_timestamp(demux->stream,c); | |
256 c=stream_read_char(demux->stream); | |
257 dts=read_mpeg_timestamp(demux->stream,c); | |
258 len-=10;hdrlen-=10; | |
259 } | |
260 len-=hdrlen; | |
261 if(hdrlen>0) stream_skip(demux->stream,hdrlen); // skip header bytes | |
262 | |
263 //============== DVD Audio sub-stream ====================== | |
264 if(id==0x1BD){ | |
15815
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
265 int aid, rawa52 = 0; |
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
266 off_t tmppos; |
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
267 unsigned int tmp; |
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
268 |
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
269 tmppos = stream_tell(demux->stream); |
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
270 tmp = stream_read_word(demux->stream); |
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
271 stream_seek(demux->stream, tmppos); |
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
272 /// vdr stores A52 without the 4 header bytes, so we have to check this condition first |
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
273 if(tmp == 0x0B77) { |
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
274 aid = 128; |
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
275 rawa52 = 1; |
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
276 } |
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
277 else { |
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
278 aid=stream_read_char(demux->stream);--len; |
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
279 if(len<3) return -1; // invalid audio packet |
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
280 } |
552 | 281 |
282 // AID: | |
283 // 0x20..0x3F subtitle | |
284 // 0x80..0x9F AC3 audio | |
285 // 0xA0..0xBF PCM audio | |
286 | |
287 if((aid & 0xE0) == 0x20){ | |
288 // subtitle: | |
289 aid&=0x1F; | |
426 | 290 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
291 if(!demux->s_streams[aid]){ |
1567 | 292 mp_msg(MSGT_DEMUX,MSGL_V,"==> Found subtitle: %d\n",aid); |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
293 demux->s_streams[aid]=1; |
552 | 294 } |
295 | |
296 if(demux->sub->id==aid){ | |
297 ds=demux->sub; | |
298 } | |
299 | |
3955 | 300 } else if((aid & 0xC0) == 0x80 || (aid & 0xE0) == 0x00) { |
552 | 301 |
302 // aid=128+(aid&0x7F); | |
303 // aid=0x80..0xBF | |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
304 new_audio_stream(demux, aid); |
426 | 305 if(demux->audio->id==aid){ |
7671 | 306 int type; |
426 | 307 ds=demux->audio; |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
308 if(!ds->sh) ds->sh=demux->a_streams[aid]; |
1 | 309 // READ Packet: Skip additional audio header data: |
15815
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
310 if(!rawa52) { |
7671 | 311 c=stream_read_char(demux->stream);//num of frames |
312 type=stream_read_char(demux->stream);//startpos hi | |
313 type=(type<<8)|stream_read_char(demux->stream);//startpos lo | |
314 // printf("\r[%02X][%04X]",c,type); | |
1 | 315 len-=3; |
15815
488f31bd127e
support raw ac3 (in private pes packets without the usual dvd 4 bytes substream header). Patch by Matthias Scharzott
nicodvb
parents:
15670
diff
changeset
|
316 } |
7671 | 317 if((aid&0xE0)==0xA0 && len>=3){ |
318 unsigned char* hdr; | |
319 // save audio header as codecdata! | |
320 if(!((sh_audio_t*)(ds->sh))->codecdata_len){ | |
321 ((sh_audio_t*)(ds->sh))->codecdata=malloc(3); | |
322 ((sh_audio_t*)(ds->sh))->codecdata_len=3; | |
323 } | |
324 hdr=((sh_audio_t*)(ds->sh))->codecdata; | |
325 // read LPCM header: | |
326 // emphasis[1], mute[1], rvd[1], frame number[5]: | |
327 hdr[0]=stream_read_char(demux->stream); | |
328 // printf(" [%01X:%02d]",c>>5,c&31); | |
329 // quantization[2],freq[2],rvd[1],channels[3] | |
330 hdr[1]=stream_read_char(demux->stream); | |
331 // printf("[%01X:%01X] ",c>>4,c&15); | |
332 // dynamic range control (0x80=off): | |
333 hdr[2]=stream_read_char(demux->stream); | |
334 // printf("[%02X] ",c); | |
335 len-=3; | |
336 if(len<=0) mp_msg(MSGT_DEMUX,MSGL_V,"End of packet while searching for PCM header\n"); | |
1 | 337 } |
7671 | 338 // printf(" \n"); |
552 | 339 } // if(demux->audio->id==aid) |
340 | |
1567 | 341 } else mp_msg(MSGT_DEMUX,MSGL_V,"Unknown 0x1BD substream: 0x%02X \n",aid); |
552 | 342 |
343 } //if(id==0x1BD) | |
1 | 344 |
345 } else { | |
539 | 346 if(c!=0x0f){ |
1567 | 347 mp_msg(MSGT_DEMUX,MSGL_V," {ERROR5,c=%d} \n",c); |
539 | 348 return -1; // invalid packet !!!!!! |
349 } | |
1 | 350 } |
1567 | 351 if(mpeg_pts_error) mp_msg(MSGT_DEMUX,MSGL_V," {PTS_err:%d} \n",mpeg_pts_error); |
352 mp_dbg(MSGT_DEMUX,MSGL_DBG3," => len=%d\n",len); | |
1 | 353 |
501 | 354 // if(len<=0 || len>MAX_PS_PACKETSIZE) return -1; // Invalid packet size |
355 if(len<=0 || len>MAX_PS_PACKETSIZE){ | |
1567 | 356 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Invalid PS data len: %d\n",len); |
501 | 357 return -1; // invalid packet !!!!!! |
358 } | |
1 | 359 |
360 if(id>=0x1C0 && id<=0x1DF){ | |
361 // mpeg audio | |
362 int aid=id-0x1C0; | |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
363 new_audio_stream(demux, aid); |
1 | 364 if(demux->audio->id==aid){ |
365 ds=demux->audio; | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
366 if(!ds->sh) ds->sh=demux->a_streams[aid]; |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
367 if(priv && ds->sh) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
368 sh_audio_t *sh = (sh_audio_t *)ds->sh; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
369 if(priv->es_map[id - 0x1B0]) |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
370 sh->format = priv->es_map[id - 0x1B0]; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
371 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"ASSIGNED TO STREAM %d CODEC %x\n", id, priv->es_map[id - 0x1B0]); |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
372 } |
1 | 373 } |
374 } else | |
375 if(id>=0x1E0 && id<=0x1EF){ | |
376 // mpeg video | |
377 int aid=id-0x1E0; | |
1289 | 378 if(!demux->v_streams[aid]) new_sh_video(demux,aid); |
1 | 379 if(demux->video->id==-1) demux->video->id=aid; |
426 | 380 if(demux->video->id==aid){ |
381 ds=demux->video; | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
382 if(!ds->sh) ds->sh=demux->v_streams[aid]; |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
383 if(priv && ds->sh) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
384 sh_video_t *sh = (sh_video_t *)ds->sh; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
385 if(priv->es_map[id - 0x1B0]) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
386 sh->format = priv->es_map[id - 0x1B0]; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
387 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"ASSIGNED TO STREAM %d CODEC %x\n", id, priv->es_map[id - 0x1B0]); |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
388 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
389 } |
426 | 390 } |
1 | 391 } |
392 | |
393 if(ds){ | |
1567 | 394 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_MPG: Read %d data bytes from packet %04X\n",len,id); |
1 | 395 // printf("packet start = 0x%X \n",stream_tell(demux->stream)-packet_start_pos); |
1735 | 396 ds_read_packet(ds,demux->stream,len,pts/90000.0f,demux->filepos,0); |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
397 if (demux->priv) ((mpg_demuxer_t*)demux->priv)->last_pts = pts/90000.0f; |
554 | 398 // if(ds==demux->sub) parse_dvdsub(ds->last->buffer,ds->last->len); |
1 | 399 return 1; |
400 } | |
1567 | 401 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_MPG: Skipping %d data bytes from packet %04X\n",len,id); |
536 | 402 if(len<=2356) stream_skip(demux->stream,len); |
1 | 403 return 0; |
404 } | |
405 | |
15670 | 406 static int num_elementary_packets100=0; |
407 static int num_elementary_packets101=0; | |
408 static int num_elementary_packets12x=0; | |
409 static int num_elementary_packets1B6=0; | |
410 static int num_elementary_packetsPES=0; | |
411 static int num_h264_slice=0; //combined slice | |
412 static int num_h264_dpa=0; //DPA Slice | |
413 static int num_h264_dpb=0; //DPB Slice | |
414 static int num_h264_dpc=0; //DPC Slice | |
415 static int num_h264_idr=0; //IDR Slice | |
416 static int num_h264_sps=0; | |
417 static int num_h264_pps=0; | |
418 | |
419 static int num_mp3audio_packets=0; | |
420 | |
16175 | 421 static int demux_mpg_probe(demuxer_t *demuxer) { |
15670 | 422 int pes=1; |
423 int tmp; | |
424 off_t tmppos; | |
425 int file_format = DEMUXER_TYPE_UNKNOWN; | |
426 | |
427 tmppos=stream_tell(demuxer->stream); | |
428 tmp=stream_read_dword(demuxer->stream); | |
429 if(tmp==0x1E0 || tmp==0x1C0) { | |
430 tmp=stream_read_word(demuxer->stream); | |
431 if(tmp>1 && tmp<=2048) pes=0; // demuxer->synced=3; // PES... | |
432 } | |
433 stream_seek(demuxer->stream,tmppos); | |
434 | |
435 num_elementary_packets100=0; | |
436 num_elementary_packets101=0; | |
437 num_elementary_packets1B6=0; | |
438 num_elementary_packets12x=0; | |
439 num_elementary_packetsPES=0; | |
440 num_h264_slice=0; //combined slice | |
441 num_h264_dpa=0; //DPA Slice | |
442 num_h264_dpb=0; //DPB Slice | |
443 num_h264_dpc=0; //DPC Slice | |
444 num_h264_idr=0; //IDR Slice | |
445 num_h264_sps=0; | |
446 num_h264_pps=0; | |
447 num_mp3audio_packets=0; | |
9824 | 448 |
15670 | 449 if(demux_mpg_open(demuxer)) |
450 file_format=DEMUXER_TYPE_MPEG_PS; | |
451 else { | |
452 mp_msg(MSGT_DEMUX,MSGL_V,"MPEG packet stats: p100: %d p101: %d p1B6: %d p12x: %d sli: %d a: %d b: %d c: %d idr: %d sps: %d pps: %d PES: %d MP3: %d, synced: %d\n", | |
453 num_elementary_packets100,num_elementary_packets101, | |
454 num_elementary_packets1B6,num_elementary_packets12x, | |
455 num_h264_slice, num_h264_dpa, | |
456 num_h264_dpb, num_h264_dpc=0, | |
457 num_h264_idr, num_h264_sps=0, | |
458 num_h264_pps, | |
459 num_elementary_packetsPES,num_mp3audio_packets, demuxer->synced); | |
460 | |
461 //MPEG packet stats: p100: 458 p101: 458 PES: 0 MP3: 1103 (.m2v) | |
462 if(num_mp3audio_packets>50 && num_mp3audio_packets>2*num_elementary_packets100 | |
463 && abs(num_elementary_packets100-num_elementary_packets101)>2) | |
464 return file_format; | |
465 | |
466 // some hack to get meaningfull error messages to our unhappy users: | |
467 if(num_elementary_packets100>=2 && num_elementary_packets101>=2 && | |
468 abs(num_elementary_packets101+8-num_elementary_packets100)<16) { | |
469 if(num_elementary_packetsPES>=4 && num_elementary_packetsPES>=num_elementary_packets100-4) { | |
470 return file_format; | |
471 } | |
472 file_format=DEMUXER_TYPE_MPEG_ES; // <-- hack is here :) | |
473 } else | |
474 #if 1 | |
475 // fuzzy mpeg4-es detection. do NOT enable without heavy testing of mpeg formats detection! | |
476 if(num_elementary_packets1B6>3 && num_elementary_packets12x>=1 && | |
477 num_elementary_packetsPES==0 && num_elementary_packets100<=num_elementary_packets12x && | |
478 demuxer->synced<2) { | |
479 file_format=DEMUXER_TYPE_MPEG4_ES; | |
480 } else | |
481 #endif | |
482 #if 1 | |
483 // fuzzy h264-es detection. do NOT enable without heavy testing of mpeg formats detection! | |
484 if((num_h264_slice>3 || (num_h264_dpa>3 && num_h264_dpb>3 && num_h264_dpc>3)) && | |
485 /* FIXME num_h264_sps>=1 && */ num_h264_pps>=1 && num_h264_idr>=1 && | |
486 num_elementary_packets1B6==0 && num_elementary_packetsPES==0 && | |
487 demuxer->synced<2) { | |
488 file_format=DEMUXER_TYPE_H264_ES; | |
489 } else | |
490 #endif | |
491 { | |
492 if(demuxer->synced==2) | |
493 mp_msg(MSGT_DEMUXER,MSGL_ERR,"MPEG: " MSGTR_MissingVideoStreamBug); | |
494 else | |
495 mp_msg(MSGT_DEMUXER,MSGL_V,MSGTR_NotSystemStream); | |
496 } | |
497 } | |
498 return file_format; | |
499 } | |
1 | 500 |
16175 | 501 static int demux_mpg_es_fill_buffer(demuxer_t *demux, demux_stream_t *ds){ |
1 | 502 // Elementary video stream |
503 if(demux->stream->eof) return 0; | |
504 demux->filepos=stream_tell(demux->stream); | |
1735 | 505 ds_read_packet(demux->video,demux->stream,STREAM_BUFFER_SIZE,0,demux->filepos,0); |
1 | 506 return 1; |
507 } | |
508 | |
16175 | 509 int demux_mpg_fill_buffer(demuxer_t *demux, demux_stream_t *ds){ |
1 | 510 unsigned int head=0; |
511 int skipped=0; | |
5570
3a8d8c51355a
max_packs increased for some dvd with too many audio/sub
arpi
parents:
4711
diff
changeset
|
512 int max_packs=256; // 512kbyte |
1 | 513 int ret=0; |
514 | |
515 // System stream | |
516 do{ | |
517 demux->filepos=stream_tell(demux->stream); | |
518 head=stream_read_dword(demux->stream); | |
547 | 519 if((head&0xFFFFFF00)!=0x100){ |
520 // sync... | |
521 demux->filepos-=skipped; | |
522 while(1){ | |
536 | 523 int c=stream_read_char(demux->stream); |
524 if(c<0) break; //EOF | |
525 head<<=8; | |
526 if(head!=0x100){ | |
527 head|=c; | |
4711 | 528 if(mp_check_mp3_header(head)) ++num_mp3audio_packets; |
536 | 529 ++skipped; //++demux->filepos; |
530 continue; | |
531 } | |
532 head|=c; | |
533 break; | |
547 | 534 } |
535 demux->filepos+=skipped; | |
1 | 536 } |
537 if(stream_eof(demux->stream)) break; | |
538 // sure: head=0x000001XX | |
1567 | 539 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"*** head=0x%X\n",head); |
1 | 540 if(demux->synced==0){ |
3770 | 541 if(head==0x1BA) demux->synced=1; //else |
542 // if(head==0x1BD || (head>=0x1C0 && head<=0x1EF)) demux->synced=3; // PES? | |
1 | 543 } else |
544 if(demux->synced==1){ | |
929 | 545 if(head==0x1BB || head==0x1BD || (head>=0x1C0 && head<=0x1EF)){ |
1 | 546 demux->synced=2; |
1567 | 547 mp_msg(MSGT_DEMUX,MSGL_V,"system stream synced at 0x%X (%d)!\n",demux->filepos,demux->filepos); |
536 | 548 num_elementary_packets100=0; // requires for re-sync! |
549 num_elementary_packets101=0; // requires for re-sync! | |
1 | 550 } else demux->synced=0; |
551 } // else | |
3255
ee28577dad02
combined PS/PES sync to allow .VDR playback from stdin
arpi
parents:
2555
diff
changeset
|
552 if(demux->synced>=2){ |
1 | 553 ret=demux_mpg_read_packet(demux,head); |
554 if(!ret) | |
555 if(--max_packs==0){ | |
556 demux->stream->eof=1; | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1735
diff
changeset
|
557 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_DoesntContainSelectedStream); |
1 | 558 return 0; |
559 } | |
3255
ee28577dad02
combined PS/PES sync to allow .VDR playback from stdin
arpi
parents:
2555
diff
changeset
|
560 if(demux->synced==3) demux->synced=(ret==1)?2:0; // PES detect |
1 | 561 } else { |
562 if(head>=0x100 && head<0x1B0){ | |
1162 | 563 if(head==0x100) ++num_elementary_packets100; else |
9069
0d2b25a821c9
raw mpeg4-es support (you need to set -fps manually!)
arpi
parents:
8254
diff
changeset
|
564 if(head==0x101) ++num_elementary_packets101; else |
0d2b25a821c9
raw mpeg4-es support (you need to set -fps manually!)
arpi
parents:
8254
diff
changeset
|
565 if(head>=0x120 && head<=0x12F) ++num_elementary_packets12x; |
9824 | 566 |
567 if((head&~0x60) == 0x101) ++num_h264_slice; else | |
568 if((head&~0x60) == 0x102) ++num_h264_dpa; else | |
569 if((head&~0x60) == 0x103) ++num_h264_dpb; else | |
570 if((head&~0x60) == 0x104) ++num_h264_dpc; else | |
571 if((head&~0x60) == 0x105 && head != 0x105) ++num_h264_idr; else | |
572 if((head&~0x60) == 0x107 && head != 0x107) ++num_h264_sps; else | |
573 if((head&~0x60) == 0x108 && head != 0x108) ++num_h264_pps; | |
574 | |
1567 | 575 mp_msg(MSGT_DEMUX,MSGL_DBG3,"Opps... elementary video packet found: %03X\n",head); |
1162 | 576 } else |
4711 | 577 if((head>=0x1C0 && head<0x1F0) || head==0x1BD){ |
1338
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
578 ++num_elementary_packetsPES; |
1567 | 579 mp_msg(MSGT_DEMUX,MSGL_DBG3,"Opps... PES packet found: %03X\n",head); |
1338
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
580 } else |
1162 | 581 if(head==0x1B6) ++num_elementary_packets1B6; |
1 | 582 #if 1 |
1338
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
583 if( ( (num_elementary_packets100>50 && num_elementary_packets101>50) || |
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
584 (num_elementary_packetsPES>50) ) && skipped>4000000){ |
1567 | 585 mp_msg(MSGT_DEMUX,MSGL_V,"sync_mpeg_ps: seems to be ES/PES stream...\n"); |
1 | 586 demux->stream->eof=1; |
587 break; | |
588 } | |
4711 | 589 if(num_mp3audio_packets>100 && num_elementary_packets100<10){ |
590 mp_msg(MSGT_DEMUX,MSGL_V,"sync_mpeg_ps: seems to be MP3 stream...\n"); | |
591 demux->stream->eof=1; | |
592 break; | |
593 } | |
1 | 594 #endif |
595 } | |
596 } while(ret!=1); | |
1567 | 597 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"demux: %d bad bytes skipped\n",skipped); |
1 | 598 if(demux->stream->eof){ |
1567 | 599 mp_msg(MSGT_DEMUX,MSGL_V,"MPEG Stream reached EOF\n"); |
1 | 600 return 0; |
601 } | |
602 return 1; | |
603 } | |
604 | |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7671
diff
changeset
|
605 extern void resync_audio_stream(sh_audio_t *sh_audio); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7671
diff
changeset
|
606 extern void skip_audio_frame(sh_audio_t *sh_audio); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7671
diff
changeset
|
607 |
1466 | 608 void demux_seek_mpg(demuxer_t *demuxer,float rel_seek_secs,int flags){ |
609 demux_stream_t *d_audio=demuxer->audio; | |
610 demux_stream_t *d_video=demuxer->video; | |
611 sh_audio_t *sh_audio=d_audio->sh; | |
612 sh_video_t *sh_video=d_video->sh; | |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
613 mpg_demuxer_t *mpg_d=(mpg_demuxer_t*)demuxer->priv; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
614 int precision = 1; |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
615 float oldpts = 0; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
616 off_t oldpos = demuxer->filepos; |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
617 float newpts = 0; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
618 off_t newpos = (flags & 1) ? demuxer->movi_start : oldpos; |
1466 | 619 |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
620 if(mpg_d) |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
621 oldpts = mpg_d->last_pts; |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
622 newpts = (flags & 1) ? 0.0 : oldpts; |
1466 | 623 //================= seek in MPEG ========================== |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
624 //calculate the pts to seek to |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
625 if(flags & 2) { |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
626 if (mpg_d && mpg_d->final_pts > 0.0) |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
627 newpts += mpg_d->final_pts * rel_seek_secs; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
628 else |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
629 newpts += rel_seek_secs * (demuxer->movi_end - demuxer->movi_start) * oldpts / oldpos; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
630 } else |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
631 newpts += rel_seek_secs; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
632 if (newpts < 0) newpts = 0; |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
633 |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
634 if(flags&2){ |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
635 // float seek 0..1 |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
636 newpos+=(demuxer->movi_end-demuxer->movi_start)*rel_seek_secs; |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
637 } else { |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
638 // time seek (secs) |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
639 if (mpg_d && mpg_d->has_valid_timestamps) { |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
640 if (mpg_d->final_pts > 0.0) |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
641 newpos += rel_seek_secs * (demuxer->movi_end - demuxer->movi_start) / mpg_d->final_pts; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
642 else if (oldpts > 0.0) |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
643 newpos += rel_seek_secs * (oldpos - demuxer->movi_start) / oldpts; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
644 } else if(!sh_video || !sh_video->i_bps) // unspecified or VBR |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
645 newpos+=2324*75*rel_seek_secs; // 174.3 kbyte/sec |
1466 | 646 else |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
647 newpos+=sh_video->i_bps*rel_seek_secs; |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
648 } |
1466 | 649 |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
650 while (1) { |
4391
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
651 if(newpos<demuxer->movi_start){ |
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
652 if(demuxer->stream->type!=STREAMTYPE_VCD) demuxer->movi_start=0; // for VCD |
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
653 if(newpos<demuxer->movi_start) newpos=demuxer->movi_start; |
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
654 } |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
655 |
1466 | 656 #ifdef _LARGEFILE_SOURCE |
657 newpos&=~((long long)STREAM_BUFFER_SIZE-1); /* sector boundary */ | |
658 #else | |
659 newpos&=~(STREAM_BUFFER_SIZE-1); /* sector boundary */ | |
660 #endif | |
661 stream_seek(demuxer->stream,newpos); | |
662 | |
663 // re-sync video: | |
664 videobuf_code_len=0; // reset ES stream buffer | |
665 | |
666 ds_fill_buffer(d_video); | |
667 if(sh_audio){ | |
668 ds_fill_buffer(d_audio); | |
669 resync_audio_stream(sh_audio); | |
670 } | |
671 | |
672 while(1){ | |
673 int i; | |
674 if(sh_audio && !d_audio->eof && d_video->pts && d_audio->pts){ | |
675 float a_pts=d_audio->pts; | |
676 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; | |
677 if(d_video->pts>a_pts){ | |
678 skip_audio_frame(sh_audio); // sync audio | |
679 continue; | |
680 } | |
681 } | |
682 i=sync_video_packet(d_video); | |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
683 if(sh_video->format == 0x10000004) { //mpeg4 |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
684 if(i==0x1B6) { //vop (frame) startcode |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
685 int pos = videobuf_len; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
686 if(!read_video_packet(d_video)) break; // EOF |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
687 if((videobuffer[pos+4] & 0x3F) == 0) break; //I-frame |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
688 } |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
689 } else if(sh_video->format == 0x10000005){ //h264 |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
690 if((i & ~0x60) == 0x101 || (i & ~0x60) == 0x102 || (i & ~0x60) == 0x105) break; |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
691 } else { //default mpeg1/2 |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
692 if(i==0x1B3 || i==0x1B8) break; // found it! |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
693 } |
1466 | 694 if(!i || !skip_video_packet(d_video)) break; // EOF? |
695 } | |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
696 if(!mpg_d) |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
697 break; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
698 if (!precision || abs(newpts - mpg_d->last_pts) < 0.5 || (mpg_d->last_pts == oldpts)) break; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
699 if ((newpos - oldpos) * (mpg_d->last_pts - oldpts) < 0) { // invalid timestamps |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
700 mpg_d->has_valid_timestamps = 0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
701 break; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
702 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
703 precision--; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
704 //prepare another seek because we are off by more than 0.5s |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
705 if(mpg_d) { |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
706 newpos += (newpts - mpg_d->last_pts) * (newpos - oldpos) / (mpg_d->last_pts - oldpts); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
707 ds_free_packs(d_audio); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
708 ds_free_packs(d_video); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
709 demuxer->stream->eof=0; // clear eof flag |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
710 d_video->eof=0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
711 d_audio->eof=0; |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
712 } |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
713 } |
1466 | 714 } |
715 | |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
716 int demux_mpg_control(demuxer_t *demuxer,int cmd, void *arg){ |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
717 demux_stream_t *d_video=demuxer->video; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
718 sh_video_t *sh_video=d_video->sh; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
719 mpg_demuxer_t *mpg_d=(mpg_demuxer_t*)demuxer->priv; |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
720 |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
721 switch(cmd) { |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
722 case DEMUXER_CTRL_GET_TIME_LENGTH: |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
723 if (mpg_d && mpg_d->has_valid_timestamps) { |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
724 *((unsigned long *)arg)=(long)mpg_d->final_pts; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
725 return DEMUXER_CTRL_GUESS; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
726 } |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
727 return DEMUXER_CTRL_DONTKNOW; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
728 |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
729 case DEMUXER_CTRL_GET_PERCENT_POS: |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
730 if (mpg_d && mpg_d->has_valid_timestamps && mpg_d->final_pts > 0.0) { |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
731 *((int *)arg)=(int)(100 * mpg_d->last_pts / mpg_d->final_pts); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
732 return DEMUXER_CTRL_OK; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
733 } |
14502
8769fa370f83
Move generic length and percent pos calculation to demuxer.c
reimar
parents:
14426
diff
changeset
|
734 return DEMUXER_CTRL_DONTKNOW; |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
735 |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
736 case DEMUXER_CTRL_SWITCH_AUDIO: |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
737 if (mpg_d && mpg_d->num_a_streams > 1 && demuxer->audio && demuxer->audio->sh) { |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
738 demux_stream_t *d_audio = demuxer->audio; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
739 sh_audio_t *sh_audio = d_audio->sh; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
740 sh_audio_t *sh_a; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
741 int i; |
15285
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
742 if (*((int*)arg) < 0) |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
743 { |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
744 for (i = 0; i < mpg_d->num_a_streams; i++) { |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
745 if (d_audio->id == mpg_d->a_stream_ids[i]) break; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
746 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
747 do { |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
748 i = (i+1) % mpg_d->num_a_streams; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
749 sh_a = (sh_audio_t*)demuxer->a_streams[mpg_d->a_stream_ids[i]]; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
750 } while (sh_a->format != sh_audio->format); |
15285
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
751 } |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
752 else { |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
753 for (i = 0; i < mpg_d->num_a_streams; i++) |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
754 if (*((int*)arg) == mpg_d->a_stream_ids[i]) break; |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
755 if (i < mpg_d->num_a_streams) |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
756 sh_a = (sh_audio_t*)demuxer->a_streams[*((int*)arg)]; |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
757 if (sh_a->format != sh_audio->format) |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
758 i = mpg_d->num_a_streams; |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
759 } |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
760 if (i < mpg_d->num_a_streams && d_audio->id != mpg_d->a_stream_ids[i]) { |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
761 d_audio->id = mpg_d->a_stream_ids[i]; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
762 d_audio->sh = sh_a; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
763 ds_free_packs(d_audio); |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
764 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
765 } |
15285
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
766 *((int*)arg) = demuxer->audio->id; |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
767 return DEMUXER_CTRL_OK; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
768 |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
769 default: |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
770 return DEMUXER_CTRL_NOTIMPL; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
771 } |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
772 } |
16175 | 773 |
774 | |
775 static int demux_mpg_pes_probe(demuxer_t *demuxer) { | |
776 demuxer->synced = 3; | |
777 return demux_mpg_probe(demuxer); | |
778 } | |
779 | |
780 | |
781 static demuxer_t* demux_mpg_es_open(demuxer_t* demuxer) | |
782 { | |
783 sh_video_t *sh_video=NULL; | |
784 | |
785 demuxer->audio->sh = NULL; // ES streams has no audio channel | |
786 demuxer->video->sh = new_sh_video(demuxer,0); // create dummy video stream header, id=0 | |
787 sh_video=demuxer->video->sh;sh_video->ds=demuxer->video; | |
788 | |
789 return demuxer; | |
790 } | |
791 | |
792 | |
793 static demuxer_t* demux_mpg_ps_open(demuxer_t* demuxer) | |
794 { | |
795 sh_audio_t *sh_audio=NULL; | |
796 sh_video_t *sh_video=NULL; | |
797 | |
798 sh_video=demuxer->video->sh;sh_video->ds=demuxer->video; | |
799 | |
800 if(demuxer->audio->id!=-2) { | |
801 if(!ds_fill_buffer(demuxer->audio)){ | |
802 mp_msg(MSGT_DEMUXER,MSGL_INFO,"MPEG: " MSGTR_MissingAudioStream); | |
803 demuxer->audio->sh=NULL; | |
804 } else { | |
805 sh_audio=demuxer->audio->sh;sh_audio->ds=demuxer->audio; | |
806 } | |
807 } | |
808 | |
809 return demuxer; | |
810 } | |
811 | |
812 | |
813 demuxer_desc_t demuxer_desc_mpeg_ps = { | |
814 "MPEG PS demuxer", | |
815 "mpegps", | |
816 "MPEG-PS", | |
817 "Arpi?", | |
818 "Mpeg", | |
819 DEMUXER_TYPE_MPEG_PS, | |
820 0, // unsafe autodetect | |
821 demux_mpg_probe, | |
822 demux_mpg_fill_buffer, | |
823 demux_mpg_ps_open, | |
824 demux_close_mpg, | |
825 demux_seek_mpg, | |
826 NULL | |
827 }; | |
828 | |
829 | |
830 demuxer_desc_t demuxer_desc_mpeg_pes = { | |
831 "MPEG PES demuxer", | |
832 "mpegpes", | |
833 "MPEG-PES", | |
834 "Arpi?", | |
835 "Mpeg", | |
836 DEMUXER_TYPE_MPEG_PES, | |
837 0, // unsafe autodetect | |
838 demux_mpg_pes_probe, | |
839 demux_mpg_fill_buffer, | |
840 NULL, | |
841 demux_close_mpg, | |
842 demux_seek_mpg, | |
843 NULL | |
844 }; | |
845 | |
846 | |
847 demuxer_desc_t demuxer_desc_mpeg_es = { | |
848 "MPEG ES demuxer", | |
849 "mpeges", | |
850 "MPEG-ES", | |
851 "Arpi?", | |
852 "Mpeg", | |
853 DEMUXER_TYPE_MPEG_ES, | |
854 0, // hack autodetection | |
855 NULL, | |
856 demux_mpg_es_fill_buffer, | |
857 demux_mpg_es_open, | |
858 demux_close_mpg, | |
859 demux_seek_mpg, | |
860 NULL | |
861 }; | |
862 | |
863 | |
864 demuxer_desc_t demuxer_desc_mpeg4_es = { | |
865 "MPEG4 ES demuxer", | |
866 "mpeg4es", | |
867 "MPEG-ES", | |
868 "Arpi?", | |
869 "Mpeg", | |
870 DEMUXER_TYPE_MPEG4_ES, | |
871 0, // hack autodetection | |
872 NULL, | |
873 demux_mpg_es_fill_buffer, | |
874 demux_mpg_es_open, | |
875 demux_close_mpg, | |
876 demux_seek_mpg, | |
877 NULL | |
878 }; | |
879 | |
880 | |
881 demuxer_desc_t demuxer_desc_h264_es = { | |
882 "H.264 ES demuxer", | |
883 "h264es", | |
884 "H264-ES", | |
885 "Arpi?", | |
886 "Mpeg", | |
887 DEMUXER_TYPE_H264_ES, | |
888 0, // hack autodetection | |
889 NULL, | |
890 demux_mpg_es_fill_buffer, | |
891 demux_mpg_es_open, | |
892 demux_close_mpg, | |
893 demux_seek_mpg, | |
894 NULL | |
895 }; |