Ignore:
Timestamp:
Apr 4, 2012 5:05:50 AM (12 years ago)
Author:
bennylp
Message:

Fixed #1478: AVI player virtual device. Initial spec:

  • Currently only Works with raw video and audio AVI files
  • Added --play-avi and --auto-play-avi options in pjsua
  • No A/V synchronization yet
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c

    r3999 r4016  
    4444#define RING_INTERVAL       3000 
    4545 
     46#define MAX_AVI             4 
    4647 
    4748/* Call specific data */ 
     
    136137    struct app_vid          vid; 
    137138    unsigned                aud_cnt; 
     139 
     140    /* AVI to play */ 
     141    unsigned                avi_cnt; 
     142    pj_str_t                avi[MAX_AVI]; 
     143    pj_bool_t               avi_auto_play; 
     144    pjmedia_vid_dev_index   avi_dev_id; 
     145    pjsua_conf_port_id      avi_slot; 
    138146} app_config; 
    139147 
     
    330338    puts  ("  --vcapture-dev=id   Video capture device ID (default=-1)"); 
    331339    puts  ("  --vrender-dev=id    Video render device ID (default=-1)"); 
     340    puts  ("  --play-avi=FILE     Load this AVI as virtual capture device"); 
     341    puts  ("  --auto-play-avi     Automatically play the AVI media to call"); 
    332342#endif 
    333343 
     
    400410    cfg->ringback_slot = PJSUA_INVALID_ID; 
    401411    cfg->ring_slot = PJSUA_INVALID_ID; 
     412 
     413    cfg->avi_dev_id = PJMEDIA_VID_INVALID_DEV; 
     414    cfg->avi_slot = PJSUA_INVALID_ID; 
    402415 
    403416    for (i=0; i<PJ_ARRAY_SIZE(cfg->acc_cfg); ++i) 
     
    577590           OPT_TIMER, OPT_TIMER_SE, OPT_TIMER_MIN_SE, 
    578591           OPT_VIDEO, OPT_EXTRA_AUDIO, 
    579            OPT_VCAPTURE_DEV, OPT_VRENDER_DEV, 
     592           OPT_VCAPTURE_DEV, OPT_VRENDER_DEV, OPT_PLAY_AVI, OPT_AUTO_PLAY_AVI 
    580593    }; 
    581594    struct pj_getopt_option long_options[] = { 
     
    703716        { "vcapture-dev", 1, 0, OPT_VCAPTURE_DEV}, 
    704717        { "vrender-dev",  1, 0, OPT_VRENDER_DEV}, 
     718        { "play-avi",   1, 0, OPT_PLAY_AVI}, 
     719        { "auto-play-avi", 0, 0, OPT_AUTO_PLAY_AVI}, 
    705720        { NULL, 0, 0, 0} 
    706721    }; 
     
    14961511            cfg->vid.vrender_dev = atoi(pj_optarg); 
    14971512            cur_acc->vid_rend_dev = cfg->vid.vrender_dev; 
     1513            break; 
     1514 
     1515        case OPT_PLAY_AVI: 
     1516            if (app_config.avi_cnt >= MAX_AVI) { 
     1517                PJ_LOG(1,(THIS_FILE, "Too many AVIs")); 
     1518                return -1; 
     1519            } 
     1520            app_config.avi[app_config.avi_cnt++] = pj_str(pj_optarg); 
     1521            break; 
     1522 
     1523        case OPT_AUTO_PLAY_AVI: 
     1524            app_config.avi_auto_play = PJ_TRUE; 
    14981525            break; 
    14991526 
     
    20822109    if (config->vid.vrender_dev != PJMEDIA_VID_DEFAULT_RENDER_DEV) { 
    20832110        pj_ansi_sprintf(line, "--vrender-dev %d\n", config->vid.vrender_dev); 
     2111        pj_strcat2(&cfg, line); 
     2112    } 
     2113    for (i=0; i<config->avi_cnt; ++i) { 
     2114        pj_ansi_sprintf(line, "--play-avi %s\n", config->avi[i].ptr); 
     2115        pj_strcat2(&cfg, line); 
     2116    } 
     2117    if (config->avi_auto_play) { 
     2118        pj_ansi_sprintf(line, "--auto-play-avi\n"); 
    20842119        pj_strcat2(&cfg, line); 
    20852120    } 
     
    27882823            pjsua_conf_connect(app_config.wav_port, call_conf_slot); 
    27892824            connect_sound = PJ_FALSE; 
     2825        } 
     2826 
     2827        /* Stream AVI, if desired */ 
     2828        if (app_config.avi_auto_play && 
     2829            app_config.avi_slot != PJSUA_INVALID_ID) 
     2830        { 
     2831            pjsua_conf_connect(app_config.avi_slot, call_conf_slot); 
    27902832        } 
    27912833 
     
    39764018    acc_cfg->vid_cap_dev = app_config.vid.vcapture_dev; 
    39774019    acc_cfg->vid_rend_dev = app_config.vid.vrender_dev; 
     4020 
     4021    if (app_config.avi_auto_play && 
     4022        app_config.avi_dev_id != PJMEDIA_VID_INVALID_DEV) 
     4023    { 
     4024        acc_cfg->vid_cap_dev = app_config.avi_dev_id; 
     4025    } 
    39784026} 
    39794027 
     
    56365684    } 
    56375685 
     5686    /* Create AVI player virtual devices */ 
     5687    if (app_config.avi_cnt) { 
     5688#if PJMEDIA_VIDEO_DEV_HAS_AVI 
     5689        pjmedia_vid_dev_factory *avi_factory; 
     5690 
     5691        status = pjmedia_avi_dev_create_factory(pjsua_get_pool_factory(), 
     5692                                                app_config.avi_cnt, 
     5693                                                &avi_factory); 
     5694        if (status != PJ_SUCCESS) { 
     5695            PJ_PERROR(1,(THIS_FILE, status, "Error creating AVI factory")); 
     5696            goto on_error; 
     5697        } 
     5698 
     5699        for (i=0; i<app_config.avi_cnt; ++i) { 
     5700            pjmedia_avi_dev_param avdp; 
     5701            pjmedia_vid_dev_index avid; 
     5702            unsigned strm_idx, strm_cnt; 
     5703 
     5704            pjmedia_avi_dev_param_default(&avdp); 
     5705            avdp.path = app_config.avi[i]; 
     5706 
     5707            status =  pjmedia_avi_dev_alloc(avi_factory, &avdp, &avid); 
     5708            if (status != PJ_SUCCESS) { 
     5709                PJ_PERROR(1,(THIS_FILE, status, 
     5710                             "Error creating AVI player for %.*s", 
     5711                             (int)avdp.path.slen, avdp.path.ptr)); 
     5712                goto on_error; 
     5713            } 
     5714 
     5715            PJ_LOG(4,(THIS_FILE, "AVI player %.*s created, dev_id=%d", 
     5716                      (int)avdp.title.slen, avdp.title.ptr, avid)); 
     5717            app_config.avi_dev_id = avid; 
     5718 
     5719            strm_cnt = pjmedia_avi_streams_get_num_streams(avdp.avi_streams); 
     5720            for (strm_idx=0; strm_idx<strm_cnt; ++strm_idx) { 
     5721                pjmedia_port *aud; 
     5722                pjmedia_format *fmt; 
     5723                pjsua_conf_port_id slot; 
     5724                char fmt_name[5]; 
     5725 
     5726                aud = pjmedia_avi_streams_get_stream(avdp.avi_streams, 
     5727                                                     strm_idx); 
     5728                fmt = &aud->info.fmt; 
     5729 
     5730                pjmedia_fourcc_name(fmt->id, fmt_name); 
     5731 
     5732                if (fmt->id == PJMEDIA_FORMAT_PCM) { 
     5733                    status = pjsua_conf_add_port(app_config.pool, aud, 
     5734                                                 &slot); 
     5735                    if (status == PJ_SUCCESS) { 
     5736                        PJ_LOG(4,(THIS_FILE, 
     5737                                  "AVI %.*s: audio added to slot %d", 
     5738                                  (int)avdp.title.slen, avdp.title.ptr, 
     5739                                  slot)); 
     5740                        app_config.avi_slot = slot; 
     5741                    } 
     5742                } else { 
     5743                    PJ_LOG(4,(THIS_FILE, 
     5744                              "AVI %.*s: audio ignored, format=%s", 
     5745                              (int)avdp.title.slen, avdp.title.ptr, 
     5746                              fmt_name)); 
     5747                } 
     5748            } 
     5749        } 
     5750#else 
     5751        PJ_LOG(2,(THIS_FILE, 
     5752                  "Warning: --play-avi is ignored because AVI is disabled")); 
     5753#endif  /* PJMEDIA_VIDEO_DEV_HAS_AVI */ 
     5754    } 
     5755 
    56385756    /* Add UDP transport unless it's disabled. */ 
    56395757    if (!app_config.no_udp) { 
Note: See TracChangeset for help on using the changeset viewer.