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