2004-03-04 23:05:54 +08:00
|
|
|
/*
|
|
|
|
* ZoneMinder MPEG Interface, $Date$, $Revision$
|
2008-07-25 17:33:23 +08:00
|
|
|
* Copyright (C) 2001-2008 Philip Coombes
|
2004-03-04 23:05:54 +08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ZM_MPEG_H
|
|
|
|
#define ZM_MPEG_H
|
|
|
|
|
2008-07-16 16:35:59 +08:00
|
|
|
#include "zm_ffmpeg.h"
|
2005-12-09 08:25:12 +08:00
|
|
|
|
2008-07-25 00:57:39 +08:00
|
|
|
#if HAVE_LIBAVCODEC
|
|
|
|
|
2004-03-04 23:05:54 +08:00
|
|
|
class VideoStream
|
|
|
|
{
|
2005-12-07 21:42:25 +08:00
|
|
|
protected:
|
|
|
|
struct MimeData
|
|
|
|
{
|
|
|
|
const char *format;
|
|
|
|
const char *mime_type;
|
|
|
|
};
|
|
|
|
|
2004-03-04 23:05:54 +08:00
|
|
|
protected:
|
|
|
|
static bool initialised;
|
2005-12-07 21:42:25 +08:00
|
|
|
static struct MimeData mime_data[];
|
2004-03-04 23:05:54 +08:00
|
|
|
|
|
|
|
protected:
|
2014-04-26 04:12:58 +08:00
|
|
|
char *codec_and_format;
|
2004-03-04 23:05:54 +08:00
|
|
|
const char *filename;
|
2004-05-05 17:18:14 +08:00
|
|
|
const char *format;
|
2014-04-26 04:12:58 +08:00
|
|
|
const char *codec_name;
|
2004-03-04 23:05:54 +08:00
|
|
|
enum PixelFormat pf;
|
|
|
|
AVOutputFormat *of;
|
|
|
|
AVFormatContext *ofc;
|
|
|
|
AVStream *ost;
|
2014-04-26 04:12:58 +08:00
|
|
|
AVCodec *codec;
|
2004-03-04 23:05:54 +08:00
|
|
|
AVFrame *opicture;
|
|
|
|
AVFrame *tmp_opicture;
|
|
|
|
uint8_t *video_outbuf;
|
|
|
|
int video_outbuf_size;
|
2014-04-26 04:12:58 +08:00
|
|
|
double last_pts;
|
|
|
|
|
|
|
|
pthread_t streaming_thread;
|
|
|
|
bool do_streaming;
|
|
|
|
uint8_t *buffer_copy;
|
|
|
|
bool add_timestamp;
|
|
|
|
unsigned int timestamp;
|
|
|
|
pthread_mutex_t *buffer_copy_lock;
|
|
|
|
int buffer_copy_size;
|
|
|
|
int buffer_copy_used;
|
2014-04-27 00:25:48 +08:00
|
|
|
AVPacket** packet_buffers;
|
|
|
|
int packet_index;
|
|
|
|
int SendPacket(AVPacket *packet);
|
2014-04-26 04:12:58 +08:00
|
|
|
static void* StreamingThreadCallback(void *ctx);
|
2004-03-04 23:05:54 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void Initialise();
|
|
|
|
|
2014-04-26 04:12:58 +08:00
|
|
|
void SetupFormat( );
|
2011-06-22 23:38:35 +08:00
|
|
|
void SetupCodec( int colours, int subpixelorder, int width, int height, int bitrate, double frame_rate );
|
2004-03-04 23:05:54 +08:00
|
|
|
void SetParameters();
|
2014-04-26 04:12:58 +08:00
|
|
|
void ActuallyOpenStream();
|
|
|
|
double ActuallyEncodeFrame( const uint8_t *buffer, int buffer_size, bool add_timestamp=false, unsigned int timestamp=0 );
|
2004-03-04 23:05:54 +08:00
|
|
|
|
|
|
|
public:
|
2011-06-22 23:38:35 +08:00
|
|
|
VideoStream( const char *filename, const char *format, int bitrate, double frame_rate, int colours, int subpixelorder, int width, int height );
|
2004-03-04 23:05:54 +08:00
|
|
|
~VideoStream();
|
2005-12-07 21:42:25 +08:00
|
|
|
const char *MimeType() const;
|
|
|
|
void OpenStream();
|
2011-05-01 02:39:34 +08:00
|
|
|
double EncodeFrame( const uint8_t *buffer, int buffer_size, bool add_timestamp=false, unsigned int timestamp=0 );
|
2004-03-04 23:05:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // HAVE_LIBAVCODEC
|
2008-07-25 00:57:39 +08:00
|
|
|
|
|
|
|
#endif // ZM_MPEG_H
|