~ubuntu-branches/ubuntu/vivid/ffmpeg/vivid

« back to all changes in this revision

Viewing changes to libavformat/rdt.c

  • Committer: Package Import Robot
  • Author(s): Andreas Cadhalpun
  • Date: 2014-11-05 01:18:23 UTC
  • mfrom: (0.2.17 sid)
  • Revision ID: package-import@ubuntu.com-20141105011823-xsbeceffs43wtkn7
Tags: 7:2.4.3-1
* Import new upstream bugfix release 2.4.3.
   - Refresh Change-symbol-versioning.patch.
   - Add new symbols to the libavdevice symbols file.
* Enable libbs2b on arm64, since it is now available.
* Disable frei0r and libx264 on x32, libsoxr and openal on sparc64
  and libopencv on m68k, sh4, sparc64 and x32, because they are not
  (yet) avialable there.
* Disable assembler optimizations on x32, as they wouldn't work there.
* Include config.log in the build-log, when compiling fails.
* Add fix-hppa-tests.patch to work around a gcc bug on hppa.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "libavutil/md5.h"
34
34
#include "rm.h"
35
35
#include "internal.h"
 
36
#include "avio_internal.h"
36
37
#include "libavcodec/get_bits.h"
37
38
 
38
39
struct RDTDemuxContext {
63
64
    do {
64
65
        s->n_streams++;
65
66
    } while (first_stream_of_set_idx + s->n_streams < ic->nb_streams &&
66
 
             s->streams[s->n_streams]->priv_data == s->streams[0]->priv_data);
 
67
             s->streams[s->n_streams]->id == s->streams[0]->id);
67
68
    s->prev_set_id    = -1;
68
69
    s->prev_stream_id = -1;
69
70
    s->prev_timestamp = -1;
76
77
void
77
78
ff_rdt_parse_close(RDTDemuxContext *s)
78
79
{
79
 
    int i;
80
 
 
81
 
    for (i = 1; i < s->n_streams; i++)
82
 
        s->streams[i]->priv_data = NULL;
83
 
 
84
80
    av_free(s);
85
81
}
86
82
 
87
83
struct PayloadContext {
88
84
    AVFormatContext *rmctx;
89
 
    RMStream *rmst[MAX_STREAMS];
 
85
    int nb_rmst;
 
86
    RMStream **rmst;
90
87
    uint8_t *mlti_data;
91
88
    unsigned int mlti_data_size;
92
89
    char buffer[RTP_MAX_PACKET_LENGTH + FF_INPUT_BUFFER_PADDING_SIZE];
101
98
    unsigned char zres[16],
102
99
        buf[64] = { 0xa1, 0xe9, 0x14, 0x9d, 0x0e, 0x6b, 0x3b, 0x59 };
103
100
#define XOR_TABLE_SIZE 37
104
 
