2009-04-06 21:14:55 +02:00
|
|
|
// Copyright (c) 2007-2009 Fredrik Mellbin
|
2008-09-01 23:16:13 +02:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
#ifndef FFVIDEOSOURCE_H
|
|
|
|
#define FFVIDEOSOURCE_H
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
#include <libswscale/swscale.h>
|
|
|
|
#include <libpostproc/postprocess.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include "indexing.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "ffms.h"
|
|
|
|
|
2009-04-11 20:45:40 +02:00
|
|
|
#ifdef HAALISOURCE
|
2008-12-31 00:57:22 +01:00
|
|
|
# define _WIN32_DCOM
|
|
|
|
# include <windows.h>
|
|
|
|
# include <tchar.h>
|
|
|
|
# include <atlbase.h>
|
|
|
|
# include <dshow.h>
|
|
|
|
# include "CoParser.h"
|
|
|
|
# include <initguid.h>
|
|
|
|
# include "guids.h"
|
|
|
|
#endif
|
|
|
|
|
2008-09-01 23:16:13 +02:00
|
|
|
class VideoBase {
|
|
|
|
private:
|
|
|
|
pp_context_t *PPContext;
|
|
|
|
pp_mode_t *PPMode;
|
2008-09-09 22:49:59 +02:00
|
|
|
SwsContext *SWS;
|
2008-09-01 23:16:13 +02:00
|
|
|
protected:
|
|
|
|
VideoProperties VP;
|
|
|
|
AVFrame *DecodeFrame;
|
2008-09-09 22:49:59 +02:00
|
|
|
AVFrame *PPFrame;
|
|
|
|
AVFrame *FinalFrame;
|
2008-09-01 23:16:13 +02:00
|
|
|
int LastFrameNum;
|
|
|
|
FrameInfoVector Frames;
|
|
|
|
int VideoTrack;
|
|
|
|
int CurrentFrame;
|
|
|
|
AVCodecContext *CodecContext;
|
|
|
|
|
|
|
|
VideoBase();
|
2009-04-06 22:15:49 +02:00
|
|
|
int InitPP(const char *PP, PixelFormat PixelFormat, char *ErrorMsg, unsigned MsgSize);
|
2008-09-01 23:16:13 +02:00
|
|
|
AVFrameLite *OutputFrame(AVFrame *Frame);
|
|
|
|
public:
|
|
|
|
virtual ~VideoBase();
|
2008-09-12 22:41:29 +02:00
|
|
|
const VideoProperties& GetVideoProperties() { return VP; }
|
2008-09-01 23:16:13 +02:00
|
|
|
FrameInfoVector *GetFrameInfoVector() { return &Frames; }
|
2008-09-09 22:49:59 +02:00
|
|
|
virtual AVFrameLite *GetFrame(int n, char *ErrorMsg, unsigned MsgSize) = 0;
|
2008-09-01 23:16:13 +02:00
|
|
|
AVFrameLite *GetFrameByTime(double Time, char *ErrorMsg, unsigned MsgSize);
|
2008-10-01 20:13:12 +02:00
|
|
|
int SetOutputFormat(int TargetFormats, int Width, int Height, char *ErrorMsg, unsigned MsgSize);
|
2008-09-09 22:49:59 +02:00
|
|
|
void ResetOutputFormat();
|
2008-09-01 23:16:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class FFVideoSource : public VideoBase {
|
|
|
|
private:
|
|
|
|
AVFormatContext *FormatContext;
|
|
|
|
int SeekMode;
|
2008-09-06 22:05:29 +02:00
|
|
|
|
|
|
|
void Free(bool CloseCodec);
|
2008-09-01 23:16:13 +02:00
|
|
|
int DecodeNextFrame(AVFrame *Frame, int64_t *DTS, char *ErrorMsg, unsigned MsgSize);
|
|
|
|
public:
|
|
|
|
FFVideoSource(const char *SourceFile, int Track, FrameIndex *TrackIndices, const char *PP, int Threads, int SeekMode, char *ErrorMsg, unsigned MsgSize);
|
|
|
|
~FFVideoSource();
|
|
|
|
AVFrameLite *GetFrame(int n, char *ErrorMsg, unsigned MsgSize);
|
|
|
|
};
|
|
|
|
|
|
|
|
class MatroskaVideoSource : public VideoBase {
|
|
|
|
private:
|
|
|
|
MatroskaFile *MF;
|
|
|
|
MatroskaReaderContext MC;
|
2008-09-04 00:26:27 +02:00
|
|
|
CompressedStream *CS;
|
|
|
|
char ErrorMessage[256];
|
2008-09-01 23:16:13 +02:00
|
|
|
|
2008-09-06 22:05:29 +02:00
|
|
|
void Free(bool CloseCodec);
|
2008-09-01 23:16:13 +02:00
|
|
|
int DecodeNextFrame(AVFrame *AFrame, int64_t *AFirstStartTime, char *ErrorMsg, unsigned MsgSize);
|
|
|
|
public:
|
|
|
|
MatroskaVideoSource(const char *SourceFile, int Track, FrameIndex *TrackIndices, const char *PP, int Threads, char *ErrorMsg, unsigned MsgSize);
|
|
|
|
~MatroskaVideoSource();
|
|
|
|
AVFrameLite *GetFrame(int n, char *ErrorMsg, unsigned MsgSize);
|
|
|
|
};
|
|
|
|
|
2009-04-11 20:45:40 +02:00
|
|
|
#ifdef HAALISOURCE
|
2008-12-31 01:06:57 +01:00
|
|
|
|
2009-04-11 20:45:40 +02:00
|
|
|
class HaaliVideoSource : public VideoBase {
|
2008-12-31 00:57:22 +01:00
|
|
|
private:
|
|
|
|
CComPtr<IMMContainer> pMMC;
|
|
|
|
|
|
|
|
void Free(bool CloseCodec);
|
|
|
|
int DecodeNextFrame(AVFrame *AFrame, int64_t *AFirstStartTime, char *ErrorMsg, unsigned MsgSize);
|
|
|
|
public:
|
2009-04-11 20:45:40 +02:00
|
|
|
HaaliVideoSource(const char *SourceFile, int Track, FrameIndex *TrackIndices, const char *PP, int Threads, int SourceMode, char *ErrorMsg, unsigned MsgSize);
|
|
|
|
~HaaliVideoSource();
|
2008-12-31 00:57:22 +01:00
|
|
|
AVFrameLite *GetFrame(int n, char *ErrorMsg, unsigned MsgSize);
|
|
|
|
};
|
|
|
|
|
2009-04-11 20:45:40 +02:00
|
|
|
#endif // HAALISOURCE
|
2008-12-31 01:06:57 +01:00
|
|
|
|
2008-09-01 23:16:13 +02:00
|
|
|
#endif
|