#include "bitstream.h"
#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
+#include "network.h"
#include "rtp_internal.h"
#include "rtp_h264.h"
+#include "rtp_mpv.h"
//#define DEBUG
RTPFirstDynamicPayloadHandler= handler;
}
-void av_register_rtp_dynamic_payload_handlers()
+void av_register_rtp_dynamic_payload_handlers(void)
{
register_dynamic_payload_handler(&mp4v_es_handler);
register_dynamic_payload_handler(&mpeg4_generic_handler);
return -1;
}
-/* return < 0 if unknown payload type */
int rtp_get_payload_type(AVCodecContext *codec)
{
int i, payload_type;
return payload_type;
}
-static inline uint32_t decode_be32(const uint8_t *p)
-{
- return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
-}
-
-static inline uint64_t decode_be64(const uint8_t *p)
-{
- return ((uint64_t)decode_be32(p) << 32) | decode_be32(p + 4);
-}
-
static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, int len)
{
if (buf[1] != 200)
return -1;
- s->last_rtcp_ntp_time = decode_be64(buf + 8);
+ s->last_rtcp_ntp_time = AV_RB64(buf + 8);
if (s->first_rtcp_ntp_time == AV_NOPTS_VALUE)
s->first_rtcp_ntp_time = s->last_rtcp_ntp_time;
- s->last_rtcp_timestamp = decode_be32(buf + 16);
+ s->last_rtcp_timestamp = AV_RB32(buf + 16);
return 0;
}
}
#endif
-/**
- * some rtp servers assume client is dead if they don't hear from them...
- * so we send a Receiver Report to the provided ByteIO context
- * (we don't have access to the rtcp handle from here)
- */
int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count)
{
ByteIOContext pb;
case CODEC_ID_MP3:
case CODEC_ID_MPEG4:
case CODEC_ID_H264:
- st->need_parsing = 1;
+ st->need_parsing = AVSTREAM_PARSE_FULL;
break;
default:
break;
infos->au_headers = av_malloc(sizeof(struct AUHeaders) * infos->nb_au_headers);
/* XXX: We handle multiple AU Section as only one (need to fix this for interleaving)
- In my test, the faad decoder doesnt behave correctly when sending each AU one by one
+ In my test, the FAAD decoder does not behave correctly when sending each AU one by one
but does when sending the whole as one big packet... */
infos->au_headers[0].size = 0;
infos->au_headers[0].index = 0;
return -1;
}
payload_type = buf[1] & 0x7f;
- seq = (buf[2] << 8) | buf[3];
- timestamp = decode_be32(buf + 4);
- ssrc = decode_be32(buf + 8);
+ seq = AV_RB16(buf + 2);
+ timestamp = AV_RB32(buf + 4);
+ ssrc = AV_RB32(buf + 8);
/* store the ssrc in the RTPDemuxContext */
s->ssrc = ssrc;
/* better than nothing: skip mpeg audio RTP header */
if (len <= 4)
return -1;
- h = decode_be32(buf);
+ h = AV_RB32(buf);
len -= 4;
buf += 4;
av_new_packet(pkt, len);
/* better than nothing: skip mpeg video RTP header */
if (len <= 4)
return -1;
- h = decode_be32(buf);
+ h = AV_RB32(buf);
buf += 4;
len -= 4;
if (h & (1 << 26)) {
max_packet_size = url_fget_max_packet_size(&s1->pb);
if (max_packet_size <= 12)
- return AVERROR_IO;
+ return AVERROR(EIO);
s->max_payload_size = max_packet_size - 12;
switch(st->codec->codec_id) {
/* send an rtp packet. sequence number is incremented, but the caller
must update the timestamp itself */
-static void rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
+void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
{
RTPDemuxContext *s = s1->priv_data;
n = (s->buf_ptr - s->buf);
/* if buffer full, then send it */
if (n >= max_packet_size) {
- rtp_send_data(s1, s->buf, n, 0);
+ ff_rtp_send_data(s1, s->buf, n, 0);
s->buf_ptr = s->buf;
/* update timestamp */
s->timestamp += n / sample_size;
len = (s->buf_ptr - s->buf);
if ((len + size) > max_packet_size) {
if (len > 4) {
- rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
+ ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
s->buf_ptr = s->buf + 4;
/* 90 KHz time stamp */
s->timestamp = s->base_timestamp +
s->buf[2] = count >> 8;
s->buf[3] = count;
memcpy(s->buf + 4, buf1, len);
- rtp_send_data(s1, s->buf, len + 4, 0);
+ ff_rtp_send_data(s1, s->buf, len + 4, 0);
size -= len;
buf1 += len;
count += len;
s->cur_timestamp += st->codec->frame_size;
}
-/* NOTE: a single frame must be passed with sequence header if
- needed. XXX: use slices. */
-static void rtp_send_mpegvideo(AVFormatContext *s1,
- const uint8_t *buf1, int size)
-{
- RTPDemuxContext *s = s1->priv_data;
- AVStream *st = s1->streams[0];
- int len, h, max_packet_size;
- uint8_t *q;
-
- max_packet_size = s->max_payload_size;
-
- while (size > 0) {
- /* XXX: more correct headers */
- h = 0;
- if (st->codec->sub_id == 2)
- h |= 1 << 26; /* mpeg 2 indicator */
- q = s->buf;
- *q++ = h >> 24;
- *q++ = h >> 16;
- *q++ = h >> 8;
- *q++ = h;
-
- if (st->codec->sub_id == 2) {
- h = 0;
- *q++ = h >> 24;
- *q++ = h >> 16;
- *q++ = h >> 8;
- *q++ = h;
- }
-
- len = max_packet_size - (q - s->buf);
- if (len > size)
- len = size;
-
- memcpy(q, buf1, len);
- q += len;
-
- /* 90 KHz time stamp */
- s->timestamp = s->base_timestamp +
- av_rescale((int64_t)s->cur_timestamp * st->codec->time_base.num, 90000, st->codec->time_base.den); //FIXME pass timestamps
- rtp_send_data(s1, s->buf, q - s->buf, (len == size));
-
- buf1 += len;
- size -= len;
- }
- s->cur_timestamp++;
-}
-
static void rtp_send_raw(AVFormatContext *s1,
const uint8_t *buf1, int size)
{
/* 90 KHz time stamp */
s->timestamp = s->base_timestamp +
av_rescale((int64_t)s->cur_timestamp * st->codec->time_base.num, 90000, st->codec->time_base.den); //FIXME pass timestamps
- rtp_send_data(s1, buf1, len, (len == size));
+ ff_rtp_send_data(s1, buf1, len, (len == size));
buf1 += len;
size -= len;
out_len = s->buf_ptr - s->buf;
if (out_len >= s->max_payload_size) {
- rtp_send_data(s1, s->buf, out_len, 0);
+ ff_rtp_send_data(s1, s->buf, out_len, 0);
s->buf_ptr = s->buf;
}
}
rtp_send_mpegaudio(s1, buf1, size);
break;
case CODEC_ID_MPEG1VIDEO:
- rtp_send_mpegvideo(s1, buf1, size);
+ ff_rtp_send_mpegvideo(s1, buf1, size);
break;
case CODEC_ID_MPEG2TS:
rtp_send_mpegts_raw(s1, buf1, size);
return 0;
}
-static int rtp_write_trailer(AVFormatContext *s1)
-{
- // RTPDemuxContext *s = s1->priv_data;
- return 0;
-}
-
AVOutputFormat rtp_muxer = {
"rtp",
"RTP output format",
CODEC_ID_NONE,
rtp_write_header,
rtp_write_packet,
- rtp_write_trailer,
};