    const unsigned char xor_table[XOR_TABLE_SIZE] = {
 
101
    static const unsigned char xor_table[XOR_TABLE_SIZE] = {
105
102
        0x05, 0x18, 0x74, 0xd0, 0x0d, 0x09, 0x02, 0x53,
106
103
        0xc0, 0x01, 0x05, 0x05, 0x67, 0x03, 0x19, 0x70,
107
104
        0x08, 0x27, 0x66, 0x10, 0x10, 0x72, 0x08, 0x09,
134
131
static int
135
132
rdt_load_mdpr (PayloadContext *rdt, AVStream *st, int rule_nr)
136
133
{
137
 
    ByteIOContext pb;
 
134
    AVIOContext pb;
138
135
    int size;
139
136
    uint32_t tag;
140
137
 
141
138
    /**
142
139
     * Layout of the MLTI chunk:
143
 
     * 4:MLTI
144
 
     * 2:<number of streams>
 
140
     * 4: MLTI
 
141
     * 2: number of streams
145
142
     * Then for each stream ([number_of_streams] times):
146
 
     *     2:<mdpr index>
147
 
     * 2:<number of mdpr chunks>
 
143
     *     2: mdpr index
 
144
     * 2: number of mdpr chunks
148
145
     * Then for each mdpr chunk ([number_of_mdpr_chunks] times):
149
 
     *     4:<size>
150
 
     *     [size]:<data>
 
146
     *     4: size
 
147
     *     [size]: data
151
148
     * we skip MDPR chunks until we reach the one of the stream
152
149
     * we're interested in, and forward that ([size]+[data]) to
153
150
     * the RM demuxer to parse the stream-specific header data.
154
151
     */
155
152
    if (!rdt->mlti_data)
156
153
        return -1;
157
 
    init_put_byte(&pb, rdt->mlti_data, rdt->mlti_data_size, 0,
 
154
    ffio_init_context(&pb, rdt->mlti_data, rdt->mlti_data_size, 0,
158
155
                  NULL, NULL, NULL, NULL);
159
 
    tag = get_le32(&pb);
 
156
    tag = avio_rl32(&pb);
160
157
    if (tag == MKTAG('M', 'L', 'T', 'I')) {
161
158
        int num, chunk_nr;
162
159
 
163
160
        /* read index of MDPR chunk numbers */
164
 
        num = get_be16(&pb);
 
161
        num = avio_rb16(&pb);
165
162
        if (rule_nr < 0 || rule_nr >= num)
166
163
            return -1;
167
 
        url_fskip(&pb, rule_nr * 2);
168
 
        chunk_nr = get_be16(&pb);
169
 
        url_fskip(&pb, (num - 1 - rule_nr) * 2);
 
164
        avio_skip(&pb, rule_nr * 2);
 
165
        chunk_nr = avio_rb16(&pb);
 
166
        avio_skip(&pb, (num - 1 - rule_nr) * 2);
170
167
 
171
168
        /* read MDPR chunks */
172
 
        num = get_be16(&pb);
 
169
        num = avio_rb16(&pb);
173
170
        if (chunk_nr >= num)
174
171
            return -1;
175
172
        while (chunk_nr--)
176
 
            url_fskip(&pb, get_be32(&pb));
177
 
        size = get_be32(&pb);
 
173
            avio_skip(&pb, avio_rb32(&pb));
 
174
        size = avio_rb32(&pb);
178
175
    } else {
179
176
        size = rdt->mlti_data_size;
180
 
        url_fseek(&pb, 0, SEEK_SET);
 
177
        avio_seek(&pb, 0, SEEK_SET);
181
178
    }
182
 
    if (ff_rm_read_mdpr_codecdata(rdt->rmctx, &pb, st, rdt->rmst[st->index], size) < 0)
 
179
    if (ff_rm_read_mdpr_codecdata(rdt->rmctx, &pb, st, rdt->rmst[st->index], size, NULL) < 0)
183
180
        return -1;
184
181
 
185
182
    return 0;
296
293
static int
297
294
rdt_parse_packet (AVFormatContext *ctx, PayloadContext *rdt, AVStream *st,
298
295
                  AVPacket *pkt, uint32_t *timestamp,
299
 
                  const uint8_t *buf, int len, int flags)
 
296
                  const uint8_t *buf, int len, uint16_t rtp_seq, int flags)
300
297
{
301
298
    int seq = 1, res;
302
 
    ByteIOContext pb;
 
299
    AVIOContext pb;
303
300
 
304
301
    if (rdt->audio_pkt_cnt == 0) {
305
302
        int pos;
306
303
 
307
 
        init_put_byte(&pb, buf, len, 0, NULL, NULL, NULL, NULL);
 
304
        ffio_init_context(&pb, (uint8_t *)buf, len, 0, NULL, NULL, NULL, NULL);
308
305
        flags = (flags & RTP_FLAG_KEY) ? 2 : 0;
309
306
        res = ff_rm_parse_packet (rdt->rmctx, &pb, st, rdt->rmst[st->index], len, pkt,
310
307
                                  &seq, flags, *timestamp);
311
 
        pos = url_ftell(&pb);
 
308
        pos = avio_tell(&pb);
312
309
        if (res < 0)
313
310
            return res;
314
311
        if (res > 0) {
315
 
            if (st->codec->codec_id == CODEC_ID_AAC) {
 
312
            if (st->codec->codec_id == AV_CODEC_ID_AAC) {
316
313
                memcpy (rdt->buffer, buf + pos, len - pos);
317
 
                rdt->rmctx->pb = av_alloc_put_byte (rdt->buffer, len - pos, 0,
 
314
                rdt->rmctx->pb = avio_alloc_context (rdt->buffer, len - pos, 0,
318
315
                                                    NULL, NULL, NULL, NULL);
319
316
            }
320
317
            goto get_cache;
325
322
            ff_rm_retrieve_cache (rdt->rmctx, rdt->rmctx->pb,
326
323
                                  st, rdt->rmst[st->index], pkt);
327
324
        if (rdt->audio_pkt_cnt == 0 &&
328
 
            st->codec->codec_id == CODEC_ID_AAC)
 
325
            st->codec->codec_id == AV_CODEC_ID_AAC)
329
326
            av_freep(&rdt->rmctx->pb);
330
327
    }
331
328
    pkt->stream_index = st->index;
336
333
 
337
334
int
338
335
ff_rdt_parse_packet(RDTDemuxContext *s, AVPacket *pkt,
339
 
                    const uint8_t *buf, int len)
 
336
                    uint8_t **bufptr, int len)
340
337
{
 
338
    uint8_t *buf = bufptr ? *bufptr : NULL;
341
339
    int seq_no, flags = 0, stream_id, set_id, is_keyframe;
342
340
    uint32_t timestamp;
343
341
    int rv= 0;
350
348
        timestamp= 0; ///< Should not be used if buf is NULL, but should be set to the timestamp of the packet returned....
351
349
        rv= s->parse_packet(s->ic, s->dynamic_protocol_context,
352
350
                            s->streams[s->prev_stream_id],
353
 
                            pkt, &timestamp, NULL, 0, flags);
 
351
                            pkt, &timestamp, NULL, 0, 0, flags);
354
352
        return rv;
355
353
    }
356
354
 
377
375
 
378
376
    rv = s->parse_packet(s->ic, s->dynamic_protocol_context,
379
377
                         s->streams[s->prev_stream_id],
380
 
                         pkt, &timestamp, buf, len, flags);
 
378
                         pkt, &timestamp, buf, len, 0, flags);
381
379
 
382
380
    return rv;
383
381
}
401
399
    }
402
400
    *target_len = len * 3 / 4;
403
401
    target = av_mallocz(*target_len + FF_INPUT_BUFFER_PADDING_SIZE);
 
402
    if (!target)
 
403
        return NULL;
404
404
    av_base64_decode(target, p, *target_len);
405
405
    return target;
406
406
}
420
420
        int n, first = -1;
421
421
 
422
422
        for (n = 0; n < s->nb_streams; n++)
423
 
