mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-29 19:50:40 +00:00
opus: properly setup caps and init state from caps
https://bugzilla.gnome.org/show_bug.cgi?id=660364
This commit is contained in:
parent
495de129ff
commit
f9d4dd5215
2 changed files with 47 additions and 37 deletions
|
@ -193,6 +193,8 @@ opus_dec_sink_setcaps (GstPad * pad, GstCaps * caps)
|
|||
GstStructure *s;
|
||||
const GValue *streamheader;
|
||||
|
||||
GST_DEBUG_OBJECT (pad, "Setting sink caps to %" GST_PTR_FORMAT, caps);
|
||||
|
||||
s = gst_caps_get_structure (caps, 0);
|
||||
if ((streamheader = gst_structure_get_value (s, "streamheader")) &&
|
||||
G_VALUE_HOLDS (streamheader, GST_TYPE_ARRAY) &&
|
||||
|
@ -237,6 +239,47 @@ opus_dec_sink_setcaps (GstPad * pad, GstCaps * caps)
|
|||
}
|
||||
}
|
||||
|
||||
if (!gst_structure_get_int (s, "frame-size", &dec->frame_size)) {
|
||||
GST_WARNING_OBJECT (dec, "Frame size not included in caps");
|
||||
}
|
||||
if (!gst_structure_get_int (s, "channels", &dec->n_channels)) {
|
||||
GST_WARNING_OBJECT (dec, "Number of channels not included in caps");
|
||||
}
|
||||
if (!gst_structure_get_int (s, "rate", &dec->sample_rate)) {
|
||||
GST_WARNING_OBJECT (dec, "Sample rate not included in caps");
|
||||
}
|
||||
switch (dec->frame_size) {
|
||||
case 2:
|
||||
dec->frame_samples = dec->sample_rate / 400;
|
||||
break;
|
||||
case 5:
|
||||
dec->frame_samples = dec->sample_rate / 200;
|
||||
break;
|
||||
case 10:
|
||||
dec->frame_samples = dec->sample_rate / 100;
|
||||
break;
|
||||
case 20:
|
||||
dec->frame_samples = dec->sample_rate / 50;
|
||||
break;
|
||||
case 40:
|
||||
dec->frame_samples = dec->sample_rate / 25;
|
||||
break;
|
||||
case 60:
|
||||
dec->frame_samples = 3 * dec->sample_rate / 50;
|
||||
break;
|
||||
default:
|
||||
GST_WARNING_OBJECT (dec, "Unsupported frame size: %d", dec->frame_size);
|
||||
break;
|
||||
}
|
||||
|
||||
dec->frame_duration = gst_util_uint64_scale_int (dec->frame_samples,
|
||||
GST_SECOND, dec->sample_rate);
|
||||
|
||||
GST_INFO_OBJECT (dec,
|
||||
"Got frame size %d, %d channels, %d Hz, giving %d samples per frame, frame duration %"
|
||||
GST_TIME_FORMAT, dec->frame_size, dec->n_channels, dec->sample_rate,
|
||||
dec->frame_samples, GST_TIME_ARGS (dec->frame_duration));
|
||||
|
||||
done:
|
||||
gst_object_unref (dec);
|
||||
return ret;
|
||||
|
@ -788,6 +831,10 @@ opus_dec_chain (GstPad * pad, GstBuffer * buf)
|
|||
GstOpusDec *dec;
|
||||
|
||||
dec = GST_OPUS_DEC (gst_pad_get_parent (pad));
|
||||
GST_LOG_OBJECT (pad,
|
||||
"Got buffer ts %" GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
|
||||
GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
|
||||
|
||||
if (GST_BUFFER_IS_DISCONT (buf)) {
|
||||
dec->discont = TRUE;
|
||||
|
|
|
@ -879,29 +879,10 @@ gst_opus_enc_chain (GstPad * pad, GstBuffer * buf)
|
|||
if (!enc->setup)
|
||||
goto not_setup;
|
||||
|
||||
#if 0
|
||||
if (!enc->header_sent) {
|
||||
/* Opus streams begin with two headers; the initial header (with
|
||||
most of the codec setup parameters) which is mandated by the Ogg
|
||||
bitstream spec. The second header holds any comment fields.
|
||||
We merely need to make the headers, then pass them to libopus
|
||||
one at a time; libopus handles the additional Ogg bitstream
|
||||
constraints */
|
||||
GstBuffer *buf1, *buf2;
|
||||
GstCaps *caps;
|
||||
guchar data[100];
|
||||
|
||||
/* create header buffer */
|
||||
opus_header_to_packet (&enc->header, data, 100);
|
||||
buf1 = gst_opus_enc_buffer_from_data (enc, data, 100, 0);
|
||||
|
||||
/* create comment buffer */
|
||||
buf2 = gst_opus_enc_create_metadata_buffer (enc);
|
||||
|
||||
/* mark and put on caps */
|
||||
caps = gst_pad_get_caps (enc->srcpad);
|
||||
caps = gst_opus_enc_set_header_on_caps (caps, buf1, buf2);
|
||||
|
||||
gst_caps_set_simple (caps,
|
||||
"rate", G_TYPE_INT, enc->sample_rate,
|
||||
"channels", G_TYPE_INT, enc->n_channels,
|
||||
|
@ -913,26 +894,8 @@ gst_opus_enc_chain (GstPad * pad, GstBuffer * buf)
|
|||
enc->sample_rate, enc->n_channels, enc->frame_size);
|
||||
gst_pad_set_caps (enc->srcpad, caps);
|
||||
|
||||
gst_buffer_set_caps (buf1, caps);
|
||||
gst_buffer_set_caps (buf2, caps);
|
||||
gst_caps_unref (caps);
|
||||
|
||||
/* push out buffers */
|
||||
ret = gst_opus_enc_push_buffer (enc, buf1);
|
||||
|
||||
if (ret != GST_FLOW_OK) {
|
||||
gst_buffer_unref (buf2);
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = gst_opus_enc_push_buffer (enc, buf2);
|
||||
|
||||
if (ret != GST_FLOW_OK)
|
||||
goto done;
|
||||
|
||||
enc->header_sent = TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
GST_DEBUG_OBJECT (enc, "received buffer of %u bytes", GST_BUFFER_SIZE (buf));
|
||||
|
||||
|
|
Loading…
Reference in a new issue