~didier-barvaux/+junk/rohc-tcp

« back to all changes in this revision

Viewing changes to src/comp/c_rtp.c

  • Committer: Didier Barvaux
  • Date: 2013-06-30 12:53:19 UTC
  • mfrom: (535.1.213 rohc-main)
  • Revision ID: didier@barvaux.org-20130630125319-33xosfau63ygas1f
Sync with main branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
 * Private function prototypes.
47
47
 */
48
48
 
 
49
static int c_rtp_create(struct c_context *const context,
 
50
                        const struct ip_packet *ip);
 
51
static void c_rtp_destroy(struct c_context *const context);
 
52
 
49
53
static bool c_rtp_check_profile(const struct rohc_comp *const comp,
50
54
                                const struct ip_packet *const outer_ip,
51
55
                                const struct ip_packet *const inner_ip,
56
60
static bool c_rtp_use_udp_port(const struct c_context *const context,
57
61
                               const unsigned int port);
58
62
 
 
63
static bool c_rtp_check_context(const struct c_context *context,
 
64
                                const struct ip_packet *ip);
 
65
 
 
66
static int c_rtp_encode(struct c_context *const context,
 
67
                        const struct ip_packet *ip,
 
68
                        const size_t packet_size,
 
69
                        unsigned char *const dest,
 
70
                        const size_t dest_size,
 
71
                        rohc_packet_t *const packet_type,
 
72
                        int *const payload_offset);
 
73
 
 
74
static void rtp_decide_state(struct c_context *const context);
 
75
 
59
76
static rohc_packet_t c_rtp_decide_FO_packet(const struct c_context *context);
60
77
static rohc_packet_t c_rtp_decide_SO_packet(const struct c_context *context);
61
78
static rohc_ext_t c_rtp_decide_extension(const struct c_context *context);
69
86
                                    const struct ip_packet *const ip2,
70
87
                                    const unsigned char *const next_header);
71
88
 
72
 
int rtp_code_static_rtp_part(const struct c_context *context,
73
 
                             const unsigned char *next_header,
74
 
                             unsigned char *const dest,
75
 
                             int counter);
76
 
 
77
 
int rtp_code_dynamic_rtp_part(const struct c_context *context,
78
 
                              const unsigned char *next_header,
79
 
                              unsigned char *const dest,
80
 
                              int counter);
81
 
 
82
 
int rtp_changed_rtp_dynamic(const struct c_context *context,
83
 
                            const struct udphdr *udp);
 
89
static int rtp_code_static_rtp_part(const struct c_context *context,
 
90
                                    const unsigned char *next_header,
 
91
                                    unsigned char *const dest,
 
92
                                    int counter);
 
93
 
 
94
static int rtp_code_dynamic_rtp_part(const struct c_context *context,
 
95
                                     const unsigned char *next_header,
 
96
                                     unsigned char *const dest,
 
97
                                     int counter);
 
98
 
 
99
static int rtp_changed_rtp_dynamic(const struct c_context *context,
 
100
                                   const struct udphdr *udp);
84
101
 
85
102
 
86
103
/**
94
111
 * @param ip      The IP/UDP/RTP packet given to initialize the new context
95
112
 * @return        1 if successful, 0 otherwise
96
113
 */
97
 
int c_rtp_create(struct c_context *const context, const struct ip_packet *ip)
 
114
static int c_rtp_create(struct c_context *const context,
 
115
                        const struct ip_packet *ip)
