summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiong Sauw Ming <ming@teluu.com>2012-04-04 05:45:46 +0000
committerLiong Sauw Ming <ming@teluu.com>2012-04-04 05:45:46 +0000
commit114fdc2a6e970673f50a6f567f758a8354ecde59 (patch)
tree5129227de7f8366770dd1f4fd7ed9e2f10c8c5fc
parent9ca48204cb8cce4241f3515b2980cafb34c2fbcf (diff)
Misc (Re #1446): Add support for aviplay to play H264 and MPEG4 decoded AVI videos. This includes support for XVID and DIVX MPEG4.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4018 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjmedia/src/pjmedia/avi_player.c88
-rw-r--r--pjsip-apps/src/samples/aviplay.c8
2 files changed, 61 insertions, 35 deletions
diff --git a/pjmedia/src/pjmedia/avi_player.c b/pjmedia/src/pjmedia/avi_player.c
index 2d86153e..aa8ca18b 100644
--- a/pjmedia/src/pjmedia/avi_player.c
+++ b/pjmedia/src/pjmedia/avi_player.c
@@ -91,6 +91,24 @@
# define data_to_host2(data, nsizes, sizes)
#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
{
unsigned num_streams;
@@ -346,22 +364,27 @@ pjmedia_avi_player_create_streams(pj_pool_t *pool,
if (COMPARE_TAG(avi_hdr.strl_hdr[i].data_type,
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 */
if ((avi_hdr.strl_hdr[i].codec != PJMEDIA_FORMAT_PCM &&
@@ -379,33 +402,30 @@ pjmedia_avi_player_create_streams(pj_pool_t *pool,
fmt_id = PJMEDIA_FORMAT_PCM;
}
- if (nstr == 0) {
- fport[0]->stream_id = i;
- nstr++;
- continue;
- }
+ if (nstr > 0) {
+ /* Create fport instance. */
+ fport[nstr] = create_avi_port(pool);
+ if (!fport[nstr]) {
+ status = PJ_ENOMEM;
+ goto on_error;
+ }
- /* 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++;
}
@@ -434,7 +454,7 @@ pjmedia_avi_player_create_streams(pj_pool_t *pool,
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,
strl_hdr->rate,
diff --git a/pjsip-apps/src/samples/aviplay.c b/pjsip-apps/src/samples/aviplay.c
index 03fbe800..98b0bb13 100644
--- a/pjsip-apps/src/samples/aviplay.c
+++ b/pjsip-apps/src/samples/aviplay.c
@@ -84,7 +84,8 @@ struct codec_fmt {
PJ_TRUE , PJMEDIA_FORMAT_I420},
{PJMEDIA_FORMAT_H263 , "h263" ,
PJ_FALSE, 0},
- {PJMEDIA_FORMAT_XVID , "xvid"},
+ {PJMEDIA_FORMAT_MPEG4, "mp4v"},
+ {PJMEDIA_FORMAT_H264 , "h264"}
};
typedef struct avi_port_t
@@ -269,12 +270,16 @@ static int aviplay(pj_pool_t *pool, const char *fname)
rc = 246; goto on_return;
}
+ 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) {
for (k=0; k<rdr_info.fmt_cnt; ++k) {
if (codec_info->dec_fmt_id[i]==(int)rdr_info.fmt[k].id)
{
param.vidparam.fmt.id = codec_info->dec_fmt_id[i];
+ i = codec_info->dec_fmt_id_cnt;
+ break;
}
}
}
@@ -292,6 +297,7 @@ static int aviplay(pj_pool_t *pool, const char *fname)
}
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);
if (status != PJ_SUCCESS) {