Changeset 2046 for branches/blt4/lang/tcl/src
- Timestamp:
- Jan 18, 2011, 7:18:39 PM (14 years ago)
- Location:
- branches/blt4/lang/tcl/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/blt4/lang/tcl/src/RpEncodeTclInterface.cc
r1409 r2046 81 81 string = (Rappture::encoding::isBinary(buf, bufLen)) ? "yes" : "no"; 82 82 } else if (('e' == *type) && (strcmp(type,"encoded") == 0)) { 83 83 bool isEncoded; 84 84 85 85 isEncoded = (Rappture::encoding::headerFlags(buf, bufLen) != 0); 86 86 string = (isEncoded) ? "yes" : "no" ; 87 87 } else { 88 89 90 88 Tcl_AppendResult(interp, "bad option \"", type, 89 "\": should be binary or encoded", (char*)NULL); 90 return TCL_ERROR; 91 91 } 92 92 Tcl_SetResult(interp, (char *)string, TCL_STATIC); … … 114 114 * AsSwitch -- 115 115 * 116 * 117 * 116 * Convert a string represent a node number into its integer 117 * value. 118 118 * 119 119 * Results: 120 * 120 * The return value is a standard Tcl result. 121 121 * 122 122 *--------------------------------------------------------------------------- … … 125 125 static int 126 126 AsSwitch( 127 ClientData clientData, 128 Tcl_Interp *interp, 129 const char *switchName, 130 Tcl_Obj *objPtr, 131 char *record, 132 int offset, 133 int flags) 127 ClientData clientData, /* Not used. */ 128 Tcl_Interp *interp, /* Interpreter to send results back to */ 129 const char *switchName, /* Not used. */ 130 Tcl_Obj *objPtr, /* String representation */ 131 char *record, /* Structure record */ 132 int offset, /* Offset to field in structure */ 133 int flags) /* Not used. */ 134 134 { 135 135 int *flagsPtr = (int *)(record + offset); … … 140 140 c = string[0]; 141 141 if ((c == 'b') && (strcmp(string, "b64") == 0)) { 142 142 *flagsPtr = RPENC_B64; 143 143 } else if ((c == 'z') && (strcmp(string, "zb64") == 0)) { 144 144 *flagsPtr = RPENC_Z | RPENC_B64; 145 145 } else if ((c == 'z') && (strcmp(string, "z") == 0)) { 146 146 *flagsPtr = RPENC_Z; 147 147 } else { 148 149 150 148 Tcl_AppendResult(interp, "bad value \"", string, 149 "\": should be b64, zb64, or z", (char *)NULL); 150 return TCL_ERROR; 151 151 } 152 152 return TCL_OK; … … 165 165 { 166 166 {SWITCH_CUSTOM, "-as", "z|b64|zb64", 167 167 offsetof(EncodeSwitches, flags), 0, 0, &asSwitch}, 168 168 {SWITCH_BITMASK, "-noheader", "", 169 169 offsetof(EncodeSwitches, flags), 0, RPENC_RAW}, 170 170 {SWITCH_END} 171 171 }; … … 173 173 static int 174 174 EncodeCmd(ClientData clientData, Tcl_Interp *interp, int objc, 175 175 Tcl_Obj *const *objv) 176 176 { 177 177 if (objc < 1) { 178 178 Tcl_AppendResult(interp, "wrong # args: should be \"", 179 180 179 Tcl_GetString(objv[0]), 180 " ?-as z|b64|zb64? ?-noheader? ?--? string\"", (char*)NULL); 181 181 return TCL_ERROR; 182 182 } … … 185 185 int n; 186 186 n = Rp_ParseSwitches(interp, encodeSwitches, objc - 1, objv + 1, &switches, 187 187 SWITCH_OBJV_PARTIAL); 188 188 if (n < 0) { 189 189 return TCL_ERROR; 190 190 } 191 191 int last; … … 193 193 if ((objc - last) != 1) { 194 194 Tcl_AppendResult(interp, "wrong # args: should be \"", 195 196 195 Tcl_GetString(objv[0]), 196 " ?-as z|b64|zb64? ?-noheader? ?--? string\"", (char*)NULL); 197 197 return TCL_ERROR; 198 198 } … … 201 201 string = (const char*)Tcl_GetByteArrayFromObj(objv[last], &nBytes); 202 202 if (nBytes <= 0) { 203 return TCL_OK;// Nothing to encode.203 return TCL_OK; // Nothing to encode. 204 204 } 205 205 Rappture::Buffer buf(string, nBytes); … … 207 207 if (!Rappture::encoding::encode(status, buf, switches.flags)) { 208 208 Tcl_AppendResult(interp, status.remark(), "\n", status.context(), NULL); 209 209 return TCL_ERROR; 210 210 } 211 211 Tcl_SetByteArrayObj(Tcl_GetObjResult(interp), 212 212 (const unsigned char*)buf.bytes(), buf.size()); 213 213 return TCL_OK; 214 214 } … … 225 225 * ::Rappture::encoding::decode ?-as z|b64|zb64? <string> 226 226 * 227 * 228 * 229 * 227 * I'd rather the interface be 228 * 229 * decode -b64 -z string 230 230 */ 231 231 … … 237 237 { 238 238 {SWITCH_CUSTOM, "-as", "z|b64|zb64", 239 239 offsetof(DecodeSwitches, flags), 0, 0, &asSwitch}, 240 240 {SWITCH_BITMASK, "-noheader", "", 241 241 offsetof(DecodeSwitches, flags), 0, RPENC_RAW}, 242 242 {SWITCH_END} 243 243 }; … … 245 245 static int 246 246 DecodeCmd(ClientData clientData, Tcl_Interp *interp, int objc, 247 247 Tcl_Obj *const *objv) 248 248 { 249 249 if (objc < 1) { 250 250 Tcl_AppendResult(interp, "wrong # args: should be \"", 251 251 Tcl_GetString(objv[0]), 252 252 " ?-as z|b64|zb64? ?--? <string>\"", (char*)NULL); 253 253 return TCL_ERROR; … … 258 258 int n; 259 259 n = Rp_ParseSwitches(interp, decodeSwitches, objc - 1, objv + 1, &switches, 260 260 SWITCH_OBJV_PARTIAL); 261 261 if (n < 0) { 262 262 return TCL_ERROR; 263 263 } 264 264 int last; … … 266 266 if ((objc - last) != 1) { 267 267 Tcl_AppendResult(interp, "wrong # args: should be \"", 268 269 268 Tcl_GetString(objv[0]), 269 " ?-as z|b64|zb64? ?--? string\"", (char*)NULL); 270 270 return TCL_ERROR; 271 271 } … … 274 274 string = (const char*)Tcl_GetByteArrayFromObj(objv[last], &nBytes); 275 275 if (nBytes <= 0) { 276 return TCL_OK;// Nothing to decode.276 return TCL_OK; // Nothing to decode. 277 277 } 278 278 Rappture::Buffer buf(string, nBytes); … … 280 280 if (!Rappture::encoding::decode(status, buf, switches.flags)) { 281 281 Tcl_AppendResult(interp, status.remark(), "\n", status.context(), NULL); 282 282 return TCL_ERROR; 283 283 } 284 284 Tcl_SetByteArrayObj(Tcl_GetObjResult(interp), 285 286 return TCL_OK; 287 } 285 (const unsigned char*)buf.bytes(), buf.size()); 286 return TCL_OK; 287 } -
branches/blt4/lang/tcl/src/RpVideoTclInterface.cc
r1932 r2046 28 28 static Tcl_ObjCmdProc SizeOp; 29 29 static Tcl_ObjCmdProc ReleaseOp; 30 static Tcl_ObjCmdProc FilenameOp; 31 static Tcl_ObjCmdProc FramerateOp; 32 static Tcl_ObjCmdProc AspectOp; 30 33 31 34 static Rp_OpSpec rpVideoOps[] = { 32 {"get", 1, (void *)GetOp, 3, 5, "[image ?width height?]|[position cur|end]|[framerate]",}, 33 {"next", 1, (void *)NextOp, 2, 2, "",}, 34 {"seek", 1, (void *)SeekOp, 3, 3, "+n|-n|n",}, 35 {"size", 1, (void *)SizeOp, 2, 2, "",}, 36 {"release", 1, (void *)ReleaseOp, 2, 2, "",}, 35 {"aspect", 1, (void *)AspectOp, 3, 3, "type",}, 36 {"filename", 1, (void *)FilenameOp, 2, 2, "",}, 37 {"framerate", 1, (void *)FramerateOp, 2, 2, "",}, 38 {"get", 1, (void *)GetOp, 3, 5, "[image ?width height?]|[position cur|end]",}, 39 {"next", 1, (void *)NextOp, 2, 2, "",}, 40 {"release", 1, (void *)ReleaseOp, 2, 2, "",}, 41 {"seek", 1, (void *)SeekOp, 3, 3, "+n|-n|n",}, 42 {"size", 1, (void *)SizeOp, 2, 2, "",}, 37 43 }; 38 44 … … 81 87 // create a new command 82 88 VideoObj *movie = NULL; 83 movie = VideoInit Cmd();89 movie = VideoInit(); 84 90 if (movie == NULL) { 85 91 Tcl_AppendResult(interp, "error while creating movie object", "\n", 86 "VideoInit Cmd(movie);", (char*)NULL);92 "VideoInit(movie);", (char*)NULL); 87 93 return TCL_ERROR; 88 94 } … … 90 96 if ((*type == 'd') && (strcmp(type,"data") == 0)) { 91 97 Tcl_AppendResult(interp, "error while creating movie: type == data not supported", 92 "\n", "VideoInit Cmd(movie);", (char*)NULL);98 "\n", "VideoInit(movie);", (char*)NULL); 93 99 return TCL_ERROR; 94 100 } else if ((*type == 'f') && (strcmp(type,"file") == 0)) { … … 96 102 if (err) { 97 103 Tcl_AppendResult(interp, "error while creating movie object: ", 98 "\n", "VideoInit Cmd(movie);", (char*)NULL);104 "\n", "VideoInit(movie);", (char*)NULL); 99 105 return TCL_ERROR; 100 106 } … … 137 143 * get image ?width height? 138 144 * get framerate 145 * get filename 146 * get aspectratio 139 147 * 140 148 */ … … 200 208 (const unsigned char*)img, bufSize); 201 209 } 210 /* 202 211 else if ((*info == 'f') && (strcmp(info,"framerate") == 0)) { 203 212 if (objc != 3) { … … 218 227 Tcl_SetObjResult(interp, Tcl_NewDoubleObj(fr)); 219 228 } 229 else if ((*info == 'f') && (strcmp(info,"filename") == 0)) { 230 if (objc != 3) { 231 Tcl_AppendResult(interp, "wrong # args: should be \"", cmd, 232 " filename\"", (char*)NULL); 233 return TCL_ERROR; 234 } 235 236 const char *fname = NULL; 237 int err = 0; 238 239 err = VideoGetFileName((VideoObj *)clientData, &fname); 240 if (err) { 241 Tcl_AppendResult(interp, "error while retrieving filename", 242 (char*)NULL); 243 return TCL_ERROR; 244 } 245 Tcl_AppendResult(interp, fname, (char*)NULL); 246 } 247 else if ((*info == 'a') && (strcmp(info,"aspectratio") == 0)) { 248 if (objc != 3) { 249 Tcl_AppendResult(interp, "wrong # args: should be \"", cmd, 250 " aspectratio\"", (char*)NULL); 251 return TCL_ERROR; 252 } 253 254 int num = 0; 255 int den = 0; 256 int err = 0; 257 258 err = VideoGetAspectRatio((VideoObj *)clientData, &num, &den); 259 if (err) { 260 Tcl_AppendResult(interp, "error while retrieving aspectratio", 261 (char*)NULL); 262 return TCL_ERROR; 263 } 264 265 Tcl_Obj *dim = NULL; 266 dim = Tcl_NewListObj(0, NULL); 267 Tcl_ListObjAppendElement(interp, dim, Tcl_NewIntObj(num)); 268 Tcl_ListObjAppendElement(interp, dim, Tcl_NewIntObj(den)); 269 Tcl_SetObjResult(interp, dim); 270 } 271 */ 220 272 else { 221 273 Tcl_AppendResult(interp, "unrecognized command \"", info, "\": should be \"", cmd, … … 243 295 Tcl_Obj *const *objv) 244 296 { 245 246 // void *img = NULL;247 // int width = 960;248 // int height = 540;249 // int bufSize = 0;250 251 297 int pos = 0; 252 298 VideoGoNext((VideoObj *)clientData); 253 299 VideoGetPositionCur((VideoObj *)clientData,&pos); 254 300 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);259 301 260 302 return TCL_OK; … … 277 319 Tcl_Obj *const *objv) 278 320 { 279 280 // void *img = NULL;281 // int width = 960;282 // int height = 540;283 // int bufSize = 0;284 321 const char *val_s = NULL; 285 322 int val = 0; … … 311 348 int c = 0; 312 349 c = VideoGoToN((VideoObj *)clientData, val); 313 // printf("c = %d\tval = %d\n",c,val); 314 } 315 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); 350 } 324 351 325 352 VideoGetPositionCur((VideoObj *)clientData,&pos); … … 331 358 /**********************************************************************/ 332 359 // FUNCTION: SizeOp() 333 /// Get the sizeof the video334 /** 335 * Return the original sizeof the video frame360 /// Get the width height of the video 361 /** 362 * Return the original width and height of the video frame 336 363 * 337 364 * Full function call: … … 351 378 352 379 353 err = VideoSize Cmd((VideoObj *)clientData,&width,&height);380 err = VideoSize((VideoObj *)clientData,&width,&height); 354 381 355 382 if (err) { … … 369 396 370 397 /**********************************************************************/ 398 // FUNCTION: FilenameOp() 399 /// Get the filename of the video 400 /** 401 * Return the original filename of the video 402 * 403 * Full function call: 404 * 405 * filename 406 * 407 */ 408 static int 409 FilenameOp (ClientData clientData, Tcl_Interp *interp, int objc, 410 Tcl_Obj *const *objv) 411 { 412 const char *fname = NULL; 413 int err = 0; 414 415 err = VideoFileName((VideoObj *)clientData, &fname); 416 if (err) { 417 Tcl_AppendResult(interp, "error while retrieving filename", 418 (char*)NULL); 419 return TCL_ERROR; 420 } 421 Tcl_AppendResult(interp, fname, (char*)NULL); 422 423 return TCL_OK; 424 } 425 426 /**********************************************************************/ 427 // FUNCTION: FramerateOp() 428 /// Get the framerate of the video 429 /** 430 * Return the framerate of the video 431 * 432 * Full function call: 433 * 434 * framerate 435 * 436 */ 437 static int 438 FramerateOp (ClientData clientData, Tcl_Interp *interp, int objc, 439 Tcl_Obj *const *objv) 440 { 441 double fr = 0; 442 int err = 0; 443 444 err = VideoFrameRate((VideoObj *)clientData, &fr); 445 if (err) { 446 Tcl_AppendResult(interp, "error while calculating framerate", 447 (char*)NULL); 448 return TCL_ERROR; 449 } 450 Tcl_SetObjResult(interp, Tcl_NewDoubleObj(fr)); 451 452 return TCL_OK; 453 } 454 455 /**********************************************************************/ 456 // FUNCTION: AspectOp() 457 /// Get the aspect ratio of the video 458 /** 459 * Return either the pixel or display aspect ratio of the video 460 * Full function call: 461 * 462 * aspect pixel 463 * aspect display 464 * 465 */ 466 static int 467 AspectOp (ClientData clientData, Tcl_Interp *interp, int objc, 468 Tcl_Obj *const *objv) 469 { 470 int err = 0; 471 int num = 0; 472 int den = 1; 473 Tcl_Obj *dim = NULL; 474 475 const char *cmd = Tcl_GetString(objv[1]); 476 const char *info = Tcl_GetString(objv[2]); 477 478 if ((*cmd == 'p') && (strcmp(info,"pixel") == 0)) { 479 err = VideoPixelAspectRatio((VideoObj *)clientData, &num, &den); 480 } 481 else if ((*info == 'd') && (strcmp(info,"display") == 0)) { 482 err = VideoDisplayAspectRatio((VideoObj *)clientData, &num, &den); 483 } 484 else { 485 Tcl_AppendResult(interp, "unrecognized command \"", info, "\": should be \"", cmd, 486 " pixel|display\"", (char*)NULL); 487 return TCL_ERROR; 488 } 489 490 if (err) { 491 Tcl_AppendResult(interp, "error while retrieving ", info, 492 " aspect ratio", (char*)NULL); 493 return TCL_ERROR; 494 } 495 496 dim = Tcl_NewListObj(0, NULL); 497 Tcl_ListObjAppendElement(interp, dim, Tcl_NewIntObj(num)); 498 Tcl_ListObjAppendElement(interp, dim, Tcl_NewIntObj(den)); 499 Tcl_SetObjResult(interp, dim); 500 501 return TCL_OK; 502 } 503 /**********************************************************************/ 371 504 // FUNCTION: ReleaseOp() 372 505 /// Clean up memory from an open video in a movie player object
Note: See TracChangeset
for help on using the changeset viewer.