annotate mpegtsenc.c @ 6396:c2e5016e2b4e libavformat

MMSH support, the most popular and widely used of all MMS variants. Written by Zhentan Feng <spyfeng gmail com> as part of Google's Summer of Code program.
author rbultje
date Sat, 21 Aug 2010 19:04:41 +0000
parents 50b1c5de4b71
children 3d0c78997acc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4251
77e0c7511d41 cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 4220
diff changeset
3 * Copyright (c) 2003 Fabrice Bellard
152
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
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 2893
diff changeset
21
4201
7d2f3f1b68d8 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 3719
diff changeset
22 #include "libavutil/bswap.h"
3286
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 2893
diff changeset
23 #include "libavutil/crc.h"
4211
5e5654752973 set pts and dts of pes packets exactly according to specs
bcoudurier
parents: 4209
diff changeset
24 #include "libavcodec/mpegvideo.h"
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
25 #include "avformat.h"
5946
28ca2d77f997 Move the internal function declarations in avformat.h to internal.h.
stefano
parents: 5930
diff changeset
26 #include "internal.h"
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
27 #include "mpegts.h"
5787
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
28 #include "adts.h"
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
29
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
30 /* 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
31
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
32 /*********************************************/
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
33 /* 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
34
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
35 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
36 int pid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
37 int cc;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
38 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
39 void *opaque;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
40 } MpegTSSection;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
41
4209
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
42 typedef struct MpegTSService {
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
43 MpegTSSection pmt; /* MPEG2 pmt table context */
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
44 int sid; /* service ID */
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
45 char *name;
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
46 char *provider_name;
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
47 int pcr_pid;
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
48 int pcr_packet_count;
5115
640c875b3bfe rename freq to period which is more correct, patch by Niobos, niobos dot be at gmail dot com
bcoudurier
parents: 4952
diff changeset
49 int pcr_packet_period;
4209
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
50 } MpegTSService;
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
51
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
52 typedef struct MpegTSWrite {
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
53 MpegTSSection pat; /* MPEG2 pat table */
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
54 MpegTSSection sdt; /* MPEG2 sdt table context */
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
55 MpegTSService **services;
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
56 int sdt_packet_count;
5115
640c875b3bfe rename freq to period which is more correct, patch by Niobos, niobos dot be at gmail dot com
bcoudurier
parents: 4952
diff changeset
57 int sdt_packet_period;
4209
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
58 int pat_packet_count;
5115
640c875b3bfe rename freq to period which is more correct, patch by Niobos, niobos dot be at gmail dot com
bcoudurier
parents: 4952
diff changeset
59 int pat_packet_period;
4209
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
60 int nb_services;
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
61 int onid;
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
62 int tsid;
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
63 uint64_t cur_pcr;
5784
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
64 int mux_rate; ///< set to 1 when VBR
4209
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
65 } MpegTSWrite;
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
66
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
67 /* 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
68 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
69 {
4209
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
70 MpegTSWrite *ts = ((AVFormatContext*)s->opaque)->priv_data;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
71 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
72 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
73 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
74 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
75 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
76
6248
e630da0f5861 Add av_ prefix to bswap macros
mru
parents: 6244
diff changeset
77 crc = av_bswap32(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
78 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
79 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
80 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
81 buf[len - 1] = (crc) & 0xff;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
82
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
83 /* 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
84 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
85 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
86 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
87 q = packet;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
88 *q++ = 0x47;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
89 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
90 if (first)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
91 b |= 0x40;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
92 *q++ = b;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
93 *q++ = s->pid;
5709
bdcd3e540558 Correctly increment continuity_counter in PCR packets.
cehoyos
parents: 5543
diff changeset
94 s->cc = (s->cc + 1) & 0xf;
3419
e78dfb00b88a fix continuity counter to start at 0
bcoudurier
parents: 3286
diff changeset
95 *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
96 if (first)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
97 *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
98 len1 = TS_PACKET_SIZE - (q - packet);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
99 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
100 len1 = len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
101 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
102 q += len1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
103 /* 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
104 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
105 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
106 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
107
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
108 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
109
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
110 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
111 len -= len1;
4209
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
112
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
113 ts->cur_pcr += TS_PACKET_SIZE*8*90000LL/ts->mux_rate;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
114 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
115 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
116
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
117 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
118 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
119 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
120 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
121 *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
122 *q++ = val;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
123 *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
124 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
125
1124
d3aff2c607f9 Add const to (mostly) char* and make some functions static, which aren't used
diego
parents: 996
diff changeset
126 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
127 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
128 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
129 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
130 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
131 unsigned int tot_len;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
132
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
133 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
134 /* 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
135 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
136 return -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
137
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
138 q = section;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
139 *q++ = tid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
140 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
141 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
142 *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
143 *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
144 *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
145 memcpy(q, buf, len);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
146
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
147 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
148 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
149 }
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 /*********************************************/
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
152 /* mpegts writer */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
153
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
154 #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
155 #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
156 #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
157 #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
158
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
159 /* 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
160 #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
161 #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
162 #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
163
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
164 /* 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
165 #define DEFAULT_PES_HEADER_FREQ 16
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
166 #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
167
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
168 /* 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
169 #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
170 #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
171 #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
172
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
173 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
174 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
175 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
176 int cc;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
177 int payload_index;
4915
26708ee9a51d ensure first pts is set, according to specs
bcoudurier
parents: 4914
diff changeset
178 int first_pts_check; ///< first pts check needed
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
179 int64_t payload_pts;
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
180 int64_t payload_dts;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
181 uint8_t payload[DEFAULT_PES_PAYLOAD_SIZE];
5787
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
182 ADTSContext *adts;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
183 } MpegTSWriteStream;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
184
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
185 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
186 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
187 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
188 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
189 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
190 int i;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
191
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
192 q = data;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
193 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
194 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
195 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
196 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
197 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
198 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
199 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
200 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
201
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
202 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
203 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
204 // 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
205 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
206 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
207
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
208 q = data;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
209 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
210
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
211 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
212 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
213
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
214 /* 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
215
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
216 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
217 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
218 program_info_length_ptr[1] = val;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
219
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
220 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
221 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
222 MpegTSWriteStream *ts_st = st->priv_data;
4525
c66cf692bea0 use new metadata API in mpegts muxer
aurel
parents: 4251
diff changeset
223 AVMetadataTag *lang = av_metadata_get(st->metadata, "language", NULL,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
224 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
225 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
226 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
227 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
228 break;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents: 250
diff changeset
229 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
230 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
231 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
232 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
233 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
234 break;
3716
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
235 case CODEC_ID_DIRAC:
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
236 stream_type = STREAM_TYPE_VIDEO_DIRAC;
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
237 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
238 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
239 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
240 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
241 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
242 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
243 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
244 break;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents: 250
diff changeset
245 case CODEC_ID_AC3:
5543
fbedfacb36ed revert wrongly commited hunk in r21205
bcoudurier
parents: 5541
diff changeset
246 stream_type = STREAM_TYPE_AUDIO_AC3;
313
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents: 250
diff changeset
247 break;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
248 default:
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
249 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
250 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
251 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
252 *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
253 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
254 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
255 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
256
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
257 /* 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
258 switch(st->codec->codec_type) {
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5804
diff changeset
259 case AVMEDIA_TYPE_AUDIO:
4525
c66cf692bea0 use new metadata API in mpegts muxer
aurel
parents: 4251
diff changeset
260 if (lang && strlen(lang->value) == 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
261 *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
262 *q++ = 4;
4525
c66cf692bea0 use new metadata API in mpegts muxer
aurel
parents: 4251
diff changeset
263 *q++ = lang->value[0];
c66cf692bea0 use new metadata API in mpegts muxer
aurel
parents: 4251
diff changeset
264 *q++ = lang->value[1];
c66cf692bea0 use new metadata API in mpegts muxer
aurel
parents: 4251
diff changeset
265 *q++ = lang->value[2];
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
266 *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
267 }
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 break;
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5804
diff changeset
269 case AVMEDIA_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
270 {
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 const char *language;
4525
c66cf692bea0 use new metadata API in mpegts muxer
aurel
parents: 4251
diff changeset
272 language = lang && strlen(lang->value)==3 ? lang->value : "eng";
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
273 *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
274 *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
275 *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
276 *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
277 *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
278 *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
279 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
280 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
281 }
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
282 break;
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5804
diff changeset
283 case AVMEDIA_TYPE_VIDEO:
3716
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
284 if (stream_type == STREAM_TYPE_VIDEO_DIRAC) {
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
285 *q++ = 0x05; /*MPEG-2 registration descriptor*/
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
286 *q++ = 4;
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
287 *q++ = 'd';
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
288 *q++ = 'r';
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
289 *q++ = 'a';
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
290 *q++ = 'c';
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
291 }
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
292 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
293 }
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
294
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
295 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
296 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
297 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
298 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
299 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
300 data, q - data);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
301 }
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
302
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
303 /* 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
304 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
305 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
306 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
307 int len;
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 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
310 if (!str)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
311 len = 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
312 else
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
313 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
314 *q++ = len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
315 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
316 q += len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
317 *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
318 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
319
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
320 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
321 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
322 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
323 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
324 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
325 int i, running_status, free_ca_mode, val;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
326
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
327 q = data;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
328 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
329 *q++ = 0xff;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
330 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
331 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
332 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
333 *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
334 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
335 q += 2;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
336 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
337 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
338
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
339 /* 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
340 *q++ = 0x48;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
341 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
342 q++;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
343 *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
344 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
345 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
346 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
347
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
348 /* fill descriptor length */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
349 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
350 (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
351 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
352 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
353 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
354 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
355 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
356 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
357
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
358 static MpegTSService *mpegts_add_service(MpegTSWrite *ts,
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
359 int sid,
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
360 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
361 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
362 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
363 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
364
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
365 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
366 if (!service)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
367 return NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
368 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
369 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
370 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
371 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
372 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
373 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
374 return service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
375 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
376
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
377 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
378 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
379 AVFormatContext *ctx = s->opaque;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 1838
diff changeset
380 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
381 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
382
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
383 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
384 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
385 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
386 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
387 MpegTSService *service;
5784
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
388 AVStream *st, *pcr_st = NULL;
4525
c66cf692bea0 use new metadata API in mpegts muxer
aurel
parents: 4251
diff changeset
389 AVMetadataTag *title;
6200
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
390 int i, j;
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
391 const char *service_name;
6200
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
392 int *pids;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
393
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
394 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
395 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
396 /* allocate a single DVB service */
4525
c66cf692bea0 use new metadata API in mpegts muxer
aurel
parents: 4251
diff changeset
397 title = av_metadata_get(s->metadata, "title", NULL, 0);
c66cf692bea0 use new metadata API in mpegts muxer
aurel
parents: 4251
diff changeset
398 service_name = title ? title->value : DEFAULT_SERVICE_NAME;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
399 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
400 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
401 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
402 service->pmt.opaque = s;
5782
3b477aba769a Start continuity counter at 0 for pmt as well
bcoudurier
parents: 5781
diff changeset
403 service->pmt.cc = 15;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
404
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
405 ts->pat.pid = PAT_PID;
5709
bdcd3e540558 Correctly increment continuity_counter in PCR packets.
cehoyos
parents: 5543
diff changeset
406 ts->pat.cc = 15; // Initialize at 15 so that it wraps and be equal to 0 for the first packet we write
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
407 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
408 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
409
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
410 ts->sdt.pid = SDT_PID;
5709
bdcd3e540558 Correctly increment continuity_counter in PCR packets.
cehoyos
parents: 5543
diff changeset
411 ts->sdt.cc = 15;
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->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
413 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
414
6212
0c4d80e5428f mpegtsenc: allocate correct size for PID table
mru
parents: 6200
diff changeset
415 pids = av_malloc(s->nb_streams * sizeof(*pids));
6200
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
416 if (!pids)
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
417 return AVERROR(ENOMEM);
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
418
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
419 /* 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
420 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
421 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
422 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
423 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
424 goto fail;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
425 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
426 ts_st->service = service;
6200
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
427 /* MPEG pid values < 16 are reserved. Applications which set st->id in
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
428 * this range are assigned a calculated pid. */
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
429 if (st->id < 16) {
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
430 ts_st->pid = DEFAULT_START_PID + i;
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
431 } else if (st->id < 0x1FFF) {
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
432 ts_st->pid = st->id;
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
433 } else {
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
434 av_log(s, AV_LOG_ERROR, "Invalid stream id %d, must be less than 8191\n", st->id);
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
435 goto fail;
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
436 }
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
437 if (ts_st->pid == service->pmt.pid) {
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
438 av_log(s, AV_LOG_ERROR, "Duplicate stream id %d\n", ts_st->pid);
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
439 goto fail;
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
440 }
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
441 for (j = 0; j < i; j++)
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
442 if (pids[j] == ts_st->pid) {
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
443 av_log(s, AV_LOG_ERROR, "Duplicate stream id %d\n", ts_st->pid);
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
444 goto fail;
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
445 }
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
446 pids[i] = ts_st->pid;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
447 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
448 ts_st->payload_dts = AV_NOPTS_VALUE;
4915
26708ee9a51d ensure first pts is set, according to specs
bcoudurier
parents: 4914
diff changeset
449 ts_st->first_pts_check = 1;
5781
2d93c764dc54 Start continuity counter at 0 for streams
bcoudurier
parents: 5780
diff changeset
450 ts_st->cc = 15;
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
451 /* update PCR pid by using the first video stream */
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5804
diff changeset
452 if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
5784
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
453 service->pcr_pid == 0x1fff) {
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
454 service->pcr_pid = ts_st->pid;
5784
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
455 pcr_st = st;
5219
583eb737b1c4 fix pes overhead computation, patch by Niobos, niobos at dest-unreach dot be
bcoudurier
parents: 5115
diff changeset
456 }
5787
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
457 if (st->codec->codec_id == CODEC_ID_AAC &&
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
458 st->codec->extradata_size > 0) {
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
459 ts_st->adts = av_mallocz(sizeof(*ts_st->adts));
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
460 if (!ts_st->adts)
5930
08cd1179a20d Replace all remaining occurrences of AVERROR_NOMEM with
stefano
parents: 5910
diff changeset
461 return AVERROR(ENOMEM);
5787
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
462 if (ff_adts_decode_extradata(s, ts_st->adts, st->codec->extradata,
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
463 st->codec->extradata_size) < 0)
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
464 return -1;
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
465 }
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
466 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
467
6200
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
468 av_free(pids);
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
469
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
470 /* 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
471 if (service->pcr_pid == 0x1fff && s->nb_streams > 0) {
5784
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
472 pcr_st = s->streams[0];
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
473 ts_st = pcr_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
474 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
475 }
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
476
5784
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
477 ts->mux_rate = s->mux_rate ? s->mux_rate : 1;
4216
de2177071c01 calculate pat, pmt and sdt exact size and adjust total bitrate
bcoudurier
parents: 4215
diff changeset
478
5784
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
479 if (ts->mux_rate > 1) {
5803
405bb9032df6 reindent
bcoudurier
parents: 5787
diff changeset
480 service->pcr_packet_period = (ts->mux_rate * PCR_RETRANS_TIME) /
405bb9032df6 reindent
bcoudurier
parents: 5787
diff changeset
481 (TS_PACKET_SIZE * 8 * 1000);
405bb9032df6 reindent
bcoudurier
parents: 5787
diff changeset
482 ts->sdt_packet_period = (ts->mux_rate * SDT_RETRANS_TIME) /
405bb9032df6 reindent
bcoudurier
parents: 5787
diff changeset
483 (TS_PACKET_SIZE * 8 * 1000);
405bb9032df6 reindent
bcoudurier
parents: 5787
diff changeset
484 ts->pat_packet_period = (ts->mux_rate * PAT_RETRANS_TIME) /
405bb9032df6 reindent
bcoudurier
parents: 5787
diff changeset
485 (TS_PACKET_SIZE * 8 * 1000);
5535
dd79e1261e28 move pcr/sdt/pat period computation after ts->mux_rate is set, patch by Mike Scheutzow, scheutzow at alcatel-lucent dot com
bcoudurier
parents: 5534
diff changeset
486
5803
405bb9032df6 reindent
bcoudurier
parents: 5787
diff changeset
487 ts->cur_pcr = av_rescale(s->max_delay, 90000, AV_TIME_BASE);
5784
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
488 } else {
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
489 /* Arbitrary values, PAT/PMT could be written on key frames */
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
490 ts->sdt_packet_period = 200;
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
491 ts->pat_packet_period = 40;
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5804
diff changeset
492 if (pcr_st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
5784
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
493 if (!pcr_st->codec->frame_size) {
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
494 av_log(s, AV_LOG_WARNING, "frame size not set\n");
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
495 service->pcr_packet_period =
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
496 pcr_st->codec->sample_rate/(10*512);
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
497 } else {
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
498 service->pcr_packet_period =
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
499 pcr_st->codec->sample_rate/(10*pcr_st->codec->frame_size);
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
500 }
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
501 } else {
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
502 // max delta PCR 0.1s
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
503 service->pcr_packet_period =
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
504 pcr_st->codec->time_base.den/(10*pcr_st->codec->time_base.num);
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
505 }
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
506 }
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
507
5534
2836866dd7a1 output a pcr as soon as possible, patch by Mike Scheutzow, scheutzow at alcatel-lucent dot com
bcoudurier
parents: 5533
diff changeset
508 // output a PCR as soon as possible
2836866dd7a1 output a pcr as soon as possible, patch by Mike Scheutzow, scheutzow at alcatel-lucent dot com
bcoudurier
parents: 5533
diff changeset
509 service->pcr_packet_count = service->pcr_packet_period;
5784
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
510 ts->pat_packet_count = ts->pat_packet_period-1;
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
511 ts->sdt_packet_count = ts->sdt_packet_period-1;
5534
2836866dd7a1 output a pcr as soon as possible, patch by Mike Scheutzow, scheutzow at alcatel-lucent dot com
bcoudurier
parents: 5533
diff changeset
512
6244
17483b8b01e7 In mpegts muxer, print VBR instead of dummy 1 when displaying muxrate
bcoudurier
parents: 6212
diff changeset
513 if (ts->mux_rate == 1)
17483b8b01e7 In mpegts muxer, print VBR instead of dummy 1 when displaying muxrate
bcoudurier
parents: 6212
diff changeset
514 av_log(s, AV_LOG_INFO, "muxrate VBR, ");
17483b8b01e7 In mpegts muxer, print VBR instead of dummy 1 when displaying muxrate
bcoudurier
parents: 6212
diff changeset
515 else
17483b8b01e7 In mpegts muxer, print VBR instead of dummy 1 when displaying muxrate
bcoudurier
parents: 6212
diff changeset
516 av_log(s, AV_LOG_INFO, "muxrate %d, ", ts->mux_rate);
17483b8b01e7 In mpegts muxer, print VBR instead of dummy 1 when displaying muxrate
bcoudurier
parents: 6212
diff changeset
517 av_log(s, AV_LOG_INFO, "pcr every %d pkts, "
5538
3ad37f4daa76 print more debug info about muxing parameters, patch by Mike Scheutzow, scheutzow at alcatel-lucent dot com
bcoudurier
parents: 5537
diff changeset
518 "sdt every %d, pat/pmt every %d pkts\n",
6244
17483b8b01e7 In mpegts muxer, print VBR instead of dummy 1 when displaying muxrate
bcoudurier
parents: 6212
diff changeset
519 service->pcr_packet_period,
5784
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
520 ts->sdt_packet_period, ts->pat_packet_period);
5538
3ad37f4daa76 print more debug info about muxing parameters, patch by Mike Scheutzow, scheutzow at alcatel-lucent dot com
bcoudurier
parents: 5537
diff changeset
521
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 1838
diff changeset
522 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
523
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
524 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
525
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
526 fail:
6200
ac9ea0fde990 Allow setting streamid when muxing mpegts.
cehoyos
parents: 5946
diff changeset
527 av_free(pids);
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
528 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
529 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
530 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
531 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
532 return -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
533 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
534
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
535 /* 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
536 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
537 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
538 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
539 int i;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
540
5115
640c875b3bfe rename freq to period which is more correct, patch by Niobos, niobos dot be at gmail dot com
bcoudurier
parents: 4952
diff changeset
541 if (++ts->sdt_packet_count == ts->sdt_packet_period) {
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
542 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
543 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
544 }
5115
640c875b3bfe rename freq to period which is more correct, patch by Niobos, niobos dot be at gmail dot com
bcoudurier
parents: 4952
diff changeset
545 if (++ts->pat_packet_count == ts->pat_packet_period) {
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
546 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
547 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
548 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
549 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
550 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
551 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
552 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
553
5536
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
554 /* Write a single null transport stream packet */
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
555 static void mpegts_insert_null_packet(AVFormatContext *s)
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
556 {
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
557 MpegTSWrite *ts = s->priv_data;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
558 uint8_t *q;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
559 uint8_t buf[TS_PACKET_SIZE];
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
560
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
561 q = buf;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
562 *q++ = 0x47;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
563 *q++ = 0x00 | 0x1f;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
564 *q++ = 0xff;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
565 *q++ = 0x10;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
566 memset(q, 0x0FF, TS_PACKET_SIZE - (q - buf));
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
567 put_buffer(s->pb, buf, TS_PACKET_SIZE);
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
568 ts->cur_pcr += TS_PACKET_SIZE*8*90000LL/ts->mux_rate;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
569 }
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
570
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
571 /* Write a single transport stream packet with a PCR and no payload */
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
572 static void mpegts_insert_pcr_only(AVFormatContext *s, AVStream *st)
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
573 {
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
574 MpegTSWrite *ts = s->priv_data;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
575 MpegTSWriteStream *ts_st = st->priv_data;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
576 uint8_t *q;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
577 uint64_t pcr = ts->cur_pcr;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
578 uint8_t buf[TS_PACKET_SIZE];
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
579
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
580 q = buf;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
581 *q++ = 0x47;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
582 *q++ = ts_st->pid >> 8;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
583 *q++ = ts_st->pid;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
584 *q++ = 0x20 | ts_st->cc; /* Adaptation only */
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
585 /* Continuity Count field does not increment (see 13818-1 section 2.4.3.3) */
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
586 *q++ = TS_PACKET_SIZE - 5; /* Adaptation Field Length */
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
587 *q++ = 0x10; /* Adaptation flags: PCR present */
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
588
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
589 /* PCR coded into 6 bytes */
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
590 *q++ = pcr >> 25;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
591 *q++ = pcr >> 17;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
592 *q++ = pcr >> 9;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
593 *q++ = pcr >> 1;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
594 *q++ = (pcr & 1) << 7;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
595 *q++ = 0;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
596
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
597 /* stuffing bytes */
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
598 memset(q, 0xFF, TS_PACKET_SIZE - (q - buf));
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
599 put_buffer(s->pb, buf, TS_PACKET_SIZE);
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
600 ts->cur_pcr += TS_PACKET_SIZE*8*90000LL/ts->mux_rate;
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
601 }
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
602
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
603 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
604 {
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
605 int val;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
606
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
607 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
608 *q++ = val;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
609 val = (((pts >> 15) & 0x7fff) << 1) | 1;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
610 *q++ = val >> 8;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
611 *q++ = val;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
612 val = (((pts) & 0x7fff) << 1) | 1;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
613 *q++ = val >> 8;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
614 *q++ = val;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
615 }
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
616
5537
8b4ac40f9525 update mpegts_write_pes documentation, patch by Mike Scheutzow, scheutzow at alcatel-lucent dot com
bcoudurier
parents: 5536
diff changeset
617 /* Add a pes header to the front of payload, and segment into an integer number of
8b4ac40f9525 update mpegts_write_pes documentation, patch by Mike Scheutzow, scheutzow at alcatel-lucent dot com
bcoudurier
parents: 5536
diff changeset
618 * ts packets. The final ts packet is padded using an over-sized adaptation header
8b4ac40f9525 update mpegts_write_pes documentation, patch by Mike Scheutzow, scheutzow at alcatel-lucent dot com
bcoudurier
parents: 5536
diff changeset
619 * to exactly fill the last ts packet.
8b4ac40f9525 update mpegts_write_pes documentation, patch by Mike Scheutzow, scheutzow at alcatel-lucent dot com
bcoudurier
parents: 5536
diff changeset
620 * NOTE: 'payload' contains a complete PES payload.
8b4ac40f9525 update mpegts_write_pes documentation, patch by Mike Scheutzow, scheutzow at alcatel-lucent dot com
bcoudurier
parents: 5536
diff changeset
621 */
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
622 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
623 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
624 int64_t pts, int64_t dts)
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
625 {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
626 MpegTSWriteStream *ts_st = st->priv_data;
4209
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
627 MpegTSWrite *ts = s->priv_data;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
628 uint8_t buf[TS_PACKET_SIZE];
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
629 uint8_t *q;
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
630 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
631 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
632 int64_t pcr = -1; /* avoid warning */
5536
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
633 int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE);
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
634
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
635 is_start = 1;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
636 while (payload_size > 0) {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
637 retransmit_si_info(s);
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
638
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
639 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
640 if (ts_st->pid == ts_st->service->pcr_pid) {
5784
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
641 if (ts->mux_rate > 1 || is_start) // VBR pcr period is based on frames
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
642 ts_st->service->pcr_packet_count++;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
643 if (ts_st->service->pcr_packet_count >=
5115
640c875b3bfe rename freq to period which is more correct, patch by Niobos, niobos dot be at gmail dot com
bcoudurier
parents: 4952
diff changeset
644 ts_st->service->pcr_packet_period) {
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
645 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
646 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
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
5784
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
650 if (ts->mux_rate > 1 && dts != AV_NOPTS_VALUE &&
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
651 (dts - (int64_t)ts->cur_pcr) > delay) {
5536
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
652 /* pcr insert gets priority over null packet insert */
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
653 if (write_pcr)
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
654 mpegts_insert_pcr_only(s, st);
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
655 else
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
656 mpegts_insert_null_packet(s);
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
657 continue; /* recalculate write_pcr and possibly retransmit si_info */
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
658 }
c13224897684 Insert null packets to keep pcr values correct, patch by Mike Scheutzow,
bcoudurier
parents: 5535
diff changeset
659
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
660 /* prepare packet header */
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
661 q = buf;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
662 *q++ = 0x47;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
663 val = (ts_st->pid >> 8);
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
664 if (is_start)
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
665 val |= 0x40;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
666 *q++ = val;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
667 *q++ = ts_st->pid;
5709
bdcd3e540558 Correctly increment continuity_counter in PCR packets.
cehoyos
parents: 5543
diff changeset
668 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
669 *q++ = 0x10 | ts_st->cc | (write_pcr ? 0x20 : 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
670 if (write_pcr) {
4209
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
671 // add 11, pcr references the last byte of program clock reference base
5784
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
672 if (ts->mux_rate > 1)
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
673 pcr = ts->cur_pcr + (4+7)*8*90000LL / ts->mux_rate;
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
674 else
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
675 pcr = dts - delay;
4214
5720e5948e0b warn if dts < pcr which means TS is invalid
bcoudurier
parents: 4213
diff changeset
676 if (dts != AV_NOPTS_VALUE && dts < pcr)
5720e5948e0b warn if dts < pcr which means TS is invalid
bcoudurier
parents: 4213
diff changeset
677 av_log(s, AV_LOG_WARNING, "dts < pcr, TS is invalid\n");
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 *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
679 *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
680 *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
681 *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
682 *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
683 *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
684 *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
685 *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
686 }
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
687 if (is_start) {
3716
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
688 int pes_extension = 0;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
689 /* write PES header */
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
690 *q++ = 0x00;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
691 *q++ = 0x00;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
692 *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
693 private_code = 0;
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5804
diff changeset
694 if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
3716
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
695 if (st->codec->codec_id == CODEC_ID_DIRAC) {
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
696 *q++ = 0xfd;
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
697 } else
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
698 *q++ = 0xe0;
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5804
diff changeset
699 } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 785
diff changeset
700 (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
701 st->codec->codec_id == CODEC_ID_MP3)) {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
702 *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
703 } 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
704 *q++ = 0xbd;
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5804
diff changeset
705 if (st->codec->codec_type == AVMEDIA_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
706 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
707 }
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
708 }
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
709 header_len = 0;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
710 flags = 0;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
711 if (pts != AV_NOPTS_VALUE) {
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
712 header_len += 5;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
713 flags |= 0x80;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
714 }
4913
5d22e1946275 do not write dts if pts is not set
bcoudurier
parents: 4912
diff changeset
715 if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != pts) {
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
716 header_len += 5;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
717 flags |= 0x40;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
718 }
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5804
diff changeset
719 if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&
3716
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
720 st->codec->codec_id == CODEC_ID_DIRAC) {
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
721 /* set PES_extension_flag */
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
722 pes_extension = 1;
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
723 flags |= 0x01;
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
724
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
725 /*
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
726 * One byte for PES2 extension flag +
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
727 * one byte for extension length +
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
728 * one byte for extension id
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
729 */
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
730 header_len += 3;
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
731 }
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
732 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
733 if (private_code != 0)
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
734 len++;
4921
fa21da521576 write a single pes for video frames, some proprietary player needs it
bcoudurier
parents: 4915
diff changeset
735 if (len > 0xffff)
fa21da521576 write a single pes for video frames, some proprietary player needs it
bcoudurier
parents: 4915
diff changeset
736 len = 0;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
737 *q++ = len >> 8;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
738 *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
739 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
740 /* data alignment indicator is required for subtitle data */
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5804
diff changeset
741 if (st->codec->codec_type == AVMEDIA_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
742 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
743 *q++ = val;
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
744 *q++ = flags;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
745 *q++ = header_len;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
746 if (pts != AV_NOPTS_VALUE) {
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
747 write_pts(q, flags >> 6, pts);
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
748 q += 5;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
749 }
4913
5d22e1946275 do not write dts if pts is not set
bcoudurier
parents: 4912
diff changeset
750 if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != pts) {
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
751 write_pts(q, 1, dts);
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
752 q += 5;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
753 }
3716
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
754 if (pes_extension && st->codec->codec_id == CODEC_ID_DIRAC) {
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
755 flags = 0x01; /* set PES_extension_flag_2 */
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
756 *q++ = flags;
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
757 *q++ = 0x80 | 0x01; /* marker bit + extension length */
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
758 /*
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
759 * Set the stream id extension flag bit to 0 and
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
760 * write the extended stream id
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
761 */
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
762 *q++ = 0x00 | 0x60;
2ca19db359bd Dirac encapsulation in MPEG-TS
diego
parents: 3424
diff changeset
763 }
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
764 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
765 *q++ = private_code;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
766 is_start = 0;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
767 }
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
768 /* 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
769 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
770 /* 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
771 len = TS_PACKET_SIZE - header_len;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
772 if (len > payload_size)
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
773 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
774 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
775 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
776 /* 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
777 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
778 /* 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
779 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
780 memmove(buf + 4 + afc_len + stuffing_len,
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
781 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
782 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
783 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
784 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
785 } 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
786 /* 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
787 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
788 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
789 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
790 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
791 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
792 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
793 }
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
794 }
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
795 }
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
796 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
797 payload += len;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
798 payload_size -= len;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 1838
diff changeset
799 put_buffer(s->pb, buf, TS_PACKET_SIZE);
4209
020395b83a14 compute pcr more accurately, regression tests need update
bcoudurier
parents: 4201
diff changeset
800 ts->cur_pcr += TS_PACKET_SIZE*8*90000LL/ts->mux_rate;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
801 }
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 1838
diff changeset
802 put_flush_packet(s->pb);
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
803 }
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
804
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
805 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
806 {
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
807 AVStream *st = s->streams[pkt->stream_index];
5539
445ebebedeaf Do not split audio frames accross pes packets.
bcoudurier
parents: 5538
diff changeset
808 int size = pkt->size;
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
809 uint8_t *buf= pkt->data;
4219
3bfd8604f480 add aud nal unit if not present in h264 bitstream
bcoudurier
parents: 4217
diff changeset
810 uint8_t *data= NULL;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
811 MpegTSWriteStream *ts_st = st->priv_data;
5784
28885ab1ef1c mpegts vbr muxing, activated when muxing rate is not supplied by the
bcoudurier
parents: 5782
diff changeset
812 const uint64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE)*2;
4220
443927a154f1 use delay for subs and dirac too
bcoudurier
parents: 4219
diff changeset
813 int64_t dts = AV_NOPTS_VALUE, pts = AV_NOPTS_VALUE;
443927a154f1 use delay for subs and dirac too
bcoudurier
parents: 4219
diff changeset
814
443927a154f1 use delay for subs and dirac too
bcoudurier
parents: 4219
diff changeset
815 if (pkt->pts != AV_NOPTS_VALUE)
443927a154f1 use delay for subs and dirac too
bcoudurier
parents: 4219
diff changeset
816 pts = pkt->pts + delay;
443927a154f1 use delay for subs and dirac too
bcoudurier
parents: 4219
diff changeset
817 if (pkt->dts != AV_NOPTS_VALUE)
443927a154f1 use delay for subs and dirac too
bcoudurier
parents: 4219
diff changeset
818 dts = pkt->dts + delay;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
819
4915
26708ee9a51d ensure first pts is set, according to specs
bcoudurier
parents: 4914
diff changeset
820 if (ts_st->first_pts_check && pts == AV_NOPTS_VALUE) {
26708ee9a51d ensure first pts is set, according to specs
bcoudurier
parents: 4914
diff changeset
821 av_log(s, AV_LOG_ERROR, "first pts value must set\n");
26708ee9a51d ensure first pts is set, according to specs
bcoudurier
parents: 4914
diff changeset
822 return -1;
26708ee9a51d ensure first pts is set, according to specs
bcoudurier
parents: 4914
diff changeset
823 }
26708ee9a51d ensure first pts is set, according to specs
bcoudurier
parents: 4914
diff changeset
824 ts_st->first_pts_check = 0;
26708ee9a51d ensure first pts is set, according to specs
bcoudurier
parents: 4914
diff changeset
825
4921
fa21da521576 write a single pes for video frames, some proprietary player needs it
bcoudurier
parents: 4915
diff changeset
826 if (st->codec->codec_id == CODEC_ID_H264) {
5786
7d670040187e In mpegts muxer, search for h264 aud nal, it might not be the first nal.
bcoudurier
parents: 5784
diff changeset
827 const uint8_t *p = buf, *buf_end = p+size;
7d670040187e In mpegts muxer, search for h264 aud nal, it might not be the first nal.
bcoudurier
parents: 5784
diff changeset
828 uint32_t state = -1;
7d670040187e In mpegts muxer, search for h264 aud nal, it might not be the first nal.
bcoudurier
parents: 5784
diff changeset
829
4219
3bfd8604f480 add aud nal unit if not present in h264 bitstream
bcoudurier
parents: 4217
diff changeset
830 if (pkt->size < 5 || AV_RB32(pkt->data) != 0x0000001) {
5786
7d670040187e In mpegts muxer, search for h264 aud nal, it might not be the first nal.
bcoudurier
parents: 5784
diff changeset
831 av_log(s, AV_LOG_ERROR, "h264 bitstream malformated, "
7d670040187e In mpegts muxer, search for h264 aud nal, it might not be the first nal.
bcoudurier
parents: 5784
diff changeset
832 "no startcode found, use -vbsf h264_mp4toannexb\n");
4219
3bfd8604f480 add aud nal unit if not present in h264 bitstream
bcoudurier
parents: 4217
diff changeset
833 return -1;
3bfd8604f480 add aud nal unit if not present in h264 bitstream
bcoudurier
parents: 4217
diff changeset
834 }
5786
7d670040187e In mpegts muxer, search for h264 aud nal, it might not be the first nal.
bcoudurier
parents: 5784
diff changeset
835
7d670040187e In mpegts muxer, search for h264 aud nal, it might not be the first nal.
bcoudurier
parents: 5784
diff changeset
836 do {
7d670040187e In mpegts muxer, search for h264 aud nal, it might not be the first nal.
bcoudurier
parents: 5784
diff changeset
837 p = ff_find_start_code(p, buf_end, &state);
7d670040187e In mpegts muxer, search for h264 aud nal, it might not be the first nal.
bcoudurier
parents: 5784
diff changeset
838 //av_log(s, AV_LOG_INFO, "nal %d\n", state & 0x1f);
7d670040187e In mpegts muxer, search for h264 aud nal, it might not be the first nal.
bcoudurier
parents: 5784
diff changeset
839 } while (p < buf_end && (state & 0x1f) != 9 &&
7d670040187e In mpegts muxer, search for h264 aud nal, it might not be the first nal.
bcoudurier
parents: 5784
diff changeset
840 (state & 0x1f) != 5 && (state & 0x1f) != 1);
7d670040187e In mpegts muxer, search for h264 aud nal, it might not be the first nal.
bcoudurier
parents: 5784
diff changeset
841
7d670040187e In mpegts muxer, search for h264 aud nal, it might not be the first nal.
bcoudurier
parents: 5784
diff changeset
842 if ((state & 0x1f) != 9) { // AUD NAL
4219
3bfd8604f480 add aud nal unit if not present in h264 bitstream
bcoudurier
parents: 4217
diff changeset
843 data = av_malloc(pkt->size+6);
3bfd8604f480 add aud nal unit if not present in h264 bitstream
bcoudurier
parents: 4217
diff changeset
844 if (!data)
3bfd8604f480 add aud nal unit if not present in h264 bitstream
bcoudurier
parents: 4217
diff changeset
845 return -1;
3bfd8604f480 add aud nal unit if not present in h264 bitstream
bcoudurier
parents: 4217
diff changeset
846 memcpy(data+6, pkt->data, pkt->size);
3bfd8604f480 add aud nal unit if not present in h264 bitstream
bcoudurier
parents: 4217
diff changeset
847 AV_WB32(data, 0x00000001);
3bfd8604f480 add aud nal unit if not present in h264 bitstream
bcoudurier
parents: 4217
diff changeset
848 data[4] = 0x09;
6304
50b1c5de4b71 In mpegts muxer, fix rbsp trailing bits in AUD nal, fixes issue #2122
bcoudurier
parents: 6248
diff changeset
849 data[5] = 0xf0; // any slice type (0xe) + rbsp stop one bit
4219
3bfd8604f480 add aud nal unit if not present in h264 bitstream
bcoudurier
parents: 4217
diff changeset
850 buf = data;
3bfd8604f480 add aud nal unit if not present in h264 bitstream
bcoudurier
parents: 4217
diff changeset
851 size = pkt->size+6;
3bfd8604f480 add aud nal unit if not present in h264 bitstream
bcoudurier
parents: 4217
diff changeset
852 }
5787
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
853 } else if (st->codec->codec_id == CODEC_ID_AAC) {
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
854 if (pkt->size < 2)
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
855 return -1;
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
856 if ((AV_RB16(pkt->data) & 0xfff0) != 0xfff0) {
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
857 ADTSContext *adts = ts_st->adts;
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
858 int new_size;
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
859 if (!adts) {
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
860 av_log(s, AV_LOG_ERROR, "aac bitstream not in adts format "
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
861 "and extradata missing\n");
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
862 return -1;
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
863 }
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
864 new_size = ADTS_HEADER_SIZE+adts->pce_size+pkt->size;
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
865 if ((unsigned)new_size >= INT_MAX)
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
866 return -1;
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
867 data = av_malloc(new_size);
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
868 if (!data)
5930
08cd1179a20d Replace all remaining occurrences of AVERROR_NOMEM with
stefano
parents: 5910
diff changeset
869 return AVERROR(ENOMEM);
5787
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
870 ff_adts_write_frame_header(adts, data, pkt->size, adts->pce_size);
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
871 if (adts->pce_size) {
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
872 memcpy(data+ADTS_HEADER_SIZE, adts->pce_data, adts->pce_size);
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
873 adts->pce_size = 0;
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
874 }
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
875 memcpy(data+ADTS_HEADER_SIZE+adts->pce_size, pkt->data, pkt->size);
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
876 buf = data;
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
877 size = new_size;
667736f463b3 In mpegts muxer, write adts header if aac bitstream does not contain it
bcoudurier
parents: 5786
diff changeset
878 }
4211
5e5654752973 set pts and dts of pes packets exactly according to specs
bcoudurier
parents: 4209
diff changeset
879 }
5e5654752973 set pts and dts of pes packets exactly according to specs
bcoudurier
parents: 4209
diff changeset
880
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5804
diff changeset
881 if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO) {
4921
fa21da521576 write a single pes for video frames, some proprietary player needs it
bcoudurier
parents: 4915
diff changeset
882 // for video and subtitle, write a single pes packet
fa21da521576 write a single pes for video frames, some proprietary player needs it
bcoudurier
parents: 4915
diff changeset
883 mpegts_write_pes(s, st, buf, size, pts, dts);
4922
2647ebecc2f5 move free data in the video case
bcoudurier
parents: 4921
diff changeset
884 av_free(data);
4921
fa21da521576 write a single pes for video frames, some proprietary player needs it
bcoudurier
parents: 4915
diff changeset
885 return 0;
fa21da521576 write a single pes for video frames, some proprietary player needs it
bcoudurier
parents: 4915
diff changeset
886 }
fa21da521576 write a single pes for video frames, some proprietary player needs it
bcoudurier
parents: 4915
diff changeset
887
5539
445ebebedeaf Do not split audio frames accross pes packets.
bcoudurier
parents: 5538
diff changeset
888 if (ts_st->payload_index + size > DEFAULT_PES_PAYLOAD_SIZE) {
445ebebedeaf Do not split audio frames accross pes packets.
bcoudurier
parents: 5538
diff changeset
889 mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index,
445ebebedeaf Do not split audio frames accross pes packets.
bcoudurier
parents: 5538
diff changeset
890 ts_st->payload_pts, ts_st->payload_dts);
445ebebedeaf Do not split audio frames accross pes packets.
bcoudurier
parents: 5538
diff changeset
891 ts_st->payload_index = 0;
4952
0be83fd54e7a simplify pes timestamps fetching, based on a patch by corp186, chasedouglas at gmail dot com
bcoudurier
parents: 4951
diff changeset
892 }
0be83fd54e7a simplify pes timestamps fetching, based on a patch by corp186, chasedouglas at gmail dot com
bcoudurier
parents: 4951
diff changeset
893
5539
445ebebedeaf Do not split audio frames accross pes packets.
bcoudurier
parents: 5538
diff changeset
894 if (!ts_st->payload_index) {
445ebebedeaf Do not split audio frames accross pes packets.
bcoudurier
parents: 5538
diff changeset
895 ts_st->payload_pts = pts;
445ebebedeaf Do not split audio frames accross pes packets.
bcoudurier
parents: 5538
diff changeset
896 ts_st->payload_dts = dts;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
897 }
4219
3bfd8604f480 add aud nal unit if not present in h264 bitstream
bcoudurier
parents: 4217
diff changeset
898
5539
445ebebedeaf Do not split audio frames accross pes packets.
bcoudurier
parents: 5538
diff changeset
899 memcpy(ts_st->payload + ts_st->payload_index, buf, size);
445ebebedeaf Do not split audio frames accross pes packets.
bcoudurier
parents: 5538
diff changeset
900 ts_st->payload_index += size;
445ebebedeaf Do not split audio frames accross pes packets.
bcoudurier
parents: 5538
diff changeset
901
5804
9f349253996d In mpegts muxer, free adts context and temporary data
bcoudurier
parents: 5803
diff changeset
902 av_free(data);
9f349253996d In mpegts muxer, free adts context and temporary data
bcoudurier
parents: 5803
diff changeset
903
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
904 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
905 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
906
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
907 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
908 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
909 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
910 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
911 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
912 AVStream *st;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
913 int i;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
914
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
915 /* 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
916 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
917 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
918 ts_st = st->priv_data;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
919 if (ts_st->payload_index > 0) {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
920 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
921 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
922 }
5804
9f349253996d In mpegts muxer, free adts context and temporary data
bcoudurier
parents: 5803
diff changeset
923 av_freep(&ts_st->adts);
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
924 }
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 1838
diff changeset
925 put_flush_packet(s->pb);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
926
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
927 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
928 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
929 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
930 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
931 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
932 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
933 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
934
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
935 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
936 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
937
1167
d89d7ef290da give AVInput/OutputFormat structs consistent names
mru
parents: 1124
diff changeset
938 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
939 "mpegts",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3420
diff changeset
940 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
941 "video/x-mpegts",
3420
8d4e4f414fc7 add pretty common .m2t as ts extension
bcoudurier
parents: 3419
diff changeset
942 "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
943 sizeof(MpegTSWrite),
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
944 CODEC_ID_MP2,
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
945 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
946 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
947 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
948 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
949 };