[FFmpeg-devel] [PATCH 1/2] lavf: add control message API

Lukasz Marek lukasz.m.luki at gmail.com
Sun Jan 19 03:42:14 CET 2014


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
 
 #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;
+
+/**
+ * Message types used by avformat_control_message and avdevice_control_message.
+ */
+enum AVDeviceMessageType {
+    AV_DEVICE_NONE,
+    AV_DEVICE_WINDOW_CREATED,                              //< Window created message
+    AV_DEVICE_WINDOW_RESIZED,                              //< Window resized message
+    AV_DEVICE_WINDOW_REPAINT,                              //< Repaint request
+    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
+};
+
+/**
  * @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);
+
 
 /**
  * @}
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
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \
-- 
1.8.3.2



More information about the ffmpeg-devel mailing list