Ticket #1984: NVR_WriteVideo_cleanup2.diff

File NVR_WriteVideo_cleanup2.diff, 5.4 KB (added by gnome42@…, 14 years ago)

FIXME fix and cleanup

  • libs/libmythtv/NuppelVideoRecorder.cpp

     
    6868    inputchannel = 1;
    6969    compression = 1;
    7070    compressaudio = 1;
    71     rawmode = 0;
    7271    usebttv = 1;
    7372    w = 352;
    7473    h = 240;
     
    28562877void NuppelVideoRecorder::WriteVideo(VideoFrame *frame, bool skipsync,
    28572878                                     bool forcekey)
    28582879{
    2859     int tmp = 0, r = 0, out_len = OUT_LEN;
     2880    int tmp = 0, out_len = OUT_LEN;
    28602881    struct rtframeheader frameheader;
    2861     int xaa, freecount = 0, compressthis;
    2862     int raw = 0;
    2863     int timeperframe = 40;
     2882    int raw = 0, compressthis = compression;
    28642883    uint8_t *planes[3];
    28652884    int len = frame->size;
    28662885    int fnum = frame->frameNumber;
     
    28712890
    28722891    planes[0] = buf;
    28732892    planes[1] = planes[0] + frame->width * frame->height;
    2874     if (picture_format == PIX_FMT_YUV422P)
    2875         planes[2] = planes[1] + (frame->width * frame->height) / 2;
    2876     else
    2877         planes[2] = planes[1] + (frame->width * frame->height) / 4;
    2878     compressthis = compression;
     2893    planes[2] = planes[1] + (frame->width * frame->height) /
     2894                (picture_format == PIX_FMT_YUV422P ? 2 : 4);
    28792895
    28802896    if (lf == 0)
    28812897    {   // this will be triggered every new file
     
    28862902        forcekey = true;
    28872903    }
    28882904
    2889     // count free buffers -- FIXME this can be done with less CPU time!!
    2890     for (xaa = 0; xaa < video_buffer_count; xaa++)
    2891     {
    2892         if (videobuffer[xaa]->freeToBuffer)
    2893             freecount++;
    2894     }
    2895 
    2896     if (freecount < (video_buffer_count / 3))
    2897         compressthis = 0; // speed up the encode process
    2898    
    2899     if (freecount < 5 || rawmode)
    2900         raw = 1; // speed up the encode process
    2901    
    2902     if (raw==1 || compressthis==0)
    2903     {
    2904         if (ringBuffer->IsIOBound())
    2905         {
    2906             /* need to compress, the disk can't handle any more bandwidth*/
    2907             raw=0;
    2908             compressthis=1;
    2909         }
    2910     }
    2911 
    2912     if (transcoding)
    2913     {
    2914         raw = 0;
    2915         compressthis = 1;
    2916     }
    2917 
    29182905    // see if it's time for a seeker header, sync information and a keyframe
    29192906    frameheader.keyframe  = frameofgop;             // no keyframe defaulted
    29202907
     
    29862973    }
    29872974    else
    29882975    {
     2976        int freecount = 0;
     2977        freecount = act_video_buffer > act_video_encode ?
     2978                    video_buffer_count - (act_video_buffer - act_video_encode) :
     2979                    act_video_encode - act_video_buffer;
     2980
     2981        if (freecount < (video_buffer_count / 3))
     2982            compressthis = 0; // speed up the encode process
     2983   
     2984        if (freecount < 5)
     2985            raw = 1; // speed up the encode process
     2986   
     2987        if (raw==1 || compressthis==0)
     2988        {
     2989            if (ringBuffer->IsIOBound())
     2990            {
     2991                /* need to compress, the disk can't handle any more bandwidth*/
     2992                raw=0;
     2993                compressthis=1;
     2994            }
     2995        }
     2996
     2997        if (transcoding)
     2998        {
     2999            raw = 0;
     3000            compressthis = 1;
     3001        }
     3002
    29893003        if (!raw)
    29903004        {
    29913005            if (wantkeyframe)
     
    29963010            tmp = len;
    29973011
    29983012        // here is lzo compression afterwards
    2999         if (compressthis) {
     3013        if (compressthis)
     3014        {
     3015            int r = 0;
    30003016            if (raw)
    30013017                r = lzo1x_1_compress((unsigned char*)buf, len,
    30023018                                     out, (lzo_uint *)&out_len, wrkmem);
     
    30113027        }
    30123028    }
    30133029
    3014     dropped = (((fnum-lf)>>1) - 1); // should be += 0 ;-)
    3015    
    3016     if (dropped>0)
    3017     {
    3018         if (ntsc_framerate)
    3019             timeperframe = (int)(1000 / (30 * framerate_multiplier));
    3020         else
    3021             timeperframe = (int)(1000 / (25 * framerate_multiplier));
    3022     }
    3023    
    3024     // if we have lost frames we insert "copied" frames until we have the
    3025     // exact count because of that we should have no problems with audio
    3026     // sync, as long as we don't loose audio samples :-/
    3027  
    3028     while (0 && dropped > 0)
    3029     {
    3030         frameheader.timecode = lasttimecode + timeperframe;
    3031         lasttimecode = frameheader.timecode;
    3032         frameheader.keyframe  = frameofgop;             // no keyframe defaulted
    3033         frameheader.packetlength =  0;   // no additional data needed
    3034         frameheader.frametype    = 'V';  // last frame (or nullframe if first)
    3035         frameheader.comptype    = 'L';
    3036         WriteFrameheader(&frameheader);
    3037         // we don't calculate sizes for lost frames for compression computation
    3038         dropped--;
    3039         frameofgop++;
    3040     }
    3041 
    30423030    frameheader.frametype = 'V'; // video frame
    30433031    frameheader.timecode  = timecode;
    30443032    lasttimecode = frameheader.timecode;
  • libs/libmythtv/NuppelVideoRecorder.h

     
    138138   
    139139    int fd; // v4l input file handle
    140140    signed char *strm;
    141     long dropped;
    142141    unsigned int lf, tf;
    143142    int M1, M2, Q;
    144143    int w, h;
     
    154153    int audio_samplerate; // rate we request from sounddevice
    155154    int effectivedsp; // actual measured rate
    156155
    157     int quiet;
    158     int rawmode;
    159156    int usebttv;
    160157    float video_aspect;
    161158