From 4abf2e5c12c158eea3461e6dc1ce5a5bfe58f48c Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sat, 20 Oct 2012 12:38:10 +0200 Subject: [PATCH] Preparations for AC3 passthrough and parser for deinterlacing --- audioomx.cc | 59 +++++++++++++++++++---------------- demuxer.cc | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++--- demuxer.h | 3 ++ videoomx.cc | 3 +- 4 files changed, 122 insertions(+), 33 deletions(-) diff --git a/audioomx.cc b/audioomx.cc index 0824869..256051b 100644 --- a/audioomx.cc +++ b/audioomx.cc @@ -582,23 +582,8 @@ int AudioOMX::ChangeAudioPortConfig(bool disport) //clock aka omx mutex needs to return 0; } - if (passthrough) { - // TODO coding - } else { - //VideoOMX* video=(VideoOMX*)Video::getInstance(); - - /*if (disport) { - if (!video->ChangeComponentState(omx_aud_rend, OMX_StateIdle)) { - Log::getInstance()->log("Audio", Log::DEBUG, - "omx_aud_rend ChangeComponentState Execute CAP"); - return 0; - } - video->DisablePort(omx_aud_rend,omx_rend_input_port,false); - DestroyInputBufsOMX(); - }*/ - - - + switch (encoding) { + case OMX_AUDIO_CodingPCM: { OMX_AUDIO_PARAM_PCMMODETYPE audio_pcm; memset(&audio_pcm, 0, sizeof(audio_pcm)); audio_pcm.nSize = sizeof(audio_pcm); @@ -623,18 +608,38 @@ int AudioOMX::ChangeAudioPortConfig(bool disport) //clock aka omx mutex needs to omx_rend_input_port); return 0; } - /*if (disport) { - video->EnablePort(omx_aud_rend,omx_rend_input_port,false); - PrepareInputBufsOMX(); - if (!video->ChangeComponentState(omx_aud_rend, OMX_StateExecuting)) { - Log::getInstance()->log("Audio", Log::DEBUG, - "omx_aud_rend ChangeComponentState Execute CAP"); - return 0; - } + } break; + case OMX_AUDIO_CodingDDP: { + OMX_AUDIO_PARAM_DDPTYPE audio_ddp; + memset(&audio_ddp, 0, sizeof(audio_ddp)); + audio_ddp.nSize = sizeof(audio_ddp); + audio_ddp.nVersion.nVersion = OMX_VERSION; + audio_ddp.nPortIndex = omx_rend_input_port; + audio_ddp.nChannels = 8; //unknown + audio_ddp.nBitRate=0; + audio_ddp.nSampleRate=48000; + audio_ddp.eChannelMapping[0] =OMX_AUDIO_ChannelLF; + audio_ddp.eChannelMapping[1] =OMX_AUDIO_ChannelRF; + audio_ddp.eChannelMapping[2] =OMX_AUDIO_ChannelCF; + audio_ddp.eChannelMapping[3] =OMX_AUDIO_ChannelLFE; + audio_ddp.eChannelMapping[4] =OMX_AUDIO_ChannelLR; + audio_ddp.eChannelMapping[5] =OMX_AUDIO_ChannelRR; + audio_ddp.eChannelMapping[6] =OMX_AUDIO_ChannelLS; + audio_ddp.eChannelMapping[7] =OMX_AUDIO_ChannelRS; + audio_ddp.eChannelMapping[8] =OMX_AUDIO_ChannelCS; + error = OMX_SetParameter(omx_aud_rend, OMX_IndexParamAudioDdp, + &audio_ddp); + if (error != OMX_ErrorNone) { + Log::getInstance()->log("Audio", Log::DEBUG, + "Init OMX_IndexParamAudioDdp failed %x %d", error, + omx_rend_input_port); + return 0; + } + + } break; + }; - }*/ - } } diff --git a/demuxer.cc b/demuxer.cc index 305c1a1..6aef0d1 100644 --- a/demuxer.cc +++ b/demuxer.cc @@ -31,9 +31,11 @@ #define DEMUXER_SEQ_HEAD 0x000001B3 #define DEMUXER_PIC_HEAD 0x00000101 +#define DEMUXER_SEQ_EXT_HEAD 0x000001B5 #define DEMUXER_H264_ACCESS_UNIT 0x00000109 #define DEMUXER_H264_SEQ_PARAMETER_SET 0x00000107 +#define DEMUXER_H264_SUB_ENHANCEMENT_INF 0x00000106 #define SEEK_THRESHOLD 150000 // About 1.5 seconds @@ -372,6 +374,43 @@ UINT PESPacket::findSeqHeader(bool h264) const return seq_header; } +UINT PESPacket::findSeqExtHeader(bool h264) const +{ + if (seq_header != 1) return seq_header; + if (size < 12) return 0; + UINT pattern = ( ((UINT)data[ 8] << 24) | + ((UINT)data[ 9] << 16) | + ((UINT)data[10] << 8) | + (UINT)data[11] ); + UINT pos = 11; + if (h264) { + while ((pattern & 0xFFFFFF1F) != DEMUXER_H264_SUB_ENHANCEMENT_INF) + { + if (++pos >= size) + { + seq_header = 0; + return 0; + } + pattern = (pattern << 8) | data[pos]; + } + seq_header = pos - 3; + } + else + { + while (pattern != DEMUXER_SEQ_EXT_HEAD && (data[pos+1]&0xf0)!=0x10) + { + if (++pos >= (size-1)) + { + seq_header = 0; + return 0; + } + pattern = (pattern << 8) | data[pos]; + } + seq_header = pos - 3; + } + return seq_header; +} + // Demuxer methods Demuxer::Demuxer() { @@ -433,6 +472,7 @@ void Demuxer::reset() flush(); video_current = audio_current = teletext_current = subtitle_current = -1; horizontal_size = vertical_size = 0; + interlaced=true; // default is true aspect_ratio = (enum AspectRatio) 0; frame_rate = bit_rate = 0; ispre_1_3_19 = false; @@ -824,17 +864,18 @@ pre_1_3_19_Recording: //This is for old recordings stuff and live TV horizontal_size=(nalu.getUe()+1)*16; vertical_size=(nalu.getUe()+1)*16; - int interlaced=nalu.getBits(1); - vertical_size*=(2-interlaced); + int tinterlaced=nalu.getBits(1); + vertical_size*=(2-tinterlaced); + interlaced=!tinterlaced; - if (!interlaced) nalu.getBits(1); + if (!tinterlaced) nalu.getBits(1); nalu.getBits(1); if (nalu.getBits(1)) { horizontal_size-=nalu.getUe()*chromunitx; horizontal_size-=nalu.getUe()*chromunitx; - vertical_size-=nalu.getUe()*(2-interlaced)*chromunity; - vertical_size-=nalu.getUe()*(2-interlaced)*chromunity; + vertical_size-=nalu.getUe()*(2-tinterlaced)*chromunity; + vertical_size-=nalu.getUe()*(2-tinterlaced)*chromunity; } if (nalu.getBits(1)) { @@ -872,6 +913,45 @@ pre_1_3_19_Recording: //This is for old recordings stuff and live TV } } + UINT posext = packet.findSeqExtHeader(h264); + if (posext>1) { + if (!h264) { + interlaced=!(packet[pos+1] & 0x08); //really simple + // if more than full hd is coming we need to add additional parsers here + } else { + /* NALUUnit nalu(packet.getData()+posext,packet.getSize()-posext); + while (!nalu.isEonalu()) { + unsigned int payloadtype=0; + unsigned int payloadadd=0xFF; + while (payloadadd==0xFF && !nalu.isEonalu()) { + payloadadd=nalu.getBits(8); + payloadtype+=payloadadd; + } + unsigned int payloadsize=0; + payloadadd=0xff; + while (payloadadd==0xFF && !nalu.isEonalu()) { + payloadadd=nalu.getBits(8); + payloadsize+=payloadadd; + } + switch (payloadtype) { + case 1: { // picture timing SEI + + } break; + default: { + while (payloadsize) { // not handled skip + nalu.getBits(8); + payloadsize--; + } + } break; + } + + + + }*/ + + + } + } if (vid_seeking) { diff --git a/demuxer.h b/demuxer.h index 1db2749..b1474ee 100644 --- a/demuxer.h +++ b/demuxer.h @@ -62,6 +62,7 @@ class PESPacket UINT findPictureHeader(bool h264) const; UINT findSeqHeader(bool h264) const; + UINT findSeqExtHeader(bool h264) const; UINT countPictureHeaders(bool h264) const; static const ULLONG PTS_INVALID = (1LL << 33); @@ -122,6 +123,7 @@ class Demuxer int getAspectRatio() { return aspect_ratio; } int getFrameRate() { return frame_rate; } int getBitRate() { return bit_rate; } + bool getInterlaced() { return interlaced;} ULLONG getVideoPTS() { return video_pts; } ULLONG getAudioPTS() { return audio_pts; } @@ -209,6 +211,7 @@ class Demuxer int horizontal_size; int vertical_size; + bool interlaced; int profile; enum AspectRatio aspect_ratio; int arcnt; diff --git a/videoomx.cc b/videoomx.cc index a250f10..05966c0 100644 --- a/videoomx.cc +++ b/videoomx.cc @@ -829,7 +829,8 @@ int VideoOMX::AllocateCodecsOMX() Log::getInstance()->log("Video", Log::NOTICE, "Allocate Codecs OMX"); //Clock, move later to audio including events - if (deinterlace!=0 && (demux->getHorizontalSize()<=720 /*|| demux->getHorizontalSize()==1920*/)) { //only deinterlace SD material + Log::getInstance()->log("Video", Log::NOTICE, "VideoType %d x %d i: %d", demux->getHorizontalSize(),demux->getVerticalSize(),demux->getInterlaced()); + if (deinterlace!=0 && (demux->getHorizontalSize()<=720 ) && demux->getInterlaced()) { //only deinterlace SD material dodeint=true; deint_first_frame=true; -- 2.39.5