Changeset 1925
- Timestamp:
- Oct 18, 2010, 7:35:40 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/Makefile.in
r1920 r1925 114 114 $(srcdir)/utils.tcl \ 115 115 $(srcdir)/valueresult.tcl \ 116 $(srcdir)/videodial.tcl \ 117 $(srcdir)/videoscreen.tcl \ 116 118 $(srcdir)/videoviewer.tcl \ 117 119 $(srcdir)/videoparticle.tcl \ -
trunk/gui/scripts/filexfer.tcl
r1756 r1925 91 91 } 92 92 } 93 uploadWord { 94 if {[Rappture::filexfer::enabled]} { 95 return "Upload" 96 } else { 97 return "Browse" 98 } 99 } 93 100 download { 94 101 if {[Rappture::filexfer::enabled]} { … … 106 113 } 107 114 default { 108 error "bad option \"$operation\": should be upload, download, or downloadWord"115 error "bad option \"$operation\": should be upload, uploadWord, download, or downloadWord" 109 116 } 110 117 } -
trunk/gui/scripts/videoviewer.tcl
r1916 r1925 16 16 package require RapptureGUI 17 17 18 option add *VideoViewer.width 5i widgetDefault18 #option add *VideoViewer.width 5i widgetDefault 19 19 option add *VideoViewer*cursor crosshair widgetDefault 20 option add *VideoViewer.height 4i widgetDefault20 #option add *VideoViewer.height 4i widgetDefault 21 21 option add *VideoViewer.foreground black widgetDefault 22 22 option add *VideoViewer.controlBackground gray widgetDefault … … 34 34 itk_option define -plotbackground plotBackground Background "" 35 35 itk_option define -plotoutline plotOutline PlotOutline "" 36 itk_option define -width width Width -1 37 itk_option define -height height Height -1 38 itk_option define -controls controls Controls "show" 36 39 37 40 constructor { args } { … … 44 47 public method load {filename} 45 48 public method video {args} 49 public method query {type} 46 50 47 51 protected method togglePtrBind {pbvar} … … 58 62 protected method updateMeasurements {} 59 63 protected method calculateTrajectory {args} 64 protected method fixSize {} 65 66 60 67 61 68 private common _settings 62 69 63 private variable _width 0 64 private variable _height 0 70 private variable _width -1 71 private variable _height -1 72 private variable _controls "" 65 73 private variable _x0 0 ;# start x for rubberbanding 66 74 private variable _y0 0 ;# start y for rubberbanding … … 399 407 # ---------------------------------------------------------------------- 400 408 itcl::body Rappture::VideoViewer::load {filename} { 401 set _movie [Rappture::Video $filename] 409 410 # open the file 411 412 set _movie [Rappture::Video "file" $filename] 402 413 set _framerate [${_movie} get framerate] 403 414 set _mspf [expr round(((1.0/${_framerate})*1000)/pow(2,[$itk_component(speed) value]-1))] 404 # set _mspf 7405 415 puts "framerate = ${_framerate}" 406 416 puts "mspf = ${_mspf}" 407 417 418 ${_movie} seek 0 419 420 # setup the image display 421 408 422 set _imh [image create photo] 409 $_imh put [$_movie next] 423 foreach {w h} [query dimensions] break 424 if {${_width} == -1} { 425 set _width $w 426 } 427 if {${_height} == -1} { 428 set _height $h 429 } 430 # ${_imh} put [$_movie get image ${_width} ${_height}] 410 431 $itk_component(main) create image 0 0 -anchor nw -image $_imh 432 433 # setup timings for playing video 411 434 412 435 set _lastFrame [$_movie get position end] … … 424 447 $itk_component(framenum) configure -max ${_lastFrame} -width $cnt 425 448 426 set pch [$itk_component(pointercontrols) cget -height] 427 set mch [$itk_component(moviecontrols) cget -height] 428 set pch 30 429 set mch 30 449 fixSize 450 } 451 452 # ---------------------------------------------------------------------- 453 # fixSize 454 # ---------------------------------------------------------------------- 455 itcl::body Rappture::VideoViewer::fixSize {} { 456 457 if {[string compare "" ${_movie}] == 0} { 458 return 459 } 460 461 # get an image with the new size 462 ${_imh} put [${_movie} get image ${_width} ${_height}] 463 464 # fix the dimesions of the canvas 465 $itk_component(main) configure -width ${_width} -height ${_height} 466 430 467 $itk_component(main) configure -scrollregion [$itk_component(main) bbox all] 431 foreach { x0 y0 x1 y1 } [$itk_component(main) bbox all] break 432 set w [expr abs($x1-$x0)] 433 set h [expr abs($y1-$y0+$pch+$mch)] 434 # $itk_component(main) configure -width $w -height $h 435 .main configure -width $w -height $h 436 468 #foreach { x0 y0 x1 y1 } [$itk_component(main) bbox all] break 469 #set w [expr abs($x1-$x0)] 470 #set h [expr abs($y1-$y0)] 471 #$itk_component(main) configure -width $w -height $h 472 # component hull configure -width $w -height $h 437 473 } 438 474 … … 483 519 484 520 # ---------------------------------------------------------------------- 521 # query - query things about the video 522 # ---------------------------------------------------------------------- 523 itcl::body Rappture::VideoViewer::query { type } { 524 set ret "" 525 switch -- $type { 526 "dimensions" { 527 set ret [${_movie} size] 528 } 529 default { 530 error "bad type \"$type\": should be dimensions." 531 } 532 } 533 return $ret 534 } 535 536 # ---------------------------------------------------------------------- 485 537 # togglePtrCtrl - choose pointer mode: 486 538 # rectangle, distance, measure, particlemark … … 617 669 618 670 # display the next frame 619 $_imh put [$_movie next] 671 $_movie next 672 $_imh put [$_movie get image ${_width} ${_height}] 620 673 621 674 # update the dial and framenum widgets … … 670 723 error "bad value: \"$val\": should be \"seek \[-percent\] value\"" 671 724 } 672 $_imh put [$_movie seek $val] 673 set cur [$_movie get position cur] 725 ${_movie} seek $val 726 ${_imh} put [${_movie} get image ${_width} ${_height}] 727 set cur [${_movie} get position cur] 674 728 set _settings($this-currenttime) [expr double($cur) / double(${_lastFrame})] 675 729 } … … 1006 1060 } 1007 1061 1062 # ---------------------------------------------------------------------- 1063 # OPTION: -width 1064 # ---------------------------------------------------------------------- 1065 itcl::configbody Rappture::VideoViewer::width { 1066 # $_dispatcher event -idle !fixsize 1067 if {[string is integer $itk_option(-width)] == 0} { 1068 error "bad value: \"$itk_option(-width)\": width should be an integer" 1069 } 1070 set _width $itk_option(-width) 1071 after idle [itcl::code $this fixSize] 1072 } 1073 1074 # ---------------------------------------------------------------------- 1075 # OPTION: -height 1076 # ---------------------------------------------------------------------- 1077 itcl::configbody Rappture::VideoViewer::height { 1078 # $_dispatcher event -idle !fixsize 1079 if {[string is integer $itk_option(-height)] == 0} { 1080 error "bad value: \"$itk_option(-height)\": height should be an integer" 1081 } 1082 set _height $itk_option(-height) 1083 after idle [itcl::code $this fixSize] 1084 } 1085 1086 # ---------------------------------------------------------------------- 1087 # OPTION: -controls 1088 # ---------------------------------------------------------------------- 1089 itcl::configbody Rappture::VideoViewer::controls { 1090 switch $itk_option(-controls) { 1091 show { 1092 } 1093 hide { 1094 } 1095 default { 1096 error "bad value: \"$itk_option(-height)\": height should be an integer" 1097 } 1098 } 1099 set _height $itk_option(-height) 1100 after idle [itcl::code $this fixSize] 1101 } 1102 -
trunk/lang/tcl/src/RpVideoTclInterface.cc
r1916 r1925 26 26 static Tcl_ObjCmdProc NextOp; 27 27 static Tcl_ObjCmdProc SeekOp; 28 static Tcl_ObjCmdProc SizeOp; 28 29 static Tcl_ObjCmdProc ReleaseOp; 29 30 30 31 static Rp_OpSpec rpVideoOps[] = { 31 {"get", 1, (void *)GetOp, 3, 5, "[image width height]|[position cur|end]|[framerate]",},32 {"get", 1, (void *)GetOp, 3, 5, "[image ?width height?]|[position cur|end]|[framerate]",}, 32 33 {"next", 1, (void *)NextOp, 2, 2, "",}, 33 34 {"seek", 1, (void *)SeekOp, 3, 3, "+n|-n|n",}, 35 {"size", 1, (void *)SizeOp, 2, 2, "",}, 34 36 {"release", 1, (void *)ReleaseOp, 2, 2, "",}, 35 37 }; … … 56 58 57 59 /* 58 * USAGE: Video < file>60 * USAGE: Video <type> <data> 59 61 */ 60 62 static int … … 64 66 char cmdName[64]; 65 67 static int movieCount = 0; 66 const char *filename = Tcl_GetString(objv[1]); 68 const char *type = NULL; 69 const char *data = NULL; 70 int err = 0; 71 72 if (objc != 3) { 73 Tcl_AppendResult(interp, "wrong # args: should be \"", 74 "Video <type> <data>\"", (char*)NULL); 75 return TCL_ERROR; 76 } 77 78 type = Tcl_GetString(objv[1]); 79 data = Tcl_GetString(objv[2]); 67 80 68 81 // create a new command … … 74 87 return TCL_ERROR; 75 88 } 76 VideoOpenFile(movie,filename,"r"); 89 90 if ((*type == 'd') && (strcmp(type,"data") == 0)) { 91 Tcl_AppendResult(interp, "error while creating movie: type == data not supported", 92 "\n", "VideoInitCmd(movie);", (char*)NULL); 93 return TCL_ERROR; 94 } else if ((*type == 'f') && (strcmp(type,"file") == 0)) { 95 err = VideoOpenFile(movie,data,"r"); 96 if (err) { 97 Tcl_AppendResult(interp, "error while creating movie object: ", 98 "\n", "VideoInitCmd(movie);", (char*)NULL); 99 return TCL_ERROR; 100 } 101 } 77 102 78 103 sprintf(cmdName,"::movieObj%d",movieCount); 104 movieCount++; 79 105 80 106 Tcl_CreateObjCommand(interp, cmdName, VideoCallCmd, … … 109 135 * get position cur 110 136 * get position end 111 * get image width height137 * get image ?width height? 112 138 * get framerate 113 139 * … … 153 179 } 154 180 else if ((*info == 'i') && (strcmp(info,"image") == 0)) { 155 if ( objc != 5) {181 if ((objc != 3) && (objc != 5)) { 156 182 Tcl_AppendResult(interp, "wrong # args: should be \"", cmd, 157 " image width height\"", (char*)NULL);183 " image ?width height?\"", (char*)NULL); 158 184 return TCL_ERROR; 159 185 } 160 186 161 187 void *img = NULL; 162 int width = 0;163 int height = 0;188 int width = -1; 189 int height = -1; 164 190 int bufSize = 0; 165 191 166 Tcl_GetIntFromObj(interp, objv[3], &width); 167 Tcl_GetIntFromObj(interp, objv[4], &height); 168 169 // VideoGoNext((VideoObj *)clientData); 192 if (objc == 5) { 193 Tcl_GetIntFromObj(interp, objv[3], &width); 194 Tcl_GetIntFromObj(interp, objv[4], &height); 195 } 196 170 197 VideoGetImage((VideoObj *)clientData, width, height, &img, &bufSize); 171 198 … … 181 208 182 209 double fr = 0; 183 184 VideoGetFrameRate((VideoObj *)clientData, &fr); 210 int err = 0; 211 212 err = VideoGetFrameRate((VideoObj *)clientData, &fr); 213 if (err) { 214 Tcl_AppendResult(interp, "error while calculating framerate", 215 (char*)NULL); 216 return TCL_ERROR; 217 } 185 218 Tcl_SetObjResult(interp, Tcl_NewDoubleObj(fr)); 186 219 } … … 211 244 { 212 245 213 void *img = NULL; 214 int width = 960; 215 int height = 540; 216 int bufSize = 0; 217 246 // void *img = NULL; 247 // int width = 960; 248 // int height = 540; 249 // int bufSize = 0; 250 251 int pos = 0; 218 252 VideoGoNext((VideoObj *)clientData); 219 VideoGetImage((VideoObj *)clientData, width, height, &img, &bufSize); 220 221 Tcl_SetByteArrayObj(Tcl_GetObjResult(interp), 222 (const unsigned char*)img, bufSize); 253 VideoGetPositionCur((VideoObj *)clientData,&pos); 254 Tcl_SetObjResult(interp, Tcl_NewIntObj(pos)); 255 // VideoGetImage((VideoObj *)clientData, width, height, &img, &bufSize); 256 257 // Tcl_SetByteArrayObj(Tcl_GetObjResult(interp), 258 // (const unsigned char*)img, bufSize); 223 259 224 260 return TCL_OK; … … 242 278 { 243 279 244 void *img = NULL;245 int width = 960;246 int height = 540;247 int bufSize = 0;280 // void *img = NULL; 281 // int width = 960; 282 // int height = 540; 283 // int bufSize = 0; 248 284 const char *val_s = NULL; 249 285 int val = 0; 286 int pos = 0; 250 287 251 288 val_s = Tcl_GetString(objv[2]); … … 277 314 } 278 315 279 VideoGetImage((VideoObj *)clientData, width, height, &img, &bufSize); 280 281 if (img == NULL) { 282 printf("img is null\n"); 283 } 284 285 Tcl_SetByteArrayObj(Tcl_GetObjResult(interp), 286 (const unsigned char*)img, bufSize); 316 // VideoGetImage((VideoObj *)clientData, width, height, &img, &bufSize); 317 318 // if (img == NULL) { 319 // printf("img is null\n"); 320 // } 321 322 // Tcl_SetByteArrayObj(Tcl_GetObjResult(interp), 323 // (const unsigned char*)img, bufSize); 324 325 VideoGetPositionCur((VideoObj *)clientData,&pos); 326 Tcl_SetObjResult(interp, Tcl_NewIntObj(pos)); 327 328 return TCL_OK; 329 } 330 331 /**********************************************************************/ 332 // FUNCTION: SizeOp() 333 /// Get the size of the video 334 /** 335 * Return the original size of the video frame 336 * 337 * Full function call: 338 * 339 * size 340 * 341 */ 342 static int 343 SizeOp (ClientData clientData, Tcl_Interp *interp, int objc, 344 Tcl_Obj *const *objv) 345 { 346 347 int width = 0; 348 int height = 0; 349 int err = 0; 350 Tcl_Obj *dim = NULL; 351 352 353 err = VideoSizeCmd((VideoObj *)clientData,&width,&height); 354 355 if (err) { 356 Tcl_AppendResult(interp, "error while calculating size of video", 357 (char*)NULL); 358 return TCL_ERROR; 359 } 360 361 362 dim = Tcl_NewListObj(0, NULL); 363 Tcl_ListObjAppendElement(interp, dim, Tcl_NewIntObj(width)); 364 Tcl_ListObjAppendElement(interp, dim, Tcl_NewIntObj(height)); 365 Tcl_SetObjResult(interp, dim); 287 366 288 367 return TCL_OK; -
trunk/src/objects/RpVideo.c
r1916 r1925 140 140 { 141 141 int fnlen = 0; 142 int err = 0; 142 143 143 144 if (fileName == NULL) { … … 161 162 } 162 163 strncpy(vidPtr->fileName,fileName,fnlen); 164 vidPtr->fileName[fnlen] = '\0'; 163 165 164 166 // FIXME: remove this constraint when we support … … 170 172 if (*mode == 'r') { 171 173 /* we're now in "input" mode */ 172 VideoModeRead(vidPtr); 174 err = VideoModeRead(vidPtr); 175 if (err) { 176 return err; 177 } 173 178 } else if (*mode == 'w') { 174 179 /* we're now in "input" mode */ … … 195 200 * Returns TCL_OK if successful, and TCL_ERROR if there is a problem 196 201 * opening or closing the stream. 202 * 203 * Error Codes 204 * -1 205 * -2 missing file name 206 * -3 couldn't open file 207 * -4 couldn't find streams in file 208 * -5 couldn't find video stream in file 209 * -6 unsupported codec for file 210 * -7 couldn't open codec for file 211 * -8 couldn't allocate frame space 212 * -9 strcpy input to vidPtr->mode failed 197 213 * ------------------------------------------------------------------------ 198 214 */ … … 213 229 // Tcl_AppendResult(interp, "missing value for -file", (char*)NULL); 214 230 // return TCL_ERROR; 215 return -1; 231 232 // missing file name 233 return -2; 216 234 } 217 235 if (*vidPtr->fileName == '\0') { … … 236 254 // fileName, "\"", (char*)NULL); 237 255 // return TCL_ERROR; 238 return -1; 256 257 // couldn't open file 258 return -3; 239 259 } 240 260 if (av_find_stream_info(vidPtr->pFormatCtx) < 0) { … … 242 262 // fileName, "\"", (char*)NULL); 243 263 // return TCL_ERROR; 244 return -1; 264 265 // couldn't find streams in file 266 return -4; 245 267 } 246 268 … … 260 282 // fileName, "\"", (char*)NULL); 261 283 // return TCL_ERROR; 262 return -1; 284 285 // couldn't find video stream in file 286 return -5; 263 287 } 264 288 … … 269 293 // fileName, "\"", (char*)NULL); 270 294 // return TCL_ERROR; 271 return -1; 295 296 // unsupported codec for file 297 return -6; 272 298 } 273 299 if (avcodec_open(vcodecCtx, vcodec) < 0) { … … 275 301 // fileName, "\"", (char*)NULL); 276 302 // return TCL_ERROR; 277 return -1; 303 304 // couldn't open codec for file 305 return -7; 278 306 } 279 307 … … 287 315 // " for file \"", fileName, "\"", (char*)NULL); 288 316 // return TCL_ERROR; 289 return -1; 317 318 // couldn't allocate frame space 319 return -8; 290 320 } 291 321 … … 308 338 309 339 if (strcpy(vidPtr->mode,"input") == NULL) { 310 return -1; 340 // strcpy input to vidPtr->mode failed 341 return -9; 311 342 } 312 343 … … 730 761 return -1; 731 762 } 763 764 if (vidPtr->pFormatCtx == NULL) { 765 // "internal error: video stream is not open", 766 return -1; 767 } 768 732 769 if (vidPtr->pFormatCtx) { 733 770 vcodecCtx = vidPtr->pFormatCtx->streams[vidPtr->videoStream]->codec; … … 773 810 } 774 811 775 if (vidPtr->pFormatCtx == NULL) {776 // "internal error: video stream is not open",777 return -1;778 }779 780 812 nabs = vidPtr->frameNumber + n; 781 813 return VideoGoToN(vidPtr, nabs); … … 872 904 */ 873 905 int 874 VideoGetImage(vidPtr, width, height, img, bufSize)906 VideoGetImage(vidPtr, iw, ih, img, bufSize) 875 907 VideoObj *vidPtr; 876 int width;877 int height;908 int iw; 909 int ih; 878 910 void **img; 879 911 int *bufSize; 880 912 { 881 913 882 int nframe, iw, ih,numBytes;914 int nframe, numBytes; 883 915 char c, buffer[64]; 884 916 AVCodecContext *vcodecCtx; … … 893 925 } 894 926 927 /* 895 928 if (vidPtr->pFormatCtx) { 896 929 vcodecCtx = vidPtr->pFormatCtx->streams[vidPtr->videoStream]->codec; … … 898 931 vcodecCtx = NULL; 899 932 } 933 */ 934 935 if (vidPtr->pFormatCtx == NULL) { 936 // vidPtr->pFormatCtx is NULL, video not open 937 return -1; 938 } 939 vcodecCtx = vidPtr->pFormatCtx->streams[vidPtr->videoStream]->codec; 900 940 901 941 /* … … 905 945 */ 906 946 907 iw = width; 908 ih = height; 947 // if the user's desired size is less then 0, 948 // use the default size 949 950 if (iw < 0) { 951 iw = vcodecCtx->width; 952 } 953 if (ih < 0) { 954 ih = vcodecCtx->height; 955 } 956 909 957 910 958 if (iw != vidPtr->rgbw || ih != vidPtr->rgbh) { … … 950 998 */ 951 999 952 int bufsize = 0; 1000 int bufsize = 0; 953 1001 if (vidPtr->img == NULL) { 954 1002 VideoAllocImgBuffer(vidPtr,iw,ih); … … 990 1038 } 991 1039 1040 if (vidPtr->pFormatCtx == NULL) { 1041 // vidPtr->pFormatCtx is NULL, video not open 1042 return -1; 1043 } 992 1044 vstreamPtr = vidPtr->pFormatCtx->streams[vidPtr->videoStream]; 993 1045 … … 1053 1105 } 1054 1106 1055 // FIXME: store the name of the file within vidPtr object1056 1107 if (VideoModeRead(vidPtr) != 0) { 1057 1108 return -1; … … 1082 1133 } 1083 1134 1084 // FIXME: store the name of the file within vidPtr object1085 1135 if (VideoModeRead(vidPtr) != 0) { 1086 1136 return -1;
Note: See TracChangeset
for help on using the changeset viewer.