~ubuntu-branches/debian/experimental/gpac/experimental

« back to all changes in this revision

Viewing changes to modules/rtp_in/rtp_in.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2014-02-22 18:15:00 UTC
  • mfrom: (1.2.2) (3.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140222181500-b4phupo05gjpmopa
Tags: 0.5.0+svn5104~dfsg1-1
* New  upstream version 0.5.0+svn5104~dfsg1:
  - src/utils/sha1.c is relicensed under LGPLv2.1, Closes: #730759
* Don't install modules in multi-arch directories, Closes: #730497
* Add libusb-1.0.0-dev headers because libfreenect requires this
* Fix install rule
* Follow upstream soname bump
  - Drop the symbols file for now until it has been revised thourougly
* Let binaries produce the correct svn revision
* Refresh patches
* Patch and build against libav10, Closes: #739321
* Bump standards version, no changes necessary

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
#ifndef GPAC_DISABLE_STREAMING
29
29
 
 
30
#define RTP_DEFAULT_TIMEOUT 10000
 
31
#define RTSP_DEFAULT_TIMEOUT 2000
 
32
 
30
33
static void RT_LoadPrefs(GF_InputService *plug, RTPClient *rtp)
31
34
{
32
35
        const char *sOpt;
65
68
                if (sOpt ) {
66
69
                        rtp->udp_time_out = atoi(sOpt);
67
70
                } else {
68
 
                        rtp->udp_time_out = 10000;
 
71
                        rtp->udp_time_out = RTP_DEFAULT_TIMEOUT;
69
72
                }
70
73
        }
71
74
 
73
76
        if (sOpt ) {
74
77
                rtp->time_out = atoi(sOpt);
75
78
        } else {
76
 
                rtp->time_out = 30000;
 
79
                rtp->time_out = RTSP_DEFAULT_TIMEOUT;
77
80
        }
78
81
 
79
82
        /*packet drop emulation*/
366
369
 
367
370
static GF_Err RP_ConnectChannel(GF_InputService *plug, LPNETCHANNEL channel, const char *url, Bool upstream)
368
371
{
369
 
        u32 ESID;
370
 
        RTPStream *ch;
 
372
        u32 ESID, i;
 
373
        RTPStream *ch, *next_ch;
371
374
        RTSPSession *sess;
372
375
        char *es_url;
373
376
        RTPClient *priv = (RTPClient *)plug->priv;
388
391
                /*this should not happen, the sdp must describe all streams in the service*/
389
392
                if (!ch) return GF_STREAM_NOT_FOUND;
390
393
 
 
394
                /*search for next stream*/
 
395
                ch->next_stream = 0;
 
396
                for (i = 0; i < gf_list_count(priv->channels); i++) {
 
397
                        next_ch = (RTPStream *)gf_list_get(priv->channels, i);
 
398
                        if (next_ch->prev_stream == ch->mid)
 
399
                        {
 
400
                                ch->next_stream = next_ch->mid;
 
401
                                break;
 
402
                        }
 
403
                }
 
404
 
391
405
                /*assign app channel*/
392
406
                ch->channel = channel;
393
407
                sess = ch->rtsp;
450
464
        return GF_OK;
451
465
}
452
466
 
 
467
static void gf_rtp_switch_quality(RTPClient *rtp, Bool switch_up)
 
468
{
 
469
        u32 i,count;
 
470
        RTPStream *ch, *cur_ch;
 
471
        GF_NetworkCommand com;
 
472
        
 
473
        count = gf_list_count(rtp->channels);
 
474
        /*find the current stream*/
 
475
        ch = cur_ch = NULL;
 
476
        for (i = 0; i < count; i++) {
 
477
                cur_ch = (RTPStream *) gf_list_get(rtp->channels, i);
 
478
                if (cur_ch->mid != rtp->cur_mid) {
 
479
                        cur_ch=NULL;
 
480
                        continue;
 
481
                }
 
482
                break;
 
483
        }
 
484
        if (!cur_ch) return;
 
485
 
 
486
        if (switch_up)
 
487
        {
 
488
                /*this is the highest stream*/
 
489
                if (!cur_ch->next_stream)
 
490
                {
 
491
                        cur_ch->status = RTP_Running;
 
492
                        return;
 
493
                }
 
494
                else
 
495
                {
 
496
                        for (i = 0; i < count; i++) {
 
497
                                ch = (RTPStream *) gf_list_get(rtp->channels, i);
 
498
                                if (ch->mid == cur_ch->next_stream)
 
499
                                {
 
500
                                        /*resume streaming next channel*/
 
501
                                        gf_mx_p(rtp->mx);
 
502
                                        RP_InitStream(ch, 0);
 
503
                                        gf_mx_v(rtp->mx);
 
504
                                        ch->status = RTP_Running;
 
505
                                        rtp->cur_mid = ch->mid;
 
506
                                        break;
 
507
                                }
 
508
                        
 
509
                        }
 
510
                }       
 
511
        }
 
512
        else
 
513
        {
 
514
                /*this is the lowest stream i.e base layer*/
 
515
                if (!cur_ch->prev_stream)
 
516
                {
 
517
                        cur_ch->status = RTP_Running;
 
518
                        return;
 
519
                }
 
520
                else
 
521
                {
 
522
                        for (i = 0; i < count; i++) {
 
523
                                ch = (RTPStream *) gf_list_get(rtp->channels, i);
 
524
                                if (ch->mid == cur_ch->prev_stream)
 
525
                                {
 
526
                                        /*stop streaming current channel*/
 
527
                                        gf_rtp_stop(cur_ch->rtp_ch);
 
528
                                        cur_ch->status = RTP_Connected;
 
529
                                        com.command_type = GF_NET_CHAN_RESET;
 
530
                                        com.base.on_channel = cur_ch;
 
531
                                        gf_term_on_command(rtp->service, &com, GF_OK);
 
532
                                        rtp->cur_mid = ch->mid;
 
533
                                        break;
 
534
                                }               
 
535
                        }
 
536
                }       
 
537
        }
 
538
        GF_LOG(GF_LOG_DEBUG, GF_LOG_CODEC, ("Switch from ES%d to ES %d\n", cur_ch->mid, ch->mid));
 
539
        return;
 
540
}
 
541
 
453
542
static GF_Err RP_ServiceCommand(GF_InputService *plug, GF_NetworkCommand *com)
454
543
{
455
544
        RTPStream *ch;
470
559
                priv->session_migration=1;
471
560
                if (priv->session_state_data) {
472
561
                        com->migrate.data = priv->session_state_data;
473
 
                        com->migrate.data_len = strlen(priv->session_state_data);
 
562
                        com->migrate.data_len = (u32) strlen(priv->session_state_data);
474
563
                        return GF_OK;
475
564
                }
476
565
                return GF_NOT_SUPPORTED;
477
566
        }
478
567
 
 
568
        if (com->command_type == GF_NET_SERVICE_QUALITY_SWITCH)
 
569
        {
 
570
                gf_rtp_switch_quality(priv, com->switch_quality.up);
 
571
                return GF_OK;
 
572
        }
 
573
 
479
574
        /*ignore commands other than channels one*/
480
575
        if (!com->base.on_channel) {
481
576
                if (com->command_type==GF_NET_IS_CACHABLE) return GF_OK;
544
639
                        RP_UserCommand(ch->rtsp, ch, com);
545
640
                } else {
546
641
                        ch->status = RTP_Running;
 
642
                        if (!ch->next_stream)
 
643
                                priv->cur_mid = ch->mid;
 
644
 
547
645
                        if (ch->rtp_ch) {
548
646
                                /*technically we shouldn't attempt to synchronize streams based on RTP, we should use RTCP/ However it
549
647
                                may happen that the RTCP traffic is absent ...*/
550
 
                                ch->check_rtp_time = RTP_SET_TIME_RTP;
 
648
                                //ch->check_rtp_time = RTP_SET_TIME_RTP;
551
649
                                ch->rtcp_init = 0;
552
650
                                gf_mx_p(priv->mx);
553
651
                                RP_InitStream(ch, (ch->flags & RTP_CONNECTED) ? 1 : 0);
616
714
                        bps = 8.0f * gf_rtp_get_tcp_bytes_sent(ch->rtp_ch); bps *= 1000; bps /= time; com->net_stats.ctrl_bw_up = (u32) bps;
617
715
                }
618
716
                return GF_OK;
 
717
        default:
 
718
                break;
619
719
        }
620
720
        return GF_NOT_SUPPORTED;
621
721
}
647
747
                /*decode data*/
