FFmpeg
webm_chunk.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, Vignesh Venkatasubramanian
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file WebM Chunk Muxer
23  * The chunk muxer enables writing WebM Live chunks where there is a header
24  * chunk, followed by data chunks where each Cluster is written out as a Chunk.
25  */
26 
27 #include "avformat.h"
28 #include "avio.h"
29 #include "avio_internal.h"
30 #include "internal.h"
31 #include "mux.h"
32 
33 #include "libavutil/log.h"
34 #include "libavutil/mem.h"
35 #include "libavutil/opt.h"
36 #include "libavutil/mathematics.h"
37 
38 #define MAX_FILENAME_SIZE 1024
39 
40 typedef struct WebMChunkContext {
41  const AVClass *class;
45  char *http_method;
46  uint64_t duration_written;
47  int64_t prev_pts;
51 
53 {
54  WebMChunkContext *wc = s->priv_data;
55  const AVOutputFormat *oformat;
56  AVFormatContext *oc;
57  AVStream *st, *ost = s->streams[0];
58  AVDictionary *dict = NULL;
59  int ret;
60 
61  // DASH Streams can only have one track per file.
62  if (s->nb_streams != 1)
63  return AVERROR(EINVAL);
64 
65  if (!wc->header_filename) {
66  av_log(s, AV_LOG_ERROR, "No header filename provided\n");
67  return AVERROR(EINVAL);
68  }
69 
71 
72  oformat = av_guess_format("webm", s->url, "video/webm");
73  if (!oformat)
75 
76  ret = avformat_alloc_output_context2(&wc->avf, oformat, NULL, NULL);
77  if (ret < 0)
78  return ret;
79  oc = wc->avf;
80 
82  wc->header_filename = NULL;
83 
84  oc->interrupt_callback = s->interrupt_callback;
85  oc->max_delay = s->max_delay;
86  oc->flags = s->flags & ~AVFMT_FLAG_FLUSH_PACKETS;
87  oc->strict_std_compliance = s->strict_std_compliance;
88  oc->avoid_negative_ts = s->avoid_negative_ts;
89 
90  oc->flush_packets = 0;
91 
92  if ((ret = av_dict_copy(&oc->metadata, s->metadata, 0)) < 0)
93  return ret;
94 
95  st = ff_stream_clone(oc, ost);
96  if (!st)
97  return AVERROR(ENOMEM);
98 
99  if (wc->http_method)
100  if ((ret = av_dict_set(&dict, "method", wc->http_method, 0)) < 0)
101  return ret;
102  ret = s->io_open(s, &oc->pb, oc->url, AVIO_FLAG_WRITE, &dict);
103  av_dict_free(&dict);
104  if (ret < 0)
105  return ret;
106  oc->pb->seekable = 0;
107 
108  if ((ret = av_dict_set_int(&dict, "dash", 1, 0)) < 0 ||
109  (ret = av_dict_set_int(&dict, "cluster_time_limit",
110  wc->chunk_duration, 0)) < 0 ||
111  (ret = av_dict_set_int(&dict, "live", 1, 0)) < 0)
112  goto fail;
113 
114  ret = avformat_init_output(oc, &dict);
115 fail:
116  av_dict_free(&dict);
117  if (ret < 0)
118  return ret;
119 
120  // Copy the timing info back to the original stream
121  // so that the timestamps of the packets are directly usable
123  st->time_base.den);
124 
125  // This ensures that the timestamps will already be properly shifted
126  // when the packets arrive here, so we don't need to shift again.
127  s->avoid_negative_ts = oc->avoid_negative_ts;
131  ffformatcontext(oc)->avoid_negative_ts_status = AVOID_NEGATIVE_TS_DISABLED;
132 
133  return 0;
134 }
135 
137 {
138  WebMChunkContext *wc = s->priv_data;
139  if (!filename) {
140  return AVERROR(EINVAL);
141  }
143  s->url, wc->chunk_index - 1) < 0) {
144  av_log(s, AV_LOG_ERROR, "Invalid chunk filename template '%s'\n", s->url);
145  return AVERROR(EINVAL);
146  }
147  return 0;
148 }
149 
151 {
152  WebMChunkContext *wc = s->priv_data;
153  AVFormatContext *oc = wc->avf;
154  AVStream *st = s->streams[0], *ost = oc->streams[0];
155  int ret;
156 
158  ff_format_io_close(s, &oc->pb);
161  wc->header_written = 1;
162  if (ret < 0)
163  return ret;
164  return 0;
165 }
166 
168 {
169  WebMChunkContext *wc = s->priv_data;
170  AVFormatContext *oc = wc->avf;
171  int ret;
172 
173  ret = avio_open_dyn_buf(&oc->pb);
174  if (ret < 0)
175  return ret;
176  wc->chunk_index++;
177  return 0;
178 }
179 
180 static int chunk_end(AVFormatContext *s, int flush)
181 {
182  WebMChunkContext *wc = s->priv_data;
183  AVFormatContext *oc = wc->avf;
184  int ret;
185  int buffer_size;
186  uint8_t *buffer;
187  AVIOContext *pb;
188  char filename[MAX_FILENAME_SIZE];
190 
191  if (!oc->pb)
192  return 0;
193 
194  if (flush)
195  // Flush the cluster in WebM muxer.
196  av_write_frame(oc, NULL);
197  buffer_size = avio_close_dyn_buf(oc->pb, &buffer);
198  oc->pb = NULL;
199  ret = get_chunk_filename(s, filename);
200  if (ret < 0)
201  goto fail;
202  if (wc->http_method)
203  if ((ret = av_dict_set(&options, "method", wc->http_method, 0)) < 0)
204  goto fail;
205  ret = s->io_open(s, &pb, filename, AVIO_FLAG_WRITE, &options);
207  if (ret < 0)
208  goto fail;
209  avio_write(pb, buffer, buffer_size);
210  ff_format_io_close(s, &pb);
211 fail:
212  av_free(buffer);
213  return (ret < 0) ? ret : 0;
214 }
215 
217 {
218  WebMChunkContext *wc = s->priv_data;
219  AVFormatContext *oc = wc->avf;
220  AVStream *st = s->streams[pkt->stream_index];
221  int ret;
222 
223  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
224  if (wc->prev_pts != AV_NOPTS_VALUE)
226  st->time_base,
227  (AVRational) {1, 1000});
228  wc->prev_pts = pkt->pts;
229  }
230 
231  // For video, a new chunk is started only on key frames. For audio, a new
232  // chunk is started based on chunk_duration. Also, a new chunk is started
233  // unconditionally if there is no currently open chunk.
234  if (!oc->pb || (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
235  (pkt->flags & AV_PKT_FLAG_KEY)) ||
237  wc->duration_written >= wc->chunk_duration)) {
238  wc->duration_written = 0;
239  if ((ret = chunk_end(s, 1)) < 0 || (ret = chunk_start(s)) < 0) {
240  return ret;
241  }
242  }
243 
244  // We only have one stream, so use the non-interleaving av_write_frame.
245  return av_write_frame(oc, pkt);
246 }
247 
249 {
250  WebMChunkContext *wc = s->priv_data;
251  AVFormatContext *oc = wc->avf;
252  int ret;
253 
254  if (!oc->pb) {
255  ret = chunk_start(s);
256  if (ret < 0)
257  return ret;
258  }
259  ret = av_write_trailer(oc);
260  if (ret < 0)
261  return ret;
262  return chunk_end(s, 0);
263 }
264 
266 {
267  WebMChunkContext *wc = s->priv_data;
268 
269  if (!wc->avf)
270  return;
271 
272  if (wc->header_written)
273  ffio_free_dyn_buf(&wc->avf->pb);
274  else
275  ff_format_io_close(s, &wc->avf->pb);
277  wc->avf = NULL;
278 }
279 
280 #define OFFSET(x) offsetof(WebMChunkContext, x)
281 static const AVOption options[] = {
282  { "chunk_start_index", "start index of the chunk", OFFSET(chunk_index), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
283  { "header", "filename of the header where the initialization data will be written", OFFSET(header_filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
284  { "audio_chunk_duration", "duration of each chunk in milliseconds", OFFSET(chunk_duration), AV_OPT_TYPE_INT, {.i64 = 5000}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
285  { "method", "set the HTTP method", OFFSET(http_method), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
286  { NULL },
287 };
288 
289 static const AVClass webm_chunk_class = {
290  .class_name = "WebM Chunk Muxer",
291  .item_name = av_default_item_name,
292  .option = options,
293  .version = LIBAVUTIL_VERSION_INT,
294 };
295 
297  .p.name = "webm_chunk",
298  .p.long_name = NULL_IF_CONFIG_SMALL("WebM Chunk Muxer"),
299  .p.mime_type = "video/webm",
300  .p.extensions = "chk",
303  .p.priv_class = &webm_chunk_class,
304  .priv_data_size = sizeof(WebMChunkContext),
310 };
webm_chunk_class
static const AVClass webm_chunk_class
Definition: webm_chunk.c:289
chunk_start
static int chunk_start(AVFormatContext *s)
Definition: webm_chunk.c:167
AVOutputFormat::name
const char * name
Definition: avformat.h:510
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
webm_chunk_write_header
static int webm_chunk_write_header(AVFormatContext *s)
Definition: webm_chunk.c:150
WebMChunkContext::chunk_index
int chunk_index
Definition: webm_chunk.c:44
ffformatcontext
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition: internal.h:188
WebMChunkContext::prev_pts
int64_t prev_pts
Definition: webm_chunk.c:47
WebMChunkContext::http_method
char * http_method
Definition: webm_chunk.c:45
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1323
deinit
static void deinit(AVFormatContext *s)
Definition: chromaprint.c:50
AVFormatContext::strict_std_compliance
int strict_std_compliance
Allow non-standard and experimental extension.
Definition: avformat.h:1612
AVOption
AVOption.
Definition: opt.h:346
ff_webm_chunk_muxer
const FFOutputFormat ff_webm_chunk_muxer
Definition: webm_chunk.c:296
mathematics.h
AVDictionary
Definition: dict.c:34
avformat_init_output
av_warn_unused_result int avformat_init_output(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and initialize the codec, but do not write the header.
Definition: mux.c:466
av_get_frame_filename
int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
Definition: utils.c:354
WebMChunkContext
Definition: webm_chunk.c:40
ost
static AVStream * ost
Definition: vaapi_transcode.c:42
get_chunk_filename
static int get_chunk_filename(AVFormatContext *s, char filename[MAX_FILENAME_SIZE])
Definition: webm_chunk.c:136
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:579
FFOutputFormat::p
AVOutputFormat p
The public AVOutputFormat.
Definition: mux.h:65
AVFormatContext::interrupt_callback
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1528
webm_chunk_write_trailer
static int webm_chunk_write_trailer(AVFormatContext *s)
Definition: webm_chunk.c:248
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: avformat.c:853
AVFormatContext::flush_packets
int flush_packets
Flush the I/O context after each packet.
Definition: avformat.h:1714
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:417
fail
#define fail()
Definition: checkasm.h:179
AVRational::num
int num
Numerator.
Definition: rational.h:59
avio_close_dyn_buf
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1407
chunk_end
static int chunk_end(AVFormatContext *s, int flush)
Definition: webm_chunk.c:180
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AVFormatContext::metadata
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1490
WebMChunkContext::header_filename
char * header_filename
Definition: webm_chunk.c:42
avio_open_dyn_buf
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1362
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1406
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:618
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
webm_chunk_write_packet
static int webm_chunk_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: webm_chunk.c:216
avformat_write_header
av_warn_unused_result int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
Definition: mux.c:487
AVFMT_NEEDNUMBER
#define AVFMT_NEEDNUMBER
Needs 'd' in filename.
Definition: avformat.h:469
AVFormatContext
Format I/O context.
Definition: avformat.h:1255
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:766
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
AVFMT_AVOID_NEG_TS_DISABLED
#define AVFMT_AVOID_NEG_TS_DISABLED
Do not shift timestamps even when they are negative.
Definition: avformat.h:1644
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:782
NULL
#define NULL
Definition: coverity.c:32
write_trailer
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:101
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition: avformat.h:1297
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts.c:368
FFOutputFormat
Definition: mux.h:61
av_write_frame
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file.
Definition: mux.c:1233
AV_OPT_FLAG_ENCODING_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Definition: opt.h:269
webm_chunk_init
static int webm_chunk_init(AVFormatContext *s)
Definition: webm_chunk.c:52
options
static const AVOption options[]
Definition: webm_chunk.c:281
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:366
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
AVIOContext::seekable
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:261
AVFormatContext::url
char * url
input or output URL.
Definition: avformat.h:1371
avio.h
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:468
ff_format_io_close
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition: avformat.c:944
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:201
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:530
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:223
av_write_trailer
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
Definition: mux.c:1295
log.h
AVFMT_GLOBALHEADER
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:478
AVOutputFormat
Definition: avformat.h:509
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:517
avio_internal.h
AVERROR_MUXER_NOT_FOUND
#define AVERROR_MUXER_NOT_FOUND
Muxer not found.
Definition: error.h:62
AVFormatContext::avoid_negative_ts
int avoid_negative_ts
Avoid negative timestamps during muxing.
Definition: avformat.h:1642
AVFormatContext::max_delay
int max_delay
Definition: avformat.h:1400
write_packet
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
Definition: ffmpeg_mux.c:209
AVFMT_TS_NONSTRICT
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:491
ffio_free_dyn_buf
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
Definition: aviobuf.c:1435
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:743
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
avformat.h
WebMChunkContext::header_written
int header_written
Definition: webm_chunk.c:49
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
FFFormatContext::avoid_negative_ts_status
enum FFFormatContext::@328 avoid_negative_ts_status
Whether the timestamp shift offset has already been determined.
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
avformat_free_context
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition: avformat.c:141
AVPacket::stream_index
int stream_index
Definition: packet.h:526
av_dict_set_int
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
Definition: dict.c:167
webm_chunk_deinit
static void webm_chunk_deinit(AVFormatContext *s)
Definition: webm_chunk.c:265
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
av_guess_format
const AVOutputFormat * av_guess_format(const char *short_name, const char *filename, const char *mime_type)
Return the output format in the list of registered output formats which best matches the provided par...
Definition: format.c:79
mem.h
MAX_FILENAME_SIZE
#define MAX_FILENAME_SIZE
Definition: webm_chunk.c:38
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
ff_stream_clone
AVStream * ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src)
Create a new stream and copy to it all parameters from a source stream, with the exception of the ind...
Definition: avformat.c:306
AVPacket
This structure stores compressed data.
Definition: packet.h:501
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:88
av_dict_copy
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:237
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVFMT_FLAG_FLUSH_PACKETS
#define AVFMT_FLAG_FLUSH_PACKETS
Flush the AVIOContext every packet.
Definition: avformat.h:1416
OFFSET
#define OFFSET(x)
Definition: webm_chunk.c:280
WebMChunkContext::avf
AVFormatContext * avf
Definition: webm_chunk.c:48
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:239
write_header
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:345
avformat_alloc_output_context2
int avformat_alloc_output_context2(AVFormatContext **ctx, const AVOutputFormat *oformat, const char *format_name, const char *filename)
Allocate an AVFormatContext for an output format.
Definition: mux.c:94
AVStream::pts_wrap_bits
int pts_wrap_bits
Number of bits in timestamps.
Definition: avformat.h:918
ff_format_set_url
void ff_format_set_url(AVFormatContext *s, char *url)
Set AVFormatContext url field to the provided pointer.
Definition: avformat.c:937
FFStream::lowest_ts_allowed
int64_t lowest_ts_allowed
This is the lowest ts allowed in this track; it may be set by the muxer during init or write_header a...
Definition: internal.h:315
WebMChunkContext::duration_written
uint64_t duration_written
Definition: webm_chunk.c:46
WebMChunkContext::chunk_duration
int chunk_duration
Definition: webm_chunk.c:43
mux.h
FFFormatContext::avoid_negative_ts_use_pts
int avoid_negative_ts_use_pts
Definition: internal.h:148