Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
libav: Use newer version of LIBAV. Patch by IRC user 'kvaster'.
source: http://pastebin.com/fGLBsdqb
Many thanks / all credit to @kvaster

[12:15] < kvaster> I've made a patch for newer libav locally. Will be able to submit today a bit later.
[12:17] < kvaster> http://pastebin.com/fGLBsdqb
[12:23] < kvaster> it was just small api changes inside libav, I'm worried only about audio stream buffer sizes.
[12:24] < kvaster> Anyway this is working for me at least.
  • Loading branch information
dreamcat4 committed Aug 5, 2014
1 parent e99a563 commit d18bc8d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 49 deletions.
4 changes: 2 additions & 2 deletions configure
Expand Up @@ -245,7 +245,7 @@ fi
if enabled_or_auto libav; then
has_libav=true

if $has_libav && ! check_pkg libavcodec "<=55.0.0"; then
if $has_libav && ! check_pkg libavcodec "<=56.0.0"; then
has_libav=false

This comment has been minimized.

Copy link
@dreamcat4

dreamcat4 Aug 6, 2014

Author Owner

This is wrong, because future versions newer than 56 will also work too (until more / future API breakage). It should be changed into being a min version requirement, as older version even before 55 may continue to work. For example .53 or something.

Ideally the version check should also really depend the ffmpeg or libav since the exact version number is different in each case. Some version drift since they branch away from each other. Else the min version can be the higher min one of {ffmpeg,libav}.

