#include "proctools/extract.h"
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
using namespace proctools;

int main(void)
{
	char *line = 0;
	size_t size = 0;
	int result;
	bool atVideo = false;
	int ac3Tracks = 0;
	int mp2Tracks = 0;
	while ((result = getline(&line, &size, stdin)) != -1) {
		cout << "zeile gelesen: |" << line;
		int cid;
		int64_t size;
		string type;

		cout << "test on \"video stream\": ";
		if (extract(line) >> "video stream")
			cout << "true";
		else
			cout << "false";
		cout << endl;

		if (extract(line) >> "video stream " >> type) {
			cout << "video (crippled), cid = " << type << endl;
		}

		if (string(line).substr(0, string("App. Size (bytes)    ").length()) == "App. Size (bytes)    ") {
			cout << "found size!" << endl;
		}

		if (string(line).substr(0, string("video stream ").length()) == "video stream ") {
			string test = string(line).substr(string("video stream ").length());
			if (extract(test) >> type)
				cout << "still there, cid = " << type << endl;
			if (extract(test) >> setbase(16) >> cid)
				cout << "yet still there, cid = " << cid << endl;
		}
		if (extract(line) >> "audio stream " >> type) {
			cout << "audio (crippled), cid = " << type << endl;
		}
		
		if (extract(line) >> "video stream " >> setbase(16) >> cid) {
			cout << "video, cid = " << cid << endl;
			atVideo = true;
		}
		else if (extract(line) >> "audio stream " >> setbase(16) >> cid
							   >> " info " >> type) {
			cout << "audio, cid = " << cid << " (" << type << ")" << endl;

			if (type == "(AC3_audio):") {
				++ac3Tracks; // XXX
			} else {
								  mp2Tracks++;
			}
		}
		else if (extract(line) >> "App. Size (bytes)    " >> size)
			cout << "size = " << size << endl;
	}
	free(line);
	cout << "done" << endl;
}
