Merge remote-tracking branch 'lukaszmluki/master'

* lukaszmluki/master:
  lavd/xv: reident after previous commits
  lavf/mux: pass options to nested structs of priv data
  lavu/opt: add av_opt_set_dict2() function
  lavd/opengl_enc: fix window size correction code
  lavd/opengl_enc: add window size param
  lavd/opengl_enc: use flag to mark inited context

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2014-05-02 18:46:20 +02:00
commit cea9ee5dbd
9 changed files with 65 additions and 23 deletions

View File

@ -15,6 +15,9 @@ libavutil: 2012-10-22
API changes, most recent first:
2014-05-xx - xxxxxxx - lavu 52.81.0 - opt.h
Add av_opt_set_dict2() function.
2014-04-xx - xxxxxxx - lavc 55.50.3 - avcodec.h
Deprecate CODEC_FLAG_MV0. It is replaced by the flag "mv0" in the
"mpv_flags" private option of the mpegvideo encoders.

View File

@ -237,6 +237,10 @@ Application must provide OpenGL context and both @code{window_size_cb} and @code
@item window_title
Set the SDL window title, if not specified default to the filename specified for the output device.
Ignored when @option{no_window} is set.
@item window_size
Set preferred window size, can be a string of the form widthxheight or a video size abbreviation.
If not specified it defaults to the size of the input video, downscaled according to the aspect ratio.
Mostly usable when @option{no_window} is not set.
@end table

View File

