~ubuntu-branches/ubuntu/saucy/gst-libav1.0/saucy-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavformat/rtmppkt.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-07-30 09:00:15 UTC
  • mfrom: (1.1.16) (7.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20130730090015-sc1ou2yssu7q5w4e
Tags: 1.1.3-1
* New upstream development snapshot:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.1.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
    bytestream_put_buffer(dst, str, strlen(str));
48
48
}
49
49
 
 
50
void ff_amf_write_string2(uint8_t **dst, const char *str1, const char *str2)
 
51
{
 
52
    int len1 = 0, len2 = 0;
 
53
    if (str1)
 
54
        len1 = strlen(str1);
 
55
    if (str2)
 
56
        len2 = strlen(str2);
 
57
    bytestream_put_byte(dst, AMF_DATA_TYPE_STRING);
 
58
    bytestream_put_be16(dst, len1 + len2);
 
59
    bytestream_put_buffer(dst, str1, len1);
 
60
    bytestream_put_buffer(dst, str2, len2);
 
61
}
 
62
 
50
63
void ff_amf_write_null(uint8_t **dst)
51
64
{
52
65
    bytestream_put_byte(dst, AMF_DATA_TYPE_NULL);
71
84
    bytestream_put_be24(dst, AMF_DATA_TYPE_OBJECT_END);
72
85
}
73
86
 
 
87
int ff_amf_read_bool(GetByteContext *bc, int *val)
 
88
{
 
89
    if (bytestream2_get_byte(bc) != AMF_DATA_TYPE_BOOL)
 
90
        return AVERROR_INVALIDDATA;
 
91
    *val = bytestream2_get_byte(bc);
 
92
    return 0;
 
93
}
 
94
 
 
95
int ff_amf_read_number(GetByteContext *bc, double *val)
 
96
{
 
97
    uint64_t read;
 
98
    if (bytestream2_get_byte(bc) != AMF_DATA_TYPE_NUMBER)
 
99
        return AVERROR_INVALIDDATA;
 
100
    read = bytestream2_get_be64(bc);
 
101
    *val = av_int2double(read);
 
102
    return 0;
 
103
}
 
104
 
 
105
int ff_amf_read_string(GetByteContext *bc, uint8_t *str,
 
106
                       int strsize, int *length)
 
107
{
 
108
    int stringlen = 0;
 
109
    int readsize;
 
110
    if (bytestream2_get_byte(bc) != AMF_DATA_TYPE_STRING)
 
111
        return AVERROR_INVALIDDATA;
 
112
    stringlen = bytestream2_get_be16(bc);
 
113
    if (stringlen + 1 > strsize)
 
114
        return AVERROR(EINVAL);
 
115
    readsize = bytestream2_get_buffer(bc, str, stringlen);
 
116
    if (readsize != stringlen) {
 
117
        av_log(NULL, AV_LOG_WARNING,
 
118
               "Unable to read as many bytes as AMF string signaled\n");
 
119
    }
 
120
    str[readsize] = '\0';
 
121
    *length = FFMIN(stringlen, readsize);
 
122
    return 0;
 
123
}
 
124
 
 
125
int ff_amf_read_null(GetByteContext *bc)
 
126
{
 
127
    if (bytestream2_get_byte(bc) != AMF_DATA_TYPE_NULL)
 
128
        return AVERROR_INVALIDDATA;
 
129
    return 0;
 
130
}
 
131
 
74
132
int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
75
133
                        int chunk_size, RTMPPacket *prev_pkt)
76
134
{
77
 
    uint8_t hdr, t, buf[16];
 
135
    uint8_t hdr;
 
136
 
 
137
    if (ffurl_read(h, &hdr, 1) != 1)
 
138
        return AVERROR(EIO);
 
139
 
 
140
    return ff_rtmp_packet_read_internal(h, p, chunk_size, prev_pkt, hdr);
 
141
}
 
142
 
 
143
int ff_rtmp_packet_read_internal(URLContext *h, RTMPPacket *p, int chunk_size,
 
144
                                 RTMPPacket *prev_pkt, uint8_t hdr)
 
145
{
 
146
 
 
147
    uint8_t t, buf[16];
78
148
    int channel_id, timestamp, data_size, offset = 0;
79
149
    uint32_t extra = 0;
80
150
    enum RTMPPacketType type;
81
151
    int size = 0;
 
152
    int ret;
82
153
 
83
 
    if (ffurl_read(h, &hdr, 1) != 1)
84
 
        return AVERROR(EIO);
85
154
    size++;
86
155
    channel_id = hdr & 0x3F;
87
156
 
129
198
    if (hdr != RTMP_PS_TWELVEBYTES)
130
199
        timestamp += prev_pkt[channel_id].timestamp;
131
200
 
132
 
    if (ff_rtmp_packet_create(p, channel_id, type, timestamp, data_size))
133
 
        return -1;
 
201
    if ((ret = ff_rtmp_packet_create(p, channel_id, type, timestamp,
 
202
                                     data_size)) < 0)
 
203
        return ret;
134
204
    p->extra = extra;
135
205
    // save history
136
206
    prev_pkt[channel_id].channel_id = channel_id;
149
219
        offset    += chunk_size;
150
220
        size      += chunk_size;
151
221
        if (data_size > 0) {
152
 
            ffurl_read_complete(h, &t, 1); //marker
 
222
            if ((ret = ffurl_read_complete(h, &t, 1)) < 0) { // marker
 
223
                ff_rtmp_packet_destroy(p);
 
224
                return ret;
 
225
            }
153
226
            size++;
154
227
            if (t != (0xC0 + channel_id))
155
228
                return -1;
165
238
    int mode = RTMP_PS_TWELVEBYTES;
166
239
    int off = 0;
167
240
    int size = 0;
 
241
    int ret;
168
242
 
169
243
    pkt->ts_delta = pkt->timestamp - prev_pkt[pkt->channel_id].timestamp;
170
244
 
216
290
    }
217
291
    prev_pkt[pkt->channel_id].extra      = pkt->extra;
218
292
 
219
 
    ffurl_write(h, pkt_hdr, p-pkt_hdr);
 
293
    if ((ret = ffurl_write(h, pkt_hdr, p - pkt_hdr)) < 0)
 
294
        return ret;
220
295
    size = p - pkt_hdr + pkt->data_size;
221
296
    while (off < pkt->data_size) {
222
297
        int towrite = FFMIN(chunk_size, pkt->data_size - off);
223
 
        ffurl_write(h, pkt->data + off, towrite);
 
298
        if ((ret = ffurl_write(h, pkt->data + off, towrite)) < 0)
 
299
            return ret;
224
300
        off += towrite;
225
301
        if (off < pkt->data_size) {
226
302
            uint8_t marker = 0xC0 | pkt->channel_id;
227
 
            ffurl_write(h, &marker, 1);
 
303
            if ((ret = ffurl_write(h, &marker, 1)) < 0)
 
304
                return ret;
228
305
            size++;
229
306
        }
230
307
    }