third_party_ffmpeg/libavformat/rtpenc_h263.c
Michael Niedermayer e2cc39b609 Merge remote-tracking branch 'qatar/master'
* qatar/master: (40 commits)
  swf: check return values for av_get/new_packet().
  wavpack: Don't shift minclip/maxclip
  rtpenc: Expose the max packet size via an avoption
  rtpenc: Move max_packet_size to a context variable
  rtpenc: Add an option for not sending RTCP packets
  lavc: drop encode() support for video.
  snowenc: switch to encode2().
  snowenc: don't abuse input picture for storing information.
  a64multienc: switch to encode2().
  a64multienc: don't write into output buffer when there's no output.
  libxvid: switch to encode2().
  tiffenc: switch to encode2().
  tiffenc: properly forward error codes in encode_frame().
  lavc: drop libdirac encoder.
  gifenc: switch to encode2().
  libvpxenc: switch to encode2().
  flashsvenc: switch to encode2().
  Remove libpostproc.
  lcl: don't overwrite input memory.
  swscale: take first/lastline over/underflows into account for MMX.
  ...

Conflicts:
	.gitignore
	Makefile
	cmdutils.c
	configure
	doc/APIchanges
	libavcodec/Makefile
	libavcodec/allcodecs.c
	libavcodec/libdiracenc.c
	libavcodec/libxvidff.c
	libavcodec/qtrleenc.c
	libavcodec/tiffenc.c
	libavcodec/utils.c
	libavformat/mov.c
	libavformat/movenc.c
	libpostproc/Makefile
	libpostproc/postprocess.c
	libpostproc/postprocess.h
	libpostproc/postprocess_altivec_template.c
	libpostproc/postprocess_internal.h
	libpostproc/postprocess_template.c
	libswscale/swscale.c
	libswscale/utils.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2012-02-24 02:57:18 +01:00

82 lines
2.4 KiB
C

/*
* RTP packetization for H.263 video
* Copyright (c) 2009 Luca Abeni
* Copyright (c) 2009 Martin Storsjo
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avformat.h"
#include "rtpenc.h"
const uint8_t *ff_h263_find_resync_marker_reverse(const uint8_t *restrict start,
const uint8_t *restrict end)
{
const uint8_t *p = end - 1;
start += 1; /* Make sure we never return the original start. */
for (; p > start; p -= 2) {
if (!*p) {
if (!p[ 1] && p[2]) return p;
else if (!p[-1] && p[1]) return p - 1;
}
}
return end;
}
/**
* Packetize H.263 frames into RTP packets according to RFC 4629
*/
void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size)
{
RTPMuxContext *s = s1->priv_data;
int len, max_packet_size;
uint8_t *q;
max_packet_size = s->max_payload_size;
while (size > 0) {
q = s->buf;
if (size >= 2 && (buf1[0] == 0) && (buf1[1] == 0)) {
*q++ = 0x04;
buf1 += 2;
size -= 2;
} else {
*q++ = 0;
}
*q++ = 0;
len = FFMIN(max_packet_size - 2, size);
/* Look for a better place to split the frame into packets. */
if (len < size) {
const uint8_t *end = ff_h263_find_resync_marker_reverse(buf1,
buf1 + len);
len = end - buf1;
}
memcpy(q, buf1, len);
q += len;
/* 90 KHz time stamp */
s->timestamp = s->cur_timestamp;
ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));
buf1 += len;
size -= len;
}
}