annotate mpegtsenc.c @ 2841:a41a1ec2213c libavformat

use proper url_is_streamed() API instead of messing with ByteIOContext internal is_streamed field
author aurel
date Wed, 19 Dec 2007 23:26:18 +0000
parents d52c718e83f9
children c31c50af40c5
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
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
3 * Copyright (c) 2003 Fabrice Bellard.
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
16 *
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1169
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 887
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
20 */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
21 #include "avformat.h"
996
2177aea28f4f generic crc calculation code
michael
parents: 902
diff changeset
22 #include "crc.h"
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
23 #include "mpegts.h"
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
24
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
25 /* 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
26
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
27 /*********************************************/
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
28 /* 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
29
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
30 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
31 int pid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
32 int cc;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
33 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
34 void *opaque;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
35 } MpegTSSection;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
36
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
37 /* 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
38 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
39 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
40 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
41 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
42 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
43 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
44 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
45
996
2177aea28f4f generic crc calculation code
michael
parents: 902
diff changeset
46 crc = bswap_32(av_crc(av_crc04C11DB7, -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
47 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
48 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
49 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
50 buf[len - 1] = (crc) & 0xff;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
51
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
52 /* 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
53 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
54 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
55 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
56 q = packet;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
57 *q++ = 0x47;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
58 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
59 if (first)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
60 b |= 0x40;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
61 *q++ = b;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
62 *q++ = s->pid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
63 s->cc = (s->cc + 1) & 0xf;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
64 *q++ = 0x10 | s->cc;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
65 if (first)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
66 *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
67 len1 = TS_PACKET_SIZE - (q - packet);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
68 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
69 len1 = len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
70 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
71 q += len1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
72 /* 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
73 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
74 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
75 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
76
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
77 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
78
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
79 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
80 len -= len1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
81 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
82 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
83
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
84 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
85 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
86 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
87 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
88 *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
89 *q++ = val;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
90 *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
91 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
92
1124
d3aff2c607f9 Add const to (mostly) char* and make some functions static, which aren't used
diego
parents: 996
diff changeset
93 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
94 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
95 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
96 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
97 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
98 unsigned int tot_len;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
99
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
100 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
101 /* 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
102 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
103 return -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
104
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
105 q = section;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
106 *q++ = tid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
107 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
108 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
109 *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
110 *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
111 *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
112 memcpy(q, buf, len);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
113
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
114 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
115 return 0;
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
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 /* mpegts writer */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
120
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
121 #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
122 #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
123 #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
124 #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
125
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
126 /* 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
127 #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
128 #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
129 #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
130
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
131 /* 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
132 #define DEFAULT_PES_HEADER_FREQ 16
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
133 #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
134
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
135 /* 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
136 #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
137 #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
138 #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
139
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
140 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
141 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
142 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
143 int cc;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
144 int payload_index;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
145 int64_t payload_pts;
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
146 int64_t payload_dts;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
147 uint8_t payload[DEFAULT_PES_PAYLOAD_SIZE];
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
148 } MpegTSWriteStream;
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 typedef struct MpegTSService {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
151 MpegTSSection pmt; /* MPEG2 pmt table context */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
152 int sid; /* service ID */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
153 char *name;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
154 char *provider_name;
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
155 int pcr_pid;
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
156 int pcr_packet_count;
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
157 int pcr_packet_freq;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
158 } MpegTSService;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
159
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
160 typedef struct MpegTSWrite {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
161 MpegTSSection pat; /* MPEG2 pat table */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
162 MpegTSSection sdt; /* MPEG2 sdt table context */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
163 MpegTSService **services;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
164 int sdt_packet_count;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
165 int sdt_packet_freq;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
166 int pat_packet_count;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
167 int pat_packet_freq;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
168 int nb_services;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
169 int onid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
170 int tsid;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
171 } MpegTSWrite;
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 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
174 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
175 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
176 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
177 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
178 int i;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
179
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
180 q = data;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
181 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
182 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
183 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
184 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
185 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
186 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
187 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
188 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
189
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
190 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
191 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
192 // 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
193 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
194 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
195
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
196 q = data;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
197 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
198
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
199 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
200 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
201
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
202 /* 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
203
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
204 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
205 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
206 program_info_length_ptr[1] = val;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
207
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
208 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
209 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
210 MpegTSWriteStream *ts_st = st->priv_data;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 785
diff changeset
211 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
212 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
213 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
214 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
215 break;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents: 250
diff changeset
216 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
217 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
218 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
219 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
220 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
221 break;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents: 250
diff changeset
222 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
223 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
224 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
225 break;
313
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents: 250
diff changeset
226 case CODEC_ID_AAC:
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_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
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_AC3:
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_AUDIO_AC3;
622892a75ddb support more codecs in MPEG-TS patch by (mru at kth dot se (M«©ns Rullg«©rd))
michael
parents: 250
diff changeset
231 break;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
232 default:
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
233 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
234 break;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
235 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
236 *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
237 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
238 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
239 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
240
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
241 /* 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
242 switch(st->codec->codec_type) {
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
243 case CODEC_TYPE_AUDIO:
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
244 if (strlen(st->language) == 3) {
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
245 *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
246 *q++ = 4;
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
247 *q++ = st->language[0];
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
248 *q++ = st->language[1];
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
249 *q++ = st->language[2];
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
250 *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
251 }
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
252 break;
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
253 case CODEC_TYPE_SUBTITLE:
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
254 {
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
255 const char *language;
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
256 language = st->language;
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
257 if (strlen(language) != 3)
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
258 language = "eng";
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
259 *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
260 *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
261 *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
262 *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
263 *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
264 *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
265 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
266 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
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;
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
269 }
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
270
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
271 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
272 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
273 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
274 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
275 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
276 data, q - data);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
277 }
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
278
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
279 /* 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
280 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
281 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
282 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
283 int len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
284
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
285 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
286 if (!str)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
287 len = 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
288 else
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
289 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
290 *q++ = len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
291 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
292 q += len;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
293 *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
294 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
295
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
296 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
297 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
298 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
299 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
300 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
301 int i, running_status, free_ca_mode, val;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
302
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
303 q = data;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
304 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
305 *q++ = 0xff;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
306 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
307 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
308 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
309 *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
310 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
311 q += 2;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
312 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
313 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
314
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
315 /* 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
316 *q++ = 0x48;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
317 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
318 q++;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
319 *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
320 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
321 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
322 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
323
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
324 /* fill descriptor length */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
325 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
326 (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
327 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
328 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
329 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
330 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
331 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
332 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
333
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
334 static MpegTSService *mpegts_add_service(MpegTSWrite *ts,
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
335 int sid,
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
336 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
337 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
338 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
339 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
340
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
341 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
342 if (!service)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
343 return NULL;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
344 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
345 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
346 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
347 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
348 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
349 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
350 return service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
351 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
352
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
353 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
354 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
355 AVFormatContext *ctx = s->opaque;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 1838
diff changeset
356 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
357 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
358
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
359 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
360 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
361 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
362 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
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 AVStream *st;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
365 int i, total_bit_rate;
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
366 const char *service_name;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
367
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
368 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
369 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
370 /* allocate a single DVB service */
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
371 service_name = s->title;
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
372 if (service_name[0] == '\0')
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
373 service_name = DEFAULT_SERVICE_NAME;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
374 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
375 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
376 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
377 service->pmt.opaque = s;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
378
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
379 ts->pat.pid = PAT_PID;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
380 ts->pat.cc = 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
381 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
382 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
383
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
384 ts->sdt.pid = SDT_PID;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
385 ts->sdt.cc = 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
386 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
387 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
388
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
389 /* 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
390 total_bit_rate = 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
391 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
392 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
393 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
394 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
395 goto fail;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
396 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
397 ts_st->service = service;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
398 ts_st->pid = DEFAULT_START_PID + i;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
399 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
400 ts_st->payload_dts = AV_NOPTS_VALUE;
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
401 /* update PCR pid by using the first video stream */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
402 if (st->codec->codec_type == CODEC_TYPE_VIDEO &&
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
403 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
404 service->pcr_pid = ts_st->pid;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 785
diff changeset
405 total_bit_rate += st->codec->bit_rate;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
406 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
407
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
408 /* 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
409 if (service->pcr_pid == 0x1fff && s->nb_streams > 0) {
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
410 ts_st = s->streams[0]->priv_data;
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
411 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
412 }
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
413
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
414 if (total_bit_rate <= 8 * 1024)
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
415 total_bit_rate = 8 * 1024;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
416 service->pcr_packet_freq = (total_bit_rate * PCR_RETRANS_TIME) /
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
417 (TS_PACKET_SIZE * 8 * 1000);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
418 ts->sdt_packet_freq = (total_bit_rate * SDT_RETRANS_TIME) /
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
419 (TS_PACKET_SIZE * 8 * 1000);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
420 ts->pat_packet_freq = (total_bit_rate * PAT_RETRANS_TIME) /
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
421 (TS_PACKET_SIZE * 8 * 1000);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
422 #if 0
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
423 printf("%d %d %d\n",
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
424 total_bit_rate, ts->sdt_packet_freq, ts->pat_packet_freq);
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
425 #endif
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
426
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
427 /* write info at the start of the file, so that it will be fast to
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
428 find them */
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
429 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
430 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
431 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
432 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
433 }
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 1838
diff changeset
434 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
435
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
436 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
437
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
438 fail:
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
439 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
440 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
441 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
442 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
443 return -1;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
444 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
445
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
446 /* 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
447 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
448 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
449 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
450 int i;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
451
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
452 if (++ts->sdt_packet_count == ts->sdt_packet_freq) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
453 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
454 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
455 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
456 if (++ts->pat_packet_count == ts->pat_packet_freq) {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
457 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
458 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
459 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
460 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
461 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
462 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
463 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
464
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
465 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
466 {
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
467 int val;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
468
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
469 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
470 *q++ = val;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
471 val = (((pts >> 15) & 0x7fff) << 1) | 1;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
472 *q++ = val >> 8;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
473 *q++ = val;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
474 val = (((pts) & 0x7fff) << 1) | 1;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
475 *q++ = val >> 8;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
476 *q++ = val;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
477 }
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
478
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
479 /* NOTE: pes_data contains all the PES packet */
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
480 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
481 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
482 int64_t pts, int64_t dts)
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
483 {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
484 MpegTSWriteStream *ts_st = st->priv_data;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
485 uint8_t buf[TS_PACKET_SIZE];
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
486 uint8_t *q;
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
487 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
488 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
489 int64_t pcr = -1; /* avoid warning */
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
490
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
491 is_start = 1;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
492 while (payload_size > 0) {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
493 retransmit_si_info(s);
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
494
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
495 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
496 if (ts_st->pid == ts_st->service->pcr_pid) {
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
497 ts_st->service->pcr_packet_count++;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
498 if (ts_st->service->pcr_packet_count >=
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
499 ts_st->service->pcr_packet_freq) {
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
500 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
501 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
502 /* XXX: this is incorrect, but at least we have a PCR
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
503 value */
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
504 pcr = pts;
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
505 }
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
506 }
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
507
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
508 /* prepare packet header */
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
509 q = buf;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
510 *q++ = 0x47;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
511 val = (ts_st->pid >> 8);
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
512 if (is_start)
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
513 val |= 0x40;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
514 *q++ = val;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
515 *q++ = ts_st->pid;
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
516 *q++ = 0x10 | ts_st->cc | (write_pcr ? 0x20 : 0);
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
517 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
518 if (write_pcr) {
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
519 *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
520 *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
521 *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
522 *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
523 *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
524 *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
525 *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
526 *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
527 }
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
528 if (is_start) {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
529 /* write PES header */
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
530 *q++ = 0x00;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
531 *q++ = 0x00;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
532 *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
533 private_code = 0;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 785
diff changeset
534 if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
535 *q++ = 0xe0;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 785
diff changeset
536 } else if (st->codec->codec_type == CODEC_TYPE_AUDIO &&
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 785
diff changeset
537 (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
538 st->codec->codec_id == CODEC_ID_MP3)) {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
539 *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
540 } 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
541 *q++ = 0xbd;
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 785
diff changeset
542 if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) {
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
543 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
544 }
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
545 }
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
546 header_len = 0;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
547 flags = 0;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
548 if (pts != AV_NOPTS_VALUE) {
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
549 header_len += 5;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
550 flags |= 0x80;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
551 }
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
552 if (dts != AV_NOPTS_VALUE) {
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
553 header_len += 5;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
554 flags |= 0x40;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
555 }
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
556 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
557 if (private_code != 0)
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
558 len++;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
559 *q++ = len >> 8;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
560 *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
561 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
562 /* data alignment indicator is required for subtitle data */
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 785
diff changeset
563 if (st->codec->codec_type == CODEC_TYPE_SUBTITLE)
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
564 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
565 *q++ = val;
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
566 *q++ = flags;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
567 *q++ = header_len;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
568 if (pts != AV_NOPTS_VALUE) {
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
569 write_pts(q, flags >> 6, pts);
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
570 q += 5;
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
571 }
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
572 if (dts != AV_NOPTS_VALUE) {
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
573 write_pts(q, 1, dts);
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
574 q += 5;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
575 }
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
576 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
577 *q++ = private_code;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
578 is_start = 0;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
579 }
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
580 /* 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
581 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
582 /* 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
583 len = TS_PACKET_SIZE - header_len;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
584 if (len > payload_size)
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
585 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
586 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
587 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
588 /* 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
589 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
590 /* 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
591 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
592 memmove(buf + 4 + afc_len + stuffing_len,
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
593 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
594 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
595 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
596 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
597 } 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
598 /* 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
599 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
600 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
601 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
602 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
603 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
604 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
605 }
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
606 }
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
607 }
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
608 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
609 payload += len;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
610 payload_size -= len;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 1838
diff changeset
611 put_buffer(s->pb, buf, TS_PACKET_SIZE);
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
612 }
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 1838
diff changeset
613 put_flush_packet(s->pb);
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
614 }
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
615
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
616 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
617 {
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
618 AVStream *st = s->streams[pkt->stream_index];
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
619 int size= pkt->size;
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
620 uint8_t *buf= pkt->data;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
621 MpegTSWriteStream *ts_st = st->priv_data;
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
622 int len, max_payload_size;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
623
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 785
diff changeset
624 if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) {
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
625 /* for subtitle, a single PES packet must be generated */
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
626 mpegts_write_pes(s, st, buf, size, pkt->pts, AV_NOPTS_VALUE);
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
627 return 0;
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
628 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
629
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
630 max_payload_size = DEFAULT_PES_PAYLOAD_SIZE;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
631 while (size > 0) {
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
632 len = max_payload_size - ts_st->payload_index;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
633 if (len > size)
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
634 len = size;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
635 memcpy(ts_st->payload + ts_st->payload_index, buf, len);
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
636 buf += len;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
637 size -= len;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
638 ts_st->payload_index += len;
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
639 if (ts_st->payload_pts == AV_NOPTS_VALUE)
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 313
diff changeset
640 ts_st->payload_pts = pkt->pts;
1838
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
641 if (ts_st->payload_dts == AV_NOPTS_VALUE)
d1af40ab8ea5 write DTS, based on patch by Luca Abeni, lucabe72 email it
mru
parents: 1415
diff changeset
642 ts_st->payload_dts = pkt->dts;
785
e277d8928f49 buggy PCR output (just to keep HW decoders happy) - audio and subtitle language support - 'title' stream field sets the service name - fixed TS packet stuffing code - support for subtitle PES packets
bellard
parents: 693
diff changeset
643 if (ts_st->payload_index >= max_payload_size) {
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
644 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
645 ts_st->payload_pts, ts_st->payload_dts);
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
646 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
647 ts_st->payload_dts = AV_NOPTS_VALUE;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
648 ts_st->payload_index = 0;
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
649 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
650 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
651 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
652 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
653
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
654 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
655 {
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
656 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
657 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
658 MpegTSService *service;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
659 AVStream *st;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
660 int i;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
661
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
662 /* 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
663 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
664 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
665 ts_st = st->priv_data;
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
666 if (ts_st->payload_index > 0) {
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
667 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
668 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
669 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
670 }
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 1838
diff changeset
671 put_flush_packet(s->pb);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
672
152
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
673 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
674 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
675 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
676 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
677 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
678 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
679 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
680
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
681 return 0;
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
682 }
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
683
1167
d89d7ef290da give AVInput/OutputFormat structs consistent names
mru
parents: 1124
diff changeset
684 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
685 "mpegts",
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
686 "MPEG2 transport stream format",
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
687 "video/x-mpegts",
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
688 "ts",
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
689 sizeof(MpegTSWrite),
cc03a75cbde4 mpeg ts demux uses DVB SI info and generates correct PTS info - added prototype mpeg ts mux
bellard
parents:
diff changeset
690 CODEC_ID_MP2,
250
2d4dcb1d3e21 generate correct PTS in transport stream - use mpeg2 encoder by default
bellard
parents: 241
diff changeset
691 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
692 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
693 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
694 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
695 };