*/
static GstStaticPadTemplate gst_rtp_h264_pay_sink_template =
-GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
- GST_STATIC_CAPS ("video/x-h264")
+ GST_STATIC_CAPS ("video/x-h264, "
+ "stream-format = (string) byte-stream, alignment = (string) { nal, au };"
+ "video/x-h264, "
+ "stream-format = (string) avc, alignment = (string) au")
);
static GstStaticPadTemplate gst_rtp_h264_pay_src_template =
gst_rtp_h264_pay_getcaps (GstRTPBasePayload * payload, GstPad * pad,
GstCaps * filter)
{
+ GstCaps *template_caps;
GstCaps *allowed_caps;
+ GstCaps *caps, *icaps;
+ guint i;
allowed_caps =
gst_pad_peer_query_caps (GST_RTP_BASE_PAYLOAD_SRCPAD (payload), filter);
- if (allowed_caps) {
- GstCaps *caps = NULL;
- guint i;
+ if (allowed_caps == NULL)
+ return NULL;
- if (gst_caps_is_any (allowed_caps)) {
- gst_caps_unref (allowed_caps);
- goto any;
- }
+ template_caps =
+ gst_static_pad_template_get_caps (&gst_rtp_h264_pay_sink_template);
- if (gst_caps_is_empty (allowed_caps))
- return allowed_caps;
+ if (gst_caps_is_any (allowed_caps)) {
+ caps = gst_caps_ref (template_caps);
+ goto done;
+ }
- caps = gst_caps_new_empty ();
+ if (gst_caps_is_empty (allowed_caps)) {
+ caps = gst_caps_ref (allowed_caps);
+ goto done;
+ }
- for (i = 0; i < gst_caps_get_size (allowed_caps); i++) {
- GstStructure *s = gst_caps_get_structure (allowed_caps, i);
- GstStructure *new_s = gst_structure_new_empty ("video/x-h264");
- const gchar *profile_level_id;
+ caps = gst_caps_new_empty ();
- profile_level_id = gst_structure_get_string (s, "profile-level-id");
+ for (i = 0; i < gst_caps_get_size (allowed_caps); i++) {
+ GstStructure *s = gst_caps_get_structure (allowed_caps, i);
+ GstStructure *new_s = gst_structure_new_empty ("video/x-h264");
+ const gchar *profile_level_id;
- if (profile_level_id && strlen (profile_level_id) == 6) {
- const gchar *profile;
- const gchar *level;
- long int spsint;
- guint8 sps[3];
+ profile_level_id = gst_structure_get_string (s, "profile-level-id");
- spsint = strtol (profile_level_id, NULL, 16);
- sps[0] = spsint >> 16;
- sps[1] = spsint >> 8;
- sps[2] = spsint;
+ if (profile_level_id && strlen (profile_level_id) == 6) {
+ const gchar *profile;
+ const gchar *level;
+ long int spsint;
+ guint8 sps[3];
- profile = gst_codec_utils_h264_get_profile (sps, 3);
- level = gst_codec_utils_h264_get_level (sps, 3);
+ spsint = strtol (profile_level_id, NULL, 16);
+ sps[0] = spsint >> 16;
+ sps[1] = spsint >> 8;
+ sps[2] = spsint;
- if (profile && level) {
- GST_LOG_OBJECT (payload, "In caps, have profile %s and level %s",
- profile, level);
+ profile = gst_codec_utils_h264_get_profile (sps, 3);
+ level = gst_codec_utils_h264_get_level (sps, 3);
- if (!strcmp (profile, "constrained-baseline"))
- gst_structure_set (new_s, "profile", G_TYPE_STRING, profile, NULL);
- else {
- GValue val = { 0, };
- GValue profiles = { 0, };
+ if (profile && level) {
+ GST_LOG_OBJECT (payload, "In caps, have profile %s and level %s",
+ profile, level);
- g_value_init (&profiles, GST_TYPE_LIST);
- g_value_init (&val, G_TYPE_STRING);
+ if (!strcmp (profile, "constrained-baseline"))
+ gst_structure_set (new_s, "profile", G_TYPE_STRING, profile, NULL);
+ else {
+ GValue val = { 0, };
+ GValue profiles = { 0, };
- g_value_set_static_string (&val, profile);
- gst_value_list_append_value (&profiles, &val);
+ g_value_init (&profiles, GST_TYPE_LIST);
+ g_value_init (&val, G_TYPE_STRING);
- g_value_set_static_string (&val, "constrained-baseline");
- gst_value_list_append_value (&profiles, &val);
+ g_value_set_static_string (&val, profile);
+ gst_value_list_append_value (&profiles, &val);
- gst_structure_take_value (new_s, "profile", &profiles);
- }
+ g_value_set_static_string (&val, "constrained-baseline");
+ gst_value_list_append_value (&profiles, &val);
- if (!strcmp (level, "1"))
- gst_structure_set (new_s, "level", G_TYPE_STRING, level, NULL);
- else {
- GValue levels = { 0, };
- GValue val = { 0, };
- int j;
-
- g_value_init (&levels, GST_TYPE_LIST);
- g_value_init (&val, G_TYPE_STRING);
-
- for (j = 0; all_levels[j]; j++) {
- g_value_set_static_string (&val, all_levels[j]);
- gst_value_list_prepend_value (&levels, &val);
- if (!strcmp (level, all_levels[j]))
- break;
- }
- gst_structure_take_value (new_s, "level", &levels);
+ gst_structure_take_value (new_s, "profile", &profiles);
+ }
+
+ if (!strcmp (level, "1"))
+ gst_structure_set (new_s, "level", G_TYPE_STRING, level, NULL);
+ else {
+ GValue levels = { 0, };
+ GValue val = { 0, };
+ int j;
+
+ g_value_init (&levels, GST_TYPE_LIST);
+ g_value_init (&val, G_TYPE_STRING);
+
+ for (j = 0; all_levels[j]; j++) {
+ g_value_set_static_string (&val, all_levels[j]);
+ gst_value_list_prepend_value (&levels, &val);
+ if (!strcmp (level, all_levels[j]))
+ break;
}
+ gst_structure_take_value (new_s, "level", &levels);
}
}
-
- gst_caps_merge_structure (caps, new_s);
}
- gst_caps_unref (allowed_caps);
- return caps;
+ gst_caps_merge_structure (caps, new_s);
}
-any:
- return gst_caps_new_empty_simple ("video/x-h264");
+ icaps = gst_caps_intersect (caps, template_caps);
+ gst_caps_unref (caps);
+ caps = icaps;
+
+done:
+
+ gst_caps_unref (template_caps);
+ gst_caps_unref (allowed_caps);
+
+ GST_LOG_OBJECT (payload, "returning caps %" GST_PTR_FORMAT, caps);
+ return caps;
}
/* take the currently configured SPS and PPS lists and set them on the caps as
typedef struct
{
GstElement *pipeline;
- GstElement *fdsrc;
- GstElement *capsfilter;
+ GstElement *appsrc;
GstElement *rtppay;
GstElement *rtpdepay;
GstElement *fakesink;
- int fd[2];
- const char *frame_data;
+ const guint8 *frame_data;
int frame_data_size;
int frame_count;
} rtp_pipeline;
* The user must free the RTP pipeline when it's not used anymore.
*/
static rtp_pipeline *
-rtp_pipeline_create (const char *frame_data, int frame_data_size,
+rtp_pipeline_create (const guint8 * frame_data, int frame_data_size,
int frame_count, const char *filtercaps, const char *pay, const char *depay)
{
gchar *pipeline_name;
-
rtp_pipeline *p;
-
GstCaps *caps;
/* Check parameters. */
pipeline_name = g_strdup_printf ("%s-%s-pipeline", pay, depay);
p->pipeline = gst_pipeline_new (pipeline_name);
g_free (pipeline_name);
- p->fdsrc = gst_element_factory_make ("fdsrc", NULL);
- p->capsfilter = gst_element_factory_make ("capsfilter", NULL);
+ p->appsrc = gst_element_factory_make ("appsrc", NULL);
p->rtppay = gst_element_factory_make (pay, NULL);
p->rtpdepay = gst_element_factory_make (depay, NULL);
p->fakesink = gst_element_factory_make ("fakesink", NULL);
/* One or more elements are not created successfully or failed to create p? */
- if (!p->pipeline || !p->fdsrc || !p->capsfilter || !p->rtppay || !p->rtpdepay
- || !p->fakesink || pipe (p->fd) == -1) {
+ if (!p->pipeline || !p->appsrc || !p->rtppay || !p->rtpdepay || !p->fakesink) {
/* Release created elements. */
RELEASE_ELEMENT (p->pipeline);
- RELEASE_ELEMENT (p->fdsrc);
- RELEASE_ELEMENT (p->capsfilter);
+ RELEASE_ELEMENT (p->appsrc);
RELEASE_ELEMENT (p->rtppay);
RELEASE_ELEMENT (p->rtpdepay);
RELEASE_ELEMENT (p->fakesink);
- /* Close pipe. */
- if (p->fd[0]) {
- close (p->fd[0]);
- }
-
- if (p->fd[1]) {
- close (p->fd[1]);
- }
-
/* Release allocated memory. */
free (p);
return NULL;
}
- /* Set fdsrc properties. */
- g_object_set (p->fdsrc, "fd", p->fd[0], NULL);
- g_object_set (p->fdsrc, "do-timestamp", TRUE, NULL);
- g_object_set (p->fdsrc, "blocksize", p->frame_data_size, NULL);
- g_object_set (p->fdsrc, "num-buffers", p->frame_count * LOOP_COUNT, NULL);
-
- /* Set caps filters. */
+ /* Set src properties. */
caps = gst_caps_from_string (filtercaps);
-
- g_object_set (p->capsfilter, "caps", caps, NULL);
+ g_object_set (p->appsrc, "do-timestamp", TRUE, "caps", caps, NULL);
gst_caps_unref (caps);
/* Add elements to the pipeline. */
- gst_bin_add (GST_BIN (p->pipeline), p->fdsrc);
- gst_bin_add (GST_BIN (p->pipeline), p->capsfilter);
+ gst_bin_add (GST_BIN (p->pipeline), p->appsrc);
gst_bin_add (GST_BIN (p->pipeline), p->rtppay);
gst_bin_add (GST_BIN (p->pipeline), p->rtpdepay);
gst_bin_add (GST_BIN (p->pipeline), p->fakesink);
/* Link elements. */
- gst_element_link (p->fdsrc, p->capsfilter);
- gst_element_link (p->capsfilter, p->rtppay);
+ gst_element_link (p->appsrc, p->rtppay);
gst_element_link (p->rtppay, p->rtpdepay);
gst_element_link (p->rtpdepay, p->fakesink);
/* Release pipeline. */
RELEASE_ELEMENT (p->pipeline);
- /* Close pipe. */
- if (p->fd[0]) {
- close (p->fd[0]);
- }
-
- if (p->fd[1]) {
- close (p->fd[1]);
- }
-
/* Release allocated memory. */
free (p);
}
static void
rtp_pipeline_run (rtp_pipeline * p)
{
+ GstFlowReturn flow_ret;
GMainLoop *mainloop = NULL;
-
GstBus *bus;
-
- gint i;
+ gint i, j;
/* Check parameters. */
if (p == NULL) {
/* Set pipeline to PLAYING. */
gst_element_set_state (p->pipeline, GST_STATE_PLAYING);
- /* TODO: Writing may need some changes... */
-
+ /* Push data into the pipeline */
for (i = 0; i < LOOP_COUNT; i++) {
- const char *frame_data_pointer = p->frame_data;
- int res;
- int frame_count = p->frame_count;
-
- /* Write in to the pipe. */
- while (frame_count > 0) {
- res = write (p->fd[1], frame_data_pointer, p->frame_data_size);
- fail_unless_equals_int (res, p->frame_data_size);
- frame_data_pointer += p->frame_data_size;
- frame_count--;
+ const guint8 *data = p->frame_data;
+
+ for (j = 0; j < p->frame_count; j++) {
+ GstBuffer *buf;
+
+ buf =
+ gst_buffer_new_wrapped_full ((guint8 *) data, NULL, 0,
+ p->frame_data_size);
+
+ g_signal_emit_by_name (p->appsrc, "push-buffer", buf, &flow_ret);
+ fail_unless_equals_int (flow_ret, GST_FLOW_OK);
+ data += p->frame_data_size;
+
+ gst_buffer_unref (buf);
}
}
+ g_signal_emit_by_name (p->appsrc, "end-of-stream", &flow_ret);
+
/* Run mainloop. */
g_main_loop_run (mainloop);
* @use_lists enable buffer lists
*/
static void
-rtp_pipeline_test (const char *frame_data, int frame_data_size, int frame_count,
- const char *filtercaps, const char *pay, const char *depay,
+rtp_pipeline_test (const guint8 * frame_data, int frame_data_size,
+ int frame_count, const char *filtercaps, const char *pay, const char *depay,
guint bytes_sent, guint mtu_size, gboolean use_lists)
{
/* Create RTP pipeline. */
}
}
-static char rtp_ilbc_frame_data[] =
+static const guint8 rtp_ilbc_frame_data[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
}
GST_END_TEST;
-static char rtp_gsm_frame_data[] =
+static const guint8 rtp_gsm_frame_data[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
}
GST_END_TEST;
-static char rtp_amr_frame_data[] =
+static const guint8 rtp_amr_frame_data[] =
{ 0x3c, 0x24, 0x03, 0xb3, 0x48, 0x10, 0x68, 0x46, 0x6c, 0xec, 0x03,
0x7a, 0x37, 0x16, 0x41, 0x41, 0xc0, 0x00, 0x0d, 0xcd, 0x12, 0xed,
0xad, 0x80, 0x00, 0x00, 0x11, 0x31, 0x00, 0x00, 0x0d, 0xa0
}
GST_END_TEST;
-static char rtp_pcma_frame_data[] =
+static const guint8 rtp_pcma_frame_data[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
}
GST_END_TEST;
-static char rtp_pcmu_frame_data[] =
+static const guint8 rtp_pcmu_frame_data[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
}
GST_END_TEST;
-static char rtp_mpa_frame_data[] =
+static const guint8 rtp_mpa_frame_data[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
}
GST_END_TEST;
-static char rtp_h263_frame_data[] =
+static const guint8 rtp_h263_frame_data[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
GST_START_TEST (rtp_h263)
{
rtp_pipeline_test (rtp_h263_frame_data, rtp_h263_frame_data_size,
- rtp_h263_frame_count, "video/x-h263,variant=itu,h263version=h263",
+ rtp_h263_frame_count, "video/x-h263,variant=(string)itu,h263version=h263",
"rtph263pay", "rtph263depay", 0, 0, FALSE);
}
GST_END_TEST;
-static char rtp_h263p_frame_data[] =
+static const guint8 rtp_h263p_frame_data[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
GST_START_TEST (rtp_h263p)
{
rtp_pipeline_test (rtp_h263p_frame_data, rtp_h263p_frame_data_size,
- rtp_h263p_frame_count, "video/x-h263,variant=itu", "rtph263ppay",
+ rtp_h263p_frame_count, "video/x-h263,variant=(string)itu", "rtph263ppay",
"rtph263pdepay", 0, 0, FALSE);
}
GST_END_TEST;
-static char rtp_h264_frame_data[] =
+static const guint8 rtp_h264_frame_data[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
GST_START_TEST (rtp_h264)
{
+ /* FIXME 0.11: fully specify h264 caps (and make payloader check) */
rtp_pipeline_test (rtp_h264_frame_data, rtp_h264_frame_data_size,
rtp_h264_frame_count, "video/x-h264", "rtph264pay", "rtph264depay",
0, 0, FALSE);
}
GST_END_TEST;
-static char rtp_h264_list_lt_mtu_frame_data[] =
+static const guint8 rtp_h264_list_lt_mtu_frame_data[] =
/* not packetized, next NAL starts with 0001 */
{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
GST_START_TEST (rtp_h264_list_lt_mtu)
{
+ /* FIXME 0.11: fully specify h264 caps (and make payloader check) */
rtp_pipeline_test (rtp_h264_list_lt_mtu_frame_data,
rtp_h264_list_lt_mtu_frame_data_size, rtp_h264_list_lt_mtu_frame_count,
"video/x-h264", "rtph264pay", "rtph264depay",
}
GST_END_TEST;
-static char rtp_h264_list_gt_mtu_frame_data[] =
+static const guint8 rtp_h264_list_gt_mtu_frame_data[] =
/* not packetized, next NAL starts with 0001 */
{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
GST_START_TEST (rtp_h264_list_gt_mtu)
{
+ /* FIXME 0.11: fully specify h264 caps (and make payloader check) */
rtp_pipeline_test (rtp_h264_list_gt_mtu_frame_data,
rtp_h264_list_gt_mtu_frame_data_size, rtp_h264_list_gt_mtu_frame_count,
"video/x-h264", "rtph264pay", "rtph264depay",
}
GST_END_TEST;
-static char rtp_L16_frame_data[] =
+static const guint8 rtp_L16_frame_data[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
}
GST_END_TEST;
-static char rtp_mp2t_frame_data[] =
+static const guint8 rtp_mp2t_frame_data[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
}
GST_END_TEST;
-static char rtp_mp4v_frame_data[] =
+static const guint8 rtp_mp4v_frame_data[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
}
GST_END_TEST;
-static char rtp_mp4v_list_frame_data[] =
+static const guint8 rtp_mp4v_list_frame_data[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
}
GST_END_TEST;
-static char rtp_mp4g_frame_data[] =
+static const guint8 rtp_mp4g_frame_data[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
}
GST_END_TEST;
-static char rtp_theora_frame_data[] =
+static const guint8 rtp_theora_frame_data[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
}
GST_END_TEST;
-static char rtp_vorbis_frame_data[] =
+static const guint8 rtp_vorbis_frame_data[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
}
GST_END_TEST;
-static char rtp_jpeg_frame_data[] =
+static const guint8 rtp_jpeg_frame_data[] =
{ /* SOF */ 0xFF, 0xC0, 0x00, 0x11, 0x08, 0x00, 0x08, 0x00, 0x08,
0x03, 0x00, 0x21, 0x08, 0x01, 0x11, 0x08, 0x02, 0x11, 0x08,
/* DQT */ 0xFF, 0xDB, 0x00, 0x43, 0x08,
}
GST_END_TEST;
-static char rtp_jpeg_list_frame_data[] =
+static const guint8 rtp_jpeg_list_frame_data[] =
{ /* SOF */ 0xFF, 0xC0, 0x00, 0x11, 0x08, 0x00, 0x08, 0x00, 0x08,
0x03, 0x00, 0x21, 0x08, 0x01, 0x11, 0x08, 0x02, 0x11, 0x08,
/* DQT */ 0xFF, 0xDB, 0x00, 0x43, 0x08,
}
GST_END_TEST;
-static char rtp_g729_frame_data[] =
+static const guint8 rtp_g729_frame_data[] =
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};