daily pastebin goal
67%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2014 1,515 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --- gst-omx_old/omx/gstomxh264enc.c     2014-01-03 21:07:09.000000000 +0000
  2. +++ gst-omx/omx/gstomxh264enc.c 2014-01-08 23:18:07.637708920 +0000
  3. @@ -26,6 +26,10 @@
  4.  
  5.  #include "gstomxh264enc.h"
  6.  
  7. +#ifdef USE_OMX_TARGET_RPI
  8. +#include <OMX_Broadcom.h>
  9. +#endif
  10. +
  11.  GST_DEBUG_CATEGORY_STATIC (gst_omx_h264_enc_debug_category);
  12.  #define GST_CAT_DEFAULT gst_omx_h264_enc_debug_category
  13.  
  14. @@ -36,12 +40,32 @@
  15.      GstOMXPort * port, GstVideoCodecState * state);
  16.  static GstFlowReturn gst_omx_h264_enc_handle_output_frame (GstOMXVideoEnc *
  17.      self, GstOMXPort * port, GstOMXBuffer * buf, GstVideoCodecFrame * frame);
  18. +static void gst_omx_h264_enc_set_property (GObject * object, guint prop_id,
  19. +    const GValue * value, GParamSpec * pspec);
  20. +static void gst_omx_h264_enc_get_property (GObject * object, guint prop_id,
  21. +    GValue * value, GParamSpec * pspec);
  22.  
  23.  enum
  24.  {
  25. -  PROP_0
  26. +  PROP_0,
  27. +#ifdef USE_OMX_TARGET_RPI
  28. +  PROP_INLINESPSPPSHEADERS,
  29. +#endif
  30. +  PROP_PERIODICITYOFIDRFRAMES,
  31. +  PROP_INTERVALOFCODINGINTRAFRAMES
  32.  };
  33.  
  34. +#ifdef USE_OMX_TARGET_RPI
  35. +/**< reference: OMX_CONFIG_PORTBOOLEANTYPE*/
  36. +#define OMX_IndexParamBrcmVideoAVCInlineHeaderEnable  0x7f0000df
  37. +#define OMX_IndexParamBrcmPixelAspectRatio        0x7f00004d
  38. +
  39. +#define GST_OMX_H264_VIDEO_ENC_INLINE_SPS_PPS_HEADERS_DEFAULT      TRUE
  40. +#endif
  41. +#define GST_OMX_H264_VIDEO_ENC_PERIODICITY_OF_IDR_FRAMES_DEFAULT    (0xffffffff)
  42. +#define GST_OMX_H264_VIDEO_ENC_INTERVAL_OF_CODING_INTRA_FRAMES_DEFAULT (0xffffffff)
  43. +
  44. +
  45.  /* class initialization */
  46.  
  47.  #define DEBUG_INIT \
  48. @@ -54,12 +78,39 @@
  49.  static void
  50.  gst_omx_h264_enc_class_init (GstOMXH264EncClass * klass)
  51.  {
  52. +  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  53.    GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
  54.    GstOMXVideoEncClass *videoenc_class = GST_OMX_VIDEO_ENC_CLASS (klass);
  55.  
  56.    videoenc_class->set_format = GST_DEBUG_FUNCPTR (gst_omx_h264_enc_set_format);
  57.    videoenc_class->get_caps = GST_DEBUG_FUNCPTR (gst_omx_h264_enc_get_caps);
  58.  
  59. +  gobject_class->set_property = gst_omx_h264_enc_set_property;
  60. +  gobject_class->get_property = gst_omx_h264_enc_get_property;
  61. +
  62. +#ifdef USE_OMX_TARGET_RPI
  63. +  g_object_class_install_property (gobject_class, PROP_INLINESPSPPSHEADERS,
  64. +      g_param_spec_boolean ("inline-header", "Inline SPS/PPS headers before IDR",
  65. +          "Inline SPS/PPS header before IDR", GST_OMX_H264_VIDEO_ENC_INLINE_SPS_PPS_HEADERS_DEFAULT,
  66. +          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
  67. +          GST_PARAM_MUTABLE_READY));
  68. +#endif
  69. +
  70. +  g_object_class_install_property (gobject_class, PROP_PERIODICITYOFIDRFRAMES,
  71. +      g_param_spec_uint ("periodicty-idr", "Target Bitrate",
  72. +          "Periodicity of IDR frames (0xffffffff=component default)",
  73. +          0, G_MAXUINT, GST_OMX_H264_VIDEO_ENC_PERIODICITY_OF_IDR_FRAMES_DEFAULT,
  74. +          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
  75. +          GST_PARAM_MUTABLE_READY));
  76. +
  77. +  g_object_class_install_property (gobject_class, PROP_INTERVALOFCODINGINTRAFRAMES,
  78. +      g_param_spec_uint ("interval-intraframes", "Interval of coding Intra frames",
  79. +          "Interval of coding Intra frames (0xffffffff=component default)",
  80. +          0, G_MAXUINT, GST_OMX_H264_VIDEO_ENC_INTERVAL_OF_CODING_INTRA_FRAMES_DEFAULT,
  81. +          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
  82. +          GST_PARAM_MUTABLE_READY));
  83. +
  84. +
  85.    videoenc_class->cdata.default_src_template_caps = "video/x-h264, "
  86.        "width=(int) [ 16, 4096 ], " "height=(int) [ 16, 4096 ]";
  87.    videoenc_class->handle_output_frame =
  88. @@ -75,8 +126,61 @@
  89.  }
  90.  
  91.  static void
  92. +gst_omx_h264_enc_set_property (GObject * object, guint prop_id,
  93. +    const GValue * value, GParamSpec * pspec)
  94. +{
  95. +  GstOMXH264Enc *self = GST_OMX_H264_ENC (object);
  96. +
  97. +  switch (prop_id) {
  98. +#ifdef USE_OMX_TARGET_RPI
  99. +    case PROP_INLINESPSPPSHEADERS:
  100. +      self->inline_sps_pps_headers = g_value_get_boolean(value);
  101. +      break;
  102. +#endif
  103. +    case PROP_PERIODICITYOFIDRFRAMES:
  104. +      self->periodicty_idr = g_value_get_uint (value);
  105. +      break;
  106. +    case PROP_INTERVALOFCODINGINTRAFRAMES:
  107. +      self->interval_intraframes = g_value_get_uint (value);
  108. +      break;
  109. +    default:
  110. +      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  111. +      break;
  112. +  }
  113. +}
  114. +
  115. +static void
  116. +gst_omx_h264_enc_get_property (GObject * object, guint prop_id, GValue * value,
  117. +    GParamSpec * pspec)
  118. +{
  119. +  GstOMXH264Enc *self = GST_OMX_H264_ENC (object);
  120. +
  121. +  switch (prop_id) {
  122. +#ifdef USE_OMX_TARGET_RPI
  123. +    case PROP_INLINESPSPPSHEADERS:
  124. +      g_value_set_boolean(value, self->inline_sps_pps_headers);
  125. +      break;
  126. +#endif
  127. +    case PROP_PERIODICITYOFIDRFRAMES:
  128. +      g_value_set_uint (value, self->periodicty_idr);
  129. +      break;
  130. +    case PROP_INTERVALOFCODINGINTRAFRAMES:
  131. +      g_value_set_uint (value, self->interval_intraframes);
  132. +      break;
  133. +    default:
  134. +      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  135. +      break;
  136. +  }
  137. +}
  138. +
  139. +static void
  140.  gst_omx_h264_enc_init (GstOMXH264Enc * self)
  141.  {
  142. +#ifdef USE_OMX_TARGET_RPI
  143. +  self->inline_sps_pps_headers = GST_OMX_H264_VIDEO_ENC_INLINE_SPS_PPS_HEADERS_DEFAULT;
  144. +#endif
  145. +  self->periodicty_idr = GST_OMX_H264_VIDEO_ENC_PERIODICITY_OF_IDR_FRAMES_DEFAULT;
  146. +  self->interval_intraframes = GST_OMX_H264_VIDEO_ENC_INTERVAL_OF_CODING_INTRA_FRAMES_DEFAULT;
  147.  }
  148.  
  149.  static gboolean
  150. @@ -86,10 +190,71 @@
  151.    GstOMXH264Enc *self = GST_OMX_H264_ENC (enc);
  152.    GstCaps *peercaps;
  153.    OMX_PARAM_PORTDEFINITIONTYPE port_def;
  154. -  OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
  155. +  OMX_VIDEO_PARAM_PROFILELEVELTYPE h264_profile_level_param;
  156. +  OMX_VIDEO_CONFIG_AVCINTRAPERIOD video_avc_intra_period_param;
  157. +#ifdef USE_OMX_TARGET_RPI
  158. +  OMX_CONFIG_PORTBOOLEANTYPE h264_enc_inline_header_param;
  159. +#endif
  160.    OMX_ERRORTYPE err;
  161.    const gchar *profile_string, *level_string;
  162.  
  163. +#ifdef USE_OMX_TARGET_RPI
  164. +  GST_OMX_INIT_STRUCT (&h264_enc_inline_header_param);
  165. +  h264_enc_inline_header_param.nPortIndex = GST_OMX_VIDEO_ENC (self)->enc_out_port->index;
  166. +  err =  gst_omx_component_get_parameter (GST_OMX_VIDEO_ENC (self)->enc, OMX_IndexParamBrcmVideoAVCInlineHeaderEnable,
  167. +                                          &h264_enc_inline_header_param);
  168. +  if (err != OMX_ErrorNone) {
  169. +    GST_ERROR_OBJECT (self, "can't get OMX_IndexParamBrcmVideoAVCInlineHeaderEnable %s (0x%08x)", gst_omx_error_to_string (err), err);
  170. +    return FALSE;
  171. +  }
  172. +
  173. +  if(self->inline_sps_pps_headers) {
  174. +    h264_enc_inline_header_param.bEnabled = OMX_TRUE;
  175. +  }
  176. +  else {
  177. +    h264_enc_inline_header_param.bEnabled = OMX_FALSE;
  178. +  }
  179. +
  180. +  err =  gst_omx_component_set_parameter (GST_OMX_VIDEO_ENC (self)->enc, OMX_IndexParamBrcmVideoAVCInlineHeaderEnable,
  181. +                                          &h264_enc_inline_header_param);
  182. +  if (err != OMX_ErrorNone) {
  183. +    GST_ERROR_OBJECT (self, "can't set OMX_IndexParamBrcmVideoAVCInlineHeaderEnable %s (0x%08x)", gst_omx_error_to_string (err), err);
  184. +    return FALSE;
  185. +  }
  186. +#endif
  187. +
  188. +  if(self->periodicty_idr != GST_OMX_H264_VIDEO_ENC_PERIODICITY_OF_IDR_FRAMES_DEFAULT ||
  189. +     self->interval_intraframes != GST_OMX_H264_VIDEO_ENC_INTERVAL_OF_CODING_INTRA_FRAMES_DEFAULT ) {
  190. +
  191. +
  192. +    GST_OMX_INIT_STRUCT (&video_avc_intra_period_param);
  193. +    video_avc_intra_period_param.nPortIndex = GST_OMX_VIDEO_ENC (self)->enc_out_port->index;
  194. +    err =  gst_omx_component_get_parameter (GST_OMX_VIDEO_ENC (self)->enc, OMX_IndexConfigVideoAVCIntraPeriod, &video_avc_intra_period_param);
  195. +    if (err != OMX_ErrorNone) {
  196. +      GST_ERROR_OBJECT (self, "can't get OMX_IndexConfigVideoAVCIntraPeriod %s (0x%08x)", gst_omx_error_to_string (err), err);
  197. +      return FALSE;
  198. +    }
  199. +
  200. +    GST_DEBUG_OBJECT(self, "default nPFrames:%u, nIDRPeriod:%u", video_avc_intra_period_param.nPFrames, video_avc_intra_period_param.nIDRPeriod);
  201. +
  202. +    if(self->periodicty_idr != GST_OMX_H264_VIDEO_ENC_PERIODICITY_OF_IDR_FRAMES_DEFAULT) {
  203. +      video_avc_intra_period_param.nIDRPeriod = self->periodicty_idr;
  204. +    }
  205. +
  206. +    if(self->interval_intraframes != GST_OMX_H264_VIDEO_ENC_INTERVAL_OF_CODING_INTRA_FRAMES_DEFAULT) {
  207. +      video_avc_intra_period_param.nPFrames = self->interval_intraframes;
  208. +    }
  209. +
  210. +    err =  gst_omx_component_set_parameter (GST_OMX_VIDEO_ENC (self)->enc, OMX_IndexConfigVideoAVCIntraPeriod,
  211. +                                            &video_avc_intra_period_param);
  212. +    if (err != OMX_ErrorNone) {
  213. +      GST_ERROR_OBJECT (self, "can't set OMX_IndexConfigVideoAVCIntraPeriod %s (0x%08x)", gst_omx_error_to_string (err), err);
  214. +      return FALSE;
  215. +    }
  216. +  }
  217. +
  218. +
  219. +
  220.    gst_omx_port_get_port_definition (GST_OMX_VIDEO_ENC (self)->enc_out_port,
  221.        &port_def);
  222.    port_def.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC;
  223. @@ -99,12 +264,12 @@
  224.    if (err != OMX_ErrorNone)
  225.      return FALSE;
  226.  
  227. -  GST_OMX_INIT_STRUCT (&param);
  228. -  param.nPortIndex = GST_OMX_VIDEO_ENC (self)->enc_out_port->index;
  229. +  GST_OMX_INIT_STRUCT (&h264_profile_level_param);
  230. +  h264_profile_level_param.nPortIndex = GST_OMX_VIDEO_ENC (self)->enc_out_port->index;
  231.  
  232.    err =
  233.        gst_omx_component_get_parameter (GST_OMX_VIDEO_ENC (self)->enc,
  234. -      OMX_IndexParamVideoProfileLevelCurrent, &param);
  235. +      OMX_IndexParamVideoProfileLevelCurrent, &h264_profile_level_param);
  236.    if (err != OMX_ErrorNone) {
  237.      GST_WARNING_OBJECT (self,
  238.          "Setting profile/level not supported by component");
  239. @@ -126,19 +291,19 @@
  240.      profile_string = gst_structure_get_string (s, "profile");
  241.      if (profile_string) {
  242.        if (g_str_equal (profile_string, "baseline")) {
  243. -        param.eProfile = OMX_VIDEO_AVCProfileBaseline;
  244. +        h264_profile_level_param.eProfile = OMX_VIDEO_AVCProfileBaseline;
  245.        } else if (g_str_equal (profile_string, "main")) {
  246. -        param.eProfile = OMX_VIDEO_AVCProfileMain;
  247. +        h264_profile_level_param.eProfile = OMX_VIDEO_AVCProfileMain;
  248.        } else if (g_str_equal (profile_string, "extended")) {
  249. -        param.eProfile = OMX_VIDEO_AVCProfileExtended;
  250. +        h264_profile_level_param.eProfile = OMX_VIDEO_AVCProfileExtended;
  251.        } else if (g_str_equal (profile_string, "high")) {
  252. -        param.eProfile = OMX_VIDEO_AVCProfileHigh;
  253. +        h264_profile_level_param.eProfile = OMX_VIDEO_AVCProfileHigh;
  254.        } else if (g_str_equal (profile_string, "high-10")) {
  255. -        param.eProfile = OMX_VIDEO_AVCProfileHigh10;
  256. +        h264_profile_level_param.eProfile = OMX_VIDEO_AVCProfileHigh10;
  257.        } else if (g_str_equal (profile_string, "high-4:2:2")) {
  258. -        param.eProfile = OMX_VIDEO_AVCProfileHigh422;
  259. +        h264_profile_level_param.eProfile = OMX_VIDEO_AVCProfileHigh422;
  260.        } else if (g_str_equal (profile_string, "high-4:4:4")) {
  261. -        param.eProfile = OMX_VIDEO_AVCProfileHigh444;
  262. +        h264_profile_level_param.eProfile = OMX_VIDEO_AVCProfileHigh444;
  263.        } else {
  264.          goto unsupported_profile;
  265.        }
  266. @@ -146,37 +311,37 @@
  267.      level_string = gst_structure_get_string (s, "level");
  268.      if (level_string) {
  269.        if (g_str_equal (level_string, "1")) {
  270. -        param.eLevel = OMX_VIDEO_AVCLevel1;
  271. +        h264_profile_level_param.eLevel = OMX_VIDEO_AVCLevel1;
  272.        } else if (g_str_equal (level_string, "1b")) {
  273. -        param.eLevel = OMX_VIDEO_AVCLevel1b;
  274. +        h264_profile_level_param.eLevel = OMX_VIDEO_AVCLevel1b;
  275.        } else if (g_str_equal (level_string, "1.1")) {
  276. -        param.eLevel = OMX_VIDEO_AVCLevel11;
  277. +        h264_profile_level_param.eLevel = OMX_VIDEO_AVCLevel11;
  278.        } else if (g_str_equal (level_string, "1.2")) {
  279. -        param.eLevel = OMX_VIDEO_AVCLevel12;
  280. +        h264_profile_level_param.eLevel = OMX_VIDEO_AVCLevel12;
  281.        } else if (g_str_equal (level_string, "1.3")) {
  282. -        param.eLevel = OMX_VIDEO_AVCLevel13;
  283. +        h264_profile_level_param.eLevel = OMX_VIDEO_AVCLevel13;
  284.        } else if (g_str_equal (level_string, "2")) {
  285. -        param.eLevel = OMX_VIDEO_AVCLevel2;
  286. +        h264_profile_level_param.eLevel = OMX_VIDEO_AVCLevel2;
  287.        } else if (g_str_equal (level_string, "2.1")) {
  288. -        param.eLevel = OMX_VIDEO_AVCLevel21;
  289. +        h264_profile_level_param.eLevel = OMX_VIDEO_AVCLevel21;
  290.        } else if (g_str_equal (level_string, "2.2")) {
  291. -        param.eLevel = OMX_VIDEO_AVCLevel22;
  292. +        h264_profile_level_param.eLevel = OMX_VIDEO_AVCLevel22;
  293.        } else if (g_str_equal (level_string, "3")) {
  294. -        param.eLevel = OMX_VIDEO_AVCLevel3;
  295. +        h264_profile_level_param.eLevel = OMX_VIDEO_AVCLevel3;
  296.        } else if (g_str_equal (level_string, "3.1")) {
  297. -        param.eLevel = OMX_VIDEO_AVCLevel31;
  298. +        h264_profile_level_param.eLevel = OMX_VIDEO_AVCLevel31;
  299.        } else if (g_str_equal (level_string, "3.2")) {
  300. -        param.eLevel = OMX_VIDEO_AVCLevel32;
  301. +        h264_profile_level_param.eLevel = OMX_VIDEO_AVCLevel32;
  302.        } else if (g_str_equal (level_string, "4")) {
  303. -        param.eLevel = OMX_VIDEO_AVCLevel4;
  304. +        h264_profile_level_param.eLevel = OMX_VIDEO_AVCLevel4;
  305.        } else if (g_str_equal (level_string, "4.1")) {
  306. -        param.eLevel = OMX_VIDEO_AVCLevel41;
  307. +        h264_profile_level_param.eLevel = OMX_VIDEO_AVCLevel41;
  308.        } else if (g_str_equal (level_string, "4.2")) {
  309. -        param.eLevel = OMX_VIDEO_AVCLevel42;
  310. +        h264_profile_level_param.eLevel = OMX_VIDEO_AVCLevel42;
  311.        } else if (g_str_equal (level_string, "5")) {
  312. -        param.eLevel = OMX_VIDEO_AVCLevel5;
  313. +        h264_profile_level_param.eLevel = OMX_VIDEO_AVCLevel5;
  314.        } else if (g_str_equal (level_string, "5.1")) {
  315. -        param.eLevel = OMX_VIDEO_AVCLevel51;
  316. +        h264_profile_level_param.eLevel = OMX_VIDEO_AVCLevel51;
  317.        } else {
  318.          goto unsupported_level;
  319.        }
  320. @@ -186,14 +351,14 @@
  321.  
  322.    err =
  323.        gst_omx_component_set_parameter (GST_OMX_VIDEO_ENC (self)->enc,
  324. -      OMX_IndexParamVideoProfileLevelCurrent, &param);
  325. +      OMX_IndexParamVideoProfileLevelCurrent, &h264_profile_level_param);
  326.    if (err == OMX_ErrorUnsupportedIndex) {
  327.      GST_WARNING_OBJECT (self,
  328.          "Setting profile/level not supported by component");
  329.    } else if (err != OMX_ErrorNone) {
  330.      GST_ERROR_OBJECT (self,
  331.          "Error setting profile %u and level %u: %s (0x%08x)",
  332. -        (guint) param.eProfile, (guint) param.eLevel,
  333. +        (guint) h264_profile_level_param.eProfile, (guint) h264_profile_level_param.eLevel,
  334.          gst_omx_error_to_string (err), err);
  335.      return FALSE;
  336.    }
  337. --- gst-omx_old/omx/gstomxh264enc.h     2014-01-03 21:07:09.000000000 +0000
  338. +++ gst-omx/omx/gstomxh264enc.h 2014-01-08 23:07:52.050031499 +0000
  339. @@ -45,6 +45,10 @@
  340.  struct _GstOMXH264Enc
  341.  {
  342.    GstOMXVideoEnc parent;
  343. +
  344. +  gboolean inline_sps_pps_headers;
  345. +  guint32 periodicty_idr;
  346. +  guint32 interval_intraframes;
  347.  };
  348.  
  349.  struct _GstOMXH264EncClass
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top