This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Using the Resizer

 I'm trying to write an app to make use of the DaVinci's resizer so I know that I understand how its done before I integrate it into my application.  For my test, I've captured an image using the CCDC and dumped the raw YUV data to a file.  My resizer test app attempts to read in this file and shrink it to half its original size such that the original size is 720x480 and the new size is 360x240.  The output is, again, a raw YUV file that I make into a PNG using the convert utility on my Linux box's command line.  The resultant image looks skewed as if the original image were split into several columns and each was smeared diagonally down and to the right instead of being shown in a straight line (I hope that makes sense, it's hard to explain).  I'm using the calccoef utility associated with the "Understanding the Davinci Resizer" app note (SPRAAI7B) to generate coefficients and other resizer parameter structure values.  My code is based off of the YUVMultipass example from v1.30 of the PSP; I've modified it to only look at one "channel" since I have one UYVY format image instead of three separate images, one with each channel.

Is there something obvious I might be overlooking?  I'd be happy to zip up the source code if anyone wants to take a look, although I don't know that I can attach it to a post here.

  • The App Note you referred to is exactly what I would have recommended in this circumstance.  Your description of the final picture seems very odd; can you display resulting YUV file using display driver (avoid conversion to PNG) to see how it looks. 

  • I actually determined that for some reason my image was actually being resized to 368x240 instead of 360x240 as I'd specified in the calccoef utility; the RSZ factors for horizontal and vertical were 510 and 509 instead of 512 and 512 like I'd expect  Further evidence was that the output pitch was calculated as 736, clearly pointing to an expected image width of 368.  When I told the conversion utility it was 360x240, it must have read the data wrong and produced an odd looking image as a result, while the size of 368x240 works fine.  The rightmost 8 pixels of each row are garbage, however.  When looking at the final image, the right side seems to have four bars of alternating green and pink color where those 8 garbage pixels are.  Is this expected or is there something I should be doing different to get rid of this extraneous information?
  • Actually, now that you mention it; there is a hardware requirement that a video line be 32-byte aligned.  Since YUV422 pixels are two bytes each, this means line lengths need to be multiples of 16 pixels (equals 32-bytes).  360 is not a multiple of 16, but 368 and 720 are; this is probably why the calcoeff utility rounded up to 368.

    FYI, had you set up your display to 360 pixels per line, it would have only displayed 360 and assumed the rest of the last 32-bytes (last 8 byte) were junk.  I hope this helps clear things up.

  • Ah, that explains it.  Thanks for the info.

    I'm not using a display in my device, just doing some processing on the raw images and/or compressing them for wireless transmission.  I'll just write a routine to chop off the pixels I don't need if my sizes don't line up with the 32-byte boundaries.

  • I have two questions on how to use Resizer.

    1) I've read spraai7b  and demo code, I find a regulation to init resize device.  I find that if the demo program(one_field_fixed;zoom) needs to resize video frames, the second parameter in mmap is "D1_FRAME_SIZE * 2" in function "initResizerDevice", but if the program (passthrough) does not to resize, this parameter will be "D1_FRAME_SIZE".  Why does "mmap" need two times of  the memory space for one video frame?

     

    resize_one_field_fixed and resize_zoom:

    buffer->start = (char *)mmap(0,D1_FRAME_SIZE*2,PROT_READ | PROT_WRITE, MAP_SHARED, fd, bufd.offset);

     

    resize_passthrough:

    buffer->start = (char *)mmap(0,D1_FRAME_SIZE,PROT_READ | PROT_WRITE, MAP_SHARED, fd, bufd.offset);

     

    2) I want to optimize my algorithm, so I want to use resizer to shrink video data. For example: I get "720x576"(PAL) from capture device,  I think "720x576" video data will affect the efficiency of Codec, so I want to shrink it to "312x236". These are the procession.

       Capture video (720x576) --> Resize (312x236) --> Codec (To deal with 312x236 video frame) --> Display(312x236)

    But when I debug at "Codec" line, my program has an error.

     

    In " Capture video (720x576) --> Resize (312x236)" step:

           a) I define a variant named "Rszmemory" to hold resized video "312x236".

                        //Rsz_FRAME_SIZE = 312 x 236 x 2;

                       Rszmemory = (char*)mmap(0,Rsz_FRAME_SIZE,
                                                            PROT_READ | PROT_WRITE,
                                                            MAP_SHARED | MAP_ANONYMOUS, -1, 0);

            b) And then I transfer video data from "rszBuf->start" to "Rszmemory"

                      for(i = 0; i < Rsz_HEIGHT; i++){               // HEIGHT is 236
                                 memcpy(Rszmemory,rszBuf->start,Rsz_LINE_WIDTH);   //Rsz_LINE_WIDTH is 312 x 2;
                                 rszBuf->start += D1_LINE_WIDTH;                                                 //D1_LINE_WIDTH is 720 x 2;
                                 Rszmemory += Rsz_LINE_WIDTH;
                         }

     

    In " Resize (312x236) --> Codec (To deal with 312x236 video frame)" step:

     

           Code :                encodeVideoBuffer(hEncode, Rszmemory,encBufSize, encBuf,encBufSize, &frameSize)   //encBufSize is 312 x 236 x 2

     

           When I debug in this code line, the code has an error, I'm sure that this code does not enter into DSP-side, because I set a break point in CCS , but it does not enter into CCS.

                  If I revise "Rszmemory" to "rszBuf->start", my codec will work well (I can debug my codec in CCS), so I decide to modify memory space of "Rszmemory" from "Rsz_FRAME_SIZE" to "D1_FRAME_SIZE x 2". That is  to say : from "312 x 236 x 2" to "720 x 576 x 2 x 2". 

                   Then I debug this code line again, It works.

            I don't know the reason why it works after I enlarge the memory space for "Rszmemory".

  • After considering my questions, I'd like to answer them, but I don't know it is right or wrong.

    1)For a resizer program, if the task of this program need to resize a frame to different resolution. it will need two times of memory space, one loads original frame (for example: 720 x 576), another loads resized frame (312 x 236).  So  the code should be "buffer->start = (char *)mmap(0,D1_FRAME_SIZE*2,PROT_READ | PROT_WRITE, MAP_SHARED, fd, bufd.offset);".   But if the program just to finish a "passthrough", it does not need two frame memory spaces.

     

    2) I should not allocate memory for "Rszmemory" using "malloc" or "mmap" while passing it to codec as one of parameters. Because this error is not related with "physical memory address" or "virtual memory address". The reason is codec needs continuous memory, so I need to use "Memory_contigAlloc" to allocate a continuous memory for it.  I've resolved it.

     

    Thanks.

  • Lorry,

    You are correct on both points!

  • I am having error when I run prebuilt examples for resizer (working on evm 6446)

    # ./resize_passthrough                                                                                                                
    ./resize_passthrough: error while loading shared libraries: libposixtime.so.2.6: cannot open shared object file: No such file or directory

    Also when I tried to build the files using make clean and make  it fails to build and cannot locate header files.

    I am facing most problem because it seems I am reading old documentation for newer products! I am referring to the old encodedecode demo (dvsdk 1.3) and my new encodedecode (dvsdk 2). Though the idea is same the code structure has changed significantly and its nearly immpossible for me to correlate document (encodedecode pdf) with actual code. Am I missinng any links for newer material???