Mercurial > mplayer.hg
annotate libmpdemux/demux_mpg.c @ 22540:52c574919687
Fix live555 compilation when stream cache is disabled.
based on patch by Gianluigi Tiesi, mplayer netfarm it
author | diego |
---|---|
date | Tue, 13 Mar 2007 23:35:00 +0000 |
parents | a46ab26b2d5e |
children | 4d81dbdf46b9 |
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> |
22036 | 6 #include <math.h> |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
7 |
1567 | 8 #include "config.h" |
9 #include "mp_msg.h" | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1735
diff
changeset
|
10 #include "help_mp.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
11 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
12 #include "stream.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
13 #include "demuxer.h" |
1466 | 14 #include "parse_es.h" |
2338 | 15 #include "stheader.h" |
4711 | 16 #include "mp3_hdr.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
17 |
524
9105fc95636c
A fast'n'ugly hack to correct DVD VOB playback problems
lgb
parents:
501
diff
changeset
|
18 //#define MAX_PS_PACKETSIZE 2048 |
501 | 19 #define MAX_PS_PACKETSIZE (224*1024) |
20 | |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
21 #define UNKNOWN 0 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
22 #define VIDEO_MPEG1 0x10000001 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
23 #define VIDEO_MPEG2 0x10000002 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
24 #define VIDEO_MPEG4 0x10000004 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
25 #define VIDEO_H264 0x10000005 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
26 #define AUDIO_MP2 0x50 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
27 #define AUDIO_A52 0x2000 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
28 #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
|
29 #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
|
30 |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
31 typedef struct mpg_demuxer { |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
32 float last_pts; |
22021
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
33 float first_pts; // first pts found in stream |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
34 float first_to_final_pts_len; // difference between final pts and first pts |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
35 int has_valid_timestamps; // !=0 iff time stamps look linear |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
36 // (not necessarily starting with 0) |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
37 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
|
38 int num_a_streams; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
39 int a_stream_ids[MAX_A_STREAMS]; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
40 } mpg_demuxer_t; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
41 |
17286
b0046966ab82
don't reset dvdsub->id unless -slang is specified; assign default sub stream id when demux->sub->id is -1 (autodetect)
nicodvb
parents:
16877
diff
changeset
|
42 extern char* dvdsub_lang; |
547 | 43 static int mpeg_pts_error=0; |
22037
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
44 off_t ps_probe = 0; |
547 | 45 |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 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
|
50 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
51 mp_dbg(MSGT_DEMUX,MSGL_V, "PARSE_PSM, len=%d\n", len); |
18549
845f94a75729
psm longer than 1018 bytes is not allowed, thus invalid
nicodvb
parents:
18382
diff
changeset
|
52 if(! len || len > 1018) |
14923
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 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
|
56 if(! (c & 0x80)) { |
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, 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
|
58 return 0; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
59 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 es_map_len = stream_read_word(demux->stream); //length of elementary streams map |
21531
a90aa203186c
Get rid of min/max macros from aviheader.h, they do not belong here.
reimar
parents:
20872
diff
changeset
|
64 es_map_len = FFMIN(es_map_len, len - prog_len - 8); //sanity check |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
65 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
|
66 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
|
67 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
|
68 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
|
69 int idoffset = id - 0xB0; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
70 switch(type) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
71 case 0x1: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
72 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
|
73 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
74 case 0x2: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
75 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
|
76 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
77 case 0x3: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
78 case 0x4: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
79 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
|
80 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
81 case 0x0f: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
82 case 0x11: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
83 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
|
84 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
85 case 0x10: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
86 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
|
87 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
88 case 0x1b: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
89 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
|
90 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
91 case 0x81: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
92 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
|
93 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
94 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
95 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
|
96 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
97 plen = stream_read_word(demux->stream); //length of elementary stream descriptors |
21531
a90aa203186c
Get rid of min/max macros from aviheader.h, they do not belong here.
reimar
parents:
20872
diff
changeset
|
98 plen = FFMIN(plen, es_map_len); //sanity check |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
99 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
|
100 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
|
101 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
102 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
|
103 return 1; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
104 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
105 |
18072
284751bccd04
make sure the check for valid timestamps does not accidentially search through
reimar
parents:
17822
diff
changeset
|
106 // 500000 is a wild guess |
284751bccd04
make sure the check for valid timestamps does not accidentially search through
reimar
parents:
17822
diff
changeset
|
107 #define TIMESTAMP_PROBE_LEN 500000 |
284751bccd04
make sure the check for valid timestamps does not accidentially search through
reimar
parents:
17822
diff
changeset
|
108 |
22021
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
109 //MAX_PTS_DIFF_FOR_CONSECUTIVE denotes the maximum difference |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
110 //between two pts to consider them consecutive |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
111 //1.0 is a wild guess |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
112 #define MAX_PTS_DIFF_FOR_CONSECUTIVE 1.0 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
113 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
114 //returns the first pts found within TIME_STAMP_PROBE_LEN bytes after stream_pos in demuxer's stream. |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
115 //if no pts is found or an error occurs, -1.0 is returned. |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
116 //Packs are freed. |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
117 static float read_first_mpeg_pts_at_position(demuxer_t* demuxer, off_t stream_pos) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
118 { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
119 stream_t *s = demuxer->stream; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
120 mpg_demuxer_t *mpg_d = demuxer->priv; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
121 float pts = -1.0; //the pts to return; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
122 float found_pts1; //the most recently found pts |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
123 float found_pts2; //the pts found before found_pts1 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
124 float found_pts3; //the pts found before found_pts2 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
125 int found = 0; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
126 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
127 if(!mpg_d || stream_pos < 0) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
128 return pts; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
129 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
130 found_pts3 = found_pts2 = found_pts1 = mpg_d->last_pts; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
131 stream_seek(s, stream_pos); |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
132 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
133 //We look for pts. |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
134 //However, we do not stop at the first found one, as timestamps may reset |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
135 //Therefore, we seek until we found three consecutive |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
136 //pts within MAX_PTS_DIFF_FOR_CONSECUTIVE. |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
137 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
138 while(found<3 && !s->eof |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
139 && (fabsf(found_pts2-found_pts1) < MAX_PTS_DIFF_FOR_CONSECUTIVE) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
140 && (fabsf(found_pts3-found_pts2) < MAX_PTS_DIFF_FOR_CONSECUTIVE) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
141 && (stream_tell(s) < stream_pos + TIMESTAMP_PROBE_LEN) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
142 && ds_fill_buffer(demuxer->video)) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
143 { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
144 if(mpg_d->last_pts != found_pts1) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
145 { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
146 if(!found) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
147 found_pts3 = found_pts2 = found_pts1 = mpg_d->last_pts; //the most recently found pts |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
148 else |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
149 { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
150 found_pts3 = found_pts2; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
151 found_pts2 = found_pts1; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
152 found_pts1 = mpg_d->last_pts; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
153 } |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
154 found++; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
155 } |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
156 } |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
157 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
158 if(found == 3) pts = found_pts3; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
159 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
160 //clean up from searching of first pts; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
161 ds_free_packs(demuxer->audio); |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
162 ds_free_packs(demuxer->video); |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
163 ds_free_packs(demuxer->sub); |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
164 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
165 return pts; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
166 } |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
167 |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
168 /// Open an mpg physical stream |
16175 | 169 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
|
170 stream_t *s = demuxer->stream; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
171 mpg_demuxer_t* mpg_d; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
172 |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
173 if (!ds_fill_buffer(demuxer->video)) return 0; |
18885 | 174 mpg_d = calloc(1,sizeof(mpg_demuxer_t)); |
22021
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
175 if(mpg_d) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
176 { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
177 demuxer->priv = mpg_d; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
178 mpg_d->last_pts = -1.0; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
179 mpg_d->first_pts = -1.0; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
180 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
181 //if seeking is allowed set has_valid_timestamps if appropriate |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
182 if(demuxer->seekable |
22363
03ba33feaae9
test the continuity of timestamps for STREAMTYPE_VCD, too; patch by Zuxy Meng
nicodvb
parents:
22352
diff
changeset
|
183 && (demuxer->stream->type == STREAMTYPE_FILE |
03ba33feaae9
test the continuity of timestamps for STREAMTYPE_VCD, too; patch by Zuxy Meng
nicodvb
parents:
22352
diff
changeset
|
184 || demuxer->stream->type == STREAMTYPE_VCD) |
22021
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
185 && demuxer->movi_start != demuxer-> movi_end |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
186 ) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
187 { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
188 //We seek to the beginning of the stream, to somewhere in the |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
189 //middle, and to the end of the stream, while remembering the pts |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
190 //at each of the three positions. With these pts, we check whether |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
191 //or not the pts are "linear enough" to justify seeking by the pts |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
192 //of the stream |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
193 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
194 //The position where the stream is now |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
195 off_t pos = stream_tell(s); |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
196 float first_pts = read_first_mpeg_pts_at_position(demuxer, demuxer->movi_start); |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
197 if(first_pts != -1.0) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
198 { |
22351
1f40a27bd2ad
100000l: average != semidistance, fixed seeking to the middle position; patch by Zuxy meng (zuxy.megn gmail com)
nicodvb
parents:
22170
diff
changeset
|
199 float middle_pts = read_first_mpeg_pts_at_position(demuxer, (demuxer->movi_end + demuxer->movi_start)/2); |
22021
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
200 if(middle_pts != -1.0) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
201 { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
202 float final_pts = read_first_mpeg_pts_at_position(demuxer, demuxer->movi_end - TIMESTAMP_PROBE_LEN); |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
203 if(final_pts != -1.0) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
204 { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
205 // found proper first, middle, and final pts. |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
206 float proportion = (middle_pts-first_pts==0) ? -1 : (final_pts-middle_pts)/(middle_pts-first_pts); |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
207 // if they are linear enough set has_valid_timestamps |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
208 if((0.5 < proportion) && (proportion < 2)) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
209 { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
210 mpg_d->first_pts = first_pts; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
211 mpg_d->first_to_final_pts_len = final_pts - first_pts; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
212 mpg_d->has_valid_timestamps = 1; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
213 } |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
214 } |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
215 } |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
216 } |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
217 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
218 //Cleaning up from seeking in stream |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
219 demuxer->stream->eof=0; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
220 demuxer->video->eof=0; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
221 demuxer->audio->eof=0; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
222 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
223 stream_seek(s,pos); |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
224 ds_fill_buffer(demuxer->video); |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
225 } // if ( demuxer->seekable ) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
226 } // if ( mpg_d ) |
16175 | 227 return demuxer; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
228 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
229 |
16175 | 230 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
|
231 mpg_demuxer_t* mpg_d = demuxer->priv; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
232 if (mpg_d) free(mpg_d); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
233 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
234 |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
235 |
18077
cede662f40a5
timestamps are 33 bits long, so they don't fit in an unsigned int; 10l
nicodvb
parents:
18072
diff
changeset
|
236 static unsigned long long read_mpeg_timestamp(stream_t *s,int c){ |
18381 | 237 unsigned int d,e; |
18077
cede662f40a5
timestamps are 33 bits long, so they don't fit in an unsigned int; 10l
nicodvb
parents:
18072
diff
changeset
|
238 unsigned long long pts; |
1 | 239 d=stream_read_word(s); |
240 e=stream_read_word(s); | |
547 | 241 if( ((c&1)!=1) || ((d&1)!=1) || ((e&1)!=1) ){ |
242 ++mpeg_pts_error; | |
243 return 0; // invalid pts | |
244 } | |
18380
841789620ed1
in read_mpeg_timestamp() cast int expression to uint64_t before shifting to avoid truncation of bits and to prevent propagation of bit 1 as sign bit in pts
nicodvb
parents:
18077
diff
changeset
|
245 pts=(((uint64_t)((c>>1)&7))<<30)|((d>>1)<<15)|(e>>1); |
18382 | 246 mp_dbg(MSGT_DEMUX,MSGL_DBG3," pts {%"PRIu64"}",pts); |
1 | 247 return pts; |
248 } | |
249 | |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
250 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
|
251 if(!demux->a_streams[aid]){ |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
252 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
|
253 sh_audio_t* sh_a; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
254 new_sh_audio(demux,aid); |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 } |
21927
ee422890bca9
in evo files [e]ac3 substreams range from 0xc0 to 0xcf
nicodvb
parents:
21919
diff
changeset
|
262 //evo files |
21934 | 263 if((aid & 0xC0) == 0xC0) sh_a->format=0x2000; |
22170 | 264 else if(aid >= 0x98 && aid <= 0x9f) sh_a->format=0x2001; |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
265 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
|
266 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
267 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
|
268 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
269 |
1 | 270 static int demux_mpg_read_packet(demuxer_t *demux,int id){ |
271 int d; | |
272 int len; | |
21978
1dbe952f3b56
set priv->last_pts to the pts read only if the pts was really read; patch by zaek7q gmx net (Christian Aistleitner)
nicodvb
parents:
21948
diff
changeset
|
273 int set_pts=0; // !=0 iff pts has been set to a proper value |
1 | 274 unsigned char c=0; |
18077
cede662f40a5
timestamps are 33 bits long, so they don't fit in an unsigned int; 10l
nicodvb
parents:
18072
diff
changeset
|
275 unsigned long long pts=0; |
cede662f40a5
timestamps are 33 bits long, so they don't fit in an unsigned int; 10l
nicodvb
parents:
18072
diff
changeset
|
276 unsigned long long dts=0; |
21781
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
277 int l; |
21948
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
278 int pes_ext2_subid=-1; |
21781
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
279 double stream_pts = MP_NOPTS_VALUE; |
1 | 280 demux_stream_t *ds=NULL; |
21781
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
281 demux_packet_t* dp; |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
282 mpg_demuxer_t *priv = (mpg_demuxer_t *) demux->priv; |
1 | 283 |
1567 | 284 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"demux_read_packet: %X\n",id); |
1 | 285 |
536 | 286 // if(id==0x1F0){ |
287 // demux->synced=0; // force resync after 0x1F0 | |
288 // return -1; | |
289 //} | |
501 | 290 |
1 | 291 // if(id==0x1BA) packet_start_pos=stream_tell(demux->stream); |
21948
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
292 if((id<0x1BC || id>=0x1F0) && id != 0x1FD) return -1; |
1 | 293 if(id==0x1BE) return -1; // padding stream |
294 if(id==0x1BF) return -1; // private2 | |
295 | |
296 len=stream_read_word(demux->stream); | |
1567 | 297 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"PACKET len=%d",len); |
536 | 298 // if(len==62480){ demux->synced=0;return -1;} /* :) */ |
501 | 299 if(len==0 || len>MAX_PS_PACKETSIZE){ |
1567 | 300 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Invalid PS packet len: %d\n",len); |
501 | 301 return -2; // invalid packet !!!!!! |
302 } | |
1 | 303 |
547 | 304 mpeg_pts_error=0; |
305 | |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
306 if(id==0x1BC) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
307 parse_psm(demux, len); |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
308 return 0; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
309 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
310 |
1 | 311 while(len>0){ // Skip stuFFing bytes |
312 c=stream_read_char(demux->stream);--len; | |
313 if(c!=0xFF)break; | |
314 } | |
315 if((c>>6)==1){ // Read (skip) STD scale & size value | |
316 // printf(" STD_scale=%d",(c>>5)&1); | |
317 d=((c&0x1F)<<8)|stream_read_char(demux->stream); | |
318 len-=2; | |
319 // printf(" STD_size=%d",d); | |
320 c=stream_read_char(demux->stream); | |
321 } | |
322 // Read System-1 stream timestamps: | |
323 if((c>>4)==2){ | |
324 pts=read_mpeg_timestamp(demux->stream,c); | |
21978
1dbe952f3b56
set priv->last_pts to the pts read only if the pts was really read; patch by zaek7q gmx net (Christian Aistleitner)
nicodvb
parents:
21948
diff
changeset
|
325 set_pts=1; |
1 | 326 len-=4; |
327 } else | |
328 if((c>>4)==3){ | |
329 pts=read_mpeg_timestamp(demux->stream,c); | |
330 c=stream_read_char(demux->stream); | |
331 if((c>>4)!=1) pts=0; //printf("{ERROR4}"); | |
21978
1dbe952f3b56
set priv->last_pts to the pts read only if the pts was really read; patch by zaek7q gmx net (Christian Aistleitner)
nicodvb
parents:
21948
diff
changeset
|
332 else set_pts = 1; |
1 | 333 dts=read_mpeg_timestamp(demux->stream,c); |
334 len-=4+1+4; | |
335 } else | |
336 if((c>>6)==2){ | |
337 int pts_flags; | |
338 int hdrlen; | |
21948
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
339 int parse_ext2; |
1 | 340 // System-2 (.VOB) stream: |
341 c=stream_read_char(demux->stream); pts_flags=c>>6; | |
21948
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
342 parse_ext2 = (id == 0x1FD) && ((c & 0x3F) == 1); |
1 | 343 c=stream_read_char(demux->stream); hdrlen=c; |
344 len-=2; | |
1567 | 345 mp_dbg(MSGT_DEMUX,MSGL_DBG3," hdrlen=%d (len=%d)",hdrlen,len); |
346 if(hdrlen>len){ mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: invalid header length \n"); return -1;} | |
7671 | 347 if(pts_flags==2 && hdrlen>=5){ |
1 | 348 c=stream_read_char(demux->stream); |
349 pts=read_mpeg_timestamp(demux->stream,c); | |
21978
1dbe952f3b56
set priv->last_pts to the pts read only if the pts was really read; patch by zaek7q gmx net (Christian Aistleitner)
nicodvb
parents:
21948
diff
changeset
|
350 set_pts=1; |
1 | 351 len-=5;hdrlen-=5; |
352 } else | |
7671 | 353 if(pts_flags==3 && hdrlen>=10){ |
1 | 354 c=stream_read_char(demux->stream); |
355 pts=read_mpeg_timestamp(demux->stream,c); | |
21978
1dbe952f3b56
set priv->last_pts to the pts read only if the pts was really read; patch by zaek7q gmx net (Christian Aistleitner)
nicodvb
parents:
21948
diff
changeset
|
356 set_pts=1; |
1 | 357 c=stream_read_char(demux->stream); |
358 dts=read_mpeg_timestamp(demux->stream,c); | |
359 len-=10;hdrlen-=10; | |
360 } | |
361 len-=hdrlen; | |
21948
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
362 if(hdrlen>0) { |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
363 if(!parse_ext2) |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
364 stream_skip(demux->stream,hdrlen); // skip header bytes |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
365 else if(hdrlen>=3) { |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
366 c=stream_read_char(demux->stream); |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
367 hdrlen--; |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
368 if(c != 0x1F && c!= 0x0F) { mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: invalid pes_extension field \n"); return -1;} |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
369 if(c == 0x1F) { |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
370 //STD |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
371 stream_skip(demux->stream, 2); |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
372 hdrlen-=2; |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
373 } |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
374 c=stream_read_char(demux->stream); //pes_extension2 flag |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
375 hdrlen--; |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
376 if(c!=0x81) { mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: unknown pes_extension2 format, len is > 1 \n"); return -1;} |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
377 c=stream_read_char(demux->stream); //pes_extension2 payload === substream id |
21979
20a9ec250b4f
substream 0x75 doesn't seem to be a valid vc1 stream, after all; removed
nicodvb
parents:
21978
diff
changeset
|
378 if(c<0x55 || c>0x5F) { mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: unknown vc1 substream_id: 0x%x \n", c); return -1;} |
21948
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
379 pes_ext2_subid=c; |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
380 } |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
381 } |
1 | 382 |
21948
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
383 if(id==0x1FD && pes_ext2_subid!=-1) { |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
384 //==== EVO VC1 STREAMS ===// |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
385 if(!demux->v_streams[pes_ext2_subid]) new_sh_video(demux,pes_ext2_subid); |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
386 if(demux->video->id==-1) demux->video->id=pes_ext2_subid; |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
387 if(demux->video->id==pes_ext2_subid){ |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
388 ds=demux->video; |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
389 if(!ds->sh) ds->sh=demux->v_streams[pes_ext2_subid]; |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
390 if(priv && ds->sh) { |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
391 sh_video_t *sh = (sh_video_t *)ds->sh; |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
392 sh->format = mmioFOURCC('W', 'V', 'C', '1'); |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
393 } |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
394 } |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
395 } |
1 | 396 //============== DVD Audio sub-stream ====================== |
397 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
|
398 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
|
399 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
|
400 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
|
401 |
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
|
402 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
|
403 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
|
404 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
|
405 /// 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
|
406 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
|
407 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
|
408 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
|
409 } |
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
|
410 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
|
411 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
|
412 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
|
413 } |
552 | 414 |
415 // AID: | |
416 // 0x20..0x3F subtitle | |
417 // 0x80..0x9F AC3 audio | |
418 // 0xA0..0xBF PCM audio | |
419 | |
420 if((aid & 0xE0) == 0x20){ | |
421 // subtitle: | |
422 aid&=0x1F; | |
426 | 423 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
424 if(!demux->s_streams[aid]){ |
1567 | 425 mp_msg(MSGT_DEMUX,MSGL_V,"==> Found subtitle: %d\n",aid); |
20872
a8b42366e68a
Make subtitle stream handling more similar to audio and video streams.
reimar
parents:
20851
diff
changeset
|
426 new_sh_sub(demux, aid); |
552 | 427 } |
428 | |
17286
b0046966ab82
don't reset dvdsub->id unless -slang is specified; assign default sub stream id when demux->sub->id is -1 (autodetect)
nicodvb
parents:
16877
diff
changeset
|
429 if(demux->sub->id > -1) |
b0046966ab82
don't reset dvdsub->id unless -slang is specified; assign default sub stream id when demux->sub->id is -1 (autodetect)
nicodvb
parents:
16877
diff
changeset
|
430 demux->sub->id &= 0x1F; |
b0046966ab82
don't reset dvdsub->id unless -slang is specified; assign default sub stream id when demux->sub->id is -1 (autodetect)
nicodvb
parents:
16877
diff
changeset
|
431 if(!dvdsub_lang && demux->sub->id == -1) |
b0046966ab82
don't reset dvdsub->id unless -slang is specified; assign default sub stream id when demux->sub->id is -1 (autodetect)
nicodvb
parents:
16877
diff
changeset
|
432 demux->sub->id = aid; |
552 | 433 if(demux->sub->id==aid){ |
434 ds=demux->sub; | |
435 } | |
436 | |
21927
ee422890bca9
in evo files [e]ac3 substreams range from 0xc0 to 0xcf
nicodvb
parents:
21919
diff
changeset
|
437 } else if((aid & 0xC0) == 0x80 || (aid & 0xE0) == 0x00 || (aid & 0xC0) == 0xC0) { |
552 | 438 |
439 // aid=128+(aid&0x7F); | |
440 // aid=0x80..0xBF | |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
441 new_audio_stream(demux, aid); |
426 | 442 if(demux->audio->id==aid){ |
7671 | 443 int type; |
426 | 444 ds=demux->audio; |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
445 if(!ds->sh) ds->sh=demux->a_streams[aid]; |
1 | 446 // 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
|
447 if(!rawa52) { |
7671 | 448 c=stream_read_char(demux->stream);//num of frames |
449 type=stream_read_char(demux->stream);//startpos hi | |
450 type=(type<<8)|stream_read_char(demux->stream);//startpos lo | |
451 // printf("\r[%02X][%04X]",c,type); | |
1 | 452 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
|
453 } |
7671 | 454 if((aid&0xE0)==0xA0 && len>=3){ |
455 unsigned char* hdr; | |
456 // save audio header as codecdata! | |
457 if(!((sh_audio_t*)(ds->sh))->codecdata_len){ | |
458 ((sh_audio_t*)(ds->sh))->codecdata=malloc(3); | |
459 ((sh_audio_t*)(ds->sh))->codecdata_len=3; | |
460 } | |
461 hdr=((sh_audio_t*)(ds->sh))->codecdata; | |
462 // read LPCM header: | |
463 // emphasis[1], mute[1], rvd[1], frame number[5]: | |
464 hdr[0]=stream_read_char(demux->stream); | |
465 // printf(" [%01X:%02d]",c>>5,c&31); | |
466 // quantization[2],freq[2],rvd[1],channels[3] | |
467 hdr[1]=stream_read_char(demux->stream); | |
468 // printf("[%01X:%01X] ",c>>4,c&15); | |
469 // dynamic range control (0x80=off): | |
470 hdr[2]=stream_read_char(demux->stream); | |
471 // printf("[%02X] ",c); | |
472 len-=3; | |
473 if(len<=0) mp_msg(MSGT_DEMUX,MSGL_V,"End of packet while searching for PCM header\n"); | |
1 | 474 } |
7671 | 475 // printf(" \n"); |
552 | 476 } // if(demux->audio->id==aid) |
477 | |
1567 | 478 } else mp_msg(MSGT_DEMUX,MSGL_V,"Unknown 0x1BD substream: 0x%02X \n",aid); |
552 | 479 |
480 } //if(id==0x1BD) | |
1 | 481 |
482 } else { | |
539 | 483 if(c!=0x0f){ |
1567 | 484 mp_msg(MSGT_DEMUX,MSGL_V," {ERROR5,c=%d} \n",c); |
539 | 485 return -1; // invalid packet !!!!!! |
486 } | |
1 | 487 } |
1567 | 488 if(mpeg_pts_error) mp_msg(MSGT_DEMUX,MSGL_V," {PTS_err:%d} \n",mpeg_pts_error); |
489 mp_dbg(MSGT_DEMUX,MSGL_DBG3," => len=%d\n",len); | |
1 | 490 |
501 | 491 // if(len<=0 || len>MAX_PS_PACKETSIZE) return -1; // Invalid packet size |
492 if(len<=0 || len>MAX_PS_PACKETSIZE){ | |
1567 | 493 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Invalid PS data len: %d\n",len); |
501 | 494 return -1; // invalid packet !!!!!! |
495 } | |
1 | 496 |
497 if(id>=0x1C0 && id<=0x1DF){ | |
498 // mpeg audio | |
499 int aid=id-0x1C0; | |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
500 new_audio_stream(demux, aid); |
1 | 501 if(demux->audio->id==aid){ |
502 ds=demux->audio; | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
503 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
|
504 if(priv && ds->sh) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
505 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
|
506 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
|
507 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
|
508 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
|
509 } |
1 | 510 } |
511 } else | |
512 if(id>=0x1E0 && id<=0x1EF){ | |
513 // mpeg video | |
514 int aid=id-0x1E0; | |
1289 | 515 if(!demux->v_streams[aid]) new_sh_video(demux,aid); |
1 | 516 if(demux->video->id==-1) demux->video->id=aid; |
426 | 517 if(demux->video->id==aid){ |
518 ds=demux->video; | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
519 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
|
520 if(priv && ds->sh) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
521 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
|
522 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
|
523 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
|
524 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
|
525 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
526 } |
426 | 527 } |
1 | 528 } |
529 | |
530 if(ds){ | |
1567 | 531 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_MPG: Read %d data bytes from packet %04X\n",len,id); |
1 | 532 // printf("packet start = 0x%X \n",stream_tell(demux->stream)-packet_start_pos); |
21781
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
533 |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
534 dp=new_demux_packet(len); |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
535 if(!dp) { |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
536 mp_dbg(MSGT_DEMUX,MSGL_ERR,"DEMUX_MPG ERROR: couldn't create demux_packet(%d bytes)\n",len); |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
537 stream_skip(demux->stream,len); |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
538 return 0; |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
539 } |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
540 l = stream_read(demux->stream,dp->buffer,len); |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
541 if(l<len) |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
542 resize_demux_packet(dp, l); |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
543 len = l; |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
544 dp->pts=pts/90000.0f; |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
545 dp->pos=demux->filepos; |
21789
b266f27109a6
set dp->stream_pts only when feeding the video stream to workaround
nicodvb
parents:
21781
diff
changeset
|
546 /* |
b266f27109a6
set dp->stream_pts only when feeding the video stream to workaround
nicodvb
parents:
21781
diff
changeset
|
547 workaround: |
b266f27109a6
set dp->stream_pts only when feeding the video stream to workaround
nicodvb
parents:
21781
diff
changeset
|
548 set dp->stream_pts only when feeding the video stream, or strangely interleaved files |
b266f27109a6
set dp->stream_pts only when feeding the video stream to workaround
nicodvb
parents:
21781
diff
changeset
|
549 (such as SWIII) will show strange alternations in the stream time, wildly going |
b266f27109a6
set dp->stream_pts only when feeding the video stream to workaround
nicodvb
parents:
21781
diff
changeset
|
550 back and forth |
b266f27109a6
set dp->stream_pts only when feeding the video stream to workaround
nicodvb
parents:
21781
diff
changeset
|
551 */ |
b266f27109a6
set dp->stream_pts only when feeding the video stream to workaround
nicodvb
parents:
21781
diff
changeset
|
552 if(ds == demux->video && stream_control(demux->stream, STREAM_CTRL_GET_CURRENT_TIME,(void *)&stream_pts)!=STREAM_UNSUPORTED) |
21781
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
553 dp->stream_pts = stream_pts; |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
554 ds_add_packet(ds,dp); |
21978
1dbe952f3b56
set priv->last_pts to the pts read only if the pts was really read; patch by zaek7q gmx net (Christian Aistleitner)
nicodvb
parents:
21948
diff
changeset
|
555 if (demux->priv && set_pts) ((mpg_demuxer_t*)demux->priv)->last_pts = pts/90000.0f; |
554 | 556 // if(ds==demux->sub) parse_dvdsub(ds->last->buffer,ds->last->len); |
1 | 557 return 1; |
558 } | |
1567 | 559 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_MPG: Skipping %d data bytes from packet %04X\n",len,id); |
536 | 560 if(len<=2356) stream_skip(demux->stream,len); |
1 | 561 return 0; |
562 } | |
563 | |
15670 | 564 static int num_elementary_packets100=0; |
565 static int num_elementary_packets101=0; | |
566 static int num_elementary_packets12x=0; | |
567 static int num_elementary_packets1B6=0; | |
568 static int num_elementary_packetsPES=0; | |
569 static int num_h264_slice=0; //combined slice | |
570 static int num_h264_dpa=0; //DPA Slice | |
571 static int num_h264_dpb=0; //DPB Slice | |
572 static int num_h264_dpc=0; //DPC Slice | |
573 static int num_h264_idr=0; //IDR Slice | |
574 static int num_h264_sps=0; | |
575 static int num_h264_pps=0; | |
576 | |
577 static int num_mp3audio_packets=0; | |
578 | |
22034
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
579 static void clear_stats() |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
580 { |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
581 num_elementary_packets100=0; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
582 num_elementary_packets101=0; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
583 num_elementary_packets1B6=0; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
584 num_elementary_packets12x=0; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
585 num_elementary_packetsPES=0; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
586 num_h264_slice=0; //combined slice |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
587 num_h264_dpa=0; //DPA Slice |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
588 num_h264_dpb=0; //DPB Slice |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
589 num_h264_dpc=0; //DPC Slice |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
590 num_h264_idr=0; //IDR Slice |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
591 num_h264_sps=0; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
592 num_h264_pps=0; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
593 num_mp3audio_packets=0; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
594 } |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
595 |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
596 //assumes demuxer->synced < 2 |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
597 static inline void update_stats(int head) |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
598 { |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
599 if(head==0x1B6) ++num_elementary_packets1B6; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
600 else if(head==0x100) ++num_elementary_packets100; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
601 else if(head==0x101) ++num_elementary_packets101; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
602 else if(head==0x1BD || (0x1C0<=head && head<=0x1EF)) |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
603 num_elementary_packetsPES++; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
604 else if(head>=0x120 && head<=0x12F) ++num_elementary_packets12x; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
605 else if(head>=0x100 && head<0x1B0) |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
606 { |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
607 if((head&~0x60) == 0x101) ++num_h264_slice; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
608 else if((head&~0x60) == 0x102) ++num_h264_dpa; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
609 else if((head&~0x60) == 0x103) ++num_h264_dpb; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
610 else if((head&~0x60) == 0x104) ++num_h264_dpc; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
611 else if((head&~0x60) == 0x105 && head != 0x105) ++num_h264_idr; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
612 else if((head&~0x60) == 0x107 && head != 0x107) ++num_h264_sps; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
613 else if((head&~0x60) == 0x108 && head != 0x108) ++num_h264_pps; |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
614 } |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
615 } |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
616 |
16175 | 617 static int demux_mpg_probe(demuxer_t *demuxer) { |
15670 | 618 int pes=1; |
619 int tmp; | |
620 off_t tmppos; | |
621 int file_format = DEMUXER_TYPE_UNKNOWN; | |
622 | |
623 tmppos=stream_tell(demuxer->stream); | |
624 tmp=stream_read_dword(demuxer->stream); | |
625 if(tmp==0x1E0 || tmp==0x1C0) { | |
626 tmp=stream_read_word(demuxer->stream); | |
627 if(tmp>1 && tmp<=2048) pes=0; // demuxer->synced=3; // PES... | |
628 } | |
629 stream_seek(demuxer->stream,tmppos); | |
630 | |
22034
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
631 clear_stats(); |
9824 | 632 |
15670 | 633 if(demux_mpg_open(demuxer)) |
634 file_format=DEMUXER_TYPE_MPEG_PS; | |
635 else { | |
636 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", | |
637 num_elementary_packets100,num_elementary_packets101, | |
638 num_elementary_packets1B6,num_elementary_packets12x, | |
639 num_h264_slice, num_h264_dpa, | |
640 num_h264_dpb, num_h264_dpc=0, | |
641 num_h264_idr, num_h264_sps=0, | |
642 num_h264_pps, | |
643 num_elementary_packetsPES,num_mp3audio_packets, demuxer->synced); | |
644 | |
645 //MPEG packet stats: p100: 458 p101: 458 PES: 0 MP3: 1103 (.m2v) | |
646 if(num_mp3audio_packets>50 && num_mp3audio_packets>2*num_elementary_packets100 | |
647 && abs(num_elementary_packets100-num_elementary_packets101)>2) | |
648 return file_format; | |
649 | |
650 // some hack to get meaningfull error messages to our unhappy users: | |
651 if(num_elementary_packets100>=2 && num_elementary_packets101>=2 && | |
652 abs(num_elementary_packets101+8-num_elementary_packets100)<16) { | |
653 if(num_elementary_packetsPES>=4 && num_elementary_packetsPES>=num_elementary_packets100-4) { | |
654 return file_format; | |
655 } | |
656 file_format=DEMUXER_TYPE_MPEG_ES; // <-- hack is here :) | |
657 } else | |
658 // fuzzy mpeg4-es detection. do NOT enable without heavy testing of mpeg formats detection! | |
659 if(num_elementary_packets1B6>3 && num_elementary_packets12x>=1 && | |
660 num_elementary_packetsPES==0 && num_elementary_packets100<=num_elementary_packets12x && | |
661 demuxer->synced<2) { | |
662 file_format=DEMUXER_TYPE_MPEG4_ES; | |
663 } else | |
664 // fuzzy h264-es detection. do NOT enable without heavy testing of mpeg formats detection! | |
665 if((num_h264_slice>3 || (num_h264_dpa>3 && num_h264_dpb>3 && num_h264_dpc>3)) && | |
666 /* FIXME num_h264_sps>=1 && */ num_h264_pps>=1 && num_h264_idr>=1 && | |
667 num_elementary_packets1B6==0 && num_elementary_packetsPES==0 && | |
668 demuxer->synced<2) { | |
669 file_format=DEMUXER_TYPE_H264_ES; | |
670 } else | |
671 { | |
672 if(demuxer->synced==2) | |
673 mp_msg(MSGT_DEMUXER,MSGL_ERR,"MPEG: " MSGTR_MissingVideoStreamBug); | |
674 else | |
675 mp_msg(MSGT_DEMUXER,MSGL_V,MSGTR_NotSystemStream); | |
676 } | |
677 } | |
22094
e2d1bb1d2c6b
demux_mpg_probe() seek to the initial position before returning - patch by reimar
nicodvb
parents:
22088
diff
changeset
|
678 //FIXME this shouldn't be necessary |
e2d1bb1d2c6b
demux_mpg_probe() seek to the initial position before returning - patch by reimar
nicodvb
parents:
22088
diff
changeset
|
679 stream_seek(demuxer->stream,tmppos); |
15670 | 680 return file_format; |
681 } | |
1 | 682 |
16175 | 683 static int demux_mpg_es_fill_buffer(demuxer_t *demux, demux_stream_t *ds){ |
1 | 684 // Elementary video stream |
685 if(demux->stream->eof) return 0; | |
686 demux->filepos=stream_tell(demux->stream); | |
1735 | 687 ds_read_packet(demux->video,demux->stream,STREAM_BUFFER_SIZE,0,demux->filepos,0); |
1 | 688 return 1; |
689 } | |
690 | |
16369 | 691 /** |
692 * \brief discard until 0x100 header and return a filled buffer | |
693 * \param b buffer-end pointer | |
694 * \param pos current pos in stream, negative since b points to end of buffer | |
695 * \param s stream to read from | |
696 * \return new position, differs from original pos when eof hit and thus | |
697 * b was modified to point to the new end of buffer | |
698 */ | |
699 static int find_end(unsigned char **b, int pos, stream_t *s) { | |
700 register int state = 0xffffffff; | |
701 unsigned char *buf = *b; | |
702 int start = pos; | |
703 int read, unused; | |
704 // search already read part | |
705 while (state != 0x100 && pos) { | |
706 state = state << 8 | buf[pos++]; | |
707 } | |
708 // continue search in stream | |
709 while (state != 0x100) { | |
710 register int c = stream_read_char(s); | |
711 if (c < 0) break; | |
712 state = state << 8 | c; | |
713 } | |
714 // modify previous header (from 0x1bc or 0x1bf to 0x100) | |
715 buf[start++] = 0; | |
716 // copy remaining buffer part to current pos | |
717 memmove(&buf[start], &buf[pos], -pos); | |
718 unused = start + -pos; // -unused bytes in buffer | |
719 read = stream_read(s, &buf[unused], -unused); | |
720 unused += read; | |
721 // fix buffer so it ends at pos == 0 (eof case) | |
722 *b = &buf[unused]; | |
723 start -= unused; | |
724 return start; | |
725 } | |
726 | |
727 /** | |
728 * This format usually uses an insane bitrate, which makes this function | |
729 * performance-critical! | |
730 * Be sure to benchmark any changes with different compiler versions. | |
731 */ | |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
732 static int demux_mpg_gxf_fill_buffer(demuxer_t *demux, demux_stream_t *ds) { |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
733 demux_packet_t *pack; |
16369 | 734 int len; |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
735 demux->filepos = stream_tell(demux->stream); |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
736 pack = new_demux_packet(STREAM_BUFFER_SIZE); |
16369 | 737 len = stream_read(demux->stream, pack->buffer, STREAM_BUFFER_SIZE); |
738 if (len <= 0) | |
17779 | 739 { |
740 free_demux_packet(pack); | |
16369 | 741 return 0; |
17779 | 742 } |
16369 | 743 { |
744 register uint32_t state = (uint32_t)demux->priv; | |
745 register int pos = -len; | |
746 unsigned char *buf = &pack->buffer[len]; | |
747 do { | |
748 state = state << 8 | buf[pos]; | |
749 if (unlikely((state | 3) == 0x1bf)) | |
750 pos = find_end(&buf, pos, demux->stream); | |
19182
c68cf9a578a8
Incorrect check in gxf demuxer leading to crash with textKO.gxf sample file
reimar
parents:
18958
diff
changeset
|
751 } while (++pos < 0); |
16369 | 752 demux->priv = (void *)state; |
753 len = buf - pack->buffer; | |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
754 } |
16369 | 755 if (len < STREAM_BUFFER_SIZE) |
756 resize_demux_packet(pack, len); | |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
757 ds_add_packet(ds, pack); |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
758 return 1; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
759 } |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
760 |
16175 | 761 int demux_mpg_fill_buffer(demuxer_t *demux, demux_stream_t *ds){ |
1 | 762 unsigned int head=0; |
763 int skipped=0; | |
5570
3a8d8c51355a
max_packs increased for some dvd with too many audio/sub
arpi
parents:
4711
diff
changeset
|
764 int max_packs=256; // 512kbyte |
1 | 765 int ret=0; |
766 | |
767 // System stream | |
768 do{ | |
769 demux->filepos=stream_tell(demux->stream); | |
18713
c6c78e77c857
workaround: at every read update demux->movi_end with stream->end_pos; needed to show the progress bar when playing dvdnav streams
nicodvb
parents:
18680
diff
changeset
|
770 #if 1 |
c6c78e77c857
workaround: at every read update demux->movi_end with stream->end_pos; needed to show the progress bar when playing dvdnav streams
nicodvb
parents:
18680
diff
changeset
|
771 //lame workaround: this is needed to show the progress bar when playing dvdnav:// |
c6c78e77c857
workaround: at every read update demux->movi_end with stream->end_pos; needed to show the progress bar when playing dvdnav streams
nicodvb
parents:
18680
diff
changeset
|
772 //(ths poor guy doesn't know teh length of the stream at startup) |
c6c78e77c857
workaround: at every read update demux->movi_end with stream->end_pos; needed to show the progress bar when playing dvdnav streams
nicodvb
parents:
18680
diff
changeset
|
773 demux->movi_end = demux->stream->end_pos; |
c6c78e77c857
workaround: at every read update demux->movi_end with stream->end_pos; needed to show the progress bar when playing dvdnav streams
nicodvb
parents:
18680
diff
changeset
|
774 #endif |
1 | 775 head=stream_read_dword(demux->stream); |
547 | 776 if((head&0xFFFFFF00)!=0x100){ |
777 // sync... | |
778 demux->filepos-=skipped; | |
779 while(1){ | |
536 | 780 int c=stream_read_char(demux->stream); |
781 if(c<0) break; //EOF | |
782 head<<=8; | |
783 if(head!=0x100){ | |
784 head|=c; | |
4711 | 785 if(mp_check_mp3_header(head)) ++num_mp3audio_packets; |
536 | 786 ++skipped; //++demux->filepos; |
787 continue; | |
788 } | |
789 head|=c; | |
790 break; | |
547 | 791 } |
792 demux->filepos+=skipped; | |
1 | 793 } |
794 if(stream_eof(demux->stream)) break; | |
795 // sure: head=0x000001XX | |
1567 | 796 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"*** head=0x%X\n",head); |
1 | 797 if(demux->synced==0){ |
3770 | 798 if(head==0x1BA) demux->synced=1; //else |
799 // if(head==0x1BD || (head>=0x1C0 && head<=0x1EF)) demux->synced=3; // PES? | |
1 | 800 } else |
801 if(demux->synced==1){ | |
929 | 802 if(head==0x1BB || head==0x1BD || (head>=0x1C0 && head<=0x1EF)){ |
1 | 803 demux->synced=2; |
17366 | 804 mp_msg(MSGT_DEMUX,MSGL_V,"system stream synced at 0x%"PRIX64" (%"PRId64")!\n",(int64_t)demux->filepos,(int64_t)demux->filepos); |
536 | 805 num_elementary_packets100=0; // requires for re-sync! |
806 num_elementary_packets101=0; // requires for re-sync! | |
1 | 807 } else demux->synced=0; |
808 } // else | |
3255
ee28577dad02
combined PS/PES sync to allow .VDR playback from stdin
arpi
parents:
2555
diff
changeset
|
809 if(demux->synced>=2){ |
1 | 810 ret=demux_mpg_read_packet(demux,head); |
811 if(!ret) | |
812 if(--max_packs==0){ | |
813 demux->stream->eof=1; | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1735
diff
changeset
|
814 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_DoesntContainSelectedStream); |
1 | 815 return 0; |
816 } | |
3255
ee28577dad02
combined PS/PES sync to allow .VDR playback from stdin
arpi
parents:
2555
diff
changeset
|
817 if(demux->synced==3) demux->synced=(ret==1)?2:0; // PES detect |
1 | 818 } else { |
22034
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
819 update_stats(head); |
22035 | 820 if(head>=0x100 && head<0x1B0) |
1567 | 821 mp_msg(MSGT_DEMUX,MSGL_DBG3,"Opps... elementary video packet found: %03X\n",head); |
22035 | 822 else if((head>=0x1C0 && head<0x1F0) || head==0x1BD) |
1567 | 823 mp_msg(MSGT_DEMUX,MSGL_DBG3,"Opps... PES packet found: %03X\n",head); |
21919 | 824 |
22035 | 825 if(((num_elementary_packets100>50 && num_elementary_packets101>50) || |
826 (num_elementary_packetsPES>50)) && skipped>4000000){ | |
1567 | 827 mp_msg(MSGT_DEMUX,MSGL_V,"sync_mpeg_ps: seems to be ES/PES stream...\n"); |
1 | 828 demux->stream->eof=1; |
829 break; | |
830 } | |
4711 | 831 if(num_mp3audio_packets>100 && num_elementary_packets100<10){ |
832 mp_msg(MSGT_DEMUX,MSGL_V,"sync_mpeg_ps: seems to be MP3 stream...\n"); | |
833 demux->stream->eof=1; | |
834 break; | |
835 } | |
1 | 836 } |
837 } while(ret!=1); | |
1567 | 838 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"demux: %d bad bytes skipped\n",skipped); |
1 | 839 if(demux->stream->eof){ |
1567 | 840 mp_msg(MSGT_DEMUX,MSGL_V,"MPEG Stream reached EOF\n"); |
1 | 841 return 0; |
842 } | |
843 return 1; | |
844 } | |
845 | |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7671
diff
changeset
|
846 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
|
847 |
17636 | 848 void demux_seek_mpg(demuxer_t *demuxer,float rel_seek_secs,float audio_delay, int flags){ |
1466 | 849 demux_stream_t *d_audio=demuxer->audio; |
850 demux_stream_t *d_video=demuxer->video; | |
851 sh_audio_t *sh_audio=d_audio->sh; | |
852 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
|
853 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
|
854 int precision = 1; |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
855 float oldpts = 0; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
856 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
|
857 float newpts = 0; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
858 off_t newpos = (flags & 1) ? demuxer->movi_start : oldpos; |
1466 | 859 |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
860 if(mpg_d) |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
861 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
|
862 newpts = (flags & 1) ? 0.0 : oldpts; |
1466 | 863 //================= seek in MPEG ========================== |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
864 //calculate the pts to seek to |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
865 if(flags & 2) { |
22021
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
866 if (mpg_d && mpg_d->first_to_final_pts_len > 0.0) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
867 newpts += mpg_d->first_to_final_pts_len * rel_seek_secs; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
868 else |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
869 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
|
870 } else |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
871 newpts += rel_seek_secs; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
872 if (newpts < 0) newpts = 0; |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
873 |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
874 if(flags&2){ |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
875 // float seek 0..1 |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
876 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
|
877 } else { |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
878 // time seek (secs) |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
879 if (mpg_d && mpg_d->has_valid_timestamps) { |
22021
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
880 if (mpg_d->first_to_final_pts_len > 0.0) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
881 newpos += rel_seek_secs * (demuxer->movi_end - demuxer->movi_start) / mpg_d->first_to_final_pts_len; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
882 else if (oldpts > 0.0) |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
883 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
|
884 } 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
|
885 newpos+=2324*75*rel_seek_secs; // 174.3 kbyte/sec |
1466 | 886 else |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
887 newpos+=sh_video->i_bps*rel_seek_secs; |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
888 } |
1466 | 889 |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
890 while (1) { |
4391
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
891 if(newpos<demuxer->movi_start){ |
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
892 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
|
893 if(newpos<demuxer->movi_start) newpos=demuxer->movi_start; |
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
894 } |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
895 |
1466 | 896 stream_seek(demuxer->stream,newpos); |
897 | |
898 // re-sync video: | |
899 videobuf_code_len=0; // reset ES stream buffer | |
900 | |
901 ds_fill_buffer(d_video); | |
902 if(sh_audio){ | |
903 ds_fill_buffer(d_audio); | |
904 } | |
905 | |
906 while(1){ | |
907 int i; | |
908 if(sh_audio && !d_audio->eof && d_video->pts && d_audio->pts){ | |
909 float a_pts=d_audio->pts; | |
910 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; | |
911 if(d_video->pts>a_pts){ | |
912 skip_audio_frame(sh_audio); // sync audio | |
913 continue; | |
914 } | |
915 } | |
17821 | 916 if(!sh_video) break; |
1466 | 917 i=sync_video_packet(d_video); |
22155
bea181ba1df4
when seeking and the codec is VC1 sync to sequence or entry point headers
nicodvb
parents:
22094
diff
changeset
|
918 if(sh_video->format == mmioFOURCC('W', 'V', 'C', '1')) { |
bea181ba1df4
when seeking and the codec is VC1 sync to sequence or entry point headers
nicodvb
parents:
22094
diff
changeset
|
919 if(i==0x10E || i==0x10F) //entry point or sequence header |
bea181ba1df4
when seeking and the codec is VC1 sync to sequence or entry point headers
nicodvb
parents:
22094
diff
changeset
|
920 break; |
bea181ba1df4
when seeking and the codec is VC1 sync to sequence or entry point headers
nicodvb
parents:
22094
diff
changeset
|
921 } else |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
922 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
|
923 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
|
924 int pos = videobuf_len; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
925 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
|
926 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
|
927 } |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
928 } else if(sh_video->format == 0x10000005){ //h264 |
17289 | 929 if((i & ~0x60) == 0x105) break; |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
930 } else { //default mpeg1/2 |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
931 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
|
932 } |
1466 | 933 if(!i || !skip_video_packet(d_video)) break; // EOF? |
934 } | |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
935 if(!mpg_d) |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
936 break; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
937 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
|
938 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
|
939 mpg_d->has_valid_timestamps = 0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
940 break; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
941 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
942 precision--; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
943 //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
|
944 if(mpg_d) { |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
945 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
|
946 ds_free_packs(d_audio); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
947 ds_free_packs(d_video); |
20005
447e41fbcb4e
Reset demuxer->sub (consistently with audio and video) after seeking and at the end
nicodvb
parents:
19896
diff
changeset
|
948 ds_free_packs(demuxer->sub); |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
949 demuxer->stream->eof=0; // clear eof flag |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
950 d_video->eof=0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
951 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
|
952 } |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
953 } |
1466 | 954 } |
955 | |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
956 int demux_mpg_control(demuxer_t *demuxer,int cmd, void *arg){ |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
957 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
|
958 |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
959 switch(cmd) { |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
960 case DEMUXER_CTRL_GET_TIME_LENGTH: |
20851
6602a90a06ec
consistency fix: STREAM_CTRL_GET_TIME_LENGTH and STREAM_CTRL_GET_CURRENT_TIME now return time in (double) seconds
nicodvb
parents:
20005
diff
changeset
|
961 if(stream_control(demuxer->stream, STREAM_CTRL_GET_TIME_LENGTH, arg) != STREAM_UNSUPORTED) { |
6602a90a06ec
consistency fix: STREAM_CTRL_GET_TIME_LENGTH and STREAM_CTRL_GET_CURRENT_TIME now return time in (double) seconds
nicodvb
parents:
20005
diff
changeset
|
962 mp_msg(MSGT_DEMUXER,MSGL_DBG2,"\r\nDEMUX_MPG_CTRL, (%.3lf)\r\n", *((double*)arg)); |
17699
b742a2c71c25
try to get duration from the stream layer, if an implementation of STREAM_CTRL_GET_TIME_LENGTH is available
nicodvb
parents:
17636
diff
changeset
|
963 return DEMUXER_CTRL_GUESS; |
b742a2c71c25
try to get duration from the stream layer, if an implementation of STREAM_CTRL_GET_TIME_LENGTH is available
nicodvb
parents:
17636
diff
changeset
|
964 } |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
965 if (mpg_d && mpg_d->has_valid_timestamps) { |
22021
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
966 *((double *)arg)=(double)mpg_d->first_to_final_pts_len; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
967 return DEMUXER_CTRL_OK; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
968 } |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
969 return DEMUXER_CTRL_DONTKNOW; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
970 |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
971 case DEMUXER_CTRL_GET_PERCENT_POS: |
22021
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
972 if (mpg_d && mpg_d->has_valid_timestamps && mpg_d->first_to_final_pts_len > 0.0) { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
973 *((int *)arg)=(int)(100 * (mpg_d->last_pts-mpg_d->first_pts) / mpg_d->first_to_final_pts_len); |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
974 return DEMUXER_CTRL_OK; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
975 } |
14502
8769fa370f83
Move generic length and percent pos calculation to demuxer.c
reimar
parents:
14426
diff
changeset
|
976 return DEMUXER_CTRL_DONTKNOW; |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
977 |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
978 case DEMUXER_CTRL_SWITCH_AUDIO: |
17822
24fc4279bf99
fail immediately if any of the parameters necessary to switch audio stream isn't set/correct; closes cid 55
nicodvb
parents:
17821
diff
changeset
|
979 if(! (mpg_d && mpg_d->num_a_streams > 1 && demuxer->audio && demuxer->audio->sh)) |
24fc4279bf99
fail immediately if any of the parameters necessary to switch audio stream isn't set/correct; closes cid 55
nicodvb
parents:
17821
diff
changeset
|
980 return DEMUXER_CTRL_NOTIMPL; |
24fc4279bf99
fail immediately if any of the parameters necessary to switch audio stream isn't set/correct; closes cid 55
nicodvb
parents:
17821
diff
changeset
|
981 else { |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
982 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
|
983 sh_audio_t *sh_audio = d_audio->sh; |
17819
7d5716fd634c
init sh_a (new audio stream) to sh_audio (current audio stream); closes cid 241
nicodvb
parents:
17779
diff
changeset
|
984 sh_audio_t *sh_a = sh_audio; |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
985 int i; |
17822
24fc4279bf99
fail immediately if any of the parameters necessary to switch audio stream isn't set/correct; closes cid 55
nicodvb
parents:
17821
diff
changeset
|
986 if(!sh_audio) |
24fc4279bf99
fail immediately if any of the parameters necessary to switch audio stream isn't set/correct; closes cid 55
nicodvb
parents:
17821
diff
changeset
|
987 return DEMUXER_CTRL_NOTIMPL; |
15285
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
988 if (*((int*)arg) < 0) |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
989 { |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
990 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
|
991 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
|
992 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
993 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
|
994 sh_a = (sh_audio_t*)demuxer->a_streams[mpg_d->a_stream_ids[i]]; |
15285
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
995 } |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
996 else { |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
997 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
|
998 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
|
999 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
|
1000 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
|
1001 } |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
1002 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
|
1003 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
|
1004 d_audio->sh = sh_a; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
1005 ds_free_packs(d_audio); |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
1006 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
1007 } |
15285
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
1008 *((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
|
1009 return DEMUXER_CTRL_OK; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
1010 |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1011 default: |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1012 return DEMUXER_CTRL_NOTIMPL; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1013 } |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1014 } |
16175 | 1015 |
1016 | |
1017 static int demux_mpg_pes_probe(demuxer_t *demuxer) { | |
1018 demuxer->synced = 3; | |
16314 | 1019 return (demux_mpg_probe(demuxer) == DEMUXER_TYPE_MPEG_PS) ? DEMUXER_TYPE_MPEG_PES : 0; |
16175 | 1020 } |
1021 | |
1022 | |
1023 static demuxer_t* demux_mpg_es_open(demuxer_t* demuxer) | |
1024 { | |
1025 sh_video_t *sh_video=NULL; | |
1026 | |
1027 demuxer->audio->sh = NULL; // ES streams has no audio channel | |
1028 demuxer->video->sh = new_sh_video(demuxer,0); // create dummy video stream header, id=0 | |
1029 sh_video=demuxer->video->sh;sh_video->ds=demuxer->video; | |
1030 | |
1031 return demuxer; | |
1032 } | |
1033 | |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1034 static demuxer_t *demux_mpg_gxf_open(demuxer_t *demuxer) { |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1035 demuxer->audio->sh = NULL; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1036 demuxer->video->sh = new_sh_video(demuxer,0); |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1037 ((sh_video_t *)demuxer->video->sh)->ds = demuxer->video; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1038 demuxer->priv = (void *) 0xffffffff; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1039 return demuxer; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1040 } |
16175 | 1041 |
1042 static demuxer_t* demux_mpg_ps_open(demuxer_t* demuxer) | |
1043 { | |
1044 sh_audio_t *sh_audio=NULL; | |
1045 sh_video_t *sh_video=NULL; | |
1046 | |
1047 sh_video=demuxer->video->sh;sh_video->ds=demuxer->video; | |
1048 | |
1049 if(demuxer->audio->id!=-2) { | |
1050 if(!ds_fill_buffer(demuxer->audio)){ | |
1051 mp_msg(MSGT_DEMUXER,MSGL_INFO,"MPEG: " MSGTR_MissingAudioStream); | |
1052 demuxer->audio->sh=NULL; | |
1053 } else { | |
1054 sh_audio=demuxer->audio->sh;sh_audio->ds=demuxer->audio; | |
1055 } | |
1056 } | |
1057 | |
22037
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1058 if(!sh_video->format && ps_probe > 0) { |
22088 | 1059 int head; |
22037
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1060 off_t pos = stream_tell(demuxer->stream); |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1061 |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1062 clear_stats(); |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1063 do { |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1064 head=sync_video_packet(demuxer->video); |
22041
f0172904ff02
sanity checks during codec detection; also reset demuxer->stream->eof
nicodvb
parents:
22037
diff
changeset
|
1065 if(!head) break; |
22037
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1066 update_stats(head); |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1067 skip_video_packet(demuxer->video); |
22041
f0172904ff02
sanity checks during codec detection; also reset demuxer->stream->eof
nicodvb
parents:
22037
diff
changeset
|
1068 } while(stream_tell(demuxer->stream) < pos + ps_probe && !demuxer->stream->eof); |
22037
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1069 |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1070 ds_free_packs(demuxer->video); |
22041
f0172904ff02
sanity checks during codec detection; also reset demuxer->stream->eof
nicodvb
parents:
22037
diff
changeset
|
1071 demuxer->stream->eof=0; |
22037
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1072 stream_seek(demuxer->stream, pos); |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1073 mp_msg(MSGT_DEMUX,MSGL_INFO,"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\n", |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1074 num_elementary_packets100, num_elementary_packets101, |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1075 num_elementary_packets1B6, num_elementary_packets12x, |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1076 num_h264_slice, num_h264_dpa, num_h264_dpb, num_h264_dpc, |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1077 num_h264_idr, num_h264_sps, num_h264_pps); |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1078 |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1079 if(num_elementary_packets1B6>3 && num_elementary_packets12x>=1 && |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1080 num_elementary_packets100<=num_elementary_packets12x) |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1081 sh_video->format = 0x10000004; |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1082 else if((num_h264_slice>3 || (num_h264_dpa>3 && num_h264_dpb>3 && num_h264_dpc>3)) && |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1083 num_h264_sps>=1 && num_h264_pps>=1 && num_h264_idr>=1 && |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1084 num_elementary_packets1B6==0) |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1085 sh_video->format = 0x10000005; |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1086 else sh_video->format = 0x10000002; |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1087 } |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1088 |
16175 | 1089 return demuxer; |
1090 } | |
1091 | |
1092 | |
1093 demuxer_desc_t demuxer_desc_mpeg_ps = { | |
1094 "MPEG PS demuxer", | |
1095 "mpegps", | |
1096 "MPEG-PS", | |
1097 "Arpi?", | |
1098 "Mpeg", | |
1099 DEMUXER_TYPE_MPEG_PS, | |
1100 0, // unsafe autodetect | |
1101 demux_mpg_probe, | |
1102 demux_mpg_fill_buffer, | |
1103 demux_mpg_ps_open, | |
1104 demux_close_mpg, | |
1105 demux_seek_mpg, | |
16771
82a56c89b54d
10l, demux_mpg_control was missing from demuxer info struct, causing audio
reimar
parents:
16369
diff
changeset
|
1106 demux_mpg_control, |
16175 | 1107 }; |
1108 | |
1109 | |
1110 demuxer_desc_t demuxer_desc_mpeg_pes = { | |
1111 "MPEG PES demuxer", | |
1112 "mpegpes", | |
1113 "MPEG-PES", | |
1114 "Arpi?", | |
1115 "Mpeg", | |
1116 DEMUXER_TYPE_MPEG_PES, | |
1117 0, // unsafe autodetect | |
1118 demux_mpg_pes_probe, | |
1119 demux_mpg_fill_buffer, | |
16314 | 1120 demux_mpg_ps_open, |
16175 | 1121 demux_close_mpg, |
1122 demux_seek_mpg, | |
16771
82a56c89b54d
10l, demux_mpg_control was missing from demuxer info struct, causing audio
reimar
parents:
16369
diff
changeset
|
1123 demux_mpg_control, |
16175 | 1124 }; |
1125 | |
1126 | |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1127 demuxer_desc_t demuxer_desc_mpeg_gxf = { |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1128 "MPEG ES in GXF demuxer", |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1129 "mpeggxf", |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1130 "MPEG-ES in GXF", |
22507
a46ab26b2d5e
Source files should not contain non-ASCII characters.
diego
parents:
22363
diff
changeset
|
1131 "Reimar Doeffinger", |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1132 "Mpeg", |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1133 DEMUXER_TYPE_MPEG_GXF, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1134 0, // hack autodetection |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1135 NULL, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1136 demux_mpg_gxf_fill_buffer, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1137 demux_mpg_gxf_open, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1138 NULL, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1139 NULL, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1140 NULL |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1141 }; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1142 |
16175 | 1143 demuxer_desc_t demuxer_desc_mpeg_es = { |
1144 "MPEG ES demuxer", | |
1145 "mpeges", | |
1146 "MPEG-ES", | |
1147 "Arpi?", | |
1148 "Mpeg", | |
1149 DEMUXER_TYPE_MPEG_ES, | |
1150 0, // hack autodetection | |
1151 NULL, | |
1152 demux_mpg_es_fill_buffer, | |
1153 demux_mpg_es_open, | |
1154 demux_close_mpg, | |
1155 demux_seek_mpg, | |
16771
82a56c89b54d
10l, demux_mpg_control was missing from demuxer info struct, causing audio
reimar
parents:
16369
diff
changeset
|
1156 demux_mpg_control, |
16175 | 1157 }; |
1158 | |
1159 | |
1160 demuxer_desc_t demuxer_desc_mpeg4_es = { | |
1161 "MPEG4 ES demuxer", | |
1162 "mpeg4es", | |
1163 "MPEG-ES", | |
1164 "Arpi?", | |
1165 "Mpeg", | |
1166 DEMUXER_TYPE_MPEG4_ES, | |
1167 0, // hack autodetection | |
1168 NULL, | |
1169 demux_mpg_es_fill_buffer, | |
1170 demux_mpg_es_open, | |
1171 demux_close_mpg, | |
1172 demux_seek_mpg, | |
16771
82a56c89b54d
10l, demux_mpg_control was missing from demuxer info struct, causing audio
reimar
parents:
16369
diff
changeset
|
1173 demux_mpg_control, |
16175 | 1174 }; |
1175 | |
1176 | |
1177 demuxer_desc_t demuxer_desc_h264_es = { | |
1178 "H.264 ES demuxer", | |
1179 "h264es", | |
1180 "H264-ES", | |
1181 "Arpi?", | |
1182 "Mpeg", | |
1183 DEMUXER_TYPE_H264_ES, | |
1184 0, // hack autodetection | |
1185 NULL, | |
1186 demux_mpg_es_fill_buffer, | |
1187 demux_mpg_es_open, | |
1188 demux_close_mpg, | |
1189 demux_seek_mpg, | |
16771
82a56c89b54d
10l, demux_mpg_control was missing from demuxer info struct, causing audio
reimar
parents:
16369
diff
changeset
|
1190 demux_mpg_control, |
16175 | 1191 }; |