FFmpeg: Remove code paths required only by 2.8 and older

With Xenial support dropped we require FFmpeg 3.2 and newer.
pull/3280/head
Peter Keresztes Schmidt 2021-06-05 17:01:46 +02:00
parent 73351f4387
commit 2d71743372
20 changed files with 109 additions and 1041 deletions

View File

@ -90,20 +90,12 @@ AVStream *Camera::getVideoStream() {
mVideoStream = avformat_new_stream(mFormatContext, nullptr);
if ( mVideoStream ) {
mVideoStream->time_base = (AVRational){1, 1000000}; // microseconds as base frame rate
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
mVideoStream->codecpar->width = width;
mVideoStream->codecpar->height = height;
mVideoStream->codecpar->format = GetFFMPEGPixelFormat(colours, subpixelorder);
mVideoStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
mVideoStream->codecpar->codec_id = AV_CODEC_ID_NONE;
Debug(1, "Allocating avstream %p %p %d", mVideoStream, mVideoStream->codecpar, mVideoStream->codecpar->codec_id);
#else
mVideoStream->codec->width = width;
mVideoStream->codec->height = height;
mVideoStream->codec->pix_fmt = GetFFMPEGPixelFormat(colours, subpixelorder);
mVideoStream->codec->codec_type = AVMEDIA_TYPE_VIDEO;
mVideoStream->codec->codec_id = AV_CODEC_ID_NONE;
#endif
Debug(1, "Allocating avstream %p %p %d", mVideoStream, mVideoStream->codecpar, mVideoStream->codecpar->codec_id);
} else {
Error("Can't create video stream");
}

View File

@ -99,20 +99,8 @@ public:
unsigned int Pixels() const { return pixels; }
unsigned long long ImageSize() const { return imagesize; }
unsigned int Bytes() const { return bytes; };
int getFrequency() {
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
return mAudioStream ? mAudioStream->codecpar->sample_rate : -1;
#else
return mAudioStream ? mAudioStream->codec->sample_rate : -1;
#endif
}
int getChannels() {
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
return mAudioStream ? mAudioStream->codecpar->channels : -1;
#else
return mAudioStream ? mAudioStream->codec->channels : -1;
#endif
}
int getFrequency() { return mAudioStream ? mAudioStream->codecpar->sample_rate : -1; }
int getChannels() { return mAudioStream ? mAudioStream->codecpar->channels : -1; }
virtual int Brightness( int/*p_brightness*/=-1 ) { return -1; }
virtual int Hue( int/*p_hue*/=-1 ) { return -1; }

View File

@ -139,55 +139,6 @@ enum _AVPIXELFORMAT GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subp
return pf;
}
/* The following is copied directly from newer ffmpeg. */
#if LIBAVUTIL_VERSION_CHECK(52, 7, 0, 17, 100)
#else
static int parse_key_value_pair(AVDictionary **pm, const char **buf,
const char *key_val_sep, const char *pairs_sep,
int flags)
{
char *key = av_get_token(buf, key_val_sep);
char *val = nullptr;
int ret;
if (key && *key && strspn(*buf, key_val_sep)) {
(*buf)++;
val = av_get_token(buf, pairs_sep);
}
if (key && *key && val && *val)
ret = av_dict_set(pm, key, val, flags);
else
ret = AVERROR(EINVAL);
av_freep(&key);
av_freep(&val);
return ret;
}
int av_dict_parse_string(AVDictionary **pm, const char *str,
const char *key_val_sep, const char *pairs_sep,
int flags) {
if (!str)
return 0;
/* ignore STRDUP flags */
flags &= ~(AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
while (*str) {
int ret;
if ( (ret = parse_key_value_pair(pm, &str, key_val_sep, pairs_sep, flags)) < 0)
return ret;
if (*str)
str++;
}
return 0;
}
#endif
#if LIBAVUTIL_VERSION_CHECK(56, 0, 0, 17, 100)
int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts, AVRational fs_tb, int duration, int64_t *last, AVRational out_tb){
@ -227,7 +178,6 @@ static void zm_log_fps(double d, const char *postfix) {
}
}
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
void zm_dump_codecpar(const AVCodecParameters *par) {
Debug(1, "Dumping codecpar codec_type %d %s codec_id %d %s codec_tag %" PRIu32
" width %d height %d bit_rate%" PRIu64 " bpcs %d bprs %d format%d %s"
@ -260,7 +210,6 @@ void zm_dump_codecpar(const AVCodecParameters *par) {
static_cast<int>(par->video_delay)
);
}
#endif
void zm_dump_codec(const AVCodecContext *codec) {
Debug(1, "Dumping codec_context codec_type %d %s codec_id %d %s width %d height %d timebase %d/%d format %s profile %d level %d "
@ -273,11 +222,7 @@ void zm_dump_codec(const AVCodecContext *codec) {
codec->height,
codec->time_base.num,
codec->time_base.den,
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
(codec->pix_fmt == AV_PIX_FMT_NONE ? "none" : av_get_pix_fmt_name(codec->pix_fmt)),
#else
"unsupported on avconv",
#endif
codec->profile,
codec->level,
codec->gop_size,
@ -302,11 +247,7 @@ void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output)
int flags = (is_output ? ic->oformat->flags : ic->iformat->flags);
AVStream *st = ic->streams[i];
AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", nullptr, 0);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
AVCodecParameters *codec = st->codecpar;
#else
AVCodecContext *codec = st->codec;
#endif
Debug(1, " Stream #%d:%d", index, i);
@ -321,16 +262,10 @@ void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output)
st->time_base.num, st->time_base.den
);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
Debug(1, "codec: %s %s",
avcodec_get_name(st->codecpar->codec_id),
av_get_media_type_string(st->codecpar->codec_type)
);
#else
char buf[256];
avcodec_string(buf, sizeof(buf), st->codec, is_output);
Debug(1, "codec: %s", buf);
#endif
if (st->sample_aspect_ratio.num && // default
av_cmp_q(st->sample_aspect_ratio, codec->sample_aspect_ratio)
@ -419,127 +354,37 @@ enum AVPixelFormat fix_deprecated_pix_fmt(enum AVPixelFormat fmt) {
}
}
#if LIBAVCODEC_VERSION_CHECK(56, 8, 0, 60, 100)
#else
unsigned int zm_av_packet_ref(AVPacket *dst, AVPacket *src) {
av_new_packet(dst,src->size);
memcpy(dst->data, src->data, src->size);
dst->flags = src->flags;
dst->pts = src->pts;
dst->dts = src->dts;
dst->duration = src->duration;
dst->stream_index = src->stream_index;
return 0;
}
const char *avcodec_get_name(enum AVCodecID id) {
const AVCodecDescriptor *cd;
if ( id == AV_CODEC_ID_NONE)
return "none";
cd = avcodec_descriptor_get(id);
if (cd)
return cd->name;
AVCodec *codec;
codec = avcodec_find_decoder(id);
if (codec)
return codec->name;
codec = avcodec_find_encoder(id);
if (codec)
return codec->name;
return "unknown codec";
}
void av_packet_rescale_ts(
AVPacket *pkt,
AVRational src_tb,
AVRational dst_tb
) {
if ( pkt->pts != AV_NOPTS_VALUE)
pkt->pts = av_rescale_q(pkt->pts, src_tb, dst_tb);
if ( pkt->dts != AV_NOPTS_VALUE)
pkt->dts = av_rescale_q(pkt->dts, src_tb, dst_tb);
if ( pkt->duration != AV_NOPTS_VALUE)
pkt->duration = av_rescale_q(pkt->duration, src_tb, dst_tb);
}
#endif
bool is_video_stream(const AVStream * stream) {
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
#else
#if (LIBAVCODEC_VERSION_CHECK(52, 64, 0, 64, 0) || LIBAVUTIL_VERSION_CHECK(50, 14, 0, 14, 0))
if (stream->codec->codec_type == AVMEDIA_TYPE_VIDEO)
#else
if (stream->codec->codec_type == CODEC_TYPE_VIDEO)
#endif
#endif
{
if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
return true;
}
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
Debug(2, "Not a video type %d != %d", stream->codecpar->codec_type, AVMEDIA_TYPE_VIDEO);
#endif
Debug(2, "Not a video type %d != %d", stream->codecpar->codec_type, AVMEDIA_TYPE_VIDEO);
return false;
}
bool is_video_context(const AVCodecContext *codec_context) {
return
#if (LIBAVCODEC_VERSION_CHECK(52, 64, 0, 64, 0) || LIBAVUTIL_VERSION_CHECK(50, 14, 0, 14, 0))
(codec_context->codec_type == AVMEDIA_TYPE_VIDEO);
#else
(codec_context->codec_type == CODEC_TYPE_VIDEO);
#endif
return codec_context->codec_type == AVMEDIA_TYPE_VIDEO;
}
bool is_audio_stream(const AVStream * stream) {
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
#else
#if (LIBAVCODEC_VERSION_CHECK(52, 64, 0, 64, 0) || LIBAVUTIL_VERSION_CHECK(50, 14, 0, 14, 0))
if (stream->codec->codec_type == AVMEDIA_TYPE_AUDIO)
#else
if (stream->codec->codec_type == CODEC_TYPE_AUDIO)
#endif
#endif
{
return true;
}
return false;
bool is_audio_stream(const AVStream *stream) {
return stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO;
}
bool is_audio_context(const AVCodecContext *codec_context) {
return
#if (LIBAVCODEC_VERSION_CHECK(52, 64, 0, 64, 0) || LIBAVUTIL_VERSION_CHECK(50, 14, 0, 14, 0))
(codec_context->codec_type == AVMEDIA_TYPE_AUDIO);
#else
(codec_context->codec_type == CODEC_TYPE_AUDIO);
#endif
return codec_context->codec_type == AVMEDIA_TYPE_AUDIO;
}
int zm_receive_packet(AVCodecContext *context, AVPacket &packet) {
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
int ret = avcodec_receive_packet(context, &packet);
if ((ret < 0) and (AVERROR_EOF != ret)) {
Error("Error encoding (%d) (%s)", ret, av_err2str(ret));
}
return ret; // 1 or 0
#else
int got_packet = 0;
int ret = avcodec_encode_audio2(context, &packet, nullptr, &got_packet);
if (ret < 0) {
Error("Error encoding (%d) (%s)", ret, av_err2str(ret));
return ret;
}
return got_packet; // 1
#endif
} // end int zm_receive_packet(AVCodecContext *context, AVPacket &packet)
int zm_send_packet_receive_frame(
AVCodecContext *context,
AVFrame *frame,
AVPacket &packet) {
int zm_send_packet_receive_frame(AVCodecContext *context, AVFrame *frame, AVPacket &packet) {
int ret;
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
if ((ret = avcodec_send_packet(context, &packet)) < 0) {
Error("Unable to send packet %s, continuing",
av_make_error_string(ret).c_str());
@ -558,74 +403,41 @@ int zm_send_packet_receive_frame(
}
// In this api the packet is always consumed, so return packet.bytes
return packet.size;
# else
int frameComplete = 0;
if (is_video_context(context)) {
ret = zm_avcodec_decode_video(context, frame, &frameComplete, &packet);
Debug(2, "ret from decode_video %d, framecomplete %d", ret, frameComplete);
} else {
ret = avcodec_decode_audio4(context, frame, &frameComplete, &packet);
Debug(2, "ret from decode_audio %d, framecomplete %d", ret, frameComplete);
}
if (ret < 0) {
Error("Unable to decode frame: %s", av_make_error_string(ret).c_str());
return ret;
}
return frameComplete ? ret : 0;
#endif
} // end int zm_send_packet_receive_frame(AVCodecContext *context, AVFrame *frame, AVPacket &packet)
/* Returns < 0 on error, 0 if codec not ready, 1 on success
*/
int zm_send_frame_receive_packet(AVCodecContext *ctx, AVFrame *frame, AVPacket &packet) {
int ret;
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
if (( (ret = avcodec_send_frame(ctx, frame)) < 0 ) and frame) {
Error("Could not send frame (error '%s')",
av_make_error_string(ret).c_str());
return ret;
}
if (((ret = avcodec_send_frame(ctx, frame)) < 0) and frame) {
Error("Could not send frame (error '%s')",
av_make_error_string(ret).c_str());
return ret;
}
if ((ret = avcodec_receive_packet(ctx, &packet)) < 0) {
if (AVERROR(EAGAIN) == ret) {
// The codec may need more samples than it has, perfectly valid
Debug(2, "Codec not ready to give us a packet");
return 0;
} else if (frame) {
// May get EOF if frame is NULL because it signals flushing
Error("Could not recieve packet (error %d = '%s')", ret,
av_make_error_string(ret).c_str());
}
zm_av_packet_unref(&packet);
return ret;
}
#else
int data_present;
if ((ret = avcodec_encode_audio2(
ctx, &packet, frame, &data_present)) < 0) {
Error("Could not encode frame (error '%s')",
av_make_error_string(ret).c_str());
zm_av_packet_unref(&packet);
return ret;
}
if (!data_present) {
Debug(2, "Not ready to out a frame yet.");
zm_av_packet_unref(&packet);
if ((ret = avcodec_receive_packet(ctx, &packet)) < 0) {
if (AVERROR(EAGAIN) == ret) {
// The codec may need more samples than it has, perfectly valid
Debug(2, "Codec not ready to give us a packet");
return 0;
} else if (frame) {
// May get EOF if frame is NULL because it signals flushing
Error("Could not recieve packet (error %d = '%s')", ret,
av_make_error_string(ret).c_str());
}
#endif
zm_av_packet_unref(&packet);
return ret;
}
return 1;
} // end int zm_send_frame_receive_packet
void zm_free_codec(AVCodecContext **ctx) {
if (*ctx) {
avcodec_close(*ctx);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
// We allocate and copy in newer ffmpeg, so need to free it
avcodec_free_context(ctx);
#endif
*ctx = NULL;
} // end if
*ctx = nullptr;
}
}
void zm_packet_copy_rescale_ts(const AVPacket *ipkt, AVPacket *opkt, const AVRational src_tb, const AVRational dst_tb) {

View File

@ -34,6 +34,7 @@ extern "C" {
#include <libavutil/avstring.h>
#include <libavutil/audio_fifo.h>
#include <libavutil/imgutils.h>
#include <libavutil/opt.h>
#if HAVE_LIBAVUTIL_HWCONTEXT_H
#include <libavutil/hwcontext.h>
#endif
@ -47,64 +48,7 @@ extern "C" {
( (LIBAVUTIL_VERSION_MICRO < 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(a, b, c) ) || \
(LIBAVUTIL_VERSION_MICRO >= 100 && LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(a, d, e) ) )
#if LIBAVUTIL_VERSION_CHECK(50, 29, 0, 29, 0)
#include <libavutil/opt.h>
#else
#include <libavcodec/opt.h>
#endif
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
#include <libavutil/imgutils.h>
#endif
#if LIBAVUTIL_VERSION_CHECK(51, 42, 0, 74, 100)
#define _AVPIXELFORMAT AVPixelFormat
#else
#define _AVPIXELFORMAT PixelFormat
#define AV_PIX_FMT_NONE PIX_FMT_NONE
#define AV_PIX_FMT_RGB444 PIX_FMT_RGB444
#define AV_PIX_FMT_RGB555 PIX_FMT_RGB555
#define AV_PIX_FMT_RGB565 PIX_FMT_RGB565
#define AV_PIX_FMT_BGR24 PIX_FMT_BGR24
#define AV_PIX_FMT_RGB24 PIX_FMT_RGB24
#define AV_PIX_FMT_BGRA PIX_FMT_BGRA
#define AV_PIX_FMT_ARGB PIX_FMT_ARGB
#define AV_PIX_FMT_ABGR PIX_FMT_ABGR
#define AV_PIX_FMT_RGBA PIX_FMT_RGBA
#define AV_PIX_FMT_GRAY8 PIX_FMT_GRAY8
#define AV_PIX_FMT_YUYV422 PIX_FMT_YUYV422
#define AV_PIX_FMT_YUV422P PIX_FMT_YUV422P
#define AV_PIX_FMT_YUV411P PIX_FMT_YUV411P
#define AV_PIX_FMT_YUV444P PIX_FMT_YUV444P
#define AV_PIX_FMT_YUV410P PIX_FMT_YUV410P
#define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P
#define AV_PIX_FMT_YUVJ444P PIX_FMT_YUVJ444P
#define AV_PIX_FMT_UYVY422 PIX_FMT_UYVY422
#define AV_PIX_FMT_YUVJ420P PIX_FMT_YUVJ420P
#define AV_PIX_FMT_YUVJ422P PIX_FMT_YUVJ422P
#define AV_PIX_FMT_UYVY422 PIX_FMT_UYVY422
#define AV_PIX_FMT_UYYVYY411 PIX_FMT_UYYVYY411
#define AV_PIX_FMT_BGR565 PIX_FMT_BGR565
#define AV_PIX_FMT_BGR555 PIX_FMT_BGR555
#define AV_PIX_FMT_BGR8 PIX_FMT_BGR8
#define AV_PIX_FMT_BGR4 PIX_FMT_BGR4
#define AV_PIX_FMT_BGR4_BYTE PIX_FMT_BGR4_BYTE
#define AV_PIX_FMT_RGB8 PIX_FMT_RGB8
#define AV_PIX_FMT_RGB4 PIX_FMT_RGB4
#define AV_PIX_FMT_RGB4_BYTE PIX_FMT_RGB4_BYTE
#define AV_PIX_FMT_NV12 PIX_FMT_NV12
#define AV_PIX_FMT_NV21 PIX_FMT_NV21
#define AV_PIX_FMT_RGB32_1 PIX_FMT_RGB32_1
#define AV_PIX_FMT_BGR32_1 PIX_FMT_BGR32_1
#define AV_PIX_FMT_GRAY16BE PIX_FMT_GRAY16BE
#define AV_PIX_FMT_GRAY16LE PIX_FMT_GRAY16LE
#define AV_PIX_FMT_YUV440P PIX_FMT_YUV440P
#define AV_PIX_FMT_YUVJ440P PIX_FMT_YUVJ440P
#define AV_PIX_FMT_YUVA420P PIX_FMT_YUVA420P
//#define AV_PIX_FMT_VDPAU_H264 PIX_FMT_VDPAU_H264
//#define AV_PIX_FMT_VDPAU_MPEG1 PIX_FMT_VDPAU_MPEG1
//#define AV_PIX_FMT_VDPAU_MPEG2 PIX_FMT_VDPAU_MPEG2
#endif
#define _AVPIXELFORMAT AVPixelFormat
// AVCODEC
#include <libavcodec/avcodec.h>
@ -119,11 +63,7 @@ extern "C" {
( (LIBAVCODEC_VERSION_MICRO < 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(a, b, c) ) || \
(LIBAVCODEC_VERSION_MICRO >= 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(a, d, e) ) )
#if LIBAVCODEC_VERSION_CHECK(54, 25, 0, 51, 100)
#define _AVCODECID AVCodecID
#else
#define _AVCODECID CodecID
#endif
#define _AVCODECID AVCodecID
// AVFORMAT
#include <libavformat/avformat.h>
@ -150,40 +90,12 @@ extern "C" {
}
#if !LIBAVFORMAT_VERSION_CHECK(52, 107, 0, 107, 0)
#if defined(AVIO_WRONLY)
#define AVIO_FLAG_WRITE AVIO_WRONLY
#else
#define AVIO_FLAG_WRITE URL_WRONLY
#endif
#endif
/* A single function to initialize ffmpeg, to avoid multiple initializations */
void FFMPEGInit();
void FFMPEGDeInit();
enum _AVPIXELFORMAT GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subpixelorder);
#if !LIBAVCODEC_VERSION_CHECK(54, 25, 0, 51, 100)
#define AV_CODEC_ID_NONE CODEC_ID_NONE
#define AV_CODEC_ID_PCM_MULAW CODEC_ID_PCM_MULAW
#define AV_CODEC_ID_PCM_ALAW CODEC_ID_PCM_ALAW
#define AV_CODEC_ID_PCM_S16BE CODEC_ID_PCM_S16BE
#define AV_CODEC_ID_QCELP CODEC_ID_QCELP
#define AV_CODEC_ID_MP2 CODEC_ID_MP2
#define AV_CODEC_ID_MP3 CODEC_ID_MP3
#define AV_CODEC_ID_MJPEG CODEC_ID_MJPEG
#define AV_CODEC_ID_H261 CODEC_ID_H261
#define AV_CODEC_ID_MPEG1VIDEO CODEC_ID_MPEG1VIDEO
#define AV_CODEC_ID_MPEG2VIDEO CODEC_ID_MPEG2VIDEO
#define AV_CODEC_ID_MPEG2TS CODEC_ID_MPEG2TS
#define AV_CODEC_ID_H263 CODEC_ID_H263
#define AV_CODEC_ID_H264 CODEC_ID_H264
#define AV_CODEC_ID_MPEG4 CODEC_ID_MPEG4
#define AV_CODEC_ID_AAC CODEC_ID_AAC
#define AV_CODEC_ID_AMR_NB CODEC_ID_AMR_NB
#endif
/*
* Some versions of libav does not contain this definition.
*/
@ -197,25 +109,13 @@ enum _AVPIXELFORMAT GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subp
*/
inline static const std::string av_make_error_string(int errnum) {
static char errbuf[AV_ERROR_MAX_STRING_SIZE];
#if LIBAVUTIL_VERSION_CHECK(50, 13, 0, 13, 0)
av_strerror(errnum, errbuf, AV_ERROR_MAX_STRING_SIZE);
#else
snprintf(errbuf, AV_ERROR_MAX_STRING_SIZE, "libav error %d", errnum);
#endif
return (std::string)errbuf;
}
#undef av_err2str
#define av_err2str(errnum) av_make_error_string(errnum).c_str()
/* The following is copied directly from newer ffmpeg */
#if LIBAVUTIL_VERSION_CHECK(52, 7, 0, 17, 100)
#else
int av_dict_parse_string(AVDictionary **pm, const char *str,
const char *key_val_sep, const char *pairs_sep,
int flags);
#endif
#ifndef av_rescale_delta
/**
* Rescale a timestamp while preserving known durations.
@ -243,9 +143,8 @@ static av_always_inline av_const int64_t av_clip64_c(int64_t a, int64_t amin, in
void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output);
void zm_dump_codec(const AVCodecContext *codec);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
void zm_dump_codecpar(const AVCodecParameters *par);
#endif
#define zm_dump_frame(frame, text) Debug(1, "%s: format %d %s sample_rate %" PRIu32 " nb_samples %d" \
" layout %" PRIu64 " pts %" PRId64, \
text, \
@ -257,7 +156,6 @@ void zm_dump_codecpar(const AVCodecParameters *par);
frame->pts \
);
#if LIBAVUTIL_VERSION_CHECK(54, 4, 0, 74, 100)
#define zm_dump_video_frame(frame, text) Debug(1, "%s: format %d %s %dx%d linesize:%dx%d pts: %" PRId64 " keyframe: %d", \
text, \
frame->format, \
@ -269,35 +167,10 @@ void zm_dump_codecpar(const AVCodecParameters *par);
frame->key_frame \
);
#else
#define zm_dump_video_frame(frame,text) Debug(1, "%s: format %d %s %dx%d linesize:%dx%d pts: %" PRId64, \
text, \
frame->format, \
"unsupported", \
frame->width, \
frame->height, \
frame->linesize[0], frame->linesize[1], \
frame->pts \
);
#endif
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
# define AV_PACKET_DURATION_FMT PRId64
#else
# define AV_PACKET_DURATION_FMT "d"
#endif
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
#define CODEC_TYPE(stream) stream->codecpar->codec_type
#else
#define CODEC_TYPE(stream) stream->codec->codec_type
#endif
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
#define CODEC(stream) stream->codecpar
#else
#define CODEC(stream) stream->codec
#endif
#ifndef DBG_OFF
# define ZM_DUMP_PACKET(pkt, text) \
@ -339,39 +212,10 @@ void zm_dump_codecpar(const AVCodecParameters *par);
# define ZM_DUMP_STREAM_PACKET(stream, pkt, text)
#endif
#if LIBAVCODEC_VERSION_CHECK(56, 8, 0, 60, 100)
#define zm_av_packet_unref(packet) av_packet_unref(packet)
#define zm_av_packet_ref(dst, src) av_packet_ref(dst, src)
#else
unsigned int zm_av_packet_ref( AVPacket *dst, AVPacket *src );
#define zm_av_packet_unref( packet ) av_free_packet( packet )
const char *avcodec_get_name(AVCodecID id);
#define zm_av_packet_unref(packet) av_packet_unref(packet)
#define zm_av_packet_ref(dst, src) av_packet_ref(dst, src)
void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb);
#endif
#if LIBAVCODEC_VERSION_CHECK(57, 24, 1, 45, 101)
#define zm_avcodec_decode_video(context, rawFrame, frameComplete, packet) \
avcodec_send_packet(context, packet); \
avcodec_receive_frame(context, rawFrame);
#else
#if LIBAVCODEC_VERSION_CHECK(52, 23, 0, 23, 0)
#define zm_avcodec_decode_video(context, rawFrame, frameComplete, packet) \
avcodec_decode_video2(context, rawFrame, frameComplete, packet)
#else
#define zm_avcodec_decode_video(context, rawFrame, frameComplete, packet) \
avcodec_decode_video(context, rawFrame, frameComplete, packet->data, packet->size)
#endif
#endif
#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101)
#define zm_av_frame_alloc() av_frame_alloc()
#else
#define zm_av_frame_alloc() avcodec_alloc_frame()
#endif
#if ! LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101)
#define av_frame_free( input_avframe ) av_freep( input_avframe )
#endif
#define zm_av_frame_alloc() av_frame_alloc()
int check_sample_fmt(AVCodec *codec, enum AVSampleFormat sample_fmt);
enum AVPixelFormat fix_deprecated_pix_fmt(enum AVPixelFormat );

View File

@ -231,11 +231,8 @@ int FfmpegCamera::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
AVStream *stream = formatContextPtr->streams[packet.stream_index];
ZM_DUMP_STREAM_PACKET(stream, packet, "ffmpeg_camera in");
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
zm_packet->codec_type = stream->codecpar->codec_type;
#else
zm_packet->codec_type = stream->codec->codec_type;
#endif
bytes += packet.size;
zm_packet->set_packet(&packet);
zm_packet->stream = stream;
@ -268,10 +265,6 @@ int FfmpegCamera::OpenFfmpeg() {
error_count = 0;
// Open the input, not necessarily a file
#if !LIBAVFORMAT_VERSION_CHECK(53, 2, 0, 4, 0)
if (av_open_input_file(&mFormatContext, mPath.c_str(), nullptr, 0, nullptr) != 0)
#else
// Handle options
AVDictionary *opts = nullptr;
ret = av_dict_parse_string(&opts, Options().c_str(), "=", ",", 0);
@ -312,18 +305,14 @@ int FfmpegCamera::OpenFfmpeg() {
ret = avformat_open_input(&mFormatContext, mPath.c_str(), nullptr, &opts);
if ( ret != 0 )
#endif
{
Error("Unable to open input %s due to: %s", mPath.c_str(),
av_make_error_string(ret).c_str());
#if !LIBAVFORMAT_VERSION_CHECK(53, 17, 0, 25, 0)
av_close_input_file(mFormatContext);
#else
if ( mFormatContext ) {
avformat_close_input(&mFormatContext);
mFormatContext = nullptr;
}
#endif
av_dict_free(&opts);
return -1;
@ -335,11 +324,8 @@ int FfmpegCamera::OpenFfmpeg() {
av_dict_free(&opts);
Debug(1, "Finding stream info");
#if !LIBAVFORMAT_VERSION_CHECK(53, 6, 0, 6, 0)
ret = av_find_stream_info(mFormatContext);
#else
ret = avformat_find_stream_info(mFormatContext, nullptr);
#endif
if ( ret < 0 ) {
Error("Unable to find stream info from %s due to: %s",
mPath.c_str(), av_make_error_string(ret).c_str());
@ -380,13 +366,7 @@ int FfmpegCamera::OpenFfmpeg() {
mVideoStreamId, mAudioStreamId);
AVCodec *mVideoCodec = nullptr;
if (mVideoStream->
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
codecpar
#else
codec
#endif
->codec_id == AV_CODEC_ID_H264) {
if (mVideoStream->codecpar->codec_id == AV_CODEC_ID_H264) {
if ((mVideoCodec = avcodec_find_decoder_by_name("h264_mmal")) == nullptr) {
Debug(1, "Failed to find decoder (h264_mmal)");
} else {
@ -395,13 +375,7 @@ int FfmpegCamera::OpenFfmpeg() {
}
if (!mVideoCodec) {
mVideoCodec = avcodec_find_decoder(mVideoStream->
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
codecpar
#else
codec
#endif
->codec_id);
mVideoCodec = avcodec_find_decoder(mVideoStream->codecpar->codec_id);
if (!mVideoCodec) {
// Try and get the codec from the codec context
Error("Can't find codec for video stream from %s", mPath.c_str());
@ -409,13 +383,9 @@ int FfmpegCamera::OpenFfmpeg() {
}
}
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
mVideoCodecContext = avcodec_alloc_context3(mVideoCodec);
avcodec_parameters_to_context(mVideoCodecContext,
mFormatContext->streams[mVideoStreamId]->codecpar);
#else
mVideoCodecContext = mFormatContext->streams[mVideoStreamId]->codec;
#endif
avcodec_parameters_to_context(mVideoCodecContext, mFormatContext->streams[mVideoStreamId]->codecpar);
#ifdef CODEC_FLAG2_FAST
mVideoCodecContext->flags2 |= CODEC_FLAG2_FAST | CODEC_FLAG_LOW_DELAY;
#endif
@ -499,11 +469,8 @@ int FfmpegCamera::OpenFfmpeg() {
#endif
} // end if hwaccel_name
#if !LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 8, 0)
ret = avcodec_open(mVideoCodecContext, mVideoCodec);
#else
ret = avcodec_open2(mVideoCodecContext, mVideoCodec, &opts);
#endif
e = nullptr;
while ((e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != nullptr) {
Warning("Option %s not recognized by ffmpeg", e->key);
@ -529,33 +496,15 @@ int FfmpegCamera::OpenFfmpeg() {
if ( mAudioStreamId >= 0 ) {
AVCodec *mAudioCodec = nullptr;
if ( (mAudioCodec = avcodec_find_decoder(
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
mAudioStream->codecpar->codec_id
#else
mAudioStream->codec->codec_id
#endif
)) == nullptr ) {
if (!(mAudioCodec = avcodec_find_decoder(mAudioStream->codecpar->codec_id))) {
Debug(1, "Can't find codec for audio stream from %s", mPath.c_str());
} else {
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
mAudioCodecContext = avcodec_alloc_context3(mAudioCodec);
avcodec_parameters_to_context(
mAudioCodecContext,
mAudioStream->codecpar
);
#else
mAudioCodecContext = mAudioStream->codec;
#endif
avcodec_parameters_to_context(mAudioCodecContext, mAudioStream->codecpar);
zm_dump_stream_format((mSecondFormatContext?mSecondFormatContext:mFormatContext), mAudioStreamId, 0, 0);
// Open the codec
#if !LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 8, 0)
if ( avcodec_open(mAudioCodecContext, mAudioCodec) < 0 )
#else
if ( avcodec_open2(mAudioCodecContext, mAudioCodec, nullptr) < 0 )
#endif
{
if (avcodec_open2(mAudioCodecContext, mAudioCodec, nullptr) < 0) {
Error("Unable to open codec for audio stream from %s", mPath.c_str());
return -1;
} // end if opened
@ -581,16 +530,12 @@ int FfmpegCamera::Close() {
if ( mVideoCodecContext ) {
avcodec_close(mVideoCodecContext);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
avcodec_free_context(&mVideoCodecContext);
#endif
mVideoCodecContext = nullptr; // Freed by av_close_input_file
}
if ( mAudioCodecContext ) {
avcodec_close(mAudioCodecContext);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
avcodec_free_context(&mAudioCodecContext);
#endif
mAudioCodecContext = nullptr; // Freed by av_close_input_file
}
@ -601,11 +546,7 @@ int FfmpegCamera::Close() {
#endif
if ( mFormatContext ) {
#if !LIBAVFORMAT_VERSION_CHECK(53, 17, 0, 25, 0)
av_close_input_file(mFormatContext);
#else
avformat_close_input(&mFormatContext);
#endif
mFormatContext = nullptr;
}

View File

@ -89,12 +89,8 @@ int FFmpeg_Input::Open(const char *filepath) {
}
streams[i].frame_count = 0;
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
streams[i].context = avcodec_alloc_context3(nullptr);
avcodec_parameters_to_context(streams[i].context, input_format_context->streams[i]->codecpar);
#else
streams[i].context = input_format_context->streams[i]->codec;
#endif
if ( !(streams[i].codec = avcodec_find_decoder(streams[i].context->codec_id)) ) {
Error("Could not find input codec");
@ -108,9 +104,7 @@ int FFmpeg_Input::Open(const char *filepath) {
if ( error < 0 ) {
Error("Could not open input codec (error '%s')",
av_make_error_string(error).c_str());
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
avcodec_free_context(&streams[i].context);
#endif
avformat_close_input(&input_format_context);
input_format_context = nullptr;
return error;
@ -129,21 +123,15 @@ int FFmpeg_Input::Close( ) {
if ( streams ) {
for ( unsigned int i = 0; i < input_format_context->nb_streams; i += 1 ) {
avcodec_close(streams[i].context);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
avcodec_free_context(&streams[i].context);
streams[i].context = nullptr;
#endif
}
delete[] streams;
streams = nullptr;
}
if ( input_format_context ) {
#if !LIBAVFORMAT_VERSION_CHECK(53, 17, 0, 25, 0)
av_close_input_file(input_format_context);
#else
avformat_close_input(&input_format_context);
#endif
input_format_context = nullptr;
}
return 1;

View File

@ -52,12 +52,8 @@ int FFmpeg_Output::Open( const char *filepath ) {
}
streams[i].frame_count = 0;
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
streams[i].context = avcodec_alloc_context3( NULL );
avcodec_parameters_to_context( streams[i].context, input_format_context->streams[i]->codecpar );
#else
streams[i].context = input_format_context->streams[i]->codec;
#endif
streams[i].context = avcodec_alloc_context3(nullptr);
avcodec_parameters_to_context(streams[i].context, input_format_context->streams[i]->codecpar);
if ( !(streams[i].codec = avcodec_find_decoder(streams[i].context->codec_id)) ) {
Error( "Could not find input codec\n");
@ -70,9 +66,7 @@ int FFmpeg_Output::Open( const char *filepath ) {
if ((error = avcodec_open2( streams[i].context, streams[i].codec, NULL)) < 0) {
Error( "Could not open input codec (error '%s')\n",
av_make_error_string(error).c_str() );
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
avcodec_free_context( &streams[i].context );
#endif
avformat_close_input(&input_format_context);
return error;
}
@ -117,7 +111,6 @@ AVFrame *FFmpeg_Output::get_frame( int stream_id ) {
AVCodecContext *context = streams[packet.stream_index].context;
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
ret = avcodec_send_packet( context, &packet );
if ( ret < 0 ) {
av_strerror( ret, errbuf, AV_ERROR_MAX_STRING_SIZE );
@ -160,15 +153,6 @@ AVFrame *FFmpeg_Output::get_frame( int stream_id ) {
#endif
frameComplete = 1;
# else
ret = zm_avcodec_decode_video( streams[packet.stream_index].context, frame, &frameComplete, &packet );
if ( ret < 0 ) {
av_strerror( ret, errbuf, AV_ERROR_MAX_STRING_SIZE );
Error( "Unable to decode frame at frame %d: %s, continuing", streams[packet.stream_index].frame_count, errbuf );
zm_av_packet_unref( &packet );
continue;
}
#endif
} // end if it's the right stream
zm_av_packet_unref( &packet );

View File

@ -226,14 +226,9 @@ Image::Image(const AVFrame *frame) {
imagePixFormat = AV_PIX_FMT_RGBA;
//(AVPixelFormat)frame->format;
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
size = av_image_get_buffer_size(AV_PIX_FMT_RGBA, width, height, 32);
// av_image_get_linesize isn't aligned, so we have to do that.
linesize = FFALIGN(av_image_get_linesize(AV_PIX_FMT_RGBA, width, 0), 32);
#else
linesize = FFALIGN(av_image_get_linesize(AV_PIX_FMT_RGBA, width, 0), 1);
size = avpicture_get_size(AV_PIX_FMT_RGB0, width, height);
#endif
padding = 0;
buffer = nullptr;
@ -259,7 +254,7 @@ int Image::PopulateFrame(AVFrame *frame) {
Warning("Failed to create av_buffer");
}
frame->buf[0] = ref;
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
// From what I've read, we should align the linesizes to 32bit so that ffmpeg can use SIMD instructions too.
int size = av_image_fill_arrays(
frame->data, frame->linesize,
@ -271,10 +266,7 @@ int Image::PopulateFrame(AVFrame *frame) {
av_make_error_string(size).c_str());
return size;
}
#else
avpicture_fill((AVPicture *)frame, buffer,
imagePixFormat, width, height);
#endif
frame->width = width;
frame->height = height;
frame->format = imagePixFormat;

View File

@ -375,7 +375,6 @@ LocalCamera::LocalCamera(
Panic("Unexpected colours: %u",colours);
}
if ( capture ) {
#if LIBSWSCALE_VERSION_CHECK(0, 8, 0, 8, 0)
if ( !sws_isSupportedInput(capturePixFormat) ) {
Error("swscale does not support the used capture format: %d", capturePixFormat);
conversion_type = 2; /* Try ZM format conversions */
@ -384,7 +383,6 @@ LocalCamera::LocalCamera(
Error("swscale does not support the target format: 0x%d", imagePixFormat);
conversion_type = 2; /* Try ZM format conversions */
}
#endif
}
/* Our YUYV->Grayscale conversion is a lot faster than swscale's */
if ( colours == ZM_COLOUR_GRAY8 && palette == V4L2_PIX_FMT_YUYV ) {
@ -445,19 +443,13 @@ LocalCamera::LocalCamera(
/* Initialize swscale stuff */
if ( capture and (conversion_type == 1) ) {
#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101)
tmpPicture = av_frame_alloc();
#else
tmpPicture = avcodec_alloc_frame();
#endif
if ( !tmpPicture )
Fatal("Could not allocate temporary picture");
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
unsigned int pSize = av_image_get_buffer_size(imagePixFormat, width, height, 1);
#else
unsigned int pSize = avpicture_get_size(imagePixFormat, width, height);
#endif
if ( pSize != imagesize ) {
Fatal("Image size mismatch. Required: %d Available: %llu", pSize, imagesize);
}
@ -699,14 +691,11 @@ void LocalCamera::Initialise() {
Fatal("Can't map video buffer %u (%u bytes) to memory: %s(%d)",
i, vid_buf.length, strerror(errno), errno);
#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101)
capturePictures[i] = av_frame_alloc();
#else
capturePictures[i] = avcodec_alloc_frame();
#endif
if ( !capturePictures[i] )
Fatal("Could not allocate picture");
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
av_image_fill_arrays(
capturePictures[i]->data,
capturePictures[i]->linesize,
@ -715,15 +704,6 @@ void LocalCamera::Initialise() {
v4l2_data.fmt.fmt.pix.width,
v4l2_data.fmt.fmt.pix.height,
1);
#else
avpicture_fill(
(AVPicture *)capturePictures[i],
(uint8_t*)v4l2_data.buffers[i].start,
capturePixFormat,
v4l2_data.fmt.fmt.pix.width,
v4l2_data.fmt.fmt.pix.height
);
#endif
} // end foreach request buf
Debug(3, "Configuring video source");
@ -769,12 +749,8 @@ void LocalCamera::Terminate() {
Debug(3, "Unmapping video buffers");
for ( unsigned int i = 0; i < v4l2_data.reqbufs.count; i++ ) {
/* Free capture pictures */
#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101)
av_frame_free(&capturePictures[i]);
#else
av_freep(&capturePictures[i]);
#endif
if ( munmap(v4l2_data.buffers[i].start, v4l2_data.buffers[i].length) < 0 )
Error("Failed to munmap buffer %d: %s", i, strerror(errno));
}
@ -1462,14 +1438,10 @@ int LocalCamera::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
if (conversion_type == 1) {
Debug(9, "Calling sws_scale to perform the conversion");
/* Use swscale to convert the image directly into the shared memory */
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
av_image_fill_arrays(tmpPicture->data,
tmpPicture->linesize, directbuffer,
imagePixFormat, width, height, 1);
#else
avpicture_fill( (AVPicture *)tmpPicture, directbuffer,
imagePixFormat, width, height );
#endif
sws_scale(
imgConversionContext,
capturePictures[capture_frame]->data,

View File

@ -2519,13 +2519,11 @@ int Monitor::Capture() {
if ( packet->keyframe ) {
// avcodec strips out important nals that describe the stream and
// stick them in extradata. Need to send them along with keyframes
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
AVStream *stream = camera->getVideoStream();
video_fifo->write(
static_cast<unsigned char *>(stream->codecpar->extradata),
stream->codecpar->extradata_size,
packet->pts);
#endif
}
video_fifo->writePacket(*packet);
}
@ -3011,28 +3009,20 @@ int Monitor::PrimeCapture() {
if (rtsp_server) {
if (video_stream_id >= 0) {
AVStream *videoStream = camera->getVideoStream();
snprintf(shared_data->video_fifo_path, sizeof(shared_data->video_fifo_path)-1, "%s/video_fifo_%u.%s",
staticConfig.PATH_SOCKS.c_str(),
id,
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
avcodec_get_name(videoStream->codecpar->codec_id)
#else
avcodec_get_name(videoStream->codec->codec_id)
#endif
);
snprintf(shared_data->video_fifo_path, sizeof(shared_data->video_fifo_path) - 1, "%s/video_fifo_%u.%s",
staticConfig.PATH_SOCKS.c_str(),
id,
avcodec_get_name(videoStream->codecpar->codec_id)
);
video_fifo = new Fifo(shared_data->video_fifo_path, true);
}
if (record_audio and (audio_stream_id >= 0)) {
AVStream *audioStream = camera->getAudioStream();
if (audioStream && CODEC(audioStream)) {
snprintf(shared_data->audio_fifo_path, sizeof(shared_data->audio_fifo_path)-1, "%s/audio_fifo_%u.%s",
staticConfig.PATH_SOCKS.c_str(), id,
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
avcodec_get_name(audioStream->codecpar->codec_id)
#else
avcodec_get_name(audioStream->codec->codec_id)
#endif
);
snprintf(shared_data->audio_fifo_path, sizeof(shared_data->audio_fifo_path) - 1, "%s/audio_fifo_%u.%s",
staticConfig.PATH_SOCKS.c_str(), id,
avcodec_get_name(audioStream->codecpar->codec_id)
);
audio_fifo = new Fifo(shared_data->audio_fifo_path, true);
} else {
Warning("No audioStream %p or codec?", audioStream);

View File

@ -46,59 +46,8 @@ void VideoStream::Initialise( ) {
void VideoStream::SetupFormat( ) {
/* allocate the output media context */
ofc = nullptr;
#if (LIBAVFORMAT_VERSION_CHECK(53, 2, 0, 2, 0) && (LIBAVFORMAT_VERSION_MICRO >= 100))
avformat_alloc_output_context2(&ofc, nullptr, format, filename);
#else
AVFormatContext *s = avformat_alloc_context();
if ( !s ) {
Fatal("avformat_alloc_context failed %d \"%s\"", (size_t)ofc, av_err2str((size_t)ofc));
return;
}
AVOutputFormat *oformat;
if ( format ) {
#if LIBAVFORMAT_VERSION_CHECK(52, 45, 0, 45, 0)
oformat = av_guess_format(format, nullptr, nullptr);
#else
oformat = guess_format(format, nullptr, nullptr);
#endif
if ( !oformat ) {
Fatal("Requested output format '%s' is not a suitable output format", format);
}
} else {
#if LIBAVFORMAT_VERSION_CHECK(52, 45, 0, 45, 0)
oformat = av_guess_format(nullptr, filename, nullptr);
#else
oformat = guess_format(nullptr, filename, nullptr);
#endif
if ( !oformat ) {
Fatal("Unable to find a suitable output format for '%s'", format);
}
}
s->oformat = oformat;
if ( s->oformat->priv_data_size > 0 ) {
s->priv_data = av_mallocz(s->oformat->priv_data_size);
if ( !(s->priv_data) ) {
Fatal("Could not allocate private data for output format.");
}
#if LIBAVFORMAT_VERSION_CHECK(52, 92, 0, 92, 0)
if ( s->oformat->priv_class ) {
*(const AVClass**)s->priv_data = s->oformat->priv_class;
av_opt_set_defaults(s->priv_data);
}
#endif
} else {
Debug(1, "No allocating priv_data");
s->priv_data = nullptr;
}
if ( filename ) {
snprintf(s->filename, sizeof(s->filename), "%s", filename);
}
ofc = s;
#endif
if ( !ofc ) {
Fatal("avformat_alloc_..._context failed");
}
@ -161,11 +110,7 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei
codec_id = a->id;
Debug(1, "Using codec \"%s\"", codec_name);
} else {
#if (LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 11, 0) && (LIBAVFORMAT_VERSION_MICRO >= 100))
Debug(1, "Could not find codec \"%s\". Using default \"%s\"", codec_name, avcodec_get_name(codec_id));
#else
Debug(1, "Could not find codec \"%s\". Using default \"%d\"", codec_name, codec_id);
#endif
}
}
@ -175,24 +120,12 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei
if ( codec_id != AV_CODEC_ID_NONE ) {
codec = avcodec_find_encoder(codec_id);
if ( !codec ) {
#if (LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 11, 0) && (LIBAVFORMAT_VERSION_MICRO >= 100))
Fatal("Could not find encoder for '%s'", avcodec_get_name(codec_id));
#else
Fatal("Could not find encoder for '%d'", codec_id);
#endif
}
#if (LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 11, 0) && (LIBAVFORMAT_VERSION_MICRO >= 100))
Debug(1, "Found encoder for '%s'", avcodec_get_name(codec_id));
#else
Debug(1, "Found encoder for '%d'", codec_id);
#endif
#if LIBAVFORMAT_VERSION_CHECK(53, 10, 0, 17, 0)
ost = avformat_new_stream( ofc, codec );
#else
ost = av_new_stream( ofc, 0 );
#endif
if ( !ost ) {
Fatal( "Could not alloc stream" );
@ -201,13 +134,8 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei
Debug( 1, "Allocated stream (%d) !=? (%d)", ost->id , ofc->nb_streams - 1 );
ost->id = ofc->nb_streams - 1;
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
codec_context = avcodec_alloc_context3(nullptr);
//avcodec_parameters_to_context(codec_context, ost->codecpar);
#else
codec_context = ost->codec;
#endif
codec_context->codec_id = codec->id;
codec_context->codec_type = codec->type;
@ -216,11 +144,7 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei
if ( bitrate <= 100 ) {
// Quality based bitrate control (VBR). Scale is 1..31 where 1 is best.
// This gets rid of artifacts in the beginning of the movie; and well, even quality.
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
codec_context->flags |= AV_CODEC_FLAG_QSCALE;
#else
codec_context->flags |= CODEC_FLAG_QSCALE;
#endif
codec_context->global_quality = FF_QP2LAMBDA * (31 - (31 * (bitrate / 100.0)));
} else {
codec_context->bit_rate = bitrate;
@ -246,15 +170,10 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei
// some formats want stream headers to be separate
if ( of->flags & AVFMT_GLOBALHEADER )
#if LIBAVCODEC_VERSION_CHECK(56, 35, 0, 64, 0)
codec_context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
#else
codec_context->flags |= CODEC_FLAG_GLOBAL_HEADER;
#endif
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
avcodec_parameters_from_context(ost->codecpar, codec_context);
zm_dump_codecpar(ost->codecpar);
#endif
} else {
Fatal( "of->video_codec == AV_CODEC_ID_NONE" );
}
@ -291,12 +210,8 @@ bool VideoStream::OpenStream( ) {
Debug(1,"Opening codec");
/* open the codec */
#if !LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 8, 0)
if ( (ret = avcodec_open(codec_context, codec)) < 0 )
#else
if ( (ret = avcodec_open2(codec_context, codec, nullptr)) < 0 )
#endif
{
if ((ret = avcodec_open2(codec_context, codec, nullptr)) < 0) {
Error("Could not open codec. Error code %d \"%s\"", ret, av_err2str(ret));
return false;
}
@ -313,11 +228,7 @@ bool VideoStream::OpenStream( ) {
opicture->height = codec_context->height;
opicture->format = codec_context->pix_fmt;
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
int size = av_image_get_buffer_size(codec_context->pix_fmt, codec_context->width, codec_context->height, 1);
#else
int size = avpicture_get_size(codec_context->pix_fmt, codec_context->width, codec_context->height);
#endif
uint8_t *opicture_buf = (uint8_t *)av_malloc(size);
if ( !opicture_buf ) {
@ -325,59 +236,39 @@ bool VideoStream::OpenStream( ) {
Error( "Could not allocate opicture_buf" );
return false;
}
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
av_image_fill_arrays(opicture->data, opicture->linesize,
opicture_buf, codec_context->pix_fmt, codec_context->width, codec_context->height, 1);
#else
avpicture_fill( (AVPicture *)opicture, opicture_buf, codec_context->pix_fmt,
codec_context->width, codec_context->height );
#endif
/* if the output format is not identical to the input format, then a temporary
picture is needed too. It is then converted to the required
output format */
tmp_opicture = nullptr;
if ( codec_context->pix_fmt != pf ) {
#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101)
tmp_opicture = av_frame_alloc( );
#else
tmp_opicture = avcodec_alloc_frame( );
#endif
tmp_opicture = av_frame_alloc();
if ( !tmp_opicture ) {
Error( "Could not allocate tmp_opicture" );
return false;
}
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
int size = av_image_get_buffer_size( pf, codec_context->width, codec_context->height,1 );
#else
int size = avpicture_get_size( pf, codec_context->width, codec_context->height );
#endif
uint8_t *tmp_opicture_buf = (uint8_t *)av_malloc( size );
if ( !tmp_opicture_buf ) {
av_frame_free( &tmp_opicture );
Error( "Could not allocate tmp_opicture_buf" );
return false;
}
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
av_image_fill_arrays(tmp_opicture->data,
tmp_opicture->linesize, tmp_opicture_buf, pf,
codec_context->width, codec_context->height, 1);
#else
avpicture_fill( (AVPicture *)tmp_opicture,
tmp_opicture_buf, pf, codec_context->width, codec_context->height );
#endif
}
} // end if ost
/* open the output file, if needed */
if ( !(of->flags & AVFMT_NOFILE) ) {
#if LIBAVFORMAT_VERSION_CHECK(53, 15, 0, 21, 0)
ret = avio_open2( &ofc->pb, filename, AVIO_FLAG_WRITE, nullptr, nullptr );
#elif LIBAVFORMAT_VERSION_CHECK(52, 102, 0, 102, 0)
ret = avio_open( &ofc->pb, filename, AVIO_FLAG_WRITE );
#else
ret = url_fopen( &ofc->pb, filename, AVIO_FLAG_WRITE );
#endif
if ( ret < 0 ) {
Error("Could not open '%s'", filename);
return false;
@ -390,12 +281,8 @@ bool VideoStream::OpenStream( ) {
}
video_outbuf = nullptr;
#if LIBAVFORMAT_VERSION_CHECK(57, 0, 0, 0, 0)
if (codec_context->codec_type == AVMEDIA_TYPE_VIDEO &&
codec_context->codec_id == AV_CODEC_ID_RAWVIDEO) {
#else
if ( !(of->flags & AVFMT_RAWPICTURE) ) {
#endif
/* allocate output buffer */
/* XXX: API change will be done */
// TODO: Make buffer dynamic.
@ -406,17 +293,9 @@ bool VideoStream::OpenStream( ) {
}
}
#if LIBAVFORMAT_VERSION_CHECK(52, 101, 0, 101, 0)
av_dump_format(ofc, 0, filename, 1);
#else
dump_format(ofc, 0, filename, 1);
#endif
#if !LIBAVFORMAT_VERSION_CHECK(53, 2, 0, 4, 0)
ret = av_write_header(ofc);
#else
ret = avformat_write_header(ofc, nullptr);
#endif
if ( ret < 0 ) {
Error("?_write_header failed with error %d \"%s\"", ret, av_err2str(ret));
@ -531,11 +410,7 @@ VideoStream::~VideoStream( ) {
if ( !(of->flags & AVFMT_NOFILE) ) {
/* close the output file */
#if LIBAVFORMAT_VERSION_CHECK(52, 105, 0, 105, 0)
avio_close( ofc->pb );
#else
url_fclose( ofc->pb );
#endif
}
/* free the stream */
@ -609,28 +484,18 @@ double VideoStream::ActuallyEncodeFrame( const uint8_t *buffer, int buffer_size,
AVPacket *pkt = packet_buffers[packet_index];
av_init_packet( pkt );
int got_packet = 0;
#if LIBAVFORMAT_VERSION_CHECK(57, 0, 0, 0, 0)
int got_packet = 0;
if (codec_context->codec_type == AVMEDIA_TYPE_VIDEO &&
codec_context->codec_id == AV_CODEC_ID_RAWVIDEO) {
#else
if ( of->flags & AVFMT_RAWPICTURE ) {
#endif
#if LIBAVCODEC_VERSION_CHECK(52, 30, 2, 30, 2)
pkt->flags |= AV_PKT_FLAG_KEY;
#else
pkt->flags |= PKT_FLAG_KEY;
#endif
pkt->stream_index = ost->index;
pkt->data = (uint8_t *)opicture_ptr;
pkt->size = sizeof (AVPicture);
got_packet = 1;
got_packet = 1;
} else {
opicture_ptr->pts = codec_context->frame_number;
opicture_ptr->quality = codec_context->global_quality;
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
avcodec_send_frame(codec_context, opicture_ptr);
int ret = avcodec_receive_packet(codec_context, pkt);
if ( ret < 0 ) {
@ -641,28 +506,11 @@ double VideoStream::ActuallyEncodeFrame( const uint8_t *buffer, int buffer_size,
} else {
got_packet = 1;
}
#else
#if LIBAVFORMAT_VERSION_CHECK(54, 1, 0, 2, 100)
int ret = avcodec_encode_video2( codec_context, pkt, opicture_ptr, &got_packet );
if ( ret != 0 ) {
Fatal( "avcodec_encode_video2 failed with errorcode %d \"%s\"", ret, av_err2str( ret ) );
}
#else
int out_size = avcodec_encode_video( codec_context, video_outbuf, video_outbuf_size, opicture_ptr );
got_packet = out_size > 0 ? 1 : 0;
pkt->data = got_packet ? video_outbuf : nullptr;
pkt->size = got_packet ? out_size : 0;
#endif
#endif
if ( got_packet ) {
// if ( c->coded_frame->key_frame )
// {
//#if LIBAVCODEC_VERSION_CHECK(52, 30, 2, 30, 2)
// pkt->flags |= AV_PKT_FLAG_KEY;
//#else
// pkt->flags |= PKT_FLAG_KEY;
//#endif
// }
if ( pkt->pts != (int64_t)AV_NOPTS_VALUE ) {
@ -685,11 +533,7 @@ int VideoStream::SendPacket(AVPacket *packet) {
if ( ret != 0 ) {
Fatal( "Error %d while writing video frame: %s", ret, av_err2str( errno ) );
}
#if LIBAVCODEC_VERSION_CHECK(57, 8, 0, 12, 100)
av_packet_unref( packet );
#else
av_free_packet( packet );
#endif
return ret;
}
@ -703,11 +547,8 @@ void *VideoStream::StreamingThreadCallback(void *ctx){
const uint64_t nanosecond_multiplier = 1000000000;
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
uint64_t target_interval_ns = nanosecond_multiplier * ( ((double)videoStream->codec_context->time_base.num) / (videoStream->codec_context->time_base.den) );
#else
uint64_t target_interval_ns = nanosecond_multiplier * ( ((double)videoStream->codec_context->time_base.num) / (videoStream->codec_context->time_base.den) );
#endif
uint64_t frame_count = 0;
timespec start_time;
clock_gettime(CLOCK_MONOTONIC, &start_time);
@ -732,11 +573,8 @@ void *VideoStream::StreamingThreadCallback(void *ctx){
if (packet->size) {
videoStream->SendPacket(packet);
}
#if LIBAVCODEC_VERSION_CHECK(57, 8, 0, 12, 100)
av_packet_unref( packet);
#else
av_free_packet( packet );
#endif
videoStream->packet_index = videoStream->packet_index ? 0 : 1;
// Lock buffer and render next frame.

View File

@ -257,7 +257,6 @@ AVFrame *ZMPacket::get_out_frame(int width, int height, AVPixelFormat format) {
return nullptr;
}
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
int alignment = 32;
if (width%alignment) alignment = 1;
@ -278,20 +277,7 @@ AVFrame *ZMPacket::get_out_frame(int width, int height, AVPixelFormat format) {
av_frame_free(&out_frame);
return nullptr;
}
#else
codec_imgsize = avpicture_get_size(
format,
width,
height);
buffer = (uint8_t *)av_malloc(codec_imgsize);
avpicture_fill(
(AVPicture *)out_frame,
buffer,
format,
width,
height
);
#endif
out_frame->width = width;
out_frame->height = height;
out_frame->format = format;

View File

@ -173,12 +173,8 @@ int RemoteCameraRtsp::PrimeCapture() {
Debug(3, "Unable to locate audio stream");
// Get a pointer to the codec context for the video stream
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
mVideoCodecContext = avcodec_alloc_context3(NULL);
mVideoCodecContext = avcodec_alloc_context3(nullptr);
avcodec_parameters_to_context(mVideoCodecContext, mFormatContext->streams[mVideoStreamId]->codecpar);
#else
mVideoCodecContext = mFormatContext->streams[mVideoStreamId]->codec;
#endif
// Find the decoder for the video stream
AVCodec *codec = avcodec_find_decoder(mVideoCodecContext->codec_id);
@ -186,18 +182,10 @@ int RemoteCameraRtsp::PrimeCapture() {
Panic("Unable to locate codec %d decoder", mVideoCodecContext->codec_id);
// Open codec
#if !LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 8, 0)
if ( avcodec_open(mVideoCodecContext, codec) < 0 )
#else
if ( avcodec_open2(mVideoCodecContext, codec, 0) < 0 )
#endif
if ( avcodec_open2(mVideoCodecContext, codec, nullptr) < 0 )
Panic("Can't open codec");
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
int pSize = av_image_get_buffer_size(imagePixFormat, width, height, 1);
#else
int pSize = avpicture_get_size(imagePixFormat, width, height);
#endif
if ( (unsigned int)pSize != imagesize ) {
Fatal("Image size mismatch. Required: %d Available: %llu", pSize, imagesize);
@ -281,25 +269,12 @@ int RemoteCameraRtsp::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
buffer -= packet->size;
if ( bytes_consumed ) {
zm_dump_video_frame(zm_packet->in_frame, "remote_rtsp_decode");
if ( ! mVideoStream->
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
codecpar
#else
codec
#endif
->width ) {
if (!mVideoStream->codecpar->width) {
zm_dump_codec(mVideoCodecContext);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
zm_dump_codecpar(mVideoStream->codecpar);
mVideoStream->codecpar->width = zm_packet->in_frame->width;
mVideoStream->codecpar->height = zm_packet->in_frame->height;
#else
mVideoStream->codec->width = zm_packet->in_frame->width;
mVideoStream->codec->height = zm_packet->in_frame->height;
#endif
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
zm_dump_codecpar(mVideoStream->codecpar);
#endif
}
zm_packet->codec_type = mVideoCodecContext->codec_type;
zm_packet->stream = mVideoStream;

View File

@ -186,11 +186,7 @@ RtspThread::~RtspThread() {
mThread.join();
if ( mFormatContext ) {
#if LIBAVFORMAT_VERSION_CHECK(52, 96, 0, 96, 0)
avformat_free_context(mFormatContext);
#else
av_free_format_context(mFormatContext);
#endif
mFormatContext = nullptr;
}
if ( mSessDesc ) {
@ -396,14 +392,7 @@ void RtspThread::Run() {
if ( mFormatContext->nb_streams >= 1 ) {
for ( unsigned int i = 0; i < mFormatContext->nb_streams; i++ ) {
SessionDescriptor::MediaDescriptor *mediaDesc = mSessDesc->getStream(i);
#if LIBAVFORMAT_VERSION_CHECK(57, 33, 0, 33, 0)
if ( mFormatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO )
#elif (LIBAVCODEC_VERSION_CHECK(52, 64, 0, 64, 0) || LIBAVUTIL_VERSION_CHECK(50, 14, 0, 14, 0))
if ( mFormatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO )
#else
if ( mFormatContext->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO )
#endif
{
if (mFormatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
// Check if control Url is absolute or relative
controlUrl = mediaDesc->getControlUrl();
if (trackUrl == controlUrl) {
@ -416,11 +405,7 @@ void RtspThread::Run() {
}
}
rtpClock = mediaDesc->getClock();
#if LIBAVFORMAT_VERSION_CHECK(57, 33, 0, 33, 0)
codecId = mFormatContext->streams[i]->codecpar->codec_id;
#else
codecId = mFormatContext->streams[i]->codec->codec_id;
#endif
break;
} // end if is video
} // end foreach stream

View File

@ -34,13 +34,7 @@ ADTS_ZoneMinderDeviceSource::ADTS_ZoneMinderDeviceSource(
:
ZoneMinderDeviceSource(env, std::move(monitor), stream, queueSize),
samplingFrequencyIndex(0),
channels(
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
stream->codecpar->channels
#else
stream->codec->channels
#endif
)
channels(stream->codecpar->channels)
{
std::ostringstream os;
os <<

View File

@ -45,13 +45,7 @@ class ADTS_ZoneMinderDeviceSource : public ZoneMinderDeviceSource {
virtual unsigned char* findMarker(unsigned char *frame, size_t size, size_t &length);
*/
public:
int samplingFrequency() { return
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
m_stream->codecpar->sample_rate;
#else
m_stream->codec->sample_rate;
#endif
};
int samplingFrequency() { return m_stream->codecpar->sample_rate; };
const char *configStr() { return config.c_str(); };
int numChannels() {
return channels;

View File

@ -23,7 +23,6 @@
#include "zm_exception.h"
#include "zm_logger.h"
#if (LIBAVCODEC_VERSION_CHECK(52, 64, 0, 64, 0) || LIBAVUTIL_VERSION_CHECK(50, 14, 0, 14, 0))
SessionDescriptor::StaticPayloadDesc SessionDescriptor::smStaticPayloads[] = {
{ 0, "PCMU", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_PCM_MULAW, 8000, 1 },
{ 3, "GSM", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_NONE, 8000, 1 },
@ -61,45 +60,6 @@ SessionDescriptor::DynamicPayloadDesc SessionDescriptor::smDynamicPayloads[] = {
{ "AMR", AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AMR_NB },
{ "vnd.onvif.metadata", AVMEDIA_TYPE_DATA, AV_CODEC_ID_NONE }
};
#else
SessionDescriptor::StaticPayloadDesc SessionDescriptor::smStaticPayloads[] = {
{ 0, "PCMU", CODEC_TYPE_AUDIO, CODEC_ID_PCM_MULAW, 8001, 1 },
{ 3, "GSM", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1 },
{ 4, "G723", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1 },
{ 5, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1 },
{ 6, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 16000, 1 },
{ 7, "LPC", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1 },
{ 8, "PCMA", CODEC_TYPE_AUDIO, CODEC_ID_PCM_ALAW, 8000, 1 },
{ 9, "G722", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1 },
{ 10, "L16", CODEC_TYPE_AUDIO, CODEC_ID_PCM_S16BE, 44100, 2 },
{ 11, "L16", CODEC_TYPE_AUDIO, CODEC_ID_PCM_S16BE, 44100, 1 },
{ 12, "QCELP", CODEC_TYPE_AUDIO, CODEC_ID_QCELP, 8000, 1 },
{ 13, "CN", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1 },
{ 14, "MPA", CODEC_TYPE_AUDIO, CODEC_ID_MP2, -1, -1 },
{ 14, "MPA", CODEC_TYPE_AUDIO, CODEC_ID_MP3, -1, -1 },
{ 15, "G728", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1 },
{ 16, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 11025, 1 },
{ 17, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 22050, 1 },
{ 18, "G729", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1 },
{ 25, "CelB", CODEC_TYPE_VIDEO, CODEC_ID_NONE, 90000, -1 },
{ 26, "JPEG", CODEC_TYPE_VIDEO, CODEC_ID_MJPEG, 90000, -1 },
{ 28, "nv", CODEC_TYPE_VIDEO, CODEC_ID_NONE, 90000, -1 },
{ 31, "H261", CODEC_TYPE_VIDEO, CODEC_ID_H261, 90000, -1 },
{ 32, "MPV", CODEC_TYPE_VIDEO, CODEC_ID_MPEG1VIDEO, 90000, -1 },
{ 32, "MPV", CODEC_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO, 90000, -1 },
{ 33, "MP2T", CODEC_TYPE_DATA, CODEC_ID_MPEG2TS, 90000, -1 },
{ 34, "H263", CODEC_TYPE_VIDEO, CODEC_ID_H263, 90000, -1 },
{ -1, "", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1 }
};
SessionDescriptor::DynamicPayloadDesc SessionDescriptor::smDynamicPayloads[] = {
{ "MP4V-ES", CODEC_TYPE_VIDEO, CODEC_ID_MPEG4 },
{ "mpeg4-generic", CODEC_TYPE_AUDIO, CODEC_ID_AAC },
{ "H264", CODEC_TYPE_VIDEO, CODEC_ID_H264 },
{ "AMR", CODEC_TYPE_AUDIO, CODEC_ID_AMR_NB },
{ "vnd.onvif.metadata", CODEC_TYPE_DATA, CODEC_ID_NONE }
};
#endif
SessionDescriptor::ConnInfo::ConnInfo( const std::string &connInfo ) :
mTtl( 16 ),
@ -341,53 +301,30 @@ AVFormatContext *SessionDescriptor::generateFormatContext() const {
//formatContext->nb_streams = mMediaList.size();
for ( unsigned int i = 0; i < mMediaList.size(); i++ ) {
const MediaDescriptor *mediaDesc = mMediaList[i];
#if !LIBAVFORMAT_VERSION_CHECK(53, 10, 0, 17, 0)
AVStream *stream = av_new_stream(formatContext, i);
#else
AVStream *stream = avformat_new_stream(formatContext, nullptr);
stream->id = i;
#endif
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
AVCodecContext *codec_context = avcodec_alloc_context3(nullptr);
#else
AVCodecContext *codec_context = stream->codec;
#endif
std::string type = mediaDesc->getType();
Debug(1, "Looking for codec for %s payload type %d / %s",
type.c_str(), mediaDesc->getPayloadType(), mediaDesc->getPayloadDesc().c_str());
#if (LIBAVCODEC_VERSION_CHECK(52, 64, 0, 64, 0) || LIBAVUTIL_VERSION_CHECK(50, 14, 0, 14, 0))
if ( type == "video" )
codec_context->codec_type = AVMEDIA_TYPE_VIDEO;
else if ( type == "audio" )
codec_context->codec_type = AVMEDIA_TYPE_AUDIO;
else if ( type == "application" )
codec_context->codec_type = AVMEDIA_TYPE_DATA;
#else
if ( type == "video" )
codec_context->codec_type = CODEC_TYPE_VIDEO;
else if ( type == "audio" )
codec_context->codec_type = CODEC_TYPE_AUDIO;
else if ( type == "application" )
codec_context->codec_type = CODEC_TYPE_DATA;
#endif
else
Warning("Unknown media_type %s", type.c_str());
#if LIBAVCODEC_VERSION_CHECK(55, 50, 3, 60, 103)
std::string codec_name;
#endif
if ( mediaDesc->getPayloadType() < PAYLOAD_TYPE_DYNAMIC ) {
// Look in static table
for ( unsigned int j = 0; j < (sizeof(smStaticPayloads)/sizeof(*smStaticPayloads)); j++ ) {
if ( smStaticPayloads[j].payloadType == mediaDesc->getPayloadType() ) {
Debug( 1, "Got static payload type %d, %s", smStaticPayloads[j].payloadType, smStaticPayloads[j].payloadName );
#if LIBAVCODEC_VERSION_CHECK(55, 50, 3, 60, 103)
codec_name = std::string(smStaticPayloads[j].payloadName);
#else
strncpy(codec_context->codec_name, smStaticPayloads[j].payloadName, sizeof(codec_context->codec_name));
#endif
codec_context->codec_type = smStaticPayloads[j].codecType;
codec_context->codec_id = smStaticPayloads[j].codecId;
codec_context->sample_rate = smStaticPayloads[j].clockRate;
@ -399,11 +336,7 @@ AVFormatContext *SessionDescriptor::generateFormatContext() const {
for ( unsigned int j = 0; j < (sizeof(smDynamicPayloads)/sizeof(*smDynamicPayloads)); j++ ) {
if ( smDynamicPayloads[j].payloadName == mediaDesc->getPayloadDesc() ) {
Debug(1, "Got dynamic payload type %d, %s", mediaDesc->getPayloadType(), smDynamicPayloads[j].payloadName);
#if LIBAVCODEC_VERSION_CHECK(55, 50, 3, 60, 103)
codec_name = std::string(smStaticPayloads[j].payloadName);
#else
strncpy(codec_context->codec_name, smDynamicPayloads[j].payloadName, sizeof(codec_context->codec_name));
#endif
codec_context->codec_type = smDynamicPayloads[j].codecType;
codec_context->codec_id = smDynamicPayloads[j].codecId;
codec_context->sample_rate = mediaDesc->getClock();
@ -413,12 +346,7 @@ AVFormatContext *SessionDescriptor::generateFormatContext() const {
} /// end if static or dynamic
#if LIBAVCODEC_VERSION_CHECK(55, 50, 3, 60, 103)
if ( codec_name.empty() )
#else
if ( !stream->codec->codec_name[0] )
#endif
{
if (codec_name.empty()) {
Warning( "Can't find payload details for %s payload type %d, name %s",
mediaDesc->getType().c_str(), mediaDesc->getPayloadType(), mediaDesc->getPayloadDesc().c_str() );
}
@ -452,15 +380,9 @@ AVFormatContext *SessionDescriptor::generateFormatContext() const {
packet_size = av_base64_decode(decoded_packet, (const char *)base64packet, (int)sizeof(decoded_packet));
Hexdump(4, (char *)decoded_packet, packet_size);
if ( packet_size ) {
uint8_t *dest =
(uint8_t *)av_malloc(packet_size + sizeof(start_sequence) +
codec_context->extradata_size +
#if LIBAVCODEC_VERSION_CHECK(57, 0, 0, 0, 0)
AV_INPUT_BUFFER_PADDING_SIZE
#else
FF_INPUT_BUFFER_PADDING_SIZE
#endif
);
uint8_t *dest =
(uint8_t *) av_malloc(
packet_size + sizeof(start_sequence) + codec_context->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
if ( dest ) {
if ( codec_context->extradata_size ) {
// av_realloc?
@ -472,11 +394,7 @@ AVFormatContext *SessionDescriptor::generateFormatContext() const {
memcpy(dest+codec_context->extradata_size+sizeof(start_sequence), decoded_packet, packet_size);
memset(dest+codec_context->extradata_size+sizeof(start_sequence)+
packet_size, 0,
#if LIBAVCODEC_VERSION_CHECK(57, 0, 0, 0, 0)
AV_INPUT_BUFFER_PADDING_SIZE
#else
FF_INPUT_BUFFER_PADDING_SIZE
#endif
);
codec_context->extradata= dest;
@ -488,9 +406,7 @@ AVFormatContext *SessionDescriptor::generateFormatContext() const {
}
}
}
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
avcodec_parameters_from_context(stream->codecpar, codec_context);
#endif
} // end foreach mediaList
return formatContext;

View File

@ -32,11 +32,7 @@ protected:
struct StaticPayloadDesc {
int payloadType;
const char payloadName[6];
#if (LIBAVCODEC_VERSION_CHECK(52, 64, 0, 64, 0) || LIBAVUTIL_VERSION_CHECK(50, 14, 0, 14, 0))
AVMediaType codecType;
#else
enum CodecType codecType;
#endif
_AVCODECID codecId;
int clockRate;
int autoChannels;
@ -44,11 +40,7 @@ protected:
struct DynamicPayloadDesc {
const char payloadName[32];
#if (LIBAVCODEC_VERSION_CHECK(52, 64, 0, 64, 0) || LIBAVUTIL_VERSION_CHECK(50, 14, 0, 14, 0))
AVMediaType codecType;
#else
enum CodecType codecType;
#endif
_AVCODECID codecId;
//int clockRate;

View File

@ -27,24 +27,14 @@ SWScale::SWScale() : gotdefaults(false), swscale_ctx(nullptr), input_avframe(nul
}
bool SWScale::init() {
/* Allocate AVFrame for the input */
#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101)
input_avframe = av_frame_alloc();
#else
input_avframe = avcodec_alloc_frame();
#endif
if ( input_avframe == nullptr ) {
if (!input_avframe) {
Error("Failed allocating AVFrame for the input");
return false;
}
/* Allocate AVFrame for the output */
#if LIBAVCODEC_VERSION_CHECK(55, 28, 1, 45, 101)
output_avframe = av_frame_alloc();
#else
output_avframe = avcodec_alloc_frame();
#endif
if ( output_avframe == nullptr ) {
if (!output_avframe) {
Error("Failed allocating AVFrame for the output");
return false;
}
@ -146,7 +136,6 @@ int SWScale::Convert(
in_pf = fix_deprecated_pix_fmt(in_pf);
#if LIBSWSCALE_VERSION_CHECK(0, 8, 0, 8, 0)
/* Warn if the input or output pixelformat is not supported */
if (!sws_isSupportedInput(in_pf)) {
Warning("swscale does not support the input format: %c%c%c%c",
@ -156,7 +145,6 @@ int SWScale::Convert(
Warning("swscale does not support the output format: %c%c%c%c",
(out_pf)&0xff,((out_pf>>8)&0xff),((out_pf>>16)&0xff),((out_pf>>24)&0xff));
}
#endif
int alignment = width % 32 ? 1 : 32;
/* Check the buffer sizes */
@ -197,23 +185,13 @@ int SWScale::Convert(
output_avframe->height = new_height;
*/
/* Fill in the buffers */
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
if (av_image_fill_arrays(input_avframe->data, input_avframe->linesize,
(uint8_t*) in_buffer, in_pf, width, height, alignment) <= 0) {
#else
if (avpicture_fill((AVPicture*) input_avframe, (uint8_t*) in_buffer,
in_pf, width, height) <= 0) {
#endif
Error("Failed filling input frame with input buffer");
return -7;
}
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
if (av_image_fill_arrays(output_avframe->data, output_avframe->linesize,
out_buffer, out_pf, new_width, new_height, alignment) <= 0) {
#else
if (avpicture_fill((AVPicture*) output_avframe, out_buffer, out_pf, new_width,
new_height) <= 0) {
#endif
Error("Failed filling output frame with output buffer");
return -8;
}
@ -284,9 +262,5 @@ int SWScale::ConvertDefaults(const uint8_t* in_buffer, const size_t in_buffer_si
}
size_t SWScale::GetBufferSize(enum _AVPIXELFORMAT pf, unsigned int width, unsigned int height) {
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
return av_image_get_buffer_size(pf, width, height, 1);
#else
return outsize = avpicture_get_size(pf, width,height);
#endif
}

View File

@ -152,9 +152,7 @@ bool VideoStore::open() {
}
if (video_in_stream) {
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
zm_dump_codecpar(video_in_stream->codecpar);
#endif
if (monitor->GetOptVideoWriter() == Monitor::PASSTHROUGH) {
video_out_stream = avformat_new_stream(oc, nullptr);
@ -163,9 +161,8 @@ bool VideoStore::open() {
return false;
}
avcodec_parameters_copy(video_out_stream->codecpar, video_in_stream->codecpar);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
zm_dump_codecpar(video_out_stream->codecpar);
#endif
video_out_stream->avg_frame_rate = video_in_stream->avg_frame_rate;
// Only set orientation if doing passthrough, otherwise the frame image will be rotated
Monitor::Orientation orientation = monitor->getOrientation();
@ -192,22 +189,15 @@ bool VideoStore::open() {
video_out_codec = avcodec_find_encoder(video_in_stream->codecpar->codec_id);
if (video_out_codec) {
video_out_ctx = avcodec_alloc_context3(video_out_codec);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
ret = avcodec_parameters_to_context(video_out_ctx, video_in_stream->codecpar);
#else
ret = avcodec_copy_context(video_out_ctx, video_in_ctx);
#endif
if (ret < 0) {
Error("Could not initialize ctx parameters");
return false;
}
//video_out_ctx->pix_fmt = fix_deprecated_pix_fmt(video_out_ctx->pix_fmt);
if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
#if LIBAVCODEC_VERSION_CHECK(56, 35, 0, 64, 0)
video_out_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
#else
video_out_ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
#endif
}
video_out_ctx->time_base = video_in_ctx->time_base;
if (!(video_out_ctx->time_base.num && video_out_ctx->time_base.den)) {
@ -234,14 +224,11 @@ bool VideoStore::open() {
video_out_codec = nullptr;
}
} // end if video_out_codec
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
ret = avcodec_parameters_from_context(video_out_stream->codecpar, video_out_ctx);
if (ret < 0) {
Error("Could not initialize stream parameteres");
}
#else
avcodec_copy_context(video_out_stream->codec, video_out_ctx);
#endif
ret = avcodec_parameters_from_context(video_out_stream->codecpar, video_out_ctx);
if (ret < 0) {
Error("Could not initialize stream parameteres");
}
} // end if extradata_entry
av_dict_free(&opts);
} else if (monitor->GetOptVideoWriter() == Monitor::ENCODE) {
@ -286,11 +273,7 @@ bool VideoStore::open() {
Debug(1, "Found video codec for %s", codec_data[i].codec_name);
video_out_ctx = avcodec_alloc_context3(video_out_codec);
if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
#if LIBAVCODEC_VERSION_CHECK(56, 35, 0, 64, 0)
video_out_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
#else
video_out_ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
#endif
}
// When encoding, we are going to use the timestamp values instead of packet pts/dts
@ -377,12 +360,14 @@ bool VideoStore::open() {
Warning("Encoder Option %s not recognized by ffmpeg codec", e->key);
}
av_dict_free(&opts);
if (video_out_codec) break;
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
if (video_out_codec) {
break;
}
// We allocate and copy in newer ffmpeg, so need to free it
avcodec_free_context(&video_out_ctx);
if (hw_device_ctx) av_buffer_unref(&hw_device_ctx);
#endif
if (hw_device_ctx) {
av_buffer_unref(&hw_device_ctx);
}
} // end foreach codec
if (!video_out_codec) {
@ -392,17 +377,12 @@ bool VideoStore::open() {
Debug(2, "Success opening codec");
video_out_stream = avformat_new_stream(oc, nullptr);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
ret = avcodec_parameters_from_context(video_out_stream->codecpar, video_out_ctx);
if (ret < 0) {
Error("Could not initialize stream parameteres");
return false;
}
#else
avcodec_copy_context(video_out_stream->codec, video_out_ctx);
#endif
} // end if copying or transcoding
// zm_dump_codec(video_out_ctx);
} // end if video_in_stream
max_stream_index = video_out_stream->index;
@ -416,24 +396,16 @@ bool VideoStore::open() {
if (!audio_out_codec) {
Error("Could not find codec for AAC");
} else {
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
audio_in_ctx = avcodec_alloc_context3(audio_out_codec);
ret = avcodec_parameters_to_context(audio_in_ctx,
audio_in_stream->codecpar);
ret = avcodec_parameters_to_context(audio_in_ctx, audio_in_stream->codecpar);
audio_in_ctx->time_base = audio_in_stream->time_base;
#else
audio_in_ctx = audio_in_stream->codec;
#endif
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
audio_out_ctx = avcodec_alloc_context3(audio_out_codec);
if (!audio_out_ctx) {
Error("could not allocate codec ctx for AAC");
return false;
}
#else
audio_out_ctx = audio_out_stream->codec;
#endif
audio_out_stream = avformat_new_stream(oc, audio_out_codec);
audio_out_stream->time_base = audio_in_stream->time_base;
@ -453,7 +425,6 @@ bool VideoStore::open() {
}
audio_out_stream->time_base = audio_in_stream->time_base;
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
// Just use the ctx to copy the parameters over
audio_out_ctx = avcodec_alloc_context3(audio_out_codec);
if (!audio_out_ctx) {
@ -477,17 +448,6 @@ bool VideoStore::open() {
Error("Unable to copy audio params to stream %s",
av_make_error_string(ret).c_str());
}
#else
audio_out_ctx = audio_out_stream->codec;
ret = avcodec_copy_context(audio_out_ctx, audio_in_stream->codec);
if (ret < 0) {
Error("Unable to copy audio ctx %s",
av_make_error_string(ret).c_str());
audio_out_stream = nullptr;
return false;
} // end if
audio_out_ctx->codec_tag = 0;
#endif
if (audio_out_ctx->channels > 1) {
Warning("Audio isn't mono, changing it.");
@ -498,11 +458,7 @@ bool VideoStore::open() {
} // end if is AAC
if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
#if LIBAVCODEC_VERSION_CHECK(56, 35, 0, 64, 0)
audio_out_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
#else
audio_out_ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
#endif
}
// We will assume that subsequent stream allocations will increase the index
@ -572,13 +528,7 @@ void VideoStore::flush_codecs() {
av_init_packet(&pkt);
// I got crashes if the codec didn't do DELAY, so let's test for it.
if (video_out_ctx && video_out_ctx->codec && ( video_out_ctx->codec->capabilities &
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
AV_CODEC_CAP_DELAY
#else
CODEC_CAP_DELAY
#endif
)) {
if (video_out_ctx && video_out_ctx->codec && (video_out_ctx->codec->capabilities & AV_CODEC_CAP_DELAY)) {
// Put encoder into flushing mode
while ((zm_send_frame_receive_packet(video_out_ctx, nullptr, pkt)) > 0) {
av_packet_rescale_ts(&pkt,
@ -637,12 +587,10 @@ void VideoStore::flush_codecs() {
} // end if data returned from fifo
} // end while still data in the fifo
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
// Put encoder into flushing mode
avcodec_send_frame(audio_out_ctx, nullptr);
#endif
while (1) {
while (true) {
if (0 >= zm_receive_packet(audio_out_ctx, pkt)) {
Debug(1, "No more packets");
break;
@ -705,19 +653,12 @@ VideoStore::~VideoStore() {
}
if (audio_out_stream) {
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
// We allocate and copy in newer ffmpeg, so need to free it
//avcodec_free_context(&audio_in_ctx);
#endif
//Debug(4, "Success freeing audio_in_ctx");
audio_in_codec = nullptr;
if (audio_out_ctx) {
Debug(4, "Success closing audio_out_ctx");
avcodec_close(audio_out_ctx);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
avcodec_free_context(&audio_out_ctx);
#endif
}
if (resample_ctx) {
@ -751,7 +692,6 @@ VideoStore::~VideoStore() {
bool VideoStore::setup_resampler() {
int ret;
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
// Newer ffmpeg wants to keep everything separate... so have to lookup our own
// decoder, can't reuse the one from the camera.
audio_in_codec = avcodec_find_decoder(audio_in_stream->codecpar->codec_id);
@ -762,17 +702,6 @@ bool VideoStore::setup_resampler() {
Error("Unable to copy audio params to ctx %s",
av_make_error_string(ret).c_str());
}
#else
// codec is already open in ffmpeg_camera
audio_in_ctx = audio_in_stream->codec;
audio_in_codec = reinterpret_cast<const AVCodec *>(audio_in_ctx->codec);
if (!audio_in_codec) {
audio_in_codec = avcodec_find_decoder(audio_in_stream->codec->codec_id);
if (!audio_in_codec) {
return false;
}
}
#endif
// if the codec is already open, nothing is done.
if ((ret = avcodec_open2(audio_in_ctx, audio_in_codec, nullptr)) < 0) {
@ -796,7 +725,6 @@ bool VideoStore::setup_resampler() {
audio_out_ctx->channels = audio_in_ctx->channels;
audio_out_ctx->channel_layout = audio_in_ctx->channel_layout;
audio_out_ctx->sample_fmt = audio_in_ctx->sample_fmt;
#if LIBAVCODEC_VERSION_CHECK(56, 8, 0, 60, 100)
if (!audio_out_ctx->channel_layout) {
Debug(3, "Correcting channel layout from (%" PRIi64 ") to (%" PRIi64 ")",
audio_out_ctx->channel_layout,
@ -804,7 +732,7 @@ bool VideoStore::setup_resampler() {
);
audio_out_ctx->channel_layout = av_get_default_channel_layout(audio_out_ctx->channels);
}
#endif
if (audio_out_codec->supported_samplerates) {
int found = 0;
for (unsigned int i = 0; audio_out_codec->supported_samplerates[i]; i++) {
@ -851,15 +779,11 @@ bool VideoStore::setup_resampler() {
zm_dump_codec(audio_out_ctx);
audio_out_stream->time_base = (AVRational){1, audio_out_ctx->sample_rate};
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
if ( (ret = avcodec_parameters_from_context(
audio_out_stream->codecpar,
audio_out_ctx)) < 0 ) {
if ((ret = avcodec_parameters_from_context(audio_out_stream->codecpar, audio_out_ctx)) < 0) {
Error("Could not initialize stream parameteres");
return false;
}
zm_dump_codecpar(audio_out_stream->codecpar);
#endif
Debug(3,
"Time bases: AUDIO in stream (%d/%d) in codec: (%d/%d) out "
@ -880,20 +804,11 @@ bool VideoStore::setup_resampler() {
audio_out_ctx->channels, audio_out_ctx->sample_fmt,
audio_out_ctx->channel_layout, audio_out_ctx->frame_size);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
Debug(1,
"Audio out stream bit_rate (%" PRIi64 ") sample_rate(%d) channels(%d) fmt(%d) layout(%" PRIi64 ") frame_size(%d)",
audio_out_stream->codecpar->bit_rate, audio_out_stream->codecpar->sample_rate,
audio_out_stream->codecpar->channels, audio_out_stream->codecpar->format,
audio_out_stream->codecpar->channel_layout, audio_out_stream->codecpar->frame_size);
#else
Debug(1,
"Audio out bit_rate (%d) sample_rate(%d) channels(%d) fmt(%d) "
"layout(%" PRIi64 ") frame_size(%d)",
audio_out_stream->codec->bit_rate, audio_out_stream->codec->sample_rate,
audio_out_stream->codec->channels, audio_out_stream->codec->sample_fmt,
audio_out_stream->codec->channel_layout, audio_out_stream->codec->frame_size);
#endif
/** Create a new frame to store the audio samples. */
if (!in_frame) {
@ -942,9 +857,7 @@ bool VideoStore::setup_resampler() {
out_frame->nb_samples = audio_out_ctx->frame_size;
out_frame->format = audio_out_ctx->sample_fmt;
#if LIBAVCODEC_VERSION_CHECK(56, 8, 0, 60, 100)
out_frame->channels = audio_out_ctx->channels;
#endif
out_frame->channel_layout = audio_out_ctx->channel_layout;
out_frame->sample_rate = audio_out_ctx->sample_rate;
@ -1074,9 +987,7 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr<ZMPacket> &zm_packet
// Do this to allow the encoder to choose whether to use I/P/B frame
//zm_packet->out_frame->pict_type = AV_PICTURE_TYPE_NONE;
//zm_packet->out_frame->key_frame = zm_packet->keyframe;
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
frame->pkt_duration = 0;
#endif
int64_t in_pts = zm_packet->timestamp.tv_sec * (uint64_t)1000000 + zm_packet->timestamp.tv_usec;
if (!video_first_pts) {