Changeset 1925


Ignore:
Timestamp:
Oct 18, 2010 7:35:40 PM (10 years ago)
Author:
dkearney
Message:

updates for video widget code. adding uploadWord to filexfer to match the downloadWord. adding some images.

Location:
trunk
Files:
7 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/Makefile.in

    r1920 r1925  
    114114                $(srcdir)/utils.tcl \
    115115                $(srcdir)/valueresult.tcl \
     116                $(srcdir)/videodial.tcl \
     117                $(srcdir)/videoscreen.tcl \
    116118                $(srcdir)/videoviewer.tcl \
    117119                $(srcdir)/videoparticle.tcl \
  • trunk/gui/scripts/filexfer.tcl

    r1756 r1925  
    9191            }
    9292        }
     93        uploadWord {
     94            if {[Rappture::filexfer::enabled]} {
     95                return "Upload"
     96            } else {
     97                return "Browse"
     98            }
     99        }
    93100        download {
    94101            if {[Rappture::filexfer::enabled]} {
     
    106113        }
    107114        default {
    108             error "bad option \"$operation\": should be upload, download, or downloadWord"
     115            error "bad option \"$operation\": should be upload, uploadWord, download, or downloadWord"
    109116        }
    110117    }
  • trunk/gui/scripts/videoviewer.tcl

    r1916 r1925  
    1616package require RapptureGUI
    1717
    18 option add *VideoViewer.width 5i widgetDefault
     18#option add *VideoViewer.width 5i widgetDefault
    1919option add *VideoViewer*cursor crosshair widgetDefault
    20 option add *VideoViewer.height 4i widgetDefault
     20#option add *VideoViewer.height 4i widgetDefault
    2121option add *VideoViewer.foreground black widgetDefault
    2222option add *VideoViewer.controlBackground gray widgetDefault
     
    3434    itk_option define -plotbackground plotBackground Background ""
    3535    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"
    3639
    3740    constructor { args } {
     
    4447    public method load {filename}
    4548    public method video {args}
     49    public method query {type}
    4650
    4751    protected method togglePtrBind {pbvar}
     
    5862    protected method updateMeasurements {}
    5963    protected method calculateTrajectory {args}
     64    protected method fixSize {}
     65
     66
    6067
    6168    private common   _settings
    6269
    63     private variable _width 0
    64     private variable _height 0
     70    private variable _width -1
     71    private variable _height -1
     72    private variable _controls ""
    6573    private variable _x0 0          ;# start x for rubberbanding
    6674    private variable _y0 0          ;# start y for rubberbanding
     
    399407# ----------------------------------------------------------------------
    400408itcl::body Rappture::VideoViewer::load {filename} {
    401     set _movie [Rappture::Video $filename]
     409
     410    # open the file
     411
     412    set _movie [Rappture::Video "file" $filename]
    402413    set _framerate [${_movie} get framerate]
    403414    set _mspf [expr round(((1.0/${_framerate})*1000)/pow(2,[$itk_component(speed) value]-1))]
    404     # set _mspf 7
    405415    puts "framerate = ${_framerate}"
    406416    puts "mspf = ${_mspf}"
    407417
     418    ${_movie} seek 0
     419
     420    # setup the image display
     421
    408422    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}]
    410431    $itk_component(main) create image 0 0 -anchor nw -image $_imh
     432
     433    # setup timings for playing video
    411434
    412435    set _lastFrame [$_movie get position end]
     
    424447    $itk_component(framenum) configure -max ${_lastFrame} -width $cnt
    425448
    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# ----------------------------------------------------------------------
     455itcl::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
    430467    $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
    437473}
    438474
     
    483519
    484520# ----------------------------------------------------------------------
     521# query - query things about the video
     522# ----------------------------------------------------------------------
     523itcl::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# ----------------------------------------------------------------------
    485537# togglePtrCtrl - choose pointer mode:
    486538#                 rectangle, distance, measure, particlemark
     
    617669
    618670    # display the next frame
    619     $_imh put [$_movie next]
     671    $_movie next
     672    $_imh put [$_movie get image ${_width} ${_height}]
    620673
    621674    # update the dial and framenum widgets
     
    670723        error "bad value: \"$val\": should be \"seek \[-percent\] value\""
    671724    }
    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]
    674728    set _settings($this-currenttime) [expr double($cur) / double(${_lastFrame})]
    675729}
     
    10061060}
    10071061
     1062# ----------------------------------------------------------------------
     1063# OPTION: -width
     1064# ----------------------------------------------------------------------
     1065itcl::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# ----------------------------------------------------------------------
     1077itcl::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# ----------------------------------------------------------------------
     1089itcl::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  
    2626static Tcl_ObjCmdProc NextOp;
    2727static Tcl_ObjCmdProc SeekOp;
     28static Tcl_ObjCmdProc SizeOp;
    2829static Tcl_ObjCmdProc ReleaseOp;
    2930
    3031static 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]",},
    3233    {"next",  1, (void *)NextOp, 2, 2, "",},
    3334    {"seek",  1, (void *)SeekOp, 3, 3, "+n|-n|n",},
     35    {"size",  1, (void *)SizeOp, 2, 2, "",},
    3436    {"release", 1, (void *)ReleaseOp, 2, 2, "",},
    3537};
     
    5658
    5759/*
    58  * USAGE: Video <file>
     60 * USAGE: Video <type> <data>
    5961 */
    6062static int
     
    6466    char cmdName[64];
    6567    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]);
    6780
    6881    // create a new command
     
    7487        return TCL_ERROR;
    7588    }
    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    }
    77102
    78103    sprintf(cmdName,"::movieObj%d",movieCount);
     104    movieCount++;
    79105
    80106    Tcl_CreateObjCommand(interp, cmdName, VideoCallCmd,
     
    109135 * get position cur
    110136 * get position end
    111  * get image width height
     137 * get image ?width height?
    112138 * get framerate
    113139 *
     
    153179    }
    154180    else if ((*info == 'i') && (strcmp(info,"image") == 0)) {
    155         if (objc != 5) {
     181        if ((objc != 3) && (objc != 5)) {
    156182            Tcl_AppendResult(interp, "wrong # args: should be \"", cmd,
    157                 " image width height\"", (char*)NULL);
     183                " image ?width height?\"", (char*)NULL);
    158184            return TCL_ERROR;
    159185        }
    160186
    161187        void *img = NULL;
    162         int width = 0;
    163         int height = 0;
     188        int width = -1;
     189        int height = -1;
    164190        int bufSize = 0;
    165191
    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
    170197        VideoGetImage((VideoObj *)clientData, width, height, &img, &bufSize);
    171198
     
    181208
    182209        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        }
    185218        Tcl_SetObjResult(interp, Tcl_NewDoubleObj(fr));
    186219    }
     
    211244{
    212245
    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;
    218252    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);
    223259
    224260    return TCL_OK;
     
    242278{
    243279
    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;
    248284    const char *val_s = NULL;
    249285    int val = 0;
     286    int pos = 0;
    250287
    251288    val_s = Tcl_GetString(objv[2]);
     
    277314    }
    278315
    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 */
     342static int
     343SizeOp (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);
    287366
    288367    return TCL_OK;
  • trunk/src/objects/RpVideo.c

    r1916 r1925  
    140140{
    141141    int fnlen = 0;
     142    int err = 0;
    142143
    143144    if (fileName == NULL) {
     
    161162    }
    162163    strncpy(vidPtr->fileName,fileName,fnlen);
     164    vidPtr->fileName[fnlen] = '\0';
    163165
    164166    // FIXME: remove this constraint when we support
     
    170172    if (*mode == 'r') {
    171173        /* we're now in "input" mode */
    172         VideoModeRead(vidPtr);
     174        err = VideoModeRead(vidPtr);
     175        if (err) {
     176            return err;
     177        }
    173178    } else if (*mode == 'w') {
    174179        /* we're now in "input" mode */
     
    195200 *  Returns TCL_OK if successful, and TCL_ERROR if there is a problem
    196201 *  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
    197213 * ------------------------------------------------------------------------
    198214 */
     
    213229        // Tcl_AppendResult(interp, "missing value for -file", (char*)NULL);
    214230        // return TCL_ERROR;
    215         return -1;
     231
     232        // missing file name
     233        return -2;
    216234    }
    217235    if (*vidPtr->fileName == '\0') {
     
    236254        //     fileName, "\"", (char*)NULL);
    237255        // return TCL_ERROR;
    238         return -1;
     256
     257        // couldn't open file
     258        return -3;
    239259    }
    240260    if (av_find_stream_info(vidPtr->pFormatCtx) < 0) {
     
    242262        //     fileName, "\"", (char*)NULL);
    243263        // return TCL_ERROR;
    244         return -1;
     264
     265        // couldn't find streams in file
     266        return -4;
    245267    }
    246268
     
    260282        //     fileName, "\"", (char*)NULL);
    261283        // return TCL_ERROR;
    262         return -1;
     284
     285        // couldn't find video stream in file
     286        return -5;
    263287    }
    264288
     
    269293        //     fileName, "\"", (char*)NULL);
    270294        // return TCL_ERROR;
    271         return -1;
     295
     296        // unsupported codec for file
     297        return -6;
    272298    }
    273299    if (avcodec_open(vcodecCtx, vcodec) < 0) {
     
    275301        //     fileName, "\"", (char*)NULL);
    276302        // return TCL_ERROR;
    277         return -1;
     303
     304        // couldn't open codec for file
     305        return -7;
    278306    }
    279307
     
    287315        //     " for file \"", fileName, "\"", (char*)NULL);
    288316        // return TCL_ERROR;
    289         return -1;
     317
     318        // couldn't allocate frame space
     319        return -8;
    290320    }
    291321
     
    308338
    309339    if (strcpy(vidPtr->mode,"input") == NULL) {
    310         return -1;
     340        // strcpy input to vidPtr->mode failed
     341        return -9;
    311342    }
    312343
     
    730761        return -1;
    731762    }
     763
     764    if (vidPtr->pFormatCtx == NULL) {
     765        // "internal error: video stream is not open",
     766        return -1;
     767    }
     768
    732769    if (vidPtr->pFormatCtx) {
    733770        vcodecCtx = vidPtr->pFormatCtx->streams[vidPtr->videoStream]->codec;
     
    773810    }
    774811
    775     if (vidPtr->pFormatCtx == NULL) {
    776         // "internal error: video stream is not open",
    777         return -1;
    778     }
    779 
    780812    nabs = vidPtr->frameNumber + n;
    781813    return VideoGoToN(vidPtr, nabs);
     
    872904 */
    873905int
    874 VideoGetImage(vidPtr, width, height, img, bufSize)
     906VideoGetImage(vidPtr, iw, ih, img, bufSize)
    875907    VideoObj *vidPtr;
    876     int width;
    877     int height;
     908    int iw;
     909    int ih;
    878910    void **img;
    879911    int *bufSize;
    880912{
    881913
    882     int nframe, iw, ih, numBytes;
     914    int nframe, numBytes;
    883915    char c, buffer[64];
    884916    AVCodecContext *vcodecCtx;
     
    893925    }
    894926
     927    /*
    895928    if (vidPtr->pFormatCtx) {
    896929        vcodecCtx = vidPtr->pFormatCtx->streams[vidPtr->videoStream]->codec;
     
    898931        vcodecCtx = NULL;
    899932    }
     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;
    900940
    901941    /*
     
    905945     */
    906946
    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
    909957
    910958    if (iw != vidPtr->rgbw || ih != vidPtr->rgbh) {
     
    950998*/
    951999
    952         int bufsize = 0; 
     1000        int bufsize = 0;
    9531001        if (vidPtr->img == NULL) {
    9541002            VideoAllocImgBuffer(vidPtr,iw,ih);
     
    9901038    }
    9911039
     1040    if (vidPtr->pFormatCtx == NULL) {
     1041        // vidPtr->pFormatCtx is NULL, video not open
     1042        return -1;
     1043    }
    9921044    vstreamPtr = vidPtr->pFormatCtx->streams[vidPtr->videoStream];
    9931045
     
    10531105    }
    10541106
    1055 // FIXME: store the name of the file within vidPtr object
    10561107    if (VideoModeRead(vidPtr) != 0) {
    10571108        return -1;
     
    10821133    }
    10831134
    1084 // FIXME: store the name of the file within vidPtr object
    10851135    if (VideoModeRead(vidPtr) != 0) {
    10861136        return -1;
Note: See TracChangeset for help on using the changeset viewer.