gstdspjpegenc.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright (C) 2009-2010 Felipe Contreras
  3. *
  4. * Author: Felipe Contreras <felipe.contreras@gmail.com>
  5. *
  6. * This file may be used under the terms of the GNU Lesser General Public
  7. * License version 2.1, a copy of which is found in LICENSE included in the
  8. * packaging of this file.
  9. */
  10. #include "gstdspjpegenc.h"
  11. #include "plugin.h"
  12. #include "util.h"
  13. #include "dsp_bridge.h"
  14. #include "log.h"
  15. #define GST_CAT_DEFAULT gstdsp_debug
  16. #define DEFAULT_ENCODING_QUALITY 90
  17. enum {
  18. ARG_0,
  19. ARG_QUALITY,
  20. };
  21. static void
  22. set_property(GObject *obj,
  23. guint prop_id,
  24. const GValue *value,
  25. GParamSpec *pspec)
  26. {
  27. GstDspVEnc *self = GST_DSP_VENC(obj);
  28. switch (prop_id) {
  29. case ARG_QUALITY: {
  30. if (GST_STATE(self) == GST_STATE_NULL) {
  31. guint quality;
  32. quality = g_value_get_uint(value);
  33. g_atomic_int_set(&self->quality, quality);
  34. } else {
  35. GST_WARNING_OBJECT(self,
  36. "encoding quality property can be set only in NULL state");
  37. }
  38. break;
  39. }
  40. default:
  41. G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);
  42. break;
  43. }
  44. }
  45. static void
  46. get_property(GObject *obj,
  47. guint prop_id,
  48. GValue *value,
  49. GParamSpec *pspec)
  50. {
  51. GstDspVEnc *self = GST_DSP_VENC(obj);
  52. switch (prop_id) {
  53. case ARG_QUALITY:
  54. g_value_set_uint(value, g_atomic_int_get(&self->quality));
  55. break;
  56. default:
  57. G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);
  58. break;
  59. }
  60. }
  61. static inline GstCaps *
  62. generate_src_template(void)
  63. {
  64. GstCaps *caps;
  65. GstStructure *struc;
  66. caps = gst_caps_new_empty();
  67. struc = gst_structure_new("image/jpeg",
  68. NULL);
  69. gst_caps_append_structure(caps, struc);
  70. return caps;
  71. }
  72. static void
  73. instance_init(GTypeInstance *instance,
  74. gpointer g_class)
  75. {
  76. GstDspBase *base = GST_DSP_BASE(instance);
  77. GstDspVEnc *self = GST_DSP_VENC(instance);
  78. base->alg = GSTDSP_JPEGENC;
  79. base->codec = &td_jpegenc_codec;
  80. base->eos_timeout = 0;
  81. base->use_pinned = true;
  82. self->quality = DEFAULT_ENCODING_QUALITY;
  83. }
  84. static void
  85. base_init(gpointer g_class)
  86. {
  87. GstElementClass *element_class;
  88. GstPadTemplate *template;
  89. GstCaps *caps;
  90. element_class = GST_ELEMENT_CLASS(g_class);
  91. gst_element_class_set_details_simple(element_class,
  92. "DSP video encoder",
  93. "Codec/Encoder/Image",
  94. "Encodes JPEG images with TI's DSP algorithms",
  95. "Felipe Contreras");
  96. template = gst_pad_template_new("src", GST_PAD_SRC,
  97. GST_PAD_ALWAYS,
  98. generate_src_template());
  99. gst_element_class_add_pad_template(element_class, template);
  100. gst_object_unref(template);
  101. /* publicly announce specific w/h restrictions */
  102. template = gst_element_class_get_pad_template(element_class, "sink");
  103. caps = gst_pad_template_get_caps(template);
  104. gst_caps_set_simple(caps,
  105. "width", GST_TYPE_INT_RANGE, 16, JPEGENC_MAX_WIDTH,
  106. "height", GST_TYPE_INT_RANGE, 16, JPEGENC_MAX_HEIGHT,
  107. NULL);
  108. }
  109. static void
  110. class_init(gpointer g_class,
  111. gpointer class_data)
  112. {
  113. GObjectClass *gobject_class;
  114. gobject_class = (GObjectClass *) g_class;
  115. gobject_class->set_property = set_property;
  116. gobject_class->get_property = get_property;
  117. g_object_class_install_property(gobject_class, ARG_QUALITY,
  118. g_param_spec_uint("encoding-quality", "Encoding quality",
  119. "Encoding quality level", 1, 100, DEFAULT_ENCODING_QUALITY,
  120. G_PARAM_READWRITE));
  121. }
  122. GType
  123. gst_dsp_jpegenc_get_type(void)
  124. {
  125. static GType type;
  126. if (G_UNLIKELY(type == 0)) {
  127. GTypeInfo type_info = {
  128. .class_size = sizeof(GstDspJpegEncClass),
  129. .base_init = base_init,
  130. .class_init = class_init,
  131. .instance_size = sizeof(GstDspJpegEnc),
  132. .instance_init = instance_init,
  133. };
  134. type = g_type_register_static(GST_DSP_VENC_TYPE, "GstDspJpegEnc", &type_info, 0);
  135. }
  136. return type;
  137. }