Changeset 4018


Ignore:
Timestamp:
Apr 4, 2012 5:45:46 AM (12 years ago)
Author:
ming
Message:

Misc (Re #1446): Add support for aviplay to play H264 and MPEG4 decoded AVI videos. This includes support for XVID and DIVX MPEG4.

Location:
pjproject/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/avi_player.c

    r4014 r4018  
    9292#endif 
    9393 
     94typedef struct avi_fmt_info 
     95{ 
     96    pjmedia_format_id   fmt_id; 
     97    pjmedia_format_id   eff_fmt_id; 
     98} avi_fmt_info; 
     99 
     100static avi_fmt_info avi_fmts[] = 
     101{ 
     102    {PJMEDIA_FORMAT_MJPEG}, {PJMEDIA_FORMAT_H264}, 
     103    {PJMEDIA_FORMAT_UYVY}, {PJMEDIA_FORMAT_YUY2}, 
     104    {PJMEDIA_FORMAT_IYUV}, {PJMEDIA_FORMAT_I420}, 
     105    {PJMEDIA_FORMAT_DIB}, {PJMEDIA_FORMAT_RGB24}, 
     106    {PJMEDIA_FORMAT_RGB32}, 
     107    {PJMEDIA_FORMAT_PACK('X','V','I','D'), PJMEDIA_FORMAT_MPEG4}, 
     108    {PJMEDIA_FORMAT_PACK('x','v','i','d'), PJMEDIA_FORMAT_MPEG4}, 
     109    {PJMEDIA_FORMAT_PACK('D','I','V','X'), PJMEDIA_FORMAT_MPEG4}, 
     110}; 
     111 
    94112struct pjmedia_avi_streams 
    95113{ 
     
    347365                        PJMEDIA_AVI_VIDS_TAG)) 
    348366        { 
    349             /* Check supported video formats here */ 
    350             if (avi_hdr.strl_hdr[i].flags & AVISF_VIDEO_PALCHANGES || 
    351                 (avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_MJPEG && 
    352                  avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_XVID && 
    353                  avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_UYVY && 
    354                  avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_YUY2 && 
    355                  avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_IYUV && 
    356                  avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_I420 && 
    357                  avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_DIB && 
    358                  avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_RGB24 && 
    359                  avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_RGB32)) 
    360             { 
     367            int j; 
     368 
     369            if (avi_hdr.strl_hdr[i].flags & AVISF_VIDEO_PALCHANGES) { 
    361370                PJ_LOG(4, (THIS_FILE, "Unsupported video stream")); 
    362371                continue; 
    363372            } 
     373 
    364374            fmt_id = avi_hdr.strl_hdr[i].codec; 
     375            for (j = sizeof(avi_fmts)/sizeof(avi_fmts[0])-1; j >= 0; j--) { 
     376                /* Check supported video formats here */ 
     377                if (fmt_id == avi_fmts[j].fmt_id) { 
     378                    if (avi_fmts[j].eff_fmt_id) 
     379                        fmt_id = avi_fmts[j].eff_fmt_id; 
     380                    break; 
     381                } 
     382            } 
     383             
     384            if (j < 0) { 
     385                PJ_LOG(4, (THIS_FILE, "Unsupported video stream")); 
     386                continue; 
     387            } 
    365388        } else { 
    366389            /* Check supported audio formats here */ 
     
    380403        } 
    381404 
    382         if (nstr == 0) { 
    383             fport[0]->stream_id = i; 
    384             nstr++; 
    385             continue; 
    386         } 
    387  
    388         /* Create fport instance. */ 
    389         fport[nstr] = create_avi_port(pool); 
    390         if (!fport[nstr]) { 
    391             status = PJ_ENOMEM; 
    392             goto on_error; 
     405        if (nstr > 0) { 
     406            /* Create fport instance. */ 
     407            fport[nstr] = create_avi_port(pool); 
     408            if (!fport[nstr]) { 
     409                status = PJ_ENOMEM; 
     410                goto on_error; 
     411            } 
     412 
     413            /* Open file. */ 
     414            status = pj_file_open(pool, filename, PJ_O_RDONLY, 
     415                                  &fport[nstr]->fd); 
     416            if (status != PJ_SUCCESS) 
     417                goto on_error; 
     418 
     419            /* Set the file position */ 
     420            status = pj_file_setpos(fport[nstr]->fd, pos, PJ_SEEK_SET); 
     421            if (status != PJ_SUCCESS) { 
     422                goto on_error; 
     423            } 
    393424        } 
    394425 
    395426        fport[nstr]->stream_id = i; 
    396427        fport[nstr]->fmt_id = fmt_id; 
    397  
    398         /* Open file. */ 
    399         status = pj_file_open(pool, filename, PJ_O_RDONLY, &fport[nstr]->fd); 
    400         if (status != PJ_SUCCESS) 
    401             goto on_error; 
    402  
    403         /* Set the file position */ 
    404         status = pj_file_setpos(fport[nstr]->fd, pos, PJ_SEEK_SET); 
    405         if (status != PJ_SUCCESS) { 
    406             goto on_error; 
    407         } 
    408428 
    409429        nstr++; 
     
    435455            fport[i]->bits_per_sample = (vfi ? vfi->bpp : 0); 
    436456            pjmedia_format_init_video(&fport[i]->base.info.fmt, 
    437                                       strl_hdr->codec, 
     457                                      fport[i]->fmt_id, 
    438458                                      strf_hdr->biWidth, 
    439459                                      strf_hdr->biHeight, 
  • pjproject/trunk/pjsip-apps/src/samples/aviplay.c

    r3905 r4018  
    8585                  {PJMEDIA_FORMAT_H263 , "h263" , 
    8686                   PJ_FALSE, 0}, 
    87                   {PJMEDIA_FORMAT_XVID , "xvid"}, 
     87                  {PJMEDIA_FORMAT_MPEG4, "mp4v"},  
     88                  {PJMEDIA_FORMAT_H264 , "h264"} 
    8889                 }; 
    8990 
     
    270271            } 
    271272             
     273            pjmedia_format_copy(&codec_param.enc_fmt, &param.vidparam.fmt); 
     274 
    272275            pjmedia_vid_dev_get_info(param.vidparam.rend_id, &rdr_info); 
    273276            for (i=0; i<codec_info->dec_fmt_id_cnt; ++i) { 
     
    276279                    { 
    277280                        param.vidparam.fmt.id = codec_info->dec_fmt_id[i]; 
     281                        i = codec_info->dec_fmt_id_cnt; 
     282                        break; 
    278283                    } 
    279284                } 
     
    293298             
    294299            pjmedia_format_copy(&codec_param.dec_fmt, &param.vidparam.fmt); 
     300            codec_param.dir = PJMEDIA_DIR_DECODING; 
    295301            codec_param.packing = PJMEDIA_VID_PACKING_WHOLE; 
    296302            status = pjmedia_vid_codec_open(codec, &codec_param); 
Note: See TracChangeset for help on using the changeset viewer.