#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(void)
{
	static const string video_stream("video stream ");
	static const string audio_stream("audio stream ");
	static const string app_size("App. Size (bytes)    ");

	char *buffer = 0;
	int result;
	size_t bufsize = 0;
	bool atVideo = false;
	int ac3Tracks = 0;
	int mp2Tracks = 0;
	while ((result = getline(&buffer, &bufsize, stdin)) != -1) {
		string line(buffer);

		if (line.substr(0, video_stream.length()) == video_stream) {
			istringstream parser(line.substr(video_stream.length()));
			int cid;
			parser >> setbase(16) >> cid;
			atVideo = true;

			cout << "video track " << cid << endl;
		}
		else if (line.substr(0, audio_stream.length()) == audio_stream) {
			istringstream parser(line.substr(audio_stream.length()));
			int cid;
			parser >> setbase(16) >> cid;
			parser.ignore(6); // " info "
			string type;
			parser >> type;
			cout << "audio track " << cid << " is " << type << endl;

			if (type == "(AC3_audio):") {
				++ac3Tracks; // XXX
			} else {
				mp2Tracks++;
			}
		}
		else if (line.substr(0, app_size.length()) == app_size) {
			istringstream parser(line.substr(app_size.length()));
			int64_t size;
			parser >> size;
			cout << (atVideo ? "video " : "audio ") << "track has " << size
				 << " bytes" << endl;
		}
	}
	free(buffer);

}
