static int sdl_write_header(AVFormatContext *s)

{

    SDLContext *sdl = s->priv_data;

    AVStream *st = s->streams[0];

    AVCodecContext *encctx = st->codec;

    AVRational sar, dar; /* sample and display aspect ratios */

    int i, ret;

    int flags = SDL_SWSURFACE | sdl->window_fullscreen ? SDL_FULLSCREEN : 0;



    if (!sdl->window_title)

        sdl->window_title = av_strdup(s->filename);

    if (!sdl->icon_title)

        sdl->icon_title = av_strdup(sdl->window_title);



    if (SDL_WasInit(SDL_INIT_VIDEO)) {

        av_log(s, AV_LOG_ERROR,

               "SDL video subsystem was already inited, aborting\n");

        sdl->sdl_was_already_inited = 1;

        ret = AVERROR(EINVAL);

        goto fail;

    }



    if (SDL_Init(SDL_INIT_VIDEO) != 0) {

        av_log(s, AV_LOG_ERROR, "Unable to initialize SDL: %s\n", SDL_GetError());

        ret = AVERROR(EINVAL);

        goto fail;

    }



    if (   s->nb_streams > 1

        || encctx->codec_type != AVMEDIA_TYPE_VIDEO

        || encctx->codec_id   != AV_CODEC_ID_RAWVIDEO) {

        av_log(s, AV_LOG_ERROR, "Only supports one rawvideo stream\n");

        ret = AVERROR(EINVAL);

        goto fail;

    }



    for (i = 0; sdl_overlay_pix_fmt_map[i].pix_fmt != AV_PIX_FMT_NONE; i++) {

        if (sdl_overlay_pix_fmt_map[i].pix_fmt == encctx->pix_fmt) {

            sdl->overlay_fmt = sdl_overlay_pix_fmt_map[i].overlay_fmt;

            break;

        }

    }



    if (!sdl->overlay_fmt) {

        av_log(s, AV_LOG_ERROR,

               "Unsupported pixel format '%s', choose one of yuv420p, yuyv422, or uyvy422\n",

               av_get_pix_fmt_name(encctx->pix_fmt));

        ret = AVERROR(EINVAL);

        goto fail;

    }



    /* compute overlay width and height from the codec context information */

    sar = st->sample_aspect_ratio.num ? st->sample_aspect_ratio : (AVRational){ 1, 1 };

    dar = av_mul_q(sar, (AVRational){ encctx->width, encctx->height });



    /* we suppose the screen has a 1/1 sample aspect ratio */

    if (sdl->window_width && sdl->window_height) {

        /* fit in the window */

        if (av_cmp_q(dar, (AVRational){ sdl->window_width, sdl->window_height }) > 0) {

            /* fit in width */

            sdl->overlay_width  = sdl->window_width;

            sdl->overlay_height = av_rescale(sdl->overlay_width, dar.den, dar.num);

        } else {

            /* fit in height */

            sdl->overlay_height = sdl->window_height;

            sdl->overlay_width  = av_rescale(sdl->overlay_height, dar.num, dar.den);

        }

    } else {

        if (sar.num > sar.den) {

            sdl->overlay_width  = encctx->width;

            sdl->overlay_height = av_rescale(sdl->overlay_width, dar.den, dar.num);

        } else {

            sdl->overlay_height = encctx->height;

            sdl->overlay_width  = av_rescale(sdl->overlay_height, dar.num, dar.den);

        }

        sdl->window_width  = sdl->overlay_width;

        sdl->window_height = sdl->overlay_height;

    }

    sdl->overlay_x = (sdl->window_width  - sdl->overlay_width ) / 2;

    sdl->overlay_y = (sdl->window_height - sdl->overlay_height) / 2;



    SDL_WM_SetCaption(sdl->window_title, sdl->icon_title);

    sdl->surface = SDL_SetVideoMode(sdl->window_width, sdl->window_height,

                                    24, flags);

    if (!sdl->surface) {

        av_log(s, AV_LOG_ERROR, "Unable to set video mode: %s\n", SDL_GetError());

        ret = AVERROR(EINVAL);

        goto fail;

    }



    sdl->overlay = SDL_CreateYUVOverlay(encctx->width, encctx->height,

                                        sdl->overlay_fmt, sdl->surface);

    if (!sdl->overlay || sdl->overlay->pitches[0] < encctx->width) {

        av_log(s, AV_LOG_ERROR,

               "SDL does not support an overlay with size of %dx%d pixels\n",

               encctx->width, encctx->height);

        ret = AVERROR(EINVAL);

        goto fail;

    }



    av_log(s, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s sar:%d/%d -> w:%d h:%d\n",

           encctx->width, encctx->height, av_get_pix_fmt_name(encctx->pix_fmt), sar.num, sar.den,

           sdl->overlay_width, sdl->overlay_height);

    return 0;



fail:

    sdl_write_trailer(s);

    return ret;

}

