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