3 * Copyright (c) 2003 The FFmpeg Project
5 * This demuxer will generate a 1 byte extradata for VP6F content.
7 * - upper 4 bits: difference between encoded width and visible width
8 * - lower 4 bits: difference between encoded height and visible height
10 * This file is part of FFmpeg.
12 * FFmpeg is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * FFmpeg is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with FFmpeg; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 #include "libavutil/avstring.h"
28 #include "libavutil/channel_layout.h"
29 #include "libavutil/dict.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/intfloat.h"
32 #include "libavutil/mathematics.h"
33 #include "libavutil/time_internal.h"
34 #include "libavcodec/bytestream.h"
37 #include "avio_internal.h"
40 #define VALIDATE_INDEX_TS_THRESH 2500
42 #define RESYNC_BUFFER_SIZE (1<<20)
44 typedef struct FLVContext {
45 const AVClass *class; ///< Class for private options.
46 int trust_metadata; ///< configure streams according onMetaData
47 int trust_datasize; ///< trust data size of FLVTag
48 int dump_full_metadata; ///< Dump full metadata of the onMetadata
49 int wrong_dts; ///< wrong dts due to negative cts
50 uint8_t *new_extradata[FLV_STREAM_TYPE_NB];
51 int new_extradata_size[FLV_STREAM_TYPE_NB];
62 uint8_t resync_buffer[2*RESYNC_BUFFER_SIZE];
67 int last_keyframe_stream_index;
69 int64_t video_bit_rate;
70 int64_t audio_bit_rate;
71 int64_t *keyframe_times;
72 int64_t *keyframe_filepositions;
81 typedef struct amf_date {
86 static int probe(const AVProbeData *p, int live)
88 const uint8_t *d = p->buf;
89 unsigned offset = AV_RB32(d + 5);
94 d[3] < 5 && d[5] == 0 &&
95 offset + 100 < p->buf_size &&
97 int is_live = !memcmp(d + offset + 40, "NGINX RTMP", 10);
100 return AVPROBE_SCORE_MAX;
105 static int flv_probe(const AVProbeData *p)
110 static int live_flv_probe(const AVProbeData *p)
115 static int kux_probe(const AVProbeData *p)
117 const uint8_t *d = p->buf;
124 return AVPROBE_SCORE_EXTENSION + 1;
129 static void add_keyframes_index(AVFormatContext *s)
131 FLVContext *flv = s->priv_data;
132 AVStream *stream = NULL;
135 if (flv->last_keyframe_stream_index < 0) {
136 av_log(s, AV_LOG_DEBUG, "keyframe stream hasn't been created\n");
140 av_assert0(flv->last_keyframe_stream_index <= s->nb_streams);
141 stream = s->streams[flv->last_keyframe_stream_index];
143 if (stream->nb_index_entries == 0) {
144 for (i = 0; i < flv->keyframe_count; i++) {
145 av_log(s, AV_LOG_TRACE, "keyframe filepositions = %"PRId64" times = %"PRId64"\n",
146 flv->keyframe_filepositions[i], flv->keyframe_times[i] * 1000);
147 av_add_index_entry(stream, flv->keyframe_filepositions[i],
148 flv->keyframe_times[i] * 1000, 0, 0, AVINDEX_KEYFRAME);
151 av_log(s, AV_LOG_WARNING, "Skipping duplicate index\n");
153 if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
154 av_freep(&flv->keyframe_times);
155 av_freep(&flv->keyframe_filepositions);
156 flv->keyframe_count = 0;
160 static AVStream *create_stream(AVFormatContext *s, int codec_type)
162 FLVContext *flv = s->priv_data;
163 AVStream *st = avformat_new_stream(s, NULL);
166 st->codecpar->codec_type = codec_type;
167 if (s->nb_streams>=3 ||( s->nb_streams==2
168 && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE
169 && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE
170 && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_DATA
171 && s->streams[1]->codecpar->codec_type != AVMEDIA_TYPE_DATA))
172 s->ctx_flags &= ~AVFMTCTX_NOHEADER;
173 if (codec_type == AVMEDIA_TYPE_AUDIO) {
174 st->codecpar->bit_rate = flv->audio_bit_rate;
175 flv->missing_streams &= ~FLV_HEADER_FLAG_HASAUDIO;
177 if (codec_type == AVMEDIA_TYPE_VIDEO) {
178 st->codecpar->bit_rate = flv->video_bit_rate;
179 flv->missing_streams &= ~FLV_HEADER_FLAG_HASVIDEO;
180 st->avg_frame_rate = flv->framerate;
184 avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
185 flv->last_keyframe_stream_index = s->nb_streams - 1;
186 add_keyframes_index(s);
190 static int flv_same_audio_codec(AVCodecParameters *apar, int flags)
192 int bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
193 int flv_codecid = flags & FLV_AUDIO_CODECID_MASK;
196 if (!apar->codec_id && !apar->codec_tag)
199 if (apar->bits_per_coded_sample != bits_per_coded_sample)
202 switch (flv_codecid) {
203 // no distinction between S16 and S8 PCM codec flags
204 case FLV_CODECID_PCM:
205 codec_id = bits_per_coded_sample == 8
208 : AV_CODEC_ID_PCM_S16BE;
210 : AV_CODEC_ID_PCM_S16LE;
212 return codec_id == apar->codec_id;
213 case FLV_CODECID_PCM_LE:
214 codec_id = bits_per_coded_sample == 8
216 : AV_CODEC_ID_PCM_S16LE;
217 return codec_id == apar->codec_id;
218 case FLV_CODECID_AAC:
219 return apar->codec_id == AV_CODEC_ID_AAC;
220 case FLV_CODECID_ADPCM:
221 return apar->codec_id == AV_CODEC_ID_ADPCM_SWF;
222 case FLV_CODECID_SPEEX:
223 return apar->codec_id == AV_CODEC_ID_SPEEX;
224 case FLV_CODECID_MP3:
225 return apar->codec_id == AV_CODEC_ID_MP3;
226 case FLV_CODECID_NELLYMOSER_8KHZ_MONO:
227 case FLV_CODECID_NELLYMOSER_16KHZ_MONO:
228 case FLV_CODECID_NELLYMOSER:
229 return apar->codec_id == AV_CODEC_ID_NELLYMOSER;
230 case FLV_CODECID_PCM_MULAW:
231 return apar->sample_rate == 8000 &&
232 apar->codec_id == AV_CODEC_ID_PCM_MULAW;
233 case FLV_CODECID_PCM_ALAW:
234 return apar->sample_rate == 8000 &&
235 apar->codec_id == AV_CODEC_ID_PCM_ALAW;
237 return apar->codec_tag == (flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
241 static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream,
242 AVCodecParameters *apar, int flv_codecid)
244 switch (flv_codecid) {
245 // no distinction between S16 and S8 PCM codec flags
246 case FLV_CODECID_PCM:
247 apar->codec_id = apar->bits_per_coded_sample == 8
250 : AV_CODEC_ID_PCM_S16BE;
252 : AV_CODEC_ID_PCM_S16LE;
255 case FLV_CODECID_PCM_LE:
256 apar->codec_id = apar->bits_per_coded_sample == 8
258 : AV_CODEC_ID_PCM_S16LE;
260 case FLV_CODECID_AAC:
261 apar->codec_id = AV_CODEC_ID_AAC;
263 case FLV_CODECID_ADPCM:
264 apar->codec_id = AV_CODEC_ID_ADPCM_SWF;
266 case FLV_CODECID_SPEEX:
267 apar->codec_id = AV_CODEC_ID_SPEEX;
268 apar->sample_rate = 16000;
270 case FLV_CODECID_MP3:
271 apar->codec_id = AV_CODEC_ID_MP3;
272 astream->need_parsing = AVSTREAM_PARSE_FULL;
274 case FLV_CODECID_NELLYMOSER_8KHZ_MONO:
275 // in case metadata does not otherwise declare samplerate
276 apar->sample_rate = 8000;
277 apar->codec_id = AV_CODEC_ID_NELLYMOSER;
279 case FLV_CODECID_NELLYMOSER_16KHZ_MONO:
280 apar->sample_rate = 16000;
281 apar->codec_id = AV_CODEC_ID_NELLYMOSER;
283 case FLV_CODECID_NELLYMOSER:
284 apar->codec_id = AV_CODEC_ID_NELLYMOSER;
286 case FLV_CODECID_PCM_MULAW:
287 apar->sample_rate = 8000;
288 apar->codec_id = AV_CODEC_ID_PCM_MULAW;
290 case FLV_CODECID_PCM_ALAW:
291 apar->sample_rate = 8000;
292 apar->codec_id = AV_CODEC_ID_PCM_ALAW;
295 avpriv_request_sample(s, "Audio codec (%x)",
296 flv_codecid >> FLV_AUDIO_CODECID_OFFSET);
297 apar->codec_tag = flv_codecid >> FLV_AUDIO_CODECID_OFFSET;
301 static int flv_same_video_codec(AVCodecParameters *vpar, int flags)
303 int flv_codecid = flags & FLV_VIDEO_CODECID_MASK;
305 if (!vpar->codec_id && !vpar->codec_tag)
308 switch (flv_codecid) {
309 case FLV_CODECID_H263:
310 return vpar->codec_id == AV_CODEC_ID_FLV1;
311 case FLV_CODECID_SCREEN:
312 return vpar->codec_id == AV_CODEC_ID_FLASHSV;
313 case FLV_CODECID_SCREEN2:
314 return vpar->codec_id == AV_CODEC_ID_FLASHSV2;
315 case FLV_CODECID_VP6:
316 return vpar->codec_id == AV_CODEC_ID_VP6F;
317 case FLV_CODECID_VP6A:
318 return vpar->codec_id == AV_CODEC_ID_VP6A;
319 case FLV_CODECID_H264:
320 return vpar->codec_id == AV_CODEC_ID_H264;
322 return vpar->codec_tag == flv_codecid;
326 static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream,
327 int flv_codecid, int read)
330 AVCodecParameters *par = vstream->codecpar;
331 enum AVCodecID old_codec_id = vstream->codecpar->codec_id;
332 switch (flv_codecid) {
333 case FLV_CODECID_H263:
334 par->codec_id = AV_CODEC_ID_FLV1;
336 case FLV_CODECID_REALH263:
337 par->codec_id = AV_CODEC_ID_H263;
338 break; // Really mean it this time
339 case FLV_CODECID_SCREEN:
340 par->codec_id = AV_CODEC_ID_FLASHSV;
342 case FLV_CODECID_SCREEN2:
343 par->codec_id = AV_CODEC_ID_FLASHSV2;
345 case FLV_CODECID_VP6:
346 par->codec_id = AV_CODEC_ID_VP6F;
347 case FLV_CODECID_VP6A:
348 if (flv_codecid == FLV_CODECID_VP6A)
349 par->codec_id = AV_CODEC_ID_VP6A;
351 if (par->extradata_size != 1) {
352 ff_alloc_extradata(par, 1);
355 par->extradata[0] = avio_r8(s->pb);
359 ret = 1; // 1 byte body size adjustment for flv_read_packet()
361 case FLV_CODECID_H264:
362 par->codec_id = AV_CODEC_ID_H264;
363 vstream->need_parsing = AVSTREAM_PARSE_HEADERS;
364 ret = 3; // not 4, reading packet type will consume one byte
366 case FLV_CODECID_MPEG4:
367 par->codec_id = AV_CODEC_ID_MPEG4;
371 avpriv_request_sample(s, "Video codec (%x)", flv_codecid);
372 par->codec_tag = flv_codecid;
375 if (!vstream->internal->need_context_update && par->codec_id != old_codec_id) {
376 avpriv_request_sample(s, "Changing the codec id midstream");
377 return AVERROR_PATCHWELCOME;
383 static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize)
385 int length = avio_rb16(ioc);
386 if (length >= buffsize) {
387 avio_skip(ioc, length);
391 avio_read(ioc, buffer, length);
393 buffer[length] = '\0';
398 static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, int64_t max_pos)
400 FLVContext *flv = s->priv_data;
401 unsigned int timeslen = 0, fileposlen = 0, i;
403 int64_t *times = NULL;
404 int64_t *filepositions = NULL;
405 int ret = AVERROR(ENOSYS);
406 int64_t initial_pos = avio_tell(ioc);
408 if (flv->keyframe_count > 0) {
409 av_log(s, AV_LOG_DEBUG, "keyframes have been parsed\n");
412 av_assert0(!flv->keyframe_times);
413 av_assert0(!flv->keyframe_filepositions);
415 if (s->flags & AVFMT_FLAG_IGNIDX)
418 while (avio_tell(ioc) < max_pos - 2 &&
419 amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
420 int64_t **current_array;
421 unsigned int arraylen;
423 // Expect array object in context
424 if (avio_r8(ioc) != AMF_DATA_TYPE_ARRAY)
427 arraylen = avio_rb32(ioc);
431 if (!strcmp(KEYFRAMES_TIMESTAMP_TAG , str_val) && !times) {
432 current_array = ×
434 } else if (!strcmp(KEYFRAMES_BYTEOFFSET_TAG, str_val) &&
436 current_array = &filepositions;
437 fileposlen = arraylen;
439 // unexpected metatag inside keyframes, will not use such
440 // metadata for indexing
443 if (!(*current_array = av_mallocz(sizeof(**current_array) * arraylen))) {
444 ret = AVERROR(ENOMEM);
448 for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++) {
449 if (avio_r8(ioc) != AMF_DATA_TYPE_NUMBER)
451 current_array[0][i] = av_int2double(avio_rb64(ioc));
453 if (times && filepositions) {
454 // All done, exiting at a position allowing amf_parse_object
455 // to finish parsing the object
461 if (timeslen == fileposlen && fileposlen>1 && max_pos <= filepositions[0]) {
462 for (i = 0; i < FFMIN(2,fileposlen); i++) {
463 flv->validate_index[i].pos = filepositions[i];
464 flv->validate_index[i].dts = times[i] * 1000;
465 flv->validate_count = i + 1;
467 flv->keyframe_times = times;
468 flv->keyframe_filepositions = filepositions;
469 flv->keyframe_count = timeslen;
471 filepositions = NULL;
474 av_log(s, AV_LOG_WARNING, "Invalid keyframes object, skipping.\n");
479 av_freep(&filepositions);
480 avio_seek(ioc, initial_pos, SEEK_SET);
484 static int amf_parse_object(AVFormatContext *s, AVStream *astream,
485 AVStream *vstream, const char *key,
486 int64_t max_pos, int depth)
488 AVCodecParameters *apar, *vpar;
489 FLVContext *flv = s->priv_data;
491 AMFDataType amf_type;
498 amf_type = avio_r8(ioc);
501 case AMF_DATA_TYPE_NUMBER:
502 num_val = av_int2double(avio_rb64(ioc));
504 case AMF_DATA_TYPE_BOOL:
505 num_val = avio_r8(ioc);
507 case AMF_DATA_TYPE_STRING:
508 if (amf_get_string(ioc, str_val, sizeof(str_val)) < 0) {
509 av_log(s, AV_LOG_ERROR, "AMF_DATA_TYPE_STRING parsing failed\n");
513 case AMF_DATA_TYPE_OBJECT:
515 (ioc->seekable & AVIO_SEEKABLE_NORMAL) &&
516 !strcmp(KEYFRAMES_TAG, key) && depth == 1)
517 if (parse_keyframes_index(s, ioc,
519 av_log(s, AV_LOG_ERROR, "Keyframe index parsing failed\n");
521 add_keyframes_index(s);
522 while (avio_tell(ioc) < max_pos - 2 &&
523 amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
524 if (amf_parse_object(s, astream, vstream, str_val, max_pos,
526 return -1; // if we couldn't skip, bomb out.
527 if (avio_r8(ioc) != AMF_END_OF_OBJECT) {
528 av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_OBJECT\n");
532 case AMF_DATA_TYPE_NULL:
533 case AMF_DATA_TYPE_UNDEFINED:
534 case AMF_DATA_TYPE_UNSUPPORTED:
535 break; // these take up no additional space
536 case AMF_DATA_TYPE_MIXEDARRAY:
539 avio_skip(ioc, 4); // skip 32-bit max array index
540 while (avio_tell(ioc) < max_pos - 2 &&
541 amf_get_string(ioc, str_val, sizeof(str_val)) > 0)
542 // this is the only case in which we would want a nested
543 // parse to not skip over the object
544 if (amf_parse_object(s, astream, vstream, str_val, max_pos,
548 if (v != AMF_END_OF_OBJECT) {
549 av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_MIXEDARRAY, found %d\n", v);
554 case AMF_DATA_TYPE_ARRAY:
556 unsigned int arraylen, i;
558 arraylen = avio_rb32(ioc);
559 for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++)
560 if (amf_parse_object(s, NULL, NULL, NULL, max_pos,
562 return -1; // if we couldn't skip, bomb out.
565 case AMF_DATA_TYPE_DATE:
566 // timestamp (double) and UTC offset (int16)
567 date.milliseconds = av_int2double(avio_rb64(ioc));
568 date.timezone = avio_rb16(ioc);
570 default: // unsupported type, we couldn't skip
571 av_log(s, AV_LOG_ERROR, "unsupported amf type %d\n", amf_type);
576 apar = astream ? astream->codecpar : NULL;
577 vpar = vstream ? vstream->codecpar : NULL;
579 // stream info doesn't live any deeper than the first object
581 if (amf_type == AMF_DATA_TYPE_NUMBER ||
582 amf_type == AMF_DATA_TYPE_BOOL) {
583 if (!strcmp(key, "duration"))
584 s->duration = num_val * AV_TIME_BASE;
585 else if (!strcmp(key, "videodatarate") &&
586 0 <= (int)(num_val * 1024.0))
587 flv->video_bit_rate = num_val * 1024.0;
588 else if (!strcmp(key, "audiodatarate") &&
589 0 <= (int)(num_val * 1024.0))
590 flv->audio_bit_rate = num_val * 1024.0;
591 else if (!strcmp(key, "datastream")) {
592 AVStream *st = create_stream(s, AVMEDIA_TYPE_SUBTITLE);
594 return AVERROR(ENOMEM);
595 st->codecpar->codec_id = AV_CODEC_ID_TEXT;
596 } else if (!strcmp(key, "framerate")) {
597 flv->framerate = av_d2q(num_val, 1000);
599 vstream->avg_frame_rate = flv->framerate;
600 } else if (flv->trust_metadata) {
601 if (!strcmp(key, "videocodecid") && vpar) {
602 int ret = flv_set_video_codec(s, vstream, num_val, 0);
605 } else if (!strcmp(key, "audiocodecid") && apar) {
606 int id = ((int)num_val) << FLV_AUDIO_CODECID_OFFSET;
607 flv_set_audio_codec(s, astream, apar, id);
608 } else if (!strcmp(key, "audiosamplerate") && apar) {
609 apar->sample_rate = num_val;
610 } else if (!strcmp(key, "audiosamplesize") && apar) {
611 apar->bits_per_coded_sample = num_val;
612 } else if (!strcmp(key, "stereo") && apar) {
613 apar->channels = num_val + 1;
614 apar->channel_layout = apar->channels == 2 ?
615 AV_CH_LAYOUT_STEREO :
617 } else if (!strcmp(key, "width") && vpar) {
618 vpar->width = num_val;
619 } else if (!strcmp(key, "height") && vpar) {
620 vpar->height = num_val;
624 if (amf_type == AMF_DATA_TYPE_STRING) {
625 if (!strcmp(key, "encoder")) {
627 if (1 == sscanf(str_val, "Open Broadcaster Software v0.%d", &version)) {
628 if (version > 0 && version <= 655)
629 flv->broken_sizes = 1;
631 } else if (!strcmp(key, "metadatacreator")) {
632 if ( !strcmp (str_val, "MEGA")
633 || !strncmp(str_val, "FlixEngine", 10))
634 flv->broken_sizes = 1;
639 if (amf_type == AMF_DATA_TYPE_OBJECT && s->nb_streams == 1 &&
640 ((!apar && !strcmp(key, "audiocodecid")) ||
641 (!vpar && !strcmp(key, "videocodecid"))))
642 s->ctx_flags &= ~AVFMTCTX_NOHEADER; //If there is either audio/video missing, codecid will be an empty object
644 if ((!strcmp(key, "duration") ||
645 !strcmp(key, "filesize") ||
646 !strcmp(key, "width") ||
647 !strcmp(key, "height") ||
648 !strcmp(key, "videodatarate") ||
649 !strcmp(key, "framerate") ||
650 !strcmp(key, "videocodecid") ||
651 !strcmp(key, "audiodatarate") ||
652 !strcmp(key, "audiosamplerate") ||
653 !strcmp(key, "audiosamplesize") ||
654 !strcmp(key, "stereo") ||
655 !strcmp(key, "audiocodecid") ||
656 !strcmp(key, "datastream")) && !flv->dump_full_metadata)
659 s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
660 if (amf_type == AMF_DATA_TYPE_BOOL) {
661 av_strlcpy(str_val, num_val > 0 ? "true" : "false",
663 av_dict_set(&s->metadata, key, str_val, 0);
664 } else if (amf_type == AMF_DATA_TYPE_NUMBER) {
665 snprintf(str_val, sizeof(str_val), "%.f", num_val);
666 av_dict_set(&s->metadata, key, str_val, 0);
667 } else if (amf_type == AMF_DATA_TYPE_STRING) {
668 av_dict_set(&s->metadata, key, str_val, 0);
669 } else if (amf_type == AMF_DATA_TYPE_DATE) {
673 time = date.milliseconds / 1000; // to seconds
674 localtime_r(&time, &t);
675 strftime(datestr, sizeof(datestr), "%a, %d %b %Y %H:%M:%S %z", &t);
677 av_dict_set(&s->metadata, key, datestr, 0);
684 #define TYPE_ONTEXTDATA 1
685 #define TYPE_ONCAPTION 2
686 #define TYPE_ONCAPTIONINFO 3
687 #define TYPE_UNKNOWN 9
689 static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
691 FLVContext *flv = s->priv_data;
693 AVStream *stream, *astream, *vstream;
694 AVStream av_unused *dstream;
704 // first object needs to be "onMetaData" string
706 if (type != AMF_DATA_TYPE_STRING ||
707 amf_get_string(ioc, buffer, sizeof(buffer)) < 0)
710 if (!strcmp(buffer, "onTextData"))
711 return TYPE_ONTEXTDATA;
713 if (!strcmp(buffer, "onCaption"))
714 return TYPE_ONCAPTION;
716 if (!strcmp(buffer, "onCaptionInfo"))
717 return TYPE_ONCAPTIONINFO;
719 if (strcmp(buffer, "onMetaData") && strcmp(buffer, "onCuePoint")) {
720 av_log(s, AV_LOG_DEBUG, "Unknown type %s\n", buffer);
724 // find the streams now so that amf_parse_object doesn't need to do
725 // the lookup every time it is called.
726 for (i = 0; i < s->nb_streams; i++) {
727 stream = s->streams[i];
728 if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
730 flv->last_keyframe_stream_index = i;
731 } else if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
733 if (flv->last_keyframe_stream_index == -1)
734 flv->last_keyframe_stream_index = i;
736 else if (stream->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
740 // parse the second object (we want a mixed array)
741 if (amf_parse_object(s, astream, vstream, buffer, next_pos, 0) < 0)
747 static int flv_read_header(AVFormatContext *s)
750 FLVContext *flv = s->priv_data;
752 int pre_tag_size = 0;
754 /* Actual FLV data at 0xe40000 in KUX file */
755 if(!strcmp(s->iformat->name, "kux"))
756 avio_skip(s->pb, 0xe40000);
759 flags = avio_r8(s->pb);
761 flv->missing_streams = flags & (FLV_HEADER_FLAG_HASVIDEO | FLV_HEADER_FLAG_HASAUDIO);
763 s->ctx_flags |= AVFMTCTX_NOHEADER;
765 offset = avio_rb32(s->pb);
766 avio_seek(s->pb, offset, SEEK_SET);
768 /* Annex E. The FLV File Format
771 * PreviousTagSize0 UI32 Always 0
773 pre_tag_size = avio_rb32(s->pb);
775 av_log(s, AV_LOG_WARNING, "Read FLV header error, input file is not a standard flv format, first PreviousTagSize0 always is 0\n");
779 flv->sum_flv_tag_size = 0;
780 flv->last_keyframe_stream_index = -1;
785 static int flv_read_close(AVFormatContext *s)
788 FLVContext *flv = s->priv_data;
789 for (i=0; i<FLV_STREAM_TYPE_NB; i++)
790 av_freep(&flv->new_extradata[i]);
791 av_freep(&flv->keyframe_times);
792 av_freep(&flv->keyframe_filepositions);
796 static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size)
801 av_freep(&st->codecpar->extradata);
802 if (ff_get_extradata(s, st->codecpar, s->pb, size) < 0)
803 return AVERROR(ENOMEM);
804 st->internal->need_context_update = 1;
808 static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream,
814 av_free(flv->new_extradata[stream]);
815 flv->new_extradata[stream] = av_mallocz(size +
816 AV_INPUT_BUFFER_PADDING_SIZE);
817 if (!flv->new_extradata[stream])
818 return AVERROR(ENOMEM);
819 flv->new_extradata_size[stream] = size;
820 avio_read(pb, flv->new_extradata[stream], size);
824 static void clear_index_entries(AVFormatContext *s, int64_t pos)
827 av_log(s, AV_LOG_WARNING,
828 "Found invalid index entries, clearing the index.\n");
829 for (i = 0; i < s->nb_streams; i++) {
830 AVStream *st = s->streams[i];
831 /* Remove all index entries that point to >= pos */
833 for (j = 0; j < st->nb_index_entries; j++)
834 if (st->index_entries[j].pos < pos)
835 st->index_entries[out++] = st->index_entries[j];
836 st->nb_index_entries = out;
840 static int amf_skip_tag(AVIOContext *pb, AMFDataType type)
842 int nb = -1, ret, parse_name = 1;
845 case AMF_DATA_TYPE_NUMBER:
848 case AMF_DATA_TYPE_BOOL:
851 case AMF_DATA_TYPE_STRING:
852 avio_skip(pb, avio_rb16(pb));
854 case AMF_DATA_TYPE_ARRAY:
856 case AMF_DATA_TYPE_MIXEDARRAY:
858 case AMF_DATA_TYPE_OBJECT:
859 while(!pb->eof_reached && (nb-- > 0 || type != AMF_DATA_TYPE_ARRAY)) {
861 int size = avio_rb16(pb);
868 if ((ret = amf_skip_tag(pb, avio_r8(pb))) < 0)
872 case AMF_DATA_TYPE_NULL:
873 case AMF_DATA_TYPE_OBJECT_END:
876 return AVERROR_INVALIDDATA;
881 static int flv_data_packet(AVFormatContext *s, AVPacket *pkt,
882 int64_t dts, int64_t next)
884 AVIOContext *pb = s->pb;
887 int ret = AVERROR_INVALIDDATA;
891 switch (avio_r8(pb)) {
892 case AMF_DATA_TYPE_ARRAY:
894 case AMF_DATA_TYPE_MIXEDARRAY:
895 avio_seek(pb, 4, SEEK_CUR);
896 case AMF_DATA_TYPE_OBJECT:
902 while (array || (ret = amf_get_string(pb, buf, sizeof(buf))) > 0) {
903 AMFDataType type = avio_r8(pb);
904 if (type == AMF_DATA_TYPE_STRING && (array || !strcmp(buf, "text"))) {
905 length = avio_rb16(pb);
906 ret = av_get_packet(pb, pkt, length);
912 if ((ret = amf_skip_tag(pb, type)) < 0)
918 ret = AVERROR_INVALIDDATA;
922 for (i = 0; i < s->nb_streams; i++) {
924 if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
928 if (i == s->nb_streams) {
929 st = create_stream(s, AVMEDIA_TYPE_SUBTITLE);
931 return AVERROR(ENOMEM);
932 st->codecpar->codec_id = AV_CODEC_ID_TEXT;
939 pkt->stream_index = st->index;
940 pkt->flags |= AV_PKT_FLAG_KEY;
943 avio_seek(s->pb, next + 4, SEEK_SET);
948 static int resync(AVFormatContext *s)
950 FLVContext *flv = s->priv_data;
952 int64_t pos = avio_tell(s->pb);
954 for (i=0; !avio_feof(s->pb); i++) {
955 int j = i & (RESYNC_BUFFER_SIZE-1);
956 int j1 = j + RESYNC_BUFFER_SIZE;
957 flv->resync_buffer[j ] =
958 flv->resync_buffer[j1] = avio_r8(s->pb);
961 uint8_t *d = flv->resync_buffer + j1 - 8;
965 d[3] < 5 && d[5] == 0) {
966 av_log(s, AV_LOG_WARNING, "Concatenated FLV detected, might fail to demux, decode and seek %"PRId64"\n", flv->last_ts);
967 flv->time_offset = flv->last_ts + 1;
968 flv->time_pos = avio_tell(s->pb);
973 unsigned lsize2 = AV_RB32(flv->resync_buffer + j1 - 4);
974 if (lsize2 >= 11 && lsize2 + 8LL < FFMIN(i, RESYNC_BUFFER_SIZE)) {
975 unsigned size2 = AV_RB24(flv->resync_buffer + j1 - lsize2 + 1 - 4);
976 unsigned lsize1 = AV_RB32(flv->resync_buffer + j1 - lsize2 - 8);
977 if (lsize1 >= 11 && lsize1 + 8LL + lsize2 < FFMIN(i, RESYNC_BUFFER_SIZE)) {
978 unsigned size1 = AV_RB24(flv->resync_buffer + j1 - lsize1 + 1 - lsize2 - 8);
979 if (size1 == lsize1 - 11 && size2 == lsize2 - 11) {
980 avio_seek(s->pb, pos + i - lsize1 - lsize2 - 8, SEEK_SET);
990 static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
992 FLVContext *flv = s->priv_data;
993 int ret, i, size, flags;
994 enum FlvTagType type;
996 int64_t next, pos, meta_pos;
997 int64_t dts, pts = AV_NOPTS_VALUE;
998 int av_uninit(channels);
999 int av_uninit(sample_rate);
1000 AVStream *st = NULL;
1005 /* pkt size is repeated at end. skip it */
1006 pos = avio_tell(s->pb);
1007 type = (avio_r8(s->pb) & 0x1F);
1009 size = avio_rb24(s->pb);
1010 flv->sum_flv_tag_size += size + 11;
1011 dts = avio_rb24(s->pb);
1012 dts |= (unsigned)avio_r8(s->pb) << 24;
1013 av_log(s, AV_LOG_TRACE, "type:%d, size:%d, last:%d, dts:%"PRId64" pos:%"PRId64"\n", type, size, last, dts, avio_tell(s->pb));
1014 if (avio_feof(s->pb))
1016 avio_skip(s->pb, 3); /* stream id, always 0 */
1019 if (flv->validate_next < flv->validate_count) {
1020 int64_t validate_pos = flv->validate_index[flv->validate_next].pos;
1021 if (pos == validate_pos) {
1022 if (FFABS(dts - flv->validate_index[flv->validate_next].dts) <=
1023 VALIDATE_INDEX_TS_THRESH) {
1024 flv->validate_next++;
1026 clear_index_entries(s, validate_pos);
1027 flv->validate_count = 0;
1029 } else if (pos > validate_pos) {
1030 clear_index_entries(s, validate_pos);
1031 flv->validate_count = 0;
1040 next = size + avio_tell(s->pb);
1042 if (type == FLV_TAG_TYPE_AUDIO) {
1043 stream_type = FLV_STREAM_TYPE_AUDIO;
1044 flags = avio_r8(s->pb);
1046 } else if (type == FLV_TAG_TYPE_VIDEO) {
1047 stream_type = FLV_STREAM_TYPE_VIDEO;
1048 flags = avio_r8(s->pb);
1050 if ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_VIDEO_INFO_CMD)
1052 } else if (type == FLV_TAG_TYPE_META) {
1053 stream_type=FLV_STREAM_TYPE_SUBTITLE;
1054 if (size > 13 + 1 + 4) { // Header-type metadata stuff
1056 meta_pos = avio_tell(s->pb);
1057 type = flv_read_metabody(s, next);
1058 if (type == 0 && dts == 0 || type < 0) {
1059 if (type < 0 && flv->validate_count &&
1060 flv->validate_index[0].pos > next &&
1061 flv->validate_index[0].pos - 4 < next
1063 av_log(s, AV_LOG_WARNING, "Adjusting next position due to index mismatch\n");
1064 next = flv->validate_index[0].pos - 4;
1067 } else if (type == TYPE_ONTEXTDATA) {
1068 avpriv_request_sample(s, "OnTextData packet");
1069 return flv_data_packet(s, pkt, dts, next);
1070 } else if (type == TYPE_ONCAPTION) {
1071 return flv_data_packet(s, pkt, dts, next);
1072 } else if (type == TYPE_UNKNOWN) {
1073 stream_type = FLV_STREAM_TYPE_DATA;
1075 avio_seek(s->pb, meta_pos, SEEK_SET);
1078 av_log(s, AV_LOG_DEBUG,
1079 "Skipping flv packet: type %d, size %d, flags %d.\n",
1082 if (avio_seek(s->pb, next, SEEK_SET) != next) {
1083 // This can happen if flv_read_metabody above read past
1084 // next, on a non-seekable input, and the preceding data has
1085 // been flushed out from the IO buffer.
1086 av_log(s, AV_LOG_ERROR, "Unable to seek to the next packet\n");
1087 return AVERROR_INVALIDDATA;
1093 /* skip empty data packets */
1099 /* now find stream */
1100 for (i = 0; i < s->nb_streams; i++) {
1102 if (stream_type == FLV_STREAM_TYPE_AUDIO) {
1103 if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
1104 (s->audio_codec_id || flv_same_audio_codec(st->codecpar, flags)))
1106 } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
1107 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
1108 (s->video_codec_id || flv_same_video_codec(st->codecpar, flags)))
1110 } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
1111 if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
1113 } else if (stream_type == FLV_STREAM_TYPE_DATA) {
1114 if (st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
1118 if (i == s->nb_streams) {
1119 static const enum AVMediaType stream_types[] = {AVMEDIA_TYPE_VIDEO, AVMEDIA_TYPE_AUDIO, AVMEDIA_TYPE_SUBTITLE, AVMEDIA_TYPE_DATA};
1120 st = create_stream(s, stream_types[stream_type]);
1122 return AVERROR(ENOMEM);
1125 av_log(s, AV_LOG_TRACE, "%d %X %d \n", stream_type, flags, st->discard);
1127 if (flv->time_pos <= pos) {
1128 dts += flv->time_offset;
1131 if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
1132 ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY ||
1133 stream_type == FLV_STREAM_TYPE_AUDIO))
1134 av_add_index_entry(st, pos, dts, size, 0, AVINDEX_KEYFRAME);
1136 if ( (st->discard >= AVDISCARD_NONKEY && !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || (stream_type == FLV_STREAM_TYPE_AUDIO)))
1137 ||(st->discard >= AVDISCARD_BIDIR && ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_DISP_INTER && (stream_type == FLV_STREAM_TYPE_VIDEO)))
1138 || st->discard >= AVDISCARD_ALL
1140 avio_seek(s->pb, next, SEEK_SET);
1145 // if not streamed and no duration from metadata then seek to end to find
1146 // the duration from the timestamps
1147 if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
1148 (!s->duration || s->duration == AV_NOPTS_VALUE) &&
1149 !flv->searched_for_end) {
1151 const int64_t pos = avio_tell(s->pb);
1152 // Read the last 4 bytes of the file, this should be the size of the
1153 // previous FLV tag. Use the timestamp of its payload as duration.
1154 int64_t fsize = avio_size(s->pb);
1156 avio_seek(s->pb, fsize - 4, SEEK_SET);
1157 size = avio_rb32(s->pb);
1158 if (size > 0 && size < fsize) {
1159 // Seek to the start of the last FLV tag at position (fsize - 4 - size)
1160 // but skip the byte indicating the type.
1161 avio_seek(s->pb, fsize - 3 - size, SEEK_SET);
1162 if (size == avio_rb24(s->pb) + 11) {
1163 uint32_t ts = avio_rb24(s->pb);
1164 ts |= avio_r8(s->pb) << 24;
1166 s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
1167 else if (fsize >= 8 && fsize - 8 >= size) {
1169 goto retry_duration;
1174 avio_seek(s->pb, pos, SEEK_SET);
1175 flv->searched_for_end = 1;
1178 if (stream_type == FLV_STREAM_TYPE_AUDIO) {
1179 int bits_per_coded_sample;
1180 channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1;
1181 sample_rate = 44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >>
1182 FLV_AUDIO_SAMPLERATE_OFFSET) >> 3;
1183 bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
1184 if (!st->codecpar->channels || !st->codecpar->sample_rate ||
1185 !st->codecpar->bits_per_coded_sample) {
1186 st->codecpar->channels = channels;
1187 st->codecpar->channel_layout = channels == 1
1189 : AV_CH_LAYOUT_STEREO;
1190 st->codecpar->sample_rate = sample_rate;
1191 st->codecpar->bits_per_coded_sample = bits_per_coded_sample;
1193 if (!st->codecpar->codec_id) {
1194 flv_set_audio_codec(s, st, st->codecpar,
1195 flags & FLV_AUDIO_CODECID_MASK);
1196 flv->last_sample_rate =
1197 sample_rate = st->codecpar->sample_rate;
1198 flv->last_channels =
1199 channels = st->codecpar->channels;
1201 AVCodecParameters *par = avcodec_parameters_alloc();
1203 ret = AVERROR(ENOMEM);
1206 par->sample_rate = sample_rate;
1207 par->bits_per_coded_sample = bits_per_coded_sample;
1208 flv_set_audio_codec(s, st, par, flags & FLV_AUDIO_CODECID_MASK);
1209 sample_rate = par->sample_rate;
1210 avcodec_parameters_free(&par);
1212 } else if (stream_type == FLV_STREAM_TYPE_VIDEO) {
1213 int ret = flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK, 1);
1217 } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) {
1218 st->codecpar->codec_id = AV_CODEC_ID_TEXT;
1219 } else if (stream_type == FLV_STREAM_TYPE_DATA) {
1220 st->codecpar->codec_id = AV_CODEC_ID_NONE; // Opaque AMF data
1223 if (st->codecpar->codec_id == AV_CODEC_ID_AAC ||
1224 st->codecpar->codec_id == AV_CODEC_ID_H264 ||
1225 st->codecpar->codec_id == AV_CODEC_ID_MPEG4) {
1226 int type = avio_r8(s->pb);
1230 ret = AVERROR_INVALIDDATA;
1234 if (st->codecpar->codec_id == AV_CODEC_ID_H264 || st->codecpar->codec_id == AV_CODEC_ID_MPEG4) {
1236 int32_t cts = (avio_rb24(s->pb) + 0xff800000) ^ 0xff800000;
1238 if (cts < 0) { // dts might be wrong
1239 if (!flv->wrong_dts)
1240 av_log(s, AV_LOG_WARNING,
1241 "Negative cts, previous timestamps might be wrong.\n");
1243 } else if (FFABS(dts - pts) > 1000*60*15) {
1244 av_log(s, AV_LOG_WARNING,
1245 "invalid timestamps %"PRId64" %"PRId64"\n", dts, pts);
1246 dts = pts = AV_NOPTS_VALUE;
1249 if (type == 0 && (!st->codecpar->extradata || st->codecpar->codec_id == AV_CODEC_ID_AAC ||
1250 st->codecpar->codec_id == AV_CODEC_ID_H264)) {
1251 AVDictionaryEntry *t;
1253 if (st->codecpar->extradata) {
1254 if ((ret = flv_queue_extradata(flv, s->pb, stream_type, size)) < 0)
1259 if ((ret = flv_get_extradata(s, st, size)) < 0)
1262 /* Workaround for buggy Omnia A/XE encoder */
1263 t = av_dict_get(s->metadata, "Encoder", NULL, 0);
1264 if (st->codecpar->codec_id == AV_CODEC_ID_AAC && t && !strcmp(t->value, "Omnia A/XE"))
1265 st->codecpar->extradata_size = 2;
1272 /* skip empty data packets */
1278 ret = av_get_packet(s->pb, pkt, size);
1282 pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts;
1283 pkt->stream_index = st->index;
1285 if (flv->new_extradata[stream_type]) {
1286 uint8_t *side = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
1287 flv->new_extradata_size[stream_type]);
1289 memcpy(side, flv->new_extradata[stream_type],
1290 flv->new_extradata_size[stream_type]);
1291 av_freep(&flv->new_extradata[stream_type]);
1292 flv->new_extradata_size[stream_type] = 0;
1295 if (stream_type == FLV_STREAM_TYPE_AUDIO &&
1296 (sample_rate != flv->last_sample_rate ||
1297 channels != flv->last_channels)) {
1298 flv->last_sample_rate = sample_rate;
1299 flv->last_channels = channels;
1300 ff_add_param_change(pkt, channels, 0, sample_rate, 0, 0);
1303 if ( stream_type == FLV_STREAM_TYPE_AUDIO ||
1304 ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY) ||
1305 stream_type == FLV_STREAM_TYPE_SUBTITLE ||
1306 stream_type == FLV_STREAM_TYPE_DATA)
1307 pkt->flags |= AV_PKT_FLAG_KEY;
1310 last = avio_rb32(s->pb);
1311 if (!flv->trust_datasize) {
1312 if (last != orig_size + 11 && last != orig_size + 10 &&
1313 !avio_feof(s->pb) &&
1314 (last != orig_size || !last) && last != flv->sum_flv_tag_size &&
1315 !flv->broken_sizes) {
1316 av_log(s, AV_LOG_ERROR, "Packet mismatch %d %d %d\n", last, orig_size + 11, flv->sum_flv_tag_size);
1317 avio_seek(s->pb, pos + 1, SEEK_SET);
1319 av_packet_unref(pkt);
1327 flv->last_ts = pkt->dts;
1332 static int flv_read_seek(AVFormatContext *s, int stream_index,
1333 int64_t ts, int flags)
1335 FLVContext *flv = s->priv_data;
1336 flv->validate_count = 0;
1337 return avio_seek_time(s->pb, stream_index, ts, flags);
1340 #define OFFSET(x) offsetof(FLVContext, x)
1341 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1342 static const AVOption options[] = {
1343 { "flv_metadata", "Allocate streams according to the onMetaData array", OFFSET(trust_metadata), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1344 { "flv_full_metadata", "Dump full metadata of the onMetadata", OFFSET(dump_full_metadata), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1345 { "flv_ignore_prevtag", "Ignore the Size of previous tag", OFFSET(trust_datasize), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VD },
1346 { "missing_streams", "", OFFSET(missing_streams), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0xFF, VD | AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
1350 static const AVClass flv_class = {
1351 .class_name = "flvdec",
1352 .item_name = av_default_item_name,
1354 .version = LIBAVUTIL_VERSION_INT,
1357 AVInputFormat ff_flv_demuxer = {
1359 .long_name = NULL_IF_CONFIG_SMALL("FLV (Flash Video)"),
1360 .priv_data_size = sizeof(FLVContext),
1361 .read_probe = flv_probe,
1362 .read_header = flv_read_header,
1363 .read_packet = flv_read_packet,
1364 .read_seek = flv_read_seek,
1365 .read_close = flv_read_close,
1366 .extensions = "flv",
1367 .priv_class = &flv_class,
1370 static const AVClass live_flv_class = {
1371 .class_name = "live_flvdec",
1372 .item_name = av_default_item_name,
1374 .version = LIBAVUTIL_VERSION_INT,
1377 AVInputFormat ff_live_flv_demuxer = {
1379 .long_name = NULL_IF_CONFIG_SMALL("live RTMP FLV (Flash Video)"),
1380 .priv_data_size = sizeof(FLVContext),
1381 .read_probe = live_flv_probe,
1382 .read_header = flv_read_header,
1383 .read_packet = flv_read_packet,
1384 .read_seek = flv_read_seek,
1385 .read_close = flv_read_close,
1386 .extensions = "flv",
1387 .priv_class = &live_flv_class,
1388 .flags = AVFMT_TS_DISCONT
1391 static const AVClass kux_class = {
1392 .class_name = "kuxdec",
1393 .item_name = av_default_item_name,
1395 .version = LIBAVUTIL_VERSION_INT,
1398 AVInputFormat ff_kux_demuxer = {
1400 .long_name = NULL_IF_CONFIG_SMALL("KUX (YouKu)"),
1401 .priv_data_size = sizeof(FLVContext),
1402 .read_probe = kux_probe,
1403 .read_header = flv_read_header,
1404 .read_packet = flv_read_packet,
1405 .read_seek = flv_read_seek,
1406 .read_close = flv_read_close,
1407 .extensions = "kux",
1408 .priv_class = &kux_class,