648
748
                data = strstr(data, ",");
649
749
                data += 1;
650
 
                *out_data_size = gf_base64_decode(data, strlen(data), ch->buffer, RTP_BUFFER_SIZE);
 
750
                *out_data_size = gf_base64_decode(data, (u32) strlen(data), ch->buffer, RTP_BUFFER_SIZE);
651
751
                /*FIXME - currently only support for empty SL header*/
652
752
                *out_data_ptr = ch->buffer;
653
753
                ch->flags &= ~GF_RTP_NEW_AU;
737
837
 
738
838
        plug->priv = priv;
739
839
 
740
 
        priv->time_out = 30000;
 
840
        priv->time_out = RTSP_DEFAULT_TIMEOUT;
741
841
        priv->mx = gf_mx_new("RTPDemux");
742
842
        priv->th = gf_th_new("RTPDemux");
743
843
 
775
875
#endif
776
876
 
777
877
 
778
 
GF_EXPORT
 
878
GPAC_MODULE_EXPORT
779
879
const u32 *QueryInterfaces()
780
880
{
781
881
        static u32 si [] = {
787
887
        return si;
788
888
}
789
889
 
790
 
GF_EXPORT
 
890
GPAC_MODULE_EXPORT
791
891
GF_BaseInterface *LoadInterface(u32 InterfaceType)
792
892
{
793
893
#ifndef GPAC_DISABLE_STREAMING
796
896
        return NULL;
797
897
}
798
898
 
799
 
GF_EXPORT
 
899
GPAC_MODULE_EXPORT
800
900
void ShutdownInterface(GF_BaseInterface *ifce)
801
901
{
802
902
        switch (ifce->InterfaceType) {
807
907
#endif
808
908
        }
809
909
}
 
910
 
 
911
GPAC_MODULE_STATIC_DELARATION( rtp_in )