Skip to content

Commit

Permalink
Better way to detect new API
Browse files Browse the repository at this point in the history
  • Loading branch information
kala13x committed Nov 6, 2024
1 parent a8d951f commit d9fb350
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ XSTATUS XEncoder_RestartCodec(xencoder_t *pEncoder, int nStreamIndex)
xstatus_t *pStatus = &pEncoder->status;

xstream_t *pStream = XStreams_GetByDstIndex(&pEncoder->streams, nStreamIndex);
XASSERT(pStream, XStat_ErrCb(pStatus, "Stream is not found: %s", nStreamIndex));
XASSERT(pStream, XStat_ErrCb(pStatus, "Stream is not found: dst(%d)", nStreamIndex));

if (pStream->pCodecCtx != NULL)
{
Expand Down Expand Up @@ -385,7 +385,7 @@ XSTATUS XEncoder_FixTS(xencoder_t *pEncoder, AVPacket *pPacket, xstream_t *pStre
if (pStream == NULL)
{
pStream = XStreams_GetByDstIndex(&pEncoder->streams, pPacket->stream_index);
XASSERT(pStream, XStat_ErrCb(pStatus, "Stream is not found: %d", pPacket->stream_index));
XASSERT(pStream, XStat_ErrCb(pStatus, "Stream is not found: dst(%d)", pPacket->stream_index));
}

if (pEncoder->nTSFix &&
Expand Down Expand Up @@ -414,8 +414,8 @@ XSTATUS XEncoder_WritePacket(xencoder_t *pEncoder, AVPacket *pPacket)
XASSERT(pEncoder->bOutputOpen, XStat_ErrCb(pStatus, "Output context is not open"));

xstream_t *pStream = XStreams_GetByDstIndex(&pEncoder->streams, pPacket->stream_index);
XASSERT(pStream, XStat_ErrCb(pStatus, "Stream is not found: %d", pPacket->stream_index));
XASSERT(pStream->pAvStream, XStat_ErrCb(pStatus, "Stream is not open: %d", pStream->nDstIndex));
XASSERT(pStream, XStat_ErrCb(pStatus, "Stream is not found: dst(%d)", pPacket->stream_index));
XASSERT(pStream->pAvStream, XStat_ErrCb(pStatus, "Stream is not open: dst(%d)", pStream->nDstIndex));

/* Rescale timestamps and fix non motion PTS/DTS if detected */
XEncoder_RescaleTS(pEncoder, pPacket, pStream);
Expand All @@ -425,7 +425,7 @@ XSTATUS XEncoder_WritePacket(xencoder_t *pEncoder, AVPacket *pPacket)
pStream->nLastDTS = pPacket->dts;

pStatus->nAVStatus = av_interleaved_write_frame(pEncoder->pFmtCtx, pPacket);
XASSERT((pStatus->nAVStatus >= 0), XStat_ErrCb(pStatus, "Failed to write packet"));
XASSERT((pStatus->nAVStatus >= 0), XStat_ErrCb(pStatus, "Failed to write packet: dst(%d)", pPacket->stream_index));

pStream->nPacketCount++;
return XSTDOK;
Expand Down
4 changes: 4 additions & 0 deletions src/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ extern "C" {
typedef void(*xencoder_stat_cb_t)(void *pUserCtx, const char *pStatus);
typedef void(*xencoder_err_cb_t)(void *pUserCtx, const char *pErrStr);
typedef int(*xencoder_pkt_cb_t)(void *pUserCtx, AVPacket *pPacket);
<<<<<<< HEAD

#ifdef __APPLE__
typedef int(*xmuxer_cb_t)(void *pUserCtx, const uint8_t *pData, int nSize);
#else
typedef int(*xmuxer_cb_t)(void *pUserCtx, uint8_t *pData, int nSize);
#endif
=======
typedef int(*xmuxer_cb_t)(void *pUserCtx, const uint8_t *pData, int nSize);
>>>>>>> 58494e1 (Better way to detect new API)

#define XENCODER_IO_SIZE (1024 * 64)

Expand Down
13 changes: 6 additions & 7 deletions src/stdinc.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@
#include <libswresample/swresample.h>
#include <libavutil/opt.h>

/*
If FF_API_OLD_CHANNEL_LAYOUT is defined, that means 'channel' and
'channel_layout' members of AVCodecContext structure are deprecated
and we need to use the new AVChannelLayout structure instead.
*/
#define XMEDIA_AVCODEC_VER_AT_LEAST(major,minor) (LIBAVCODEC_VERSION_MAJOR > major || \
(LIBAVCODEC_VERSION_MAJOR == major && \
LIBAVCODEC_VERSION_MINOR >= minor))

#ifndef XCODEC_USE_NEW_CHANNEL
#if defined(FF_API_OLD_CHANNEL_LAYOUT) || defined(__APPLE__)
#if XMEDIA_AVCODEC_VER_AT_LEAST(5, 7)
#define XCODEC_USE_NEW_CHANNEL 1
#endif
#endif

#ifndef XCODEC_USE_NEW_FIFO
#if defined(FF_API_FIFO_OLD_API) || defined(__APPLE__)
#if XMEDIA_AVCODEC_VER_AT_LEAST(5, 7)
#define XCODEC_USE_NEW_FIFO 1
#endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#define XMEDIA_VERSION_MAX 1
#define XMEDIA_VERSION_MIN 2
#define XMEDIA_BUILD_NUMBER 14
#define XMEDIA_BUILD_NUMBER 15

#ifdef __cplusplus
extern "C" {
Expand Down

0 comments on commit d9fb350

Please sign in to comment.