2009-07-19 06:13:46 +02:00
|
|
|
// Copyright (c) 2009, Karl Blomster
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2009-07-19 06:13:46 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file video_provider_yuv4mpeg.h
|
|
|
|
/// @see video_provider_yuv4mpeg.cpp
|
|
|
|
/// @ingroup video_input
|
|
|
|
///
|
2009-07-19 06:13:46 +02:00
|
|
|
|
|
|
|
#include "include/aegisub/video_provider.h"
|
2009-09-11 04:36:34 +02:00
|
|
|
#ifndef AGI_PRE
|
2009-07-19 06:13:46 +02:00
|
|
|
#include <stdio.h>
|
2009-09-11 04:36:34 +02:00
|
|
|
|
2009-07-19 06:13:46 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2009-09-11 04:36:34 +02:00
|
|
|
#include <wx/filename.h>
|
|
|
|
#include <wx/log.h>
|
|
|
|
#endif
|
|
|
|
|
2009-08-07 21:59:37 +02:00
|
|
|
/// the maximum allowed header length, in bytes
|
2009-07-19 06:13:46 +02:00
|
|
|
#define YUV4MPEG_HEADER_MAXLEN 128
|
|
|
|
|
2009-07-30 06:25:52 +02:00
|
|
|
/// @class YUV4MPEGVideoProvider
|
2009-08-07 21:59:37 +02:00
|
|
|
/// @brief Implements reading of YUV4MPEG uncompressed video files
|
2009-07-19 06:13:46 +02:00
|
|
|
class YUV4MPEGVideoProvider : public VideoProvider {
|
2009-08-07 21:59:37 +02:00
|
|
|
/// Pixel formats
|
2009-07-19 06:13:46 +02:00
|
|
|
enum Y4M_PixelFormat {
|
2009-08-07 21:59:37 +02:00
|
|
|
Y4M_PIXFMT_NONE = -1, /// not set/unknown
|
2009-07-30 06:25:52 +02:00
|
|
|
|
2009-08-07 21:59:37 +02:00
|
|
|
/// 4:2:0 sampling variants.
|
|
|
|
/// afaict the only difference between these three
|
|
|
|
/// is the chroma sample location, and nobody cares about that.
|
|
|
|
Y4M_PIXFMT_420JPEG, /// 4:2:0, H/V centered, for JPEG/MPEG-1
|
|
|
|
Y4M_PIXFMT_420MPEG2, /// 4:2:0, H cosited, for MPEG-2
|
|
|
|
Y4M_PIXFMT_420PALDV, /// 4:2:0, alternating Cb/Cr, for PAL-DV
|
2009-07-30 06:25:52 +02:00
|
|
|
|
2009-08-07 21:59:37 +02:00
|
|
|
Y4M_PIXFMT_411, /// 4:1:1, H cosited
|
|
|
|
Y4M_PIXFMT_422, /// 4:2:2, H cosited
|
|
|
|
Y4M_PIXFMT_444, /// 4:4:4, i.e. no chroma subsampling
|
|
|
|
Y4M_PIXFMT_444ALPHA, /// 4:4:4 plus alpha channel
|
2009-07-30 06:25:52 +02:00
|
|
|
|
2011-12-28 22:27:06 +01:00
|
|
|
Y4M_PIXFMT_MONO /// luma only (grayscale)
|
2009-07-19 06:13:46 +02:00
|
|
|
};
|
|
|
|
|
2009-07-30 06:25:52 +02:00
|
|
|
|
2009-08-07 21:59:37 +02:00
|
|
|
/// Interlacing mode for an entire stream
|
2009-07-19 06:13:46 +02:00
|
|
|
enum Y4M_InterlacingMode {
|
2009-08-07 21:59:37 +02:00
|
|
|
Y4M_ILACE_NOTSET = -1, /// undefined
|
|
|
|
Y4M_ILACE_PROGRESSIVE, /// progressive (no interlacing)
|
2009-07-30 06:25:52 +02:00
|
|
|
|
2009-08-07 21:59:37 +02:00
|
|
|
Y4M_ILACE_TFF, /// interlaced, top field first
|
|
|
|
Y4M_ILACE_BFF, /// interlaced, bottom field first
|
2009-07-30 06:25:52 +02:00
|
|
|
|
2009-08-07 21:59:37 +02:00
|
|
|
Y4M_ILACE_MIXED, /// mixed interlaced/progressive, possibly with RFF flags
|
2011-12-28 22:27:06 +01:00
|
|
|
Y4M_ILACE_UNKNOWN /// unknown interlacing mode (not the same as undefined)
|
2009-07-19 06:13:46 +02:00
|
|
|
};
|
|
|
|
|
2009-07-30 06:25:52 +02:00
|
|
|
|
2009-08-07 21:59:37 +02:00
|
|
|
/// Frame information flags
|
2009-07-19 06:13:46 +02:00
|
|
|
enum Y4M_FrameFlags {
|
2009-08-07 21:59:37 +02:00
|
|
|
Y4M_FFLAG_NOTSET = -1, /// undefined
|
|
|
|
Y4M_FFLAG_NONE = 0x0000, /// no flags set
|
|
|
|
|
|
|
|
/// field order/repeat field flags
|
|
|
|
Y4M_FFLAG_R_TFF = 0x0001, /// top field first
|
|
|
|
Y4M_FFLAG_R_TFF_R = 0x0002, /// top field first, and repeat that field
|
|
|
|
Y4M_FFLAG_R_BFF = 0x0004, /// bottom field first
|
|
|
|
Y4M_FFLAG_R_BFF_R = 0x0008, /// bottom field first, and repeat that field
|
|
|
|
Y4M_FFLAG_R_P = 0x0010, /// progressive
|
|
|
|
Y4M_FFLAG_R_P_R = 0x0020, /// progressive, and repeat frame once
|
|
|
|
Y4M_FFLAG_R_P_RR = 0x0040, /// progressive, and repeat frame twice
|
|
|
|
|
|
|
|
/// temporal sampling flags
|
|
|
|
Y4M_FFLAG_T_P = 0x0080, /// progressive (fields sampled at the same time)
|
|
|
|
Y4M_FFLAG_T_I = 0x0100, /// interlaced (fields sampled at different times)
|
|
|
|
|
|
|
|
/// chroma subsampling flags
|
|
|
|
Y4M_FFLAG_C_P = 0x0200, /// progressive (whole frame subsampled)
|
|
|
|
Y4M_FFLAG_C_I = 0x0400, /// interlaced (fields subsampled independently)
|
2011-12-28 22:27:06 +01:00
|
|
|
Y4M_FFLAG_C_UNKNOWN = 0x0800 /// unknown (only allowed for non-4:2:0 sampling)
|
2009-07-19 06:13:46 +02:00
|
|
|
};
|
|
|
|
|
2009-07-30 06:25:52 +02:00
|
|
|
|
2009-08-07 21:59:37 +02:00
|
|
|
FILE *sf; /// source file
|
|
|
|
bool inited; /// initialization state
|
2009-07-30 06:25:52 +02:00
|
|
|
|
2009-08-07 21:59:37 +02:00
|
|
|
int w, h; /// frame width/height
|
|
|
|
int num_frames; /// length of file in frames
|
|
|
|
int frame_sz; /// size of each frame in bytes
|
|
|
|
int luma_sz; /// size of the luma plane of each frame, in bytes
|
|
|
|
int chroma_sz; /// size of one of the two chroma planes of each frame, in bytes
|
|
|
|
int cur_fn; /// current frame number
|
2009-07-30 06:25:52 +02:00
|
|
|
|
2009-08-07 21:59:37 +02:00
|
|
|
Y4M_PixelFormat pixfmt; /// colorspace/pixel format
|
|
|
|
Y4M_InterlacingMode imode; /// interlacing mode (for the entire stream)
|
2009-07-19 06:13:46 +02:00
|
|
|
struct {
|
2009-08-07 21:59:37 +02:00
|
|
|
int num; /// numerator
|
|
|
|
int den; /// denominator
|
|
|
|
} fps_rat; /// framerate
|
2009-07-30 06:25:52 +02:00
|
|
|
|
2010-07-08 06:29:04 +02:00
|
|
|
agi::vfr::Framerate fps;
|
|
|
|
|
2009-08-07 21:59:37 +02:00
|
|
|
/// a list of byte positions detailing where in the file
|
|
|
|
/// each frame header can be found
|
|
|
|
std::vector<int64_t> seek_table;
|
2009-07-30 06:25:52 +02:00
|
|
|
|
2009-07-19 06:13:46 +02:00
|
|
|
void CheckFileFormat();
|
|
|
|
void ParseFileHeader(const std::vector<wxString>& tags);
|
|
|
|
Y4M_FrameFlags ParseFrameHeader(const std::vector<wxString>& tags);
|
|
|
|
std::vector<wxString> ReadHeader(int64_t startpos, bool reset_pos=false);
|
|
|
|
int IndexFile();
|
|
|
|
|
|
|
|
public:
|
2009-07-23 17:16:53 +02:00
|
|
|
YUV4MPEGVideoProvider(wxString filename);
|
2009-07-19 06:13:46 +02:00
|
|
|
~YUV4MPEGVideoProvider();
|
|
|
|
|
2009-07-20 05:50:25 +02:00
|
|
|
const AegiVideoFrame GetFrame(int n);
|
2009-07-30 06:25:52 +02:00
|
|
|
|
2010-07-08 06:29:04 +02:00
|
|
|
int GetFrameCount() const { return num_frames; }
|
|
|
|
int GetWidth() const { return w; }
|
|
|
|
int GetHeight() const { return h; }
|
|
|
|
agi::vfr::Framerate GetFPS() const { return fps; }
|
|
|
|
std::vector<int> GetKeyFrames() const { return std::vector<int>(); };
|
2011-09-28 21:43:11 +02:00
|
|
|
wxString GetDecoderName() const { return "YU4MPEG"; };
|
2010-07-08 06:29:04 +02:00
|
|
|
bool WantsCaching() const { return true; };
|
|
|
|
};
|