annotate mpegts.c @ 5039:d35f30da9724 libavformat

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