Revision 98561024

View differences:

libavformat/Makefile
119 119
OBJS-$(CONFIG_RM_MUXER)                  += rmenc.o
120 120
OBJS-$(CONFIG_ROQ_DEMUXER)               += idroq.o
121 121
OBJS-$(CONFIG_ROQ_MUXER)                 += raw.o
122
OBJS-$(CONFIG_RTP_MUXER)                 += rtp.o rtp_h264.o
122
OBJS-$(CONFIG_RTP_MUXER)                 += rtp.o rtp_h264.o rtp_mpv.o
123 123
OBJS-$(CONFIG_RTSP_DEMUXER)              += rtsp.o
124 124
OBJS-$(CONFIG_SDP_DEMUXER)               += rtsp.o
125 125
OBJS-$(CONFIG_SEGAFILM_DEMUXER)          += segafilm.o
libavformat/rtp.c
27 27

  
28 28
#include "rtp_internal.h"
29 29
#include "rtp_h264.h"
30
#include "rtp_mpv.h"
30 31

  
31 32
//#define DEBUG
32 33

  
......
788 789

  
789 790
/* send an rtp packet. sequence number is incremented, but the caller
790 791
   must update the timestamp itself */
791
static void rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
792
void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
792 793
{
793 794
    RTPDemuxContext *s = s1->priv_data;
794 795

  
......
836 837
        n = (s->buf_ptr - s->buf);
837 838
        /* if buffer full, then send it */
838 839
        if (n >= max_packet_size) {
839
            rtp_send_data(s1, s->buf, n, 0);
840
            ff_rtp_send_data(s1, s->buf, n, 0);
840 841
            s->buf_ptr = s->buf;
841 842
            /* update timestamp */
842 843
            s->timestamp += n / sample_size;
......
859 860
    len = (s->buf_ptr - s->buf);
860 861
    if ((len + size) > max_packet_size) {
861 862
        if (len > 4) {
862
            rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
863
            ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
863 864
            s->buf_ptr = s->buf + 4;
864 865
            /* 90 KHz time stamp */
865 866
            s->timestamp = s->base_timestamp +
......
881 882
            s->buf[2] = count >> 8;
882 883
            s->buf[3] = count;
883 884
            memcpy(s->buf + 4, buf1, len);
884
            rtp_send_data(s1, s->buf, len + 4, 0);
885
            ff_rtp_send_data(s1, s->buf, len + 4, 0);
885 886
            size -= len;
886 887
            buf1 += len;
887 888
            count += len;
......
900 901
    s->cur_timestamp += st->codec->frame_size;
901 902
}
902 903

  
903
/* NOTE: a single frame must be passed with sequence header if
904
   needed. XXX: use slices. */
905
static void rtp_send_mpegvideo(AVFormatContext *s1,
906
                               const uint8_t *buf1, int size)
907
{
908
    RTPDemuxContext *s = s1->priv_data;
909
    AVStream *st = s1->streams[0];
910
    int len, h, max_packet_size;
911
    uint8_t *q;
912

  
913
    max_packet_size = s->max_payload_size;
914

  
915
    while (size > 0) {
916
        /* XXX: more correct headers */
917
        h = 0;
918
        if (st->codec->sub_id == 2)
919
            h |= 1 << 26; /* mpeg 2 indicator */
920
        q = s->buf;
921
        *q++ = h >> 24;
922
        *q++ = h >> 16;
923
        *q++ = h >> 8;
924
        *q++ = h;
925

  
926
        if (st->codec->sub_id == 2) {
927
            h = 0;
928
            *q++ = h >> 24;
929
            *q++ = h >> 16;
930
            *q++ = h >> 8;
931
            *q++ = h;
932
        }
933

  
934
        len = max_packet_size - (q - s->buf);
935
        if (len > size)
936
            len = size;
937

  
938
        memcpy(q, buf1, len);
939
        q += len;
940

  
941
        /* 90 KHz time stamp */
942
        s->timestamp = s->base_timestamp +
943
            av_rescale((int64_t)s->cur_timestamp * st->codec->time_base.num, 90000, st->codec->time_base.den); //FIXME pass timestamps
944
        rtp_send_data(s1, s->buf, q - s->buf, (len == size));
945

  
946
        buf1 += len;
947
        size -= len;
948
    }
949
    s->cur_timestamp++;
950
}
951

  
952 904
static void rtp_send_raw(AVFormatContext *s1,
953 905
                         const uint8_t *buf1, int size)
954 906
{
......
966 918
        /* 90 KHz time stamp */
967 919
        s->timestamp = s->base_timestamp +
968 920
            av_rescale((int64_t)s->cur_timestamp * st->codec->time_base.num, 90000, st->codec->time_base.den); //FIXME pass timestamps
969
        rtp_send_data(s1, buf1, len, (len == size));
921
        ff_rtp_send_data(s1, buf1, len, (len == size));
970 922

  
971 923
        buf1 += len;
972 924
        size -= len;
......
992 944

  
993 945
        out_len = s->buf_ptr - s->buf;
994 946
        if (out_len >= s->max_payload_size) {
995
            rtp_send_data(s1, s->buf, out_len, 0);
947
            ff_rtp_send_data(s1, s->buf, out_len, 0);
996 948
            s->buf_ptr = s->buf;
997 949
        }
998 950
    }
......
1042 994
        rtp_send_mpegaudio(s1, buf1, size);
1043 995
        break;
1044 996
    case CODEC_ID_MPEG1VIDEO:
1045
        rtp_send_mpegvideo(s1, buf1, size);
997
        ff_rtp_send_mpegvideo(s1, buf1, size);
1046 998
        break;
1047 999
    case CODEC_ID_MPEG2TS:
1048 1000
        rtp_send_mpegts_raw(s1, buf1, size);
libavformat/rtp_internal.h
110 110
extern RTPDynamicProtocolHandler *RTPFirstDynamicPayloadHandler;
111 111

  
112 112
int rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size); ///< from rtsp.c, but used by rtp dynamic protocol handlers.
113

  
114
void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m);
113 115
#endif /* RTP_INTERNAL_H */
114 116

  
libavformat/rtp_mpv.c
1
/*
2
 * RTP packetization for MPEG video
3
 * Copyright (c) 2002 Fabrice Bellard.
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21
#include "avformat.h"
22
#include "rtp_internal.h"
23

  
24
/* NOTE: a single frame must be passed with sequence header if
25
   needed. XXX: use slices. */
26
void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
27
{
28
    RTPDemuxContext *s = s1->priv_data;
29
    AVStream *st = s1->streams[0];
30
    int len, h, max_packet_size;
31
    uint8_t *q;
32

  
33
    max_packet_size = s->max_payload_size;
34

  
35
    while (size > 0) {
36
        /* XXX: more correct headers */
37
        h = 0;
38
        if (st->codec->sub_id == 2)
39
            h |= 1 << 26; /* mpeg 2 indicator */
40
        q = s->buf;
41
        *q++ = h >> 24;
42
        *q++ = h >> 16;
43
        *q++ = h >> 8;
44
        *q++ = h;
45

  
46
        if (st->codec->sub_id == 2) {
47
            h = 0;
48
            *q++ = h >> 24;
49
            *q++ = h >> 16;
50
            *q++ = h >> 8;
51
            *q++ = h;
52
        }
53

  
54
        len = max_packet_size - (q - s->buf);
55
        if (len > size)
56
            len = size;
57

  
58
        memcpy(q, buf1, len);
59
        q += len;
60

  
61
        /* 90 KHz time stamp */
62
        s->timestamp = s->base_timestamp +
63
            av_rescale((int64_t)s->cur_timestamp * st->codec->time_base.num, 90000, st->codec->time_base.den); //FIXME pass timestamps
64
        ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));
65

  
66
        buf1 += len;
67
        size -= len;
68
    }
69
    s->cur_timestamp++;
70
}
71

  
72

  
libavformat/rtp_mpv.h
1
/*
2
 * RTP definitions
3
 * Copyright (c) 2002 Fabrice Bellard.
4
 *
5
 * This file is part of FFmpeg.
6
 *
7
 * FFmpeg is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 of the License, or (at your option) any later version.
11
 *
12
 * FFmpeg is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with FFmpeg; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21
#ifndef RTP_MPV_H
22
#define RTP_MPV_H
23

  
24
void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size);
25

  
26
#endif /* RTP_MPV_H */

Also available in: Unified diff