How to update NV12 texture?

I’m using gstreamer to show video content on an SDL based application.
However I don’t know how to call SDL_UpdateTexture. On windows it behaves quite well however on my embeded device it is giving me segmentation fault.

I think it could be pitch calculation. What is the correct pitch calculation for NV12?

I’m getting the data from gstreamer like this:


        GstBuffer *buffer = gst_sample_get_buffer(sample);
        // Get the buffer data
        GstMapInfo info;
        gst_buffer_map(buffer, &info, GST_MAP_READ);

I’m creating the texture like this:

    SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_NV12, SDL_TEXTUREACCESS_STREAMING, SCREEN_WIDTH, SCREEN_HEIGHT);

Later on I call SDL_updateTexture:

SDL_UpdateTexture(texture, NULL, info.data, SCREEN_WIDTH * 2);

It is really strange, because on Windows I works even if I set the pitch as SCREEN_WIDTH or SCREEN_WIDTH * 4 or SCREEN_WIDTH / 2

:-/

Thank you

SDL_LockTexture() returns the pitch value, it’s the fourth parameter: “pitch this is filled in with the pitch of the locked pixels”.

With SDL_UpdateTexture(), the pitch argument is the pitch, in bytes, for the pixel data you’re supplying (including any padding bytes at the end).

Does GStreamer not give you this information? Surely it tells you the size of the pixel data, from which you can do something like uint32_t pitch = pixelDataSizeInBytes / imageHeight;