gstdsph264enc.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Copyright (C) 2009-2010 Felipe Contreras
  3. * Copyright (C) 2009-2010 Nokia Corporation
  4. *
  5. * Authors:
  6. * Juha Alanen <juha.m.alanen@nokia.com>
  7. * Felipe Contreras <felipe.contreras@nokia.com>
  8. *
  9. * This file may be used under the terms of the GNU Lesser General Public
  10. * License version 2.1, a copy of which is found in LICENSE included in the
  11. * packaging of this file.
  12. */
  13. #include "gstdsph264enc.h"
  14. #include "plugin.h"
  15. #include "util.h"
  16. #include "dsp_bridge.h"
  17. #include "log.h"
  18. #define GST_CAT_DEFAULT gstdsp_debug
  19. /*
  20. * H.264 supported levels
  21. * Source http://www.itu.int/rec/T-REC-H.264-201003-I/ page 294 - Annex A table A-1
  22. * the bitrates of the last 2 levels is not up to standard due to encdoder
  23. * limitations.
  24. */
  25. static struct gstdsp_codec_level levels[] = {
  26. {10, 99, 1485 , 64000 }, /* Level 1 - QCIF@15fps */
  27. {10, 99, 1485 , 128000 }, /* Level 1b - QCIF@15fps */
  28. {11, 396, 3000 , 192000 }, /* Level 1.1 - QCIF@30fps */
  29. {12, 396, 6000 , 384000 }, /* Level 1.2 - CIF@15fps */
  30. {13, 396, 11880 , 768000 }, /* Level 1.3- CIF@30fps */
  31. {20, 396, 11880 , 2000000 }, /* Level 2 - CIF@30fps */
  32. {21, 792, 19800 , 4000000 }, /* Level 2.1 - 352x480@30fps */
  33. {22, 1620, 20250 , 4000000 }, /* Level 2.2 - 720x480@15fps */
  34. {30, 1620, 40500 , 8000000 }, /* Level 3 - D1@25/30fps (PAL/NTSC) --> 10Mbps */
  35. {31, 3600, 48600 , 8000000 }, /* Max supported (WVGA) - 864x480@30fps */
  36. };
  37. enum {
  38. ARG_0,
  39. #ifdef GST_DSP_ENABLE_DEPRECATED
  40. ARG_BYTESTREAM,
  41. #endif
  42. };
  43. static inline GstCaps *
  44. generate_src_template(void)
  45. {
  46. GstCaps *caps;
  47. GstStructure *struc;
  48. caps = gst_caps_new_empty();
  49. struc = gst_structure_new("video/x-h264",
  50. NULL);
  51. gst_caps_append_structure(caps, struc);
  52. return caps;
  53. }
  54. static void
  55. instance_init(GTypeInstance *instance,
  56. gpointer g_class)
  57. {
  58. GstDspBase *base = GST_DSP_BASE(instance);
  59. GstDspVEnc *self = GST_DSP_VENC(instance);
  60. base->alg = GSTDSP_H264ENC;
  61. base->codec = &td_h264enc_codec;
  62. self->priv.h264.bytestream = true;
  63. self->supported_levels = levels;
  64. self->nr_supported_levels = ARRAY_SIZE(levels);
  65. base->use_pinned = true;
  66. }
  67. static void
  68. base_init(gpointer g_class)
  69. {
  70. GstElementClass *element_class;
  71. GstPadTemplate *template;
  72. element_class = GST_ELEMENT_CLASS(g_class);
  73. gst_element_class_set_details_simple(element_class,
  74. "DSP video encoder",
  75. "Codec/Encoder/Video",
  76. "Encodes H.264 video with TI's DSP algorithms",
  77. "Juha Alanen");
  78. template = gst_pad_template_new("src", GST_PAD_SRC,
  79. GST_PAD_ALWAYS,
  80. generate_src_template());
  81. gst_element_class_add_pad_template(element_class, template);
  82. gst_object_unref(template);
  83. }
  84. static void
  85. set_property(GObject *obj,
  86. guint prop_id,
  87. const GValue *value,
  88. GParamSpec *pspec)
  89. {
  90. GstDspVEnc *self G_GNUC_UNUSED = GST_DSP_VENC(obj);
  91. switch (prop_id) {
  92. #ifdef GST_DSP_ENABLE_DEPRECATED
  93. case ARG_BYTESTREAM:
  94. self->priv.h264.bytestream = g_value_get_boolean(value);
  95. break;
  96. #endif
  97. default:
  98. G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);
  99. break;
  100. }
  101. }
  102. static void
  103. get_property(GObject *obj,
  104. guint prop_id,
  105. GValue *value,
  106. GParamSpec *pspec)
  107. {
  108. GstDspVEnc *self G_GNUC_UNUSED = GST_DSP_VENC(obj);
  109. switch (prop_id) {
  110. #ifdef GST_DSP_ENABLE_DEPRECATED
  111. case ARG_BYTESTREAM:
  112. g_value_set_boolean(value, self->priv.h264.bytestream);
  113. break;
  114. #endif
  115. default:
  116. G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);
  117. break;
  118. }
  119. }
  120. static void
  121. class_init(gpointer g_class,
  122. gpointer class_data)
  123. {
  124. GObjectClass *gobject_class;
  125. gobject_class = G_OBJECT_CLASS(g_class);
  126. /* Properties stuff */
  127. gobject_class->set_property = set_property;
  128. gobject_class->get_property = get_property;
  129. #ifdef GST_DSP_ENABLE_DEPRECATED
  130. g_object_class_install_property(gobject_class, ARG_BYTESTREAM,
  131. g_param_spec_boolean("bytestream", "BYTESTREAM", "bytestream",
  132. true, G_PARAM_READWRITE));
  133. #endif
  134. }
  135. GType
  136. gst_dsp_h264enc_get_type(void)
  137. {
  138. static GType type;
  139. if (G_UNLIKELY(type == 0)) {
  140. GTypeInfo type_info = {
  141. .class_size = sizeof(GstDspH264EncClass),
  142. .base_init = base_init,
  143. .class_init = class_init,
  144. .instance_size = sizeof(GstDspH264Enc),
  145. .instance_init = instance_init,
  146. };
  147. type = g_type_register_static(GST_DSP_VENC_TYPE, "GstDspH264Enc", &type_info, 0);
  148. }
  149. return type;
  150. }