static int sdl_write_header(AVFormatContext *s)

{

    SDLContext *sdl = s->priv_data;

    AVStream *st = s->streams[0];

    AVCodecContext *encctx = st->codec;

    AVRational sar, dar; 

    int i, ret;

    int flags = SDL_SWSURFACE | sdl->window_fullscreen ? SDL_FULLSCREEN : 0;



    if (!sdl->window_title)

        sdl->window_title = av_strdup(s->filename);

    if (!sdl->icon_title)

        sdl->icon_title = av_strdup(sdl->window_title);



    if (SDL_WasInit(SDL_INIT_VIDEO)) {

        av_log(s, AV_LOG_ERROR,

               "SDL video subsystem was already inited, aborting\n");

        sdl->sdl_was_already_inited = 1;

        ret = AVERROR(EINVAL);

        goto fail;

    }



    if (SDL_Init(SDL_INIT_VIDEO) != 0) {

        av_log(s, AV_LOG_ERROR, "Unable to initialize SDL: %s\n", SDL_GetError());

        ret = AVERROR(EINVAL);

        goto fail;

    }



    if (   s->nb_streams > 1

        || encctx->codec_type != AVMEDIA_TYPE_VIDEO

        || encctx->codec_id   != AV_CODEC_ID_RAWVIDEO) {

        av_log(s, AV_LOG_ERROR, "Only supports one rawvideo stream\n");

        ret = AVERROR(EINVAL);

        goto fail;

    }



    for (i = 0; sdl_overlay_pix_fmt_map[i].pix_fmt != AV_PIX_FMT_NONE; i++) {

        if (sdl_overlay_pix_fmt_map[i].pix_fmt == encctx->pix_fmt) {

            sdl->overlay_fmt = sdl_overlay_pix_fmt_map[i].overlay_fmt;

            break;

        }

    }



    if (!sdl->overlay_fmt) {

        av_log(s, AV_LOG_ERROR,

               "Unsupported pixel format '%s', choose one of yuv420p, yuyv422, or uyvy422\n",

               av_get_pix_fmt_name(encctx->pix_fmt));

        ret = AVERROR(EINVAL);

        goto fail;

    }



    

    sar = st->sample_aspect_ratio.num ? st->sample_aspect_ratio : (AVRational){ 1, 1 };

    dar = av_mul_q(sar, (AVRational){ encctx->width, encctx->height });



    

    if (sdl->window_width && sdl->window_height) {

        

        if (av_cmp_q(dar, (AVRational){ sdl->window_width, sdl->window_height }) > 0) {

            

            sdl->overlay_width  = sdl->window_width;

            sdl->overlay_height = av_rescale(sdl->overlay_width, dar.den, dar.num);

        } else {

            

            sdl->overlay_height = sdl->window_height;

            sdl->overlay_width  = av_rescale(sdl->overlay_height, dar.num, dar.den);

        }

    } else {

        if (sar.num > sar.den) {

            sdl->overlay_width  = encctx->width;

            sdl->overlay_height = av_rescale(sdl->overlay_width, dar.den, dar.num);

        } else {

            sdl->overlay_height = encctx->height;

            sdl->overlay_width  = av_rescale(sdl->overlay_height, dar.num, dar.den);

        }

        sdl->window_width  = sdl->overlay_width;

        sdl->window_height = sdl->overlay_height;

    }

    sdl->overlay_x = (sdl->window_width  - sdl->overlay_width ) / 2;

    sdl->overlay_y = (sdl->window_height - sdl->overlay_height) / 2;



    SDL_WM_SetCaption(sdl->window_title, sdl->icon_title);

    sdl->surface = SDL_SetVideoMode(sdl->window_width, sdl->window_height,

                                    24, flags);

    if (!sdl->surface) {

        av_log(s, AV_LOG_ERROR, "Unable to set video mode: %s\n", SDL_GetError());

        ret = AVERROR(EINVAL);

        goto fail;

    }



    sdl->overlay = SDL_CreateYUVOverlay(encctx->width, encctx->height,

                                        sdl->overlay_fmt, sdl->surface);

    if (!sdl->overlay || sdl->overlay->pitches[0] < encctx->width) {

        av_log(s, AV_LOG_ERROR,

               "SDL does not support an overlay with size of %dx%d pixels\n",

               encctx->width, encctx->height);

        ret = AVERROR(EINVAL);

        goto fail;

    }



    av_log(s, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s sar:%d/%d -> w:%d h:%d\n",

           encctx->width, encctx->height, av_get_pix_fmt_name(encctx->pix_fmt), sar.num, sar.den,

           sdl->overlay_width, sdl->overlay_height);

    return 0;



fail:

    sdl_write_trailer(s);

    return ret;

}

    int flags = SDL_SWSURFACE | sdl->window_fullscreen ? SDL_FULLSCREEN : 0;     if (SDL_Init(SDL_INIT_VIDEO) != 0) {         av_log(s, AV_LOG_ERROR, "Unable to initialize SDL: %s\n", SDL_GetError());         ret = AVERROR(EINVAL);         goto fail;     SDL_WM_SetCaption(sdl->window_title, sdl->icon_title);     sdl->surface = SDL_SetVideoMode(sdl->window_width, sdl->window_height,                                     24, flags);     if (!sdl->surface) {         av_log(s, AV_LOG_ERROR, "Unable to set video mode: %s\n", SDL_GetError());         ret = AVERROR(EINVAL);     sdl->overlay = SDL_CreateYUVOverlay(encctx->width, encctx->height,                                         sdl->overlay_fmt, sdl->surface);     if (!sdl->overlay || sdl->overlay->pitches[0] < encctx->width) {         av_log(s, AV_LOG_ERROR,                "SDL does not support an overlay with size of %dx%d pixels\n",                encctx->width, encctx->height);         ret = AVERROR(EINVAL);     av_log(s, AV_LOG_VERBOSE, "w:%d h:%d fmt:%s sar:%d/%d -> w:%d h:%d\n",            encctx->width, encctx->height, av_get_pix_fmt_name(encctx->pix_fmt), sar.num, sar.den,            sdl->overlay_width, sdl->overlay_height);
static int FUNC_0(AVFormatContext *VAR_0)

{

    SDLContext *sdl = VAR_0->priv_data;

    AVStream *st = VAR_0->streams[0];

    AVCodecContext *encctx = st->codec;

    AVRational sar, dar; 

    int VAR_1, VAR_2;

    int VAR_3 = SDL_SWSURFACE | sdl->window_fullscreen ? SDL_FULLSCREEN : 0;



    if (!sdl->window_title)

        sdl->window_title = av_strdup(VAR_0->filename);

    if (!sdl->icon_title)

        sdl->icon_title = av_strdup(sdl->window_title);



    if (SDL_WasInit(SDL_INIT_VIDEO)) {

        av_log(VAR_0, AV_LOG_ERROR,

               "SDL video subsystem was already inited, aborting\n");

        sdl->sdl_was_already_inited = 1;

        VAR_2 = AVERROR(EINVAL);

        goto fail;

    }



    if (SDL_Init(SDL_INIT_VIDEO) != 0) {

        av_log(VAR_0, AV_LOG_ERROR, "Unable to initialize SDL: %VAR_0\n", SDL_GetError());

        VAR_2 = AVERROR(EINVAL);

        goto fail;

    }



    if (   VAR_0->nb_streams > 1

        || encctx->codec_type != AVMEDIA_TYPE_VIDEO

        || encctx->codec_id   != AV_CODEC_ID_RAWVIDEO) {

        av_log(VAR_0, AV_LOG_ERROR, "Only supports one rawvideo stream\n");

        VAR_2 = AVERROR(EINVAL);

        goto fail;

    }



    for (VAR_1 = 0; sdl_overlay_pix_fmt_map[VAR_1].pix_fmt != AV_PIX_FMT_NONE; VAR_1++) {

        if (sdl_overlay_pix_fmt_map[VAR_1].pix_fmt == encctx->pix_fmt) {

            sdl->overlay_fmt = sdl_overlay_pix_fmt_map[VAR_1].overlay_fmt;

            break;

        }

    }



    if (!sdl->overlay_fmt) {

        av_log(VAR_0, AV_LOG_ERROR,

               "Unsupported pixel format '%VAR_0', choose one of yuv420p, yuyv422, or uyvy422\n",

               av_get_pix_fmt_name(encctx->pix_fmt));

        VAR_2 = AVERROR(EINVAL);

        goto fail;

    }



    

    sar = st->sample_aspect_ratio.num ? st->sample_aspect_ratio : (AVRational){ 1, 1 };

    dar = av_mul_q(sar, (AVRational){ encctx->width, encctx->height });



    

    if (sdl->window_width && sdl->window_height) {

        

        if (av_cmp_q(dar, (AVRational){ sdl->window_width, sdl->window_height }) > 0) {

            

            sdl->overlay_width  = sdl->window_width;

            sdl->overlay_height = av_rescale(sdl->overlay_width, dar.den, dar.num);

        } else {

            

            sdl->overlay_height = sdl->window_height;

            sdl->overlay_width  = av_rescale(sdl->overlay_height, dar.num, dar.den);

        }

    } else {

        if (sar.num > sar.den) {

            sdl->overlay_width  = encctx->width;

            sdl->overlay_height = av_rescale(sdl->overlay_width, dar.den, dar.num);

        } else {

            sdl->overlay_height = encctx->height;

            sdl->overlay_width  = av_rescale(sdl->overlay_height, dar.num, dar.den);

        }

        sdl->window_width  = sdl->overlay_width;

        sdl->window_height = sdl->overlay_height;

    }

    sdl->overlay_x = (sdl->window_width  - sdl->overlay_width ) / 2;

    sdl->overlay_y = (sdl->window_height - sdl->overlay_height) / 2;



    SDL_WM_SetCaption(sdl->window_title, sdl->icon_title);

    sdl->surface = SDL_SetVideoMode(sdl->window_width, sdl->window_height,

                                    24, VAR_3);

    if (!sdl->surface) {

        av_log(VAR_0, AV_LOG_ERROR, "Unable to set video mode: %VAR_0\n", SDL_GetError());

        VAR_2 = AVERROR(EINVAL);

        goto fail;

    }



    sdl->overlay = SDL_CreateYUVOverlay(encctx->width, encctx->height,

                                        sdl->overlay_fmt, sdl->surface);

    if (!sdl->overlay || sdl->overlay->pitches[0] < encctx->width) {

        av_log(VAR_0, AV_LOG_ERROR,

               "SDL does not support an overlay with size of %dx%d pixels\n",

               encctx->width, encctx->height);

        VAR_2 = AVERROR(EINVAL);

        goto fail;

    }



    av_log(VAR_0, AV_LOG_VERBOSE, "w:%d h:%d fmt:%VAR_0 sar:%d/%d -> w:%d h:%d\n",

           encctx->width, encctx->height, av_get_pix_fmt_name(encctx->pix_fmt), sar.num, sar.den,

           sdl->overlay_width, sdl->overlay_height);

    return 0;



fail:

    sdl_write_trailer(VAR_0);

    return VAR_2;

}

static int FUNC_0(AVFormatContext *VAR_0)
{ SDLContext *sdl = VAR_0->priv_data; AVStream *st = VAR_0->streams[0]; AVCodecContext *encctx = st->codec; AVRational sar, dar; int VAR_1, VAR_2; int VAR_3 = SDL_SWSURFACE | sdl->window_fullscreen ? SDL_FULLSCREEN : 0; if (!sdl->window_title)
sdl->window_title = av_strdup(VAR_0->filename); if (!sdl->icon_title)
sdl->icon_title = av_strdup(sdl->window_title); if (SDL_WasInit(SDL_INIT_VIDEO)) { av_log(VAR_0, AV_LOG_ERROR,
"SDL video subsystem was already inited, aborting\n"); sdl->sdl_was_already_inited = 1; VAR_2 = AVERROR(EINVAL); goto fail; } if (SDL_Init(SDL_INIT_VIDEO) != 0) { av_log(VAR_0, AV_LOG_ERROR, "Unable to initialize SDL: %VAR_0\n", SDL_GetError()); VAR_2 = AVERROR(EINVAL); goto fail; } if (   VAR_0->nb_streams > 1
|| encctx->codec_type != AVMEDIA_TYPE_VIDEO
|| encctx->codec_id   != AV_CODEC_ID_RAWVIDEO) { av_log(VAR_0, AV_LOG_ERROR, "Only supports one rawvideo stream\n"); VAR_2 = AVERROR(EINVAL); goto fail; } for (VAR_1 = 0; sdl_overlay_pix_fmt_map[VAR_1].pix_fmt != AV_PIX_FMT_NONE; VAR_1++) { if (sdl_overlay_pix_fmt_map[VAR_1].pix_fmt == encctx->pix_fmt) { sdl->overlay_fmt = sdl_overlay_pix_fmt_map[VAR_1].overlay_fmt; break; } } if (!sdl->overlay_fmt) { av_log(VAR_0, AV_LOG_ERROR,
"Unsupported pixel format '%VAR_0', choose one of yuv420p, yuyv422, or uyvy422\n",
av_get_pix_fmt_name(encctx->pix_fmt)); VAR_2 = AVERROR(EINVAL); goto fail; } sar = st->sample_aspect_ratio.num ? st->sample_aspect_ratio : (AVRational){ 1, 1 }; dar = av_mul_q(sar, (AVRational){ encctx->width, encctx->height }); if (sdl->window_width && sdl->window_height) { if (av_cmp_q(dar, (AVRational){ sdl->window_width, sdl->window_height }) > 0) { sdl->overlay_width  = sdl->window_width; sdl->overlay_height = av_rescale(sdl->overlay_width, dar.den, dar.num); } else { sdl->overlay_height = sdl->window_height; sdl->overlay_width  = av_rescale(sdl->overlay_height, dar.num, dar.den); } } else { if (sar.num > sar.den) { sdl->overlay_width  = encctx->width; sdl->overlay_height = av_rescale(sdl->overlay_width, dar.den, dar.num); } else { sdl->overlay_height = encctx->height; sdl->overlay_width  = av_rescale(sdl->overlay_height, dar.num, dar.den); } sdl->window_width  = sdl->overlay_width; sdl->window_height = sdl->overlay_height; } sdl->overlay_x = (sdl->window_width  - sdl->overlay_width ) / 2; sdl->overlay_y = (sdl->window_height - sdl->overlay_height) / 2; SDL_WM_SetCaption(sdl->window_title, sdl->icon_title); sdl->surface = SDL_SetVideoMode(sdl->window_width, sdl->window_height,
24, VAR_3); if (!sdl->surface) { av_log(VAR_0, AV_LOG_ERROR, "Unable to set video mode: %VAR_0\n", SDL_GetError()); VAR_2 = AVERROR(EINVAL); goto fail; } sdl->overlay = SDL_CreateYUVOverlay(encctx->width, encctx->height,
sdl->overlay_fmt, sdl->surface); if (!sdl->overlay || sdl->overlay->pitches[0] < encctx->width) { av_log(VAR_0, AV_LOG_ERROR,
"SDL does not support an overlay with size of %dx%d pixels\n",
encctx->width, encctx->height); VAR_2 = AVERROR(EINVAL); goto fail; } av_log(VAR_0, AV_LOG_VERBOSE, "w:%d h:%d fmt:%VAR_0 sar:%d/%d -> w:%d h:%d\n",
encctx->width, encctx->height, av_get_pix_fmt_name(encctx->pix_fmt), sar.num, sar.den,
sdl->overlay_width, sdl->overlay_height); return 0; fail:
sdl_write_trailer(VAR_0); return VAR_2; }