Changeset 3689

Show
Ignore:
Timestamp:
12/17/06 03:20:12 (2 years ago)
Author:
hverkuil
Message:

More work on speed changes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ivtvtv/trunk/ivtvtv.cpp

    r3687 r3689  
    1212 
    1313#include <string> 
     14 
     15int g_skip = 0; 
     16int g_spd = 0; 
     17int idx = 0; 
    1418 
    1519#if 0 
     
    5559static int ivtv_api_dec_speed(int ivtvfd, int direction, int speed) 
    5660{ 
    57         int b_per_gop = 1
     61        int b_per_gop = 2
    5862        int aud_mute = 0; 
    5963        int fr_field = 0; 
     
    6367        int ip_frames = 1; 
    6468        int ipb_frames = 2; 
     69 
     70        if (speed > 2) 
     71                speed = 2; 
    6572 
    6673        /* Make input sane */ 
     
    7380                if (speed < 0) { 
    7481                        __ivtv_api_dec_speed(ivtvfd, 
    75                                              -speed, 0, 0, direction, 
     82                                             -speed+1, 0, 0, direction, 
    7683                                             ipb_frames, 0, aud_mute, fr_field, mute); 
    7784                } else if (speed == 0) { 
     
    7986                                             0, 0, 0, direction, ipb_frames, 0, 
    8087                                             aud_mute, fr_field, mute); 
    81                 } else if (speed == 1 || speed == 2) { 
    82                         __ivtv_api_dec_speed(ivtvfd, 
    83                                              speed, 0, 1, direction, 
     88                } else if (speed == 1) { 
     89                        __ivtv_api_dec_speed(ivtvfd, 
     90                                             speed, 1, 1, direction, 
    8491                                             ipb_frames, 0, aud_mute, fr_field, mute); 
    8592                } else { 
    8693                        __ivtv_api_dec_speed(ivtvfd, 
    87                                              0, 0, 0, direction, i_frames, 0, 
     94                                             speed, 0, 1, direction, i_frames, 0, 
    8895                                             aud_mute, fr_field, mute); 
    8996                } 
     
    9198                if (speed < 0) { 
    9299                        __ivtv_api_dec_speed(ivtvfd, 
    93                                              -speed, 0, 0, direction, ip_frames, 
     100                                             -speed+1, 0, 0, direction, ip_frames, 
    94101                                             b_per_gop, aud_mute, fr_field, mute); 
    95102                } else if (speed == 0) { 
     
    101108                                             speed, 0, 1, direction, ip_frames, 
    102109                                             b_per_gop, aud_mute, fr_field, mute); 
    103                 } else if (speed > 2)
    104                         __ivtv_api_dec_speed(ivtvfd, 
    105                                              0, 0, 0, direction, i_frames, 
     110                } else
     111                        __ivtv_api_dec_speed(ivtvfd, 
     112                                             speed, 0, 1, direction, i_frames, 
    106113                                             b_per_gop, aud_mute, fr_field, mute); 
    107                 } else { 
    108                         __ivtv_api_dec_speed(ivtvfd, 
    109                                              speed, 0, 1, direction, 
    110                                              ipb_frames, b_per_gop, aud_mute, 
    111                                              fr_field, mute); 
    112114                } 
    113115        } 
     
    119121void speed(int fh, int delta) 
    120122{ 
    121         static int spd = 0; 
    122  
    123         spd += delta; 
    124         printf("dir = %d spd = %d\n", dir, spd); 
    125         ivtv_api_dec_speed(fh, dir, spd); 
     123        g_spd += delta; 
     124        printf("dir = %d spd = %d\n", dir, g_spd); 
     125        ivtv_api_dec_speed(fh, dir, g_spd); 
    126126} 
    127127 
    128128void process(int fh, int ch) 
    129129{ 
     130        struct ivtv_cfg_start_decode start; 
     131        struct ivtv_cfg_stop_decode stop; 
    130132        int step = 0; 
    131133 
     
    141143                break; 
    142144        case 'r': 
     145                dir = 0; 
     146                speed(fh, 0); 
    143147                ioctl(fh, IVTV_IOC_PLAY, 0); 
     148                break; 
     149        case 'd': 
     150                dir = !dir; 
     151                stop.hide_last = 0; 
     152                stop.pts_stop = 0; 
     153                ioctl(fh, IVTV_IOC_STOP_DECODE, &stop); 
     154                start.gop_offset = 0; 
     155                start.muted_audio_frames = 0; 
     156                ioctl(fh, IVTV_IOC_START_DECODE, &start); 
     157                speed(fh, 0); 
     158                if (dir) idx -= g_skip; 
     159                else idx += g_skip; 
     160                if (idx < 0) idx = 0; 
    144161                break; 
    145162        case '-': 
     
    176193        unsigned long long *indices; 
    177194        int max_idx; 
    178         int idx = 0; 
    179195 
    180196        if (argc < 3) { 
     
    208224                        max_sz = indices[i+1] - indices[i]; 
    209225        buf = new char[max_sz]; 
     226        printf("max %d\n", max_sz); 
    210227 
    211228        //if (fin > fmax) fmax = fin; 
     
    215232                exit(1); 
    216233        } 
     234        int fast = 1; 
     235        ioctl(fout, IVTV_IOC_DEC_FAST_STOP, &fast); 
     236        //ioctl(fout, IVTV_IOC_DEC_SPLICE, &fast); 
    217237        if (fout > fmax) fmax = fout; 
    218238 
    219239        fd_set fd_in; 
    220240        fd_set fd_out; 
     241        int first = 1; 
     242        time_t t1, t2; 
     243        int cnt = 0; 
     244 
     245        t1 = time(NULL); 
    221246 
    222247        while (1) { 
     
    241266                if (bufoffset == bufsz) { 
    242267                        ssize_t sz; 
     268                        int i = idx; 
    243269 
    244270                        if (dir) { 
     
    247273                                        break; 
    248274                                } 
    249                                 idx--
     275                                idx -= g_spd > 2 ? g_spd-1 : 1
    250276                        } 
    251277                        else { 
     
    254280                                        break; 
    255281                                } 
    256                                 idx++
    257                         } 
    258                         lseek(fin, indices[idx], SEEK_SET); 
    259                         bufsz = indices[idx + 1] - indices[idx]; 
     282                                idx += g_spd > 2 ? g_spd-1 : 1
     283                        } 
     284                        lseek(fin, indices[i], SEEK_SET); 
     285                        bufsz = indices[i + 1] - indices[i]; 
    260286                        sz = read(fin, buf, bufsz); 
     287                        struct ivtv_ioctl_framesync info; 
     288                        ioctl(fout, IVTV_IOC_GET_TIMING, &info); 
     289                        printf("frame %d %lld %d\n", info.frame, info.pts, idx); 
     290                        cnt++; 
     291                        t2 = time(NULL); 
     292                        if (t1 != t2) { 
     293//                              printf("sec %d %d\n", cnt, t2 - t1); 
     294                                cnt = 0; 
     295                                t1 = t2; 
     296                        } 
     297                        if (info.frame && first) { 
     298                                first = 0; 
     299                                g_skip = idx; 
     300                                printf("skip = %d\n", g_skip); 
     301                        } 
    261302 
    262303                        if (sz == 0) { 
     
    277318                } 
    278319        } 
     320        fast = 0; 
     321        ioctl(fout, IVTV_IOC_DEC_FAST_STOP, &fast); 
     322        struct ivtv_cfg_stop_decode stop; 
     323        stop.hide_last = 1; 
     324        stop.pts_stop = 0; 
     325        //ioctl(fout, IVTV_IOC_STOP_DECODE, &stop); 
     326        ioctl(fout, VIDIOC_STREAMOFF, 0); 
    279327        return 0; 
    280328}