/*****************************************************************************
 *
 *  interfaceffprobe_struct.h -- InterfaceFFprobe settings and structures.
 *
 *  Copyright (C) 2010 Starbuck <starbuck@labdv.com>
 *  All rights reserved.
 *
 *  GNU Lesser General Public License Usage
 *  This file may be used under the terms of the GNU Lesser General
 *  Public License version 2.1 as published by the Free Software
 *  Foundation and appearing in the file LICENSE.LGPL included in the
 *  packaging of this file.  Please review the following information to
 *  ensure the GNU Lesser General Public License version 2.1 requirements
 *  will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 *
 *  GNU General Public License Usage
 *  Alternatively, this file may be used under the terms of the GNU
 *  General Public License version 3.0 as published by the Free Software
 *  Foundation and appearing in the file LICENSE.GPL included in the
 *  packaging of this file.  Please review the following information to
 *  ensure the GNU General Public License version 3.0 requirements will be
 *  met: http://www.gnu.org/copyleft/gpl.html.
 *
 *****************************************************************************/

#ifndef INTERFACEFFPROBE_STRUCT_H
#define INTERFACEFFPROBE_STRUCT_H

#include "../video/video_struct.h"
#include "../video/video_constants.h"
#include <QString>
#include <QList>

// FFprobe data
struct interfaceffprobe_t
{
	struct video_t
	{
		int index;	// ffmpeg mapping 0, 1 for 0.0, 0.1 etc
		QString codec;
		QString codec_long_name;
		QString codec_tag_string;   // usually FOURCC (or something like [0][0][0][0], U[0][0])
		QString pixel_format;
		QSize rez;
		double sample_aspect_ratio;
		double display_aspect_ratio;	// if > 100: display_aspect_ratio - 100 is MPEG-2 code
		double bitrate;					// kbps
		double fps;						// if > 100: display_aspect_ratio - 100 is MPEG-2 code
		double r_fps;
		double start_time; 
		double duration;

		video_t() { clear(); }

		void clear() 
		{
			index = 0;
			codec.clear();
			codec_long_name.clear();
			codec_tag_string.clear();
			pixel_format.clear();
			rez = QSize();
			sample_aspect_ratio = 0.0;
			display_aspect_ratio = 0.0;
			bitrate = 0.0;
			fps = 0.0;
			r_fps = 0.0;
			start_time = 0.0;
			duration = 0.0;
		}
	};

	struct audio_t
	{
		int index;	// ffmpeg mapping 0, 1 for 0.0, 0.1 etc
		QString codec;
		QString codec_long_name;
		int sampling;
		int bits;
		double bitrate;					// kbps
		int channels;
		double start_time;
		double duration; 
		QString language;
		QString title;

		audio_t() { clear(); }

		void clear() 
		{
			index = 0;
			codec.clear();
			codec_long_name.clear();
			sampling = 0;
			bits = 0;
			bitrate = 0.0;
			channels = 0;
			start_time = 0.0;
			duration = 0.0;
			language.clear();
			title.clear();
		}
	};

	struct subtitle_t
	{
		int index;	// ffmpeg mapping 0, 1 for 0.0, 0.1 etc
		QString codec;
		QString codec_long_name;
		QString language;
		QString title;

		subtitle_t() { clear(); }

		void clear() 
		{
			index = 0;
			codec.clear();
			codec_long_name.clear();
			language.clear();
			title.clear();
		}
	};

	QString path;
	QString muxer;
	QString muxer_long_name;
	double duration; 
	QList<video_t *> video;  // empty for audio files
	QList<audio_t *> audio;
	QList<subtitle_t *> subtitle;

	interfaceffprobe_t() { clear(); }

	void clear() 
	{
		path.clear();
		muxer.clear();
		muxer_long_name.clear();
		duration = 0.0;
		while (!video.isEmpty()) delete(video.takeLast());
		video.clear();
		while (!audio.isEmpty()) delete(audio.takeLast());
		audio.clear();
		while (!subtitle.isEmpty()) delete(subtitle.takeLast());
		subtitle.clear();
	}

	video_t *addVideo()
	{
		video_t *newVideo = new video_t;
		video.append(newVideo);
		return newVideo;
	}

	audio_t *addAudio()
	{
		audio_t *newAudio = new audio_t;
		audio.append(newAudio);
		return newAudio;
	}

	subtitle_t *addSubtitle()
	{
		subtitle_t *newSubtitle = new subtitle_t;
		subtitle.append(newSubtitle);
		return newSubtitle;
	}
};

#endif
