From 44228422b7c2d3af84272db42b92a164ab564a1e Mon Sep 17 00:00:00 2001 From: Christian Gmeiner Date: Sat, 10 Apr 2010 17:41:32 +0000 Subject: make use of Accessors --- dxr3audiodecoder.c | 4 +- dxr3device.c | 6 +-- dxr3pesframe.c | 26 ++++++------- dxr3pesframe.h | 106 ++++++++--------------------------------------------- 4 files changed, 34 insertions(+), 108 deletions(-) diff --git a/dxr3audiodecoder.c b/dxr3audiodecoder.c index 8f9da64..71196fa 100644 --- a/dxr3audiodecoder.c +++ b/dxr3audiodecoder.c @@ -91,8 +91,8 @@ void cDxr3AudioDecoder::decode(cDxr3PesFrame *frame, iAudio *audio) { int len, out_size; - const uint8_t *buf = frame->GetPayload(); - int length = frame->GetPayloadLength(); + const uint8_t *buf = frame->payload(); + int length = frame->payloadSize(); if (checkMpegAudioHdr(buf)) { diff --git a/dxr3device.c b/dxr3device.c index 81726c6..19af588 100644 --- a/dxr3device.c +++ b/dxr3device.c @@ -233,7 +233,7 @@ int cDxr3Device::PlayVideo(const uchar *Data, int Length) cDxr3PesFrame frame; frame.parse(Data, Length); - uint32_t pts = frame.GetPts(); + uint32_t pts = frame.pts(); if (pts == 0) { pts = vPts; @@ -557,8 +557,8 @@ void cDxr3Device::playVideoFrame(cDxr3PesFrame *frame, uint32_t pts) CHECK(ioctl(fdVideo, EM8300_IOCTL_VIDEO_SETPTS, &pts)); } - const uint8_t *data = frame->GetPayload(); - uint32_t len = frame->GetPayloadLength(); + const uint8_t *data = frame->payload(); + uint32_t len = frame->payloadSize(); WriteAllOrNothing(fdVideo, data, len, 1000, 10); } diff --git a/dxr3pesframe.c b/dxr3pesframe.c index c0731da..1514d95 100644 --- a/dxr3pesframe.c +++ b/dxr3pesframe.c @@ -37,15 +37,15 @@ bool cDxr3PesFrame::parse(const uint8_t *pes, uint32_t length) // handle stream id switch (pes[3]) { case 0xBD: // private stream 1 - m_pesDataType = PES_PRIVATE_DATA; + pesDataType = PES_PRIVATE_DATA; break; case 0xC0 ... 0xDF: // audio stream - m_pesDataType = PES_AUDIO_DATA; + pesDataType = PES_AUDIO_DATA; break; case 0xE0 ... 0xEF: // video stream - m_pesDataType = PES_VIDEO_DATA; + pesDataType = PES_VIDEO_DATA; break; default: @@ -53,7 +53,7 @@ bool cDxr3PesFrame::parse(const uint8_t *pes, uint32_t length) } // store start of pes frame - m_pesStart = pes; + pesStart = pes; // read pes header len uint8_t pesHeaderDataLength = pes[8]; @@ -67,15 +67,15 @@ bool cDxr3PesFrame::parse(const uint8_t *pes, uint32_t length) pts |= ( (int64_t)pes[12]) << 7; pts |= (((int64_t)pes[13]) & 0xfe) >> 1; - m_pts = pts >> 1; + this->pts = pts >> 1; } // set pointer to start of payload int payloadStart = 9 + pesHeaderDataLength; - m_payload = &pes[payloadStart]; - m_payloadLength = length - payloadStart; + payload = &pes[payloadStart]; + payloadSize = length - payloadStart; - if (m_pesDataType == PES_VIDEO_DATA) { + if (pesDataType() == PES_VIDEO_DATA) { // we can get some informations about the video payload // of this pes frame. For more informations have a look @@ -94,20 +94,20 @@ bool cDxr3PesFrame::parse(const uint8_t *pes, uint32_t length) // in the sequence header we get informations about horizontal // and vertical size of the video and the current aspect ratio. - m_horizontalSize = (video[5] & 0xf0) >> 4 | video[4] << 4; - m_verticalSize = (video[5] & 0x0f) << 8 | video[6]; + horizontalSize = (video[5] & 0xf0) >> 4 | video[4] << 4; + verticalSize = (video[5] & 0x0f) << 8 | video[6]; switch (video[7] & 0xf0) { case 0x20: - m_aspectRatio = EM8300_ASPECTRATIO_4_3; + aspectRatio = EM8300_ASPECTRATIO_4_3; break; case 0x30: - m_aspectRatio = EM8300_ASPECTRATIO_16_9; + aspectRatio = EM8300_ASPECTRATIO_16_9; break; } - m_staticAspectRatio = m_aspectRatio; + m_staticAspectRatio = aspectRatio(); } } diff --git a/dxr3pesframe.h b/dxr3pesframe.h index 5faa175..66fa69b 100644 --- a/dxr3pesframe.h +++ b/dxr3pesframe.h @@ -22,18 +22,9 @@ #ifndef _DXR3PESFRAME_H_ #define _DXR3PESFRAME_H_ -#include #include #include "uncopyable.h" - -// ================================== -enum eVideoFrameType -{ - I_FRAME, - P_FRAME, - B_FRAME, - UNKNOWN_FRAME -}; +#include "accessors.h" // ================================== // pes - packetized elementary stream @@ -41,98 +32,33 @@ class cDxr3PesFrame : private Uncopyable { public: // ================================== - enum ePesDataType - { - PES_AUDIO_DATA, - PES_VIDEO_DATA, - PES_PRIVATE_DATA, - PES_UNKNOWN_DATA + enum ePesDataType { + PES_AUDIO_DATA, + PES_VIDEO_DATA, + PES_PRIVATE_DATA, + PES_UNKNOWN_DATA }; public: - cDxr3PesFrame() : - m_pesDataType(PES_UNKNOWN_DATA), - m_pesStart(0), - m_payload(0), - m_payloadLength(0), - m_pts(0), - m_videoFrameType(UNKNOWN_FRAME), - m_aspectRatio(m_staticAspectRatio), - m_horizontalSize(0), - m_verticalSize(0) {} - - virtual ~cDxr3PesFrame() {} + cDxr3PesFrame() : pesDataType(PES_UNKNOWN_DATA), pesStart(0), payload(0), payloadSize(0), + pts(0), aspectRatio(m_staticAspectRatio), horizontalSize(0), verticalSize(0) {} bool parse(const uint8_t *pes, uint32_t length); - ePesDataType GetPesDataType() const - { - return m_pesDataType; - } - - const uint8_t* GetPesStart() const - { - return m_pesStart; - } - - const uint8_t* GetPayload() const - { - return m_payload; - } - - uint32_t GetPayloadLength() const - { - return m_payloadLength; - } + Accessors pesDataType; - uint32_t GetPts() const - { - return m_pts; - } + Accessors pesStart; + Accessors payload; - eVideoFrameType GetFrameType() const - { - assert(m_pesDataType == PES_VIDEO_DATA); - return m_videoFrameType; - } + Accessors payloadSize; + Accessors pts; - uint32_t GetAspectRatio() const - { - assert(m_pesDataType == PES_VIDEO_DATA); - return m_aspectRatio; - } - - uint32_t GetHorizontalSize() const - { - assert(m_pesDataType == PES_VIDEO_DATA); - return m_horizontalSize; - } - - uint32_t GetVerticalSize() const - { - assert(m_pesDataType == PES_VIDEO_DATA); - return m_verticalSize; - } - - // needed for audio - uint32_t decodedSize; - int16_t *decoded; + Accessors aspectRatio; + Accessors horizontalSize; + Accessors verticalSize; private: - ePesDataType m_pesDataType; - const uint8_t* m_pesStart; - const uint8_t* m_payload; - uint32_t m_payloadLength; - uint32_t m_pts; - - eVideoFrameType m_videoFrameType; - uint32_t m_aspectRatio; - uint32_t m_horizontalSize; - uint32_t m_verticalSize; - static uint32_t m_staticAspectRatio; - - static const uint32_t MAX_PES_HEADER_SIZE; }; #endif /*_DXR3PESFRAME_H_*/ -- cgit v1.2.3