diff --git a/tools/ismindex.c b/tools/ismindex.c index bf8c69d2e6..0a01c901d2 100644 --- a/tools/ismindex.c +++ b/tools/ismindex.c @@ -56,7 +56,7 @@ struct MoofOffset { int duration; }; -struct VideoFile { +struct Track { const char *name; int64_t duration; int bitrate; @@ -74,12 +74,12 @@ struct VideoFile { int tag; }; -struct VideoFiles { - int nb_files; +struct Tracks { + int nb_tracks; int64_t duration; - struct VideoFile **files; - int video_file, audio_file; - int nb_video_files, nb_audio_files; + struct Track **tracks; + int video_track, audio_track; + int nb_video_tracks, nb_audio_tracks; }; static int copy_tag(AVIOContext *in, AVIOContext *out, int32_t tag_name) @@ -120,62 +120,62 @@ static int write_fragment(const char *filename, AVIOContext *in) return ret; } -static int write_fragments(struct VideoFiles *files, int start_index, +static int write_fragments(struct Tracks *tracks, int start_index, AVIOContext *in) { char dirname[100], filename[500]; int i, j; - for (i = start_index; i < files->nb_files; i++) { - struct VideoFile *vf = files->files[i]; - const char *type = vf->is_video ? "video" : "audio"; - snprintf(dirname, sizeof(dirname), "QualityLevels(%d)", vf->bitrate); + for (i = start_index; i < tracks->nb_tracks; i++) { + struct Track *track = tracks->tracks[i]; + const char *type = track->is_video ? "video" : "audio"; + snprintf(dirname, sizeof(dirname), "QualityLevels(%d)", track->bitrate); mkdir(dirname, 0777); - for (j = 0; j < vf->chunks; j++) { + for (j = 0; j < track->chunks; j++) { snprintf(filename, sizeof(filename), "%s/Fragments(%s=%"PRId64")", - dirname, type, vf->offsets[j].time); - avio_seek(in, vf->offsets[j].offset, SEEK_SET); + dirname, type, track->offsets[j].time); + avio_seek(in, track->offsets[j].offset, SEEK_SET); write_fragment(filename, in); } } return 0; } -static int read_tfra(struct VideoFiles *files, int start_index, AVIOContext *f) +static int read_tfra(struct Tracks *tracks, int start_index, AVIOContext *f) { int ret = AVERROR_EOF, track_id; int version, fieldlength, i, j; int64_t pos = avio_tell(f); uint32_t size = avio_rb32(f); - struct VideoFile *vf = NULL; + struct Track *track = NULL; if (avio_rb32(f) != MKBETAG('t', 'f', 'r', 'a')) goto fail; version = avio_r8(f); avio_rb24(f); track_id = avio_rb32(f); /* track id */ - for (i = start_index; i < files->nb_files && !vf; i++) - if (files->files[i]->track_id == track_id) - vf = files->files[i]; - if (!vf) { + for (i = start_index; i < tracks->nb_tracks && !track; i++) + if (tracks->tracks[i]->track_id == track_id) + track = tracks->tracks[i]; + if (!track) { /* Ok, continue parsing the next atom */ ret = 0; goto fail; } fieldlength = avio_rb32(f); - vf->chunks = avio_rb32(f); - vf->offsets = av_mallocz(sizeof(*vf->offsets) * vf->chunks); - if (!vf->offsets) { + track->chunks = avio_rb32(f); + track->offsets = av_mallocz(sizeof(*track->offsets) * track->chunks); + if (!track->offsets) { ret = AVERROR(ENOMEM); goto fail; } - for (i = 0; i < vf->chunks; i++) { + for (i = 0; i < track->chunks; i++) { if (version == 1) { - vf->offsets[i].time = avio_rb64(f); - vf->offsets[i].offset = avio_rb64(f); + track->offsets[i].time = avio_rb64(f); + track->offsets[i].offset = avio_rb64(f); } else { - vf->offsets[i].time = avio_rb32(f); - vf->offsets[i].offset = avio_rb32(f); + track->offsets[i].time = avio_rb32(f); + track->offsets[i].offset = avio_rb32(f); } for (j = 0; j < ((fieldlength >> 4) & 3) + 1; j++) avio_r8(f); @@ -184,12 +184,12 @@ static int read_tfra(struct VideoFiles *files, int start_index, AVIOContext *f) for (j = 0; j < ((fieldlength >> 0) & 3) + 1; j++) avio_r8(f); if (i > 0) - vf->offsets[i - 1].duration = vf->offsets[i].time - - vf->offsets[i - 1].time; + track->offsets[i - 1].duration = track->offsets[i].time - + track->offsets[i - 1].time; } - if (vf->chunks > 0) - vf->offsets[vf->chunks - 1].duration = vf->duration - - vf->offsets[vf->chunks - 1].time; + if (track->chunks > 0) + track->offsets[track->chunks - 1].duration = track->duration - + track->offsets[track->chunks - 1].time; ret = 0; fail: @@ -197,7 +197,7 @@ fail: return ret; } -static int read_mfra(struct VideoFiles *files, int start_index, +static int read_mfra(struct Tracks *tracks, int start_index, const char *file, int split) { int err = 0; @@ -217,12 +217,12 @@ static int read_mfra(struct VideoFiles *files, int start_index, err = AVERROR_INVALIDDATA; goto fail; } - while (!read_tfra(files, start_index, f)) { + while (!read_tfra(tracks, start_index, f)) { /* Empty */ } if (split) - write_fragments(files, start_index, f); + write_fragments(tracks, start_index, f); fail: if (f) @@ -232,24 +232,24 @@ fail: return err; } -static int get_private_data(struct VideoFile *vf, AVCodecContext *codec) +static int get_private_data(struct Track *track, AVCodecContext *codec) { - vf->codec_private_size = codec->extradata_size; - vf->codec_private = av_mallocz(codec->extradata_size); - if (!vf->codec_private) + track->codec_private_size = codec->extradata_size; + track->codec_private = av_mallocz(codec->extradata_size); + if (!track->codec_private) return AVERROR(ENOMEM); - memcpy(vf->codec_private, codec->extradata, codec->extradata_size); + memcpy(track->codec_private, codec->extradata, codec->extradata_size); return 0; } -static int get_video_private_data(struct VideoFile *vf, AVCodecContext *codec) +static int get_video_private_data(struct Track *track, AVCodecContext *codec) { AVIOContext *io = NULL; uint16_t sps_size, pps_size; int err = AVERROR(EINVAL); if (codec->codec_id == AV_CODEC_ID_VC1) - return get_private_data(vf, codec); + return get_private_data(track, codec); avio_open_dyn_buf(&io); if (codec->extradata_size < 11 || codec->extradata[0] != 1) @@ -267,16 +267,16 @@ static int get_video_private_data(struct VideoFile *vf, AVCodecContext *codec) err = 0; fail: - vf->codec_private_size = avio_close_dyn_buf(io, &vf->codec_private); + track->codec_private_size = avio_close_dyn_buf(io, &track->codec_private); return err; } -static int handle_file(struct VideoFiles *files, const char *file, int split) +static int handle_file(struct Tracks *tracks, const char *file, int split) { AVFormatContext *ctx = NULL; - int err = 0, i, orig_files = files->nb_files; + int err = 0, i, orig_tracks = tracks->nb_tracks; char errbuf[50], *ptr; - struct VideoFile *vf; + struct Track *track; err = avformat_open_input(&ctx, file, NULL, NULL); if (err < 0) { @@ -296,72 +296,72 @@ static int handle_file(struct VideoFiles *files, const char *file, int split) fprintf(stderr, "No streams found in %s\n", file); goto fail; } - if (!files->duration) - files->duration = ctx->duration; + if (!tracks->duration) + tracks->duration = ctx->duration; for (i = 0; i < ctx->nb_streams; i++) { AVStream *st = ctx->streams[i]; - vf = av_mallocz(sizeof(*vf)); - files->files = av_realloc(files->files, - sizeof(*files->files) * (files->nb_files + 1)); - files->files[files->nb_files] = vf; + track = av_mallocz(sizeof(*track)); + tracks->tracks = av_realloc(tracks->tracks, + sizeof(*tracks->tracks) * (tracks->nb_tracks + 1)); + tracks->tracks[tracks->nb_tracks] = track; - vf->name = file; + track->name = file; if ((ptr = strrchr(file, '/')) != NULL) - vf->name = ptr + 1; + track->name = ptr + 1; - vf->bitrate = st->codec->bit_rate; - vf->track_id = st->id; - vf->timescale = st->time_base.den; - vf->duration = av_rescale_rnd(ctx->duration, vf->timescale, - AV_TIME_BASE, AV_ROUND_UP); - vf->is_audio = st->codec->codec_type == AVMEDIA_TYPE_AUDIO; - vf->is_video = st->codec->codec_type == AVMEDIA_TYPE_VIDEO; + track->bitrate = st->codec->bit_rate; + track->track_id = st->id; + track->timescale = st->time_base.den; + track->duration = av_rescale_rnd(ctx->duration, track->timescale, + AV_TIME_BASE, AV_ROUND_UP); + track->is_audio = st->codec->codec_type == AVMEDIA_TYPE_AUDIO; + track->is_video = st->codec->codec_type == AVMEDIA_TYPE_VIDEO; - if (!vf->is_audio && !vf->is_video) { + if (!track->is_audio && !track->is_video) { fprintf(stderr, "Track %d in %s is neither video nor audio, skipping\n", - vf->track_id, file); - av_freep(&files->files[files->nb_files]); + track->track_id, file); + av_freep(&tracks->tracks[tracks->nb_tracks]); continue; } - if (vf->is_audio) { - if (files->audio_file < 0) - files->audio_file = files->nb_files; - files->nb_audio_files++; - vf->channels = st->codec->channels; - vf->sample_rate = st->codec->sample_rate; + if (track->is_audio) { + if (tracks->audio_track < 0) + tracks->audio_track = tracks->nb_tracks; + tracks->nb_audio_tracks++; + track->channels = st->codec->channels; + track->sample_rate = st->codec->sample_rate; if (st->codec->codec_id == AV_CODEC_ID_AAC) { - vf->fourcc = "AACL"; - vf->tag = 255; - vf->blocksize = 4; + track->fourcc = "AACL"; + track->tag = 255; + track->blocksize = 4; } else if (st->codec->codec_id == AV_CODEC_ID_WMAPRO) { - vf->fourcc = "WMAP"; - vf->tag = st->codec->codec_tag; - vf->blocksize = st->codec->block_align; + track->fourcc = "WMAP"; + track->tag = st->codec->codec_tag; + track->blocksize = st->codec->block_align; } - get_private_data(vf, st->codec); + get_private_data(track, st->codec); } - if (vf->is_video) { - if (files->video_file < 0) - files->video_file = files->nb_files; - files->nb_video_files++; - vf->width = st->codec->width; - vf->height = st->codec->height; + if (track->is_video) { + if (tracks->video_track < 0) + tracks->video_track = tracks->nb_tracks; + tracks->nb_video_tracks++; + track->width = st->codec->width; + track->height = st->codec->height; if (st->codec->codec_id == AV_CODEC_ID_H264) - vf->fourcc = "H264"; + track->fourcc = "H264"; else if (st->codec->codec_id == AV_CODEC_ID_VC1) - vf->fourcc = "WVC1"; - get_video_private_data(vf, st->codec); + track->fourcc = "WVC1"; + get_video_private_data(track, st->codec); } - files->nb_files++; + tracks->nb_tracks++; } avformat_close_input(&ctx); - err = read_mfra(files, orig_files, file, split); + err = read_mfra(tracks, orig_tracks, file, split); fail: if (ctx) @@ -369,7 +369,7 @@ fail: return err; } -static void output_server_manifest(struct VideoFiles *files, +static void output_server_manifest(struct Tracks *tracks, const char *basename) { char filename[1000]; @@ -390,13 +390,13 @@ static void output_server_manifest(struct VideoFiles *files, fprintf(out, "\t\n"); fprintf(out, "\t
\n"); fprintf(out, "\t\t