Mercurial > libavformat.hg
annotate mpegts.c @ 4200:898c3d1d9e4e libavformat
Use setmode() if it exists in <io.h>, and not based on O_BINARY.
author | ramiro |
---|---|
date | Sun, 11 Jan 2009 22:05:43 +0000 |
parents | 950dc8531665 |
children | 7d2f3f1b68d8 |
rev | line source |
---|---|
0 | 1 /* |
1415
3b00fb8ef8e4
replace coder/decoder file description in libavformat by muxer/demuxer
aurel
parents:
1358
diff
changeset
|
2 * MPEG2 transport stream (aka DVB) demuxer |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
3 * Copyright (c) 2002-2003 Fabrice Bellard. |
0 | 4 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1280
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1280
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1280
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
0 | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1280
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
0 | 11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1280
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
0 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1280
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
892
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 20 */ |
3286 | 21 |
22 #include "libavutil/crc.h" | |
0 | 23 #include "avformat.h" |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
24 #include "mpegts.h" |
4062
297c1d6f9c5e
Add necessary header for av_set_program_name and av_program_add_stream_index.
diego
parents:
4059
diff
changeset
|
25 #include "internal.h" |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
26 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
27 //#define DEBUG_SI |
310 | 28 //#define DEBUG_SEEK |
0 | 29 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
30 /* 1.0 second at 24Mbit/s */ |
170
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
31 #define MAX_SCAN_PACKETS 32000 |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
32 |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
33 /* maximum size in which we look for synchronisation if |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
34 synchronisation is lost */ |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
35 #define MAX_RESYNC_SIZE 4096 |
3059
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
36 #define REGISTRATION_DESCRIPTOR 5 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
37 |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
38 typedef struct PESContext PESContext; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
39 |
2157
0103a8479df5
proper per stream pcr_pid support by (Wolfram Gloger wmglo dent.med.uni-muenchen@de )
michael
parents:
2146
diff
changeset
|
40 static PESContext* add_pes_stream(MpegTSContext *ts, int pid, int pcr_pid, int stream_type); |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
41 static AVStream* new_pes_av_stream(PESContext *pes, uint32_t code); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
42 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
43 enum MpegTSFilterType { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
44 MPEGTS_PES, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
45 MPEGTS_SECTION, |
0 | 46 }; |
47 | |
2236
117edddfce20
update SectionCallback and PESCallback typedefs to match functions
mru
parents:
2222
diff
changeset
|
48 typedef struct MpegTSFilter MpegTSFilter; |
117edddfce20
update SectionCallback and PESCallback typedefs to match functions
mru
parents:
2222
diff
changeset
|
49 |
117edddfce20
update SectionCallback and PESCallback typedefs to match functions
mru
parents:
2222
diff
changeset
|
50 typedef void PESCallback(MpegTSFilter *f, const uint8_t *buf, int len, int is_start); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
51 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
52 typedef struct MpegTSPESFilter { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
53 PESCallback *pes_cb; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
54 void *opaque; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
55 } MpegTSPESFilter; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
56 |
2236
117edddfce20
update SectionCallback and PESCallback typedefs to match functions
mru
parents:
2222
diff
changeset
|
57 typedef void SectionCallback(MpegTSFilter *f, const uint8_t *buf, int len); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
58 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
59 typedef void SetServiceCallback(void *opaque, int ret); |
0 | 60 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
61 typedef struct MpegTSSectionFilter { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
62 int section_index; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
63 int section_h_size; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
64 uint8_t *section_buf; |
3553
c3b9334f46ae
One-bit bitfields should probably be unsigned. Unfortunately, it is left
takis
parents:
3487
diff
changeset
|
65 unsigned int check_crc:1; |
c3b9334f46ae
One-bit bitfields should probably be unsigned. Unfortunately, it is left
takis
parents:
3487
diff
changeset
|
66 unsigned int end_of_section_reached:1; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
67 SectionCallback *section_cb; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
68 void *opaque; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
69 } MpegTSSectionFilter; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
70 |
2236
117edddfce20
update SectionCallback and PESCallback typedefs to match functions
mru
parents:
2222
diff
changeset
|
71 struct MpegTSFilter { |
0 | 72 int pid; |
73 int last_cc; /* last cc code (-1 if first packet) */ | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
74 enum MpegTSFilterType type; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
75 union { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
76 MpegTSPESFilter pes_filter; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
77 MpegTSSectionFilter section_filter; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
78 } u; |
2236
117edddfce20
update SectionCallback and PESCallback typedefs to match functions
mru
parents:
2222
diff
changeset
|
79 }; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
80 |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
81 #define MAX_PIDS_PER_PROGRAM 64 |
4087
950dc8531665
mpegts: replace Program_t typedef with "struct Program"
mru
parents:
4062
diff
changeset
|
82 struct Program { |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
83 unsigned int id; //program id/service id |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
84 unsigned int nb_pids; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
85 unsigned int pids[MAX_PIDS_PER_PROGRAM]; |
4087
950dc8531665
mpegts: replace Program_t typedef with "struct Program"
mru
parents:
4062
diff
changeset
|
86 }; |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
87 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
88 struct MpegTSContext { |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
89 /* user data */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
90 AVFormatContext *stream; |
1726
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
91 /** raw packet size, including FEC if present */ |
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
92 int raw_packet_size; |
3240
78153a85dccc
Ensure that the timestamp reading code used for seeking chooses a position
michael
parents:
3226
diff
changeset
|
93 |
78153a85dccc
Ensure that the timestamp reading code used for seeking chooses a position
michael
parents:
3226
diff
changeset
|
94 int pos47; |
78153a85dccc
Ensure that the timestamp reading code used for seeking chooses a position
michael
parents:
3226
diff
changeset
|
95 |
1726
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
96 /** if true, all pids are analyzed to find streams */ |
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
97 int auto_guess; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
98 |
1726
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
99 /** compute exact PCR for each transport stream packet */ |
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
100 int mpeg2ts_compute_pcr; |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
101 |
1726
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
102 int64_t cur_pcr; /**< used to estimate the exact PCR */ |
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
103 int pcr_incr; /**< used to estimate the exact PCR */ |
885 | 104 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
105 /* data needed to handle file based ts */ |
1726
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
106 /** stop parsing loop */ |
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
107 int stop_parse; |
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
108 /** packet containing Audio/Video data */ |
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
109 AVPacket *pkt; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
110 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
111 /******************************************/ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
112 /* private mpegts data */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
113 /* scan context */ |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
114 /** structure to keep track of Program->pids mapping */ |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
115 unsigned int nb_prg; |
4087
950dc8531665
mpegts: replace Program_t typedef with "struct Program"
mru
parents:
4062
diff
changeset
|
116 struct Program *prg; |
885 | 117 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
118 |
1726
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
119 /** filters for various streams specified by PMT + for the PAT and PMT */ |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
120 MpegTSFilter *pids[NB_PID_MAX]; |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
121 }; |
0 | 122 |
2133
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
123 /* TS stream handling */ |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
124 |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
125 enum MpegTSState { |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
126 MPEGTS_HEADER = 0, |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
127 MPEGTS_PESHEADER_FILL, |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
128 MPEGTS_PAYLOAD, |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
129 MPEGTS_SKIP, |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
130 }; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
131 |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
132 /* enough for PES header + length */ |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
133 #define PES_START_SIZE 9 |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
134 #define MAX_PES_HEADER_SIZE (9 + 255) |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
135 |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
136 struct PESContext { |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
137 int pid; |
2157
0103a8479df5
proper per stream pcr_pid support by (Wolfram Gloger wmglo dent.med.uni-muenchen@de )
michael
parents:
2146
diff
changeset
|
138 int pcr_pid; /**< if -1 then all packets containing PCR are considered */ |
2133
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
139 int stream_type; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
140 MpegTSContext *ts; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
141 AVFormatContext *stream; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
142 AVStream *st; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
143 enum MpegTSState state; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
144 /* used to get the format */ |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
145 int data_index; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
146 int total_size; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
147 int pes_header_size; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
148 int64_t pts, dts; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
149 uint8_t header[MAX_PES_HEADER_SIZE]; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
150 }; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
151 |
2555 | 152 extern AVInputFormat mpegts_demuxer; |
153 | |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
154 static void clear_program(MpegTSContext *ts, unsigned int programid) |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
155 { |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
156 int i; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
157 |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
158 for(i=0; i<ts->nb_prg; i++) |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
159 if(ts->prg[i].id == programid) |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
160 ts->prg[i].nb_pids = 0; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
161 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
162 |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
163 static void clear_programs(MpegTSContext *ts) |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
164 { |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
165 av_freep(&ts->prg); |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
166 ts->nb_prg=0; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
167 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
168 |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
169 static void add_pat_entry(MpegTSContext *ts, unsigned int programid) |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
170 { |
4087
950dc8531665
mpegts: replace Program_t typedef with "struct Program"
mru
parents:
4062
diff
changeset
|
171 struct Program *p; |
950dc8531665
mpegts: replace Program_t typedef with "struct Program"
mru
parents:
4062
diff
changeset
|
172 void *tmp = av_realloc(ts->prg, (ts->nb_prg+1)*sizeof(struct Program)); |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
173 if(!tmp) |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
174 return; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
175 ts->prg = tmp; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
176 p = &ts->prg[ts->nb_prg]; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
177 p->id = programid; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
178 p->nb_pids = 0; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
179 ts->nb_prg++; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
180 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
181 |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
182 static void add_pid_to_pmt(MpegTSContext *ts, unsigned int programid, unsigned int pid) |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
183 { |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
184 int i; |
4087
950dc8531665
mpegts: replace Program_t typedef with "struct Program"
mru
parents:
4062
diff
changeset
|
185 struct Program *p = NULL; |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
186 for(i=0; i<ts->nb_prg; i++) { |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
187 if(ts->prg[i].id == programid) { |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
188 p = &ts->prg[i]; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
189 break; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
190 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
191 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
192 if(!p) |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
193 return; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
194 |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
195 if(p->nb_pids >= MAX_PIDS_PER_PROGRAM) |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
196 return; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
197 p->pids[p->nb_pids++] = pid; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
198 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
199 |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
200 /** |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
201 * \brief discard_pid() decides if the pid is to be discarded according |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
202 * to caller's programs selection |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
203 * \param ts : - TS context |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
204 * \param pid : - pid |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
205 * \return 1 if the pid is only comprised in programs that have .discard=AVDISCARD_ALL |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
206 * 0 otherwise |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
207 */ |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
208 static int discard_pid(MpegTSContext *ts, unsigned int pid) |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
209 { |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
210 int i, j, k; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
211 int used = 0, discarded = 0; |
4087
950dc8531665
mpegts: replace Program_t typedef with "struct Program"
mru
parents:
4062
diff
changeset
|
212 struct Program *p; |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
213 for(i=0; i<ts->nb_prg; i++) { |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
214 p = &ts->prg[i]; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
215 for(j=0; j<p->nb_pids; j++) { |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
216 if(p->pids[j] != pid) |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
217 continue; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
218 //is program with id p->id set to be discarded? |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
219 for(k=0; k<ts->stream->nb_programs; k++) { |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
220 if(ts->stream->programs[k]->id == p->id) { |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
221 if(ts->stream->programs[k]->discard == AVDISCARD_ALL) |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
222 discarded++; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
223 else |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
224 used++; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
225 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
226 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
227 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
228 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
229 |
3278 | 230 return !used && discarded; |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
231 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
232 |
1726
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
233 /** |
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
234 * Assembles PES packets out of TS packets, and then calls the "section_cb" |
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
235 * function when they are complete. |
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
236 */ |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
237 static void write_section_data(AVFormatContext *s, MpegTSFilter *tss1, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
238 const uint8_t *buf, int buf_size, int is_start) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
239 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
240 MpegTSSectionFilter *tss = &tss1->u.section_filter; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
241 int len; |
885 | 242 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
243 if (is_start) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
244 memcpy(tss->section_buf, buf, buf_size); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
245 tss->section_index = buf_size; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
246 tss->section_h_size = -1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
247 tss->end_of_section_reached = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
248 } else { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
249 if (tss->end_of_section_reached) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
250 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
251 len = 4096 - tss->section_index; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
252 if (buf_size < len) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
253 len = buf_size; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
254 memcpy(tss->section_buf + tss->section_index, buf, len); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
255 tss->section_index += len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
256 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
257 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
258 /* compute section length if possible */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
259 if (tss->section_h_size == -1 && tss->section_index >= 3) { |
2222 | 260 len = (AV_RB16(tss->section_buf + 1) & 0xfff) + 3; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
261 if (len > 4096) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
262 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
263 tss->section_h_size = len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
264 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
265 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
266 if (tss->section_h_size != -1 && tss->section_index >= tss->section_h_size) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
267 tss->end_of_section_reached = 1; |
675
29a19aec26b2
Writing to freed memory in write_section_data() patch by (Wolfram Gloger <wmglo dent dot med dot uni-muenchen de>)
michael
parents:
555
diff
changeset
|
268 if (!tss->check_crc || |
2893 | 269 av_crc(av_crc_get_table(AV_CRC_32_IEEE), -1, |
270 tss->section_buf, tss->section_h_size) == 0) | |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
271 tss->section_cb(tss1, tss->section_buf, tss->section_h_size); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
272 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
273 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
274 |
1124
d3aff2c607f9
Add const to (mostly) char* and make some functions static, which aren't used
diego
parents:
1047
diff
changeset
|
275 static MpegTSFilter *mpegts_open_section_filter(MpegTSContext *ts, unsigned int pid, |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
276 SectionCallback *section_cb, void *opaque, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
277 int check_crc) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
278 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
279 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
280 MpegTSFilter *filter; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
281 MpegTSSectionFilter *sec; |
885 | 282 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
283 #ifdef DEBUG_SI |
1748 | 284 av_log(ts->stream, AV_LOG_DEBUG, "Filter: pid=0x%x\n", pid); |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
285 #endif |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
286 if (pid >= NB_PID_MAX || ts->pids[pid]) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
287 return NULL; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
288 filter = av_mallocz(sizeof(MpegTSFilter)); |
885 | 289 if (!filter) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
290 return NULL; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
291 ts->pids[pid] = filter; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
292 filter->type = MPEGTS_SECTION; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
293 filter->pid = pid; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
294 filter->last_cc = -1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
295 sec = &filter->u.section_filter; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
296 sec->section_cb = section_cb; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
297 sec->opaque = opaque; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
298 sec->section_buf = av_malloc(MAX_SECTION_SIZE); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
299 sec->check_crc = check_crc; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
300 if (!sec->section_buf) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
301 av_free(filter); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
302 return NULL; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
303 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
304 return filter; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
305 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
306 |
1124
d3aff2c607f9
Add const to (mostly) char* and make some functions static, which aren't used
diego
parents:
1047
diff
changeset
|
307 static MpegTSFilter *mpegts_open_pes_filter(MpegTSContext *ts, unsigned int pid, |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
308 PESCallback *pes_cb, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
309 void *opaque) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
310 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
311 MpegTSFilter *filter; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
312 MpegTSPESFilter *pes; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
313 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
314 if (pid >= NB_PID_MAX || ts->pids[pid]) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
315 return NULL; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
316 filter = av_mallocz(sizeof(MpegTSFilter)); |
885 | 317 if (!filter) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
318 return NULL; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
319 ts->pids[pid] = filter; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
320 filter->type = MPEGTS_PES; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
321 filter->pid = pid; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
322 filter->last_cc = -1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
323 pes = &filter->u.pes_filter; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
324 pes->pes_cb = pes_cb; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
325 pes->opaque = opaque; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
326 return filter; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
327 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
328 |
1124
d3aff2c607f9
Add const to (mostly) char* and make some functions static, which aren't used
diego
parents:
1047
diff
changeset
|
329 static void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
330 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
331 int pid; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
332 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
333 pid = filter->pid; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
334 if (filter->type == MPEGTS_SECTION) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
335 av_freep(&filter->u.section_filter.section_buf); |
342
0c1b489c96bf
memleak patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
329
diff
changeset
|
336 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
337 av_free(filter); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
338 ts->pids[pid] = NULL; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
339 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
340 |
329 | 341 static int analyze(const uint8_t *buf, int size, int packet_size, int *index){ |
342 int stat[packet_size]; | |
343 int i; | |
344 int x=0; | |
345 int best_score=0; | |
346 | |
347 memset(stat, 0, packet_size*sizeof(int)); | |
348 | |
3589 | 349 for(x=i=0; i<size-3; i++){ |
350 if(buf[i] == 0x47 && !(buf[i+1] & 0x80) && (buf[i+3] & 0x30)){ | |
329 | 351 stat[x]++; |
352 if(stat[x] > best_score){ | |
353 best_score= stat[x]; | |
354 if(index) *index= x; | |
355 } | |
356 } | |
357 | |
358 x++; | |
359 if(x == packet_size) x= 0; | |
360 } | |
361 | |
362 return best_score; | |
363 } | |
364 | |
0 | 365 /* autodetect fec presence. Must have at least 1024 bytes */ |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
366 static int get_packet_size(const uint8_t *buf, int size) |
0 | 367 { |
891 | 368 int score, fec_score, dvhs_score; |
0 | 369 |
370 if (size < (TS_FEC_PACKET_SIZE * 5 + 1)) | |
371 return -1; | |
885 | 372 |
329 | 373 score = analyze(buf, size, TS_PACKET_SIZE, NULL); |
891 | 374 dvhs_score = analyze(buf, size, TS_DVHS_PACKET_SIZE, NULL); |
329 | 375 fec_score= analyze(buf, size, TS_FEC_PACKET_SIZE, NULL); |
891 | 376 // av_log(NULL, AV_LOG_DEBUG, "score: %d, dvhs_score: %d, fec_score: %d \n", score, dvhs_score, fec_score); |
885 | 377 |
891 | 378 if (score > fec_score && score > dvhs_score) return TS_PACKET_SIZE; |
379 else if(dvhs_score > score && dvhs_score > fec_score) return TS_DVHS_PACKET_SIZE; | |
380 else if(score < fec_score && dvhs_score < fec_score) return TS_FEC_PACKET_SIZE; | |
329 | 381 else return -1; |
0 | 382 } |
383 | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
384 typedef struct SectionHeader { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
385 uint8_t tid; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
386 uint16_t id; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
387 uint8_t version; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
388 uint8_t sec_num; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
389 uint8_t last_sec_num; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
390 } SectionHeader; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
391 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
392 static inline int get8(const uint8_t **pp, const uint8_t *p_end) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
393 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
394 const uint8_t *p; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
395 int c; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
396 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
397 p = *pp; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
398 if (p >= p_end) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
399 return -1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
400 c = *p++; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
401 *pp = p; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
402 return c; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
403 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
404 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
405 static inline int get16(const uint8_t **pp, const uint8_t *p_end) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
406 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
407 const uint8_t *p; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
408 int c; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
409 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
410 p = *pp; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
411 if ((p + 1) >= p_end) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
412 return -1; |
2222 | 413 c = AV_RB16(p); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
414 p += 2; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
415 *pp = p; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
416 return c; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
417 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
418 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
419 /* read and allocate a DVB string preceeded by its length */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
420 static char *getstr8(const uint8_t **pp, const uint8_t *p_end) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
421 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
422 int len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
423 const uint8_t *p; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
424 char *str; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
425 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
426 p = *pp; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
427 len = get8(&p, p_end); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
428 if (len < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
429 return NULL; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
430 if ((p + len) > p_end) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
431 return NULL; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
432 str = av_malloc(len + 1); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
433 if (!str) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
434 return NULL; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
435 memcpy(str, p, len); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
436 str[len] = '\0'; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
437 p += len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
438 *pp = p; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
439 return str; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
440 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
441 |
885 | 442 static int parse_section_header(SectionHeader *h, |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
443 const uint8_t **pp, const uint8_t *p_end) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
444 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
445 int val; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
446 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
447 val = get8(pp, p_end); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
448 if (val < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
449 return -1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
450 h->tid = val; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
451 *pp += 2; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
452 val = get16(pp, p_end); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
453 if (val < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
454 return -1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
455 h->id = val; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
456 val = get8(pp, p_end); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
457 if (val < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
458 return -1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
459 h->version = (val >> 1) & 0x1f; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
460 val = get8(pp, p_end); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
461 if (val < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
462 return -1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
463 h->sec_num = val; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
464 val = get8(pp, p_end); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
465 if (val < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
466 return -1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
467 h->last_sec_num = val; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
468 return 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
469 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
470 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
471 |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
472 static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
473 { |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
474 MpegTSContext *ts = filter->u.section_filter.opaque; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
475 SectionHeader h1, *h = &h1; |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
476 PESContext *pes; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
477 AVStream *st; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
478 const uint8_t *p, *p_end, *desc_list_end, *desc_end; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
479 int program_info_length, pcr_pid, pid, stream_type; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
480 int desc_list_len, desc_len, desc_tag; |
851
62e66722e9bb
Kill some compiler warnings. Compiled code verified identical after changes.
mru
parents:
820
diff
changeset
|
481 int comp_page = 0, anc_page = 0; /* initialize to kill warnings */ |
2101 | 482 char language[4] = {0}; /* initialize to kill warnings */ |
3059
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
483 int has_hdmv_descr = 0; |
3716 | 484 int has_dirac_descr = 0; |
885 | 485 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
486 #ifdef DEBUG_SI |
1748 | 487 av_log(ts->stream, AV_LOG_DEBUG, "PMT: len %i\n", section_len); |
1908
174083eafc6c
Introduce two new logging functions av_hex_dump_log() and av_pkt_dump_log()
takis
parents:
1787
diff
changeset
|
488 av_hex_dump_log(ts->stream, AV_LOG_DEBUG, (uint8_t *)section, section_len); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
489 #endif |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
490 p_end = section + section_len - 4; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
491 p = section; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
492 if (parse_section_header(h, &p, p_end) < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
493 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
494 #ifdef DEBUG_SI |
1748 | 495 av_log(ts->stream, AV_LOG_DEBUG, "sid=0x%x sec_num=%d/%d\n", |
1724
940907f49a33
"converts printf's to avlog's" patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1481
diff
changeset
|
496 h->id, h->sec_num, h->last_sec_num); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
497 #endif |
2134
16cf48c9af53
dont rescan for information on each pid, but rather do it just once by
michael
parents:
2133
diff
changeset
|
498 if (h->tid != PMT_TID) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
499 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
500 |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
501 clear_program(ts, h->id); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
502 pcr_pid = get16(&p, p_end) & 0x1fff; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
503 if (pcr_pid < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
504 return; |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
505 add_pid_to_pmt(ts, h->id, pcr_pid); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
506 #ifdef DEBUG_SI |
1748 | 507 av_log(ts->stream, AV_LOG_DEBUG, "pcr_pid=0x%x\n", pcr_pid); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
508 #endif |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
509 program_info_length = get16(&p, p_end) & 0xfff; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
510 if (program_info_length < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
511 return; |
3059
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
512 while(program_info_length >= 2) { |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
513 uint8_t tag, len; |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
514 tag = get8(&p, p_end); |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
515 len = get8(&p, p_end); |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
516 if(len > program_info_length - 2) |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
517 //something else is broken, exit the program_descriptors_loop |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
518 break; |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
519 program_info_length -= len + 2; |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
520 if(tag == REGISTRATION_DESCRIPTOR && len >= 4) { |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
521 uint8_t bytes[4]; |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
522 bytes[0] = get8(&p, p_end); |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
523 bytes[1] = get8(&p, p_end); |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
524 bytes[2] = get8(&p, p_end); |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
525 bytes[3] = get8(&p, p_end); |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
526 len -= 4; |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
527 if(bytes[0] == 'H' && bytes[1] == 'D' && |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
528 bytes[2] == 'M' && bytes[3] == 'V') |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
529 has_hdmv_descr = 1; |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
530 } |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
531 p += len; |
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
532 } |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
533 p += program_info_length; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
534 if (p >= p_end) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
535 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
536 for(;;) { |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
537 language[0] = 0; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
538 st = 0; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
539 stream_type = get8(&p, p_end); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
540 if (stream_type < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
541 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
542 pid = get16(&p, p_end) & 0x1fff; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
543 if (pid < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
544 break; |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
545 desc_list_len = get16(&p, p_end) & 0xfff; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
546 if (desc_list_len < 0) |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
547 break; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
548 desc_list_end = p + desc_list_len; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
549 if (desc_list_end > p_end) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
550 break; |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
551 for(;;) { |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
552 desc_tag = get8(&p, desc_list_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
553 if (desc_tag < 0) |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
554 break; |
1164
55627fca95a1
Etsi identifies DTS audio with stream_private+descriptor 0x7b (in the PMT).
mru
parents:
1124
diff
changeset
|
555 if (stream_type == STREAM_TYPE_PRIVATE_DATA) { |
55627fca95a1
Etsi identifies DTS audio with stream_private+descriptor 0x7b (in the PMT).
mru
parents:
1124
diff
changeset
|
556 if((desc_tag == 0x6A) || (desc_tag == 0x7A)) { |
1047
76c75a88560d
This patch simply adds demuxing support for AC-3 streams in DVB TS
mru
parents:
1046
diff
changeset
|
557 /*assume DVB AC-3 Audio*/ |
76c75a88560d
This patch simply adds demuxing support for AC-3 streams in DVB TS
mru
parents:
1046
diff
changeset
|
558 stream_type = STREAM_TYPE_AUDIO_AC3; |
1164
55627fca95a1
Etsi identifies DTS audio with stream_private+descriptor 0x7b (in the PMT).
mru
parents:
1124
diff
changeset
|
559 } else if(desc_tag == 0x7B) { |
55627fca95a1
Etsi identifies DTS audio with stream_private+descriptor 0x7b (in the PMT).
mru
parents:
1124
diff
changeset
|
560 /* DVB DTS audio */ |
55627fca95a1
Etsi identifies DTS audio with stream_private+descriptor 0x7b (in the PMT).
mru
parents:
1124
diff
changeset
|
561 stream_type = STREAM_TYPE_AUDIO_DTS; |
55627fca95a1
Etsi identifies DTS audio with stream_private+descriptor 0x7b (in the PMT).
mru
parents:
1124
diff
changeset
|
562 } |
1047
76c75a88560d
This patch simply adds demuxing support for AC-3 streams in DVB TS
mru
parents:
1046
diff
changeset
|
563 } |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
564 desc_len = get8(&p, desc_list_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
565 desc_end = p + desc_len; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
566 if (desc_end > desc_list_end) |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
567 break; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
568 #ifdef DEBUG_SI |
1748 | 569 av_log(ts->stream, AV_LOG_DEBUG, "tag: 0x%02x len=%d\n", |
1724
940907f49a33
"converts printf's to avlog's" patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1481
diff
changeset
|
570 desc_tag, desc_len); |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
571 #endif |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
572 switch(desc_tag) { |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
573 case DVB_SUBT_DESCID: |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
574 if (stream_type == STREAM_TYPE_PRIVATE_DATA) |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
575 stream_type = STREAM_TYPE_SUBTITLE_DVB; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
576 |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
577 language[0] = get8(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
578 language[1] = get8(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
579 language[2] = get8(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
580 language[3] = 0; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
581 get8(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
582 comp_page = get16(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
583 anc_page = get16(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
584 |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
585 break; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
586 case 0x0a: /* ISO 639 language descriptor */ |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
587 language[0] = get8(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
588 language[1] = get8(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
589 language[2] = get8(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
590 language[3] = 0; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
591 break; |
3716 | 592 case REGISTRATION_DESCRIPTOR: /*MPEG-2 Registration descriptor */ |
593 { | |
594 uint8_t bytes[4]; | |
595 bytes[0] = get8(&p, desc_end); | |
596 bytes[1] = get8(&p, desc_end); | |
597 bytes[2] = get8(&p, desc_end); | |
598 bytes[3] = get8(&p, desc_end); | |
599 if(bytes[0] == 'd' && bytes[1] == 'r' && | |
600 bytes[2] == 'a' && bytes[3] == 'c') | |
601 has_dirac_descr = 1; | |
602 break; | |
603 } | |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
604 default: |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
605 break; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
606 } |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
607 p = desc_end; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
608 } |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
609 p = desc_list_end; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
610 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
611 #ifdef DEBUG_SI |
1748 | 612 av_log(ts->stream, AV_LOG_DEBUG, "stream_type=%d pid=0x%x\n", |
1724
940907f49a33
"converts printf's to avlog's" patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1481
diff
changeset
|
613 stream_type, pid); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
614 #endif |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
615 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
616 /* now create ffmpeg stream */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
617 switch(stream_type) { |
160
9bde37b1a5ce
try to filter _all_ PATs if no SDT could be found patch by (<gbazin at altern dot org>)
michaelni
parents:
152
diff
changeset
|
618 case STREAM_TYPE_AUDIO_MPEG1: |
9bde37b1a5ce
try to filter _all_ PATs if no SDT could be found patch by (<gbazin at altern dot org>)
michaelni
parents:
152
diff
changeset
|
619 case STREAM_TYPE_AUDIO_MPEG2: |
9bde37b1a5ce
try to filter _all_ PATs if no SDT could be found patch by (<gbazin at altern dot org>)
michaelni
parents:
152
diff
changeset
|
620 case STREAM_TYPE_VIDEO_MPEG1: |
9bde37b1a5ce
try to filter _all_ PATs if no SDT could be found patch by (<gbazin at altern dot org>)
michaelni
parents:
152
diff
changeset
|
621 case STREAM_TYPE_VIDEO_MPEG2: |
313
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
310
diff
changeset
|
622 case STREAM_TYPE_VIDEO_MPEG4: |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
310
diff
changeset
|
623 case STREAM_TYPE_VIDEO_H264: |
1774 | 624 case STREAM_TYPE_VIDEO_VC1: |
3716 | 625 case STREAM_TYPE_VIDEO_DIRAC: |
313
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
310
diff
changeset
|
626 case STREAM_TYPE_AUDIO_AAC: |
165
e4d2f704bf80
- Looks a tiny bit harder in mpegps_probe() for a valid start code. This is
michaelni
parents:
160
diff
changeset
|
627 case STREAM_TYPE_AUDIO_AC3: |
496
112057e05179
libdts support by (Benjamin Zores <ben at geexbox dot org>)
michael
parents:
474
diff
changeset
|
628 case STREAM_TYPE_AUDIO_DTS: |
3059
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
629 case STREAM_TYPE_AUDIO_HDMV_DTS: |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
630 case STREAM_TYPE_SUBTITLE_DVB: |
3716 | 631 if((stream_type == STREAM_TYPE_AUDIO_HDMV_DTS && !has_hdmv_descr) |
632 || (stream_type == STREAM_TYPE_VIDEO_DIRAC && !has_dirac_descr)) | |
3059
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
633 break; |
2761
5e808c3a55a8
When new streams are detected, look for old filters and close them out.
heydowns
parents:
2651
diff
changeset
|
634 if(ts->pids[pid] && ts->pids[pid]->type == MPEGTS_PES){ |
2134
16cf48c9af53
dont rescan for information on each pid, but rather do it just once by
michael
parents:
2133
diff
changeset
|
635 pes= ts->pids[pid]->u.pes_filter.opaque; |
16cf48c9af53
dont rescan for information on each pid, but rather do it just once by
michael
parents:
2133
diff
changeset
|
636 st= pes->st; |
16cf48c9af53
dont rescan for information on each pid, but rather do it just once by
michael
parents:
2133
diff
changeset
|
637 }else{ |
2761
5e808c3a55a8
When new streams are detected, look for old filters and close them out.
heydowns
parents:
2651
diff
changeset
|
638 if (ts->pids[pid]) mpegts_close_filter(ts, ts->pids[pid]); //wrongly added sdt filter probably |
2157
0103a8479df5
proper per stream pcr_pid support by (Wolfram Gloger wmglo dent.med.uni-muenchen@de )
michael
parents:
2146
diff
changeset
|
639 pes = add_pes_stream(ts, pid, pcr_pid, stream_type); |
2137 | 640 if (pes) |
641 st = new_pes_av_stream(pes, 0); | |
2134
16cf48c9af53
dont rescan for information on each pid, but rather do it just once by
michael
parents:
2133
diff
changeset
|
642 } |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
643 add_pid_to_pmt(ts, h->id, pid); |
2651
38639f62f23f
associate to each AVProgram the indexes of the AVStreams contained in it
nicodvb
parents:
2575
diff
changeset
|
644 if(st) |
38639f62f23f
associate to each AVProgram the indexes of the AVStreams contained in it
nicodvb
parents:
2575
diff
changeset
|
645 av_program_add_stream_index(ts->stream, h->id, st->index); |
2138 | 646 break; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
647 default: |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
648 /* we ignore the other streams */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
649 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
650 } |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
651 |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
652 if (st) { |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
653 if (language[0] != 0) { |
2159 | 654 memcpy(st->language, language, 4); |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
655 } |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
656 |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
657 if (stream_type == STREAM_TYPE_SUBTITLE_DVB) { |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
658 st->codec->sub_id = (anc_page << 16) | comp_page; |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
659 } |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
660 } |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
661 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
662 /* all parameters are there */ |
2134
16cf48c9af53
dont rescan for information on each pid, but rather do it just once by
michael
parents:
2133
diff
changeset
|
663 ts->stop_parse++; |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
664 mpegts_close_filter(ts, filter); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
665 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
666 |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
667 static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
668 { |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
669 MpegTSContext *ts = filter->u.section_filter.opaque; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
670 SectionHeader h1, *h = &h1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
671 const uint8_t *p, *p_end; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
672 int sid, pmt_pid; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
673 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
674 #ifdef DEBUG_SI |
1748 | 675 av_log(ts->stream, AV_LOG_DEBUG, "PAT:\n"); |
1908
174083eafc6c
Introduce two new logging functions av_hex_dump_log() and av_pkt_dump_log()
takis
parents:
1787
diff
changeset
|
676 av_hex_dump_log(ts->stream, AV_LOG_DEBUG, (uint8_t *)section, section_len); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
677 #endif |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
678 p_end = section + section_len - 4; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
679 p = section; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
680 if (parse_section_header(h, &p, p_end) < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
681 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
682 if (h->tid != PAT_TID) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
683 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
684 |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
685 clear_programs(ts); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
686 for(;;) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
687 sid = get16(&p, p_end); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
688 if (sid < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
689 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
690 pmt_pid = get16(&p, p_end) & 0x1fff; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
691 if (pmt_pid < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
692 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
693 #ifdef DEBUG_SI |
1748 | 694 av_log(ts->stream, AV_LOG_DEBUG, "sid=0x%x pid=0x%x\n", sid, pmt_pid); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
695 #endif |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
696 if (sid == 0x0000) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
697 /* NIT info */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
698 } else { |
2574
9e51e62f5bdd
replaced custom tracking of programs/services with calls to with av_new_program()
nicodvb
parents:
2555
diff
changeset
|
699 av_new_program(ts->stream, sid); |
2134
16cf48c9af53
dont rescan for information on each pid, but rather do it just once by
michael
parents:
2133
diff
changeset
|
700 ts->stop_parse--; |
2137 | 701 mpegts_open_section_filter(ts, pmt_pid, pmt_cb, ts, 1); |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
702 add_pat_entry(ts, sid); |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
703 add_pid_to_pmt(ts, sid, 0); //add pat pid to program |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
704 add_pid_to_pmt(ts, sid, pmt_pid); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
705 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
706 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
707 /* not found */ |
2134
16cf48c9af53
dont rescan for information on each pid, but rather do it just once by
michael
parents:
2133
diff
changeset
|
708 ts->stop_parse++; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
709 |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
710 mpegts_close_filter(ts, filter); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
711 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
712 |
2134
16cf48c9af53
dont rescan for information on each pid, but rather do it just once by
michael
parents:
2133
diff
changeset
|
713 static void mpegts_set_service(MpegTSContext *ts) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
714 { |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
715 mpegts_open_section_filter(ts, PAT_PID, |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
716 pat_cb, ts, 1); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
717 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
718 |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
719 static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
720 { |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
721 MpegTSContext *ts = filter->u.section_filter.opaque; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
722 SectionHeader h1, *h = &h1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
723 const uint8_t *p, *p_end, *desc_list_end, *desc_end; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
724 int onid, val, sid, desc_list_len, desc_tag, desc_len, service_type; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
725 char *name, *provider_name; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
726 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
727 #ifdef DEBUG_SI |
1748 | 728 av_log(ts->stream, AV_LOG_DEBUG, "SDT:\n"); |
1908
174083eafc6c
Introduce two new logging functions av_hex_dump_log() and av_pkt_dump_log()
takis
parents:
1787
diff
changeset
|
729 av_hex_dump_log(ts->stream, AV_LOG_DEBUG, (uint8_t *)section, section_len); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
730 #endif |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
731 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
732 p_end = section + section_len - 4; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
733 p = section; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
734 if (parse_section_header(h, &p, p_end) < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
735 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
736 if (h->tid != SDT_TID) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
737 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
738 onid = get16(&p, p_end); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
739 if (onid < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
740 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
741 val = get8(&p, p_end); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
742 if (val < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
743 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
744 for(;;) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
745 sid = get16(&p, p_end); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
746 if (sid < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
747 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
748 val = get8(&p, p_end); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
749 if (val < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
750 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
751 desc_list_len = get16(&p, p_end) & 0xfff; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
752 if (desc_list_len < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
753 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
754 desc_list_end = p + desc_list_len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
755 if (desc_list_end > p_end) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
756 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
757 for(;;) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
758 desc_tag = get8(&p, desc_list_end); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
759 if (desc_tag < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
760 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
761 desc_len = get8(&p, desc_list_end); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
762 desc_end = p + desc_len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
763 if (desc_end > desc_list_end) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
764 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
765 #ifdef DEBUG_SI |
1748 | 766 av_log(ts->stream, AV_LOG_DEBUG, "tag: 0x%02x len=%d\n", |
1724
940907f49a33
"converts printf's to avlog's" patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1481
diff
changeset
|
767 desc_tag, desc_len); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
768 #endif |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
769 switch(desc_tag) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
770 case 0x48: |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
771 service_type = get8(&p, p_end); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
772 if (service_type < 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
773 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
774 provider_name = getstr8(&p, p_end); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
775 if (!provider_name) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
776 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
777 name = getstr8(&p, p_end); |
2574
9e51e62f5bdd
replaced custom tracking of programs/services with calls to with av_new_program()
nicodvb
parents:
2555
diff
changeset
|
778 if (name) { |
9e51e62f5bdd
replaced custom tracking of programs/services with calls to with av_new_program()
nicodvb
parents:
2555
diff
changeset
|
779 AVProgram *program = av_new_program(ts->stream, sid); |
9e51e62f5bdd
replaced custom tracking of programs/services with calls to with av_new_program()
nicodvb
parents:
2555
diff
changeset
|
780 if(program) |
9e51e62f5bdd
replaced custom tracking of programs/services with calls to with av_new_program()
nicodvb
parents:
2555
diff
changeset
|
781 av_set_program_name(program, provider_name, name); |
9e51e62f5bdd
replaced custom tracking of programs/services with calls to with av_new_program()
nicodvb
parents:
2555
diff
changeset
|
782 } |
3247 | 783 av_free(name); |
784 av_free(provider_name); | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
785 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
786 default: |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
787 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
788 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
789 p = desc_end; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
790 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
791 p = desc_list_end; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
792 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
793 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
794 |
170
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
795 /* scan services in a transport stream by looking at the SDT */ |
1124
d3aff2c607f9
Add const to (mostly) char* and make some functions static, which aren't used
diego
parents:
1047
diff
changeset
|
796 static void mpegts_scan_sdt(MpegTSContext *ts) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
797 { |
2129
020f3b7f0eb0
do not perform SDT scan at the begin (this avoids a timeconsuming search for
michael
parents:
2128
diff
changeset
|
798 mpegts_open_section_filter(ts, SDT_PID, |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
799 sdt_cb, ts, 1); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
800 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
801 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
802 static int64_t get_pts(const uint8_t *p) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
803 { |
2222 | 804 int64_t pts = (int64_t)((p[0] >> 1) & 0x07) << 30; |
805 pts |= (AV_RB16(p + 1) >> 1) << 15; | |
806 pts |= AV_RB16(p + 3) >> 1; | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
807 return pts; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
808 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
809 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
810 /* return non zero if a packet could be constructed */ |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
811 static void mpegts_push_data(MpegTSFilter *filter, |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
812 const uint8_t *buf, int buf_size, int is_start) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
813 { |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
814 PESContext *pes = filter->u.pes_filter.opaque; |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
815 MpegTSContext *ts = pes->ts; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
816 const uint8_t *p; |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
817 int len, code; |
885 | 818 |
2111
4aafc6050f39
kill completely idiotic code which hides all but 2 streams
michael
parents:
2110
diff
changeset
|
819 if(!ts->pkt) |
4aafc6050f39
kill completely idiotic code which hides all but 2 streams
michael
parents:
2110
diff
changeset
|
820 return; |
4aafc6050f39
kill completely idiotic code which hides all but 2 streams
michael
parents:
2110
diff
changeset
|
821 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
822 if (is_start) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
823 pes->state = MPEGTS_HEADER; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
824 pes->data_index = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
825 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
826 p = buf; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
827 while (buf_size > 0) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
828 switch(pes->state) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
829 case MPEGTS_HEADER: |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
830 len = PES_START_SIZE - pes->data_index; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
831 if (len > buf_size) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
832 len = buf_size; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
833 memcpy(pes->header + pes->data_index, p, len); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
834 pes->data_index += len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
835 p += len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
836 buf_size -= len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
837 if (pes->data_index == PES_START_SIZE) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
838 /* we got all the PES or section header. We can now |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
839 decide */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
840 #if 0 |
1908
174083eafc6c
Introduce two new logging functions av_hex_dump_log() and av_pkt_dump_log()
takis
parents:
1787
diff
changeset
|
841 av_hex_dump_log(pes->stream, AV_LOG_DEBUG, pes->header, pes->data_index); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
842 #endif |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
843 if (pes->header[0] == 0x00 && pes->header[1] == 0x00 && |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
844 pes->header[2] == 0x01) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
845 /* it must be an mpeg2 PES stream */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
846 code = pes->header[3] | 0x100; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
847 if (!((code >= 0x1c0 && code <= 0x1df) || |
165
e4d2f704bf80
- Looks a tiny bit harder in mpegps_probe() for a valid start code. This is
michaelni
parents:
160
diff
changeset
|
848 (code >= 0x1e0 && code <= 0x1ef) || |
1774 | 849 (code == 0x1bd) || (code == 0x1fd))) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
850 goto skip; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
851 if (!pes->st) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
852 /* allocate stream */ |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
853 new_pes_av_stream(pes, code); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
854 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
855 pes->state = MPEGTS_PESHEADER_FILL; |
2222 | 856 pes->total_size = AV_RB16(pes->header + 4); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
857 /* NOTE: a zero total size means the PES size is |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
858 unbounded */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
859 if (pes->total_size) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
860 pes->total_size += 6; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
861 pes->pes_header_size = pes->header[8] + 9; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
862 } else { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
863 /* otherwise, it should be a table */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
864 /* skip packet */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
865 skip: |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
866 pes->state = MPEGTS_SKIP; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
867 continue; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
868 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
869 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
870 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
871 /**********************************************/ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
872 /* PES packing parsing */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
873 case MPEGTS_PESHEADER_FILL: |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
874 len = pes->pes_header_size - pes->data_index; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
875 if (len > buf_size) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
876 len = buf_size; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
877 memcpy(pes->header + pes->data_index, p, len); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
878 pes->data_index += len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
879 p += len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
880 buf_size -= len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
881 if (pes->data_index == pes->pes_header_size) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
882 const uint8_t *r; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
883 unsigned int flags; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
884 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
885 flags = pes->header[7]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
886 r = pes->header + 9; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
887 pes->pts = AV_NOPTS_VALUE; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
888 pes->dts = AV_NOPTS_VALUE; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
889 if ((flags & 0xc0) == 0x80) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
890 pes->pts = get_pts(r); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
891 r += 5; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
892 } else if ((flags & 0xc0) == 0xc0) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
893 pes->pts = get_pts(r); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
894 r += 5; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
895 pes->dts = get_pts(r); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
896 r += 5; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
897 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
898 /* we got the full header. We parse it and get the payload */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
899 pes->state = MPEGTS_PAYLOAD; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
900 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
901 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
902 case MPEGTS_PAYLOAD: |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
903 if (pes->total_size) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
904 len = pes->total_size - pes->data_index; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
905 if (len > buf_size) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
906 len = buf_size; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
907 } else { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
908 len = buf_size; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
909 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
910 if (len > 0) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
911 AVPacket *pkt = ts->pkt; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
912 if (pes->st && av_new_packet(pkt, len) == 0) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
913 memcpy(pkt->data, p, len); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
914 pkt->stream_index = pes->st->index; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
915 pkt->pts = pes->pts; |
367
3fca8e9142a4
avsync patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
342
diff
changeset
|
916 pkt->dts = pes->dts; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
917 /* reset pts values */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
918 pes->pts = AV_NOPTS_VALUE; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
919 pes->dts = AV_NOPTS_VALUE; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
920 ts->stop_parse = 1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
921 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
922 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
923 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
924 buf_size = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
925 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
926 case MPEGTS_SKIP: |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
927 buf_size = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
928 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
929 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
930 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
931 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
932 |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
933 static AVStream* new_pes_av_stream(PESContext *pes, uint32_t code) |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
934 { |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
935 AVStream *st; |
3967 | 936 enum CodecID codec_id; |
937 enum CodecType codec_type; | |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
938 |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
939 switch(pes->stream_type){ |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
940 case STREAM_TYPE_AUDIO_MPEG1: |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
941 case STREAM_TYPE_AUDIO_MPEG2: |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
942 codec_type = CODEC_TYPE_AUDIO; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
943 codec_id = CODEC_ID_MP3; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
944 break; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
945 case STREAM_TYPE_VIDEO_MPEG1: |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
946 case STREAM_TYPE_VIDEO_MPEG2: |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
947 codec_type = CODEC_TYPE_VIDEO; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
948 codec_id = CODEC_ID_MPEG2VIDEO; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
949 break; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
950 case STREAM_TYPE_VIDEO_MPEG4: |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
951 codec_type = CODEC_TYPE_VIDEO; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
952 codec_id = CODEC_ID_MPEG4; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
953 break; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
954 case STREAM_TYPE_VIDEO_H264: |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
955 codec_type = CODEC_TYPE_VIDEO; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
956 codec_id = CODEC_ID_H264; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
957 break; |
1774 | 958 case STREAM_TYPE_VIDEO_VC1: |
959 codec_type = CODEC_TYPE_VIDEO; | |
960 codec_id = CODEC_ID_VC1; | |
961 break; | |
3716 | 962 case STREAM_TYPE_VIDEO_DIRAC: |
963 codec_type = CODEC_TYPE_VIDEO; | |
964 codec_id = CODEC_ID_DIRAC; | |
965 break; | |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
966 case STREAM_TYPE_AUDIO_AAC: |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
967 codec_type = CODEC_TYPE_AUDIO; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
968 codec_id = CODEC_ID_AAC; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
969 break; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
970 case STREAM_TYPE_AUDIO_AC3: |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
971 codec_type = CODEC_TYPE_AUDIO; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
972 codec_id = CODEC_ID_AC3; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
973 break; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
974 case STREAM_TYPE_AUDIO_DTS: |
3059
f982a5a75e40
treat stream_type==0x82 as AUDIO_DTS when the program has a REGISTRATION_DESCRIPTOR with the value HDMV; approved by Mans
nicodvb
parents:
2893
diff
changeset
|
975 case STREAM_TYPE_AUDIO_HDMV_DTS: |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
976 codec_type = CODEC_TYPE_AUDIO; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
977 codec_id = CODEC_ID_DTS; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
978 break; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
979 case STREAM_TYPE_SUBTITLE_DVB: |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
980 codec_type = CODEC_TYPE_SUBTITLE; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
981 codec_id = CODEC_ID_DVB_SUBTITLE; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
982 break; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
983 default: |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
984 if (code >= 0x1c0 && code <= 0x1df) { |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
985 codec_type = CODEC_TYPE_AUDIO; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
986 codec_id = CODEC_ID_MP2; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
987 } else if (code == 0x1bd) { |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
988 codec_type = CODEC_TYPE_AUDIO; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
989 codec_id = CODEC_ID_AC3; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
990 } else { |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
991 codec_type = CODEC_TYPE_VIDEO; |
3604
8017c6d153a3
Fix misdetection of H.264 in mpegts as mpeg1video in mpegts.
michael
parents:
3589
diff
changeset
|
992 codec_id = CODEC_ID_PROBE; |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
993 } |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
994 break; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
995 } |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
996 st = av_new_stream(pes->stream, pes->pid); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
997 if (st) { |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
998 av_set_pts_info(st, 33, 1, 90000); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
999 st->priv_data = pes; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1000 st->codec->codec_type = codec_type; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1001 st->codec->codec_id = codec_id; |
2023 | 1002 st->need_parsing = AVSTREAM_PARSE_FULL; |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
1003 pes->st = st; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
1004 } |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
1005 return st; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
1006 } |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
1007 |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
1008 |
2157
0103a8479df5
proper per stream pcr_pid support by (Wolfram Gloger wmglo dent.med.uni-muenchen@de )
michael
parents:
2146
diff
changeset
|
1009 static PESContext *add_pes_stream(MpegTSContext *ts, int pid, int pcr_pid, int stream_type) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1010 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1011 MpegTSFilter *tss; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1012 PESContext *pes; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1013 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1014 /* if no pid found, then add a pid context */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1015 pes = av_mallocz(sizeof(PESContext)); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1016 if (!pes) |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
1017 return 0; |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1018 pes->ts = ts; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1019 pes->stream = ts->stream; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1020 pes->pid = pid; |
2157
0103a8479df5
proper per stream pcr_pid support by (Wolfram Gloger wmglo dent.med.uni-muenchen@de )
michael
parents:
2146
diff
changeset
|
1021 pes->pcr_pid = pcr_pid; |
313
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
310
diff
changeset
|
1022 pes->stream_type = stream_type; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1023 tss = mpegts_open_pes_filter(ts, pid, mpegts_push_data, pes); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1024 if (!tss) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1025 av_free(pes); |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
1026 return 0; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1027 } |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
1028 return pes; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1029 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1030 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1031 /* handle one TS packet */ |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1032 static void handle_packet(MpegTSContext *ts, const uint8_t *packet) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1033 { |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1034 AVFormatContext *s = ts->stream; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1035 MpegTSFilter *tss; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1036 int len, pid, cc, cc_ok, afc, is_start; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1037 const uint8_t *p, *p_end; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1038 |
2222 | 1039 pid = AV_RB16(packet + 1) & 0x1fff; |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
1040 if(pid && discard_pid(ts, pid)) |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
1041 return; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1042 is_start = packet[1] & 0x40; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1043 tss = ts->pids[pid]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1044 if (ts->auto_guess && tss == NULL && is_start) { |
2157
0103a8479df5
proper per stream pcr_pid support by (Wolfram Gloger wmglo dent.med.uni-muenchen@de )
michael
parents:
2146
diff
changeset
|
1045 add_pes_stream(ts, pid, -1, 0); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1046 tss = ts->pids[pid]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1047 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1048 if (!tss) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1049 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1050 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1051 /* continuity check (currently not used) */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1052 cc = (packet[3] & 0xf); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1053 cc_ok = (tss->last_cc < 0) || ((((tss->last_cc + 1) & 0x0f) == cc)); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1054 tss->last_cc = cc; |
885 | 1055 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1056 /* skip adaptation field */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1057 afc = (packet[3] >> 4) & 3; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1058 p = packet + 4; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1059 if (afc == 0) /* reserved value */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1060 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1061 if (afc == 2) /* adaptation field only */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1062 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1063 if (afc == 3) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1064 /* skip adapation field */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1065 p += p[0] + 1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1066 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1067 /* if past the end of packet, ignore */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1068 p_end = packet + TS_PACKET_SIZE; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1069 if (p >= p_end) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1070 return; |
885 | 1071 |
3240
78153a85dccc
Ensure that the timestamp reading code used for seeking chooses a position
michael
parents:
3226
diff
changeset
|
1072 ts->pos47= url_ftell(ts->stream->pb) % ts->raw_packet_size; |
78153a85dccc
Ensure that the timestamp reading code used for seeking chooses a position
michael
parents:
3226
diff
changeset
|
1073 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1074 if (tss->type == MPEGTS_SECTION) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1075 if (is_start) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1076 /* pointer field present */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1077 len = *p++; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1078 if (p + len > p_end) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1079 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1080 if (len && cc_ok) { |
675
29a19aec26b2
Writing to freed memory in write_section_data() patch by (Wolfram Gloger <wmglo dent dot med dot uni-muenchen de>)
michael
parents:
555
diff
changeset
|
1081 /* write remaining section bytes */ |
885 | 1082 write_section_data(s, tss, |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1083 p, len, 0); |
675
29a19aec26b2
Writing to freed memory in write_section_data() patch by (Wolfram Gloger <wmglo dent dot med dot uni-muenchen de>)
michael
parents:
555
diff
changeset
|
1084 /* check whether filter has been closed */ |
29a19aec26b2
Writing to freed memory in write_section_data() patch by (Wolfram Gloger <wmglo dent dot med dot uni-muenchen de>)
michael
parents:
555
diff
changeset
|
1085 if (!ts->pids[pid]) |
29a19aec26b2
Writing to freed memory in write_section_data() patch by (Wolfram Gloger <wmglo dent dot med dot uni-muenchen de>)
michael
parents:
555
diff
changeset
|
1086 return; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1087 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1088 p += len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1089 if (p < p_end) { |
885 | 1090 write_section_data(s, tss, |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1091 p, p_end - p, 1); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1092 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1093 } else { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1094 if (cc_ok) { |
885 | 1095 write_section_data(s, tss, |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1096 p, p_end - p, 0); |
170
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1097 } |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1098 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1099 } else { |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
1100 tss->u.pes_filter.pes_cb(tss, |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1101 p, p_end - p, is_start); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1102 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1103 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1104 |
170
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1105 /* XXX: try to find a better synchro over several packets (use |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1106 get_packet_size() ?) */ |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1107 static int mpegts_resync(ByteIOContext *pb) |
170
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1108 { |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1109 int c, i; |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1110 |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1111 for(i = 0;i < MAX_RESYNC_SIZE; i++) { |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1112 c = url_fgetc(pb); |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1113 if (c < 0) |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1114 return -1; |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1115 if (c == 0x47) { |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1116 url_fseek(pb, -1, SEEK_CUR); |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1117 return 0; |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1118 } |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1119 } |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1120 /* no sync found */ |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1121 return -1; |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1122 } |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1123 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1124 /* return -1 if error or EOF. Return 0 if OK. */ |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1125 static int read_packet(ByteIOContext *pb, uint8_t *buf, int raw_packet_size) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1126 { |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1127 int skip, len; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1128 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1129 for(;;) { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1130 len = get_buffer(pb, buf, TS_PACKET_SIZE); |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1131 if (len != TS_PACKET_SIZE) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2247
diff
changeset
|
1132 return AVERROR(EIO); |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1133 /* check paquet sync byte */ |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1134 if (buf[0] != 0x47) { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1135 /* find a new packet start */ |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1136 url_fseek(pb, -TS_PACKET_SIZE, SEEK_CUR); |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1137 if (mpegts_resync(pb) < 0) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1138 return AVERROR_INVALIDDATA; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1139 else |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1140 continue; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1141 } else { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1142 skip = raw_packet_size - TS_PACKET_SIZE; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1143 if (skip > 0) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1144 url_fskip(pb, skip); |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1145 break; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1146 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1147 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1148 return 0; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1149 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1150 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1151 static int handle_packets(MpegTSContext *ts, int nb_packets) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1152 { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1153 AVFormatContext *s = ts->stream; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1154 ByteIOContext *pb = s->pb; |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1155 uint8_t packet[TS_PACKET_SIZE]; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1156 int packet_num, ret; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1157 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1158 ts->stop_parse = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1159 packet_num = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1160 for(;;) { |
2134
16cf48c9af53
dont rescan for information on each pid, but rather do it just once by
michael
parents:
2133
diff
changeset
|
1161 if (ts->stop_parse>0) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1162 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1163 packet_num++; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1164 if (nb_packets != 0 && packet_num >= nb_packets) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1165 break; |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1166 ret = read_packet(pb, packet, ts->raw_packet_size); |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1167 if (ret != 0) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1168 return ret; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1169 handle_packet(ts, packet); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1170 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1171 return 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1172 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1173 |
0 | 1174 static int mpegts_probe(AVProbeData *p) |
1175 { | |
170
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1176 #if 1 |
329 | 1177 const int size= p->buf_size; |
891 | 1178 int score, fec_score, dvhs_score; |
329 | 1179 #define CHECK_COUNT 10 |
885 | 1180 |
329 | 1181 if (size < (TS_FEC_PACKET_SIZE * CHECK_COUNT)) |
1182 return -1; | |
885 | 1183 |
329 | 1184 score = analyze(p->buf, TS_PACKET_SIZE *CHECK_COUNT, TS_PACKET_SIZE, NULL); |
891 | 1185 dvhs_score = analyze(p->buf, TS_DVHS_PACKET_SIZE *CHECK_COUNT, TS_DVHS_PACKET_SIZE, NULL); |
329 | 1186 fec_score= analyze(p->buf, TS_FEC_PACKET_SIZE*CHECK_COUNT, TS_FEC_PACKET_SIZE, NULL); |
891 | 1187 // av_log(NULL, AV_LOG_DEBUG, "score: %d, dvhs_score: %d, fec_score: %d \n", score, dvhs_score, fec_score); |
885 | 1188 |
329 | 1189 // we need a clear definition for the returned score otherwise things will become messy sooner or later |
891 | 1190 if (score > fec_score && score > dvhs_score && score > 6) return AVPROBE_SCORE_MAX + score - CHECK_COUNT; |
1191 else if(dvhs_score > score && dvhs_score > fec_score && dvhs_score > 6) return AVPROBE_SCORE_MAX + dvhs_score - CHECK_COUNT; | |
329 | 1192 else if( fec_score > 6) return AVPROBE_SCORE_MAX + fec_score - CHECK_COUNT; |
1193 else return -1; | |
170
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1194 #else |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1195 /* only use the extension for safer guess */ |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1196 if (match_ext(p->filename, "ts")) |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1197 return AVPROBE_SCORE_MAX; |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1198 else |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1199 return 0; |
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1200 #endif |
0 | 1201 } |
1202 | |
3968 | 1203 /* return the 90kHz PCR and the extension for the 27MHz PCR. return |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1204 (-1) if not available */ |
885 | 1205 static int parse_pcr(int64_t *ppcr_high, int *ppcr_low, |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1206 const uint8_t *packet) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1207 { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1208 int afc, len, flags; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1209 const uint8_t *p; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1210 unsigned int v; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1211 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1212 afc = (packet[3] >> 4) & 3; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1213 if (afc <= 1) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1214 return -1; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1215 p = packet + 4; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1216 len = p[0]; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1217 p++; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1218 if (len == 0) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1219 return -1; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1220 flags = *p++; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1221 len--; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1222 if (!(flags & 0x10)) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1223 return -1; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1224 if (len < 6) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1225 return -1; |
2222 | 1226 v = AV_RB32(p); |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1227 *ppcr_high = ((int64_t)v << 1) | (p[4] >> 7); |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1228 *ppcr_low = ((p[4] & 1) << 8) | p[5]; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1229 return 0; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1230 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1231 |
0 | 1232 static int mpegts_read_header(AVFormatContext *s, |
1233 AVFormatParameters *ap) | |
1234 { | |
1235 MpegTSContext *ts = s->priv_data; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1236 ByteIOContext *pb = s->pb; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1237 uint8_t buf[1024]; |
2135 | 1238 int len; |
65 | 1239 int64_t pos; |
474 | 1240 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1241 if (ap) { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1242 ts->mpeg2ts_compute_pcr = ap->mpeg2ts_compute_pcr; |
2108
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1243 if(ap->mpeg2ts_raw){ |
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1244 av_log(s, AV_LOG_ERROR, "use mpegtsraw_demuxer!\n"); |
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1245 return -1; |
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1246 } |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1247 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1248 |
0 | 1249 /* read the first 1024 bytes to get packet size */ |
1250 pos = url_ftell(pb); | |
1251 len = get_buffer(pb, buf, sizeof(buf)); | |
1252 if (len != sizeof(buf)) | |
1253 goto fail; | |
1254 ts->raw_packet_size = get_packet_size(buf, sizeof(buf)); | |
1255 if (ts->raw_packet_size <= 0) | |
1256 goto fail; | |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1257 ts->stream = s; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1258 ts->auto_guess = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1259 |
2108
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1260 if (s->iformat == &mpegts_demuxer) { |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1261 /* normal demux */ |
170
0543d27721c1
cosmetic change in resync code - added PAT scanning code if no SDT is found (in the futur it would be interesting to give an API to change channel - also useful for DV input number or TV grab tunning
bellard
parents:
165
diff
changeset
|
1262 |
2126 | 1263 /* first do a scaning to get all the services */ |
1264 url_fseek(pb, pos, SEEK_SET); | |
1265 mpegts_scan_sdt(ts); | |
1266 | |
2137 | 1267 mpegts_set_service(ts); |
885 | 1268 |
2137 | 1269 handle_packets(ts, s->probesize); |
2126 | 1270 /* if could not find service, enable auto_guess */ |
885 | 1271 |
2126 | 1272 ts->auto_guess = 1; |
885 | 1273 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1274 #ifdef DEBUG_SI |
2126 | 1275 av_log(ts->stream, AV_LOG_DEBUG, "tuning done\n"); |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1276 #endif |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1277 s->ctx_flags |= AVFMTCTX_NOHEADER; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1278 } else { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1279 AVStream *st; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1280 int pcr_pid, pid, nb_packets, nb_pcrs, ret, pcr_l; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1281 int64_t pcrs[2], pcr_h; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1282 int packet_count[2]; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1283 uint8_t packet[TS_PACKET_SIZE]; |
885 | 1284 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1285 /* only read packets */ |
885 | 1286 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1287 st = av_new_stream(s, 0); |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1288 if (!st) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1289 goto fail; |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
444
diff
changeset
|
1290 av_set_pts_info(st, 60, 1, 27000000); |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1291 st->codec->codec_type = CODEC_TYPE_DATA; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1292 st->codec->codec_id = CODEC_ID_MPEG2TS; |
885 | 1293 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1294 /* we iterate until we find two PCRs to estimate the bitrate */ |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1295 pcr_pid = -1; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1296 nb_pcrs = 0; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1297 nb_packets = 0; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1298 for(;;) { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1299 ret = read_packet(s->pb, packet, ts->raw_packet_size); |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1300 if (ret < 0) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1301 return -1; |
2222 | 1302 pid = AV_RB16(packet + 1) & 0x1fff; |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1303 if ((pcr_pid == -1 || pcr_pid == pid) && |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1304 parse_pcr(&pcr_h, &pcr_l, packet) == 0) { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1305 pcr_pid = pid; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1306 packet_count[nb_pcrs] = nb_packets; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1307 pcrs[nb_pcrs] = pcr_h * 300 + pcr_l; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1308 nb_pcrs++; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1309 if (nb_pcrs >= 2) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1310 break; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1311 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1312 nb_packets++; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1313 } |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1314 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1315 /* NOTE1: the bitrate is computed without the FEC */ |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1316 /* NOTE2: it is only the bitrate of the start of the stream */ |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1317 ts->pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]); |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1318 ts->cur_pcr = pcrs[0] - ts->pcr_incr * packet_count[0]; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1319 s->bit_rate = (TS_PACKET_SIZE * 8) * 27e6 / ts->pcr_incr; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
819
diff
changeset
|
1320 st->codec->bit_rate = s->bit_rate; |
743 | 1321 st->start_time = ts->cur_pcr; |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1322 #if 0 |
1748 | 1323 av_log(ts->stream, AV_LOG_DEBUG, "start=%0.3f pcr=%0.3f incr=%d\n", |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1324 st->start_time / 1000000.0, pcrs[0] / 27e6, ts->pcr_incr); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1325 #endif |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1326 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1327 |
0 | 1328 url_fseek(pb, pos, SEEK_SET); |
1329 return 0; | |
1330 fail: | |
1331 return -1; | |
1332 } | |
1333 | |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1334 #define MAX_PACKET_READAHEAD ((128 * 1024) / 188) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1335 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1336 static int mpegts_raw_read_packet(AVFormatContext *s, |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1337 AVPacket *pkt) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1338 { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1339 MpegTSContext *ts = s->priv_data; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1340 int ret, i; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1341 int64_t pcr_h, next_pcr_h, pos; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1342 int pcr_l, next_pcr_l; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1343 uint8_t pcr_buf[12]; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1344 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1345 if (av_new_packet(pkt, TS_PACKET_SIZE) < 0) |
1787
eb16c64144ee
This fixes error handling for BeOS, removing the need for some ifdefs.
mmu_man
parents:
1774
diff
changeset
|
1346 return AVERROR(ENOMEM); |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1347 pkt->pos= url_ftell(s->pb); |
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1348 ret = read_packet(s->pb, pkt->data, ts->raw_packet_size); |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1349 if (ret < 0) { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1350 av_free_packet(pkt); |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1351 return ret; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1352 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1353 if (ts->mpeg2ts_compute_pcr) { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1354 /* compute exact PCR for each packet */ |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1355 if (parse_pcr(&pcr_h, &pcr_l, pkt->data) == 0) { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1356 /* we read the next PCR (XXX: optimize it by using a bigger buffer */ |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1357 pos = url_ftell(s->pb); |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1358 for(i = 0; i < MAX_PACKET_READAHEAD; i++) { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1359 url_fseek(s->pb, pos + i * ts->raw_packet_size, SEEK_SET); |
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1360 get_buffer(s->pb, pcr_buf, 12); |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1361 if (parse_pcr(&next_pcr_h, &next_pcr_l, pcr_buf) == 0) { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1362 /* XXX: not precise enough */ |
885 | 1363 ts->pcr_incr = ((next_pcr_h - pcr_h) * 300 + (next_pcr_l - pcr_l)) / |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1364 (i + 1); |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1365 break; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1366 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1367 } |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1368 url_fseek(s->pb, pos, SEEK_SET); |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1369 /* no next PCR found: we use previous increment */ |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1370 ts->cur_pcr = pcr_h * 300 + pcr_l; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1371 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1372 pkt->pts = ts->cur_pcr; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1373 pkt->duration = ts->pcr_incr; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1374 ts->cur_pcr += ts->pcr_incr; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1375 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1376 pkt->stream_index = 0; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1377 return 0; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1378 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1379 |
0 | 1380 static int mpegts_read_packet(AVFormatContext *s, |
1381 AVPacket *pkt) | |
1382 { | |
1383 MpegTSContext *ts = s->priv_data; | |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1384 |
2108
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1385 ts->pkt = pkt; |
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1386 return handle_packets(ts, 0); |
0 | 1387 } |
1388 | |
1389 static int mpegts_read_close(AVFormatContext *s) | |
1390 { | |
1391 MpegTSContext *ts = s->priv_data; | |
1392 int i; | |
3247 | 1393 |
1394 clear_programs(ts); | |
1395 | |
0 | 1396 for(i=0;i<NB_PID_MAX;i++) |
342
0c1b489c96bf
memleak patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
329
diff
changeset
|
1397 if (ts->pids[i]) mpegts_close_filter(ts, ts->pids[i]); |
1046 | 1398 |
0 | 1399 return 0; |
1400 } | |
1401 | |
885 | 1402 static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index, |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1403 int64_t *ppos, int64_t pos_limit) |
310 | 1404 { |
1405 MpegTSContext *ts = s->priv_data; | |
1406 int64_t pos, timestamp; | |
1407 uint8_t buf[TS_PACKET_SIZE]; | |
2157
0103a8479df5
proper per stream pcr_pid support by (Wolfram Gloger wmglo dent.med.uni-muenchen@de )
michael
parents:
2146
diff
changeset
|
1408 int pcr_l, pcr_pid = ((PESContext*)s->streams[stream_index]->priv_data)->pcr_pid; |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1409 const int find_next= 1; |
3240
78153a85dccc
Ensure that the timestamp reading code used for seeking chooses a position
michael
parents:
3226
diff
changeset
|
1410 pos = ((*ppos + ts->raw_packet_size - 1 - ts->pos47) / ts->raw_packet_size) * ts->raw_packet_size + ts->pos47; |
310 | 1411 if (find_next) { |
1412 for(;;) { | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1413 url_fseek(s->pb, pos, SEEK_SET); |
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1414 if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) |
310 | 1415 return AV_NOPTS_VALUE; |
2222 | 1416 if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) && |
310 | 1417 parse_pcr(×tamp, &pcr_l, buf) == 0) { |
1418 break; | |
1419 } | |
1420 pos += ts->raw_packet_size; | |
1421 } | |
1422 } else { | |
1423 for(;;) { | |
1424 pos -= ts->raw_packet_size; | |
1425 if (pos < 0) | |
1426 return AV_NOPTS_VALUE; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1427 url_fseek(s->pb, pos, SEEK_SET); |
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1428 if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) |
310 | 1429 return AV_NOPTS_VALUE; |
2222 | 1430 if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) && |
310 | 1431 parse_pcr(×tamp, &pcr_l, buf) == 0) { |
1432 break; | |
1433 } | |
1434 } | |
1435 } | |
1436 *ppos = pos; | |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1437 |
310 | 1438 return timestamp; |
1439 } | |
1440 | |
555 | 1441 static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){ |
474 | 1442 MpegTSContext *ts = s->priv_data; |
1443 uint8_t buf[TS_PACKET_SIZE]; | |
1444 int64_t pos; | |
1445 | |
555 | 1446 if(av_seek_frame_binary(s, stream_index, target_ts, flags) < 0) |
474 | 1447 return -1; |
1448 | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1449 pos= url_ftell(s->pb); |
474 | 1450 |
1451 for(;;) { | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1452 url_fseek(s->pb, pos, SEEK_SET); |
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1453 if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) |
474 | 1454 return -1; |
2222 | 1455 // pid = AV_RB16(buf + 1) & 0x1fff; |
474 | 1456 if(buf[1] & 0x40) break; |
1457 pos += ts->raw_packet_size; | |
885 | 1458 } |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1459 url_fseek(s->pb, pos, SEEK_SET); |
474 | 1460 |
1461 return 0; | |
1462 } | |
1463 | |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1464 /**************************************************************/ |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1465 /* parsing functions - called from other demuxers such as RTP */ |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1466 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1467 MpegTSContext *mpegts_parse_open(AVFormatContext *s) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1468 { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1469 MpegTSContext *ts; |
885 | 1470 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1471 ts = av_mallocz(sizeof(MpegTSContext)); |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1472 if (!ts) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1473 return NULL; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1474 /* no stream case, currently used by RTP */ |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1475 ts->raw_packet_size = TS_PACKET_SIZE; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1476 ts->stream = s; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1477 ts->auto_guess = 1; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1478 return ts; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1479 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1480 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1481 /* return the consumed length if a packet was output, or -1 if no |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1482 packet is output */ |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1483 int mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt, |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1484 const uint8_t *buf, int len) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1485 { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1486 int len1; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1487 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1488 len1 = len; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1489 ts->pkt = pkt; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1490 ts->stop_parse = 0; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1491 for(;;) { |
2134
16cf48c9af53
dont rescan for information on each pid, but rather do it just once by
michael
parents:
2133
diff
changeset
|
1492 if (ts->stop_parse>0) |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1493 break; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1494 if (len < TS_PACKET_SIZE) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1495 return -1; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1496 if (buf[0] != 0x47) { |
444
d42038d418a0
Off-by-two in mpegts.c patch by (Wolfram Gloger <wmglo at dent dot med dot uni-muenchen dot de>)
michael
parents:
398
diff
changeset
|
1497 buf++; |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1498 len--; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1499 } else { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1500 handle_packet(ts, buf); |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1501 buf += TS_PACKET_SIZE; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1502 len -= TS_PACKET_SIZE; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1503 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1504 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1505 return len1 - len; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1506 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1507 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1508 void mpegts_parse_close(MpegTSContext *ts) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1509 { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1510 int i; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1511 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1512 for(i=0;i<NB_PID_MAX;i++) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1513 av_free(ts->pids[i]); |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1514 av_free(ts); |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1515 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1516 |
1167 | 1517 AVInputFormat mpegts_demuxer = { |
0 | 1518 "mpegts", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3286
diff
changeset
|
1519 NULL_IF_CONFIG_SMALL("MPEG-2 transport stream format"), |
0 | 1520 sizeof(MpegTSContext), |
1521 mpegts_probe, | |
1522 mpegts_read_header, | |
1523 mpegts_read_packet, | |
1524 mpegts_read_close, | |
474 | 1525 read_seek, |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1526 mpegts_get_pcr, |
3724
178cc6f9d5ec
Add flag to mark demuxers that can output discontinuous timestamps.
michael
parents:
3716
diff
changeset
|
1527 .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT, |
0 | 1528 }; |
2108
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1529 |
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1530 AVInputFormat mpegtsraw_demuxer = { |
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1531 "mpegtsraw", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3286
diff
changeset
|
1532 NULL_IF_CONFIG_SMALL("MPEG-2 raw transport stream format"), |
2108
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1533 sizeof(MpegTSContext), |
3226
dcde7da1d183
Using the same probe function in 2 formats is not a good idea.
michael
parents:
3059
diff
changeset
|
1534 NULL, |
2108
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1535 mpegts_read_header, |
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1536 mpegts_raw_read_packet, |
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1537 mpegts_read_close, |
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1538 read_seek, |
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1539 mpegts_get_pcr, |
3724
178cc6f9d5ec
Add flag to mark demuxers that can output discontinuous timestamps.
michael
parents:
3716
diff
changeset
|
1540 .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT, |
2108
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1541 }; |