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>
|
|
|
|
}
|
|
|
|
|
2009-09-27 01:54:26 +02:00
|
|
|
// must be included after ffmpeg headers
|
|
|
|
#include "ffmscompat.h"
|
|
|
|
|
2008-09-01 23:16:13 +02:00
|
|
|
#include <vector>
|
2009-10-12 02:11:15 +02:00
|
|
|
#include <sstream>
|
2008-09-01 23:16:13 +02:00
|
|
|
#include "indexing.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "ffms.h"
|
|
|
|
|
2009-04-11 20:45:40 +02:00
|
|
|
#ifdef HAALISOURCE
|
2009-07-14 00:27:40 +02:00
|
|
|
# define WIN32_LEAN_AND_MEAN
|
2008-12-31 00:57:22 +01:00
|
|
|
# define _WIN32_DCOM
|
|
|
|
# include <windows.h>
|
|
|
|
# include <tchar.h>
|
|
|
|
# include <atlbase.h>
|
|
|
|
# include <dshow.h>
|
|
|
|
# include <initguid.h>
|
2009-07-14 00:27:40 +02:00
|
|
|
# include "CoParser.h"
|
2008-12-31 00:57:22 +01:00
|
|
|
# include "guids.h"
|
|
|
|
#endif
|
|
|
|
|
2009-09-26 23:56:15 +02:00
|
|
|
class FFMS_VideoSource {
|
|
|
|
friend class FFSourceResources<FFMS_VideoSource>;
|
2008-09-01 23:16:13 +02:00
|
|
|
private:
|
|
|
|
pp_context_t *PPContext;
|
|
|
|
pp_mode_t *PPMode;
|
2008-09-09 22:49:59 +02:00
|
|
|
SwsContext *SWS;
|
2009-07-14 00:27:40 +02:00
|
|
|
int LastFrameHeight;
|
|
|
|
int LastFrameWidth;
|
|
|
|
PixelFormat LastFramePixelFormat;
|
|
|
|
int TargetHeight;
|
|
|
|
int TargetWidth;
|
|
|
|
int64_t TargetPixelFormats;
|
|
|
|
int TargetResizer;
|
2009-09-26 23:56:15 +02:00
|
|
|
PixelFormat OutputFormat;
|
2009-07-14 00:27:40 +02:00
|
|
|
AVPicture PPFrame;
|
|
|
|
AVPicture SWSFrame;
|
2008-09-01 23:16:13 +02:00
|
|
|
protected:
|
2009-09-26 23:56:15 +02:00
|
|
|
FFMS_VideoProperties VP;
|
|
|
|
FFMS_Frame LocalFrame;
|
2008-09-01 23:16:13 +02:00
|
|
|
AVFrame *DecodeFrame;
|
|
|
|
int LastFrameNum;
|
2009-09-26 23:56:15 +02:00
|
|
|
FFMS_Track Frames;
|
2008-09-01 23:16:13 +02:00
|
|
|
int VideoTrack;
|
|
|
|
int CurrentFrame;
|
|
|
|
AVCodecContext *CodecContext;
|
|
|
|
|
2009-09-26 23:56:15 +02:00
|
|
|
FFMS_VideoSource(const char *SourceFile, FFMS_Index *Index, int Track);
|
|
|
|
void ReAdjustPP(PixelFormat VPixelFormat, int Width, int Height);
|
|
|
|
void ReAdjustOutputFormat(int64_t TargetFormats, int Width, int Height, int Resizer);
|
|
|
|
FFMS_Frame *OutputFrame(AVFrame *Frame);
|
|
|
|
virtual void Free(bool CloseCodec) = 0;
|
2008-09-01 23:16:13 +02:00
|
|
|
public:
|
2009-09-26 23:56:15 +02:00
|
|
|
virtual ~FFMS_VideoSource();
|
|
|
|
const FFMS_VideoProperties& GetVideoProperties() { return VP; }
|
|
|
|
FFMS_Track *GetTrack() { return &Frames; }
|
|
|
|
virtual FFMS_Frame *GetFrame(int n) = 0;
|
|
|
|
void GetFrameCheck(int n);
|
|
|
|
FFMS_Frame *GetFrameByTime(double Time);
|
|
|
|
void SetPP(const char *PP);
|
|
|
|
void ResetPP();
|
|
|
|
void SetOutputFormat(int64_t TargetFormats, int Width, int Height, int Resizer);
|
2008-09-09 22:49:59 +02:00
|
|
|
void ResetOutputFormat();
|
2008-09-01 23:16:13 +02:00
|
|
|
};
|
|
|
|
|
2009-09-26 23:56:15 +02:00
|
|
|
class FFLAVFVideo : public FFMS_VideoSource {
|
2008-09-01 23:16:13 +02:00
|
|
|
private:
|
|
|
|
AVFormatContext *FormatContext;
|
|
|
|
int SeekMode;
|
2009-09-26 23:56:15 +02:00
|
|
|
FFSourceResources<FFMS_VideoSource> Res;
|
2008-09-06 22:05:29 +02:00
|
|
|
|
2009-11-21 22:11:41 +01:00
|
|
|
void DecodeNextFrame(int64_t *PTS);
|
2009-09-26 23:56:15 +02:00
|
|
|
protected:
|
2008-09-06 22:05:29 +02:00
|
|
|
void Free(bool CloseCodec);
|
2008-09-01 23:16:13 +02:00
|
|
|
public:
|
2009-09-26 23:56:15 +02:00
|
|
|
FFLAVFVideo(const char *SourceFile, int Track, FFMS_Index *Index, int Threads, int SeekMode);
|
|
|
|
FFMS_Frame *GetFrame(int n);
|
2008-09-01 23:16:13 +02:00
|
|
|
};
|
|
|
|
|
2009-09-26 23:56:15 +02:00
|
|
|
class FFMatroskaVideo : public FFMS_VideoSource {
|
2008-09-01 23:16:13 +02:00
|
|
|
private:
|
|
|
|
MatroskaFile *MF;
|
|
|
|
MatroskaReaderContext MC;
|
2008-09-04 00:26:27 +02:00
|
|
|
CompressedStream *CS;
|
|
|
|
char ErrorMessage[256];
|
2009-09-26 23:56:15 +02:00
|
|
|
FFSourceResources<FFMS_VideoSource> Res;
|
|
|
|
size_t PacketNumber;
|
2008-09-01 23:16:13 +02:00
|
|
|
|
2009-09-26 23:56:15 +02:00
|
|
|
void DecodeNextFrame();
|
|
|
|
protected:
|
2008-09-06 22:05:29 +02:00
|
|
|
void Free(bool CloseCodec);
|
2008-09-01 23:16:13 +02:00
|
|
|
public:
|
2009-09-26 23:56:15 +02:00
|
|
|
FFMatroskaVideo(const char *SourceFile, int Track, FFMS_Index *Index, int Threads);
|
|
|
|
FFMS_Frame *GetFrame(int n);
|
2008-09-01 23:16:13 +02:00
|
|
|
};
|
|
|
|
|
2009-04-11 20:45:40 +02:00
|
|
|
#ifdef HAALISOURCE
|
2008-12-31 01:06:57 +01:00
|
|
|
|
2009-09-26 23:56:15 +02:00
|
|
|
class FFHaaliVideo : public FFMS_VideoSource {
|
2008-12-31 00:57:22 +01:00
|
|
|
private:
|
|
|
|
CComPtr<IMMContainer> pMMC;
|
2009-07-14 00:27:40 +02:00
|
|
|
std::vector<uint8_t> CodecPrivate;
|
|
|
|
AVBitStreamFilterContext *BitStreamFilter;
|
2009-09-26 23:56:15 +02:00
|
|
|
FFSourceResources<FFMS_VideoSource> Res;
|
2009-05-22 23:28:02 +02:00
|
|
|
|
2009-09-26 23:56:15 +02:00
|
|
|
void DecodeNextFrame(int64_t *AFirstStartTime);
|
|
|
|
protected:
|
2008-12-31 00:57:22 +01:00
|
|
|
void Free(bool CloseCodec);
|
|
|
|
public:
|
2009-09-26 23:56:15 +02:00
|
|
|
FFHaaliVideo(const char *SourceFile, int Track, FFMS_Index *Index, int Threads, enum FFMS_Sources SourceMode);
|
|
|
|
FFMS_Frame *GetFrame(int n);
|
2008-12-31 00:57:22 +01:00
|
|
|
};
|
|
|
|
|
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
|