Mercurial > mplayer.hg
annotate libmpdemux/demux_mpg.c @ 36671:55f218d04dd3
Remove pointless pair of parentheses.
It will detect #define statements having no replacement text
without the second pair of parentheses just as well.
Thanks to al for spotting it.
author | ib |
---|---|
date | Fri, 31 Jan 2014 14:06:25 +0000 |
parents | 740a60d26cc0 |
children | 690ca924c15a |
rev | line source |
---|---|
29238
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
1 /* |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
2 * MPG/VOB file parser for DEMUXER v2.5 |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
3 * copyright (c) 2001 by A'rpi/ESP-team |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
4 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
5 * This file is part of MPlayer. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
6 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
7 * MPlayer is free software; you can redistribute it and/or modify |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
9 * the Free Software Foundation; either version 2 of the License, or |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
10 * (at your option) any later version. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
11 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
12 * MPlayer is distributed in the hope that it will be useful, |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
15 * GNU General Public License for more details. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
16 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
17 * You should have received a copy of the GNU General Public License along |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
18 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28051
diff
changeset
|
20 */ |
1 | 21 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
22 #include <stdio.h> |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
23 #include <stdlib.h> |
1430 | 24 #include <unistd.h> |
22036 | 25 #include <math.h> |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
26 |
1567 | 27 #include "config.h" |
28 #include "mp_msg.h" | |
32060
c3b7fc7eb796
Move audio_lang / dvdsub_lang extern variable declarations to mpcommon.h.
diego
parents:
31610
diff
changeset
|
29 #include "mpcommon.h" |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1735
diff
changeset
|
30 #include "help_mp.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
31 |
32345
e9556f0abee8
Replace forward declarations of skip_audio_frame() by proper #include.
diego
parents:
32060
diff
changeset
|
32 #include "libmpcodecs/dec_audio.h" |
22605
4d81dbdf46b9
Add explicit location for headers from the stream/ directory.
diego
parents:
22507
diff
changeset
|
33 #include "stream/stream.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
34 #include "demuxer.h" |
1466 | 35 #include "parse_es.h" |
2338 | 36 #include "stheader.h" |
4711 | 37 #include "mp3_hdr.h" |
31414
5e0a4702be52
Add header file for externally used variable ps_probe.
diego
parents:
30578
diff
changeset
|
38 #include "demux_mpg.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
39 |
524
9105fc95636c
A fast'n'ugly hack to correct DVD VOB playback problems
lgb
parents:
501
diff
changeset
|
40 //#define MAX_PS_PACKETSIZE 2048 |
501 | 41 #define MAX_PS_PACKETSIZE (224*1024) |
42 | |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
43 #define UNKNOWN 0 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
44 #define VIDEO_MPEG1 0x10000001 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
45 #define VIDEO_MPEG2 0x10000002 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
46 #define VIDEO_MPEG4 0x10000004 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
47 #define VIDEO_H264 0x10000005 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
48 #define AUDIO_MP2 0x50 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
49 #define AUDIO_A52 0x2000 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
50 #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
|
51 #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
|
52 |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
53 typedef struct mpg_demuxer { |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
54 float last_pts; |
22021
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 // (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
|
59 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
|
60 int num_a_streams; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
61 int a_stream_ids[MAX_A_STREAMS]; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
62 } mpg_demuxer_t; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
63 |
547 | 64 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
|
65 off_t ps_probe = 0; |
547 | 66 |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
67 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
|
68 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
|
69 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
|
70 mpg_demuxer_t *priv = (mpg_demuxer_t *) demux->priv; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
71 |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
72 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
|
73 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
|
74 return 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
75 |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
76 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
|
77 if(! (c & 0x80)) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
78 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
|
79 return 0; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
80 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 while(es_map_len > 0) { |
36446 | 87 if (demux->stream->eof) |
88 return 0; | |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
89 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
|
90 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
|
91 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
|
92 int idoffset = id - 0xB0; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
93 switch(type) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
94 case 0x1: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
95 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
|
96 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
97 case 0x2: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
98 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
|
99 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
100 case 0x3: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
101 case 0x4: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
102 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
|
103 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
104 case 0x0f: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
105 case 0x11: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
106 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
|
107 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
108 case 0x10: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
109 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
|
110 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
111 case 0x1b: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
112 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
|
113 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
114 case 0x81: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
115 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
|
116 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
117 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
118 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
|
119 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 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
|
124 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
125 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
|
126 return 1; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
127 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
128 |
18072
284751bccd04
make sure the check for valid timestamps does not accidentially search through
reimar
parents:
17822
diff
changeset
|
129 // 500000 is a wild guess |
284751bccd04
make sure the check for valid timestamps does not accidentially search through
reimar
parents:
17822
diff
changeset
|
130 #define TIMESTAMP_PROBE_LEN 500000 |
284751bccd04
make sure the check for valid timestamps does not accidentially search through
reimar
parents:
17822
diff
changeset
|
131 |
22021
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
132 //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
|
133 //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
|
134 //1.0 is a wild guess |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
135 #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
|
136 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
137 //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
|
138 //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
|
139 //Packs are freed. |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
140 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
|
141 { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
142 stream_t *s = demuxer->stream; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 int found = 0; |
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 if(!mpg_d || stream_pos < 0) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
151 return pts; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
152 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
153 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
|
154 stream_seek(s, stream_pos); |
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 //We look for pts. |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
157 //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
|
158 //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
|
159 //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
|
160 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
161 while(found<3 && !s->eof |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
162 && (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
|
163 && (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
|
164 && (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
|
165 && ds_fill_buffer(demuxer->video)) |
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 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
|
168 { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
169 if(!found) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
170 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
|
171 else |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
172 { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
173 found_pts3 = found_pts2; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
174 found_pts2 = found_pts1; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
175 found_pts1 = mpg_d->last_pts; |
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 found++; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
178 } |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
179 } |
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(found == 3) pts = found_pts3; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
182 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
183 //clean up from searching of first pts; |
26927 | 184 demux_flush(demuxer); |
22021
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
185 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
186 return pts; |
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 |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
189 /// Open an mpg physical stream |
16175 | 190 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
|
191 stream_t *s = demuxer->stream; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
192 mpg_demuxer_t* mpg_d; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
193 |
36447
740a60d26cc0
Only detect a file as MPEG-PS if we can find at least 2 packets.
reimar
parents:
36446
diff
changeset
|
194 while (demuxer->video->packs + demuxer->audio->packs < 2) |
740a60d26cc0
Only detect a file as MPEG-PS if we can find at least 2 packets.
reimar
parents:
36446
diff
changeset
|
195 if (!ds_fill_buffer(demuxer->video)) return 0; |
18885 | 196 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
|
197 if(mpg_d) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
198 { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
199 demuxer->priv = mpg_d; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
200 mpg_d->last_pts = -1.0; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
201 mpg_d->first_pts = -1.0; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
202 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
203 //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
|
204 if(demuxer->seekable |
22363
03ba33feaae9
test the continuity of timestamps for STREAMTYPE_VCD, too; patch by Zuxy Meng
nicodvb
parents:
22352
diff
changeset
|
205 && (demuxer->stream->type == STREAMTYPE_FILE |
03ba33feaae9
test the continuity of timestamps for STREAMTYPE_VCD, too; patch by Zuxy Meng
nicodvb
parents:
22352
diff
changeset
|
206 || demuxer->stream->type == STREAMTYPE_VCD) |
22021
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
207 && demuxer->movi_start != demuxer-> movi_end |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
208 ) |
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 //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
|
211 //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
|
212 //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
|
213 //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
|
214 //of the stream |
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 //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
|
217 off_t pos = stream_tell(s); |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
218 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
|
219 if(first_pts != -1.0) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
220 { |
22351
1f40a27bd2ad
100000l: average != semidistance, fixed seeking to the middle position; patch by Zuxy meng (zuxy.megn gmail com)
nicodvb
parents:
22170
diff
changeset
|
221 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
|
222 if(middle_pts != -1.0) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
223 { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
224 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
|
225 if(final_pts != -1.0) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
226 { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
227 // 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
|
228 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
|
229 // 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
|
230 if((0.5 < proportion) && (proportion < 2)) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
231 { |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
232 mpg_d->first_pts = first_pts; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
233 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
|
234 mpg_d->has_valid_timestamps = 1; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
235 } |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
236 } |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
237 } |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
238 } |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
239 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
240 //Cleaning up from seeking in stream |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
241 demuxer->stream->eof=0; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
242 demuxer->video->eof=0; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
243 demuxer->audio->eof=0; |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
244 |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
245 stream_seek(s,pos); |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
246 ds_fill_buffer(demuxer->video); |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
247 } // if ( demuxer->seekable ) |
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
248 } // if ( mpg_d ) |
16175 | 249 return demuxer; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
250 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
251 |
16175 | 252 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
|
253 mpg_demuxer_t* mpg_d = demuxer->priv; |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32352
diff
changeset
|
254 free(mpg_d); |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
255 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
256 |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
257 |
18077
cede662f40a5
timestamps are 33 bits long, so they don't fit in an unsigned int; 10l
nicodvb
parents:
18072
diff
changeset
|
258 static unsigned long long read_mpeg_timestamp(stream_t *s,int c){ |
18381 | 259 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
|
260 unsigned long long pts; |
1 | 261 d=stream_read_word(s); |
262 e=stream_read_word(s); | |
547 | 263 if( ((c&1)!=1) || ((d&1)!=1) || ((e&1)!=1) ){ |
264 ++mpeg_pts_error; | |
265 return 0; // invalid pts | |
266 } | |
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
|
267 pts=(((uint64_t)((c>>1)&7))<<30)|((d>>1)<<15)|(e>>1); |
33841
25667edae85c
cleanup: adjust printf format strings to match parameter types
diego
parents:
33827
diff
changeset
|
268 mp_dbg(MSGT_DEMUX,MSGL_DBG3," pts {%llu}",pts); |
1 | 269 return pts; |
270 } | |
271 | |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
272 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
|
273 if(!demux->a_streams[aid]){ |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
274 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
|
275 sh_audio_t* sh_a; |
31609
cd81fce1f010
Make the stream language an argument to the stream creation function
reimar
parents:
31414
diff
changeset
|
276 new_sh_audio(demux,aid, NULL); |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
277 sh_a = (sh_audio_t*)demux->a_streams[aid]; |
30088
4977e04f3a18
Add support for parsing audio streams (though should be easy to extend to video)
reimar
parents:
29263
diff
changeset
|
278 sh_a->needs_parsing = 1; |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 } |
21927
ee422890bca9
in evo files [e]ac3 substreams range from 0xc0 to 0xcf
nicodvb
parents:
21919
diff
changeset
|
285 //evo files |
21934 | 286 if((aid & 0xC0) == 0xC0) sh_a->format=0x2000; |
22170 | 287 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
|
288 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
|
289 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
290 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
|
291 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
292 |
1 | 293 static int demux_mpg_read_packet(demuxer_t *demux,int id){ |
294 int d; | |
295 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
|
296 int set_pts=0; // !=0 iff pts has been set to a proper value |
1 | 297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 double stream_pts = MP_NOPTS_VALUE; |
1 | 303 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
|
304 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
|
305 mpg_demuxer_t *priv = (mpg_demuxer_t *) demux->priv; |
23723
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
306 |
1567 | 307 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"demux_read_packet: %X\n",id); |
1 | 308 |
536 | 309 // if(id==0x1F0){ |
310 // demux->synced=0; // force resync after 0x1F0 | |
311 // return -1; | |
312 //} | |
501 | 313 |
1 | 314 // 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
|
315 if((id<0x1BC || id>=0x1F0) && id != 0x1FD) return -1; |
1 | 316 if(id==0x1BE) return -1; // padding stream |
317 if(id==0x1BF) return -1; // private2 | |
318 | |
319 len=stream_read_word(demux->stream); | |
1567 | 320 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"PACKET len=%d",len); |
536 | 321 // if(len==62480){ demux->synced=0;return -1;} /* :) */ |
501 | 322 if(len==0 || len>MAX_PS_PACKETSIZE){ |
1567 | 323 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Invalid PS packet len: %d\n",len); |
501 | 324 return -2; // invalid packet !!!!!! |
325 } | |
1 | 326 |
547 | 327 mpeg_pts_error=0; |
328 | |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
329 if(id==0x1BC) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
330 parse_psm(demux, len); |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
331 return 0; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
332 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
333 |
1 | 334 while(len>0){ // Skip stuFFing bytes |
23710
df28abb8fe74
cosmetics: split separate instructions in separate lines
nicodvb
parents:
23709
diff
changeset
|
335 c=stream_read_char(demux->stream); |
df28abb8fe74
cosmetics: split separate instructions in separate lines
nicodvb
parents:
23709
diff
changeset
|
336 --len; |
1 | 337 if(c!=0xFF)break; |
338 } | |
339 if((c>>6)==1){ // Read (skip) STD scale & size value | |
340 // printf(" STD_scale=%d",(c>>5)&1); | |
341 d=((c&0x1F)<<8)|stream_read_char(demux->stream); | |
342 len-=2; | |
343 // printf(" STD_size=%d",d); | |
344 c=stream_read_char(demux->stream); | |
345 } | |
346 // Read System-1 stream timestamps: | |
347 if((c>>4)==2){ | |
348 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
|
349 set_pts=1; |
1 | 350 len-=4; |
351 } else | |
352 if((c>>4)==3){ | |
353 pts=read_mpeg_timestamp(demux->stream,c); | |
354 c=stream_read_char(demux->stream); | |
355 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
|
356 else set_pts = 1; |
1 | 357 dts=read_mpeg_timestamp(demux->stream,c); |
358 len-=4+1+4; | |
359 } else | |
360 if((c>>6)==2){ | |
361 int pts_flags; | |
362 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
|
363 int parse_ext2; |
1 | 364 // System-2 (.VOB) stream: |
23710
df28abb8fe74
cosmetics: split separate instructions in separate lines
nicodvb
parents:
23709
diff
changeset
|
365 c=stream_read_char(demux->stream); |
df28abb8fe74
cosmetics: split separate instructions in separate lines
nicodvb
parents:
23709
diff
changeset
|
366 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
|
367 parse_ext2 = (id == 0x1FD) && ((c & 0x3F) == 1); |
23710
df28abb8fe74
cosmetics: split separate instructions in separate lines
nicodvb
parents:
23709
diff
changeset
|
368 c=stream_read_char(demux->stream); |
df28abb8fe74
cosmetics: split separate instructions in separate lines
nicodvb
parents:
23709
diff
changeset
|
369 hdrlen=c; |
1 | 370 len-=2; |
1567 | 371 mp_dbg(MSGT_DEMUX,MSGL_DBG3," hdrlen=%d (len=%d)",hdrlen,len); |
372 if(hdrlen>len){ mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: invalid header length \n"); return -1;} | |
7671 | 373 if(pts_flags==2 && hdrlen>=5){ |
1 | 374 c=stream_read_char(demux->stream); |
375 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
|
376 set_pts=1; |
1 | 377 len-=5;hdrlen-=5; |
378 } else | |
7671 | 379 if(pts_flags==3 && hdrlen>=10){ |
1 | 380 c=stream_read_char(demux->stream); |
381 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
|
382 set_pts=1; |
1 | 383 c=stream_read_char(demux->stream); |
384 dts=read_mpeg_timestamp(demux->stream,c); | |
385 len-=10;hdrlen-=10; | |
386 } | |
387 len-=hdrlen; | |
23723
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
388 if(parse_ext2 && hdrlen>=3) { |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
389 c=stream_read_char(demux->stream); |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
390 hdrlen--; |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
391 |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
392 if((c & 0x0F) != 0x0F) { |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
393 mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: pes_extension_flag2 not set, discarding pes packet\n"); |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
394 return -1; |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
395 } |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
396 if(c & 0x80) { //pes_private_data_flag |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
397 if(hdrlen<16) { |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
398 mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: not enough pes_private_data bytes: %d < 16, discarding pes packet\n", hdrlen); |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
399 return -1; |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
400 } |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
401 stream_skip(demux->stream, 16); |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
402 hdrlen-=16; |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
403 } |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
404 if(c & 0x40) { //pack_header_field_flag |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
405 int l = stream_read_char(demux->stream); |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
406 if(l < 0) //couldn't read from the stream? |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
407 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
|
408 hdrlen--; |
23723
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
409 if(l < 0 || hdrlen < l) { |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
410 mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: not enough pack_header bytes: hdrlen: %d < skip: %d, discarding pes packet\n", |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
411 hdrlen, l); |
23709
b214397ad0e2
proper parsing of pes_extension[12] fields (replaces the previous code that relied on specific flags set
nicodvb
parents:
23550
diff
changeset
|
412 return -1; |
b214397ad0e2
proper parsing of pes_extension[12] fields (replaces the previous code that relied on specific flags set
nicodvb
parents:
23550
diff
changeset
|
413 } |
23723
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
414 stream_skip(demux->stream, l); |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
415 hdrlen-=l; |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
416 } |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
417 if(c & 0x20) { //program_packet_sequence_counter_flag |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
418 if(hdrlen < 2) { |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
419 mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: not enough program_packet bytes: hdrlen: %d, discarding pes packet\n", hdrlen); |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
420 return -1; |
23709
b214397ad0e2
proper parsing of pes_extension[12] fields (replaces the previous code that relied on specific flags set
nicodvb
parents:
23550
diff
changeset
|
421 } |
23723
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
422 stream_skip(demux->stream, 2); |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
423 hdrlen-=2; |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
424 } |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
425 if(c & 0x10) { |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
426 //STD |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
427 stream_skip(demux->stream, 2); |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
428 hdrlen-=2; |
21948
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
429 } |
23723
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
430 c=stream_read_char(demux->stream); //pes_extension2 flag |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
431 hdrlen--; |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
432 if(c!=0x81) { mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: unknown pes_extension2 format, len is > 1 \n"); return -1;} |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
433 c=stream_read_char(demux->stream); //pes_extension2 payload === substream id |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
434 hdrlen--; |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
435 if(c<0x55 || c>0x5F) { mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: unknown vc1 substream_id: 0x%x \n", c); return -1;} |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
436 pes_ext2_subid=c; |
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
437 } |
23722
5c5a3b4c0eb7
unified the skip of header and stuffing bytes after the parsing of pes_extension[12] fields
nicodvb
parents:
23711
diff
changeset
|
438 if(hdrlen>0) |
5c5a3b4c0eb7
unified the skip of header and stuffing bytes after the parsing of pes_extension[12] fields
nicodvb
parents:
23711
diff
changeset
|
439 stream_skip(demux->stream,hdrlen); // skip header and stuffing bytes |
23723
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
440 |
21948
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
441 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
|
442 //==== 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
|
443 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
|
444 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
|
445 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
|
446 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
|
447 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
|
448 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
|
449 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
|
450 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
|
451 } |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
452 } |
3b9115e57f24
demux vc1 (stream id 0x1Fd with 0x55 <= substream id <= 0x5F in the pes_extension_2 payload)
nicodvb
parents:
21934
diff
changeset
|
453 } |
1 | 454 //============== DVD Audio sub-stream ====================== |
455 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
|
456 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
|
457 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
|
458 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
|
459 |
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
|
460 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
|
461 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
|
462 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
|
463 /// 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
|
464 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
|
465 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
|
466 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
|
467 } |
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
|
468 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
|
469 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
|
470 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
|
471 } |
23723
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
472 |
552 | 473 // AID: |
474 // 0x20..0x3F subtitle | |
23530
c325aaa89171
clearly specify the valid substream id range, rather than using unreadable bitmasks (it also prevents misdetection 0xFF as valid)
nicodvb
parents:
22886
diff
changeset
|
475 // 0x80..0x87 and 0xC0..0xCF AC3 audio |
c325aaa89171
clearly specify the valid substream id range, rather than using unreadable bitmasks (it also prevents misdetection 0xFF as valid)
nicodvb
parents:
22886
diff
changeset
|
476 // 0x88..0x8F and 0x98..0x9F DTS audio |
552 | 477 // 0xA0..0xBF PCM audio |
23723
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
478 |
552 | 479 if((aid & 0xE0) == 0x20){ |
480 // subtitle: | |
481 aid&=0x1F; | |
426 | 482 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
483 if(!demux->s_streams[aid]){ |
31609
cd81fce1f010
Make the stream language an argument to the stream creation function
reimar
parents:
31414
diff
changeset
|
484 sh_sub_t *sh = new_sh_sub(demux, aid, NULL); |
23550
1915012c8f7d
Set subtitle type in mpg demuxer. Fixes subtitle switching with 'j'
reimar
parents:
23530
diff
changeset
|
485 if (sh) sh->type = 'v'; |
1567 | 486 mp_msg(MSGT_DEMUX,MSGL_V,"==> Found subtitle: %d\n",aid); |
552 | 487 } |
488 | |
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
|
489 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
|
490 demux->sub->id &= 0x1F; |
31610
9e2c61ae171f
Revert and accidentally committed hunk from last commit.
reimar
parents:
31609
diff
changeset
|
491 if(!dvdsub_lang && demux->sub->id == -1) |
9e2c61ae171f
Revert and accidentally committed hunk from last commit.
reimar
parents:
31609
diff
changeset
|
492 demux->sub->id = aid; |
552 | 493 if(demux->sub->id==aid){ |
494 ds=demux->sub; | |
495 } | |
23530
c325aaa89171
clearly specify the valid substream id range, rather than using unreadable bitmasks (it also prevents misdetection 0xFF as valid)
nicodvb
parents:
22886
diff
changeset
|
496 } else if((aid >= 0x80 && aid <= 0x8F) || (aid >= 0x98 && aid <= 0xAF) || (aid >= 0xC0 && aid <= 0xCF)) { |
552 | 497 |
498 // aid=128+(aid&0x7F); | |
499 // aid=0x80..0xBF | |
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); |
426 | 501 if(demux->audio->id==aid){ |
7671 | 502 int type; |
426 | 503 ds=demux->audio; |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
504 if(!ds->sh) ds->sh=demux->a_streams[aid]; |
1 | 505 // 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
|
506 if(!rawa52) { |
7671 | 507 c=stream_read_char(demux->stream);//num of frames |
508 type=stream_read_char(demux->stream);//startpos hi | |
509 type=(type<<8)|stream_read_char(demux->stream);//startpos lo | |
510 // printf("\r[%02X][%04X]",c,type); | |
1 | 511 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
|
512 } |
7671 | 513 if((aid&0xE0)==0xA0 && len>=3){ |
514 unsigned char* hdr; | |
515 // save audio header as codecdata! | |
516 if(!((sh_audio_t*)(ds->sh))->codecdata_len){ | |
517 ((sh_audio_t*)(ds->sh))->codecdata=malloc(3); | |
518 ((sh_audio_t*)(ds->sh))->codecdata_len=3; | |
519 } | |
520 hdr=((sh_audio_t*)(ds->sh))->codecdata; | |
521 // read LPCM header: | |
522 // emphasis[1], mute[1], rvd[1], frame number[5]: | |
523 hdr[0]=stream_read_char(demux->stream); | |
524 // printf(" [%01X:%02d]",c>>5,c&31); | |
525 // quantization[2],freq[2],rvd[1],channels[3] | |
526 hdr[1]=stream_read_char(demux->stream); | |
527 // printf("[%01X:%01X] ",c>>4,c&15); | |
528 // dynamic range control (0x80=off): | |
529 hdr[2]=stream_read_char(demux->stream); | |
530 // printf("[%02X] ",c); | |
531 len-=3; | |
532 if(len<=0) mp_msg(MSGT_DEMUX,MSGL_V,"End of packet while searching for PCM header\n"); | |
1 | 533 } |
7671 | 534 // printf(" \n"); |
552 | 535 } // if(demux->audio->id==aid) |
536 | |
1567 | 537 } else mp_msg(MSGT_DEMUX,MSGL_V,"Unknown 0x1BD substream: 0x%02X \n",aid); |
552 | 538 } //if(id==0x1BD) |
1 | 539 } else { |
539 | 540 if(c!=0x0f){ |
1567 | 541 mp_msg(MSGT_DEMUX,MSGL_V," {ERROR5,c=%d} \n",c); |
539 | 542 return -1; // invalid packet !!!!!! |
543 } | |
1 | 544 } |
1567 | 545 if(mpeg_pts_error) mp_msg(MSGT_DEMUX,MSGL_V," {PTS_err:%d} \n",mpeg_pts_error); |
546 mp_dbg(MSGT_DEMUX,MSGL_DBG3," => len=%d\n",len); | |
1 | 547 |
501 | 548 // if(len<=0 || len>MAX_PS_PACKETSIZE) return -1; // Invalid packet size |
549 if(len<=0 || len>MAX_PS_PACKETSIZE){ | |
1567 | 550 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Invalid PS data len: %d\n",len); |
501 | 551 return -1; // invalid packet !!!!!! |
552 } | |
23723
148b85340a65
100% cosmetics: reindentation and removal of trailing spaces
nicodvb
parents:
23722
diff
changeset
|
553 |
1 | 554 if(id>=0x1C0 && id<=0x1DF){ |
555 // mpeg audio | |
556 int aid=id-0x1C0; | |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
557 new_audio_stream(demux, aid); |
1 | 558 if(demux->audio->id==aid){ |
559 ds=demux->audio; | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
560 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
|
561 if(priv && ds->sh) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
562 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
|
563 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
|
564 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
|
565 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
|
566 } |
1 | 567 } |
568 } else | |
569 if(id>=0x1E0 && id<=0x1EF){ | |
570 // mpeg video | |
571 int aid=id-0x1E0; | |
1289 | 572 if(!demux->v_streams[aid]) new_sh_video(demux,aid); |
1 | 573 if(demux->video->id==-1) demux->video->id=aid; |
426 | 574 if(demux->video->id==aid){ |
575 ds=demux->video; | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
576 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
|
577 if(priv && ds->sh) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
578 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
|
579 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
|
580 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
|
581 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
|
582 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
583 } |
426 | 584 } |
1 | 585 } |
586 | |
587 if(ds){ | |
1567 | 588 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_MPG: Read %d data bytes from packet %04X\n",len,id); |
1 | 589 // 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
|
590 |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
591 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
|
592 if(!dp) { |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
593 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
|
594 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
|
595 return 0; |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
596 } |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
597 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
|
598 if(l<len) |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
599 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
|
600 len = l; |
24945
46337ac77770
10l, setting a non-existent timestamp (default 0.0) when the pts flag isn't set in
nicodvb
parents:
24681
diff
changeset
|
601 if(set_pts) |
24946 | 602 dp->pts=pts/90000.0f; |
21781
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
603 dp->pos=demux->filepos; |
21789
b266f27109a6
set dp->stream_pts only when feeding the video stream to workaround
nicodvb
parents:
21781
diff
changeset
|
604 /* |
b266f27109a6
set dp->stream_pts only when feeding the video stream to workaround
nicodvb
parents:
21781
diff
changeset
|
605 workaround: |
b266f27109a6
set dp->stream_pts only when feeding the video stream to workaround
nicodvb
parents:
21781
diff
changeset
|
606 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
|
607 (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
|
608 back and forth |
b266f27109a6
set dp->stream_pts only when feeding the video stream to workaround
nicodvb
parents:
21781
diff
changeset
|
609 */ |
24257 | 610 if(ds == demux->video && stream_control(demux->stream, STREAM_CTRL_GET_CURRENT_TIME,(void *)&stream_pts)!=STREAM_UNSUPPORTED) |
21781
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
611 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
|
612 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
|
613 if (demux->priv && set_pts) ((mpg_demuxer_t*)demux->priv)->last_pts = pts/90000.0f; |
554 | 614 // if(ds==demux->sub) parse_dvdsub(ds->last->buffer,ds->last->len); |
1 | 615 return 1; |
616 } | |
1567 | 617 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_MPG: Skipping %d data bytes from packet %04X\n",len,id); |
536 | 618 if(len<=2356) stream_skip(demux->stream,len); |
1 | 619 return 0; |
620 } | |
621 | |
15670 | 622 static int num_elementary_packets100=0; |
623 static int num_elementary_packets101=0; | |
624 static int num_elementary_packets12x=0; | |
625 static int num_elementary_packets1B6=0; | |
626 static int num_elementary_packetsPES=0; | |
25838
f75a531569a2
in the crazy ES probing code return DEMUXER_TYPE_MPEG_ES (mpeg12v) only if we have at least a couple of SEQ/GOP startcodes
nicodvb
parents:
25707
diff
changeset
|
627 static int num_mpeg12_startcode=0; |
15670 | 628 static int num_h264_slice=0; //combined slice |
629 static int num_h264_dpa=0; //DPA Slice | |
630 static int num_h264_dpb=0; //DPB Slice | |
631 static int num_h264_dpc=0; //DPC Slice | |
632 static int num_h264_idr=0; //IDR Slice | |
633 static int num_h264_sps=0; | |
634 static int num_h264_pps=0; | |
635 | |
636 static int num_mp3audio_packets=0; | |
637 | |
22886 | 638 static void clear_stats(void) |
22034
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
639 { |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
640 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
|
641 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
|
642 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
|
643 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
|
644 num_elementary_packetsPES=0; |
25838
f75a531569a2
in the crazy ES probing code return DEMUXER_TYPE_MPEG_ES (mpeg12v) only if we have at least a couple of SEQ/GOP startcodes
nicodvb
parents:
25707
diff
changeset
|
645 num_mpeg12_startcode=0; |
22034
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
646 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
|
647 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
|
648 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
|
649 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
|
650 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
|
651 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
|
652 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
|
653 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
|
654 } |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
655 |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
656 //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
|
657 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
|
658 { |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
659 if(head==0x1B6) ++num_elementary_packets1B6; |
25838
f75a531569a2
in the crazy ES probing code return DEMUXER_TYPE_MPEG_ES (mpeg12v) only if we have at least a couple of SEQ/GOP startcodes
nicodvb
parents:
25707
diff
changeset
|
660 else if(head==0x1B3 || head==0x1B8) ++num_mpeg12_startcode; |
22034
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
661 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
|
662 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
|
663 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
|
664 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
|
665 else if(head>=0x120 && head<=0x12F) ++num_elementary_packets12x; |
24681
1ecf2ff1d512
in update_stats() removed a wrong 'else' that would prevent h264 headers to be recognized:
nicodvb
parents:
24257
diff
changeset
|
666 if(head>=0x100 && head<0x1B0) |
22034
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
667 { |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
668 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
|
669 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
|
670 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
|
671 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
|
672 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
|
673 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
|
674 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
|
675 } |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
676 } |
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
677 |
16175 | 678 static int demux_mpg_probe(demuxer_t *demuxer) { |
15670 | 679 int pes=1; |
680 int tmp; | |
681 off_t tmppos; | |
682 int file_format = DEMUXER_TYPE_UNKNOWN; | |
683 | |
684 tmppos=stream_tell(demuxer->stream); | |
685 tmp=stream_read_dword(demuxer->stream); | |
686 if(tmp==0x1E0 || tmp==0x1C0) { | |
687 tmp=stream_read_word(demuxer->stream); | |
688 if(tmp>1 && tmp<=2048) pes=0; // demuxer->synced=3; // PES... | |
689 } | |
690 stream_seek(demuxer->stream,tmppos); | |
691 | |
22034
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
692 clear_stats(); |
9824 | 693 |
15670 | 694 if(demux_mpg_open(demuxer)) |
695 file_format=DEMUXER_TYPE_MPEG_PS; | |
696 else { | |
697 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", | |
698 num_elementary_packets100,num_elementary_packets101, | |
699 num_elementary_packets1B6,num_elementary_packets12x, | |
700 num_h264_slice, num_h264_dpa, | |
701 num_h264_dpb, num_h264_dpc=0, | |
702 num_h264_idr, num_h264_sps=0, | |
703 num_h264_pps, | |
704 num_elementary_packetsPES,num_mp3audio_packets, demuxer->synced); | |
705 | |
706 //MPEG packet stats: p100: 458 p101: 458 PES: 0 MP3: 1103 (.m2v) | |
707 if(num_mp3audio_packets>50 && num_mp3audio_packets>2*num_elementary_packets100 | |
708 && abs(num_elementary_packets100-num_elementary_packets101)>2) | |
709 return file_format; | |
710 | |
711 // some hack to get meaningfull error messages to our unhappy users: | |
25838
f75a531569a2
in the crazy ES probing code return DEMUXER_TYPE_MPEG_ES (mpeg12v) only if we have at least a couple of SEQ/GOP startcodes
nicodvb
parents:
25707
diff
changeset
|
712 if(num_mpeg12_startcode>=2 && num_elementary_packets100>=2 && num_elementary_packets101>=2 && |
15670 | 713 abs(num_elementary_packets101+8-num_elementary_packets100)<16) { |
714 if(num_elementary_packetsPES>=4 && num_elementary_packetsPES>=num_elementary_packets100-4) { | |
715 return file_format; | |
716 } | |
717 file_format=DEMUXER_TYPE_MPEG_ES; // <-- hack is here :) | |
718 } else | |
719 // fuzzy mpeg4-es detection. do NOT enable without heavy testing of mpeg formats detection! | |
720 if(num_elementary_packets1B6>3 && num_elementary_packets12x>=1 && | |
721 num_elementary_packetsPES==0 && num_elementary_packets100<=num_elementary_packets12x && | |
722 demuxer->synced<2) { | |
723 file_format=DEMUXER_TYPE_MPEG4_ES; | |
724 } else | |
725 // fuzzy h264-es detection. do NOT enable without heavy testing of mpeg formats detection! | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
726 if((num_h264_slice>3 || (num_h264_dpa>3 && num_h264_dpb>3 && num_h264_dpc>3)) && |
15670 | 727 /* FIXME num_h264_sps>=1 && */ num_h264_pps>=1 && num_h264_idr>=1 && |
728 num_elementary_packets1B6==0 && num_elementary_packetsPES==0 && | |
729 demuxer->synced<2) { | |
730 file_format=DEMUXER_TYPE_H264_ES; | |
731 } else | |
732 { | |
733 if(demuxer->synced==2) | |
734 mp_msg(MSGT_DEMUXER,MSGL_ERR,"MPEG: " MSGTR_MissingVideoStreamBug); | |
735 else | |
33827
277ec491a8a7
Do not translate console messages of verbosity level MSGL_V and above.
diego
parents:
32537
diff
changeset
|
736 mp_msg(MSGT_DEMUXER, MSGL_V, "Not MPEG System Stream format... (maybe Transport Stream?)\n"); |
15670 | 737 } |
738 } | |
22094
e2d1bb1d2c6b
demux_mpg_probe() seek to the initial position before returning - patch by reimar
nicodvb
parents:
22088
diff
changeset
|
739 //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
|
740 stream_seek(demuxer->stream,tmppos); |
15670 | 741 return file_format; |
742 } | |
1 | 743 |
16175 | 744 static int demux_mpg_es_fill_buffer(demuxer_t *demux, demux_stream_t *ds){ |
1 | 745 // Elementary video stream |
746 if(demux->stream->eof) return 0; | |
747 demux->filepos=stream_tell(demux->stream); | |
1735 | 748 ds_read_packet(demux->video,demux->stream,STREAM_BUFFER_SIZE,0,demux->filepos,0); |
1 | 749 return 1; |
750 } | |
751 | |
16369 | 752 /** |
753 * \brief discard until 0x100 header and return a filled buffer | |
754 * \param b buffer-end pointer | |
755 * \param pos current pos in stream, negative since b points to end of buffer | |
756 * \param s stream to read from | |
757 * \return new position, differs from original pos when eof hit and thus | |
758 * b was modified to point to the new end of buffer | |
759 */ | |
760 static int find_end(unsigned char **b, int pos, stream_t *s) { | |
761 register int state = 0xffffffff; | |
762 unsigned char *buf = *b; | |
763 int start = pos; | |
764 int read, unused; | |
765 // search already read part | |
766 while (state != 0x100 && pos) { | |
767 state = state << 8 | buf[pos++]; | |
768 } | |
769 // continue search in stream | |
770 while (state != 0x100) { | |
771 register int c = stream_read_char(s); | |
772 if (c < 0) break; | |
773 state = state << 8 | c; | |
774 } | |
775 // modify previous header (from 0x1bc or 0x1bf to 0x100) | |
776 buf[start++] = 0; | |
777 // copy remaining buffer part to current pos | |
778 memmove(&buf[start], &buf[pos], -pos); | |
779 unused = start + -pos; // -unused bytes in buffer | |
780 read = stream_read(s, &buf[unused], -unused); | |
781 unused += read; | |
782 // fix buffer so it ends at pos == 0 (eof case) | |
783 *b = &buf[unused]; | |
784 start -= unused; | |
785 return start; | |
786 } | |
787 | |
788 /** | |
789 * This format usually uses an insane bitrate, which makes this function | |
790 * performance-critical! | |
791 * Be sure to benchmark any changes with different compiler versions. | |
792 */ | |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
793 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
|
794 demux_packet_t *pack; |
16369 | 795 int len; |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
796 demux->filepos = stream_tell(demux->stream); |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
797 pack = new_demux_packet(STREAM_BUFFER_SIZE); |
16369 | 798 len = stream_read(demux->stream, pack->buffer, STREAM_BUFFER_SIZE); |
799 if (len <= 0) | |
17779 | 800 { |
801 free_demux_packet(pack); | |
16369 | 802 return 0; |
17779 | 803 } |
16369 | 804 { |
805 register uint32_t state = (uint32_t)demux->priv; | |
806 register int pos = -len; | |
807 unsigned char *buf = &pack->buffer[len]; | |
808 do { | |
809 state = state << 8 | buf[pos]; | |
810 if (unlikely((state | 3) == 0x1bf)) | |
811 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
|
812 } while (++pos < 0); |
16369 | 813 demux->priv = (void *)state; |
814 len = buf - pack->buffer; | |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
815 } |
16369 | 816 if (len < STREAM_BUFFER_SIZE) |
817 resize_demux_packet(pack, len); | |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
818 ds_add_packet(ds, pack); |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
819 return 1; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
820 } |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
821 |
30570
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30088
diff
changeset
|
822 static int demux_mpg_fill_buffer(demuxer_t *demux, demux_stream_t *ds) |
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30088
diff
changeset
|
823 { |
1 | 824 unsigned int head=0; |
825 int skipped=0; | |
5570
3a8d8c51355a
max_packs increased for some dvd with too many audio/sub
arpi
parents:
4711
diff
changeset
|
826 int max_packs=256; // 512kbyte |
1 | 827 int ret=0; |
828 | |
829 // System stream | |
830 do{ | |
831 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
|
832 //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
|
833 //(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
|
834 demux->movi_end = demux->stream->end_pos; |
1 | 835 head=stream_read_dword(demux->stream); |
547 | 836 if((head&0xFFFFFF00)!=0x100){ |
837 // sync... | |
838 demux->filepos-=skipped; | |
839 while(1){ | |
536 | 840 int c=stream_read_char(demux->stream); |
841 if(c<0) break; //EOF | |
842 head<<=8; | |
843 if(head!=0x100){ | |
844 head|=c; | |
4711 | 845 if(mp_check_mp3_header(head)) ++num_mp3audio_packets; |
536 | 846 ++skipped; //++demux->filepos; |
847 continue; | |
848 } | |
849 head|=c; | |
850 break; | |
547 | 851 } |
852 demux->filepos+=skipped; | |
1 | 853 } |
854 if(stream_eof(demux->stream)) break; | |
855 // sure: head=0x000001XX | |
1567 | 856 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"*** head=0x%X\n",head); |
1 | 857 if(demux->synced==0){ |
3770 | 858 if(head==0x1BA) demux->synced=1; //else |
859 // if(head==0x1BD || (head>=0x1C0 && head<=0x1EF)) demux->synced=3; // PES? | |
1 | 860 } else |
861 if(demux->synced==1){ | |
929 | 862 if(head==0x1BB || head==0x1BD || (head>=0x1C0 && head<=0x1EF)){ |
1 | 863 demux->synced=2; |
17366 | 864 mp_msg(MSGT_DEMUX,MSGL_V,"system stream synced at 0x%"PRIX64" (%"PRId64")!\n",(int64_t)demux->filepos,(int64_t)demux->filepos); |
536 | 865 num_elementary_packets100=0; // requires for re-sync! |
866 num_elementary_packets101=0; // requires for re-sync! | |
1 | 867 } else demux->synced=0; |
868 } // else | |
3255
ee28577dad02
combined PS/PES sync to allow .VDR playback from stdin
arpi
parents:
2555
diff
changeset
|
869 if(demux->synced>=2){ |
1 | 870 ret=demux_mpg_read_packet(demux,head); |
871 if(!ret) | |
872 if(--max_packs==0){ | |
873 demux->stream->eof=1; | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1735
diff
changeset
|
874 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_DoesntContainSelectedStream); |
1 | 875 return 0; |
876 } | |
36412 | 877 if(demux->synced == 3) { // PES detect |
878 update_stats(head); | |
879 if (ret < 0) demux->synced = 0; | |
880 else if (ret == 1 && num_elementary_packetsPES > 1 && !mpeg_pts_error) demux->synced = 2; | |
881 else ret = 0; | |
882 } | |
1 | 883 } else { |
22034
a3d208daed8c
moved scoreboarding code to 2 separate functions (update_stats() and clear_stats()) to be reused next
nicodvb
parents:
22021
diff
changeset
|
884 update_stats(head); |
22035 | 885 if(head>=0x100 && head<0x1B0) |
1567 | 886 mp_msg(MSGT_DEMUX,MSGL_DBG3,"Opps... elementary video packet found: %03X\n",head); |
22035 | 887 else if((head>=0x1C0 && head<0x1F0) || head==0x1BD) |
1567 | 888 mp_msg(MSGT_DEMUX,MSGL_DBG3,"Opps... PES packet found: %03X\n",head); |
21919 | 889 |
22035 | 890 if(((num_elementary_packets100>50 && num_elementary_packets101>50) || |
891 (num_elementary_packetsPES>50)) && skipped>4000000){ | |
1567 | 892 mp_msg(MSGT_DEMUX,MSGL_V,"sync_mpeg_ps: seems to be ES/PES stream...\n"); |
1 | 893 demux->stream->eof=1; |
894 break; | |
895 } | |
4711 | 896 if(num_mp3audio_packets>100 && num_elementary_packets100<10){ |
897 mp_msg(MSGT_DEMUX,MSGL_V,"sync_mpeg_ps: seems to be MP3 stream...\n"); | |
898 demux->stream->eof=1; | |
899 break; | |
900 } | |
1 | 901 } |
902 } while(ret!=1); | |
1567 | 903 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"demux: %d bad bytes skipped\n",skipped); |
1 | 904 if(demux->stream->eof){ |
1567 | 905 mp_msg(MSGT_DEMUX,MSGL_V,"MPEG Stream reached EOF\n"); |
1 | 906 return 0; |
907 } | |
908 return 1; | |
909 } | |
910 | |
30570
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30088
diff
changeset
|
911 static void demux_seek_mpg(demuxer_t *demuxer, float rel_seek_secs, |
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30088
diff
changeset
|
912 float audio_delay, int flags) |
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30088
diff
changeset
|
913 { |
1466 | 914 demux_stream_t *d_audio=demuxer->audio; |
915 demux_stream_t *d_video=demuxer->video; | |
916 sh_audio_t *sh_audio=d_audio->sh; | |
917 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
|
918 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
|
919 int precision = 1; |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
920 float oldpts = 0; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
921 off_t oldpos = demuxer->filepos; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
922 float newpts = 0; |
25883
baf32110d3fc
Use defines to give names to the different seek flags.
reimar
parents:
25838
diff
changeset
|
923 off_t newpos = (flags & SEEK_ABSOLUTE) ? demuxer->movi_start : oldpos; |
1466 | 924 |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
925 if(mpg_d) |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
926 oldpts = mpg_d->last_pts; |
25883
baf32110d3fc
Use defines to give names to the different seek flags.
reimar
parents:
25838
diff
changeset
|
927 newpts = (flags & SEEK_ABSOLUTE) ? 0.0 : oldpts; |
1466 | 928 //================= seek in MPEG ========================== |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
929 //calculate the pts to seek to |
25883
baf32110d3fc
Use defines to give names to the different seek flags.
reimar
parents:
25838
diff
changeset
|
930 if(flags & SEEK_FACTOR) { |
22021
71d78117fbf0
set has_valid_timestamps and corresponding first and final pts only after
nicodvb
parents:
21979
diff
changeset
|
931 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
|
932 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
|
933 else |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
934 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
|
935 } else |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
936 newpts += rel_seek_secs; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
937 if (newpts < 0) newpts = 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
938 |
25883
baf32110d3fc
Use defines to give names to the different seek flags.
reimar
parents:
25838
diff
changeset
|
939 if(flags&SEEK_FACTOR){ |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
940 // float seek 0..1 |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
941 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
|
942 } else { |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
943 // time seek (secs) |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
944 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
|
945 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
|
946 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
|
947 else if (oldpts > 0.0) |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
948 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
|
949 } 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
|
950 newpos+=2324*75*rel_seek_secs; // 174.3 kbyte/sec |
1466 | 951 else |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
952 newpos+=sh_video->i_bps*rel_seek_secs; |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
953 } |
1466 | 954 |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
955 while (1) { |
4391
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
956 if(newpos<demuxer->movi_start){ |
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
957 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
|
958 if(newpos<demuxer->movi_start) newpos=demuxer->movi_start; |
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
959 } |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
960 |
1466 | 961 stream_seek(demuxer->stream,newpos); |
962 | |
963 // re-sync video: | |
964 videobuf_code_len=0; // reset ES stream buffer | |
965 | |
966 ds_fill_buffer(d_video); | |
967 if(sh_audio){ | |
968 ds_fill_buffer(d_audio); | |
969 } | |
970 | |
971 while(1){ | |
972 int i; | |
973 if(sh_audio && !d_audio->eof && d_video->pts && d_audio->pts){ | |
974 float a_pts=d_audio->pts; | |
975 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; | |
976 if(d_video->pts>a_pts){ | |
977 skip_audio_frame(sh_audio); // sync audio | |
978 continue; | |
979 } | |
980 } | |
17821 | 981 if(!sh_video) break; |
1466 | 982 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
|
983 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
|
984 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
|
985 break; |
bea181ba1df4
when seeking and the codec is VC1 sync to sequence or entry point headers
nicodvb
parents:
22094
diff
changeset
|
986 } else |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
987 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
|
988 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
|
989 int pos = videobuf_len; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
990 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
|
991 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
|
992 } |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
993 } else if(sh_video->format == 0x10000005){ //h264 |
17289 | 994 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
|
995 } else { //default mpeg1/2 |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
996 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
|
997 } |
1466 | 998 if(!i || !skip_video_packet(d_video)) break; // EOF? |
999 } | |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
1000 if(!mpg_d) |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
1001 break; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
1002 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
|
1003 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
|
1004 mpg_d->has_valid_timestamps = 0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
1005 break; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
1006 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
1007 precision--; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
1008 //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
|
1009 if(mpg_d) { |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
1010 newpos += (newpts - mpg_d->last_pts) * (newpos - oldpos) / (mpg_d->last_pts - oldpts); |
26927 | 1011 demux_flush(demuxer); |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
1012 demuxer->stream->eof=0; // clear eof flag |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
1013 d_video->eof=0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
1014 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
|
1015 } |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
1016 } |
1466 | 1017 } |
1018 | |
30570
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30088
diff
changeset
|
1019 static int demux_mpg_control(demuxer_t *demuxer, int cmd, void *arg) |
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30088
diff
changeset
|
1020 { |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
1021 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
|
1022 |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1023 switch(cmd) { |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1024 case DEMUXER_CTRL_GET_TIME_LENGTH: |
24257 | 1025 if(stream_control(demuxer->stream, STREAM_CTRL_GET_TIME_LENGTH, arg) != STREAM_UNSUPPORTED) { |
32352
76f94c00a69f
1000l, %lf is not valid format string for printf (only for scanf) and actually
reimar
parents:
32345
diff
changeset
|
1026 mp_msg(MSGT_DEMUXER,MSGL_DBG2,"\r\nDEMUX_MPG_CTRL, (%.3f)\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
|
1027 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
|
1028 } |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
1029 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
|
1030 *((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
|
1031 return DEMUXER_CTRL_OK; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
1032 } |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1033 return DEMUXER_CTRL_DONTKNOW; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1034 |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1035 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
|
1036 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
|
1037 *((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
|
1038 return DEMUXER_CTRL_OK; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
1039 } |
14502
8769fa370f83
Move generic length and percent pos calculation to demuxer.c
reimar
parents:
14426
diff
changeset
|
1040 return DEMUXER_CTRL_DONTKNOW; |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1041 |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
1042 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
|
1043 if(! (mpg_d && mpg_d->num_a_streams > 1 && demuxer->audio && demuxer->audio->sh)) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
1044 return DEMUXER_CTRL_NOTIMPL; |
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
|
1045 else { |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
1046 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
|
1047 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
|
1048 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
|
1049 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
|
1050 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
|
1051 return DEMUXER_CTRL_NOTIMPL; |
15285
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
1052 if (*((int*)arg) < 0) |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
1053 { |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
1054 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
|
1055 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
|
1056 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
1057 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
|
1058 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
|
1059 } |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
1060 else { |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
1061 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
|
1062 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
|
1063 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
|
1064 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
|
1065 } |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
1066 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
|
1067 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
|
1068 d_audio->sh = sh_a; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
1069 ds_free_packs(d_audio); |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
1070 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
1071 } |
15285
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
1072 *((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
|
1073 return DEMUXER_CTRL_OK; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
1074 |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1075 default: |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1076 return DEMUXER_CTRL_NOTIMPL; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1077 } |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
1078 } |
16175 | 1079 |
1080 | |
1081 static int demux_mpg_pes_probe(demuxer_t *demuxer) { | |
1082 demuxer->synced = 3; | |
36411 | 1083 return (demux_mpg_probe(demuxer) == DEMUXER_TYPE_MPEG_PS) ? DEMUXER_TYPE_MPEG_PES : DEMUXER_TYPE_UNKNOWN; |
16175 | 1084 } |
1085 | |
1086 | |
1087 static demuxer_t* demux_mpg_es_open(demuxer_t* demuxer) | |
1088 { | |
1089 sh_video_t *sh_video=NULL; | |
1090 | |
1091 demuxer->audio->sh = NULL; // ES streams has no audio channel | |
1092 demuxer->video->sh = new_sh_video(demuxer,0); // create dummy video stream header, id=0 | |
1093 sh_video=demuxer->video->sh;sh_video->ds=demuxer->video; | |
1094 | |
1095 return demuxer; | |
1096 } | |
1097 | |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1098 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
|
1099 demuxer->audio->sh = NULL; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1100 demuxer->video->sh = new_sh_video(demuxer,0); |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1101 ((sh_video_t *)demuxer->video->sh)->ds = demuxer->video; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1102 demuxer->priv = (void *) 0xffffffff; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1103 return demuxer; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1104 } |
16175 | 1105 |
1106 static demuxer_t* demux_mpg_ps_open(demuxer_t* demuxer) | |
1107 { | |
1108 sh_audio_t *sh_audio=NULL; | |
1109 sh_video_t *sh_video=NULL; | |
1110 | |
1111 sh_video=demuxer->video->sh;sh_video->ds=demuxer->video; | |
1112 | |
1113 if(demuxer->audio->id!=-2) { | |
1114 if(!ds_fill_buffer(demuxer->audio)){ | |
1115 mp_msg(MSGT_DEMUXER,MSGL_INFO,"MPEG: " MSGTR_MissingAudioStream); | |
1116 demuxer->audio->sh=NULL; | |
1117 } else { | |
1118 sh_audio=demuxer->audio->sh;sh_audio->ds=demuxer->audio; | |
1119 } | |
1120 } | |
1121 | |
22037
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1122 if(!sh_video->format && ps_probe > 0) { |
22088 | 1123 int head; |
22037
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1124 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
|
1125 |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1126 clear_stats(); |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1127 do { |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1128 head=sync_video_packet(demuxer->video); |
22041
f0172904ff02
sanity checks during codec detection; also reset demuxer->stream->eof
nicodvb
parents:
22037
diff
changeset
|
1129 if(!head) break; |
22037
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1130 update_stats(head); |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1131 skip_video_packet(demuxer->video); |
22041
f0172904ff02
sanity checks during codec detection; also reset demuxer->stream->eof
nicodvb
parents:
22037
diff
changeset
|
1132 } 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
|
1133 |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1134 ds_free_packs(demuxer->video); |
22041
f0172904ff02
sanity checks during codec detection; also reset demuxer->stream->eof
nicodvb
parents:
22037
diff
changeset
|
1135 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
|
1136 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
|
1137 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
|
1138 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
|
1139 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
|
1140 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
|
1141 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
|
1142 |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1143 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
|
1144 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
|
1145 sh_video->format = 0x10000004; |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1146 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
|
1147 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
|
1148 num_elementary_packets1B6==0) |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1149 sh_video->format = 0x10000005; |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1150 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
|
1151 } |
489b443a8ecf
added code to scan the video stream to search the actual video codec used;
nicodvb
parents:
22036
diff
changeset
|
1152 |
16175 | 1153 return demuxer; |
1154 } | |
1155 | |
1156 | |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
24946
diff
changeset
|
1157 const demuxer_desc_t demuxer_desc_mpeg_ps = { |
16175 | 1158 "MPEG PS demuxer", |
1159 "mpegps", | |
1160 "MPEG-PS", | |
1161 "Arpi?", | |
1162 "Mpeg", | |
1163 DEMUXER_TYPE_MPEG_PS, | |
1164 0, // unsafe autodetect | |
1165 demux_mpg_probe, | |
1166 demux_mpg_fill_buffer, | |
1167 demux_mpg_ps_open, | |
1168 demux_close_mpg, | |
1169 demux_seek_mpg, | |
16771
82a56c89b54d
10l, demux_mpg_control was missing from demuxer info struct, causing audio
reimar
parents:
16369
diff
changeset
|
1170 demux_mpg_control, |
16175 | 1171 }; |
1172 | |
1173 | |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
24946
diff
changeset
|
1174 const demuxer_desc_t demuxer_desc_mpeg_pes = { |
16175 | 1175 "MPEG PES demuxer", |
1176 "mpegpes", | |
1177 "MPEG-PES", | |
1178 "Arpi?", | |
1179 "Mpeg", | |
1180 DEMUXER_TYPE_MPEG_PES, | |
1181 0, // unsafe autodetect | |
1182 demux_mpg_pes_probe, | |
1183 demux_mpg_fill_buffer, | |
16314 | 1184 demux_mpg_ps_open, |
16175 | 1185 demux_close_mpg, |
1186 demux_seek_mpg, | |
16771
82a56c89b54d
10l, demux_mpg_control was missing from demuxer info struct, causing audio
reimar
parents:
16369
diff
changeset
|
1187 demux_mpg_control, |
16175 | 1188 }; |
1189 | |
1190 | |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
24946
diff
changeset
|
1191 const demuxer_desc_t demuxer_desc_mpeg_gxf = { |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1192 "MPEG ES in GXF demuxer", |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1193 "mpeggxf", |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1194 "MPEG-ES in GXF", |
22507
a46ab26b2d5e
Source files should not contain non-ASCII characters.
diego
parents:
22363
diff
changeset
|
1195 "Reimar Doeffinger", |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1196 "Mpeg", |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1197 DEMUXER_TYPE_MPEG_GXF, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1198 0, // hack autodetection |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1199 NULL, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1200 demux_mpg_gxf_fill_buffer, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1201 demux_mpg_gxf_open, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1202 NULL, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1203 NULL, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1204 NULL |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1205 }; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
1206 |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
24946
diff
changeset
|
1207 const demuxer_desc_t demuxer_desc_mpeg_es = { |
16175 | 1208 "MPEG ES demuxer", |
1209 "mpeges", | |
1210 "MPEG-ES", | |
1211 "Arpi?", | |
1212 "Mpeg", | |
1213 DEMUXER_TYPE_MPEG_ES, | |
1214 0, // hack autodetection | |
1215 NULL, | |
1216 demux_mpg_es_fill_buffer, | |
1217 demux_mpg_es_open, | |
1218 demux_close_mpg, | |
1219 demux_seek_mpg, | |
16771
82a56c89b54d
10l, demux_mpg_control was missing from demuxer info struct, causing audio
reimar
parents:
16369
diff
changeset
|
1220 demux_mpg_control, |
16175 | 1221 }; |
1222 | |
1223 | |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
24946
diff
changeset
|
1224 const demuxer_desc_t demuxer_desc_mpeg4_es = { |
16175 | 1225 "MPEG4 ES demuxer", |
1226 "mpeg4es", | |
1227 "MPEG-ES", | |
1228 "Arpi?", | |
1229 "Mpeg", | |
1230 DEMUXER_TYPE_MPEG4_ES, | |
1231 0, // hack autodetection | |
1232 NULL, | |
1233 demux_mpg_es_fill_buffer, | |
1234 demux_mpg_es_open, | |
1235 demux_close_mpg, | |
1236 demux_seek_mpg, | |
16771
82a56c89b54d
10l, demux_mpg_control was missing from demuxer info struct, causing audio
reimar
parents:
16369
diff
changeset
|
1237 demux_mpg_control, |
16175 | 1238 }; |
1239 | |
1240 | |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
24946
diff
changeset
|
1241 const demuxer_desc_t demuxer_desc_h264_es = { |
16175 | 1242 "H.264 ES demuxer", |
1243 "h264es", | |
1244 "H264-ES", | |
1245 "Arpi?", | |
1246 "Mpeg", | |
1247 DEMUXER_TYPE_H264_ES, | |
1248 0, // hack autodetection | |
1249 NULL, | |
1250 demux_mpg_es_fill_buffer, | |
1251 demux_mpg_es_open, | |
1252 demux_close_mpg, | |
1253 demux_seek_mpg, | |
16771
82a56c89b54d
10l, demux_mpg_control was missing from demuxer info struct, causing audio
reimar
parents:
16369
diff
changeset
|
1254 demux_mpg_control, |
16175 | 1255 }; |