add:compat.h

This commit is contained in:
Barry 2019-06-15 07:24:07 +08:00
commit c1c8f56265
4 changed files with 48 additions and 17 deletions

View file

@ -1,6 +1,7 @@
#include <QDebug>
#include <QTime>
#include "compat.h"
#include "decoder.h"
#include "frames.h"
#include "devicesocket.h"
@ -53,7 +54,7 @@ static void avLogCallback(void *avcl, int level, const char *fmt, va_list vl) {
bool Decoder::init()
{
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100)
#ifdef QTSCRCPY_LAVF_REQUIRES_REGISTER_ALL
av_register_all();
#endif
if (avformat_network_init()) {
@ -325,7 +326,7 @@ void Decoder::run()
AVFrame* decodingFrame = m_frames->decodingFrame();
// the new decoding/encoding API has been introduced by:
// <http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=7fc329e2dd6226dfecaa4a1d7adf353bf2773726>
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 0)
#ifdef QTSCRCPY_LAVF_HAS_NEW_ENCODING_DECODING_API
int ret;
if ((ret = avcodec_send_packet(codecCtx, &packet)) < 0) {
char errorbuf[255] = { 0 };
@ -371,7 +372,7 @@ void Decoder::run()
int gotPicture = 0;
int len = -1;
if (decodingFrame) {
len = avcodec_decode_video2(codecCtx, decodingFrame, &gotpicture, &packet);
len = avcodec_decode_video2(codecCtx, decodingFrame, &gotPicture, &packet);
}
if (len < 0) {
qCritical("Could not decode video packet: %d", len);

View file

@ -1,18 +1,9 @@
#include <QDebug>
#include <QFileInfo>
#include "compat.h"
#include "recorder.h"
// In ffmpeg/doc/APIchanges:
// 2016-04-11 - 6f69f7a / 9200514 - lavf 57.33.100 / 57.5.0 - avformat.h
// Add AVStream.codecpar, deprecate AVStream.codec.
#if (LIBAVFORMAT_VERSION_MICRO >= 100 /* FFmpeg */ && \
LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 33, 100)) \
|| (LIBAVFORMAT_VERSION_MICRO < 100 && /* Libav */ \
LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 5, 0))
# define LAVF_NEW_CODEC_API
#endif
static const AVRational SCRCPY_TIME_BASE = {1, 1000000}; // timestamps in us
Recorder::Recorder(const QString& fileName)
@ -67,7 +58,7 @@ bool Recorder::open(AVCodec *inputCodec)
return false;
}
#ifdef LAVF_NEW_CODEC_API
#ifdef QTSCRCPY_LAVF_HAS_NEW_CODEC_PARAMS_API
outStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
outStream->codecpar->codec_id = inputCodec->id;
outStream->codecpar->format = AV_PIX_FMT_YUV420P;
@ -126,12 +117,12 @@ bool Recorder::write(AVPacket *packet)
const AVOutputFormat *Recorder::findMuxer(const char* name)
{
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 9, 100)
#ifdef QTSCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API
void* opaque = Q_NULLPTR;
#endif
const AVOutputFormat* outFormat = Q_NULLPTR;
do {
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 9, 100)
#ifdef QTSCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API
outFormat = av_muxer_iterate(&opaque);
#else
outFormat = av_oformat_next(outFormat);
@ -152,7 +143,7 @@ bool Recorder::recorderWriteHeader(AVPacket *packet)
// copy the first packet to the extra data
memcpy(extradata, packet->data, packet->size);
#ifdef LAVF_NEW_CODEC_API
#ifdef QTSCRCPY_LAVF_HAS_NEW_CODEC_PARAMS_API
ostream->codecpar->extradata = extradata;
ostream->codecpar->extradata_size = packet->size;
#else

36
QtScrcpy/util/compat.h Normal file
View file

@ -0,0 +1,36 @@
#ifndef COMPAT_H
#define COMPAT_H
#include "libavcodec/version.h"
#include "libavformat/version.h"
// In ffmpeg/doc/APIchanges:
// 2016-04-11 - 6f69f7a / 9200514 - lavf 57.33.100 / 57.5.0 - avformat.h
// Add AVStream.codecpar, deprecate AVStream.codec.
#if (LIBAVFORMAT_VERSION_MICRO >= 100 /* FFmpeg */ && \
LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 33, 100)) \
|| (LIBAVFORMAT_VERSION_MICRO < 100 && /* Libav */ \
LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(57, 5, 0))
# define QTSCRCPY_LAVF_HAS_NEW_CODEC_PARAMS_API
#endif
// In ffmpeg/doc/APIchanges:
// 2018-02-06 - 0694d87024 - lavf 58.9.100 - avformat.h
// Deprecate use of av_register_input_format(), av_register_output_format(),
// av_register_all(), av_iformat_next(), av_oformat_next().
// Add av_demuxer_iterate(), and av_muxer_iterate().
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(58, 9, 100)
# define QTSCRCPY_LAVF_HAS_NEW_MUXER_ITERATOR_API
#else
# define QTSCRCPY_LAVF_REQUIRES_REGISTER_ALL
#endif
// In ffmpeg/doc/APIchanges:
// 2016-04-21 - 7fc329e - lavc 57.37.100 - avcodec.h
// Add a new audio/video encoding and decoding API with decoupled input
// and output -- avcodec_send_packet(), avcodec_receive_frame(),
// avcodec_send_frame() and avcodec_receive_packet().
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 37, 100)
# define QTSCRCPY_LAVF_HAS_NEW_ENCODING_DECODING_API
#endif
#endif // COMPAT_H

View file

@ -1 +1,4 @@
include ($$PWD/mousetap/mousetap.pri)
HEADERS += \
$$PWD/compat.h