From 075e91fa27e4fe0579febf35469ea86c8e381a56 Mon Sep 17 00:00:00 2001 From: "pwestin@webrtc.org" Date: Wed, 2 Nov 2011 23:14:58 +0000 Subject: [PATCH] Added parsing of width and height from VP8 header Review URL: http://webrtc-codereview.appspot.com/241012 git-svn-id: http://webrtc.googlecode.com/svn/trunk@875 4adac7df-926f-26a2-2b94-8c16560cd09d --- src/modules/interface/module_common_types.h | 4 +++ .../rtp_rtcp/source/rtp_receiver_video.cc | 4 +++ src/modules/rtp_rtcp/source/rtp_utility.cc | 33 ++++++++++++++++--- src/modules/rtp_rtcp/source/rtp_utility.h | 12 +++++-- 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/modules/interface/module_common_types.h b/src/modules/interface/module_common_types.h index 99e1b6895..2070029ca 100644 --- a/src/modules/interface/module_common_types.h +++ b/src/modules/interface/module_common_types.h @@ -58,6 +58,8 @@ struct RTPVideoHeaderVP8 temporalIdx = kNoTemporalIdx; partitionId = 0; beginningOfPartition = false; + frameWidth = 0; + frameHeight = 0; } bool nonReference; // Frame is discardable. @@ -69,6 +71,8 @@ struct RTPVideoHeaderVP8 int partitionId; // VP8 partition ID bool beginningOfPartition; // True if this packet is the first // in a VP8 partition. Otherwise false + int frameWidth; // Exists for key frames. + int frameHeight; // Exists for key frames. }; union RTPVideoTypeHeader { diff --git a/src/modules/rtp_rtcp/source/rtp_receiver_video.cc b/src/modules/rtp_rtcp/source/rtp_receiver_video.cc index e1e99ccc5..fc002373c 100644 --- a/src/modules/rtp_rtcp/source/rtp_receiver_video.cc +++ b/src/modules/rtp_rtcp/source/rtp_receiver_video.cc @@ -647,6 +647,10 @@ RTPReceiverVideo::ReceiveVp8Codec(WebRtcRTPHeader* rtpHeader, kNoTl0PicIdx; toHeader->temporalIdx = fromHeader->hasTID ? fromHeader->tID : kNoTemporalIdx; + + toHeader->frameWidth = fromHeader->frameWidth; + toHeader->frameHeight = fromHeader->frameHeight; + toHeader->partitionId = fromHeader->partitionID; toHeader->beginningOfPartition = fromHeader->beginningOfPartition; diff --git a/src/modules/rtp_rtcp/source/rtp_utility.cc b/src/modules/rtp_rtcp/source/rtp_utility.cc index f89f9c64a..08be8a07d 100644 --- a/src/modules/rtp_rtcp/source/rtp_utility.cc +++ b/src/modules/rtp_rtcp/source/rtp_utility.cc @@ -385,6 +385,8 @@ ModuleRTPUtility::RTPPayload::SetType(RtpVideoCodecTypes videoType) info.VP8.pictureID = -1; info.VP8.tl0PicIdx = -1; info.VP8.tID = -1; + info.VP8.frameWidth = 0; + info.VP8.frameHeight = 0; break; } default: @@ -868,15 +870,38 @@ ModuleRTPUtility::RTPPayloadParser::ParseVP8(RTPPayload& parsedPacket) const { parsedPacket.frameType = kPFrame; } - + if (0 != ParseVP8FrameSize(parsedPacket, dataPtr, dataLength)) + { + return false; + } parsedPacket.info.VP8.data = dataPtr; parsedPacket.info.VP8.dataLength = dataLength; - return true; } -int -ModuleRTPUtility::RTPPayloadParser::ParseVP8Extension( +int ModuleRTPUtility::RTPPayloadParser::ParseVP8FrameSize( + RTPPayload &parsedPacket, + const WebRtc_UWord8 *dataPtr, + int dataLength) const +{ + if (parsedPacket.frameType != kIFrame) + { + // Included in payload header for I-frames. + return 0; + } + if (dataLength < 10) + { + // For an I-frame we should always have the uncompressed VP8 header + // in the beginning of the partition. + return -1; + } + RTPPayloadVP8 *vp8 = &parsedPacket.info.VP8; + vp8->frameWidth = ((dataPtr[7] << 8) + dataPtr[6]) & 0x3FFF; + vp8->frameHeight = ((dataPtr[9] << 8) + dataPtr[8]) & 0x3FFF; + return 0; +} + +int ModuleRTPUtility::RTPPayloadParser::ParseVP8Extension( RTPPayloadVP8 *vp8, const WebRtc_UWord8 *dataPtr, int dataLength) const diff --git a/src/modules/rtp_rtcp/source/rtp_utility.h b/src/modules/rtp_rtcp/source/rtp_utility.h index 4481b6369..72127ce26 100644 --- a/src/modules/rtp_rtcp/source/rtp_utility.h +++ b/src/modules/rtp_rtcp/source/rtp_utility.h @@ -42,7 +42,7 @@ namespace ModuleRTPUtility struct VideoPayload { RtpVideoCodecTypes videoCodecType; - WebRtc_UWord32 maxRate; + WebRtc_UWord32 maxRate; }; union PayloadUnion { @@ -51,7 +51,7 @@ namespace ModuleRTPUtility }; struct Payload { - WebRtc_Word8 name[RTP_PAYLOAD_NAME_SIZE]; + WebRtc_Word8 name[RTP_PAYLOAD_NAME_SIZE]; bool audio; PayloadUnion typeSpecific; }; @@ -148,8 +148,10 @@ namespace ModuleRTPUtility int pictureID; int tl0PicIdx; int tID; + int frameWidth; + int frameHeight; - const WebRtc_UWord8* data; + const WebRtc_UWord8* data; WebRtc_UWord16 dataLength; }; @@ -211,6 +213,10 @@ namespace ModuleRTPUtility int *dataLength, int *parsedBytes) const; + int ParseVP8FrameSize(RTPPayload& parsedPacket, + const WebRtc_UWord8 *dataPtr, + int dataLength) const; + // H.263 bool H263PictureStartCode(const WebRtc_UWord8* data, const bool skipFirst2bytes = false) const;