From efbc9d9043ff8ff92716ddd00a5f61412d535593 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Fri, 9 Apr 2010 14:12:59 +0000 Subject: revert r1783 git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@1785 10f7b99b-c216-0410-bff0-8a66a9350fd8 --- src/filters/parser/DiracSplitter/DiracSplitter.cpp | 127 +- src/filters/parser/DiracSplitter/DiracSplitter.h | 56 +- .../parser/DiracSplitter/DiracSplitterFile.cpp | 38 +- .../parser/DiracSplitter/DiracSplitterFile.h | 26 +- .../libdirac/libdirac_byteio/accessunit_byteio.cpp | 88 +- .../libdirac/libdirac_byteio/accessunit_byteio.h | 243 +- .../libdirac/libdirac_byteio/byteio.cpp | 110 +- .../libdirac/libdirac_byteio/byteio.h | 687 +++-- .../libdirac_byteio/codingparams_byteio.cpp | 34 +- .../libdirac/libdirac_byteio/codingparams_byteio.h | 150 +- .../libdirac/libdirac_byteio/component_byteio.cpp | 16 +- .../libdirac/libdirac_byteio/component_byteio.h | 130 +- .../libdirac/libdirac_byteio/dirac_byte_stats.cpp | 22 +- .../libdirac/libdirac_byteio/dirac_byte_stats.h | 125 +- .../libdirac/libdirac_byteio/dirac_byte_stream.cpp | 54 +- .../libdirac/libdirac_byteio/dirac_byte_stream.h | 194 +- .../libdirac_byteio/displayparams_byteio.cpp | 210 +- .../libdirac_byteio/displayparams_byteio.h | 284 +- .../libdirac_byteio/endofsequence_byteio.cpp | 12 +- .../libdirac_byteio/endofsequence_byteio.h | 96 +- .../libdirac/libdirac_byteio/mvdata_byteio.cpp | 154 +- .../libdirac/libdirac_byteio/mvdata_byteio.h | 439 ++- .../libdirac_byteio/mvdataelement_byteio.cpp | 10 +- .../libdirac_byteio/mvdataelement_byteio.h | 132 +- .../libdirac_byteio/parseparams_byteio.cpp | 58 +- .../libdirac/libdirac_byteio/parseparams_byteio.h | 114 +- .../libdirac/libdirac_byteio/parseunit_byteio.cpp | 64 +- .../libdirac/libdirac_byteio/parseunit_byteio.h | 395 ++- .../libdirac/libdirac_byteio/picture_byteio.cpp | 92 +- .../libdirac/libdirac_byteio/picture_byteio.h | 314 +- .../libdirac/libdirac_byteio/subband_byteio.cpp | 42 +- .../libdirac/libdirac_byteio/subband_byteio.h | 114 +- .../libdirac/libdirac_byteio/transform_byteio.cpp | 50 +- .../libdirac/libdirac_byteio/transform_byteio.h | 172 +- .../libdirac/libdirac_common/arith_codec.cpp | 226 +- .../libdirac/libdirac_common/arith_codec.h | 661 +++-- .../libdirac/libdirac_common/arrays.h | 885 +++--- .../libdirac/libdirac_common/band_codec.cpp | 30 +- .../libdirac/libdirac_common/band_codec.h | 324 +-- .../libdirac/libdirac_common/band_codec_template.h | 354 +-- .../libdirac/libdirac_common/band_vlc.cpp | 16 +- .../libdirac/libdirac_common/band_vlc.h | 156 +- .../libdirac/libdirac_common/bit_manager.cpp | 176 +- .../libdirac/libdirac_common/bit_manager.h | 848 +++--- .../libdirac/libdirac_common/cmd_line.cpp | 16 +- .../libdirac/libdirac_common/cmd_line.h | 72 +- .../libdirac/libdirac_common/common.cpp | 400 ++- .../libdirac/libdirac_common/common.h | 3009 ++++++++------------ .../libdirac/libdirac_common/common_types.h | 263 +- .../libdirac/libdirac_common/dirac_assertions.cpp | 14 +- .../libdirac/libdirac_common/dirac_assertions.h | 4 +- .../libdirac/libdirac_common/dirac_exception.cpp | 16 +- .../libdirac/libdirac_common/dirac_exception.h | 65 +- .../libdirac/libdirac_common/dirac_types.h | 244 +- .../libdirac/libdirac_common/mot_comp.cpp | 764 +++-- .../libdirac/libdirac_common/mot_comp.h | 468 +-- .../libdirac/libdirac_common/mot_comp_mmx.cpp | 432 ++- .../libdirac/libdirac_common/mot_comp_mmx.h | 14 +- .../libdirac/libdirac_common/motion.cpp | 624 ++-- .../libdirac/libdirac_common/motion.h | 661 ++--- .../libdirac/libdirac_common/mv_codec.cpp | 532 ++-- .../libdirac/libdirac_common/mv_codec.h | 434 +-- .../libdirac/libdirac_common/pic_io.cpp | 305 +- .../libdirac/libdirac_common/pic_io.h | 844 +++--- .../libdirac/libdirac_common/picture.cpp | 226 +- .../libdirac/libdirac_common/picture.h | 170 +- .../libdirac/libdirac_common/picture_buffer.cpp | 128 +- .../libdirac/libdirac_common/picture_buffer.h | 277 +- .../libdirac/libdirac_common/upconvert.cpp | 70 +- .../libdirac/libdirac_common/upconvert.h | 78 +- .../libdirac_common/video_format_defaults.cpp | 40 +- .../libdirac_common/video_format_defaults.h | 94 +- .../libdirac/libdirac_common/wavelet_utils.cpp | 1209 ++++---- .../libdirac/libdirac_common/wavelet_utils.h | 1140 ++++---- .../libdirac/libdirac_common/wavelet_utils_mmx.cpp | 1432 +++++----- .../libdirac/libdirac_decoder/comp_decompress.cpp | 88 +- .../libdirac/libdirac_decoder/comp_decompress.h | 144 +- .../libdirac/libdirac_decoder/decoder_types.h | 21 +- .../libdirac/libdirac_decoder/dirac_cppparser.cpp | 116 +- .../libdirac/libdirac_decoder/dirac_cppparser.h | 248 +- .../libdirac/libdirac_decoder/dirac_parser.cpp | 578 ++-- .../libdirac/libdirac_decoder/dirac_parser.h | 164 +- .../libdirac_decoder/picture_decompress.cpp | 300 +- .../libdirac/libdirac_decoder/picture_decompress.h | 200 +- .../libdirac/libdirac_decoder/seq_decompress.cpp | 68 +- .../libdirac/libdirac_decoder/seq_decompress.h | 264 +- .../libdirac/libdirac_encoder/comp_compress.cpp | 76 +- .../libdirac/libdirac_encoder/comp_compress.h | 112 +- .../libdirac/libdirac_encoder/dirac_encoder.cpp | 794 +++--- .../libdirac/libdirac_encoder/dirac_encoder.h | 627 ++-- .../libdirac/libdirac_encoder/enc_picture.cpp | 309 +- .../libdirac/libdirac_encoder/enc_picture.h | 77 +- .../libdirac/libdirac_encoder/enc_queue.cpp | 145 +- .../libdirac/libdirac_encoder/enc_queue.h | 328 ++- .../libdirac/libdirac_encoder/picture_compress.cpp | 600 ++-- .../libdirac/libdirac_encoder/picture_compress.h | 286 +- .../libdirac/libdirac_encoder/prefilter.cpp | 847 ++---- .../libdirac/libdirac_encoder/prefilter.h | 10 +- .../libdirac/libdirac_encoder/quality_monitor.cpp | 146 +- .../libdirac/libdirac_encoder/quality_monitor.h | 108 +- .../libdirac/libdirac_encoder/quant_chooser.cpp | 252 +- .../libdirac/libdirac_encoder/quant_chooser.h | 123 +- .../libdirac/libdirac_encoder/rate_control.cpp | 280 +- .../libdirac/libdirac_encoder/rate_control.h | 243 +- .../libdirac/libdirac_encoder/seq_compress.cpp | 681 ++--- .../libdirac/libdirac_encoder/seq_compress.h | 570 ++-- .../libdirac/libdirac_motionest/block_match.cpp | 386 +-- .../libdirac/libdirac_motionest/block_match.h | 289 +- .../libdirac/libdirac_motionest/downconvert.cpp | 144 +- .../libdirac/libdirac_motionest/downconvert.h | 77 +- .../libdirac_motionest/downconvert_mmx.cpp | 148 +- .../libdirac/libdirac_motionest/me_mode_decn.cpp | 390 ++- .../libdirac/libdirac_motionest/me_mode_decn.h | 178 +- .../libdirac/libdirac_motionest/me_subpel.cpp | 62 +- .../libdirac/libdirac_motionest/me_subpel.h | 100 +- .../libdirac/libdirac_motionest/me_utils.cpp | 1723 ++++++----- .../libdirac/libdirac_motionest/me_utils.h | 1000 ++++--- .../libdirac/libdirac_motionest/me_utils_mmx.cpp | 1913 +++++++------ .../libdirac/libdirac_motionest/me_utils_mmx.h | 44 +- .../libdirac_motionest/motion_estimate.cpp | 152 +- .../libdirac/libdirac_motionest/motion_estimate.h | 113 +- .../libdirac/libdirac_motionest/pixel_match.cpp | 208 +- .../libdirac/libdirac_motionest/pixel_match.h | 142 +- src/filters/parser/DiracSplitter/resource.h | 2 +- src/filters/parser/DiracSplitter/stdafx.cpp | 8 +- src/filters/parser/DiracSplitter/stdafx.h | 36 +- 126 files changed, 18227 insertions(+), 20266 deletions(-) (limited to 'src/filters/parser/DiracSplitter') diff --git a/src/filters/parser/DiracSplitter/DiracSplitter.cpp b/src/filters/parser/DiracSplitter/DiracSplitter.cpp index b9e3cc8b7..db544603f 100644 --- a/src/filters/parser/DiracSplitter/DiracSplitter.cpp +++ b/src/filters/parser/DiracSplitter/DiracSplitter.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2004 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, 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 GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -28,7 +28,7 @@ #ifdef REGISTER_FILTER const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = -{ +{ {&MEDIATYPE_Stream, &MEDIASUBTYPE_Dirac}, {&MEDIATYPE_Stream, &MEDIASUBTYPE_NULL} }; @@ -74,8 +74,8 @@ int g_cTemplates = countof(g_Templates); STDAPI DllRegisterServer() { RegisterSourceFilter( - CLSID_AsyncReader, - MEDIASUBTYPE_Dirac, + CLSID_AsyncReader, + MEDIASUBTYPE_Dirac, _T("0,8,,4B572D4449524143"), // KW-DIRAC _T(".drc"), NULL); @@ -107,7 +107,7 @@ STDMETHODIMP CDiracSplitterFilter::NonDelegatingQueryInterface(REFIID riid, void { CheckPointer(ppv, E_POINTER); - return + return __super::NonDelegatingQueryInterface(riid, ppv); } @@ -121,11 +121,7 @@ HRESULT CDiracSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader) m_pFile.Attach(DNew CDiracSplitterFile(pAsyncReader, hr)); if(!m_pFile) return E_OUTOFMEMORY; - if(FAILED(hr)) - { - m_pFile.Free(); - return hr; - } + if(FAILED(hr)) {m_pFile.Free(); return hr;} CAtlArray mts; mts.Add(m_pFile->GetMediaType()); @@ -162,7 +158,7 @@ void CDiracSplitterFilter::DemuxSeek(REFERENCE_TIME rt) // TODO __int64 len = m_pFile->GetLength(); - __int64 seekpos = (__int64)(1.0 * rt / m_rtDuration * len); + __int64 seekpos = (__int64)(1.0*rt/m_rtDuration*len); m_pFile->Seek(seekpos); seekpos = 0; @@ -176,11 +172,7 @@ void CDiracSplitterFilter::DemuxSeek(REFERENCE_TIME rt) for(int j = 0; j < 10; j++) { while(m_pFile->Next(code) && code != AU_START_CODE); - if(code != AU_START_CODE) - { - m_pFile->Seek(seekpos >>= 1); - continue; - } + if(code != AU_START_CODE) {m_pFile->Seek(seekpos >>= 1); continue;} __int64 pos = m_pFile->GetPos() - 5; @@ -194,7 +186,7 @@ void CDiracSplitterFilter::DemuxSeek(REFERENCE_TIME rt) break; } - m_pFile->Seek(pos - (__int64)(1.0 * dt / m_rtDuration * len)); + m_pFile->Seek(pos - (__int64)(1.0*dt/m_rtDuration*len)); pdt = dt; } @@ -222,7 +214,7 @@ bool CDiracSplitterFilter::DemuxLoop() memcpy(p->GetData(), pBuff, size); p->TrackNumber = 0; - p->rtStart = rtAvgTimePerFrame * fnum; + p->rtStart = rtAvgTimePerFrame*fnum; p->rtStop = p->rtStart + rtAvgTimePerFrame; p->bSyncPoint = code == AU_START_CODE; @@ -283,8 +275,7 @@ void CDiracVideoDecoder::FreeDecoder() { dirac_decoder_close((dirac_decoder_t*)m_decoder); m_decoder = NULL; - delete [] m_pYUV[0]; - m_pYUV[0] = NULL; + delete [] m_pYUV[0]; m_pYUV[0] = NULL; } } @@ -304,7 +295,7 @@ HRESULT CDiracVideoDecoder::Receive(IMediaSample* pIn) long len = pIn->GetActualDataLength(); if(len <= 0) return S_OK; // nothing to do - if(pIn->IsDiscontinuity() == S_OK) + if(pIn->IsDiscontinuity() == S_OK) InitDecoder(); dirac_decoder_t* decoder = (dirac_decoder_t*)m_decoder; @@ -326,7 +317,7 @@ HRESULT CDiracVideoDecoder::Receive(IMediaSample* pIn) { DIRACINFOHEADER* dvih = (DIRACINFOHEADER*)m_pInput->CurrentMediaType().Format(); if(dvih->hdr.bmiHeader.biWidth != decoder->src_params.width - || dvih->hdr.bmiHeader.biHeight != decoder->src_params.height) + || dvih->hdr.bmiHeader.biHeight != decoder->src_params.height) return E_FAIL; // hmm } @@ -335,14 +326,13 @@ HRESULT CDiracVideoDecoder::Receive(IMediaSample* pIn) int w = decoder->src_params.width; int h = decoder->src_params.height; int wc = decoder->src_params.chroma_width; - int hc = decoder->src_params.chroma_height; - delete [] m_pYUV[0]; - m_pYUV[0] = NULL; + int hc = decoder->src_params.chroma_height; + delete [] m_pYUV[0]; m_pYUV[0] = NULL; m_pYUV[0] = DNew BYTE[w*h + wc*hc*2 + w/2*h/2]; - m_pYUV[1] = m_pYUV[0] + w * h; - m_pYUV[2] = m_pYUV[1] + wc * hc; - m_pYUV[3] = m_pYUV[2] + wc * hc; - memset(m_pYUV[3], 0x80, w / 2 * h / 2); + m_pYUV[1] = m_pYUV[0] + w*h; + m_pYUV[2] = m_pYUV[1] + wc*hc; + m_pYUV[3] = m_pYUV[2] + wc*hc; + memset(m_pYUV[3], 0x80, w/2*h/2); m_rtAvgTimePerFrame = 10000000i64 * decoder->src_params.frame_rate.denominator / decoder->src_params.frame_rate.numerator; dirac_set_buf(decoder, m_pYUV, NULL); } @@ -379,7 +369,7 @@ HRESULT CDiracVideoDecoder::Deliver(IMediaSample* pIn, REFERENCE_TIME rtStart, R CComPtr pOut; BYTE* pDataOut = NULL; if(FAILED(hr = m_pOutput->GetDeliveryBuffer(&pOut, NULL, NULL, 0)) - || FAILED(hr = pOut->GetPointer(&pDataOut))) + || FAILED(hr = pOut->GetPointer(&pDataOut))) return hr; AM_MEDIA_TYPE* pmt; @@ -423,28 +413,28 @@ void CDiracVideoDecoder::Copy(BYTE* pOut) int pitchIn = w; BYTE* pY = m_pYUV[0]; - BYTE* pU = w / 2 == wc && h / 2 == hc ? m_pYUV[1] : m_pYUV[3]; // FIXME - BYTE* pV = w / 2 == wc && h / 2 == hc ? m_pYUV[2] : m_pYUV[3]; // FIXME + BYTE* pU = w/2 == wc && h/2 == hc ? m_pYUV[1] : m_pYUV[3]; // FIXME + BYTE* pV = w/2 == wc && h/2 == hc ? m_pYUV[2] : m_pYUV[3]; // FIXME if(bihOut.biCompression == '2YUY') { - BitBltFromI420ToYUY2(w, h, pOut, bihOut.biWidth * 2, pY, pU, pV, pitchIn); + BitBltFromI420ToYUY2(w, h, pOut, bihOut.biWidth*2, pY, pU, pV, pitchIn); } else if(bihOut.biCompression == 'I420' || bihOut.biCompression == 'VUYI') { - BitBltFromI420ToI420(w, h, pOut, pOut + bihOut.biWidth * h, pOut + bihOut.biWidth * h * 5 / 4, bihOut.biWidth, pY, pU, pV, pitchIn); + BitBltFromI420ToI420(w, h, pOut, pOut + bihOut.biWidth*h, pOut + bihOut.biWidth*h*5/4, bihOut.biWidth, pY, pU, pV, pitchIn); } else if(bihOut.biCompression == '21VY') { - BitBltFromI420ToI420(w, h, pOut, pOut + bihOut.biWidth * h * 5 / 4, pOut + bihOut.biWidth * h, bihOut.biWidth, pY, pU, pV, pitchIn); + BitBltFromI420ToI420(w, h, pOut, pOut + bihOut.biWidth*h*5/4, pOut + bihOut.biWidth*h, bihOut.biWidth, pY, pU, pV, pitchIn); } else if(bihOut.biCompression == BI_RGB || bihOut.biCompression == BI_BITFIELDS) { - int pitchOut = bihOut.biWidth * bihOut.biBitCount >> 3; + int pitchOut = bihOut.biWidth*bihOut.biBitCount>>3; if(bihOut.biHeight > 0) { - pOut += pitchOut * (h - 1); + pOut += pitchOut*(h-1); pitchOut = -pitchOut; } @@ -460,10 +450,10 @@ HRESULT CDiracVideoDecoder::CheckInputType(const CMediaType* mtIn) { DIRACINFOHEADER* dvih = (DIRACINFOHEADER*)mtIn->Format(); - if(mtIn->majortype != MEDIATYPE_Video - || mtIn->subtype != MEDIASUBTYPE_DiracVideo - || mtIn->formattype != FORMAT_DiracVideoInfo - || (dvih->hdr.bmiHeader.biWidth & 1) || (dvih->hdr.bmiHeader.biHeight & 1)) + if(mtIn->majortype != MEDIATYPE_Video + || mtIn->subtype != MEDIASUBTYPE_DiracVideo + || mtIn->formattype != FORMAT_DiracVideoInfo + || (dvih->hdr.bmiHeader.biWidth&1) || (dvih->hdr.bmiHeader.biHeight&1)) return VFW_E_TYPE_NOT_ACCEPTED; return S_OK; @@ -475,22 +465,22 @@ HRESULT CDiracVideoDecoder::CheckTransform(const CMediaType* mtIn, const CMediaT { BITMAPINFOHEADER bih1, bih2; if(ExtractBIH(mtOut, &bih1) && ExtractBIH(&m_pOutput->CurrentMediaType(), &bih2) - && abs(bih1.biHeight) != abs(bih2.biHeight)) + && abs(bih1.biHeight) != abs(bih2.biHeight)) return VFW_E_TYPE_NOT_ACCEPTED; } return mtIn->majortype == MEDIATYPE_Video && mtIn->subtype == MEDIASUBTYPE_DiracVideo - && mtOut->majortype == MEDIATYPE_Video && (mtOut->subtype == MEDIASUBTYPE_YUY2 - || mtOut->subtype == MEDIASUBTYPE_YV12 - || mtOut->subtype == MEDIASUBTYPE_I420 - || mtOut->subtype == MEDIASUBTYPE_IYUV - || mtOut->subtype == MEDIASUBTYPE_ARGB32 - || mtOut->subtype == MEDIASUBTYPE_RGB32 - || mtOut->subtype == MEDIASUBTYPE_RGB24 - || mtOut->subtype == MEDIASUBTYPE_RGB565 - || mtOut->subtype == MEDIASUBTYPE_RGB555) - ? S_OK - : VFW_E_TYPE_NOT_ACCEPTED; + && mtOut->majortype == MEDIATYPE_Video && (mtOut->subtype == MEDIASUBTYPE_YUY2 + || mtOut->subtype == MEDIASUBTYPE_YV12 + || mtOut->subtype == MEDIASUBTYPE_I420 + || mtOut->subtype == MEDIASUBTYPE_IYUV + || mtOut->subtype == MEDIASUBTYPE_ARGB32 + || mtOut->subtype == MEDIASUBTYPE_RGB32 + || mtOut->subtype == MEDIASUBTYPE_RGB24 + || mtOut->subtype == MEDIASUBTYPE_RGB565 + || mtOut->subtype == MEDIASUBTYPE_RGB555) + ? S_OK + : VFW_E_TYPE_NOT_ACCEPTED; } HRESULT CDiracVideoDecoder::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties) @@ -507,24 +497,19 @@ HRESULT CDiracVideoDecoder::DecideBufferSize(IMemAllocator* pAllocator, ALLOCATO HRESULT hr; ALLOCATOR_PROPERTIES Actual; - if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual))) + if(FAILED(hr = pAllocator->SetProperties(pProperties, &Actual))) return hr; return(pProperties->cBuffers > Actual.cBuffers || pProperties->cbBuffer > Actual.cbBuffer - ? E_FAIL - : NOERROR); + ? E_FAIL + : NOERROR); } HRESULT CDiracVideoDecoder::GetMediaType(int iPosition, CMediaType* pmt) { if(m_pInput->IsConnected() == FALSE) return E_UNEXPECTED; - struct - { - const GUID* subtype; - WORD biPlanes, biBitCount; - DWORD biCompression; - } fmts[] = + struct {const GUID* subtype; WORD biPlanes, biBitCount; DWORD biCompression;} fmts[] = { {&MEDIASUBTYPE_YV12, 3, 12, '21VY'}, {&MEDIASUBTYPE_I420, 3, 12, '024I'}, @@ -543,10 +528,10 @@ HRESULT CDiracVideoDecoder::GetMediaType(int iPosition, CMediaType* pmt) }; if(m_pInput->CurrentMediaType().formattype == FORMAT_VideoInfo) - iPosition = iPosition * 2 + 1; + iPosition = iPosition*2 + 1; if(iPosition < 0) return E_INVALIDARG; - if(iPosition >= 2 * countof(fmts)) return VFW_S_NO_MORE_ITEMS; + if(iPosition >= 2*countof(fmts)) return VFW_S_NO_MORE_ITEMS; BITMAPINFOHEADER bih; ExtractBIH(&m_pInput->CurrentMediaType(), &bih); @@ -562,9 +547,9 @@ HRESULT CDiracVideoDecoder::GetMediaType(int iPosition, CMediaType* pmt) bihOut.biPlanes = fmts[iPosition/2].biPlanes; bihOut.biBitCount = fmts[iPosition/2].biBitCount; bihOut.biCompression = fmts[iPosition/2].biCompression; - bihOut.biSizeImage = bih.biWidth * bih.biHeight * bihOut.biBitCount >> 3; + bihOut.biSizeImage = bih.biWidth*bih.biHeight*bihOut.biBitCount>>3; - if(iPosition & 1) + if(iPosition&1) { pmt->formattype = FORMAT_VideoInfo; VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)pmt->AllocFormatBuffer(sizeof(VIDEOINFOHEADER)); @@ -575,7 +560,7 @@ HRESULT CDiracVideoDecoder::GetMediaType(int iPosition, CMediaType* pmt) { vih->bmiHeader.biWidth = ((VIDEOINFOHEADER2*)m_pInput->CurrentMediaType().Format())->dwPictAspectRatioX; vih->bmiHeader.biHeight = ((VIDEOINFOHEADER2*)m_pInput->CurrentMediaType().Format())->dwPictAspectRatioY; - vih->bmiHeader.biSizeImage = vih->bmiHeader.biWidth * vih->bmiHeader.biHeight * vih->bmiHeader.biBitCount >> 3; + vih->bmiHeader.biSizeImage = vih->bmiHeader.biWidth*vih->bmiHeader.biHeight*vih->bmiHeader.biBitCount>>3; } } else @@ -617,7 +602,7 @@ HRESULT CDiracVideoDecoder::NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tSt HRESULT CDiracVideoDecoder::AlterQuality(Quality q) { - if(q.Late > 500 * 10000i64) m_fDropFrames = true; + if(q.Late > 500*10000i64) m_fDropFrames = true; if(q.Late <= 0) m_fDropFrames = false; return E_NOTIMPL; } diff --git a/src/filters/parser/DiracSplitter/DiracSplitter.h b/src/filters/parser/DiracSplitter/DiracSplitter.h index 4b3915ba2..0ed5d14cb 100644 --- a/src/filters/parser/DiracSplitter/DiracSplitter.h +++ b/src/filters/parser/DiracSplitter/DiracSplitter.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (C) 2003-2006 Gabest * http://www.gabest.org * @@ -6,15 +6,15 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, 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 GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * http://www.gnu.org/copyleft/gpl.html * */ @@ -28,17 +28,17 @@ class CDiracSplitterFilter : public CBaseSplitterFilter { protected: - CAutoPtr m_pFile; - HRESULT CreateOutputs(IAsyncReader* pAsyncReader); + CAutoPtr m_pFile; + HRESULT CreateOutputs(IAsyncReader* pAsyncReader); - bool DemuxInit(); - void DemuxSeek(REFERENCE_TIME rt); - bool DemuxLoop(); + bool DemuxInit(); + void DemuxSeek(REFERENCE_TIME rt); + bool DemuxLoop(); public: - CDiracSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr); + CDiracSplitterFilter(LPUNKNOWN pUnk, HRESULT* phr); - DECLARE_IUNKNOWN + DECLARE_IUNKNOWN STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv); }; @@ -46,35 +46,35 @@ public: class CDiracSourceFilter : public CDiracSplitterFilter { public: - CDiracSourceFilter(LPUNKNOWN pUnk, HRESULT* phr); + CDiracSourceFilter(LPUNKNOWN pUnk, HRESULT* phr); }; [uuid("F78CF248-180E-4713-B107-B13F7B5C31E1")] class CDiracVideoDecoder : public CTransformFilter { void* m_decoder; // dirac_decoder_t* - void InitDecoder(), FreeDecoder(); - BYTE* m_pYUV[4]; - bool m_fDropFrames; - REFERENCE_TIME m_tStart, m_rtAvgTimePerFrame; + void InitDecoder(), FreeDecoder(); + BYTE* m_pYUV[4]; + bool m_fDropFrames; + REFERENCE_TIME m_tStart, m_rtAvgTimePerFrame; - HRESULT Deliver(IMediaSample* pIn, REFERENCE_TIME rtStart, REFERENCE_TIME rtStop); - void Copy(BYTE* pOut); + HRESULT Deliver(IMediaSample* pIn, REFERENCE_TIME rtStart, REFERENCE_TIME rtStop); + void Copy(BYTE* pOut); public: - CDiracVideoDecoder(LPUNKNOWN lpunk, HRESULT* phr); - virtual ~CDiracVideoDecoder(); + CDiracVideoDecoder(LPUNKNOWN lpunk, HRESULT* phr); + virtual ~CDiracVideoDecoder(); - HRESULT Receive(IMediaSample* pIn); - HRESULT CheckInputType(const CMediaType* mtIn); - HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut); - HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties); - HRESULT GetMediaType(int iPosition, CMediaType* pMediaType); + HRESULT Receive(IMediaSample* pIn); + HRESULT CheckInputType(const CMediaType* mtIn); + HRESULT CheckTransform(const CMediaType* mtIn, const CMediaType* mtOut); + HRESULT DecideBufferSize(IMemAllocator* pAllocator, ALLOCATOR_PROPERTIES* pProperties); + HRESULT GetMediaType(int iPosition, CMediaType* pMediaType); - HRESULT StartStreaming(); - HRESULT StopStreaming(); + HRESULT StartStreaming(); + HRESULT StopStreaming(); HRESULT NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate); - HRESULT AlterQuality(Quality q); + HRESULT AlterQuality(Quality q); }; \ No newline at end of file diff --git a/src/filters/parser/DiracSplitter/DiracSplitterFile.cpp b/src/filters/parser/DiracSplitter/DiracSplitterFile.cpp index 7bae7f357..de3b42b45 100644 --- a/src/filters/parser/DiracSplitter/DiracSplitterFile.cpp +++ b/src/filters/parser/DiracSplitter/DiracSplitterFile.cpp @@ -18,11 +18,11 @@ HRESULT CDiracSplitterFile::Init() HRESULT hr = E_FAIL; Seek(0); - + // Dirac streams are no longer preceded with KW-DIRAC //UINT64 hdr; //if(FAILED(Read((BYTE*)&hdr, sizeof(hdr))) || hdr != 0x43415249442D574Bui64) // KW-DIRAC - //return E_FAIL; + //return E_FAIL; dirac_decoder_t* decoder = dirac_decoder_init(0); @@ -31,20 +31,12 @@ HRESULT CDiracSplitterFile::Init() while(GetPos() < limit) { BYTE b; - if(!Next(b)) - { - ASSERT(0); - break; - } + if(!Next(b)) {ASSERT(0); break;} if(b == AU_START_CODE) { __int64 pos = GetPos() - 13; //Parse info size = 13 - if(!Next(b)) - { - ASSERT(0); - break; - } + if(!Next(b)) {ASSERT(0); break;} __int64 len = GetPos() - pos; Seek(pos); @@ -61,14 +53,10 @@ HRESULT CDiracSplitterFile::Init() dirac_buffer(decoder, (BYTE*)&dvih->dwSequenceHeader[0], (BYTE*)&dvih->dwSequenceHeader[0] + len); DecoderState dec_state = dirac_parse(decoder); - if(dec_state != STATE_SEQUENCE) - { - ASSERT(0); - break; - } + if(dec_state != STATE_SEQUENCE) {ASSERT(0); break;} if(decoder->src_params.frame_rate.denominator) - dvih->hdr.AvgTimePerFrame = 10000000i64 * decoder->src_params.frame_rate.denominator / decoder->src_params.frame_rate.numerator; + dvih->hdr.AvgTimePerFrame = 10000000i64 * decoder->src_params.frame_rate.denominator / decoder->src_params.frame_rate.numerator; dvih->hdr.bmiHeader.biSize = sizeof(dvih->hdr.bmiHeader); dvih->hdr.bmiHeader.biWidth = decoder->src_params.width; dvih->hdr.bmiHeader.biHeight = decoder->src_params.height; @@ -94,7 +82,7 @@ HRESULT CDiracSplitterFile::Init() } UINT64 CDiracSplitterFile::UnsignedGolombDecode() -{ +{ int M = 0; while(M < 64 && !BitRead(1)) M++; @@ -103,7 +91,7 @@ UINT64 CDiracSplitterFile::UnsignedGolombDecode() for(int i = 0; i < M; i++) info |= BitRead(1) << i; - return (1ui64 << M) - 1 + info; + return (1ui64<= GetLength()) return(false); qw = (qw << 8) | (BYTE)BitRead(8); } - while((qw & 0xffffffff00) != ((UINT64)START_CODE_PREFIX << 8)); + while((qw&0xffffffff00) != ((UINT64)START_CODE_PREFIX<<8)); int size_bytes = 0; // Read in the 6 bytes of next and previous parse unit offsets. - while(size_bytes < 6) + while (size_bytes < 6) { if(len-- == 0 || GetPos() >= GetLength()) return(false); BitRead(8); @@ -143,7 +131,7 @@ const BYTE* CDiracSplitterFile::NextBlock(BYTE& code, int& size, int& fnum) if(size == 0) { - if((qw & 0xffffffff00) == ((UINT64)START_CODE_PREFIX << 8)) + if((qw & 0xffffffff00) == ((UINT64)START_CODE_PREFIX<<8) ) code = (BYTE)(qw & 0xff); if(isFrameStartCode(code)) @@ -157,14 +145,14 @@ const BYTE* CDiracSplitterFile::NextBlock(BYTE& code, int& size, int& fnum) } else { - if((qw & 0xffffffff00) == ((UINT64)START_CODE_PREFIX << 8)) + if((qw & 0xffffffff00) == ((UINT64)START_CODE_PREFIX<<8)) break; } } if(size >= m_pBuff.GetSize()) { - int newsize = max(1024, size * 2); + int newsize = max(1024, size*2); m_pBuff.SetSize(newsize, newsize); pBuff = m_pBuff.GetData(); } diff --git a/src/filters/parser/DiracSplitter/DiracSplitterFile.h b/src/filters/parser/DiracSplitter/DiracSplitterFile.h index a69e61fb1..cc2ec185a 100644 --- a/src/filters/parser/DiracSplitter/DiracSplitterFile.h +++ b/src/filters/parser/DiracSplitter/DiracSplitterFile.h @@ -7,27 +7,21 @@ class CDiracSplitterFile : public CBaseSplitterFile { - CMediaType m_mt; - REFERENCE_TIME m_rtDuration; - CArray m_pBuff; + CMediaType m_mt; + REFERENCE_TIME m_rtDuration; + CArray m_pBuff; - HRESULT Init(); + HRESULT Init(); public: - CDiracSplitterFile(IAsyncReader* pAsyncReader, HRESULT& hr); + CDiracSplitterFile(IAsyncReader* pAsyncReader, HRESULT& hr); // using CBaseSplitterFile::Read; - bool Next(BYTE& code, __int64 len = -1); - const BYTE* NextBlock(BYTE& code, int& size, int& fnum); - UINT64 UnsignedGolombDecode(); + bool Next(BYTE& code, __int64 len = -1); + const BYTE* NextBlock(BYTE& code, int& size, int& fnum); + UINT64 UnsignedGolombDecode(); - const CMediaType& GetMediaType() - { - return m_mt; - } - REFERENCE_TIME GetDuration() - { - return m_rtDuration; - } + const CMediaType& GetMediaType() {return m_mt;} + REFERENCE_TIME GetDuration() {return m_rtDuration;} }; diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.cpp index 8248a0003..33bb8ff9f 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.cpp @@ -42,40 +42,40 @@ using namespace dirac; // Constructor for encoding -SequenceHeaderByteIO::SequenceHeaderByteIO(SourceParams& src_params, - EncoderParams& enc_params): - ParseUnitByteIO(), - m_parseparams_byteio(*this, m_parse_params, enc_params), +SequenceHeaderByteIO::SequenceHeaderByteIO( SourceParams& src_params, + EncoderParams& enc_params): +ParseUnitByteIO(), +m_parseparams_byteio(*this, m_parse_params, enc_params), // create default source parameters for comparisions - m_default_src_params(src_params.GetVideoFormat()), - m_src_params(src_params), - m_sourceparams_byteio(m_src_params, - m_default_src_params, - *this), - m_codec_params(enc_params), - m_codingparams_byteio(m_src_params, - m_codec_params, - m_default_src_params, - *this) +m_default_src_params(src_params.GetVideoFormat()), +m_src_params(src_params), +m_sourceparams_byteio( m_src_params, + m_default_src_params, + *this), +m_codec_params(enc_params), +m_codingparams_byteio(m_src_params, + m_codec_params, + m_default_src_params, + *this) { } // Constructor for decoding SequenceHeaderByteIO::SequenceHeaderByteIO(const ParseUnitByteIO& parseunit_byteio, - ParseParams& parse_params, - SourceParams& src_params, - CodecParams& codec_params) : - ParseUnitByteIO(parseunit_byteio), - m_parseparams_byteio(parseunit_byteio, parse_params), - m_src_params(src_params), - m_sourceparams_byteio(m_src_params, - m_default_src_params, - parseunit_byteio), - m_codec_params(codec_params), - m_codingparams_byteio(m_src_params, - m_codec_params, - m_default_src_params, - parseunit_byteio) + ParseParams& parse_params, + SourceParams& src_params, + CodecParams& codec_params) : +ParseUnitByteIO(parseunit_byteio), +m_parseparams_byteio( parseunit_byteio, parse_params), +m_src_params(src_params), +m_sourceparams_byteio( m_src_params, + m_default_src_params, + parseunit_byteio), +m_codec_params(codec_params), +m_codingparams_byteio( m_src_params, + m_codec_params, + m_default_src_params, + parseunit_byteio) { } @@ -84,7 +84,7 @@ SequenceHeaderByteIO::~SequenceHeaderByteIO() } //-----public------------------------------------------------------ -bool SequenceHeaderByteIO::Input() +bool SequenceHeaderByteIO::Input() { //int o=mp_stream->tellg(); InputParseParams(); @@ -92,22 +92,22 @@ bool SequenceHeaderByteIO::Input() // Inout Video format SetByteParams(m_parseparams_byteio); VideoFormat vf = IntToVideoFormat(ReadUint()); - if(vf == VIDEO_FORMAT_UNDEFINED) - DIRAC_THROW_EXCEPTION( - ERR_INVALID_VIDEO_FORMAT, - "Dirac does not recognise the specified video-format", - SEVERITY_ACCESSUNIT_ERROR); + if(vf==VIDEO_FORMAT_UNDEFINED) + DIRAC_THROW_EXCEPTION( + ERR_INVALID_VIDEO_FORMAT, + "Dirac does not recognise the specified video-format", + SEVERITY_ACCESSUNIT_ERROR); SourceParams src_params(vf, true); m_src_params = src_params; - + InputSourceParams(); - + CodecParams codec_params(vf); m_codec_params = codec_params; - + InputCodingParams(); - + return true; } @@ -122,15 +122,15 @@ void SequenceHeaderByteIO::Output() OutputSourceParams(); OutputCodingParams(); - + } int SequenceHeaderByteIO::GetSize() const { - return ParseUnitByteIO::GetSize() + - m_parseparams_byteio.GetSize() + - ByteIO::GetSize() + - m_sourceparams_byteio.GetSize() + + return ParseUnitByteIO::GetSize()+ + m_parseparams_byteio.GetSize()+ + ByteIO::GetSize() + + m_sourceparams_byteio.GetSize()+ m_codingparams_byteio.GetSize(); } @@ -150,7 +150,7 @@ unsigned char SequenceHeaderByteIO::CalcParseCode() const void SequenceHeaderByteIO::InputSourceParams() { - // copy current input params + // copy current input params m_sourceparams_byteio.SetByteParams(*this); m_sourceparams_byteio.Input(); diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.h index 346bd4110..2c2966ed8 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.h @@ -50,135 +50,132 @@ namespace dirac { -/** -* A random access point within a Dirac bytestream -*/ -class SequenceHeaderByteIO : public ParseUnitByteIO -{ -public: - /** - * Constructor (encoding) - *@param src_params Source parameters for current AccessUnit - *@param enc_params Encoder parameters for current AccessUnit + * A random access point within a Dirac bytestream */ - SequenceHeaderByteIO(SourceParams& src_params, - EncoderParams& enc_params); - - /** - * Constructor (decoding) - *@param parseunit_byteio Source of data - *@param parse_params Destination of parse paramters data - *@param src_params Destination of source paramters data - *@param codec_params Destination of coding paramters data - */ - SequenceHeaderByteIO(const ParseUnitByteIO& parseunit_byteio, + class SequenceHeaderByteIO : public ParseUnitByteIO + { + public: + + /** + * Constructor (encoding) + *@param src_params Source parameters for current AccessUnit + *@param enc_params Encoder parameters for current AccessUnit + */ + SequenceHeaderByteIO( SourceParams& src_params, + EncoderParams& enc_params); + + /** + * Constructor (decoding) + *@param parseunit_byteio Source of data + *@param parse_params Destination of parse paramters data + *@param src_params Destination of source paramters data + *@param codec_params Destination of coding paramters data + */ + SequenceHeaderByteIO(const ParseUnitByteIO& parseunit_byteio, ParseParams& parse_params, SourceParams& src_params, CodecParams& codec_params); - /** - * Destructor - */ - ~SequenceHeaderByteIO(); - - /** - * Parses data in Dirac-stream format (decoding) - */ - bool Input(); - - /** - * Writes access-unit info to Dirac stream-format (encoding) - */ - void Output(); - - /* - * Gets size of access-unit (in bytes) - */ - int GetSize() const; - - /** - * Gets parse-unit type - */ - ParseUnitType GetType() const - { - return PU_SEQ_HEADER; - } - -private: - - /** - * Calculates parse-code based on access-unit parameters (encoding) - *@return Char bit-set - */ - unsigned char CalcParseCode() const; - - /** - * Parse source attributes from bytestream-compatible input (decoding) - */ - void InputSourceParams(); - - /** - * Parse parse attributes from bytestream-compatible input (decoding) - */ - void InputParseParams(); - - /** - * Parse Coding attributes from bytestream-compatible input (decoding) - */ - void InputCodingParams(); - - /** - * Output source attributes for bytestream-compatible output (encoding) - */ - void OutputSourceParams(); - - /** - * Output parse attributes for bytestream-compatible output (encoding) - */ - void OutputParseParams(); - - /** - * Output coding attributes for bytestream-compatible output (encoding) - */ - void OutputCodingParams(); - - /** - * Current parse parameters - */ - ParseParams m_parse_params; - - - /** - * Parse-params byte input/output - */ - ParseParamsByteIO m_parseparams_byteio; - - /** - * Default source parameters - */ - SourceParams m_default_src_params; - - /** - * Current source parameters - */ - SourceParams& m_src_params; - - /** - * Source-params byte input/output - */ - SourceParamsByteIO m_sourceparams_byteio; - - /** - * Current codec parameters - */ - CodecParams& m_codec_params; - - /** - * Coding-params byte input/output - */ - CodingParamsByteIO m_codingparams_byteio; -}; + /** + * Destructor + */ + ~SequenceHeaderByteIO(); + + /** + * Parses data in Dirac-stream format (decoding) + */ + bool Input(); + + /** + * Writes access-unit info to Dirac stream-format (encoding) + */ + void Output(); + + /* + * Gets size of access-unit (in bytes) + */ + int GetSize() const; + + /** + * Gets parse-unit type + */ + ParseUnitType GetType() const { return PU_SEQ_HEADER;} + + private: + + /** + * Calculates parse-code based on access-unit parameters (encoding) + *@return Char bit-set + */ + unsigned char CalcParseCode() const; + + /** + * Parse source attributes from bytestream-compatible input (decoding) + */ + void InputSourceParams(); + + /** + * Parse parse attributes from bytestream-compatible input (decoding) + */ + void InputParseParams(); + + /** + * Parse Coding attributes from bytestream-compatible input (decoding) + */ + void InputCodingParams(); + + /** + * Output source attributes for bytestream-compatible output (encoding) + */ + void OutputSourceParams(); + + /** + * Output parse attributes for bytestream-compatible output (encoding) + */ + void OutputParseParams(); + + /** + * Output coding attributes for bytestream-compatible output (encoding) + */ + void OutputCodingParams(); + + /** + * Current parse parameters + */ + ParseParams m_parse_params; + + + /** + * Parse-params byte input/output + */ + ParseParamsByteIO m_parseparams_byteio; + + /** + * Default source parameters + */ + SourceParams m_default_src_params; + + /** + * Current source parameters + */ + SourceParams& m_src_params; + + /** + * Source-params byte input/output + */ + SourceParamsByteIO m_sourceparams_byteio; + + /** + * Current codec parameters + */ + CodecParams& m_codec_params; + + /** + * Coding-params byte input/output + */ + CodingParamsByteIO m_codingparams_byteio; + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.cpp index 724239e54..12b129953 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.cpp @@ -42,37 +42,37 @@ using namespace dirac; using namespace std; ByteIO::ByteIO(bool new_stream): - m_current_byte(0), - m_current_pos(0), - m_num_bytes(0), - m_new_stream(true), - m_bits_left(0) +m_current_byte(0), +m_current_pos(0), +m_num_bytes(0), +m_new_stream(true), +m_bits_left(0) { if(new_stream) mp_stream = new stringstream(stringstream::in | stringstream::out | stringstream::binary); - + } ByteIO::ByteIO(const ByteIO& stream_data): - m_current_byte(0), - m_current_pos(0), - m_num_bytes(0), - m_new_stream(false), - m_bits_left(0) +m_current_byte(0), +m_current_pos(0), +m_num_bytes(0), +m_new_stream(false), +m_bits_left(0) { - mp_stream = stream_data.mp_stream; + mp_stream=stream_data.mp_stream; } ByteIO::~ByteIO() { - if(m_new_stream) + if (m_new_stream) delete mp_stream; } -const string ByteIO::GetBytes() +const string ByteIO::GetBytes() { return mp_stream->str(); } @@ -84,35 +84,35 @@ int ByteIO::GetSize() const void ByteIO::SetByteParams(const ByteIO& byte_io) { - mp_stream = byte_io.mp_stream; - m_current_byte = byte_io.m_current_byte; - m_current_pos = byte_io.m_current_pos; + mp_stream=byte_io.mp_stream; + m_current_byte=byte_io.m_current_byte; + m_current_pos=byte_io.m_current_pos; } //----------protected--------------------------------------------------------------- void ByteIO::ByteAlignInput() { - m_current_pos = 0; - m_current_byte = 0; + m_current_pos=0; + m_current_byte=0; } void ByteIO::ByteAlignOutput() { - if(m_current_pos != 0) + if(m_current_pos!=0) OutputCurrentByte(); } int ByteIO::ReadBit() { if(m_current_pos == CHAR_BIT) - m_current_pos = 0; + m_current_pos=0; - if(m_current_pos == 0) + if (m_current_pos == 0) m_current_byte = InputUnByte(); #if 1 // MSB to LSB - return GetBit(m_current_byte, (CHAR_BIT - 1 - m_current_pos++)); + return GetBit(m_current_byte, (CHAR_BIT-1-m_current_pos++)); #else // LSB to MSB return GetBit(m_current_byte, m_current_pos++); @@ -121,7 +121,7 @@ int ByteIO::ReadBit() int ByteIO::ReadBitB() { - if(m_bits_left) + if (m_bits_left) { --m_bits_left; return ReadBit(); @@ -143,7 +143,7 @@ bool ByteIO::ReadBoolB() unsigned int ByteIO::ReadNBits(int count) { unsigned int val = 0; - for(int i = 0; i < count; ++i) + for (int i = 0; i < count; ++i) { val <<= 1; val += ReadBit(); @@ -166,14 +166,14 @@ int ByteIO::ReadSint() int val = ReadUint(); bool bit; - //get the sign - if(val != 0) + //get the sign + if (val != 0) { bit = ReadBit(); - if(bit) + if (bit ) val = -val; } - return val; + return val; } int ByteIO::ReadSintB() @@ -182,24 +182,24 @@ int ByteIO::ReadSintB() int val = ReadUintB(); bool bit; - //get the sign - if(val != 0) + //get the sign + if (val != 0) { bit = ReadBitB(); - if(bit) + if (bit ) val = -val; } - return val; + return val; } unsigned int ByteIO::ReadUint() { unsigned int value = 1; - while(!ReadBit()) + while (!ReadBit()) { value <<= 1; - if(ReadBit()) - value += 1; + if (ReadBit()) + value +=1; } --value; return value; @@ -208,11 +208,11 @@ unsigned int ByteIO::ReadUint() unsigned int ByteIO::ReadUintB() { unsigned int value = 1; - while(!ReadBitB()) + while (!ReadBitB()) { value <<= 1; - if(ReadBitB()) - value += 1; + if (ReadBitB()) + value +=1; } --value; return value; @@ -223,21 +223,21 @@ void ByteIO::WriteBit(const bool& bit) if(bit) #if 1 // MSB to LSB - SetBit(m_current_byte, CHAR_BIT - 1 - m_current_pos); + SetBit(m_current_byte, CHAR_BIT-1-m_current_pos); #else // LSB to MSB SetBit(m_current_byte, m_current_pos); #endif - if(m_current_pos == CHAR_BIT - 1) - { + if ( m_current_pos == CHAR_BIT-1) + { // If a whole byte has been written, output to stream OutputCurrentByte(); m_current_byte = 0; m_current_pos = 0; - } + } else - // Shift mask to next bit in the output byte + // Shift mask to next bit in the output byte ++m_current_pos; } @@ -245,7 +245,7 @@ void ByteIO::WriteNBits(unsigned int val, int count) { do { - WriteBit(val & (1 << (count - 1))); + WriteBit(val & ( 1 << (count-1))); count--; } while(count > 0); @@ -253,7 +253,7 @@ void ByteIO::WriteNBits(unsigned int val, int count) int ByteIO::WriteNBits(unsigned int val) { - int nbits = static_cast(log(static_cast(val)) / log(2.0)) + 1; + int nbits = static_cast(log(static_cast(val))/log(2.0)) + 1; WriteNBits(val, nbits); return nbits; } @@ -265,24 +265,24 @@ void ByteIO::WriteSint(int val) WriteUint(value); //do sign - if(val < 0) WriteBit(1); - else if(val > 0) WriteBit(0); + if (val<0) WriteBit(1); + else if (val>0) WriteBit(0); } void ByteIO::WriteUint(unsigned int value) { - unsigned int val = value + 1; + unsigned int val = value+1; int num_follow_zeroes = 0; - while(val >= (1U << num_follow_zeroes)) + while (val >= (1U <= 0; --i) + for (int i=num_follow_zeroes-1; i>=0; --i) { WriteBit(BIT_ZERO); - WriteBit(val&(1 << i)); + WriteBit(val&(1<tellg(); - string data = mp_stream->str(); + string data=mp_stream->str(); data.erase(0, size); mp_stream->str(data); - m_num_bytes = data.size(); + m_num_bytes=data.size(); if(data.size()) - SeekGet(max(prev_pos - size, 0), ios_base::beg); + SeekGet(max(prev_pos-size, 0), ios_base::beg); } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.h index 806d98a55..db885d658 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.h @@ -53,371 +53,342 @@ namespace dirac { + + // BIT DEFS + #define BIT_ZERO 0 + #define BIT_ONE 1 + + // most significant bit in a character + #define MS_BIT (1 << (CHAR_BIT - 1)) + + /* array index for character containing bit */ + //#define BIT_IN_CHAR(bit) (1 << (CHAR_BIT-1-bit)) + #define BIT_IN_CHAR(bit) (1 << bit) + + + /** + * Class ByteIO - top-level class for reading/writing bytes to a stream + */ + class ByteIO + { + public: + + /** + * Default constructor + *@param new_stream Has Creates & owns data buffer + */ + ByteIO(bool new_stream=true); + + /** + * Constructor + *@param stream_data Copies data buffer details + */ + ByteIO(const ByteIO& stream_data); + + /** + * Destructor + */ + virtual ~ByteIO(); + + /** + * Gathers byte-stream statistics + *@param dirac_byte_stats Collates byte information + */ + virtual void CollateByteStats(DiracByteStats& dirac_byte_stats) + { dirac_byte_stats.Clear(); } + + /** + * Get bytes in Dirac-bytestream format + */ + virtual const std::string GetBytes(); + + /** + * Get position of read stream pointer + */ + int GetReadBytePosition() const { return mp_stream->tellg();}; + + + /** + *Gets size (in bytes) + */ + virtual int GetSize() const; + + /** + * Copies stream source/destination info + *@param byte_io Byte source/destination + */ + void SetByteParams(const ByteIO& byte_io); + + /** + * Sync input for byte-alignment + */ + void ByteAlignOutput(); + + /** + * Ouputs an unsigned integer in interleaved exp Golomb format + *@param value Integer to be output + */ + //void OutputVarLengthUint(const unsigned int& value); + void WriteUint(unsigned int value); + + /** + * Sets input size in bits. Read is limited by this + */ + void SetBitsLeft(int left_bits) { m_bits_left = left_bits; } + + /** + * Sets input size in bits. Read is limited by this + */ + int BitsLeft(void) { return m_bits_left; } + + protected: + + inline bool CanRead() const { return(!mp_stream->eof()); } + + inline bool GetBit(unsigned char& c, int pos) const { return (c & BIT_IN_CHAR(pos)); } + + inline void SetBit(unsigned char& c, int pos) const { c |= BIT_IN_CHAR(pos); } + + inline void SetBits(unsigned char& c, unsigned char bits) const { c |= bits; } + + /** + * Sync input for byte-alignment + */ + void ByteAlignInput(); + + + /** + * Reads boolean value + */ + bool ReadBool(); + + /** + * Reads boolean value - bounded i/o + */ + bool ReadBoolB(); + + /** + * Reads next bit + */ + int ReadBit(); + + /** + * Reads next bit - bounded i/o + */ + int ReadBitB(); + + /** + * Reads next 'count' bits + *@param count number of bits to be read + *@return unsigned interger read + */ + unsigned int ReadNBits(int count); + + /** + * Reads from stream + *@param data Start of char buffer + *@param count Number of bytes to read + */ + void InputBytes(char* data, int count) + { + //int j=mp_stream->tellg(); + mp_stream->read(data, count); -// BIT DEFS -#define BIT_ZERO 0 -#define BIT_ONE 1 - -// most significant bit in a character -#define MS_BIT (1 << (CHAR_BIT - 1)) - -/* array index for character containing bit */ -//#define BIT_IN_CHAR(bit) (1 << (CHAR_BIT-1-bit)) -#define BIT_IN_CHAR(bit) (1 << bit) - + //int h=mp_stream->tellg(); + } -/** -* Class ByteIO - top-level class for reading/writing bytes to a stream -*/ -class ByteIO -{ -public: - - /** - * Default constructor - *@param new_stream Has Creates & owns data buffer - */ - ByteIO(bool new_stream = true); - - /** - * Constructor - *@param stream_data Copies data buffer details - */ - ByteIO(const ByteIO& stream_data); - - /** - * Destructor - */ - virtual ~ByteIO(); - - /** - * Gathers byte-stream statistics - *@param dirac_byte_stats Collates byte information - */ - virtual void CollateByteStats(DiracByteStats& dirac_byte_stats) - { - dirac_byte_stats.Clear(); - } - - /** - * Get bytes in Dirac-bytestream format - */ - virtual const std::string GetBytes(); - - /** - * Get position of read stream pointer - */ - int GetReadBytePosition() const - { - return mp_stream->tellg(); - }; - - - /** - *Gets size (in bytes) - */ - virtual int GetSize() const; - - /** - * Copies stream source/destination info - *@param byte_io Byte source/destination - */ - void SetByteParams(const ByteIO& byte_io); - - /** - * Sync input for byte-alignment - */ - void ByteAlignOutput(); - - /** - * Ouputs an unsigned integer in interleaved exp Golomb format - *@param value Integer to be output - */ - //void OutputVarLengthUint(const unsigned int& value); - void WriteUint(unsigned int value); - - /** - * Sets input size in bits. Read is limited by this - */ - void SetBitsLeft(int left_bits) - { - m_bits_left = left_bits; - } - - /** - * Sets input size in bits. Read is limited by this - */ - int BitsLeft(void) - { - return m_bits_left; - } - -protected: - - inline bool CanRead() const - { - return(!mp_stream->eof()); - } - - inline bool GetBit(unsigned char& c, int pos) const - { - return (c & BIT_IN_CHAR(pos)); - } - - inline void SetBit(unsigned char& c, int pos) const - { - c |= BIT_IN_CHAR(pos); - } - - inline void SetBits(unsigned char& c, unsigned char bits) const - { - c |= bits; - } - - /** - * Sync input for byte-alignment - */ - void ByteAlignInput(); - - - /** - * Reads boolean value - */ - bool ReadBool(); - - /** - * Reads boolean value - bounded i/o - */ - bool ReadBoolB(); - - /** - * Reads next bit - */ - int ReadBit(); - - /** - * Reads next bit - bounded i/o - */ - int ReadBitB(); - - /** - * Reads next 'count' bits - *@param count number of bits to be read - *@return unsigned interger read - */ - unsigned int ReadNBits(int count); - - /** - * Reads from stream - *@param data Start of char buffer - *@param count Number of bytes to read - */ - void InputBytes(char* data, int count) - { - //int j=mp_stream->tellg(); - mp_stream->read(data, count); - - //int h=mp_stream->tellg(); - } - - /** - * Flushes the bounde input - */ - void FlushInputB(); - - /** - * Reads a signed integer in interleaved exp-Golomb format - *return Signed integer read - */ - //int InputVarLengthInt(); - int ReadSint(); - - /** - * Reads a signed integer in interleaved exp-Golomb format from bounded input - *return Signed integer read - */ - int ReadSintB(); - - /** - * Reads an unsigned integer in interleaved exp Golomb format - *@return Unsigned Integer read - */ - //unsigned int InputVarLengthUint(); - unsigned int ReadUint(); - - /** - * Reads an unsigned integer in interleaved exp Golomb format from bounded input - *@return Unsigned Integer read - */ - //unsigned int InputVarLengthUint(); - unsigned int ReadUintB(); - - /** - * Reads a fixed length unsigned integer from the stream in big endian - *@param byte_size Number of bytes in fixed length integer - *@return Unsigned Integer read - */ - //inline unsigned int InputFixedLengthUint(const int byte_size) { - inline unsigned int ReadUintLit(const int byte_size) - { - unsigned int val = 0; - for(int i = 0; i < byte_size; ++i) + /** + * Flushes the bounde input + */ + void FlushInputB(); + + /** + * Reads a signed integer in interleaved exp-Golomb format + *return Signed integer read + */ + //int InputVarLengthInt(); + int ReadSint(); + + /** + * Reads a signed integer in interleaved exp-Golomb format from bounded input + *return Signed integer read + */ + int ReadSintB(); + + /** + * Reads an unsigned integer in interleaved exp Golomb format + *@return Unsigned Integer read + */ + //unsigned int InputVarLengthUint(); + unsigned int ReadUint(); + + /** + * Reads an unsigned integer in interleaved exp Golomb format from bounded input + *@return Unsigned Integer read + */ + //unsigned int InputVarLengthUint(); + unsigned int ReadUintB(); + + /** + * Reads a fixed length unsigned integer from the stream in big endian + *@param byte_size Number of bytes in fixed length integer + *@return Unsigned Integer read + */ + //inline unsigned int InputFixedLengthUint(const int byte_size) { + inline unsigned int ReadUintLit(const int byte_size) { + unsigned int val=0; + for(int i=0; i < byte_size; ++i) + { + val <<= 8; + val += (unsigned char)mp_stream->get(); + } + m_num_bytes+=byte_size; + return val; + } + + /** + * Reads a byte from the stream + */ + inline unsigned char InputUnByte() {m_num_bytes++ ; return mp_stream->get(); } + + /** + * Reads a series of bytes from a stream + */ + inline std::string InputUnString(const int count) { - val <<= 8; - val += (unsigned char)mp_stream->get(); + std::string str; + for(int index=0; index < count; ++index) + str.push_back(InputUnByte()); + return str; } - m_num_bytes += byte_size; - return val; - } - - /** - * Reads a byte from the stream - */ - inline unsigned char InputUnByte() - { - m_num_bytes++ ; - return mp_stream->get(); - } - - /** - * Reads a series of bytes from a stream - */ - inline std::string InputUnString(const int count) - { - std::string str; - for(int index = 0; index < count; ++index) - str.push_back(InputUnByte()); - return str; - } - - /** - * Outputs a bit - *@param bit 1/0 Output - */ - void WriteBit(const bool& bit); - - /** - * Outputs an unsigned integer - *@param val Integer to be output - *@return number of bits written - */ - int WriteNBits(unsigned int val); - - /** - * Outputs an n bit integer - *@param val Unsigned Integer to be output - *@param count number of bits to be written - */ - void WriteNBits(unsigned int val, int count); - - - - /** - * Outputs a series of bytes - */ - void OutputBytes(const std::string& bytes) - { - int cur_pos = mp_stream->tellg(); - mp_stream->str(mp_stream->str() + bytes); - m_num_bytes += bytes.size(); + + /** + * Outputs a bit + *@param bit 1/0 Output + */ + void WriteBit(const bool& bit); + + /** + * Outputs an unsigned integer + *@param val Integer to be output + *@return number of bits written + */ + int WriteNBits(unsigned int val); + + /** + * Outputs an n bit integer + *@param val Unsigned Integer to be output + *@param count number of bits to be written + */ + void WriteNBits(unsigned int val, int count); + + + + /** + * Outputs a series of bytes + */ + void OutputBytes(const std::string& bytes) { + int cur_pos = mp_stream->tellg(); + mp_stream->str(mp_stream->str()+bytes); + m_num_bytes+=bytes.size(); // *mp_stream << bytes; - mp_stream->seekg(std::max(cur_pos, 0), std::ios_base::beg); - } - - /** - * Outputs current byte contents - */ - inline void OutputCurrentByte() - { - if(m_current_pos) - { - *mp_stream << (m_current_byte); - ++m_num_bytes; - m_current_pos = 0; - m_current_byte = 0; + mp_stream->seekg(std::max(cur_pos,0), std::ios_base::beg); } - }; - - /** - * Outputs an integer in Golomb signed integer format - *@param val Integer to be output - */ - //void OutputVarLengthInt(const int val); - void WriteSint(int val); - - /** - * Output unsigned int value in big endian format - * @param value Integer to be output - * @param length number of bytes in val to output - */ - //inline void OutputFixedLengthUint(const unsigned int& value, const int& length) - inline void WriteUintLit(const unsigned int& value, const int& length) - { - for(int i = length - 1; i >= 0 ; --i) + + /** + * Outputs current byte contents + */ + inline void OutputCurrentByte() { - unsigned char cp = (value >> (i * 8)) & 0xff; - *mp_stream << cp; - } - m_num_bytes += length; - } - - /** - * Removes portion of byte-stream no longer required - *@param count Number of bytes to be removed from beginning of stream - */ - void RemoveRedundantBytes(const int count); - - inline void SeekGet(const int offset, std::ios_base::seekdir dir) - { - mp_stream->seekg(offset, dir); - } - - /** - * Input/output steam - */ - std::stringstream* mp_stream; - - -private: - - /** - * ArithCodec can see internals for getting/setting bits - */ - friend class ArithCodecBase; - - /** - * VLC entropy coder can see internals for getting/setting bits - */ - friend class ArithCodecToVLCAdapter; - - /** - * Char used for temporary storage of op data bits - */ - unsigned char m_current_byte; - - /** - * Used to set individual bit within the current header byte - */ - int m_current_pos; - - /** - * Number of bytes processed - */ - int m_num_bytes; - - /** - * stream alloc flag - */ - bool m_new_stream; - - /** - * num bits left to read - */ - int m_bits_left; -protected: - - -}; + if (m_current_pos) + { + *mp_stream << (m_current_byte); + ++m_num_bytes; + m_current_pos = 0; + m_current_byte = 0; + } + }; + + /** + * Outputs an integer in Golomb signed integer format + *@param val Integer to be output + */ + //void OutputVarLengthInt(const int val); + void WriteSint(int val); + + /** + * Output unsigned int value in big endian format + * @param value Integer to be output + * @param length number of bytes in val to output + */ + //inline void OutputFixedLengthUint(const unsigned int& value, const int& length) + inline void WriteUintLit(const unsigned int& value, const int& length) + { + for(int i=length-1; i >=0 ; --i) + { + unsigned char cp = (value>>(i*8))&0xff; + *mp_stream << cp; + } + m_num_bytes+=length; + } + + /** + * Removes portion of byte-stream no longer required + *@param count Number of bytes to be removed from beginning of stream + */ + void RemoveRedundantBytes(const int count); + + inline void SeekGet(const int offset, std::ios_base::seekdir dir) + { + mp_stream->seekg(offset, dir); + } + + /** + * Input/output steam + */ + std::stringstream* mp_stream; + + + private: + + /** + * ArithCodec can see internals for getting/setting bits + */ + friend class ArithCodecBase; + + /** + * VLC entropy coder can see internals for getting/setting bits + */ + friend class ArithCodecToVLCAdapter; + + /** + * Char used for temporary storage of op data bits + */ + unsigned char m_current_byte; + + /** + * Used to set individual bit within the current header byte + */ + int m_current_pos; + + /** + * Number of bytes processed + */ + int m_num_bytes; + + /** + * stream alloc flag + */ + bool m_new_stream; + + /** + * num bits left to read + */ + int m_bits_left; + protected: + + + }; diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.cpp index 69875e31b..7326b4562 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.cpp @@ -42,13 +42,13 @@ using namespace dirac; CodingParamsByteIO::CodingParamsByteIO(const SourceParams& src_params, - CodecParams& codec_params, - const SourceParams& default_source_params, - const ByteIO& stream_data): - ByteIO(stream_data), - m_src_params(src_params), - m_codec_params(codec_params), - m_default_source_params(default_source_params) + CodecParams& codec_params, + const SourceParams& default_source_params, + const ByteIO& stream_data): +ByteIO(stream_data), +m_src_params(src_params), +m_codec_params(codec_params), +m_default_source_params(default_source_params) { } @@ -75,22 +75,22 @@ void CodingParamsByteIO::Input() // If source was coded as fields, halve the vertical dimensions // to set them to field dimensions - if(m_codec_params.FieldCoding()) + if (m_codec_params.FieldCoding()) { - m_codec_params.SetYl(m_codec_params.Yl() >> 1); - m_codec_params.SetChromaYl(m_codec_params.ChromaYl() >> 1); + m_codec_params.SetYl(m_codec_params.Yl()>>1); + m_codec_params.SetChromaYl(m_codec_params.ChromaYl()>>1); } unsigned int luma_depth = static_cast - ( - std::log((double)m_src_params.LumaExcursion()) / std::log(2.0) + 1 - ); + ( + std::log((double)m_src_params.LumaExcursion())/std::log(2.0) + 1 + ); m_codec_params.SetLumaDepth(luma_depth); unsigned int chroma_depth = static_cast - ( - std::log((double)m_src_params.ChromaExcursion()) / std::log(2.0) + 1 - ); + ( + std::log((double)m_src_params.ChromaExcursion())/std::log(2.0) + 1 + ); m_codec_params.SetChromaDepth(chroma_depth); // byte align @@ -112,7 +112,7 @@ void CodingParamsByteIO::Output() void CodingParamsByteIO::InputPictureCodingMode() { unsigned int coding_mode = ReadUint(); - if(coding_mode > 1) + if (coding_mode > 1) { std::ostringstream errstr; errstr << "Picture coding mode " << coding_mode diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.h index 05b512df8..b96b037a0 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.h @@ -51,83 +51,83 @@ namespace dirac { - -/** -* Represents compressed sequence-parameter data used in an AccessUnit -*/ -class CodingParamsByteIO : public ByteIO -{ -public: - - /** - * Constructor - *@param src_params Source parameters - *@param codec_params Coding parameters - *@param default_source_params Default source parameters - *@param stream_data Source/Destination of data - */ - CodingParamsByteIO(const SourceParams& src_params, - CodecParams& codec_params, - const SourceParams& default_source_params, - const ByteIO& stream_data); - - - /** - * Destructor - */ - ~CodingParamsByteIO(); - - /** - * Reads sequence information from Dirac byte-format - */ - void Input(); - - /** - * Outputs sequence information to Dirac byte-format - */ - void Output(); - -protected: - - -private: - - /** - * Reads number of bits used to compress input signal - */ - void InputVideoDepth(); - - /** - * Reads picture coding mode - 0 - frames, 1 - fields - */ - void InputPictureCodingMode(); - - /** - * Outputs number of bits used to compress input signal - */ - void OutputVideoDepth(); - + /** - * Outputs how input was coded - i.e. frames or fields + * Represents compressed sequence-parameter data used in an AccessUnit */ - void OutputPictureCodingMode(); - - /** - * Source paramters for intput/output - */ - const SourceParams& m_src_params; - - /** - * Coding paramters for intput/output - */ - CodecParams& m_codec_params; - - /** - * Default source parameters - */ - const SourceParams& m_default_source_params; - -}; + class CodingParamsByteIO : public ByteIO + { + public: + + /** + * Constructor + *@param src_params Source parameters + *@param codec_params Coding parameters + *@param default_source_params Default source parameters + *@param stream_data Source/Destination of data + */ + CodingParamsByteIO(const SourceParams& src_params, + CodecParams& codec_params, + const SourceParams& default_source_params, + const ByteIO& stream_data); + + + /** + * Destructor + */ + ~CodingParamsByteIO(); + + /** + * Reads sequence information from Dirac byte-format + */ + void Input(); + + /** + * Outputs sequence information to Dirac byte-format + */ + void Output(); + + protected: + + + private: + + /** + * Reads number of bits used to compress input signal + */ + void InputVideoDepth(); + + /** + * Reads picture coding mode - 0 - frames, 1 - fields + */ + void InputPictureCodingMode(); + + /** + * Outputs number of bits used to compress input signal + */ + void OutputVideoDepth(); + + /** + * Outputs how input was coded - i.e. frames or fields + */ + void OutputPictureCodingMode(); + + /** + * Source paramters for intput/output + */ + const SourceParams& m_src_params; + + /** + * Coding paramters for intput/output + */ + CodecParams& m_codec_params; + + /** + * Default source parameters + */ + const SourceParams& m_default_source_params; + + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.cpp index 88a63811a..07f5433d1 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.cpp @@ -42,13 +42,13 @@ using namespace std; ComponentByteIO::ComponentByteIO(CompSort cs, const ByteIO& byteio): - ByteIO(byteio), - m_compsort(cs) +ByteIO(byteio), +m_compsort(cs) {} ComponentByteIO::ComponentByteIO(CompSort cs): - ByteIO(), - m_compsort(cs) +ByteIO(), +m_compsort(cs) {} ComponentByteIO::~ComponentByteIO() @@ -83,16 +83,16 @@ void ComponentByteIO::CollateByteStats(DiracByteStats& dirac_byte_stats) bool ComponentByteIO::Input() { - - return true; + + return true; } void ComponentByteIO::Output() { - + } //-------------private------------------------------------------------------- - + diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.h index 03ee2f1ea..e80b0877a 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.h @@ -52,73 +52,73 @@ namespace dirac { -/** -* Picture component in Dirac bytestream format -*/ -class ComponentByteIO : public ByteIO -{ -public: - - /** - * Constructor - *@param cs Picture-component type - *@param byteIO Input/output Byte stream - */ - ComponentByteIO(CompSort cs, - const ByteIO& byteIO); - - /** - * Constructor - *@param cs Picture-component type - */ - ComponentByteIO(CompSort cs); - /** - * Destructor + * Picture component in Dirac bytestream format */ - ~ComponentByteIO(); - - /** - * Gathers byte stats on the component data - *@param dirac_byte_stats Stat container - */ - void CollateByteStats(DiracByteStats& dirac_byte_stats); - - /** - * Add a subband byte-stream to this component - *@param p_subband_byteio Subband to be added - */ - void AddSubband(SubbandByteIO *p_subband_byteio); - - /** - * Inputs data from Dirac stream-format - */ - bool Input(); - - /** - * Outputs picture values to Dirac stream-format - */ - void Output(); - - - -protected: - - -private: - - /** - * Picture component type - */ - CompSort m_compsort; - - /** - * List of subbands in output/input order - */ - std::vector m_subband_list; - - -}; + class ComponentByteIO : public ByteIO + { + public: + + /** + * Constructor + *@param cs Picture-component type + *@param byteIO Input/output Byte stream + */ + ComponentByteIO(CompSort cs, + const ByteIO& byteIO); + + /** + * Constructor + *@param cs Picture-component type + */ + ComponentByteIO(CompSort cs); + + /** + * Destructor + */ + ~ComponentByteIO(); + + /** + * Gathers byte stats on the component data + *@param dirac_byte_stats Stat container + */ + void CollateByteStats(DiracByteStats& dirac_byte_stats); + + /** + * Add a subband byte-stream to this component + *@param p_subband_byteio Subband to be added + */ + void AddSubband(SubbandByteIO *p_subband_byteio); + + /** + * Inputs data from Dirac stream-format + */ + bool Input(); + + /** + * Outputs picture values to Dirac stream-format + */ + void Output(); + + + + protected: + + + private: + + /** + * Picture component type + */ + CompSort m_compsort; + + /** + * List of subbands in output/input order + */ + std::vector m_subband_list; + + + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.cpp index 883badb14..9c697bc3d 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.cpp @@ -46,7 +46,7 @@ DiracByteStats::DiracByteStats() } DiracByteStats::DiracByteStats(const DiracByteStats& dirac_byte_stats): - m_byte_count(dirac_byte_stats.m_byte_count) +m_byte_count(dirac_byte_stats.m_byte_count) { } @@ -60,25 +60,25 @@ void DiracByteStats::Clear() m_byte_count.clear(); } -int64_t DiracByteStats::GetBitCount(const StatType& stat_type) const +int64_t DiracByteStats::GetBitCount(const StatType& stat_type) const { return GetByteCount(stat_type) * CHAR_BIT; } int64_t DiracByteStats::GetByteCount(const StatType& stat_type) const { - std::map::const_iterator it; - it = m_byte_count.find(stat_type); - if(it == m_byte_count.end()) - return 0; + std::map::const_iterator it; + it = m_byte_count.find(stat_type); + if(it==m_byte_count.end()) + return 0; - return it->second; + return it->second; } void DiracByteStats::SetByteCount(const StatType& stat_type, int64_t count) { - if(m_byte_count.find(stat_type) == m_byte_count.end()) - m_byte_count[stat_type] = 0; + if(m_byte_count.find(stat_type)==m_byte_count.end()) + m_byte_count[stat_type]=0; - m_byte_count[stat_type] += count; -} + m_byte_count[stat_type]+=count; + } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.h index d32635a2a..0da273f0a 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.h @@ -50,71 +50,70 @@ namespace dirac { -#ifdef _MSC_VER -// char length -#define CHAR_BIT 8 + #ifdef _MSC_VER + // char length + #define CHAR_BIT 8 #endif -typedef enum -{ - STAT_TOTAL_BYTE_COUNT = 0, - STAT_MV_BYTE_COUNT, - STAT_YCOMP_BYTE_COUNT, - STAT_UCOMP_BYTE_COUNT, - STAT_VCOMP_BYTE_COUNT -} StatType; - - -/** -* Class DiracByteStats - for collecting statistics on aspects of the Dirac byte-stream -*/ -class DiracByteStats -{ -public: - /** - * Constructor - */ - DiracByteStats(); - - /** - * Copy constructor - */ - DiracByteStats(const DiracByteStats& dirac_byte_stats); - - /** - * Destructor - */ - ~DiracByteStats(); - - /** - * Clears data - */ - void Clear(); - - /** - * Gets number of bits for a particular stat-type - */ - int64_t GetBitCount(const StatType& stat_type) const; - - /** - * Gets number of bytes for a particular stat-type - */ - int64_t GetByteCount(const StatType& stat_type) const; - - /** - * Sets number of bytes for a particular stat-type - */ - void SetByteCount(const StatType& stat_type, int64_t count); - - -private: - - /** - * Map of byte-counts - */ - std::map m_byte_count; - -}; + typedef enum { + STAT_TOTAL_BYTE_COUNT=0, + STAT_MV_BYTE_COUNT, + STAT_YCOMP_BYTE_COUNT, + STAT_UCOMP_BYTE_COUNT, + STAT_VCOMP_BYTE_COUNT + } StatType; + + + /** + * Class DiracByteStats - for collecting statistics on aspects of the Dirac byte-stream + */ + class DiracByteStats + { + public: + /** + * Constructor + */ + DiracByteStats(); + + /** + * Copy constructor + */ + DiracByteStats(const DiracByteStats& dirac_byte_stats); + + /** + * Destructor + */ + ~DiracByteStats(); + + /** + * Clears data + */ + void Clear(); + + /** + * Gets number of bits for a particular stat-type + */ + int64_t GetBitCount(const StatType& stat_type) const; + + /** + * Gets number of bytes for a particular stat-type + */ + int64_t GetByteCount(const StatType& stat_type) const; + + /** + * Sets number of bytes for a particular stat-type + */ + void SetByteCount(const StatType& stat_type, int64_t count); + + + private: + + /** + * Map of byte-counts + */ + std::map m_byte_count; + + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stream.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stream.cpp index b31e8de47..a45e54706 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stream.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stream.cpp @@ -44,8 +44,8 @@ using namespace dirac; using namespace std; DiracByteStream::DiracByteStream(): - ByteIO(), - mp_prev_parse_unit(NULL) +ByteIO(), +mp_prev_parse_unit(NULL) { } @@ -86,29 +86,29 @@ void DiracByteStream::Reset(ParseUnitByteIO* p_curr_unit, int pos) ParseUnitByteIO* DiracByteStream::GetNextParseUnit() { - if(GetSize() == 0) + if(GetSize()==0) return NULL; - int pos = 0; + int pos=0; if(mp_prev_parse_unit) { // remove the unwanted bytes associated with the previous parse-unit int prev_offset = mp_prev_parse_unit->GetNextParseOffset(); RemoveRedundantBytes(prev_offset ? prev_offset : mp_prev_parse_unit->GetSize()); delete mp_prev_parse_unit; - mp_prev_parse_unit = NULL; + mp_prev_parse_unit=NULL; if(!GetSize()) return NULL; } - ParseUnitByteIO* p_curr_unit = NULL; + ParseUnitByteIO* p_curr_unit=NULL; while(true) { pos = GetReadBytePosition(); p_curr_unit = new ParseUnitByteIO(*this); - if(!p_curr_unit->Input()) + if (!p_curr_unit->Input()) { Reset(p_curr_unit, pos); return NULL; @@ -121,7 +121,7 @@ ParseUnitByteIO* DiracByteStream::GetNextParseUnit() return NULL; } - if(p_curr_unit->IsEndOfSequence()) + if (p_curr_unit->IsEndOfSequence()) { break; } @@ -140,15 +140,15 @@ ParseUnitByteIO* DiracByteStream::GetNextParseUnit() } // while // Remove all redundant bytes that are not part of a parse unit - int remove_size = std::max(0, GetReadBytePosition() - p_curr_unit->GetSize()); - if(remove_size) + int remove_size = std::max (0, GetReadBytePosition()-p_curr_unit->GetSize()); + if (remove_size) { - //std::cerr << "Size="< 1) + if (source_sampling > 1) { std::ostringstream errstr; errstr << "Source Sampling " << source_sampling @@ -279,25 +279,25 @@ void SourceParamsByteIO::InputSignalRange() // read index value int signal_range_index = ReadUint(); SignalRangeType signal_range = IntToSignalRangeType(signal_range_index); - if(signal_range == SIGNAL_RANGE_UNDEFINED) + if(signal_range==SIGNAL_RANGE_UNDEFINED) DIRAC_THROW_EXCEPTION( - ERR_INVALID_SIGNAL_RANGE, - "Dirac does not recognise the specified signal-range", - SEVERITY_ACCESSUNIT_ERROR) + ERR_INVALID_SIGNAL_RANGE, + "Dirac does not recognise the specified signal-range", + SEVERITY_ACCESSUNIT_ERROR) - if(signal_range_index != SIGNAL_RANGE_CUSTOM) - { - m_src_params.SetSignalRange(signal_range); - } - else - { - // read luma values - m_src_params.SetLumaOffset(ReadUint()); - m_src_params.SetLumaExcursion(ReadUint()); - // read chroma values - m_src_params.SetChromaOffset(ReadUint()); - m_src_params.SetChromaExcursion(ReadUint()); - } + if(signal_range_index!=SIGNAL_RANGE_CUSTOM) + { + m_src_params.SetSignalRange(signal_range); + } + else + { + // read luma values + m_src_params.SetLumaOffset( ReadUint() ); + m_src_params.SetLumaExcursion( ReadUint() ); + // read chroma values + m_src_params.SetChromaOffset( ReadUint() ); + m_src_params.SetChromaExcursion( ReadUint() ); + } } void SourceParamsByteIO::InputTransferFunction() @@ -315,8 +315,8 @@ void SourceParamsByteIO::OutputFrameSize() { // output 'is custom' dimensions flag - bool is_custom = (m_src_params.Xl() != m_default_src_params.Xl() || - m_src_params.Yl() != m_default_src_params.Yl()); + bool is_custom = (m_src_params.Xl()!=m_default_src_params.Xl() || + m_src_params.Yl()!=m_default_src_params.Yl()); WriteBit(is_custom); @@ -332,8 +332,8 @@ void SourceParamsByteIO::OutputFrameSize() void SourceParamsByteIO::OutputChromaSamplingFormat() { // output 'is default' flag - bool not_default = m_src_params.CFormat() != m_default_src_params.CFormat(); - + bool not_default = m_src_params.CFormat()!=m_default_src_params.CFormat(); + WriteBit(not_default); if(!not_default) @@ -346,20 +346,20 @@ void SourceParamsByteIO::OutputChromaSamplingFormat() void SourceParamsByteIO::OutputPixelAspectRatio() { - if(m_src_params.PixelAspectRatioIndex() != PIXEL_ASPECT_RATIO_CUSTOM - && m_src_params.PixelAspectRatioIndex() == m_default_src_params.PixelAspectRatioIndex()) + if (m_src_params.PixelAspectRatioIndex()!= PIXEL_ASPECT_RATIO_CUSTOM + && m_src_params.PixelAspectRatioIndex() == m_default_src_params.PixelAspectRatioIndex()) { // default frame rate index WriteBit(0); return; } // Non-defaults - WriteBit(1); + WriteBit(1); // Picture rate index WriteUint(m_src_params.PixelAspectRatioIndex()); - - if(!m_src_params.PixelAspectRatioIndex()) // i,e. custom value + + if (!m_src_params.PixelAspectRatioIndex()) // i,e. custom value { WriteUint(m_src_params.PixelAspectRatio().m_num); WriteUint(m_src_params.PixelAspectRatio().m_denom); @@ -369,10 +369,10 @@ void SourceParamsByteIO::OutputPixelAspectRatio() void SourceParamsByteIO::OutputCleanArea() { - if(m_src_params.CleanWidth() != m_default_src_params.CleanWidth() || - m_src_params.CleanHeight() != m_default_src_params.CleanHeight() || - m_src_params.LeftOffset() != m_default_src_params.LeftOffset() || - m_src_params.TopOffset() != m_default_src_params.TopOffset()) + if (m_src_params.CleanWidth() != m_default_src_params.CleanWidth() || + m_src_params.CleanHeight() != m_default_src_params.CleanHeight() || + m_src_params.LeftOffset() != m_default_src_params.LeftOffset() || + m_src_params.TopOffset() != m_default_src_params.TopOffset()) { WriteBit(1); // non-default value WriteUint(m_src_params.CleanWidth()); @@ -386,9 +386,9 @@ void SourceParamsByteIO::OutputCleanArea() void SourceParamsByteIO::OutputColourSpecification() { - if(m_src_params.ColourSpecificationIndex() && - m_src_params.ColourSpecificationIndex() == - m_default_src_params.ColourSpecificationIndex()) + if (m_src_params.ColourSpecificationIndex() && + m_src_params.ColourSpecificationIndex() == + m_default_src_params.ColourSpecificationIndex()) { // default colour specification WriteBit(0); @@ -396,14 +396,14 @@ void SourceParamsByteIO::OutputColourSpecification() } // Non-defaults - WriteBit(1); + WriteBit(1); // Output Colour specification index WriteUint(m_src_params.ColourSpecificationIndex()); - if(!m_src_params.ColourSpecificationIndex()) // i,e, custom values + if (!m_src_params.ColourSpecificationIndex()) // i,e, custom values { // Output Colour Primaries - if(m_src_params.ColourPrimariesIndex() == m_default_src_params.ColourPrimariesIndex()) + if (m_src_params.ColourPrimariesIndex() == m_default_src_params.ColourPrimariesIndex()) { // default value WriteBit(0); @@ -415,7 +415,7 @@ void SourceParamsByteIO::OutputColourSpecification() } // Output Colour Matrix - if(m_src_params.ColourMatrixIndex() == m_default_src_params.ColourMatrixIndex()) + if (m_src_params.ColourMatrixIndex() == m_default_src_params.ColourMatrixIndex()) { // default value WriteBit(0); @@ -427,7 +427,7 @@ void SourceParamsByteIO::OutputColourSpecification() } // Output TransferFunction - if(m_src_params.TransferFunctionIndex() == m_default_src_params.TransferFunctionIndex()) + if (m_src_params.TransferFunctionIndex() == m_default_src_params.TransferFunctionIndex()) { // default value WriteBit(0); @@ -442,20 +442,20 @@ void SourceParamsByteIO::OutputColourSpecification() void SourceParamsByteIO::OutputFrameRate() { - if(m_src_params.FrameRateIndex() != FRAMERATE_CUSTOM - && m_src_params.FrameRateIndex() == m_default_src_params.FrameRateIndex()) + if (m_src_params.FrameRateIndex()!=FRAMERATE_CUSTOM + && m_src_params.FrameRateIndex() == m_default_src_params.FrameRateIndex()) { // default frame rate index WriteBit(0); return; } // Non-defaults - WriteBit(1); + WriteBit(1); // Picture rate index WriteUint(m_src_params.FrameRateIndex()); - - if(!m_src_params.FrameRateIndex()) // i,e. custom value + + if (!m_src_params.FrameRateIndex()) // i,e. custom value { WriteUint(m_src_params.FrameRate().m_num); WriteUint(m_src_params.FrameRate().m_denom); @@ -465,8 +465,8 @@ void SourceParamsByteIO::OutputFrameRate() void SourceParamsByteIO::OutputScanFormat() { // output 'is default' flag - bool not_interlace_default = m_src_params.SourceSampling() != m_default_src_params.SourceSampling(); - + bool not_interlace_default = m_src_params.SourceSampling()!=m_default_src_params.SourceSampling(); + WriteBit(not_interlace_default); if(!not_interlace_default) @@ -479,20 +479,20 @@ void SourceParamsByteIO::OutputScanFormat() void SourceParamsByteIO::OutputSignalRange() { - if(m_src_params.SignalRangeIndex() != SIGNAL_RANGE_CUSTOM && - m_src_params.SignalRangeIndex() == m_default_src_params.SignalRangeIndex()) + if (m_src_params.SignalRangeIndex()!=SIGNAL_RANGE_CUSTOM && + m_src_params.SignalRangeIndex() == m_default_src_params.SignalRangeIndex()) { // defaults WriteBit(0); return; } - + // Non-defaults - WriteBit(1); + WriteBit(1); // Output Signal Range Index WriteUint(m_src_params.SignalRangeIndex()); - if(!m_src_params.SignalRangeIndex()) // i.e. custom values + if (!m_src_params.SignalRangeIndex()) // i.e. custom values { WriteUint(m_src_params.LumaOffset()); WriteUint(m_src_params.LumaExcursion()); diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/displayparams_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/displayparams_byteio.h index 12cf7cec6..bc5fe823d 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/displayparams_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/displayparams_byteio.h @@ -51,148 +51,148 @@ namespace dirac { - -/** -* Represents compressed source-parameter data contained in a sequence header -*/ -class SourceParamsByteIO : public ByteIO -{ -public: - - /** - * Constructor for Input/Output - *@param src_params Source parameters - *@param default_src_params Default Source parameters - *@param stream_data Source/Destination of data - */ - SourceParamsByteIO(SourceParams& src_params, - const SourceParams& default_src_params, - const ByteIO& stream_data); - /** - * Destructor - */ - ~SourceParamsByteIO(); - - /** - * Reads source params information from Dirac byte-format - */ - void Input(); - - /** - * Outputs source params information to Dirac byte-format - */ - void Output(); - -protected: - - -private: - - /** - * Reads frame dimensions - */ - void InputFrameSize(); - - /** - * Reads Chroma Sampling Format - */ - void InputChromaSamplingFormat(); - - /** - * Reads pixel aspect ratio info - */ - void InputPixelAspectRatio(); - - /** - * Reads clean-area info - */ - void InputCleanArea(); - - /** - * Reads colour-matrix info - */ - void InputColourMatrix(); - - /** - * Reads primary-colour info - */ - void InputColourPrimaries(); - - /** - * Reads colour spec info - */ - void InputColourSpecification(); - - /** - * Reads frame-rate info - */ - void InputFrameRate(); - - /** - * Reads Scan info - */ - void InputScanFormat(); - - /** - * Reads signal range info - */ - void InputSignalRange(); - - /** - * Reads transfer-function info - */ - void InputTransferFunction(); - - /** - * Outputs frame dimensions - */ - void OutputFrameSize(); - - /** - * Outputs Chroma Sampling Format - */ - void OutputChromaSamplingFormat(); - - /** - * Outputs pixel aspect ratio info - */ - void OutputPixelAspectRatio(); - - /** - * Outputs clean-area info - */ - void OutputCleanArea(); - - /** - * Outputs colour spec info - */ - void OutputColourSpecification(); - - /** - * Outputs frame-rate info - */ - void OutputFrameRate(); - - /** - * Outputs Scan info - */ - void OutputScanFormat(); - - /** - * Outputs signal range info - */ - void OutputSignalRange(); - - /** - * Source parameters for input/ouput - */ - SourceParams& m_src_params; - - /** - * Default source parameters - */ - const SourceParams& m_default_src_params; -}; + + /** + * Represents compressed source-parameter data contained in a sequence header + */ + class SourceParamsByteIO : public ByteIO + { + public: + + /** + * Constructor for Input/Output + *@param src_params Source parameters + *@param default_src_params Default Source parameters + *@param stream_data Source/Destination of data + */ + SourceParamsByteIO( SourceParams& src_params, + const SourceParams& default_src_params, + const ByteIO& stream_data); + /** + * Destructor + */ + ~SourceParamsByteIO(); + + /** + * Reads source params information from Dirac byte-format + */ + void Input(); + + /** + * Outputs source params information to Dirac byte-format + */ + void Output(); + + protected: + + + private: + + /** + * Reads frame dimensions + */ + void InputFrameSize(); + + /** + * Reads Chroma Sampling Format + */ + void InputChromaSamplingFormat(); + + /** + * Reads pixel aspect ratio info + */ + void InputPixelAspectRatio(); + + /** + * Reads clean-area info + */ + void InputCleanArea(); + + /** + * Reads colour-matrix info + */ + void InputColourMatrix(); + + /** + * Reads primary-colour info + */ + void InputColourPrimaries(); + + /** + * Reads colour spec info + */ + void InputColourSpecification(); + + /** + * Reads frame-rate info + */ + void InputFrameRate(); + + /** + * Reads Scan info + */ + void InputScanFormat(); + + /** + * Reads signal range info + */ + void InputSignalRange(); + + /** + * Reads transfer-function info + */ + void InputTransferFunction(); + + /** + * Outputs frame dimensions + */ + void OutputFrameSize(); + + /** + * Outputs Chroma Sampling Format + */ + void OutputChromaSamplingFormat(); + + /** + * Outputs pixel aspect ratio info + */ + void OutputPixelAspectRatio(); + + /** + * Outputs clean-area info + */ + void OutputCleanArea(); + + /** + * Outputs colour spec info + */ + void OutputColourSpecification(); + + /** + * Outputs frame-rate info + */ + void OutputFrameRate(); + + /** + * Outputs Scan info + */ + void OutputScanFormat(); + + /** + * Outputs signal range info + */ + void OutputSignalRange(); + + /** + * Source parameters for input/ouput + */ + SourceParams& m_src_params; + + /** + * Default source parameters + */ + const SourceParams& m_default_src_params; + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.cpp index 58f74870a..ca0144e8e 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.cpp @@ -46,9 +46,9 @@ using namespace std; EndOfSequenceByteIO::EndOfSequenceByteIO(const ByteIO& byte_io): - ParseUnitByteIO(byte_io) +ParseUnitByteIO(byte_io) { - + } @@ -65,14 +65,14 @@ void EndOfSequenceByteIO::CollateByteStats(DiracByteStats& dirac_byte_stats) //-------------private------------------------------------------------------- - + unsigned char EndOfSequenceByteIO::CalcParseCode() const { unsigned char code = 0; - // set end-of-sequence parse-code - SetBits(code, PARSE_CODE_END_OF_SEQUENCE); + // set end-of-sequence parse-code + SetBits(code, PARSE_CODE_END_OF_SEQUENCE); - return code; + return code; } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.h index f1b7bdb87..0bce3997f 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.h @@ -50,60 +50,54 @@ namespace dirac { -/** -* Signals the end of a sequence in a Dirac-formatted bitstream. Current Accessunit parameters -* are no longer valid for subsequent frames -*/ -class EndOfSequenceByteIO : public ParseUnitByteIO -{ -public: - - /** - * Constructor - *@param stream_data Stream parameters - */ - EndOfSequenceByteIO(const ByteIO& stream_data); - - /** - * Destructor - */ - ~EndOfSequenceByteIO(); - - - /** - * Gets parse-unit type - */ - ParseUnitType GetType() const - { - return PU_END_OF_SEQUENCE; - } - - /** - * Gathers byte stats on the end of sequence data - *@param dirac_byte_stats Stat container - */ - void CollateByteStats(DiracByteStats& dirac_byte_stats); -protected: - /** - * Calculates number of bytes to start of next unit - *@return Zero(0) End of sequence does not specify a 'next'unit + * Signals the end of a sequence in a Dirac-formatted bitstream. Current Accessunit parameters + * are no longer valid for subsequent frames */ - int CalcNextUnitOffset() + class EndOfSequenceByteIO : public ParseUnitByteIO { - return 0; - } - -private: - - /** - * Calculates parse-code based on picture parameters - *@return Char bit-set - */ - unsigned char CalcParseCode() const; - - -}; + public: + + /** + * Constructor + *@param stream_data Stream parameters + */ + EndOfSequenceByteIO(const ByteIO& stream_data); + + /** + * Destructor + */ + ~EndOfSequenceByteIO(); + + + /** + * Gets parse-unit type + */ + ParseUnitType GetType() const { return PU_END_OF_SEQUENCE;} + + /** + * Gathers byte stats on the end of sequence data + *@param dirac_byte_stats Stat container + */ + void CollateByteStats(DiracByteStats& dirac_byte_stats); + protected: + + /** + * Calculates number of bytes to start of next unit + *@return Zero(0) End of sequence does not specify a 'next'unit + */ + int CalcNextUnitOffset() { return 0;} + + private: + + /** + * Calculates parse-code based on picture parameters + *@return Char bit-set + */ + unsigned char CalcParseCode() const; + + + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.cpp index 075fe0176..2ed0357aa 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.cpp @@ -42,35 +42,35 @@ using namespace dirac; MvDataByteIO::MvDataByteIO(PictureParams& pparams, - PicturePredParams& picpredparams): - ByteIO(), - m_pparams(pparams), - m_picpredparams(picpredparams), - m_splitmode_data(), - m_predmode_data(), - m_mv1hblock_data(), - m_mv1vblock_data(), - m_mv2hblock_data(), - m_mv2vblock_data(), - m_ydcblock_data(), - m_udcblock_data(), - m_vdcblock_data() + PicturePredParams& picpredparams): +ByteIO(), +m_pparams(pparams), +m_picpredparams(picpredparams), +m_splitmode_data(), +m_predmode_data(), +m_mv1hblock_data(), +m_mv1vblock_data(), +m_mv2hblock_data(), +m_mv2vblock_data(), +m_ydcblock_data(), +m_udcblock_data(), +m_vdcblock_data() {} MvDataByteIO::MvDataByteIO(ByteIO &byte_io, PictureParams& pparams, - PicturePredParams& picpredparams): - ByteIO(byte_io), - m_pparams(pparams), - m_picpredparams(picpredparams), - m_splitmode_data(byte_io), - m_predmode_data(byte_io), - m_mv1hblock_data(byte_io), - m_mv1vblock_data(byte_io), - m_mv2hblock_data(byte_io), - m_mv2vblock_data(byte_io), - m_ydcblock_data(byte_io), - m_udcblock_data(byte_io), - m_vdcblock_data(byte_io) + PicturePredParams& picpredparams): +ByteIO(byte_io), +m_pparams(pparams), +m_picpredparams(picpredparams), +m_splitmode_data(byte_io), +m_predmode_data(byte_io), +m_mv1hblock_data(byte_io), +m_mv1vblock_data(byte_io), +m_mv2hblock_data(byte_io), +m_mv2vblock_data(byte_io), +m_ydcblock_data(byte_io), +m_udcblock_data(byte_io), +m_vdcblock_data(byte_io) {} MvDataByteIO::~MvDataByteIO() @@ -85,50 +85,50 @@ void MvDataByteIO::CollateByteStats(DiracByteStats& dirac_byte_stats) int MvDataByteIO::GetSize() const { - if(m_pparams.NumRefs() == 2) + if (m_pparams.NumRefs()==2) return ByteIO::GetSize() + - m_splitmode_data.GetSize() + - m_predmode_data.GetSize() + - m_mv1hblock_data.GetSize() + - m_mv1vblock_data.GetSize() + - m_mv2hblock_data.GetSize() + - m_mv2vblock_data.GetSize() + - m_ydcblock_data.GetSize() + - m_udcblock_data.GetSize() + + m_splitmode_data.GetSize()+ + m_predmode_data.GetSize()+ + m_mv1hblock_data.GetSize()+ + m_mv1vblock_data.GetSize()+ + m_mv2hblock_data.GetSize()+ + m_mv2vblock_data.GetSize()+ + m_ydcblock_data.GetSize()+ + m_udcblock_data.GetSize()+ m_vdcblock_data.GetSize(); else return ByteIO::GetSize() + - m_splitmode_data.GetSize() + - m_predmode_data.GetSize() + - m_mv1hblock_data.GetSize() + - m_mv1vblock_data.GetSize() + - m_ydcblock_data.GetSize() + - m_udcblock_data.GetSize() + + m_splitmode_data.GetSize()+ + m_predmode_data.GetSize()+ + m_mv1hblock_data.GetSize()+ + m_mv1vblock_data.GetSize()+ + m_ydcblock_data.GetSize()+ + m_udcblock_data.GetSize()+ m_vdcblock_data.GetSize(); } const std::string MvDataByteIO::GetBytes() { //Output header and block data - if(m_pparams.NumRefs() == 2) + if (m_pparams.NumRefs()==2 ) return ByteIO::GetBytes() + - m_splitmode_data.GetBytes() + - m_predmode_data.GetBytes() + - m_mv1hblock_data.GetBytes() + - m_mv1vblock_data.GetBytes() + - m_mv2hblock_data.GetBytes() + - m_mv2vblock_data.GetBytes() + - m_ydcblock_data.GetBytes() + - m_udcblock_data.GetBytes() + + m_splitmode_data.GetBytes()+ + m_predmode_data.GetBytes()+ + m_mv1hblock_data.GetBytes()+ + m_mv1vblock_data.GetBytes()+ + m_mv2hblock_data.GetBytes()+ + m_mv2vblock_data.GetBytes()+ + m_ydcblock_data.GetBytes()+ + m_udcblock_data.GetBytes()+ m_vdcblock_data.GetBytes(); else return ByteIO::GetBytes() + - m_splitmode_data.GetBytes() + - m_predmode_data.GetBytes() + - m_mv1hblock_data.GetBytes() + - m_mv1vblock_data.GetBytes() + - m_ydcblock_data.GetBytes() + - m_udcblock_data.GetBytes() + + m_splitmode_data.GetBytes()+ + m_predmode_data.GetBytes()+ + m_mv1hblock_data.GetBytes()+ + m_mv1vblock_data.GetBytes()+ + m_ydcblock_data.GetBytes()+ + m_udcblock_data.GetBytes()+ m_vdcblock_data.GetBytes(); } @@ -186,7 +186,7 @@ void MvDataByteIO::OutputBlockParams() // output custom block params flag unsigned int pidx = BlockParametersIndex(olb_params); WriteUint(pidx); - if(pidx == 0) // custom block params + if (pidx == 0) // custom block params { // output Xblen WriteUint(olb_params.Xblen()); @@ -204,7 +204,7 @@ void MvDataByteIO::InputBlockParams() OLBParams olb_params; unsigned int p_idx = ReadUint(); - if(p_idx == 0) + if (p_idx == 0) { // Input Xblen olb_params.SetXblen(ReadUint()); @@ -216,7 +216,7 @@ void MvDataByteIO::InputBlockParams() olb_params.SetYbsep(ReadUint()); } else - SetDefaultBlockParameters(olb_params, p_idx); + SetDefaultBlockParameters (olb_params, p_idx); m_picpredparams.SetLumaBlockParams(olb_params); } @@ -231,13 +231,13 @@ void MvDataByteIO::InputMVPrecision() { // Input Motion vector precision MVPrecisionType mv_prec = IntToMVPrecisionType(ReadUint()); - if(mv_prec == MV_PRECISION_UNDEFINED) + if(mv_prec==MV_PRECISION_UNDEFINED) DIRAC_THROW_EXCEPTION( - ERR_INVALID_MOTION_VECTOR_PRECISION, - "Dirac does not recognise the specified MV precision", - SEVERITY_PICTURE_ERROR) + ERR_INVALID_MOTION_VECTOR_PRECISION, + "Dirac does not recognise the specified MV precision", + SEVERITY_PICTURE_ERROR) - m_picpredparams.SetMVPrecision(mv_prec); + m_picpredparams.SetMVPrecision(mv_prec); } void MvDataByteIO::OutputGlobalMotionParams() @@ -252,15 +252,15 @@ void MvDataByteIO::InputGlobalMotionParams() { // Always setting global motion to false // Using Global motion flag - if(ReadBool()) + if (ReadBool()) { m_picpredparams.SetUsingGlobalMotion(true); // NOTE: FIXME - input actual global motion params in future DIRAC_THROW_EXCEPTION( - ERR_UNSUPPORTED_STREAM_DATA, - "Cannot handle global motion parameters", - SEVERITY_PICTURE_ERROR) + ERR_UNSUPPORTED_STREAM_DATA, + "Cannot handle global motion parameters", + SEVERITY_PICTURE_ERROR) } else m_picpredparams.SetUsingGlobalMotion(false); @@ -278,7 +278,7 @@ void MvDataByteIO::InputFramePredictionMode() // TODO - need to process this field when alternative prediction modes // become available. unsigned int frame_pred_mode = ReadUint(); - if(frame_pred_mode != 0) + if (frame_pred_mode != 0) { DIRAC_THROW_EXCEPTION( ERR_UNSUPPORTED_STREAM_DATA, @@ -291,16 +291,16 @@ void MvDataByteIO::InputFramePredictionMode() void MvDataByteIO::OutputPictureWeights() { // Output default weights flags - if(m_picpredparams.PictureWeightsBits() != 1 || - m_picpredparams.Ref1Weight() != 1 || - (m_pparams.Refs().size() > 1 && m_picpredparams.Ref2Weight() != 1)) + if (m_picpredparams.PictureWeightsBits() != 1 || + m_picpredparams.Ref1Weight() != 1 || + (m_pparams.Refs().size() > 1 && m_picpredparams.Ref2Weight() != 1) ) { - WriteBit(true); + WriteBit(true); // Output weight precision bits WriteUint(m_picpredparams.PictureWeightsBits()); // Output Ref1 weight WriteSint(m_picpredparams.Ref1Weight()); - if(m_pparams.Refs().size() > 1) + if (m_pparams.Refs().size() > 1) { // Output Ref1 weight WriteSint(m_picpredparams.Ref2Weight()); @@ -308,17 +308,17 @@ void MvDataByteIO::OutputPictureWeights() } else { - WriteBit(false); + WriteBit(false); } } void MvDataByteIO::InputPictureWeights() { - if(ReadBool()) + if (ReadBool()) { m_picpredparams.SetPictureWeightsPrecision(ReadUint()); m_picpredparams.SetRef1Weight(ReadSint()); - if(m_pparams.Refs().size() > 1) + if (m_pparams.Refs().size() > 1) m_picpredparams.SetRef2Weight(ReadSint()); else m_picpredparams.SetRef2Weight(0); diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.h index ff809c3d5..578a3594e 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.h @@ -53,244 +53,217 @@ namespace dirac { -/** -* Represents compressed sequence-parameter data used in an AccessUnit -*/ -class MvDataByteIO : public ByteIO -{ -public: - - /** - * Constructor - *@param pparams Picture Params - *@param picpredparams Picture prediction parameters - */ - MvDataByteIO(PictureParams& pparams, - PicturePredParams& picpredparams); - - /** - * Constructor - *@param byte_io Input/Output Byte stream - *@param pparams Picture Params - *@param picpredparams Picture prediction parameters - */ - MvDataByteIO(ByteIO &byte_io, PictureParams& pparams, - PicturePredParams& picpredparams); - - /** - * Destructor - */ - virtual ~MvDataByteIO(); - - /** - * Gathers byte stats on the motion vector data - *@param dirac_byte_stats Stat container - */ - void CollateByteStats(DiracByteStats& dirac_byte_stats); - - /** - * Outputs motion vector data Dirac byte-format - */ - void Output(); - - /** - * Inputs motion vector information - */ - void Input(); - - - /** - * Get string containing coded bytes - */ - virtual const std::string GetBytes(); - /** - * Return pointer to the superblock splitting modes ByteIO stream + * Represents compressed sequence-parameter data used in an AccessUnit */ - MvDataElementByteIO* SplitModeData() + class MvDataByteIO : public ByteIO { - return &m_splitmode_data; + public: + + /** + * Constructor + *@param pparams Picture Params + *@param picpredparams Picture prediction parameters + */ + MvDataByteIO(PictureParams& pparams, + PicturePredParams& picpredparams); + + /** + * Constructor + *@param byte_io Input/Output Byte stream + *@param pparams Picture Params + *@param picpredparams Picture prediction parameters + */ + MvDataByteIO(ByteIO &byte_io, PictureParams& pparams, + PicturePredParams& picpredparams); + + /** + * Destructor + */ + virtual ~MvDataByteIO(); + + /** + * Gathers byte stats on the motion vector data + *@param dirac_byte_stats Stat container + */ + void CollateByteStats(DiracByteStats& dirac_byte_stats); + + /** + * Outputs motion vector data Dirac byte-format + */ + void Output(); + + /** + * Inputs motion vector information + */ + void Input(); + + + /** + * Get string containing coded bytes + */ + virtual const std::string GetBytes(); + + /** + * Return pointer to the superblock splitting modes ByteIO stream + */ + MvDataElementByteIO* SplitModeData() { return &m_splitmode_data; }; + + /** + * Return pointer to the superblock splitting modes ByteIO stream + */ + MvDataElementByteIO* PredModeData() { return &m_predmode_data; }; + + /** + * Return pointer to the block MVs reference 1 ByteIO stream + */ + MvDataElementByteIO* MV1HorizData() { return &m_mv1hblock_data; }; + + /** + * Return pointer to the block MVs reference 1 ByteIO stream + */ + MvDataElementByteIO* MV1VertData() { return &m_mv1vblock_data; }; + + /** + * Return pointer to the block MV reference 2 ByteIO stream + */ + MvDataElementByteIO* MV2HorizData() { return &m_mv2hblock_data; }; + + /** + * Return pointer to the block MV reference 2 ByteIO stream + */ + MvDataElementByteIO* MV2VertData() { return &m_mv2vblock_data; }; + + /** + * Return pointer to the block Y DC values ByteIO stream + */ + MvDataElementByteIO* YDCData() { return &m_ydcblock_data; }; + + /** + * Return pointer to the block U DC values ByteIO stream + */ + MvDataElementByteIO* UDCData() { return &m_udcblock_data; }; + + /** + * Return pointer to the block V DC values ByteIO stream + */ + MvDataElementByteIO* VDCData() { return &m_vdcblock_data; }; + + /** + * Return the size + */ + int GetSize() const; + + protected: + + + private: + /** + * Inputs block parameters + */ + void InputBlockParams(); + + /** + * Inputs Motion vector precision data + */ + void InputMVPrecision(); + + /** + * Inputs global motion parameters + */ + void InputGlobalMotionParams(); + + /** + * Inputs picture prediction mode + */ + void InputFramePredictionMode(); + + /** + * Inputs Picture Weights + */ + void InputPictureWeights(); + + /** + * Outputs block parameters + */ + void OutputBlockParams(); + + /** + * Outputs Motion vector precision data + */ + void OutputMVPrecision(); + + /** + * Outputs global motion parameters + */ + void OutputGlobalMotionParams(); + + /** + * Outputs picture prediction mode + */ + void OutputFramePredictionMode(); + + /** + * Outputs Picture Weights + */ + void OutputPictureWeights(); + + /** + * Sequence paramters for intput/output + */ + PictureParams& m_pparams; + + /** + * Codec params - EncParams for Output and DecParams for input + */ + PicturePredParams& m_picpredparams; + + /** + * block data containing split modes + */ + MvDataElementByteIO m_splitmode_data; + + /** + * block data containing prediction modes + */ + MvDataElementByteIO m_predmode_data; + + /** + * block data containing horizontal MV components for reference 1 + */ + MvDataElementByteIO m_mv1hblock_data; + + /** + * block data containing vertical MV components for reference 1 + */ + MvDataElementByteIO m_mv1vblock_data; + + /** + * block data containing horizontal MV components for reference 2 + */ + MvDataElementByteIO m_mv2hblock_data; + + /** + * block data containing vertical MV components for reference 2 + */ + MvDataElementByteIO m_mv2vblock_data; + + /** + * block data containing Y DC data + */ + MvDataElementByteIO m_ydcblock_data; + + /** + * block data containing U DC data + */ + MvDataElementByteIO m_udcblock_data; + + /** + * block data containing V DC data + */ + MvDataElementByteIO m_vdcblock_data; }; - /** - * Return pointer to the superblock splitting modes ByteIO stream - */ - MvDataElementByteIO* PredModeData() - { - return &m_predmode_data; - }; - - /** - * Return pointer to the block MVs reference 1 ByteIO stream - */ - MvDataElementByteIO* MV1HorizData() - { - return &m_mv1hblock_data; - }; - - /** - * Return pointer to the block MVs reference 1 ByteIO stream - */ - MvDataElementByteIO* MV1VertData() - { - return &m_mv1vblock_data; - }; - - /** - * Return pointer to the block MV reference 2 ByteIO stream - */ - MvDataElementByteIO* MV2HorizData() - { - return &m_mv2hblock_data; - }; - - /** - * Return pointer to the block MV reference 2 ByteIO stream - */ - MvDataElementByteIO* MV2VertData() - { - return &m_mv2vblock_data; - }; - - /** - * Return pointer to the block Y DC values ByteIO stream - */ - MvDataElementByteIO* YDCData() - { - return &m_ydcblock_data; - }; - - /** - * Return pointer to the block U DC values ByteIO stream - */ - MvDataElementByteIO* UDCData() - { - return &m_udcblock_data; - }; - - /** - * Return pointer to the block V DC values ByteIO stream - */ - MvDataElementByteIO* VDCData() - { - return &m_vdcblock_data; - }; - - /** - * Return the size - */ - int GetSize() const; - -protected: - - -private: - /** - * Inputs block parameters - */ - void InputBlockParams(); - - /** - * Inputs Motion vector precision data - */ - void InputMVPrecision(); - - /** - * Inputs global motion parameters - */ - void InputGlobalMotionParams(); - - /** - * Inputs picture prediction mode - */ - void InputFramePredictionMode(); - - /** - * Inputs Picture Weights - */ - void InputPictureWeights(); - - /** - * Outputs block parameters - */ - void OutputBlockParams(); - - /** - * Outputs Motion vector precision data - */ - void OutputMVPrecision(); - - /** - * Outputs global motion parameters - */ - void OutputGlobalMotionParams(); - - /** - * Outputs picture prediction mode - */ - void OutputFramePredictionMode(); - - /** - * Outputs Picture Weights - */ - void OutputPictureWeights(); - - /** - * Sequence paramters for intput/output - */ - PictureParams& m_pparams; - - /** - * Codec params - EncParams for Output and DecParams for input - */ - PicturePredParams& m_picpredparams; - - /** - * block data containing split modes - */ - MvDataElementByteIO m_splitmode_data; - - /** - * block data containing prediction modes - */ - MvDataElementByteIO m_predmode_data; - - /** - * block data containing horizontal MV components for reference 1 - */ - MvDataElementByteIO m_mv1hblock_data; - - /** - * block data containing vertical MV components for reference 1 - */ - MvDataElementByteIO m_mv1vblock_data; - - /** - * block data containing horizontal MV components for reference 2 - */ - MvDataElementByteIO m_mv2hblock_data; - - /** - * block data containing vertical MV components for reference 2 - */ - MvDataElementByteIO m_mv2vblock_data; - - /** - * block data containing Y DC data - */ - MvDataElementByteIO m_ydcblock_data; - - /** - * block data containing U DC data - */ - MvDataElementByteIO m_udcblock_data; - - /** - * block data containing V DC data - */ - MvDataElementByteIO m_vdcblock_data; -}; - } // namespace dirac #endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.cpp index 524845df4..f8785616d 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.cpp @@ -44,14 +44,14 @@ using namespace dirac; MvDataElementByteIO::MvDataElementByteIO(): - ByteIO(), - m_block_data() +ByteIO(), +m_block_data() { } MvDataElementByteIO::MvDataElementByteIO(ByteIO &byte_io): - ByteIO(byte_io), - m_block_data(byte_io) +ByteIO(byte_io), +m_block_data(byte_io) { } @@ -88,7 +88,7 @@ void MvDataElementByteIO::Input() } void MvDataElementByteIO::Output() -{ +{ //Output size of block data WriteUint(m_block_data.GetSize()); diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.h index 6896ac7ea..2e0aa4211 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.h @@ -53,80 +53,74 @@ namespace dirac { - -/** -* Represents compressed sequence-parameter data used in an AccessUnit -*/ -class MvDataElementByteIO : public ByteIO -{ -public: - - /** - * Constructor - */ - MvDataElementByteIO(); - - /** - * Constructor - *@param byte_io Input/Output Byte stream - */ - MvDataElementByteIO(ByteIO &byte_io); - - /** - * Destructor - */ - virtual ~MvDataElementByteIO(); - - /** - * Outputs motion vector data Dirac byte-format - */ - void Output(); - - /** - * Inputs motion vector information - */ - void Input(); - - - /** - * Get string containing coded bytes - */ - virtual const std::string GetBytes(); - + /** - * Return pointer to the block data ByteIO stream + * Represents compressed sequence-parameter data used in an AccessUnit */ - ByteIO* DataBlock() + class MvDataElementByteIO : public ByteIO { - return &m_block_data; + public: + + /** + * Constructor + */ + MvDataElementByteIO(); + + /** + * Constructor + *@param byte_io Input/Output Byte stream + */ + MvDataElementByteIO(ByteIO &byte_io); + + /** + * Destructor + */ + virtual ~MvDataElementByteIO(); + + /** + * Outputs motion vector data Dirac byte-format + */ + void Output(); + + /** + * Inputs motion vector information + */ + void Input(); + + + /** + * Get string containing coded bytes + */ + virtual const std::string GetBytes(); + + /** + * Return pointer to the block data ByteIO stream + */ + ByteIO* DataBlock() { return &m_block_data; }; + + /** + * Return the input block data size + */ + unsigned int DataBlockSize() { return m_block_size; } + + /** + * Return the size + */ + int GetSize() const; + + protected: + + /** + * block data + */ + ByteIO m_block_data; + + /** + * In block data size + */ + unsigned int m_block_size; }; - /** - * Return the input block data size - */ - unsigned int DataBlockSize() - { - return m_block_size; - } - - /** - * Return the size - */ - int GetSize() const; - -protected: - - /** - * block data - */ - ByteIO m_block_data; - - /** - * In block data size - */ - unsigned int m_block_size; -}; - } // namespace dirac #endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.cpp index cd3691ee0..5034933bc 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.cpp @@ -44,15 +44,15 @@ const unsigned int PP_AU_PICTURE_NUM_SIZE = 4; using namespace dirac; -ParseParamsByteIO::ParseParamsByteIO(const ByteIO& stream_data, - ParseParams &parse_params, - EncoderParams &enc_params): - ByteIO(stream_data), - m_parse_params(parse_params) +ParseParamsByteIO::ParseParamsByteIO( const ByteIO& stream_data, + ParseParams &parse_params, + EncoderParams &enc_params): +ByteIO(stream_data), +m_parse_params(parse_params) { - if(enc_params.NumL1() == 0) + if (enc_params.NumL1() == 0) { - if(!enc_params.UsingAC()) + if (!enc_params.UsingAC()) { // Simple Profile m_parse_params.SetProfile(1); @@ -66,15 +66,15 @@ ParseParamsByteIO::ParseParamsByteIO(const ByteIO& stream_data, else { // Main (Long GOP) profile - m_parse_params.SetProfile(8); + m_parse_params.SetProfile(8); } // FIXME - no support for Low Delay Profile } -ParseParamsByteIO::ParseParamsByteIO(const ByteIO& stream_data, +ParseParamsByteIO::ParseParamsByteIO( const ByteIO& stream_data, ParseParams &parse_params): - ByteIO(stream_data), - m_parse_params(parse_params) +ByteIO(stream_data), +m_parse_params(parse_params) { @@ -89,8 +89,8 @@ void ParseParamsByteIO::CheckVersion() std::ostringstream errstr; ParseParams def_parse_params; - if(m_parse_params.MajorVersion() > def_parse_params.MajorVersion() || - m_parse_params.MajorVersion() == 0 || + if (m_parse_params.MajorVersion() > def_parse_params.MajorVersion() || + m_parse_params.MajorVersion() == 0 || (m_parse_params.MajorVersion() == def_parse_params.MajorVersion() && m_parse_params.MinorVersion() > def_parse_params.MinorVersion())) { @@ -103,7 +103,7 @@ void ParseParamsByteIO::CheckVersion() errstr << ". May not be able to decode bitstream correctly" << std::endl; } - if(errstr.str().size()) + if (errstr.str().size()) { DiracException err( ERR_UNSUPPORTED_STREAM_DATA, @@ -120,21 +120,21 @@ void ParseParamsByteIO::CheckProfile() // No profiles were specified in versions 1.0, 1.1, and 2.0 and 2.1. // So for these versions profile should be 0 in the bitstream - if(m_parse_params.MajorVersion() <= 2 && - m_parse_params.MinorVersion() < 2 && - m_parse_params.Profile() != 0) + if (m_parse_params.MajorVersion() <= 2 && + m_parse_params.MinorVersion() < 2 && + m_parse_params.Profile() != 0) { errstr << "Cannot handle profile " << m_parse_params.Profile() << " for bitstream version " << m_parse_params.MajorVersion() << "." << m_parse_params.MinorVersion(); errstr << ". May not be able to decode bitstream correctly" << std::endl; } - else if(m_parse_params.MajorVersion() == def_parse_params.MajorVersion() && - m_parse_params.MinorVersion() == def_parse_params.MinorVersion() && - m_parse_params.Profile() != 1 /* Simple */ && - m_parse_params.Profile() != 2 /* Main (Intra) */ && - m_parse_params.Profile() != 8 /* Main (Long GOP) */ - ) + else if (m_parse_params.MajorVersion() == def_parse_params.MajorVersion() && + m_parse_params.MinorVersion() == def_parse_params.MinorVersion() && + m_parse_params.Profile() != 1 /* Simple */ && + m_parse_params.Profile() != 2 /* Main (Intra) */ && + m_parse_params.Profile() != 8 /* Main (Long GOP) */ + ) { errstr << "Cannot handle profile " << m_parse_params.Profile() << " for bitstream version " << m_parse_params.MajorVersion() @@ -144,7 +144,7 @@ void ParseParamsByteIO::CheckProfile() errstr << ". May not be able to decode bitstream correctly" << std::endl; } - if(errstr.str().size()) + if (errstr.str().size()) { DiracException err( ERR_UNSUPPORTED_STREAM_DATA, @@ -160,15 +160,15 @@ void ParseParamsByteIO::CheckLevel() ParseParams def_parse_params; // No resources constraints for decoder - if(def_parse_params.Level() == 0) + if (def_parse_params.Level() == 0) return; // Constraints on Decoder. Can Handles level 1 for Simple and Main (Intra) // profiles, and level 128 for Main (Long GOP) Profile. - if(def_parse_params.Level() != 0) + if (def_parse_params.Level() != 0) { - if((m_parse_params.Profile() <= 2 && m_parse_params.Level() != 1) || - (m_parse_params.Profile() == 8 && m_parse_params.Level() != 128)) + if ((m_parse_params.Profile() <= 2 && m_parse_params.Level() != 1) || + (m_parse_params.Profile() ==8 && m_parse_params.Level() != 128)) { errstr << "Cannot handle Level " << m_parse_params.Level() << " for bitstream version " << m_parse_params.MajorVersion() @@ -180,7 +180,7 @@ void ParseParamsByteIO::CheckLevel() } } - if(errstr.str().size()) + if (errstr.str().size()) { DiracException err( ERR_UNSUPPORTED_STREAM_DATA, diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.h index 04f040c2d..1e5423f31 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.h @@ -51,65 +51,65 @@ namespace dirac { - -/** -* Represents compressed parse-parameter data used in an AccessUnit -*/ -class ParseParamsByteIO : public ByteIO -{ -public: - - /** - * Constructor - *@param stream_data Destination of data - *@param parse_params Parse parameters - *@param enc_params Encoder parameters - */ - ParseParamsByteIO(const ByteIO& stream_data, - ParseParams &parse_params, - EncoderParams &enc_params); - - /** - * Constructor - *@param stream_data Source of data - *@param parse_params Destination of parse params - */ - ParseParamsByteIO(const ByteIO& stream_data, - ParseParams &parse_params); - - /** - * Destructor - */ - ~ParseParamsByteIO(); - - /** - * Reads parse information from Dirac byte-format - */ - void Input(); - - /** - * Outputs parse information to Dirac byte-format - */ - void Output(); - - /** - * Get access-unit number - */ - int GetIdNumber() const; - -protected: - -private: - void CheckVersion(); - void CheckProfile(); - void CheckLevel(); - -private: + /** - * Reference to parse parameters + * Represents compressed parse-parameter data used in an AccessUnit */ - ParseParams& m_parse_params; -}; + class ParseParamsByteIO : public ByteIO + { + public: + + /** + * Constructor + *@param stream_data Destination of data + *@param parse_params Parse parameters + *@param enc_params Encoder parameters + */ + ParseParamsByteIO(const ByteIO& stream_data, + ParseParams &parse_params, + EncoderParams &enc_params); + + /** + * Constructor + *@param stream_data Source of data + *@param parse_params Destination of parse params + */ + ParseParamsByteIO(const ByteIO& stream_data, + ParseParams &parse_params); + + /** + * Destructor + */ + ~ParseParamsByteIO(); + + /** + * Reads parse information from Dirac byte-format + */ + void Input(); + + /** + * Outputs parse information to Dirac byte-format + */ + void Output(); + + /** + * Get access-unit number + */ + int GetIdNumber() const; + + protected: + + private: + void CheckVersion(); + void CheckProfile(); + void CheckLevel(); + + private: + /** + * Reference to parse parameters + */ + ParseParams& m_parse_params; + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.cpp index 9d4ac83de..56c0ebb8b 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.cpp @@ -52,30 +52,30 @@ const int PU_NEXT_PARSE_OFFSET_SIZE = 4; const int PU_PREVIOUS_PARSE_OFFSET_SIZE = 4; const int PU_PREFIX_SIZE = 4; const int PU_PARSE_CODE_SIZE = 1; -const int PU_PARSEUNIT_SIZE = PU_NEXT_PARSE_OFFSET_SIZE + PU_PREVIOUS_PARSE_OFFSET_SIZE + +const int PU_PARSEUNIT_SIZE = PU_NEXT_PARSE_OFFSET_SIZE + PU_PREVIOUS_PARSE_OFFSET_SIZE+ PU_PREFIX_SIZE + PU_PARSE_CODE_SIZE; ParseUnitByteIO::ParseUnitByteIO(): - ByteIO(), - m_previous_parse_offset(0), - m_next_parse_offset(0) +ByteIO(), +m_previous_parse_offset(0), +m_next_parse_offset(0) { } ParseUnitByteIO::ParseUnitByteIO(const ByteIO& byte_io): - ByteIO(byte_io), - m_previous_parse_offset(0), - m_next_parse_offset(0) +ByteIO(byte_io), +m_previous_parse_offset(0), +m_next_parse_offset(0) { } ParseUnitByteIO::ParseUnitByteIO(const ParseUnitByteIO& parseunit_byteio): - ByteIO(parseunit_byteio), - m_previous_parse_offset(parseunit_byteio.m_previous_parse_offset), - m_next_parse_offset(parseunit_byteio.m_next_parse_offset), - m_parse_code(parseunit_byteio.m_parse_code) +ByteIO(parseunit_byteio), +m_previous_parse_offset(parseunit_byteio.m_previous_parse_offset), +m_next_parse_offset(parseunit_byteio.m_next_parse_offset), +m_parse_code(parseunit_byteio.m_parse_code) { } @@ -113,16 +113,16 @@ bool ParseUnitByteIO::Input() bool ParseUnitByteIO::IsValid() { - if(IsEndOfSequence()) + if (IsEndOfSequence()) return true; // Skip past the end of current parse unit - SeekGet(m_next_parse_offset - GetSize(), ios_base::cur); + SeekGet(m_next_parse_offset-GetSize(), ios_base::cur); // check the next series of bytes are the parse-info prefix string prefix = InputUnString(PU_PREFIX_SIZE); - if(prefix == PU_PREFIX) + if(prefix==PU_PREFIX) { unsigned char next_parse_code; @@ -133,28 +133,28 @@ bool ParseUnitByteIO::IsValid() int next_unit_previous_parse_offset; next_unit_previous_parse_offset = ReadUintLit(PU_PREVIOUS_PARSE_OFFSET_SIZE); - if(next_unit_previous_parse_offset == m_next_parse_offset) + if (next_unit_previous_parse_offset == m_next_parse_offset) { - SeekGet(-(m_next_parse_offset - GetSize() + PU_PARSEUNIT_SIZE), ios_base::cur); + SeekGet(-(m_next_parse_offset-GetSize()+PU_PARSEUNIT_SIZE), ios_base::cur); return true; } } - SeekGet(-(m_next_parse_offset - GetSize()), ios_base::cur); + SeekGet(-(m_next_parse_offset-GetSize()), ios_base::cur); return false; } bool ParseUnitByteIO::CanSkip() { - if(m_next_parse_offset == 0 || m_next_parse_offset == GetSize()) + if(m_next_parse_offset==0 || m_next_parse_offset == GetSize()) return true; // Skip past the end of current parse unit and past the header of the // next unit - SeekGet(m_next_parse_offset - GetSize() + GetSize(), ios_base::cur); + SeekGet(m_next_parse_offset-GetSize() + GetSize(), ios_base::cur); if(GetReadBytePosition() >= 0) { - SeekGet(-(m_next_parse_offset - GetSize() + GetSize()), ios_base::cur); - return true; // success + SeekGet(-(m_next_parse_offset-GetSize() + GetSize()), ios_base::cur); + return true; // success } // end of stream reached @@ -171,15 +171,15 @@ const string ParseUnitByteIO::GetBytes() //FIXME : Need to do this properly. // Write the parse offsets in Big Endian format - for(int i = PU_NEXT_PARSE_OFFSET_SIZE - 1; i >= 0; --i) + for(int i=PU_NEXT_PARSE_OFFSET_SIZE-1; i >= 0; --i) { - unsigned char cp = (m_next_parse_offset >> (i * 8)) & 0xff; + unsigned char cp = (m_next_parse_offset>>(i*8)) & 0xff; parse_string << cp; } - for(int i = PU_PREVIOUS_PARSE_OFFSET_SIZE - 1; i >= 0; --i) + for(int i=PU_PREVIOUS_PARSE_OFFSET_SIZE-1; i >= 0; --i) { - unsigned char cp = (m_previous_parse_offset >> (i * 8)) & 0xff; + unsigned char cp = (m_previous_parse_offset>>(i*8)) & 0xff; parse_string << cp; } @@ -251,32 +251,32 @@ int ParseUnitByteIO::CalcNextUnitOffset() bool ParseUnitByteIO::SyncToUnitStart() { - // locate parse-unit prefix + // locate parse-unit prefix string byte_buffer; - while(CanRead() == true && mp_stream->tellg() >= 0) + while(CanRead()==true && mp_stream->tellg() >= 0) { // ensure current buffer length if((int)byte_buffer.size() == PU_PREFIX_SIZE) { - byte_buffer.assign(byte_buffer.substr(1, PU_PREFIX_SIZE - 1)); + byte_buffer.assign(byte_buffer.substr(1,PU_PREFIX_SIZE-1)); } // read next byte byte_buffer.push_back(InputUnByte()); //look to see if we have prefix - if(byte_buffer == PU_PREFIX) + if(byte_buffer==PU_PREFIX) { // check we can read a parse-unit //int prev_pos = mp_stream->tellg(); - mp_stream->seekg(PU_PARSEUNIT_SIZE - PU_PREFIX_SIZE, ios_base::cur); + mp_stream->seekg (PU_PARSEUNIT_SIZE-PU_PREFIX_SIZE, ios_base::cur); int cur_pos = mp_stream->tellg(); - if(cur_pos < 0) // past end of stream + if (cur_pos < 0) // past end of stream { mp_stream->clear(); return false; } - mp_stream->seekg(-(PU_PARSEUNIT_SIZE - PU_PREFIX_SIZE), ios_base::cur); + mp_stream->seekg(-(PU_PARSEUNIT_SIZE-PU_PREFIX_SIZE), ios_base::cur); return true; } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.h index ab015d1fe..8d7742afa 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.h @@ -53,216 +53,193 @@ namespace dirac { -/* Types of parse-unit */ -typedef enum -{ - PU_SEQ_HEADER = 0, - PU_PICTURE, - PU_END_OF_SEQUENCE, - PU_AUXILIARY_DATA, - PU_PADDING_DATA, - PU_CORE_PICTURE, - PU_LOW_DELAY_PICTURE, - PU_UNDEFINED -} ParseUnitType; - -/** -* Represents a collection of data in a Dirac bytestream that can be parsed as a -* self-contained unit -*/ -class ParseUnitByteIO : public ByteIO -{ -public: - - /** - * Constructor - */ - ParseUnitByteIO(); - - /** - * Constructor - *@param byte_io Stream parameters - */ - ParseUnitByteIO(const ByteIO& byte_io); - - /** - * Constructor - *@param parseunit_byteio Parse-unit parameters - */ - ParseUnitByteIO(const ParseUnitByteIO& parseunit_byteio); - - /** - * Destructor - */ - ~ParseUnitByteIO(); - - /** - * Gathers byte stats on the parse-unit data - *@param dirac_byte_stats Stat container - */ - virtual void CollateByteStats(DiracByteStats& dirac_byte_stats); - - /** - * Reads from byte-stream to find parse data - *@return false if not enough data in stream - */ - bool Input(); // decoding - - /** - * Accesses validity of a unit by comparing it with an adjacent unit - */ - bool IsValid(); - - /** - * Can Skip past the entire parse-unit - *@return false Nothing to skip to - */ - bool CanSkip(); - - /** - * Gets string containing coded bytes - */ - virtual const std::string GetBytes(); // encoding - - /** - * Set next/previous parse-unit values - *@param p_prev_parseunit Previous parse-unit - */ - void SetAdjacentParseUnits(ParseUnitByteIO *p_prev_parseunit); // encoding - - /* - * Gets number of bytes input/output within unit - */ - virtual int GetSize() const; - - /** - * Gets expected number of bytes to start of next parse-unit - */ - int GetNextParseOffset() const; - - /** - * Gets number of bytes to start of previous parse-unit - */ - int GetPreviousParseOffset() const; - - /** - * Gets parse-unit type - */ - virtual ParseUnitType GetType() const; - - /** - * Returns true is parse unit is a Sequence Header - */ - bool IsSeqHeader() const - { - return m_parse_code == 0x00; - } - - /** - * Returns true is parse unit is an End of Sequence unit - */ - bool IsEndOfSequence() const - { - return m_parse_code == 0x10; - } - - /** - * Returns true is parse unit is Auxiliary Data - */ - bool IsAuxiliaryData() const - { - return (m_parse_code & 0xF8) == 0x20; - } - - /** - * Returns true is parse unit is Padding data - */ - bool IsPaddingData() const - { - return m_parse_code == 0x30; - } - - /** - * Returns true is parse unit is Picture data - */ - bool IsPicture() const - { - return ((m_parse_code & 0x08) == 0x08); - } - - /** - * Returns true is parse unit is Low Delay Sybtax unit - */ - bool IsLowDelay() const - { - return ((m_parse_code & 0x88) == 0x88); - } - - /** - * Returns true is parse unit is Core syntax unit - */ - bool IsCoreSyntax() const - { - return ((m_parse_code & 0x88) == 0x08); - } - - /** - * Returns true is parse unit uses Arithmetic coding - */ - bool IsUsingAC() const + /* Types of parse-unit */ + typedef enum { + PU_SEQ_HEADER=0, + PU_PICTURE, + PU_END_OF_SEQUENCE, + PU_AUXILIARY_DATA, + PU_PADDING_DATA, + PU_CORE_PICTURE, + PU_LOW_DELAY_PICTURE, + PU_UNDEFINED + } ParseUnitType; + + /** + * Represents a collection of data in a Dirac bytestream that can be parsed as a + * self-contained unit + */ + class ParseUnitByteIO : public ByteIO { - return ((m_parse_code & 0x48) == 0x08); - } - -protected: - - /** - * Calculates number of bytes to start of next unit - *@return Number of bytes to next unit - */ - virtual int CalcNextUnitOffset(); - - /** - * Pure virtual method for calculating parse-code - *@return Char containing bit-set for parse-unit parameters - */ - virtual unsigned char CalcParseCode() const - { - return 0; // encoding - } - - /** - * Locates start of parse-unit - *@return false if not enough data - */ - bool SyncToUnitStart(); // decoding - - /** - * Get parse code - */ - unsigned char GetParseCode() const - { - return m_parse_code; - } - -private: - - /** - * Number of bytes to next parse-unit - */ - int m_previous_parse_offset; - - /** - * Number of bytes to previous parse-unit - */ - int m_next_parse_offset; - - /** - * Parse-type-identifier - */ - unsigned char m_parse_code; - -}; + public: + + /** + * Constructor + */ + ParseUnitByteIO(); + + /** + * Constructor + *@param byte_io Stream parameters + */ + ParseUnitByteIO(const ByteIO& byte_io); + + /** + * Constructor + *@param parseunit_byteio Parse-unit parameters + */ + ParseUnitByteIO(const ParseUnitByteIO& parseunit_byteio); + + /** + * Destructor + */ + ~ParseUnitByteIO(); + + /** + * Gathers byte stats on the parse-unit data + *@param dirac_byte_stats Stat container + */ + virtual void CollateByteStats(DiracByteStats& dirac_byte_stats); + + /** + * Reads from byte-stream to find parse data + *@return false if not enough data in stream + */ + bool Input(); // decoding + + /** + * Accesses validity of a unit by comparing it with an adjacent unit + */ + bool IsValid(); + + /** + * Can Skip past the entire parse-unit + *@return false Nothing to skip to + */ + bool CanSkip(); + + /** + * Gets string containing coded bytes + */ + virtual const std::string GetBytes(); // encoding + + /** + * Set next/previous parse-unit values + *@param p_prev_parseunit Previous parse-unit + */ + void SetAdjacentParseUnits(ParseUnitByteIO *p_prev_parseunit); // encoding + + /* + * Gets number of bytes input/output within unit + */ + virtual int GetSize() const; + + /** + * Gets expected number of bytes to start of next parse-unit + */ + int GetNextParseOffset() const; + + /** + * Gets number of bytes to start of previous parse-unit + */ + int GetPreviousParseOffset() const; + + /** + * Gets parse-unit type + */ + virtual ParseUnitType GetType() const; + + /** + * Returns true is parse unit is a Sequence Header + */ + bool IsSeqHeader() const + { return m_parse_code==0x00; } + + /** + * Returns true is parse unit is an End of Sequence unit + */ + bool IsEndOfSequence() const + { return m_parse_code==0x10; } + + /** + * Returns true is parse unit is Auxiliary Data + */ + bool IsAuxiliaryData() const + { return (m_parse_code&0xF8)==0x20; } + + /** + * Returns true is parse unit is Padding data + */ + bool IsPaddingData() const + { return m_parse_code==0x30; } + + /** + * Returns true is parse unit is Picture data + */ + bool IsPicture() const + { return ((m_parse_code&0x08)==0x08); } + + /** + * Returns true is parse unit is Low Delay Sybtax unit + */ + bool IsLowDelay() const + { return ((m_parse_code&0x88)==0x88); } + + /** + * Returns true is parse unit is Core syntax unit + */ + bool IsCoreSyntax() const + { return ((m_parse_code&0x88)==0x08); } + + /** + * Returns true is parse unit uses Arithmetic coding + */ + bool IsUsingAC() const + { return ((m_parse_code&0x48)==0x08); } + + protected: + + /** + * Calculates number of bytes to start of next unit + *@return Number of bytes to next unit + */ + virtual int CalcNextUnitOffset(); + + /** + * Pure virtual method for calculating parse-code + *@return Char containing bit-set for parse-unit parameters + */ + virtual unsigned char CalcParseCode() const { return 0;} // encoding + + /** + * Locates start of parse-unit + *@return false if not enough data + */ + bool SyncToUnitStart(); // decoding + + /** + * Get parse code + */ + unsigned char GetParseCode() const { return m_parse_code;} + + private: + + /** + * Number of bytes to next parse-unit + */ + int m_previous_parse_offset; + + /** + * Number of bytes to previous parse-unit + */ + int m_next_parse_offset; + + /** + * Parse-type-identifier + */ + unsigned char m_parse_code; + + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.cpp index 06b52aa62..23231bea7 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.cpp @@ -54,37 +54,37 @@ const int CODE_VLC_ENTROPY_CODING_BIT = 6; const unsigned int MAX_NUM_REFS = 2; PictureByteIO::PictureByteIO(PictureParams& frame_params, - int frame_num) : - ParseUnitByteIO(), - m_frame_params(frame_params), - m_frame_num(frame_num), - m_mv_data(0), - m_transform_data(0) + int frame_num) : +ParseUnitByteIO(), +m_frame_params(frame_params), +m_frame_num(frame_num), +m_mv_data(0), +m_transform_data(0) { - + } PictureByteIO::PictureByteIO(PictureParams& frame_params, - const ParseUnitByteIO& parseunit_byteio): - ParseUnitByteIO(parseunit_byteio), - m_frame_params(frame_params), - m_frame_num(0), - m_mv_data(0), - m_transform_data(0) + const ParseUnitByteIO& parseunit_byteio ): +ParseUnitByteIO(parseunit_byteio), +m_frame_params(frame_params), +m_frame_num(0), +m_mv_data(0), +m_transform_data(0) { - + } PictureByteIO::~PictureByteIO() { //delete block data - if(m_mv_data) + if (m_mv_data) { delete m_mv_data; m_mv_data = 0; } - if(m_transform_data) + if (m_transform_data) { delete m_transform_data; m_transform_data = 0; @@ -110,13 +110,13 @@ bool PictureByteIO::Input() // Use of VLC for entropy coding is supported for // intra frames only - if(m_frame_params.GetPictureType() == INTER_PICTURE && - m_frame_params.UsingAC() == false) + if (m_frame_params.GetPictureType() == INTER_PICTURE && + m_frame_params.UsingAC() == false) { DIRAC_THROW_EXCEPTION( - ERR_UNSUPPORTED_STREAM_DATA, - "VLC codes for entropy coding of coefficient data supported for Intra frames only", - SEVERITY_PICTURE_ERROR); + ERR_UNSUPPORTED_STREAM_DATA, + "VLC codes for entropy coding of coefficient data supported for Intra frames only", + SEVERITY_PICTURE_ERROR); } // input picture number @@ -125,10 +125,10 @@ bool PictureByteIO::Input() // input reference Picture numbers InputReferencePictures(); - + // input retired Picture numbers list m_frame_params.SetRetiredPictureNum(-1); - if(IsRef()) + if (IsRef()) InputRetiredPicture(); // byte align @@ -137,7 +137,7 @@ bool PictureByteIO::Input() return true; } -const string PictureByteIO::GetBytes() +const string PictureByteIO::GetBytes() { // Write mv data if(m_frame_params.PicSort().IsInter() && m_mv_data) @@ -146,7 +146,7 @@ const string PictureByteIO::GetBytes() } // Write transform header - if(m_transform_data) + if (m_transform_data) { OutputBytes(m_transform_data->GetBytes()); } @@ -156,15 +156,15 @@ const string PictureByteIO::GetBytes() int PictureByteIO::GetSize() const { int size = 0; - if(m_mv_data) + if (m_mv_data) size += m_mv_data->GetSize(); - if(m_transform_data) + if (m_transform_data) size += m_transform_data->GetSize(); //std::cerr << "Picture Header Size=" << ByteIO::GetSize(); //std::cerr << "Data Size=" << size << std::endl; - return size + ParseUnitByteIO::GetSize() + ByteIO::GetSize(); + return size+ParseUnitByteIO::GetSize()+ByteIO::GetSize(); } void PictureByteIO::Output() @@ -172,23 +172,23 @@ void PictureByteIO::Output() // output picture number WriteUintLit(m_frame_num, PP_PICTURE_NUM_SIZE); - if(m_frame_params.GetPictureType() == INTER_PICTURE) + if(m_frame_params.GetPictureType()==INTER_PICTURE) { // output reference picture numbers const std::vector& refs = m_frame_params.Refs(); - for(size_t i = 0; i < refs.size() && i < MAX_NUM_REFS; ++i) + for(size_t i=0; i < refs.size() && i < MAX_NUM_REFS; ++i) WriteSint(refs[i] - m_frame_num); } // output retired picture - ASSERTM(m_frame_params.GetReferenceType() == REFERENCE_PICTURE || m_frame_params.RetiredPictureNum() == -1, "Only Reference frames can retire frames"); + ASSERTM (m_frame_params.GetReferenceType() == REFERENCE_PICTURE || m_frame_params.RetiredPictureNum() == -1, "Only Reference frames can retire frames"); if(m_frame_params.GetReferenceType() == REFERENCE_PICTURE) { - if(m_frame_params.RetiredPictureNum() == -1) + if (m_frame_params.RetiredPictureNum() == -1) WriteSint(0); else { - WriteSint(m_frame_params.RetiredPictureNum() - m_frame_num); + WriteSint (m_frame_params.RetiredPictureNum() - m_frame_num); } } // byte align output @@ -198,14 +198,14 @@ void PictureByteIO::Output() //-------------private------------------------------------------------------- - + unsigned char PictureByteIO::CalcParseCode() const { unsigned char code = 0; int num_refs = m_frame_params.Refs().size(); - if(m_frame_params.GetPictureType() == INTER_PICTURE) + if(m_frame_params.GetPictureType()==INTER_PICTURE) { // set number of refs if(num_refs == 1) @@ -214,42 +214,42 @@ unsigned char PictureByteIO::CalcParseCode() const SetBit(code, CODE_TWO_REF_BIT); } // set ref type - if(m_frame_params.GetReferenceType() == REFERENCE_PICTURE) + if(m_frame_params.GetReferenceType()==REFERENCE_PICTURE) SetBit(code, CODE_REF_PICTURE_BIT); // Set parse unit type SetBit(code, CODE_PUTYPE_1_BIT); // Set Entropy Coding type - if(!m_frame_params.UsingAC()) + if (!m_frame_params.UsingAC()) { SetBit(code, CODE_VLC_ENTROPY_CODING_BIT); } return code; - + } -void PictureByteIO::InputReferencePictures() +void PictureByteIO::InputReferencePictures() { // get number of frames referred to - int ref_count = NumRefs(); + int ref_count = NumRefs(); - // get the number of these frames + // get the number of these frames vector& refs = m_frame_params.Refs(); refs.resize(ref_count); - for(int i = 0; i < ref_count; ++i) - refs[i] = m_frame_num + ReadSint(); + for(int i=0; i < ref_count; ++i) + refs[i]=m_frame_num+ReadSint(); } - -void PictureByteIO::InputRetiredPicture() + +void PictureByteIO::InputRetiredPicture() { TESTM(IsRef(), "Retired Picture offset only set for Reference Frames"); // input retired picture offset int offset = ReadSint(); // input retired frames - if(offset) + if (offset) { m_frame_params.SetRetiredPictureNum(m_frame_num + offset); } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.h index 1fcd0cb9c..bdca76f40 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.h @@ -54,178 +54,154 @@ namespace dirac { -/** -* A compressed picture in Dirac bytestream format -*/ -class PictureByteIO : public ParseUnitByteIO -{ -public: - - /** - * Constructor - *@param frame_params Picture parameters - *@param frame_num Picture number - */ - PictureByteIO(PictureParams& frame_params, - int frame_num); - - - /** - * Constructor - *@param frame_params Destination of data - *@param parseunit_byteio Source of data - */ - PictureByteIO(PictureParams& frame_params, - const ParseUnitByteIO& parseunit_byteio); - - /** - * Destructor - */ - virtual ~PictureByteIO(); - - /** - * Gathers byte stats on the picture data - *@param dirac_byte_stats Stat container - */ - void CollateByteStats(DiracByteStats& dirac_byte_stats); - - /** - * Inputs data from Dirac stream-format - */ - bool Input(); - - /** - * Outputs picture values to Dirac stream-format - */ - void Output(); - - - - const std::string GetBytes(); - - int GetSize() const; - - /** - * Gets parse-unit type - */ - ParseUnitType GetType() const - { - return PU_PICTURE; - } - - /** - * Returns true is picture in Reference picture - */ - int IsRef() const - { - return (GetParseCode() & 0x0C) == 0x0C; - } - - /** - * Returns true is picture in Non-Reference picture - */ - int IsNonRef() const - { - return (GetParseCode() & 0x0C) == 0x08; - } - - /** - * Gets parse-unit type - */ - int NumRefs() const - { - return (GetParseCode() & 0x03); - } - - /** - * Returns true is picture is Intra picture - */ - bool IsIntra() const - { - return IsPicture() && (NumRefs() == 0) ; - } - /** - * Returns true is picture is Inter picture - */ - bool IsInter() const - { - return IsPicture() && (NumRefs() > 0) ; - } - - /*** - * Sets the MVDataIO + * A compressed picture in Dirac bytestream format */ - void SetMvData(MvDataByteIO *mv_data) + class PictureByteIO : public ParseUnitByteIO { - m_mv_data = mv_data; - } - - /*** - * Sets the TransformByteIo - */ - void SetTransformData(TransformByteIO *transform_data) - { - m_transform_data = transform_data; - } - -protected: - - -private: - - /** - * Calculates parse-code based on picture parameters - *@return Char bit-set - */ - unsigned char CalcParseCode() const; - - /** - * Reads reference-picture data - */ - void InputReferencePictures(); - - /** - * Reads retired picture number - */ - void InputRetiredPicture(); - - /** - * Calculates picture-type (eg INTRA/INTER) of picture - */ - void SetPictureType(); - - /** - * Calculates reference-type of picture - */ - void SetReferenceType(); - - /** - * Sets the entropy coding flag in the picture parameters - */ - void SetEntropyCodingFlag(); - - /** - * Picture parameters - */ - PictureParams& m_frame_params; - - /** - * Picture number - */ - int m_frame_num; - - /** - * MV data - */ - MvDataByteIO * m_mv_data; - - /** - * Transform data - */ - TransformByteIO * m_transform_data; - -}; + public: + + /** + * Constructor + *@param frame_params Picture parameters + *@param frame_num Picture number + */ + PictureByteIO(PictureParams& frame_params, + int frame_num); + + + /** + * Constructor + *@param frame_params Destination of data + *@param parseunit_byteio Source of data + */ + PictureByteIO(PictureParams& frame_params, + const ParseUnitByteIO& parseunit_byteio); + + /** + * Destructor + */ + virtual ~PictureByteIO(); + + /** + * Gathers byte stats on the picture data + *@param dirac_byte_stats Stat container + */ + void CollateByteStats(DiracByteStats& dirac_byte_stats); + + /** + * Inputs data from Dirac stream-format + */ + bool Input(); + + /** + * Outputs picture values to Dirac stream-format + */ + void Output(); + + + + const std::string GetBytes(); + + int GetSize() const; + + /** + * Gets parse-unit type + */ + ParseUnitType GetType() const { return PU_PICTURE;} + + /** + * Returns true is picture in Reference picture + */ + int IsRef() const { return (GetParseCode()&0x0C)==0x0C;} + + /** + * Returns true is picture in Non-Reference picture + */ + int IsNonRef() const { return (GetParseCode()&0x0C)==0x08;} + + /** + * Gets parse-unit type + */ + int NumRefs() const { return (GetParseCode()&0x03);} + + /** + * Returns true is picture is Intra picture + */ + bool IsIntra() const { return IsPicture() && (NumRefs()==0) ; } + + /** + * Returns true is picture is Inter picture + */ + bool IsInter() const { return IsPicture() && (NumRefs()>0) ; } + + /*** + * Sets the MVDataIO + */ + void SetMvData(MvDataByteIO *mv_data) {m_mv_data = mv_data; } + + /*** + * Sets the TransformByteIo + */ + void SetTransformData(TransformByteIO *transform_data) {m_transform_data = transform_data; } + + protected: + + + private: + + /** + * Calculates parse-code based on picture parameters + *@return Char bit-set + */ + unsigned char CalcParseCode() const; + + /** + * Reads reference-picture data + */ + void InputReferencePictures(); + + /** + * Reads retired picture number + */ + void InputRetiredPicture(); + + /** + * Calculates picture-type (eg INTRA/INTER) of picture + */ + void SetPictureType(); + + /** + * Calculates reference-type of picture + */ + void SetReferenceType(); + + /** + * Sets the entropy coding flag in the picture parameters + */ + void SetEntropyCodingFlag(); + + /** + * Picture parameters + */ + PictureParams& m_frame_params; + + /** + * Picture number + */ + int m_frame_num; + + /** + * MV data + */ + MvDataByteIO * m_mv_data; + + /** + * Transform data + */ + TransformByteIO * m_transform_data; + + }; } // namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/subband_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/subband_byteio.cpp index 41b6fcb66..63d0607b9 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/subband_byteio.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/subband_byteio.cpp @@ -42,19 +42,19 @@ using namespace std; SubbandByteIO::SubbandByteIO(Subband& sub_band, const ByteIO& byteio): - ByteIO(byteio), - m_subband(sub_band), - m_band_data_length(0) +ByteIO(byteio), +m_subband(sub_band), +m_band_data_length(0) { - + } SubbandByteIO::SubbandByteIO(Subband& sub_band): - ByteIO(), - m_subband(sub_band), - m_band_data_length(0) +ByteIO(), +m_subband(sub_band), +m_band_data_length(0) { - + } SubbandByteIO::~SubbandByteIO() @@ -70,7 +70,7 @@ bool SubbandByteIO::Input() m_band_data_length = ReadUint(); // set skip flag if no data - m_subband.SetSkip(m_band_data_length == 0 ? true : false); + m_subband.SetSkip(m_band_data_length==0 ? true : false); // check for zero-length sub-band if(m_subband.Skipped()) @@ -79,16 +79,16 @@ bool SubbandByteIO::Input() return true; } - // If we're not skipped, we need a quantisation index for the subband - m_subband.SetQuantIndex(ReadUint()); + // If we're not skipped, we need a quantisation index for the subband + m_subband.SetQuantIndex(ReadUint() ); - if(!m_subband.UsingMultiQuants()) + if ( !m_subband.UsingMultiQuants() ) { - // Propogate the quantiser index to all the code blocks if we + // Propogate the quantiser index to all the code blocks if we // don't have multiquants - for(int j = 0 ; j < m_subband.GetCodeBlocks().LengthY() ; ++j) - for(int i = 0 ; i < m_subband.GetCodeBlocks().LengthX() ; ++i) - m_subband.GetCodeBlocks()[j][i].SetQuantIndex(m_subband.QuantIndex()); + for ( int j=0 ; j -std::istream & operator>> (std::istream & stream, TwoDArray & array) -{ - for(int j = 0 ; j < array.LengthY() ; ++j) + //! A function for inserting array data + template + std::istream & operator>> (std::istream & stream, TwoDArray & array) { - for(int i = 0 ; i < array.LengthX() ; ++i) + for (int j=0 ; j> array[j][i]; - }// i - }// j + for (int i=0 ; i> array[j][i]; + }// i + }// j - return stream; -} + return stream; + } } //namespace dirac #endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec.cpp index bb751e1f0..fc0e42312 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec.cpp @@ -72,25 +72,25 @@ GenericIntraDCBandCodec >::GenericIntraDCBandCodec( void IntraDCBandCodec::DoWorkCode(CoeffArray& in_data) { // Residues after prediction, quantisation and inverse quantisation - m_dc_pred_res.Resize(m_node.Yl() , m_node.Xl()); - m_dc_pred_res.Fill(0); + m_dc_pred_res.Resize( m_node.Yl() , m_node.Xl() ); + m_dc_pred_res.Fill( 0 ); BandCodec::DoWorkCode(in_data); } -void IntraDCBandCodec::CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos) +void IntraDCBandCodec::CodeCoeff( CoeffArray& in_data, const int xpos, const int ypos) { m_nhood_nonzero = false; - if(ypos > m_node.Yp()) + if (ypos > m_node.Yp()) m_nhood_nonzero |= bool(m_dc_pred_res[ypos-1][xpos]); - if(xpos > m_node.Xp()) + if (xpos > m_node.Xp()) m_nhood_nonzero |= bool(m_dc_pred_res[ypos][xpos-1]); - if(ypos > m_node.Yp() && xpos > m_node.Xp()) + if (ypos > m_node.Yp() && xpos > m_node.Xp()) m_nhood_nonzero |= bool(m_dc_pred_res[ypos-1][xpos-1]); - ValueType prediction = GetPrediction(in_data , xpos , ypos); + ValueType prediction = GetPrediction( in_data , xpos , ypos ); ValueType val = in_data[ypos][xpos] - prediction; - CodeVal(in_data , xpos , ypos , val); + CodeVal( in_data , xpos , ypos , val ); m_dc_pred_res[ypos][xpos] = in_data[ypos][xpos]; in_data[ypos][xpos] += prediction; } @@ -98,22 +98,22 @@ void IntraDCBandCodec::CodeCoeff(CoeffArray& in_data, const int xpos, const int void IntraDCBandCodec::DoWorkDecode(CoeffArray& out_data) { // Residues after prediction, quantisation and inverse quantisation - m_dc_pred_res.Resize(m_node.Yl() , m_node.Xl()); - m_dc_pred_res.Fill(0); + m_dc_pred_res.Resize( m_node.Yl() , m_node.Xl() ); + m_dc_pred_res.Fill( 0 ); BandCodec::DoWorkDecode(out_data); } -void IntraDCBandCodec::DecodeCoeff(CoeffArray& out_data, const int xpos, const int ypos) +void IntraDCBandCodec::DecodeCoeff( CoeffArray& out_data, const int xpos, const int ypos) { m_nhood_nonzero = false; - if(ypos > m_node.Yp()) + if (ypos > m_node.Yp()) m_nhood_nonzero |= bool(m_dc_pred_res[ypos-1][xpos]); - if(xpos > m_node.Xp()) + if (xpos > m_node.Xp()) m_nhood_nonzero |= bool(m_dc_pred_res[ypos][xpos-1]); - if(ypos > m_node.Yp() && xpos > m_node.Xp()) + if (ypos > m_node.Yp() && xpos > m_node.Xp()) m_nhood_nonzero |= bool(m_dc_pred_res[ypos-1][xpos-1]); - DecodeVal(out_data , xpos , ypos); + DecodeVal( out_data , xpos , ypos ); m_dc_pred_res[ypos][xpos] = out_data[ypos][xpos]; } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec.h index e03c75aaa..dfebb2e7f 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec.h @@ -48,201 +48,201 @@ namespace dirac { -class SubbandByteIO; + class SubbandByteIO; -//Subclasses the arithmetic codec to produce a coding/decoding tool for subbands + //Subclasses the arithmetic codec to produce a coding/decoding tool for subbands -//! A template class for coding and decoding wavelet subband data. -template -class GenericBandCodec: public EntropyCodec -{ -public: - - //! Constructor - /*! - Creates a BandCodec object to encode subband data - \param subband_byteio input/output for the encoded bits - \param number_of_contexts the number of contexts used in the encoding process - \param band_list the set of all the subbands - \param band_num the number of the subband being coded - \param is_intra Flag indicating whether the band comes from an intra picture - */ - GenericBandCodec(SubbandByteIO* subband_byteio, - size_t number_of_contexts, - const SubbandList& band_list, - int band_num, - const bool is_intra); + //! A template class for coding and decoding wavelet subband data. + template + class GenericBandCodec: public EntropyCodec + { + public: -protected: - //! Code an individual quantised value and perform inverse-quantisation - inline void CodeVal(CoeffArray& in_data , const int xpos , const int ypos , const CoeffType val); + //! Constructor + /*! + Creates a BandCodec object to encode subband data + \param subband_byteio input/output for the encoded bits + \param number_of_contexts the number of contexts used in the encoding process + \param band_list the set of all the subbands + \param band_num the number of the subband being coded + \param is_intra Flag indicating whether the band comes from an intra picture + */ + GenericBandCodec(SubbandByteIO* subband_byteio, + size_t number_of_contexts, + const SubbandList& band_list, + int band_num, + const bool is_intra); - //! Decode an individual quantised value and perform inverse-quantisation - inline void DecodeVal(CoeffArray& out_data , const int xpos , const int ypos); + protected: + //! Code an individual quantised value and perform inverse-quantisation + inline void CodeVal( CoeffArray& in_data , const int xpos , const int ypos , const CoeffType val); - //! Encode the offset for a code block quantiser - void CodeQuantIndexOffset(const int offset); + //! Decode an individual quantised value and perform inverse-quantisation + inline void DecodeVal(CoeffArray& out_data , const int xpos , const int ypos ); - //! Decode the offset for a code block quantiser - int DecodeQuantIndexOffset(); + //! Encode the offset for a code block quantiser + void CodeQuantIndexOffset( const int offset ); - //! Set a code block area to a given value - inline void SetToVal(const CodeBlock& code_block , CoeffArray& coeff_data , const CoeffType val); + //! Decode the offset for a code block quantiser + int DecodeQuantIndexOffset(); - //! Set all block values to 0 - virtual void ClearBlock(const CodeBlock& code_block , CoeffArray& coeff_data); + //! Set a code block area to a given value + inline void SetToVal( const CodeBlock& code_block , CoeffArray& coeff_data , const CoeffType val); -protected: - //functions - // Overridden from the base class - virtual void DoWorkCode(CoeffArray& in_data); - // Ditto - virtual void DoWorkDecode(CoeffArray& out_data); + //! Set all block values to 0 + virtual void ClearBlock( const CodeBlock& code_block , CoeffArray& coeff_data); - virtual void CodeCoeffBlock(const CodeBlock& code_block , CoeffArray& in_data); - virtual void DecodeCoeffBlock(const CodeBlock& code_block , CoeffArray& out_data); + protected: + //functions + // Overridden from the base class + virtual void DoWorkCode(CoeffArray& in_data); + // Ditto + virtual void DoWorkDecode(CoeffArray& out_data); - virtual void CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos); + virtual void CodeCoeffBlock(const CodeBlock& code_block , CoeffArray& in_data); + virtual void DecodeCoeffBlock(const CodeBlock& code_block , CoeffArray& out_data); - virtual void DecodeCoeff(CoeffArray& in_data, const int xpos, const int ypos); - //! A function for choosing the context for "follow bits" - inline int ChooseFollowContext(const int bin_number) const; + virtual void CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos); - //! A function for choosing the context for "information bits" - inline int ChooseInfoContext() const; + virtual void DecodeCoeff(CoeffArray& in_data, const int xpos, const int ypos); + //! A function for choosing the context for "follow bits" + inline int ChooseFollowContext( const int bin_number ) const; - //! A function for choosing the context for sign bits - inline int ChooseSignContext(const CoeffArray& data , const int xpos , const int ypos) const; + //! A function for choosing the context for "information bits" + inline int ChooseInfoContext() const; -private: - //! Private, bodyless copy constructor: class should not be copied - GenericBandCodec(const GenericBandCodec& cpy); - //! Private, bodyless copy operator=: class should not be assigned - GenericBandCodec& operator=(const GenericBandCodec& rhs); + //! A function for choosing the context for sign bits + inline int ChooseSignContext(const CoeffArray& data , const int xpos , const int ypos ) const; -protected: + private: + //! Private, bodyless copy constructor: class should not be copied + GenericBandCodec(const GenericBandCodec& cpy); + //! Private, bodyless copy operator=: class should not be assigned + GenericBandCodec& operator=(const GenericBandCodec& rhs); - //! Flag indicating whether the band comes from an intra picture - bool m_is_intra; + protected: - //! variables - int m_bnum; + //! Flag indicating whether the band comes from an intra picture + bool m_is_intra; - //! the subband being coded - const Subband m_node; + //! variables + int m_bnum; - //! the quantisation index of the last codeblock - int m_last_qf_idx; + //! the subband being coded + const Subband m_node; - //! quantisation value - int m_qf; + //! the quantisation index of the last codeblock + int m_last_qf_idx; - //! reconstruction point - CoeffType m_offset; + //! quantisation value + int m_qf; - //! True if neighbours non-zero - bool m_nhood_nonzero; + //! reconstruction point + CoeffType m_offset; - //! the parent subband - Subband m_pnode; + //! True if neighbours non-zero + bool m_nhood_nonzero; - //! position of the parent coefficient - int m_pxpos, m_pypos; + //! the parent subband + Subband m_pnode; - //! True if the parent of a coeff is not zero - bool m_parent_notzero; + //! position of the parent coefficient + int m_pxpos, m_pypos; -}; + //! True if the parent of a coeff is not zero + bool m_parent_notzero; -//! A general class for coding and decoding wavelet subband data. -/*! - A general class for coding and decoding wavelet subband data, deriving from the abstract ArithCodec class. - */ -typedef GenericBandCodec > BandCodec; -typedef BandCodec LFBandCodec; + }; -////////////////////////////////////////////////////////////////////////////////// -//Finally,special class incorporating prediction for the DC band of intra frames// -////////////////////////////////////////////////////////////////////////////////// - -//! A template class specially for coding the DC subband of Intra frames -template -class GenericIntraDCBandCodec : public GenericBandCodec -{ -public: - //! Constructor + //! A general class for coding and decoding wavelet subband data. /*! - Creates a IntraDCBandCodec object to encode subband data - \param subband_byteio input/output for the encoded bits - \param number_of_contexts the number of contexts used in the encoding process - \param band_list the set of all the subbands + A general class for coding and decoding wavelet subband data, deriving from the abstract ArithCodec class. */ - GenericIntraDCBandCodec(SubbandByteIO* subband_byteio, - size_t number_of_contexts, - const SubbandList& band_list) - : GenericBandCodec(subband_byteio, number_of_contexts, - band_list, band_list.Length(), - true) {} - -protected: - //! When coding a skipped block, propegate the predicted values for future non skipped blocks - void ClearBlock(const CodeBlock& code_block , CoeffArray& coeff_data); - - //! Prediction of a DC value from its previously coded neighbours - CoeffType GetPrediction(const CoeffArray& data , const int xpos , const int ypos) const; - - //! Decode codeblock of coefficients and perform DC prediction - void DecodeCoeffBlock(const CodeBlock& code_block , CoeffArray& out_data); -}; - - -//! A class specially for coding the DC subband of Intra frames -/*! - A class specially for coding the DC subband of Intra frames, using - intra-band prediction of coefficients. It uses the abstract ArithCodec - class -*/ -class IntraDCBandCodec: public GenericIntraDCBandCodec > -{ -public: - //! Constructor + typedef GenericBandCodec > BandCodec; + typedef BandCodec LFBandCodec; + + ////////////////////////////////////////////////////////////////////////////////// + //Finally,special class incorporating prediction for the DC band of intra frames// + ////////////////////////////////////////////////////////////////////////////////// + + //! A template class specially for coding the DC subband of Intra frames + template + class GenericIntraDCBandCodec : public GenericBandCodec + { + public: + //! Constructor + /*! + Creates a IntraDCBandCodec object to encode subband data + \param subband_byteio input/output for the encoded bits + \param number_of_contexts the number of contexts used in the encoding process + \param band_list the set of all the subbands + */ + GenericIntraDCBandCodec(SubbandByteIO* subband_byteio, + size_t number_of_contexts, + const SubbandList& band_list) + : GenericBandCodec(subband_byteio,number_of_contexts, + band_list, band_list.Length(), + true){} + + protected: + //! When coding a skipped block, propegate the predicted values for future non skipped blocks + void ClearBlock( const CodeBlock& code_block , CoeffArray& coeff_data); + + //! Prediction of a DC value from its previously coded neighbours + CoeffType GetPrediction(const CoeffArray& data , const int xpos , const int ypos ) const; + + //! Decode codeblock of coefficients and perform DC prediction + void DecodeCoeffBlock(const CodeBlock& code_block , CoeffArray& out_data); + }; + + + //! A class specially for coding the DC subband of Intra frames /*! - Creates a IntraDCBandCodec object to encode subband data, based on parameters - \param subband_byteio input/output for the encoded bits - \param number_of_contexts the number of contexts used in the encoding process - \param band_list the set of all the subbands - */ - IntraDCBandCodec(SubbandByteIO* subband_byteio, - size_t number_of_contexts, - const SubbandList& band_list) - : GenericIntraDCBandCodec >(subband_byteio, - number_of_contexts, - band_list) {} - - -private: - //! Initialize extra data required for error-feedback DC quantization - void DoWorkCode(CoeffArray& in_data); //overridden from the base class - - //! Ditto - void DoWorkDecode(CoeffArray& out_data); - - //! Encode a single coefficient using error-feedback DC quantization - void CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos); - - //! Decode a single coefficient using error-feedback DC quantization - void DecodeCoeff(CoeffArray& out_data, const int xpos, const int ypos); - - //! Private, bodyless copy constructor: class should not be copied - IntraDCBandCodec(const IntraDCBandCodec& cpy); - - //! Private, bodyless copy operator=: class should not be assigned - IntraDCBandCodec& operator=(const IntraDCBandCodec& rhs); - -private: - CoeffArray m_dc_pred_res; -}; + A class specially for coding the DC subband of Intra frames, using + intra-band prediction of coefficients. It uses the abstract ArithCodec + class + */ + class IntraDCBandCodec: public GenericIntraDCBandCodec > + { + public: + //! Constructor + /*! + Creates a IntraDCBandCodec object to encode subband data, based on parameters + \param subband_byteio input/output for the encoded bits + \param number_of_contexts the number of contexts used in the encoding process + \param band_list the set of all the subbands + */ + IntraDCBandCodec(SubbandByteIO* subband_byteio, + size_t number_of_contexts, + const SubbandList& band_list) + : GenericIntraDCBandCodec >(subband_byteio, + number_of_contexts, + band_list){} + + + private: + //! Initialize extra data required for error-feedback DC quantization + void DoWorkCode(CoeffArray& in_data); //overridden from the base class + + //! Ditto + void DoWorkDecode(CoeffArray& out_data); + + //! Encode a single coefficient using error-feedback DC quantization + void CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos); + + //! Decode a single coefficient using error-feedback DC quantization + void DecodeCoeff(CoeffArray& out_data, const int xpos, const int ypos); + + //! Private, bodyless copy constructor: class should not be copied + IntraDCBandCodec(const IntraDCBandCodec& cpy); + + //! Private, bodyless copy operator=: class should not be assigned + IntraDCBandCodec& operator=(const IntraDCBandCodec& rhs); + + private: + CoeffArray m_dc_pred_res; + }; }// end namespace dirac #endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec_template.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec_template.h index b1f924786..8ca94d089 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec_template.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_codec_template.h @@ -7,18 +7,18 @@ using namespace dirac; //! Constructor for encoding. template GenericBandCodec::GenericBandCodec(SubbandByteIO* subband_byteio, - size_t number_of_contexts, - const SubbandList & band_list, - int band_num, - const bool is_intra): - EntropyCodec(subband_byteio, number_of_contexts), + size_t number_of_contexts, + const SubbandList & band_list, + int band_num, + const bool is_intra): + EntropyCodec(subband_byteio,number_of_contexts), m_is_intra(is_intra), m_bnum(band_num), m_node(band_list(band_num)), m_last_qf_idx(m_node.QuantIndex()) { - if(m_node.Parent() != 0) - m_pnode = band_list(m_node.Parent()); + if (m_node.Parent()!=0) + m_pnode=band_list(m_node.Parent()); } @@ -27,30 +27,30 @@ template void GenericBandCodec::DoWorkCode(CoeffArray& in_data) { - const TwoDArray& block_list(m_node.GetCodeBlocks()); + const TwoDArray& block_list( m_node.GetCodeBlocks() ); // coeff blocks can be skipped only if SpatialPartitioning is // enabled i.e. more than one code-block per subband bool code_skip = (block_list.LengthX() > 1 || block_list.LengthY() > 1); // Now loop over the blocks and code - for(int j = block_list.FirstY() ; j <= block_list.LastY() ; ++j) + for (int j=block_list.FirstY() ; j<=block_list.LastY() ; ++j) { CodeBlock *block = block_list[j]; - for(int i = block_list.FirstX() ; i <= block_list.LastX() ; ++i) + for (int i=block_list.FirstX() ; i<=block_list.LastX() ; ++i) { - if(code_skip) - EntropyCodec::EncodeSymbol(block[i].Skipped() , BLOCK_SKIP_CTX); - if(!block[i].Skipped()) - CodeCoeffBlock(block[i] , in_data); + if (code_skip) + EntropyCodec::EncodeSymbol(block[i].Skipped() , BLOCK_SKIP_CTX ); + if ( !block[i].Skipped() ) + CodeCoeffBlock( block[i] , in_data ); else - ClearBlock(block[i] , in_data); + ClearBlock (block[i] , in_data); }// i }// j } template -void GenericBandCodec::CodeCoeffBlock(const CodeBlock& code_block , CoeffArray& in_data) +void GenericBandCodec::CodeCoeffBlock( const CodeBlock& code_block , CoeffArray& in_data ) { //main coding function, using binarisation @@ -63,39 +63,39 @@ void GenericBandCodec::CodeCoeffBlock(const CodeBlock& code_block bool has_parent = m_node.Parent() != 0; - if(m_node.UsingMultiQuants()) + if ( m_node.UsingMultiQuants() ) { - CodeQuantIndexOffset(qf_idx - m_last_qf_idx); - m_last_qf_idx = qf_idx; + CodeQuantIndexOffset( qf_idx - m_last_qf_idx); + m_last_qf_idx = qf_idx; } - m_qf = dirac_quantiser_lists.QuantFactor4(qf_idx); - if(m_is_intra) - m_offset = dirac_quantiser_lists.IntraQuantOffset4(qf_idx); + m_qf = dirac_quantiser_lists.QuantFactor4( qf_idx ); + if (m_is_intra) + m_offset = dirac_quantiser_lists.IntraQuantOffset4( qf_idx ); else - m_offset = dirac_quantiser_lists.InterQuantOffset4(qf_idx); + m_offset = dirac_quantiser_lists.InterQuantOffset4( qf_idx ); - for(int ypos = ybeg; ypos < yend ; ++ypos) + for ( int ypos=ybeg; ypos> 1) + m_pnode.Yp(); - for(int xpos = xbeg; xpos < xend ; ++xpos) + m_pypos=(( ypos-m_node.Yp() )>>1)+m_pnode.Yp(); + for ( int xpos=xbeg; xpos> 1) + m_pnode.Xp(); + m_pxpos=(( xpos-m_node.Xp() )>>1)+m_pnode.Xp(); m_nhood_nonzero = false; - if(ypos > m_node.Yp()) + if (ypos > m_node.Yp()) m_nhood_nonzero |= bool(in_data[ypos-1][xpos]); - if(xpos > m_node.Xp()) + if (xpos > m_node.Xp()) m_nhood_nonzero |= bool(in_data[ypos][xpos-1]); - if(ypos > m_node.Yp() && xpos > m_node.Xp()) + if (ypos > m_node.Yp() && xpos > m_node.Xp()) m_nhood_nonzero |= bool(in_data[ypos-1][xpos-1]); - if(has_parent) - m_parent_notzero = static_cast(in_data[m_pypos][m_pxpos]); + if (has_parent) + m_parent_notzero = static_cast ( in_data[m_pypos][m_pxpos] ); else m_parent_notzero = false; - CodeCoeff(in_data , xpos , ypos); + CodeCoeff( in_data , xpos , ypos ); }// xpos }// ypos @@ -103,9 +103,9 @@ void GenericBandCodec::CodeCoeffBlock(const CodeBlock& code_block } template -void GenericBandCodec::CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos) +void GenericBandCodec::CodeCoeff( CoeffArray& in_data, const int xpos, const int ypos) { - CodeVal(in_data , xpos , ypos , in_data[ypos][xpos]); + CodeVal( in_data , xpos , ypos , in_data[ypos][xpos] ); } @@ -128,99 +128,99 @@ based on position, and have different contexts from the info bits. */ template -inline void GenericBandCodec::CodeVal(CoeffArray& in_data , - const int xpos , - const int ypos , - const CoeffType val) +inline void GenericBandCodec::CodeVal( CoeffArray& in_data , + const int xpos , + const int ypos , + const CoeffType val ) { - unsigned int abs_val(std::abs(val)); + unsigned int abs_val( std::abs(val) ); abs_val <<= 2; abs_val /= m_qf; - const int N = abs_val + 1; - int num_follow_zeroes = 0; + const int N = abs_val+1; + int num_follow_zeroes=0; - while(N >= (1 << num_follow_zeroes)) + while ( N >= (1<= 0; --i, ++c) + for ( int i=num_follow_zeroes-1, c=1; i>=0; --i, ++c ) { - EntropyCodec::EncodeSymbol(0, ChooseFollowContext(c)); - EntropyCodec::EncodeSymbol(N&(1 << i), ChooseInfoContext()); + EntropyCodec::EncodeSymbol( 0, ChooseFollowContext( c ) ); + EntropyCodec::EncodeSymbol( N&(1<(abs_val); + in_data[ypos][xpos] = static_cast( abs_val ); - if(abs_val) + if ( abs_val ) { // Must code sign bits and reconstruct in_data[ypos][xpos] *= m_qf; - in_data[ypos][xpos] += m_offset + 2; + in_data[ypos][xpos] += m_offset+2; in_data[ypos][xpos] >>= 2; - if(val > 0) + if ( val>0 ) { - EntropyCodec::EncodeSymbol(0 , ChooseSignContext(in_data , xpos , ypos)); + EntropyCodec::EncodeSymbol( 0 , ChooseSignContext( in_data , xpos , ypos ) ); } else { - EntropyCodec::EncodeSymbol(1 , ChooseSignContext(in_data , xpos , ypos)); + EntropyCodec::EncodeSymbol( 1 , ChooseSignContext( in_data , xpos , ypos ) ); in_data[ypos][xpos] = -in_data[ypos][xpos]; } } } template -void GenericBandCodec::CodeQuantIndexOffset(const int offset) +void GenericBandCodec::CodeQuantIndexOffset( const int offset ) { - const int abs_val = std::abs(offset); + const int abs_val = std::abs( offset ); - int N = abs_val + 1; - int num_follow_zeroes = 0; + int N = abs_val+1; + int num_follow_zeroes=0; - while(N >= (1 << num_follow_zeroes)) + while ( N>= (1<= 0; --i, ++c) + for ( int i=num_follow_zeroes-1, c=1; i>=0; --i, ++c ) { - EntropyCodec::EncodeSymbol(0 , Q_OFFSET_FOLLOW_CTX); - EntropyCodec::EncodeSymbol(N&(1 << i), Q_OFFSET_INFO_CTX); + EntropyCodec::EncodeSymbol( 0 , Q_OFFSET_FOLLOW_CTX ); + EntropyCodec::EncodeSymbol( N&(1< 0) - EntropyCodec::EncodeSymbol(0 , Q_OFFSET_SIGN_CTX); + if ( offset>0 ) + EntropyCodec::EncodeSymbol( 0 , Q_OFFSET_SIGN_CTX ); else - EntropyCodec::EncodeSymbol(1 , Q_OFFSET_SIGN_CTX); + EntropyCodec::EncodeSymbol( 1 , Q_OFFSET_SIGN_CTX ); } } template -void GenericBandCodec::DoWorkDecode(CoeffArray& out_data) +void GenericBandCodec::DoWorkDecode( CoeffArray& out_data ) { - const TwoDArray& block_list(m_node.GetCodeBlocks()); + const TwoDArray& block_list( m_node.GetCodeBlocks() ); // coeff blocks can be skipped only if SpatialPartitioning is // enabled i.e. more than one code-block per subband - bool decode_skip = (block_list.LengthX() > 1 || block_list.LengthY() > 1); + bool decode_skip= (block_list.LengthX() > 1 || block_list.LengthY() > 1); // Now loop over the blocks and decode - for(int j = block_list.FirstY() ; j <= block_list.LastY() ; ++j) + for (int j=block_list.FirstY() ; j<=block_list.LastY() ; ++j) { CodeBlock *block = block_list[j]; - for(int i = block_list.FirstX() ; i <= block_list.LastX() ; ++i) + for (int i=block_list.FirstX() ; i<=block_list.LastX() ; ++i) { - if(decode_skip) - block[i].SetSkip(EntropyCodec::DecodeSymbol(BLOCK_SKIP_CTX)); - if(!block[i].Skipped()) - DecodeCoeffBlock(block[i] , out_data); + if (decode_skip) + block[i].SetSkip( EntropyCodec::DecodeSymbol( BLOCK_SKIP_CTX ) ); + if ( !block[i].Skipped() ) + DecodeCoeffBlock( block[i] , out_data ); else - ClearBlock(block[i] , out_data); + ClearBlock (block[i] , out_data); }// i }// j @@ -228,7 +228,7 @@ void GenericBandCodec::DoWorkDecode(CoeffArray& out_data) } template -void GenericBandCodec::DecodeCoeffBlock(const CodeBlock& code_block , CoeffArray& out_data) +void GenericBandCodec::DecodeCoeffBlock( const CodeBlock& code_block , CoeffArray& out_data ) { @@ -241,13 +241,13 @@ void GenericBandCodec::DecodeCoeffBlock(const CodeBlock& code_bloc bool has_parent = m_node.Parent() != 0; - if(m_node.UsingMultiQuants()) + if ( m_node.UsingMultiQuants() ) { - qf_idx = m_last_qf_idx + DecodeQuantIndexOffset(); + qf_idx = m_last_qf_idx+DecodeQuantIndexOffset(); m_last_qf_idx = qf_idx; } - if(qf_idx > (int)dirac_quantiser_lists.MaxQuantIndex()) + if (qf_idx > (int)dirac_quantiser_lists.MaxQuantIndex()) { std::ostringstream errstr; errstr << "Quantiser index out of range [0.." @@ -258,54 +258,54 @@ void GenericBandCodec::DecodeCoeffBlock(const CodeBlock& code_bloc SEVERITY_PICTURE_ERROR); } - m_qf = dirac_quantiser_lists.QuantFactor4(qf_idx); + m_qf = dirac_quantiser_lists.QuantFactor4( qf_idx ); - if(m_is_intra) - m_offset = dirac_quantiser_lists.IntraQuantOffset4(qf_idx); + if (m_is_intra) + m_offset = dirac_quantiser_lists.IntraQuantOffset4( qf_idx ); else - m_offset = dirac_quantiser_lists.InterQuantOffset4(qf_idx); + m_offset = dirac_quantiser_lists.InterQuantOffset4( qf_idx ); //Work - for(int ypos = ybeg; ypos < yend ; ++ypos) + for ( int ypos=ybeg; ypos> 1) + m_pnode.Yp(); + m_pypos=(( ypos-m_node.Yp() )>>1)+m_pnode.Yp(); CoeffType *p_out_data = NULL; - if(has_parent) + if (has_parent) p_out_data = out_data[m_pypos]; CoeffType *c_out_data_1 = NULL; - if(ypos != m_node.Yp()) + if (ypos!=m_node.Yp()) c_out_data_1 = out_data[ypos-1]; CoeffType *c_out_data_2 = out_data[ypos]; - for(int xpos = xbeg; xpos < xend ; ++xpos) + for ( int xpos=xbeg; xpos> 1) + m_pnode.Xp(); + m_pxpos=(( xpos-m_node.Xp() )>>1)+m_pnode.Xp(); m_nhood_nonzero = false; /* c_out_data_1 is the line above the current * c_out_data_2 is the current line */ - if(ypos > m_node.Yp()) + if (ypos > m_node.Yp()) m_nhood_nonzero |= bool(c_out_data_1[xpos]); - if(xpos > m_node.Xp()) + if (xpos > m_node.Xp()) m_nhood_nonzero |= bool(c_out_data_2[xpos-1]); - if(ypos > m_node.Yp() && xpos > m_node.Xp()) + if (ypos > m_node.Yp() && xpos > m_node.Xp()) m_nhood_nonzero |= bool(c_out_data_1[xpos-1]); - if(has_parent) - m_parent_notzero = (p_out_data[m_pxpos] != 0); + if (has_parent) + m_parent_notzero = ( p_out_data[m_pxpos] != 0 ); else m_parent_notzero = false; - DecodeCoeff(out_data , xpos , ypos); + DecodeCoeff( out_data , xpos , ypos ); }// xpos }// ypos } template -void GenericBandCodec::DecodeCoeff(CoeffArray& in_data, const int xpos, const int ypos) +void GenericBandCodec::DecodeCoeff( CoeffArray& in_data, const int xpos, const int ypos) { - DecodeVal(in_data , xpos , ypos); + DecodeVal( in_data , xpos , ypos ); } @@ -327,80 +327,80 @@ All bits are arithmetically coded. The follow bits have separate contexts based on position, and have different contexts from the info bits. */ template -inline void GenericBandCodec::DecodeVal(CoeffArray& out_data , const int xpos , const int ypos) +inline void GenericBandCodec::DecodeVal( CoeffArray& out_data , const int xpos , const int ypos ) { CoeffType& out_pixel = out_data[ypos][xpos]; out_pixel = 1; - int bit_count = 1; + int bit_count=1; - while(!EntropyCodec::DecodeSymbol(ChooseFollowContext(bit_count))) + while ( !EntropyCodec::DecodeSymbol( ChooseFollowContext( bit_count ) ) ) { out_pixel <<= 1; - out_pixel |= EntropyCodec::DecodeSymbol(ChooseInfoContext()); + out_pixel |= EntropyCodec::DecodeSymbol( ChooseInfoContext() ); bit_count++; }; --out_pixel; - if(out_pixel) + if ( out_pixel ) { out_pixel *= m_qf; - out_pixel += m_offset + 2; + out_pixel += m_offset+2; out_pixel >>= 2; - if(EntropyCodec::DecodeSymbol(ChooseSignContext(out_data, xpos, ypos))) + if ( EntropyCodec::DecodeSymbol( ChooseSignContext(out_data, xpos, ypos)) ) out_pixel = -out_pixel; } } template -inline int GenericBandCodec::ChooseFollowContext(const int bin_number) const +inline int GenericBandCodec::ChooseFollowContext( const int bin_number ) const { //condition on neighbouring values and parent values - if(!m_parent_notzero) + if (!m_parent_notzero) { - switch(bin_number) + switch ( bin_number ) { - case 1 : - if(m_nhood_nonzero == false) - return Z_FBIN1z_CTX; - - return Z_FBIN1nz_CTX; - - case 2 : - return Z_FBIN2_CTX; - case 3 : - return Z_FBIN3_CTX; - case 4 : - return Z_FBIN4_CTX; - case 5 : - return Z_FBIN5_CTX; - default : - return Z_FBIN6plus_CTX; + case 1 : + if(m_nhood_nonzero == false) + return Z_FBIN1z_CTX; + + return Z_FBIN1nz_CTX; + + case 2 : + return Z_FBIN2_CTX; + case 3 : + return Z_FBIN3_CTX; + case 4 : + return Z_FBIN4_CTX; + case 5 : + return Z_FBIN5_CTX; + default : + return Z_FBIN6plus_CTX; } } else { - switch(bin_number) + switch ( bin_number ) { - case 1 : - if(m_nhood_nonzero == false) - return NZ_FBIN1z_CTX; - - return NZ_FBIN1nz_CTX; - - case 2 : - return NZ_FBIN2_CTX; - case 3 : - return NZ_FBIN3_CTX; - case 4 : - return NZ_FBIN4_CTX; - case 5 : - return NZ_FBIN5_CTX; - default : - return NZ_FBIN6plus_CTX; + case 1 : + if(m_nhood_nonzero == false) + return NZ_FBIN1z_CTX; + + return NZ_FBIN1nz_CTX; + + case 2 : + return NZ_FBIN2_CTX; + case 3 : + return NZ_FBIN3_CTX; + case 4 : + return NZ_FBIN4_CTX; + case 5 : + return NZ_FBIN5_CTX; + default : + return NZ_FBIN6plus_CTX; } } @@ -416,33 +416,33 @@ inline int GenericBandCodec::ChooseInfoContext() const } template -inline int GenericBandCodec::ChooseSignContext(const CoeffArray& data , const int xpos , const int ypos) const +inline int GenericBandCodec::ChooseSignContext( const CoeffArray& data , const int xpos , const int ypos ) const { - if(m_node.Yp() == 0 && m_node.Xp() != 0) + if ( m_node.Yp()==0 && m_node.Xp()!=0 ) { //we're in a vertically oriented subband - if(ypos == 0) + if (ypos == 0) return SIGN0_CTX; else { - if(data[ypos-1][xpos] > 0) + if (data[ypos-1][xpos]>0) return SIGN_POS_CTX; - else if(data[ypos-1][xpos] < 0) + else if (data[ypos-1][xpos]<0) return SIGN_NEG_CTX; else return SIGN0_CTX; } } - else if(m_node.Xp() == 0 && m_node.Yp() != 0) + else if ( m_node.Xp()==0 && m_node.Yp()!=0 ) { //we're in a horizontally oriented subband - if(xpos == 0) + if (xpos == 0) return SIGN0_CTX; else { - if(data[ypos][xpos-1] > 0) + if ( data[ypos][xpos-1] > 0 ) return SIGN_POS_CTX; - else if(data[ypos][xpos-1] < 0) + else if ( data[ypos][xpos-1] < 0 ) return SIGN_NEG_CTX; else return SIGN0_CTX; @@ -457,40 +457,40 @@ int GenericBandCodec::DecodeQuantIndexOffset() { int offset = 1; - while(!EntropyCodec::DecodeSymbol(Q_OFFSET_FOLLOW_CTX)) + while ( !EntropyCodec::DecodeSymbol( Q_OFFSET_FOLLOW_CTX ) ) { offset <<= 1; - offset |= EntropyCodec::DecodeSymbol(Q_OFFSET_INFO_CTX); + offset |= EntropyCodec::DecodeSymbol( Q_OFFSET_INFO_CTX ); } --offset; - if(offset) + if ( offset ) { - if(EntropyCodec::DecodeSymbol(Q_OFFSET_SIGN_CTX)) + if ( EntropyCodec::DecodeSymbol( Q_OFFSET_SIGN_CTX ) ) offset = -offset; } return offset; } template -void GenericBandCodec::SetToVal(const CodeBlock& code_block , CoeffArray& pic_data , const CoeffType val) +void GenericBandCodec::SetToVal( const CodeBlock& code_block , CoeffArray& pic_data , const CoeffType val) { - for(int j = code_block.Ystart() ; j < code_block.Yend() ; j++) + for (int j=code_block.Ystart() ; j -void GenericBandCodec::ClearBlock(const CodeBlock& code_block , CoeffArray& coeff_data) +void GenericBandCodec::ClearBlock( const CodeBlock& code_block , CoeffArray& coeff_data) { - for(int j = code_block.Ystart() ; j < code_block.Yend() ; j++) + for (int j=code_block.Ystart() ; j::DecodeCoeffBlock(const CodeBlock& co { GenericBandCodec::DecodeCoeffBlock(code_block, out_data); /* do prediction for this block */ - for(int ypos = code_block.Ystart() ; ypos < code_block.Yend() ; ++ypos) + for ( int ypos=code_block.Ystart() ; ypos::DecodeCoeffBlock(const CodeBlock& co * predict the values in the next codeblock */ template -void GenericIntraDCBandCodec::ClearBlock(const CodeBlock& code_block , CoeffArray& coeff_data) +void GenericIntraDCBandCodec::ClearBlock( const CodeBlock& code_block , CoeffArray& coeff_data) { - for(int ypos = code_block.Ystart() ; ypos < code_block.Yend() ; ++ypos) + for (int ypos=code_block.Ystart() ; ypos -CoeffType GenericIntraDCBandCodec::GetPrediction(const CoeffArray& data , const int xpos , const int ypos) const +CoeffType GenericIntraDCBandCodec::GetPrediction( const CoeffArray& data , const int xpos , const int ypos ) const { /* NB, 4.5.3 integer division * numbers are rounded down towards -ve infinity, differing from * C's convention that rounds towards 0 */ - if(ypos != 0) + if (ypos!=0) { - if(xpos != 0) + if (xpos!=0) { - int sum = data[ypos][xpos-1] + data[ypos-1][xpos-1] + data[ypos-1][xpos] + 3 / 2; - if(sum < 0) - return (sum - 2) / 3; + int sum = data[ypos][xpos-1] + data[ypos-1][xpos-1] + data[ypos-1][xpos] + 3/2; + if (sum<0) + return (sum-2)/3; else - return sum / 3; + return sum/3; } else return data[ypos - 1][0]; } else { - if(xpos != 0) + if(xpos!=0) return data[0][xpos - 1]; else return 0; diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_vlc.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_vlc.cpp index 9ea1aa081..b6ddf5337 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_vlc.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_vlc.cpp @@ -47,8 +47,8 @@ using namespace dirac; ArithCodecToVLCAdapter::ArithCodecToVLCAdapter( - SubbandByteIO* subband_byteio, - size_t /*number_of_contexts*/): + SubbandByteIO* subband_byteio, + size_t /*number_of_contexts*/): m_byteio(subband_byteio) {} @@ -82,19 +82,19 @@ GenericIntraDCBandCodec::GenericIntraDCBandCodec( const SubbandList & band_list); IntraDCBandVLC::IntraDCBandVLC(SubbandByteIO* subband_byteio, - const SubbandList& band_list): + const SubbandList& band_list): GenericIntraDCBandCodec(subband_byteio, 0, band_list) {} -void IntraDCBandVLC::CodeCoeff(CoeffArray& in_data , - const int xpos , - const int ypos) +void IntraDCBandVLC::CodeCoeff( CoeffArray& in_data , + const int xpos , + const int ypos ) { CoeffType val, prediction; - prediction = GetPrediction(in_data, xpos, ypos); + prediction = GetPrediction( in_data, xpos, ypos ); val = in_data[ypos][xpos] - prediction; - CodeVal(in_data , xpos , ypos , val); + CodeVal( in_data , xpos , ypos , val ); in_data[ypos][xpos] += prediction; } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_vlc.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_vlc.h index 4cde9849c..597802d26 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_vlc.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/band_vlc.h @@ -48,92 +48,92 @@ namespace dirac { -class SubbandByteIO; -class ByteIO; + class SubbandByteIO; + class ByteIO; -/*! Abstract VLC entropy codec base class */ -class ArithCodecToVLCAdapter -{ -public: - /*! Constructor */ - ArithCodecToVLCAdapter(SubbandByteIO* subband_byteio, size_t number_of_contexts); + /*! Abstract VLC entropy codec base class */ + class ArithCodecToVLCAdapter + { + public: + /*! Constructor */ + ArithCodecToVLCAdapter(SubbandByteIO* subband_byteio, size_t number_of_contexts); - /*! Virtual Destructor */ - virtual ~ArithCodecToVLCAdapter() {} + /*! Virtual Destructor */ + virtual ~ArithCodecToVLCAdapter(){} - /* Compresses the input and returns the number of bits written */ - int Compress(CoeffArray &in_data); + /* Compresses the input and returns the number of bits written */ + int Compress (CoeffArray &in_data); - /* Decompresses the bitstream */ - void Decompress(CoeffArray& out_data, int num_bytes); + /* Decompresses the bitstream */ + void Decompress (CoeffArray& out_data, int num_bytes); - /* Encodes a symbol and writes to the output */ - void EncodeSymbol(bool val, int /*context_num*/) - { - m_byteio->WriteBit(val); - } + /* Encodes a symbol and writes to the output */ + void EncodeSymbol(bool val, int /*context_num*/) + { + m_byteio->WriteBit(val); + } - /* Decodes a symbol */ - bool DecodeSymbol(int /*context_num*/) - { - return m_byteio->ReadBoolB(); - } - - /*! Purely virtual function that does the actual encoding. Derived classes must define it */ - virtual void DoWorkCode(CoeffArray &in_data) = 0; - - /*! Purely virtual function that does the actual decoding. Derived classes must define it */ - virtual void DoWorkDecode(CoeffArray &out_data) = 0; - -protected: - /*! Input/output stream for Dirac-format bytes */ - ByteIO *m_byteio; - -private: - //! Private, bodyless copy constructor: class should not be copied - ArithCodecToVLCAdapter(const ArithCodecToVLCAdapter& cpy); - //! Private, bodyless copy operator=: class should not be assigned - ArithCodecToVLCAdapter& operator=(const ArithCodecToVLCAdapter& rhs); -}; - - -//! A general class for coding and decoding wavelet subband data using variable length coding. -/*! - A general class for coding and decoding wavelet subband data using variable length coding, - */ -typedef GenericBandCodec BandVLC; - -////////////////////////////////////////////////////////////////////////////////// -//Finally,special class incorporating prediction for the DC band of intra frames// -////////////////////////////////////////////////////////////////////////////////// - -//! A class specially for coding the DC subband of Intra frames -/*! - A class specially for coding the DC subband of Intra frames, using intra-band prediction - of coefficients. -*/ -class IntraDCBandVLC: public GenericIntraDCBandCodec -{ -public: - //! Constructor + /* Decodes a symbol */ + bool DecodeSymbol(int /*context_num*/) + { + return m_byteio->ReadBoolB(); + } + + /*! Purely virtual function that does the actual encoding. Derived classes must define it */ + virtual void DoWorkCode(CoeffArray &in_data) = 0; + + /*! Purely virtual function that does the actual decoding. Derived classes must define it */ + virtual void DoWorkDecode(CoeffArray &out_data) = 0; + + protected: + /*! Input/output stream for Dirac-format bytes */ + ByteIO *m_byteio; + + private: + //! Private, bodyless copy constructor: class should not be copied + ArithCodecToVLCAdapter(const ArithCodecToVLCAdapter& cpy); + //! Private, bodyless copy operator=: class should not be assigned + ArithCodecToVLCAdapter& operator=(const ArithCodecToVLCAdapter& rhs); + }; + + + //! A general class for coding and decoding wavelet subband data using variable length coding. /*! - Creates a IntraDCBandVLC object to encode subband data, based on parameters - \param subband_byteio input/output for the encoded bits - \param band_list the set of all the subbands + A general class for coding and decoding wavelet subband data using variable length coding, */ - IntraDCBandVLC(SubbandByteIO* subband_byteio, - const SubbandList& band_list); -private: - //! Encode a single coefficient using error-feedback DC quantization - void CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos); - -private: - //! Private, bodyless copy constructor: class should not be copied - IntraDCBandVLC(const IntraDCBandVLC& cpy); - - //! Private, bodyless copy operator=: class should not be assigned - IntraDCBandVLC& operator=(const IntraDCBandVLC& rhs); -}; + typedef GenericBandCodec BandVLC; + + ////////////////////////////////////////////////////////////////////////////////// + //Finally,special class incorporating prediction for the DC band of intra frames// + ////////////////////////////////////////////////////////////////////////////////// + + //! A class specially for coding the DC subband of Intra frames + /*! + A class specially for coding the DC subband of Intra frames, using intra-band prediction + of coefficients. + */ + class IntraDCBandVLC: public GenericIntraDCBandCodec + { + public: + //! Constructor + /*! + Creates a IntraDCBandVLC object to encode subband data, based on parameters + \param subband_byteio input/output for the encoded bits + \param band_list the set of all the subbands + */ + IntraDCBandVLC(SubbandByteIO* subband_byteio, + const SubbandList& band_list); + private: + //! Encode a single coefficient using error-feedback DC quantization + void CodeCoeff(CoeffArray& in_data, const int xpos, const int ypos); + + private: + //! Private, bodyless copy constructor: class should not be copied + IntraDCBandVLC (const IntraDCBandVLC& cpy); + + //! Private, bodyless copy operator=: class should not be assigned + IntraDCBandVLC& operator=(const IntraDCBandVLC& rhs); + }; }// end namespace dirac diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/bit_manager.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/bit_manager.cpp index 7a3470ad8..aed3d145c 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/bit_manager.cpp +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/bit_manager.cpp @@ -49,7 +49,7 @@ using std::vector; //////////////// //Constructor -BasicOutputManager::BasicOutputManager(std::ostream* out_data): +BasicOutputManager::BasicOutputManager(std::ostream* out_data ): m_num_out_bytes(0), m_op_ptr(out_data) { @@ -59,9 +59,9 @@ BasicOutputManager::BasicOutputManager(std::ostream* out_data): void BasicOutputManager::InitOutputStream() { // Set byte pointer to start of buffer - m_current_byte = 0; - // Set output mask to MSB of byte - m_output_mask = 0x80; + m_current_byte = 0; + // Set output mask to MSB of byte + m_output_mask = 0x80; // Reset the output buffer m_buffer.clear(); } @@ -69,82 +69,82 @@ void BasicOutputManager::InitOutputStream() void BasicOutputManager::OutputSkipInterpretStartPrefixByte() { size_t buf_size = m_buffer.size(); - if(buf_size >= 4 && - m_buffer[buf_size-1] == (char)START_CODE_PREFIX_BYTE3 && - m_buffer[buf_size-2] == (char)START_CODE_PREFIX_BYTE2 && - m_buffer[buf_size-3] == (char)START_CODE_PREFIX_BYTE1 && - m_buffer[buf_size-4] == (char)START_CODE_PREFIX_BYTE0) + if (buf_size >=4 && + m_buffer[buf_size-1] == (char)START_CODE_PREFIX_BYTE3 && + m_buffer[buf_size-2] == (char)START_CODE_PREFIX_BYTE2 && + m_buffer[buf_size-3] == (char)START_CODE_PREFIX_BYTE1 && + m_buffer[buf_size-4] == (char)START_CODE_PREFIX_BYTE0) { m_buffer.push_back((char)NOT_START_CODE); std::cerr << "Wrote ignore code " << std::endl; } } -void BasicOutputManager::OutputBit(const bool& bit) +void BasicOutputManager::OutputBit(const bool& bit ) { - m_current_byte |= (bit ? (m_output_mask) : 0); + m_current_byte |= (bit ? (m_output_mask):0); // Shift mask to next bit in the output byte - m_output_mask >>= 1; + m_output_mask >>= 1; - if(m_output_mask == 0) - { + if ( m_output_mask == 0 ) + { // If a whole byte has been written, write out m_output_mask = 0x80; m_buffer.push_back(m_current_byte); OutputSkipInterpretStartPrefixByte(); m_current_byte = 0; - } + } } void BasicOutputManager::OutputBit(const bool& bit, int& count) { OutputBit(bit); - count++; + count++; } void BasicOutputManager::OutputByte(const char& byte) { FlushOutput(); - m_buffer.push_back(byte); + m_buffer.push_back( byte ); OutputSkipInterpretStartPrefixByte(); } -void BasicOutputManager::OutputBytes(char* str_array) +void BasicOutputManager::OutputBytes( char* str_array ) { FlushOutput(); - while(*str_array != 0) + while ( *str_array != 0 ) { - m_buffer.push_back(*str_array); + m_buffer.push_back( *str_array ); str_array++; } } -void BasicOutputManager::OutputBytes(char* str_array, int num) +void BasicOutputManager::OutputBytes(char* str_array,int num) { FlushOutput(); - for(int i = 0 ; i < num ; ++i) - m_buffer.push_back(str_array[i]); + for ( int i=0 ; i::iterator it = m_buffer.begin() ; it != m_buffer.end() ; ++it) + for ( vector::iterator it=m_buffer.begin() ; it!=m_buffer.end() ; ++it ) { - m_op_ptr->write(&(*it) , 1); + m_op_ptr->write( &( *it ) , 1 ); } m_num_out_bytes = m_buffer.size(); - InitOutputStream(); + InitOutputStream(); } void BasicOutputManager::FlushOutput() { // Flush the current byte to output buffer and reset - if(m_output_mask != 0x80) + if ( m_output_mask != 0x80 ) { - m_buffer.push_back(m_current_byte); + m_buffer.push_back( m_current_byte ); m_current_byte = 0; m_output_mask = 0x80; } @@ -152,27 +152,27 @@ void BasicOutputManager::FlushOutput() size_t BasicOutputManager::Size() const { - if(m_output_mask == 0x80) + if ( m_output_mask==0x80 ) return m_buffer.size(); else - return m_buffer.size() + 1; + return m_buffer.size()+1; } // Unit output - a subband or the MV data, for example // -UnitOutputManager::UnitOutputManager(std::ostream* out_data): +UnitOutputManager::UnitOutputManager(std::ostream* out_data ): m_header(out_data), m_data(out_data), m_unit_bytes(0), m_unit_data_bytes(0), m_unit_head_bytes(0) -{} + {} void UnitOutputManager::WriteToFile() { m_header.WriteToFile(); m_data.WriteToFile(); - + // after writing to file, get the number of unit bytes written m_unit_data_bytes = m_data.GetNumBytes(); m_unit_head_bytes = m_header.GetNumBytes(); @@ -182,16 +182,16 @@ void UnitOutputManager::WriteToFile() size_t UnitOutputManager::Size() const { - return m_data.Size() + m_header.Size(); + return m_data.Size()+m_header.Size(); } -FrameOutputManager::FrameOutputManager(std::ostream* out_data , int num_bands) : - m_data_array(3 , num_bands), - m_comp_bytes(3), - m_comp_hdr_bytes(3), - m_out_stream(out_data) +FrameOutputManager::FrameOutputManager( std::ostream* out_data , int num_bands ) : + m_data_array( 3 , num_bands ), + m_comp_bytes( 3 ), + m_comp_hdr_bytes( 3 ), + m_out_stream( out_data ) { - Init(num_bands); + Init( num_bands ); } FrameOutputManager::~FrameOutputManager() @@ -218,13 +218,13 @@ void FrameOutputManager::WriteToFile() m_header_bytes += m_mv_hdr_bytes; // Write out the component data - for(int c = 0 ; c < 3 ; ++c) + for ( int c=0 ; c<3 ; ++c) { m_comp_hdr_bytes[c] = 0; m_comp_bytes[c] = 0; - for(int b = m_data_array.LastX() ; b >= 0 ; --b) + for ( int b=m_data_array.LastX() ; b>=0 ; --b) { m_data_array[c][b]->WriteToFile(); // after writing to file, get the number of bytes written @@ -234,52 +234,52 @@ void FrameOutputManager::WriteToFile() }// c - for(int c = 0 ; c < m_data_array.LengthY() ; ++c) + for ( int c=0 ; cSize(); - for(int c = 0 ; c < 3 ; ++c) + for ( int c=0 ; c<3 ; ++c) { - for(int b = 0 ; b < m_data_array.LengthX() ; ++b) + for ( int b=0 ; bSize(); } @@ -306,17 +306,17 @@ size_t FrameOutputManager::Size() const size += m_mv_data->Size(); return size; -} +} // Sequence stuff // -SequenceOutputManager::SequenceOutputManager(std::ostream* out_data): - m_frame_op_mgr(out_data), - m_seq_header(out_data), - m_seq_end(out_data), - m_comp_bytes(3), - m_comp_hdr_bytes(3), +SequenceOutputManager::SequenceOutputManager( std::ostream* out_data ): + m_frame_op_mgr( out_data ), + m_seq_header( out_data ), + m_seq_end( out_data ), + m_comp_bytes( 3 ), + m_comp_hdr_bytes( 3 ), m_mv_hdr_bytes(0), m_mv_bytes(0), m_total_bytes(0), @@ -324,7 +324,7 @@ SequenceOutputManager::SequenceOutputManager(std::ostream* out_data): m_trailer_bytes(0) { - for(int c = 0 ; c < 3 ; ++c) + for (int c=0 ; c<3 ; ++c ) { m_comp_hdr_bytes[c] = 0; m_comp_bytes[c] = 0; @@ -334,12 +334,12 @@ SequenceOutputManager::SequenceOutputManager(std::ostream* out_data): void SequenceOutputManager::WriteFrameData() { m_frame_op_mgr.WriteToFile(); - + // Keep up with count of component bytes - for(int c = 0 ; c < m_comp_hdr_bytes.Length(); ++c) + for (int c=0 ; cread(&m_current_byte, 1); + m_ip_ptr->read(&m_current_byte,1); m_input_bits_left = 8; - if(m_shift == START_CODE_PREFIX && (unsigned char)m_current_byte == NOT_START_CODE) + if (m_shift == START_CODE_PREFIX && (unsigned char)m_current_byte == NOT_START_CODE) { std::cerr << "Ignoring byte " << std::endl; - m_ip_ptr->read(&m_current_byte, 1); + m_ip_ptr->read(&m_current_byte,1); m_shift = 0xffffffff; } m_shift = (m_shift << 8) | m_current_byte; @@ -403,7 +403,7 @@ bool BitInputManager::InputBit() m_input_bits_left--; - return bool((m_current_byte >> m_input_bits_left) & 1); + return bool( ( m_current_byte >> m_input_bits_left ) & 1 ); } @@ -415,7 +415,7 @@ bool BitInputManager::InputBit(int& count) bool BitInputManager::InputBit(int& count, const int max_count) { - if(count < max_count) + if ( countread(&byte, 1); + m_ip_ptr->read(&byte,1); - return byte; + return byte; } void BitInputManager::InputBytes(char* cptr, int num) { - // Forget about what's in the current byte + // Forget about what's in the current byte FlushInput(); - m_ip_ptr->read(cptr, num); + m_ip_ptr->read(cptr,num); } void BitInputManager::FlushInput() { - m_input_bits_left = 0; + m_input_bits_left = 0; } -bool BitInputManager::End() const +bool BitInputManager::End() const { - return m_ip_ptr->eof(); + return m_ip_ptr->eof(); } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/bit_manager.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/bit_manager.h index 194fca1e0..6f75e8004 100644 --- a/src/filters/parser/DiracSplitter/libdirac/libdirac_common/bit_manager.h +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_common/bit_manager.h @@ -48,543 +48,477 @@ namespace dirac { -//! Prefix for all start codes -const unsigned int START_CODE_PREFIX = 0x42424344; //BBCD -const unsigned int START_CODE_PREFIX_BYTE0 = - (START_CODE_PREFIX >> 24) & 0xFF; -const unsigned int START_CODE_PREFIX_BYTE1 = - (START_CODE_PREFIX >> 16) & 0xFF; -const unsigned int START_CODE_PREFIX_BYTE2 = - (START_CODE_PREFIX >> 8) & 0xFF; -const unsigned int START_CODE_PREFIX_BYTE3 = - START_CODE_PREFIX & 0xFF; - -//! Random Access Point (RAP) Intra Picture start Code -const unsigned char RAP_START_CODE = 0xD7; -//! Non-RAP Intra Picture start code -const unsigned char IFRAME_START_CODE = 0xD6; -//! L1 Picture start code -const unsigned char L1FRAME_START_CODE = 0xD4; -//! L2 Picture start code -const unsigned char L2FRAME_START_CODE = 0xD5; -//! Sequence end code -const unsigned char SEQ_END_CODE = 0xD0; -//! Not a start code but part of data -const unsigned char NOT_START_CODE = 0xFF; -//! Bitstream version -const unsigned char BITSTREAM_VERSION = 0x05; //0.5 - - -//////////////////////////////////////////////// -//--------------Bit output stuff--------------// -//////////////////////////////////////////////// - -class UnitOutputManager; -class FrameOutputManager; -class SequenceOutputManager; - -//! Class for managing bit- and byte-oriented output. -/*! - A class for managing bit- and byte-oriented output. Wraps around - an ostream object but stores data in memory until told told to - write out in order to support data re-ordering - for example - writing a header once the subsequent data has been obtained. - Implementation to be reviewed in future. TJD 13 April 2004. -*/ -class BasicOutputManager -{ - // Data cannot be written to file directly, only by other o/p classes - friend class UnitOutputManager; - friend class FrameOutputManager; - friend class SequenceOutputManager; - -public: - //! Constructor + //! Prefix for all start codes + const unsigned int START_CODE_PREFIX = 0x42424344; //BBCD + const unsigned int START_CODE_PREFIX_BYTE0 = + (START_CODE_PREFIX >> 24) & 0xFF; + const unsigned int START_CODE_PREFIX_BYTE1 = + (START_CODE_PREFIX >> 16) & 0xFF; + const unsigned int START_CODE_PREFIX_BYTE2 = + (START_CODE_PREFIX >> 8) & 0xFF; + const unsigned int START_CODE_PREFIX_BYTE3 = + START_CODE_PREFIX & 0xFF; + + //! Random Access Point (RAP) Intra Picture start Code + const unsigned char RAP_START_CODE = 0xD7; + //! Non-RAP Intra Picture start code + const unsigned char IFRAME_START_CODE = 0xD6; + //! L1 Picture start code + const unsigned char L1FRAME_START_CODE = 0xD4; + //! L2 Picture start code + const unsigned char L2FRAME_START_CODE = 0xD5; + //! Sequence end code + const unsigned char SEQ_END_CODE = 0xD0; + //! Not a start code but part of data + const unsigned char NOT_START_CODE = 0xFF; + //! Bitstream version + const unsigned char BITSTREAM_VERSION = 0x05; //0.5 + + + //////////////////////////////////////////////// + //--------------Bit output stuff--------------// + //////////////////////////////////////////////// + + class UnitOutputManager; + class FrameOutputManager; + class SequenceOutputManager; + + //! Class for managing bit- and byte-oriented output. /*! - Constructor requires an ostream object pointer. - \param out_data the output stream object pointer + A class for managing bit- and byte-oriented output. Wraps around + an ostream object but stores data in memory until told told to + write out in order to support data re-ordering - for example + writing a header once the subsequent data has been obtained. + Implementation to be reviewed in future. TJD 13 April 2004. */ - BasicOutputManager(std::ostream* out_data); - - //Copy constructor is default shallow copy - - //Operator= is default shallow= - - //! Destructor - ~BasicOutputManager() {} - - //! Write a bit out. - /*! - Write a bit out to the internal data cache. - */ - void OutputBit(const bool& bit); - - //! Write a bit out and increment count - /*! - Write a bit out to the internal data cache and increment the - count of bits written. - */ - void OutputBit(const bool& bit, int& count); - - //! Write a byte out. - /*! - Write a byte out to the internal data cache. - */ - void OutputByte(const char& byte); - - //! Write a null-terminated set of bytes out. - /*! - Write a null-terminated set of bytes out to the internal data cache. - */ - void OutputBytes(char* str_array); - - //! Write a number of bytes out. - /*! - Write a number of bytes out to the internal data cache. - */ - void OutputBytes(char* str_array, int num); - - //! Return the number of bytes last output to file. - /*! - Return the number of bytes last output to file. - */ - size_t GetNumBytes() const + class BasicOutputManager { - return m_num_out_bytes; - } - - //! Current size of the internal data cache in bytes. + // Data cannot be written to file directly, only by other o/p classes + friend class UnitOutputManager; + friend class FrameOutputManager; + friend class SequenceOutputManager; + + public: + //! Constructor + /*! + Constructor requires an ostream object pointer. + \param out_data the output stream object pointer + */ + BasicOutputManager(std::ostream* out_data ); + + //Copy constructor is default shallow copy + + //Operator= is default shallow= + + //! Destructor + ~BasicOutputManager(){} + + //! Write a bit out. + /*! + Write a bit out to the internal data cache. + */ + void OutputBit(const bool& bit); + + //! Write a bit out and increment count + /*! + Write a bit out to the internal data cache and increment the + count of bits written. + */ + void OutputBit(const bool& bit,int& count); + + //! Write a byte out. + /*! + Write a byte out to the internal data cache. + */ + void OutputByte(const char& byte); + + //! Write a null-terminated set of bytes out. + /*! + Write a null-terminated set of bytes out to the internal data cache. + */ + void OutputBytes(char* str_array); + + //! Write a number of bytes out. + /*! + Write a number of bytes out to the internal data cache. + */ + void OutputBytes(char* str_array,int num); + + //! Return the number of bytes last output to file. + /*! + Return the number of bytes last output to file. + */ + size_t GetNumBytes() const {return m_num_out_bytes;} + + //! Current size of the internal data cache in bytes. + /*! + Current size of the internal data cache in bytes. + */ + size_t Size() const; + + private: + // Number of output bytes written + size_t m_num_out_bytes; + std::ostream* m_op_ptr; + // Buffer used to store output prior to saving to file + std::vector m_buffer; + // Char used for temporary storage of op data bits + char m_current_byte; + // Used to set individual bit within the current header byte + int m_output_mask; + + //functions + + //! Write all data to file. + /*! + Dump the internal data cache to the internal ostream object. + */ + void WriteToFile(); + + //Initialise the output stream. + void InitOutputStream(); + + //Clean out any remaining output bits to the buffer + void FlushOutput(); + + //! Write an ignore code + /*! + Write a skip interpret start prefix byte out to the internal data + cache. + */ + void OutputSkipInterpretStartPrefixByte(); + }; + + //! A class for handling data output, including headers. /*! - Current size of the internal data cache in bytes. + A class for handling data output, including headers and reordering. */ - size_t Size() const; - -private: - // Number of output bytes written - size_t m_num_out_bytes; - std::ostream* m_op_ptr; - // Buffer used to store output prior to saving to file - std::vector m_buffer; - // Char used for temporary storage of op data bits - char m_current_byte; - // Used to set individual bit within the current header byte - int m_output_mask; - - //functions - - //! Write all data to file. - /*! - Dump the internal data cache to the internal ostream object. - */ - void WriteToFile(); - - //Initialise the output stream. - void InitOutputStream(); - - //Clean out any remaining output bits to the buffer - void FlushOutput(); - - //! Write an ignore code - /*! - Write a skip interpret start prefix byte out to the internal data - cache. - */ - void OutputSkipInterpretStartPrefixByte(); -}; - -//! A class for handling data output, including headers. -/*! -A class for handling data output, including headers and reordering. -*/ -class UnitOutputManager -{ - // Only the FrameOutputManager can make this class write data to file - friend class FrameOutputManager; - -public: - //! Constructor. - /*! - Constructor wraps around a pointer to an ostream object, and - initialises two BasicOutputManager objects for header and data - */ - UnitOutputManager(std::ostream* out_data); - - //Copy constructor is default shallow copy - - //Operator= is default shallow= - - //! Destructor - ~UnitOutputManager() {} - - //! Handles the header bits. - /*! - A BasicOutputManager object for handling the header bits. - */ - BasicOutputManager& Header() + class UnitOutputManager { - return m_header; - } - - //! Handles the data bits. - /*! - A BasicOutputManager object for handling the data bits. - */ - BasicOutputManager& Data() + // Only the FrameOutputManager can make this class write data to file + friend class FrameOutputManager; + + public: + //! Constructor. + /*! + Constructor wraps around a pointer to an ostream object, and + initialises two BasicOutputManager objects for header and data + */ + UnitOutputManager(std::ostream* out_data ); + + //Copy constructor is default shallow copy + + //Operator= is default shallow= + + //! Destructor + ~UnitOutputManager(){} + + //! Handles the header bits. + /*! + A BasicOutputManager object for handling the header bits. + */ + BasicOutputManager& Header(){return m_header;} + + //! Handles the data bits. + /*! + A BasicOutputManager object for handling the data bits. + */ + BasicOutputManager& Data(){return m_data;} + + //! Returns the total number of bytes written in the last unit coded. + /*! + Returns the total number of bytes written in the last unit coded - header + data. + */ + const size_t GetUnitBytes() const {return m_unit_bytes;} + + //! Returns the total number of header bytes written in the last unit coded. + const size_t GetUnitHeaderBytes() const {return m_unit_head_bytes;} + + //! Current size of the internal data cache in bytes. + /*! + Current size of the internal data cache in bytes. + */ + size_t Size() const; + + private: + // basic output managers for the header and data + BasicOutputManager m_header,m_data; + + // total number of bytes written in the last unit coded + size_t m_unit_bytes; + + // number of data bytes for the last unit coded + size_t m_unit_data_bytes; + + // number of data bytes for the last unit coded + size_t m_unit_head_bytes; + + // functions + + //! Writes the bit caches to file. + /*! + Writes the header bits to the ostream, followed by the data bits. + */ + void WriteToFile(); + }; + + class FrameOutputManager { - return m_data; - } + public: - //! Returns the total number of bytes written in the last unit coded. - /*! - Returns the total number of bytes written in the last unit coded - header + data. - */ - const size_t GetUnitBytes() const - { - return m_unit_bytes; - } + // Only the SequenceOutputManager can make this class write data to file + friend class SequenceOutputManager; - //! Returns the total number of header bytes written in the last unit coded. - const size_t GetUnitHeaderBytes() const - { - return m_unit_head_bytes; - } + //! Constructor + /* + Constructs a class which manages output for an entire picture. + \param out_data pointer to the output stream + \param num_bands the number of subbands per component + */ + FrameOutputManager( std::ostream* out_data , const int num_bands=13 ); - //! Current size of the internal data cache in bytes. - /*! - Current size of the internal data cache in bytes. - */ - size_t Size() const; - -private: - // basic output managers for the header and data - BasicOutputManager m_header, m_data; - - // total number of bytes written in the last unit coded - size_t m_unit_bytes; - - // number of data bytes for the last unit coded - size_t m_unit_data_bytes; - - // number of data bytes for the last unit coded - size_t m_unit_head_bytes; - - // functions - - //! Writes the bit caches to file. - /*! - Writes the header bits to the ostream, followed by the data bits. - */ - void WriteToFile(); -}; - -class FrameOutputManager -{ -public: - - // Only the SequenceOutputManager can make this class write data to file - friend class SequenceOutputManager; + //! Destructor + ~FrameOutputManager(); - //! Constructor - /* - Constructs a class which manages output for an entire picture. - \param out_data pointer to the output stream - \param num_bands the number of subbands per component - */ - FrameOutputManager(std::ostream* out_data , const int num_bands = 13); - - //! Destructor - ~FrameOutputManager(); - - //! Set the number of bands there will be in a component - void SetNumBands(const int num_bands); - - //! Get an output manager for a subband - /*! - Get an output manager for a subband. - \param csort the component (Y, U or V) - \param band_num the number of the subband - */ - UnitOutputManager& BandOutput(const int csort , const int band_num); + //! Set the number of bands there will be in a component + void SetNumBands( const int num_bands ); - //! Get an output manager for a subband - /*! - Get an output manager for a subband. - \param csort the component (Y, U or V) - \param band_num the number of the subband - */ - const UnitOutputManager& BandOutput(const int csort , const int band_num) const; + //! Get an output manager for a subband + /*! + Get an output manager for a subband. + \param csort the component (Y, U or V) + \param band_num the number of the subband + */ + UnitOutputManager& BandOutput( const int csort , const int band_num ); - //! Get an output manager for MV data - /*! - Get an output manager for MV data - */ - UnitOutputManager& MVOutput() - { - return *m_mv_data; - } + //! Get an output manager for a subband + /*! + Get an output manager for a subband. + \param csort the component (Y, U or V) + \param band_num the number of the subband + */ + const UnitOutputManager& BandOutput( const int csort , const int band_num ) const; - //! Get an output manager for MV data - /*! - Get an output manager for MV data - */ - const UnitOutputManager& MVOutput() const - { - return *m_mv_data; - } + //! Get an output manager for MV data + /*! + Get an output manager for MV data + */ + UnitOutputManager& MVOutput(){ return *m_mv_data; } - //! Get an output manager for the picture header - BasicOutputManager& HeaderOutput() - { - return *m_frame_header; - } + //! Get an output manager for MV data + /*! + Get an output manager for MV data + */ + const UnitOutputManager& MVOutput() const { return *m_mv_data; } - //! Return the number of bytes used for each component - const size_t ComponentBytes(const int comp_num) const - { - return m_comp_bytes[comp_num]; - } + //! Get an output manager for the picture header + BasicOutputManager& HeaderOutput(){ return *m_frame_header; } - //! Return the number of header bytes used for each component - const size_t ComponentHeadBytes(const int comp_num) const - { - return m_comp_hdr_bytes[comp_num]; - } + //! Return the number of bytes used for each component + const size_t ComponentBytes( const int comp_num ) const { return m_comp_bytes[comp_num];} - //! Return the number of motion vector bytes used - const size_t MVBytes() const - { - return m_mv_bytes; - } + //! Return the number of header bytes used for each component + const size_t ComponentHeadBytes( const int comp_num ) const { return m_comp_hdr_bytes[comp_num];} - //! Return the number of motion vector header bytes used - const size_t MVHeadBytes() const - { - return m_mv_hdr_bytes; - } + //! Return the number of motion vector bytes used + const size_t MVBytes() const { return m_mv_bytes;} - //! Return the number of bytes used for the whole picture - const size_t FrameBytes() const - { - return m_total_bytes; - } + //! Return the number of motion vector header bytes used + const size_t MVHeadBytes() const { return m_mv_hdr_bytes;} - //! Return the number of header bytes used throughout the picture - const size_t FrameHeadBytes() const - { - return m_header_bytes; - } + //! Return the number of bytes used for the whole picture + const size_t FrameBytes() const { return m_total_bytes;} - //! Current size of the internal data cache in bytes. - /*! - Current size of the internal data cache in bytes. - */ - size_t Size() const; + //! Return the number of header bytes used throughout the picture + const size_t FrameHeadBytes() const { return m_header_bytes;} -private: + //! Current size of the internal data cache in bytes. + /*! + Current size of the internal data cache in bytes. + */ + size_t Size() const; - // Array of subband outputs, 1 for each component and subband - TwoDArray< UnitOutputManager* > m_data_array; + private: - // Motion vector output - UnitOutputManager* m_mv_data; + // Array of subband outputs, 1 for each component and subband + TwoDArray< UnitOutputManager* > m_data_array; - // Picture header output - BasicOutputManager* m_frame_header; + // Motion vector output + UnitOutputManager* m_mv_data; - // The total number of picture bytes - size_t m_total_bytes; + // Picture header output + BasicOutputManager* m_frame_header; - // The total number of header bytes - size_t m_header_bytes; + // The total number of picture bytes + size_t m_total_bytes; - // The total number of MV header bytes - size_t m_mv_hdr_bytes; + // The total number of header bytes + size_t m_header_bytes; - // The total number of MV bytes - size_t m_mv_bytes; + // The total number of MV header bytes + size_t m_mv_hdr_bytes; - // The total number of bytes in each component - OneDArray< size_t > m_comp_bytes; + // The total number of MV bytes + size_t m_mv_bytes; - // The total number of header bytes in each component - OneDArray< size_t > m_comp_hdr_bytes; + // The total number of bytes in each component + OneDArray< size_t > m_comp_bytes; - // A copy of a pointer to the output stream - std::ostream* m_out_stream; + // The total number of header bytes in each component + OneDArray< size_t > m_comp_hdr_bytes; - // Functions + // A copy of a pointer to the output stream + std::ostream* m_out_stream; - //! Initialise the band data - void Init(const int num_bands); + // Functions - //! Reset all the data - void Reset(); + //! Initialise the band data + void Init( const int num_bands ); - //! Delete all the data - void DeleteAll(); + //! Reset all the data + void Reset(); - //! Write all the picture data to file - void WriteToFile(); -}; + //! Delete all the data + void DeleteAll(); -class SequenceOutputManager -{ -public: - //! Constructor - SequenceOutputManager(std::ostream* out_data); + //! Write all the picture data to file + void WriteToFile(); + }; - //! Return a reference to the output for a single picture - FrameOutputManager& FrameOutput() + class SequenceOutputManager { - return m_frame_op_mgr; - } + public: + //! Constructor + SequenceOutputManager( std::ostream* out_data ); - //! Return a reference to the output for the sequence header - BasicOutputManager& HeaderOutput() - { - return m_seq_header; - } + //! Return a reference to the output for a single picture + FrameOutputManager& FrameOutput(){ return m_frame_op_mgr; } - //! Return a reference to the output for the sequence trailer - BasicOutputManager& TrailerOutput() - { - return m_seq_end; - } + //! Return a reference to the output for the sequence header + BasicOutputManager& HeaderOutput(){ return m_seq_header; } - //! Reset the picture data without outputting - void ResetFrame() - { - m_frame_op_mgr.Reset(); - } + //! Return a reference to the output for the sequence trailer + BasicOutputManager& TrailerOutput(){ return m_seq_end; } - //! Write the sequence header - void WriteSeqHeaderToFile(); + //! Reset the picture data without outputting + void ResetFrame(){ m_frame_op_mgr.Reset(); } - //! Write all the picture data to file - void WriteFrameData(); + //! Write the sequence header + void WriteSeqHeaderToFile(); - //! Write the sequence trailer - void WriteSeqTrailerToFile(); + //! Write all the picture data to file + void WriteFrameData(); - //! Return the total number of bytes used for the sequence - const size_t SequenceBytes() - { - return m_total_bytes; - } + //! Write the sequence trailer + void WriteSeqTrailerToFile(); - //! Return the total number of header bytes used throughout the sequence - const size_t SequenceHeadBytes() - { - return m_header_bytes; - } + //! Return the total number of bytes used for the sequence + const size_t SequenceBytes() { return m_total_bytes; } - //! Return the total number bytes used for MVs - const size_t MVBytes() - { - return m_mv_bytes; - } + //! Return the total number of header bytes used throughout the sequence + const size_t SequenceHeadBytes() { return m_header_bytes; } - //! Return the total number bytes used for a component - const size_t ComponentBytes(const int comp_num) - { - return m_comp_bytes[comp_num]; - } + //! Return the total number bytes used for MVs + const size_t MVBytes() { return m_mv_bytes; } - //! Reset the picture data - void ResetFrameData(); + //! Return the total number bytes used for a component + const size_t ComponentBytes( const int comp_num ) { return m_comp_bytes[comp_num]; } + //! Reset the picture data + void ResetFrameData(); -private: - // The picture output manager - FrameOutputManager m_frame_op_mgr; + private: - // Output manager for the sequence header - BasicOutputManager m_seq_header; + // The picture output manager + FrameOutputManager m_frame_op_mgr; - // Output manager for the sequence end - BasicOutputManager m_seq_end; + // Output manager for the sequence header + BasicOutputManager m_seq_header; - // The total number of bytes in each component - OneDArray< size_t > m_comp_bytes; + // Output manager for the sequence end + BasicOutputManager m_seq_end; - // The total number of header bits in each component - OneDArray< size_t > m_comp_hdr_bytes; + // The total number of bytes in each component + OneDArray< size_t > m_comp_bytes; - // The number of MV header bytes - size_t m_mv_hdr_bytes; + // The total number of header bits in each component + OneDArray< size_t > m_comp_hdr_bytes; - // The total number of MV bytes - size_t m_mv_bytes; + // The number of MV header bytes + size_t m_mv_hdr_bytes; - // The total number of bytes written so far - size_t m_total_bytes; + // The total number of MV bytes + size_t m_mv_bytes; - // The total number of header bytes written so far - size_t m_header_bytes; + // The total number of bytes written so far + size_t m_total_bytes; - // The total number of trailer bytes written so far - size_t m_trailer_bytes; -}; + // The total number of header bytes written so far + size_t m_header_bytes; -/////////////////////////////////////////////// -//--------------Bit input stuff--------------// -/////////////////////////////////////////////// + // The total number of trailer bytes written so far + size_t m_trailer_bytes; + }; -//! A class for managing bit-wise and byte-wise input. -class BitInputManager -{ + /////////////////////////////////////////////// + //--------------Bit input stuff--------------// + /////////////////////////////////////////////// -public: - //! Constructor. - /*! - Constructor. Wraps around an istream object. - */ - BitInputManager(std::istream* in_data); + //! A class for managing bit-wise and byte-wise input. + class BitInputManager + { + + public: + //! Constructor. + /*! + Constructor. Wraps around an istream object. + */ + BitInputManager(std::istream* in_data ); - //Copy constructor is default shallow copy + //Copy constructor is default shallow copy - //Operator= is default shallow= + //Operator= is default shallow= - //! Destructor - ~BitInputManager() {} + //! Destructor + ~BitInputManager(){} - //input functions - //! Obtain the next bit. - bool InputBit(); + //input functions + //! Obtain the next bit. + bool InputBit(); - //! Obtain the next bit, incrementing count. - bool InputBit(int& count); + //! Obtain the next bit, incrementing count. + bool InputBit(int& count); - //! Obtain the next bit, incrementing count, if count & bool_opts) - : m_options(), - m_inputs(), - m_bool_opts(bool_opts) + : m_options(), + m_inputs(), + m_bool_opts(bool_opts) { bool option_active = false; vector