} else
pa_assert_not_reached();
- /*
- * The common encoder/decoder initialisation functions need to be called
- * before the codec specific ones, as the codec specific initialisation
- * function needs to set the caps specific property appropriately on the
- * appsrc and appsink as per the sample spec and the codec.
- */
- if (for_encoding) {
- if (!gst_init_enc_common(info))
- goto fail;
- } else {
- if (!gst_init_dec_common(info))
- goto fail;
- }
-
if (!gst_init_aptx(info, sample_spec, for_encoding))
- goto enc_dec_fail;
+ goto fail;
if (!gst_codec_init(info, for_encoding))
- goto enc_dec_fail;
+ goto fail;
return info;
-enc_dec_fail:
- if (for_encoding)
- gst_deinit_enc_common(info);
- else
- gst_deinit_dec_common(info);
fail:
if (info)
pa_xfree(info);
return GST_FLOW_OK;
}
-void gst_deinit_enc_common(struct gst_info *info) {
+static void gst_deinit_enc_common(struct gst_info *info) {
if (!info)
return;
if (info->enc_fdsem)
gst_object_unref(info->enc_pipeline);
}
-void gst_deinit_dec_common(struct gst_info *info) {
+static void gst_deinit_dec_common(struct gst_info *info) {
if (!info)
return;
if (info->dec_fdsem)
info->seq_num = 0;
+ if (for_encoding) {
+ if (!gst_init_enc_common(info))
+ goto fail_common;
+ } else {
+ if (!gst_init_dec_common(info))
+ goto fail_common;
+ }
+
caps = gst_create_caps_from_sample_spec(info->ss);
/* In case if we ever have a codec which supports decoding but not encoding */
- if (for_encoding && info->enc_bin) {
+ if (for_encoding) {
+ pa_assert(info->enc_bin);
+
g_object_set(info->enc_src, "caps", caps, NULL);
gst_caps_unref(caps);
pad = gst_element_get_static_pad(info->enc_bin, "sink");
gst_pad_add_probe(pad, GST_PAD_PROBE_TYPE_BUFFER, gst_encoder_buffer_probe, info, NULL);
gst_object_unref(pad);
- } else if (!for_encoding && info->dec_bin) {
+ } else {
+ pa_assert(info->dec_bin);
+
g_object_set(info->dec_sink, "caps", caps, NULL);
gst_caps_unref(caps);
pad = gst_element_get_static_pad(info->dec_bin, "sink");
gst_pad_add_probe(pad, GST_PAD_PROBE_TYPE_BUFFER, gst_decoder_buffer_probe, info, NULL);
gst_object_unref(pad);
- } else
- pa_assert_not_reached();
+ }
- pa_log_info("Gstreamer pipeline initialisation succeeded");
+ pa_log_info("GStreamer pipeline initialisation succeeded");
return true;
else
gst_deinit_dec_common(info);
- pa_log_error("Gstreamer pipeline initialisation failed");
+ pa_log_error("GStreamer pipeline initialisation failed");
+
+ return false;
+
+fail_common:
+ /* If common initialization fails these have not had their ownership
+ * transferred to the pipeline yet.
+ */
+ if (for_encoding)
+ gst_object_unref(info->enc_bin);
+ else
+ gst_object_unref(info->dec_bin);
+
+
+ pa_log_error("GStreamer pipeline creation failed");
return false;
}
size_t gst_encode_buffer(void *codec_info, uint32_t timestamp, const uint8_t *input_buffer, size_t input_size, uint8_t *output_buffer, size_t output_size, size_t *processed);
size_t gst_decode_buffer(void *codec_info, const uint8_t *input_buffer, size_t input_size, uint8_t *output_buffer, size_t output_size, size_t *processed);
void gst_codec_deinit(void *codec_info);
-
-bool gst_init_enc_common(struct gst_info *info);
-bool gst_init_dec_common(struct gst_info *info);
-void gst_deinit_enc_common(struct gst_info *info);
-void gst_deinit_dec_common(struct gst_info *info);
static void *init_common(enum a2dp_codec_type codec_type, bool for_encoding, bool for_backchannel, const uint8_t *config_buffer, uint8_t config_size, pa_sample_spec *sample_spec, pa_core *core) {
struct gst_info *info = NULL;
+ if (!for_encoding) {
+ pa_log_error("LDAC decoder not supported");
+ return NULL;
+ }
+
info = pa_xnew0(struct gst_info, 1);
pa_assert(info);
info->a2dp_codec_t.ldac_config = (const a2dp_ldac_t *) config_buffer;
pa_assert(config_size == sizeof(*(info->a2dp_codec_t.ldac_config)));
- /*
- * The common encoder/decoder initialisation functions need to be called
- * before the codec specific ones, as the codec specific initialisation
- * function needs to set the caps specific property appropriately on the
- * appsrc and appsink as per the sample spec and the codec.
- */
- if (!gst_init_enc_common(info))
- goto fail;
-
if (!gst_init_ldac(info, sample_spec, for_encoding))
- goto enc_fail;
+ goto fail;
if (!gst_codec_init(info, for_encoding))
- goto enc_fail;
+ goto fail;
return info;
-enc_fail:
- gst_deinit_enc_common(info);
fail:
if (info)
pa_xfree(info);