- Timestamp:
- Jul 30, 2015 6:23:35 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-videodev/android_dev.c
r5003 r5138 17 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 18 */ 19 #include "util.h" 19 20 #include <pjmedia-videodev/videodev_imp.h> 20 21 #include <pj/assert.h> … … 39 40 #define ALIGN16(x) ((((x)+15) >> 4) << 4) 40 41 42 /* Define whether we should maintain the aspect ratio when rotating the image. 43 * For more details, please refer to util.h. 44 */ 45 #define MAINTAIN_ASPECT_RATIO PJ_TRUE 41 46 42 47 /* Format map info */ … … 119 124 /** NV21/YV12 -> I420 Conversion buffer */ 120 125 pj_uint8_t *convert_buf; 126 pjmedia_rect_size cam_size; 127 128 /** Converter to rotate frame */ 129 pjmedia_vid_dev_conv conv; 121 130 122 131 /** Frame format param for NV21/YV12 -> I420 conversion */ … … 512 521 vdi->dir = PJMEDIA_DIR_CAPTURE; 513 522 vdi->has_callback = PJ_TRUE; 514 vdi->caps = PJMEDIA_VID_DEV_CAP_SWITCH; 523 vdi->caps = PJMEDIA_VID_DEV_CAP_SWITCH | 524 PJMEDIA_VID_DEV_CAP_ORIENTATION; 515 525 516 526 /* Set driver & name info */ … … 579 589 580 590 for (k = 0; k < adi->sup_size_cnt && 581 vdi->fmt_cnt < max_fmt_cnt ; k++)591 vdi->fmt_cnt < max_fmt_cnt-1; k++) 582 592 { 593 /* Landscape video */ 583 594 pjmedia_format_init_video(&vdi->fmt[vdi->fmt_cnt++], 584 595 fmt, 585 596 adi->sup_size[k].w, 586 597 adi->sup_size[k].h, 598 DEFAULT_FPS, 1); 599 /* Portrait video */ 600 pjmedia_format_init_video(&vdi->fmt[vdi->fmt_cnt++], 601 fmt, 602 adi->sup_size[k].h, 603 adi->sup_size[k].w, 587 604 DEFAULT_FPS, 1); 588 605 } … … 599 616 adi->forced_i420 = PJ_TRUE; 600 617 for (k = 0; k < adi->sup_size_cnt && 601 vdi->fmt_cnt < max_fmt_cnt ; k++)618 vdi->fmt_cnt < max_fmt_cnt-1; k++) 602 619 { 603 620 pjmedia_format_init_video(&vdi->fmt[vdi->fmt_cnt++], … … 605 622 adi->sup_size[k].w, 606 623 adi->sup_size[k].h, 624 DEFAULT_FPS, 1); 625 pjmedia_format_init_video(&vdi->fmt[vdi->fmt_cnt++], 626 PJMEDIA_FORMAT_I420, 627 adi->sup_size[k].h, 628 adi->sup_size[k].w, 607 629 DEFAULT_FPS, 1); 608 630 } … … 637 659 for (i = 0; i < f->dev_count; i++) { 638 660 and_dev_info *adi = &f->dev_info[i]; 639 char tmp_str[ 1024], *p;661 char tmp_str[2048], *p; 640 662 int j, plen, slen; 641 663 PJ_LOG(4, (THIS_FILE, "%2d: %s", i, f->dev_info[i].info.name)); … … 793 815 794 816 /* Instantiate PjCamera */ 817 strm->cam_size.w = (vfd->size.w > vfd->size.h? vfd->size.w: vfd->size.h); 818 strm->cam_size.h = (vfd->size.w > vfd->size.h? vfd->size.h: vfd->size.w); 795 819 jcam = (*jni_env)->NewObject(jni_env, jobjs.cam.cls, jobjs.cam.m_init, 796 820 adi->dev_idx, /* idx */ 797 vfd->size.w,/* w */798 vfd->size.h,/* h */821 strm->cam_size.w, /* w */ 822 strm->cam_size.h, /* h */ 799 823 and_fmt, /* fmt */ 800 824 vfd->fps.num*1000/ … … 814 838 status = PJMEDIA_EVID_SYSERR; 815 839 goto on_return; 840 } 841 842 /* Video orientation. 843 * If we send in portrait, we need to set up orientation converter 844 * as well. 845 */ 846 if ((param->flags & PJMEDIA_VID_DEV_CAP_ORIENTATION) || 847 (vfd->size.h > vfd->size.w)) 848 { 849 if (param->orient == PJMEDIA_ORIENT_UNKNOWN) 850 param->orient = PJMEDIA_ORIENT_NATURAL; 851 and_stream_set_cap(&strm->base, PJMEDIA_VID_DEV_CAP_ORIENTATION, 852 ¶m->orient); 816 853 } 817 854 … … 922 959 } 923 960 961 case PJMEDIA_VID_DEV_CAP_ORIENTATION: 962 { 963 pjmedia_orient orient = *(pjmedia_orient *)pval; 964 965 pj_assert(orient >= PJMEDIA_ORIENT_UNKNOWN && 966 orient <= PJMEDIA_ORIENT_ROTATE_270DEG); 967 968 if (orient == PJMEDIA_ORIENT_UNKNOWN) 969 return PJ_EINVAL; 970 971 pj_memcpy(&strm->param.orient, pval, 972 sizeof(strm->param.orient)); 973 974 if (!strm->conv.conv) { 975 status = pjmedia_vid_dev_conv_create_converter( 976 &strm->conv, strm->pool, 977 &strm->param.fmt, 978 strm->cam_size, 979 strm->param.fmt.det.vid.size, 980 PJ_TRUE, 981 MAINTAIN_ASPECT_RATIO); 982 983 if (status != PJ_SUCCESS) 984 return status; 985 } 986 987 pjmedia_vid_dev_conv_set_rotation(&strm->conv, strm->param.orient); 988 989 PJ_LOG(4, (THIS_FILE, "Video capture orientation set to %d", 990 strm->param.orient)); 991 992 break; 993 } 994 924 995 default: 925 996 status = PJMEDIA_EVID_INVCAP; … … 1006 1077 jni_detach_env(with_attach); 1007 1078 1079 pjmedia_vid_dev_conv_destroy_converter(&strm->conv); 1080 1008 1081 if (strm->pool) 1009 1082 pj_pool_release(strm->pool); … … 1021 1094 pjmedia_frame f; 1022 1095 pj_uint8_t *Y, *U, *V; 1096 pj_status_t status; 1097 void *frame_buf, *data_buf; 1023 1098 1024 1099 strm->frame_ts.u64 += strm->ts_inc; … … 1040 1115 f.size = length; 1041 1116 f.timestamp.u64 = strm->frame_ts.u64; 1042 f.buf = (*env)->GetByteArrayElements(env, data, 0);1117 f.buf = data_buf = (*env)->GetByteArrayElements(env, data, 0); 1043 1118 1044 1119 Y = (pj_uint8_t*)f.buf; … … 1116 1191 } 1117 1192 } 1193 1194 status = pjmedia_vid_dev_conv_resize_and_rotate(&strm->conv, 1195 f.buf, 1196 &frame_buf); 1197 if (status == PJ_SUCCESS) { 1198 f.buf = frame_buf; 1199 } 1118 1200 1119 1201 (*strm->vid_cb.capture_cb)(&strm->base, strm->user_data, &f); 1120 (*env)->ReleaseByteArrayElements(env, data, f.buf, JNI_ABORT);1202 (*env)->ReleaseByteArrayElements(env, data, data_buf, JNI_ABORT); 1121 1203 } 1122 1204
Note: See TracChangeset
for help on using the changeset viewer.