Ejemplo n.º 1
0
static int init_display(X11DisplaySink* sink, const StreamInfo* streamInfo)
{
    if (!sink->displayInitialised)
    {
        CHK_OFAIL(x11c_prepare_display(&sink->x11Common));
    }

    sink->inputWidth = streamInfo->width;
    sink->inputHeight = streamInfo->height;

    sink->width = sink->inputWidth / sink->swScale;
    sink->height = sink->inputHeight / sink->swScale;

    sink->aspectRatio.num = 4;
    sink->aspectRatio.den = 3;
    sink->displayWidth = sink->width;
    sink->displayHeight = sink->height;

    if (streamInfo->format == UYVY_FORMAT ||
        streamInfo->format == UYVY_10BIT_FORMAT)
    {
        sink->yuvFormat = UYVY;
    }
    else if (streamInfo->format == YUV422_FORMAT)
    {
        sink->yuvFormat = YV16;
    }
    else /* streamInfo->format == YUV420_FORMAT */
    {
        sink->yuvFormat = I420;
    }

    /* check if we can use shared memory */
    sink->useSharedMemory = x11c_shared_memory_available(&sink->x11Common);

    CHK_OFAIL(x11c_init_window(&sink->x11Common, sink->displayWidth, sink->displayHeight, sink->width, sink->height));

    sink->displayInitialised = 1;
    sink->displayInitFailed = 0;
    return 1;

fail:
    sink->displayInitialised = 0;
    sink->displayInitFailed = 1;
    return 0;
}
Ejemplo n.º 2
0
static int init_display(X11XVDisplaySink* sink, const StreamInfo* streamInfo)
{
    double wFactor;
    Rational sampleAspectRatio;

    if (!sink->displayInitialised)
    {
        CHK_OFAIL(x11c_prepare_display(&sink->x11Common));
    }

    sink->inputWidth = streamInfo->width;
    sink->inputHeight = streamInfo->height;

    sink->width = sink->inputWidth / sink->swScale;
    sink->height = sink->inputHeight / sink->swScale;

    if (streamInfo->format == UYVY_FORMAT)
    {
        sink->outputYUVFormat = UYVY;
    }
    else if (streamInfo->format == YUV420_FORMAT || streamInfo->format == YUV420_10BIT_FORMAT)
    {
        sink->outputYUVFormat = I420;
    }
    else /* streamInfo->format == UYVY_10BIT_FORMAT or YUV422_FORMAT or YUV422_10BIT_FORMAT or YUV444_FORMAT */
    {
        /* format is converted to UYVY */
        sink->outputYUVFormat = UYVY;
    }

    if (streamInfo->aspectRatio.num > 0 && streamInfo->aspectRatio.den > 0)
    {
        sink->aspectRatio = streamInfo->aspectRatio;

        /* default to square pixels */
        sampleAspectRatio = (Rational){1, 1};

        if (sink->inputWidth == 720 || sink->inputWidth == 702 || sink->inputWidth == 704 ||
            sink->inputWidth == 360 || sink->inputWidth == 351 || sink->inputWidth == 352 ||
            sink->inputWidth == 288)
        {
            /* assume rec. 601 non-square pixels */
            if (streamInfo->frameRate.num == 25 && streamInfo->frameRate.den == 1) {
                if (streamInfo->aspectRatio.num == 4 && streamInfo->aspectRatio.den == 3) {
                    /* 4:3 625 line */
                    sampleAspectRatio = (Rational){59, 54};
                }
                else if (streamInfo->aspectRatio.num == 16 && streamInfo->aspectRatio.den == 9) {
                    /* 16:9 625 line */
                    sampleAspectRatio = (Rational){118, 81};
                }
            } else if (streamInfo->frameRate.num == 30000 && streamInfo->frameRate.den == 1001) {
                if (streamInfo->aspectRatio.num == 4 && streamInfo->aspectRatio.den == 3) {
                    /* 4:3 525 line */
                    sampleAspectRatio = (Rational){10, 11};
                }
                else if (streamInfo->aspectRatio.num == 16 && streamInfo->aspectRatio.den == 9) {
                    /* 16:9 525 line */
                    sampleAspectRatio = (Rational){40, 33};
                }
            }
        }
        else if (((sink->inputHeight == 1080 && sink->inputWidth == 1440) ||
                  (sink->inputHeight == 720 && sink->inputWidth == 960)) &&
                    streamInfo->aspectRatio.num == 4 && streamInfo->aspectRatio.den == 3)
        {
            /* DVCPro-HD and AVC-Intra class 50 */
            sampleAspectRatio = (Rational){4, 3};
        }
        else if (sink->inputHeight == 1080 && sink->inputWidth == 1280 &&
                 streamInfo->aspectRatio.num == 3 && streamInfo->aspectRatio.den == 2)
        {
            /* DVCPro-HD 1080i60 */
            sampleAspectRatio = (Rational){3, 2};
        }

        sampleAspectRatio.num *= sink->pixelAspectRatio.den;
        sampleAspectRatio.den *= sink->pixelAspectRatio.num;

        wFactor = (sampleAspectRatio.num * sink->pixelAspectRatio.den) /
                (double)(sampleAspectRatio.den * sink->pixelAspectRatio.num);

        /* scale in horizontal direction only to avoid dealing with interlacing */
        sink->initialDisplayWidth = (int)(wFactor * sink->width);
        sink->initialDisplayHeight = sink->height;

        sink->initialDisplayWidth *= sink->scale;
        sink->initialDisplayHeight *= sink->scale;
    }
    else
    {
        sink->aspectRatio = (Rational){4, 3};

        sink->initialDisplayWidth = sink->width;
        sink->initialDisplayHeight = sink->height;
    }

    sink->inputVideoFormat = streamInfo->format;

    if (streamInfo->format == UYVY_FORMAT ||
        streamInfo->format == UYVY_10BIT_FORMAT ||
        streamInfo->format == YUV422_FORMAT ||
        streamInfo->format == YUV422_10BIT_FORMAT ||
        streamInfo->format == YUV444_FORMAT)
    {
        sink->frameFormat = X11_FOURCC('U','Y','V','Y');
        sink->frameSize = sink->width * sink->height * 2;
        sink->outputVideoFormat = UYVY_FORMAT;
    }
    else /* YUV420_FORMAT || YUV420_10BIT_FORMAT*/
    {
        sink->frameFormat = X11_FOURCC('I','4','2','0');
        sink->frameSize = sink->width * sink->height * 3 / 2;
        sink->outputVideoFormat = streamInfo->format;
    }


    /* Check that we have access to an XVideo port providing this chroma    */
    /* Commonly supported chromas: YV12, I420, YUY2, YUY2                   */
    XLockDisplay(sink->x11Common.windowInfo.display);
    sink->xvport = XVideoGetPort(sink->x11Common.windowInfo.display, sink->frameFormat, -1);
    XUnlockDisplay(sink->x11Common.windowInfo.display);
    if (sink->xvport < 0)
    {
        ml_log_error("Cannot find an xv port for requested video format\n");
        goto fail;
    }

    /* check if we can use shared memory */
    sink->useSharedMemory = x11c_shared_memory_available(&sink->x11Common);

    CHK_OFAIL(x11c_init_window(&sink->x11Common, sink->initialDisplayWidth, sink->initialDisplayHeight, sink->width, sink->height));

    sink->displayInitialised = 1;
    sink->displayInitFailed = 0;
    return 1;

fail:
    sink->displayInitialised = 0;
    sink->displayInitFailed = 1;
    return 0;
}