From c005f02625b58fa003832bdc5fffbe0cc0db6e4d Mon Sep 17 00:00:00 2001 From: Jochen Dolze Date: Thu, 11 Mar 2010 17:02:12 +0100 Subject: Decoder can now be disabled with commandline switch --- decoder.cpp | 49 +++++++++++++++++++--------- decoder.h | 2 +- global.h | 3 ++ markad-standalone.cpp | 76 +++++++++++++++++++++++++++++++++++++------ markad-standalone.h | 1 + queue.cpp | 2 +- streaminfo.cpp | 90 ++++----------------------------------------------- video.cpp | 13 +++++--- 8 files changed, 122 insertions(+), 114 deletions(-) diff --git a/decoder.cpp b/decoder.cpp index ea0672e..a9fb7b4 100644 --- a/decoder.cpp +++ b/decoder.cpp @@ -126,8 +126,6 @@ cMarkAdDecoder::cMarkAdDecoder(int RecvNumber, bool useH264, bool useMP2, bool h if (video_codec->capabilities & CODEC_CAP_TRUNCATED) video_context->flags|=CODEC_FLAG_TRUNCATED; // we do not send complete frames - video_context->flags|=CODEC_FLAG_EMU_EDGE; // now linesize should be the same as width - video_context->flags|=CODEC_FLAG_GRAY; // only decode grayscale video_context->flags2|=CODEC_FLAG2_FAST; // really? @@ -137,11 +135,11 @@ cMarkAdDecoder::cMarkAdDecoder(int RecvNumber, bool useH264, bool useMP2, bool h { video_context->flags2|=CODEC_FLAG2_CHUNKS; // needed for H264! video_context->skip_loop_filter=AVDISCARD_ALL; // skip deblocking - video_context->skip_frame=AVDISCARD_NONREF; // P/I-frames + av_log_set_level(AV_LOG_FATAL); // H264 decoder is very chatty } else { - video_context->skip_frame=AVDISCARD_NONKEY; // I-frames + video_context->skip_frame=AVDISCARD_NONKEY; // just I-frames } int ret=avcodec_open(video_context, video_codec); @@ -171,6 +169,14 @@ cMarkAdDecoder::cMarkAdDecoder(int RecvNumber, bool useH264, bool useMP2, bool h } else { + + dsyslog("markad [%i]: using codec %s",recvnumber,video_codec->long_name); + + if (video_context->hwaccel) + { + dsyslog("markad [%i]: using hwaccel %s",recvnumber,video_context->hwaccel->name); + } + video_frame = avcodec_alloc_frame(); if (!video_frame) { @@ -224,7 +230,6 @@ cMarkAdDecoder::~cMarkAdDecoder() av_free(mp2_context); } if (audiobuf) free(audiobuf); - SetVideoInfos(NULL,NULL,NULL,NULL); } bool cMarkAdDecoder::DecodeMP2(MarkAdContext *maContext, uchar *espkt, int eslen) @@ -260,7 +265,7 @@ bool cMarkAdDecoder::DecodeMP2(MarkAdContext *maContext, uchar *espkt, int eslen if (audiobufsize>0) { memcpy(audiobuf,Taudiobuf,audiobufsize); - SetAudioInfos(maContext,ac3_context); + SetAudioInfos(maContext,mp2_context); ret=true; avpkt.size-=len; avpkt.data+=len; @@ -273,6 +278,7 @@ bool cMarkAdDecoder::SetAudioInfos(MarkAdContext *maContext, AVCodecContext *Aud { if ((!maContext) || (!Audio_Context)) return false; + maContext->Audio.Info.SampleRate = Audio_Context->sample_rate; maContext->Audio.Info.Channels = Audio_Context->channels; maContext->Audio.Data.SampleBuf=audiobuf; maContext->Audio.Data.SampleBufLen=audiobufsize; @@ -328,7 +334,7 @@ void cMarkAdDecoder::PAR2DAR(AVRational a, AVRational *erg) video_context->height*a.den,1024*1024); } -bool cMarkAdDecoder::SetVideoInfos(MarkAdContext *maContext,AVCodecContext *Video_Context, AVFrame *Video_Frame, AVRational *DAR) +bool cMarkAdDecoder::SetVideoInfos(MarkAdContext *maContext,AVCodecContext *Video_Context, AVFrame *Video_Frame) { if ((!maContext) || (!Video_Context) || (!Video_Frame)) return false; maContext->Video.Data.Valid=false; @@ -347,11 +353,11 @@ bool cMarkAdDecoder::SetVideoInfos(MarkAdContext *maContext,AVCodecContext *Vide maContext->Video.Info.Pict_Type=Video_Context->coded_frame->pict_type; } - if (DAR) - { - maContext->Video.Info.AspectRatio.Num=DAR->num; - maContext->Video.Info.AspectRatio.Den=DAR->den; - } + AVRational dar; + PAR2DAR(Video_Context->sample_aspect_ratio,&dar); + + maContext->Video.Info.AspectRatio.Num=dar.num; + maContext->Video.Info.AspectRatio.Den=dar.den; maContext->Video.Data.Valid=true; return true; @@ -361,6 +367,21 @@ bool cMarkAdDecoder::DecodeVideo(MarkAdContext *maContext,uchar *pkt, int plen) { if (!video_context) return false; + if ((video_context->codec_id==CODEC_ID_H264) && (!video_context->skip_frame)) + { + if (maContext->Video.Info.Pict_Type) + { + if (maContext->Video.Info.Interlaced) + { + video_context->skip_frame=AVDISCARD_BIDIR; // just P/I-frames + } + else + { + video_context->skip_frame=AVDISCARD_NONKEY; // just I-frames + } + } + } + AVPacket avpkt; #if LIBAVCODEC_VERSION_INT >= ((52<<16)+(25<<8)+0) av_init_packet(&avpkt); @@ -399,9 +420,7 @@ bool cMarkAdDecoder::DecodeVideo(MarkAdContext *maContext,uchar *pkt, int plen) { if (last_qscale_table!=video_frame->qscale_table) { - AVRational dar; - PAR2DAR(video_context->sample_aspect_ratio,&dar); - if (SetVideoInfos(maContext,video_context,video_frame,&dar)) ret=true; + if (SetVideoInfos(maContext,video_context,video_frame)) ret=true; last_qscale_table=video_frame->qscale_table; } } diff --git a/decoder.h b/decoder.h index c14a48f..7a0d4e2 100644 --- a/decoder.h +++ b/decoder.h @@ -56,7 +56,7 @@ private: void PAR2DAR(AVRational a, AVRational *erg); bool SetVideoInfos(MarkAdContext *maContext,AVCodecContext *Video_Context, - AVFrame *Video_Frame, AVRational *DAR); + AVFrame *Video_Frame); public: bool DecodeVideo(MarkAdContext *maContext, uchar *pkt, int plen); bool DecodeMP2(MarkAdContext *maContext, uchar *espkt, int eslen); diff --git a/global.h b/global.h index 189613c..ec74501 100644 --- a/global.h +++ b/global.h @@ -56,6 +56,7 @@ typedef struct MarkAdContext int LogoExtraction; int LogoWidth; int LogoHeight; + MarkAdAspectRatio AspectRatioHint; } StandAlone; struct General @@ -75,6 +76,7 @@ typedef struct MarkAdContext int Pict_Type; // picture type (I,P,B,S,SI,SP,BI) MarkAdAspectRatio AspectRatio; double FramesPerSecond; + bool Interlaced; } Info; struct Data @@ -90,6 +92,7 @@ typedef struct MarkAdContext struct Info { int Channels; // number of audio channels + int SampleRate; } Info; struct Data { diff --git a/markad-standalone.cpp b/markad-standalone.cpp index 4d41ac5..8222920 100644 --- a/markad-standalone.cpp +++ b/markad-standalone.cpp @@ -15,6 +15,8 @@ char logoDirectory[1024]=""; int logoExtraction=-1; int logoWidth=-1; int logoHeight=-1; +bool bDecodeVideo=true; +bool bDecodeAudio=true; void syslog_with_tid(int priority, const char *format, ...) { @@ -80,10 +82,12 @@ void cMarkAdStandalone::SaveFrame(int frame) return; // Write header - fprintf(pFile, "P5\n%d %d\n255\n", macontext.Video.Info.Width,macontext.Video.Info.Height); + fprintf(pFile, "P5\n%d %d\n255\n", macontext.Video.Data.PlaneLinesize[0], + macontext.Video.Info.Height); // Write pixel data - fwrite(macontext.Video.Data.Plane[0],1,macontext.Video.Info.Width*macontext.Video.Info.Height,pFile); + fwrite(macontext.Video.Data.Plane[0],1, + macontext.Video.Data.PlaneLinesize[0]*macontext.Video.Info.Height,pFile); // Close file fclose(pFile); } @@ -118,7 +122,7 @@ bool cMarkAdStandalone::ProcessFile(const char *Directory, int Number) if (abort) break; MarkAdMark *mark=NULL; - if ((video_demux) && (video) && (decoder) && (streaminfo)) + if ((video_demux) && (video) && (streaminfo)) { uchar *pkt; int pktlen; @@ -143,11 +147,13 @@ bool cMarkAdStandalone::ProcessFile(const char *Directory, int Number) framecnt++; } - if (decoder->DecodeVideo(&macontext,pkt,pktlen)) + bool dRes=true; + if ((decoder) && (bDecodeVideo)) dRes=decoder->DecodeVideo(&macontext,pkt,pktlen); + if (dRes) { if (macontext.Video.Info.Pict_Type==MA_I_TYPE) { - if (macontext.General.VPid.Type==MARKAD_PIDTYPE_VIDEO_H264) + if ((macontext.General.VPid.Type==MARKAD_PIDTYPE_VIDEO_H264) || (!bDecodeVideo)) { lastiframe=framecnt-1; } @@ -155,7 +161,7 @@ bool cMarkAdStandalone::ProcessFile(const char *Directory, int Number) { lastiframe=framecnt-2; } - // SaveFrame(lastiframe); // TODO: JUST FOR DEBUGGING! + //SaveFrame(lastiframe); // TODO: JUST FOR DEBUGGING! mark=video->Process(lastiframe); AddMark(mark); } @@ -208,7 +214,7 @@ bool cMarkAdStandalone::ProcessFile(const char *Directory, int Number) } } - if ((mp2_demux) && (decoder) && (audio)) + if ((mp2_demux) && (decoder) && (audio) && (bDecodeAudio)) { uchar *pkt; int pktlen; @@ -252,6 +258,12 @@ bool cMarkAdStandalone::ProcessFile(const char *Directory, int Number) void cMarkAdStandalone::Process(const char *Directory) { if (abort) return; + + struct timeval tv1,tv2; + struct timezone tz; + + gettimeofday(&tv1,&tz); + for (int i=1; i<=MaxFiles; i++) { if (abort) break; @@ -264,6 +276,25 @@ void cMarkAdStandalone::Process(const char *Directory) { isyslog("markad [%i]: aborted",recvnumber); } + else + { + gettimeofday(&tv2,&tz); + long sec,usec; + sec=tv2.tv_sec-tv1.tv_sec; + usec=tv2.tv_usec-tv1.tv_usec; + if (usec<0) + { + usec+=1000000; + sec--; + } + double etime,ftime=0,ptime=0; + etime=sec+((double) usec/1000000); + if (etime>0) ftime=framecnt/etime; + if (macontext.Video.Info.FramesPerSecond>0) + ptime=ftime/macontext.Video.Info.FramesPerSecond; + isyslog("markad [%i]: elapsed time %.2fs, %i frames, %.1f fps, %.1f pps",recvnumber, + etime,framecnt,ftime,ptime); + } } bool cMarkAdStandalone::LoadInfo(const char *Directory) @@ -485,6 +516,7 @@ cMarkAdStandalone::cMarkAdStandalone(const char *Directory) } else { + macontext.General.APid.Num=-1; macontext.General.DPid.Num=-1; macontext.General.VPid.Num=-1; macontext.General.VPid.Type=MARKAD_PIDTYPE_VIDEO_H262; @@ -588,6 +620,9 @@ int usage() "-b --background\n" " markad runs as a background-process\n" " this will be automatically set if called with \"after\"\n" + "-d --disable=