2009-01-20 23:01:32 +08:00
|
|
|
//
|
|
|
|
// ZoneMinder Ffmpeg Class Interface, $Date: 2008-07-25 10:33:23 +0100 (Fri, 25 Jul 2008) $, $Revision: 2611 $
|
|
|
|
// Copyright (C) 2001-2008 Philip Coombes
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2016-12-26 23:23:16 +08:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2009-01-20 23:01:32 +08:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ZM_FFMPEG_CAMERA_H
|
|
|
|
#define ZM_FFMPEG_CAMERA_H
|
|
|
|
|
|
|
|
#include "zm_camera.h"
|
|
|
|
|
|
|
|
#include "zm_buffer.h"
|
|
|
|
#include "zm_ffmpeg.h"
|
2013-09-06 10:53:24 +08:00
|
|
|
#include "zm_videostore.h"
|
2016-09-01 04:58:59 +08:00
|
|
|
#include "zm_packetqueue.h"
|
2009-01-20 23:01:32 +08:00
|
|
|
|
2019-06-26 02:11:59 +08:00
|
|
|
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
2017-08-16 23:31:47 +08:00
|
|
|
typedef struct DecodeContext {
|
|
|
|
AVBufferRef *hw_device_ref;
|
|
|
|
} DecodeContext;
|
2017-08-17 01:41:44 +08:00
|
|
|
#endif
|
2009-01-20 23:01:32 +08:00
|
|
|
//
|
2014-01-28 08:52:46 +08:00
|
|
|
// Class representing 'ffmpeg' cameras, i.e. those which are
|
|
|
|
// accessed using ffmpeg multimedia framework
|
2009-01-20 23:01:32 +08:00
|
|
|
//
|
2017-04-19 22:34:17 +08:00
|
|
|
class FfmpegCamera : public Camera {
|
2016-09-01 04:58:59 +08:00
|
|
|
protected:
|
|
|
|
std::string mPath;
|
2016-09-22 22:43:20 +08:00
|
|
|
std::string mMethod;
|
|
|
|
std::string mOptions;
|
2019-06-26 03:33:54 +08:00
|
|
|
std::string hwaccel_name;
|
|
|
|
std::string hwaccel_device;
|
2009-01-20 23:01:32 +08:00
|
|
|
|
2016-09-01 04:58:59 +08:00
|
|
|
int frameCount;
|
2011-05-22 17:25:33 +08:00
|
|
|
|
2009-01-20 23:01:32 +08:00
|
|
|
#if HAVE_LIBAVFORMAT
|
2016-09-01 04:58:59 +08:00
|
|
|
AVFormatContext *mFormatContext;
|
|
|
|
int mVideoStreamId;
|
|
|
|
int mAudioStreamId;
|
2016-09-08 21:39:04 +08:00
|
|
|
AVCodecContext *mVideoCodecContext;
|
|
|
|
AVCodecContext *mAudioCodecContext;
|
|
|
|
AVCodec *mVideoCodec;
|
|
|
|
AVCodec *mAudioCodec;
|
2016-09-01 04:58:59 +08:00
|
|
|
AVFrame *mRawFrame;
|
|
|
|
AVFrame *mFrame;
|
2016-09-22 22:43:20 +08:00
|
|
|
_AVPIXELFORMAT imagePixFormat;
|
2019-06-25 05:22:59 +08:00
|
|
|
AVFrame *input_frame; // Use to point to mRawFrame or hwFrame;
|
2016-09-22 22:43:20 +08:00
|
|
|
|
2017-08-16 23:31:47 +08:00
|
|
|
bool hwaccel;
|
|
|
|
AVFrame *hwFrame;
|
2019-06-26 02:11:59 +08:00
|
|
|
#if HAVE_LIBAVUTIL_HWCONTEXT_H
|
2018-09-24 04:47:06 +08:00
|
|
|
DecodeContext decode;
|
2019-06-25 05:22:59 +08:00
|
|
|
AVBufferRef *hw_device_ctx = NULL;
|
2019-06-26 10:06:00 +08:00
|
|
|
#endif
|
2017-08-16 23:31:47 +08:00
|
|
|
|
2016-09-22 22:43:20 +08:00
|
|
|
// Used to store the incoming packet, it will get copied when queued.
|
|
|
|
// We only ever need one at a time, so instead of constantly allocating
|
|
|
|
// and freeing this structure, we will just make it a member of the object.
|
|
|
|
AVPacket packet;
|
2016-09-01 04:58:59 +08:00
|
|
|
|
|
|
|
int OpenFfmpeg();
|
2018-04-17 22:02:52 +08:00
|
|
|
int Close();
|
2016-09-01 04:58:59 +08:00
|
|
|
bool mCanCapture;
|
2009-01-20 23:01:32 +08:00
|
|
|
#endif // HAVE_LIBAVFORMAT
|
|
|
|
|
2016-09-01 04:58:59 +08:00
|
|
|
VideoStore *videoStore;
|
2018-10-15 22:51:56 +08:00
|
|
|
zm_packetqueue *packetqueue;
|
2017-08-10 00:50:46 +08:00
|
|
|
bool have_video_keyframe;
|
2009-01-20 23:01:32 +08:00
|
|
|
|
2011-05-07 04:07:40 +08:00
|
|
|
#if HAVE_LIBSWSCALE
|
2016-09-01 04:58:59 +08:00
|
|
|
struct SwsContext *mConvertContext;
|
2011-05-07 04:07:40 +08:00
|
|
|
#endif
|
2009-01-20 23:01:32 +08:00
|
|
|
|
2018-11-30 02:09:29 +08:00
|
|
|
int error_count;
|
2016-04-30 20:27:10 +08:00
|
|
|
|
2016-09-01 04:58:59 +08:00
|
|
|
public:
|
2019-06-26 03:33:54 +08:00
|
|
|
FfmpegCamera(
|
|
|
|
int p_id,
|
|
|
|
const std::string &path,
|
|
|
|
const std::string &p_method,
|
|
|
|
const std::string &p_options,
|
|
|
|
int p_width,
|
|
|
|
int p_height,
|
|
|
|
int p_colours,
|
|
|
|
int p_brightness,
|
|
|
|
int p_contrast,
|
|
|
|
int p_hue,
|
|
|
|
int p_colour,
|
|
|
|
bool p_capture,
|
|
|
|
bool p_record_audio,
|
|
|
|
const std::string &p_hwaccel_name,
|
|
|
|
const std::string &p_hwaccel_device
|
|
|
|
);
|
2016-09-01 04:58:59 +08:00
|
|
|
~FfmpegCamera();
|
2009-01-20 23:01:32 +08:00
|
|
|
|
2019-06-26 03:33:54 +08:00
|
|
|
const std::string &Path() const { return mPath; }
|
|
|
|
const std::string &Options() const { return mOptions; }
|
|
|
|
const std::string &Method() const { return mMethod; }
|
2009-01-20 23:01:32 +08:00
|
|
|
|
2016-09-01 04:58:59 +08:00
|
|
|
void Initialise();
|
|
|
|
void Terminate();
|
2009-01-20 23:01:32 +08:00
|
|
|
|
2016-09-01 04:58:59 +08:00
|
|
|
int PrimeCapture();
|
|
|
|
int PreCapture();
|
|
|
|
int Capture( Image &image );
|
2017-04-13 01:38:39 +08:00
|
|
|
int CaptureAndRecord( Image &image, timeval recording, char* event_directory );
|
2016-09-01 04:58:59 +08:00
|
|
|
int PostCapture();
|
2019-01-09 02:12:22 +08:00
|
|
|
private:
|
|
|
|
static int FfmpegInterruptCallback(void*ctx);
|
2019-06-26 02:11:59 +08:00
|
|
|
int transfer_to_image(Image &i, AVFrame *output_frame, AVFrame *input_frame);
|
2009-01-20 23:01:32 +08:00
|
|
|
};
|
|
|
|
#endif // ZM_FFMPEG_CAMERA_H
|