Index: pjproject/trunk/pjmedia/src/pjmedia/avi_player.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/avi_player.c	(revision 4017)
+++ pjproject/trunk/pjmedia/src/pjmedia/avi_player.c	(revision 4018)
@@ -92,4 +92,22 @@
 #endif
 
+typedef struct avi_fmt_info
+{
+    pjmedia_format_id   fmt_id;
+    pjmedia_format_id   eff_fmt_id;
+} avi_fmt_info;
+
+static avi_fmt_info avi_fmts[] =
+{
+    {PJMEDIA_FORMAT_MJPEG}, {PJMEDIA_FORMAT_H264},
+    {PJMEDIA_FORMAT_UYVY}, {PJMEDIA_FORMAT_YUY2},
+    {PJMEDIA_FORMAT_IYUV}, {PJMEDIA_FORMAT_I420},
+    {PJMEDIA_FORMAT_DIB}, {PJMEDIA_FORMAT_RGB24},
+    {PJMEDIA_FORMAT_RGB32},
+    {PJMEDIA_FORMAT_PACK('X','V','I','D'), PJMEDIA_FORMAT_MPEG4},
+    {PJMEDIA_FORMAT_PACK('x','v','i','d'), PJMEDIA_FORMAT_MPEG4},
+    {PJMEDIA_FORMAT_PACK('D','I','V','X'), PJMEDIA_FORMAT_MPEG4},
+};
+
 struct pjmedia_avi_streams
 {
@@ -347,20 +365,25 @@
                         PJMEDIA_AVI_VIDS_TAG))
         {
-            /* Check supported video formats here */
-            if (avi_hdr.strl_hdr[i].flags & AVISF_VIDEO_PALCHANGES ||
-                (avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_MJPEG &&
-                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_XVID &&
-                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_UYVY &&
-                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_YUY2 &&
-                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_IYUV &&
-                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_I420 &&
-                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_DIB &&
-                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_RGB24 &&
-                 avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_RGB32))
-            {
+            int j;
+
+            if (avi_hdr.strl_hdr[i].flags & AVISF_VIDEO_PALCHANGES) {
                 PJ_LOG(4, (THIS_FILE, "Unsupported video stream"));
                 continue;
             }
+
             fmt_id = avi_hdr.strl_hdr[i].codec;
+            for (j = sizeof(avi_fmts)/sizeof(avi_fmts[0])-1; j >= 0; j--) {
+                /* Check supported video formats here */
+                if (fmt_id == avi_fmts[j].fmt_id) {
+                    if (avi_fmts[j].eff_fmt_id)
+                        fmt_id = avi_fmts[j].eff_fmt_id;
+                    break;
+                }
+            }
+            
+            if (j < 0) {
+                PJ_LOG(4, (THIS_FILE, "Unsupported video stream"));
+                continue;
+            }
         } else {
             /* Check supported audio formats here */
@@ -380,30 +403,27 @@
         }
 
-        if (nstr == 0) {
-            fport[0]->stream_id = i;
-            nstr++;
-            continue;
-        }
-
-        /* Create fport instance. */
-        fport[nstr] = create_avi_port(pool);
-        if (!fport[nstr]) {
-	    status = PJ_ENOMEM;
-            goto on_error;
+        if (nstr > 0) {
+            /* Create fport instance. */
+            fport[nstr] = create_avi_port(pool);
+            if (!fport[nstr]) {
+	        status = PJ_ENOMEM;
+                goto on_error;
+            }
+
+            /* Open file. */
+            status = pj_file_open(pool, filename, PJ_O_RDONLY,
+                                  &fport[nstr]->fd);
+            if (status != PJ_SUCCESS)
+                goto on_error;
+
+            /* Set the file position */
+            status = pj_file_setpos(fport[nstr]->fd, pos, PJ_SEEK_SET);
+            if (status != PJ_SUCCESS) {
+                goto on_error;
+            }
         }
 
         fport[nstr]->stream_id = i;
         fport[nstr]->fmt_id = fmt_id;
-
-        /* Open file. */
-        status = pj_file_open(pool, filename, PJ_O_RDONLY, &fport[nstr]->fd);
-        if (status != PJ_SUCCESS)
-            goto on_error;
-
-        /* Set the file position */
-        status = pj_file_setpos(fport[nstr]->fd, pos, PJ_SEEK_SET);
-        if (status != PJ_SUCCESS) {
-            goto on_error;
-        }
 
         nstr++;
@@ -435,5 +455,5 @@
             fport[i]->bits_per_sample = (vfi ? vfi->bpp : 0);
             pjmedia_format_init_video(&fport[i]->base.info.fmt,
-                                      strl_hdr->codec,
+                                      fport[i]->fmt_id,
                                       strf_hdr->biWidth,
                                       strf_hdr->biHeight,
Index: pjproject/trunk/pjsip-apps/src/samples/aviplay.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/aviplay.c	(revision 4017)
+++ pjproject/trunk/pjsip-apps/src/samples/aviplay.c	(revision 4018)
@@ -85,5 +85,6 @@
                   {PJMEDIA_FORMAT_H263 , "h263" ,
                    PJ_FALSE, 0},
-		  {PJMEDIA_FORMAT_XVID , "xvid"},
+                  {PJMEDIA_FORMAT_MPEG4, "mp4v"}, 
+                  {PJMEDIA_FORMAT_H264 , "h264"}
                  };
 
@@ -270,4 +271,6 @@
             }
 	    
+            pjmedia_format_copy(&codec_param.enc_fmt, &param.vidparam.fmt);
+
             pjmedia_vid_dev_get_info(param.vidparam.rend_id, &rdr_info);
             for (i=0; i<codec_info->dec_fmt_id_cnt; ++i) {
@@ -276,4 +279,6 @@
                     {
                         param.vidparam.fmt.id = codec_info->dec_fmt_id[i];
+                        i = codec_info->dec_fmt_id_cnt;
+                        break;
                     }
                 }
@@ -293,4 +298,5 @@
 	    
             pjmedia_format_copy(&codec_param.dec_fmt, &param.vidparam.fmt);
+            codec_param.dir = PJMEDIA_DIR_DECODING;
             codec_param.packing = PJMEDIA_VID_PACKING_WHOLE;
             status = pjmedia_vid_codec_open(codec, &codec_param);
