static inline bool destroy_node(struct dsp_node *node) { if (node) { if (!dsp_node_free(dsp_handle, node)) { pr_err("dsp node free failed"); return false; } pr_info("dsp node deleted"); } return true; }
static inline bool destroy_node(int dsp_handle, dsp_node_t *node) { if (node) { if (!dsp_node_free(dsp_handle, node)) { GST_ERROR("dsp node free failed"); return false; } GST_INFO("dsp node deleted"); } return true; }
static void * create_node(GstDspBase *base) { GstDspVpp *self; struct td_codec *codec; int dsp_handle; struct dsp_node *node; const struct dsp_uuid usn_uuid = { 0x79A3C8B3, 0x95F2, 0x403F, 0x9A, 0x4B, { 0xCF, 0x80, 0x57, 0x73, 0x05, 0x41 } }; self = GST_DSP_VPP(base); dsp_handle = base->dsp_handle; if (!gstdsp_register(dsp_handle, &usn_uuid, DSP_DCD_LIBRARYTYPE, "usn.dll64P")) { pr_err(self, "failed to register usn node library"); return NULL; } codec = base->codec; if (!codec) { pr_err(self, "unknown algorithm"); return NULL; } pr_info(base, "algo=%s", codec->filename); if (!gstdsp_register(dsp_handle, codec->uuid, DSP_DCD_LIBRARYTYPE, codec->filename)) { pr_err(self, "failed to register algo node library"); return NULL; } if (!gstdsp_register(dsp_handle, codec->uuid, DSP_DCD_NODETYPE, codec->filename)) { pr_err(self, "failed to register algo node"); return NULL; } { struct dsp_node_attr_in attrs = { .cb = sizeof(attrs), .priority = 5, .timeout = 1000, }; void *arg_data; codec->create_args(base, &attrs.profile_id, &arg_data); if (!arg_data) return NULL; if (!dsp_node_allocate(dsp_handle, base->proc, codec->uuid, arg_data, &attrs, &node)) { pr_err(self, "dsp node allocate failed"); free(arg_data); return NULL; } free(arg_data); } if (!dsp_node_create(dsp_handle, node)) { pr_err(self, "dsp node create failed"); dsp_node_free(dsp_handle, node); return NULL; } pr_info(self, "dsp node created"); if (codec->setup_params) codec->setup_params(base); if (codec->send_params) codec->send_params(base, node); return node; } static inline bool destroy_node(GstDspVpp *self, int dsp_handle, struct dsp_node *node) { if (node) { if (!dsp_node_free(dsp_handle, node)) { pr_err(self, "dsp node free failed"); return false; } pr_info(self, "dsp node deleted"); } return true; } static inline void configure_caps(GstDspVpp *self, GstCaps *in, GstCaps *out) { GstDspBase *base; GstStructure *out_struc, *in_struc; const GValue *aspect_ratio; const GValue *framerate; GstCaps *allowed_caps; base = GST_DSP_BASE(self); in_struc = gst_caps_get_structure(in, 0); out_struc = gst_structure_new("video/x-raw-yuv", "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC('I', '4', '2', '0'), NULL); if (gst_structure_get_int(in_struc, "width", &self->width)) self->out_width = self->width; if (gst_structure_get_int(in_struc, "height", &self->height)) self->out_height = self->height; allowed_caps = gst_pad_get_allowed_caps(base->srcpad); if (allowed_caps) { if (gst_caps_get_size(allowed_caps) > 0) { GstStructure *s; s = gst_caps_get_structure(allowed_caps, 0); gst_structure_get_int(s, "width", &self->out_width); gst_structure_get_int(s, "height", &self->out_height); } gst_caps_unref(allowed_caps); } gst_structure_set(out_struc, "width", G_TYPE_INT, self->out_width, NULL); gst_structure_set(out_struc, "height", G_TYPE_INT, self->out_height, NULL); aspect_ratio = gst_structure_get_value(in_struc, "pixel-aspect-ratio"); if (aspect_ratio) gst_structure_set_value(out_struc, "pixel-aspect-ratio", aspect_ratio); framerate = gst_structure_get_value(in_struc, "framerate"); if (framerate) gst_structure_set_value(out_struc, "framerate", framerate); base->output_buffer_size = self->out_width * self->out_height * 1.5; gst_caps_append_structure(out, out_struc); }
static inline void * create_node(GstDspVEnc *self) { GstDspBase *base; int dsp_handle; struct dsp_node *node; struct td_codec *codec; const struct dsp_uuid usn_uuid = { 0x79A3C8B3, 0x95F2, 0x403F, 0x9A, 0x4B, { 0xCF, 0x80, 0x57, 0x73, 0x05, 0x41 } }; const struct dsp_uuid conversions_uuid = { 0x722DD0DA, 0xF532, 0x4238, 0xB8, 0x46, { 0xAB, 0xFF, 0x5D, 0xA4, 0xBA, 0x02 } }; base = GST_DSP_BASE(self); dsp_handle = base->dsp_handle; if (!gstdsp_register(dsp_handle, &usn_uuid, DSP_DCD_LIBRARYTYPE, "usn.dll64P")) { pr_err(self, "failed to register usn node library"); return NULL; } codec = base->codec; if (!codec) { pr_err(self, "unknown algorithm"); return NULL; } if (!gstdsp_register(dsp_handle, codec->uuid, DSP_DCD_LIBRARYTYPE, codec->filename)) { pr_err(self, "failed to register algo node library"); return NULL; } if (!gstdsp_register(dsp_handle, codec->uuid, DSP_DCD_NODETYPE, codec->filename)) { pr_err(self, "failed to register algo node"); return NULL; } /* only needed for jpegenc */ if (base->alg == GSTDSP_JPEGENC) { /* SN_API == 0 doesn't have it, so don't fail */ (void) gstdsp_register(dsp_handle, &conversions_uuid, DSP_DCD_LIBRARYTYPE, "conversions.dll64P"); } { struct dsp_node_attr_in attrs = { .cb = sizeof(attrs), .priority = 5, .timeout = 1000, }; void *arg_data; codec->create_args(base, &attrs.profile_id, &arg_data); if (!arg_data) return NULL; if (!dsp_node_allocate(dsp_handle, base->proc, codec->uuid, arg_data, &attrs, &node)) { pr_err(self, "dsp node allocate failed"); free(arg_data); return NULL; } free(arg_data); } if (!dsp_node_create(dsp_handle, node)) { pr_err(self, "dsp node create failed"); dsp_node_free(dsp_handle, node); return NULL; } pr_info(self, "dsp node created"); return node; } static void check_supported_levels(GstDspVEnc *self, gint tgt_level) { guint i; gint tgt_mbps, tgt_mbpf, tgt_bitrate; struct gstdsp_codec_level *cur, *level; if (!self->supported_levels) return; tgt_bitrate = self->user_max_bitrate; tgt_mbpf = ROUND_UP(self->width, 16) / 16 * ROUND_UP(self->height, 16) / 16; tgt_mbps = tgt_mbpf * self->framerate; if (!tgt_bitrate) tgt_bitrate = self->bitrate; search: level = cur = self->supported_levels; for (i = 0; i < self->nr_supported_levels; i++, cur++) { bool ok = false; /* is this the level we want? */ if (tgt_level > 0 && tgt_level != cur->id) continue; /* is the bitrate enough? (and doesn't overshoot) */ if (tgt_bitrate && cur->bitrate >= tgt_bitrate && level->bitrate < tgt_bitrate) ok = true; /* are the mbps enough? (and don't overshoot) */ if (cur->mbps >= tgt_mbps && level->mbps < tgt_mbps) ok = true; /* at same level of mbps, get the biggest bitrate */ if (cur->mbps >= tgt_mbps && cur->mbps == level->mbps && !tgt_bitrate && cur->bitrate >= level->bitrate) ok = true; /* are the mbpf enough? (and don't overshoot) */ if (cur->mbpf >= tgt_mbpf && level->mbpf < tgt_mbpf) ok = true; if (!ok) continue; /* we got a winner */ level = cur; } if (tgt_level > 0 && tgt_level != level->id) { pr_warning(self, "invalid level: %d; ignoring", tgt_level); tgt_level = -1; goto search; } /* went beyond the table looking for a target; pick last one */ if ((tgt_bitrate && level->bitrate < tgt_bitrate) || (level->mbps < tgt_mbps)) { if (tgt_level > 0) { pr_warning(self, "invalid level: %d; ignoring", tgt_level); tgt_level = -1; goto search; } else level = --cur; } if (!self->user_max_bitrate || self->user_max_bitrate >= level->bitrate) self->max_bitrate = level->bitrate; else self->max_bitrate = self->user_max_bitrate; self->level = level->id; pr_info(self, "level bitrate: %d", level->bitrate); pr_info(self, "max bitrate: %d", self->max_bitrate); pr_info(self, "level: %d", self->level); }
static void * create_node(GstDspBase *base) { GstDspADec *self; struct td_codec *codec; int dsp_handle; struct dsp_node *node; const struct dsp_uuid usn_uuid = { 0x79A3C8B3, 0x95F2, 0x403F, 0x9A, 0x4B, { 0xCF, 0x80, 0x57, 0x73, 0x05, 0x41 } }; self = GST_DSP_ADEC(base); dsp_handle = base->dsp_handle; if (!gstdsp_register(dsp_handle, &usn_uuid, DSP_DCD_LIBRARYTYPE, "usn.dll64P")) { pr_err(self, "failed to register usn node library"); return NULL; } codec = base->codec; if (!codec) { pr_err(self, "unknown algorithm"); return NULL; } pr_info(base, "algo=%s", codec->filename); if (!gstdsp_register(dsp_handle, codec->uuid, DSP_DCD_LIBRARYTYPE, codec->filename)) { pr_err(self, "failed to register algo node library"); return NULL; } if (!gstdsp_register(dsp_handle, codec->uuid, DSP_DCD_NODETYPE, codec->filename)) { pr_err(self, "failed to register algo node"); return NULL; } { struct dsp_node_attr_in attrs = { .cb = sizeof(attrs), .priority = 10, .timeout = 10000, }; void *arg_data; codec->create_args(base, &attrs.profile_id, &arg_data); if (!arg_data) return NULL; if (!dsp_node_allocate(dsp_handle, base->proc, codec->uuid, arg_data, &attrs, &node)) { pr_err(self, "dsp node allocate failed"); free(arg_data); return NULL; } free(arg_data); } if (!dsp_node_create(dsp_handle, node)) { pr_err(self, "dsp node create failed"); dsp_node_free(dsp_handle, node); return NULL; } pr_info(self, "dsp node created"); if (codec->send_params) codec->send_params(base, node); if (codec->setup_params) codec->setup_params(base); base->flush_buffer = codec->flush_buffer; return node; } static inline void configure_caps(GstDspADec *self, GstCaps *in, GstCaps *out) { GstDspBase *base; GstStructure *out_struc, *in_struc; int channels; base = GST_DSP_BASE(self); in_struc = gst_caps_get_structure(in, 0); out_struc = gst_structure_new("audio/x-raw-int", "endianness", G_TYPE_INT, G_BYTE_ORDER, "signed", G_TYPE_BOOLEAN, TRUE, "width", G_TYPE_INT, 16, "depth", G_TYPE_INT, 16, NULL); if (gst_structure_get_int(in_struc, "channels", &channels)) gst_structure_set(out_struc, "channels", G_TYPE_INT, channels, NULL); if (gst_structure_get_int(in_struc, "rate", &self->samplerate)) gst_structure_set(out_struc, "rate", G_TYPE_INT, self->samplerate, NULL); if (base->alg == GSTDSP_AACDEC) { const char *fmt; gboolean tmp; gst_structure_get_boolean(in_struc, "framed", &tmp); self->packetized = tmp; fmt = gst_structure_get_string(in_struc, "stream-format"); self->raw = strcmp(fmt, "raw") == 0; } base->output_buffer_size = 4 * 1024; gst_caps_append_structure(out, out_struc); }