Mercurial > libavformat.hg
annotate mpegts.c @ 5324:3616c1434288 libavformat
Add comment on #endif about condition that triggers it.
author | ramiro |
---|---|
date | Wed, 21 Oct 2009 01:25:39 +0000 |
parents | ca4d9e153f56 |
children | 9a3338ab7453 |
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 |
4251
77e0c7511d41
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
4201
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 |
4962
66a7afa20cc7
move DEBUG define before include to get dprintf
bcoudurier
parents:
4868
diff
changeset
|
22 //#define DEBUG |
66a7afa20cc7
move DEBUG define before include to get dprintf
bcoudurier
parents:
4868
diff
changeset
|
23 //#define DEBUG_SEEK |
5162
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
24 //#define USE_SYNCPOINT_SEARCH |
4962
66a7afa20cc7
move DEBUG define before include to get dprintf
bcoudurier
parents:
4868
diff
changeset
|
25 |
3286 | 26 #include "libavutil/crc.h" |
4201
7d2f3f1b68d8
Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents:
4087
diff
changeset
|
27 #include "libavutil/intreadwrite.h" |
4860
d14d1f5f4eb4
simplify registration descriptor parsing with bytestream get functions
bcoudurier
parents:
4859
diff
changeset
|
28 #include "libavcodec/bytestream.h" |
0 | 29 #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
|
30 #include "mpegts.h" |
4062
297c1d6f9c5e
Add necessary header for av_set_program_name and av_program_add_stream_index.
diego
parents:
4059
diff
changeset
|
31 #include "internal.h" |
5140
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
32 #include "seek.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
|
33 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
34 /* 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
|
35 #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
|
36 |
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
|
37 /* 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
|
38 synchronisation is lost */ |
5303
03d4d6534554
Increase max resync size, fix demuxing of dvgrab-2009.03.28_19-07-22.m2t
bcoudurier
parents:
5271
diff
changeset
|
39 #define MAX_RESYNC_SIZE 65536 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
40 |
4963 | 41 #define MAX_PES_PAYLOAD 200*1024 |
42 | |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
43 typedef struct PESContext PESContext; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
44 |
2157
0103a8479df5
proper per stream pcr_pid support by (Wolfram Gloger wmglo dent.med.uni-muenchen@de )
michael
parents:
2146
diff
changeset
|
45 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
|
46 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
47 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
|
48 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
|
49 MPEGTS_SECTION, |
0 | 50 }; |
51 | |
2236
117edddfce20
update SectionCallback and PESCallback typedefs to match functions
mru
parents:
2222
diff
changeset
|
52 typedef struct MpegTSFilter MpegTSFilter; |
117edddfce20
update SectionCallback and PESCallback typedefs to match functions
mru
parents:
2222
diff
changeset
|
53 |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
54 typedef int PESCallback(MpegTSFilter *f, const uint8_t *buf, int len, int is_start, int64_t pos); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
55 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
56 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
|
57 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
|
58 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
|
59 } MpegTSPESFilter; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
60 |
2236
117edddfce20
update SectionCallback and PESCallback typedefs to match functions
mru
parents:
2222
diff
changeset
|
61 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
|
62 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
63 typedef void SetServiceCallback(void *opaque, int ret); |
0 | 64 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
65 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
|
66 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
|
67 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
|
68 uint8_t *section_buf; |
3553
c3b9334f46ae
One-bit bitfields should probably be unsigned. Unfortunately, it is left
takis
parents:
3487
diff
changeset
|
69 unsigned int check_crc:1; |
c3b9334f46ae
One-bit bitfields should probably be unsigned. Unfortunately, it is left
takis
parents:
3487
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 } MpegTSSectionFilter; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
74 |
2236
117edddfce20
update SectionCallback and PESCallback typedefs to match functions
mru
parents:
2222
diff
changeset
|
75 struct MpegTSFilter { |
0 | 76 int pid; |
77 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
|
78 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
|
79 union { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
80 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
|
81 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
|
82 } u; |
2236
117edddfce20
update SectionCallback and PESCallback typedefs to match functions
mru
parents:
2222
diff
changeset
|
83 }; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
84 |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
85 #define MAX_PIDS_PER_PROGRAM 64 |
4087
950dc8531665
mpegts: replace Program_t typedef with "struct Program"
mru
parents:
4062
diff
changeset
|
86 struct Program { |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
87 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
|
88 unsigned int nb_pids; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
89 unsigned int pids[MAX_PIDS_PER_PROGRAM]; |
4087
950dc8531665
mpegts: replace Program_t typedef with "struct Program"
mru
parents:
4062
diff
changeset
|
90 }; |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
91 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
92 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
|
93 /* 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
|
94 AVFormatContext *stream; |
1726
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
95 /** 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
|
96 int raw_packet_size; |
3240
78153a85dccc
Ensure that the timestamp reading code used for seeking chooses a position
michael
parents:
3226
diff
changeset
|
97 |
78153a85dccc
Ensure that the timestamp reading code used for seeking chooses a position
michael
parents:
3226
diff
changeset
|
98 int pos47; |
78153a85dccc
Ensure that the timestamp reading code used for seeking chooses a position
michael
parents:
3226
diff
changeset
|
99 |
1726
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
100 /** 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
|
101 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
|
102 |
1726
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
103 /** 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
|
104 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
|
105 |
1726
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
106 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
|
107 int pcr_incr; /**< used to estimate the exact PCR */ |
885 | 108 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
109 /* 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
|
110 /** stop parsing loop */ |
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
111 int stop_parse; |
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
112 /** 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
|
113 AVPacket *pkt; |
4963 | 114 /** to detect seek */ |
115 int64_t last_pos; | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
116 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
117 /******************************************/ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
118 /* 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
|
119 /* scan context */ |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
120 /** 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
|
121 unsigned int nb_prg; |
4087
950dc8531665
mpegts: replace Program_t typedef with "struct Program"
mru
parents:
4062
diff
changeset
|
122 struct Program *prg; |
885 | 123 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
124 |
1726
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
125 /** 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
|
126 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
|
127 }; |
0 | 128 |
2133
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
129 /* TS stream handling */ |
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 enum MpegTSState { |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
132 MPEGTS_HEADER = 0, |
5000 | 133 MPEGTS_PESHEADER, |
2133
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
134 MPEGTS_PESHEADER_FILL, |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
135 MPEGTS_PAYLOAD, |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
136 MPEGTS_SKIP, |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
137 }; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
138 |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
139 /* enough for PES header + length */ |
5000 | 140 #define PES_START_SIZE 6 |
141 #define PES_HEADER_SIZE 9 | |
2133
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
142 #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
|
143 |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
144 struct PESContext { |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
145 int pid; |
2157
0103a8479df5
proper per stream pcr_pid support by (Wolfram Gloger wmglo dent.med.uni-muenchen@de )
michael
parents:
2146
diff
changeset
|
146 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
|
147 int stream_type; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
148 MpegTSContext *ts; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
149 AVFormatContext *stream; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
150 AVStream *st; |
5262
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
151 AVStream *sub_st; /**< stream for the embedded AC3 stream in HDMV TrueHD */ |
2133
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
152 enum MpegTSState state; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
153 /* used to get the format */ |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
154 int data_index; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
155 int total_size; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
156 int pes_header_size; |
5262
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
157 int extended_stream_id; |
2133
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
158 int64_t pts, dts; |
4615
12a7cd9178dd
Change TS seeking so it returns position/timestamp of a key frame.
cehoyos
parents:
4427
diff
changeset
|
159 int64_t ts_packet_pos; /**< position of first TS packet of this PES packet */ |
2133
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
160 uint8_t header[MAX_PES_HEADER_SIZE]; |
4963 | 161 uint8_t *buffer; |
2133
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
162 }; |
2b2f5fc314e0
move structs and enums to top of file so they can be used
michael
parents:
2132
diff
changeset
|
163 |
2555 | 164 extern AVInputFormat mpegts_demuxer; |
165 | |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
166 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
|
167 { |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
168 int i; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
169 |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
170 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
|
171 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
|
172 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
|
173 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
174 |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
175 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
|
176 { |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
177 av_freep(&ts->prg); |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
178 ts->nb_prg=0; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
179 } |
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 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
|
182 { |
4087
950dc8531665
mpegts: replace Program_t typedef with "struct Program"
mru
parents:
4062
diff
changeset
|
183 struct Program *p; |
950dc8531665
mpegts: replace Program_t typedef with "struct Program"
mru
parents:
4062
diff
changeset
|
184 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
|
185 if(!tmp) |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
186 return; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
187 ts->prg = tmp; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
188 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
|
189 p->id = programid; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
190 p->nb_pids = 0; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
191 ts->nb_prg++; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
192 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
193 |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
194 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
|
195 { |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
196 int i; |
4087
950dc8531665
mpegts: replace Program_t typedef with "struct Program"
mru
parents:
4062
diff
changeset
|
197 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
|
198 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
|
199 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
|
200 p = &ts->prg[i]; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
201 break; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
202 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
203 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
204 if(!p) |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
205 return; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
206 |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
207 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
|
208 return; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
209 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
|
210 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
211 |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
212 /** |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
213 * \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
|
214 * 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
|
215 * \param ts : - TS context |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
216 * \param pid : - pid |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
217 * \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
|
218 * 0 otherwise |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
219 */ |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
220 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
|
221 { |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
222 int i, j, k; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
223 int used = 0, discarded = 0; |
4087
950dc8531665
mpegts: replace Program_t typedef with "struct Program"
mru
parents:
4062
diff
changeset
|
224 struct Program *p; |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
225 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
|
226 p = &ts->prg[i]; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
227 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
|
228 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
|
229 continue; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
230 //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
|
231 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
|
232 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
|
233 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
|
234 discarded++; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
235 else |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
236 used++; |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
237 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
238 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
239 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
240 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
241 |
3278 | 242 return !used && discarded; |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
243 } |
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
244 |
1726
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
245 /** |
63bb140936c0
mpegts-documentation-only.patch -- adds documentation patch by Daniel Kristjansson / danielk mrl.nyu edu
michael
parents:
1724
diff
changeset
|
246 * 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
|
247 * 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
|
248 */ |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
249 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
|
250 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
|
251 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
252 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
|
253 int len; |
885 | 254 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 } else { |
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 (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
|
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 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
269 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
270 /* 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
|
271 if (tss->section_h_size == -1 && tss->section_index >= 3) { |
2222 | 272 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
|
273 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
|
274 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
275 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
|
276 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
277 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
278 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
|
279 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
|
280 if (!tss->check_crc || |
2893 | 281 av_crc(av_crc_get_table(AV_CRC_32_IEEE), -1, |
282 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
|
283 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
|
284 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
285 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
286 |
1124
d3aff2c607f9
Add const to (mostly) char* and make some functions static, which aren't used
diego
parents:
1047
diff
changeset
|
287 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
|
288 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
|
289 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
|
290 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
291 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
292 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
|
293 MpegTSSectionFilter *sec; |
885 | 294 |
4862 | 295 dprintf(ts->stream, "Filter: pid=0x%x\n", pid); |
296 | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
297 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
|
298 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
|
299 filter = av_mallocz(sizeof(MpegTSFilter)); |
885 | 300 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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 } |
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 filter; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
316 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
317 |
1124
d3aff2c607f9
Add const to (mostly) char* and make some functions static, which aren't used
diego
parents:
1047
diff
changeset
|
318 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
|
319 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
|
320 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
|
321 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
322 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
|
323 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
|
324 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
325 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
|
326 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
|
327 filter = av_mallocz(sizeof(MpegTSFilter)); |
885 | 328 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
|
329 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
|
330 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
|
331 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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 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
|
337 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
|
338 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
339 |
1124
d3aff2c607f9
Add const to (mostly) char* and make some functions static, which aren't used
diego
parents:
1047
diff
changeset
|
340 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
|
341 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
342 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
|
343 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
344 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
|
345 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
|
346 av_freep(&filter->u.section_filter.section_buf); |
4390 | 347 else if (filter->type == MPEGTS_PES) { |
4963 | 348 PESContext *pes = filter->u.pes_filter.opaque; |
349 av_freep(&pes->buffer); | |
4390 | 350 /* referenced private data will be freed later in |
351 * av_close_input_stream */ | |
352 if (!((PESContext *)filter->u.pes_filter.opaque)->st) { | |
353 av_freep(&filter->u.pes_filter.opaque); | |
354 } | |
355 } | |
342
0c1b489c96bf
memleak patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents:
329
diff
changeset
|
356 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
357 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
|
358 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
|
359 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
360 |
329 | 361 static int analyze(const uint8_t *buf, int size, int packet_size, int *index){ |
5143 | 362 int stat[TS_MAX_PACKET_SIZE]; |
329 | 363 int i; |
364 int x=0; | |
365 int best_score=0; | |
366 | |
367 memset(stat, 0, packet_size*sizeof(int)); | |
368 | |
3589 | 369 for(x=i=0; i<size-3; i++){ |
370 if(buf[i] == 0x47 && !(buf[i+1] & 0x80) && (buf[i+3] & 0x30)){ | |
329 | 371 stat[x]++; |
372 if(stat[x] > best_score){ | |
373 best_score= stat[x]; | |
374 if(index) *index= x; | |
375 } | |
376 } | |
377 | |
378 x++; | |
379 if(x == packet_size) x= 0; | |
380 } | |
381 | |
382 return best_score; | |
383 } | |
384 | |
0 | 385 /* 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
|
386 static int get_packet_size(const uint8_t *buf, int size) |
0 | 387 { |
891 | 388 int score, fec_score, dvhs_score; |
0 | 389 |
390 if (size < (TS_FEC_PACKET_SIZE * 5 + 1)) | |
391 return -1; | |
885 | 392 |
329 | 393 score = analyze(buf, size, TS_PACKET_SIZE, NULL); |
891 | 394 dvhs_score = analyze(buf, size, TS_DVHS_PACKET_SIZE, NULL); |
329 | 395 fec_score= analyze(buf, size, TS_FEC_PACKET_SIZE, NULL); |
891 | 396 // av_log(NULL, AV_LOG_DEBUG, "score: %d, dvhs_score: %d, fec_score: %d \n", score, dvhs_score, fec_score); |
885 | 397 |
891 | 398 if (score > fec_score && score > dvhs_score) return TS_PACKET_SIZE; |
399 else if(dvhs_score > score && dvhs_score > fec_score) return TS_DVHS_PACKET_SIZE; | |
400 else if(score < fec_score && dvhs_score < fec_score) return TS_FEC_PACKET_SIZE; | |
329 | 401 else return -1; |
0 | 402 } |
403 | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
404 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
|
405 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
|
406 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
|
407 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
|
408 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
|
409 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
|
410 } SectionHeader; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
411 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
412 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
|
413 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
414 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
|
415 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
|
416 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
417 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
|
418 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
|
419 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
|
420 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
|
421 *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
|
422 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
|
423 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
424 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
425 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
|
426 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
427 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
|
428 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
|
429 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
430 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
|
431 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
|
432 return -1; |
2222 | 433 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
|
434 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
|
435 *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
|
436 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
|
437 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
438 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
439 /* 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
|
440 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
|
441 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
442 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
|
443 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
|
444 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
|
445 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
446 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
|
447 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
|
448 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
|
449 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
|
450 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
|
451 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
|
452 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
|
453 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
|
454 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
|
455 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
|
456 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
|
457 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
|
458 *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
|
459 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
|
460 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
461 |
885 | 462 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
|
463 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
|
464 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
465 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
|
466 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
467 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
|
468 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
|
469 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
|
470 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
|
471 *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
|
472 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
|
473 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
|
474 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
|
475 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
|
476 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
|
477 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
|
478 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
|
479 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
|
480 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
|
481 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
|
482 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
|
483 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
|
484 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
|
485 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
|
486 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
|
487 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
|
488 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
|
489 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
490 |
4980
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
491 typedef struct { |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
492 uint32_t stream_type; |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
493 enum CodecType codec_type; |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
494 enum CodecID codec_id; |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
495 } StreamType; |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
496 |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
497 static const StreamType ISO_types[] = { |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
498 { 0x01, CODEC_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
499 { 0x02, CODEC_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
500 { 0x03, CODEC_TYPE_AUDIO, CODEC_ID_MP3 }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
501 { 0x04, CODEC_TYPE_AUDIO, CODEC_ID_MP3 }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
502 { 0x0f, CODEC_TYPE_AUDIO, CODEC_ID_AAC }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
503 { 0x10, CODEC_TYPE_VIDEO, CODEC_ID_MPEG4 }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
504 { 0x1b, CODEC_TYPE_VIDEO, CODEC_ID_H264 }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
505 { 0xd1, CODEC_TYPE_VIDEO, CODEC_ID_DIRAC }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
506 { 0xea, CODEC_TYPE_VIDEO, CODEC_ID_VC1 }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
507 { 0 }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
508 }; |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
509 |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
510 static const StreamType HDMV_types[] = { |
5150 | 511 { 0x80, CODEC_TYPE_AUDIO, CODEC_ID_PCM_BLURAY }, |
4980
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
512 { 0x81, CODEC_TYPE_AUDIO, CODEC_ID_AC3 }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
513 { 0x82, CODEC_TYPE_AUDIO, CODEC_ID_DTS }, |
5262
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
514 { 0x83, CODEC_TYPE_AUDIO, CODEC_ID_TRUEHD }, |
5271
9a5be9006cf7
Allow demuxing of E-AC3 (stream type 0x84) in MPEG-TS.
cehoyos
parents:
5262
diff
changeset
|
515 { 0x84, CODEC_TYPE_AUDIO, CODEC_ID_EAC3 }, |
5145 | 516 { 0x90, CODEC_TYPE_SUBTITLE, CODEC_ID_HDMV_PGS_SUBTITLE }, |
4980
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
517 { 0 }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
518 }; |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
519 |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
520 /* ATSC ? */ |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
521 static const StreamType MISC_types[] = { |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
522 { 0x81, CODEC_TYPE_AUDIO, CODEC_ID_AC3 }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
523 { 0x8a, CODEC_TYPE_AUDIO, CODEC_ID_DTS }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
524 { 0 }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
525 }; |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
526 |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
527 static const StreamType REGD_types[] = { |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
528 { MKTAG('d','r','a','c'), CODEC_TYPE_VIDEO, CODEC_ID_DIRAC }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
529 { MKTAG('A','C','-','3'), CODEC_TYPE_AUDIO, CODEC_ID_AC3 }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
530 { 0 }, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
531 }; |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
532 |
4982 | 533 /* descriptor present */ |
534 static const StreamType DESC_types[] = { | |
535 { 0x6a, CODEC_TYPE_AUDIO, CODEC_ID_AC3 }, /* AC-3 descriptor */ | |
4991 | 536 { 0x7a, CODEC_TYPE_AUDIO, CODEC_ID_EAC3 }, /* E-AC-3 descriptor */ |
4982 | 537 { 0x7b, CODEC_TYPE_AUDIO, CODEC_ID_DTS }, |
538 { 0x59, CODEC_TYPE_SUBTITLE, CODEC_ID_DVB_SUBTITLE }, /* subtitling descriptor */ | |
5048
d44e963aaf1c
add 0-termination in table, patch by Wolfram Gloger, wmglo at dent dot med dot uni-muenchen dot de
bcoudurier
parents:
5000
diff
changeset
|
539 { 0 }, |
4982 | 540 }; |
541 | |
4980
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
542 static void mpegts_find_stream_type(AVStream *st, |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
543 uint32_t stream_type, const StreamType *types) |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
544 { |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
545 for (; types->stream_type; types++) { |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
546 if (stream_type == types->stream_type) { |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
547 st->codec->codec_type = types->codec_type; |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
548 st->codec->codec_id = types->codec_id; |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
549 return; |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
550 } |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
551 } |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
552 } |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
553 |
4986
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
554 static AVStream *new_pes_av_stream(PESContext *pes, uint32_t prog_reg_desc, uint32_t code) |
4980
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
555 { |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
556 AVStream *st = av_new_stream(pes->stream, pes->pid); |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
557 |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
558 if (!st) |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
559 return NULL; |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
560 |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
561 av_set_pts_info(st, 33, 1, 90000); |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
562 st->priv_data = pes; |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
563 st->codec->codec_type = CODEC_TYPE_DATA; |
5070
11e86c7bdc25
Only set CODEC_ID_PROBE when a packet from a stream having a PES header
bcoudurier
parents:
5048
diff
changeset
|
564 st->codec->codec_id = CODEC_ID_NONE; |
4980
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
565 st->need_parsing = AVSTREAM_PARSE_FULL; |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
566 pes->st = st; |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
567 |
4981 | 568 dprintf(pes->stream, "stream_type=%x pid=%x prog_reg_desc=%.4s\n", |
569 pes->stream_type, pes->pid, (char*)&prog_reg_desc); | |
4980
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
570 |
4988
ba58d4eaca58
set codec_tag to stream type, so user can deal with it
bcoudurier
parents:
4987
diff
changeset
|
571 st->codec->codec_tag = pes->stream_type; |
ba58d4eaca58
set codec_tag to stream type, so user can deal with it
bcoudurier
parents:
4987
diff
changeset
|
572 |
4984 | 573 mpegts_find_stream_type(st, pes->stream_type, ISO_types); |
574 if (prog_reg_desc == AV_RL32("HDMV") && | |
5262
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
575 st->codec->codec_id == CODEC_ID_NONE) { |
4984 | 576 mpegts_find_stream_type(st, pes->stream_type, HDMV_types); |
5262
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
577 if (pes->stream_type == 0x83) { |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
578 // HDMV TrueHD streams also contain an AC3 coded version of the |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
579 // audio track - add a second stream for this |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
580 AVStream *sub_st; |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
581 // priv_data cannot be shared between streams |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
582 PESContext *sub_pes = av_malloc(sizeof(*sub_pes)); |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
583 if (!sub_pes) |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
584 return NULL; |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
585 memcpy(sub_pes, pes, sizeof(*sub_pes)); |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
586 |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
587 sub_st = av_new_stream(pes->stream, pes->pid); |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
588 if (!sub_st) { |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
589 av_free(sub_pes); |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
590 return NULL; |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
591 } |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
592 |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
593 av_set_pts_info(sub_st, 33, 1, 90000); |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
594 sub_st->priv_data = sub_pes; |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
595 sub_st->codec->codec_type = CODEC_TYPE_AUDIO; |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
596 sub_st->codec->codec_id = CODEC_ID_AC3; |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
597 sub_st->need_parsing = AVSTREAM_PARSE_FULL; |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
598 sub_pes->sub_st = pes->sub_st = sub_st; |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
599 } |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
600 } |
5070
11e86c7bdc25
Only set CODEC_ID_PROBE when a packet from a stream having a PES header
bcoudurier
parents:
5048
diff
changeset
|
601 if (st->codec->codec_id == CODEC_ID_NONE) |
4984 | 602 mpegts_find_stream_type(st, pes->stream_type, MISC_types); |
4980
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
603 |
4986
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
604 /* stream was not present in PMT, guess based on PES start code */ |
5070
11e86c7bdc25
Only set CODEC_ID_PROBE when a packet from a stream having a PES header
bcoudurier
parents:
5048
diff
changeset
|
605 if (st->codec->codec_id == CODEC_ID_NONE) { |
4986
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
606 if (code >= 0x1c0 && code <= 0x1df) { |
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
607 st->codec->codec_type = CODEC_TYPE_AUDIO; |
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
608 st->codec->codec_id = CODEC_ID_MP2; |
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
609 } else if (code == 0x1bd) { |
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
610 st->codec->codec_type = CODEC_TYPE_AUDIO; |
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
611 st->codec->codec_id = CODEC_ID_AC3; |
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
612 } |
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
613 } |
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
614 |
4980
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
615 return st; |
3f9b378936f2
move new_pes_av_stream to avoid forward declaration
bcoudurier
parents:
4979
diff
changeset
|
616 } |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
617 |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
618 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
|
619 { |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
620 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
|
621 SectionHeader h1, *h = &h1; |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
622 PESContext *pes; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
623 AVStream *st; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
624 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
|
625 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
|
626 int desc_list_len, desc_len, desc_tag; |
4983 | 627 int comp_page, anc_page; |
628 char language[4]; | |
4978 | 629 uint32_t prog_reg_desc = 0; /* registration descriptor */ |
885 | 630 |
4862 | 631 #ifdef DEBUG |
632 dprintf(ts->stream, "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
|
633 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
|
634 #endif |
4862 | 635 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
636 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
|
637 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
|
638 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
|
639 return; |
4862 | 640 |
641 dprintf(ts->stream, "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
|
642 h->id, h->sec_num, h->last_sec_num); |
4862 | 643 |
2134
16cf48c9af53
dont rescan for information on each pid, but rather do it just once by
michael
parents:
2133
diff
changeset
|
644 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
|
645 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
646 |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
647 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
|
648 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
|
649 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
|
650 return; |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
651 add_pid_to_pmt(ts, h->id, pcr_pid); |
4862 | 652 |
653 dprintf(ts->stream, "pcr_pid=0x%x\n", pcr_pid); | |
654 | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
655 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
|
656 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
|
657 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
|
658 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
|
659 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
|
660 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
|
661 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
|
662 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
|
663 //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
|
664 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
|
665 program_info_length -= len + 2; |
4979 | 666 if(tag == 0x05 && len >= 4) { // registration descriptor |
4978 | 667 prog_reg_desc = bytestream_get_le32(&p); |
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
|
668 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
|
669 } |
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
|
670 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
|
671 } |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
672 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
|
673 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
|
674 return; |
5116
c4e22fecdcaa
Stop parsing in read_header only after finding pmt, and
bcoudurier
parents:
5070
diff
changeset
|
675 |
c4e22fecdcaa
Stop parsing in read_header only after finding pmt, and
bcoudurier
parents:
5070
diff
changeset
|
676 // stop parsing after pmt, we found header |
c4e22fecdcaa
Stop parsing in read_header only after finding pmt, and
bcoudurier
parents:
5070
diff
changeset
|
677 if (!ts->stream->nb_streams) |
c4e22fecdcaa
Stop parsing in read_header only after finding pmt, and
bcoudurier
parents:
5070
diff
changeset
|
678 ts->stop_parse = 1; |
c4e22fecdcaa
Stop parsing in read_header only after finding pmt, and
bcoudurier
parents:
5070
diff
changeset
|
679 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
680 for(;;) { |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
681 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
|
682 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
|
683 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
|
684 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
685 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
|
686 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
|
687 break; |
4981 | 688 |
689 /* now create ffmpeg stream */ | |
690 if (ts->pids[pid] && ts->pids[pid]->type == MPEGTS_PES) { | |
691 pes = ts->pids[pid]->u.pes_filter.opaque; | |
692 st = pes->st; | |
693 } else { | |
694 if (ts->pids[pid]) mpegts_close_filter(ts, ts->pids[pid]); //wrongly added sdt filter probably | |
695 pes = add_pes_stream(ts, pid, pcr_pid, stream_type); | |
696 if (pes) | |
4986
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
697 st = new_pes_av_stream(pes, prog_reg_desc, 0); |
4981 | 698 } |
699 | |
700 if (!st) | |
701 return; | |
702 | |
703 add_pid_to_pmt(ts, h->id, pid); | |
704 | |
705 av_program_add_stream_index(ts->stream, h->id, st->index); | |
706 | |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
707 desc_list_len = get16(&p, p_end) & 0xfff; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
708 if (desc_list_len < 0) |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
709 break; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
710 desc_list_end = p + desc_list_len; |
4859
0929b70d4407
Ok, ts demuxer is more complicated than I thought
bcoudurier
parents:
4858
diff
changeset
|
711 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
|
712 break; |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
713 for(;;) { |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
714 desc_tag = get8(&p, desc_list_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
715 if (desc_tag < 0) |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
716 break; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
717 desc_len = get8(&p, desc_list_end); |
4859
0929b70d4407
Ok, ts demuxer is more complicated than I thought
bcoudurier
parents:
4858
diff
changeset
|
718 if (desc_len < 0) |
0929b70d4407
Ok, ts demuxer is more complicated than I thought
bcoudurier
parents:
4858
diff
changeset
|
719 break; |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
720 desc_end = p + desc_len; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
721 if (desc_end > desc_list_end) |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
722 break; |
4862 | 723 |
724 dprintf(ts->stream, "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
|
725 desc_tag, desc_len); |
4862 | 726 |
5070
11e86c7bdc25
Only set CODEC_ID_PROBE when a packet from a stream having a PES header
bcoudurier
parents:
5048
diff
changeset
|
727 if (st->codec->codec_id == CODEC_ID_NONE && |
4982 | 728 stream_type == STREAM_TYPE_PRIVATE_DATA) |
729 mpegts_find_stream_type(st, desc_tag, DESC_types); | |
730 | |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
731 switch(desc_tag) { |
4979 | 732 case 0x59: /* subtitling descriptor */ |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
733 language[0] = get8(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
734 language[1] = get8(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
735 language[2] = get8(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
736 language[3] = 0; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
737 get8(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
738 comp_page = get16(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
739 anc_page = get16(&p, desc_end); |
4981 | 740 st->codec->sub_id = (anc_page << 16) | comp_page; |
741 av_metadata_set(&st->metadata, "language", language); | |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
742 break; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
743 case 0x0a: /* ISO 639 language descriptor */ |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
744 language[0] = get8(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
745 language[1] = get8(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
746 language[2] = get8(&p, desc_end); |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
747 language[3] = 0; |
4981 | 748 av_metadata_set(&st->metadata, "language", language); |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
749 break; |
4979 | 750 case 0x05: /* registration descriptor */ |
4987
62bf51efe6ec
set codec_tag to registration descriptor if present
bcoudurier
parents:
4986
diff
changeset
|
751 st->codec->codec_tag = bytestream_get_le32(&p); |
4995 | 752 dprintf(ts->stream, "reg_desc=%.4s\n", (char*)&st->codec->codec_tag); |
5070
11e86c7bdc25
Only set CODEC_ID_PROBE when a packet from a stream having a PES header
bcoudurier
parents:
5048
diff
changeset
|
753 if (st->codec->codec_id == CODEC_ID_NONE && |
4981 | 754 stream_type == STREAM_TYPE_PRIVATE_DATA) |
4987
62bf51efe6ec
set codec_tag to registration descriptor if present
bcoudurier
parents:
4986
diff
changeset
|
755 mpegts_find_stream_type(st, st->codec->codec_tag, REGD_types); |
4860
d14d1f5f4eb4
simplify registration descriptor parsing with bytestream get functions
bcoudurier
parents:
4859
diff
changeset
|
756 break; |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
757 default: |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
758 break; |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
759 } |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
760 p = desc_end; |
5262
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
761 |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
762 if (prog_reg_desc == AV_RL32("HDMV") && stream_type == 0x83 && pes->sub_st) { |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
763 av_program_add_stream_index(ts->stream, h->id, pes->sub_st->index); |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
764 pes->sub_st->codec->codec_tag = st->codec->codec_tag; |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
765 } |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
766 } |
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
767 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
|
768 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
769 /* all parameters are there */ |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
770 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
|
771 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
772 |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
773 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
|
774 { |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
775 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
|
776 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
|
777 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
|
778 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
|
779 |
4862 | 780 #ifdef DEBUG |
781 dprintf(ts->stream, "PAT:\n"); | |
1908
174083eafc6c
Introduce two new logging functions av_hex_dump_log() and av_pkt_dump_log()
takis
parents:
1787
diff
changeset
|
782 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
|
783 #endif |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
784 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
|
785 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
|
786 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
|
787 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
788 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
|
789 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
790 |
2575
06d31789d338
added structures and code to keep track of pids<->programs mapping: it's needed
nicodvb
parents:
2574
diff
changeset
|
791 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
|
792 for(;;) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
793 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
|
794 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
|
795 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
796 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
|
797 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
|
798 break; |
4862 | 799 |
800 dprintf(ts->stream, "sid=0x%x pid=0x%x\n", sid, pmt_pid); | |
801 | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
802 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
|
803 /* 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
|
804 } else { |
2574
9e51e62f5bdd
replaced custom tracking of programs/services with calls to with av_new_program()
nicodvb
parents:
2555
diff
changeset
|
805 av_new_program(ts->stream, sid); |
2137 | 806 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
|
807 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
|
808 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
|
809 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
|
810 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
811 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
812 } |
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 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
|
815 { |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
816 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
|
817 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
|
818 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
|
819 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
|
820 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
|
821 |
4862 | 822 #ifdef DEBUG |
823 dprintf(ts->stream, "SDT:\n"); | |
1908
174083eafc6c
Introduce two new logging functions av_hex_dump_log() and av_pkt_dump_log()
takis
parents:
1787
diff
changeset
|
824 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
|
825 #endif |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
826 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
827 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
|
828 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
|
829 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
|
830 return; |
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 (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
|
832 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
833 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
|
834 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
|
835 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
836 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
|
837 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
|
838 return; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
839 for(;;) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
840 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
|
841 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
|
842 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
843 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
|
844 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
|
845 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
846 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
|
847 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
|
848 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
849 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
|
850 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
|
851 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
852 for(;;) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
853 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
|
854 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
|
855 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
856 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
|
857 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
|
858 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
|
859 break; |
4862 | 860 |
861 dprintf(ts->stream, "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
|
862 desc_tag, desc_len); |
4862 | 863 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
864 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
|
865 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
|
866 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
|
867 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
|
868 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
869 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
|
870 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
|
871 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
872 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
|
873 if (name) { |
9e51e62f5bdd
replaced custom tracking of programs/services with calls to with av_new_program()
nicodvb
parents:
2555
diff
changeset
|
874 AVProgram *program = av_new_program(ts->stream, sid); |
4427 | 875 if(program) { |
876 av_metadata_set(&program->metadata, "name", name); | |
877 av_metadata_set(&program->metadata, "provider_name", provider_name); | |
878 } | |
2574
9e51e62f5bdd
replaced custom tracking of programs/services with calls to with av_new_program()
nicodvb
parents:
2555
diff
changeset
|
879 } |
3247 | 880 av_free(name); |
881 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
|
882 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
883 default: |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
884 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
885 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
886 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
|
887 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
888 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
|
889 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
890 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
891 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
892 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
|
893 { |
2222 | 894 int64_t pts = (int64_t)((p[0] >> 1) & 0x07) << 30; |
895 pts |= (AV_RB16(p + 1) >> 1) << 15; | |
896 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
|
897 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
|
898 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
899 |
4963 | 900 static void new_pes_packet(PESContext *pes, AVPacket *pkt) |
901 { | |
902 av_init_packet(pkt); | |
903 | |
904 pkt->destruct = av_destruct_packet; | |
905 pkt->data = pes->buffer; | |
906 pkt->size = pes->data_index; | |
907 memset(pkt->data+pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE); | |
908 | |
5262
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
909 // Separate out the AC3 substream from an HDMV combined TrueHD/AC3 PID |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
910 if (pes->sub_st && pes->stream_type == 0x83 && pes->extended_stream_id == 0x76) |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
911 pkt->stream_index = pes->sub_st->index; |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
912 else |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
913 pkt->stream_index = pes->st->index; |
4963 | 914 pkt->pts = pes->pts; |
915 pkt->dts = pes->dts; | |
916 /* store position of first TS packet of this PES packet */ | |
917 pkt->pos = pes->ts_packet_pos; | |
918 | |
919 /* reset pts values */ | |
920 pes->pts = AV_NOPTS_VALUE; | |
921 pes->dts = AV_NOPTS_VALUE; | |
922 pes->buffer = NULL; | |
923 pes->data_index = 0; | |
924 } | |
925 | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
926 /* return non zero if a packet could be constructed */ |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
927 static int mpegts_push_data(MpegTSFilter *filter, |
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
928 const uint8_t *buf, int buf_size, int is_start, |
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
929 int64_t pos) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
930 { |
2132
c8e642dd5f9c
passing MpegTSFilter to the filters instead of a random void *opaque
michael
parents:
2129
diff
changeset
|
931 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
|
932 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
|
933 const uint8_t *p; |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
934 int len, code; |
885 | 935 |
2111
4aafc6050f39
kill completely idiotic code which hides all but 2 streams
michael
parents:
2110
diff
changeset
|
936 if(!ts->pkt) |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
937 return 0; |
2111
4aafc6050f39
kill completely idiotic code which hides all but 2 streams
michael
parents:
2110
diff
changeset
|
938 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
939 if (is_start) { |
4963 | 940 if (pes->state == MPEGTS_PAYLOAD && pes->data_index > 0) { |
941 new_pes_packet(pes, ts->pkt); | |
942 ts->stop_parse = 1; | |
943 } | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
944 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
|
945 pes->data_index = 0; |
4615
12a7cd9178dd
Change TS seeking so it returns position/timestamp of a key frame.
cehoyos
parents:
4427
diff
changeset
|
946 pes->ts_packet_pos = pos; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
947 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
948 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
|
949 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
|
950 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
|
951 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
|
952 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
|
953 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
|
954 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
|
955 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
|
956 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
|
957 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
|
958 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
|
959 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
|
960 /* 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
|
961 decide */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
962 #if 0 |
1908
174083eafc6c
Introduce two new logging functions av_hex_dump_log() and av_pkt_dump_log()
takis
parents:
1787
diff
changeset
|
963 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
|
964 #endif |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
965 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
|
966 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
|
967 /* 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
|
968 code = pes->header[3] | 0x100; |
4998 | 969 dprintf(pes->stream, "pid=%x pes_code=%#x\n", pes->pid, code); |
970 | |
4999 | 971 if ((!pes->st && pes->stream->nb_streams == MAX_STREAMS) || |
972 (pes->st && pes->st->discard == AVDISCARD_ALL) || | |
4998 | 973 code == 0x1be) /* padding_stream */ |
974 goto skip; | |
4986
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
975 |
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
976 /* stream not present in PMT */ |
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
977 if (!pes->st) |
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
978 pes->st = new_pes_av_stream(pes, 0, code); |
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
979 if (!pes->st) |
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
980 return AVERROR(ENOMEM); |
b9c3d05b3267
add streams even if they are not present in PMT, fix #1092 and #835
bcoudurier
parents:
4985
diff
changeset
|
981 |
2222 | 982 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
|
983 /* 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
|
984 unbounded */ |
4998 | 985 if (!pes->total_size) |
986 pes->total_size = MAX_PES_PAYLOAD; | |
987 | |
988 /* allocate pes buffer */ | |
989 pes->buffer = av_malloc(pes->total_size+FF_INPUT_BUFFER_PADDING_SIZE); | |
990 if (!pes->buffer) | |
991 return AVERROR(ENOMEM); | |
992 | |
993 if (code != 0x1bc && code != 0x1bf && /* program_stream_map, private_stream_2 */ | |
994 code != 0x1f0 && code != 0x1f1 && /* ECM, EMM */ | |
995 code != 0x1ff && code != 0x1f2 && /* program_stream_directory, DSMCC_stream */ | |
996 code != 0x1f8) { /* ITU-T Rec. H.222.1 type E stream */ | |
5000 | 997 pes->state = MPEGTS_PESHEADER; |
5070
11e86c7bdc25
Only set CODEC_ID_PROBE when a packet from a stream having a PES header
bcoudurier
parents:
5048
diff
changeset
|
998 if (pes->st->codec->codec_id == CODEC_ID_NONE) { |
11e86c7bdc25
Only set CODEC_ID_PROBE when a packet from a stream having a PES header
bcoudurier
parents:
5048
diff
changeset
|
999 dprintf(pes->stream, "pid=%x stream_type=%x probing\n", |
11e86c7bdc25
Only set CODEC_ID_PROBE when a packet from a stream having a PES header
bcoudurier
parents:
5048
diff
changeset
|
1000 pes->pid, pes->stream_type); |
11e86c7bdc25
Only set CODEC_ID_PROBE when a packet from a stream having a PES header
bcoudurier
parents:
5048
diff
changeset
|
1001 pes->st->codec->codec_id = CODEC_ID_PROBE; |
11e86c7bdc25
Only set CODEC_ID_PROBE when a packet from a stream having a PES header
bcoudurier
parents:
5048
diff
changeset
|
1002 } |
4998 | 1003 } else { |
1004 pes->state = MPEGTS_PAYLOAD; | |
1005 pes->data_index = 0; | |
1006 } | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1007 } else { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1008 /* 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
|
1009 /* 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
|
1010 skip: |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1011 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
|
1012 continue; |
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 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1015 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1016 /**********************************************/ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1017 /* PES packing parsing */ |
5000 | 1018 case MPEGTS_PESHEADER: |
1019 len = PES_HEADER_SIZE - pes->data_index; | |
1020 if (len < 0) | |
1021 return -1; | |
1022 if (len > buf_size) | |
1023 len = buf_size; | |
1024 memcpy(pes->header + pes->data_index, p, len); | |
1025 pes->data_index += len; | |
1026 p += len; | |
1027 buf_size -= len; | |
1028 if (pes->data_index == PES_HEADER_SIZE) { | |
1029 pes->pes_header_size = pes->header[8] + 9; | |
1030 pes->state = MPEGTS_PESHEADER_FILL; | |
1031 } | |
1032 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
|
1033 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
|
1034 len = pes->pes_header_size - pes->data_index; |
4964 | 1035 if (len < 0) |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1036 return -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
|
1037 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
|
1038 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
|
1039 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
|
1040 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
|
1041 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
|
1042 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
|
1043 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
|
1044 const uint8_t *r; |
5262
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
1045 unsigned int flags, pes_ext, skip; |
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 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1047 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
|
1048 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
|
1049 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
|
1050 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
|
1051 if ((flags & 0xc0) == 0x80) { |
4280
99d0dac39813
set pts and dts when only pts is present, according to specs
bcoudurier
parents:
4251
diff
changeset
|
1052 pes->dts = pes->pts = get_pts(r); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1053 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
|
1054 } 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
|
1055 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
|
1056 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
|
1057 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
|
1058 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
|
1059 } |
5262
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
1060 pes->extended_stream_id = -1; |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
1061 if (flags & 0x01) { /* PES extension */ |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
1062 pes_ext = *r++; |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
1063 /* Skip PES private data, program packet sequence counter and P-STD buffer */ |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
1064 skip = (pes_ext >> 4) & 0xb; |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
1065 skip += skip & 0x9; |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
1066 r += skip; |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
1067 if ((pes_ext & 0x41) == 0x01 && |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
1068 (r + 2) <= (pes->header + pes->pes_header_size)) { |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
1069 /* PES extension 2 */ |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
1070 if ((r[0] & 0x7f) > 0 && (r[1] & 0x80) == 0) |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
1071 pes->extended_stream_id = r[1]; |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
1072 } |
a2289abc9e23
Allow the combined TrueHD/AC3 tracks on Blu-Ray discs to be demuxed as two separate streams.
cehoyos
parents:
5175
diff
changeset
|
1073 } |
4963 | 1074 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1075 /* 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
|
1076 pes->state = MPEGTS_PAYLOAD; |
4963 | 1077 pes->data_index = 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
|
1078 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1079 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1080 case MPEGTS_PAYLOAD: |
5175 | 1081 if (buf_size > 0 && pes->buffer) { |
4963 | 1082 if (pes->data_index+buf_size > pes->total_size) { |
1083 new_pes_packet(pes, ts->pkt); | |
1084 pes->total_size = MAX_PES_PAYLOAD; | |
1085 pes->buffer = av_malloc(pes->total_size+FF_INPUT_BUFFER_PADDING_SIZE); | |
1086 if (!pes->buffer) | |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1087 return AVERROR(ENOMEM); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1088 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
|
1089 } |
4963 | 1090 memcpy(pes->buffer+pes->data_index, p, buf_size); |
1091 pes->data_index += buf_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
|
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 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
|
1094 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1095 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
|
1096 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
|
1097 break; |
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 } |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1100 |
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1101 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
|
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 |
2157
0103a8479df5
proper per stream pcr_pid support by (Wolfram Gloger wmglo dent.med.uni-muenchen@de )
michael
parents:
2146
diff
changeset
|
1104 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
|
1105 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1106 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
|
1107 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
|
1108 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1109 /* 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
|
1110 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
|
1111 if (!pes) |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
1112 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
|
1113 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
|
1114 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
|
1115 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
|
1116 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
|
1117 pes->stream_type = stream_type; |
4997 | 1118 pes->state = MPEGTS_SKIP; |
5121
84b8032a5227
init pes dts and pts to AV_NOPTS_VALUE, fix issue #1297
bcoudurier
parents:
5116
diff
changeset
|
1119 pes->pts = AV_NOPTS_VALUE; |
84b8032a5227
init pes dts and pts to AV_NOPTS_VALUE, fix issue #1297
bcoudurier
parents:
5116
diff
changeset
|
1120 pes->dts = AV_NOPTS_VALUE; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1121 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
|
1122 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
|
1123 av_free(pes); |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
1124 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
|
1125 } |
819
a6c035e7f429
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
775
diff
changeset
|
1126 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
|
1127 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1128 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1129 /* handle one TS packet */ |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1130 static int 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
|
1131 { |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1132 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
|
1133 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
|
1134 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
|
1135 const uint8_t *p, *p_end; |
4615
12a7cd9178dd
Change TS seeking so it returns position/timestamp of a key frame.
cehoyos
parents:
4427
diff
changeset
|
1136 int64_t pos; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1137 |
2222 | 1138 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
|
1139 if(pid && discard_pid(ts, pid)) |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1140 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
|
1141 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
|
1142 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
|
1143 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
|
1144 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
|
1145 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
|
1146 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1147 if (!tss) |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1148 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
|
1149 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1150 /* 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
|
1151 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
|
1152 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
|
1153 tss->last_cc = cc; |
885 | 1154 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1155 /* 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
|
1156 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
|
1157 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
|
1158 if (afc == 0) /* reserved value */ |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1159 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
|
1160 if (afc == 2) /* adaptation field only */ |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1161 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
|
1162 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
|
1163 /* 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
|
1164 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
|
1165 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1166 /* 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
|
1167 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
|
1168 if (p >= p_end) |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1169 return 0; |
885 | 1170 |
4615
12a7cd9178dd
Change TS seeking so it returns position/timestamp of a key frame.
cehoyos
parents:
4427
diff
changeset
|
1171 pos = url_ftell(ts->stream->pb); |
12a7cd9178dd
Change TS seeking so it returns position/timestamp of a key frame.
cehoyos
parents:
4427
diff
changeset
|
1172 ts->pos47= pos % ts->raw_packet_size; |
3240
78153a85dccc
Ensure that the timestamp reading code used for seeking chooses a position
michael
parents:
3226
diff
changeset
|
1173 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1174 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
|
1175 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
|
1176 /* 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
|
1177 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
|
1178 if (p + len > p_end) |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1179 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
|
1180 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
|
1181 /* write remaining section bytes */ |
885 | 1182 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
|
1183 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
|
1184 /* 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
|
1185 if (!ts->pids[pid]) |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1186 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
|
1187 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1188 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
|
1189 if (p < p_end) { |
885 | 1190 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
|
1191 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
|
1192 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1193 } else { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1194 if (cc_ok) { |
885 | 1195 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
|
1196 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
|
1197 } |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1198 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1199 } else { |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1200 int ret; |
4615
12a7cd9178dd
Change TS seeking so it returns position/timestamp of a key frame.
cehoyos
parents:
4427
diff
changeset
|
1201 // Note: The position here points actually behind the current packet. |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1202 if ((ret = tss->u.pes_filter.pes_cb(tss, p, p_end - p, is_start, |
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1203 pos - ts->raw_packet_size)) < 0) |
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1204 return 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
|
1205 } |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1206 |
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1207 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
|
1208 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1209 |
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
|
1210 /* 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
|
1211 get_packet_size() ?) */ |
5303
03d4d6534554
Increase max resync size, fix demuxing of dvgrab-2009.03.28_19-07-22.m2t
bcoudurier
parents:
5271
diff
changeset
|
1212 static int mpegts_resync(AVFormatContext *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
|
1213 { |
5303
03d4d6534554
Increase max resync size, fix demuxing of dvgrab-2009.03.28_19-07-22.m2t
bcoudurier
parents:
5271
diff
changeset
|
1214 ByteIOContext *pb = s->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
|
1215 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
|
1216 |
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
|
1217 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
|
1218 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
|
1219 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
|
1220 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
|
1221 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
|
1222 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
|
1223 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
|
1224 } |
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
|
1225 } |
5303
03d4d6534554
Increase max resync size, fix demuxing of dvgrab-2009.03.28_19-07-22.m2t
bcoudurier
parents:
5271
diff
changeset
|
1226 av_log(s, AV_LOG_ERROR, "max resync size reached, could not find sync byte\n"); |
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
|
1227 /* 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
|
1228 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
|
1229 } |
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
|
1230 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1231 /* return -1 if error or EOF. Return 0 if OK. */ |
5303
03d4d6534554
Increase max resync size, fix demuxing of dvgrab-2009.03.28_19-07-22.m2t
bcoudurier
parents:
5271
diff
changeset
|
1232 static int read_packet(AVFormatContext *s, 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
|
1233 { |
5303
03d4d6534554
Increase max resync size, fix demuxing of dvgrab-2009.03.28_19-07-22.m2t
bcoudurier
parents:
5271
diff
changeset
|
1234 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
|
1235 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
|
1236 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1237 for(;;) { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1238 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
|
1239 if (len != TS_PACKET_SIZE) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2247
diff
changeset
|
1240 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
|
1241 /* 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
|
1242 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
|
1243 /* 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
|
1244 url_fseek(pb, -TS_PACKET_SIZE, SEEK_CUR); |
5303
03d4d6534554
Increase max resync size, fix demuxing of dvgrab-2009.03.28_19-07-22.m2t
bcoudurier
parents:
5271
diff
changeset
|
1245 if (mpegts_resync(s) < 0) |
03d4d6534554
Increase max resync size, fix demuxing of dvgrab-2009.03.28_19-07-22.m2t
bcoudurier
parents:
5271
diff
changeset
|
1246 return AVERROR(EAGAIN); |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1247 else |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1248 continue; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1249 } else { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1250 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
|
1251 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
|
1252 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
|
1253 break; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1254 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1255 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1256 return 0; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1257 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1258 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1259 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
|
1260 { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1261 AVFormatContext *s = ts->stream; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1262 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
|
1263 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
|
1264 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1265 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
|
1266 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
|
1267 for(;;) { |
2134
16cf48c9af53
dont rescan for information on each pid, but rather do it just once by
michael
parents:
2133
diff
changeset
|
1268 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
|
1269 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1270 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
|
1271 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
|
1272 break; |
5303
03d4d6534554
Increase max resync size, fix demuxing of dvgrab-2009.03.28_19-07-22.m2t
bcoudurier
parents:
5271
diff
changeset
|
1273 ret = read_packet(s, 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
|
1274 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
|
1275 return ret; |
4966
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1276 ret = handle_packet(ts, packet); |
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1277 if (ret != 0) |
a6c807c154b1
return error in mpegts_push_data and propagate it
bcoudurier
parents:
4965
diff
changeset
|
1278 return 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
|
1279 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1280 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
|
1281 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1282 |
0 | 1283 static int mpegts_probe(AVProbeData *p) |
1284 { | |
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
|
1285 #if 1 |
329 | 1286 const int size= p->buf_size; |
891 | 1287 int score, fec_score, dvhs_score; |
4365
85ba93088fb5
Fix probe & demuxing of Topfield 58XXPVR and 68XXPVR (topfield.rec)
michael
parents:
4280
diff
changeset
|
1288 int check_count= size / TS_FEC_PACKET_SIZE; |
329 | 1289 #define CHECK_COUNT 10 |
885 | 1290 |
4365
85ba93088fb5
Fix probe & demuxing of Topfield 58XXPVR and 68XXPVR (topfield.rec)
michael
parents:
4280
diff
changeset
|
1291 if (check_count < CHECK_COUNT) |
329 | 1292 return -1; |
885 | 1293 |
4365
85ba93088fb5
Fix probe & demuxing of Topfield 58XXPVR and 68XXPVR (topfield.rec)
michael
parents:
4280
diff
changeset
|
1294 score = analyze(p->buf, TS_PACKET_SIZE *check_count, TS_PACKET_SIZE , NULL)*CHECK_COUNT/check_count; |
85ba93088fb5
Fix probe & demuxing of Topfield 58XXPVR and 68XXPVR (topfield.rec)
michael
parents:
4280
diff
changeset
|
1295 dvhs_score= analyze(p->buf, TS_DVHS_PACKET_SIZE*check_count, TS_DVHS_PACKET_SIZE, NULL)*CHECK_COUNT/check_count; |
85ba93088fb5
Fix probe & demuxing of Topfield 58XXPVR and 68XXPVR (topfield.rec)
michael
parents:
4280
diff
changeset
|
1296 fec_score = analyze(p->buf, TS_FEC_PACKET_SIZE *check_count, TS_FEC_PACKET_SIZE , NULL)*CHECK_COUNT/check_count; |
891 | 1297 // av_log(NULL, AV_LOG_DEBUG, "score: %d, dvhs_score: %d, fec_score: %d \n", score, dvhs_score, fec_score); |
885 | 1298 |
329 | 1299 // we need a clear definition for the returned score otherwise things will become messy sooner or later |
891 | 1300 if (score > fec_score && score > dvhs_score && score > 6) return AVPROBE_SCORE_MAX + score - CHECK_COUNT; |
1301 else if(dvhs_score > score && dvhs_score > fec_score && dvhs_score > 6) return AVPROBE_SCORE_MAX + dvhs_score - CHECK_COUNT; | |
329 | 1302 else if( fec_score > 6) return AVPROBE_SCORE_MAX + fec_score - CHECK_COUNT; |
1303 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
|
1304 #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
|
1305 /* 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
|
1306 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
|
1307 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
|
1308 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
|
1309 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
|
1310 #endif |
0 | 1311 } |
1312 | |
3968 | 1313 /* 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
|
1314 (-1) if not available */ |
885 | 1315 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
|
1316 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
|
1317 { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1318 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
|
1319 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
|
1320 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
|
1321 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1322 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
|
1323 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
|
1324 return -1; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1325 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
|
1326 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
|
1327 p++; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1328 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
|
1329 return -1; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1330 flags = *p++; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1331 len--; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1332 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
|
1333 return -1; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1334 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
|
1335 return -1; |
2222 | 1336 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
|
1337 *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
|
1338 *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
|
1339 return 0; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1340 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1341 |
0 | 1342 static int mpegts_read_header(AVFormatContext *s, |
1343 AVFormatParameters *ap) | |
1344 { | |
1345 MpegTSContext *ts = s->priv_data; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1346 ByteIOContext *pb = s->pb; |
4365
85ba93088fb5
Fix probe & demuxing of Topfield 58XXPVR and 68XXPVR (topfield.rec)
michael
parents:
4280
diff
changeset
|
1347 uint8_t buf[5*1024]; |
2135 | 1348 int len; |
65 | 1349 int64_t pos; |
474 | 1350 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1351 if (ap) { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1352 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
|
1353 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
|
1354 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
|
1355 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
|
1356 } |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1357 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1358 |
0 | 1359 /* read the first 1024 bytes to get packet size */ |
1360 pos = url_ftell(pb); | |
1361 len = get_buffer(pb, buf, sizeof(buf)); | |
1362 if (len != sizeof(buf)) | |
1363 goto fail; | |
1364 ts->raw_packet_size = get_packet_size(buf, sizeof(buf)); | |
1365 if (ts->raw_packet_size <= 0) | |
1366 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
|
1367 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
|
1368 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
|
1369 |
2108
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1370 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
|
1371 /* 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
|
1372 |
2126 | 1373 /* first do a scaning to get all the services */ |
1374 url_fseek(pb, pos, SEEK_SET); | |
4868 | 1375 |
1376 mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1); | |
2126 | 1377 |
4866 | 1378 mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1); |
885 | 1379 |
5304
ca4d9e153f56
handle_packets takes number of packets as arg, avoid reading too much
bcoudurier
parents:
5303
diff
changeset
|
1380 handle_packets(ts, s->probesize / ts->raw_packet_size); |
2126 | 1381 /* if could not find service, enable auto_guess */ |
885 | 1382 |
2126 | 1383 ts->auto_guess = 1; |
885 | 1384 |
4862 | 1385 dprintf(ts->stream, "tuning done\n"); |
1386 | |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1387 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
|
1388 } else { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1389 AVStream *st; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1390 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
|
1391 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
|
1392 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
|
1393 uint8_t packet[TS_PACKET_SIZE]; |
885 | 1394 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1395 /* only read packets */ |
885 | 1396 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1397 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
|
1398 if (!st) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1399 goto fail; |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
444
diff
changeset
|
1400 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
|
1401 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
|
1402 st->codec->codec_id = CODEC_ID_MPEG2TS; |
885 | 1403 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1404 /* 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
|
1405 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
|
1406 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
|
1407 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
|
1408 for(;;) { |
5303
03d4d6534554
Increase max resync size, fix demuxing of dvgrab-2009.03.28_19-07-22.m2t
bcoudurier
parents:
5271
diff
changeset
|
1409 ret = read_packet(s, 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
|
1410 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
|
1411 return -1; |
2222 | 1412 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
|
1413 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
|
1414 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
|
1415 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
|
1416 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
|
1417 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
|
1418 nb_pcrs++; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1419 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
|
1420 break; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1421 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1422 nb_packets++; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1423 } |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1424 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1425 /* 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
|
1426 /* 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
|
1427 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
|
1428 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
|
1429 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
|
1430 st->codec->bit_rate = s->bit_rate; |
743 | 1431 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
|
1432 #if 0 |
1748 | 1433 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
|
1434 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
|
1435 #endif |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1436 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
107
diff
changeset
|
1437 |
0 | 1438 url_fseek(pb, pos, SEEK_SET); |
1439 return 0; | |
1440 fail: | |
1441 return -1; | |
1442 } | |
1443 | |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1444 #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
|
1445 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1446 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
|
1447 AVPacket *pkt) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1448 { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1449 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
|
1450 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
|
1451 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
|
1452 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
|
1453 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
|
1454 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1455 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
|
1456 return AVERROR(ENOMEM); |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1457 pkt->pos= url_ftell(s->pb); |
5303
03d4d6534554
Increase max resync size, fix demuxing of dvgrab-2009.03.28_19-07-22.m2t
bcoudurier
parents:
5271
diff
changeset
|
1458 ret = read_packet(s, 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
|
1459 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
|
1460 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
|
1461 return ret; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1462 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1463 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
|
1464 /* 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
|
1465 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
|
1466 /* 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
|
1467 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
|
1468 for(i = 0; i < MAX_PACKET_READAHEAD; i++) { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1469 url_fseek(s->pb, pos + i * ts->raw_packet_size, SEEK_SET); |
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1470 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
|
1471 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
|
1472 /* XXX: not precise enough */ |
885 | 1473 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
|
1474 (i + 1); |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1475 break; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1476 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1477 } |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1478 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
|
1479 /* 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
|
1480 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
|
1481 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1482 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
|
1483 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
|
1484 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
|
1485 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1486 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
|
1487 return 0; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1488 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1489 |
0 | 1490 static int mpegts_read_packet(AVFormatContext *s, |
1491 AVPacket *pkt) | |
1492 { | |
1493 MpegTSContext *ts = s->priv_data; | |
4963 | 1494 int ret, i; |
1495 | |
1496 if (url_ftell(s->pb) != ts->last_pos) { | |
1497 /* seek detected, flush pes buffer */ | |
1498 for (i = 0; i < NB_PID_MAX; i++) { | |
1499 if (ts->pids[i] && ts->pids[i]->type == MPEGTS_PES) { | |
1500 PESContext *pes = ts->pids[i]->u.pes_filter.opaque; | |
1501 av_freep(&pes->buffer); | |
1502 pes->data_index = 0; | |
1503 pes->state = MPEGTS_SKIP; /* skip until pes header */ | |
1504 } | |
1505 } | |
1506 } | |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1507 |
2108
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1508 ts->pkt = pkt; |
4963 | 1509 ret = handle_packets(ts, 0); |
1510 if (ret < 0) { | |
1511 /* flush pes data left */ | |
1512 for (i = 0; i < NB_PID_MAX; i++) { | |
1513 if (ts->pids[i] && ts->pids[i]->type == MPEGTS_PES) { | |
1514 PESContext *pes = ts->pids[i]->u.pes_filter.opaque; | |
1515 if (pes->state == MPEGTS_PAYLOAD && pes->data_index > 0) { | |
1516 new_pes_packet(pes, pkt); | |
5174
664c0b8ae082
reset pes state to skip after flushing, avoid segv with dvgrab-2009.03.28_19-07-22.m2t
bcoudurier
parents:
5162
diff
changeset
|
1517 pes->state = MPEGTS_SKIP; |
4963 | 1518 ret = 0; |
1519 break; | |
1520 } | |
1521 } | |
1522 } | |
1523 } | |
1524 | |
1525 ts->last_pos = url_ftell(s->pb); | |
1526 | |
1527 return ret; | |
0 | 1528 } |
1529 | |
1530 static int mpegts_read_close(AVFormatContext *s) | |
1531 { | |
1532 MpegTSContext *ts = s->priv_data; | |
1533 int i; | |
3247 | 1534 |
1535 clear_programs(ts); | |
1536 | |
0 | 1537 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
|
1538 if (ts->pids[i]) mpegts_close_filter(ts, ts->pids[i]); |
1046 | 1539 |
0 | 1540 return 0; |
1541 } | |
1542 | |
885 | 1543 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
|
1544 int64_t *ppos, int64_t pos_limit) |
310 | 1545 { |
1546 MpegTSContext *ts = s->priv_data; | |
1547 int64_t pos, timestamp; | |
1548 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
|
1549 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
|
1550 const int find_next= 1; |
3240
78153a85dccc
Ensure that the timestamp reading code used for seeking chooses a position
michael
parents:
3226
diff
changeset
|
1551 pos = ((*ppos + ts->raw_packet_size - 1 - ts->pos47) / ts->raw_packet_size) * ts->raw_packet_size + ts->pos47; |
310 | 1552 if (find_next) { |
1553 for(;;) { | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1554 url_fseek(s->pb, pos, SEEK_SET); |
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1555 if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) |
310 | 1556 return AV_NOPTS_VALUE; |
2222 | 1557 if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) && |
310 | 1558 parse_pcr(×tamp, &pcr_l, buf) == 0) { |
1559 break; | |
1560 } | |
1561 pos += ts->raw_packet_size; | |
1562 } | |
1563 } else { | |
1564 for(;;) { | |
1565 pos -= ts->raw_packet_size; | |
1566 if (pos < 0) | |
1567 return AV_NOPTS_VALUE; | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1568 url_fseek(s->pb, pos, SEEK_SET); |
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2761
diff
changeset
|
1569 if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) |
310 | 1570 return AV_NOPTS_VALUE; |
2222 | 1571 if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) && |
310 | 1572 parse_pcr(×tamp, &pcr_l, buf) == 0) { |
1573 break; | |
1574 } | |
1575 } | |
1576 } | |
1577 *ppos = pos; | |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1578 |
310 | 1579 return timestamp; |
1580 } | |
1581 | |
5162
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1582 #ifdef USE_SYNCPOINT_SEARCH |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1583 |
5151 | 1584 static int read_seek2(AVFormatContext *s, |
1585 int stream_index, | |
1586 int64_t min_ts, | |
1587 int64_t target_ts, | |
1588 int64_t max_ts, | |
1589 int flags) | |
5140
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1590 { |
474 | 1591 int64_t pos; |
1592 | |
5140
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1593 int64_t ts_ret, ts_adj; |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1594 int stream_index_gen_search; |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1595 AVStream *st; |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1596 AVParserState *backup; |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1597 |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1598 backup = ff_store_parser_state(s); |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1599 |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1600 // detect direction of seeking for search purposes |
5151 | 1601 flags |= (target_ts - min_ts > (uint64_t)(max_ts - target_ts)) ? |
1602 AVSEEK_FLAG_BACKWARD : 0; | |
474 | 1603 |
5140
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1604 if (flags & AVSEEK_FLAG_BYTE) { |
5151 | 1605 // use position directly, we will search starting from it |
5140
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1606 pos = target_ts; |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1607 } else { |
5151 | 1608 // search for some position with good timestamp match |
1609 if (stream_index < 0) { | |
5140
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1610 stream_index_gen_search = av_find_default_stream_index(s); |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1611 if (stream_index_gen_search < 0) { |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1612 ff_restore_parser_state(s, backup); |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1613 return -1; |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1614 } |
474 | 1615 |
5140
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1616 st = s->streams[stream_index_gen_search]; |
5151 | 1617 // timestamp for default must be expressed in AV_TIME_BASE units |
1618 ts_adj = av_rescale(target_ts, | |
1619 st->time_base.den, | |
1620 AV_TIME_BASE * (int64_t)st->time_base.num); | |
5140
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1621 } else { |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1622 ts_adj = target_ts; |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1623 stream_index_gen_search = stream_index; |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1624 } |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1625 pos = av_gen_search(s, stream_index_gen_search, ts_adj, |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1626 0, INT64_MAX, -1, |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1627 AV_NOPTS_VALUE, |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1628 AV_NOPTS_VALUE, |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1629 flags, &ts_ret, mpegts_get_pcr); |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1630 if (pos < 0) { |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1631 ff_restore_parser_state(s, backup); |
474 | 1632 return -1; |
5140
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1633 } |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1634 } |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1635 |
5151 | 1636 // search for actual matching keyframe/starting position for all streams |
1637 if (ff_gen_syncpoint_search(s, stream_index, pos, | |
1638 min_ts, target_ts, max_ts, | |
1639 flags) < 0) { | |
5140
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1640 ff_restore_parser_state(s, backup); |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1641 return -1; |
885 | 1642 } |
5140
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1643 |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1644 ff_free_parser_state(s, backup); |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1645 return 0; |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1646 } |
474 | 1647 |
5140
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1648 static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags) |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1649 { |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1650 int ret; |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1651 if (flags & AVSEEK_FLAG_BACKWARD) { |
5151 | 1652 flags &= ~AVSEEK_FLAG_BACKWARD; |
1653 ret = read_seek2(s, stream_index, INT64_MIN, target_ts, target_ts, flags); | |
1654 if (ret < 0) | |
1655 // for compatibility reasons, seek to the best-fitting timestamp | |
1656 ret = read_seek2(s, stream_index, INT64_MIN, target_ts, INT64_MAX, flags); | |
5140
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1657 } else { |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1658 ret = read_seek2(s, stream_index, target_ts, target_ts, INT64_MAX, flags); |
5151 | 1659 if (ret < 0) |
1660 // for compatibility reasons, seek to the best-fitting timestamp | |
5140
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1661 ret = read_seek2(s, stream_index, INT64_MIN, target_ts, INT64_MAX, flags); |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1662 } |
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1663 return ret; |
474 | 1664 } |
1665 | |
5162
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1666 #else |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1667 |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1668 static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){ |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1669 MpegTSContext *ts = s->priv_data; |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1670 uint8_t buf[TS_PACKET_SIZE]; |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1671 int64_t pos; |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1672 |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1673 if(av_seek_frame_binary(s, stream_index, target_ts, flags) < 0) |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1674 return -1; |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1675 |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1676 pos= url_ftell(s->pb); |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1677 |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1678 for(;;) { |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1679 url_fseek(s->pb, pos, SEEK_SET); |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1680 if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1681 return -1; |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1682 // pid = AV_RB16(buf + 1) & 0x1fff; |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1683 if(buf[1] & 0x40) break; |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1684 pos += ts->raw_packet_size; |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1685 } |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1686 url_fseek(s->pb, pos, SEEK_SET); |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1687 |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1688 return 0; |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1689 } |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1690 |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1691 #endif |
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1692 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1693 /**************************************************************/ |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1694 /* 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
|
1695 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1696 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
|
1697 { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1698 MpegTSContext *ts; |
885 | 1699 |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1700 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
|
1701 if (!ts) |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1702 return NULL; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1703 /* 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
|
1704 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
|
1705 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
|
1706 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
|
1707 return ts; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1708 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1709 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1710 /* 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
|
1711 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
|
1712 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
|
1713 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
|
1714 { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1715 int len1; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1716 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1717 len1 = len; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1718 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
|
1719 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
|
1720 for(;;) { |
2134
16cf48c9af53
dont rescan for information on each pid, but rather do it just once by
michael
parents:
2133
diff
changeset
|
1721 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
|
1722 break; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1723 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
|
1724 return -1; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1725 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
|
1726 buf++; |
292
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1727 len--; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1728 } else { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1729 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
|
1730 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
|
1731 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
|
1732 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1733 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1734 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
|
1735 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1736 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1737 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
|
1738 { |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1739 int i; |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1740 |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1741 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
|
1742 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
|
1743 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
|
1744 } |
155ce13f1033
mpeg TS demux API (called from RTP layer) - raw mpeg TS reader (uses fake codec MPEG2TS)
bellard
parents:
283
diff
changeset
|
1745 |
1167 | 1746 AVInputFormat mpegts_demuxer = { |
0 | 1747 "mpegts", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3286
diff
changeset
|
1748 NULL_IF_CONFIG_SMALL("MPEG-2 transport stream format"), |
0 | 1749 sizeof(MpegTSContext), |
1750 mpegts_probe, | |
1751 mpegts_read_header, | |
1752 mpegts_read_packet, | |
1753 mpegts_read_close, | |
474 | 1754 read_seek, |
463
696f41bc8784
store index for seeking in the native timebase of each stream
michael
parents:
462
diff
changeset
|
1755 mpegts_get_pcr, |
3724
178cc6f9d5ec
Add flag to mark demuxers that can output discontinuous timestamps.
michael
parents:
3716
diff
changeset
|
1756 .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT, |
5162
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1757 #ifdef USE_SYNCPOINT_SEARCH |
5140
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1758 .read_seek2 = read_seek2, |
5162
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1759 #endif |
0 | 1760 }; |
2108
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1761 |
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1762 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
|
1763 "mpegtsraw", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3286
diff
changeset
|
1764 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
|
1765 sizeof(MpegTSContext), |
3226
dcde7da1d183
Using the same probe function in 2 formats is not a good idea.
michael
parents:
3059
diff
changeset
|
1766 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
|
1767 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
|
1768 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
|
1769 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
|
1770 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
|
1771 mpegts_get_pcr, |
3724
178cc6f9d5ec
Add flag to mark demuxers that can output discontinuous timestamps.
michael
parents:
3716
diff
changeset
|
1772 .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT, |
5162
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1773 #ifdef USE_SYNCPOINT_SEARCH |
5140
9c846d0a6803
Use generic multi-stream key frame finding routine to implement read_seek2 and map
schreter
parents:
5121
diff
changeset
|
1774 .read_seek2 = read_seek2, |
5162
68b98b497783
disable new seeking code in mpeg-ts per #ifdef (use old read_seek by default)
schreter
parents:
5151
diff
changeset
|
1775 #endif |
2108
31619b03d1ce
split mpeg2ts_raw mode into its own demuxer using such a flag is an incredibly dirty hack
michael
parents:
2101
diff
changeset
|
1776 }; |