@ -178,6 +178,7 @@ typedef struct OpenGLContext {
#endif
FFOpenGLFunctions glprocs;
int inited; ///< Set to 1 when write_header was successfully called.
uint8_t background[4]; ///< Background color
int no_window; ///< 0 for create default window
char *window_title; ///< Title of the window
@ -309,8 +310,7 @@ static int opengl_resize(AVFormatContext *h, int width, int height)
OpenGLContext *opengl = h->priv_data;
opengl->window_width = width;
opengl->window_height = height;
/* max_viewport_width == 0 means write_header was not called yet. */
if (opengl->max_viewport_width) {
if (opengl->inited) {
if (opengl->no_window &&
(ret = avdevice_dev_to_app_control_message(h, AV_DEV_TO_APP_PREPARE_WINDOW_BUFFER, NULL , 0)) < 0) {
av_log(opengl, AV_LOG_ERROR, "Application failed to prepare window buffer.\n");
@ -407,7 +407,8 @@ static int av_cold opengl_sdl_create_window(AVFormatContext *h)
av_log(opengl, AV_LOG_ERROR, "Unable to initialize SDL: %s\n", SDL_GetError());
return AVERROR_EXTERNAL;
}
if ((ret = opengl_sdl_recreate_window(opengl, opengl->width, opengl->height)) < 0)
if ((ret = opengl_sdl_recreate_window(opengl, opengl->window_width,
opengl->window_height)) < 0)
return ret;
av_log(opengl, AV_LOG_INFO, "SDL driver: '%s'.\n", SDL_VideoDriverName(buffer, sizeof(buffer)));
message.width = opengl->surface->w;
@ -871,8 +872,8 @@ static av_cold int opengl_prepare_vertex(AVFormatContext *s)
int tex_w, tex_h;
if (opengl->window_width > opengl->max_viewport_width || opengl->window_height > opengl->max_viewport_height) {
opengl->window_width = FFMAX(opengl->window_width, opengl->max_viewport_width);
opengl->window_height = FFMAX(opengl->window_height, opengl->max_viewport_height);
opengl->window_width = FFMIN(opengl->window_width, opengl->max_viewport_width);
opengl->window_height = FFMIN(opengl->window_height, opengl->max_viewport_height);
av_log(opengl, AV_LOG_WARNING, "Too big viewport requested, limited to %dx%d", opengl->window_width, opengl->window_height);
}
glViewport(0, 0, opengl->window_width, opengl->window_height);
@ -951,7 +952,12 @@ static int opengl_create_window(AVFormatContext *h)
return AVERROR(ENOSYS);
#endif
} else {
if ((ret = avdevice_dev_to_app_control_message(h, AV_DEV_TO_APP_CREATE_WINDOW_BUFFER, NULL , 0)) < 0) {
AVDeviceRect message;
message.x = message.y = 0;
message.width = opengl->window_width;
message.height = opengl->window_height;
if ((ret = avdevice_dev_to_app_control_message(h, AV_DEV_TO_APP_CREATE_WINDOW_BUFFER,
&message , sizeof(message))) < 0) {
av_log(opengl, AV_LOG_ERROR, "Application failed to create window buffer.\n");
return ret;
}
@ -1067,6 +1073,10 @@ static av_cold int opengl_write_header(AVFormatContext *h)
opengl->width = st->codec->width;
opengl->height = st->codec->height;
opengl->pix_fmt = st->codec->pix_fmt;
if (!opengl->window_width)
opengl->window_width = opengl->width;
if (!opengl->window_height)
opengl->window_height = opengl->height;
if (!opengl->window_title && !opengl->no_window)
opengl->window_title = av_strdup(h->filename);
@ -1110,6 +1120,8 @@ static av_cold int opengl_write_header(AVFormatContext *h)
ret = AVERROR_EXTERNAL;
OPENGL_ERROR_CHECK(opengl);
opengl->inited = 1;
return 0;
fail:
@ -1266,6 +1278,7 @@ static const AVOption options[] = {
{ "background", "set background color", OFFSET(background), AV_OPT_TYPE_COLOR, {.str = "black"}, CHAR_MIN, CHAR_MAX, ENC },
{ "no_window", "disable default window", OFFSET(no_window), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, ENC },
{ "window_title", "set window title", OFFSET(window_title), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, ENC },
{ "window_size", "set window size", OFFSET(window_width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, ENC },
{ NULL }
};

View File

@ -29,7 +29,7 @@
#define LIBAVDEVICE_VERSION_MAJOR 55
#define LIBAVDEVICE_VERSION_MINOR 13
#define LIBAVDEVICE_VERSION_MICRO 100
#define LIBAVDEVICE_VERSION_MICRO 101
#define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
LIBAVDEVICE_VERSION_MINOR, \

View File

@ -145,19 +145,18 @@ static int xv_write_header(AVFormatContext *s)
}
}
if (!xv->window_id) {
//TODO: reident
xv->window = XCreateSimpleWindow(xv->display, DefaultRootWindow(xv->display),
xv->window_x, xv->window_y,
xv->window_width, xv->window_height,
0, 0, 0);
if (!xv->window_title) {
if (!(xv->window_title = av_strdup(s->filename))) {
ret = AVERROR(ENOMEM);
goto fail;
xv->window = XCreateSimpleWindow(xv->display, DefaultRootWindow(xv->display),
xv->window_x, xv->window_y,
xv->window_width, xv->window_height,
0, 0, 0);
if (!xv->window_title) {
if (!(xv->window_title = av_strdup(s->filename))) {
ret = AVERROR(ENOMEM);
goto fail;
}
}
}
XStoreName(xv->display, xv->window, xv->window_title);
XMapWindow(xv->display, xv->window);
XStoreName(xv->display, xv->window, xv->window_title);
XMapWindow(xv->display, xv->window);
} else
xv->window = xv->window_id;

View File

@ -334,7 +334,7 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options)
if (of->priv_class) {
*(const AVClass **)s->priv_data = of->priv_class;
av_opt_set_defaults(s->priv_data);
if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0)
if ((ret = av_opt_set_dict2(s->priv_data, &tmp, AV_OPT_SEARCH_CHILDREN)) < 0)
goto fail;
}
}

View File

@ -1415,7 +1415,7 @@ void av_opt_free(void *obj)
av_freep((uint8_t *)obj + o->offset);
}
int av_opt_set_dict(void *obj, AVDictionary **options)
int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
{
AVDictionaryEntry *t = NULL;
AVDictionary *tmp = NULL;
@ -1425,7 +1425,7 @@ int av_opt_set_dict(void *obj, AVDictionary **options)
return 0;
while ((t = av_dict_get(*options, "", t, AV_DICT_IGNORE_SUFFIX))) {
ret = av_opt_set(obj, t->key, t->value, 0);
ret = av_opt_set(obj, t->key, t->value, search_flags);
if (ret == AVERROR_OPTION_NOT_FOUND)
av_dict_set(&tmp, t->key, t->value, 0);
else if (ret < 0) {
@ -1439,6 +1439,11 @@ int av_opt_set_dict(void *obj, AVDictionary **options)
return ret;
}
int av_opt_set_dict(void *obj, AVDictionary **options)
{
return av_opt_set_dict2(obj, options, 0);
}
const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
int opt_flags, int search_flags)
{

View File

@ -541,6 +541,24 @@ int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
*/
int av_opt_set_dict(void *obj, struct AVDictionary **options);
/**
* Set all the options from a given dictionary on an object.
*
* @param obj a struct whose first element is a pointer to AVClass
* @param options options to process. This dictionary will be freed and replaced
* by a new one containing all options not found in obj.
* Of course this new dictionary needs to be freed by caller
* with av_dict_free().
* @param search_flags A combination of AV_OPT_SEARCH_*.
*
* @return 0 on success, a negative AVERROR if some option was found in obj,
* but could not be set.
*
* @see av_dict_copy()
*/
int av_opt_set_dict2(void *obj, struct AVDictionary **options, int search_flags);
/**
* Extract a key-value pair from the beginning of a string.
*

View File

@ -56,7 +56,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 52
#define LIBAVUTIL_VERSION_MINOR 80
#define LIBAVUTIL_VERSION_MINOR 81
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \