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

libavformat/rtp_mpv.c

Go to the documentation of this file.
00001 /*
00002  * RTP packetization for MPEG video
00003  * Copyright (c) 2002 Fabrice Bellard
00004  * Copyright (c) 2007 Luca Abeni
00005  *
00006  * This file is part of FFmpeg.
00007  *
00008  * FFmpeg is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * FFmpeg is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 #include "libavcodec/mpegvideo.h"
00024 #include "avformat.h"
00025 #include "rtpenc.h"
00026 
00027 /* NOTE: a single frame must be passed with sequence header if
00028    needed. XXX: use slices. */
00029 void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
00030 {
00031     RTPMuxContext *s = s1->priv_data;
00032     int len, h, max_packet_size;
00033     uint8_t *q;
00034     int begin_of_slice, end_of_slice, frame_type, temporal_reference;
00035 
00036     max_packet_size = s->max_payload_size;
00037     begin_of_slice = 1;
00038     end_of_slice = 0;
00039     frame_type = 0;
00040     temporal_reference = 0;
00041 
00042     while (size > 0) {
00043         int begin_of_sequence;
00044 
00045         begin_of_sequence = 0;
00046         len = max_packet_size - 4;
00047 
00048         if (len >= size) {
00049             len = size;
00050             end_of_slice = 1;
00051         } else {
00052             const uint8_t *r, *r1;
00053             int start_code;
00054 
00055             r1 = buf1;
00056             while (1) {
00057                 start_code = -1;
00058                 r = ff_find_start_code(r1, buf1 + size, &start_code);
00059                 if((start_code & 0xFFFFFF00) == 0x100) {
00060                     /* New start code found */
00061                     if (start_code == 0x100) {
00062                         frame_type = (r[1] & 0x38) >> 3;
00063                         temporal_reference = (int)r[0] << 2 | r[1] >> 6;
00064                     }
00065                     if (start_code == 0x1B8) {
00066                         begin_of_sequence = 1;
00067                     }
00068 
00069                     if (r - buf1 - 4 <= len) {
00070                         /* The current slice fits in the packet */
00071                         if (begin_of_slice == 0) {
00072                             /* no slice at the beginning of the packet... */
00073                             end_of_slice = 1;
00074                             len = r - buf1 - 4;
00075                             break;
00076                         }
00077                         r1 = r;
00078                     } else {
00079                         if ((r1 - buf1 > 4) && (r - r1 < max_packet_size)) {
00080                             len = r1 - buf1 - 4;
00081                             end_of_slice = 1;
00082                         }
00083                         break;
00084                     }
00085                 } else {
00086                     break;
00087                 }
00088             }
00089         }
00090 
00091         h = 0;
00092         h |= temporal_reference << 16;
00093         h |= begin_of_sequence << 13;
00094         h |= begin_of_slice << 12;
00095         h |= end_of_slice << 11;
00096         h |= frame_type << 8;
00097 
00098         q = s->buf;
00099         *q++ = h >> 24;
00100         *q++ = h >> 16;
00101         *q++ = h >> 8;
00102         *q++ = h;
00103 
00104         memcpy(q, buf1, len);
00105         q += len;
00106 
00107         /* 90kHz time stamp */
00108         s->timestamp = s->cur_timestamp;
00109         ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));
00110 
00111         buf1 += len;
00112         size -= len;
00113         begin_of_slice = end_of_slice;
00114         end_of_slice = 0;
00115     }
00116 }
00117 
00118 

Generated on Sat Feb 16 2013 09:23:15 for ffmpeg by  doxygen 1.7.1