refactored VideoReader (convert it to abstract interface)

also refactored VideoSource interface (made it simplier, now it has only 2 abstract methods)
This commit is contained in:
Vladislav Vinogradov
2013-06-11 13:05:02 +04:00
parent e9a74c17f8
commit 76211709a3
23 changed files with 616 additions and 728 deletions

View File

@@ -48,8 +48,6 @@
# error gpucodec.hpp header must be compiled as C++
#endif
#include <iosfwd>
#include "opencv2/core/gpu.hpp"
namespace cv { namespace gpucodec {
@@ -144,112 +142,65 @@ CV_EXPORTS Ptr<VideoWriter> createVideoWriter(const String& fileName, Size frame
CV_EXPORTS Ptr<VideoWriter> createVideoWriter(const Ptr<EncoderCallBack>& encoderCallback, Size frameSize, double fps, SurfaceFormat format = SF_BGR);
CV_EXPORTS Ptr<VideoWriter> createVideoWriter(const Ptr<EncoderCallBack>& encoderCallback, Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
}} // namespace cv { namespace gpucodec {
namespace cv { namespace gpu {
////////////////////////////////// Video Decoding //////////////////////////////////////////
namespace detail
enum Codec
{
class FrameQueue;
class VideoParser;
}
MPEG1 = 0,
MPEG2,
MPEG4,
VC1,
H264,
JPEG,
H264_SVC,
H264_MVC,
class CV_EXPORTS VideoReader_GPU
{
public:
enum Codec
{
MPEG1 = 0,
MPEG2,
MPEG4,
VC1,
H264,
JPEG,
H264_SVC,
H264_MVC,
Uncompressed_YUV420 = (('I'<<24)|('Y'<<16)|('U'<<8)|('V')), // Y,U,V (4:2:0)
Uncompressed_YV12 = (('Y'<<24)|('V'<<16)|('1'<<8)|('2')), // Y,V,U (4:2:0)
Uncompressed_NV12 = (('N'<<24)|('V'<<16)|('1'<<8)|('2')), // Y,UV (4:2:0)
Uncompressed_YUYV = (('Y'<<24)|('U'<<16)|('Y'<<8)|('V')), // YUYV/YUY2 (4:2:2)
Uncompressed_UYVY = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y')), // UYVY (4:2:2)
};
enum ChromaFormat
{
Monochrome=0,
YUV420,
YUV422,
YUV444,
};
struct FormatInfo
{
Codec codec;
ChromaFormat chromaFormat;
int width;
int height;
};
class VideoSource;
VideoReader_GPU();
explicit VideoReader_GPU(const String& filename);
explicit VideoReader_GPU(const cv::Ptr<VideoSource>& source);
~VideoReader_GPU();
void open(const String& filename);
void open(const cv::Ptr<VideoSource>& source);
bool isOpened() const;
void close();
bool read(GpuMat& image);
FormatInfo format() const;
void dumpFormat(std::ostream& st);
class CV_EXPORTS VideoSource
{
public:
VideoSource() : frameQueue_(0), videoParser_(0) {}
virtual ~VideoSource() {}
virtual FormatInfo format() const = 0;
virtual void start() = 0;
virtual void stop() = 0;
virtual bool isStarted() const = 0;
virtual bool hasError() const = 0;
void setFrameQueue(detail::FrameQueue* frameQueue) { frameQueue_ = frameQueue; }
void setVideoParser(detail::VideoParser* videoParser) { videoParser_ = videoParser; }
protected:
bool parseVideoData(const uchar* data, size_t size, bool endOfStream = false);
private:
VideoSource(const VideoSource&);
VideoSource& operator =(const VideoSource&);
detail::FrameQueue* frameQueue_;
detail::VideoParser* videoParser_;
};
class Impl;
private:
cv::Ptr<Impl> impl_;
Uncompressed_YUV420 = (('I'<<24)|('Y'<<16)|('U'<<8)|('V')), // Y,U,V (4:2:0)
Uncompressed_YV12 = (('Y'<<24)|('V'<<16)|('1'<<8)|('2')), // Y,V,U (4:2:0)
Uncompressed_NV12 = (('N'<<24)|('V'<<16)|('1'<<8)|('2')), // Y,UV (4:2:0)
Uncompressed_YUYV = (('Y'<<24)|('U'<<16)|('Y'<<8)|('V')), // YUYV/YUY2 (4:2:2)
Uncompressed_UYVY = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y')) // UYVY (4:2:2)
};
}} // namespace cv { namespace gpu {
enum ChromaFormat
{
Monochrome = 0,
YUV420,
YUV422,
YUV444
};
namespace cv {
struct FormatInfo
{
Codec codec;
ChromaFormat chromaFormat;
int width;
int height;
};
template <> CV_EXPORTS void Ptr<cv::gpu::VideoReader_GPU::Impl>::delete_obj();
class CV_EXPORTS VideoReader
{
public:
virtual ~VideoReader() {}
}
virtual bool nextFrame(OutputArray frame) = 0;
virtual FormatInfo format() const = 0;
};
class CV_EXPORTS RawVideoSource
{
public:
virtual ~RawVideoSource() {}
virtual bool getNextPacket(unsigned char** data, int* size, bool* endOfFile) = 0;
virtual FormatInfo format() const = 0;
};
CV_EXPORTS Ptr<VideoReader> createVideoReader(const String& filename);
CV_EXPORTS Ptr<VideoReader> createVideoReader(const Ptr<RawVideoSource>& source);
}} // namespace cv { namespace gpucodec {
#endif /* __OPENCV_GPUCODEC_HPP__ */