Previously it accept any oldest version. Maybe that still true (I don't know). In which case (for feature-based configuration) the version check could instead be dropped entirely. Which probably wouldn't hurt anybody, since everybody these days use some 55 or newer versions.

fi

Expand All @@ -257,7 +257,7 @@ if enabled_or_auto libav; then
has_libav=false
fi

if $has_libav && ! check_pkg libavformat "<=55.0.0"; then
if $has_libav && ! check_pkg libavformat "<=56.0.0"; then
has_libav=false
fi

Expand Down
56 changes: 28 additions & 28 deletions src/libav.c
Expand Up @@ -50,47 +50,47 @@ libav_log_callback(void *ptr, int level, const char *fmt, va_list vl)
/**
* Translate a component type to a libavcodec id
*/
enum CodecID
enum AVCodecID
streaming_component_type2codec_id(streaming_component_type_t type)
{
enum CodecID codec_id = CODEC_ID_NONE;
enum AVCodecID codec_id = AV_CODEC_ID_NONE;

This comment has been minimized.

Copy link
@dreamcat4

dreamcat4 Aug 6, 2014

Author Owner

These are all is good change for AV_* prefix of the CODEC_IDs. But for backwards compatibility with old version we also need to include each time some extra headers like this:

https://gist.github.com/dreamcat4/240e9e4bb32467dc4316

And that header should be updated if ever adding some new AV_CODED_IDs, that were not previously used here.

switch(type) {
case SCT_H264:
codec_id = CODEC_ID_H264;
codec_id = AV_CODEC_ID_H264;
break;
case SCT_MPEG2VIDEO:
codec_id = CODEC_ID_MPEG2VIDEO;
codec_id = AV_CODEC_ID_MPEG2VIDEO;
break;
case SCT_VP8:
codec_id = CODEC_ID_VP8;
codec_id = AV_CODEC_ID_VP8;
break;
case SCT_AC3:
codec_id = CODEC_ID_AC3;
codec_id = AV_CODEC_ID_AC3;
break;
case SCT_EAC3:
codec_id = CODEC_ID_EAC3;
codec_id = AV_CODEC_ID_EAC3;
break;
case SCT_AAC:
codec_id = CODEC_ID_AAC;
codec_id = AV_CODEC_ID_AAC;
break;
case SCT_MPEG2AUDIO:
codec_id = CODEC_ID_MP2;
codec_id = AV_CODEC_ID_MP2;
break;
case SCT_VORBIS:
codec_id = CODEC_ID_VORBIS;
codec_id = AV_CODEC_ID_VORBIS;
break;
case SCT_DVBSUB:
codec_id = CODEC_ID_DVB_SUBTITLE;
codec_id = AV_CODEC_ID_DVB_SUBTITLE;
break;
case SCT_TEXTSUB:
codec_id = CODEC_ID_TEXT;
codec_id = AV_CODEC_ID_TEXT;
break;
case SCT_TELETEXT:
codec_id = CODEC_ID_DVB_TELETEXT;
codec_id = AV_CODEC_ID_DVB_TELETEXT;
break;
default:
codec_id = CODEC_ID_NONE;
codec_id = AV_CODEC_ID_NONE;
break;
}

Expand All @@ -102,45 +102,45 @@ streaming_component_type2codec_id(streaming_component_type_t type)
* Translate a libavcodec id to a component type
*/
streaming_component_type_t
codec_id2streaming_component_type(enum CodecID id)
codec_id2streaming_component_type(enum AVCodecID id)
{
streaming_component_type_t type = CODEC_ID_NONE;
streaming_component_type_t type = AV_CODEC_ID_NONE;

switch(id) {
case CODEC_ID_H264:
case AV_CODEC_ID_H264:
type = SCT_H264;
break;
case CODEC_ID_MPEG2VIDEO:
case AV_CODEC_ID_MPEG2VIDEO:
type = SCT_MPEG2VIDEO;
break;
case CODEC_ID_VP8:
case AV_CODEC_ID_VP8:
type = SCT_VP8;
break;
case CODEC_ID_AC3:
case AV_CODEC_ID_AC3:
type = SCT_AC3;
break;
case CODEC_ID_EAC3:
case AV_CODEC_ID_EAC3:
type = SCT_EAC3;
break;
case CODEC_ID_AAC:
case AV_CODEC_ID_AAC:
type = SCT_AAC;
break;
case CODEC_ID_MP2:
case AV_CODEC_ID_MP2:
type = SCT_MPEG2AUDIO;
break;
case CODEC_ID_VORBIS:
case AV_CODEC_ID_VORBIS:
type = SCT_VORBIS;
break;
case CODEC_ID_DVB_SUBTITLE:
case AV_CODEC_ID_DVB_SUBTITLE:
type = SCT_DVBSUB;
break;
case CODEC_ID_TEXT:
case AV_CODEC_ID_TEXT:
type = SCT_TEXTSUB;
break;
case CODEC_ID_DVB_TELETEXT:
case AV_CODEC_ID_DVB_TELETEXT:
type = SCT_TELETEXT;
break;
case CODEC_ID_NONE:
case AV_CODEC_ID_NONE:
type = SCT_NONE;
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions src/libav.h
Expand Up @@ -23,8 +23,8 @@
#include <libavformat/avformat.h>
#include "tvheadend.h"

enum CodecID streaming_component_type2codec_id(streaming_component_type_t type);
streaming_component_type_t codec_id2streaming_component_type(enum CodecID id);
enum AVCodecID streaming_component_type2codec_id(streaming_component_type_t type);
streaming_component_type_t codec_id2streaming_component_type(enum AVCodecID id);
int libav_is_encoder(AVCodec *codec);
void libav_init(void);

Expand Down
34 changes: 17 additions & 17 deletions src/plumbing/transcoding.c
Expand Up @@ -108,9 +108,9 @@ typedef struct transcoder {



#define WORKING_ENCODER(x) (x == CODEC_ID_H264 || x == CODEC_ID_MPEG2VIDEO || \
x == CODEC_ID_VP8 || x == CODEC_ID_AAC || \
x == CODEC_ID_MP2 || x == CODEC_ID_VORBIS)
#define WORKING_ENCODER(x) (x == AV_CODEC_ID_H264 || x == AV_CODEC_ID_MPEG2VIDEO || \
x == AV_CODEC_ID_VP8 || x == AV_CODEC_ID_AAC || \
x == AV_CODEC_ID_MP2 || x == AV_CODEC_ID_VORBIS)


uint32_t transcoding_enabled = 0;
Expand All @@ -121,11 +121,11 @@ uint32_t transcoding_enabled = 0;
static AVCodec *
transcoder_get_decoder(streaming_component_type_t ty)
{
enum CodecID codec_id;
enum AVCodecID codec_id;
AVCodec *codec;

codec_id = streaming_component_type2codec_id(ty);
if (codec_id == CODEC_ID_NONE) {
if (codec_id == AV_CODEC_ID_NONE) {
tvhlog(LOG_ERR, "transcode", "Unsupported input codec %s",
streaming_component_type2txt(ty));
return NULL;
Expand All @@ -150,11 +150,11 @@ transcoder_get_decoder(streaming_component_type_t ty)
static AVCodec *
transcoder_get_encoder(streaming_component_type_t ty)
{
enum CodecID codec_id;
enum AVCodecID codec_id;
AVCodec *codec;

codec_id = streaming_component_type2codec_id(ty);
if (codec_id == CODEC_ID_NONE) {
if (codec_id == AV_CODEC_ID_NONE) {
tvhlog(LOG_ERR, "transcode", "Unable to find %s codec",
streaming_component_type2txt(ty));
return NULL;
Expand Down Expand Up @@ -214,7 +214,7 @@ transcoder_stream_subtitle(transcoder_stream_t *ts, th_pkt_t *pkt)
icodec = ss->sub_icodec;
//ocodec = ss->sub_ocodec;

if (ictx->codec_id == CODEC_ID_NONE) {
if (ictx->codec_id == AV_CODEC_ID_NONE) {
ictx->codec_id = icodec->id;

if (avcodec_open2(ictx, icodec, NULL) < 0) {
Expand Down Expand Up @@ -272,7 +272,7 @@ transcoder_stream_audio(transcoder_stream_t *ts, th_pkt_t *pkt)
icodec = as->aud_icodec;
ocodec = as->aud_ocodec;

if (ictx->codec_id == CODEC_ID_NONE) {
if (ictx->codec_id == AV_CODEC_ID_NONE) {
ictx->codec_id = icodec->id;

if (avcodec_open2(ictx, icodec, NULL) < 0) {
Expand Down Expand Up @@ -391,7 +391,7 @@ transcoder_stream_audio(transcoder_stream_t *ts, th_pkt_t *pkt)
break;
}

if (octx->codec_id == CODEC_ID_NONE) {
if (octx->codec_id == AV_CODEC_ID_NONE) {
octx->codec_id = ocodec->id;

if (avcodec_open2(octx, ocodec, NULL) < 0) {
Expand Down Expand Up @@ -478,7 +478,7 @@ transcoder_stream_video(transcoder_stream_t *ts, th_pkt_t *pkt)
buf = out = deint = NULL;
opts = NULL;

if (ictx->codec_id == CODEC_ID_NONE) {
if (ictx->codec_id == AV_CODEC_ID_NONE) {
ictx->codec_id = icodec->id;

if (avcodec_open2(ictx, icodec, NULL) < 0) {
Expand Down Expand Up @@ -523,7 +523,7 @@ transcoder_stream_video(transcoder_stream_t *ts, th_pkt_t *pkt)
vs->vid_enc_frame->sample_aspect_ratio.num = vs->vid_dec_frame->sample_aspect_ratio.num;
vs->vid_enc_frame->sample_aspect_ratio.den = vs->vid_dec_frame->sample_aspect_ratio.den;

if(octx->codec_id == CODEC_ID_NONE) {
if(octx->codec_id == AV_CODEC_ID_NONE) {
// Common settings
octx->width = vs->vid_width ? vs->vid_width : ictx->width;
octx->height = vs->vid_height ? vs->vid_height : ictx->height;
Expand All @@ -534,7 +534,7 @@ transcoder_stream_video(transcoder_stream_t *ts, th_pkt_t *pkt)

switch (ts->ts_type) {
case SCT_MPEG2VIDEO:
octx->codec_id = CODEC_ID_MPEG2VIDEO;
octx->codec_id = AV_CODEC_ID_MPEG2VIDEO;
octx->pix_fmt = PIX_FMT_YUV420P;
octx->flags |= CODEC_FLAG_GLOBAL_HEADER;

Expand All @@ -547,7 +547,7 @@ transcoder_stream_video(transcoder_stream_t *ts, th_pkt_t *pkt)
break;

case SCT_VP8:
octx->codec_id = CODEC_ID_VP8;
octx->codec_id = AV_CODEC_ID_VP8;
octx->pix_fmt = PIX_FMT_YUV420P;

octx->qmin = 10;
Expand All @@ -561,7 +561,7 @@ transcoder_stream_video(transcoder_stream_t *ts, th_pkt_t *pkt)
break;

case SCT_H264:
octx->codec_id = CODEC_ID_H264;
octx->codec_id = AV_CODEC_ID_H264;
octx->pix_fmt = PIX_FMT_YUV420P;
octx->flags |= CODEC_FLAG_GLOBAL_HEADER;

Expand Down Expand Up @@ -951,8 +951,8 @@ transcoder_init_audio(transcoder_t *t, streaming_start_component_t *ssc)
as->aud_ictx->thread_count = sysconf(_SC_NPROCESSORS_ONLN);
as->aud_octx->thread_count = sysconf(_SC_NPROCESSORS_ONLN);

as->aud_dec_size = AVCODEC_MAX_AUDIO_FRAME_SIZE*2;
as->aud_enc_size = AVCODEC_MAX_AUDIO_FRAME_SIZE*2;
as->aud_dec_size = 192000*2;
as->aud_enc_size = 192000*2;

This comment has been minimized.

Copy link
@dreamcat4

dreamcat4 Aug 6, 2014

Author Owner

This #define no longer exists in newer versions. The hard-coded value 192000 should be fine for both old and new. Used to be defined in libavcodec/avcodec.h.

https://github.com/FFmpeg/FFmpeg/blob/97478ef5fe7dd2ff8da98e381de4a6b2b979b485/doc/APIchanges#L1029-1034

https://github.com/libav/libav/blob/a7153444df9040bf6ae103e0bbf6104b66f974cb/doc/APIchanges#L657-662

as->aud_dec_sample = av_malloc(as->aud_dec_size + FF_INPUT_BUFFER_PADDING_SIZE);
as->aud_enc_sample = av_malloc(as->aud_enc_size + FF_INPUT_BUFFER_PADDING_SIZE);
Expand Down

2 comments on commit d18bc8d

@kvaster
Copy link

@kvaster kvaster commented on d18bc8d Aug 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can drop version now. It was 'draft' patch made locally in a fast way.

@dreamcat4
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kvaster yes - done in next commits of dreamcat4/libav branch. It compiles for me now with ffmpeg-2.2.4. So next I'm gonna do some basic testing myself, see if it will work or segfault (on HEAD).

Please sign in to comment.