• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavformat/rtpdec_h263.c

Go to the documentation of this file.
00001 /*
00002  * RTP H.263 Depacketizer, RFC 4629
00003  * Copyright (c) 2010 Martin Storsjo
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "avformat.h"
00023 #include "rtpdec_h263.h"
00024 #include "libavutil/intreadwrite.h"
00025 
00026 static int h263_handle_packet(AVFormatContext *ctx,
00027                               PayloadContext *data,
00028                               AVStream *st,
00029                               AVPacket * pkt,
00030                               uint32_t * timestamp,
00031                               const uint8_t * buf,
00032                               int len, int flags)
00033 {
00034     uint8_t *ptr;
00035     uint16_t header;
00036     int startcode, vrc, picture_header;
00037 
00038     if (len < 2) {
00039         av_log(ctx, AV_LOG_ERROR, "Too short H.263 RTP packet\n");
00040         return AVERROR_INVALIDDATA;
00041     }
00042 
00043     /* Decode the 16 bit H.263+ payload header, as described in section
00044      * 5.1 of RFC 4629. The fields of this header are:
00045      * - 5 reserved bits, should be ignored.
00046      * - One bit (P, startcode), indicating a picture start, picture segment
00047      *   start or video sequence end. If set, two zero bytes should be
00048      *   prepended to the payload.
00049      * - One bit (V, vrc), indicating the presence of an 8 bit Video
00050      *   Redundancy Coding field after this 16 bit header.
00051      * - 6 bits (PLEN, picture_header), the length (in bytes) of an extra
00052      *   picture header, following the VRC field.
00053      * - 3 bits (PEBIT), the number of bits to ignore of the last byte
00054      *   of the extra picture header. (Not used at the moment.)
00055      */
00056     header = AV_RB16(buf);
00057     startcode      = (header & 0x0400) >> 9;
00058     vrc            =  header & 0x0200;
00059     picture_header = (header & 0x01f8) >> 3;
00060     buf += 2;
00061     len -= 2;
00062 
00063     if (vrc) {
00064         /* Skip VRC header if present, not used at the moment. */
00065         buf += 1;
00066         len -= 1;
00067     }
00068     if (picture_header) {
00069         /* Skip extra picture header if present, not used at the moment. */
00070         buf += picture_header;
00071         len -= picture_header;
00072     }
00073 
00074     if (len < 0) {
00075         av_log(ctx, AV_LOG_ERROR, "Too short H.263 RTP packet\n");
00076         return AVERROR_INVALIDDATA;
00077     }
00078 
00079     if (av_new_packet(pkt, len + startcode)) {
00080         av_log(ctx, AV_LOG_ERROR, "Out of memory\n");
00081         return AVERROR(ENOMEM);
00082     }
00083     pkt->stream_index = st->index;
00084     ptr = pkt->data;
00085 
00086     if (startcode) {
00087         *ptr++ = 0;
00088         *ptr++ = 0;
00089     }
00090     memcpy(ptr, buf, len);
00091 
00092     return 0;
00093 }
00094 
00095 RTPDynamicProtocolHandler ff_h263_1998_dynamic_handler = {
00096     .enc_name         = "H263-1998",
00097     .codec_type       = AVMEDIA_TYPE_VIDEO,
00098     .codec_id         = CODEC_ID_H263,
00099     .parse_packet     = h263_handle_packet,
00100 };
00101 
00102 RTPDynamicProtocolHandler ff_h263_2000_dynamic_handler = {
00103     .enc_name         = "H263-2000",
00104     .codec_type       = AVMEDIA_TYPE_VIDEO,
00105     .codec_id         = CODEC_ID_H263,
00106     .parse_packet     = h263_handle_packet,
00107 };
00108 

Generated on Fri Sep 16 2011 17:17:50 for FFmpeg by  doxygen 1.7.1