/** * @class vetCodec_MOV * * @brief This module interfaces VETLib standard format with quicktime4linux * library, it's able to decode and encode following formats: * * - JPEG, MJPA, RGB, PNG, or YUV2 compression * - YUV 4:2:2, and YUV 4:2:0 * * quicktime4linux library requires libpthread * * * @bug errors after writing file. * * @warning Linux Only; require quicktime4linux library (1.4 or greater) * * @todo more tests, audio support, raw data access * * @see vetCodec * @see quicktime4linux * * @example test_vetCodec_MOV.cpp * @example test_vetLinuxMOVPlayer.cpp * @example test_vetLinuxMOVPlayerGTK.cpp * * @version 0.8 * @date 12/09/2005 * @author Alessandro Polo * * **************************************************************************** * VETLib Framework 1.0.2 * Copyright (C) Alessandro Polo 2006 * http://www.ewgate.net/vetlib * ****************************************************************************/ #ifndef __VETLIB_VETCODEC_MOV_H__ #define __VETLIB_VETCODEC_MOV_H__ #include "../vetDefs.h" #include "../vetCodec.h" #include "../vetFrameYUV420.h" #include "../vetFrameRGB24.h" #include "../vetFrameT.h" // struct quicktime_t; extern "C" { #include "../../support/quicktime4linux/quicktime.h" } class vetCodec_MOVParameters : public vetCodecParameters { protected: char fileName[128]; long frameIndex; int stream; friend class vetCodec_MOV; public: /** * @brief Default constructor, call reset(). */ vetCodec_MOVParameters(); /** * @brief Full constructor, call reset() and set parameters. * * @param[in] filename pointer to NULL terminated string [max 128]. * @param[in] stream movie's stream to load (default=0, first stream) * @param[in] frameIndex stream position (default=0, first frame) * */ vetCodec_MOVParameters(const char* filename, int stream = 0, long frameIndex = 0 ); /** * @brief Default destructor. */ ~vetCodec_MOVParameters() { } /** * @brief Reset all parameters: filename, current stream, frame index. */ void reset(); /** * @brief set current stream (it's not applied really, but must call * load(stream) of vetCodec_MOV class). * * @param[in] stream movie's stream to load (default=0, first stream) */ void setStream(int stream = 0); /** * @brief set current stream (it's not applied really, but must call * load(filename, stream) of vetCodec_MOV class). * * @param[in] stream movie's filename to load (NULL Terminated string, max 128) */ void setFileName(const char *filename); /** * @brief set current frame index (it's not applied really, but must call * setFrameIndex(index) of vetCodec_MOV class). * * @param[in] frameIndex stream position (default=0, first frame) */ void setFrameIndex(long index = 0); /** * @brief Serialize class to XML format. * Class' tag is * * @param[in] fp output stream's pointer * * @return VETRET_OK if everything is fine, VETRET_INTERNAL_ERR else. */ VETRESULT saveToStreamXML(FILE *fp); /** * @brief Deserialize class from XML format. * Class' tag must be * * @param[in] fp input stream's pointer * * @return VETRET_OK if everything is fine, VETRET_INTERNAL_ERR else. */ VETRESULT loadFromStreamXML(FILE *fp); }; class vetCodec_MOV : public vetCodec { protected: /** * @brief vetCodec_MOV parameters pointer. */ vetCodec_MOVParameters* myParams; /** * @brief Quicktime file handle. */ quicktime_t* file; /** * @brief decoded data buffer. */ unsigned char** buff; /** * @brief number of frames (total). */ long lenghtFrames; /** * @brief when last frame is extracted this is set to true. */ bool streamEOF; /** * @brief quicktime movie width. */ unsigned int width; /** * @brief quicktime movie height. */ unsigned int height; /** * @brief frame rate */ float outFrameRate; public: /** * @brief Default constructor, initialize parameters and superclasses. * @param[in] initParams parameters for this module or NULL for defaults. */ vetCodec_MOV(vetCodec_MOVParameters* initParams = NULL); /** * @brief Initialize parameters and load given mpeg movie. * * @param[in] filename a valid MPEG1-2 movie filename * @param[in] stream video stream to load (default is first: 0) * */ vetCodec_MOV(char* filename, int stream = 0); /** * @brief Default destructor, close file and free buffer. */ ~vetCodec_MOV(); /** * @brief Load a BMP format image into current buffer (vetFrameRGB). * * @param[in] filename a valid MPEG1-2 movie filename * @param[in] w movie's width * @param[in] h movie's height * @param[in] frame_rate movie's fps * @param[in] quality jpeg compression quality value [10, 100], default 80; * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @see save() */ VETRESULT newVideo(char* filename, unsigned int w, unsigned int h, float frame_rate, int quality = 80); /** * @brief Save new movie to file, must be called at the end of writing, * use newVideo(..) to create an empty video. * * @return VETRET_ILLEGAL_USE if file is not correctly loaded, VETRET_OK else. * * @see newVideo(char*, unsigned int, unsigned int, float, int) */ VETRESULT save(); /** * @brief Load movie from current filename, use SetFileName() or * load(char*, int). * * @return VETRET_ILLEGAL_USE if file is not correctly loaded, VETRET_OK else. */ VETRESULT load(); /** * @brief Load a BMP format image into current buffer (vetFrameRGB). * * @param[in] filename a valid MPEG1-2 movie filename * @param[in] stream video stream to load (default is first: 0) * * @return VETRET_ILLEGAL_USE if file is not correctly loaded, VETRET_OK else. */ VETRESULT load(char* filename, int stream = 0); VETRESULT save(char* filename, int stream = 0) { return VETRET_NOT_IMPLEMENTED; }; /** * @brief Set parameters for (de)coding. * * @param[in] initParams Instance of vetCodec_MOVParameters or NULL, * NULL argument make function to create a new * instance with default parameters. * * @return VETRET_OK */ VETRESULT setParameters(vetCodec_MOVParameters* initParams); /** * @brief Get parameters for (de)coding. * * @return pointer to vetCodec_MOVParameters class. */ vetCodec_MOVParameters& getParameters() { return *myParams; }; VETRESULT setFilterParameters (vetFilterParameters* initParams) { return setParameters(static_cast(initParams)); }; vetFilterParameters* getFilterParameters () { return static_cast(myParams); }; /** * @brief Reset filename and movie related settings. * * @return VETRET_OK */ VETRESULT reset(); /** * @brief Get the state of current data source. * * @return true is there are no more frames to load, false else. */ // bool EoF() const { return streamEOF; }; bool EoF(); /** * @brief Test for end of file. * * @return true if frame index is last frame, false else. */ // FRAME BROWSING FUNCTIONS /** * @brief Read current frame index (position in the video timeline). * * @param[in] stream select stream index. * default is -1: current active stream. * * @return current frame index, -1 if stream has not been loaded. * */ long getAudioFrameIndex(int stream = -1); /** * @brief Read current sample index (position in the audio timeline). * * @param[in] stream select stream index. * default is -1: current active stream. * * @return current frame index, -1 if stream has not been loaded. */ long getVideoFrameIndex(int stream = -1); /** * @brief Seek to point in stream (position in the video timeline). * * @param[in] index position to set, number of frame offset [0, framesCount[ * @param[in] stream select stream index. * default is -1: current active stream. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if index or * stream are not valid, VETRET_ILLEGAL_USE if stream hasn't been loaded. */ VETRESULT setFrameIndex(long index, int stream = -1); /** * @brief Move frame index to start (first frame) * * @return VETRET_OK if everything is fine, VETRET_ILLEGAL_USE is stream * hasn't been loaded. */ VETRESULT goToStart(); /** * @brief Move frame index to end (last frame) * * @return VETRET_OK if everything is fine, VETRET_ILLEGAL_USE is stream * hasn't been loaded. */ VETRESULT goToEnd(); /** * @brief * * @param[in] fps * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. */ VETRESULT setVideoFrameRate(float fps); // VIDEO INFO FUNCTIONS /** * @brief Set current canvas' height. * * @return height in pixel. */ VETRESULT setHeight(unsigned int value) { height = value; return VETRET_OK; }; /** * @brief Set current canvas' width. * * @return width in pixel. */ VETRESULT setWidth(unsigned int value) { width = value; return VETRET_OK; }; /** * @brief read current image's width. * * @return Width in pixel. */ unsigned int getWidth() const { return width; }; /** * @brief read current image's height. * * @return Height in pixel. */ unsigned int getHeight() const { return height; }; /** * @brief read current image's depth. * * @param[in] stream select stream index. * default is -1: current active stream. * * @return movie's depth. */ int getVideoDepth(int stream = 0); /** * @brief check if loaded movie has a video stream. * * @return true if there is at least one video stream, false else. */ bool hasVideo(); /** * @brief get movie's video streams count. * * @return number of video streams. */ int getVideoStreamCount(); /** * @brief get movie's video frame rate. * * @param[in] stream select stream index. * default is -1: current active stream. * * @return number of frame per second. */ float getVideoFrameRate(int stream = -1); /** * @brief get movie's video frame count. * * @param[in] stream select stream index. * default is -1: current active stream. * * @return number of frames in the stream. */ long getVideoStreamLength(int stream = -1); /** * @brief get movie's video compressor name. * * @param[in] stream select stream index. * default is -1: current active stream. * * @return pointer to a NULL terminated string.. */ char* getVideoCompressor(int stream = -1); // AUDIO INFO FUNCTIONS /** * @brief get movie's audio streams count. * * @return number of audio streams. */ bool hasAudio(); /** * @brief get movie's audio streams count. * * @return number of audio streams. */ int getAudioStreamCount(); /** * @brief get movie's audio channel count for selected stream. * * @param[in] stream select stream index. * default is -1: current active stream. * * @return number of audio channels. */ int getAudioChannels(int stream = -1); /** * @brief get movie's audio sample rate for selected stream. * * @param[in] stream select stream index. * default is -1: current active stream. * * @return number of sample per second. */ long getAudioSampleRate(int stream = -1); /** * @brief get movie's audio sample count for selected stream. * * @param[in] stream select stream index. * default is -1: current active stream. * * @return number of sample. */ long getAudioStreamLength(int stream = -1); /** * @brief get movie's audio compressor name. * * @param[in] stream select stream index. * default is -1: current active stream. * * @return pointer to a NULL terminated string. */ char* getAudioCompressor(int stream = -1); // MOVIE INFORMATIONS FUNCTIONS /** * @brief set movie's name. * * @param[in] string pointer to a NULL terminated string * * @return VETRET_OK if everything is fine, VETRET_ILLEGAL_USE if movie * hasn't been loaded. */ VETRESULT setName(char *string); /** * @brief set movie's informations. * * @param[in] string pointer to a NULL terminated string * * @return VETRET_OK if everything is fine, VETRET_ILLEGAL_USE if movie * hasn't been loaded. */ VETRESULT setInfo(char *string); /** * @brief set movie's copyright. * * @param[in] string pointer to a NULL terminated string * * @return VETRET_OK if everything is fine, VETRET_ILLEGAL_USE if movie * hasn't been loaded. */ VETRESULT setCopyRight(char *string); /** * @brief get movie's name. * * @return pointer to a NULL terminated string. */ char* getName(); /** * @brief get movie's informations. * * @return pointer to a NULL terminated string. */ char* getInfo(); /** * @brief get movie's copyright. * * @return pointer to a NULL terminated string. */ char* getCopyRight(); /** * @brief Load current frame data into image (parameter), increments * frame index. * * @param[out] img VETLib Cache Frame to store data. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note Ouput operator (>>) call directly this function. * @see operator >> (vetFrameYUV420&) */ VETRESULT extractTo(vetFrameYUV420& img); /** * @brief Load current frame data into image (parameter), increments * frame index. * * @param[out] img VETLib Cache24 Frame to store data. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note Ouput operator (>>) call directly this function. * @see operator >> (vetFrameRGB24&) */ VETRESULT extractTo(vetFrameRGB24& img); /** * @brief Load current frame data into image (parameter), increments * frame index. * * @param[out] img Greyscale VETLib Frame to store data. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note Ouput operator (>>) call directly this function. * @see operator >> (vetFrameT&) */ VETRESULT extractTo(vetFrameT& img); /** * @brief Encode given image to stream, increments frame index. * * @param[in] img VETLib Cache Frame to be encoded. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note Input operator (<<) call directly this function. * @see operator << (vetFrameYUV420&) */ VETRESULT importFrom(vetFrameYUV420& img); /** * @brief Encode given image to stream, increments frame index. * * @param[in] img VETLib Cache Frame to be encoded. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note Input operator (<<) call directly this function. * @see operator << (vetFrameRGB24&) */ VETRESULT importFrom(vetFrameRGB24& img); /** * @brief Encode given image to stream, increments frame index. * * @param[in] img VETLib Cache Frame to be encoded. * * @return VETRET_OK if everything is fine, VETRET_PARAM_ERR if frame * is not valid, VETRET_INTERNAL_ERR or VETRET_ILLEGAL_USE else. * * @note Input operator (<<) call directly this function. * @see operator << (vetFrameT&) */ VETRESULT importFrom(vetFrameT& img); /** * @brief Input operator, import standard VETLib frame formats, * current implementation calls directly importFrom() method. * * @param[in] img VETLib Cache Frame to be processed (encoded for example) * * @see importFrom(vetFrameYUV420&) */ // void operator << (vetFrameYUV420& img) { vetOutput::operator << (img); } // void operator << (vetFrameRGB24& img) { vetOutput::operator << (img); } // void operator << (vetFrameT& img) { vetOutput::operator << (img); } /** * @brief Ouput operator, export to standard VETLib frame formats, * current implementation calls directly extractTo() method * and if framerate isn't zero waits untill clock is syncronized, * if elaboration time is greater than sleeptime, no delay is applied. * * @param[out] img VETLib Cache Frame to store data. * * @return Address of current instance. * * @see importFrom(vetFrameYUV420&) * @see vetsleep() * @see setElaborationStart() * @see getElaborationTime() */ // vetInput& operator >> (vetFrameYUV420& img) { vetInput::operator >> (img); return *this; } // vetInput& operator >> (vetFrameRGB24& img) { vetInput::operator >> (img); return *this; } // vetInput& operator >> (vetFrameT& img) { vetInput::operator >>( img); return *this; } bool isEncodingAvailable() { return true; }; bool isDecodingAvailable() { return true; }; }; #endif //__VETLIB_VETCODEC_MOV_H__