Changeset 5102 for pjproject/trunk
- Timestamp:
- May 28, 2015 7:14:24 AM (10 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/swig/java/android/res/layout/activity_call.xml
r4997 r5102 24 24 android:gravity="center" 25 25 android:text="Call state" /> 26 27 <Button 28 android:id="@+id/buttonAccept" 26 27 <LinearLayout 29 28 android:layout_width="match_parent" 30 29 android:layout_height="wrap_content" 31 android:onClick="acceptCall" 32 android:text="Accept" /> 33 34 <Button 35 android:id="@+id/buttonHangup" 36 android:layout_width="match_parent" 37 android:layout_height="wrap_content" 38 android:onClick="hangupCall" 39 android:text="Reject" /> 40 30 android:orientation="horizontal"> 31 32 <LinearLayout 33 android:layout_width="0dp" 34 android:layout_height="wrap_content" 35 android:orientation="vertical" 36 android:layout_weight=".50"> 37 38 <Button 39 android:id="@+id/buttonAccept" 40 android:layout_width="match_parent" 41 android:layout_height="wrap_content" 42 android:onClick="acceptCall" 43 android:text="Accept" /> 44 45 <Button 46 android:id="@+id/buttonHangup" 47 android:layout_width="match_parent" 48 android:layout_height="wrap_content" 49 android:onClick="hangupCall" 50 android:text="Reject" /> 51 52 <Button 53 android:id="@+id/buttonShowPreview" 54 android:layout_width="match_parent" 55 android:layout_height="wrap_content" 56 android:onClick="showPreview" 57 android:text="@+string/show_preview" /> 58 59 </LinearLayout> 60 <SurfaceView 61 android:id="@+id/surfacePreviewCapture" 62 android:layout_width="0dp" 63 android:layout_height="match_parent" 64 android:layout_weight=".50" /> 65 66 </LinearLayout> 67 41 68 <SurfaceView 42 43 44 45 69 android:id="@+id/surfaceIncomingVideo" 70 android:layout_width="match_parent" 71 android:layout_height="match_parent" /> 72 46 73 </LinearLayout> -
pjproject/trunk/pjsip-apps/src/swig/java/android/res/values/strings.xml
r4704 r5102 6 6 <string name="title_activity_call">Call</string> 7 7 <string name="hello_world">Hello world!</string> 8 8 <string name="show_preview">Show Preview</string> 9 <string name="hide_preview">Hide Preview</string> 9 10 </resources> -
pjproject/trunk/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/CallActivity.java
r5017 r5102 31 31 import org.pjsip.pjsua2.*; 32 32 33 class VideoPreviewHandler implements SurfaceHolder.Callback 34 { 35 public boolean videoPreviewActive = false; 36 37 public void updateVideoPreview(SurfaceHolder holder) 38 { 39 if (MainActivity.currentCall != null && 40 MainActivity.currentCall.vidWin != null && 41 MainActivity.currentCall.vidPrev != null) 42 { 43 if (videoPreviewActive) { 44 VideoWindowHandle vidWH = new VideoWindowHandle(); 45 vidWH.getHandle().setWindow(holder.getSurface()); 46 VideoPreviewOpParam vidPrevParam = new VideoPreviewOpParam(); 47 vidPrevParam.setWindow(vidWH); 48 try { 49 MainActivity.currentCall.vidPrev.start(vidPrevParam); 50 } catch (Exception e) { 51 System.out.println(e); 52 } 53 } else { 54 try { 55 MainActivity.currentCall.vidPrev.stop(); 56 } catch (Exception e) { 57 System.out.println(e); 58 } 59 } 60 } 61 } 62 63 @Override 64 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) 65 { 66 updateVideoPreview(holder); 67 } 68 69 @Override 70 public void surfaceCreated(SurfaceHolder holder) 71 { 72 73 } 74 75 @Override 76 public void surfaceDestroyed(SurfaceHolder holder) 77 { 78 try { 79 MainActivity.currentCall.vidPrev.stop(); 80 } catch (Exception e) { 81 System.out.println(e); 82 } 83 } 84 } 85 33 86 public class CallActivity extends Activity 34 87 implements Handler.Callback, SurfaceHolder.Callback … … 36 89 37 90 public static Handler handler_; 91 private static VideoPreviewHandler previewHandler = 92 new VideoPreviewHandler(); 38 93 39 94 private final Handler handler = new Handler(this); … … 46 101 setContentView(R.layout.activity_call); 47 102 48 SurfaceView surface View= (SurfaceView)103 SurfaceView surfaceInVideo = (SurfaceView) 49 104 findViewById(R.id.surfaceIncomingVideo); 105 SurfaceView surfacePreview = (SurfaceView) 106 findViewById(R.id.surfacePreviewCapture); 107 Button buttonShowPreview = (Button) 108 findViewById(R.id.buttonShowPreview); 109 50 110 if (MainActivity.currentCall == null || 51 111 MainActivity.currentCall.vidWin == null) 52 112 { 53 surfaceView.setVisibility(View.GONE); 54 } 55 surfaceView.getHolder().addCallback(this); 113 surfaceInVideo.setVisibility(View.GONE); 114 buttonShowPreview.setVisibility(View.GONE); 115 } 116 setupVideoPreview(surfacePreview, buttonShowPreview); 117 surfaceInVideo.getHolder().addCallback(this); 118 surfacePreview.getHolder().addCallback(previewHandler); 56 119 57 120 handler_ = handler; … … 74 137 handler_ = null; 75 138 } 76 77 private void updateVideoWindow( SurfaceHolder holder)78 { 139 140 private void updateVideoWindow(boolean show) 141 { 79 142 if (MainActivity.currentCall != null && 80 MainActivity.currentCall.vidWin != null) 143 MainActivity.currentCall.vidWin != null && 144 MainActivity.currentCall.vidPrev != null) 81 145 { 82 VideoWindowHandle vidWH = new VideoWindowHandle(); 83 if (holder == null) 146 SurfaceView surfaceInVideo = (SurfaceView) 147 findViewById(R.id.surfaceIncomingVideo); 148 149 VideoWindowHandle vidWH = new VideoWindowHandle(); 150 if (show) { 151 vidWH.getHandle().setWindow( 152 surfaceInVideo.getHolder().getSurface()); 153 } else { 84 154 vidWH.getHandle().setWindow(null); 85 else 86 vidWH.getHandle().setWindow(holder.getSurface()); 155 } 87 156 try { 88 157 MainActivity.currentCall.vidWin.setWindow(vidWH); 89 } catch (Exception e) {} 90 } 91 } 92 158 } catch (Exception e) { 159 System.out.println(e); 160 } 161 } 162 } 163 93 164 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) 94 165 { 95 updateVideoWindow( holder);166 updateVideoWindow(true); 96 167 } 97 168 … … 102 173 public void surfaceDestroyed(SurfaceHolder holder) 103 174 { 104 updateVideoWindow( null);175 updateVideoWindow(false); 105 176 } 106 177 … … 133 204 } 134 205 } 206 207 public void setupVideoPreview(SurfaceView surfacePreview, 208 Button buttonShowPreview) 209 { 210 surfacePreview.setVisibility(previewHandler.videoPreviewActive? 211 View.VISIBLE:View.GONE); 212 213 buttonShowPreview.setText(previewHandler.videoPreviewActive? 214 getString(R.string.hide_preview): 215 getString(R.string.show_preview)); 216 } 217 218 public void showPreview(View view) 219 { 220 SurfaceView surfacePreview = (SurfaceView) 221 findViewById(R.id.surfacePreviewCapture); 222 223 Button buttonShowPreview = (Button) 224 findViewById(R.id.buttonShowPreview); 225 226 227 previewHandler.videoPreviewActive = !previewHandler.videoPreviewActive; 228 229 setupVideoPreview(surfacePreview, buttonShowPreview); 230 231 previewHandler.updateVideoPreview(surfacePreview.getHolder()); 232 } 135 233 136 234 private void setupVideoSurface() 137 235 { 138 SurfaceView surface View= (SurfaceView)236 SurfaceView surfaceInVideo = (SurfaceView) 139 237 findViewById(R.id.surfaceIncomingVideo); 140 surfaceView.setVisibility(View.VISIBLE); 141 updateVideoWindow(surfaceView.getHolder()); 238 SurfaceView surfacePreview = (SurfaceView) 239 findViewById(R.id.surfacePreviewCapture); 240 Button buttonShowPreview = (Button) 241 findViewById(R.id.buttonShowPreview); 242 surfaceInVideo.setVisibility(View.VISIBLE); 243 buttonShowPreview.setVisibility(View.VISIBLE); 244 surfacePreview.setVisibility(View.GONE); 142 245 } 143 246 -
pjproject/trunk/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/MyApp.java
r5022 r5102 50 50 { 51 51 public VideoWindow vidWin; 52 public VideoPreview vidPrev; 52 53 53 54 MyCall(MyAccount acc, int call_id) … … 113 114 { 114 115 vidWin = new VideoWindow(cmi.getVideoIncomingWindowId()); 116 vidPrev = new VideoPreview(cmi.getVideoCapDev()); 115 117 } 116 118 } -
pjproject/trunk/pjsip/include/pjsua2/media.hpp
r4996 r5102 1489 1489 }; 1490 1490 1491 /** 1492 * This structure contains parameters for VideoPreview::start() 1493 */ 1494 struct VideoPreviewOpParam { 1495 /** 1496 * Device ID for the video renderer to be used for rendering the 1497 * capture stream for preview. This parameter is ignored if native 1498 * preview is being used. 1499 * 1500 * Default: PJMEDIA_VID_DEFAULT_RENDER_DEV 1501 */ 1502 pjmedia_vid_dev_index rendId; 1503 1504 /** 1505 * Show window initially. 1506 * 1507 * Default: PJ_TRUE. 1508 */ 1509 bool show; 1510 1511 /** 1512 * Window flags. The value is a bitmask combination of 1513 * \a pjmedia_vid_dev_wnd_flag. 1514 * 1515 * Default: 0. 1516 */ 1517 unsigned windowFlags; 1518 1519 /** 1520 * Media format. If left unitialized, this parameter will not be used. 1521 */ 1522 MediaFormat format; 1523 1524 /** 1525 * Optional output window to be used to display the video preview. 1526 * This parameter will only be used if the video device supports 1527 * PJMEDIA_VID_DEV_CAP_OUTPUT_WINDOW capability and the capability 1528 * is not read-only. 1529 */ 1530 VideoWindowHandle window; 1531 1532 public: 1533 /** 1534 * Default constructor initializes with default values. 1535 */ 1536 VideoPreviewOpParam(); 1537 1538 /** 1539 * Convert from pjsip 1540 */ 1541 void fromPj(const pjsua_vid_preview_param &prm); 1542 1543 /** 1544 * Convert to pjsip 1545 */ 1546 pjsua_vid_preview_param toPj() const; 1547 }; 1548 1549 /** 1550 * Video Preview 1551 */ 1552 class VideoPreview { 1553 public: 1554 /** 1555 * Constructor 1556 */ 1557 VideoPreview(int dev_id); 1558 1559 /** 1560 * Determine if the specified video input device has built-in native 1561 * preview capability. This is a convenience function that is equal to 1562 * querying device's capability for PJMEDIA_VID_DEV_CAP_INPUT_PREVIEW 1563 * capability. 1564 * 1565 * @return true if it has. 1566 */ 1567 bool hasNative(); 1568 1569 /** 1570 * Start video preview window for the specified capture device. 1571 * 1572 * @param p Video preview parameters. 1573 */ 1574 void start(const VideoPreviewOpParam ¶m) throw(Error); 1575 1576 /** 1577 * Stop video preview. 1578 */ 1579 void stop() throw(Error); 1580 1581 /* 1582 * Get the preview window handle associated with the capture device,if any. 1583 */ 1584 VideoWindow getVideoWindow(); 1585 1586 private: 1587 pjmedia_vid_dev_index devId; 1588 }; 1589 1491 1590 /************************************************************************* 1492 1591 * Codec management -
pjproject/trunk/pjsip/src/pjsua2/media.cpp
r5045 r5102 1094 1094 #endif 1095 1095 } 1096 /////////////////////////////////////////////////////////////////////////////// 1097 1098 VideoPreviewOpParam::VideoPreviewOpParam() 1099 { 1100 #if PJSUA_HAS_VIDEO 1101 pjsua_vid_preview_param vid_prev_param; 1102 1103 pjsua_vid_preview_param_default(&vid_prev_param); 1104 fromPj(vid_prev_param); 1105 #endif 1106 } 1107 1108 void VideoPreviewOpParam::fromPj(const pjsua_vid_preview_param &prm) 1109 { 1110 #if PJSUA_HAS_VIDEO 1111 this->rendId = prm.rend_id; 1112 this->show = PJ2BOOL(prm.show); 1113 this->windowFlags = prm.wnd_flags; 1114 this->format.id = prm.format.id; 1115 this->format.type = prm.format.type; 1116 this->window.type = prm.wnd.type; 1117 this->window.handle.window = prm.wnd.info.window; 1118 #else 1119 PJ_UNUSED_ARG(prm); 1120 #endif 1121 } 1122 1123 pjsua_vid_preview_param VideoPreviewOpParam::toPj() const 1124 { 1125 pjsua_vid_preview_param param; 1126 #if PJSUA_HAS_VIDEO 1127 param.rend_id = this->rendId; 1128 param.show = this->show; 1129 param.wnd_flags = this->windowFlags; 1130 param.format.id = this->format.id; 1131 param.format.type = this->format.type; 1132 param.wnd.type = this->window.type; 1133 param.wnd.info.window = this->window.handle.window; 1134 #endif 1135 return param; 1136 } 1137 1138 VideoPreview::VideoPreview(int dev_id) 1139 : devId(dev_id) 1140 { 1141 1142 } 1143 1144 bool VideoPreview::hasNative() 1145 { 1146 #if PJSUA_HAS_VIDEO 1147 return(PJ2BOOL(pjsua_vid_preview_has_native(devId))); 1148 #else 1149 return false; 1150 #endif 1151 } 1152 1153 void VideoPreview::start(const VideoPreviewOpParam ¶m) throw(Error) 1154 { 1155 #if PJSUA_HAS_VIDEO 1156 pjsua_vid_preview_param prm = param.toPj(); 1157 PJSUA2_CHECK_EXPR(pjsua_vid_preview_start(devId, &prm)); 1158 #else 1159 PJ_UNUSED_ARG(param); 1160 #endif 1161 } 1162 1163 void VideoPreview::stop() throw(Error) 1164 { 1165 #if PJSUA_HAS_VIDEO 1166 pjsua_vid_preview_stop(devId); 1167 #endif 1168 } 1169 1170 VideoWindow VideoPreview::getVideoWindow() 1171 { 1172 #if PJSUA_HAS_VIDEO 1173 return (VideoWindow(pjsua_vid_preview_get_win(devId))); 1174 #else 1175 return (VideoWindow(PJSUA_INVALID_ID)); 1176 #endif 1177 } 1096 1178 1097 1179 ///////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.