Ticket #41490: 0001-Cherrypicking-vtenc-improvements.patch

File 0001-Cherrypicking-vtenc-improvements.patch, 8.9 KB (added by d-r@…, 11 years ago)

Cherrypicking vtenc improvements

  • gnome/gstreamer1-gst-plugins-bad/Portfile

    a b PortGroup muniversal 1.0 
    99name                gstreamer1-gst-plugins-bad
    1010set my_name         gst-plugins-bad
    1111version             1.2.1
     12revision            1
    1213description         A set of plug-ins for GStreamer that need more quality.
    1314long_description    \
    1415    GStreamer Bad Plug-ins is a set of plug-ins that aren't up to par compared \
    configure.cflags-append -funroll-loops -fstrict-aliasing 
    103104configure.env-append        "HAVE_CXX=yes"
    104105
    105106patchfiles  modplug.patch
     107patchfiles  vtenc_improvements_cherrypick.patch
    106108
    107109variant no_x11 {
    108110        configure.args-append --disable-examples
  • new file gnome/gstreamer1-gst-plugins-bad/files/vtenc_improvements_cherrypick.patch

    diff --git a/gnome/gstreamer1-gst-plugins-bad/files/vtenc_improvements_cherrypick.patch b/gnome/gstreamer1-gst-plugins-bad/files/vtenc_improvements_cherrypick.patch
    new file mode 100644
    index 0000000..13cd47a
    - +  
     1--- sys/applemedia/vtenc.c
     2+++ sys/applemedia/vtenc.c
     3@@ -1,5 +1,6 @@
     4 /*
     5  * Copyright (C) 2010, 2013 Ole André Vadla Ravnås <oleavr@soundrop.com>
     6+ * Copyright (C) 2013 Intel Corporation
     7  *
     8  * This library is free software; you can redistribute it and/or
     9  * modify it under the terms of the GNU Library General Public
     10@@ -45,7 +46,7 @@ typedef struct _GstVTEncFrame GstVTEncFrame;
     11 struct _GstVTEncFrame
     12 {
     13   GstBuffer *buf;
     14-  GstMapInfo map;
     15+  GstVideoFrame videoframe;
     16 };
     17 
     18 static GstElementClass *parent_class = NULL;
     19@@ -94,9 +95,13 @@ static VTStatus gst_vtenc_enqueue_buffer (void *data, int a2, int a3, int a4,
     20 static gboolean gst_vtenc_buffer_is_keyframe (GstVTEnc * self,
     21     CMSampleBufferRef sbuf);
     22 
     23-static GstVTEncFrame *gst_vtenc_frame_new (GstBuffer * buf);
     24+static GstVTEncFrame *gst_vtenc_frame_new (GstBuffer * buf,
     25+    GstVideoInfo * videoinfo);
     26 static void gst_vtenc_frame_free (GstVTEncFrame * frame);
     27 
     28+static GstStaticCaps sink_caps =
     29+GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ NV12, I420 }"));
     30+
     31 static void
     32 gst_vtenc_base_init (GstVTEncClass * klass)
     33 {
     34@@ -116,20 +121,13 @@ gst_vtenc_base_init (GstVTEncClass * klass)
     35 
     36   gst_element_class_set_metadata (element_class, longname,
     37       "Codec/Encoder/Video", description,
     38-      "Ole André Vadla Ravnås <oleavr@soundrop.com>");
     39+      "Ole André Vadla Ravnås <oleavr@soundrop.com>, Dominik Röttsches <dominik.rottsches@intel.com>");
     40 
     41   g_free (longname);
     42   g_free (description);
     43 
     44   sink_template = gst_pad_template_new ("sink",
     45-      GST_PAD_SINK,
     46-      GST_PAD_ALWAYS,
     47-      gst_caps_new_simple ("video/x-raw",
     48-          "format", G_TYPE_STRING, "NV12",
     49-          "width", GST_TYPE_INT_RANGE, min_width, max_width,
     50-          "height", GST_TYPE_INT_RANGE, min_height, max_height,
     51-          "framerate", GST_TYPE_FRACTION_RANGE,
     52-          min_fps_n, min_fps_d, max_fps_n, max_fps_d, NULL));
     53+      GST_PAD_SINK, GST_PAD_ALWAYS, gst_static_caps_get (&sink_caps));
     54   gst_element_class_add_pad_template (element_class, sink_template);
     55 
     56   src_caps = gst_caps_new_simple (codec_details->mimetype,
     57@@ -197,6 +195,8 @@ gst_vtenc_init (GstVTEnc * self)
     58   /* These could be controlled by properties later */
     59   self->dump_properties = FALSE;
     60   self->dump_attributes = FALSE;
     61+
     62+  self->session = NULL;
     63 }
     64 
     65 static gint
     66@@ -377,6 +377,9 @@ gst_vtenc_sink_setcaps (GstVTEnc * self, GstCaps * caps)
     67   gst_structure_get_fraction (structure, "framerate",
     68       &self->negotiated_fps_n, &self->negotiated_fps_d);
     69 
     70+  if (!gst_video_info_from_caps (&self->video_info, caps))
     71+    return FALSE;
     72+
     73   gst_vtenc_destroy_session (self, &self->session);
     74 
     75   GST_OBJECT_UNLOCK (self);
     76@@ -530,8 +533,6 @@ gst_vtenc_create_session (GstVTEnc * self)
     77 
     78   pb_attrs = CFDictionaryCreateMutable (NULL, 0, &kCFTypeDictionaryKeyCallBacks,
     79       &kCFTypeDictionaryValueCallBacks);
     80-  gst_vtutil_dict_set_i32 (pb_attrs, kCVPixelBufferPixelFormatTypeKey,
     81-      kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange);
     82   gst_vtutil_dict_set_i32 (pb_attrs, kCVPixelBufferWidthKey,
     83       self->negotiated_width);
     84   gst_vtutil_dict_set_i32 (pb_attrs, kCVPixelBufferHeightKey,
     85@@ -760,8 +761,7 @@ gst_vtenc_encode_frame (GstVTEnc * self, GstBuffer * buf)
     86 
     87   self->cur_inbuf = buf;
     88 
     89-  ts = CMTimeMake
     90-      (GST_TIME_AS_MSECONDS (GST_BUFFER_TIMESTAMP (buf)), 1000);
     91+  ts = CMTimeMake (GST_TIME_AS_MSECONDS (GST_BUFFER_TIMESTAMP (buf)), 1000);
     92   duration = CMTimeMake
     93       (GST_TIME_AS_MSECONDS (GST_BUFFER_DURATION (buf)), 1000);
     94 
     95@@ -774,16 +774,57 @@ gst_vtenc_encode_frame (GstVTEnc * self, GstBuffer * buf)
     96     GstVTEncFrame *frame;
     97     CVReturn cv_ret;
     98 
     99-    frame = gst_vtenc_frame_new (buf);
     100-    cv_ret = CVPixelBufferCreateWithBytes (NULL,
     101-        self->negotiated_width, self->negotiated_height,
     102-        kCVPixelFormatType_422YpCbCr8, frame->map.data,
     103-        self->negotiated_width * 2,
     104-        (CVPixelBufferReleaseBytesCallback) gst_vtenc_frame_free, frame,
     105-        NULL, &pbuf);
     106-    if (cv_ret != kCVReturnSuccess) {
     107-      gst_vtenc_frame_free (frame);
     108+    frame = gst_vtenc_frame_new (buf, &self->video_info);
     109+    if (!frame)
     110       goto cv_error;
     111+
     112+    {
     113+      const size_t num_planes = GST_VIDEO_FRAME_N_PLANES (&frame->videoframe);
     114+      void *plane_base_addresses[num_planes];
     115+      size_t plane_widths[num_planes];
     116+      size_t plane_heights[num_planes];
     117+      size_t plane_bytes_per_row[num_planes];
     118+      OSType pixel_format_type;
     119+      size_t i;
     120+
     121+      for (i = 0; i < num_planes; i++) {
     122+        plane_base_addresses[i] =
     123+            GST_VIDEO_FRAME_PLANE_DATA (&frame->videoframe, i);
     124+        plane_widths[i] = GST_VIDEO_FRAME_COMP_WIDTH (&frame->videoframe, i);
     125+        plane_heights[i] = GST_VIDEO_FRAME_COMP_HEIGHT (&frame->videoframe, i);
     126+        plane_bytes_per_row[i] =
     127+            GST_VIDEO_FRAME_COMP_STRIDE (&frame->videoframe, i);
     128+        plane_bytes_per_row[i] =
     129+            GST_VIDEO_FRAME_COMP_STRIDE (&frame->videoframe, i);
     130+      }
     131+
     132+      switch (GST_VIDEO_INFO_FORMAT (&self->video_info)) {
     133+        case GST_VIDEO_FORMAT_I420:
     134+          pixel_format_type = kCVPixelFormatType_420YpCbCr8Planar;
     135+          break;
     136+        case GST_VIDEO_FORMAT_NV12:
     137+          pixel_format_type = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
     138+          break;
     139+        default:
     140+          goto cv_error;
     141+      }
     142+
     143+      cv_ret = CVPixelBufferCreateWithPlanarBytes (NULL,
     144+          self->negotiated_width, self->negotiated_height,
     145+          pixel_format_type,
     146+          NULL,
     147+          GST_VIDEO_FRAME_SIZE (&frame->videoframe),
     148+          num_planes,
     149+          plane_base_addresses,
     150+          plane_widths,
     151+          plane_heights,
     152+          plane_bytes_per_row,
     153+          (CVPixelBufferReleasePlanarBytesCallback) gst_vtenc_frame_free, frame,
     154+          NULL, &pbuf);
     155+      if (cv_ret != kCVReturnSuccess) {
     156+        gst_vtenc_frame_free (frame);
     157+        goto cv_error;
     158+      }
     159     }
     160   }
     161 
     162@@ -884,8 +925,7 @@ gst_vtenc_buffer_is_keyframe (GstVTEnc * self, CMSampleBufferRef sbuf)
     163   gboolean result = FALSE;
     164   CFArrayRef attachments_for_sample;
     165 
     166-  attachments_for_sample =
     167-      CMSampleBufferGetSampleAttachmentsArray (sbuf, 0);
     168+  attachments_for_sample = CMSampleBufferGetSampleAttachmentsArray (sbuf, 0);
     169   if (attachments_for_sample != NULL) {
     170     CFDictionaryRef attachments;
     171     CFBooleanRef depends_on_others;
     172@@ -900,13 +940,17 @@ gst_vtenc_buffer_is_keyframe (GstVTEnc * self, CMSampleBufferRef sbuf)
     173 }
     174 
     175 static GstVTEncFrame *
     176-gst_vtenc_frame_new (GstBuffer * buf)
     177+gst_vtenc_frame_new (GstBuffer * buf, GstVideoInfo * video_info)
     178 {
     179   GstVTEncFrame *frame;
     180 
     181   frame = g_slice_new (GstVTEncFrame);
     182   frame->buf = gst_buffer_ref (buf);
     183-  gst_buffer_map (buf, &frame->map, GST_MAP_READ);
     184+  if (!gst_video_frame_map (&frame->videoframe, video_info, buf, GST_MAP_READ)) {
     185+    gst_buffer_unref (frame->buf);
     186+    g_slice_free (GstVTEncFrame, frame);
     187+    return NULL;
     188+  }
     189 
     190   return frame;
     191 }
     192@@ -914,7 +958,7 @@ gst_vtenc_frame_new (GstBuffer * buf)
     193 static void
     194 gst_vtenc_frame_free (GstVTEncFrame * frame)
     195 {
     196-  gst_buffer_unmap (frame->buf, &frame->map);
     197+  gst_video_frame_unmap (&frame->videoframe);
     198   gst_buffer_unref (frame->buf);
     199   g_slice_free (GstVTEncFrame, frame);
     200 }
     201diff --git sys/applemedia/vtenc.h sys/applemedia/vtenc.h
     202index 594e1e2..776e04b 100644
     203--- sys/applemedia/vtenc.h
     204+++ sys/applemedia/vtenc.h
     205@@ -21,6 +21,7 @@
     206 #define __GST_VTENC_H__
     207 
     208 #include <gst/gst.h>
     209+#include <gst/video/video.h>
     210 
     211 #include "coremediactx.h"
     212 
     213@@ -72,6 +73,7 @@ struct _GstVTEnc
     214   gint negotiated_fps_n, negotiated_fps_d;
     215   gint caps_width, caps_height;
     216   gint caps_fps_n, caps_fps_d;
     217+  GstVideoInfo video_info;
     218   VTCompressionSessionRef session;
     219   CFMutableDictionaryRef options;
     220 
     221--
     2221.8.4
     223