Mercurial > libavformat.hg
annotate mpegtsenc.c @ 4187:77af10d4d406 libavformat
Reindent to properly fit a 80 chars terminal.
author | rbultje |
---|---|
date | Fri, 09 Jan 2009 23:44:52 +0000 |
parents | 6772cfc78d33 |
children | 7d2f3f1b68d8 |
rev | line source |
---|---|
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
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) muxer |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
3 * Copyright (c) 2003 Fabrice Bellard. |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
4 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
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:
1169
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
16 * |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
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:
1169
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:
887
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
20 */ |
3286 | 21 |
22 #include "libavutil/crc.h" | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
23 #include "avformat.h" |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
24 #include "mpegts.h" |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
25 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
26 /* write DVB SI sections */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
27 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
28 /*********************************************/ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
29 /* mpegts section writer */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
30 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
31 typedef struct MpegTSSection { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
32 int pid; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
33 int cc; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
34 void (*write_packet)(struct MpegTSSection *s, const uint8_t *packet); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
35 void *opaque; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
36 } MpegTSSection; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
37 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
38 /* NOTE: 4 bytes must be left at the end for the crc32 */ |
1124
d3aff2c607f9
Add const to (mostly) char* and make some functions static, which aren't used
diego
parents:
996
diff
changeset
|
39 static void mpegts_write_section(MpegTSSection *s, 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:
diff
changeset
|
40 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
41 unsigned int crc; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
42 unsigned char packet[TS_PACKET_SIZE]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
43 const unsigned char *buf_ptr; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
44 unsigned char *q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
45 int first, b, len1, left; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
46 |
2893 | 47 crc = bswap_32(av_crc(av_crc_get_table(AV_CRC_32_IEEE), -1, buf, len - 4)); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
48 buf[len - 4] = (crc >> 24) & 0xff; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
49 buf[len - 3] = (crc >> 16) & 0xff; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
50 buf[len - 2] = (crc >> 8) & 0xff; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
51 buf[len - 1] = (crc) & 0xff; |
885 | 52 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
53 /* send each packet */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
54 buf_ptr = buf; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
55 while (len > 0) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
56 first = (buf == buf_ptr); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
57 q = packet; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
58 *q++ = 0x47; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
59 b = (s->pid >> 8); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
60 if (first) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
61 b |= 0x40; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
62 *q++ = b; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
63 *q++ = s->pid; |
3419 | 64 *q++ = 0x10 | s->cc; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
65 s->cc = (s->cc + 1) & 0xf; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
66 if (first) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
67 *q++ = 0; /* 0 offset */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
68 len1 = TS_PACKET_SIZE - (q - packet); |
885 | 69 if (len1 > len) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
70 len1 = len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
71 memcpy(q, buf_ptr, len1); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
72 q += len1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
73 /* add known padding data */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
74 left = TS_PACKET_SIZE - (q - packet); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
75 if (left > 0) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
76 memset(q, 0xff, left); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
77 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
78 s->write_packet(s, packet); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
79 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
80 buf_ptr += len1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
81 len -= len1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
82 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
83 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
84 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
85 static inline void put16(uint8_t **q_ptr, int val) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
86 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
87 uint8_t *q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
88 q = *q_ptr; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
89 *q++ = val >> 8; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
90 *q++ = val; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
91 *q_ptr = q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
92 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
93 |
1124
d3aff2c607f9
Add const to (mostly) char* and make some functions static, which aren't used
diego
parents:
996
diff
changeset
|
94 static int mpegts_write_section1(MpegTSSection *s, int tid, int id, |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
95 int version, int sec_num, int last_sec_num, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
96 uint8_t *buf, int len) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
97 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
98 uint8_t section[1024], *q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
99 unsigned int tot_len; |
885 | 100 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
101 tot_len = 3 + 5 + len + 4; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
102 /* check if not too big */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
103 if (tot_len > 1024) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
104 return -1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
105 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
106 q = section; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
107 *q++ = tid; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
108 put16(&q, 0xb000 | (len + 5 + 4)); /* 5 byte header + 4 byte CRC */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
109 put16(&q, id); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
110 *q++ = 0xc1 | (version << 1); /* current_next_indicator = 1 */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
111 *q++ = sec_num; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
112 *q++ = last_sec_num; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
113 memcpy(q, buf, len); |
885 | 114 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
115 mpegts_write_section(s, section, tot_len); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
116 return 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
117 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
118 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
119 /*********************************************/ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
120 /* mpegts writer */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
121 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
122 #define DEFAULT_PMT_START_PID 0x1000 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
123 #define DEFAULT_START_PID 0x0100 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
124 #define DEFAULT_PROVIDER_NAME "FFmpeg" |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
125 #define DEFAULT_SERVICE_NAME "Service01" |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
126 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
127 /* default network id, transport stream and service identifiers */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
128 #define DEFAULT_ONID 0x0001 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
129 #define DEFAULT_TSID 0x0001 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
130 #define DEFAULT_SID 0x0001 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
131 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
132 /* a PES packet header is generated every DEFAULT_PES_HEADER_FREQ packets */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
133 #define DEFAULT_PES_HEADER_FREQ 16 |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
134 #define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
135 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
136 /* we retransmit the SI info at this rate */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
137 #define SDT_RETRANS_TIME 500 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
138 #define PAT_RETRANS_TIME 100 |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
139 #define PCR_RETRANS_TIME 20 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
140 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
141 typedef struct MpegTSWriteStream { |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
142 struct MpegTSService *service; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
143 int pid; /* stream associated pid */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
144 int cc; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
145 int payload_index; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
146 int64_t payload_pts; |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
147 int64_t payload_dts; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
148 uint8_t payload[DEFAULT_PES_PAYLOAD_SIZE]; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
149 } MpegTSWriteStream; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
150 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
151 typedef struct MpegTSService { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
152 MpegTSSection pmt; /* MPEG2 pmt table context */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
153 int sid; /* service ID */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
154 char *name; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
155 char *provider_name; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
156 int pcr_pid; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
157 int pcr_packet_count; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
158 int pcr_packet_freq; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
159 } MpegTSService; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
160 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
161 typedef struct MpegTSWrite { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
162 MpegTSSection pat; /* MPEG2 pat table */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
163 MpegTSSection sdt; /* MPEG2 sdt table context */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
164 MpegTSService **services; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
165 int sdt_packet_count; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
166 int sdt_packet_freq; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
167 int pat_packet_count; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
168 int pat_packet_freq; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
169 int nb_services; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
170 int onid; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
171 int tsid; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
172 } MpegTSWrite; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
173 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
174 static void mpegts_write_pat(AVFormatContext *s) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
175 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
176 MpegTSWrite *ts = s->priv_data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
177 MpegTSService *service; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
178 uint8_t data[1012], *q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
179 int i; |
885 | 180 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
181 q = data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
182 for(i = 0; i < ts->nb_services; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
183 service = ts->services[i]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
184 put16(&q, service->sid); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
185 put16(&q, 0xe000 | service->pmt.pid); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
186 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
187 mpegts_write_section1(&ts->pat, PAT_TID, ts->tsid, 0, 0, 0, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
188 data, q - data); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
189 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
190 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
191 static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
192 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
193 // MpegTSWrite *ts = s->priv_data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
194 uint8_t data[1012], *q, *desc_length_ptr, *program_info_length_ptr; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
195 int val, stream_type, i; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
196 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
197 q = data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
198 put16(&q, 0xe000 | service->pcr_pid); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
199 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
200 program_info_length_ptr = q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
201 q += 2; /* patched after */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
202 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
203 /* put program info here */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
204 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
205 val = 0xf000 | (q - program_info_length_ptr - 2); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
206 program_info_length_ptr[0] = val >> 8; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
207 program_info_length_ptr[1] = val; |
885 | 208 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
209 for(i = 0; i < s->nb_streams; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
210 AVStream *st = s->streams[i]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
211 MpegTSWriteStream *ts_st = st->priv_data; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
212 switch(st->codec->codec_id) { |
313
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
213 case CODEC_ID_MPEG1VIDEO: |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
214 case CODEC_ID_MPEG2VIDEO: |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
215 stream_type = STREAM_TYPE_VIDEO_MPEG2; |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
216 break; |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
217 case CODEC_ID_MPEG4: |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
218 stream_type = STREAM_TYPE_VIDEO_MPEG4; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
219 break; |
313
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
220 case CODEC_ID_H264: |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
221 stream_type = STREAM_TYPE_VIDEO_H264; |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
222 break; |
3716 | 223 case CODEC_ID_DIRAC: |
224 stream_type = STREAM_TYPE_VIDEO_DIRAC; | |
225 break; | |
313
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
226 case CODEC_ID_MP2: |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
227 case CODEC_ID_MP3: |
160
9bde37b1a5ce
try to filter _all_ PATs if no SDT could be found patch by (<gbazin at altern dot org>)
michaelni
parents:
152
diff
changeset
|
228 stream_type = STREAM_TYPE_AUDIO_MPEG1; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
229 break; |
313
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
230 case CODEC_ID_AAC: |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
231 stream_type = STREAM_TYPE_AUDIO_AAC; |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
232 break; |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
233 case CODEC_ID_AC3: |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
234 stream_type = STREAM_TYPE_AUDIO_AC3; |
622892a75ddb
support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents:
250
diff
changeset
|
235 break; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
236 default: |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
237 stream_type = STREAM_TYPE_PRIVATE_DATA; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
238 break; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
239 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
240 *q++ = stream_type; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
241 put16(&q, 0xe000 | ts_st->pid); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
242 desc_length_ptr = q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
243 q += 2; /* patched after */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
244 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
245 /* write optional descriptors here */ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
246 switch(st->codec->codec_type) { |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
247 case CODEC_TYPE_AUDIO: |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
248 if (strlen(st->language) == 3) { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
249 *q++ = 0x0a; /* ISO 639 language descriptor */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
250 *q++ = 4; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
251 *q++ = st->language[0]; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
252 *q++ = st->language[1]; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
253 *q++ = st->language[2]; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
254 *q++ = 0; /* undefined type */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
255 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
256 break; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
257 case CODEC_TYPE_SUBTITLE: |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
258 { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
259 const char *language; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
260 language = st->language; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
261 if (strlen(language) != 3) |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
262 language = "eng"; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
263 *q++ = 0x59; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
264 *q++ = 8; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
265 *q++ = language[0]; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
266 *q++ = language[1]; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
267 *q++ = language[2]; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
268 *q++ = 0x10; /* normal subtitles (0x20 = if hearing pb) */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
269 put16(&q, 1); /* page id */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
270 put16(&q, 1); /* ancillary page id */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
271 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
272 break; |
3716 | 273 case CODEC_TYPE_VIDEO: |
274 if (stream_type == STREAM_TYPE_VIDEO_DIRAC) { | |
275 *q++ = 0x05; /*MPEG-2 registration descriptor*/ | |
276 *q++ = 4; | |
277 *q++ = 'd'; | |
278 *q++ = 'r'; | |
279 *q++ = 'a'; | |
280 *q++ = 'c'; | |
281 } | |
282 break; | |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
283 } |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
284 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
285 val = 0xf000 | (q - desc_length_ptr - 2); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
286 desc_length_ptr[0] = val >> 8; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
287 desc_length_ptr[1] = val; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
288 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
289 mpegts_write_section1(&service->pmt, PMT_TID, service->sid, 0, 0, 0, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
290 data, q - data); |
885 | 291 } |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
292 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
293 /* NOTE: str == NULL is accepted for an empty string */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
294 static void putstr8(uint8_t **q_ptr, const char *str) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
295 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
296 uint8_t *q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
297 int len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
298 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
299 q = *q_ptr; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
300 if (!str) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
301 len = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
302 else |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
303 len = strlen(str); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
304 *q++ = len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
305 memcpy(q, str, len); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
306 q += len; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
307 *q_ptr = q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
308 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
309 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
310 static void mpegts_write_sdt(AVFormatContext *s) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
311 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
312 MpegTSWrite *ts = s->priv_data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
313 MpegTSService *service; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
314 uint8_t data[1012], *q, *desc_list_len_ptr, *desc_len_ptr; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
315 int i, running_status, free_ca_mode, val; |
885 | 316 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
317 q = data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
318 put16(&q, ts->onid); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
319 *q++ = 0xff; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
320 for(i = 0; i < ts->nb_services; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
321 service = ts->services[i]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
322 put16(&q, service->sid); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
323 *q++ = 0xfc | 0x00; /* currently no EIT info */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
324 desc_list_len_ptr = q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
325 q += 2; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
326 running_status = 4; /* running */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
327 free_ca_mode = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
328 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
329 /* write only one descriptor for the service name and provider */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
330 *q++ = 0x48; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
331 desc_len_ptr = q; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
332 q++; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
333 *q++ = 0x01; /* digital television service */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
334 putstr8(&q, service->provider_name); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
335 putstr8(&q, service->name); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
336 desc_len_ptr[0] = q - desc_len_ptr - 1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
337 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
338 /* fill descriptor length */ |
885 | 339 val = (running_status << 13) | (free_ca_mode << 12) | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
340 (q - desc_list_len_ptr - 2); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
341 desc_list_len_ptr[0] = val >> 8; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
342 desc_list_len_ptr[1] = val; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
343 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
344 mpegts_write_section1(&ts->sdt, SDT_TID, ts->tsid, 0, 0, 0, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
345 data, q - data); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
346 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
347 |
885 | 348 static MpegTSService *mpegts_add_service(MpegTSWrite *ts, |
349 int sid, | |
350 const char *provider_name, | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
351 const char *name) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
352 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
353 MpegTSService *service; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
354 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
355 service = av_mallocz(sizeof(MpegTSService)); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
356 if (!service) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
357 return NULL; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
358 service->pmt.pid = DEFAULT_PMT_START_PID + ts->nb_services - 1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
359 service->sid = sid; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
360 service->provider_name = av_strdup(provider_name); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
361 service->name = av_strdup(name); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
362 service->pcr_pid = 0x1fff; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
363 dynarray_add(&ts->services, &ts->nb_services, service); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
364 return service; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
365 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
366 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
367 static void section_write_packet(MpegTSSection *s, const uint8_t *packet) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
368 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
369 AVFormatContext *ctx = s->opaque; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
1838
diff
changeset
|
370 put_buffer(ctx->pb, packet, TS_PACKET_SIZE); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
371 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
372 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
373 static int mpegts_write_header(AVFormatContext *s) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
374 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
375 MpegTSWrite *ts = s->priv_data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
376 MpegTSWriteStream *ts_st; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
377 MpegTSService *service; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
378 AVStream *st; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
379 int i, total_bit_rate; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
380 const char *service_name; |
885 | 381 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
382 ts->tsid = DEFAULT_TSID; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
383 ts->onid = DEFAULT_ONID; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
384 /* allocate a single DVB service */ |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
385 service_name = s->title; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
386 if (service_name[0] == '\0') |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
387 service_name = DEFAULT_SERVICE_NAME; |
885 | 388 service = mpegts_add_service(ts, DEFAULT_SID, |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
389 DEFAULT_PROVIDER_NAME, service_name); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
390 service->pmt.write_packet = section_write_packet; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
391 service->pmt.opaque = s; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
392 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
393 ts->pat.pid = PAT_PID; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
394 ts->pat.cc = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
395 ts->pat.write_packet = section_write_packet; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
396 ts->pat.opaque = s; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
397 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
398 ts->sdt.pid = SDT_PID; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
399 ts->sdt.cc = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
400 ts->sdt.write_packet = section_write_packet; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
401 ts->sdt.opaque = s; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
402 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
403 /* assign pids to each stream */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
404 total_bit_rate = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
405 for(i = 0;i < s->nb_streams; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
406 st = s->streams[i]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
407 ts_st = av_mallocz(sizeof(MpegTSWriteStream)); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
408 if (!ts_st) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
409 goto fail; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
410 st->priv_data = ts_st; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
411 ts_st->service = service; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
412 ts_st->pid = DEFAULT_START_PID + i; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
413 ts_st->payload_pts = AV_NOPTS_VALUE; |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
414 ts_st->payload_dts = AV_NOPTS_VALUE; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
415 /* update PCR pid by using the first video stream */ |
885 | 416 if (st->codec->codec_type == CODEC_TYPE_VIDEO && |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
417 service->pcr_pid == 0x1fff) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
418 service->pcr_pid = ts_st->pid; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
419 total_bit_rate += st->codec->bit_rate; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
420 } |
885 | 421 |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
422 /* if no video stream, use the first stream as PCR */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
423 if (service->pcr_pid == 0x1fff && s->nb_streams > 0) { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
424 ts_st = s->streams[0]->priv_data; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
425 service->pcr_pid = ts_st->pid; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
426 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
427 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
428 if (total_bit_rate <= 8 * 1024) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
429 total_bit_rate = 8 * 1024; |
885 | 430 service->pcr_packet_freq = (total_bit_rate * PCR_RETRANS_TIME) / |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
431 (TS_PACKET_SIZE * 8 * 1000); |
885 | 432 ts->sdt_packet_freq = (total_bit_rate * SDT_RETRANS_TIME) / |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
433 (TS_PACKET_SIZE * 8 * 1000); |
885 | 434 ts->pat_packet_freq = (total_bit_rate * PAT_RETRANS_TIME) / |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
435 (TS_PACKET_SIZE * 8 * 1000); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
436 #if 0 |
885 | 437 printf("%d %d %d\n", |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
438 total_bit_rate, ts->sdt_packet_freq, ts->pat_packet_freq); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
439 #endif |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
440 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
441 /* write info at the start of the file, so that it will be fast to |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
442 find them */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
443 mpegts_write_sdt(s); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
444 mpegts_write_pat(s); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
445 for(i = 0; i < ts->nb_services; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
446 mpegts_write_pmt(s, ts->services[i]); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
447 } |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
1838
diff
changeset
|
448 put_flush_packet(s->pb); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
449 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
450 return 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
451 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
452 fail: |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
453 for(i = 0;i < s->nb_streams; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
454 st = s->streams[i]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
455 av_free(st->priv_data); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
456 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
457 return -1; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
458 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
459 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
460 /* send SDT, PAT and PMT tables regulary */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
461 static void retransmit_si_info(AVFormatContext *s) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
462 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
463 MpegTSWrite *ts = s->priv_data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
464 int i; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
465 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
466 if (++ts->sdt_packet_count == ts->sdt_packet_freq) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
467 ts->sdt_packet_count = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
468 mpegts_write_sdt(s); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
469 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
470 if (++ts->pat_packet_count == ts->pat_packet_freq) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
471 ts->pat_packet_count = 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
472 mpegts_write_pat(s); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
473 for(i = 0; i < ts->nb_services; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
474 mpegts_write_pmt(s, ts->services[i]); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
475 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
476 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
477 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
478 |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
479 static void write_pts(uint8_t *q, int fourbits, int64_t pts) |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
480 { |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
481 int val; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
482 |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
483 val = fourbits << 4 | (((pts >> 30) & 0x07) << 1) | 1; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
484 *q++ = val; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
485 val = (((pts >> 15) & 0x7fff) << 1) | 1; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
486 *q++ = val >> 8; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
487 *q++ = val; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
488 val = (((pts) & 0x7fff) << 1) | 1; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
489 *q++ = val >> 8; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
490 *q++ = val; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
491 } |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
492 |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
493 /* NOTE: pes_data contains all the PES packet */ |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
494 static void mpegts_write_pes(AVFormatContext *s, AVStream *st, |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
495 const uint8_t *payload, int payload_size, |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
496 int64_t pts, int64_t dts) |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
497 { |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
498 MpegTSWriteStream *ts_st = st->priv_data; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
499 uint8_t buf[TS_PACKET_SIZE]; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
500 uint8_t *q; |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
501 int val, is_start, len, header_len, write_pcr, private_code, flags; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
502 int afc_len, stuffing_len; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
503 int64_t pcr = -1; /* avoid warning */ |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
504 |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
505 is_start = 1; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
506 while (payload_size > 0) { |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
507 retransmit_si_info(s); |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
508 |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
509 write_pcr = 0; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
510 if (ts_st->pid == ts_st->service->pcr_pid) { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
511 ts_st->service->pcr_packet_count++; |
885 | 512 if (ts_st->service->pcr_packet_count >= |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
513 ts_st->service->pcr_packet_freq) { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
514 ts_st->service->pcr_packet_count = 0; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
515 write_pcr = 1; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
516 /* XXX: this is incorrect, but at least we have a PCR |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
517 value */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
518 pcr = pts; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
519 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
520 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
521 |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
522 /* prepare packet header */ |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
523 q = buf; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
524 *q++ = 0x47; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
525 val = (ts_st->pid >> 8); |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
526 if (is_start) |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
527 val |= 0x40; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
528 *q++ = val; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
529 *q++ = ts_st->pid; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
530 *q++ = 0x10 | ts_st->cc | (write_pcr ? 0x20 : 0); |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
531 ts_st->cc = (ts_st->cc + 1) & 0xf; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
532 if (write_pcr) { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
533 *q++ = 7; /* AFC length */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
534 *q++ = 0x10; /* flags: PCR present */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
535 *q++ = pcr >> 25; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
536 *q++ = pcr >> 17; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
537 *q++ = pcr >> 9; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
538 *q++ = pcr >> 1; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
539 *q++ = (pcr & 1) << 7; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
540 *q++ = 0; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
541 } |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
542 if (is_start) { |
3716 | 543 int pes_extension = 0; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
544 /* write PES header */ |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
545 *q++ = 0x00; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
546 *q++ = 0x00; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
547 *q++ = 0x01; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
548 private_code = 0; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
549 if (st->codec->codec_type == CODEC_TYPE_VIDEO) { |
3716 | 550 if (st->codec->codec_id == CODEC_ID_DIRAC) { |
551 *q++ = 0xfd; | |
552 } else | |
553 *q++ = 0xe0; | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
554 } else if (st->codec->codec_type == CODEC_TYPE_AUDIO && |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
555 (st->codec->codec_id == CODEC_ID_MP2 || |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
556 st->codec->codec_id == CODEC_ID_MP3)) { |
885 | 557 *q++ = 0xc0; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
558 } else { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
559 *q++ = 0xbd; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
560 if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) { |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
561 private_code = 0x20; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
562 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
563 } |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
564 header_len = 0; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
565 flags = 0; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
566 if (pts != AV_NOPTS_VALUE) { |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
567 header_len += 5; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
568 flags |= 0x80; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
569 } |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
570 if (dts != AV_NOPTS_VALUE) { |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
571 header_len += 5; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
572 flags |= 0x40; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
573 } |
3716 | 574 if (st->codec->codec_type == CODEC_TYPE_VIDEO && |
575 st->codec->codec_id == CODEC_ID_DIRAC) { | |
576 /* set PES_extension_flag */ | |
577 pes_extension = 1; | |
578 flags |= 0x01; | |
579 | |
580 /* | |
581 * One byte for PES2 extension flag + | |
582 * one byte for extension length + | |
583 * one byte for extension id | |
584 */ | |
585 header_len += 3; | |
586 } | |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
587 len = payload_size + header_len + 3; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
588 if (private_code != 0) |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
589 len++; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
590 *q++ = len >> 8; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
591 *q++ = len; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
592 val = 0x80; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
593 /* data alignment indicator is required for subtitle data */ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
594 if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
595 val |= 0x04; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
596 *q++ = val; |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
597 *q++ = flags; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
598 *q++ = header_len; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
599 if (pts != AV_NOPTS_VALUE) { |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
600 write_pts(q, flags >> 6, pts); |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
601 q += 5; |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
602 } |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
603 if (dts != AV_NOPTS_VALUE) { |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
604 write_pts(q, 1, dts); |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
605 q += 5; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
606 } |
3716 | 607 if (pes_extension && st->codec->codec_id == CODEC_ID_DIRAC) { |
608 flags = 0x01; /* set PES_extension_flag_2 */ | |
609 *q++ = flags; | |
610 *q++ = 0x80 | 0x01; /* marker bit + extension length */ | |
611 /* | |
612 * Set the stream id extension flag bit to 0 and | |
613 * write the extended stream id | |
614 */ | |
615 *q++ = 0x00 | 0x60; | |
616 } | |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
617 if (private_code != 0) |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
618 *q++ = private_code; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
619 is_start = 0; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
620 } |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
621 /* header size */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
622 header_len = q - buf; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
623 /* data len */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
624 len = TS_PACKET_SIZE - header_len; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
625 if (len > payload_size) |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
626 len = payload_size; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
627 stuffing_len = TS_PACKET_SIZE - header_len - len; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
628 if (stuffing_len > 0) { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
629 /* add stuffing with AFC */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
630 if (buf[3] & 0x20) { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
631 /* stuffing already present: increase its size */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
632 afc_len = buf[4] + 1; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
633 memmove(buf + 4 + afc_len + stuffing_len, |
885 | 634 buf + 4 + afc_len, |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
635 header_len - (4 + afc_len)); |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
636 buf[4] += stuffing_len; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
637 memset(buf + 4 + afc_len, 0xff, stuffing_len); |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
638 } else { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
639 /* add stuffing */ |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
640 memmove(buf + 4 + stuffing_len, buf + 4, header_len - 4); |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
641 buf[3] |= 0x20; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
642 buf[4] = stuffing_len - 1; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
643 if (stuffing_len >= 2) { |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
644 buf[5] = 0x00; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
645 memset(buf + 6, 0xff, stuffing_len - 2); |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
646 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
647 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
648 } |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
649 memcpy(buf + TS_PACKET_SIZE - len, payload, len); |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
650 payload += len; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
651 payload_size -= len; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
1838
diff
changeset
|
652 put_buffer(s->pb, buf, TS_PACKET_SIZE); |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
653 } |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
1838
diff
changeset
|
654 put_flush_packet(s->pb); |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
655 } |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
656 |
468 | 657 static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt) |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
658 { |
468 | 659 AVStream *st = s->streams[pkt->stream_index]; |
660 int size= pkt->size; | |
661 uint8_t *buf= pkt->data; | |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
662 MpegTSWriteStream *ts_st = st->priv_data; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
663 int len, max_payload_size; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
664 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
785
diff
changeset
|
665 if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) { |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
666 /* for subtitle, a single PES packet must be generated */ |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
667 mpegts_write_pes(s, st, buf, size, pkt->pts, AV_NOPTS_VALUE); |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
668 return 0; |
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
669 } |
885 | 670 |
3719
6772cfc78d33
Change Dirac in MPEG-TS encapsulation to conform with spec changes.
diego
parents:
3716
diff
changeset
|
671 if (st->codec->codec_id == CODEC_ID_DIRAC) { |
6772cfc78d33
Change Dirac in MPEG-TS encapsulation to conform with spec changes.
diego
parents:
3716
diff
changeset
|
672 /* for Dirac, a single PES packet must be generated */ |
6772cfc78d33
Change Dirac in MPEG-TS encapsulation to conform with spec changes.
diego
parents:
3716
diff
changeset
|
673 mpegts_write_pes(s, st, buf, size, pkt->pts, pkt->dts); |
6772cfc78d33
Change Dirac in MPEG-TS encapsulation to conform with spec changes.
diego
parents:
3716
diff
changeset
|
674 return 0; |
6772cfc78d33
Change Dirac in MPEG-TS encapsulation to conform with spec changes.
diego
parents:
3716
diff
changeset
|
675 } |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
676 max_payload_size = DEFAULT_PES_PAYLOAD_SIZE; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
677 while (size > 0) { |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
678 len = max_payload_size - ts_st->payload_index; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
679 if (len > size) |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
680 len = size; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
681 memcpy(ts_st->payload + ts_st->payload_index, buf, len); |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
682 buf += len; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
683 size -= len; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
684 ts_st->payload_index += len; |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
685 if (ts_st->payload_pts == AV_NOPTS_VALUE) |
468 | 686 ts_st->payload_pts = pkt->pts; |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
687 if (ts_st->payload_dts == AV_NOPTS_VALUE) |
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
688 ts_st->payload_dts = pkt->dts; |
785
e277d8928f49
buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents:
693
diff
changeset
|
689 if (ts_st->payload_index >= max_payload_size) { |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
690 mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index, |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
691 ts_st->payload_pts, ts_st->payload_dts); |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
692 ts_st->payload_pts = AV_NOPTS_VALUE; |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
693 ts_st->payload_dts = AV_NOPTS_VALUE; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
694 ts_st->payload_index = 0; |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
695 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
696 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
697 return 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
698 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
699 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
700 static int mpegts_write_end(AVFormatContext *s) |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
701 { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
702 MpegTSWrite *ts = s->priv_data; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
703 MpegTSWriteStream *ts_st; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
704 MpegTSService *service; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
705 AVStream *st; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
706 int i; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
707 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
708 /* flush current packets */ |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
709 for(i = 0; i < s->nb_streams; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
710 st = s->streams[i]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
711 ts_st = st->priv_data; |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
712 if (ts_st->payload_index > 0) { |
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
713 mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index, |
1838
d1af40ab8ea5
write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents:
1415
diff
changeset
|
714 ts_st->payload_pts, ts_st->payload_dts); |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
715 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
716 } |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
1838
diff
changeset
|
717 put_flush_packet(s->pb); |
885 | 718 |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
719 for(i = 0; i < ts->nb_services; i++) { |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
720 service = ts->services[i]; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
721 av_freep(&service->provider_name); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
722 av_freep(&service->name); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
723 av_free(service); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
724 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
725 av_free(ts->services); |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
726 |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
727 return 0; |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
728 } |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
729 |
1167 | 730 AVOutputFormat mpegts_muxer = { |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
731 "mpegts", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3420
diff
changeset
|
732 NULL_IF_CONFIG_SMALL("MPEG-2 transport stream format"), |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
733 "video/x-mpegts", |
3420 | 734 "ts,m2t", |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
735 sizeof(MpegTSWrite), |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
736 CODEC_ID_MP2, |
250
2d4dcb1d3e21
generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents:
241
diff
changeset
|
737 CODEC_ID_MPEG2VIDEO, |
152
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
738 mpegts_write_header, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
739 mpegts_write_packet, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
740 mpegts_write_end, |
cc03a75cbde4
mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff
changeset
|
741 }; |