            if (s->streams[n]->priv_data == stream->priv_data) {
 
423
            if (s->streams[n]->id == stream->id) {
 
424
                int count = s->streams[n]->index + 1, err;
424
425
                if (first == -1) first = n;
 
426
                if (rdt->nb_rmst < count) {
 
427
                    if ((err = av_reallocp(&rdt->rmst,
 
428
                                           count * sizeof(*rdt->rmst))) < 0) {
 
429
                        rdt->nb_rmst = 0;
 
430
                        return err;
 
431
                    }
 
432
                    memset(rdt->rmst + rdt->nb_rmst, 0,
 
433
                           (count - rdt->nb_rmst) * sizeof(*rdt->rmst));
 
434
                    rdt->nb_rmst = count;
 
435
                }
425
436
                rdt->rmst[s->streams[n]->index] = ff_rm_alloc_rmstream();
426
437
                rdt_load_mdpr(rdt, s->streams[n], (n - first) * 2);
427
 
 
428
 
                if (s->streams[n]->codec->codec_id == CODEC_ID_AAC)
429
 
                    s->streams[n]->codec->frame_size = 1; // FIXME
430
438
           }
431
439
    }
432
440
 
451
459
{
452
460
    AVStream *st;
453
461
 
454
 
    if (!(st = av_new_stream(s, 0)))
 
462
    if (!(st = avformat_new_stream(s, NULL)))
455
463
        return NULL;
 
464
    st->id = orig_st->id;
456
465
    st->codec->codec_type = orig_st->codec->codec_type;
457
 
    st->priv_data         = orig_st->priv_data;
458
466
    st->first_dts         = orig_st->first_dts;
459
467
 
460
468
    return st;
465
473
                        const char *p)
466
474
{
467
475
    const char *end;
468
 
    int n_rules, odd = 0;
 
476
    int n_rules = 0, odd = 0;
469
477
    AVStream *st;
470
478
 
471
479
    /**
476
484
     * is set and once for if it isn't. We only read the first because we
477
485
     * don't care much (that's what the "odd" variable is for).
478
486
     * Each rule contains a set of one or more statements, optionally
479
 
     * preceeded by a single condition. If there's a condition, the rule
 
487
     * preceded by a single condition. If there's a condition, the rule
480
488
     * starts with a '#'. Multiple conditions are merged between brackets,
481
489
     * so there are never multiple conditions spread out over separate
482
490
     * statements. Generally, these conditions are bitrate limits (min/max)
483
491
     * for multi-bitrate streams.
484
492
     */
485
493
    if (*p == '\"') p++;
486
 
    for (n_rules = 0; s->nb_streams < MAX_STREAMS;) {
 
494
    while (1) {
487
495
        if (!(end = strchr(p, ';')))
488
496
            break;
489
497
        if (!odd && end != p) {
491
499
                st = add_dstream(s, orig_st);
492
500
            else
493
501
                st = orig_st;
 
502
            if (!st)
 
503
                break;
494
504
            real_parse_asm_rule(st, p, end);
495
505
            n_rules++;
496
506
        }
513
523
rdt_new_context (void)
514
524
{
515
525
    PayloadContext *rdt = av_mallocz(sizeof(PayloadContext));
516
 
 
517
 
    av_open_input_stream(&rdt->rmctx, NULL, "", &rdt_demuxer, NULL);
 
526
    int ret;
 
527
    if (!rdt)
 
528
        return NULL;
 
529
    ret = avformat_open_input(&rdt->rmctx, "", &ff_rdt_demuxer, NULL);
 
530
    if (ret < 0) {
 
531
        av_free(rdt);
 
532
        return NULL;
 
533
    }
518
534
 
519
535
    return rdt;
520
536
}
524
540
{
525
541
    int i;
526
542
 
527
 
    for (i = 0; i < MAX_STREAMS; i++)
 
543
    for (i = 0; i < rdt->nb_rmst; i++)
528
544
        if (rdt->rmst[i]) {
529
545
            ff_rm_free_rmstream(rdt->rmst[i]);
530
546
            av_freep(&rdt->rmst[i]);
531
547
        }
532
548
    if (rdt->rmctx)
533
 
        av_close_input_stream(rdt->rmctx);
 
549
        avformat_close_input(&rdt->rmctx);
534
550
    av_freep(&rdt->mlti_data);
 
551
    av_freep(&rdt->rmst);
535
552
    av_free(rdt);
536
553
}
537
554
 
538
555
#define RDT_HANDLER(n, s, t) \
539
 
static RTPDynamicProtocolHandler ff_rdt_ ## n ## _handler = { \
 
556
static RTPDynamicProtocolHandler rdt_ ## n ## _handler = { \
540
557
    .enc_name         = s, \
541
558
    .codec_type       = t, \
542
 
    .codec_id         = CODEC_ID_NONE, \
 
559
    .codec_id         = AV_CODEC_ID_NONE, \
543
560
    .parse_sdp_a_line = rdt_parse_sdp_line, \
544
 
    .open             = rdt_new_context, \
545
 
    .close            = rdt_free_context, \
 
561
    .alloc            = rdt_new_context, \
 
562
    .free             = rdt_free_context, \
546
563
    .parse_packet     = rdt_parse_packet \
547
 
};
 
564
}
548
565
 
549
566
RDT_HANDLER(live_video, "x-pn-multirate-realvideo-live", AVMEDIA_TYPE_VIDEO);
550
567
RDT_HANDLER(live_audio, "x-pn-multirate-realaudio-live", AVMEDIA_TYPE_AUDIO);
551
568
RDT_HANDLER(video,      "x-pn-realvideo",                AVMEDIA_TYPE_VIDEO);
552
569
RDT_HANDLER(audio,      "x-pn-realaudio",                AVMEDIA_TYPE_AUDIO);
553
570
 
554
 
void av_register_rdt_dynamic_payload_handlers(void)
 
571
void ff_register_rdt_dynamic_payload_handlers(void)
555
572
{
556
 
    ff_register_dynamic_payload_handler(&ff_rdt_video_handler);
557
 
    ff_register_dynamic_payload_handler(&ff_rdt_audio_handler);
558
 
    ff_register_dynamic_payload_handler(&ff_rdt_live_video_handler);
559
 
    ff_register_dynamic_payload_handler(&ff_rdt_live_audio_handler);
 
573
    ff_register_dynamic_payload_handler(&rdt_video_handler);
 
574
    ff_register_dynamic_payload_handler(&rdt_audio_handler);
 
575
    ff_register_dynamic_payload_handler(&rdt_live_video_handler);
 
576
    ff_register_dynamic_payload_handler(&rdt_live_audio_handler);
560
577
}