From 3ea06ac59e76cc2a63553f5913a9a17ca7c6db82 Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Sat, 6 Oct 2012 02:27:49 +0300 Subject: smoothstreamingenc: Move the output_chunk_list and write_manifest functions up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows calling write_manifest from ism_write_header without a forward declaration. Signed-off-by: Martin Storsjö --- libavformat/smoothstreamingenc.c | 186 +++++++++++++++++++-------------------- 1 file changed, 93 insertions(+), 93 deletions(-) (limited to 'libavformat/smoothstreamingenc.c') diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c index d86e87fc05..cc34f7eb4f 100644 --- a/libavformat/smoothstreamingenc.c +++ b/libavformat/smoothstreamingenc.c @@ -186,6 +186,99 @@ static void ism_free(AVFormatContext *s) av_freep(&c->streams); } +static void output_chunk_list(OutputStream *os, AVIOContext *out, int final, int skip, int window_size) +{ + int removed = 0, i, start = 0; + if (os->nb_fragments <= 0) + return; + if (os->fragments[0]->n > 0) + removed = 1; + if (final) + skip = 0; + if (window_size) + start = FFMAX(os->nb_fragments - skip - window_size, 0); + for (i = start; i < os->nb_fragments - skip; i++) { + Fragment *frag = os->fragments[i]; + if (!final || removed) + avio_printf(out, "\n", frag->start_time, frag->duration); + else + avio_printf(out, "\n", frag->n, frag->duration); + } +} + +static int write_manifest(AVFormatContext *s, int final) +{ + SmoothStreamingContext *c = s->priv_data; + AVIOContext *out; + char filename[1024]; + int ret, i, video_chunks = 0, audio_chunks = 0, video_streams = 0, audio_streams = 0; + int64_t duration = 0; + + snprintf(filename, sizeof(filename), "%s/Manifest", s->filename); + ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL); + if (ret < 0) + return ret; + avio_printf(out, "\n"); + for (i = 0; i < s->nb_streams; i++) { + OutputStream *os = &c->streams[i]; + if (os->nb_fragments > 0) { + Fragment *last = os->fragments[os->nb_fragments - 1]; + duration = last->start_time + last->duration; + } + if (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + video_chunks = os->nb_fragments; + video_streams++; + } else { + audio_chunks = os->nb_fragments; + audio_streams++; + } + } + if (!final) { + duration = 0; + video_chunks = audio_chunks = 0; + } + if (c->window_size) { + video_chunks = FFMIN(video_chunks, c->window_size); + audio_chunks = FFMIN(audio_chunks, c->window_size); + } + avio_printf(out, "lookahead_count); + avio_printf(out, ">\n"); + if (c->has_video) { + int last = -1, index = 0; + avio_printf(out, "\n", video_streams, video_chunks); + for (i = 0; i < s->nb_streams; i++) { + OutputStream *os = &c->streams[i]; + if (s->streams[i]->codec->codec_type != AVMEDIA_TYPE_VIDEO) + continue; + last = i; + avio_printf(out, "\n", index, s->streams[i]->codec->bit_rate, os->fourcc, s->streams[i]->codec->width, s->streams[i]->codec->height, os->private_str); + index++; + } + output_chunk_list(&c->streams[last], out, final, c->lookahead_count, c->window_size); + avio_printf(out, "\n"); + } + if (c->has_audio) { + int last = -1, index = 0; + avio_printf(out, "\n", audio_streams, audio_chunks); + for (i = 0; i < s->nb_streams; i++) { + OutputStream *os = &c->streams[i]; + if (s->streams[i]->codec->codec_type != AVMEDIA_TYPE_AUDIO) + continue; + last = i; + avio_printf(out, "\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); + index++; + } + output_chunk_list(&c->streams[last], out, final, c->lookahead_count, c->window_size); + avio_printf(out, "\n"); + } + avio_printf(out, "\n"); + avio_flush(out); + avio_close(out); + return 0; +} + static int ism_write_header(AVFormatContext *s) { SmoothStreamingContext *c = s->priv_data; @@ -401,99 +494,6 @@ static int copy_moof(AVFormatContext *s, const char* infile, const char *outfile return ret; } -static void output_chunk_list(OutputStream *os, AVIOContext *out, int final, int skip, int window_size) -{ - int removed = 0, i, start = 0; - if (os->nb_fragments <= 0) - return; - if (os->fragments[0]->n > 0) - removed = 1; - if (final) - skip = 0; - if (window_size) - start = FFMAX(os->nb_fragments - skip - window_size, 0); - for (i = start; i < os->nb_fragments - skip; i++) { - Fragment *frag = os->fragments[i]; - if (!final || removed) - avio_printf(out, "\n", frag->start_time, frag->duration); - else - avio_printf(out, "\n", frag->n, frag->duration); - } -} - -static int write_manifest(AVFormatContext *s, int final) -{ - SmoothStreamingContext *c = s->priv_data; - AVIOContext *out; - char filename[1024]; - int ret, i, video_chunks = 0, audio_chunks = 0, video_streams = 0, audio_streams = 0; - int64_t duration = 0; - - snprintf(filename, sizeof(filename), "%s/Manifest", s->filename); - ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL); - if (ret < 0) - return ret; - avio_printf(out, "\n"); - for (i = 0; i < s->nb_streams; i++) { - OutputStream *os = &c->streams[i]; - if (os->nb_fragments > 0) { - Fragment *last = os->fragments[os->nb_fragments - 1]; - duration = last->start_time + last->duration; - } - if (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { - video_chunks = os->nb_fragments; - video_streams++; - } else { - audio_chunks = os->nb_fragments; - audio_streams++; - } - } - if (!final) { - duration = 0; - video_chunks = audio_chunks = 0; - } - if (c->window_size) { - video_chunks = FFMIN(video_chunks, c->window_size); - audio_chunks = FFMIN(audio_chunks, c->window_size); - } - avio_printf(out, "lookahead_count); - avio_printf(out, ">\n"); - if (c->has_video) { - int last = -1, index = 0; - avio_printf(out, "\n", video_streams, video_chunks); - for (i = 0; i < s->nb_streams; i++) { - OutputStream *os = &c->streams[i]; - if (s->streams[i]->codec->codec_type != AVMEDIA_TYPE_VIDEO) - continue; - last = i; - avio_printf(out, "\n", index, s->streams[i]->codec->bit_rate, os->fourcc, s->streams[i]->codec->width, s->streams[i]->codec->height, os->private_str); - index++; - } - output_chunk_list(&c->streams[last], out, final, c->lookahead_count, c->window_size); - avio_printf(out, "\n"); - } - if (c->has_audio) { - int last = -1, index = 0; - avio_printf(out, "\n", audio_streams, audio_chunks); - for (i = 0; i < s->nb_streams; i++) { - OutputStream *os = &c->streams[i]; - if (s->streams[i]->codec->codec_type != AVMEDIA_TYPE_AUDIO) - continue; - last = i; - avio_printf(out, "\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); - index++; - } - output_chunk_list(&c->streams[last], out, final, c->lookahead_count, c->window_size); - avio_printf(out, "\n"); - } - avio_printf(out, "\n"); - avio_flush(out); - avio_close(out); - return 0; -} - static int ism_flush(AVFormatContext *s, int final) { SmoothStreamingContext *c = s->priv_data; -- cgit v1.2.3