[FFmpeg-devel] [PATCH 1/2] lavf: add control message API
Nicolas George
george at nsup.org
Sun Jan 19 12:21:14 CET 2014
Le decadi 30 nivôse, an CCXXII, Lukasz Marek a écrit :
> New API allows communication between application and devices.
>
> Signed-off-by: Lukasz Marek <lukasz.m.luki at gmail.com>
> ---
> libavdevice/avdevice.c | 10 +++++++
> libavdevice/avdevice.h | 13 +++++++++
> libavdevice/version.h | 2 +-
> libavformat/avformat.h | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++
> libavformat/mux.c | 10 +++++++
> libavformat/utils.c | 2 ++
> libavformat/version.h | 2 +-
> 7 files changed, 108 insertions(+), 2 deletions(-)
>
> diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
> index b9b18f2..2773653 100644
> --- a/libavdevice/avdevice.c
> +++ b/libavdevice/avdevice.c
> @@ -36,3 +36,13 @@ const char * avdevice_license(void)
> #define LICENSE_PREFIX "libavdevice license: "
> return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
> }
> +
> +int avdevice_control_message(struct AVFormatContext *s, enum AVDeviceMessageType type,
> + void *data, size_t data_size)
> +{
> + if (!s->control_message_cb)
> + return AVERROR(ENOSYS);
> + if (type < AV_CTL_FIRST)
> + return AVERROR(EINVAL);
> + return s->control_message_cb(s, type, data, data_size);
> +}
> diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h
> index 93a044f..cdf26fd 100644
> --- a/libavdevice/avdevice.h
> +++ b/libavdevice/avdevice.h
> @@ -66,4 +66,17 @@ const char *avdevice_license(void);
> */
> void avdevice_register_all(void);
>
> +/**
> + * Send control message to application.
> + *
> + * @param s device context
> + * @param type message type.
> + * @param data message data. Can be NULL.
> + * @param data_size size of message data.
> + * @return 0 on success, negative on error.
> + * AVERROR(EBADMSG) when application doesn't implement handler of the message.
> + */
> +int avdevice_control_message(struct AVFormatContext *s, enum AVDeviceMessageType type,
> + void *data, size_t data_size);
> +
> #endif /* AVDEVICE_AVDEVICE_H */
> diff --git a/libavdevice/version.h b/libavdevice/version.h
> index d569fae..84f013d 100644
> --- a/libavdevice/version.h
> +++ b/libavdevice/version.h
> @@ -29,7 +29,7 @@
>
> #define LIBAVDEVICE_VERSION_MAJOR 55
> #define LIBAVDEVICE_VERSION_MINOR 5
> -#define LIBAVDEVICE_VERSION_MICRO 102
> +#define LIBAVDEVICE_VERSION_MICRO 103
Unless I am mistaken, it should be a minor bump.
>
> #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
> LIBAVDEVICE_VERSION_MINOR, \
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 6d719d7..0cf3d22 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -380,6 +380,37 @@ typedef struct AVProbeData {
> #define AVFMT_SEEK_TO_PTS 0x4000000 /**< Seeking is based on PTS */
>
> /**
> + * Structure with data for AV_DEVICE_WINDOW_CREATED message.
> + */
> +typedef struct AVDeviceWindowCreated {
> + int width; //< window width
> + int height; //< window height
> +} AVDeviceWindowCreated;
> +
> +/**
> + * Structure with data for AV_DEVICE_WINDOW_RESIZED message.
> + */
> +typedef struct AVDeviceWindowResized {
> + int width; //< new width
> + int height; //< new height
> +} AVDeviceWindowResized;
Looks redudant: a simple AVDeviceWindowGeometry structure would work for
both.
> +
> +/**
> + * Message types used by avformat_control_message and avdevice_control_message.
> + */
> +enum AVDeviceMessageType {
It looks that this structure mixes several distinct APIs:
> + AV_DEVICE_NONE,
> + AV_DEVICE_WINDOW_CREATED, //< Window created message
> + AV_DEVICE_WINDOW_RESIZED, //< Window resized message
> + AV_DEVICE_WINDOW_REPAINT, //< Repaint request
These are messages from the application to the library, meant for
AVOutputFormat.control_message().
> + AV_CTL_FIRST = 10000, //< Messages sent to application
> + AV_CTL_MESSAGE_PREPARE_WINDOW_BUFFER = 10000, //< Application is asked to prepare buffer for rendering
> + AV_CTL_MESSAGE_DISPLAY_WINDOW_BUFFER, //< Application is asked to present buffer to the user
> + AV_CTL_MESSAGE_CREATE_WINDOW_BUFFER, //< Application is asked to create buffer
> + AV_CTL_MESSAGE_DESTROY_WINDOW_BUFFER //< Application is asked to release buffer
> +};
These are messages from the library to the application, meant for
AVFormatContext.control_message_cb().
IMHO, a different enum type should be used for the different kind of
messages.
In fact, I would suggest to split this patch in two parts along that line.
Also, maybe using fourccs for the enum values would be a bit more
future-proof: AV_DEVICE_WINDOW_GEOMETRY = MKBETAG('G','E','O','M').
> +
> +/**
> * @addtogroup lavf_encoding
> * @{
> */
> @@ -453,6 +484,11 @@ typedef struct AVOutputFormat {
>
> void (*get_output_timestamp)(struct AVFormatContext *s, int stream,
> int64_t *dts, int64_t *wall);
> + /**
> + * Allows sending messages from application to device.
> + */
> + int (*control_message)(struct AVFormatContext *s, enum AVDeviceMessageType type,
> + void *data, size_t data_size);
> } AVOutputFormat;
> /**
> * @}
> @@ -948,6 +984,13 @@ typedef struct AVChapter {
>
>
> /**
> + * Callback used by devices to communicate with application.
> + */
> +typedef int (*av_format_control_message)(struct AVFormatContext *s, enum AVDeviceMessageType type,
> + void *data, size_t data_size);
> +
> +
> +/**
> * The duration of a video can be estimated through various ways, and this enum can be used
> * to know how the duration was estimated.
> */
> @@ -1348,6 +1391,17 @@ typedef struct AVFormatContext {
> * Demuxing: Set by user via av_format_set_subtitle_codec (NO direct access).
> */
> AVCodec *subtitle_codec;
> +
> + /**
> + * User data.
> + */
> + void *opaque;
> +
> + /**
> + * Callback used by devices to communicate with application.
> + */
> + av_format_control_message control_message_cb;
> +
> } AVFormatContext;
>
> int av_format_get_probe_score(const AVFormatContext *s);
> @@ -1357,6 +1411,10 @@ AVCodec * av_format_get_audio_codec(const AVFormatContext *s);
> void av_format_set_audio_codec(AVFormatContext *s, AVCodec *c);
> AVCodec * av_format_get_subtitle_codec(const AVFormatContext *s);
> void av_format_set_subtitle_codec(AVFormatContext *s, AVCodec *c);
> +void * av_format_get_opaque(const AVFormatContext *s);
> +void av_format_set_opaque(AVFormatContext *s, void *opaque);
> +av_format_control_message av_format_get_control_message_cb(const AVFormatContext *s);
> +void av_format_set_control_message_cb(AVFormatContext *s, av_format_control_message callback);
>
> /**
> * Returns the method used to set ctx->duration.
> @@ -1959,6 +2017,19 @@ enum AVCodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
> int av_get_output_timestamp(struct AVFormatContext *s, int stream,
> int64_t *dts, int64_t *wall);
>
> +/**
> + * Send control message to device.
> + *
> + * @param s device context
> + * @param type message type.
> + * @param data message data. Can be NULL.
> + * @param data_size size of message data.
> + * @return 0 on success, negative on error.
> + * AVERROR(EBADMSG) when device doesn't implement handler of the message.
> + */
> +int avformat_control_message(struct AVFormatContext *s, enum AVDeviceMessageType type,
> + void *data, size_t data_size);
Some of the functions live in the avformat namespace, and some in the
avdevice namespace, this is a bit confusing.
> +
>
> /**
> * @}
> diff --git a/libavformat/mux.c b/libavformat/mux.c
> index bd50191..46796d1 100644
> --- a/libavformat/mux.c
> +++ b/libavformat/mux.c
> @@ -850,6 +850,16 @@ int av_get_output_timestamp(struct AVFormatContext *s, int stream,
> return 0;
> }
>
> +int avformat_control_message(struct AVFormatContext *s, enum AVDeviceMessageType type,
> + void *data, size_t data_size)
> +{
> + if (!s->oformat || !s->oformat->control_message)
> + return AVERROR(ENOSYS);
> + if (type >= AV_CTL_FIRST)
> + return AVERROR(EINVAL);
> + return s->oformat->control_message(s, type, data, data_size);
> +}
> +
> int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
> AVFormatContext *src)
> {
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index c530511..f552cee 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -103,6 +103,8 @@ MAKE_ACCESSORS(AVStream, stream, AVRational, r_frame_rate)
> MAKE_ACCESSORS(AVFormatContext, format, AVCodec *, video_codec)
> MAKE_ACCESSORS(AVFormatContext, format, AVCodec *, audio_codec)
> MAKE_ACCESSORS(AVFormatContext, format, AVCodec *, subtitle_codec)
> +MAKE_ACCESSORS(AVFormatContext, format, void *, opaque)
> +MAKE_ACCESSORS(AVFormatContext, format, av_format_control_message, control_message_cb)
>
> static AVCodec *find_decoder(AVFormatContext *s, AVStream *st, enum AVCodecID codec_id)
> {
> diff --git a/libavformat/version.h b/libavformat/version.h
> index 40c56c9..84d1546 100644
> --- a/libavformat/version.h
> +++ b/libavformat/version.h
> @@ -31,7 +31,7 @@
>
> #define LIBAVFORMAT_VERSION_MAJOR 55
> #define LIBAVFORMAT_VERSION_MINOR 24
> -#define LIBAVFORMAT_VERSION_MICRO 100
> +#define LIBAVFORMAT_VERSION_MICRO 101
Same as above: I believe it should be minor.
>
> #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
> LIBAVFORMAT_VERSION_MINOR, \
Regards,
--
Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140119/f7c69d9b/attachment.asc>
More information about the ffmpeg-devel
mailing list