diff options
author | Jochen Dolze <vdr@dolze.de> | 2010-09-26 00:30:30 +0200 |
---|---|---|
committer | Jochen Dolze <vdr@dolze.de> | 2010-09-26 00:30:30 +0200 |
commit | 101d294a50e16da992e10363c51b435e6a2fa226 (patch) | |
tree | e94bc2bbbf4c3eff48a3532b0ed15176b66dc24a | |
parent | 05dff1022a467deec38f93b0987db9aeb2b43420 (diff) | |
download | vdr-plugin-markad-101d294a50e16da992e10363c51b435e6a2fa226.tar.gz vdr-plugin-markad-101d294a50e16da992e10363c51b435e6a2fa226.tar.bz2 |
Added better thread handling in decoder.cpp, added --threads option
-rw-r--r-- | command/decoder.cpp | 29 | ||||
-rw-r--r-- | command/decoder.h | 4 | ||||
-rw-r--r-- | command/markad-standalone.cpp | 20 | ||||
-rw-r--r-- | command/markad-standalone.h | 2 |
4 files changed, 41 insertions, 14 deletions
diff --git a/command/decoder.cpp b/command/decoder.cpp index 92ea1a0..e14a65f 100644 --- a/command/decoder.cpp +++ b/command/decoder.cpp @@ -95,7 +95,7 @@ fail: } #endif -cMarkAdDecoder::cMarkAdDecoder(bool useH264, bool useMP2, bool hasAC3) +cMarkAdDecoder::cMarkAdDecoder(bool useH264, bool useMP2, bool hasAC3, int Threads) { avcodec_init(); avcodec_register_all(); @@ -115,10 +115,19 @@ cMarkAdDecoder::cMarkAdDecoder(bool useH264, bool useMP2, bool hasAC3) cpucount=CPU_COUNT(&cpumask); } + if (Threads==-1) + { + threadcount=cpucount; + } + else + { + threadcount=Threads; + } + int ver = avcodec_version(); char libver[256]; snprintf(libver,sizeof(libver),"%i.%i.%i",ver >> 16 & 0xFF,ver >> 8 & 0xFF,ver & 0xFF); - isyslog("using libavcodec.so.%s with %i threads",libver,cpucount); + isyslog("using libavcodec.so.%s with %i threads",libver,threadcount); if (ver!=LIBAVCODEC_VERSION_INT) { @@ -149,7 +158,6 @@ cMarkAdDecoder::cMarkAdDecoder(bool useH264, bool useMP2, bool hasAC3) mp2_context = avcodec_alloc_context(); if (mp2_context) { - mp2_context->thread_count=cpucount; mp2_context->codec_id = mp2_codecid; mp2_context->codec_type = CODEC_TYPE_AUDIO; if (avcodec_open(mp2_context, mp2_codec) < 0) @@ -158,6 +166,7 @@ cMarkAdDecoder::cMarkAdDecoder(bool useH264, bool useMP2, bool hasAC3) av_free(mp2_context); mp2_context=NULL; } + avcodec_thread_init(mp2_context,threadcount); } else { @@ -184,7 +193,6 @@ cMarkAdDecoder::cMarkAdDecoder(bool useH264, bool useMP2, bool hasAC3) ac3_context = avcodec_alloc_context(); if (ac3_context) { - ac3_context->thread_count=cpucount; ac3_context->codec_id = ac3_codecid; ac3_context->codec_type = CODEC_TYPE_AUDIO; if (avcodec_open(ac3_context, ac3_codec) < 0) @@ -193,6 +201,7 @@ cMarkAdDecoder::cMarkAdDecoder(bool useH264, bool useMP2, bool hasAC3) av_free(ac3_context); ac3_context=NULL; } + avcodec_thread_init(ac3_context,threadcount); } else { @@ -235,12 +244,10 @@ cMarkAdDecoder::cMarkAdDecoder(bool useH264, bool useMP2, bool hasAC3) video_context = avcodec_alloc_context(); if (video_context) { - video_context->thread_count=cpucount; if (video_codec->capabilities & CODEC_CAP_TRUNCATED) video_context->flags|=CODEC_FLAG_TRUNCATED; // we do not send complete frames video_context->flags2|=CODEC_FLAG2_FAST; // really? - video_context->skip_idct=AVDISCARD_ALL; av_log_set_level(AV_LOG_FATAL); // silence decoder output @@ -317,6 +324,10 @@ cMarkAdDecoder::cMarkAdDecoder(bool useH264, bool useMP2, bool hasAC3) av_free(video_context); video_context=NULL; } + else + { + avcodec_thread_init(video_context,threadcount); + } } } else @@ -352,7 +363,6 @@ cMarkAdDecoder::cMarkAdDecoder(bool useH264, bool useMP2, bool hasAC3) { audiobuf=NULL; } - initial_coded_picture=-1; } cMarkAdDecoder::~cMarkAdDecoder() @@ -360,6 +370,7 @@ cMarkAdDecoder::~cMarkAdDecoder() Clear(); if (video_context) { + if (video_context->thread_opaque) avcodec_thread_free(video_context); avcodec_close(video_context); av_free(video_context); av_free(video_frame); @@ -367,12 +378,14 @@ cMarkAdDecoder::~cMarkAdDecoder() if (ac3_context) { + if (ac3_context->thread_opaque) avcodec_thread_free(ac3_context); avcodec_close(ac3_context); av_free(ac3_context); } if (mp2_context) { + if (mp2_context->thread_opaque) avcodec_thread_free(mp2_context); avcodec_close(mp2_context); av_free(mp2_context); } @@ -384,6 +397,7 @@ bool cMarkAdDecoder::Clear() bool ret=true; if (video_context) { + if (video_context->thread_opaque) avcodec_thread_free(video_context); avcodec_flush_buffers(video_context); AVCodecContext *dest; dest=avcodec_alloc_context(); @@ -402,6 +416,7 @@ bool cMarkAdDecoder::Clear() video_context=dest; if (avcodec_open(video_context,video_codec)<0) ret=false; } + avcodec_thread_init(video_context,threadcount); } if (ac3_context) avcodec_flush_buffers(ac3_context); if (mp2_context) avcodec_flush_buffers(mp2_context); diff --git a/command/decoder.h b/command/decoder.h index 4a59883..ff03f6f 100644 --- a/command/decoder.h +++ b/command/decoder.h @@ -49,8 +49,8 @@ private: AVCodecContext *video_context; AVFrame *video_frame; + int threadcount; int8_t *last_qscale_table; - int initial_coded_picture; static int our_get_buffer(struct AVCodecContext *c, AVFrame *pic); static void our_release_buffer(struct AVCodecContext *c, AVFrame *pic); @@ -63,7 +63,7 @@ public: bool DecodeMP2(MarkAdContext *maContext, uchar *espkt, int eslen); bool DecodeAC3(MarkAdContext *maContext, uchar *espkt, int eslen); bool Clear(); - cMarkAdDecoder(bool useH264, bool useMP2, bool hasAC3); + cMarkAdDecoder(bool useH264, bool useMP2, bool hasAC3, int Threads); ~cMarkAdDecoder(); }; diff --git a/command/markad-standalone.cpp b/command/markad-standalone.cpp index e9701ff..d522da9 100644 --- a/command/markad-standalone.cpp +++ b/command/markad-standalone.cpp @@ -1952,7 +1952,7 @@ cMarkAdStandalone::cMarkAdStandalone(const char *Directory, bool BackupMarks, in bool DecodeAudio, int IgnoreInfo, const char *LogoDir, const char *MarkFileName, bool noPid, bool OSD, const char *SVDRPHost, int SVDRPPort, - bool Before, bool GenIndex) + bool Before, bool GenIndex, int Threads) { setlocale(LC_MESSAGES, ""); directory=Directory; @@ -2180,7 +2180,7 @@ cMarkAdStandalone::cMarkAdStandalone(const char *Directory, bool BackupMarks, in if (!abort) { decoder = new cMarkAdDecoder(macontext.Info.VPid.Type==MARKAD_PIDTYPE_VIDEO_H264, - macontext.Info.APid.Num!=0,macontext.Info.DPid.Num!=0); + macontext.Info.APid.Num!=0,macontext.Info.DPid.Num!=0,Threads); video = new cMarkAdVideo(&macontext); audio = new cMarkAdAudio(&macontext); streaminfo = new cMarkAdStreamInfo; @@ -2298,6 +2298,9 @@ int usage(int svdrpport) " [height] range from 20 to %3i, default %3i\n" "-O --OSD\n" " markad sends an OSD-Message for start and end\n" + "-T --threads=<number>\n" + " number of threads used for decoding, max. 16\n" + " (default is the number of cpus)\n" "-V --version\n" " print version-info and exit\n" " --markfile=<markfilename>\n" @@ -2393,6 +2396,7 @@ int main(int argc, char *argv[]) bool bGenIndex=false; bool bPass2Only=false; int online=0; + int threads=-1; strcpy(logoDirectory,"/var/lib/markad"); @@ -2445,12 +2449,13 @@ int main(int argc, char *argv[]) {"extractlogo", 1, 0, 'L'}, {"OSD",0,0,'O' }, {"savelogo", 0, 0, 'S'}, + {"threads", 1, 0, 'T'}, {"version", 0, 0, 'V'}, {0, 0, 0, 0} }; - c = getopt_long (argc, argv, "abcd:i:jl:nop:s:vBCGL:OSV", + c = getopt_long (argc, argv, "abcd:i:jl:nop:s:vBCGL:OST:V", long_options, &option_index); if (c == -1) break; @@ -2606,6 +2611,13 @@ int main(int argc, char *argv[]) // --savelogo break; + case 'T': + // --threads + threads=atoi(optarg); + if (threads<1) threads=1; + if (threads>16) threads=16; + break; + case 'V': printf("markad %s - marks advertisements in VDR recordings\n",VERSION); return 0; @@ -2850,7 +2862,7 @@ int main(int argc, char *argv[]) cmasta = new cMarkAdStandalone(recDir,bBackupMarks, logoExtraction, logoWidth, logoHeight, bDecodeVideo,bDecodeAudio,ignoreInfo, logoDirectory,markFileName,bNoPid,bOSD,svdrphost, - svdrpport,bBefore,bGenIndex); + svdrpport,bBefore,bGenIndex,threads); if (!cmasta) return -1; if (!bPass2Only) cmasta->Process(); diff --git a/command/markad-standalone.h b/command/markad-standalone.h index c6d2ff9..0ef14ef 100644 --- a/command/markad-standalone.h +++ b/command/markad-standalone.h @@ -262,7 +262,7 @@ public: bool DecodeAudio, int IgnoreInfo, const char *LogoDir, const char *MarkFileName, bool noPid, bool OSD, const char *SVDRPHost, int SVDRPPort, - bool Before, bool GenIndex); + bool Before, bool GenIndex, int Threads); ~cMarkAdStandalone(); }; |