2011-10-11 08:44:27 -05:00
|
|
|
/**
|
2013-09-09 23:32:16 -05:00
|
|
|
* @file
|
|
|
|
|
* @brief Header file for ReaderBase class
|
2013-09-12 17:52:10 -05:00
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
|
|
|
|
*
|
|
|
|
|
* @section LICENSE
|
|
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* Copyright (c) 2008-2014 OpenShot Studios, LLC
|
|
|
|
|
* <http://www.openshotstudios.com/>. This file is part of
|
|
|
|
|
* OpenShot Library (libopenshot), an open-source project dedicated to
|
|
|
|
|
* delivering high quality video editing and animation solutions to the
|
|
|
|
|
* world. For more information visit <http://www.openshot.org/>.
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is free software: you can redistribute it
|
2014-07-11 16:52:14 -05:00
|
|
|
* and/or modify it under the terms of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* as published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is distributed in the hope that it will be
|
|
|
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2014-07-11 16:52:14 -05:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2014-07-11 16:52:14 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
2011-10-11 08:44:27 -05:00
|
|
|
*/
|
|
|
|
|
|
2013-09-12 17:52:10 -05:00
|
|
|
#ifndef OPENSHOT_READER_BASE_H
|
|
|
|
|
#define OPENSHOT_READER_BASE_H
|
|
|
|
|
|
2011-10-11 08:44:27 -05:00
|
|
|
#include <iostream>
|
|
|
|
|
#include <iomanip>
|
2012-10-14 03:43:52 -05:00
|
|
|
#include <tr1/memory>
|
2013-12-07 21:09:55 -06:00
|
|
|
#include <stdlib.h>
|
2015-02-05 00:00:52 -06:00
|
|
|
#include "ChannelLayouts.h"
|
2011-10-11 08:44:27 -05:00
|
|
|
#include "Fraction.h"
|
|
|
|
|
#include "Frame.h"
|
2013-12-03 00:13:25 -06:00
|
|
|
#include "Json.h"
|
2014-01-23 13:32:07 +08:00
|
|
|
#include <QtCore/qstring.h>
|
2014-01-22 01:08:14 -06:00
|
|
|
#include <QGraphicsItem>
|
|
|
|
|
#include <QGraphicsScene>
|
|
|
|
|
#include <QGraphicsPixmapItem>
|
|
|
|
|
#include <QPixmap>
|
2011-10-11 08:44:27 -05:00
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
namespace openshot
|
|
|
|
|
{
|
|
|
|
|
/**
|
2013-09-09 23:32:16 -05:00
|
|
|
* @brief This struct contains info about a media file, such as height, width, frames per second, etc...
|
2011-10-11 08:44:27 -05:00
|
|
|
*
|
2013-09-08 16:40:57 -05:00
|
|
|
* Each derived class of ReaderBase is responsible for updating this struct to reflect accurate information
|
|
|
|
|
* about the streams. Derived classes of ReaderBase should call the InitFileInfo() method to initialize the
|
2011-10-11 08:44:27 -05:00
|
|
|
* default values of this struct.
|
|
|
|
|
*/
|
2012-07-12 15:55:41 -05:00
|
|
|
struct ReaderInfo
|
2011-10-11 08:44:27 -05:00
|
|
|
{
|
|
|
|
|
bool has_video; ///< Determines if this file has a video stream
|
|
|
|
|
bool has_audio; ///< Determines if this file has an audio stream
|
|
|
|
|
float duration; ///< Length of time (in seconds)
|
2012-08-29 15:29:15 -05:00
|
|
|
long long file_size; ///< Size of file (in bytes)
|
2011-10-11 08:44:27 -05:00
|
|
|
int height; ///< The height of the video (in pixels)
|
|
|
|
|
int width; ///< The width of the video (in pixesl)
|
|
|
|
|
int pixel_format; ///< The pixel format (i.e. YUV420P, RGB24, etc...)
|
|
|
|
|
Fraction fps; ///< Frames per second, as a fraction (i.e. 24/1 = 24 fps)
|
|
|
|
|
int video_bit_rate; ///< The bit rate of the video stream (in bytes)
|
|
|
|
|
Fraction pixel_ratio; ///< The pixel ratio of the video stream as a fraction (i.e. some pixels are not square)
|
|
|
|
|
Fraction display_ratio; ///< The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3)
|
|
|
|
|
string vcodec; ///< The name of the video codec used to encode / decode the video stream
|
2011-12-11 20:42:50 -06:00
|
|
|
long int video_length; ///< The number of frames in the video stream
|
2011-10-11 08:44:27 -05:00
|
|
|
int video_stream_index; ///< The index of the video stream
|
|
|
|
|
Fraction video_timebase; ///< The video timebase determines how long each frame stays on the screen
|
2011-12-11 20:42:50 -06:00
|
|
|
bool interlaced_frame; // Are the contents of this frame interlaced
|
|
|
|
|
bool top_field_first; // Which interlaced field should be displayed first
|
2011-10-11 08:44:27 -05:00
|
|
|
string acodec; ///< The name of the audio codec used to encode / decode the video stream
|
|
|
|
|
int audio_bit_rate; ///< The bit rate of the audio stream (in bytes)
|
|
|
|
|
int sample_rate; ///< The number of audio samples per second (44100 is a common sample rate)
|
|
|
|
|
int channels; ///< The number of audio channels used in the audio stream
|
2015-02-05 00:00:52 -06:00
|
|
|
ChannelLayout channel_layout; ///< The channel layout (mono, stereo, 5 point surround, etc...)
|
2011-10-11 08:44:27 -05:00
|
|
|
int audio_stream_index; ///< The index of the audio stream
|
|
|
|
|
Fraction audio_timebase; ///< The audio timebase determines how long each audio packet should be played
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2013-09-10 22:11:47 -05:00
|
|
|
* @brief This abstract class is the base class, used by all readers in libopenshot.
|
2011-10-11 08:44:27 -05:00
|
|
|
*
|
2013-09-10 22:11:47 -05:00
|
|
|
* Readers are types of classes that read video, audio, and image files, and
|
|
|
|
|
* return openshot::Frame objects. The only requirements for a 'reader', are to
|
|
|
|
|
* derive from this base class, implement the GetFrame method, and call the InitFileInfo() method.
|
2011-10-11 08:44:27 -05:00
|
|
|
*/
|
2013-09-08 16:40:57 -05:00
|
|
|
class ReaderBase
|
2011-10-11 08:44:27 -05:00
|
|
|
{
|
2014-08-27 09:44:27 -05:00
|
|
|
protected:
|
|
|
|
|
/// Section lock for multiple threads
|
2014-02-12 14:55:49 +08:00
|
|
|
CriticalSection getFrameCriticalSection;
|
|
|
|
|
|
2014-08-27 09:44:27 -05:00
|
|
|
/// Debug JSON root
|
|
|
|
|
Json::Value debug_root;
|
|
|
|
|
|
|
|
|
|
/// Append debug information as JSON
|
|
|
|
|
void AppendDebugItem(Json::Value debug_item);
|
|
|
|
|
|
|
|
|
|
/// Append debug information as JSON
|
2015-02-24 23:59:26 -06:00
|
|
|
void AppendDebugMethod(string method_name, string arg1_name, float arg1_value,
|
|
|
|
|
string arg2_name, float arg2_value,
|
|
|
|
|
string arg3_name, float arg3_value,
|
|
|
|
|
string arg4_name, float arg4_value,
|
|
|
|
|
string arg5_name, float arg5_value,
|
|
|
|
|
string arg6_name, float arg6_value);
|
2014-08-27 09:44:27 -05:00
|
|
|
|
2011-10-11 08:44:27 -05:00
|
|
|
public:
|
2014-08-27 09:44:27 -05:00
|
|
|
|
|
|
|
|
/// Constructor for the base reader, where many things are initialized.
|
|
|
|
|
ReaderBase();
|
|
|
|
|
|
|
|
|
|
/// Enable or disable debug output. Output will display on the standard output, and you can
|
|
|
|
|
/// optionally invoke the OutputDebugJSON() method, which will format the debug output as JSON.
|
|
|
|
|
bool debug;
|
|
|
|
|
|
2011-10-11 08:44:27 -05:00
|
|
|
/// Information about the current media file
|
2012-07-12 15:55:41 -05:00
|
|
|
ReaderInfo info;
|
2011-10-11 08:44:27 -05:00
|
|
|
|
2012-10-08 16:22:18 -05:00
|
|
|
/// Close the reader (and any resources it was consuming)
|
|
|
|
|
virtual void Close() = 0;
|
|
|
|
|
|
|
|
|
|
/// Display file information in the standard output stream (stdout)
|
|
|
|
|
void DisplayInfo();
|
|
|
|
|
|
2014-08-27 09:44:27 -05:00
|
|
|
/// Test method to draw a bitmap on a Qt QGraphicsScene
|
|
|
|
|
void DrawFrameOnScene(string path, long _graphics_scene_address);
|
|
|
|
|
|
2013-09-28 22:00:52 -05:00
|
|
|
/// This method is required for all derived classes of ReaderBase, and returns the
|
2011-10-11 08:44:27 -05:00
|
|
|
/// openshot::Frame object, which contains the image and audio information for that
|
|
|
|
|
/// frame of video.
|
|
|
|
|
///
|
|
|
|
|
/// @returns The requested frame of video
|
|
|
|
|
/// @param[in] number The frame number that is requested.
|
2012-10-14 03:43:52 -05:00
|
|
|
virtual tr1::shared_ptr<Frame> GetFrame(int number) = 0;
|
2011-10-11 08:44:27 -05:00
|
|
|
|
2014-02-12 14:55:49 +08:00
|
|
|
/// A thread safe version of GetFrame.
|
|
|
|
|
tr1::shared_ptr<Frame> GetFrameSafe(int number);
|
|
|
|
|
|
2013-12-18 21:55:43 -06:00
|
|
|
/// Determine if reader is open or closed
|
|
|
|
|
virtual bool IsOpen() = 0;
|
|
|
|
|
|
2013-12-07 16:52:09 -06:00
|
|
|
/// Get and Set JSON methods
|
2013-12-07 21:09:55 -06:00
|
|
|
virtual string Json() = 0; ///< Generate JSON string of this object
|
|
|
|
|
virtual void SetJson(string value) throw(InvalidJSON) = 0; ///< Load JSON string into this object
|
2013-12-18 21:55:43 -06:00
|
|
|
virtual Json::Value JsonValue() = 0; ///< Generate Json::JsonValue for this object
|
|
|
|
|
virtual void SetJsonValue(Json::Value root) = 0; ///< Load Json::JsonValue into this object
|
2013-12-03 00:13:25 -06:00
|
|
|
|
2012-10-08 16:22:18 -05:00
|
|
|
/// Open the reader (and start consuming resources, such as images or video files)
|
|
|
|
|
virtual void Open() = 0;
|
2014-08-27 09:44:27 -05:00
|
|
|
|
|
|
|
|
/// Output debug information as JSON
|
|
|
|
|
string OutputDebugJSON();
|
|
|
|
|
|
2011-10-11 08:44:27 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|