98
116
{
99
117
        struct c_generic_context *g_context;
100
118
        struct sc_rtp_context *rtp_context;
151
169
        rtp = (struct rtphdr *) (udp + 1);
152
170
 
153
171
        /* initialize SN with the SN found in the RTP header */
154
 
        g_context->sn = (uint32_t) ntohs(rtp->sn);
 
172
        g_context->sn = (uint32_t) rohc_ntoh16(rtp->sn);
155
173
        assert(g_context->sn <= 0xffff);
156
174
        rohc_comp_debug(context, "initialize context(SN) = hdr(SN) of first "
157
175
                        "packet = %u\n", g_context->sn);
171
189
        memcpy(&rtp_context->old_udp, udp, sizeof(struct udphdr));
172
190
        rtp_context->rtp_pt_change_count = 0;
173
191
        rtp_context->rtp_padding_change_count = 0;
 
192
        rtp_context->rtp_extension_change_count = 0;
174
193
        memcpy(&rtp_context->old_rtp, rtp, sizeof(struct rtphdr));
175
194
        if(!c_create_sc(&rtp_context->ts_sc,
176
195
                        context->compressor->wlsb_window_width,
191
210
        rtp_context->tmp.is_marker_bit_set = false;
192
211
        rtp_context->tmp.rtp_pt_changed = 0;
193
212
        rtp_context->tmp.padding_bit_changed = false;
 
213
        rtp_context->tmp.extension_bit_changed = false;
194
214
 
195
215
        /* init the RTP-specific variables and functions */
196
216
        g_context->next_header_proto = ROHC_IPPROTO_UDP;
227
247
 *
228
248
 * @param context The RTP compression context to destroy
229
249
 */
230
 
void c_rtp_destroy(struct c_context *const context)
 
250
static void c_rtp_destroy(struct c_context *const context)
231
251
{
232
252
        struct c_generic_context *g_context;
233
253
        struct sc_rtp_context *rtp_context;
356
376
                /* check if the UDP destination port belongs to the list of RTP
357
377
                   destination ports reserved for RTP traffic */
358
378
 
359
 
                const uint16_t dest_port = ntohs(udp_header->dest);
 
379
                const uint16_t dest_port = rohc_ntoh16(udp_header->dest);
360
380
                bool is_rtp_packet;
361
381
 
362
382
 
450
470
 *
451
471
 * @param context The compression context
452
472
 * @param ip      The IP/UDP/RTP packet to check
453
 
 * @return        1 if the IP/UDP/RTP packet belongs to the context,
454
 
 *                0 if it does not belong to the context and
455
 
 *                -1 if an error occurs
 
473
 * @return        true if the IP/UDP/RTP packet belongs to the context
 
474
 *                false if it does not belong to the context
456
475
 *
457
476
 * @see c_udp_check_context
458
477
 */
459
 
int c_rtp_check_context(const struct c_context *context,
460
 
                        const struct ip_packet *ip)
 
478
static bool c_rtp_check_context(const struct c_context *context,
 
479
                                const struct ip_packet *ip)
461
480
{
462
481
        const struct c_generic_context *g_context;
463
482
        const struct sc_rtp_context *rtp_context;
466
485
        const struct udphdr *udp;
467
486
        const struct rtphdr *rtp;
468
487
        unsigned int ip_proto;
469
 
        int udp_check;
470
 
        int is_rtp_same;
 
488
        bool udp_check;
 
489
        bool is_rtp_same;
471
490
 
472
491
        /* check IP and UDP headers */
473
492
        udp_check = c_udp_check_context(context, ip);
474
 
        if(udp_check != 1)
 
493
        if(!udp_check)
475
494
        {
476
 
                goto quit;
 
495
                goto bad_context;
477
496
        }
478
497
 
479
498
        /* get the last IP header */
485
504
                {
486
505
                        rohc_warning(context->compressor, ROHC_TRACE_COMP, context->profile->id,
487
506
                                     "cannot create the inner IP header\n");
488
 
                        goto error;
 
507
                        goto bad_context;
489
508
                }
490
509
                last_ip_header = &ip2;
491
510
        }
506
525
 
507
526
        return is_rtp_same;
508
527
 
509
 
quit:
510
 
        return udp_check;
511
 
error:
512
 
        return -1;
 
528
bad_context:
 
529
        return false;
513
530
}
514
531
 
515
532
 
726
743
        assert(rtp_context->tmp.send_rtp_dynamic == 0);
727
744
        /* RTP Padding bit is a STATIC field, not allowed to change in SO state */
728
745
        assert(!rtp_context->tmp.padding_bit_changed);
 
746
        /* RTP eXtension bit is STATIC field, not allowed to change in SO state */
 
747
        assert(!rtp_context->tmp.extension_bit_changed);
729
748
 
730
749
        /* find out how many IP headers are IPv4 headers with non-random IP-IDs */
731
750
        nr_ipv4_non_rnd = 0;
793
812
                !rtp_context->tmp.is_marker_bit_set)
794
813
        {
795
814
                /* TODO: when extensions are supported within the UO-1-ID packet,
796
 
                 * please check whether the !is_marker_bit_set conditions could be
 
815
                 * please check whether the !is_marker_bit_set condition could be
797
816
                 * removed or not, and whether nr_ipv4_non_rnd_with_bits == 1 should
798
817
                 * not be replaced by nr_ipv4_non_rnd_with_bits >= 1 */
799
818
                packet = PACKET_UO_1_ID;
912
931
 * @param payload_offset The offset for the payload in the IP packet
913
932
 * @return               The length of the created ROHC packet
914
933
 */
915
 
int c_rtp_encode(struct c_context *const context,
916
 
                 const struct ip_packet *ip,
917
 
                 const int packet_size,
918
 
                 unsigned char *const dest,
919
 
                 const int dest_size,
920
 
                 rohc_packet_t *const packet_type,
921
 
                 int *const payload_offset)
 
934
static int c_rtp_encode(struct c_context *const context,
 
935
                        const struct ip_packet *ip,
 
936
                        const size_t packet_size,
 
937
                        unsigned char *const dest,
 
938
                        const size_t dest_size,
 
939
                        rohc_packet_t *const packet_type,
 
940
                        int *const payload_offset)
922
941
{
923
942
        struct c_generic_context *g_context;
924
943
        struct sc_rtp_context *rtp_context;
993
1012
                memcpy(&rtp_context->old_udp, udp, sizeof(struct udphdr));
994
1013
                memcpy(&rtp_context->old_rtp, rtp, sizeof(struct rtphdr));
995
1014
        }
996
 
        else if(rtp_context->tmp.padding_bit_changed)
 
1015
        else
997
1016
        {
998
 
                rtp_context->old_rtp.padding = rtp->padding;
 
1017
                if(rtp_context->tmp.padding_bit_changed)
 
1018
                {
 
1019
                        rtp_context->old_rtp.padding = rtp->padding;
 
1020
                }
 
1021
                if(rtp_context->tmp.extension_bit_changed)
 
1022
                {
 
1023
                        rtp_context->old_rtp.extension = rtp->extension;
 
1024
                }
999
1025
        }
1000
1026
 
1001
1027
quit:
1014
1040
 *
1015
1041
 * @param context The compression context
1016
1042
 */
1017
 
void rtp_decide_state(struct c_context *const context)
 
1043
static void rtp_decide_state(struct c_context *const context)
1018
1044
{
1019
1045
        struct c_generic_context *g_context;
1020
1046
        struct sc_rtp_context *rtp_context;
1092
1118
        }
1093
1119
        rtp = (struct rtphdr *) (udp + 1);
1094
1120
 
1095
 
        next_sn = (uint32_t) ntohs(rtp->sn);
 
1121
        next_sn = (uint32_t) rohc_ntoh16(rtp->sn);
1096
1122
 
1097
1123
        assert(next_sn <= 0xffff);
1098
1124
        return next_sn;
1140
1166
        {
1141
1167
                /* TS_STRIDE cannot be computed yet (first packet or TS is constant),
1142
1168
                 * so send TS only */
1143
 
                rtp_context->tmp.ts_send = ntohl(rtp->timestamp);
 
1169
                rtp_context->tmp.ts_send = rohc_ntoh32(rtp->timestamp);
1144
1170
                rtp_context->tmp.nr_ts_bits = 32;
1145
1171
                rohc_comp_debug(context, "cannot send TS scaled, send TS only\n");
1146
1172
        }
1147
1173
        else if(rtp_context->ts_sc.state == INIT_STRIDE)
1148
1174
        {
1149
1175
                /* TS and TS_STRIDE will be send */
1150
 
                rtp_context->tmp.ts_send = ntohl(rtp->timestamp);
 
1176
                rtp_context->tmp.ts_send = rohc_ntoh32(rtp->timestamp);
1151
1177
                rtp_context->tmp.nr_ts_bits = 32;
1152
1178
                rohc_comp_debug(context, "cannot send TS scaled, send TS and TS_STRIDE\n");
1153
1179
        }
1228
1254
 *
1229
1255
 * @see udp_code_static_udp_part
1230
1256
 */
1231
 
int rtp_code_static_rtp_part(const struct c_context *context,
1232
 
                             const unsigned char *next_header,
1233
 
                             unsigned char *const dest,
1234
 
                             int counter)
 
1257
static int rtp_code_static_rtp_part(const struct c_context *context,
 
1258
                                    const unsigned char *next_header,
 
1259
                                    unsigned char *const dest,
 
1260
                                    int counter)
1235
1261
{
1236
1262
        struct udphdr *udp = (struct udphdr *) next_header;
1237
1263
        struct rtphdr *rtp = (struct rtphdr *) (udp + 1);
1289
1315
 * @param counter     The current position in the rohc-packet-under-build buffer
1290
1316
 * @return            The new position in the rohc-packet-under-build buffer
1291
1317
 */
1292
 
int rtp_code_dynamic_rtp_part(const struct c_context *context,
1293
 
                              const unsigned char *next_header,
1294
 
                              unsigned char *const dest,
1295
 
                              int counter)
 
1318
static int rtp_code_dynamic_rtp_part(const struct c_context *context,
 
1319
                                     const unsigned char *next_header,
 
1320
                                     unsigned char *const dest,
 
1321
                                     int counter)
1296
1322
{
1297
1323
        struct c_generic_context *g_context;
1298
1324
        struct sc_rtp_context *rtp_context;
1315
1341
 
1316
1342
        /* part 2 */
1317
1343
        byte = 0;
1318
 
        if(rtp_context->ts_sc.state == INIT_STRIDE)
 
1344
        if(rtp_context->ts_sc.state == INIT_STRIDE ||
 
1345
           rtp_context->tmp.extension_bit_changed ||
 
1346
           rtp_context->rtp_extension_change_count < MAX_IR_COUNT)
1319
1347
        {
1320
 
                /* send ts_stride */
 
1348
                /* send TS_STRIDE and/or the eXtension (X) bit */
1321
1349
                rx_byte = 1;
1322
1350
                byte |= 1 << 4;
1323
1351
        }
1375
1403
                dest[counter] = byte;
1376
1404
                rohc_comp_debug(context, "part 7 = 0x%02x\n", dest[counter]);
1377
1405
                counter++;
 
1406
                rtp_context->rtp_extension_change_count++;
1378
1407
 
1379
1408
                /* part 8 */
1380
1409
                if(tss)
1447
1476
 * @param udp     The UDP/RTP headers
1448
1477
 * @return        The number of UDP/RTP fields that changed
1449
1478
 */
1450
 
int rtp_changed_rtp_dynamic(const struct c_context *context,
1451
 
                            const struct udphdr *udp)
 
1479
static int rtp_changed_rtp_dynamic(const struct c_context *context,
 
1480
                                   const struct udphdr *udp)
1452
1481
{
1453
1482
        struct c_generic_context *g_context;
1454
1483
        struct sc_rtp_context *rtp_context;
1537
1566
                rtp_context->tmp.padding_bit_changed = false;
1538
1567
        }
1539
1568
 
 
1569
        /* check RTP eXtension (X) field */
 
1570
        if(rtp->extension != rtp_context->old_rtp.extension ||
 
1571
           rtp_context->rtp_extension_change_count < MAX_IR_COUNT)
 
1572
        {
 
1573
                if(rtp->extension != rtp_context->old_rtp.extension)
 
1574
                {
 
1575
                        rohc_comp_debug(context, "RTP eXtension (X) bit changed "
 
1576
                                        "(0x%x -> 0x%x)\n",
 
1577
                                        rtp_context->old_rtp.extension, rtp->extension);
 
1578
                        rtp_context->tmp.extension_bit_changed = true;
 
1579
                        rtp_context->rtp_extension_change_count = 0;
 
1580
                }
 
1581
                else
 
1582
                {
 
1583
                        rohc_comp_debug(context, "RTP eXtension (X) bit did not change but "
 
1584
                                        "changed in the last few packets\n");
 
1585
                        rtp_context->tmp.extension_bit_changed = false;
 
1586
                }
 
1587
 
 
1588
                fields++;
 
1589
        }
 
1590
        else
 
1591
        {
 
1592
                rtp_context->tmp.extension_bit_changed = false;
 
1593
        }
 
1594
 
1540
1595
        /* check RTP Payload Type field */
1541
1596
        if(rtp->pt != rtp_context->old_rtp.pt ||
1542
1597
           rtp_context->rtp_pt_change_count < MAX_IR_COUNT)
1563
1618
        }
1564
1619
 
1565
1620
        /* we verify if ts_stride changed */
1566
 
        rtp_context->tmp.timestamp = ntohl(rtp->timestamp);
 
1621
        rtp_context->tmp.timestamp = rohc_ntoh32(rtp->timestamp);
1567
1622
        if(rtp_context->ts_sc.state != SEND_SCALED)
1568
1623
        {
1569
1624
                rohc_comp_debug(context, "TS_STRIDE changed now or in the last few "