00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "config.h"
00023 #include <float.h>
00024 #if HAVE_UNISTD_H
00025 #include <unistd.h>
00026 #endif
00027
00028 #include "avformat.h"
00029 #include "internal.h"
00030 #include "os_support.h"
00031 #include "avc.h"
00032 #include "url.h"
00033 #include "isom.h"
00034
00035 #include "libavutil/opt.h"
00036 #include "libavutil/avstring.h"
00037 #include "libavutil/mathematics.h"
00038 #include "libavutil/intreadwrite.h"
00039
00040 typedef struct {
00041 char file[1024];
00042 char infofile[1024];
00043 int64_t start_time, duration;
00044 int n;
00045 int64_t start_pos, size;
00046 } Fragment;
00047
00048 typedef struct {
00049 AVFormatContext *ctx;
00050 int ctx_inited;
00051 char dirname[1024];
00052 uint8_t iobuf[32768];
00053 URLContext *out;
00054 URLContext *out2;
00055 URLContext *tail_out;
00056 int64_t tail_pos, cur_pos, cur_start_pos;
00057 int packets_written;
00058 const char *stream_type_tag;
00059 int nb_fragments, fragments_size, fragment_index;
00060 Fragment **fragments;
00061
00062 const char *fourcc;
00063 char *private_str;
00064 int packet_size;
00065 int audio_tag;
00066 } OutputStream;
00067
00068 typedef struct {
00069 const AVClass *class;
00070 int window_size;
00071 int extra_window_size;
00072 int lookahead_count;
00073 int min_frag_duration;
00074 int remove_at_exit;
00075 OutputStream *streams;
00076 int has_video, has_audio;
00077 int nb_fragments;
00078 } SmoothStreamingContext;
00079
00080 static int ism_write(void *opaque, uint8_t *buf, int buf_size)
00081 {
00082 OutputStream *os = opaque;
00083 if (os->out)
00084 ffurl_write(os->out, buf, buf_size);
00085 if (os->out2)
00086 ffurl_write(os->out2, buf, buf_size);
00087 os->cur_pos += buf_size;
00088 if (os->cur_pos >= os->tail_pos)
00089 os->tail_pos = os->cur_pos;
00090 return buf_size;
00091 }
00092
00093 static int64_t ism_seek(void *opaque, int64_t offset, int whence)
00094 {
00095 OutputStream *os = opaque;
00096 int i;
00097 if (whence != SEEK_SET)
00098 return AVERROR(ENOSYS);
00099 if (os->tail_out) {
00100 if (os->out) {
00101 ffurl_close(os->out);
00102 }
00103 if (os->out2) {
00104 ffurl_close(os->out2);
00105 }
00106 os->out = os->tail_out;
00107 os->out2 = NULL;
00108 os->tail_out = NULL;
00109 }
00110 if (offset >= os->cur_start_pos) {
00111 ffurl_seek(os->out, offset - os->cur_start_pos, SEEK_SET);
00112 os->cur_pos = offset;
00113 return offset;
00114 }
00115 for (i = os->nb_fragments - 1; i >= 0; i--) {
00116 Fragment *frag = os->fragments[i];
00117 if (offset >= frag->start_pos && offset < frag->start_pos + frag->size) {
00118 int ret;
00119 AVDictionary *opts = NULL;
00120 os->tail_out = os->out;
00121 av_dict_set(&opts, "truncate", "0", 0);
00122 ret = ffurl_open(&os->out, frag->file, AVIO_FLAG_READ_WRITE, &os->ctx->interrupt_callback, &opts);
00123 av_dict_free(&opts);
00124 if (ret < 0) {
00125 os->out = os->tail_out;
00126 os->tail_out = NULL;
00127 return ret;
00128 }
00129 av_dict_set(&opts, "truncate", "0", 0);
00130 ffurl_open(&os->out2, frag->infofile, AVIO_FLAG_READ_WRITE, &os->ctx->interrupt_callback, &opts);
00131 av_dict_free(&opts);
00132 ffurl_seek(os->out, offset - frag->start_pos, SEEK_SET);
00133 if (os->out2)
00134 ffurl_seek(os->out2, offset - frag->start_pos, SEEK_SET);
00135 os->cur_pos = offset;
00136 return offset;
00137 }
00138 }
00139 return AVERROR(EIO);
00140 }
00141
00142 static void get_private_data(OutputStream *os)
00143 {
00144 AVCodecContext *codec = os->ctx->streams[0]->codec;
00145 uint8_t *ptr = codec->extradata;
00146 int size = codec->extradata_size;
00147 int i;
00148 if (codec->codec_id == AV_CODEC_ID_H264) {
00149 ff_avc_write_annexb_extradata(ptr, &ptr, &size);
00150 if (!ptr)
00151 ptr = codec->extradata;
00152 }
00153 if (!ptr)
00154 return;
00155 os->private_str = av_mallocz(2*size + 1);
00156 for (i = 0; i < size; i++)
00157 snprintf(&os->private_str[2*i], 3, "%02x", ptr[i]);
00158 if (ptr != codec->extradata)
00159 av_free(ptr);
00160 }
00161
00162 static void ism_free(AVFormatContext *s)
00163 {
00164 SmoothStreamingContext *c = s->priv_data;
00165 int i, j;
00166 if (!c->streams)
00167 return;
00168 for (i = 0; i < s->nb_streams; i++) {
00169 OutputStream *os = &c->streams[i];
00170 ffurl_close(os->out);
00171 ffurl_close(os->out2);
00172 ffurl_close(os->tail_out);
00173 os->out = os->out2 = os->tail_out = NULL;
00174 if (os->ctx && os->ctx_inited)
00175 av_write_trailer(os->ctx);
00176 if (os->ctx && os->ctx->pb)
00177 av_free(os->ctx->pb);
00178 if (os->ctx)
00179 avformat_free_context(os->ctx);
00180 av_free(os->private_str);
00181 for (j = 0; j < os->nb_fragments; j++)
00182 av_free(os->fragments[j]);
00183 av_free(os->fragments);
00184 }
00185 av_freep(&c->streams);
00186 }
00187
00188 static int ism_write_header(AVFormatContext *s)
00189 {
00190 SmoothStreamingContext *c = s->priv_data;
00191 int ret = 0, i;
00192 AVOutputFormat *oformat;
00193
00194 ret = mkdir(s->filename, 0777);
00195 if (ret) {
00196 av_log(s, AV_LOG_ERROR, "mkdir(%s): %s\n", s->filename, strerror(errno));
00197 return AVERROR(errno);
00198 }
00199 ret = 0;
00200
00201 oformat = av_guess_format("ismv", NULL, NULL);
00202 if (!oformat) {
00203 ret = AVERROR_MUXER_NOT_FOUND;
00204 goto fail;
00205 }
00206
00207 c->streams = av_mallocz(sizeof(*c->streams) * s->nb_streams);
00208 if (!c->streams) {
00209 ret = AVERROR(ENOMEM);
00210 goto fail;
00211 }
00212
00213 for (i = 0; i < s->nb_streams; i++) {
00214 OutputStream *os = &c->streams[i];
00215 AVFormatContext *ctx;
00216 AVStream *st;
00217 AVDictionary *opts = NULL;
00218 char buf[10];
00219
00220 if (!s->streams[i]->codec->bit_rate) {
00221 av_log(s, AV_LOG_ERROR, "No bit rate set for stream %d\n", i);
00222 ret = AVERROR(EINVAL);
00223 goto fail;
00224 }
00225 snprintf(os->dirname, sizeof(os->dirname), "%s/QualityLevels(%d)", s->filename, s->streams[i]->codec->bit_rate);
00226 mkdir(os->dirname, 0777);
00227
00228 ctx = avformat_alloc_context();
00229 if (!ctx) {
00230 ret = AVERROR(ENOMEM);
00231 goto fail;
00232 }
00233 os->ctx = ctx;
00234 ctx->oformat = oformat;
00235 ctx->interrupt_callback = s->interrupt_callback;
00236
00237 if (!(st = avformat_new_stream(ctx, NULL))) {
00238 ret = AVERROR(ENOMEM);
00239 goto fail;
00240 }
00241 avcodec_copy_context(st->codec, s->streams[i]->codec);
00242 st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
00243
00244 ctx->pb = avio_alloc_context(os->iobuf, sizeof(os->iobuf), AVIO_FLAG_WRITE, os, NULL, ism_write, ism_seek);
00245 if (!ctx->pb) {
00246 ret = AVERROR(ENOMEM);
00247 goto fail;
00248 }
00249
00250 snprintf(buf, sizeof(buf), "%d", c->lookahead_count);
00251 av_dict_set(&opts, "ism_lookahead", buf, 0);
00252 av_dict_set(&opts, "movflags", "frag_custom", 0);
00253 if ((ret = avformat_write_header(ctx, &opts)) < 0) {
00254 goto fail;
00255 }
00256 os->ctx_inited = 1;
00257 avio_flush(ctx->pb);
00258 av_dict_free(&opts);
00259 s->streams[i]->time_base = st->time_base;
00260 if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
00261 c->has_video = 1;
00262 os->stream_type_tag = "video";
00263 if (st->codec->codec_id == AV_CODEC_ID_H264) {
00264 os->fourcc = "H264";
00265 } else if (st->codec->codec_id == AV_CODEC_ID_VC1) {
00266 os->fourcc = "WVC1";
00267 } else {
00268 av_log(s, AV_LOG_ERROR, "Unsupported video codec\n");
00269 ret = AVERROR(EINVAL);
00270 goto fail;
00271 }
00272 } else {
00273 c->has_audio = 1;
00274 os->stream_type_tag = "audio";
00275 if (st->codec->codec_id == AV_CODEC_ID_AAC) {
00276 os->fourcc = "AACL";
00277 os->audio_tag = 0xff;
00278 } else if (st->codec->codec_id == AV_CODEC_ID_WMAPRO) {
00279 os->fourcc = "WMAP";
00280 os->audio_tag = 0x0162;
00281 } else {
00282 av_log(s, AV_LOG_ERROR, "Unsupported audio codec\n");
00283 ret = AVERROR(EINVAL);
00284 goto fail;
00285 }
00286 os->packet_size = st->codec->block_align ? st->codec->block_align : 4;
00287 }
00288 get_private_data(os);
00289 }
00290
00291 if (!c->has_video && c->min_frag_duration <= 0) {
00292 av_log(s, AV_LOG_WARNING, "no video stream and no min frag duration set\n");
00293 ret = AVERROR(EINVAL);
00294 }
00295
00296 fail:
00297 if (ret)
00298 ism_free(s);
00299 return ret;
00300 }
00301
00302 static int parse_fragment(AVFormatContext *s, const char *filename, int64_t *start_ts, int64_t *duration, int64_t *moof_size, int64_t size)
00303 {
00304 AVIOContext *in;
00305 int ret;
00306 uint32_t len;
00307 if ((ret = avio_open2(&in, filename, AVIO_FLAG_READ, &s->interrupt_callback, NULL)) < 0)
00308 return ret;
00309 ret = AVERROR(EIO);
00310 *moof_size = avio_rb32(in);
00311 if (*moof_size < 8 || *moof_size > size)
00312 goto fail;
00313 if (avio_rl32(in) != MKTAG('m','o','o','f'))
00314 goto fail;
00315 len = avio_rb32(in);
00316 if (len > *moof_size)
00317 goto fail;
00318 if (avio_rl32(in) != MKTAG('m','f','h','d'))
00319 goto fail;
00320 avio_seek(in, len - 8, SEEK_CUR);
00321 avio_rb32(in);
00322 if (avio_rl32(in) != MKTAG('t','r','a','f'))
00323 goto fail;
00324 while (avio_tell(in) < *moof_size) {
00325 uint32_t len = avio_rb32(in);
00326 uint32_t tag = avio_rl32(in);
00327 int64_t end = avio_tell(in) + len - 8;
00328 if (len < 8 || len >= *moof_size)
00329 goto fail;
00330 if (tag == MKTAG('u','u','i','d')) {
00331 const uint8_t tfxd[] = {
00332 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
00333 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2
00334 };
00335 uint8_t uuid[16];
00336 avio_read(in, uuid, 16);
00337 if (!memcmp(uuid, tfxd, 16) && len >= 8 + 16 + 4 + 16) {
00338 avio_seek(in, 4, SEEK_CUR);
00339 *start_ts = avio_rb64(in);
00340 *duration = avio_rb64(in);
00341 ret = 0;
00342 break;
00343 }
00344 }
00345 avio_seek(in, end, SEEK_SET);
00346 }
00347 fail:
00348 avio_close(in);
00349 return ret;
00350 }
00351
00352 static int add_fragment(OutputStream *os, const char *file, const char *infofile, int64_t start_time, int64_t duration, int64_t start_pos, int64_t size)
00353 {
00354 Fragment *frag;
00355 if (os->nb_fragments >= os->fragments_size) {
00356 os->fragments_size = (os->fragments_size + 1) * 2;
00357 os->fragments = av_realloc(os->fragments, sizeof(*os->fragments)*os->fragments_size);
00358 if (!os->fragments)
00359 return AVERROR(ENOMEM);
00360 }
00361 frag = av_mallocz(sizeof(*frag));
00362 if (!frag)
00363 return AVERROR(ENOMEM);
00364 av_strlcpy(frag->file, file, sizeof(frag->file));
00365 av_strlcpy(frag->infofile, infofile, sizeof(frag->infofile));
00366 frag->start_time = start_time;
00367 frag->duration = duration;
00368 frag->start_pos = start_pos;
00369 frag->size = size;
00370 frag->n = os->fragment_index;
00371 os->fragments[os->nb_fragments++] = frag;
00372 os->fragment_index++;
00373 return 0;
00374 }
00375
00376 static int copy_moof(AVFormatContext *s, const char* infile, const char *outfile, int64_t size)
00377 {
00378 AVIOContext *in, *out;
00379 int ret = 0;
00380 if ((ret = avio_open2(&in, infile, AVIO_FLAG_READ, &s->interrupt_callback, NULL)) < 0)
00381 return ret;
00382 if ((ret = avio_open2(&out, outfile, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL)) < 0) {
00383 avio_close(in);
00384 return ret;
00385 }
00386 while (size > 0) {
00387 uint8_t buf[8192];
00388 int n = FFMIN(size, sizeof(buf));
00389 n = avio_read(in, buf, n);
00390 if (n <= 0) {
00391 ret = AVERROR(EIO);
00392 break;
00393 }
00394 avio_write(out, buf, n);
00395 size -= n;
00396 }
00397 avio_flush(out);
00398 avio_close(out);
00399 avio_close(in);
00400 return ret;
00401 }
00402
00403 static void output_chunk_list(OutputStream *os, AVIOContext *out, int final, int skip, int window_size)
00404 {
00405 int removed = 0, i, start = 0;
00406 if (os->nb_fragments <= 0)
00407 return;
00408 if (os->fragments[0]->n > 0)
00409 removed = 1;
00410 if (final)
00411 skip = 0;
00412 if (window_size)
00413 start = FFMAX(os->nb_fragments - skip - window_size, 0);
00414 for (i = start; i < os->nb_fragments - skip; i++) {
00415 Fragment *frag = os->fragments[i];
00416 if (!final || removed)
00417 avio_printf(out, "<c t=\"%"PRIu64"\" d=\"%"PRIu64"\" />\n", frag->start_time, frag->duration);
00418 else
00419 avio_printf(out, "<c n=\"%d\" d=\"%"PRIu64"\" />\n", frag->n, frag->duration);
00420 }
00421 }
00422
00423 static int write_manifest(AVFormatContext *s, int final)
00424 {
00425 SmoothStreamingContext *c = s->priv_data;
00426 AVIOContext *out;
00427 char filename[1024];
00428 int ret, i, video_chunks = 0, audio_chunks = 0, video_streams = 0, audio_streams = 0;
00429 int64_t duration = 0;
00430
00431 snprintf(filename, sizeof(filename), "%s/Manifest", s->filename);
00432 ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL);
00433 if (ret < 0)
00434 return ret;
00435 avio_printf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
00436 for (i = 0; i < s->nb_streams; i++) {
00437 OutputStream *os = &c->streams[i];
00438 if (os->nb_fragments > 0) {
00439 Fragment *last = os->fragments[os->nb_fragments - 1];
00440 duration = last->start_time + last->duration;
00441 }
00442 if (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
00443 video_chunks = os->nb_fragments;
00444 video_streams++;
00445 } else {
00446 audio_chunks = os->nb_fragments;
00447 audio_streams++;
00448 }
00449 }
00450 if (!final) {
00451 duration = 0;
00452 video_chunks = audio_chunks = 0;
00453 }
00454 if (c->window_size) {
00455 video_chunks = FFMIN(video_chunks, c->window_size);
00456 audio_chunks = FFMIN(audio_chunks, c->window_size);
00457 }
00458 avio_printf(out, "<SmoothStreamingMedia MajorVersion=\"2\" MinorVersion=\"0\" Duration=\"%"PRIu64"\"", duration);
00459 if (!final)
00460 avio_printf(out, " IsLive=\"true\" LookAheadFragmentCount=\"%d\" DVRWindowLength=\"0\"", c->lookahead_count);
00461 avio_printf(out, ">\n");
00462 if (c->has_video) {
00463 int last = -1, index = 0;
00464 avio_printf(out, "<StreamIndex Type=\"video\" QualityLevels=\"%d\" Chunks=\"%d\" Url=\"QualityLevels({bitrate})/Fragments(video={start time})\">\n", video_streams, video_chunks);
00465 for (i = 0; i < s->nb_streams; i++) {
00466 OutputStream *os = &c->streams[i];
00467 if (s->streams[i]->codec->codec_type != AVMEDIA_TYPE_VIDEO)
00468 continue;
00469 last = i;
00470 avio_printf(out, "<QualityLevel Index=\"%d\" Bitrate=\"%d\" FourCC=\"%s\" MaxWidth=\"%d\" MaxHeight=\"%d\" CodecPrivateData=\"%s\" />\n", index, s->streams[i]->codec->bit_rate, os->fourcc, s->streams[i]->codec->width, s->streams[i]->codec->height, os->private_str);
00471 index++;
00472 }
00473 output_chunk_list(&c->streams[last], out, final, c->lookahead_count, c->window_size);
00474 avio_printf(out, "</StreamIndex>\n");
00475 }
00476 if (c->has_audio) {
00477 int last = -1, index = 0;
00478 avio_printf(out, "<StreamIndex Type=\"audio\" QualityLevels=\"%d\" Chunks=\"%d\" Url=\"QualityLevels({bitrate})/Fragments(audio={start time})\">\n", audio_streams, audio_chunks);
00479 for (i = 0; i < s->nb_streams; i++) {
00480 OutputStream *os = &c->streams[i];
00481 if (s->streams[i]->codec->codec_type != AVMEDIA_TYPE_AUDIO)
00482 continue;
00483 last = i;
00484 avio_printf(out, "<QualityLevel Index=\"%d\" Bitrate=\"%d\" FourCC=\"%s\" SamplingRate=\"%d\" Channels=\"%d\" BitsPerSample=\"16\" PacketSize=\"%d\" AudioTag=\"%d\" CodecPrivateData=\"%s\" />\n", index, s->streams[i]->codec->bit_rate, os->fourcc, s->streams[i]->codec->sample_rate, s->streams[i]->codec->channels, os->packet_size, os->audio_tag, os->private_str);
00485 index++;
00486 }
00487 output_chunk_list(&c->streams[last], out, final, c->lookahead_count, c->window_size);
00488 avio_printf(out, "</StreamIndex>\n");
00489 }
00490 avio_printf(out, "</SmoothStreamingMedia>\n");
00491 avio_flush(out);
00492 avio_close(out);
00493 return 0;
00494 }
00495
00496 static int ism_flush(AVFormatContext *s, int final)
00497 {
00498 SmoothStreamingContext *c = s->priv_data;
00499 int i, ret = 0;
00500
00501 for (i = 0; i < s->nb_streams; i++) {
00502 OutputStream *os = &c->streams[i];
00503 char filename[1024], target_filename[1024], header_filename[1024];
00504 int64_t start_pos = os->tail_pos, size;
00505 int64_t start_ts, duration, moof_size;
00506 if (!os->packets_written)
00507 continue;
00508
00509 snprintf(filename, sizeof(filename), "%s/temp", os->dirname);
00510 ret = ffurl_open(&os->out, filename, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL);
00511 if (ret < 0)
00512 break;
00513 os->cur_start_pos = os->tail_pos;
00514 av_write_frame(os->ctx, NULL);
00515 avio_flush(os->ctx->pb);
00516 os->packets_written = 0;
00517 if (!os->out || os->tail_out)
00518 return AVERROR(EIO);
00519
00520 ffurl_close(os->out);
00521 os->out = NULL;
00522 size = os->tail_pos - start_pos;
00523 if ((ret = parse_fragment(s, filename, &start_ts, &duration, &moof_size, size)) < 0)
00524 break;
00525 snprintf(header_filename, sizeof(header_filename), "%s/FragmentInfo(%s=%"PRIu64")", os->dirname, os->stream_type_tag, start_ts);
00526 snprintf(target_filename, sizeof(target_filename), "%s/Fragments(%s=%"PRIu64")", os->dirname, os->stream_type_tag, start_ts);
00527 copy_moof(s, filename, header_filename, moof_size);
00528 rename(filename, target_filename);
00529 add_fragment(os, target_filename, header_filename, start_ts, duration, start_pos, size);
00530 }
00531
00532 if (c->window_size || (final && c->remove_at_exit)) {
00533 for (i = 0; i < s->nb_streams; i++) {
00534 OutputStream *os = &c->streams[i];
00535 int j;
00536 int remove = os->nb_fragments - c->window_size - c->extra_window_size - c->lookahead_count;
00537 if (final && c->remove_at_exit)
00538 remove = os->nb_fragments;
00539 if (remove > 0) {
00540 for (j = 0; j < remove; j++) {
00541 unlink(os->fragments[j]->file);
00542 unlink(os->fragments[j]->infofile);
00543 av_free(os->fragments[j]);
00544 }
00545 os->nb_fragments -= remove;
00546 memmove(os->fragments, os->fragments + remove, os->nb_fragments * sizeof(*os->fragments));
00547 }
00548 if (final && c->remove_at_exit)
00549 rmdir(os->dirname);
00550 }
00551 }
00552
00553 write_manifest(s, final);
00554 return ret;
00555 }
00556
00557 static int ism_write_packet(AVFormatContext *s, AVPacket *pkt)
00558 {
00559 SmoothStreamingContext *c = s->priv_data;
00560 AVStream *st = s->streams[pkt->stream_index];
00561 OutputStream *os = &c->streams[pkt->stream_index];
00562 int64_t end_pts = (c->nb_fragments + 1) * c->min_frag_duration;
00563
00564 if ((!c->has_video || st->codec->codec_type == AVMEDIA_TYPE_VIDEO) &&
00565 av_compare_ts(pkt->pts, st->time_base,
00566 end_pts, AV_TIME_BASE_Q) >= 0 &&
00567 pkt->flags & AV_PKT_FLAG_KEY && os->packets_written) {
00568
00569 ism_flush(s, 0);
00570 c->nb_fragments++;
00571 }
00572
00573 os->packets_written++;
00574 return ff_write_chained(os->ctx, 0, pkt, s);
00575 }
00576
00577 static int ism_write_trailer(AVFormatContext *s)
00578 {
00579 SmoothStreamingContext *c = s->priv_data;
00580 ism_flush(s, 1);
00581
00582 if (c->remove_at_exit) {
00583 char filename[1024];
00584 snprintf(filename, sizeof(filename), "%s/Manifest", s->filename);
00585 unlink(filename);
00586 rmdir(s->filename);
00587 }
00588
00589 ism_free(s);
00590 return 0;
00591 }
00592
00593 #define OFFSET(x) offsetof(SmoothStreamingContext, x)
00594 #define E AV_OPT_FLAG_ENCODING_PARAM
00595 static const AVOption options[] = {
00596 { "window_size", "number of fragments kept in the manifest", OFFSET(window_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, E },
00597 { "extra_window_size", "number of fragments kept outside of the manifest before removing from disk", OFFSET(extra_window_size), AV_OPT_TYPE_INT, { .i64 = 5 }, 0, INT_MAX, E },
00598 { "lookahead_count", "number of lookahead fragments", OFFSET(lookahead_count), AV_OPT_TYPE_INT, { .i64 = 2 }, 0, INT_MAX, E },
00599 { "min_frag_duration", "minimum fragment duration (in microseconds)", OFFSET(min_frag_duration), AV_OPT_TYPE_INT64, { .i64 = 5000000 }, 0, INT_MAX, E },
00600 { "remove_at_exit", "remove all fragments when finished", OFFSET(remove_at_exit), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, E },
00601 { NULL },
00602 };
00603
00604 static const AVClass ism_class = {
00605 .class_name = "smooth streaming muxer",
00606 .item_name = av_default_item_name,
00607 .option = options,
00608 .version = LIBAVUTIL_VERSION_INT,
00609 };
00610
00611
00612 AVOutputFormat ff_smoothstreaming_muxer = {
00613 .name = "smoothstreaming",
00614 .long_name = NULL_IF_CONFIG_SMALL("Smooth Streaming Muxer"),
00615 .priv_data_size = sizeof(SmoothStreamingContext),
00616 .audio_codec = AV_CODEC_ID_AAC,
00617 .video_codec = AV_CODEC_ID_H264,
00618 .flags = AVFMT_GLOBALHEADER | AVFMT_NOFILE,
00619 .write_header = ism_write_header,
00620 .write_packet = ism_write_packet,
00621 .write_trailer = ism_write_trailer,
00622 .codec_tag = (const AVCodecTag* const []){ ff_mp4_obj_type, 0 },
00623 .priv_class = &ism_class,
00624 };