[Sumover-dev] [svn commit] r4400 - vic/branches/mpeg4/codec
sumover-dev at cs.ucl.ac.uk
sumover-dev at cs.ucl.ac.uk
Wed Mar 18 10:41:02 GMT 2009
Author: piers
Date: Wed Mar 18 10:41:01 2009
New Revision: 4400
Modified:
vic/branches/mpeg4/codec/decoder-h264.cpp
vic/branches/mpeg4/codec/rtp_h264_depayloader.cpp
vic/branches/mpeg4/codec/rtp_h264_depayloader.h
Log:
Fixed IOCOM's proprietary H.264 decoding - Previously it was checking for a predefined byte start sequence but this wasn't always present. It has been changed to use the RTP payload type identifier (107 for IOCOM_H.264 or 96 for RFC3984 H.264) which is a better approach.
We should probably change VIC to use ffmpeg's AVPacket structures as well and we could probably eliminate some packet copying which would speed things up - but it seems to work pretty well at resolutions up to 960x720 (from IOCOM)
Modified: vic/branches/mpeg4/codec/decoder-h264.cpp
==============================================================================
--- vic/branches/mpeg4/codec/decoder-h264.cpp (original)
+++ vic/branches/mpeg4/codec/decoder-h264.cpp Wed Mar 18 10:41:01 2009
@@ -52,6 +52,8 @@
int last_iframe;
bool startPkt;
+ int aggregate_pkt; // Count of mbits for decoding IOCOM H.264
+
/* image */
UCHAR xxx_frame[MAX_FRAME_SIZE];
FFMpegCodec h264;
@@ -188,14 +190,16 @@
{
rtphdr *rh = (rtphdr *) pb->dp;
int hdrsize = sizeof(rtphdr) + hdrlen();
- u_char *bp = pb->dp + hdrsize;
- int cc = pb->len - hdrsize;
+ u_char *buf = pb->dp + hdrsize;
+ int len = pb->len - hdrsize;
//static int iframe_c = 0, pframe_c = 0;
-
- int mbit = ntohs(rh->rh_flags) >> 7 & 1;
+ int decodeLen=0;
+ int flags = ntohs(rh->rh_flags);
+ int mbit = flags >> 7 & 1;
+ int fmt = flags & 0x7f;
uint16_t seq = ntohs(rh->rh_seqno);
- int ts = ntohl(rh->rh_ts);
-
+ int packetStatus;
+ //int ts = ntohl(rh->rh_ts);
//Barz: =============================================
@@ -212,40 +216,54 @@
}
if (abs(seq - last_seq) > 5) {
- //fprintf(stderr, "H264_RTP: sequece interrupt!\n");
+ fprintf(stderr, "H264_RTP: sequece interrupt!\n");
idx = seq;
pktIdx = 0;
stream->clear();
}else if (last_seq + 1 != seq) {
// oops - missing packet
- //fprintf(stderr, "H264_RTP: missing packet\n");
+ fprintf(stderr, "H264_RTP: missing packet\n");
}
//===================================================
+ //fprintf(stderr, "H264_RTP: packet idx:%d, seq: %d\n", pktIdx,seq);
- //copy packet
- //stream->write(pktIdx, cc, (char *) bp);
- //fprintf(stderr, "H264_RTP: -------------------------------- seq = %d, m=%d, ts=%d, cc=%d\n", seq, mbit, ts, cc);
- //fprintf(stderr, "H264_RTP: pktIdx = %d\n", pktIdx);
- int yo = h264depayloader->h264_handle_packet(h264depayloader->h264_extradata, pktIdx, stream, /*ts,*/ bp, cc, mbit);
- //fprintf(stderr, "H264_RTP: h264_handle_packet = %d\n", yo);
+
+ if (fmt == 107 ){
+ // IOCOM's non-standard H.264 packet format
+ //fprintf(stderr,"IOCOM pkt\n");
+ if (mbit) {
+ if (aggregate_pkt)
+ stream->writeAppend(pktIdx, len-20, (char *)buf+20);
+ else
+ stream->writeAppend(pktIdx, len-21, (char *)buf+21);
+ aggregate_pkt = 0;
+ } else {
+ if (aggregate_pkt)
+ stream->writeAppend(pktIdx, len-20, (char *)buf+20);
+ else
+ stream->writeAppend(pktIdx, len-21, (char *)buf+21);
+ aggregate_pkt = 1;
+ }
+ } else {
+ packetStatus = h264depayloader->h264_handle_packet(h264depayloader->h264_extradata, pktIdx, stream, buf, len);
+ }
//Barz: =============================================
last_seq = seq;
- int len=0;
if (mbit) {
stream->setTotalPkts(pktIdx + 1);
DataBuffer *f;
if (stream->isComplete()) {
f = stream->getStream();
- len = h264.decode((UCHAR *) f->getData(), f->getDataSize(), xxx_frame);
+ decodeLen = h264.decode((UCHAR *) f->getData(), f->getDataSize(), xxx_frame);
}
- if (len < 0) {
+ if (decodeLen < 0) {
debug_msg("H264_RTP: frame error\n");
}
@@ -255,6 +273,7 @@
resize(inw_, inh_);
} else {
Decoder::redraw(xxx_frame);
+ //render_frame(xxx_frame);
}
stream->clear();
idx = seq+1;
Modified: vic/branches/mpeg4/codec/rtp_h264_depayloader.cpp
==============================================================================
--- vic/branches/mpeg4/codec/rtp_h264_depayloader.cpp (original)
+++ vic/branches/mpeg4/codec/rtp_h264_depayloader.cpp Wed Mar 18 10:41:01 2009
@@ -290,10 +290,8 @@
// return 0 on packet, no more left, 1 on packet, 1 on partial packet...
int H264Depayloader::h264_handle_packet(h264_rtp_extra_data *data,
- /*AVPacket * pkt,*/ int pktIdx, PacketBuffer *pb,
- /*uint32_t * timestamp,*/
- const uint8_t * buf,
- int len, int mbit)
+ int pktIdx, PacketBuffer *pb,
+ const uint8_t * buf, int len)
{
//h264_rtp_extra_data *data = s->dynamic_protocol_context;
uint8_t nal = buf[0];
@@ -308,11 +306,11 @@
//fprintf(stderr, /*NULL, AV_LOG_ERROR,*/ "H264_RTP: Single NAL type (%d, equiv. to >=1 or <=23), len=%4d\n", type, len);
- if (buf[0]==0x02 && buf[1]==0x5d && buf[2]==0x47){
- type=99; // IOCOM's non-standard H.264 packet format
- //fprintf(stderr,"found IOCOM pkt\n");
- } else if (type >= 1 && type <= 23)
- type = 1; // simplify the case. (these are all the nal types used internally by the h264 codec)
+ if (type >= 1 && type <= 23)
+ type = 1;
+ // simplify the case. (these are all the nal types used
+ // internally by the h264 codec)
+
switch (type) {
case 0: // undefined;
fprintf(stderr, /*NULL, AV_LOG_ERROR,*/ "H.264/RTP: Undefined NAL type (%d)\n", type);
@@ -485,24 +483,6 @@
}
break;
- case 99: // IOCOM's non-standard H.264
-
- //fprintf(stderr,"IOCOM pkt\n");
- if (mbit) {
- if (aggregate_pkt)
- pb->writeAppend(pktIdx, len-20, (char *)buf+20);
- else
- pb->writeAppend(pktIdx, len-21, (char *)buf+21);
- aggregate_pkt = 0;
- } else {
- if (aggregate_pkt)
- //stream->writeAppend(pktIdx,cc-bit_pos+1, (char *)bp+bit_pos-1);
- pb->writeAppend(pktIdx, len-20, (char *)buf+20);
- else
- pb->writeAppend(pktIdx, len-21, (char *)buf+21);
- aggregate_pkt = 1;
- }
- break;
case 30: // undefined
case 31: // undefined
Modified: vic/branches/mpeg4/codec/rtp_h264_depayloader.h
==============================================================================
--- vic/branches/mpeg4/codec/rtp_h264_depayloader.h (original)
+++ vic/branches/mpeg4/codec/rtp_h264_depayloader.h Wed Mar 18 10:41:01 2009
@@ -80,7 +80,7 @@
h264_rtp_extra_data *h264_extradata;
int parse_h264_sdp_line(AVCodecContext *codec, /*AVStream * stream,*/ void *data, const char *line);
- int h264_handle_packet(h264_rtp_extra_data *data, /*AVPacket * pkt*/ int pktIdx, PacketBuffer *pb, /*uint32_t * timestamp,*/ const uint8_t * buf, int len, int mbit);
+ int h264_handle_packet(h264_rtp_extra_data *data, /*AVPacket * pkt*/ int pktIdx, PacketBuffer *pb, /*uint32_t * timestamp,*/ const uint8_t * buf, int len);
/**
RTP/H264 specific private data.
More information about the Sumover-dev
mailing list