diff --git a/lib/libdvbsub/dvbsubtitle.cpp b/lib/libdvbsub/dvbsubtitle.cpp index e2bd49e5b..8fc069509 100644 --- a/lib/libdvbsub/dvbsubtitle.cpp +++ b/lib/libdvbsub/dvbsubtitle.cpp @@ -68,8 +68,13 @@ cDvbSubtitleBitmaps::~cDvbSubtitleBitmaps() if(sub.rects) { for (i = 0; i < Count(); i++) { +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 5, 0) av_freep(&sub.rects[i]->pict.data[0]); av_freep(&sub.rects[i]->pict.data[1]); +#else + av_freep(&sub.rects[i]->data[0]); + av_freep(&sub.rects[i]->data[1]); +#endif av_freep(&sub.rects[i]); } @@ -122,7 +127,11 @@ void cDvbSubtitleBitmaps::Draw(int &min_x, int &min_y, int &max_x, int &max_y) int xf = int(xc * (double) 720); for (i = 0; i < Count(); i++) { +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 5, 0) uint32_t * colors = (uint32_t *) sub.rects[i]->pict.data[1]; +#else + uint32_t * colors = (uint32_t *) sub.rects[i]->data[1]; +#endif int width = sub.rects[i]->w; int height = sub.rects[i]->h; int xoff, yoff; @@ -142,9 +151,11 @@ void cDvbSubtitleBitmaps::Draw(int &min_x, int &min_y, int &max_x, int &max_y) dbgconverter("cDvbSubtitleBitmaps::Draw: #%d at %d,%d size %dx%d colors %d (x=%d y=%d w=%d h=%d) \n", i+1, sub.rects[i]->x, sub.rects[i]->y, sub.rects[i]->w, sub.rects[i]->h, sub.rects[i]->nb_colors, xoff, yoff, nw, nh); - +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 5, 0) fb_pixel_t * newdata = simple_resize32 (sub.rects[i]->pict.data[0], colors, sub.rects[i]->nb_colors, width, height, nw, nh); - +#else + fb_pixel_t * newdata = simple_resize32 (sub.rects[i]->data[0], colors, sub.rects[i]->nb_colors, width, height, nw, nh); +#endif fb_pixel_t * ptr = newdata; for (int y2 = 0; y2 < nh; y2++) { int y = (yoff + y2) * stride; diff --git a/src/compatibility.h b/src/compatibility.h new file mode 100644 index 000000000..aa03d1ef8 --- /dev/null +++ b/src/compatibility.h @@ -0,0 +1,34 @@ +/* + Based up Neutrino-GUI - Tuxbox-Project + Copyright (C) 2001 by Steffen Hehn 'McClean' + + Copyright (C) 2017, Michael Liebmann 'micha-bbg' + + License: GPL + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef __COMPATIBILITY_H__ +#define __COMPATIBILITY_H__ + + +#if !defined __UCLIBC__ || ((__UCLIBC_MAJOR__ >= 1) && (__UCLIBC_MINOR__ >= 0) && (__UCLIBC_SUBLEVEL__ >= 10)) +#define comp_malloc_stats(a) malloc_stats() +#else +#define comp_malloc_stats(a) malloc_stats(a) +#endif + + +#endif // __COMPATIBILITY_H__ diff --git a/src/driver/audiodec/ffmpegdec.cpp b/src/driver/audiodec/ffmpegdec.cpp index c97497175..695f67d89 100644 --- a/src/driver/audiodec/ffmpegdec.cpp +++ b/src/driver/audiodec/ffmpegdec.cpp @@ -47,6 +47,11 @@ extern "C" { #define av_frame_unref avcodec_get_frame_defaults #define av_frame_free avcodec_free_frame #endif + +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57, 8, 0 )) +#define av_packet_unref av_free_packet +#endif + #include #include @@ -218,9 +223,16 @@ CBaseDec::RetCode CFfmpegDec::Decoder(FILE *_in, int /*OutputFd*/, State* state, Status=DATA_ERR; return Status; } - +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,5,0 )) AVCodecContext *c = avc->streams[best_stream]->codec; - +#else + AVCodecContext *c = avcodec_alloc_context3(codec); + if(avcodec_parameters_to_context(c,avc->streams[best_stream]->codecpar) < 0){ + DeInit(); + Status=DATA_ERR; + return Status; + } +#endif mutex.lock(); int r = avcodec_open2(c, codec, NULL); mutex.unlock(); @@ -326,9 +338,10 @@ CBaseDec::RetCode CFfmpegDec::Decoder(FILE *_in, int /*OutputFd*/, State* state, Status=DATA_ERR; break; } - } else + } else{ av_frame_unref(frame); - + } +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,37,100) int len = avcodec_decode_audio4(c, frame, &got_frame, &packet); if (len < 0) { // skip frame @@ -340,6 +353,27 @@ CBaseDec::RetCode CFfmpegDec::Decoder(FILE *_in, int /*OutputFd*/, State* state, mutex.unlock(); continue; } + packet.size -= len; + packet.data += len; +#else + int ret = avcodec_send_packet(c, &packet); + if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF){ + break; + } + if (ret >= 0){ + packet.size = 0; + } + ret = avcodec_receive_frame(c, frame); + if (ret < 0){ + if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF){ + break; + } + else{ + continue; + } + } + got_frame = 1; +#endif if (got_frame && *state!=PAUSE) { int out_samples; outsamples = av_rescale_rnd(swr_get_delay(swr, c->sample_rate) + frame->nb_samples, @@ -368,8 +402,6 @@ CBaseDec::RetCode CFfmpegDec::Decoder(FILE *_in, int /*OutputFd*/, State* state, if (!start_pts) start_pts = pts; } - packet.size -= len; - packet.data += len; } if (time_played && avc->streams[best_stream]->time_base.den) *time_played = (pts - start_pts) * avc->streams[best_stream]->time_base.num / avc->streams[best_stream]->time_base.den; @@ -428,7 +460,11 @@ bool CFfmpegDec::SetMetaData(FILE *_in, CAudioMetaData* m, bool save_cover) if (!is_stream) { GetMeta(avc->metadata); for(unsigned int i = 0; i < avc->nb_streams; i++) { +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,5,0 )) if (avc->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) +#else + if (avc->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) +#endif GetMeta(avc->streams[i]->metadata); } } @@ -445,12 +481,17 @@ bool CFfmpegDec::SetMetaData(FILE *_in, CAudioMetaData* m, bool save_cover) DeInit(); return false; } - +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,5,0 )) if (!codec) codec = avcodec_find_decoder(avc->streams[best_stream]->codec->codec_id); samplerate = avc->streams[best_stream]->codec->sample_rate; mChannels = av_get_channel_layout_nb_channels(avc->streams[best_stream]->codec->channel_layout); - +#else + if (!codec) + codec = avcodec_find_decoder(avc->streams[best_stream]->codecpar->codec_id); + samplerate = avc->streams[best_stream]->codecpar->sample_rate; + mChannels = av_get_channel_layout_nb_channels(avc->streams[best_stream]->codecpar->channel_layout); +#endif std::stringstream ss; if (codec && codec->long_name != NULL) @@ -470,8 +511,13 @@ bool CFfmpegDec::SetMetaData(FILE *_in, CAudioMetaData* m, bool save_cover) printf("CFfmpegDec: format %s (%s) duration %ld\n", avc->iformat->name, type_info.c_str(), total_time); for(unsigned int i = 0; i < avc->nb_streams; i++) { +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,5,0 )) if (avc->streams[i]->codec->bit_rate > 0) bitrate += avc->streams[i]->codec->bit_rate; +#else + if (avc->streams[i]->codecpar->bit_rate > 0) + bitrate += avc->streams[i]->codecpar->bit_rate; +#endif if (save_cover && (avc->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC)) { mkdir(COVERDIR, 0755); std::string cover(COVERDIR); diff --git a/src/driver/record.cpp b/src/driver/record.cpp index fd9a9af49..4fb173e08 100644 --- a/src/driver/record.cpp +++ b/src/driver/record.cpp @@ -69,12 +69,20 @@ extern "C" { #include } +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57, 8, 0 )) +#define av_packet_unref av_free_packet +#endif + class CStreamRec : public CRecordInstance, OpenThreads::Thread { private: AVFormatContext *ifcx; AVFormatContext *ofcx; +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,52,100 )) AVBitStreamFilterContext *bsfc; +#else + AVBSFContext *bsfc; +#endif bool stopped; bool interrupt; time_t time_started; @@ -1994,8 +2002,13 @@ void CStreamRec::Close() } avformat_free_context(ofcx); } - if (bsfc) + if (bsfc){ +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,52,100 )) av_bitstream_filter_close(bsfc); +#else + av_bsf_free(&bsfc); +#endif + } ifcx = NULL; ofcx = NULL; bsfc = NULL; @@ -2012,7 +2025,11 @@ void CStreamRec::FillMovieInfo(CZapitChannel * /*channel*/, APIDList & /*apid_li for (unsigned i = 0; i < ofcx->nb_streams; i++) { AVStream *st = ofcx->streams[i]; +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,5,0 )) AVCodecContext * codec = st->codec; +#else + AVCodecParameters * codec = st->codecpar; +#endif if (codec->codec_type == AVMEDIA_TYPE_AUDIO) { AUDIO_PIDS audio_pids; AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0); @@ -2241,12 +2258,17 @@ bool CStreamRec::Open(CZapitChannel * channel) stream_index = -1; int stid = 0x200; for (unsigned i = 0; i < ifcx->nb_streams; i++) { +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,5,0 )) AVCodecContext * iccx = ifcx->streams[i]->codec; - AVStream *ost = avformat_new_stream(ofcx, iccx->codec); avcodec_copy_context(ost->codec, iccx); +#else + AVCodecParameters * iccx = ifcx->streams[i]->codecpar; + AVStream *ost = avformat_new_stream(ofcx, NULL); + avcodec_parameters_copy(ost->codecpar, iccx); +#endif av_dict_copy(&ost->metadata, ifcx->streams[i]->metadata, 0); - ost->time_base = iccx->time_base; + ost->time_base = ifcx->streams[i]->time_base; ost->id = stid++; if (iccx->codec_type == AVMEDIA_TYPE_VIDEO) { stream_index = i; @@ -2256,10 +2278,19 @@ bool CStreamRec::Open(CZapitChannel * channel) av_log_set_level(AV_LOG_VERBOSE); av_dump_format(ofcx, 0, ofcx->filename, 1); av_log_set_level(AV_LOG_WARNING); +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,52,100 )) bsfc = av_bitstream_filter_init("h264_mp4toannexb"); if (!bsfc) printf("%s: av_bitstream_filter_init h264_mp4toannexb failed!\n", __FUNCTION__); - +#else + const AVBitStreamFilter *bsf = av_bsf_get_by_name("h264_mp4toannexb"); + if(!bsf) { + return false; + } + if ((av_bsf_alloc(bsf, &bsfc))) { + return false; + } +#endif return true; } @@ -2283,16 +2314,34 @@ void CStreamRec::run() break; if (pkt.stream_index < 0) continue; - +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,5,0 )) AVCodecContext *codec = ifcx->streams[pkt.stream_index]->codec; +#else + AVCodecParameters *codec = ifcx->streams[pkt.stream_index]->codecpar; +#endif if (bsfc && codec->codec_id == AV_CODEC_ID_H264) { AVPacket newpkt = pkt; - +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,52,100 )) if (av_bitstream_filter_filter(bsfc, codec, NULL, &newpkt.data, &newpkt.size, pkt.data, pkt.size, pkt.flags & AV_PKT_FLAG_KEY) >= 0) { av_packet_unref(&pkt); newpkt.buf = av_buffer_create(newpkt.data, newpkt.size, av_buffer_default_free, NULL, 0); pkt = newpkt; } +#else + int ret = av_bsf_send_packet(bsfc, &pkt); + if (ret < 0){ + break; + } + ret = av_bsf_receive_packet(bsfc, &newpkt); + if (ret == AVERROR(EAGAIN)){ + break; + } + if(ret != AVERROR_EOF){ + av_packet_unref(&pkt); + newpkt.buf = av_buffer_create(newpkt.data, newpkt.size, av_buffer_default_free, NULL, 0); + pkt = newpkt; + } +#endif } pkt.pts = av_rescale_q(pkt.pts, ifcx->streams[pkt.stream_index]->time_base, ofcx->streams[pkt.stream_index]->time_base); pkt.dts = av_rescale_q(pkt.dts, ifcx->streams[pkt.stream_index]->time_base, ofcx->streams[pkt.stream_index]->time_base); diff --git a/src/driver/streamts.cpp b/src/driver/streamts.cpp index 691714d25..0a21afaf3 100644 --- a/src/driver/streamts.cpp +++ b/src/driver/streamts.cpp @@ -59,6 +59,10 @@ #include #include +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57, 8, 0 )) +#define av_packet_unref av_free_packet +#endif + /* experimental mode: * stream not possible, if record running * pids in url ignored, and added from channel, with fake PAT/PMT @@ -753,8 +757,13 @@ void CStreamStream::Close() if (avio_ctx) av_free(avio_ctx); - if (bsfc) + if (bsfc){ +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,52,100 )) av_bitstream_filter_close(bsfc); +#else + av_bsf_free(&bsfc); +#endif + } ifcx = NULL; ofcx = NULL; @@ -837,21 +846,35 @@ bool CStreamStream::Open() av_dict_copy(&ofcx->metadata, ifcx->metadata, 0); int stid = 0x200; for (unsigned i = 0; i < ifcx->nb_streams; i++) { +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,5,0 )) AVCodecContext * iccx = ifcx->streams[i]->codec; - AVStream *ost = avformat_new_stream(ofcx, iccx->codec); avcodec_copy_context(ost->codec, iccx); +#else + AVCodecParameters * iccx = ifcx->streams[i]->codecpar; + AVStream *ost = avformat_new_stream(ofcx, NULL); + avcodec_parameters_copy(ost->codecpar, iccx); +#endif av_dict_copy(&ost->metadata, ifcx->streams[i]->metadata, 0); - ost->time_base = iccx->time_base; + ost->time_base = ifcx->streams[i]->time_base; ost->id = stid++; } av_log_set_level(AV_LOG_VERBOSE); av_dump_format(ofcx, 0, ofcx->filename, 1); av_log_set_level(AV_LOG_WARNING); +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,52,100 )) bsfc = av_bitstream_filter_init("h264_mp4toannexb"); if (!bsfc) printf("%s: av_bitstream_filter_init h264_mp4toannexb failed!\n", __FUNCTION__); - +#else + const AVBitStreamFilter *bsf = av_bsf_get_by_name("h264_mp4toannexb"); + if(!bsf) { + return false; + } + if ((av_bsf_alloc(bsf, &bsfc))) { + return false; + } +#endif return true; } @@ -896,15 +919,34 @@ void CStreamStream::run() if (pkt.stream_index < 0) continue; +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,5,0 )) AVCodecContext *codec = ifcx->streams[pkt.stream_index]->codec; +#else + AVCodecParameters *codec = ifcx->streams[pkt.stream_index]->codecpar; +#endif if (bsfc && codec->codec_id == AV_CODEC_ID_H264 ) { AVPacket newpkt = pkt; - +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,52,100 )) if (av_bitstream_filter_filter(bsfc, codec, NULL, &newpkt.data, &newpkt.size, pkt.data, pkt.size, pkt.flags & AV_PKT_FLAG_KEY) >= 0) { av_packet_unref(&pkt); newpkt.buf = av_buffer_create(newpkt.data, newpkt.size, av_buffer_default_free, NULL, 0); pkt = newpkt; - } + } +#else + int ret = av_bsf_send_packet(bsfc, &pkt); + if (ret < 0){ + break; + } + ret = av_bsf_receive_packet(bsfc, &newpkt); + if (ret == AVERROR(EAGAIN)){ + break; + } + if(ret != AVERROR_EOF){ + av_packet_unref(&pkt); + newpkt.buf = av_buffer_create(newpkt.data, newpkt.size, av_buffer_default_free, NULL, 0); + pkt = newpkt; + } +#endif } pkt.pts = av_rescale_q(pkt.pts, ifcx->streams[pkt.stream_index]->time_base, ofcx->streams[pkt.stream_index]->time_base); pkt.dts = av_rescale_q(pkt.dts, ifcx->streams[pkt.stream_index]->time_base, ofcx->streams[pkt.stream_index]->time_base); diff --git a/src/driver/streamts.h b/src/driver/streamts.h index da2708e51..7ec1bd321 100644 --- a/src/driver/streamts.h +++ b/src/driver/streamts.h @@ -73,7 +73,11 @@ class CStreamStream : public CStreamInstance private: AVFormatContext *ifcx; AVFormatContext *ofcx; +#if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT( 57,52,100 )) AVBitStreamFilterContext *bsfc; +#else + AVBSFContext *bsfc; +#endif AVIOContext *avio_ctx; bool stopped; diff --git a/src/eitd/sectionsd.cpp b/src/eitd/sectionsd.cpp index e872c903c..11e4f0714 100644 --- a/src/eitd/sectionsd.cpp +++ b/src/eitd/sectionsd.cpp @@ -55,6 +55,8 @@ #include "xmlutil.h" #include "debug.h" +#include + //#define ENABLE_SDT //FIXME //#define DEBUG_SDT_THREAD @@ -1067,11 +1069,7 @@ static void commandDumpStatusInformation(int /*connfd*/, char* /*data*/, const u // resourceUsage.ru_maxrss, resourceUsage.ru_ixrss, resourceUsage.ru_idrss, resourceUsage.ru_isrss, ); printf("%s\n", stati); -#ifdef __UCLIBC__ - malloc_stats(NULL); -#else - malloc_stats(); -#endif + comp_malloc_stats(NULL); return ; } @@ -1200,11 +1198,7 @@ static void FreeMemory() unlockEvents(); -#ifdef __UCLIBC__ - malloc_stats(NULL); -#else - malloc_stats(); -#endif + comp_malloc_stats(NULL); xprintf("[sectionsd] free memory done\n"); //wakeupAll(); //FIXME should we re-start eit here ? } @@ -2056,11 +2050,7 @@ static void print_meminfo(void) if (!sections_debug) return; -#ifdef __UCLIBC__ - malloc_stats(NULL); -#else - malloc_stats(); -#endif + comp_malloc_stats(NULL); } //--------------------------------------------------------------------- diff --git a/src/gui/movieplayer.cpp b/src/gui/movieplayer.cpp index 15ea540e1..3692a873e 100644 --- a/src/gui/movieplayer.cpp +++ b/src/gui/movieplayer.cpp @@ -2504,8 +2504,11 @@ void CMoviePlayerGui::showSubtitle(neutrino_msg_data_t data) clearSubtitle(); for (unsigned i = 0; i < sub->num_rects; i++) { +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 5, 0) uint32_t * colors = (uint32_t *) sub->rects[i]->pict.data[1]; - +#else + uint32_t * colors = (uint32_t *) sub->rects[i]->data[1]; +#endif int xoff = (double) sub->rects[i]->x * xc; int yoff = (double) sub->rects[i]->y * yc; int nw = frameBuffer->getWidth4FB_HW_ACC(xoff, (double) sub->rects[i]->w * xc); @@ -2514,9 +2517,14 @@ void CMoviePlayerGui::showSubtitle(neutrino_msg_data_t data) printf("Draw: #%d at %d,%d size %dx%d colors %d (x=%d y=%d w=%d h=%d) \n", i+1, sub->rects[i]->x, sub->rects[i]->y, sub->rects[i]->w, sub->rects[i]->h, sub->rects[i]->nb_colors, xoff, yoff, nw, nh); - +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 5, 0) fb_pixel_t * newdata = simple_resize32 (sub->rects[i]->pict.data[0], colors, sub->rects[i]->nb_colors, sub->rects[i]->w, sub->rects[i]->h, nw, nh); +#else + fb_pixel_t * newdata = simple_resize32 (sub->rects[i]->data[0], colors, + sub->rects[i]->nb_colors, sub->rects[i]->w, sub->rects[i]->h, nw, nh); +#endif + frameBuffer->blit2FB(newdata, nw, nh, xoff, yoff); free(newdata); diff --git a/src/neutrino.cpp b/src/neutrino.cpp index d2c06bd75..b946e06aa 100644 --- a/src/neutrino.cpp +++ b/src/neutrino.cpp @@ -140,6 +140,8 @@ #include #include +#include + #include #include #include @@ -5096,11 +5098,8 @@ void CNeutrinoApp::Cleanup() delete CEitManager::getInstance(); printf("cleanup 6\n");fflush(stdout); delete CVFD::getInstance(); -#ifdef __UCLIBC__ - malloc_stats(NULL); -#else - malloc_stats(); -#endif + + comp_malloc_stats(NULL); #endif }