Add an helper function and a compatibility layer for exporting
information through coded_frame.

Signed-off-by: Vittorio Giovara <[email protected]>
---
A small fixup/leftover, right on the first patch. ;-;
Vittorio

 doc/APIchanges        |  4 ++++
 libavcodec/avcodec.h  | 23 +++++++++++++++++++++++
 libavcodec/internal.h |  5 +++++
 libavcodec/utils.c    | 37 +++++++++++++++++++++++++++++++++++++
 libavcodec/version.h  |  2 +-
 libavformat/dump.c    | 23 +++++++++++++++++++++++
 6 files changed, 93 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 5d39ec6..08bd913 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,10 @@ libavutil:     2014-08-09
 
 API changes, most recent first:
 
+2015-xx-xx - xxxxxxx - lavc 56.25.0 - avcodec.h
+  Add AV_PKT_DATA_CODING_PARAMS and to carry AVPacket compression parameters
+  in the form of an AVPacketCodingParams structure.
+
 2015-xx-xx - xxxxxxx - lavc 56.23.0
   Add av_vda_default_init2.
 
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3440126..eb28e7b 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -853,6 +853,23 @@ typedef struct AVPanScan{
  */
 #define AV_GET_BUFFER_FLAG_REF (1 << 0)
 
+typedef struct AVPacketCodingParams {
+    /**
+     * Picture type of the frame contained in the packet.
+     */
+    enum AVPictureType pict_type;
+
+    /**
+     * Quality after compression, between 1 (good) and FF_LAMBDA_MAX (bad).
+     */
+    int quality;
+
+    /**
+     * Compression error for each data pointer.
+     */
+    uint64_t error[AV_NUM_DATA_POINTERS];
+} AVPacketCodingParams;
+
 /**
  * @defgroup lavc_packet AVPacket
  *
@@ -927,6 +944,12 @@ enum AVPacketSideDataType {
      * to enum AVAudioServiceType.
      */
     AV_PKT_DATA_AUDIO_SERVICE_TYPE,
+
+    /**
+     * This side data should be associated with a video stream and corresponds
+     * to statistical data, as described in AVPacketCodingParams.
+     */
+    AV_PKT_DATA_CODING_PARAMS,
 };
 
 typedef struct AVPacketSideData {
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index 634400f..6afbbda 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -219,6 +219,11 @@ int ff_side_data_update_matrix_encoding(AVFrame *frame,
                                         enum AVMatrixEncoding matrix_encoding);
 
 /**
+ * Allocate and initialize an AV_PKT_DATA_CODING_PARAMS side data.
+ */
+int ff_packet_default_coding_params(AVPacket *pkt);
+
+/**
  * Select the (possibly hardware accelerated) pixel format.
  * This is a wrapper around AVCodecContext.get_format() and should be used
  * instead of calling get_format() directly.
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index c9ae19b..0a98138 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -177,6 +177,23 @@ int ff_side_data_update_matrix_encoding(AVFrame *frame,
     return 0;
 }
 
+int ff_packet_default_coding_params(AVPacket *pkt)
+{
+    int i;
+    AVPacketCodingParams *params = (AVPacketCodingParams *)
+        av_packet_new_side_data(pkt, AV_PKT_DATA_CODING_PARAMS,
+                                sizeof(AVPacketCodingParams));
+    if (!params)
+        return AVERROR(ENOMEM);
+
+    params->pict_type = AV_PICTURE_TYPE_I;
+    params->quality = 0;
+    for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
+        params->error[i] = 0;
+
+    return 0;
+}
+
 #if HAVE_SIMD_ALIGN_16
 #   define STRIDE_ALIGN 16
 #else
@@ -1509,6 +1526,8 @@ int attribute_align_arg 
avcodec_encode_video2(AVCodecContext *avctx,
 
     ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
     if (!ret) {
+        AVPacketCodingParams *params;
+
         if (!*got_packet_ptr)
             avpkt->size = 0;
         else if (!(avctx->codec->capabilities & CODEC_CAP_DELAY))
@@ -1520,6 +1539,24 @@ int attribute_align_arg 
avcodec_encode_video2(AVCodecContext *avctx,
                 avpkt->data = avpkt->buf->data;
         }
 
+        params = (AVPacketCodingParams *)
+            av_packet_get_side_data(avpkt, AV_PKT_DATA_CODING_PARAMS, NULL);
+        if (params) {
+            int i;
+            AVFrame *cf = avctx->coded_frame;
+            cf->key_frame = avpkt->flags & AV_PKT_FLAG_KEY;
+            cf->pict_type = params->pict_type;
+            cf->quality   = params->quality;
+            for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
+                avctx->coded_frame->error[i] = params->error[i];
+            if (frame) {
+                cf->interlaced_frame    = frame->interlaced_frame;
+                cf->top_field_first     = frame->top_field_first;
+                cf->sample_aspect_ratio = frame->sample_aspect_ratio;
+                cf->pts                 = frame->pts;
+            }
+        }
+
         avctx->frame_number++;
     }
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index c478ca3..c57bd85 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR 56
-#define LIBAVCODEC_VERSION_MINOR 24
+#define LIBAVCODEC_VERSION_MINOR 25
 #define LIBAVCODEC_VERSION_MICRO  0
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavformat/dump.c b/libavformat/dump.c
index 3248e56..26bf581 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -318,6 +318,25 @@ static void dump_audioservicetype(void *ctx, 
AVPacketSideData *sd)
     }
 }
 
+static void dump_compparams(void *ctx, AVPacketSideData *sd)
+{
+    AVPacketCodingParams *params = (AVPacketCodingParams *)sd->data;
+
+    if (sd->size < sizeof(*params)) {
+        av_log(ctx, AV_LOG_INFO, "invalid data");
+        return;
+    }
+
+    av_log(ctx, AV_LOG_INFO, "%c picture type",
+           av_get_picture_type_char(params->pict_type));
+
+    if (params->quality > 0)
+        av_log(ctx, AV_LOG_INFO, " (%d quality)", params->quality);
+    if (params->error[0] || params->error[1] || params->error[2])
+        av_log(ctx, AV_LOG_INFO, " [%"PRIu64" %"PRIu64" %"PRIu64"]",
+               params->error[0], params->error[1], params->error[2]);
+}
+
 static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
 {
     int i;
@@ -359,6 +378,10 @@ static void dump_sidedata(void *ctx, AVStream *st, const 
char *indent)
             av_log(ctx, AV_LOG_INFO, "audio service type: ");
             dump_audioservicetype(ctx, &sd);
             break;
+        case AV_PKT_DATA_CODING_PARAMS:
+            av_log(ctx, AV_LOG_INFO, "compression parameters: ");
+            dump_compparams(ctx, &sd);
+            break;
         default:
             av_log(ctx, AV_LOG_WARNING,
                    "unknown side data type %d (%d bytes)", sd.type, sd.size);
-- 
1.9.5 (Apple Git-50.3)

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to