Mercurial > mplayer.hg
annotate libmpdemux/demux_mpg.c @ 21929:145ca84ffbf7
unified creation of sh_audio and sh_video is ts_add_stream; patch by elupus
author | nicodvb |
---|---|
date | Wed, 17 Jan 2007 00:12:35 +0000 |
parents | ee422890bca9 |
children | a18fc58a4900 |
rev | line source |
---|---|
1 | 1 // MPG/VOB file parser for DEMUXER v2.5 by A'rpi/ESP-team |
2 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
3 #include <stdio.h> |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
4 #include <stdlib.h> |
1430 | 5 #include <unistd.h> |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
6 |
1567 | 7 #include "config.h" |
8 #include "mp_msg.h" | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1735
diff
changeset
|
9 #include "help_mp.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
10 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
11 #include "stream.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
12 #include "demuxer.h" |
1466 | 13 #include "parse_es.h" |
2338 | 14 #include "stheader.h" |
4711 | 15 #include "mp3_hdr.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
16 |
524
9105fc95636c
A fast'n'ugly hack to correct DVD VOB playback problems
lgb
parents:
501
diff
changeset
|
17 //#define MAX_PS_PACKETSIZE 2048 |
501 | 18 #define MAX_PS_PACKETSIZE (224*1024) |
19 | |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
20 #define UNKNOWN 0 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
21 #define VIDEO_MPEG1 0x10000001 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
22 #define VIDEO_MPEG2 0x10000002 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
23 #define VIDEO_MPEG4 0x10000004 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
24 #define VIDEO_H264 0x10000005 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
25 #define AUDIO_MP2 0x50 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
26 #define AUDIO_A52 0x2000 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
27 #define AUDIO_LPCM_BE 0x10001 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
28 #define AUDIO_AAC mmioFOURCC('M', 'P', '4', 'A') |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
29 |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
30 typedef struct mpg_demuxer { |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
31 float last_pts; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
32 float final_pts; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
33 int has_valid_timestamps; |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
34 unsigned int es_map[0x40]; //es map of stream types (associated to the pes id) from 0xb0 to 0xef |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
35 int num_a_streams; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
36 int a_stream_ids[MAX_A_STREAMS]; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
37 } mpg_demuxer_t; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
38 |
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
|
39 extern char* dvdsub_lang; |
547 | 40 static int mpeg_pts_error=0; |
41 | |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
42 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
|
43 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
|
44 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
|
45 mpg_demuxer_t *priv = (mpg_demuxer_t *) demux->priv; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
46 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
47 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
|
48 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
|
49 return 0; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
50 |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
51 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
|
52 if(! (c & 0x80)) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
53 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
|
54 return 0; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
55 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 while(es_map_len > 0) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 int idoffset = id - 0xB0; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
66 switch(type) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
67 case 0x1: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
68 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
|
69 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
70 case 0x2: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
71 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
|
72 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
73 case 0x3: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
74 case 0x4: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
75 priv->es_map[idoffset] = AUDIO_MP2; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
76 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
77 case 0x0f: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
78 case 0x11: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
79 priv->es_map[idoffset] = AUDIO_AAC; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
80 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
81 case 0x10: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
82 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
|
83 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
84 case 0x1b: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
85 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
|
86 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
87 case 0x81: |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
88 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
|
89 break; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
90 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
91 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
|
92 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 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
|
97 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
98 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
|
99 return 1; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
100 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
101 |
18072
284751bccd04
make sure the check for valid timestamps does not accidentially search through
reimar
parents:
17822
diff
changeset
|
102 // 500000 is a wild guess |
284751bccd04
make sure the check for valid timestamps does not accidentially search through
reimar
parents:
17822
diff
changeset
|
103 #define TIMESTAMP_PROBE_LEN 500000 |
284751bccd04
make sure the check for valid timestamps does not accidentially search through
reimar
parents:
17822
diff
changeset
|
104 |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
105 /// Open an mpg physical stream |
16175 | 106 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
|
107 stream_t *s = demuxer->stream; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
108 off_t pos = stream_tell(s); |
19896
7f0caf768528
demuxer->movi_end is updated after ds_fill_buffer(),
nicodvb
parents:
19182
diff
changeset
|
109 off_t end_seq_start; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
110 float half_pts = 0.0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
111 mpg_demuxer_t* mpg_d; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
112 |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
113 if (!ds_fill_buffer(demuxer->video)) return 0; |
19896
7f0caf768528
demuxer->movi_end is updated after ds_fill_buffer(),
nicodvb
parents:
19182
diff
changeset
|
114 end_seq_start = demuxer->movi_end-TIMESTAMP_PROBE_LEN; |
18885 | 115 mpg_d = calloc(1,sizeof(mpg_demuxer_t)); |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
116 demuxer->priv = mpg_d; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
117 mpg_d->final_pts = 0.0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
118 mpg_d->has_valid_timestamps = 1; |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
119 mpg_d->num_a_streams = 0; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
120 if (demuxer->seekable && stream_tell(demuxer->stream) < end_seq_start) { |
18072
284751bccd04
make sure the check for valid timestamps does not accidentially search through
reimar
parents:
17822
diff
changeset
|
121 off_t half_pos = pos + end_seq_start / 2; |
284751bccd04
make sure the check for valid timestamps does not accidentially search through
reimar
parents:
17822
diff
changeset
|
122 stream_seek(s, half_pos); |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
123 while ((!s->eof) && ds_fill_buffer(demuxer->video) && half_pts == 0.0) { |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
124 half_pts = mpg_d->last_pts; |
18072
284751bccd04
make sure the check for valid timestamps does not accidentially search through
reimar
parents:
17822
diff
changeset
|
125 if (stream_tell(s) > half_pos + TIMESTAMP_PROBE_LEN) |
284751bccd04
make sure the check for valid timestamps does not accidentially search through
reimar
parents:
17822
diff
changeset
|
126 break; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
127 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
128 stream_seek(s,end_seq_start); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
129 while ((!s->eof) && ds_fill_buffer(demuxer->video)) { |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
130 if (mpg_d->final_pts < mpg_d->last_pts) mpg_d->final_pts = mpg_d->last_pts; |
18072
284751bccd04
make sure the check for valid timestamps does not accidentially search through
reimar
parents:
17822
diff
changeset
|
131 if (stream_tell(s) > demuxer->movi_end) |
284751bccd04
make sure the check for valid timestamps does not accidentially search through
reimar
parents:
17822
diff
changeset
|
132 break; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
133 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
134 // educated guess about validity of timestamps |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
135 if (mpg_d->final_pts > 3 * half_pts || mpg_d->final_pts < 1.5 * half_pts) { |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
136 mpg_d->has_valid_timestamps = 0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
137 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
138 ds_free_packs(demuxer->audio); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
139 ds_free_packs(demuxer->video); |
20005
447e41fbcb4e
Reset demuxer->sub (consistently with audio and video) after seeking and at the end
nicodvb
parents:
19896
diff
changeset
|
140 ds_free_packs(demuxer->sub); |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
141 demuxer->stream->eof=0; // clear eof flag |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
142 demuxer->video->eof=0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
143 demuxer->audio->eof=0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
144 |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
145 stream_seek(s,pos); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
146 ds_fill_buffer(demuxer->video); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
147 } |
16175 | 148 return demuxer; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
149 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
150 |
16175 | 151 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
|
152 mpg_demuxer_t* mpg_d = demuxer->priv; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
153 if (mpg_d) free(mpg_d); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
154 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
155 |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
156 |
18077
cede662f40a5
timestamps are 33 bits long, so they don't fit in an unsigned int; 10l
nicodvb
parents:
18072
diff
changeset
|
157 static unsigned long long read_mpeg_timestamp(stream_t *s,int c){ |
18381 | 158 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
|
159 unsigned long long pts; |
1 | 160 d=stream_read_word(s); |
161 e=stream_read_word(s); | |
547 | 162 if( ((c&1)!=1) || ((d&1)!=1) || ((e&1)!=1) ){ |
163 ++mpeg_pts_error; | |
164 return 0; // invalid pts | |
165 } | |
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
|
166 pts=(((uint64_t)((c>>1)&7))<<30)|((d>>1)<<15)|(e>>1); |
18382 | 167 mp_dbg(MSGT_DEMUX,MSGL_DBG3," pts {%"PRIu64"}",pts); |
1 | 168 return pts; |
169 } | |
170 | |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
171 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
|
172 if(!demux->a_streams[aid]){ |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
173 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
|
174 sh_audio_t* sh_a; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
175 new_sh_audio(demux,aid); |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
176 sh_a = (sh_audio_t*)demux->a_streams[aid]; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 } |
21927
ee422890bca9
in evo files [e]ac3 substreams range from 0xc0 to 0xcf
nicodvb
parents:
21919
diff
changeset
|
183 //evo files |
ee422890bca9
in evo files [e]ac3 substreams range from 0xc0 to 0xcf
nicodvb
parents:
21919
diff
changeset
|
184 if(aid & 0xC0 == 0xC0) sh_a->format=0x2000; |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
185 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
|
186 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
187 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
|
188 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
189 |
1 | 190 static int demux_mpg_read_packet(demuxer_t *demux,int id){ |
191 int d; | |
192 int len; | |
193 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
|
194 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
|
195 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
|
196 int l; |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
197 double stream_pts = MP_NOPTS_VALUE; |
1 | 198 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
|
199 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
|
200 mpg_demuxer_t *priv = (mpg_demuxer_t *) demux->priv; |
1 | 201 |
1567 | 202 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"demux_read_packet: %X\n",id); |
1 | 203 |
536 | 204 // if(id==0x1F0){ |
205 // demux->synced=0; // force resync after 0x1F0 | |
206 // return -1; | |
207 //} | |
501 | 208 |
1 | 209 // if(id==0x1BA) packet_start_pos=stream_tell(demux->stream); |
501 | 210 if(id<0x1BC || id>=0x1F0) return -1; |
1 | 211 if(id==0x1BE) return -1; // padding stream |
212 if(id==0x1BF) return -1; // private2 | |
213 | |
214 len=stream_read_word(demux->stream); | |
1567 | 215 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"PACKET len=%d",len); |
536 | 216 // if(len==62480){ demux->synced=0;return -1;} /* :) */ |
501 | 217 if(len==0 || len>MAX_PS_PACKETSIZE){ |
1567 | 218 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Invalid PS packet len: %d\n",len); |
501 | 219 return -2; // invalid packet !!!!!! |
220 } | |
1 | 221 |
547 | 222 mpeg_pts_error=0; |
223 | |
14923
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
224 if(id==0x1BC) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
225 parse_psm(demux, len); |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
226 return 0; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
227 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
228 |
1 | 229 while(len>0){ // Skip stuFFing bytes |
230 c=stream_read_char(demux->stream);--len; | |
231 if(c!=0xFF)break; | |
232 } | |
233 if((c>>6)==1){ // Read (skip) STD scale & size value | |
234 // printf(" STD_scale=%d",(c>>5)&1); | |
235 d=((c&0x1F)<<8)|stream_read_char(demux->stream); | |
236 len-=2; | |
237 // printf(" STD_size=%d",d); | |
238 c=stream_read_char(demux->stream); | |
239 } | |
240 // Read System-1 stream timestamps: | |
241 if((c>>4)==2){ | |
242 pts=read_mpeg_timestamp(demux->stream,c); | |
243 len-=4; | |
244 } else | |
245 if((c>>4)==3){ | |
246 pts=read_mpeg_timestamp(demux->stream,c); | |
247 c=stream_read_char(demux->stream); | |
248 if((c>>4)!=1) pts=0; //printf("{ERROR4}"); | |
249 dts=read_mpeg_timestamp(demux->stream,c); | |
250 len-=4+1+4; | |
251 } else | |
252 if((c>>6)==2){ | |
253 int pts_flags; | |
254 int hdrlen; | |
255 // System-2 (.VOB) stream: | |
256 c=stream_read_char(demux->stream); pts_flags=c>>6; | |
257 c=stream_read_char(demux->stream); hdrlen=c; | |
258 len-=2; | |
1567 | 259 mp_dbg(MSGT_DEMUX,MSGL_DBG3," hdrlen=%d (len=%d)",hdrlen,len); |
260 if(hdrlen>len){ mp_msg(MSGT_DEMUX,MSGL_V,"demux_mpg: invalid header length \n"); return -1;} | |
7671 | 261 if(pts_flags==2 && hdrlen>=5){ |
1 | 262 c=stream_read_char(demux->stream); |
263 pts=read_mpeg_timestamp(demux->stream,c); | |
264 len-=5;hdrlen-=5; | |
265 } else | |
7671 | 266 if(pts_flags==3 && hdrlen>=10){ |
1 | 267 c=stream_read_char(demux->stream); |
268 pts=read_mpeg_timestamp(demux->stream,c); | |
269 c=stream_read_char(demux->stream); | |
270 dts=read_mpeg_timestamp(demux->stream,c); | |
271 len-=10;hdrlen-=10; | |
272 } | |
273 len-=hdrlen; | |
274 if(hdrlen>0) stream_skip(demux->stream,hdrlen); // skip header bytes | |
275 | |
276 //============== DVD Audio sub-stream ====================== | |
277 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
|
278 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
|
279 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
|
280 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
|
281 |
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
|
282 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
|
283 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
|
284 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
|
285 /// 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
|
286 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
|
287 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
|
288 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
|
289 } |
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
|
290 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
|
291 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
|
292 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
|
293 } |
552 | 294 |
295 // AID: | |
296 // 0x20..0x3F subtitle | |
297 // 0x80..0x9F AC3 audio | |
298 // 0xA0..0xBF PCM audio | |
299 | |
300 if((aid & 0xE0) == 0x20){ | |
301 // subtitle: | |
302 aid&=0x1F; | |
426 | 303 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
304 if(!demux->s_streams[aid]){ |
1567 | 305 mp_msg(MSGT_DEMUX,MSGL_V,"==> Found subtitle: %d\n",aid); |
20872
a8b42366e68a
Make subtitle stream handling more similar to audio and video streams.
reimar
parents:
20851
diff
changeset
|
306 new_sh_sub(demux, aid); |
552 | 307 } |
308 | |
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
|
309 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
|
310 demux->sub->id &= 0x1F; |
b0046966ab82
don't reset dvdsub->id unless -slang is specified; assign default sub stream id when demux->sub->id is -1 (autodetect)
nicodvb
parents:
16877
diff
changeset
|
311 if(!dvdsub_lang && demux->sub->id == -1) |
b0046966ab82
don't reset dvdsub->id unless -slang is specified; assign default sub stream id when demux->sub->id is -1 (autodetect)
nicodvb
parents:
16877
diff
changeset
|
312 demux->sub->id = aid; |
552 | 313 if(demux->sub->id==aid){ |
314 ds=demux->sub; | |
315 } | |
316 | |
21927
ee422890bca9
in evo files [e]ac3 substreams range from 0xc0 to 0xcf
nicodvb
parents:
21919
diff
changeset
|
317 } else if((aid & 0xC0) == 0x80 || (aid & 0xE0) == 0x00 || (aid & 0xC0) == 0xC0) { |
552 | 318 |
319 // aid=128+(aid&0x7F); | |
320 // aid=0x80..0xBF | |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
321 new_audio_stream(demux, aid); |
426 | 322 if(demux->audio->id==aid){ |
7671 | 323 int type; |
426 | 324 ds=demux->audio; |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
325 if(!ds->sh) ds->sh=demux->a_streams[aid]; |
1 | 326 // 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
|
327 if(!rawa52) { |
7671 | 328 c=stream_read_char(demux->stream);//num of frames |
329 type=stream_read_char(demux->stream);//startpos hi | |
330 type=(type<<8)|stream_read_char(demux->stream);//startpos lo | |
331 // printf("\r[%02X][%04X]",c,type); | |
1 | 332 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
|
333 } |
7671 | 334 if((aid&0xE0)==0xA0 && len>=3){ |
335 unsigned char* hdr; | |
336 // save audio header as codecdata! | |
337 if(!((sh_audio_t*)(ds->sh))->codecdata_len){ | |
338 ((sh_audio_t*)(ds->sh))->codecdata=malloc(3); | |
339 ((sh_audio_t*)(ds->sh))->codecdata_len=3; | |
340 } | |
341 hdr=((sh_audio_t*)(ds->sh))->codecdata; | |
342 // read LPCM header: | |
343 // emphasis[1], mute[1], rvd[1], frame number[5]: | |
344 hdr[0]=stream_read_char(demux->stream); | |
345 // printf(" [%01X:%02d]",c>>5,c&31); | |
346 // quantization[2],freq[2],rvd[1],channels[3] | |
347 hdr[1]=stream_read_char(demux->stream); | |
348 // printf("[%01X:%01X] ",c>>4,c&15); | |
349 // dynamic range control (0x80=off): | |
350 hdr[2]=stream_read_char(demux->stream); | |
351 // printf("[%02X] ",c); | |
352 len-=3; | |
353 if(len<=0) mp_msg(MSGT_DEMUX,MSGL_V,"End of packet while searching for PCM header\n"); | |
1 | 354 } |
7671 | 355 // printf(" \n"); |
552 | 356 } // if(demux->audio->id==aid) |
357 | |
1567 | 358 } else mp_msg(MSGT_DEMUX,MSGL_V,"Unknown 0x1BD substream: 0x%02X \n",aid); |
552 | 359 |
360 } //if(id==0x1BD) | |
1 | 361 |
362 } else { | |
539 | 363 if(c!=0x0f){ |
1567 | 364 mp_msg(MSGT_DEMUX,MSGL_V," {ERROR5,c=%d} \n",c); |
539 | 365 return -1; // invalid packet !!!!!! |
366 } | |
1 | 367 } |
1567 | 368 if(mpeg_pts_error) mp_msg(MSGT_DEMUX,MSGL_V," {PTS_err:%d} \n",mpeg_pts_error); |
369 mp_dbg(MSGT_DEMUX,MSGL_DBG3," => len=%d\n",len); | |
1 | 370 |
501 | 371 // if(len<=0 || len>MAX_PS_PACKETSIZE) return -1; // Invalid packet size |
372 if(len<=0 || len>MAX_PS_PACKETSIZE){ | |
1567 | 373 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"Invalid PS data len: %d\n",len); |
501 | 374 return -1; // invalid packet !!!!!! |
375 } | |
1 | 376 |
377 if(id>=0x1C0 && id<=0x1DF){ | |
378 // mpeg audio | |
379 int aid=id-0x1C0; | |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
380 new_audio_stream(demux, aid); |
1 | 381 if(demux->audio->id==aid){ |
382 ds=demux->audio; | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
383 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
|
384 if(priv && ds->sh) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
385 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
|
386 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
|
387 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
|
388 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
|
389 } |
1 | 390 } |
391 } else | |
392 if(id>=0x1E0 && id<=0x1EF){ | |
393 // mpeg video | |
394 int aid=id-0x1E0; | |
1289 | 395 if(!demux->v_streams[aid]) new_sh_video(demux,aid); |
1 | 396 if(demux->video->id==-1) demux->video->id=aid; |
426 | 397 if(demux->video->id==aid){ |
398 ds=demux->video; | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
554
diff
changeset
|
399 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
|
400 if(priv && ds->sh) { |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
401 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
|
402 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
|
403 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
|
404 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
|
405 } |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
406 } |
426 | 407 } |
1 | 408 } |
409 | |
410 if(ds){ | |
1567 | 411 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_MPG: Read %d data bytes from packet %04X\n",len,id); |
1 | 412 // 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
|
413 |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
414 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
|
415 if(!dp) { |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
416 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
|
417 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
|
418 return 0; |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
419 } |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
420 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
|
421 if(l<len) |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
422 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
|
423 len = l; |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
424 dp->pts=pts/90000.0f; |
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
425 dp->pos=demux->filepos; |
21789
b266f27109a6
set dp->stream_pts only when feeding the video stream to workaround
nicodvb
parents:
21781
diff
changeset
|
426 /* |
b266f27109a6
set dp->stream_pts only when feeding the video stream to workaround
nicodvb
parents:
21781
diff
changeset
|
427 workaround: |
b266f27109a6
set dp->stream_pts only when feeding the video stream to workaround
nicodvb
parents:
21781
diff
changeset
|
428 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
|
429 (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
|
430 back and forth |
b266f27109a6
set dp->stream_pts only when feeding the video stream to workaround
nicodvb
parents:
21781
diff
changeset
|
431 */ |
b266f27109a6
set dp->stream_pts only when feeding the video stream to workaround
nicodvb
parents:
21781
diff
changeset
|
432 if(ds == demux->video && stream_control(demux->stream, STREAM_CTRL_GET_CURRENT_TIME,(void *)&stream_pts)!=STREAM_UNSUPORTED) |
21781
36112fcf78d6
replace call to ds_read_packet() with the usual stream_read()+ds_add_packet() sequence;
nicodvb
parents:
21531
diff
changeset
|
433 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
|
434 ds_add_packet(ds,dp); |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
435 if (demux->priv) ((mpg_demuxer_t*)demux->priv)->last_pts = pts/90000.0f; |
554 | 436 // if(ds==demux->sub) parse_dvdsub(ds->last->buffer,ds->last->len); |
1 | 437 return 1; |
438 } | |
1567 | 439 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_MPG: Skipping %d data bytes from packet %04X\n",len,id); |
536 | 440 if(len<=2356) stream_skip(demux->stream,len); |
1 | 441 return 0; |
442 } | |
443 | |
15670 | 444 static int num_elementary_packets100=0; |
445 static int num_elementary_packets101=0; | |
446 static int num_elementary_packets12x=0; | |
447 static int num_elementary_packets1B6=0; | |
448 static int num_elementary_packetsPES=0; | |
449 static int num_h264_slice=0; //combined slice | |
450 static int num_h264_dpa=0; //DPA Slice | |
451 static int num_h264_dpb=0; //DPB Slice | |
452 static int num_h264_dpc=0; //DPC Slice | |
453 static int num_h264_idr=0; //IDR Slice | |
454 static int num_h264_sps=0; | |
455 static int num_h264_pps=0; | |
456 | |
457 static int num_mp3audio_packets=0; | |
458 | |
16175 | 459 static int demux_mpg_probe(demuxer_t *demuxer) { |
15670 | 460 int pes=1; |
461 int tmp; | |
462 off_t tmppos; | |
463 int file_format = DEMUXER_TYPE_UNKNOWN; | |
464 | |
465 tmppos=stream_tell(demuxer->stream); | |
466 tmp=stream_read_dword(demuxer->stream); | |
467 if(tmp==0x1E0 || tmp==0x1C0) { | |
468 tmp=stream_read_word(demuxer->stream); | |
469 if(tmp>1 && tmp<=2048) pes=0; // demuxer->synced=3; // PES... | |
470 } | |
471 stream_seek(demuxer->stream,tmppos); | |
472 | |
473 num_elementary_packets100=0; | |
474 num_elementary_packets101=0; | |
475 num_elementary_packets1B6=0; | |
476 num_elementary_packets12x=0; | |
477 num_elementary_packetsPES=0; | |
478 num_h264_slice=0; //combined slice | |
479 num_h264_dpa=0; //DPA Slice | |
480 num_h264_dpb=0; //DPB Slice | |
481 num_h264_dpc=0; //DPC Slice | |
482 num_h264_idr=0; //IDR Slice | |
483 num_h264_sps=0; | |
484 num_h264_pps=0; | |
485 num_mp3audio_packets=0; | |
9824 | 486 |
15670 | 487 if(demux_mpg_open(demuxer)) |
488 file_format=DEMUXER_TYPE_MPEG_PS; | |
489 else { | |
490 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", | |
491 num_elementary_packets100,num_elementary_packets101, | |
492 num_elementary_packets1B6,num_elementary_packets12x, | |
493 num_h264_slice, num_h264_dpa, | |
494 num_h264_dpb, num_h264_dpc=0, | |
495 num_h264_idr, num_h264_sps=0, | |
496 num_h264_pps, | |
497 num_elementary_packetsPES,num_mp3audio_packets, demuxer->synced); | |
498 | |
499 //MPEG packet stats: p100: 458 p101: 458 PES: 0 MP3: 1103 (.m2v) | |
500 if(num_mp3audio_packets>50 && num_mp3audio_packets>2*num_elementary_packets100 | |
501 && abs(num_elementary_packets100-num_elementary_packets101)>2) | |
502 return file_format; | |
503 | |
504 // some hack to get meaningfull error messages to our unhappy users: | |
505 if(num_elementary_packets100>=2 && num_elementary_packets101>=2 && | |
506 abs(num_elementary_packets101+8-num_elementary_packets100)<16) { | |
507 if(num_elementary_packetsPES>=4 && num_elementary_packetsPES>=num_elementary_packets100-4) { | |
508 return file_format; | |
509 } | |
510 file_format=DEMUXER_TYPE_MPEG_ES; // <-- hack is here :) | |
511 } else | |
512 // fuzzy mpeg4-es detection. do NOT enable without heavy testing of mpeg formats detection! | |
513 if(num_elementary_packets1B6>3 && num_elementary_packets12x>=1 && | |
514 num_elementary_packetsPES==0 && num_elementary_packets100<=num_elementary_packets12x && | |
515 demuxer->synced<2) { | |
516 file_format=DEMUXER_TYPE_MPEG4_ES; | |
517 } else | |
518 // fuzzy h264-es detection. do NOT enable without heavy testing of mpeg formats detection! | |
519 if((num_h264_slice>3 || (num_h264_dpa>3 && num_h264_dpb>3 && num_h264_dpc>3)) && | |
520 /* FIXME num_h264_sps>=1 && */ num_h264_pps>=1 && num_h264_idr>=1 && | |
521 num_elementary_packets1B6==0 && num_elementary_packetsPES==0 && | |
522 demuxer->synced<2) { | |
523 file_format=DEMUXER_TYPE_H264_ES; | |
524 } else | |
525 { | |
526 if(demuxer->synced==2) | |
527 mp_msg(MSGT_DEMUXER,MSGL_ERR,"MPEG: " MSGTR_MissingVideoStreamBug); | |
528 else | |
529 mp_msg(MSGT_DEMUXER,MSGL_V,MSGTR_NotSystemStream); | |
530 } | |
531 } | |
532 return file_format; | |
533 } | |
1 | 534 |
16175 | 535 static int demux_mpg_es_fill_buffer(demuxer_t *demux, demux_stream_t *ds){ |
1 | 536 // Elementary video stream |
537 if(demux->stream->eof) return 0; | |
538 demux->filepos=stream_tell(demux->stream); | |
1735 | 539 ds_read_packet(demux->video,demux->stream,STREAM_BUFFER_SIZE,0,demux->filepos,0); |
1 | 540 return 1; |
541 } | |
542 | |
16369 | 543 /** |
544 * \brief discard until 0x100 header and return a filled buffer | |
545 * \param b buffer-end pointer | |
546 * \param pos current pos in stream, negative since b points to end of buffer | |
547 * \param s stream to read from | |
548 * \return new position, differs from original pos when eof hit and thus | |
549 * b was modified to point to the new end of buffer | |
550 */ | |
551 static int find_end(unsigned char **b, int pos, stream_t *s) { | |
552 register int state = 0xffffffff; | |
553 unsigned char *buf = *b; | |
554 int start = pos; | |
555 int read, unused; | |
556 // search already read part | |
557 while (state != 0x100 && pos) { | |
558 state = state << 8 | buf[pos++]; | |
559 } | |
560 // continue search in stream | |
561 while (state != 0x100) { | |
562 register int c = stream_read_char(s); | |
563 if (c < 0) break; | |
564 state = state << 8 | c; | |
565 } | |
566 // modify previous header (from 0x1bc or 0x1bf to 0x100) | |
567 buf[start++] = 0; | |
568 // copy remaining buffer part to current pos | |
569 memmove(&buf[start], &buf[pos], -pos); | |
570 unused = start + -pos; // -unused bytes in buffer | |
571 read = stream_read(s, &buf[unused], -unused); | |
572 unused += read; | |
573 // fix buffer so it ends at pos == 0 (eof case) | |
574 *b = &buf[unused]; | |
575 start -= unused; | |
576 return start; | |
577 } | |
578 | |
579 /** | |
580 * This format usually uses an insane bitrate, which makes this function | |
581 * performance-critical! | |
582 * Be sure to benchmark any changes with different compiler versions. | |
583 */ | |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
584 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
|
585 demux_packet_t *pack; |
16369 | 586 int len; |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
587 demux->filepos = stream_tell(demux->stream); |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
588 pack = new_demux_packet(STREAM_BUFFER_SIZE); |
16369 | 589 len = stream_read(demux->stream, pack->buffer, STREAM_BUFFER_SIZE); |
590 if (len <= 0) | |
17779 | 591 { |
592 free_demux_packet(pack); | |
16369 | 593 return 0; |
17779 | 594 } |
16369 | 595 { |
596 register uint32_t state = (uint32_t)demux->priv; | |
597 register int pos = -len; | |
598 unsigned char *buf = &pack->buffer[len]; | |
599 do { | |
600 state = state << 8 | buf[pos]; | |
601 if (unlikely((state | 3) == 0x1bf)) | |
602 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
|
603 } while (++pos < 0); |
16369 | 604 demux->priv = (void *)state; |
605 len = buf - pack->buffer; | |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
606 } |
16369 | 607 if (len < STREAM_BUFFER_SIZE) |
608 resize_demux_packet(pack, len); | |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
609 ds_add_packet(ds, pack); |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
610 return 1; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
611 } |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
612 |
16175 | 613 int demux_mpg_fill_buffer(demuxer_t *demux, demux_stream_t *ds){ |
1 | 614 unsigned int head=0; |
615 int skipped=0; | |
5570
3a8d8c51355a
max_packs increased for some dvd with too many audio/sub
arpi
parents:
4711
diff
changeset
|
616 int max_packs=256; // 512kbyte |
1 | 617 int ret=0; |
618 | |
619 // System stream | |
620 do{ | |
621 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
|
622 #if 1 |
c6c78e77c857
workaround: at every read update demux->movi_end with stream->end_pos; needed to show the progress bar when playing dvdnav streams
nicodvb
parents:
18680
diff
changeset
|
623 //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
|
624 //(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
|
625 demux->movi_end = demux->stream->end_pos; |
c6c78e77c857
workaround: at every read update demux->movi_end with stream->end_pos; needed to show the progress bar when playing dvdnav streams
nicodvb
parents:
18680
diff
changeset
|
626 #endif |
1 | 627 head=stream_read_dword(demux->stream); |
547 | 628 if((head&0xFFFFFF00)!=0x100){ |
629 // sync... | |
630 demux->filepos-=skipped; | |
631 while(1){ | |
536 | 632 int c=stream_read_char(demux->stream); |
633 if(c<0) break; //EOF | |
634 head<<=8; | |
635 if(head!=0x100){ | |
636 head|=c; | |
4711 | 637 if(mp_check_mp3_header(head)) ++num_mp3audio_packets; |
536 | 638 ++skipped; //++demux->filepos; |
639 continue; | |
640 } | |
641 head|=c; | |
642 break; | |
547 | 643 } |
644 demux->filepos+=skipped; | |
1 | 645 } |
646 if(stream_eof(demux->stream)) break; | |
647 // sure: head=0x000001XX | |
1567 | 648 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"*** head=0x%X\n",head); |
1 | 649 if(demux->synced==0){ |
3770 | 650 if(head==0x1BA) demux->synced=1; //else |
651 // if(head==0x1BD || (head>=0x1C0 && head<=0x1EF)) demux->synced=3; // PES? | |
1 | 652 } else |
653 if(demux->synced==1){ | |
929 | 654 if(head==0x1BB || head==0x1BD || (head>=0x1C0 && head<=0x1EF)){ |
1 | 655 demux->synced=2; |
17366 | 656 mp_msg(MSGT_DEMUX,MSGL_V,"system stream synced at 0x%"PRIX64" (%"PRId64")!\n",(int64_t)demux->filepos,(int64_t)demux->filepos); |
536 | 657 num_elementary_packets100=0; // requires for re-sync! |
658 num_elementary_packets101=0; // requires for re-sync! | |
1 | 659 } else demux->synced=0; |
660 } // else | |
3255
ee28577dad02
combined PS/PES sync to allow .VDR playback from stdin
arpi
parents:
2555
diff
changeset
|
661 if(demux->synced>=2){ |
1 | 662 ret=demux_mpg_read_packet(demux,head); |
663 if(!ret) | |
664 if(--max_packs==0){ | |
665 demux->stream->eof=1; | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1735
diff
changeset
|
666 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_DoesntContainSelectedStream); |
1 | 667 return 0; |
668 } | |
3255
ee28577dad02
combined PS/PES sync to allow .VDR playback from stdin
arpi
parents:
2555
diff
changeset
|
669 if(demux->synced==3) demux->synced=(ret==1)?2:0; // PES detect |
1 | 670 } else { |
671 if(head>=0x100 && head<0x1B0){ | |
1162 | 672 if(head==0x100) ++num_elementary_packets100; else |
9069
0d2b25a821c9
raw mpeg4-es support (you need to set -fps manually!)
arpi
parents:
8254
diff
changeset
|
673 if(head==0x101) ++num_elementary_packets101; else |
0d2b25a821c9
raw mpeg4-es support (you need to set -fps manually!)
arpi
parents:
8254
diff
changeset
|
674 if(head>=0x120 && head<=0x12F) ++num_elementary_packets12x; |
9824 | 675 |
676 if((head&~0x60) == 0x101) ++num_h264_slice; else | |
677 if((head&~0x60) == 0x102) ++num_h264_dpa; else | |
678 if((head&~0x60) == 0x103) ++num_h264_dpb; else | |
679 if((head&~0x60) == 0x104) ++num_h264_dpc; else | |
680 if((head&~0x60) == 0x105 && head != 0x105) ++num_h264_idr; else | |
681 if((head&~0x60) == 0x107 && head != 0x107) ++num_h264_sps; else | |
682 if((head&~0x60) == 0x108 && head != 0x108) ++num_h264_pps; | |
683 | |
1567 | 684 mp_msg(MSGT_DEMUX,MSGL_DBG3,"Opps... elementary video packet found: %03X\n",head); |
1162 | 685 } else |
4711 | 686 if((head>=0x1C0 && head<0x1F0) || head==0x1BD){ |
1338
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
687 ++num_elementary_packetsPES; |
1567 | 688 mp_msg(MSGT_DEMUX,MSGL_DBG3,"Opps... PES packet found: %03X\n",head); |
1338
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
689 } else |
1162 | 690 if(head==0x1B6) ++num_elementary_packets1B6; |
21919 | 691 |
1338
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
692 if( ( (num_elementary_packets100>50 && num_elementary_packets101>50) || |
345585097137
mpeg PES steram support (only 1E0 & 1C0 packets, no 1BA/1BB headers)
arpi
parents:
1331
diff
changeset
|
693 (num_elementary_packetsPES>50) ) && skipped>4000000){ |
1567 | 694 mp_msg(MSGT_DEMUX,MSGL_V,"sync_mpeg_ps: seems to be ES/PES stream...\n"); |
1 | 695 demux->stream->eof=1; |
696 break; | |
697 } | |
4711 | 698 if(num_mp3audio_packets>100 && num_elementary_packets100<10){ |
699 mp_msg(MSGT_DEMUX,MSGL_V,"sync_mpeg_ps: seems to be MP3 stream...\n"); | |
700 demux->stream->eof=1; | |
701 break; | |
702 } | |
1 | 703 } |
704 } while(ret!=1); | |
1567 | 705 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"demux: %d bad bytes skipped\n",skipped); |
1 | 706 if(demux->stream->eof){ |
1567 | 707 mp_msg(MSGT_DEMUX,MSGL_V,"MPEG Stream reached EOF\n"); |
1 | 708 return 0; |
709 } | |
710 return 1; | |
711 } | |
712 | |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7671
diff
changeset
|
713 extern void skip_audio_frame(sh_audio_t *sh_audio); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
7671
diff
changeset
|
714 |
17636 | 715 void demux_seek_mpg(demuxer_t *demuxer,float rel_seek_secs,float audio_delay, int flags){ |
1466 | 716 demux_stream_t *d_audio=demuxer->audio; |
717 demux_stream_t *d_video=demuxer->video; | |
718 sh_audio_t *sh_audio=d_audio->sh; | |
719 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
|
720 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
|
721 int precision = 1; |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
722 float oldpts = 0; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
723 off_t oldpos = demuxer->filepos; |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
724 float newpts = 0; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
725 off_t newpos = (flags & 1) ? demuxer->movi_start : oldpos; |
1466 | 726 |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
727 if(mpg_d) |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
728 oldpts = mpg_d->last_pts; |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
729 newpts = (flags & 1) ? 0.0 : oldpts; |
1466 | 730 //================= seek in MPEG ========================== |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
731 //calculate the pts to seek to |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
732 if(flags & 2) { |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
733 if (mpg_d && mpg_d->final_pts > 0.0) |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
734 newpts += mpg_d->final_pts * rel_seek_secs; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
735 else |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
736 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
|
737 } else |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
738 newpts += rel_seek_secs; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
739 if (newpts < 0) newpts = 0; |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
740 |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
741 if(flags&2){ |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
742 // float seek 0..1 |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
743 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
|
744 } else { |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
745 // time seek (secs) |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
746 if (mpg_d && mpg_d->has_valid_timestamps) { |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
747 if (mpg_d->final_pts > 0.0) |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
748 newpos += rel_seek_secs * (demuxer->movi_end - demuxer->movi_start) / mpg_d->final_pts; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
749 else if (oldpts > 0.0) |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
750 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
|
751 } 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
|
752 newpos+=2324*75*rel_seek_secs; // 174.3 kbyte/sec |
1466 | 753 else |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
754 newpos+=sh_video->i_bps*rel_seek_secs; |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
755 } |
1466 | 756 |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
757 while (1) { |
4391
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
758 if(newpos<demuxer->movi_start){ |
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
759 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
|
760 if(newpos<demuxer->movi_start) newpos=demuxer->movi_start; |
6394c1e9e770
DVD start position handling changed (progbar/eta fix)
arpi
parents:
3975
diff
changeset
|
761 } |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1597
diff
changeset
|
762 |
1466 | 763 #ifdef _LARGEFILE_SOURCE |
764 newpos&=~((long long)STREAM_BUFFER_SIZE-1); /* sector boundary */ | |
765 #else | |
766 newpos&=~(STREAM_BUFFER_SIZE-1); /* sector boundary */ | |
767 #endif | |
768 stream_seek(demuxer->stream,newpos); | |
769 | |
770 // re-sync video: | |
771 videobuf_code_len=0; // reset ES stream buffer | |
772 | |
773 ds_fill_buffer(d_video); | |
774 if(sh_audio){ | |
775 ds_fill_buffer(d_audio); | |
776 } | |
777 | |
778 while(1){ | |
779 int i; | |
780 if(sh_audio && !d_audio->eof && d_video->pts && d_audio->pts){ | |
781 float a_pts=d_audio->pts; | |
782 a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; | |
783 if(d_video->pts>a_pts){ | |
784 skip_audio_frame(sh_audio); // sync audio | |
785 continue; | |
786 } | |
787 } | |
17821 | 788 if(!sh_video) break; |
1466 | 789 i=sync_video_packet(d_video); |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
790 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
|
791 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
|
792 int pos = videobuf_len; |
658fc109eefc
added support for other codecs (mpeg4/h264/aac) in mpeg-ps parsing the PSM
nicodvb
parents:
14502
diff
changeset
|
793 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
|
794 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
|
795 } |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
796 } else if(sh_video->format == 0x10000005){ //h264 |
17289 | 797 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
|
798 } else { //default mpeg1/2 |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
799 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
|
800 } |
1466 | 801 if(!i || !skip_video_packet(d_video)) break; // EOF? |
802 } | |
14426
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
803 if(!mpg_d) |
3faa873334d7
fixed broken seeking in mpeg-es files; syncword seeking for all 3 video codecs
nicodvb
parents:
13738
diff
changeset
|
804 break; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
805 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
|
806 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
|
807 mpg_d->has_valid_timestamps = 0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
808 break; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
809 } |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
810 precision--; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
811 //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
|
812 if(mpg_d) { |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
813 newpos += (newpts - mpg_d->last_pts) * (newpos - oldpos) / (mpg_d->last_pts - oldpts); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
814 ds_free_packs(d_audio); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
815 ds_free_packs(d_video); |
20005
447e41fbcb4e
Reset demuxer->sub (consistently with audio and video) after seeking and at the end
nicodvb
parents:
19896
diff
changeset
|
816 ds_free_packs(demuxer->sub); |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
817 demuxer->stream->eof=0; // clear eof flag |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
818 d_video->eof=0; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
819 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
|
820 } |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
821 } |
1466 | 822 } |
823 | |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
824 int demux_mpg_control(demuxer_t *demuxer,int cmd, void *arg){ |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
825 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
|
826 |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
827 switch(cmd) { |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
828 case DEMUXER_CTRL_GET_TIME_LENGTH: |
20851
6602a90a06ec
consistency fix: STREAM_CTRL_GET_TIME_LENGTH and STREAM_CTRL_GET_CURRENT_TIME now return time in (double) seconds
nicodvb
parents:
20005
diff
changeset
|
829 if(stream_control(demuxer->stream, STREAM_CTRL_GET_TIME_LENGTH, arg) != STREAM_UNSUPORTED) { |
6602a90a06ec
consistency fix: STREAM_CTRL_GET_TIME_LENGTH and STREAM_CTRL_GET_CURRENT_TIME now return time in (double) seconds
nicodvb
parents:
20005
diff
changeset
|
830 mp_msg(MSGT_DEMUXER,MSGL_DBG2,"\r\nDEMUX_MPG_CTRL, (%.3lf)\r\n", *((double*)arg)); |
17699
b742a2c71c25
try to get duration from the stream layer, if an implementation of STREAM_CTRL_GET_TIME_LENGTH is available
nicodvb
parents:
17636
diff
changeset
|
831 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
|
832 } |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
833 if (mpg_d && mpg_d->has_valid_timestamps) { |
16346
6ff303d2876b
Make -identify's 'ID_LENGTH=' print a float and not an integer.. The
ods15
parents:
16314
diff
changeset
|
834 *((double *)arg)=(double)mpg_d->final_pts; |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
835 return DEMUXER_CTRL_GUESS; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
836 } |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
837 return DEMUXER_CTRL_DONTKNOW; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
838 |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
839 case DEMUXER_CTRL_GET_PERCENT_POS: |
13738
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
840 if (mpg_d && mpg_d->has_valid_timestamps && mpg_d->final_pts > 0.0) { |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
841 *((int *)arg)=(int)(100 * mpg_d->last_pts / mpg_d->final_pts); |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
842 return DEMUXER_CTRL_OK; |
39004f891def
seeking based on the largest timestamp in an mpeg stream
aurel
parents:
13649
diff
changeset
|
843 } |
14502
8769fa370f83
Move generic length and percent pos calculation to demuxer.c
reimar
parents:
14426
diff
changeset
|
844 return DEMUXER_CTRL_DONTKNOW; |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
845 |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
846 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
|
847 if(! (mpg_d && mpg_d->num_a_streams > 1 && demuxer->audio && demuxer->audio->sh)) |
24fc4279bf99
fail immediately if any of the parameters necessary to switch audio stream isn't set/correct; closes cid 55
nicodvb
parents:
17821
diff
changeset
|
848 return DEMUXER_CTRL_NOTIMPL; |
24fc4279bf99
fail immediately if any of the parameters necessary to switch audio stream isn't set/correct; closes cid 55
nicodvb
parents:
17821
diff
changeset
|
849 else { |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
850 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
|
851 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
|
852 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
|
853 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
|
854 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
|
855 return DEMUXER_CTRL_NOTIMPL; |
15285
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
856 if (*((int*)arg) < 0) |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
857 { |
15046
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
858 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
|
859 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
|
860 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
861 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
|
862 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
|
863 } |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
864 else { |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
865 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
|
866 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
|
867 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
|
868 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
|
869 } |
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
870 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
|
871 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
|
872 d_audio->sh = sh_a; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
873 ds_free_packs(d_audio); |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
874 } |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
875 } |
15285
39eb8a327ea9
adds a parameter to the switch_audio command to directly select a track.
reimar
parents:
15046
diff
changeset
|
876 *((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
|
877 return DEMUXER_CTRL_OK; |
b7aa70b05d76
Added support of audio stream switching in the MPEG demuxer using the #-key
gpoirier
parents:
14923
diff
changeset
|
878 |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
879 default: |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
880 return DEMUXER_CTRL_NOTIMPL; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
881 } |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
882 } |
16175 | 883 |
884 | |
885 static int demux_mpg_pes_probe(demuxer_t *demuxer) { | |
886 demuxer->synced = 3; | |
16314 | 887 return (demux_mpg_probe(demuxer) == DEMUXER_TYPE_MPEG_PS) ? DEMUXER_TYPE_MPEG_PES : 0; |
16175 | 888 } |
889 | |
890 | |
891 static demuxer_t* demux_mpg_es_open(demuxer_t* demuxer) | |
892 { | |
893 sh_video_t *sh_video=NULL; | |
894 | |
895 demuxer->audio->sh = NULL; // ES streams has no audio channel | |
896 demuxer->video->sh = new_sh_video(demuxer,0); // create dummy video stream header, id=0 | |
897 sh_video=demuxer->video->sh;sh_video->ds=demuxer->video; | |
898 | |
899 return demuxer; | |
900 } | |
901 | |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
902 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
|
903 demuxer->audio->sh = NULL; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
904 demuxer->video->sh = new_sh_video(demuxer,0); |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
905 ((sh_video_t *)demuxer->video->sh)->ds = demuxer->video; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
906 demuxer->priv = (void *) 0xffffffff; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
907 return demuxer; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
908 } |
16175 | 909 |
910 static demuxer_t* demux_mpg_ps_open(demuxer_t* demuxer) | |
911 { | |
912 sh_audio_t *sh_audio=NULL; | |
913 sh_video_t *sh_video=NULL; | |
914 | |
915 sh_video=demuxer->video->sh;sh_video->ds=demuxer->video; | |
916 | |
917 if(demuxer->audio->id!=-2) { | |
918 if(!ds_fill_buffer(demuxer->audio)){ | |
919 mp_msg(MSGT_DEMUXER,MSGL_INFO,"MPEG: " MSGTR_MissingAudioStream); | |
920 demuxer->audio->sh=NULL; | |
921 } else { | |
922 sh_audio=demuxer->audio->sh;sh_audio->ds=demuxer->audio; | |
923 } | |
924 } | |
925 | |
926 return demuxer; | |
927 } | |
928 | |
929 | |
930 demuxer_desc_t demuxer_desc_mpeg_ps = { | |
931 "MPEG PS demuxer", | |
932 "mpegps", | |
933 "MPEG-PS", | |
934 "Arpi?", | |
935 "Mpeg", | |
936 DEMUXER_TYPE_MPEG_PS, | |
937 0, // unsafe autodetect | |
938 demux_mpg_probe, | |
939 demux_mpg_fill_buffer, | |
940 demux_mpg_ps_open, | |
941 demux_close_mpg, | |
942 demux_seek_mpg, | |
16771
82a56c89b54d
10l, demux_mpg_control was missing from demuxer info struct, causing audio
reimar
parents:
16369
diff
changeset
|
943 demux_mpg_control, |
16175 | 944 }; |
945 | |
946 | |
947 demuxer_desc_t demuxer_desc_mpeg_pes = { | |
948 "MPEG PES demuxer", | |
949 "mpegpes", | |
950 "MPEG-PES", | |
951 "Arpi?", | |
952 "Mpeg", | |
953 DEMUXER_TYPE_MPEG_PES, | |
954 0, // unsafe autodetect | |
955 demux_mpg_pes_probe, | |
956 demux_mpg_fill_buffer, | |
16314 | 957 demux_mpg_ps_open, |
16175 | 958 demux_close_mpg, |
959 demux_seek_mpg, | |
16771
82a56c89b54d
10l, demux_mpg_control was missing from demuxer info struct, causing audio
reimar
parents:
16369
diff
changeset
|
960 demux_mpg_control, |
16175 | 961 }; |
962 | |
963 | |
16310
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
964 demuxer_desc_t demuxer_desc_mpeg_gxf = { |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
965 "MPEG ES in GXF demuxer", |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
966 "mpeggxf", |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
967 "MPEG-ES in GXF", |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
968 "Reimar Döffinger", |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
969 "Mpeg", |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
970 DEMUXER_TYPE_MPEG_GXF, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
971 0, // hack autodetection |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
972 NULL, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
973 demux_mpg_gxf_fill_buffer, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
974 demux_mpg_gxf_open, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
975 NULL, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
976 NULL, |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
977 NULL |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
978 }; |
fb95057e370e
support MPEG in GXF container with extension-based detection.
reimar
parents:
16175
diff
changeset
|
979 |
16175 | 980 demuxer_desc_t demuxer_desc_mpeg_es = { |
981 "MPEG ES demuxer", | |
982 "mpeges", | |
983 "MPEG-ES", | |
984 "Arpi?", | |
985 "Mpeg", | |
986 DEMUXER_TYPE_MPEG_ES, | |
987 0, // hack autodetection | |
988 NULL, | |
989 demux_mpg_es_fill_buffer, | |
990 demux_mpg_es_open, | |
991 demux_close_mpg, | |
992 demux_seek_mpg, | |
16771
82a56c89b54d
10l, demux_mpg_control was missing from demuxer info struct, causing audio
reimar
parents:
16369
diff
changeset
|
993 demux_mpg_control, |
16175 | 994 }; |
995 | |
996 | |
997 demuxer_desc_t demuxer_desc_mpeg4_es = { | |
998 "MPEG4 ES demuxer", | |
999 "mpeg4es", | |
1000 "MPEG-ES", | |
1001 "Arpi?", | |
1002 "Mpeg", | |
1003 DEMUXER_TYPE_MPEG4_ES, | |
1004 0, // hack autodetection | |
1005 NULL, | |
1006 demux_mpg_es_fill_buffer, | |
1007 demux_mpg_es_open, | |
1008 demux_close_mpg, | |
1009 demux_seek_mpg, | |
16771
82a56c89b54d
10l, demux_mpg_control was missing from demuxer info struct, causing audio
reimar
parents:
16369
diff
changeset
|
1010 demux_mpg_control, |
16175 | 1011 }; |
1012 | |
1013 | |
1014 demuxer_desc_t demuxer_desc_h264_es = { | |
1015 "H.264 ES demuxer", | |
1016 "h264es", | |
1017 "H264-ES", | |
1018 "Arpi?", | |
1019 "Mpeg", | |
1020 DEMUXER_TYPE_H264_ES, | |
1021 0, // hack autodetection | |
1022 NULL, | |
1023 demux_mpg_es_fill_buffer, | |
1024 demux_mpg_es_open, | |
1025 demux_close_mpg, | |
1026 demux_seek_mpg, | |
16771
82a56c89b54d
10l, demux_mpg_control was missing from demuxer info struct, causing audio
reimar
parents:
16369
diff
changeset
|
1027 demux_mpg_control, |
16175 | 1028 }; |